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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
#!/usr/bin/perl -w
# pcd2html module pcd2html_create_html
# Copyright Andreas Tille <tille@debian.org>
# License: GPL
#
# This modul creates HTML files for each image using
# .eng, .deu, .tec and .drf files if available
use pcd2html_uti;
use strict;
my ( $key,
$source,
$dir,
$title,
$textfile,
$num,
$name,
$image,
$next,
$prev,
%keys, # Available keys with directories
%dirs,
%item, # List of items for translations.
# Can be %pcd2html_uti::german or %pcd2html_uti::english
$O, $Q, $E, $WikiPediaLink
) ;
unless ( $ARGV[0] ) { die "Usage: pcd2html_create_html <image_info_file>" ; };
%keys = OpenRules();
$_ = $ARGV[0] ;
/^(\w*)_(\w*)\.\w{3,4}$/ ;
my $pickey = $1 ;
my $picnum = $2 ;
($key, $source) = GetKeyAndSource($pickey, $picnum, $ARGV[0]);
($num, $name, $image, $O, $Q, $E, $WikiPediaLink ) = GetParametersFromRules($pickey, $picnum) ;
if ( ! defined ( $source ) ) {
if ( -f $image ) {
$source = $image ;
} else {
die "Image $image is missing and Photo CD with key $pickey is not inserted." ;
}
}
print " Creating $num$name.html from $source ...\n" ;
%item = GetTranslationItems("eng") ;
CreateFooterString ( $item{"lang"}, "../index".$item{"text"} ) ;
my $html_target = "${num}$item{\"hext\"}";
if ( -f "$html_target" ) {
if ( $picnum =~ /extra/ ) {
my ( $target_time, $extra_time ) ;
$target_time = (stat($html_target))[10];
$extra_time = (stat("${key}_extra"))[10];
if ( $target_time > $extra_time ) {
unless ( open(IMG, ">>$ARGV[0]" ) ) { die "Unable to open $ARGV[0]\n" ; }
print IMG "rules according to this image not changed\n" ;
close IMG ;
system "touch", "$html_target" ;
exit 0;
}
} else {
if ( CheckChanges($html_target, $ARGV[0], $O, $E, $Q) == 0 ) {
system "touch", "$html_target" ;
exit 0;
}
}
}
open(HTML, ">$html_target" ) || die "Unable to open $html_target\n" ;
select (HTML) ;
($title, $textfile) = GetTitle($num, $name, $item{"text"}) ;
($next, $prev) = NextPrev($num) ;
CreateHtml($num, $image, $title, $textfile);
close HTML;
%item = GetTranslationItems("deu") ;
CreateFooterString ( $item{"lang"}, "../index".$item{"text"} ) ;
open(HTML, ">${num}$item{\"hext\"}" ) || die "Unable to open ${num}$item{\"hext\"}\n" ;
select (HTML) ;
%item = GetTranslationItems("deu") ;
($title, $textfile) = GetTitle($num, $name, $item{"text"}) ;
CreateHtml($num, $image, $title, $textfile);
close HTML;
sub CreateHtml {
my ( $num, $image, $title, $textfile, $internal, $cite, $w, $h );
$num = $_[0];
$image = $_[1];
$title = $_[2];
$textfile = $_[3];
if ( $item{"lang"} eq "en" ) {
if ( $image =~ /extra/ ) {
$internal = undef ;
} else {
my $internal_info_key = GetInternalInfoKey() ;
$internal = "\n<!-- $internal_info_key: O=$O, E=$E, Q=$Q -->\n" ;
}
}
MyHtmlStart($title, undef, undef, "../".GetCSS(), $internal ) ;
if ( $image =~ /extra/ ) {
open(RULES, "rules" ) || die "Unable to open rules file\n" ;
while ( <RULES> ) {
unless ( /[ \t]*#/ ) {
if ( /extra/ ) {
chomp ;
s/(\w*):extra\s*([\w\.]*)\s*.*/$1_extra$2/ ;
$image = $_ ;
}
}
}
close RULES ;
}
print "<table width=\"100%\">\n <tr>\n" ;
print " <th class=\"prev\">\n" ;
if ( $prev ) {
# former "<<" / ">>" navigation is replaced by small icons
# print ' <a href="' . $prev . $item{"hext"}. '" class="prev">' . "<<</a>\n" ;
($w, $h) = ImageSize("$prev.jpg");
print ' <a href="' . $prev . $item{"hext"}. '" class="prev">' .
"<img src=\"$prev.jpg\" width=\"$w\" height=\"$h\" alt=\"<<\" /></a>\n" ;
} else {
print IndexLink($item{"index"}, "prev", 1)
}
print " </th>\n" ;
($w, $h) = ImageSize($image);
if ( defined ($w) && defined ($h) ) {
print " <th rowspan=\"2\">\n " ;
if ( $WikiPediaLink ) { print "<a class=\"big\" href=\"http://commons.wikipedia.org/wiki/Image:$WikiPediaLink\">" ; }
print "<img class=\"big\"\n src=\"$image\" width=\"$w\" height=\"$h\"" ;
if ( $title ) {
print " alt=\"$title\"" ;
} else {
print " alt=\"$image\"" ;
}
print "/>" ;
if ( $WikiPediaLink ) { print "</a>" ; }
} else {
print " <th>\n " ;
if ( $WikiPediaLink ) { print "<a class=\"big\" href=\"http://commons.wikipedia.org/wiki/Image:$WikiPediaLink\">" ; }
print "<img class=\"big\"\n src=\"$image\" alt=\"$title\"/>" ;
if ( $WikiPediaLink ) { print "</a>" ; }
}
print "\n </th>\n" ;
print " <th class=\"next\">\n" ;
if ( $next ) {
# former "<<" / ">>" navigation is replaced by small icons
# print ' <a href="' . $next . $item{"hext"}. '" class="next">' . ">></a>\n" ;
## Unfortunately the next icon does not yet exist.
## Calculating this image at this time would require a complete rewrite of pcd2html
#### rewrite in process ...
($w, $h) = ImageSize("$next.jpg", 1);
print ' <a href="' . $next . $item{"hext"}. '" class="next">' . "<img src=\"$next.jpg\"";
print " width=\"$w\" height=\"$h\" alt=\">>\" /></a>\n" ;
} else {
print IndexLink($item{"index"}, "next", 1)
}
print " </th>\n </tr>\n <tr>" ;
print " <th class=\"indexl\">\n" ;
# former "V<br />V" navigation is replaced by index-icons
# print " <a href=\"" . $item{"index"} . "\" class=\"index\">V<br />V</a>\n" ;
print IndexLink($item{"index"}, "index", 1);
print " </th>\n <th class=\"indexr\">\n" ;
print IndexLink($item{"index"}, "index", 0);
print " </th>\n </tr>\n" ;
if ( $textfile ne "none" ) {
print " <tr>\n <th></th>\n <th class=\"description\">" ;
File2HTML( $textfile, 1, $title ) ;
print " </th>\n <th></th>\n </tr>\n" ;
}
# technical information
if ( -f "$num.tec" ) {
print " <tr>\n <th></th>\n <th>\n" ;
print " <table class=\"tectype\">\n" ;
open(TEC, "$num.tec" ) || die "Unable to open rules $num.tex\n" ;
while ( <TEC> ) {
s?([^:]*:)(.*)? <tr><th class=\"tectype\">$1</th><th class=\"tectype\">$2</th></tr>? ;
print ;
}
close TEC ;
print " </table>\n" ;
print " </th>\n <th></th>\n </tr>\n" ;
}
if ( $item{"lang"} eq "de" && -f "$num.drf" ) {
print " <tr>\n <th></th>\n <th class=\"linktype\">\n" ;
print " <a href=\"${num}_drf.html\">Bildkritiken aus de.rec.fotografie</a>\n" ;
print " </th>\n <th></th>\n </tr>\n" ;
}
print "</table>\n" ;
MyHtmlEnd( );
close HTML ;
if ( $item{"lang"} eq "de" && -f "$num.drf" ) {
my ( $print_from, $print_date, $print_any ) ;
open(DRFOUT, ">${num}_drf.html" ) || die "Unable to open ${num}_drf.html: $!\n" ;
select DRFOUT;
$_ = "Bildkritiken aus de.rec.fotografie zu $title" ;
MyHtmlStart($_, undef, undef, "../".GetCSS(), undef ) ;
open (DRFIN, "$num.drf" ) || die "Unable to open $num.drf\n" ;
$print_from = $print_date = undef ;
$print_any = 0;
my $pre = 0;
while ( <DRFIN> ) {
unless ( /^#/ ) {
if ( /From:*\s*(.*)$/ ) {
$print_from = $_ = $1 ;
/(.*)\s*<(.*)>/ ;
if ( defined($2) ) {
$print_from = "<a href=\"mailto:$2\">$1</a>" ;
}
next ;
}
if ( /Date: (.*)/ ) {
$print_date = $1 ;
next ;
}
if ( defined( $print_from ) && defined ( $print_date ) ) {
if ( $print_any ) { print "</p>\n" ; }
print "<p class=\"From\">\n$print_from ($print_date):</p>\n" ;
print "<p class=\"Kritik\">\n" ;
$print_from = $print_date = undef ;
$print_any++ ;
if ( /^\s*$/ ) { next ; }
}
Iso2Html () ;
if ( /^\s*> / ) {
unless ( $pre ) {
print "<cite>\n" ;
$pre = 1 ;
}
} else {
if ( $pre ) {
print "</cite>\n" ;
$pre = 0 ;
}
}
if ( /^\s*$/ ) { print "<br />" ; }
print ;
if ( $pre ) { print "<br />" ; }
}
}
close DRFIN ;
print "</p>\n" ;
MyHtmlEnd( ) ;
close DRFOUT ;
}
}
sub NextPrev {
my ($rulenum, $next, $prev) ;
$_ = $_[0] ;
s/_/:/ ;
$rulenum = $_ ;
open(RULES, "rules" ) || die "Unable to open rules file\n" ;
while ( <RULES> ) {
unless ( /^#/ ) {
if ( /$rulenum/ ) {
while ( <RULES> ) {
unless ( /^#/ ) {
if ( /^([^:]*):(\d*) / ) { $next = "$1_$2" ; }
else {
if ( /^([^:]*):extra / ) {
$next = "$1_extra" ;
} else {
$next = undef ;
}
}
close RULES ;
return ($next, $prev) ;
}
}
return (undef, $prev) ;
}
if ( /^([^:]*):(\d*) / ) { $prev = "$1_$2" ; }
else {
if ( /^([^:]*):extra / ) {
$prev = "$1_extra" ;
} else {
$prev = undef ;
}
}
}
}
close RULES ;
return (undef, undef) ;
}
|