1<?php 2 3/** 4 * Timeline Action Plugin: Plain Text Renderer Component. 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author mukl 8 * @author Tom Cafferty <tcafferty@glocalfocal.com> 9 */ 10 11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12 13if ( !defined('DOKU_LF') ) { 14 define ('DOKU_LF',"\n"); 15} 16 17if ( !defined('DOKU_TAB') ) { 18 define ('DOKU_TAB',"\t"); 19} 20 21require_once DOKU_INC . 'inc/parser/renderer.php'; 22require_once DOKU_INC . 'inc/parser/xhtml.php'; 23 24/** 25 * The Renderer 26 * Provides plain text output for xml file input to Timeline app. 27 */ 28class Doku_Renderer_plain extends Doku_Renderer_xhtml { 29 30 var $base_url; 31 32 function set_base_url($url) { 33 $this->base_url = $url; 34 } 35 36 function getFormat() { 37 return 'plain'; 38 } 39 40 function document_start() { 41 } 42 43 function document_end() { 44 } 45 46 function cdata($text) { 47 $this->doc .= ' ' .$text . ' '; 48 } 49 50 function header($text, $level, $pos) { 51 $this->doc .= DOKU_LF . $text . DOKU_LF; 52 } 53 54 function preformatted($text) { 55 $this->doc .= ' ' . $text . ' '. DOKU_LF; 56 } 57 58 function file($text) { 59 $this->doc .= ' ' . $text . ' '. DOKU_LF; 60 } 61 62 function p_open() { 63 } 64 65 function p_close() { 66 } 67 68 function code($text, $language = NULL) { 69 $this->doc .= ' ' . $text . ' '. DOKU_LF; 70 } 71 72 function acronym($acronym) { 73 $this->doc .= ' ' . $acronym . ' '; 74 } 75 76 function smiley($smiley) { 77 $this->doc .= ' ' . $smiley . ' '; 78 } 79 80 function entity($entity) { 81 $this->doc .= ' ' . $entity . ' '; 82 } 83 84 function camelcaselink($link) { 85 $this->internallink($link,$link); 86 } 87 88 function locallink($hash, $name = NULL){ 89 $this->doc .= ' ' . $hash . ' '; 90 } 91 92 function externallink($url, $name = NULL) { 93 if ($name == NULL) 94 $this->doc .= ' ' . html_entity_decode($url, ENT_NOQUOTES) . ' '; 95 else 96 $this->doc .= ' <a href="' . html_entity_decode($url, ENT_NOQUOTES) . '">'.$name.'</a> '; 97 } 98 99 function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 100 $this->doc .= ' ' . $match . ' '; 101 } 102 103 function emaillink($address, $name = NULL) { 104 $this->doc .= ' ' . $address . ' '; 105 } 106 107 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 108 $height=NULL, $cache=NULL, $linking=NULL) { 109 global $ID; 110 list($src,$hash) = explode('#',$src,2); 111 resolve_mediaid(getNS($ID),$src, $exists); 112 113 $noLink = false; 114 $render = ($linking == 'linkonly') ? false : true; 115 $link = $this->getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 116 117 list($ext,$mime,$dl) = mimetype($src,false); 118 if($hash) $link['url'] .= '#'.$hash; 119 120 //output formatted 121 $this->doc .= $link['name']; 122 } 123 124 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 125 $height=NULL, $cache=NULL, $linking=NULL) { 126 $this->doc .= ' ' . $src . ' '; 127 } 128 129 function internallink($id, $name = NULL, $search=NULL,$returnonly=false) 130 { 131 global $conf; 132 global $ID; 133 134 $default = $id; 135 136 // now first resolve and clean up the $id 137 resolve_pageid(getNS($ID),$id,$exists); 138 $name = $this->_getLinkTitle($name, $default, $isImage, $id); 139 if ( !$isImage ) { 140 $class='wikilink1'; 141 } else { 142 $class='media'; 143 } 144 145 // don't keep hash anchor 146 $hash = ""; 147 148 //prepare for formating 149 $link['target'] = $conf['target']['wiki']; 150 $link['style'] = ''; 151 $link['pre'] = ''; 152 $link['suf'] = ''; 153 154 // highlight link to current page 155 if ($id == $ID) { 156 $link['pre'] = '<span class="curid">'; 157 $link['suf'] = '</span>'; 158 } 159 $link['more'] = ''; 160 $link['class'] = $class; 161 162 // make links 163 if ($class = 'wikilink2') { 164 $link['url'] = $this->base_url . $id; 165 } 166 else { 167 $link['url'] = $this->base_url . $id; 168 } 169 $link['name'] = $name; 170 $link['title'] = $id; 171 172 //add search string 173 if($search){ 174 ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 175 $link['url'] .= rawurlencode($search); 176 } 177 178 //keep hash 179 if($hash) $link['url'].='#'.$hash; 180 181 //output formatted 182 if($returnonly){ 183 return $this->_formatLink($link); 184 }else{ 185 $this->doc .= $this->_formatLink($link); 186 } 187 } 188 189 //---------------------------------------------------------- 190 // Utils 191 192 /** 193 * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 194 * which returns a basic link to a media. 195 * 196 * @author Pierre Spring <pierre.spring@liip.ch> 197 * @author Tom Cafferty <tcafferty@glocalfocal.com> 198 * @param string $src 199 * @param string $title 200 * @param string $align 201 * @param string $width 202 * @param string $height 203 * @param string $cache 204 * @param string $render 205 * @access protected 206 * @return array 207 */ 208 function getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 209 { 210 global $conf; 211 212 $link = array(); 213 $link['class'] = ''; 214 $link['style'] = ''; 215 $link['pre'] = ''; 216 $link['suf'] = ''; 217 $link['more'] = ''; 218 $link['target'] = ''; 219 $link['name'] = $this->timelineMedia($src, $title, $align, $width, $height, $cache, $render); 220 221 return $link; 222 } 223 224 /** 225 * Renders internal and external media 226 * 227 * @author Andreas Gohr <andi@splitbrain.org> 228 * @author Tom Caferty <tcafferty@glocalfocal.com> 229 */ 230 function timelineMedia ($src, $title=NULL, $align=NULL, $width=NULL, 231 $height=NULL, $cache=NULL, $render = true) { 232 233 $ret = ''; 234 235 list($ext,$mime,$dl) = mimetype($src); 236 if(substr($mime,0,5) == 'image'){ 237 // first get the $title 238 if (!is_null($title)) { 239 $title = $this->_xmlEntities($title); 240 }elseif($ext == 'jpg' || $ext == 'jpeg'){ 241 //try to use the caption from IPTC/EXIF 242 require_once(DOKU_INC.'inc/JpegMeta.php'); 243 $jpeg =new JpegMeta(mediaFN($src)); 244 if($jpeg !== false) $cap = $jpeg->getTitle(); 245 if($cap){ 246 $title = $this->_xmlEntities($cap); 247 } 248 } 249 if (!$render) { 250 // if the picture is not supposed to be rendered 251 // return the title of the picture 252 if (!$title) { 253 // just show the sourcename 254 $title = $this->_xmlEntities(basename(noNS($src))); 255 } 256 return $title; 257 } 258 //add image tag 259 $ret .= 'image="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 260 261 // make left/right alignment for no-CSS view work (feeds) 262 if($align == 'right') $ret .= ' align="right"'; 263 if($align == 'left') $ret .= ' align="left"'; 264 265 if ($title) 266 $ret .= ' title="' . $title . '"'; 267 268 if ( !is_null($width) ) 269 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 270 271 if ( !is_null($height) ) 272 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 273 274 275 }elseif($mime == 'application/x-shockwave-flash'){ 276 if (!$render) { 277 // if the flash is not supposed to be rendered 278 // return the title of the flash 279 if (!$title) { 280 // just show the sourcename 281 $title = basename(noNS($src)); 282 } 283 return $this->_xmlEntities($title); 284 } 285 286 $att = array(); 287 $att['class'] = "media$align"; 288 if($align == 'right') $att['align'] = 'right'; 289 if($align == 'left') $att['align'] = 'left'; 290 $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 291 array('quality' => 'high'), 292 null, 293 $att, 294 $this->_xmlEntities($title)); 295 }elseif($title){ 296 // well at least we have a title to display 297 $ret .= $this->_xmlEntities($title); 298 }else{ 299 // just show the sourcename 300 $ret .= $this->_xmlEntities(basename(noNS($src))); 301 } 302 303 return $ret; 304 } 305 306 307} 308 309