10cecf9d5Sandi<?php 2b625487dSandi/** 3b625487dSandi * Renderer for XHTML output 4b625487dSandi * 5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 7b625487dSandi */ 8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 90cecf9d5Sandi 100cecf9d5Sandiif ( !defined('DOKU_LF') ) { 110cecf9d5Sandi // Some whitespace to help View > Source 120cecf9d5Sandi define ('DOKU_LF',"\n"); 130cecf9d5Sandi} 140cecf9d5Sandi 150cecf9d5Sandiif ( !defined('DOKU_TAB') ) { 160cecf9d5Sandi // Some whitespace to help View > Source 170cecf9d5Sandi define ('DOKU_TAB',"\t"); 180cecf9d5Sandi} 190cecf9d5Sandi 200e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php'; 2156fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php'; 220e1c636eSandi 230cecf9d5Sandi/** 24b625487dSandi * The Renderer 250cecf9d5Sandi */ 26ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer { 270cecf9d5Sandi 28c5a8fd96SAndreas Gohr // @access public 29c5a8fd96SAndreas Gohr var $doc = ''; // will contain the whole document 30c5a8fd96SAndreas Gohr var $toc = array(); // will contain the Table of Contents 31c5a8fd96SAndreas Gohr 320cecf9d5Sandi 330cecf9d5Sandi var $headers = array(); 340cecf9d5Sandi var $footnotes = array(); 3591459163SAnika Henke var $lastlevel = 0; 3691459163SAnika Henke var $node = array(0,0,0,0,0); 377764a90aSandi var $store = ''; 387764a90aSandi 39b5742cedSPierre Spring var $_counter = array(); // used as global counter, introduced for table classes 403d491f75SAndreas Gohr var $_codeblock = 0; // counts the code and file blocks, used to provide download links 41b5742cedSPierre Spring 425f70445dSAndreas Gohr function getFormat(){ 435f70445dSAndreas Gohr return 'xhtml'; 445f70445dSAndreas Gohr } 455f70445dSAndreas Gohr 465f70445dSAndreas Gohr 470cecf9d5Sandi function document_start() { 48c5a8fd96SAndreas Gohr //reset some internals 49c5a8fd96SAndreas Gohr $this->toc = array(); 50c5a8fd96SAndreas Gohr $this->headers = array(); 510cecf9d5Sandi } 520cecf9d5Sandi 530cecf9d5Sandi function document_end() { 540cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 55a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 56d74aace9Schris 57d74aace9Schris $id = 0; 580cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 59d74aace9Schris $id++; // the number of the current footnote 60d74aace9Schris 61d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 62d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 63d74aace9Schris 64d74aace9Schris // open the footnote and set the anchor and backlink 65d74aace9Schris $this->doc .= '<div class="fn">'; 6629bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 6729bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 68d74aace9Schris 69d74aace9Schris // get any other footnotes that use the same markup 70d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 71d74aace9Schris 72d74aace9Schris if (count($alt)) { 73d74aace9Schris foreach ($alt as $ref) { 74d74aace9Schris // set anchor and backlink for the other footnotes 7529bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 7629bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 77d74aace9Schris } 78d74aace9Schris } 79d74aace9Schris 80d74aace9Schris // add footnote markup and close this footnote 81a2d649c4Sandi $this->doc .= $footnote; 82d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 83d74aace9Schris } 840cecf9d5Sandi } 85a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 860cecf9d5Sandi } 87c5a8fd96SAndreas Gohr 88b8595a66SAndreas Gohr // Prepare the TOC 89851f2e89SAnika Henke global $conf; 90851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 91b8595a66SAndreas Gohr global $TOC; 92b8595a66SAndreas Gohr $TOC = $this->toc; 930cecf9d5Sandi } 943e55d035SAndreas Gohr 953e55d035SAndreas Gohr // make sure there are no empty paragraphs 9627918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 97e41c4da9SAndreas Gohr } 980cecf9d5Sandi 99e7856beaSchris function toc_additem($id, $text, $level) { 100af587fa8Sandi global $conf; 101af587fa8Sandi 102c5a8fd96SAndreas Gohr //handle TOC 103c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1047d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 105c5a8fd96SAndreas Gohr } 106e7856beaSchris } 107e7856beaSchris 108e7856beaSchris function header($text, $level, $pos) { 109bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 110e7856beaSchris 111e7856beaSchris $hid = $this->_headerToLink($text,true); 112e7856beaSchris 113e7856beaSchris //only add items within configured levels 114e7856beaSchris $this->toc_additem($hid, $text, $level); 115c5a8fd96SAndreas Gohr 11691459163SAnika Henke // adjust $node to reflect hierarchy of levels 11791459163SAnika Henke $this->node[$level-1]++; 11891459163SAnika Henke if ($level < $this->lastlevel) { 11991459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 12091459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 12191459163SAnika Henke } 12291459163SAnika Henke } 12391459163SAnika Henke $this->lastlevel = $level; 12491459163SAnika Henke 125c5a8fd96SAndreas Gohr // write the header 126c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 127a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 12859869a4bSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1290cecf9d5Sandi } 1300cecf9d5Sandi 13135dae8b0SBen Coburn /** 13235dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 13335dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 13435dae8b0SBen Coburn * 13535dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 13635dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 13735dae8b0SBen Coburn */ 13835dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 13935dae8b0SBen Coburn global $conf; 14035dae8b0SBen Coburn 14135dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 14235dae8b0SBen Coburn $name = str_replace('"', '', $name); 14335dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 14435dae8b0SBen Coburn } 14535dae8b0SBen Coburn } 14635dae8b0SBen Coburn 1470cecf9d5Sandi function section_open($level) { 148a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1490cecf9d5Sandi } 1500cecf9d5Sandi 1510cecf9d5Sandi function section_close() { 152a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1530cecf9d5Sandi } 1540cecf9d5Sandi 1550cecf9d5Sandi function cdata($text) { 156a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1570cecf9d5Sandi } 1580cecf9d5Sandi 1590cecf9d5Sandi function p_open() { 16059869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1610cecf9d5Sandi } 1620cecf9d5Sandi 1630cecf9d5Sandi function p_close() { 16459869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1650cecf9d5Sandi } 1660cecf9d5Sandi 1670cecf9d5Sandi function linebreak() { 168a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1690cecf9d5Sandi } 1700cecf9d5Sandi 1710cecf9d5Sandi function hr() { 1724beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1730cecf9d5Sandi } 1740cecf9d5Sandi 1750cecf9d5Sandi function strong_open() { 176a2d649c4Sandi $this->doc .= '<strong>'; 1770cecf9d5Sandi } 1780cecf9d5Sandi 1790cecf9d5Sandi function strong_close() { 180a2d649c4Sandi $this->doc .= '</strong>'; 1810cecf9d5Sandi } 1820cecf9d5Sandi 1830cecf9d5Sandi function emphasis_open() { 184a2d649c4Sandi $this->doc .= '<em>'; 1850cecf9d5Sandi } 1860cecf9d5Sandi 1870cecf9d5Sandi function emphasis_close() { 188a2d649c4Sandi $this->doc .= '</em>'; 1890cecf9d5Sandi } 1900cecf9d5Sandi 1910cecf9d5Sandi function underline_open() { 19202e51121SAnika Henke $this->doc .= '<em class="u">'; 1930cecf9d5Sandi } 1940cecf9d5Sandi 1950cecf9d5Sandi function underline_close() { 19602e51121SAnika Henke $this->doc .= '</em>'; 1970cecf9d5Sandi } 1980cecf9d5Sandi 1990cecf9d5Sandi function monospace_open() { 200a2d649c4Sandi $this->doc .= '<code>'; 2010cecf9d5Sandi } 2020cecf9d5Sandi 2030cecf9d5Sandi function monospace_close() { 204a2d649c4Sandi $this->doc .= '</code>'; 2050cecf9d5Sandi } 2060cecf9d5Sandi 2070cecf9d5Sandi function subscript_open() { 208a2d649c4Sandi $this->doc .= '<sub>'; 2090cecf9d5Sandi } 2100cecf9d5Sandi 2110cecf9d5Sandi function subscript_close() { 212a2d649c4Sandi $this->doc .= '</sub>'; 2130cecf9d5Sandi } 2140cecf9d5Sandi 2150cecf9d5Sandi function superscript_open() { 216a2d649c4Sandi $this->doc .= '<sup>'; 2170cecf9d5Sandi } 2180cecf9d5Sandi 2190cecf9d5Sandi function superscript_close() { 220a2d649c4Sandi $this->doc .= '</sup>'; 2210cecf9d5Sandi } 2220cecf9d5Sandi 2230cecf9d5Sandi function deleted_open() { 224a2d649c4Sandi $this->doc .= '<del>'; 2250cecf9d5Sandi } 2260cecf9d5Sandi 2270cecf9d5Sandi function deleted_close() { 228a2d649c4Sandi $this->doc .= '</del>'; 2290cecf9d5Sandi } 2300cecf9d5Sandi 2313fd0b676Sandi /** 2323fd0b676Sandi * Callback for footnote start syntax 2333fd0b676Sandi * 2343fd0b676Sandi * All following content will go to the footnote instead of 235d74aace9Schris * the document. To achieve this the previous rendered content 2363fd0b676Sandi * is moved to $store and $doc is cleared 2373fd0b676Sandi * 2383fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2393fd0b676Sandi */ 2400cecf9d5Sandi function footnote_open() { 2417764a90aSandi 2427764a90aSandi // move current content to store and record footnote 2437764a90aSandi $this->store = $this->doc; 2447764a90aSandi $this->doc = ''; 2450cecf9d5Sandi } 2460cecf9d5Sandi 2473fd0b676Sandi /** 2483fd0b676Sandi * Callback for footnote end syntax 2493fd0b676Sandi * 2503fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2513fd0b676Sandi * content is restored from $store again 2523fd0b676Sandi * 2533fd0b676Sandi * @author Andreas Gohr 2543fd0b676Sandi */ 2550cecf9d5Sandi function footnote_close() { 2567764a90aSandi 257d74aace9Schris // recover footnote into the stack and restore old content 258d74aace9Schris $footnote = $this->doc; 2597764a90aSandi $this->doc = $this->store; 2607764a90aSandi $this->store = ''; 261d74aace9Schris 262d74aace9Schris // check to see if this footnote has been seen before 263d74aace9Schris $i = array_search($footnote, $this->footnotes); 264d74aace9Schris 265d74aace9Schris if ($i === false) { 266d74aace9Schris // its a new footnote, add it to the $footnotes array 267d74aace9Schris $id = count($this->footnotes)+1; 268d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 269d74aace9Schris } else { 270d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 271d74aace9Schris $i++; 272d74aace9Schris $id = count($this->footnotes)+1; 273d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 274d74aace9Schris } 275d74aace9Schris 2766b379cbfSAndreas Gohr // output the footnote reference and link 27729bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 2780cecf9d5Sandi } 2790cecf9d5Sandi 2800cecf9d5Sandi function listu_open() { 281a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2820cecf9d5Sandi } 2830cecf9d5Sandi 2840cecf9d5Sandi function listu_close() { 285a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 2860cecf9d5Sandi } 2870cecf9d5Sandi 2880cecf9d5Sandi function listo_open() { 289a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 2900cecf9d5Sandi } 2910cecf9d5Sandi 2920cecf9d5Sandi function listo_close() { 293a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 2940cecf9d5Sandi } 2950cecf9d5Sandi 2960cecf9d5Sandi function listitem_open($level) { 29759869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 2980cecf9d5Sandi } 2990cecf9d5Sandi 3000cecf9d5Sandi function listitem_close() { 301a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3020cecf9d5Sandi } 3030cecf9d5Sandi 3040cecf9d5Sandi function listcontent_open() { 30590db23d7Schris $this->doc .= '<div class="li">'; 3060cecf9d5Sandi } 3070cecf9d5Sandi 3080cecf9d5Sandi function listcontent_close() { 30959869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3100cecf9d5Sandi } 3110cecf9d5Sandi 3120cecf9d5Sandi function unformatted($text) { 313a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3140cecf9d5Sandi } 3150cecf9d5Sandi 3160cecf9d5Sandi /** 3173fd0b676Sandi * Execute PHP code if allowed 3183fd0b676Sandi * 3195d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3205d568b99SChris Smith * 3213fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3220cecf9d5Sandi */ 3235d568b99SChris Smith function php($text, $wrapper='code') { 32435a56260SChris Smith global $conf; 32535a56260SChris Smith 326d86d5af0SChris Smith if($conf['phpok']){ 327bad0b545Sandi ob_start(); 3284de671bcSandi eval($text); 3293fd0b676Sandi $this->doc .= ob_get_contents(); 330bad0b545Sandi ob_end_clean(); 331d86d5af0SChris Smith } else { 3325d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 333d86d5af0SChris Smith } 3340cecf9d5Sandi } 3350cecf9d5Sandi 33607f89c3cSAnika Henke function phpblock($text) { 3375d568b99SChris Smith $this->php($text, 'pre'); 33807f89c3cSAnika Henke } 33907f89c3cSAnika Henke 3400cecf9d5Sandi /** 3413fd0b676Sandi * Insert HTML if allowed 3423fd0b676Sandi * 3435d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3445d568b99SChris Smith * 3453fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3460cecf9d5Sandi */ 3475d568b99SChris Smith function html($text, $wrapper='code') { 34835a56260SChris Smith global $conf; 34935a56260SChris Smith 350d86d5af0SChris Smith if($conf['htmlok']){ 351a2d649c4Sandi $this->doc .= $text; 352d86d5af0SChris Smith } else { 3535d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 354d86d5af0SChris Smith } 3554de671bcSandi } 3560cecf9d5Sandi 35707f89c3cSAnika Henke function htmlblock($text) { 3585d568b99SChris Smith $this->html($text, 'pre'); 35907f89c3cSAnika Henke } 36007f89c3cSAnika Henke 3610cecf9d5Sandi function quote_open() { 36296331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3630cecf9d5Sandi } 3640cecf9d5Sandi 3650cecf9d5Sandi function quote_close() { 36696331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3670cecf9d5Sandi } 3680cecf9d5Sandi 3693d491f75SAndreas Gohr function preformatted($text) { 370c9250713SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 3713d491f75SAndreas Gohr } 3723d491f75SAndreas Gohr 3733d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 3743d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 3753d491f75SAndreas Gohr } 3763d491f75SAndreas Gohr 3773d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 3783d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 3793d491f75SAndreas Gohr } 3803d491f75SAndreas Gohr 3810cecf9d5Sandi /** 3823d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 3833fd0b676Sandi * 3843fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3850cecf9d5Sandi */ 3863d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 3874de671bcSandi global $conf; 3883d491f75SAndreas Gohr global $ID; 3893d491f75SAndreas Gohr global $lang; 3903d491f75SAndreas Gohr 3913d491f75SAndreas Gohr if($filename){ 392190c56e8SAndreas Gohr // add icon 39327bf7924STom N Harris list($ext) = mimetype($filename,false); 394190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 395190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 396190c56e8SAndreas Gohr 3973d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 398190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 3993d491f75SAndreas Gohr $this->doc .= hsc($filename); 4003d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 4013d491f75SAndreas Gohr } 4020cecf9d5Sandi 4030cecf9d5Sandi if ( is_null($language) ) { 4043d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4050cecf9d5Sandi } else { 4063d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4073d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4083d491f75SAndreas Gohr 4093d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4100cecf9d5Sandi } 4113d491f75SAndreas Gohr 4123d491f75SAndreas Gohr if($filename){ 4133d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4143d491f75SAndreas Gohr } 4153d491f75SAndreas Gohr 4163d491f75SAndreas Gohr $this->_codeblock++; 4170cecf9d5Sandi } 4180cecf9d5Sandi 4190cecf9d5Sandi function acronym($acronym) { 4200cecf9d5Sandi 4210cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4220cecf9d5Sandi 423433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4240cecf9d5Sandi 425a2d649c4Sandi $this->doc .= '<acronym title="'.$title 426433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4270cecf9d5Sandi 4280cecf9d5Sandi } else { 429a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4300cecf9d5Sandi } 4310cecf9d5Sandi } 4320cecf9d5Sandi 4330cecf9d5Sandi function smiley($smiley) { 4340cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 435433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 436f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4374beabca9SAnika Henke '" class="middle" alt="'. 438433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4390cecf9d5Sandi } else { 440a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4410cecf9d5Sandi } 4420cecf9d5Sandi } 4430cecf9d5Sandi 444f62ea8a1Sandi /* 4454de671bcSandi * not used 4460cecf9d5Sandi function wordblock($word) { 4470cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 448a2d649c4Sandi $this->doc .= '** BLEEP **'; 4490cecf9d5Sandi } else { 450a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4510cecf9d5Sandi } 4520cecf9d5Sandi } 4534de671bcSandi */ 4540cecf9d5Sandi 4550cecf9d5Sandi function entity($entity) { 4560cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 457a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4580cecf9d5Sandi } else { 459a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4600cecf9d5Sandi } 4610cecf9d5Sandi } 4620cecf9d5Sandi 4630cecf9d5Sandi function multiplyentity($x, $y) { 464a2d649c4Sandi $this->doc .= "$x×$y"; 4650cecf9d5Sandi } 4660cecf9d5Sandi 4670cecf9d5Sandi function singlequoteopening() { 46871b40da2SAnika Henke global $lang; 46971b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4700cecf9d5Sandi } 4710cecf9d5Sandi 4720cecf9d5Sandi function singlequoteclosing() { 47371b40da2SAnika Henke global $lang; 47471b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4750cecf9d5Sandi } 4760cecf9d5Sandi 47757d757d1SAndreas Gohr function apostrophe() { 47857d757d1SAndreas Gohr global $lang; 479a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 48057d757d1SAndreas Gohr } 48157d757d1SAndreas Gohr 4820cecf9d5Sandi function doublequoteopening() { 48371b40da2SAnika Henke global $lang; 48471b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4850cecf9d5Sandi } 4860cecf9d5Sandi 4870cecf9d5Sandi function doublequoteclosing() { 48871b40da2SAnika Henke global $lang; 48971b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4900cecf9d5Sandi } 4910cecf9d5Sandi 4920cecf9d5Sandi /** 4930cecf9d5Sandi */ 4940cecf9d5Sandi function camelcaselink($link) { 49511d0aa47Sandi $this->internallink($link,$link); 4960cecf9d5Sandi } 4970cecf9d5Sandi 4980b7c14c2Sandi 4990b7c14c2Sandi function locallink($hash, $name = NULL){ 5000b7c14c2Sandi global $ID; 5010b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5020b7c14c2Sandi $hash = $this->_headerToLink($hash); 5030b7c14c2Sandi $title = $ID.' ↵'; 5040b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5050b7c14c2Sandi $this->doc .= $name; 5060b7c14c2Sandi $this->doc .= '</a>'; 5070b7c14c2Sandi } 5080b7c14c2Sandi 509cffcc403Sandi /** 5103fd0b676Sandi * Render an internal Wiki Link 5113fd0b676Sandi * 512fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 513cffcc403Sandi * elsewhere - no need to implement them in other renderers 5143fd0b676Sandi * 5153fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 516cffcc403Sandi */ 517fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 518ba11bd29Sandi global $conf; 51937e34a5eSandi global $ID; 5200339c872Sjan // default name is based on $id as given 5210339c872Sjan $default = $this->_simpleTitle($id); 522ad32e47eSAndreas Gohr 5230339c872Sjan // now first resolve and clean up the $id 52437e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 525fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5260e1c636eSandi if ( !$isImage ) { 5270e1c636eSandi if ( $exists ) { 528ba11bd29Sandi $class='wikilink1'; 5290cecf9d5Sandi } else { 530ba11bd29Sandi $class='wikilink2'; 53144a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5320cecf9d5Sandi } 5330cecf9d5Sandi } else { 534ba11bd29Sandi $class='media'; 5350cecf9d5Sandi } 5360cecf9d5Sandi 537a1685bedSandi //keep hash anchor 538ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 539943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 540a1685bedSandi 541ba11bd29Sandi //prepare for formating 542ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 543ba11bd29Sandi $link['style'] = ''; 544ba11bd29Sandi $link['pre'] = ''; 545ba11bd29Sandi $link['suf'] = ''; 54640eb54bbSjan // highlight link to current page 54740eb54bbSjan if ($id == $ID) { 54892795d04Sandi $link['pre'] = '<span class="curid">'; 54992795d04Sandi $link['suf'] = '</span>'; 55040eb54bbSjan } 5515e163278SAndreas Gohr $link['more'] = ''; 552ba11bd29Sandi $link['class'] = $class; 553ba11bd29Sandi $link['url'] = wl($id); 554ba11bd29Sandi $link['name'] = $name; 555ba11bd29Sandi $link['title'] = $id; 556723d78dbSandi //add search string 557723d78dbSandi if($search){ 558546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 559546d3a99SAndreas Gohr if(is_array($search)){ 560546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 561546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 562546d3a99SAndreas Gohr }else{ 563546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 564546d3a99SAndreas Gohr } 565723d78dbSandi } 566723d78dbSandi 567a1685bedSandi //keep hash 568a1685bedSandi if($hash) $link['url'].='#'.$hash; 569a1685bedSandi 570ba11bd29Sandi //output formatted 571cffcc403Sandi if($returnonly){ 572cffcc403Sandi return $this->_formatLink($link); 573cffcc403Sandi }else{ 574a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5750cecf9d5Sandi } 576cffcc403Sandi } 5770cecf9d5Sandi 578b625487dSandi function externallink($url, $name = NULL) { 579b625487dSandi global $conf; 5800cecf9d5Sandi 581433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5826f0c5dbfSandi 5830cecf9d5Sandi if ( !$isImage ) { 584b625487dSandi $class='urlextern'; 5850cecf9d5Sandi } else { 586b625487dSandi $class='media'; 5870cecf9d5Sandi } 5880cecf9d5Sandi 589b625487dSandi //prepare for formating 590b625487dSandi $link['target'] = $conf['target']['extern']; 591b625487dSandi $link['style'] = ''; 592b625487dSandi $link['pre'] = ''; 593b625487dSandi $link['suf'] = ''; 5945e163278SAndreas Gohr $link['more'] = ''; 595b625487dSandi $link['class'] = $class; 596b625487dSandi $link['url'] = $url; 597e1c10e4dSchris 598b625487dSandi $link['name'] = $name; 599433bef32Sandi $link['title'] = $this->_xmlEntities($url); 600b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6010cecf9d5Sandi 602b625487dSandi //output formatted 603a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6040cecf9d5Sandi } 6050cecf9d5Sandi 6060cecf9d5Sandi /** 6070cecf9d5Sandi */ 60897a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 609b625487dSandi global $conf; 6100cecf9d5Sandi 61197a3e4e3Sandi $link = array(); 61297a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 61397a3e4e3Sandi $link['pre'] = ''; 61497a3e4e3Sandi $link['suf'] = ''; 6155e163278SAndreas Gohr $link['more'] = ''; 616433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6170cecf9d5Sandi 61897a3e4e3Sandi //get interwiki URL 6191f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6200cecf9d5Sandi 62197a3e4e3Sandi if ( !$isImage ) { 6229d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6239d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6241c2d1019SAndreas Gohr } else { 6251c2d1019SAndreas Gohr $link['class'] = 'media'; 62697a3e4e3Sandi } 6270cecf9d5Sandi 62897a3e4e3Sandi //do we stay at the same server? Use local target 62997a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 63097a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 63197a3e4e3Sandi } 6320cecf9d5Sandi 63397a3e4e3Sandi $link['url'] = $url; 63497a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 63597a3e4e3Sandi 63697a3e4e3Sandi //output formatted 637a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6380cecf9d5Sandi } 6390cecf9d5Sandi 6400cecf9d5Sandi /** 6410cecf9d5Sandi */ 6421d47afe1Sandi function windowssharelink($url, $name = NULL) { 6431d47afe1Sandi global $conf; 6441d47afe1Sandi global $lang; 6451d47afe1Sandi //simple setup 6461d47afe1Sandi $link['target'] = $conf['target']['windows']; 6471d47afe1Sandi $link['pre'] = ''; 6481d47afe1Sandi $link['suf'] = ''; 6491d47afe1Sandi $link['style'] = ''; 6500cecf9d5Sandi 651433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6520cecf9d5Sandi if ( !$isImage ) { 6531d47afe1Sandi $link['class'] = 'windows'; 6540cecf9d5Sandi } else { 6551d47afe1Sandi $link['class'] = 'media'; 6560cecf9d5Sandi } 6570cecf9d5Sandi 6580cecf9d5Sandi 659433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6601d47afe1Sandi $url = str_replace('\\','/',$url); 6611d47afe1Sandi $url = 'file:///'.$url; 6621d47afe1Sandi $link['url'] = $url; 6630cecf9d5Sandi 6641d47afe1Sandi //output formatted 665a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6660cecf9d5Sandi } 6670cecf9d5Sandi 66871352defSandi function emaillink($address, $name = NULL) { 66971352defSandi global $conf; 67071352defSandi //simple setup 67171352defSandi $link = array(); 67271352defSandi $link['target'] = ''; 67371352defSandi $link['pre'] = ''; 67471352defSandi $link['suf'] = ''; 67571352defSandi $link['style'] = ''; 67671352defSandi $link['more'] = ''; 6770cecf9d5Sandi 678c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 6790cecf9d5Sandi if ( !$isImage ) { 680776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6810cecf9d5Sandi } else { 682776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6830cecf9d5Sandi } 6840cecf9d5Sandi 68507738714SAndreas Gohr $address = $this->_xmlEntities($address); 68600a7b5adSEsther Brunner $address = obfuscate($address); 68700a7b5adSEsther Brunner $title = $address; 6888c128049SAndreas Gohr 68971352defSandi if(empty($name)){ 69000a7b5adSEsther Brunner $name = $address; 69171352defSandi } 6920cecf9d5Sandi 693776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 694776b36ecSAndreas Gohr 695776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 69671352defSandi $link['name'] = $name; 69771352defSandi $link['title'] = $title; 6980cecf9d5Sandi 69971352defSandi //output formatted 700a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7010cecf9d5Sandi } 7020cecf9d5Sandi 7034826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 704dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 70537e34a5eSandi global $ID; 70691df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 70737e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7080cecf9d5Sandi 709d98d4540SBen Coburn $noLink = false; 7108acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 711b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7123685f775Sandi 71327bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 714b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 715dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7161c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7172ca14335SEsther Brunner // don't link flash movies 71844881bd0Shenning.noren $noLink = true; 71955efc227SAndreas Gohr }else{ 7202ca14335SEsther Brunner // add file icons 7219d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7229d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7236de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 72455efc227SAndreas Gohr } 7253685f775Sandi 72691df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 72791df343aSAndreas Gohr 7286fe20453SGina Haeussge //markup non existing files 7296fe20453SGina Haeussge if (!$exists) 7306fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7316fe20453SGina Haeussge 7323685f775Sandi //output formatted 733dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7342ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7350cecf9d5Sandi } 7360cecf9d5Sandi 7374826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 738dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 73991df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 740d98d4540SBen Coburn $noLink = false; 7418acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 742b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 743b739ff0fSPierre Spring 744b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7453685f775Sandi 74627bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 747b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7482ca14335SEsther Brunner // link only jpeg images 74944881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7501c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7512ca14335SEsther Brunner // don't link flash movies 75244881bd0Shenning.noren $noLink = true; 7532ca14335SEsther Brunner }else{ 7542ca14335SEsther Brunner // add file icons 75527bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 75627bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 7572ca14335SEsther Brunner } 7582ca14335SEsther Brunner 75991df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 76091df343aSAndreas Gohr 7613685f775Sandi //output formatted 762dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7632ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7640cecf9d5Sandi } 7650cecf9d5Sandi 7664826ab45Sandi /** 7673db95becSAndreas Gohr * Renders an RSS feed 768b625487dSandi * 769b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 770b625487dSandi */ 7713db95becSAndreas Gohr function rss ($url,$params){ 772b625487dSandi global $lang; 7733db95becSAndreas Gohr global $conf; 7743db95becSAndreas Gohr 7753db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7763db95becSAndreas Gohr $feed = new FeedParser(); 77700077af8SAndreas Gohr $feed->set_feed_url($url); 778b625487dSandi 779b625487dSandi //disable warning while fetching 780bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7813db95becSAndreas Gohr $rc = $feed->init(); 782bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 783b625487dSandi 7843db95becSAndreas Gohr //decide on start and end 7853db95becSAndreas Gohr if($params['reverse']){ 7863db95becSAndreas Gohr $mod = -1; 7873db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7883db95becSAndreas Gohr $end = $start - ($params['max']); 789b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7903db95becSAndreas Gohr }else{ 7913db95becSAndreas Gohr $mod = 1; 7923db95becSAndreas Gohr $start = 0; 7933db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7943db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7953db95becSAndreas Gohr } 7963db95becSAndreas Gohr 797a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7983db95becSAndreas Gohr if($rc){ 7993db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8001bde1582SAndreas Gohr $item = $feed->get_item($x); 8013db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 802d2ea3363SAndreas Gohr // support feeds without links 803d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 804d2ea3363SAndreas Gohr if($lnkurl){ 805793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 806793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8071bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 808793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 809d2ea3363SAndreas Gohr }else{ 810d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 811d2ea3363SAndreas Gohr } 8123db95becSAndreas Gohr if($params['author']){ 8131bde1582SAndreas Gohr $author = $item->get_author(0); 8141bde1582SAndreas Gohr if($author){ 8151bde1582SAndreas Gohr $name = $author->get_name(); 8161bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8171bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8181bde1582SAndreas Gohr } 8193db95becSAndreas Gohr } 8203db95becSAndreas Gohr if($params['date']){ 8212e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8223db95becSAndreas Gohr } 8231bde1582SAndreas Gohr if($params['details']){ 8243db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 825173dccb7STom N Harris if($conf['htmlok']){ 8261bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8273db95becSAndreas Gohr }else{ 8281bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8293db95becSAndreas Gohr } 8303db95becSAndreas Gohr $this->doc .= '</div>'; 8313db95becSAndreas Gohr } 8323db95becSAndreas Gohr 8333db95becSAndreas Gohr $this->doc .= '</div></li>'; 834b625487dSandi } 835b625487dSandi }else{ 8363db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 837a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 838b625487dSandi $this->externallink($url); 83945e147ccSAndreas Gohr if($conf['allowdebug']){ 84045e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 84145e147ccSAndreas Gohr } 8423db95becSAndreas Gohr $this->doc .= '</div></li>'; 843b625487dSandi } 844a2d649c4Sandi $this->doc .= '</ul>'; 845b625487dSandi } 846b625487dSandi 8470cecf9d5Sandi // $numrows not yet implemented 8480cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 849b5742cedSPierre Spring // initialize the row counter used for classes 850b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 85159869a4bSAnika Henke $this->doc .= '<table class="inline">'.DOKU_LF; 8520cecf9d5Sandi } 8530cecf9d5Sandi 8540cecf9d5Sandi function table_close(){ 85559869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8560cecf9d5Sandi } 8570cecf9d5Sandi 8580cecf9d5Sandi function tablerow_open(){ 859b5742cedSPierre Spring // initialize the cell counter used for classes 860b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 861b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 862b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8630cecf9d5Sandi } 8640cecf9d5Sandi 8650cecf9d5Sandi function tablerow_close(){ 866a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8670cecf9d5Sandi } 8680cecf9d5Sandi 86925b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 870b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8710cecf9d5Sandi if ( !is_null($align) ) { 872b5742cedSPierre Spring $class .= ' '.$align.'align'; 8730cecf9d5Sandi } 874b5742cedSPierre Spring $class .= '"'; 875b5742cedSPierre Spring $this->doc .= '<th ' . $class; 8760cecf9d5Sandi if ( $colspan > 1 ) { 877a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 878a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8790cecf9d5Sandi } 88025b97867Shakan.sandell if ( $rowspan > 1 ) { 88125b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 88225b97867Shakan.sandell } 883a2d649c4Sandi $this->doc .= '>'; 8840cecf9d5Sandi } 8850cecf9d5Sandi 8860cecf9d5Sandi function tableheader_close(){ 887a2d649c4Sandi $this->doc .= '</th>'; 8880cecf9d5Sandi } 8890cecf9d5Sandi 89025b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 891b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8920cecf9d5Sandi if ( !is_null($align) ) { 893b5742cedSPierre Spring $class .= ' '.$align.'align'; 8940cecf9d5Sandi } 895b5742cedSPierre Spring $class .= '"'; 896b5742cedSPierre Spring $this->doc .= '<td '.$class; 8970cecf9d5Sandi if ( $colspan > 1 ) { 898a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 899a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9000cecf9d5Sandi } 90125b97867Shakan.sandell if ( $rowspan > 1 ) { 90225b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 90325b97867Shakan.sandell } 904a2d649c4Sandi $this->doc .= '>'; 9050cecf9d5Sandi } 9060cecf9d5Sandi 9070cecf9d5Sandi function tablecell_close(){ 908a2d649c4Sandi $this->doc .= '</td>'; 9090cecf9d5Sandi } 9100cecf9d5Sandi 9110cecf9d5Sandi //---------------------------------------------------------- 9120cecf9d5Sandi // Utils 9130cecf9d5Sandi 914ba11bd29Sandi /** 9153fd0b676Sandi * Build a link 9163fd0b676Sandi * 9173fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 918ba11bd29Sandi * 919ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 920ba11bd29Sandi */ 921433bef32Sandi function _formatLink($link){ 922ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 923ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 924ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 925ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 926ba11bd29Sandi } 927ba11bd29Sandi //remove double encodings in titles 928ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 929ba11bd29Sandi 930453493f2SAndreas Gohr // be sure there are no bad chars in url or title 931453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 932453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 933453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 934453493f2SAndreas Gohr 935ba11bd29Sandi $ret = ''; 936ba11bd29Sandi $ret .= $link['pre']; 937ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 938bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 939bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 940bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 941bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 94244a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 943bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 944ba11bd29Sandi $ret .= '>'; 945ba11bd29Sandi $ret .= $link['name']; 946ba11bd29Sandi $ret .= '</a>'; 947ba11bd29Sandi $ret .= $link['suf']; 948ba11bd29Sandi return $ret; 949ba11bd29Sandi } 950ba11bd29Sandi 951ba11bd29Sandi /** 9523fd0b676Sandi * Renders internal and external media 9533fd0b676Sandi * 9543fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9553fd0b676Sandi */ 9563fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 957b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9583fd0b676Sandi 9593fd0b676Sandi $ret = ''; 9603fd0b676Sandi 961ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 9623fd0b676Sandi if(substr($mime,0,5) == 'image'){ 963b739ff0fSPierre Spring // first get the $title 964b739ff0fSPierre Spring if (!is_null($title)) { 965b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 966b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 967b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 968b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 969b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 970b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 971b739ff0fSPierre Spring if($cap){ 972b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 973b739ff0fSPierre Spring } 974b739ff0fSPierre Spring } 975b739ff0fSPierre Spring if (!$render) { 976b739ff0fSPierre Spring // if the picture is not supposed to be rendered 977b739ff0fSPierre Spring // return the title of the picture 978b739ff0fSPierre Spring if (!$title) { 979b739ff0fSPierre Spring // just show the sourcename 980b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 981b739ff0fSPierre Spring } 982b739ff0fSPierre Spring return $title; 983b739ff0fSPierre Spring } 9843fd0b676Sandi //add image tag 9856de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9863fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9873fd0b676Sandi 9884ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 9894ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 9904ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 9914ab889eaSAndreas Gohr 992b739ff0fSPierre Spring if ($title) { 993b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 994b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 9953fd0b676Sandi }else{ 9963fd0b676Sandi $ret .= ' alt=""'; 9973fd0b676Sandi } 9983fd0b676Sandi 9993fd0b676Sandi if ( !is_null($width) ) 10003fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10013fd0b676Sandi 10023fd0b676Sandi if ( !is_null($height) ) 10033fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10043fd0b676Sandi 10053fd0b676Sandi $ret .= ' />'; 10063fd0b676Sandi 10073fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10081c882ba8SAndreas Gohr if (!$render) { 10091c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10101c882ba8SAndreas Gohr // return the title of the flash 10111c882ba8SAndreas Gohr if (!$title) { 10121c882ba8SAndreas Gohr // just show the sourcename 101307bf32b2SAndreas Gohr $title = basename(noNS($src)); 10141c882ba8SAndreas Gohr } 101507bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10161c882ba8SAndreas Gohr } 10171c882ba8SAndreas Gohr 101807bf32b2SAndreas Gohr $att = array(); 101907bf32b2SAndreas Gohr $att['class'] = "media$align"; 102007bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 102107bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1022*c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 102307bf32b2SAndreas Gohr array('quality' => 'high'), 102407bf32b2SAndreas Gohr null, 102507bf32b2SAndreas Gohr $att, 102607bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10270f428d7dSAndreas Gohr }elseif($title){ 10283fd0b676Sandi // well at least we have a title to display 10293fd0b676Sandi $ret .= $this->_xmlEntities($title); 10303fd0b676Sandi }else{ 10315291ca3aSAndreas Gohr // just show the sourcename 10320f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10333fd0b676Sandi } 10343fd0b676Sandi 10353fd0b676Sandi return $ret; 10363fd0b676Sandi } 10373fd0b676Sandi 1038433bef32Sandi function _xmlEntities($string) { 1039de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10400cecf9d5Sandi } 10410cecf9d5Sandi 10428a831f2bSAndreas Gohr /** 10438a831f2bSAndreas Gohr * Creates a linkid from a headline 1044c5a8fd96SAndreas Gohr * 1045c5a8fd96SAndreas Gohr * @param string $title The headline title 1046c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1047c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10488a831f2bSAndreas Gohr */ 1049c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1050c5a8fd96SAndreas Gohr if($create){ 10514ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10524ceab83fSAndreas Gohr }else{ 1053443d207bSAndreas Gohr $check = false; 1054443d207bSAndreas Gohr return sectionID($title,$check); 1055c5a8fd96SAndreas Gohr } 10560cecf9d5Sandi } 10570cecf9d5Sandi 1058af587fa8Sandi /** 10593fd0b676Sandi * Construct a title and handle images in titles 10603fd0b676Sandi * 10610b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10623fd0b676Sandi */ 1063fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1064bb0a59d4Sjan global $conf; 1065bb0a59d4Sjan 106644881bd0Shenning.noren $isImage = false; 106729657f9eSAndreas Gohr if ( is_array($title) ) { 106829657f9eSAndreas Gohr $isImage = true; 106929657f9eSAndreas Gohr return $this->_imageTitle($title); 107029657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1071fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1072fc18c0fbSchris $heading = p_get_first_heading($id,true); 1073bb0a59d4Sjan if ($heading) { 1074433bef32Sandi return $this->_xmlEntities($heading); 1075bb0a59d4Sjan } 1076bb0a59d4Sjan } 1077433bef32Sandi return $this->_xmlEntities($default); 107868c26e6dSMichael Klier } else { 107968c26e6dSMichael Klier return $this->_xmlEntities($title); 10800cecf9d5Sandi } 10810cecf9d5Sandi } 10820cecf9d5Sandi 10830cecf9d5Sandi /** 10843fd0b676Sandi * Returns an HTML code for images used in link titles 10853fd0b676Sandi * 10863fd0b676Sandi * @todo Resolve namespace on internal images 10873fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10880cecf9d5Sandi */ 1089433bef32Sandi function _imageTitle($img) { 1090d9baf1a7SKazutaka Miyasaka global $ID; 1091d9baf1a7SKazutaka Miyasaka 1092d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1093d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1094d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1095d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1096d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1097d9baf1a7SKazutaka Miyasaka } 1098d9baf1a7SKazutaka Miyasaka 1099433bef32Sandi return $this->_media($img['src'], 11004826ab45Sandi $img['title'], 11014826ab45Sandi $img['align'], 11024826ab45Sandi $img['width'], 11034826ab45Sandi $img['height'], 11044826ab45Sandi $img['cache']); 11050cecf9d5Sandi } 1106b739ff0fSPierre Spring 1107b739ff0fSPierre Spring /** 1108b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1109b739ff0fSPierre Spring * which returns a basic link to a media. 1110b739ff0fSPierre Spring * 1111b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1112b739ff0fSPierre Spring * @param string $src 1113b739ff0fSPierre Spring * @param string $title 1114b739ff0fSPierre Spring * @param string $align 1115b739ff0fSPierre Spring * @param string $width 1116b739ff0fSPierre Spring * @param string $height 1117b739ff0fSPierre Spring * @param string $cache 1118b739ff0fSPierre Spring * @param string $render 1119b739ff0fSPierre Spring * @access protected 1120b739ff0fSPierre Spring * @return array 1121b739ff0fSPierre Spring */ 1122b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1123b739ff0fSPierre Spring { 1124b739ff0fSPierre Spring global $conf; 1125b739ff0fSPierre Spring 1126b739ff0fSPierre Spring $link = array(); 1127b739ff0fSPierre Spring $link['class'] = 'media'; 1128b739ff0fSPierre Spring $link['style'] = ''; 1129b739ff0fSPierre Spring $link['pre'] = ''; 1130b739ff0fSPierre Spring $link['suf'] = ''; 1131b739ff0fSPierre Spring $link['more'] = ''; 1132b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1133b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1134b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1135b739ff0fSPierre Spring 1136b739ff0fSPierre Spring return $link; 1137b739ff0fSPierre Spring } 113891459163SAnika Henke 113991459163SAnika Henke 11400cecf9d5Sandi} 11410cecf9d5Sandi 11424826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1143