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) { 370*c9250713SAnika 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){ 3923d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 3933d491f75SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'">'; 3943d491f75SAndreas Gohr $this->doc .= hsc($filename); 3953d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 3963d491f75SAndreas Gohr } 3970cecf9d5Sandi 3980cecf9d5Sandi if ( is_null($language) ) { 3993d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4000cecf9d5Sandi } else { 4013d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4023d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4033d491f75SAndreas Gohr 4043d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4050cecf9d5Sandi } 4063d491f75SAndreas Gohr 4073d491f75SAndreas Gohr if($filename){ 4083d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4093d491f75SAndreas Gohr } 4103d491f75SAndreas Gohr 4113d491f75SAndreas Gohr $this->_codeblock++; 4120cecf9d5Sandi } 4130cecf9d5Sandi 4140cecf9d5Sandi function acronym($acronym) { 4150cecf9d5Sandi 4160cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4170cecf9d5Sandi 418433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4190cecf9d5Sandi 420a2d649c4Sandi $this->doc .= '<acronym title="'.$title 421433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4220cecf9d5Sandi 4230cecf9d5Sandi } else { 424a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4250cecf9d5Sandi } 4260cecf9d5Sandi } 4270cecf9d5Sandi 4280cecf9d5Sandi function smiley($smiley) { 4290cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 430433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 431f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4324beabca9SAnika Henke '" class="middle" alt="'. 433433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4340cecf9d5Sandi } else { 435a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4360cecf9d5Sandi } 4370cecf9d5Sandi } 4380cecf9d5Sandi 439f62ea8a1Sandi /* 4404de671bcSandi * not used 4410cecf9d5Sandi function wordblock($word) { 4420cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 443a2d649c4Sandi $this->doc .= '** BLEEP **'; 4440cecf9d5Sandi } else { 445a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4460cecf9d5Sandi } 4470cecf9d5Sandi } 4484de671bcSandi */ 4490cecf9d5Sandi 4500cecf9d5Sandi function entity($entity) { 4510cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 452a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4530cecf9d5Sandi } else { 454a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4550cecf9d5Sandi } 4560cecf9d5Sandi } 4570cecf9d5Sandi 4580cecf9d5Sandi function multiplyentity($x, $y) { 459a2d649c4Sandi $this->doc .= "$x×$y"; 4600cecf9d5Sandi } 4610cecf9d5Sandi 4620cecf9d5Sandi function singlequoteopening() { 46371b40da2SAnika Henke global $lang; 46471b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4650cecf9d5Sandi } 4660cecf9d5Sandi 4670cecf9d5Sandi function singlequoteclosing() { 46871b40da2SAnika Henke global $lang; 46971b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4700cecf9d5Sandi } 4710cecf9d5Sandi 47257d757d1SAndreas Gohr function apostrophe() { 47357d757d1SAndreas Gohr global $lang; 474a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 47557d757d1SAndreas Gohr } 47657d757d1SAndreas Gohr 4770cecf9d5Sandi function doublequoteopening() { 47871b40da2SAnika Henke global $lang; 47971b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4800cecf9d5Sandi } 4810cecf9d5Sandi 4820cecf9d5Sandi function doublequoteclosing() { 48371b40da2SAnika Henke global $lang; 48471b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4850cecf9d5Sandi } 4860cecf9d5Sandi 4870cecf9d5Sandi /** 4880cecf9d5Sandi */ 4890cecf9d5Sandi function camelcaselink($link) { 49011d0aa47Sandi $this->internallink($link,$link); 4910cecf9d5Sandi } 4920cecf9d5Sandi 4930b7c14c2Sandi 4940b7c14c2Sandi function locallink($hash, $name = NULL){ 4950b7c14c2Sandi global $ID; 4960b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4970b7c14c2Sandi $hash = $this->_headerToLink($hash); 4980b7c14c2Sandi $title = $ID.' ↵'; 4990b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5000b7c14c2Sandi $this->doc .= $name; 5010b7c14c2Sandi $this->doc .= '</a>'; 5020b7c14c2Sandi } 5030b7c14c2Sandi 504cffcc403Sandi /** 5053fd0b676Sandi * Render an internal Wiki Link 5063fd0b676Sandi * 507fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 508cffcc403Sandi * elsewhere - no need to implement them in other renderers 5093fd0b676Sandi * 5103fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 511cffcc403Sandi */ 512fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 513ba11bd29Sandi global $conf; 51437e34a5eSandi global $ID; 5150339c872Sjan // default name is based on $id as given 5160339c872Sjan $default = $this->_simpleTitle($id); 517ad32e47eSAndreas Gohr 5180339c872Sjan // now first resolve and clean up the $id 51937e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 520fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5210e1c636eSandi if ( !$isImage ) { 5220e1c636eSandi if ( $exists ) { 523ba11bd29Sandi $class='wikilink1'; 5240cecf9d5Sandi } else { 525ba11bd29Sandi $class='wikilink2'; 52644a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5270cecf9d5Sandi } 5280cecf9d5Sandi } else { 529ba11bd29Sandi $class='media'; 5300cecf9d5Sandi } 5310cecf9d5Sandi 532a1685bedSandi //keep hash anchor 533ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 534943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 535a1685bedSandi 536ba11bd29Sandi //prepare for formating 537ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 538ba11bd29Sandi $link['style'] = ''; 539ba11bd29Sandi $link['pre'] = ''; 540ba11bd29Sandi $link['suf'] = ''; 54140eb54bbSjan // highlight link to current page 54240eb54bbSjan if ($id == $ID) { 54392795d04Sandi $link['pre'] = '<span class="curid">'; 54492795d04Sandi $link['suf'] = '</span>'; 54540eb54bbSjan } 5465e163278SAndreas Gohr $link['more'] = ''; 547ba11bd29Sandi $link['class'] = $class; 548ba11bd29Sandi $link['url'] = wl($id); 549ba11bd29Sandi $link['name'] = $name; 550ba11bd29Sandi $link['title'] = $id; 551723d78dbSandi //add search string 552723d78dbSandi if($search){ 553546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 554546d3a99SAndreas Gohr if(is_array($search)){ 555546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 556546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 557546d3a99SAndreas Gohr }else{ 558546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 559546d3a99SAndreas Gohr } 560723d78dbSandi } 561723d78dbSandi 562a1685bedSandi //keep hash 563a1685bedSandi if($hash) $link['url'].='#'.$hash; 564a1685bedSandi 565ba11bd29Sandi //output formatted 566cffcc403Sandi if($returnonly){ 567cffcc403Sandi return $this->_formatLink($link); 568cffcc403Sandi }else{ 569a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5700cecf9d5Sandi } 571cffcc403Sandi } 5720cecf9d5Sandi 573b625487dSandi function externallink($url, $name = NULL) { 574b625487dSandi global $conf; 5750cecf9d5Sandi 576433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5776f0c5dbfSandi 5780cecf9d5Sandi if ( !$isImage ) { 579b625487dSandi $class='urlextern'; 5800cecf9d5Sandi } else { 581b625487dSandi $class='media'; 5820cecf9d5Sandi } 5830cecf9d5Sandi 584b625487dSandi //prepare for formating 585b625487dSandi $link['target'] = $conf['target']['extern']; 586b625487dSandi $link['style'] = ''; 587b625487dSandi $link['pre'] = ''; 588b625487dSandi $link['suf'] = ''; 5895e163278SAndreas Gohr $link['more'] = ''; 590b625487dSandi $link['class'] = $class; 591b625487dSandi $link['url'] = $url; 592e1c10e4dSchris 593b625487dSandi $link['name'] = $name; 594433bef32Sandi $link['title'] = $this->_xmlEntities($url); 595b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5960cecf9d5Sandi 597b625487dSandi //output formatted 598a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5990cecf9d5Sandi } 6000cecf9d5Sandi 6010cecf9d5Sandi /** 6020cecf9d5Sandi */ 60397a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 604b625487dSandi global $conf; 6050cecf9d5Sandi 60697a3e4e3Sandi $link = array(); 60797a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 60897a3e4e3Sandi $link['pre'] = ''; 60997a3e4e3Sandi $link['suf'] = ''; 6105e163278SAndreas Gohr $link['more'] = ''; 611433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6120cecf9d5Sandi 61397a3e4e3Sandi //get interwiki URL 6141f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6150cecf9d5Sandi 61697a3e4e3Sandi if ( !$isImage ) { 6179d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6189d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6191c2d1019SAndreas Gohr } else { 6201c2d1019SAndreas Gohr $link['class'] = 'media'; 62197a3e4e3Sandi } 6220cecf9d5Sandi 62397a3e4e3Sandi //do we stay at the same server? Use local target 62497a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 62597a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 62697a3e4e3Sandi } 6270cecf9d5Sandi 62897a3e4e3Sandi $link['url'] = $url; 62997a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 63097a3e4e3Sandi 63197a3e4e3Sandi //output formatted 632a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6330cecf9d5Sandi } 6340cecf9d5Sandi 6350cecf9d5Sandi /** 6360cecf9d5Sandi */ 6371d47afe1Sandi function windowssharelink($url, $name = NULL) { 6381d47afe1Sandi global $conf; 6391d47afe1Sandi global $lang; 6401d47afe1Sandi //simple setup 6411d47afe1Sandi $link['target'] = $conf['target']['windows']; 6421d47afe1Sandi $link['pre'] = ''; 6431d47afe1Sandi $link['suf'] = ''; 6441d47afe1Sandi $link['style'] = ''; 6450cecf9d5Sandi 646433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6470cecf9d5Sandi if ( !$isImage ) { 6481d47afe1Sandi $link['class'] = 'windows'; 6490cecf9d5Sandi } else { 6501d47afe1Sandi $link['class'] = 'media'; 6510cecf9d5Sandi } 6520cecf9d5Sandi 6530cecf9d5Sandi 654433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6551d47afe1Sandi $url = str_replace('\\','/',$url); 6561d47afe1Sandi $url = 'file:///'.$url; 6571d47afe1Sandi $link['url'] = $url; 6580cecf9d5Sandi 6591d47afe1Sandi //output formatted 660a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6610cecf9d5Sandi } 6620cecf9d5Sandi 66371352defSandi function emaillink($address, $name = NULL) { 66471352defSandi global $conf; 66571352defSandi //simple setup 66671352defSandi $link = array(); 66771352defSandi $link['target'] = ''; 66871352defSandi $link['pre'] = ''; 66971352defSandi $link['suf'] = ''; 67071352defSandi $link['style'] = ''; 67171352defSandi $link['more'] = ''; 6720cecf9d5Sandi 673c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 6740cecf9d5Sandi if ( !$isImage ) { 675776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6760cecf9d5Sandi } else { 677776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6780cecf9d5Sandi } 6790cecf9d5Sandi 68007738714SAndreas Gohr $address = $this->_xmlEntities($address); 68100a7b5adSEsther Brunner $address = obfuscate($address); 68200a7b5adSEsther Brunner $title = $address; 6838c128049SAndreas Gohr 68471352defSandi if(empty($name)){ 68500a7b5adSEsther Brunner $name = $address; 68671352defSandi } 6870cecf9d5Sandi 688776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 689776b36ecSAndreas Gohr 690776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 69171352defSandi $link['name'] = $name; 69271352defSandi $link['title'] = $title; 6930cecf9d5Sandi 69471352defSandi //output formatted 695a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6960cecf9d5Sandi } 6970cecf9d5Sandi 6984826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 699dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 70037e34a5eSandi global $ID; 70191df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 70237e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7030cecf9d5Sandi 704d98d4540SBen Coburn $noLink = false; 7058acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 706b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7073685f775Sandi 708ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 709b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 710dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7111c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7122ca14335SEsther Brunner // don't link flash movies 71344881bd0Shenning.noren $noLink = true; 71455efc227SAndreas Gohr }else{ 7152ca14335SEsther Brunner // add file icons 7169d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7179d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7186de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 71955efc227SAndreas Gohr } 7203685f775Sandi 72191df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 72291df343aSAndreas Gohr 7236fe20453SGina Haeussge //markup non existing files 7246fe20453SGina Haeussge if (!$exists) 7256fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7266fe20453SGina Haeussge 7273685f775Sandi //output formatted 728dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7292ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7300cecf9d5Sandi } 7310cecf9d5Sandi 7324826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 733dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 73491df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 735d98d4540SBen Coburn $noLink = false; 7368acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 737b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 738b739ff0fSPierre Spring 739b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7403685f775Sandi 741ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 742b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7432ca14335SEsther Brunner // link only jpeg images 74444881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7451c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7462ca14335SEsther Brunner // don't link flash movies 74744881bd0Shenning.noren $noLink = true; 7482ca14335SEsther Brunner }else{ 7492ca14335SEsther Brunner // add file icons 750d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7512ca14335SEsther Brunner } 7522ca14335SEsther Brunner 75391df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 75491df343aSAndreas Gohr 7553685f775Sandi //output formatted 756dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7572ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7580cecf9d5Sandi } 7590cecf9d5Sandi 7604826ab45Sandi /** 7613db95becSAndreas Gohr * Renders an RSS feed 762b625487dSandi * 763b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 764b625487dSandi */ 7653db95becSAndreas Gohr function rss ($url,$params){ 766b625487dSandi global $lang; 7673db95becSAndreas Gohr global $conf; 7683db95becSAndreas Gohr 7693db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7703db95becSAndreas Gohr $feed = new FeedParser(); 77100077af8SAndreas Gohr $feed->set_feed_url($url); 772b625487dSandi 773b625487dSandi //disable warning while fetching 774bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7753db95becSAndreas Gohr $rc = $feed->init(); 776bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 777b625487dSandi 7783db95becSAndreas Gohr //decide on start and end 7793db95becSAndreas Gohr if($params['reverse']){ 7803db95becSAndreas Gohr $mod = -1; 7813db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7823db95becSAndreas Gohr $end = $start - ($params['max']); 783b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7843db95becSAndreas Gohr }else{ 7853db95becSAndreas Gohr $mod = 1; 7863db95becSAndreas Gohr $start = 0; 7873db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7883db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7893db95becSAndreas Gohr } 7903db95becSAndreas Gohr 791a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7923db95becSAndreas Gohr if($rc){ 7933db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7941bde1582SAndreas Gohr $item = $feed->get_item($x); 7953db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 796d2ea3363SAndreas Gohr // support feeds without links 797d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 798d2ea3363SAndreas Gohr if($lnkurl){ 799793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 800793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8011bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 802793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 803d2ea3363SAndreas Gohr }else{ 804d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 805d2ea3363SAndreas Gohr } 8063db95becSAndreas Gohr if($params['author']){ 8071bde1582SAndreas Gohr $author = $item->get_author(0); 8081bde1582SAndreas Gohr if($author){ 8091bde1582SAndreas Gohr $name = $author->get_name(); 8101bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8111bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8121bde1582SAndreas Gohr } 8133db95becSAndreas Gohr } 8143db95becSAndreas Gohr if($params['date']){ 8152e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8163db95becSAndreas Gohr } 8171bde1582SAndreas Gohr if($params['details']){ 8183db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 819173dccb7STom N Harris if($conf['htmlok']){ 8201bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8213db95becSAndreas Gohr }else{ 8221bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8233db95becSAndreas Gohr } 8243db95becSAndreas Gohr $this->doc .= '</div>'; 8253db95becSAndreas Gohr } 8263db95becSAndreas Gohr 8273db95becSAndreas Gohr $this->doc .= '</div></li>'; 828b625487dSandi } 829b625487dSandi }else{ 8303db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 831a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 832b625487dSandi $this->externallink($url); 83345e147ccSAndreas Gohr if($conf['allowdebug']){ 83445e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 83545e147ccSAndreas Gohr } 8363db95becSAndreas Gohr $this->doc .= '</div></li>'; 837b625487dSandi } 838a2d649c4Sandi $this->doc .= '</ul>'; 839b625487dSandi } 840b625487dSandi 8410cecf9d5Sandi // $numrows not yet implemented 8420cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 843b5742cedSPierre Spring // initialize the row counter used for classes 844b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 84559869a4bSAnika Henke $this->doc .= '<table class="inline">'.DOKU_LF; 8460cecf9d5Sandi } 8470cecf9d5Sandi 8480cecf9d5Sandi function table_close(){ 84959869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8500cecf9d5Sandi } 8510cecf9d5Sandi 8520cecf9d5Sandi function tablerow_open(){ 853b5742cedSPierre Spring // initialize the cell counter used for classes 854b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 855b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 856b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8570cecf9d5Sandi } 8580cecf9d5Sandi 8590cecf9d5Sandi function tablerow_close(){ 860a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8610cecf9d5Sandi } 8620cecf9d5Sandi 8630cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 864b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8650cecf9d5Sandi if ( !is_null($align) ) { 866b5742cedSPierre Spring $class .= ' '.$align.'align'; 8670cecf9d5Sandi } 868b5742cedSPierre Spring $class .= '"'; 869b5742cedSPierre Spring $this->doc .= '<th ' . $class; 8700cecf9d5Sandi if ( $colspan > 1 ) { 871a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 872a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8730cecf9d5Sandi } 874a2d649c4Sandi $this->doc .= '>'; 8750cecf9d5Sandi } 8760cecf9d5Sandi 8770cecf9d5Sandi function tableheader_close(){ 878a2d649c4Sandi $this->doc .= '</th>'; 8790cecf9d5Sandi } 8800cecf9d5Sandi 8810cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 882b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8830cecf9d5Sandi if ( !is_null($align) ) { 884b5742cedSPierre Spring $class .= ' '.$align.'align'; 8850cecf9d5Sandi } 886b5742cedSPierre Spring $class .= '"'; 887b5742cedSPierre Spring $this->doc .= '<td '.$class; 8880cecf9d5Sandi if ( $colspan > 1 ) { 889a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 890a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8910cecf9d5Sandi } 892a2d649c4Sandi $this->doc .= '>'; 8930cecf9d5Sandi } 8940cecf9d5Sandi 8950cecf9d5Sandi function tablecell_close(){ 896a2d649c4Sandi $this->doc .= '</td>'; 8970cecf9d5Sandi } 8980cecf9d5Sandi 8990cecf9d5Sandi //---------------------------------------------------------- 9000cecf9d5Sandi // Utils 9010cecf9d5Sandi 902ba11bd29Sandi /** 9033fd0b676Sandi * Build a link 9043fd0b676Sandi * 9053fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 906ba11bd29Sandi * 907ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 908ba11bd29Sandi */ 909433bef32Sandi function _formatLink($link){ 910ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 911ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 912ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 913ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 914ba11bd29Sandi } 915ba11bd29Sandi //remove double encodings in titles 916ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 917ba11bd29Sandi 918453493f2SAndreas Gohr // be sure there are no bad chars in url or title 919453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 920453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 921453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 922453493f2SAndreas Gohr 923ba11bd29Sandi $ret = ''; 924ba11bd29Sandi $ret .= $link['pre']; 925ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 926bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 927bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 928bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 929bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 93044a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 931bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 932ba11bd29Sandi $ret .= '>'; 933ba11bd29Sandi $ret .= $link['name']; 934ba11bd29Sandi $ret .= '</a>'; 935ba11bd29Sandi $ret .= $link['suf']; 936ba11bd29Sandi return $ret; 937ba11bd29Sandi } 938ba11bd29Sandi 939ba11bd29Sandi /** 9403fd0b676Sandi * Renders internal and external media 9413fd0b676Sandi * 9423fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9433fd0b676Sandi */ 9443fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 945b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9463fd0b676Sandi 9473fd0b676Sandi $ret = ''; 9483fd0b676Sandi 949ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 9503fd0b676Sandi if(substr($mime,0,5) == 'image'){ 951b739ff0fSPierre Spring // first get the $title 952b739ff0fSPierre Spring if (!is_null($title)) { 953b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 954b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 955b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 956b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 957b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 958b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 959b739ff0fSPierre Spring if($cap){ 960b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 961b739ff0fSPierre Spring } 962b739ff0fSPierre Spring } 963b739ff0fSPierre Spring if (!$render) { 964b739ff0fSPierre Spring // if the picture is not supposed to be rendered 965b739ff0fSPierre Spring // return the title of the picture 966b739ff0fSPierre Spring if (!$title) { 967b739ff0fSPierre Spring // just show the sourcename 968b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 969b739ff0fSPierre Spring } 970b739ff0fSPierre Spring return $title; 971b739ff0fSPierre Spring } 9723fd0b676Sandi //add image tag 9736de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9743fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9753fd0b676Sandi 9764ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 9774ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 9784ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 9794ab889eaSAndreas Gohr 980b739ff0fSPierre Spring if ($title) { 981b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 982b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 9833fd0b676Sandi }else{ 9843fd0b676Sandi $ret .= ' alt=""'; 9853fd0b676Sandi } 9863fd0b676Sandi 9873fd0b676Sandi if ( !is_null($width) ) 9883fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9893fd0b676Sandi 9903fd0b676Sandi if ( !is_null($height) ) 9913fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9923fd0b676Sandi 9933fd0b676Sandi $ret .= ' />'; 9943fd0b676Sandi 9953fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9961c882ba8SAndreas Gohr if (!$render) { 9971c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 9981c882ba8SAndreas Gohr // return the title of the flash 9991c882ba8SAndreas Gohr if (!$title) { 10001c882ba8SAndreas Gohr // just show the sourcename 100107bf32b2SAndreas Gohr $title = basename(noNS($src)); 10021c882ba8SAndreas Gohr } 100307bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10041c882ba8SAndreas Gohr } 10051c882ba8SAndreas Gohr 100607bf32b2SAndreas Gohr $att = array(); 100707bf32b2SAndreas Gohr $att['class'] = "media$align"; 100807bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 100907bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1010109577f5SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 101107bf32b2SAndreas Gohr array('quality' => 'high'), 101207bf32b2SAndreas Gohr null, 101307bf32b2SAndreas Gohr $att, 101407bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10150f428d7dSAndreas Gohr }elseif($title){ 10163fd0b676Sandi // well at least we have a title to display 10173fd0b676Sandi $ret .= $this->_xmlEntities($title); 10183fd0b676Sandi }else{ 10195291ca3aSAndreas Gohr // just show the sourcename 10200f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10213fd0b676Sandi } 10223fd0b676Sandi 10233fd0b676Sandi return $ret; 10243fd0b676Sandi } 10253fd0b676Sandi 1026433bef32Sandi function _xmlEntities($string) { 1027de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10280cecf9d5Sandi } 10290cecf9d5Sandi 10308a831f2bSAndreas Gohr /** 10318a831f2bSAndreas Gohr * Creates a linkid from a headline 1032c5a8fd96SAndreas Gohr * 1033c5a8fd96SAndreas Gohr * @param string $title The headline title 1034c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1035c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10368a831f2bSAndreas Gohr */ 1037c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1038c5a8fd96SAndreas Gohr if($create){ 10394ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10404ceab83fSAndreas Gohr }else{ 1041443d207bSAndreas Gohr $check = false; 1042443d207bSAndreas Gohr return sectionID($title,$check); 1043c5a8fd96SAndreas Gohr } 10440cecf9d5Sandi } 10450cecf9d5Sandi 1046af587fa8Sandi /** 10473fd0b676Sandi * Construct a title and handle images in titles 10483fd0b676Sandi * 10490b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10503fd0b676Sandi */ 1051fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1052bb0a59d4Sjan global $conf; 1053bb0a59d4Sjan 105444881bd0Shenning.noren $isImage = false; 1055a6f3bd20SAnika Henke if ( is_null($title) || trim($title)=='') { 1056fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1057fc18c0fbSchris $heading = p_get_first_heading($id,true); 1058bb0a59d4Sjan if ($heading) { 1059433bef32Sandi return $this->_xmlEntities($heading); 1060bb0a59d4Sjan } 1061bb0a59d4Sjan } 1062433bef32Sandi return $this->_xmlEntities($default); 10630cecf9d5Sandi } else if ( is_array($title) ) { 106444881bd0Shenning.noren $isImage = true; 1065433bef32Sandi return $this->_imageTitle($title); 106668c26e6dSMichael Klier } else { 106768c26e6dSMichael Klier return $this->_xmlEntities($title); 10680cecf9d5Sandi } 10690cecf9d5Sandi } 10700cecf9d5Sandi 10710cecf9d5Sandi /** 10723fd0b676Sandi * Returns an HTML code for images used in link titles 10733fd0b676Sandi * 10743fd0b676Sandi * @todo Resolve namespace on internal images 10753fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10760cecf9d5Sandi */ 1077433bef32Sandi function _imageTitle($img) { 1078433bef32Sandi return $this->_media($img['src'], 10794826ab45Sandi $img['title'], 10804826ab45Sandi $img['align'], 10814826ab45Sandi $img['width'], 10824826ab45Sandi $img['height'], 10834826ab45Sandi $img['cache']); 10840cecf9d5Sandi } 1085b739ff0fSPierre Spring 1086b739ff0fSPierre Spring /** 1087b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1088b739ff0fSPierre Spring * which returns a basic link to a media. 1089b739ff0fSPierre Spring * 1090b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1091b739ff0fSPierre Spring * @param string $src 1092b739ff0fSPierre Spring * @param string $title 1093b739ff0fSPierre Spring * @param string $align 1094b739ff0fSPierre Spring * @param string $width 1095b739ff0fSPierre Spring * @param string $height 1096b739ff0fSPierre Spring * @param string $cache 1097b739ff0fSPierre Spring * @param string $render 1098b739ff0fSPierre Spring * @access protected 1099b739ff0fSPierre Spring * @return array 1100b739ff0fSPierre Spring */ 1101b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1102b739ff0fSPierre Spring { 1103b739ff0fSPierre Spring global $conf; 1104b739ff0fSPierre Spring 1105b739ff0fSPierre Spring $link = array(); 1106b739ff0fSPierre Spring $link['class'] = 'media'; 1107b739ff0fSPierre Spring $link['style'] = ''; 1108b739ff0fSPierre Spring $link['pre'] = ''; 1109b739ff0fSPierre Spring $link['suf'] = ''; 1110b739ff0fSPierre Spring $link['more'] = ''; 1111b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1112b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1113b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1114b739ff0fSPierre Spring 1115b739ff0fSPierre Spring return $link; 1116b739ff0fSPierre Spring } 111791459163SAnika Henke 111891459163SAnika Henke 11190cecf9d5Sandi} 11200cecf9d5Sandi 11214826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1122