View source for Handler: SlideShow

#||
||
Compatible with: !!(green)**R6.1**!!
Current version: **0.3**

Copy the file slideshow.php into the **/handler/page/**-directory. 
Works fine, if an unchanged version of the default-theme is in the themes-directory.
The handler is called with ##pagename/slideshow.xml##.

Example: ((https://wackowiki.org/doc/Dev/PatchesHacks/SlideShowHandler/slideshow.xml SlideShow))

 |{{toc numerate=1}}
 ||
||#


**/handlers/page/slideshow.xml.php**
%%(php)
<?php
/*
Handler slideshow.xml
uses .xml.php because then it does not load the theme header and footer by default
*/

if (!defined('IN_WACKO'))
{
	exit;
}

// redirect to show method if page don't exists
if (!$this->page)
{
	$this->http->redirect($this->href('show'));
}

if ($this->has_access('read'))
{
	// TODO: define more options for splitting the page body
	// split the page
	$body_f	= $this->format($this->page['body_r'], 'post_wacko', ['strip_notypo' => true]);
	$body	= preg_split('/(<h2 .*>.*<\/h2>)/u', $body_f, -1, PREG_SPLIT_DELIM_CAPTURE);

	if (isset($_GET['debug']) && $_GET['debug'] == 1)
	{
		# echo "<div style=\"display: none\">\n";
		$tpl->debug =  Ut::debug_print_r($body);
		# echo "</div>\n\n";
	}

	// If the first slide starts with a level 1 heading
	if (preg_match('/^<h2 .*>.*<\/h2>/u', $body_f))
	{
		$first_slide = 0;
	}
	else
	{
		$first_slide = 1;
	}

	// we test all the parameters of the handler 'slideshow',
	// if there is none, this is the "slide = 1" parameter is invoked by default

	if (!$body)
	{
		return;
	}
	else
	{
		// If you do not specify a parameter, it defaults to the first slide
		if (!isset($_GET['slide']) or $_GET['slide'] == 1)
		{
			$slide = 1;
		}
		else
		{
			$slide = (int) ($_GET['slide'] ?? '');
		}

		// HTTP header with right Charset settings
		header('Content-Type: text/html; charset=' . $this->get_charset());
		header_remove('X-Powered-By');

		$tpl->lang		= $this->page_lang;
		$tpl->dir		= $this->languages[$this->page_lang]['dir'];
		$tpl->charset	= $this->get_charset();
		$tpl->method	= $this->method;
		!Ut::is_empty($tpl->title = @$this->page['title']) or $tpl->tag = $this->add_spaces($this->tag);
		$tpl->favicon	= $this->get_favicon();

		if (!file_exists($this->db->theme_url . 'css/slideshow.css'))
		{
			#$tpl->css	= false;
		}
		else
		{
			#echo '<link rel="stylesheet" href="'.$this->config['theme_url'].'css/slideshow.css">';
		}

		// display navigation menu

		// If this is not the first slide, we display links "<< previous" and "[start]"
		if ($slide !== 1)
		{
			$tpl->nav_p_hrefprev	= $this->href('slideshow.xml', '', 'slide=' . ($_GET['slide'] - 1));
			$tpl->nav_p_hrefstart	= $this->href('slideshow.xml', '', 'slide=1');
		}

		if (isset($body[($slide) * 2 - ($first_slide * 2) + 2]) or $slide == 1)
		{
			$tpl->nav_n_hrefnext	=	$this->href('slideshow.xml', '', 'slide='.($slide + 1));
		}

		// showing content

		// if this is the first slide
		if ($slide == 1 and $first_slide == 1)
		{
			$tpl->body = $body[0];
		}
		// from the second slide
		else
		{
			$tpl->body =  $body[($slide * 2) - ($first_slide * 2) - 1] . $body[($slide * 2) - ($first_slide * 2)];
		}
	}
}
else
{
	$message = $this->_t('ReadAccessDenied');
	$this->show_message($message, 'info');
}

%%

**/handlers/page/template/slideshow.xml.tpl**
%%(hl html)
[ === main === ]
	[ ' dummy | default * // ADD_NO_DIV ' ]<!DOCTYPE html>
	<html dir="[ ' dir ' ]" lang="[ ' lang ' ]">
	<head>
		<meta charset="[ ' charset ' ]">
		<title>[ ' title | e ' ][ ' tag ' ][ ' method | enclose " (" ")" ' ] - [ ' db: site_name | e ' ]</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="robots" content="noindex, nofollow, noarchive">
		<meta name="language" content="[ ' lang ' ]">
		<link rel="stylesheet" href="[ ' db: theme_url ' ]css/default.css">
		[= unused _ =
			<link rel="stylesheet" href="[ ' db: theme_url ' ]css/wacko.css">
		=]
		<link rel="icon" href="[ ' favicon ' ]" type="image/x-icon">
		[= css _ =
		<style>
			.slide { font-size: 160%; margin: 1% 3%; background-color: #fff; padding: 30px; border: 1px inset; line-height: 1.5; }
			.slide ul, li, .slide p { font-size: 100%; }
			.slide li li { font-size: 90% }
			.sl_nav p { text-decoration: none; text-align: right; font-size: 80%; line-height: 0.4; }
			.sl_nav a { text-decoration: none; }
			.sl_nav a:hover { color: #CF8888 }
			div.sl_nav  { padding: 10px 20px 10px 0; }
			.page { background-color: #d1d1d1 }
			.sum { font-size: 8px; }
			br { display:none; }
		</style>
		=]
	</head>
	<body >
		[ '' nav navigation '' ]
		<div class="slide">
			[ ' body | pre ' ]<br><br>
		</div>
		[ '' nav navigation '' ]
	</body>
	</html>


[ == navigation == ]
<div class="sl_nav">
	<p>
		[= p _ =
			<a href="[ ' hrefprev ' ]">« [ ' _t: PrevAcr ' ]</a>
			<a href="[ ' hrefstart ' ]">[Start]</a> 
		=]
		[= n _ =
			<a href="[ ' hrefnext ' ]">[ ' _t: NextAcr ' ] »</a>
		=]
	</p>	
	<p>
		<a href="[ ' href: edit ' ]">[ ' _t: EditText ' ] </a> ·
		<a href="[ ' href: ' ]">[ ' _t: CancelButton ' ]</a>
	</p>
</div>


%%

===Documentation===
uses heading H2 as page break


===How to===
example:
%%
(1) Presentation
Slide 1

=== (2) Title ===
Slide 2

=== (3) Title ===
Slide 3

%%
====Localization (optional)====

put this at the end of your language file

**/lang/wacko.xyz.php**
%%
//hacks "YourPhrase" => "your translation here",
%%
pls. notice that this entry will not survive an Wacko upgrade, so you have to redo this

**[xyz] proposed translations**
[de] ...
[fr] 
[ru]

===Changelog===
  * 0.1 ported to WackoWiki
  * 0.2 adapted for R6.0
  * 0.3 uses ##get_favicon()## function

===To Do===
  * still a mess..
  * define more options for splitting the page body
  * fix CSS