/[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

Annotation of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat May 5 03:31:31 2001 UTC (18 years, 4 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +115 -164 lines
File MIME type: text/plain
separated presentation from code using Text::FastTemplate

1 dpavlin 1.5 #!/usr/bin/perl
2 dpavlin 1.1 #
3     # SLies 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 dpavlin 1.5 #
46     # Text::FastTemplate:
47     # Robert Lehr - bozzio@the-lehrs.com
48    
49     use Text::FastTemplate;
50 dpavlin 1.1
51     ##############################################################################
52     ## default values of variables
53     ##
54    
55     ## default DOCTYPE added on the slides
56     $doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">';
57    
58     ## name of raw HTML file containing the slides
59     $all = 'all.htm';
60    
61     ## table of content built from all.htm - also first page of the presentation
62     ## this is only the basename as we need to generate one toc for each style sheets
63     ## the main toc will not bear any more so the server can understand a request for '/'
64     ## the next ones will bear a number corresponding to the slide index
65     #$overview = 'Overview';
66     $overview = 'index';
67    
68     ## name of the file containing the parameters of the presentation
69     $infos = 'infos.txt';
70    
71     ## link to the logo printed on all the slides
72     $logoLink = '';
73    
74     ## default location of the logo - works when slidemaker is used as a package
75     $logoFile = '';
76    
77     ### localization
78     $loc_toc = "Table of contents";
79     $loc_by = "by";
80     $loc_amp = "&amp;"; # author separator
81     $loc_slide = "Slide";
82     $loc_of = "of"; # $loc_slide nr $loc_of total
83    
84     ## alternate representation of the logo
85     $logoAlt = '';
86    
87     ## default values set to none
88     $logoLink2 = ''; # link to a potential second reference
89     $logoFile2 = ''; # location of a second logo
90     $logoAlt2 = ''; # alternate representation of the second logo
91    
92     ## default accesskeys for navigation icons used in the slides
93     $prevKey = 'P'; # accesskey for previous slide
94     $nextKey = 'N'; # accesskey for next slide
95     $tocKey = 'C'; # accesskey for table of contents
96     $styleKey = 'S'; # accesskey for changing style sheets
97    
98     ## default author name
99     $author = 'Staff';
100    
101     ## default presentation title
102     $talkTitle = 'Talk';
103    
104     ## standard style sheets
105     $cssStandard = '../PLies/css/default.css';
106    
107 dpavlin 1.5 ## template name
108     $template = '../PLies/default';
109    
110 dpavlin 1.1 ## default charset use in meta tag http-equiv (undef to skip)
111     #$charset = 'ISO-8859-1';
112    
113     ## default <body> tag
114     $body = '<body>';
115    
116     ## number of entries on each TOC page
117     $toc_on_page = 10;
118    
119     ## use progress bar
120     $progress_bar = 1;
121    
122 dpavlin 1.2 ## content hight for each slide
123     $content_hight = "70%";
124    
125 dpavlin 1.1 ## end of default values for the presentation
126     ##############################################################################
127    
128     ## globals
129     my $logo_html;
130     my $date_html;
131     my $last_toc_title;
132 dpavlin 1.5 my %page_data;
133     my %overview_data;
134 dpavlin 1.1
135     ##############################################################################
136     ## reading user input from $infos
137     ##
138     @PARAM = @ARGV; # we keep this for backward compatibility with an old version
139     # of the slidemaker tool
140     #when the parameters were in Makefile or make.bat
141    
142     # read parameters from infos.txt and put them in @PARAM
143     if (open(INFOS, $infos)) {
144     print STDOUT "--- Reading parameters file $infos ---\n";
145     local(@file,$counter);
146     $counter = 0;
147     @file = <INFOS>;
148     @PARAM = ();
149     do {
150     if ($file[0] && $file[0] =~ /^[^#\n\r]/) {
151     $file[0] =~ s/\n//; # remove UNIX \n
152     $file[0] =~ s/\r//; # remove WINDOWS \r
153     $file[0] =~ s/ *= */=/;
154     $PARAM[$counter++] = $file[0];
155     print "$file[0]\n";
156     }
157     } while (shift(@file));
158     }
159     ## @PARAM is now a table with the user preferences for his presentation
160    
161     ## process arguments
162     ## each preset variable is now re-attributed using the user preferences
163     foreach (@PARAM) {
164 dpavlin 1.5 my ($var,$value) = split(/ *= */,$_,2);
165     $value=~s/'/\\'/g;
166     $cmd="\$$var = \'$value\';";
167     if ($value) {
168     eval($cmd) || die "problem with eval of: $cmd";
169     } else {
170     die "no value defined for $var";
171     }
172 dpavlin 1.1 }
173    
174     ## use charset
175    
176     if ($charset) {
177     $http_equiv='<meta http-equiv="Content-type" content="text/html; charset='.$charset.'">';
178     } else {
179     $http_equiv='';
180     }
181    
182     ##############################################################################
183     ## read the raw html presentation
184     ##
185    
186     ## copy file in memory
187     my $sep = $/;
188     $/ = undef;
189     if (!open(ALL, $all)) {
190     print "Error: Cannot open file: $all\n";
191     exit 0;
192     }
193     my $buf = <ALL>;
194     close(ALL);
195     $/ = $sep;
196    
197     ## Remove comments from the raw presentation
198     ## they do not need to show up on the slides
199     $buf =~ s/<!--.*?-->//sgo;
200    
201     ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
202     ## if not it will generate a rather weird output
203     ## split using <h1...> and </h1...> as separator (ignores attributes!)
204     ## h1 or H1 can be used
205     @table = split(/<\/?[hH]1[^>]*>/, $buf);
206    
207     ## compute the total number of slides
208     $total = $#table / 2;
209     if ($#table % 2 != 0) {
210     $total = ($#table +1)/2;
211     }
212    
213     ##
214     ## raw presentation has been read successfully
215     ##############################################################################
216    
217     ##############################################################################
218     ## processing the slides
219    
220     print STDOUT "\n--- Processing $total slides ---\n";
221    
222     ## generate the header table of content of the presentation
223     ## which is also the first page of the talk
224     &openOverview($overview);
225    
226     ## start the slide count so we can number them
227     $slideCount = 1;
228    
229 dpavlin 1.5 ## pre-load template slides using $template dir
230     Text::FastTemplate->defaults(
231     path => [ $template ]
232     );
233    
234     Text::FastTemplate->preload( [
235     { file => 'slide.html', key => 'slide' },
236     { file => 'overview.html', key => 'overview' },
237     ]);
238 dpavlin 1.1
239     ## @table is the array containing each slide with its title
240     ## for each slide to be generated
241     ## we delete each slide and its title when generated
242     ## so that the current slide and its title are always at $table[0] (for the title)
243     ## and $table[1] (for the slide content)
244     do {
245    
246     ## get rid of the first element contained by the raw presentation array
247     shift(@table);
248     ## then $table[0] is the title of the slide to be generated
249     $table[0] =~ s/\n+/ /g; ## replace return character by a white space
250     $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
251     $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
252     $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
253     $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
254     ## $slideTitle preserves link(s) in the title
255     $slideTitle = $table[0];
256     ## need to check if the title contains any anchor
257     ## if so it needs to be removed
258     ## because the title is being used in the table of content to link to the corresponding slide
259     $table[0] =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;
260    
261     ## grab next slide title $table[2] (if there's a next slide)
262     ## to be able to use in the 'next' navigation button
263     ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
264     $next_slide_title = $table[2] if $table[2];
265     ## remove any anchor from the next slide title
266     $next_slide_title =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;
267    
268     ## the current slide content is stored $table[1]
269     ## there is an attempt to make sure it's clean HTML
270     ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
271     ## to make use of the validation service
272     $slideContent = &clean_html($table[1]) ;
273    
274     ## extract slide Sub Title <h2>
275     undef $slideSubTitle;
276     if ($slideContent =~ s/<[hH]2[^>]*>([^<]+)<\/[hH]2[^>]*>//) {
277     $slideSubTitle=$1;
278     }
279    
280     ## add the title of the current slide to the table of content
281     &addTitle($slideTitle,$slideSubTitle,$slideCount);
282    
283     ## generate the current slide
284     ## parameters are:
285     ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
286     &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$previous_slide_title,$next_slide_title);
287    
288     ## save the title of the previous slide to be displayed in the 'previous' navigation button
289     $previous_slide_title="$table[0]";
290     }
291     ## process the next slide
292     while (shift(@table));
293    
294     ## close the table of content
295     &closeOverview;
296    
297     ## generate more toc with the all the style sheets
298     ## as there's no way of loading a style sheet
299     ## except dynamically, but that would be slow
300     ## and would not work on all platforms (ie would fail on Joe's laptop)
301     &generateTOC;
302    
303    
304     print STDOUT "--- Finished ---\n";
305     exit 0;
306     ##
307     ## end of the slidemaker main program
308     ##############################################################################
309    
310    
311     ##############################################################################
312     ## generate the header of the table of content
313    
314     sub openOverview
315     {
316     ## open the file to write to
317     open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
318    
319     ## the style sheet used in the table of content is
320     $stylelink = "";
321     ## here is the standard style sheet
322     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
323    
324 dpavlin 1.5 %overview_data = (
325     doctype => $doctype,
326     title => $title,
327     http_equiv => $http_equiv,
328     stylelink => $stylelink,
329     body => $body,
330    
331     logoLink => $logoLink,
332     logoFile => $logoFile,
333     logoAlt => $logoAlt,
334    
335     talkTitle => $talkTitle,
336     talkSubTitle => $talkSubTitle,
337    
338     content_hight => $content_hight,
339    
340     author => $author,
341     authorUrl => $authorUrl,
342     author2 => $author2,
343     authorUrl2 => $authorUrl2,
344 dpavlin 1.1
345 dpavlin 1.5 date => $date,
346 dpavlin 1.1
347 dpavlin 1.5 toc => $loc_toc,
348     );
349 dpavlin 1.1
350     }
351     ##
352     ## the beginning of the table of content has been generated and saved
353     ##############################################################################
354    
355     ##############################################################################
356     ## generate the footer of the table of content
357    
358     sub closeOverview
359     {
360 dpavlin 1.5 $overview_data{slide_html} = make_progress_bar(0,$total);
361     $overview_data{toc_entries} = [ @toc_entries ];
362    
363     print "---",$#toc_entries;
364     use Data::Dumper;
365     print Dumper([ @toc_entries ]);
366    
367     my $page= new Text::FastTemplate key => 'overview';
368     print FOO $page->output( \%overview_data );
369 dpavlin 1.1
370     close(FOO);
371     }
372     ##
373     ## the toc has been completed and saved
374     ##############################################################################
375    
376     ##############################################################################
377     ## add an item in the toc
378    
379     sub addTitle
380     {
381     my ($title,$subtitle,$nr) = @_;
382     $title =~ s/\r//ig; # remove the windows CR+LF
383     $title =~ s/<[^>]+>//g;
384    
385     if (! $title) {
386     return 1;
387     }
388    
389     # split TOC entries to multiple pages
390    
391     if ($nr % $toc_on_page == 0) {
392     my $toc_nr=int($nr/$toc_on_page);
393    
394 dpavlin 1.5 %item = (
395     pre_html => $pre_ul,
396     accesskey => " ", # space
397     href => "index-toc$toc_nr.html",
398     title => "...",
399     post_html => $post_ul,
400     more => 1, # use style for more pages link (...)
401     )
402     # push @toc_entries, %item;
403    
404 dpavlin 1.1 &closeOverview;
405     &openOverview("$overview-toc$toc_nr");
406     $last_toc_title='';
407     }
408    
409 dpavlin 1.5 $pre_ul=$post_ul='';
410 dpavlin 1.1 if ($last_toc_title eq $title) {
411     $title = $subtitle;
412 dpavlin 1.5 $pre_ul='<ul>';
413     $post_ul='</ul>';
414 dpavlin 1.1 } else {
415     $last_toc_title=$title;
416     }
417    
418     # add accesskey for first 9 slides (`1' - `9') or just for first
419     # TOC page, and tabindex for all slides
420     if ($nr < 10 && $nr < $toc_on_page) {
421 dpavlin 1.5 $item = {
422     pre_html => $pre_ul,
423     accesskey => "$nr",
424     tabindex => "$nr",
425     href => "slide$nr.html",
426     title => $title,
427     post_html => $post_ul,
428     more => 0,
429     };
430     push @toc_entries,$item;
431 dpavlin 1.1 } else {
432 dpavlin 1.5 %item = (
433     pre_html => $pre_ul,
434     tabindex => "$nr",
435     href => "slide$nr.html",
436     title => $title,
437     post_html => $post_ul,
438     )
439     # push @toc_entries,\%item;
440 dpavlin 1.1 }
441     }
442     ##
443     ##############################################################################
444    
445     ##############################################################################
446     ## generate the current slide
447    
448     sub createSlide
449     {
450    
451     # parameters are respectively the slide title, its content,
452     # its number, the next slide title and the previous slide title
453    
454     my ($title,$subtitle,$content,$nr,$next_title,$prev_title) = @_;
455    
456     if (! $title) {
457     return 1;
458     }
459    
460     # work the slide title, the previous and next titles
461     chomp $title;
462     $title =~ s/\r//ig; # remove the windows CR+LF
463     $next_title =~ s/\r//ig;
464     $prev_title =~ s/\r//ig;
465    
466     # Remove any tags from the prev & next titles
467     $next_title =~ s/<[^>]+>//g;
468     $prev_title =~ s/<[^>]+>//g;
469     $title =~ s/<[^>]+>//g;
470    
471     # Replace double quotes
472     # $title =~ s/"/&#34;/g;
473     $next_title =~ s/"/&#34;/g;
474     $prev_title =~ s/"/&#34;/g;
475    
476     # work the slide content
477     $content =~ s/<\/body>//i; # remove if any
478     $content =~ s/<\/html>//i; # remove if any
479    
480     $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
481     $status =~ s/<[^>]+>//g;
482     print STDOUT $status;
483    
484     &verify_html($content); # check the html
485    
486     ## write to the slide
487     open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
488    
489     my $toclink = "[ <a href=\"$overview\.html\" title=\"Contents\">Contents</a> ]";
490    
491     ## initialization of the navigation links
492     my $nextlink = "";
493     my $prevlink = "";
494    
495     if ($nr>1) {
496     $prevlink = "<a href=\"slide".($nr-1).".html\" title=\"Previous\">&lt;&lt;</a>";
497     # } else {
498     # ## add a link back to the toc for the first slide --CMN 19991102
499     # $prevlink = "<a href=\"$overview\.html\" title=\"Previous\">&lt;&lt;</a>";
500     }
501    
502     if ($nr != $total) {
503     $nextlink = "<a href=\"slide".($nr+1).".html\" title=\"Next\">&gt;&gt;</a>";
504     }
505    
506     $stylelink = "";
507     # here is the standard style sheet
508     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
509    
510     $title_html="<h1>$title</h1>";
511     if ($subtitle) {
512     $title_html.="<h2>$subtitle</h2>";
513     }
514    
515     my $slide_html=make_progress_bar($nr,$total);
516    
517 dpavlin 1.5 %page_data = (
518     doctype => $doctype,
519     talkTitle => $talkTitle,
520     title => $title,
521     http_equiv => $http_equiv,
522     stylelink => $stylelink,
523     body => $body,
524    
525     logo_html => $logo_html,
526     title_html => $title_html,
527     content_hight => $content_hight,
528     content => $content,
529     author => $author,
530     date_html => $date_html,
531     prevlink => $prevlink,
532     toclink => $toclink,
533     nextlink => $nextlink,
534     slide_html => $slide_html,
535     author2 => $author2
536    
537     );
538    
539     my $page= new Text::FastTemplate key => 'slide';
540     print SLIDE $page->output( \%page_data );
541 dpavlin 1.1
542     close(SLIDE);
543     return 0;
544     }
545    
546     ##############################################################################
547     ## generate all the toc of contents needed for each css choosen by the user
548     ## the default toc is not numbered so it can be served by a request to '/'
549     ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
550    
551     sub generateTOC {
552    
553     ## read the general toc
554     open(FOO, "<$overview.html");
555     @TOC = <FOO>;
556     close(FOO);
557     $toc = "@TOC";
558    
559     ## for each user CSS file
560     ## starting after the default css
561     for ($css=1;$css<$nbCssStandard;$css++) {
562    
563     ## create new TOC
564     $newTOC = $toc;
565    
566     ## the links on the toc need also to be modified
567     ## to link to the correct slides
568     $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
569     $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
570    
571     ## write to new TOC
572     $outfile = $overview."-".$css.".html";
573     open(OUT, ">$outfile");
574     print OUT $newTOC;
575     close(OUT)
576     }
577    
578    
579     }
580    
581     ##############################################################################
582     # check that the html of the slide
583     # is correct (ALT tags, ...)
584     # This procedure produces only warning
585     sub verify_html {
586    
587     if ($_[0] =~ /<img([^>]*)>/im) {
588     if (!($1 =~ /ALT=/im)) {
589     print STDOUT "WARNING: <IMG> without ALT\n";
590     print STDOUT " <IMG$1>\n" ;
591     }
592     }
593     }
594    
595     ##############################################################################
596     # clean the html of the slide
597     # remove all <div class="comment">blabla</div>
598     sub clean_html {
599     $_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
600     return $_[0];
601     }
602    
603     ##############################################################################
604     # make transparent 1x1 gif (for layout tricks)
605     sub make_dotgif {
606     @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
607     249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
608     open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
609     my $dotgif;
610     foreach (@dot_gif) {
611     $dotgif.=chr($_);
612     }
613     print GIF $dotgif;
614     close(GIF);
615     }
616    
617     ##############################################################################
618     # make slide progress bar
619     sub make_progress_bar {
620     my ($nr,$total) = @_;
621    
622     my $pcnt_done=int($nr*100/$total);
623     my $pcnt_left=100-$pcnt_done;
624    
625     if ($progress_bar) {
626     my $l=$r="&nbsp;";
627     my $t="$nr of $total";
628     if ($pcnt_done > 50) {
629     $l=$t;
630     } else {
631     $r=$t;
632     }
633 dpavlin 1.4 $html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr><td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td><td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td></tr></table>';
634 dpavlin 1.1 } else {
635     $html="$loc_slide $nr $loc_of $total";
636     }
637    
638     return $html;
639     }
640    

  ViewVC Help
Powered by ViewVC 1.1.26