-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_p.cgi
executable file
·193 lines (157 loc) · 5.88 KB
/
_p.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/local/bin/perl
#################################################################################
# _P.CGI
#
# Author : Zheileman (zheileman at gmail.com)
# URL : http://github.com/zheileman/potiphoti
#
# Copyright 2003-2011, Zheileman.
#
#
# This file is part of PotiPhoti.
#
# PotiPhoti is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# PotiPhoti 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PotiPhoti; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#################################################################################
use strict;
use CGI;
use GD;
use lib::Thumbnail;
use lib::BASE;
my $img = $BASE::img;
my $thumb = $BASE::thumb;
my $xml = $BASE::xml;
my $initimg;
my $totalfotos = 0;
my $totalsize = 0;
my $extrainfo = $BASE::extrainfo;
print "Content-type: text/html\n\n";
my $q = new CGI;
my $id = $q->param('id') || 0;
my $offset = $q->param('offset') || 1;
my $all = $q->param('all') || 0;
# Remove all but numbers
$id = BASE::validate($id);
$offset = BASE::validate($offset);
$all = BASE::validate($all);
if ($id < 0) { $id = 0; }
if ($offset < 0) { $offset = 1; }
if ($all < 0) { $all = 0; }
&printHTML($id, $offset, $all);
sub printHTML {
my $html = BASE::joinTemplate("template_p.txt");
my $minifotos = &getMinifotos($_[0], $_[1], $_[2]);
my $fotoactual = &getFoto($_[0], $_[1], $_[2]);
my $infolateral = BASE::joinSide("template_s.txt", $totalfotos, $totalsize);
my $poweredby = "<div class=\"poweredby\">$BASE::version</div>";
$html =~ s/<!--<MINIFOTOS>-->/$minifotos/;
$html =~ s/<!--<FOTOACTUAL>-->/$fotoactual/;
$html =~ s/<!--<INFOLATERAL>-->/$infolateral/ if $extrainfo;
$html =~ s/<!--<POWEREDBY>-->/$poweredby/;
print $html;
}
sub getMinifotos {
my $ret;
my $alt;
my $id = $_[0];
my $style;
my $i = 0;
my $offset = $_[1];
my $all = $_[2];
my $newtr = 1;
my @fotos = <$img*>;
if ($extrainfo) {
# Complementary information
$totalfotos = @fotos;
$totalsize = `du -ch $BASE::thumb $BASE::img $BASE::big`;
$totalsize =~ s/\n/<br \/>/g;
}
foreach my $src (reverse sort @fotos) {
my $thumbfile = $src;
$thumbfile =~ s/$img/$thumb/g;
$thumbfile =~ s/\.jpg/m\.jpg/g;
if (!-e $thumbfile) {
if (open IN, "$src") {
my $srcImage = GD::Image->newFromJpeg(*IN);
close IN;
# Create a thumbnail where the biggest side is X
my ($thumbb,$x,$y) = Thumbnail::create($srcImage, $BASE::thumbsize2);
# Save the thumbnail
if (open OUT, "> $thumbfile") {
binmode OUT;
print OUT $thumbb->jpeg;
close OUT;
}
}
}
$style = "style=\"FILTER:alpha(opacity=50);\" onmouseover=\"high(this)\" onmouseout=\"low(this)\"";
$i++;
if ($all) {
# We are building a table with thumbnails
$ret .= "\r\n<tr>\r\n" if ($newtr == 1);
$alt = BASE::getFecha($src);
$ret .= "<td><a href=\"?offset=" . $offset . "&id=" . BASE::getID($src) . "\"><img src=\"$thumbfile\" alt=\"$alt\" title=\"$alt\" border=\"0\" $style /></a></td>\r\n";
$newtr++;
if ($i == @fotos) {
while ($newtr++ < 5) {
$ret .= "<td> </td>\r\n";
}
}
if ($newtr >= 5) {
# End of TR
$ret .= "</tr>";
$newtr = 1;
}
} else {
next if ($i <= ($offset-1)*4);
$initimg = $src if (!$initimg); # Get the first photo from each set for later reference
if ( ($src eq "$img$id.jpg") || (($id==0) && ($src eq $initimg)) ) { $style = "style=\"$BASE::sphotostyle\""; }
$alt = BASE::getFecha($src);
$ret .= " <a href=\"?offset=" . $offset . "&id=" . BASE::getID($src) . "\"><img src=\"$thumbfile\" alt=\"$alt\" title=\"$alt\" border=\"0\" $style /></a>\r\n";
last if ((($i % 4)==0) && ($i < @fotos)); # Exit loop because now we have 4 photos
}
}
if ($all) {
$ret = "\r\n<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">" . $ret . "</table>";
} else {
$ret .= " ";
# Add left arrow (go back)
if ($offset > 1) { $ret .= "<a href=\"?offset=" . ($offset-1) . "\"><img src=\"arrow1.jpg\" alt=\"\" width=\"7\" height=\"9\" border=\"0\" /></a>"; }
# Add right arrow (next 4 photos)
if ($i < @fotos) { $ret .= "<a href=\"?offset=" . ++$offset . "\"><img src=\"arrow2.jpg\" alt=\"\" width=\"7\" height=\"9\" border=\"0\" /></a>"; }
}
$ret = "<center><div class=\"photominis\">$ret</div></center>";
return $ret;
}
sub getFoto {
return if ($_[2]);
my $ret;
my $xmlfile;
my $id = $_[0];
my $offset = $_[1];
if ($id==0) {
# There is no photo selected
$xmlfile = BASE::getID($initimg);
$xmlfile .= ".xml" if ($xmlfile>0);
} else {
$xmlfile = "$id.xml";
}
$xmlfile = $xmlfile ? "$xml$xmlfile" : "";
$xmlfile = "" if (!-e $xmlfile); # File exists?
$ret = "
<iframe id=\"photolog\" name=\"photolog\" src=\"$xmlfile\" style=\"$BASE::iframestyle\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" scrolling=\"no\"></iframe>
";
return $ret;
}