ONO::FW::Apps::Info

package ONO::FW::Apps::Info;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

use strict;

use ONO::IO;

use ONO::Lib::UI::MSG;
use ONO::Lib::UI::Rate;
use ONO::Lib::UI::Icon;

use ONO::FW::Apps::Rank;
use ONO::FW::Apps::ToolBox;

use ONO::Lib::DateTime::ToolBox;
use ONO::Lib::Image::QR;

###############################################################################
# info
###############################################################################

sub info {

#: Display ONO app information.

my (
$self,
$db,
$community,
$lang,
$setup_ref,
$BLK_ref,
$variation,
$vars_ref,
$BASE,
) = @_;

my %setup = %$setup_ref;
my %BLK = %$BLK_ref;
my %vars = %$vars_ref;

my $Community = ucfirst $community;

# langkit

my @text = (
"No app description available yet...",
"Thanks for rating this app!",
"Ratings & comments",
"You've already rated or commented this app - re-rating the app will replace your previous rating.",
"Rate this app!",
"launch app now",
"max. 1000 characters, no HTML...",
);

if ($lang eq "de") {
@text = (
"Noch keine Beschreibung der App verfügbar...",
"Danke für die Bewertung dieser App!",
"Bewertungen & Kommentare",
"Du hast diese App bereits bewertet oder kommentiert - eine Neubewertung wird deine alte Bewertung ersetzen.",
"Diese App bewerten!",
"App jetzt starten",
"max. 1000 Zeichen, kein HTML...",
);
}

if ($lang eq "fr") {
@text = (
"Pas de description disponible pour le moment...",
"Merci d'avoir évalué cette application!",
"Evaluations & commentaires",
"Vous avez déjà évalué ou commenté cette application - une ré-évaluation replaçera votre dernière évaluation.",
"Evaluez cette appliaction!",
"Démarrer l'application maintenant",
"max. 1000 charactères, pas de code HTML...",
);
}

if ($lang eq "lu") {
@text = (
"Nach keng Beschreiwung vun der App disponibel...",
"Merci fir d'Bewertung vun dëser App!",
"Bewertungen & Kommentarer",
"Du hues dës App scho bewertet oder kommentéiert - eng Neibewertung ersetzt deng aal Bewertung.",
"Dës App bewerten!",
"App elo starten",
"max. 1000 Zeechen, keen HTML...",
);
}

# clean up variables

$vars{'app'} =~ s~[^a-z0-9\_]~~g;
$ENV{'SCRIPT_NAME'} =~ s~^//~/~;

my ($WEB,$MSG,$DEBUG);

my (
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$isdst
) = ONO::Lib::DateTime::ToolBox->get;

my %info;
my @lines = ONO::IO->list("var/community/$community/apps/$vars{'app'}.txt");
foreach my $line (@lines) {
if ($line =~ m~^(.*?):(.*):~) {
$info{$1} = $2;
}
}

if ($info{"title_$lang"}) {
$info{'title_en'} = $info{"title_$lang"};
}

my $description = ONO::IO->load("var/community/$community/apps/$vars{'app'}/description_en.txt");

if (ONO::IO->exists("var/community/$community/apps/$vars{'app'}/description_$lang.txt")) {
my $test = ONO::IO->load("var/community/$community/apps/$vars{'app'}/description_$lang.txt");
if ($test =~ /[a-z]/) {
$description = $test;
}
}

$description =~ s~\n~<br>~g;

unless ($description =~ /[a-z]/) {
$description = $text[0];
}

$info{'icon'} =~ s~256~128~;

my $domain = ONO::IO->domain();
my $domain_full = ONO::IO->domain_full();
my $HTTP = ONO::IO->http();

my $APPS_BASE = ONO::FW::Apps::ToolBox->apps_base();

my $RUN = qq~$HTTP://$domain_full$BASE/$APPS_BASE/$vars{'app'}/~;
if ($info{'url'} !~ m~/cgi-bin/local/perl/$community/apps/~) {
$RUN = qq~$HTTP://$domain_full$BASE$info{'url'}~;
}

# add a comment

$MSG = ONO::FW::Apps::Rank->add_comment($db,$community,"apps","apps",\@text,\%vars);

# load ratings and comments

my (
$comments,
$rank,
$counter,
$ranked,
$commented,
) = ONO::FW::Apps::Rank->comments($db,$community,"apps","apps","",\%vars);

my (
$stars1,
$stars2,
) = ONO::FW::Apps::Rank->stars($db,$community,"apps","apps",\%vars);

my $RANK = qq~<img class="block auto" src="/ono/osr/images/rating/stars_$stars2.gif" style="width:80px;height:16px" alt="">~;

my $COMM = qq~<br><br>
<img class="block w100 mb10" src="/ono/osr/images/spacer/grey.gif" style="height:1px" alt="">
<h2>$text[2]</h2>
<br>
$MSG
$comments
~;

my $STARS = ONO::FW::Apps::Rank->star_sel($ranked);

my $action = "/account/";
if ($vars{'sid'}) {
$action = $ENV{'SCRIPT_NAME'};
}

my $NOTE;
if ($ranked ne "") {
$NOTE = qq~<strong>$text[3]</strong>~;
}

$COMM .= qq~<div class="box_fabric w95 mt10">
<form action="$action" method="post">
<input type="hidden" name="mode" value="$vars{'mode'}">
<input type="hidden" name="app" value="$vars{'app'}">
<h2>$text[4]</h2>
$NOTE
<div class="box_white">
$STARS
<div class="bold mt10">$BLK{'Comment'}:</div>
<textarea name="app_comment" class="w95" style="height:100px" maxlength="1000" placeholder="$text[6]">$commented</textarea>
<div class="inline"><input type="submit" name="$BLK{'rate'}" value="$BLK{'rate'}" class="button_green"></div>
</div>
</form>
</div>
~;

my $copyright_year = $year;
my $copyright_web = $ENV{'SERVER_NAME'};
my $copyright_holder = $ENV{'SERVER_NAME'};

if (ONO::IO->exists("var/community/$community/apps/$vars{'app'}/copyright.txt")) {

my @cp = split(/:/,ONO::IO->load("var/community/$community/apps/$vars{'app'}/copyright.txt"));
if ($cp[0] && $cp[0] ne $year) {
$copyright_year = "$cp[0]-$year";
}
if ($cp[1] =~ /[A-Za-z0-9]/) {
$copyright_holder .= qq~, $cp[1]~;
}

}

my $QR;
my $DOMAIN = ONO::IO->http_domain_base();
my $qrfile = "$DOMAIN/apps/$vars{'app'}/run";
$qrfile =~ s~^(http|https)://~~g;
$qrfile =~ s~[^A-Za-z0-9]~-~g;
if (!ONO::IO->exists("images/qr/$qrfile.jpg") || ONO::IO->devstation) {
ONO::Lib::Image::QR->make("$DOMAIN/$APPS_BASE/$vars{'app'}/");
}
if (ONO::IO->exists("images/qr/$qrfile.jpg")) {
$QR = qq~<div class="block128 bo radius10 hide720" style="overflow:hidden"><a href="$DOMAIN/$APPS_BASE/qrcode/?/qrcode/$qrfile/"><img class="block128 radius10" src="/images/qr/$qrfile.jpg" alt=""></a></div>
<div class="block64 bo radius10 hide block720" style="overflow:hidden"><a href="$DOMAIN/$APPS_BASE/qrcode/?/qrcode/$qrfile/"><img class="block64 radius10" src="/images/qr/$qrfile.jpg" alt=""></a></div>
~;
}

# <div class="fl mr10">$SCREEN</div>

my ($COM,$TAB,$PDF) = &display_all("",$variation,$vars{'app'},256,"t");

my $PREVIEWS;

if ($PDF) {
$PREVIEWS .= qq~<div class="mb10" style="width:100%;height:384px;resize:both;overflow-y:hidden;overflow-x:auto;"><table class="default_table"><tr>$PDF</tr></table></div>~;
}
if ($TAB) {
$PREVIEWS .= qq~<div class="mb10" style="width:100%;height:276px;overflow-y:hidden;overflow-x:auto;"><table class="default_table"><tr>$TAB</tr></table></div>~;
}

my $APP = ONO::Lib::UI::Icon->icon($info{'icon'},128);

$WEB = qq~<table class="wide_table mb10">
<tr class="vtop">
<td>
<a href="$RUN">
$APP
</a>
$RANK
</td>
<td class="w100 pad10_2">
<h1>$info{'title_en'}</h1>
<div>$description</div>
</td>
</tr>
</table>
$MSG
$PREVIEWS
<table class="wide_table">
<tr class="vtop">
<td>$QR</td>
<td class="w100">
<table class="wide_table ml10 mb10">
<tr>
<td class="pad10_2"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/devices/network.png" alt=""></td>
<td class="w100"><input type="text" name="ono_fw_apps_app_url" value="$RUN" class="w98" onclick="this.select();"></td>
</tr>
</table>
<div class="inline">
<a href="$RUN" class="button_green ml20">$text[5]</a>
<a href="$setup{'url_account'}?community_screen=bookmarks&add=app_$vars{'app'}" class="button_green ml10">$BLK{'bookmark'}</a>
</div>
</td>
</tr>
</table>
$COMM
~;

# <div class="italic ml20 mb20">©$copyright_year $copyright_holder</div>

$WEB .= ONO::Lib::UI::Rate->script;

if (ONO::IO->exists("cgi-bin/local/perl/$community/$Community/Apps/LICENSE/$vars{'app'}")) {

$WEB .= qq~<div class="mt10"><h2>Copyright Information</h2></div>~;

if (ONO::IO->exists("cgi-bin/local/perl/$community/$Community/Apps/LICENSE/$vars{'app'}/README.txt")) {

$WEB .= ONO::IO->load("cgi-bin/local/perl/$community/$Community/Apps/LICENSE/$vars{'app'}/README.txt");

}

if (ONO::IO->exists("cgi-bin/local/perl/$community/$Community/Apps/LICENSE/$vars{'app'}/LICENSE.txt")) {

my $LIC = ONO::IO->load("cgi-bin/local/perl/$community/$Community/Apps/LICENSE/$vars{'app'}/LICENSE.txt");

$LIC =~ s~\n~<br>~g;

$WEB .= $LIC;

}

}

return $WEB;

}

