Handler: SlideShow

Compatible with: R6.1
Current version: 0.4


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: SlideShow


handler/page/slideshow.xml.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());
}

if ($this->has_access('read'))
{
    // TODO: define more options for splitting the page body, e.g. smallest splitting header
    // split the page
    $this->context[++$this->current_context] = $this->page['tag'];

    #$body_f    = $this->format($this->page['body'], 'wiki', ['post_wacko' => true]);
    $body_f    = $this->format($this->page['body'], 'wordprocessor');

    $this->context[$this->current_context] = '~~'; // clean stack
    $this->current_context--;

    $body    = preg_split('#(<h[2-6] .*?>.*?</h[2-6]>)#u', $body_f, -1, PREG_SPLIT_DELIM_CAPTURE);

    #Ut::debug_print_r($body);

    if (!$body)
    {
        return;
    }
    else
    {
        // first slide starts with a level 1 heading
        if (preg_match('#^<h[2-6] .*?>.*?</h[2-6]>#u', $body[0]))
        {
            $first_slide = 0;
        }
        else
        {
            $first_slide = 1;
        }

        // If you do not specify a parameter, it defaults to the first slide
        $slide = (int) (($_GET['slide'] ?? 1) ?: 1);

        // 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']) || $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
        #{
            #$this->add_html('header', '<link rel="stylesheet" href="' . $this->db->theme_url . 'css/slideshow.css">');
        #}

        // current slide
        $c_slide = ($slide * 2) - ($first_slide * 2);

        // display navigation menu
        if ($slide !== 1
            && preg_match('#<h\d id=\"h\d+-(\d+)\" class=\"heading\">#', $body[$c_slide - 1], $match))
        {
            $section = ['section' => $match[1]];
        }

        $tpl->nav_href = $this->href('edit', '', $section ?? []);

        // 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=' . ($slide - 1));
            $tpl->nav_p_hrefstart    = $this->href('slideshow.xml', '', 'slide=1');
        }

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

        // first slide
        if ($slide == 1 && $first_slide == 1)
        {
            $tpl->body =
                '<h1>' . $this->page['title'] . '</h1>' . "\n" .
                $body[0];
        }
        // other slides (header + section)
        else
        {
            $tpl->body =
                $body[$c_slide - 1] .
                $body[$c_slide];
        }
    }
}
else
{
    $this->http->redirect($this->href());
}

handler/page/template/slideshow.xml.tpl

[ === 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; min-height: 500px;}
            .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 ' ]">[ ' _t: EditText ' ] </a> ·
        <a href="[ ' href: ' ]">[ ' _t: CancelButton ' ]</a>
    </p>
</div>

1. Documentation

uses heading H2 and smaller as page break


2. How to

example:

(1) Presentation
Slide 1

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

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

3. Changelog

  • 0.1 ported to WackoWiki
  • 0.2 adapted for R6.0
  • 0.3 uses get_favicon() function
  • 0.4 added section editing support

4. To Do

  • still a mess
  • define more options for splitting the page body
  • fix CSS