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 40*3d491f75SAndreas 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 preformatted($text) { 362*3d491f75SAndreas Gohr $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text)) . '</pre>'. DOKU_LF; 3630cecf9d5Sandi } 3640cecf9d5Sandi 3650cecf9d5Sandi function file($text) { 366*3d491f75SAndreas Gohr $this->doc .= '<pre class="file">' . trim($this->_xmlEntities($text)). '</pre>'. DOKU_LF; 3670cecf9d5Sandi } 3680cecf9d5Sandi 3690cecf9d5Sandi function quote_open() { 37096331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3710cecf9d5Sandi } 3720cecf9d5Sandi 3730cecf9d5Sandi function quote_close() { 37496331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3750cecf9d5Sandi } 3760cecf9d5Sandi 377*3d491f75SAndreas Gohr function preformatted($text) { 378*3d491f75SAndreas Gohr $this->doc .= '<pre class="'.$class.'">' . trim($this->_xmlEntities($text)) . '</pre>'. DOKU_LF; 379*3d491f75SAndreas Gohr } 380*3d491f75SAndreas Gohr 381*3d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 382*3d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 383*3d491f75SAndreas Gohr } 384*3d491f75SAndreas Gohr 385*3d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 386*3d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 387*3d491f75SAndreas Gohr } 388*3d491f75SAndreas Gohr 3890cecf9d5Sandi /** 390*3d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 3913fd0b676Sandi * 3923fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3930cecf9d5Sandi */ 394*3d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 3954de671bcSandi global $conf; 396*3d491f75SAndreas Gohr global $ID; 397*3d491f75SAndreas Gohr global $lang; 398*3d491f75SAndreas Gohr 399*3d491f75SAndreas Gohr if($filename){ 400*3d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 401*3d491f75SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'">'; 402*3d491f75SAndreas Gohr $this->doc .= hsc($filename); 403*3d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 404*3d491f75SAndreas Gohr } 4050cecf9d5Sandi 4060cecf9d5Sandi if ( is_null($language) ) { 407*3d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4080cecf9d5Sandi } else { 409*3d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 410*3d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 411*3d491f75SAndreas Gohr 412*3d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4130cecf9d5Sandi } 414*3d491f75SAndreas Gohr 415*3d491f75SAndreas Gohr if($filename){ 416*3d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 417*3d491f75SAndreas Gohr } 418*3d491f75SAndreas Gohr 419*3d491f75SAndreas Gohr $this->_codeblock++; 4200cecf9d5Sandi } 4210cecf9d5Sandi 4220cecf9d5Sandi function acronym($acronym) { 4230cecf9d5Sandi 4240cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4250cecf9d5Sandi 426433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4270cecf9d5Sandi 428a2d649c4Sandi $this->doc .= '<acronym title="'.$title 429433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4300cecf9d5Sandi 4310cecf9d5Sandi } else { 432a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4330cecf9d5Sandi } 4340cecf9d5Sandi } 4350cecf9d5Sandi 4360cecf9d5Sandi function smiley($smiley) { 4370cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 438433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 439f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4404beabca9SAnika Henke '" class="middle" alt="'. 441433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4420cecf9d5Sandi } else { 443a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4440cecf9d5Sandi } 4450cecf9d5Sandi } 4460cecf9d5Sandi 447f62ea8a1Sandi /* 4484de671bcSandi * not used 4490cecf9d5Sandi function wordblock($word) { 4500cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 451a2d649c4Sandi $this->doc .= '** BLEEP **'; 4520cecf9d5Sandi } else { 453a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4540cecf9d5Sandi } 4550cecf9d5Sandi } 4564de671bcSandi */ 4570cecf9d5Sandi 4580cecf9d5Sandi function entity($entity) { 4590cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 460a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4610cecf9d5Sandi } else { 462a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4630cecf9d5Sandi } 4640cecf9d5Sandi } 4650cecf9d5Sandi 4660cecf9d5Sandi function multiplyentity($x, $y) { 467a2d649c4Sandi $this->doc .= "$x×$y"; 4680cecf9d5Sandi } 4690cecf9d5Sandi 4700cecf9d5Sandi function singlequoteopening() { 47171b40da2SAnika Henke global $lang; 47271b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4730cecf9d5Sandi } 4740cecf9d5Sandi 4750cecf9d5Sandi function singlequoteclosing() { 47671b40da2SAnika Henke global $lang; 47771b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4780cecf9d5Sandi } 4790cecf9d5Sandi 48057d757d1SAndreas Gohr function apostrophe() { 48157d757d1SAndreas Gohr global $lang; 482a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 48357d757d1SAndreas Gohr } 48457d757d1SAndreas Gohr 4850cecf9d5Sandi function doublequoteopening() { 48671b40da2SAnika Henke global $lang; 48771b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4880cecf9d5Sandi } 4890cecf9d5Sandi 4900cecf9d5Sandi function doublequoteclosing() { 49171b40da2SAnika Henke global $lang; 49271b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4930cecf9d5Sandi } 4940cecf9d5Sandi 4950cecf9d5Sandi /** 4960cecf9d5Sandi */ 4970cecf9d5Sandi function camelcaselink($link) { 49811d0aa47Sandi $this->internallink($link,$link); 4990cecf9d5Sandi } 5000cecf9d5Sandi 5010b7c14c2Sandi 5020b7c14c2Sandi function locallink($hash, $name = NULL){ 5030b7c14c2Sandi global $ID; 5040b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5050b7c14c2Sandi $hash = $this->_headerToLink($hash); 5060b7c14c2Sandi $title = $ID.' ↵'; 5070b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5080b7c14c2Sandi $this->doc .= $name; 5090b7c14c2Sandi $this->doc .= '</a>'; 5100b7c14c2Sandi } 5110b7c14c2Sandi 512cffcc403Sandi /** 5133fd0b676Sandi * Render an internal Wiki Link 5143fd0b676Sandi * 515fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 516cffcc403Sandi * elsewhere - no need to implement them in other renderers 5173fd0b676Sandi * 5183fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 519cffcc403Sandi */ 520fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 521ba11bd29Sandi global $conf; 52237e34a5eSandi global $ID; 5230339c872Sjan // default name is based on $id as given 5240339c872Sjan $default = $this->_simpleTitle($id); 525ad32e47eSAndreas Gohr 5260339c872Sjan // now first resolve and clean up the $id 52737e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 528fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5290e1c636eSandi if ( !$isImage ) { 5300e1c636eSandi if ( $exists ) { 531ba11bd29Sandi $class='wikilink1'; 5320cecf9d5Sandi } else { 533ba11bd29Sandi $class='wikilink2'; 53444a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5350cecf9d5Sandi } 5360cecf9d5Sandi } else { 537ba11bd29Sandi $class='media'; 5380cecf9d5Sandi } 5390cecf9d5Sandi 540a1685bedSandi //keep hash anchor 541ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 542943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 543a1685bedSandi 544ba11bd29Sandi //prepare for formating 545ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 546ba11bd29Sandi $link['style'] = ''; 547ba11bd29Sandi $link['pre'] = ''; 548ba11bd29Sandi $link['suf'] = ''; 54940eb54bbSjan // highlight link to current page 55040eb54bbSjan if ($id == $ID) { 55192795d04Sandi $link['pre'] = '<span class="curid">'; 55292795d04Sandi $link['suf'] = '</span>'; 55340eb54bbSjan } 5545e163278SAndreas Gohr $link['more'] = ''; 555ba11bd29Sandi $link['class'] = $class; 556ba11bd29Sandi $link['url'] = wl($id); 557ba11bd29Sandi $link['name'] = $name; 558ba11bd29Sandi $link['title'] = $id; 559723d78dbSandi //add search string 560723d78dbSandi if($search){ 561546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 562546d3a99SAndreas Gohr if(is_array($search)){ 563546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 564546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 565546d3a99SAndreas Gohr }else{ 566546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 567546d3a99SAndreas Gohr } 568723d78dbSandi } 569723d78dbSandi 570a1685bedSandi //keep hash 571a1685bedSandi if($hash) $link['url'].='#'.$hash; 572a1685bedSandi 573ba11bd29Sandi //output formatted 574cffcc403Sandi if($returnonly){ 575cffcc403Sandi return $this->_formatLink($link); 576cffcc403Sandi }else{ 577a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5780cecf9d5Sandi } 579cffcc403Sandi } 5800cecf9d5Sandi 581b625487dSandi function externallink($url, $name = NULL) { 582b625487dSandi global $conf; 5830cecf9d5Sandi 584433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5856f0c5dbfSandi 5860cecf9d5Sandi if ( !$isImage ) { 587b625487dSandi $class='urlextern'; 5880cecf9d5Sandi } else { 589b625487dSandi $class='media'; 5900cecf9d5Sandi } 5910cecf9d5Sandi 592b625487dSandi //prepare for formating 593b625487dSandi $link['target'] = $conf['target']['extern']; 594b625487dSandi $link['style'] = ''; 595b625487dSandi $link['pre'] = ''; 596b625487dSandi $link['suf'] = ''; 5975e163278SAndreas Gohr $link['more'] = ''; 598b625487dSandi $link['class'] = $class; 599b625487dSandi $link['url'] = $url; 600e1c10e4dSchris 601b625487dSandi $link['name'] = $name; 602433bef32Sandi $link['title'] = $this->_xmlEntities($url); 603b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6040cecf9d5Sandi 605b625487dSandi //output formatted 606a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6070cecf9d5Sandi } 6080cecf9d5Sandi 6090cecf9d5Sandi /** 6100cecf9d5Sandi */ 61197a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 612b625487dSandi global $conf; 6130cecf9d5Sandi 61497a3e4e3Sandi $link = array(); 61597a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 61697a3e4e3Sandi $link['pre'] = ''; 61797a3e4e3Sandi $link['suf'] = ''; 6185e163278SAndreas Gohr $link['more'] = ''; 619433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6200cecf9d5Sandi 62197a3e4e3Sandi //get interwiki URL 6221f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6230cecf9d5Sandi 62497a3e4e3Sandi if ( !$isImage ) { 6259d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6269d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6271c2d1019SAndreas Gohr } else { 6281c2d1019SAndreas Gohr $link['class'] = 'media'; 62997a3e4e3Sandi } 6300cecf9d5Sandi 63197a3e4e3Sandi //do we stay at the same server? Use local target 63297a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 63397a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 63497a3e4e3Sandi } 6350cecf9d5Sandi 63697a3e4e3Sandi $link['url'] = $url; 63797a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 63897a3e4e3Sandi 63997a3e4e3Sandi //output formatted 640a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6410cecf9d5Sandi } 6420cecf9d5Sandi 6430cecf9d5Sandi /** 6440cecf9d5Sandi */ 6451d47afe1Sandi function windowssharelink($url, $name = NULL) { 6461d47afe1Sandi global $conf; 6471d47afe1Sandi global $lang; 6481d47afe1Sandi //simple setup 6491d47afe1Sandi $link['target'] = $conf['target']['windows']; 6501d47afe1Sandi $link['pre'] = ''; 6511d47afe1Sandi $link['suf'] = ''; 6521d47afe1Sandi $link['style'] = ''; 6530cecf9d5Sandi 654433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6550cecf9d5Sandi if ( !$isImage ) { 6561d47afe1Sandi $link['class'] = 'windows'; 6570cecf9d5Sandi } else { 6581d47afe1Sandi $link['class'] = 'media'; 6590cecf9d5Sandi } 6600cecf9d5Sandi 6610cecf9d5Sandi 662433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6631d47afe1Sandi $url = str_replace('\\','/',$url); 6641d47afe1Sandi $url = 'file:///'.$url; 6651d47afe1Sandi $link['url'] = $url; 6660cecf9d5Sandi 6671d47afe1Sandi //output formatted 668a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6690cecf9d5Sandi } 6700cecf9d5Sandi 67171352defSandi function emaillink($address, $name = NULL) { 67271352defSandi global $conf; 67371352defSandi //simple setup 67471352defSandi $link = array(); 67571352defSandi $link['target'] = ''; 67671352defSandi $link['pre'] = ''; 67771352defSandi $link['suf'] = ''; 67871352defSandi $link['style'] = ''; 67971352defSandi $link['more'] = ''; 6800cecf9d5Sandi 681c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 6820cecf9d5Sandi if ( !$isImage ) { 683776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6840cecf9d5Sandi } else { 685776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6860cecf9d5Sandi } 6870cecf9d5Sandi 68807738714SAndreas Gohr $address = $this->_xmlEntities($address); 68900a7b5adSEsther Brunner $address = obfuscate($address); 69000a7b5adSEsther Brunner $title = $address; 6918c128049SAndreas Gohr 69271352defSandi if(empty($name)){ 69300a7b5adSEsther Brunner $name = $address; 69471352defSandi } 6950cecf9d5Sandi 696776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 697776b36ecSAndreas Gohr 698776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 69971352defSandi $link['name'] = $name; 70071352defSandi $link['title'] = $title; 7010cecf9d5Sandi 70271352defSandi //output formatted 703a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7040cecf9d5Sandi } 7050cecf9d5Sandi 7064826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 707dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 70837e34a5eSandi global $ID; 70991df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 71037e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7110cecf9d5Sandi 712d98d4540SBen Coburn $noLink = false; 7138acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 714b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7153685f775Sandi 716ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 717b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 718dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7191c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7202ca14335SEsther Brunner // don't link flash movies 72144881bd0Shenning.noren $noLink = true; 72255efc227SAndreas Gohr }else{ 7232ca14335SEsther Brunner // add file icons 7249d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7259d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7266de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 72755efc227SAndreas Gohr } 7283685f775Sandi 72991df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 73091df343aSAndreas Gohr 7316fe20453SGina Haeussge //markup non existing files 7326fe20453SGina Haeussge if (!$exists) 7336fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7346fe20453SGina Haeussge 7353685f775Sandi //output formatted 736dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7372ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7380cecf9d5Sandi } 7390cecf9d5Sandi 7404826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 741dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 74291df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 743d98d4540SBen Coburn $noLink = false; 7448acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 745b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 746b739ff0fSPierre Spring 747b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7483685f775Sandi 749ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 750b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7512ca14335SEsther Brunner // link only jpeg images 75244881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7531c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7542ca14335SEsther Brunner // don't link flash movies 75544881bd0Shenning.noren $noLink = true; 7562ca14335SEsther Brunner }else{ 7572ca14335SEsther Brunner // add file icons 758d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7592ca14335SEsther Brunner } 7602ca14335SEsther Brunner 76191df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 76291df343aSAndreas Gohr 7633685f775Sandi //output formatted 764dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7652ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7660cecf9d5Sandi } 7670cecf9d5Sandi 7684826ab45Sandi /** 7693db95becSAndreas Gohr * Renders an RSS feed 770b625487dSandi * 771b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 772b625487dSandi */ 7733db95becSAndreas Gohr function rss ($url,$params){ 774b625487dSandi global $lang; 7753db95becSAndreas Gohr global $conf; 7763db95becSAndreas Gohr 7773db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7783db95becSAndreas Gohr $feed = new FeedParser(); 77900077af8SAndreas Gohr $feed->set_feed_url($url); 780b625487dSandi 781b625487dSandi //disable warning while fetching 782bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7833db95becSAndreas Gohr $rc = $feed->init(); 784bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 785b625487dSandi 7863db95becSAndreas Gohr //decide on start and end 7873db95becSAndreas Gohr if($params['reverse']){ 7883db95becSAndreas Gohr $mod = -1; 7893db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7903db95becSAndreas Gohr $end = $start - ($params['max']); 791b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7923db95becSAndreas Gohr }else{ 7933db95becSAndreas Gohr $mod = 1; 7943db95becSAndreas Gohr $start = 0; 7953db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7963db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7973db95becSAndreas Gohr } 7983db95becSAndreas Gohr 799a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8003db95becSAndreas Gohr if($rc){ 8013db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8021bde1582SAndreas Gohr $item = $feed->get_item($x); 8033db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 804d2ea3363SAndreas Gohr // support feeds without links 805d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 806d2ea3363SAndreas Gohr if($lnkurl){ 807793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 808793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8091bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 810793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 811d2ea3363SAndreas Gohr }else{ 812d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 813d2ea3363SAndreas Gohr } 8143db95becSAndreas Gohr if($params['author']){ 8151bde1582SAndreas Gohr $author = $item->get_author(0); 8161bde1582SAndreas Gohr if($author){ 8171bde1582SAndreas Gohr $name = $author->get_name(); 8181bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8191bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8201bde1582SAndreas Gohr } 8213db95becSAndreas Gohr } 8223db95becSAndreas Gohr if($params['date']){ 8232e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8243db95becSAndreas Gohr } 8251bde1582SAndreas Gohr if($params['details']){ 8263db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 827173dccb7STom N Harris if($conf['htmlok']){ 8281bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8293db95becSAndreas Gohr }else{ 8301bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8313db95becSAndreas Gohr } 8323db95becSAndreas Gohr $this->doc .= '</div>'; 8333db95becSAndreas Gohr } 8343db95becSAndreas Gohr 8353db95becSAndreas Gohr $this->doc .= '</div></li>'; 836b625487dSandi } 837b625487dSandi }else{ 8383db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 839a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 840b625487dSandi $this->externallink($url); 84145e147ccSAndreas Gohr if($conf['allowdebug']){ 84245e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 84345e147ccSAndreas Gohr } 8443db95becSAndreas Gohr $this->doc .= '</div></li>'; 845b625487dSandi } 846a2d649c4Sandi $this->doc .= '</ul>'; 847b625487dSandi } 848b625487dSandi 8490cecf9d5Sandi // $numrows not yet implemented 8500cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 851b5742cedSPierre Spring // initialize the row counter used for classes 852b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 85359869a4bSAnika Henke $this->doc .= '<table class="inline">'.DOKU_LF; 8540cecf9d5Sandi } 8550cecf9d5Sandi 8560cecf9d5Sandi function table_close(){ 85759869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8580cecf9d5Sandi } 8590cecf9d5Sandi 8600cecf9d5Sandi function tablerow_open(){ 861b5742cedSPierre Spring // initialize the cell counter used for classes 862b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 863b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 864b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8650cecf9d5Sandi } 8660cecf9d5Sandi 8670cecf9d5Sandi function tablerow_close(){ 868a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8690cecf9d5Sandi } 8700cecf9d5Sandi 8710cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 872b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8730cecf9d5Sandi if ( !is_null($align) ) { 874b5742cedSPierre Spring $class .= ' '.$align.'align'; 8750cecf9d5Sandi } 876b5742cedSPierre Spring $class .= '"'; 877b5742cedSPierre Spring $this->doc .= '<th ' . $class; 8780cecf9d5Sandi if ( $colspan > 1 ) { 879a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 880a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8810cecf9d5Sandi } 882a2d649c4Sandi $this->doc .= '>'; 8830cecf9d5Sandi } 8840cecf9d5Sandi 8850cecf9d5Sandi function tableheader_close(){ 886a2d649c4Sandi $this->doc .= '</th>'; 8870cecf9d5Sandi } 8880cecf9d5Sandi 8890cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 890b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8910cecf9d5Sandi if ( !is_null($align) ) { 892b5742cedSPierre Spring $class .= ' '.$align.'align'; 8930cecf9d5Sandi } 894b5742cedSPierre Spring $class .= '"'; 895b5742cedSPierre Spring $this->doc .= '<td '.$class; 8960cecf9d5Sandi if ( $colspan > 1 ) { 897a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 898a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8990cecf9d5Sandi } 900a2d649c4Sandi $this->doc .= '>'; 9010cecf9d5Sandi } 9020cecf9d5Sandi 9030cecf9d5Sandi function tablecell_close(){ 904a2d649c4Sandi $this->doc .= '</td>'; 9050cecf9d5Sandi } 9060cecf9d5Sandi 9070cecf9d5Sandi //---------------------------------------------------------- 9080cecf9d5Sandi // Utils 9090cecf9d5Sandi 910ba11bd29Sandi /** 9113fd0b676Sandi * Build a link 9123fd0b676Sandi * 9133fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 914ba11bd29Sandi * 915ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 916ba11bd29Sandi */ 917433bef32Sandi function _formatLink($link){ 918ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 919ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 920ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 921ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 922ba11bd29Sandi } 923ba11bd29Sandi //remove double encodings in titles 924ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 925ba11bd29Sandi 926453493f2SAndreas Gohr // be sure there are no bad chars in url or title 927453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 928453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 929453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 930453493f2SAndreas Gohr 931ba11bd29Sandi $ret = ''; 932ba11bd29Sandi $ret .= $link['pre']; 933ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 934bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 935bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 936bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 937bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 93844a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 939bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 940ba11bd29Sandi $ret .= '>'; 941ba11bd29Sandi $ret .= $link['name']; 942ba11bd29Sandi $ret .= '</a>'; 943ba11bd29Sandi $ret .= $link['suf']; 944ba11bd29Sandi return $ret; 945ba11bd29Sandi } 946ba11bd29Sandi 947ba11bd29Sandi /** 9483fd0b676Sandi * Renders internal and external media 9493fd0b676Sandi * 9503fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9513fd0b676Sandi */ 9523fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 953b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9543fd0b676Sandi 9553fd0b676Sandi $ret = ''; 9563fd0b676Sandi 957ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 9583fd0b676Sandi if(substr($mime,0,5) == 'image'){ 959b739ff0fSPierre Spring // first get the $title 960b739ff0fSPierre Spring if (!is_null($title)) { 961b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 962b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 963b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 964b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 965b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 966b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 967b739ff0fSPierre Spring if($cap){ 968b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 969b739ff0fSPierre Spring } 970b739ff0fSPierre Spring } 971b739ff0fSPierre Spring if (!$render) { 972b739ff0fSPierre Spring // if the picture is not supposed to be rendered 973b739ff0fSPierre Spring // return the title of the picture 974b739ff0fSPierre Spring if (!$title) { 975b739ff0fSPierre Spring // just show the sourcename 976b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 977b739ff0fSPierre Spring } 978b739ff0fSPierre Spring return $title; 979b739ff0fSPierre Spring } 9803fd0b676Sandi //add image tag 9816de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9823fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9833fd0b676Sandi 9844ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 9854ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 9864ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 9874ab889eaSAndreas Gohr 988b739ff0fSPierre Spring if ($title) { 989b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 990b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 9913fd0b676Sandi }else{ 9923fd0b676Sandi $ret .= ' alt=""'; 9933fd0b676Sandi } 9943fd0b676Sandi 9953fd0b676Sandi if ( !is_null($width) ) 9963fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9973fd0b676Sandi 9983fd0b676Sandi if ( !is_null($height) ) 9993fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10003fd0b676Sandi 10013fd0b676Sandi $ret .= ' />'; 10023fd0b676Sandi 10033fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10041c882ba8SAndreas Gohr if (!$render) { 10051c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10061c882ba8SAndreas Gohr // return the title of the flash 10071c882ba8SAndreas Gohr if (!$title) { 10081c882ba8SAndreas Gohr // just show the sourcename 100907bf32b2SAndreas Gohr $title = basename(noNS($src)); 10101c882ba8SAndreas Gohr } 101107bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10121c882ba8SAndreas Gohr } 10131c882ba8SAndreas Gohr 101407bf32b2SAndreas Gohr $att = array(); 101507bf32b2SAndreas Gohr $att['class'] = "media$align"; 101607bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 101707bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1018109577f5SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 101907bf32b2SAndreas Gohr array('quality' => 'high'), 102007bf32b2SAndreas Gohr null, 102107bf32b2SAndreas Gohr $att, 102207bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10230f428d7dSAndreas Gohr }elseif($title){ 10243fd0b676Sandi // well at least we have a title to display 10253fd0b676Sandi $ret .= $this->_xmlEntities($title); 10263fd0b676Sandi }else{ 10275291ca3aSAndreas Gohr // just show the sourcename 10280f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10293fd0b676Sandi } 10303fd0b676Sandi 10313fd0b676Sandi return $ret; 10323fd0b676Sandi } 10333fd0b676Sandi 1034433bef32Sandi function _xmlEntities($string) { 1035de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10360cecf9d5Sandi } 10370cecf9d5Sandi 10388a831f2bSAndreas Gohr /** 10398a831f2bSAndreas Gohr * Creates a linkid from a headline 1040c5a8fd96SAndreas Gohr * 1041c5a8fd96SAndreas Gohr * @param string $title The headline title 1042c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1043c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10448a831f2bSAndreas Gohr */ 1045c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1046c5a8fd96SAndreas Gohr if($create){ 10474ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10484ceab83fSAndreas Gohr }else{ 1049443d207bSAndreas Gohr $check = false; 1050443d207bSAndreas Gohr return sectionID($title,$check); 1051c5a8fd96SAndreas Gohr } 10520cecf9d5Sandi } 10530cecf9d5Sandi 1054af587fa8Sandi /** 10553fd0b676Sandi * Construct a title and handle images in titles 10563fd0b676Sandi * 10570b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10583fd0b676Sandi */ 1059fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1060bb0a59d4Sjan global $conf; 1061bb0a59d4Sjan 106244881bd0Shenning.noren $isImage = false; 1063a6f3bd20SAnika Henke if ( is_null($title) || trim($title)=='') { 1064fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1065fc18c0fbSchris $heading = p_get_first_heading($id,true); 1066bb0a59d4Sjan if ($heading) { 1067433bef32Sandi return $this->_xmlEntities($heading); 1068bb0a59d4Sjan } 1069bb0a59d4Sjan } 1070433bef32Sandi return $this->_xmlEntities($default); 10710cecf9d5Sandi } else if ( is_array($title) ) { 107244881bd0Shenning.noren $isImage = true; 1073433bef32Sandi return $this->_imageTitle($title); 107468c26e6dSMichael Klier } else { 107568c26e6dSMichael Klier return $this->_xmlEntities($title); 10760cecf9d5Sandi } 10770cecf9d5Sandi } 10780cecf9d5Sandi 10790cecf9d5Sandi /** 10803fd0b676Sandi * Returns an HTML code for images used in link titles 10813fd0b676Sandi * 10823fd0b676Sandi * @todo Resolve namespace on internal images 10833fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10840cecf9d5Sandi */ 1085433bef32Sandi function _imageTitle($img) { 1086433bef32Sandi return $this->_media($img['src'], 10874826ab45Sandi $img['title'], 10884826ab45Sandi $img['align'], 10894826ab45Sandi $img['width'], 10904826ab45Sandi $img['height'], 10914826ab45Sandi $img['cache']); 10920cecf9d5Sandi } 1093b739ff0fSPierre Spring 1094b739ff0fSPierre Spring /** 1095b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1096b739ff0fSPierre Spring * which returns a basic link to a media. 1097b739ff0fSPierre Spring * 1098b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1099b739ff0fSPierre Spring * @param string $src 1100b739ff0fSPierre Spring * @param string $title 1101b739ff0fSPierre Spring * @param string $align 1102b739ff0fSPierre Spring * @param string $width 1103b739ff0fSPierre Spring * @param string $height 1104b739ff0fSPierre Spring * @param string $cache 1105b739ff0fSPierre Spring * @param string $render 1106b739ff0fSPierre Spring * @access protected 1107b739ff0fSPierre Spring * @return array 1108b739ff0fSPierre Spring */ 1109b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1110b739ff0fSPierre Spring { 1111b739ff0fSPierre Spring global $conf; 1112b739ff0fSPierre Spring 1113b739ff0fSPierre Spring $link = array(); 1114b739ff0fSPierre Spring $link['class'] = 'media'; 1115b739ff0fSPierre Spring $link['style'] = ''; 1116b739ff0fSPierre Spring $link['pre'] = ''; 1117b739ff0fSPierre Spring $link['suf'] = ''; 1118b739ff0fSPierre Spring $link['more'] = ''; 1119b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1120b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1121b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1122b739ff0fSPierre Spring 1123b739ff0fSPierre Spring return $link; 1124b739ff0fSPierre Spring } 112591459163SAnika Henke 112691459163SAnika Henke 11270cecf9d5Sandi} 11280cecf9d5Sandi 11294826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1130