sub display_pdf {

my (
$self,
$variation,
$app,
$img,
$width,
$switches,
) = @_;

#: Display a small PDF preview.

my @size = (384,542,90,68);

if ($width && $width != 384) {
my $ratio = 384/$width;
@size = (
$width,
$size[1]/$ratio,
$size[2]/$ratio,
$size[3]/$ratio,
);
}

my $var = "varpdf$app$img";
$var =~ s~[^a-z0-9]~~g;

my $IMG = "/examples/data-mz/apps/$app/img/$img";
if ($switches =~ /f/) {
$IMG = $img;
$var = "varpdf$app";
}

my $CODE = qq~<div class="bo mr10 mb10 fl" onmouseover="onojs_block('hover-pdf-$app-$img');onojs_hide('static-pdf-$app-$img');" onmouseout="onojs_hide('hover-pdf-$app-$img');onojs_block('static-pdf-$app-$img');">
<div class="rel" style="width:$size[0]px;height:$size[1]px;overflow:hidden">
<div id="hover-pdf-$app-$img" class="abs hide cursorlink"
style="width:$size[0]px;height:$size[1]px;background-image:url('$IMG');background-size:200%;background-position:center;background-repeat:no-repeat"></div>
<div id="static-pdf-$app-$img">
<img class="block abs" src="/examples/data-mz/app-design/pdf_header_${variation}_1280_280_top.jpg" style="width:$size[0]px;height:$size[2]px;top:0px;left:0px" alt="">
<img class="block abs" src="/examples/data-mz/app-design/pdf_header_${variation}_1280_225_bot.jpg" style="width:$size[0]px;height:$size[3]px;bottom:0px;left:0px" alt="">
<img class="block" src="$IMG" style="width:$size[0]px;height:$size[1]px" alt="">
</div>
</div>
</div>
<script>onojs_hover_zoom("hover-pdf-$app-$img",20,0,120,220);</script>
~;
if ($switches =~ /t/) {
$CODE = qq~<td>$CODE</td>~;
}

return $CODE;

}

