/[PLies]/burst.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations)
Fri May 11 14:17:27 2001 UTC (22 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.15: +34 -22 lines
File MIME type: text/plain
read local template infos.txt, progress bar can be turned off in it.

1 #!/usr/bin/perl
2 #
3 # PLies Copyright 2001 Dobrica Pavlinusic <dpavlin@rot13.org>
4 #
5 # this tool is based on SlideMaker and XLSies tool
6 # split a all.htm into slide*.htm
7 #
8 # For more information please see presentation about this tool on
9 # http://www.rot13.org/~dpavlin/presentations/XLSies_to_PLies/
10 #
11 # Copyright 1999 World Wide Web Consortium,
12 # (Massachusetts Institute of Technology, Institut
13 # National de Recherche en Informatique et en
14 # Automatique, Keio University). All Rights Reserved.
15 # This program is distributed under the W3C's
16 # Intellectual Property License. This program is
17 # distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied
19 # warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See W3C License
21 # http://www.w3.org/Consortium/Legal/ for more details.
22 #
23 #
24 ##############################################################################
25 #
26 # slidemaker credits:
27 #
28 # Stephan Montigaud - stephan@w3.org
29 # created 970601
30 # modified by Pierre Fillault
31 # check the documentation at http://www.w3.org/Talks/YYMMsub/
32 #
33 # modified 19990505 Bert Bos: ALT text of prev/next arrows is now
34 # "prev"/"next" rather than the title of the prev/next slide; looks better
35 # in lynx.
36 #
37 # version: 4.14 - 19990719
38 # $Id: w3cburst.pl,v 1.41 1999/11/02 17:25:50 charles Exp $
39 #
40 #
41 # XLSies credits:
42 #
43 # Sami Lempinen - lempinen@iki.fi
44 # http://www.snowman.sgic.fi/ssl/xslies/
45 #
46 # Text::FastTemplate:
47 # Robert Lehr - bozzio@the-lehrs.com
48
49 use Text::FastTemplate;
50
51 ##############################################################################
52 ## default values of variables
53 ##
54
55 ## show debug output
56 my $debug=0;
57
58 ## default DOCTYPE added on the slides
59 $doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">';
60
61 ## name of raw HTML file containing the slides
62 $all = 'all.htm';
63
64 ## table of content built from all.htm - also first page of the presentation
65 ## this is only the basename as we need to generate one toc for each style sheets
66 ## the main toc will not bear any more so the server can understand a request for '/'
67 ## the next ones will bear a number corresponding to the slide index
68 #$overview = 'Overview';
69 $overview = 'index';
70
71 ## name of the file containing the parameters of the presentation
72 $infos = 'infos.txt';
73
74 ## link to the logo printed on all the slides
75 $logoLink = '';
76
77 ## default location of the logo - works when slidemaker is used as a package
78 $logoFile = '';
79
80 ### localization
81 $loc_toc = "Table of contents";
82 $loc_by = "by";
83 $loc_amp = "&amp;"; # author separator
84 $loc_slide = "Slide";
85 $loc_of = "of"; # $loc_slide nr $loc_of total
86
87 ## alternate representation of the logo
88 $logoAlt = '';
89
90 ## default values set to none
91 $logoLink2 = ''; # link to a potential second reference
92 $logoFile2 = ''; # location of a second logo
93 $logoAlt2 = ''; # alternate representation of the second logo
94
95 ## default accesskeys for navigation icons used in the slides
96 $prevKey = 'P'; # accesskey for previous slide
97 $nextKey = 'N'; # accesskey for next slide
98 $tocKey = 'C'; # accesskey for table of contents
99 $styleKey = 'S'; # accesskey for changing style sheets
100
101 ## default author name
102 $author = 'Staff';
103
104 ## default presentation title
105 $talkTitle = 'Talk';
106
107 ## standard style sheets
108 $cssStandard = '../PLies/css/default.css';
109
110 ## template name
111 $template = '../PLies/default';
112
113 ## default charset use in meta tag http-equiv (undef to skip)
114 #$charset = 'ISO-8859-1';
115
116 ## default <body> tag
117 $body = '<body>';
118
119 ## number of entries on each TOC page
120 $toc_on_page = 10;
121
122 ## use progress bar
123 $progress_bar = 1;
124
125 ## content hight for each slide
126 $content_hight = "70%";
127
128 ## end of default values for the presentation
129 ##############################################################################
130
131 ## globals
132 my $last_toc_title;
133 my %page_data;
134 my %overview_data;
135
136 my $pack = 0;
137 my @pack_additional; # additional files to pack (pictures, logos...)
138
139 ##############################################################################
140 ## reading user input from $infos
141 ##
142 @PARAM = @ARGV; # we keep this for backward compatibility with an old version
143 # of the slidemaker tool
144 #when the parameters were in Makefile or make.bat
145
146 my @file;
147
148 ##############################################################################
149 sub parse_infos {
150 my @file=@_;
151 do {
152 if ($file[0] && $file[0] =~ /^[^#\n\r]/) {
153 $file[0] =~ s/\n//; # remove UNIX \n
154 $file[0] =~ s/\r//; # remove WINDOWS \r
155 my ($var,$value) = split(/ *= */,$file[0],2);
156 $value=~s/'/\\'/g;
157 $cmd="\$$var = \'$value\';";
158 if (defined($value)) {
159 eval($cmd) || warn "problem with eval of: $cmd";
160 } else {
161 die "no value defined for $var";
162 }
163 print STDERR "$file[0]\n";
164 }
165 } while (shift(@file));
166 }
167 ##############################################################################
168
169 # read parameters from infos.txt and put them in @PARAM
170 if (open(INFOS, $infos)) {
171 print STDERR "--- Reading parameters file $infos ---\n";
172 @file = <INFOS>;
173 parse_infos(@file);
174 }
175
176 # try to read local infos.txt for template
177 if (-f "$template/$infos" && open(INFOS,"$template/$infos")) {
178 print STDERR "--- Reading template parameters file $template/$infos ---\n";
179 @file = <INFOS>;
180 parse_infos(@file);
181 close(INFOS);
182 }
183
184 ## @PARAM is now a table with the user preferences for his presentation
185
186 ## use charset
187
188 if ($charset) {
189 $http_equiv='<meta http-equiv="Content-type" content="text/html; charset='.$charset.'">';
190 } else {
191 $http_equiv='';
192 }
193
194
195 ##############################################################################
196 ## read the raw html presentation
197 ##
198
199 ## copy file in memory
200 my $sep = $/;
201 $/ = undef;
202 open(ALL, $all) || die "Error: Cannot open file: $all";
203 my $buf = <ALL>;
204 $buf =~ s/\r//g; # remove WINDOWS \r
205 close(ALL);
206 $/ = $sep;
207
208 ## Remove comments from the raw presentation
209 ## they do not need to show up on the slides
210 $buf =~ s/<!--.*?-->//sgo;
211
212 ## if $pack is set, output name of css (for inclusion in archive), but
213 ## reset $cssStandard only to filename (without path)
214
215 if ($pack) {
216 push @pack_additional,$cssStandard;
217 $cssStandard =~ s/^.*\/([^\/]+)$/$1/g;
218 }
219
220 ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
221 ## if not it will generate a rather weird output
222 ## split using <h1...> and </h1...> as separator (ignores attributes!)
223 ## h1 or H1 can be used
224 @table = split(/<\/?[hH]1[^>]*>/, $buf);
225
226 ## compute the total number of slides
227 $total = $#table / 2;
228 if ($#table % 2 != 0) {
229 $total = ($#table +1)/2;
230 }
231
232 ##
233 ## raw presentation has been read successfully
234 ##############################################################################
235
236 ##############################################################################
237 ## processing the slides
238
239 print STDERR "\n--- Processing $total slides ---\n";
240
241 ## generate the header table of content of the presentation
242 ## which is also the first page of the talk
243 &openOverview($overview);
244
245 ## start the slide count so we can number them
246 $slideCount = 1;
247
248 ## pre-load template slides using $template dir
249 Text::FastTemplate->defaults(
250 path => [ $template ]
251 );
252
253 Text::FastTemplate->preload( [
254 { file => 'slide.html', key => 'slide' },
255 { file => 'overview.html', key => 'overview' },
256 { file => 'title.html', key => 'title' },
257 ]);
258
259 ## unroll relative anchors (#something) into links with slides
260
261 my %anchor_on_slide;
262
263 ## step 1: record anchors
264 for($i=0; $i<$total; $i++) {
265 my $tmp = $table[($i*2)].$table[($i*2)+1];
266 while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) {
267 $anchor_on_slide{$1}=($i+1);
268 print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug);
269 }
270 }
271
272 ## step 2: fix links
273 for($i=0; $i<$total; $i++) {
274 foreach (keys %anchor_on_slide) {
275 $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi;
276 }
277 }
278
279 ## @table is the array containing each slide with its title
280 ## for each slide to be generated
281 ## we delete each slide and its title when generated
282 ## so that the current slide and its title are always at $table[0] (for the title)
283 ## and $table[1] (for the slide content)
284
285 undef $prev_title;
286 undef $next_title;
287
288 do {
289
290 ## get rid of the first element contained by the raw presentation array
291 shift(@table);
292 ## then $table[0] is the title of the slide to be generated
293 $table[0] =~ s/\n+/ /g; ## replace return character by a white space
294 $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
295 $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
296 $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
297 $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
298 ## $slideTitle preserves link(s) in the title
299 $slideTitle = $table[0];
300 ## need to check if the title contains any anchor
301 ## if so it needs to be removed
302 ## because the title is being used in the table of content to link to the corresponding slide
303 $table[0] = remove_anchor($table[0]);
304
305 ## grab next slide title $table[2] (if there's a next slide)
306 ## to be able to use in the 'next' navigation button
307 ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
308 if ($table[2]) {
309 $next_title= remove_anchor($table[2]);
310 }
311
312 ## the current slide content is stored $table[1]
313 ## there is an attempt to make sure it's clean HTML
314 ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
315 ## to make use of the validation service
316 $slideContent = &clean_html($table[1]) ;
317
318 ## extract slide Sub Title <h2>
319 undef $slideSubTitle;
320 if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) {
321 $slideSubTitle=remove_anchor($1);
322 }
323
324 ## add the title of the current slide to the table of content
325 &addTitle($slideTitle,$slideSubTitle,$slideCount);
326
327 ## generate the current slide
328 ## parameters are:
329 ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
330 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
331
332 ## save the title of the previous slide to be displayed in the 'previous' navigation button
333 $prev_title=remove_anchor($table[0]);
334 }
335 ## process the next slide
336 while (shift(@table));
337
338 ## close the table of content
339 &closeOverview;
340
341 ## generate more toc with the all the style sheets
342 ## as there's no way of loading a style sheet
343 ## except dynamically, but that would be slow
344 ## and would not work on all platforms (ie would fail on Joe's laptop)
345 &generateTOC;
346
347 ## print additional files to pack
348 print STDOUT join("\n",@pack_additional) if ($pack);
349
350 print STDERR "--- Finished ---\n";
351 exit 0;
352 ##
353 ## end of the slidemaker main program
354 ##############################################################################
355
356
357 ##############################################################################
358 ## generate the header of the table of content
359
360 sub openOverview
361 {
362 ## open the file to write to
363 open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
364 push @pack_additional,"$_[0].html" if ($pack);
365
366 ## the style sheet used in the table of content is
367 $stylelink = "";
368 ## here is the standard style sheet
369 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
370
371 %overview_data = (
372 doctype => $doctype,
373 title => $title,
374 http_equiv => $http_equiv,
375 stylelink => $stylelink,
376 body => $body,
377
378 logoLink => $logoLink,
379 logoFile => $logoFile,
380 logoAlt => $logoAlt,
381 logoLink2 => $logoLink2,
382 logoFile2 => $logoFile2,
383 logoAlt2 => $logoAlt2,
384
385 talkTitle => $talkTitle,
386 talkSubTitle => $talkSubTitle,
387
388 content_hight => $content_hight,
389
390 author => $author,
391 authorUrl => $authorUrl,
392 author2 => $author2,
393 authorUrl2 => $authorUrl2,
394
395 date => $date,
396
397 toc_title => $loc_toc,
398 template => $template,
399 );
400
401 }
402 ##
403 ## the beginning of the table of content has been generated and saved
404 ##############################################################################
405
406 ##############################################################################
407 ## generate the footer of the table of content
408
409 sub closeOverview
410 {
411 $overview_data{slide_html} = make_progress_bar(0,$total);
412 $overview_data{toc_entries} = [ @toc_entries ];
413
414 my $page= new Text::FastTemplate key => 'overview';
415 print FOO $page->output( \%overview_data );
416
417 close(FOO);
418 }
419 ##
420 ## the toc has been completed and saved
421 ##############################################################################
422
423 ##############################################################################
424 ## add an item in the toc
425
426 sub addTitle
427 {
428 my ($title,$subtitle,$nr) = @_;
429 $title =~ s/\r//ig; # remove the windows CR+LF
430 $title =~ s/<[^>]+>//g;
431
432 if (! $title) {
433 return 1;
434 }
435
436 # split TOC entries to multiple pages
437
438 if ($nr % $toc_on_page == 0) {
439 my $toc_nr=int($nr/$toc_on_page);
440
441 $item = {
442 pre_html => $pre_ul,
443 accesskey => " ", # space
444 href => "index-toc$toc_nr.html",
445 title => "...",
446 post_html => $post_ul,
447 more => 1, # use style for more pages link (...)
448 };
449 push @toc_entries, $item;
450
451 &closeOverview;
452 undef @toc_entries;
453 &openOverview("$overview-toc$toc_nr");
454 $last_toc_title='';
455 }
456
457 $pre_ul=$post_ul='';
458 if ($last_toc_title eq $title && $subtitle) {
459 $title = $subtitle;
460 $pre_ul='<ul>';
461 $post_ul='</ul>';
462 } else {
463 $last_toc_title=$title;
464 }
465
466 # add accesskey for first 9 slides (`1' - `9') or just for first
467 # TOC page, and tabindex for all slides
468 if ($nr < 10 && $nr < $toc_on_page) {
469 $item = {
470 pre_html => $pre_ul,
471 accesskey => "$nr",
472 tabindex => "$nr",
473 href => "slide$nr.html",
474 title => $title,
475 post_html => $post_ul,
476 more => 0,
477 };
478 push @toc_entries,$item;
479 } else {
480 $item = {
481 pre_html => $pre_ul,
482 tabindex => "$nr",
483 href => "slide$nr.html",
484 title => $title,
485 post_html => $post_ul,
486 };
487 push @toc_entries,$item;
488 }
489 }
490 ##
491 ##############################################################################
492
493 ##############################################################################
494 ## generate the current slide
495
496 sub createSlide
497 {
498
499 # parameters are respectively the slide title, its content,
500 # its number, the next slide title and the previous slide title
501
502 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
503
504 if (! $title) {
505 return 1;
506 }
507
508 # work the slide title, the previous and next titles
509 chomp $title;
510 $title =~ s/\r//ig; # remove the windows CR+LF
511 $next_title =~ s/\r//ig;
512 $prev_title =~ s/\r//ig;
513
514 # Remove any tags from the prev & next titles
515 $next_title =~ s/<[^>]+>//g;
516 $prev_title =~ s/<[^>]+>//g;
517 $title =~ s/<[^>]+>//g;
518
519 # Replace double quotes
520 # $title =~ s/"/&#34;/g;
521 $next_title =~ s/"/&#34;/g;
522 $prev_title =~ s/"/&#34;/g;
523
524 # work the slide content
525 $content =~ s/<\/body>//i; # remove if any
526 $content =~ s/<\/html>//i; # remove if any
527
528 $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
529 $status =~ s/<[^>]+>//g;
530 print STDERR $status;
531
532 &verify_html($content); # check the html
533
534 ## write to the slide
535 open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
536 push @pack_additional,"slide$nr.html" if ($pack);
537
538 my $toc_link = "$overview\.html";
539
540 ## initialization of the navigation links
541 my $next_link = "";
542 my $prev_link = "";
543
544 if ($nr>1) {
545 $prev_link = "slide".($nr-1).".html";
546 # } else {
547 # ## add a link back to the toc for the first slide --CMN 19991102
548 # $prev_link = "$overview\.html";
549 }
550
551 if ($nr != $total) {
552 $next_link = "slide".($nr+1).".html";
553 }
554
555 $stylelink = "";
556 # here is the standard style sheet
557 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
558
559 my $slide_html=make_progress_bar($nr,$total);
560
561 # undefine body if no content is found (so that template can show
562 # only title and sub-title
563 if ($content !~ m/\S/g) {
564 undef $content;
565 }
566
567 %page_data = (
568 doctype => $doctype,
569 talkTitle => $talkTitle,
570 title => $title,
571 subtitle => $subtitle,
572 http_equiv => $http_equiv,
573 stylelink => $stylelink,
574 body => $body,
575
576 logoLink => $logoLink,
577 logoFile => $logoFile,
578 logoAlt => $logoAlt,
579 logoLink2 => $logoLink2,
580 logoFile2 => $logoFile2,
581 logoAlt2 => $logoAlt2,
582
583
584 content_hight => $content_hight,
585 content => $content,
586
587 prev_link => $prev_link,
588 toc_link => $toc_link,
589 next_link => $next_link,
590 prev_title => $prev_title,
591 toc_title => $loc_toc,
592 next_title => $next_title,
593
594 author => $author,
595 authorUrl => $authorUrl,
596 author2 => $author2,
597 authorUrl2 => $authorUrl2,
598
599 date => $date,
600
601 slide_html => $slide_html,
602
603 template => $template,
604 );
605
606 my $page;
607 if ($content) {
608 $page= new Text::FastTemplate key => 'slide';
609 } else {
610 $page= new Text::FastTemplate key => 'title';
611 }
612 print SLIDE $page->output( \%page_data );
613 extract_files($page->output( \%page_data )) if ($pack);
614 close(SLIDE);
615 return 0;
616 }
617
618 ##############################################################################
619 ## generate all the toc of contents needed for each css choosen by the user
620 ## the default toc is not numbered so it can be served by a request to '/'
621 ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
622
623 sub generateTOC {
624
625 ## read the general toc
626 open(FOO, "<$overview.html");
627 @TOC = <FOO>;
628 close(FOO);
629 $toc = "@TOC";
630
631 ## for each user CSS file
632 ## starting after the default css
633 for ($css=1;$css<$nbCssStandard;$css++) {
634
635 ## create new TOC
636 $newTOC = $toc;
637
638 ## the links on the toc need also to be modified
639 ## to link to the correct slides
640 $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
641 $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
642
643 ## write to new TOC
644 $outfile = $overview."-".$css.".html";
645 open(OUT, ">$outfile");
646 print OUT $newTOC;
647 close(OUT)
648 }
649
650
651 }
652
653 ##############################################################################
654 # check that the html of the slide
655 # is correct (ALT tags, ...)
656 # This procedure produces only warning
657 sub verify_html {
658
659 if ($_[0] =~ /<img([^>]*)>/im) {
660 if (!($1 =~ /ALT=/im)) {
661 print STDERR "WARNING: <IMG> without ALT\n";
662 print STDERR " <IMG$1>\n" ;
663 }
664 }
665 }
666
667 ##############################################################################
668 # clean the html of the slide
669 # remove all <div class="comment">blabla</div>
670 sub clean_html {
671 my $tmp=$_[0];
672 $tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
673 $tmp =~ s,</*font[^>]+>,,ig;
674 return $tmp;
675 }
676
677 ##############################################################################
678 # make transparent 1x1 gif (for layout tricks)
679 sub make_dotgif {
680 @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
681 249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
682 open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
683 my $dotgif;
684 foreach (@dot_gif) {
685 $dotgif.=chr($_);
686 }
687 print GIF $dotgif;
688 close(GIF);
689 }
690
691 ##############################################################################
692 # make slide progress bar
693 sub make_progress_bar {
694 my ($nr,$total) = @_;
695
696 my $pcnt_done=int($nr*100/$total);
697 my $pcnt_left=100-$pcnt_done;
698
699 if ($progress_bar && uc($progress_bar) ne "NO") {
700 my $l=$r="&nbsp;";
701 my $t="$nr of $total";
702 if ($pcnt_done > 50) {
703 $l=$t;
704 } else {
705 $r=$t;
706 }
707 $html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr>';
708 if ($pcnt_done != 0) {
709 $html.='<td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td>';
710 }
711 if ($pcnt_left != 0) {
712 $html.='<td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td>';
713 }
714 $html.='</tr></table>';
715 } else {
716 $html="$loc_slide $nr $loc_of $total";
717 }
718
719 return $html;
720 }
721
722 ##############################################################################
723 # remove anchors <a href...> from html (for titles)
724 sub remove_anchor {
725 my $tmp = $_[0];
726 $tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
727 return $tmp;
728 }
729
730 ##############################################################################
731 # extract files referenced in presentation
732
733 sub extract_files {
734 my $tmp = $_[0];
735 while ($tmp =~ s/<a\s+href="*([^"\s]+)"*//ism ||
736 $tmp =~ s/<img\s+src="*([^"\s]+)"*//ism) {
737 if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) {
738 push @pack_additional,$1;
739 }
740 }
741 }

  ViewVC Help
Powered by ViewVC 1.1.26