1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function wikiplugin_slideshow_info()
9{
10	return [
11		'name' => tra('Slideshow'),
12		'documentation' => 'Slideshow',
13		'description' => tra('Create a slideshow from the content of a wiki page'),
14		'prefs' => [ 'wikiplugin_slideshow', 'feature_slideshow' ],
15		'iconname' => 'tv',
16		'introduced' => 7,
17		'tags' => [ 'basic' ],
18		'params' => [
19			'theme' => [
20				'required' => false,
21				'name' => tra('Theme'),
22				'description' => tra('The theme you want to use for the slideshow, default will be what you choose from
23					the admin panel under Look and Feel for jQuery UI'),
24				'filter' => 'text',
25				'default' => 'black',
26				'since' => '19.0',
27				'options' => [
28					['text' => 'Black: Black background, white text, blue links', 'value' => 'black'],
29					['text' => 'Blood: Dark gray background, dark text, maroon links', 'value' => 'blood'],
30					['text' => 'Beige: Beige background, dark text, brown links', 'value' => 'beige'],
31					['text' => 'League: Gray background, white text, blue links', 'value' => 'league'],
32					['text' => 'Moon: Navy blue background, blue links', 'value' => 'moon'],
33					['text' => 'Night: Black background, thick white text, orange links', 'value' => 'night'],
34					['text' => 'Serif: Cappuccino background, gray text, brown links', 'value' => 'serif'],
35					['text' => 'Simple: White background, black text, blue links', 'value' => 'simple'],
36					['text' => 'Sky: Blue background, thin dark text, blue links', 'value' => 'sky'],
37					['text' => 'Solarized: Cream-colored background, dark green text, blue links', 'value' => 'solarized'],
38				],
39			],
40			'parallaxBackgroundImage' => [
41				'required' => false,
42				'name' => tra('Parallax Background Image'),
43				'description' => tr(
44					'URL of the background image to use in your slideshow, overrides %0',
45					'<code>backgroundcolor</code>'
46				),
47				'filter' => 'url',
48				'accepted' => tra('Valid URL'),
49				'default' => '',
50				'since' => '19.0',
51			],
52            'parallaxBackgroundSize' => [
53                'required' => false,
54                'name' => tra('Parallax Background Size'),
55                'description' => tra('syntax, e.g. "2100px 900px" - currently only pixels are supported (don\'t use % or auto)'),
56                'default' => '',
57                'since' => '19.0'
58            ],
59            'parallaxBackgroundHorizontal' => [
60                'required' => false,
61                'name' => tra('Parallax Background Horizontal'),
62                'description' => tra('Number of pixels to move the parallax background per slide, Calculated automatically unless specified. Set to 0 to disable movement along an axis'),
63                'default' => null,
64                'since' => '19.0'
65            ],
66            'parallaxBackgroundVertical' => [
67                'required' => false,
68                'name' => tra('Parallax Background Vertical'),
69                'description' => '',
70                'default' => null,
71                'since' => '19.0'
72            ],
73            'transition' => [
74                'required' => false,
75                'name' => tra('Transition'),
76                'description' => tra(' Transition style'),
77                'filter' => 'word',
78                'default' => 'zoom',
79                'since' => '19.0',
80                'options' => [
81					['text' => 'Zoom', 'value' => 'zoom'],
82                    ['text' => 'Fade', 'value' => 'fade'],
83                    ['text' => 'Slide', 'value' => 'slide'],
84                    ['text' => 'Convex', 'value' => 'convex'],
85                    ['text' => 'Concave', 'value' => 'concave'],
86					['text' => 'off', 'value' => ''],
87
88
89				],
90            ],
91            'transitionSpeed' => [
92                'required' => false,
93                'name' => tra('Transition Speed'),
94                'description' => tra('Transition Speed'),
95                'filter' => 'word',
96                'default' => '',
97                'since' => '19.0',
98                'options' => [
99                    ['text' => 'Default', 'value' => 'default'],
100                    ['text' => 'Fast', 'value' => 'fast'],
101                    ['text' => 'Slow', 'value' => 'slow'],
102                ],
103            ],
104            'backgroundTransition' => [
105                'required' => false,
106                'name' => tra('Background Transition'),
107                'description' => tra('Transition style for full page slide backgrounds'),
108                'filter' => 'word',
109                'default' => 'fade',
110                'since' => '19.0',
111                'options' => [
112                    ['text' => 'None', 'value' => 'none'],
113                    ['text' => 'Fade', 'value' => 'fade'],
114                    ['text' => 'Slide', 'value' => 'slide'],
115                    ['text' => 'Convex', 'value' => 'convex'],
116                    ['text' => 'Concave', 'value' => 'concave'],
117                    ['text' => 'Zoom', 'value' => 'zoom'],
118                ],
119            ],
120            'controls' => [
121                'required' => false,
122                'name' => tra('Controls'),
123                'description' => tra('Display presentation control arrows'),
124                'filter' => 'word',
125                'default' => 'y',
126                'since' => '19.0',
127                'options' => [
128                    ['text' => 'True', 'value' => 'y'],
129                    ['text' => 'False', 'value' => 'n'],
130                ],
131            ],
132            'controlsLayout' => [
133                'required' => false,
134                'name' => tra('Controls Layout'),
135                'description' => tra('Determines where controls appear, "edges" or "bottom-right"'),
136                'filter' => 'word',
137                'default' => 'bottom-right',
138                'since' => '19.0',
139                'options' => [
140                    ['text' => 'Bottom-Right', 'value' => 'bottom-right'],
141                    ['text' => 'Edges', 'value' => 'edges'],
142                ],
143            ],
144            'controlsBackArrows' => [
145                'required' => false,
146                'name' => tra('Controls Back Arrows'),
147                'description' => tra('Visibility rule for backwards navigation arrows; "faded", "hidden" or "visible"'),
148                'filter' => 'word',
149                'default' => 'faded',
150                'since' => '19.0',
151                'options' => [
152                    ['text' => 'Faded', 'value' => 'faded'],
153                    ['text' => 'Hidden', 'value' => 'hidden'],
154                    ['text' => 'Visible', 'value' => 'visible'],
155                ],
156            ],
157            'progress' => [
158                'required' => false,
159                'name' => tra('Progress'),
160                'description' => tra('Display a presentation progress bar'),
161                'filter' => 'word',
162                'default' => 'y',
163                'since' => '19.0',
164                'options' => [
165                    ['text' => 'True', 'value' => 'y'],
166                    ['text' => 'False', 'value' => 'n'],
167                ],
168            ],
169            'slideNumber' => [
170                'required' => false,
171                'name' => tra('Slide Number'),
172                'description' => tra('Display the page number of the current slide'),
173                'filter' => 'word',
174                'default' => 'n',
175                'since' => '19.0',
176                'options' => [
177                    ['text' => 'True', 'value' => 'y'],
178                    ['text' => 'False', 'value' => 'n'],
179                ],
180            ],
181            'fragments' => [
182                'required' => false,
183                'name' => tra('Fragments'),
184                'description' => tra('Turns fragments on and off globally'),
185                'filter' => 'word',
186                'default' => 'y',
187                'since' => '19.0',
188                'options' => [
189                    ['text' => 'On', 'value' => 'y'],
190                    ['text' => 'Off', 'value' => 'n'],
191                ],
192            ],
193            'fragmentClass' => [
194                'required' => false,
195                'name' => tra('Fragment Effects'),
196                'description' => tra(''),
197                'filter' => 'word',
198                'default' => 'grow',
199                'since' => '19.0',
200                'options' => [
201                    ['text' => 'Grow', 'value' => 'grow'],
202                    ['text' => 'Shrink', 'value' => 'shrink'],
203                    ['text' => 'Fade-OUT', 'value' => 'fade-out'],
204                    ['text' => 'Fade-UP', 'value' => 'fade-up'],
205                    ['text' => 'Current-Visible', 'value' => 'current-visible'],
206                ],
207            ],
208            'fragmentHighlightColor' => [
209                'required' => false,
210                'name' => tra('Fragment Highlight Color'),
211                'description' => tra(''),
212                'filter' => 'word',
213                'default' => 'blue',
214                'since' => '19.0',
215                'options' => [
216                    ['text' => 'None', 'value' => 'none'],
217                    ['text' => 'Red', 'value' => 'red'],
218                    ['text' => 'Green', 'value' => 'green'],
219                    ['text' => 'Blue', 'value' => 'blue']
220                ],
221            ],
222            'autoSlide' => [
223                'required' => false,
224                'name' => tra('Auto Slide'),
225                'description' => tra('Number of milliseconds between automatically proceeding to the next slide, disabled when set to 0, this value can be overwritten by using a data-autoslide attribute on your slides'),
226                'filter' => 'digits',
227                'default' => '0',
228                'since' => '19.0',
229            ],
230            'autoSlideStoppable' => [
231                'required' => false,
232                'name' => tra('Auto Slide Stoppable'),
233                'description' => tra('Stop auto-sliding after user input'),
234                'filter' => 'word',
235                'default' => 'y',
236                'since' => '19.0',
237                'options' => [
238                    ['text' => 'On', 'value' => 'y'],
239                    ['text' => 'Off', 'value' => 'n'],
240                ],
241            ],
242			'alignImage' => [
243				'required' => false,
244				'name' => tra('Auto-align Images'),
245				'description' => tra('Automatically move images to left hand side of slide text, will only align images greater than 200px in width'),
246				'filter' => 'word',
247				'default' => 'n',
248				'since' => '19.0',
249				'options' => [
250					['text' => 'Off', 'value' => 'n'],
251					['text' => 'On', 'value' => 'y']
252				],
253			],
254
255		],
256	];
257}
258
259function wikiplugin_slideshow($data, $params)
260{
261	if(strstr($_SERVER['PHP_SELF'],'tiki-slideshow.php')=='') {
262		if (strstr($_SERVER['PHP_SELF'], 'tiki-index.php')) {
263			return '<a class="btn btn-primary hidden-print" data-role="button" data-inline="true" title="Start Slideshow" href="./tiki-slideshow.php?page='
264				. $_REQUEST['page'] . '">'.tr('Start Slideshow Presentation').'</a>';
265		}
266		return;
267	}
268
269	if(! empty($_REQUEST['pdf'])){
270		global $pdfStyles;
271		if(isset($params['parallaxBackgroundImage'])) {
272			$pdfStyles='<style>@page,body,div.reveal{background-image-resize:0 !important;
273			background-image:url("'.$params['parallaxBackgroundImage'].'") !important;}</style>';
274		}
275	}
276    $defaults = [];
277    $plugininfo = wikiplugin_slideshow_info();
278    foreach ($plugininfo['params'] as $key => $param) {
279        $defaults["$key"] = $param['default'];
280        //separating digits filter parameters
281        if(isset($param['filter']) && $param['filter'] === "digits") {
282            $slideshowDigitsParams[]=$key;
283        }
284    }
285    $params = array_merge($defaults, $params);
286
287    $revealParams=array('parallaxBackgroundImage','parallaxBackgroundSize','parallaxBackgroundHorizontal','parallaxBackgroundVertical','slideSeconds','transition','transitionSpeed','backgroundTransition','controls','controlsLayout','controlsBackArrows','progress','slideNumber','autoSlide','autoSlideStoppable');
288    $revealSettings = '';
289    foreach($revealParams as $revealParam) {
290		if (isset($params[$revealParam])) {
291			$revealSettings .= $revealParam . ":";
292			if (! in_array($revealParam, $slideshowDigitsParams)) {
293				$revealSettings .= "'" . $params[$revealParam] . "',";
294			} else {
295				$revealSettings .= $params[$revealParam] . ",";
296			}
297		}
298    }
299    $revealSettings =str_replace(array("'y'","'n'"),array("true","false"),$revealSettings);
300    $revealSettings.='viewDistance:3,display:"block",hash:true';
301	$headerlib = TikiLib::lib('header');
302	if(!isset($_REQUEST['theme'])) {
303		$headerlib->add_cssfile('vendor_bundled/vendor/npm-asset/reveal.js/css/theme/'.$params['theme'].'.css',1);
304		$headerlib->add_js(
305			'$( "#showtheme" ).val( "'.$params['theme'].'" );'
306		);
307	}
308	if($params['alignImage']=='y'){
309		$headerlib->add_js('(function(){
310
311			var images = [];
312			$("section table tr").each(function(){
313				var tr=this;
314				var imgsrc="";
315				var minwidth="";
316
317				if($(this).text().length>20 && window.innerHeight < window.innerWidth){ //checking for text content and screen orientation
318
319					$(this).find("img").each(function(){
320
321						if(this.width>200 ){
322							$(tr).find("td").attr("style","vertical-align:top");
323							imgsrc=this.src;
324							minwidth=(this.width)/2;
325							this.remove();
326							if(minwidth>450){ //to avoid distortion of text, in case of large image
327								minwidth=450;
328							}
329						}
330					});
331					if(imgsrc!="") {
332						var tableData = $("<td style=\"width:50%\"><img src="+imgsrc+" style=\"min-width:"+minwidth+"px;max-height:85%\"></td>");
333						$(this).append(tableData);
334					}
335				}
336			})
337		})()');
338	}
339	$headerlib->add_js(
340	"Reveal.configure({".$revealSettings."});
341	var fragments='".$params['fragments']."';
342	var fragmentClass='".$params['fragmentClass']."';
343	var fragmentHighlightColor='highlight-".$params['fragmentHighlightColor']."';"
344	);
345}
346