1
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
3
# Copyright (C) 2002-2007 Peter Thoeny, peter@thoeny.org
4
# Copyright (C) 2008 Foswiki Contributors
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version. For
10
# more details read LICENSE in the root of this distribution.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details, published at
16
# http://www.gnu.org/copyleft/gpl.html
18
# As per the GPL, removal of this notice is prohibited.
23
package Foswiki::Plugins::SlideShowPlugin::SlideShow;
25
use vars qw( $imgRoot $installWeb );
27
# =========================
31
$imgRoot = '%PUBURLPATH%/'.$installWeb.'/SlideShowPlugin';
34
# =========================
37
my( $text, $theTopic, $theWeb ) = @_;
42
if( $text =~ /^(.*)%SLIDESHOWSTART%(.*)$/s ) {
45
} elsif( $text =~ /^(.*)%SLIDESHOWSTART{(.*?)}%(.*)$/s ) {
50
if( $text =~ /^(.*)%SLIDESHOWEND%(.*)$/s ) {
55
# Make sure we don't end up back in the handler again
56
# SMELL: there should be a better block
57
$text =~ s/%SLIDESHOW/%<nop>SLIDESHOW/g;
59
my $query = Foswiki::Func::getCgiQuery();
61
# Build query string based on existingURL parameters
62
my $qparams = '?slideshow=on;skin=print';
63
foreach my $name ( $query->param ) {
64
next if ( $name =~ /(text|keywords|web|topic|slideshow|skin|\#)/ );
65
$qparams .= ';' . $name . '=' . urlEncode( $query->param($name) );
68
if( $query && $query->param( 'slideshow' ) ) {
69
# in presentation mode
71
$textPre .= "\n#StartPresentation\n";
72
$textPre .= renderSlideNav( $theWeb, $theTopic, 1, 1, "e", $qparams );
76
if( $text =~ /(.*?[\n\r])\-\-\-+(\++)\!* (.*)/s ) {
80
$level =~ s/\+/\\\+/go;
81
my @slides = split( /[\n\r]\-\-\-+$level\!* /, $text );
84
my $hideComments = Foswiki::Func::getPreferencesValue( 'SLIDESHOWPLUGIN_HIDECOMMENTS' ) || '';
86
my $tmplText = readTmplText( $theWeb, $args );
90
my $slideComment = "";
95
next unless /^([^\n\r]*)(.*)$/s;
96
$slideTitle = $1 || '';
97
$slideBody = $2 || '';
99
if( $hideComments && $slideBody =~ s/(\-\-\-+\+$level+\!*\s*Comments.*)//is ) {
102
push( @titles, $slideTitle );
103
$slideText = $tmplText;
104
$slideText =~ s/%SLIDETITLE%/$slideTitle/go;
105
$slideText =~ s/%SLIDETEXT%/$slideBody/go;
106
$slideText =~ s/%SLIDENUM%/$slideNum/go;
107
$slideText =~ s/%SLIDEMAX%/$slideMax/go;
108
$slideText =~ s/%SLIDENAV%/renderSlideNav(
109
$theWeb, $theTopic, $slideNum, $slideMax, "f p n", $qparams )/geo;
110
$slideText =~ s/%SLIDENAVALL%/renderSlideNav(
111
$theWeb, $theTopic, $slideNum, $slideMax, "f p n l", $qparams )/geo;
112
$slideText =~ s/%SLIDENAVFIRST%/renderSlideNav(
113
$theWeb, $theTopic, $slideNum, $slideMax, "f", $qparams )/geo;
114
$slideText =~ s/%SLIDENAVPREV%/renderSlideNav(
115
$theWeb, $theTopic, $slideNum, $slideMax, "p", $qparams )/geo;
116
$slideText =~ s/%SLIDENAVNEXT%/renderSlideNav(
117
$theWeb, $theTopic, $slideNum, $slideMax, "n", $qparams )/geo;
118
$slideText =~ s/%SLIDENAVLAST%/renderSlideNav(
119
$theWeb, $theTopic, $slideNum, $slideMax, "l", $qparams )/geo;
120
$text .= "\n\n-----\n#GoSlide$slideNum\n$slideText";
121
unless( $text =~ s/%SLIDECOMMENT%/\n$slideComment\n/go ) {
122
$text .= "\n$slideComment\n\n" if( $slideComment );
124
$text .= "%BR%\n\n" x 20;
127
$text =~ s/%TOC(?:\{.*?\})*%/renderSlideToc( $theWeb, $theTopic, @titles )/geo;
128
$text .= "\n#GoSlide$slideNum\n%BR%\n";
131
$text = "$textPre\n$text\n";
132
$text .= renderSlideNav( $theWeb, $theTopic, $slideMax + 1, $slideMax, "f p e", $qparams );
134
$text .= "%BR%\n\n" x 30;
135
$text =~ s/%BR%/<br \/>/go;
139
# in normal topic view mode
140
if( $text =~ /[\n\r]\-\-\-+(\++)/s ) {
142
$level =~ s/\+/\\\+/go;
143
# add slide number to heading
145
$text =~ s/([\n\r]\-\-\-+$level\!*) ([^\n\r]+)/"$1 Slide " . $slideNum++ . ": $2"/ges;
147
$text = "$textPre \n#StartPresentation\n"
148
. renderSlideNav( $theWeb, $theTopic, 1, 1, "s", $qparams )
149
. "\n$text $textPost";
155
# =========================
158
my( $theWeb, $theTopic, $theNum, $theMax, $theButtons, $qstring ) = @_;
159
my $prev = $theNum - 1 || 1;
160
my $next = $theNum + 1;
161
my $text = '<span style="white-space: nowrap">';
162
my $viewUrl = Foswiki::Func::getViewUrl($theWeb, $theTopic);
163
if( $theButtons =~ /f/ ) {
165
if( $theButtons =~ / f/ ) {
168
$text .= "<a href=\"$viewUrl$qstring#GoSlide1\">"
169
. "<img src=\"$imgRoot/first.gif\" border=\"0\""
170
. " alt=\"First slide\" /></a>";
172
if( $theButtons =~ /p/ ) {
173
# previous slide button
174
if( $theButtons =~ / p/ ) {
177
$text .= "<a href=\"$viewUrl$qstring#GoSlide$prev\">"
178
. "<img src=\"$imgRoot/prev.gif\" border=\"0\""
179
. " alt=\"Previous\" /></a>";
181
if( $theButtons =~ /n/ ) {
183
if( $theButtons =~ / n/ ) {
186
$text .= "<a href=\"$viewUrl$qstring#GoSlide$next\">"
187
. "<img src=\"$imgRoot/next.gif\" border=\"0\""
188
. " alt=\"Next\" /></a>";
190
if( $theButtons =~ /l/ ) {
192
if( $theButtons =~ / l/ ) {
195
$text .= "<a href=\"$viewUrl$qstring#GoSlide$theMax\">"
196
. "<img src=\"$imgRoot/last.gif\" border=\"0\""
197
. " alt=\"Last slide\" /></a>";
199
if( $theButtons =~ /e/ ) {
200
# end slideshow button
201
if( $theButtons =~ / e/ ) {
204
$text .= "<a href=\"$viewUrl\">"
205
. "<img src=\"$imgRoot/endpres.gif\" border=\"0\""
206
. " alt=\"End Presentation\" /></a>";
208
if( $theButtons =~ /s/ ) {
209
# start slideshow button
210
if( $theButtons =~ / s/ ) {
213
$text .= "<a href=\"$viewUrl$qstring#GoSlide1\">"
214
. "<img src=\"$imgRoot/startpres.gif\" border=\"0\""
215
. " alt=\"Start Presentation\" /></a>";
221
# =========================
224
my( $theWeb, $theTopic, @theTitles ) = @_;
228
my $viewUrl = Foswiki::Func::getViewUrl($theWeb, $theTopic);
229
foreach( @theTitles ) {
231
$text .= "<a href=\"$viewUrl?slideshow=on&skin=print#GoSlide$slideNum\">";
232
$text .= " $_ </a>\n";
238
# =========================
241
my( $theWeb, $theArgs ) = @_;
243
my $tmplTopic = Foswiki::Func::extractNameValuePair( $theArgs, "template" );
244
unless( $tmplTopic ) {
245
$theWeb = $installWeb;
246
$tmplTopic = Foswiki::Func::getPreferencesValue( "SLIDESHOWPLUGIN_TEMPLATE" )
247
|| "SlideShowPlugin";
249
if( $tmplTopic =~ /^([^\.]+)\.(.*)$/o ) {
253
my( $meta, $text ) = Foswiki::Func::readTopic( $theWeb, $tmplTopic );
254
# remove everything before %STARTINCLUDE% and after %STOPINCLUDE%
255
$text =~ s/.*?%STARTINCLUDE%//os;
256
$text =~ s/%STOPINCLUDE%.*//os;
259
$text = "<font color=\"red\"> $installWeb.SlideShowPlugin Error: </font>"
260
. "Slide template topic <nop>$theWeb.$tmplTopic not found or empty!\n\n"
261
. "%SLIDETITLE%\n\n%SLIDETEXT%\n\n";
262
} elsif( $text =~ /%SLIDETITLE%/ && $text =~ /%SLIDETEXT%/ ) {
263
# assume that format is OK
265
$text = "<font color=\"red\"> $installWeb.SlideShowPlugin Error: </font>"
266
. "Missing =%<nop>SLIDETITLE%= or =%<nop>SLIDETEXT%= in "
267
. "slide template topic $theWeb.$tmplTopic.\n\n"
268
. "%SLIDETITLE%\n\n%SLIDETEXT%\n\n";
270
$text =~ s/%WEB%/$theWeb/go;
271
$text =~ s/%TOPIC%/$tmplTopic/go;
272
$text =~ s/%ATTACHURL%/%PUBURL%\/$theWeb\/$tmplTopic/go;
276
# =========================
280
$text =~ s/([^0-9a-zA-Z-_.:~!*'()\/%])/'%'.sprintf('%02x',ord($1))/ge;