(file) Return to SlideShowPlugin.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki / Plugins

  1 rizwank 1.1 # Plugin for TWiki Collaboration Platform, http://TWiki.org/
  2             #
  3             # Copyright (C) 2002-2004 Peter Thoeny, peter@thoeny.com
  4             #
  5             # This program is free software; you can redistribute it and/or
  6             # modify it under the terms of the GNU General Public License
  7             # as published by the Free Software Foundation; either version 2
  8             # of the License, or (at your option) any later version.
  9             #
 10             # This program is distributed in the hope that it will be useful,
 11             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 12             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13             # GNU General Public License for more details, published at
 14             # http://www.gnu.org/copyleft/gpl.html
 15             #
 16             # =========================
 17             #
 18             # Each plugin is a package that contains the subs:
 19             #
 20             #   initPlugin           ( $topic, $web, $user, $installWeb )
 21             #   commonTagsHandler    ( $text, $topic, $web )
 22 rizwank 1.1 #   startRenderingHandler( $text, $web )
 23             #   outsidePREHandler    ( $text )
 24             #   insidePREHandler     ( $text )
 25             #   endRenderingHandler  ( $text )
 26             #   beforeSaveHandler    ( $text, $topic, $web )
 27             #
 28             # initPlugin is required, all other are optional.
 29             # For increased performance, all handlers except initPlugin are
 30             # disabled. To enable a handler remove the leading DISABLE_ from
 31             # the function name.
 32             #
 33             # NOTE: To interact with TWiki use the official TWiki functions
 34             # in the &TWiki::Func module. Do not reference any functions or
 35             # variables elsewhere in TWiki!!
 36             
 37             
 38             # =========================
 39             package TWiki::Plugins::SlideShowPlugin;
 40             
 41             # =========================
 42             use vars qw(
 43 rizwank 1.1         $web $topic $user $installWeb $VERSION $debug
 44                 );
 45             
 46             $VERSION = '1.003';
 47             
 48             # =========================
 49             sub initPlugin
 50             {
 51                 ( $topic, $web, $user, $installWeb ) = @_;
 52             
 53                 # check for Plugins.pm versions
 54                 if( $TWiki::Plugins::VERSION < 1 ) {
 55                     &TWiki::Func::writeWarning( "Version mismatch between SlideShowPlugin and Plugins.pm" );
 56                     return 0;
 57                 }
 58             
 59                 # Get plugin debug flag
 60                 $debug = &TWiki::Func::getPreferencesFlag( "SLIDESHOWPLUGIN_DEBUG" );
 61             
 62                 # Plugin correctly initialized
 63                 TWiki::Func::writeDebug( "- TWiki::Plugins::SlideShowPlugin::initPlugin( $web.$topic ) is OK" ) if $debug;
 64 rizwank 1.1     return 1;
 65             }
 66             
 67             # =========================
 68             sub commonTagsHandler
 69             {
 70             ### my ( $text, $topic, $web ) = @_;   # do not uncomment, use $_[0], $_[1]... instead
 71             
 72                 TWiki::Func::writeDebug( "- SlideShowPlugin::commonTagsHandler( $_[2].$_[1] )" ) if $debug;
 73             
 74                 # This is the place to define customized tags and variables
 75                 # Called by sub handleCommonTags, after %INCLUDE:"..."%
 76             
 77                 if( $_[0] =~ /%SLIDESHOWSTART/ ) {
 78                     $_[0] = slideShowHandler( $_[0], $_[2], $_[1] );
 79                 }
 80             }
 81             
 82             # =========================
 83             sub slideShowHandler
 84             {
 85 rizwank 1.1     my( $text, $theWeb, $theTopic ) = @_;
 86             
 87                 my $textPre = "";
 88                 my $textPost = "";
 89                 my $args = "";
 90                 if( $text =~ /^(.*)%SLIDESHOWSTART%(.*)$/s ) {
 91                     $textPre = $1;
 92                     $text = $2;
 93                 } elsif( $text =~ /^(.*)%SLIDESHOWSTART{(.*?)}%(.*)$/s ) {
 94                     $textPre = $1;
 95                     $args = $2;
 96                     $text = $3;
 97                 }
 98                 if( $text =~ /^(.*)%SLIDESHOWEND%(.*)$/s ) {
 99                     $text = $1;
100                     $textPost = $2;
101                 }
102             
103                 $query = TWiki::Func::getCgiQuery();
104                 if( $query && $query->param( 'slideshow' ) ) {
105                     # in presentation mode
106 rizwank 1.1 
107                     $textPre .= "\n#StartPresentation\n";
108                     $textPre .= renderSlideNav( $theWeb, $theTopic, 1, 1, "e" );
109             
110                     my $slideMax = 0;
111             
112                     if( $text =~ /(.*?[\n\r])\-\-\-+(\++)\!* (.*)/s ) {
113                         $textPre .= $1;
114                         $text = $3;
115                         my $level = $2;
116                         $level =~ s/\+/\\\+/go;
117                         my @slides = split( /[\n\r]\-\-\-+$level\!* /, $text );
118                         $text = "";
119             
120                         my $hideComments = TWiki::Prefs::getPreferencesValue( "SLIDESHOWPLUGIN_HIDECOMMENTS" ) || "";
121             
122                         my $tmplText = readTmplText( $theWeb, $args );
123                         my $slideText = "";
124                         my $slideTitle = "";
125                         my $slideBody = "";
126                         my $slideComment = "";
127 rizwank 1.1             my $slideNum = 1;
128                         $slideMax = @slides;
129                         my @titles = ();
130                         foreach( @slides ) {
131                             /^([^\n\r]*)(.*)$/s;
132                             $slideTitle = $1 || "";
133                             $slideBody  = $2 || "";
134                             $slideComment = "";
135                             if( $hideComments && $slideBody =~ s/(\-\-\-+\+$level+\!*\s*Comments.*)//is ) {
136                                 $slideComment = $1;
137                             }
138                             push( @titles, $slideTitle );
139                             $slideText = $tmplText;
140                             $slideText =~ s/%SLIDETITLE%/$slideTitle/go;
141                             $slideText =~ s/%SLIDETEXT%/$slideBody/go;
142                             $slideText =~ s/%SLIDENUM%/$slideNum/go;
143                             $slideText =~ s/%SLIDEMAX%/$slideMax/go;
144                             $slideText =~ s/%SLIDENAV%/renderSlideNav(      $theWeb, $theTopic, $slideNum, $slideMax, "f p n" )/geo;
145                             $slideText =~ s/%SLIDENAVALL%/renderSlideNav(   $theWeb, $theTopic, $slideNum, $slideMax, "f p n l" )/geo;
146                             $slideText =~ s/%SLIDENAVFIRST%/renderSlideNav( $theWeb, $theTopic, $slideNum, $slideMax, "f" )/geo;
147                             $slideText =~ s/%SLIDENAVPREV%/renderSlideNav(  $theWeb, $theTopic, $slideNum, $slideMax, "p" )/geo;
148 rizwank 1.1                 $slideText =~ s/%SLIDENAVNEXT%/renderSlideNav(  $theWeb, $theTopic, $slideNum, $slideMax, "n" )/geo;
149                             $slideText =~ s/%SLIDENAVLAST%/renderSlideNav(  $theWeb, $theTopic, $slideNum, $slideMax, "l" )/geo;
150                             $text .= "\n\n-----\n#GoSlide$slideNum\n$slideText";
151                             $text .= "\n$slideComment\n\n" if( $slideComment );
152                             $text .= "%BR%\n\n" x 20;
153                             $slideNum++;
154                         }
155                         $text =~ s/%TOC(?:\{.*?\})*%/renderSlideToc( $theWeb, $theTopic, @titles )/geo;
156                         $text .= "\n#GoSlide$slideNum\n%BR%\n";
157                     }
158             
159                     $text = "$textPre\n$text\n";
160                     $text .= renderSlideNav( $theWeb, $theTopic, $slideMax + 1, $slideMax, "f p e" );
161                     $text .= "\n";
162                     $text .= "%BR%\n\n" x 30;
163                     $text =~ s/%BR%/<br \/>/go;
164                     $text .= $textPost;
165             
166                 } else {
167                     # in normal topic view mode
168             
169 rizwank 1.1         if( $text =~ /[\n\r]\-\-\-+(\++)/s ) {
170                         my $level = $1;
171                         $level =~ s/\+/\\\+/go;
172                         # add slide number to heading
173                         my $slideNum = 1;
174                         $text =~ s/([\n\r]\-\-\-+$level\!*) ([^\n\r]+)/"$1 Slide " . $slideNum++ . ": $2"/ges;
175                     }
176                     $text = "$textPre \n#StartPresentation\n"
177                           . renderSlideNav( $theWeb, $theTopic, 1, 1, "s" )
178                           . "\n$text $textPost";
179                 }
180             
181                 return $text;
182             }
183             
184             # =========================
185             sub renderSlideNav
186             {
187                 my( $theWeb, $theTopic, $theNum, $theMax, $theButtons ) = @_;
188                 my $prev = $theNum - 1 || 1;
189                 my $next = $theNum + 1;
190 rizwank 1.1     my $text = "";
191                 my $viewUrl = "%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/$theWeb/$theTopic";
192                 if( $theButtons =~ /f/ ) {
193                     # first slide button
194                     if( $theButtons =~ / f/ ) {
195                         $text .= "&nbsp;";
196                     }
197                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide1\">"
198                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/first.gif\" border=\"0\""
199                            . " alt=\"First slide\" /></a>";
200                 }
201                 if( $theButtons =~ /p/ ) {
202                     # previous slide button
203                     if( $theButtons =~ / p/ ) {
204                         $text .= "&nbsp;";
205                     }
206                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide$prev\">"
207                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/prev.gif\" border=\"0\""
208                            . " alt=\"Previous\" /></a>";
209                 }
210                 if( $theButtons =~ /n/ ) {
211 rizwank 1.1         # next slide button
212                     if( $theButtons =~ / n/ ) {
213                         $text .= "&nbsp;";
214                     }
215                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide$next\">"
216                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/next.gif\" border=\"0\""
217                            . " alt=\"Next\" /></a>";
218                 }
219                 if( $theButtons =~ /l/ ) {
220                     # last slide button
221                     if( $theButtons =~ / l/ ) {
222                         $text .= "&nbsp;";
223                     }
224                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide$theMax\">"
225                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/last.gif\" border=\"0\""
226                            . " alt=\"Last slide\" /></a>";
227                 }
228                 if( $theButtons =~ /e/ ) {
229                     # end slideshow button
230                     if( $theButtons =~ / e/ ) {
231                         $text .= "&nbsp;";
232 rizwank 1.1         }
233                     $text .= "<a href=\"$viewUrl#StartPresentation\">"
234                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/endpres.gif\" border=\"0\""
235                            . " alt=\"End Presentation\" /></a>";
236                 }
237                 if( $theButtons =~ /s/ ) {
238                     # start slideshow button
239                     if( $theButtons =~ / s/ ) {
240                         $text .= "&nbsp;";
241                     }
242                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide1\">"
243                            . "<img src=\"%PUBURLPATH%/$installWeb/SlideShowPlugin/startpres.gif\" border=\"0\""
244                            . " alt=\"Start Presentation\" /></a>";
245                 }
246             
247                 return $text;
248             }
249             
250             # =========================
251             sub renderSlideToc
252             {
253 rizwank 1.1     my( $theWeb, $theTopic, @theTitles ) = @_;
254             
255                 my $slideNum = 1;
256                 my $text = "";
257                 my $viewUrl = "%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/$theWeb/$theTopic";
258                 foreach( @theTitles ) {
259                     $text .= "\t\* ";
260                     $text .= "<a href=\"$viewUrl?slideshow=on&amp;skin=print#GoSlide$slideNum\">";
261                     $text .= " $_ </a>\n";
262                     $slideNum++;
263                 }
264                 return $text;
265             }
266             
267             # =========================
268             sub readTmplText
269             {
270                 my( $theWeb, $theArgs ) = @_;
271             
272                 my $tmplTopic =  TWiki::Func::extractNameValuePair( $theArgs, "template" );
273                 unless( $tmplTopic ) {
274 rizwank 1.1         $theWeb = $installWeb;
275                     $tmplTopic =  TWiki::Func::getPreferencesValue( "SLIDESHOWPLUGIN_TEMPLATE" )
276                                || "SlideShowPlugin";
277                 }
278                 if( $tmplTopic =~ /^([^\.]+)\.(.*)$/o ) {
279                     $theWeb = $1;
280                     $tmplTopic = $2;
281                 }
282                 my( $meta, $text ) = TWiki::Func::readTopic( $theWeb, $tmplTopic );
283                 # remove everything before %STARTINCLUDE% and after %STOPINCLUDE%
284                 $text =~ s/.*?%STARTINCLUDE%//os;
285                 $text =~ s/%STOPINCLUDE%.*//os;
286             
287                 unless( $text ) {
288                     $text = "<font color=\"red\"> $installWeb.SlideShowPlugin Error: </font>"
289                           . "Slide template topic <nop>$theWeb.$tmplTopic not found or empty!\n\n"
290                           . "%SLIDETITLE%\n\n%SLIDETEXT%\n\n";
291                 } elsif( $text =~ /%SLIDETITLE%/ && $text =~ /%SLIDETEXT%/ ) {
292                     # assume that format is OK
293                 } else {
294                     $text = "<font color=\"red\"> $installWeb.SlideShowPlugin Error: </font>"
295 rizwank 1.1               . "Missing =%<nop>SLIDETITLE%= or =%<nop>SLIDETEXT%= in "
296                           . "slide template topic $theWeb.$tmplTopic.\n\n"
297                           . "%SLIDETITLE%\n\n%SLIDETEXT%\n\n";
298                 }
299                 $text =~ s/%WEB%/$theWeb/go;
300                 $text =~ s/%TOPIC%/$tmplTopic/go;
301                 $text =~ s/%ATTACHURL%/%PUBURL%\/$theWeb\/$tmplTopic/go;
302                 return $text;
303             }
304             
305             # =========================
306             
307             1;

Rizwan Kassim
Powered by
ViewCVS 0.9.2