1<?php
2/**
3 * Renderer for XHTML output
4 *
5 * @author Harry Fuecks <hfuecks@gmail.com>
6 * @author Andreas Gohr <andi@splitbrain.org>
7 * @author Tomas Alonso <t.alonso@oan.es>
8 */
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12// we inherit from the XHTML renderer instead directly of the base renderer
13require_once DOKU_INC.'inc/parser/xhtml.php';
14
15/**
16 * The Renderer
17 */
18class renderer_plugin_s5reloaded extends Doku_Renderer_xhtml {
19    var $slideopen = false;
20    var $notesopen = false;
21    var $base='';
22    var $tpl='';
23
24    /**
25     * the format we produce
26     */
27    function getFormat(){
28        // this should be 's5' usally, but we inherit from the xhtml renderer
29        // and produce XHTML as well, so we can gain magically compatibility
30        // by saying we're the 'xhtml' renderer here.
31        return 'xhtml';
32    }
33
34
35    /**
36     * Initialize the rendering
37     */
38    function document_start() {
39        global $ID;
40
41        // call the parent
42        parent::document_start();
43
44        // store the content type headers in metadata
45        $headers = array(
46            'Content-Type' => 'text/html; charset=utf-8'
47        );
48        p_set_metadata($ID,array('format' => array('s5reloaded' => $headers) ));
49        $this->base = DOKU_BASE.'lib/plugins/s5reloaded/ui/';
50/*        $this->tpl  = $this->getConf('template'); */
51        $this->tpl  = isset($_GET['s5theme'])?$_GET['s5theme']:$this->getConf('template');
52    }
53
54    /**
55     * Print the header of the page
56     *
57     * Gets called when the very first H1 header is discovered. It includes
58     * all the S5 CSS and JavaScript magic
59     */
60    function s5reloaded_init($title){
61        global $conf;
62        global $lang;
63        global $INFO;
64        global $ID;
65
66        //throw away any previous content
67        $this->doc = '
68<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
69 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
70<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"
71 lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">
72
73<head>
74<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
75<title>'.hsc($title).'</title>
76<!-- metadata -->
77<meta name="generator" content="S5" />
78<meta name="version" content="S5 1.3" />
79<meta name="author" content="Eric A. Meyer" />
80<meta name="company" content="Complex Spiral Consulting" />
81<!-- meta extensions -->
82<meta name="subject" content="S5 1.3beta7" />
83<meta name="creator" content="Christian Effenberger" />
84<meta name="contributor" content="youcan[64]netzgesta[46]de" />
85<meta name="publisher" content="s5.netzgesta.de" />
86<meta name="description" content="S5 1.3 is a very flexible and lightweight slide show system available for anyone to use (including transitions and scalable fonts and images)" />
87<meta name="keywords" content="S5, slide show, projection-mode, powerpoint-like, scala-like, keynote-like, incremental display, scalable fonts, scalable images, transitions, notes, osf, xoxo, css, javascript, xhtml, public domain" />
88<!-- configuration parameters -->
89<meta name="defaultView" content="slideshow" />
90<meta name="controlVis" content="hidden" />
91<meta name="tranSitions" content="true" />
92<meta name="fadeDuration" content="500" />
93<meta name="incrDuration" content="250" />
94<!-- configuration autoplay extension -->
95<meta name="autoMatic" content="false" />
96<meta name="playLoop" content="true" />
97<meta name="playDelay" content="10" />
98<!-- configuration audio extension -->
99<meta name="audioSupport" content="true" />
100<meta name="audioVolume" content="100" />
101<meta name="audioError" content="true" />
102<!-- configuration audio debug -->
103<meta name="audioDebug" content="false" />
104<!-- style sheet links -->
105<link rel="stylesheet" href="'.$this->base.$this->tpl.'/slides.css" type="text/css" media="projection" id="slideProj" />
106<link rel="stylesheet" href="'.$this->base.$this->tpl.'/outline.css" type="text/css" media="screen" id="outlineStyle" />
107<link rel="stylesheet" href="'.$this->base.$this->tpl.'/print.css" type="text/css" media="print" id="slidePrint" />
108<link rel="stylesheet" href="'.$this->base.$this->tpl.'/opera.css" type="text/css" media="projection" id="operaFix" />
109<link rel="stylesheet" href="'.$this->base.$this->tpl.'/wrap.css" type="text/css" />
110<link rel="stylesheet" href="'.$this->base.'../../../styles/style.css" type="text/css" />
111
112<style type="text/css" media="all">
113.imgcon {width: 100%; margin: 0 auto; padding: 0; text-align: center;}
114#anim {width: 33%; height: 320px; position: relative;}
115#anim img {position: absolute; top: 0px; left: 0px;}
116.logo {margin: 0.2em 0 0 0.15em; padding: 0;}
117.clock {margin: 0.1em 0.2em; padding: 0; position: absolute; top: 0em; right: 0em;}
118.red {color: #C02;}
119</style>
120
121
122<!-- S5 JS -->
123<script src="'.$this->base.$this->tpl.'/slides.js" type="text/javascript"></script>
124
125<!-- prototype + scriptaculous -->
126<script src="'.$this->base.'effects_support/prototype.js" type="text/javascript"></script>
127<script src="'.$this->base.'effects_support/scriptaculous.js" type="text/javascript"></script>
128
129<!-- Presentaculous JS -->
130<script src="'.$this->base.'effects_support/presentacular.js" type="text/javascript"></script>
131
132<script type="text/javascript" charset="utf-8" src="'.$this->base.'../../asciimath/asciimathml148r.js" ></script>
133<script type="text/javascript" charset="utf-8" src="'.$this->base.'../../asciimathml/ASCIIMathML148.js" ></script>
134<script type="text/javascript" charset="utf-8" src="'.$this->base.'../../sortablejs/script.js" ></script>
135<script type="text/x-mathjax-config">
136  MathJax.Hub.Config({
137    tex2jax: {
138        inlineMath: [ ["$","$"], ["\\\\(","\\\\)"] ],
139        displayMath: [ ["$$","$$"], ["\\\\[","\\\\]"] ],
140        processEscapes: true
141    }});
142</script>
143<script type="text/javascript" charset="utf-8" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
144
145</head>
146<body>
147
148<div class="layout">
149<div id="controls"><!-- DO NOT EDIT --></div>
150<div id="currentSlide"><!-- DO NOT EDIT --></div>
151<div id="header">
152<div class="scale" id="logo"><!-- DO NOT EDIT --></div>
153</div>
154<div id="footer">
155<h1>'.$title.'</h1>
156<h2>'.hsc($conf['title']).' &#8226; '.strftime($conf['dformat'],$INFO['lastmod']).'</h2>
157<div class="scale" id="logo_bottom"><!-- DO NOT EDIT --></div>
158</div>
159</div>
160<div class="presentation">
161';
162    }
163
164    /**
165     * Closes the document
166     */
167    function document_end(){
168        // we don't care for footnotes and toc
169        // but cleanup is nice
170        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
171
172        if($this->slideopen){
173            $this->doc .= '</div>'.DOKU_LF; //close previous slide
174        }
175        if($this->notesopen){
176            $this->doc .= '</div>'.DOKU_LF; //close notes
177            $this->notesopen = false;
178        }
179        $this->doc .= '</div>
180                       </body>
181                       </html>';
182    }
183
184    /**
185     * This is what creates new slides
186     *
187     * A new slide is started for each H2 header
188     */
189    function header($text, $level, $pos) {
190        if($level == 1){
191            if(!$this->slideopen){
192                $this->s5reloaded_init($text); // this is the first slide
193                $level = 2;
194            }else{
195                return;
196            }
197        }
198
199        if($level == 2){
200            if($this->notesopen){
201                $this->doc .= '</div>'.DOKU_LF; //close notes
202                $this->notesopen = false;
203	    }
204            $this->doc .= '<div class="slide">'.DOKU_LF;
205            $this->slideopen = true;
206        }
207        $this->doc .= '<h'.($level-1).'>';
208        $this->doc .= $this->_xmlEntities($text);
209        $this->doc .= '</h'.($level-1).'>'.DOKU_LF;
210    }
211
212    /**
213     * Top-Level Sections are slides
214     */
215    function section_open($level) {
216//        if($level < 3){
217//            $this->doc .= '<div class="slidecontent">'.DOKU_LF;
218//        }else{
219//            $this->doc .= '<div>'.DOKU_LF;
220//        }
221        // we don't use it
222    }
223
224    /**
225     * Throw away footnote
226     */
227    function footnote_close() {
228        // recover footnote into the stack and restore old content
229        $footnote = $this->doc;
230        $this->doc = $this->store;
231        $this->store = '';
232    }
233
234    /**
235     * No acronyms in a presentation
236     */
237    function acronym($acronym){
238        $this->doc .= $this->_xmlEntities($acronym);
239    }
240
241    /**
242     * A line stops the slide and start the handout section
243     */
244    function hr() {
245        $this->doc .= '<div class="notes">'.DOKU_LF;
246        $this->notesopen = true;
247    }
248
249    /**
250     * Renders internal and external media
251     */
252    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
253                      $height=NULL, $cache=NULL, $render = true) {
254
255        $ret = '';
256
257        list($ext,$mime,$dl) = mimetype($src);
258        if(substr($mime,0,5) == 'image'){
259            // first get the $title
260            if (!is_null($title)) {
261                $title  = $this->_xmlEntities($title);
262            }elseif($ext == 'jpg' || $ext == 'jpeg'){
263                //try to use the caption from IPTC/EXIF
264                require_once(DOKU_INC.'inc/JpegMeta.php');
265                $jpeg =& new JpegMeta(mediaFN($src));
266                if($jpeg !== false) $cap = $jpeg->getTitle();
267                if($cap){
268                    $title = $this->_xmlEntities($cap);
269                }
270            }
271            if (!$render) {
272                // if the picture is not supposed to be rendered
273                // return the title of the picture
274                if (!$title) {
275                    // just show the sourcename
276                    $title = $this->_xmlEntities(basename(noNS($src)));
277                }
278                return $title;
279            }
280            //add image tag
281            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
282            $ret .= ' class="scale"';
283
284            // make left/right alignment for no-CSS view work (feeds)
285            if($align == 'right') $ret .= ' align="right"';
286            if($align == 'left')  $ret .= ' align="left"';
287
288            if ($title) {
289                $ret .= ' title="' . $title . '"';
290                $ret .= ' alt="'   . $title .'"';
291            }else{
292                $ret .= ' alt=""';
293            }
294
295            if ( !is_null($width) )
296                $ret .= ' width="'.$this->_xmlEntities($width).'"';
297
298            if ( !is_null($height) )
299                $ret .= ' height="'.$this->_xmlEntities($height).'"';
300
301            $ret .= ' />';
302
303        }elseif($mime == 'application/x-shockwave-flash'){
304            if (!$render) {
305                // if the flash is not supposed to be rendered
306                // return the title of the flash
307                if (!$title) {
308                    // just show the sourcename
309                    $title = basename(noNS($src));
310                }
311                return $this->_xmlEntities($title);
312            }
313
314            $att = array();
315            $att['class'] = "media$align";
316            if($align == 'right') $att['align'] = 'right';
317            if($align == 'left')  $att['align'] = 'left';
318            $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height,
319                                     array('quality' => 'high'),
320                                     null,
321                                     $att,
322                                     $this->_xmlEntities($title));
323        }elseif($title){
324            // well at least we have a title to display
325            $ret .= $this->_xmlEntities($title);
326        }else{
327            // just show the sourcename
328            $ret .= $this->_xmlEntities(basename(noNS($src)));
329        }
330
331        return $ret;
332    }
333
334}
335
336//Setup VIM: ex: et ts=4 enc=utf-8 :
337