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