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; 85168841027Shakan.sandell $this->_counter['table_begin_pos'] = strlen($this->doc); 85259869a4bSAnika Henke $this->doc .= '<table class="inline">'.DOKU_LF; 8530cecf9d5Sandi } 8540cecf9d5Sandi 8550cecf9d5Sandi function table_close(){ 85659869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 85768841027Shakan.sandell 85868841027Shakan.sandell // modify created table to add rowspan for cells containing ::: 85968841027Shakan.sandell // first preprocess created xhtml table and transfer data to $tbody array 86068841027Shakan.sandell $table = substr($this->doc, $this->_counter['table_begin_pos']); 8613a0a18ffShakan.sandell if (!preg_match('/>\s*?:::\s*?</', $table)) return; 8623a0a18ffShakan.sandell 86368841027Shakan.sandell preg_match('/(<table.*?>)(.*?)<\/table>/ims', $table, $matches, PREG_OFFSET_CAPTURE); 86468841027Shakan.sandell $tbody_prefix = $matches[1][0]; 86568841027Shakan.sandell $nrow = preg_match_all('/(<tr.*?>)(.*?)<\/tr>/ims', $matches[2][0], $matches); // split and get number of rows 86668841027Shakan.sandell $tbody = array('rows_begin' => $matches[1], 'rows_content' => null); 86768841027Shakan.sandell foreach($matches[0] as $i_row => $row) { // foreach <tr> 86868841027Shakan.sandell preg_match_all('/(<t[d|h].*?>)(.*?)<\/(t[d|h])>/ims', $row, $match_cols); 86968841027Shakan.sandell $cols_attrib = $cols_content = $cols_tag = null; 87068841027Shakan.sandell foreach($match_cols[1] as $i_col => $col) { // foreach <th> or <td> 87168841027Shakan.sandell preg_match_all('/\s(.*?)="(.*?)"/ims', $col, $match_attribs); 87268841027Shakan.sandell for ($i = 0, $col_attrib = null; $i < count($match_attribs[0]); $i++) { // search for colspan="" in attributes 87368841027Shakan.sandell if ($match_attribs[1][$i] == 'colspan'){ 87468841027Shakan.sandell $col_attrib[$match_attribs[1][$i]] = (int)$match_attribs[2][$i]; 87568841027Shakan.sandell $col_padding = $col_attrib[$match_attribs[1][$i]]; 87668841027Shakan.sandell } else { 87768841027Shakan.sandell $col_attrib[$match_attribs[1][$i]] = $match_attribs[2][$i]; 87868841027Shakan.sandell } 87968841027Shakan.sandell } 88068841027Shakan.sandell if (is_null($col_attrib['colspan'])) // default colspan=1 88168841027Shakan.sandell $col_attrib['colspan'] = 1; 88268841027Shakan.sandell $col_attrib['rowspan'] = 1; // rowspan is 1 before processing 88368841027Shakan.sandell 88468841027Shakan.sandell // save data from this row to cols... arrays and $tbody 88568841027Shakan.sandell $cols_attrib[] = $col_attrib; 88668841027Shakan.sandell $cols_content[] = trim($match_cols[2][$i_col]); 88768841027Shakan.sandell $cols_tag[] = $match_cols[3][$i_col]; 88868841027Shakan.sandell while (--$col_padding > 0) {// pad with null to normalize array 88968841027Shakan.sandell $cols_attrib[] = $cols_content[] = $cols_tag[] = null; 89068841027Shakan.sandell } 89168841027Shakan.sandell } 89268841027Shakan.sandell $tbody['rows_content']["row${i_row}"] = array( 89368841027Shakan.sandell 'attrib' => $cols_attrib, 89468841027Shakan.sandell 'content' => $cols_content, 89568841027Shakan.sandell 'tag' => $cols_tag); 89668841027Shakan.sandell } 89768841027Shakan.sandell 89868841027Shakan.sandell // process table array from bottomleft and increment rowspan attributes as indicated by ::: 89968841027Shakan.sandell foreach($tbody['rows_content'] as $row) { // get leftmost column 90068841027Shakan.sandell if(count($row['tag']) > $ncol) { 90168841027Shakan.sandell $ncol = count($row['tag']); 90268841027Shakan.sandell } 90368841027Shakan.sandell } 90468841027Shakan.sandell for($r = $nrow - 1; $r > 0 ; $r--) { // from bottom to up 90568841027Shakan.sandell for ($c = 0; $c < $ncol; $c++) { // from left to right 90668841027Shakan.sandell if ($tbody["rows_content"]["row".($r) ]["content"][$c] == ":::"){ 90768841027Shakan.sandell $tbody["rows_content"]["row".($r-1)]["attrib"][$c]["rowspan"] = 90868841027Shakan.sandell $tbody["rows_content"]["row".($r) ]["attrib"][$c]["rowspan"] + 1; 90968841027Shakan.sandell $tbody["rows_content"]["row".$r]["tag"][$c] = null; // set cell data to NULL instead of ::: 91068841027Shakan.sandell $tbody["rows_content"]["row".$r]["attrib"][$c] = null; 91168841027Shakan.sandell $tbody["rows_content"]["row".$r]["content"][$c] = null; 91268841027Shakan.sandell } 91368841027Shakan.sandell } 91468841027Shakan.sandell } 91568841027Shakan.sandell 91668841027Shakan.sandell // recreate xhtml table from $tbody array 91768841027Shakan.sandell $new_table = "$tbody_prefix\n"; 91868841027Shakan.sandell for ($i_row = 0; $i_row < count($tbody["rows_begin"]); $i_row++) { 91968841027Shakan.sandell $new_table .= $tbody["rows_begin"][$i_row]; 92068841027Shakan.sandell for ($i_col = 0, $cols = $tbody["rows_content"]["row${i_row}"]; $i_col < count($cols['attrib']); $i_col++) { 92168841027Shakan.sandell if (is_null($cols['tag'][$i_col])) continue; 92268841027Shakan.sandell $new_table .= "\n\t<".$cols['tag'][$i_col]; 92368841027Shakan.sandell foreach($cols['attrib'][$i_col] as $attrib => $value) { 92468841027Shakan.sandell if (!(($attrib == 'rowspan' || $attrib == 'colspan') && $value == 1)) { 92568841027Shakan.sandell $new_table .= " $attrib=\"$value\""; 92668841027Shakan.sandell } 92768841027Shakan.sandell } 92868841027Shakan.sandell $new_table .= ">"; 92968841027Shakan.sandell $new_table .= $cols['content'][$i_col]; 93068841027Shakan.sandell $new_table .= "</".$cols['tag'][$i_col].">"; 93168841027Shakan.sandell } 93268841027Shakan.sandell $new_table .= "\n</tr>\n"; 93368841027Shakan.sandell } 93468841027Shakan.sandell $new_table .= "</table>"; 93568841027Shakan.sandell 93668841027Shakan.sandell // replace table 93768841027Shakan.sandell $this->doc = substr($this->doc, 0, $this->_counter['table_begin_pos']).$new_table; 9380cecf9d5Sandi } 9390cecf9d5Sandi 9400cecf9d5Sandi function tablerow_open(){ 941b5742cedSPierre Spring // initialize the cell counter used for classes 942b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 943b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 944b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9450cecf9d5Sandi } 9460cecf9d5Sandi 9470cecf9d5Sandi function tablerow_close(){ 948a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9490cecf9d5Sandi } 9500cecf9d5Sandi 951*25b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 952b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9530cecf9d5Sandi if ( !is_null($align) ) { 954b5742cedSPierre Spring $class .= ' '.$align.'align'; 9550cecf9d5Sandi } 956b5742cedSPierre Spring $class .= '"'; 957b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9580cecf9d5Sandi if ( $colspan > 1 ) { 959a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 960a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9610cecf9d5Sandi } 962*25b97867Shakan.sandell if ( $rowspan > 1 ) { 963*25b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 964*25b97867Shakan.sandell } 965a2d649c4Sandi $this->doc .= '>'; 9660cecf9d5Sandi } 9670cecf9d5Sandi 9680cecf9d5Sandi function tableheader_close(){ 969a2d649c4Sandi $this->doc .= '</th>'; 9700cecf9d5Sandi } 9710cecf9d5Sandi 972*25b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 973b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9740cecf9d5Sandi if ( !is_null($align) ) { 975b5742cedSPierre Spring $class .= ' '.$align.'align'; 9760cecf9d5Sandi } 977b5742cedSPierre Spring $class .= '"'; 978b5742cedSPierre Spring $this->doc .= '<td '.$class; 9790cecf9d5Sandi if ( $colspan > 1 ) { 980a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 981a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9820cecf9d5Sandi } 983*25b97867Shakan.sandell if ( $rowspan > 1 ) { 984*25b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 985*25b97867Shakan.sandell } 986a2d649c4Sandi $this->doc .= '>'; 9870cecf9d5Sandi } 9880cecf9d5Sandi 9890cecf9d5Sandi function tablecell_close(){ 990a2d649c4Sandi $this->doc .= '</td>'; 9910cecf9d5Sandi } 9920cecf9d5Sandi 9930cecf9d5Sandi //---------------------------------------------------------- 9940cecf9d5Sandi // Utils 9950cecf9d5Sandi 996ba11bd29Sandi /** 9973fd0b676Sandi * Build a link 9983fd0b676Sandi * 9993fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 1000ba11bd29Sandi * 1001ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 1002ba11bd29Sandi */ 1003433bef32Sandi function _formatLink($link){ 1004ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 1005ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 1006ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 1007ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 1008ba11bd29Sandi } 1009ba11bd29Sandi //remove double encodings in titles 1010ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 1011ba11bd29Sandi 1012453493f2SAndreas Gohr // be sure there are no bad chars in url or title 1013453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 1014453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 1015453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 1016453493f2SAndreas Gohr 1017ba11bd29Sandi $ret = ''; 1018ba11bd29Sandi $ret .= $link['pre']; 1019ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 1020bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 1021bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 1022bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1023bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 102444a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 1025bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1026ba11bd29Sandi $ret .= '>'; 1027ba11bd29Sandi $ret .= $link['name']; 1028ba11bd29Sandi $ret .= '</a>'; 1029ba11bd29Sandi $ret .= $link['suf']; 1030ba11bd29Sandi return $ret; 1031ba11bd29Sandi } 1032ba11bd29Sandi 1033ba11bd29Sandi /** 10343fd0b676Sandi * Renders internal and external media 10353fd0b676Sandi * 10363fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10373fd0b676Sandi */ 10383fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 1039b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 10403fd0b676Sandi 10413fd0b676Sandi $ret = ''; 10423fd0b676Sandi 1043ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10443fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1045b739ff0fSPierre Spring // first get the $title 1046b739ff0fSPierre Spring if (!is_null($title)) { 1047b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1048b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1049b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1050b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 1051b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 1052b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1053b739ff0fSPierre Spring if($cap){ 1054b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1055b739ff0fSPierre Spring } 1056b739ff0fSPierre Spring } 1057b739ff0fSPierre Spring if (!$render) { 1058b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1059b739ff0fSPierre Spring // return the title of the picture 1060b739ff0fSPierre Spring if (!$title) { 1061b739ff0fSPierre Spring // just show the sourcename 1062b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1063b739ff0fSPierre Spring } 1064b739ff0fSPierre Spring return $title; 1065b739ff0fSPierre Spring } 10663fd0b676Sandi //add image tag 10676de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10683fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10693fd0b676Sandi 10704ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10714ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10724ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10734ab889eaSAndreas Gohr 1074b739ff0fSPierre Spring if ($title) { 1075b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1076b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10773fd0b676Sandi }else{ 10783fd0b676Sandi $ret .= ' alt=""'; 10793fd0b676Sandi } 10803fd0b676Sandi 10813fd0b676Sandi if ( !is_null($width) ) 10823fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10833fd0b676Sandi 10843fd0b676Sandi if ( !is_null($height) ) 10853fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10863fd0b676Sandi 10873fd0b676Sandi $ret .= ' />'; 10883fd0b676Sandi 10893fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10901c882ba8SAndreas Gohr if (!$render) { 10911c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10921c882ba8SAndreas Gohr // return the title of the flash 10931c882ba8SAndreas Gohr if (!$title) { 10941c882ba8SAndreas Gohr // just show the sourcename 109507bf32b2SAndreas Gohr $title = basename(noNS($src)); 10961c882ba8SAndreas Gohr } 109707bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10981c882ba8SAndreas Gohr } 10991c882ba8SAndreas Gohr 110007bf32b2SAndreas Gohr $att = array(); 110107bf32b2SAndreas Gohr $att['class'] = "media$align"; 110207bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 110307bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1104109577f5SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 110507bf32b2SAndreas Gohr array('quality' => 'high'), 110607bf32b2SAndreas Gohr null, 110707bf32b2SAndreas Gohr $att, 110807bf32b2SAndreas Gohr $this->_xmlEntities($title)); 11090f428d7dSAndreas Gohr }elseif($title){ 11103fd0b676Sandi // well at least we have a title to display 11113fd0b676Sandi $ret .= $this->_xmlEntities($title); 11123fd0b676Sandi }else{ 11135291ca3aSAndreas Gohr // just show the sourcename 11140f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 11153fd0b676Sandi } 11163fd0b676Sandi 11173fd0b676Sandi return $ret; 11183fd0b676Sandi } 11193fd0b676Sandi 1120433bef32Sandi function _xmlEntities($string) { 1121de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 11220cecf9d5Sandi } 11230cecf9d5Sandi 11248a831f2bSAndreas Gohr /** 11258a831f2bSAndreas Gohr * Creates a linkid from a headline 1126c5a8fd96SAndreas Gohr * 1127c5a8fd96SAndreas Gohr * @param string $title The headline title 1128c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1129c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11308a831f2bSAndreas Gohr */ 1131c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1132c5a8fd96SAndreas Gohr if($create){ 11334ceab83fSAndreas Gohr return sectionID($title,$this->headers); 11344ceab83fSAndreas Gohr }else{ 1135443d207bSAndreas Gohr $check = false; 1136443d207bSAndreas Gohr return sectionID($title,$check); 1137c5a8fd96SAndreas Gohr } 11380cecf9d5Sandi } 11390cecf9d5Sandi 1140af587fa8Sandi /** 11413fd0b676Sandi * Construct a title and handle images in titles 11423fd0b676Sandi * 11430b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11443fd0b676Sandi */ 1145fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1146bb0a59d4Sjan global $conf; 1147bb0a59d4Sjan 114844881bd0Shenning.noren $isImage = false; 114929657f9eSAndreas Gohr if ( is_array($title) ) { 115029657f9eSAndreas Gohr $isImage = true; 115129657f9eSAndreas Gohr return $this->_imageTitle($title); 115229657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1153fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1154fc18c0fbSchris $heading = p_get_first_heading($id,true); 1155bb0a59d4Sjan if ($heading) { 1156433bef32Sandi return $this->_xmlEntities($heading); 1157bb0a59d4Sjan } 1158bb0a59d4Sjan } 1159433bef32Sandi return $this->_xmlEntities($default); 116068c26e6dSMichael Klier } else { 116168c26e6dSMichael Klier return $this->_xmlEntities($title); 11620cecf9d5Sandi } 11630cecf9d5Sandi } 11640cecf9d5Sandi 11650cecf9d5Sandi /** 11663fd0b676Sandi * Returns an HTML code for images used in link titles 11673fd0b676Sandi * 11683fd0b676Sandi * @todo Resolve namespace on internal images 11693fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11700cecf9d5Sandi */ 1171433bef32Sandi function _imageTitle($img) { 1172433bef32Sandi return $this->_media($img['src'], 11734826ab45Sandi $img['title'], 11744826ab45Sandi $img['align'], 11754826ab45Sandi $img['width'], 11764826ab45Sandi $img['height'], 11774826ab45Sandi $img['cache']); 11780cecf9d5Sandi } 1179b739ff0fSPierre Spring 1180b739ff0fSPierre Spring /** 1181b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1182b739ff0fSPierre Spring * which returns a basic link to a media. 1183b739ff0fSPierre Spring * 1184b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1185b739ff0fSPierre Spring * @param string $src 1186b739ff0fSPierre Spring * @param string $title 1187b739ff0fSPierre Spring * @param string $align 1188b739ff0fSPierre Spring * @param string $width 1189b739ff0fSPierre Spring * @param string $height 1190b739ff0fSPierre Spring * @param string $cache 1191b739ff0fSPierre Spring * @param string $render 1192b739ff0fSPierre Spring * @access protected 1193b739ff0fSPierre Spring * @return array 1194b739ff0fSPierre Spring */ 1195b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1196b739ff0fSPierre Spring { 1197b739ff0fSPierre Spring global $conf; 1198b739ff0fSPierre Spring 1199b739ff0fSPierre Spring $link = array(); 1200b739ff0fSPierre Spring $link['class'] = 'media'; 1201b739ff0fSPierre Spring $link['style'] = ''; 1202b739ff0fSPierre Spring $link['pre'] = ''; 1203b739ff0fSPierre Spring $link['suf'] = ''; 1204b739ff0fSPierre Spring $link['more'] = ''; 1205b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1206b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1207b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1208b739ff0fSPierre Spring 1209b739ff0fSPierre Spring return $link; 1210b739ff0fSPierre Spring } 121191459163SAnika Henke 121291459163SAnika Henke 12130cecf9d5Sandi} 12140cecf9d5Sandi 12154826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1216