sub display_tab {

my (
$self,
$variation,
$app,
$img,
$width,
$switches,
) = @_;

#: Display a small tablet (iPad) preview.

my $var = "vartab$app$img";
$var =~ s~[^a-z0-9]~~g;

my $IMG = "/examples/data-mz/apps/$app/img/$img";
if ($switches =~ /f/) {
$IMG = $img;
$var = "vartab$app";
}

my $CODE = qq~<div class="mr10 mb10 fl" onmouseover="onojs_block('hover-tab-$app-$img');onojs_hide('static-tab-$app-$img');" onmouseout="onojs_hide('hover-tab-$app-$img');onojs_block('static-tab-$app-$img');">
<div class="rel" style="max-width:400px">
<img class="block" src="/examples/data-mz/app-design/ipad_1024_740.png" style="width:100%;height:auto" alt="">
<div id="static-tab-$app-$img" class="abs" style="top:0px;left:0px;width:80%;padding:10%"><img class="block" src="$IMG" style="width:100%;height:auto" alt=""></div>
<div id="hover-tab-$app-$img" class="abs hide cursorlink" style="top:10%;left:7%;width:86%;height:90%">
<div id="hover-tab2-$app-$img" style="width:100%;height:90%;background-image:url('$IMG');background-size:200%;background-position:center;background-repeat:no-repeat"></div>
</div>
</div>
</div>
<script>onojs_hover_zoom("hover-tab2-$app-$img");</script>
~;

if ($switches =~ /t/) {
$CODE = qq~<td>$CODE</td>~;
}

return $CODE;

}

sub display_all {

my (
$self,
$variation,
$app,
$width,
$switches,
) = @_;

#: Display both small PDF and tablet/iPad preview.
#:
#: Switches
#:
#: -f use external file
#: -h force respect height (not implemented)
#: -t wrap in horizontal table (only td, not table/td)

my ($COM,$TAB,$PDF);

foreach my $img (sort ONO::IO->dir("examples/data-mz/apps/$app/img")) {

# screenshots:

if ($img =~ /screenshot_(.*?)_640\.jpg$/) {

$TAB .= &display_tab("",$variation,$app,$img,$width,$switches);

}

# PDF worksheets:

if ($img =~ /sheet_(.*?)_640\.jpg$/) {

$PDF .= &display_pdf("",$variation,$app,$img,$width,$switches);

}
}

return ($COM,$TAB,$PDF);

}

###############################################################################
# end of script
###############################################################################

1;

__END__