1<?php
2/**
3 * Renderer for XHTML output
4 *
5 * @author Harry Fuecks <hfuecks@gmail.com>
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11// we inherit from the XHTML renderer instead directly of the base renderer
12require_once DOKU_INC.'inc/parser/xhtml.php';
13
14/**
15 * The Renderer
16 */
17class renderer_plugin_s5 extends Doku_Renderer_xhtml {
18    var $slideopen = false;
19    var $base='';
20    var $tpl='';
21
22    /**
23     * the format we produce
24     */
25    function getFormat(){
26        // this should be 's5' usally, but we inherit from the xhtml renderer
27        // and produce XHTML as well, so we can gain magically compatibility
28        // by saying we're the 'xhtml' renderer here.
29        return 'xhtml';
30    }
31
32
33    /**
34     * Initialize the rendering
35     */
36    function document_start() {
37        global $ID;
38
39        // call the parent
40        parent::document_start();
41
42        // store the content type headers in metadata
43        $headers = array(
44            'Content-Type' => 'text/html; charset=utf-8'
45        );
46        p_set_metadata($ID,array('format' => array('s5' => $headers) ));
47        $this->base = DOKU_BASE.'lib/plugins/s5/ui/';
48        $this->tpl  = isset($_GET['s5theme'])?$_GET['s5theme']:$this->getConf('template');
49        $this->tpl = preg_replace('/[^a-z0-9_-]+/', '', $this->tpl); // clean user provided path
50    }
51
52    /**
53     * Print the header of the page
54     *
55     * Gets called when the very first H1 header is discovered. It includes
56     * all the S5 CSS and JavaScript magic
57     */
58    function s5_init($title){
59        global $conf;
60        global $lang;
61        global $INFO;
62        global $ID;
63
64        //throw away any previous content
65        $this->doc = '
66<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
67 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
68<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"
69 lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">
70
71<head>
72<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
73<title>'.hsc($title).'</title>
74<!-- metadata -->
75<meta name="generator" content="S5" />
76<meta name="version" content="S5 1.1" />
77<!-- configuration parameters -->
78<meta name="defaultView" content="slideshow" />
79<meta name="controlVis" content="hidden" />
80<!-- style sheet links -->
81<link rel="stylesheet" href="'.DOKU_BASE.'lib/styles/all.css" type="text/css" media="screen" />
82<link rel="stylesheet" href="'.DOKU_BASE.'lib/styles/screen.css" type="text/css" media="screen" />
83<link rel="stylesheet" href="'.$this->base.$this->tpl.'/slides.css" type="text/css" media="projection" id="slideProj" />
84<link rel="stylesheet" href="'.$this->base.'default/outline.css" type="text/css" media="screen" id="outlineStyle" />
85<link rel="stylesheet" href="'.$this->base.'default/print.css" type="text/css" media="print" id="slidePrint" />
86<link rel="stylesheet" href="'.$this->base.'default/opera.css" type="text/css" media="projection" id="operaFix" />
87<!-- S5 JS -->
88<script src="'.$this->base.'default/slides.js" type="text/javascript"></script>
89</head>
90<body>
91<div class="layout">
92<div id="controls"><!-- DO NOT EDIT --></div>
93<div id="currentSlide"><!-- DO NOT EDIT --></div>
94<div id="header"></div>
95<div id="footer">
96<h1>'.tpl_pagetitle($ID, true).'</h1>
97<h2>'.hsc($conf['title']).' &#8226; '.strftime($conf['dformat'],$INFO['lastmod']).'</h2>
98</div>
99
100</div>
101<div class="presentation">
102';
103    }
104
105    /**
106     * Closes the document
107     */
108    function document_end(){
109        // we don't care for footnotes and toc
110        // but cleanup is nice
111        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
112
113        if($this->slideopen){
114            $this->doc .= '</div>'.DOKU_LF; //close previous slide
115        }
116        $this->doc .= '</div>
117                       </body>
118                       </html>';
119    }
120
121    /**
122     * This is what creates new slides
123     *
124     * A new slide is started for each H2 header
125     */
126    function header($text, $level, $pos) {
127        if($level == 1){
128            if(!$this->slideopen){
129                $this->s5_init($text); // this is the first slide
130                $level = 2;
131            }else{
132                return;
133            }
134        }
135
136        if($level == 2){
137            if($this->slideopen){
138                $this->doc .= '</div>'.DOKU_LF; //close previous slide
139            }
140            $this->doc .= '<div class="slide">'.DOKU_LF;
141            $this->slideopen = true;
142        }
143        $this->doc .= '<h'.($level-1).'>';
144        $this->doc .= $this->_xmlEntities($text);
145        $this->doc .= '</h'.($level-1).'>'.DOKU_LF;
146    }
147
148    /**
149     * Top-Level Sections are slides
150     */
151    function section_open($level) {
152        if($level < 3){
153            $this->doc .= '<div class="slidecontent">'.DOKU_LF;
154        }else{
155            $this->doc .= '<div>'.DOKU_LF;
156        }
157        // we don't use it
158    }
159
160    /**
161     * Throw away footnote
162     */
163    function footnote_close() {
164        // recover footnote into the stack and restore old content
165        $footnote = $this->doc;
166        $this->doc = $this->store;
167        $this->store = '';
168    }
169
170    /**
171     * No acronyms in a presentation
172     */
173    function acronym($acronym){
174        $this->doc .= $this->_xmlEntities($acronym);
175    }
176
177    /**
178     * A line stops the slide and start the handout section
179     */
180    function hr() {
181        $this->doc .= '</div>'.DOKU_LF;
182        $this->doc .= '<div class="handout">'.DOKU_LF;
183    }
184}
185
186//Setup VIM: ex: et ts=4 enc=utf-8 :
187