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 40b5742cedSPierre Spring 415f70445dSAndreas Gohr function getFormat(){ 425f70445dSAndreas Gohr return 'xhtml'; 435f70445dSAndreas Gohr } 445f70445dSAndreas Gohr 455f70445dSAndreas Gohr 460cecf9d5Sandi function document_start() { 47c5a8fd96SAndreas Gohr //reset some internals 48c5a8fd96SAndreas Gohr $this->toc = array(); 49c5a8fd96SAndreas Gohr $this->headers = array(); 500cecf9d5Sandi } 510cecf9d5Sandi 520cecf9d5Sandi function document_end() { 530cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 54a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 55d74aace9Schris 56d74aace9Schris $id = 0; 570cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 58d74aace9Schris $id++; // the number of the current footnote 59d74aace9Schris 60d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 61d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 62d74aace9Schris 63d74aace9Schris // open the footnote and set the anchor and backlink 64d74aace9Schris $this->doc .= '<div class="fn">'; 6529bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 6629bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 67d74aace9Schris 68d74aace9Schris // get any other footnotes that use the same markup 69d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 70d74aace9Schris 71d74aace9Schris if (count($alt)) { 72d74aace9Schris foreach ($alt as $ref) { 73d74aace9Schris // set anchor and backlink for the other footnotes 7429bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 7529bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 76d74aace9Schris } 77d74aace9Schris } 78d74aace9Schris 79d74aace9Schris // add footnote markup and close this footnote 80a2d649c4Sandi $this->doc .= $footnote; 81d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 82d74aace9Schris } 830cecf9d5Sandi } 84a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 850cecf9d5Sandi } 86c5a8fd96SAndreas Gohr 87b8595a66SAndreas Gohr // Prepare the TOC 88851f2e89SAnika Henke global $conf; 89851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 90b8595a66SAndreas Gohr global $TOC; 91b8595a66SAndreas Gohr $TOC = $this->toc; 920cecf9d5Sandi } 933e55d035SAndreas Gohr 943e55d035SAndreas Gohr // make sure there are no empty paragraphs 9527918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 96e41c4da9SAndreas Gohr } 970cecf9d5Sandi 98e7856beaSchris function toc_additem($id, $text, $level) { 99af587fa8Sandi global $conf; 100af587fa8Sandi 101c5a8fd96SAndreas Gohr //handle TOC 102c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1037d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 104c5a8fd96SAndreas Gohr } 105e7856beaSchris } 106e7856beaSchris 107e7856beaSchris function header($text, $level, $pos) { 108bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 109e7856beaSchris 110e7856beaSchris $hid = $this->_headerToLink($text,true); 111e7856beaSchris 112e7856beaSchris //only add items within configured levels 113e7856beaSchris $this->toc_additem($hid, $text, $level); 114c5a8fd96SAndreas Gohr 11591459163SAnika Henke // adjust $node to reflect hierarchy of levels 11691459163SAnika Henke $this->node[$level-1]++; 11791459163SAnika Henke if ($level < $this->lastlevel) { 11891459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 11991459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 12091459163SAnika Henke } 12191459163SAnika Henke } 12291459163SAnika Henke $this->lastlevel = $level; 12391459163SAnika Henke 124c5a8fd96SAndreas Gohr // write the header 125c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 126a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 12759869a4bSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1280cecf9d5Sandi } 1290cecf9d5Sandi 13035dae8b0SBen Coburn /** 13135dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 13235dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 13335dae8b0SBen Coburn * 13435dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 13535dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 13635dae8b0SBen Coburn */ 13735dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 13835dae8b0SBen Coburn global $conf; 13935dae8b0SBen Coburn 14035dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 14135dae8b0SBen Coburn $name = str_replace('"', '', $name); 14235dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 14335dae8b0SBen Coburn } 14435dae8b0SBen Coburn } 14535dae8b0SBen Coburn 1460cecf9d5Sandi function section_open($level) { 147a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1480cecf9d5Sandi } 1490cecf9d5Sandi 1500cecf9d5Sandi function section_close() { 151a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1520cecf9d5Sandi } 1530cecf9d5Sandi 1540cecf9d5Sandi function cdata($text) { 155a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1560cecf9d5Sandi } 1570cecf9d5Sandi 1580cecf9d5Sandi function p_open() { 15959869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1600cecf9d5Sandi } 1610cecf9d5Sandi 1620cecf9d5Sandi function p_close() { 16359869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1640cecf9d5Sandi } 1650cecf9d5Sandi 1660cecf9d5Sandi function linebreak() { 167a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1680cecf9d5Sandi } 1690cecf9d5Sandi 1700cecf9d5Sandi function hr() { 1714beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1720cecf9d5Sandi } 1730cecf9d5Sandi 1740cecf9d5Sandi function strong_open() { 175a2d649c4Sandi $this->doc .= '<strong>'; 1760cecf9d5Sandi } 1770cecf9d5Sandi 1780cecf9d5Sandi function strong_close() { 179a2d649c4Sandi $this->doc .= '</strong>'; 1800cecf9d5Sandi } 1810cecf9d5Sandi 1820cecf9d5Sandi function emphasis_open() { 183a2d649c4Sandi $this->doc .= '<em>'; 1840cecf9d5Sandi } 1850cecf9d5Sandi 1860cecf9d5Sandi function emphasis_close() { 187a2d649c4Sandi $this->doc .= '</em>'; 1880cecf9d5Sandi } 1890cecf9d5Sandi 1900cecf9d5Sandi function underline_open() { 19102e51121SAnika Henke $this->doc .= '<em class="u">'; 1920cecf9d5Sandi } 1930cecf9d5Sandi 1940cecf9d5Sandi function underline_close() { 19502e51121SAnika Henke $this->doc .= '</em>'; 1960cecf9d5Sandi } 1970cecf9d5Sandi 1980cecf9d5Sandi function monospace_open() { 199a2d649c4Sandi $this->doc .= '<code>'; 2000cecf9d5Sandi } 2010cecf9d5Sandi 2020cecf9d5Sandi function monospace_close() { 203a2d649c4Sandi $this->doc .= '</code>'; 2040cecf9d5Sandi } 2050cecf9d5Sandi 2060cecf9d5Sandi function subscript_open() { 207a2d649c4Sandi $this->doc .= '<sub>'; 2080cecf9d5Sandi } 2090cecf9d5Sandi 2100cecf9d5Sandi function subscript_close() { 211a2d649c4Sandi $this->doc .= '</sub>'; 2120cecf9d5Sandi } 2130cecf9d5Sandi 2140cecf9d5Sandi function superscript_open() { 215a2d649c4Sandi $this->doc .= '<sup>'; 2160cecf9d5Sandi } 2170cecf9d5Sandi 2180cecf9d5Sandi function superscript_close() { 219a2d649c4Sandi $this->doc .= '</sup>'; 2200cecf9d5Sandi } 2210cecf9d5Sandi 2220cecf9d5Sandi function deleted_open() { 223a2d649c4Sandi $this->doc .= '<del>'; 2240cecf9d5Sandi } 2250cecf9d5Sandi 2260cecf9d5Sandi function deleted_close() { 227a2d649c4Sandi $this->doc .= '</del>'; 2280cecf9d5Sandi } 2290cecf9d5Sandi 2303fd0b676Sandi /** 2313fd0b676Sandi * Callback for footnote start syntax 2323fd0b676Sandi * 2333fd0b676Sandi * All following content will go to the footnote instead of 234d74aace9Schris * the document. To achieve this the previous rendered content 2353fd0b676Sandi * is moved to $store and $doc is cleared 2363fd0b676Sandi * 2373fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2383fd0b676Sandi */ 2390cecf9d5Sandi function footnote_open() { 2407764a90aSandi 2417764a90aSandi // move current content to store and record footnote 2427764a90aSandi $this->store = $this->doc; 2437764a90aSandi $this->doc = ''; 2440cecf9d5Sandi } 2450cecf9d5Sandi 2463fd0b676Sandi /** 2473fd0b676Sandi * Callback for footnote end syntax 2483fd0b676Sandi * 2493fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2503fd0b676Sandi * content is restored from $store again 2513fd0b676Sandi * 2523fd0b676Sandi * @author Andreas Gohr 2533fd0b676Sandi */ 2540cecf9d5Sandi function footnote_close() { 2557764a90aSandi 256d74aace9Schris // recover footnote into the stack and restore old content 257d74aace9Schris $footnote = $this->doc; 2587764a90aSandi $this->doc = $this->store; 2597764a90aSandi $this->store = ''; 260d74aace9Schris 261d74aace9Schris // check to see if this footnote has been seen before 262d74aace9Schris $i = array_search($footnote, $this->footnotes); 263d74aace9Schris 264d74aace9Schris if ($i === false) { 265d74aace9Schris // its a new footnote, add it to the $footnotes array 266d74aace9Schris $id = count($this->footnotes)+1; 267d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 268d74aace9Schris } else { 269d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 270d74aace9Schris $i++; 271d74aace9Schris $id = count($this->footnotes)+1; 272d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 273d74aace9Schris } 274d74aace9Schris 2756b379cbfSAndreas Gohr // output the footnote reference and link 27629bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 2770cecf9d5Sandi } 2780cecf9d5Sandi 2790cecf9d5Sandi function listu_open() { 280a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2810cecf9d5Sandi } 2820cecf9d5Sandi 2830cecf9d5Sandi function listu_close() { 284a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 2850cecf9d5Sandi } 2860cecf9d5Sandi 2870cecf9d5Sandi function listo_open() { 288a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 2890cecf9d5Sandi } 2900cecf9d5Sandi 2910cecf9d5Sandi function listo_close() { 292a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 2930cecf9d5Sandi } 2940cecf9d5Sandi 2950cecf9d5Sandi function listitem_open($level) { 29659869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 2970cecf9d5Sandi } 2980cecf9d5Sandi 2990cecf9d5Sandi function listitem_close() { 300a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3010cecf9d5Sandi } 3020cecf9d5Sandi 3030cecf9d5Sandi function listcontent_open() { 30490db23d7Schris $this->doc .= '<div class="li">'; 3050cecf9d5Sandi } 3060cecf9d5Sandi 3070cecf9d5Sandi function listcontent_close() { 30859869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3090cecf9d5Sandi } 3100cecf9d5Sandi 3110cecf9d5Sandi function unformatted($text) { 312a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3130cecf9d5Sandi } 3140cecf9d5Sandi 3150cecf9d5Sandi /** 3163fd0b676Sandi * Execute PHP code if allowed 3173fd0b676Sandi * 3185d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3195d568b99SChris Smith * 3203fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3210cecf9d5Sandi */ 3225d568b99SChris Smith function php($text, $wrapper='code') { 32335a56260SChris Smith global $conf; 32435a56260SChris Smith 325d86d5af0SChris Smith if($conf['phpok']){ 326bad0b545Sandi ob_start(); 3274de671bcSandi eval($text); 3283fd0b676Sandi $this->doc .= ob_get_contents(); 329bad0b545Sandi ob_end_clean(); 330d86d5af0SChris Smith } else { 3315d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 332d86d5af0SChris Smith } 3330cecf9d5Sandi } 3340cecf9d5Sandi 33507f89c3cSAnika Henke function phpblock($text) { 3365d568b99SChris Smith $this->php($text, 'pre'); 33707f89c3cSAnika Henke } 33807f89c3cSAnika Henke 3390cecf9d5Sandi /** 3403fd0b676Sandi * Insert HTML if allowed 3413fd0b676Sandi * 3425d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3435d568b99SChris Smith * 3443fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3450cecf9d5Sandi */ 3465d568b99SChris Smith function html($text, $wrapper='code') { 34735a56260SChris Smith global $conf; 34835a56260SChris Smith 349d86d5af0SChris Smith if($conf['htmlok']){ 350a2d649c4Sandi $this->doc .= $text; 351d86d5af0SChris Smith } else { 3525d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 353d86d5af0SChris Smith } 3544de671bcSandi } 3550cecf9d5Sandi 35607f89c3cSAnika Henke function htmlblock($text) { 3575d568b99SChris Smith $this->html($text, 'pre'); 35807f89c3cSAnika Henke } 35907f89c3cSAnika Henke 3600cecf9d5Sandi function preformatted($text) { 36169ddc332SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 3620cecf9d5Sandi } 3630cecf9d5Sandi 3640cecf9d5Sandi function file($text) { 36569ddc332SAnika Henke $this->doc .= '<pre class="file">' . trim($this->_xmlEntities($text),"\n\r"). '</pre>'. DOKU_LF; 3660cecf9d5Sandi } 3670cecf9d5Sandi 3680cecf9d5Sandi function quote_open() { 36996331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3700cecf9d5Sandi } 3710cecf9d5Sandi 3720cecf9d5Sandi function quote_close() { 37396331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3740cecf9d5Sandi } 3750cecf9d5Sandi 3760cecf9d5Sandi /** 3773fd0b676Sandi * Callback for code text 3783fd0b676Sandi * 3793fd0b676Sandi * Uses GeSHi to highlight language syntax 3803fd0b676Sandi * 3813fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3820cecf9d5Sandi */ 3830cecf9d5Sandi function code($text, $language = NULL) { 3844de671bcSandi global $conf; 3850cecf9d5Sandi 3860cecf9d5Sandi if ( is_null($language) ) { 3870cecf9d5Sandi $this->preformatted($text); 3880cecf9d5Sandi } else { 3898f7d700cSchris $this->doc .= p_xhtml_cached_geshi($text, $language); 3900cecf9d5Sandi } 3910cecf9d5Sandi } 3920cecf9d5Sandi 3930cecf9d5Sandi function acronym($acronym) { 3940cecf9d5Sandi 3950cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 3960cecf9d5Sandi 397433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 3980cecf9d5Sandi 399a2d649c4Sandi $this->doc .= '<acronym title="'.$title 400433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4010cecf9d5Sandi 4020cecf9d5Sandi } else { 403a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4040cecf9d5Sandi } 4050cecf9d5Sandi } 4060cecf9d5Sandi 4070cecf9d5Sandi function smiley($smiley) { 4080cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 409433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 410f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4114beabca9SAnika Henke '" class="middle" alt="'. 412433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4130cecf9d5Sandi } else { 414a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4150cecf9d5Sandi } 4160cecf9d5Sandi } 4170cecf9d5Sandi 418f62ea8a1Sandi /* 4194de671bcSandi * not used 4200cecf9d5Sandi function wordblock($word) { 4210cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 422a2d649c4Sandi $this->doc .= '** BLEEP **'; 4230cecf9d5Sandi } else { 424a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4250cecf9d5Sandi } 4260cecf9d5Sandi } 4274de671bcSandi */ 4280cecf9d5Sandi 4290cecf9d5Sandi function entity($entity) { 4300cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 431a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4320cecf9d5Sandi } else { 433a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4340cecf9d5Sandi } 4350cecf9d5Sandi } 4360cecf9d5Sandi 4370cecf9d5Sandi function multiplyentity($x, $y) { 438a2d649c4Sandi $this->doc .= "$x×$y"; 4390cecf9d5Sandi } 4400cecf9d5Sandi 4410cecf9d5Sandi function singlequoteopening() { 44271b40da2SAnika Henke global $lang; 44371b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4440cecf9d5Sandi } 4450cecf9d5Sandi 4460cecf9d5Sandi function singlequoteclosing() { 44771b40da2SAnika Henke global $lang; 44871b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4490cecf9d5Sandi } 4500cecf9d5Sandi 45157d757d1SAndreas Gohr function apostrophe() { 45257d757d1SAndreas Gohr global $lang; 453a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 45457d757d1SAndreas Gohr } 45557d757d1SAndreas Gohr 4560cecf9d5Sandi function doublequoteopening() { 45771b40da2SAnika Henke global $lang; 45871b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4590cecf9d5Sandi } 4600cecf9d5Sandi 4610cecf9d5Sandi function doublequoteclosing() { 46271b40da2SAnika Henke global $lang; 46371b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4640cecf9d5Sandi } 4650cecf9d5Sandi 4660cecf9d5Sandi /** 4670cecf9d5Sandi */ 4680cecf9d5Sandi function camelcaselink($link) { 46911d0aa47Sandi $this->internallink($link,$link); 4700cecf9d5Sandi } 4710cecf9d5Sandi 4720b7c14c2Sandi 4730b7c14c2Sandi function locallink($hash, $name = NULL){ 4740b7c14c2Sandi global $ID; 4750b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4760b7c14c2Sandi $hash = $this->_headerToLink($hash); 4770b7c14c2Sandi $title = $ID.' ↵'; 4780b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 4790b7c14c2Sandi $this->doc .= $name; 4800b7c14c2Sandi $this->doc .= '</a>'; 4810b7c14c2Sandi } 4820b7c14c2Sandi 483cffcc403Sandi /** 4843fd0b676Sandi * Render an internal Wiki Link 4853fd0b676Sandi * 486fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 487cffcc403Sandi * elsewhere - no need to implement them in other renderers 4883fd0b676Sandi * 4893fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 490cffcc403Sandi */ 491fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 492ba11bd29Sandi global $conf; 49337e34a5eSandi global $ID; 4940339c872Sjan // default name is based on $id as given 4950339c872Sjan $default = $this->_simpleTitle($id); 496ad32e47eSAndreas Gohr 4970339c872Sjan // now first resolve and clean up the $id 49837e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 499fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5000e1c636eSandi if ( !$isImage ) { 5010e1c636eSandi if ( $exists ) { 502ba11bd29Sandi $class='wikilink1'; 5030cecf9d5Sandi } else { 504ba11bd29Sandi $class='wikilink2'; 50544a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5060cecf9d5Sandi } 5070cecf9d5Sandi } else { 508ba11bd29Sandi $class='media'; 5090cecf9d5Sandi } 5100cecf9d5Sandi 511a1685bedSandi //keep hash anchor 512ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 513943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 514a1685bedSandi 515ba11bd29Sandi //prepare for formating 516ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 517ba11bd29Sandi $link['style'] = ''; 518ba11bd29Sandi $link['pre'] = ''; 519ba11bd29Sandi $link['suf'] = ''; 52040eb54bbSjan // highlight link to current page 52140eb54bbSjan if ($id == $ID) { 52292795d04Sandi $link['pre'] = '<span class="curid">'; 52392795d04Sandi $link['suf'] = '</span>'; 52440eb54bbSjan } 5255e163278SAndreas Gohr $link['more'] = ''; 526ba11bd29Sandi $link['class'] = $class; 527ba11bd29Sandi $link['url'] = wl($id); 528ba11bd29Sandi $link['name'] = $name; 529ba11bd29Sandi $link['title'] = $id; 530723d78dbSandi //add search string 531723d78dbSandi if($search){ 532546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 533546d3a99SAndreas Gohr if(is_array($search)){ 534546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 535546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 536546d3a99SAndreas Gohr }else{ 537546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 538546d3a99SAndreas Gohr } 539723d78dbSandi } 540723d78dbSandi 541a1685bedSandi //keep hash 542a1685bedSandi if($hash) $link['url'].='#'.$hash; 543a1685bedSandi 544ba11bd29Sandi //output formatted 545cffcc403Sandi if($returnonly){ 546cffcc403Sandi return $this->_formatLink($link); 547cffcc403Sandi }else{ 548a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5490cecf9d5Sandi } 550cffcc403Sandi } 5510cecf9d5Sandi 552b625487dSandi function externallink($url, $name = NULL) { 553b625487dSandi global $conf; 5540cecf9d5Sandi 555433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5566f0c5dbfSandi 5570cecf9d5Sandi if ( !$isImage ) { 558b625487dSandi $class='urlextern'; 5590cecf9d5Sandi } else { 560b625487dSandi $class='media'; 5610cecf9d5Sandi } 5620cecf9d5Sandi 563b625487dSandi //prepare for formating 564b625487dSandi $link['target'] = $conf['target']['extern']; 565b625487dSandi $link['style'] = ''; 566b625487dSandi $link['pre'] = ''; 567b625487dSandi $link['suf'] = ''; 5685e163278SAndreas Gohr $link['more'] = ''; 569b625487dSandi $link['class'] = $class; 570b625487dSandi $link['url'] = $url; 571e1c10e4dSchris 572b625487dSandi $link['name'] = $name; 573433bef32Sandi $link['title'] = $this->_xmlEntities($url); 574b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5750cecf9d5Sandi 576b625487dSandi //output formatted 577a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5780cecf9d5Sandi } 5790cecf9d5Sandi 5800cecf9d5Sandi /** 5810cecf9d5Sandi */ 58297a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 583b625487dSandi global $conf; 5840cecf9d5Sandi 58597a3e4e3Sandi $link = array(); 58697a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 58797a3e4e3Sandi $link['pre'] = ''; 58897a3e4e3Sandi $link['suf'] = ''; 5895e163278SAndreas Gohr $link['more'] = ''; 590433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5910cecf9d5Sandi 59297a3e4e3Sandi //get interwiki URL 5931f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 5940cecf9d5Sandi 59597a3e4e3Sandi if ( !$isImage ) { 5969d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5979d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5981c2d1019SAndreas Gohr } else { 5991c2d1019SAndreas Gohr $link['class'] = 'media'; 60097a3e4e3Sandi } 6010cecf9d5Sandi 60297a3e4e3Sandi //do we stay at the same server? Use local target 60397a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 60497a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 60597a3e4e3Sandi } 6060cecf9d5Sandi 60797a3e4e3Sandi $link['url'] = $url; 60897a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 60997a3e4e3Sandi 61097a3e4e3Sandi //output formatted 611a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6120cecf9d5Sandi } 6130cecf9d5Sandi 6140cecf9d5Sandi /** 6150cecf9d5Sandi */ 6161d47afe1Sandi function windowssharelink($url, $name = NULL) { 6171d47afe1Sandi global $conf; 6181d47afe1Sandi global $lang; 6191d47afe1Sandi //simple setup 6201d47afe1Sandi $link['target'] = $conf['target']['windows']; 6211d47afe1Sandi $link['pre'] = ''; 6221d47afe1Sandi $link['suf'] = ''; 6231d47afe1Sandi $link['style'] = ''; 6240cecf9d5Sandi 625433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6260cecf9d5Sandi if ( !$isImage ) { 6271d47afe1Sandi $link['class'] = 'windows'; 6280cecf9d5Sandi } else { 6291d47afe1Sandi $link['class'] = 'media'; 6300cecf9d5Sandi } 6310cecf9d5Sandi 6320cecf9d5Sandi 633433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6341d47afe1Sandi $url = str_replace('\\','/',$url); 6351d47afe1Sandi $url = 'file:///'.$url; 6361d47afe1Sandi $link['url'] = $url; 6370cecf9d5Sandi 6381d47afe1Sandi //output formatted 639a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6400cecf9d5Sandi } 6410cecf9d5Sandi 64271352defSandi function emaillink($address, $name = NULL) { 64371352defSandi global $conf; 64471352defSandi //simple setup 64571352defSandi $link = array(); 64671352defSandi $link['target'] = ''; 64771352defSandi $link['pre'] = ''; 64871352defSandi $link['suf'] = ''; 64971352defSandi $link['style'] = ''; 65071352defSandi $link['more'] = ''; 6510cecf9d5Sandi 652c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 6530cecf9d5Sandi if ( !$isImage ) { 654776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6550cecf9d5Sandi } else { 656776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6570cecf9d5Sandi } 6580cecf9d5Sandi 65907738714SAndreas Gohr $address = $this->_xmlEntities($address); 66000a7b5adSEsther Brunner $address = obfuscate($address); 66100a7b5adSEsther Brunner $title = $address; 6628c128049SAndreas Gohr 66371352defSandi if(empty($name)){ 66400a7b5adSEsther Brunner $name = $address; 66571352defSandi } 6660cecf9d5Sandi 667776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 668776b36ecSAndreas Gohr 669776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 67071352defSandi $link['name'] = $name; 67171352defSandi $link['title'] = $title; 6720cecf9d5Sandi 67371352defSandi //output formatted 674a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6750cecf9d5Sandi } 6760cecf9d5Sandi 6774826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 678dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 67937e34a5eSandi global $ID; 68091df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 68137e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6820cecf9d5Sandi 683d98d4540SBen Coburn $noLink = false; 6848acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 685b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 6863685f775Sandi 687ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 688b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 689dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 6901c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 6912ca14335SEsther Brunner // don't link flash movies 69244881bd0Shenning.noren $noLink = true; 69355efc227SAndreas Gohr }else{ 6942ca14335SEsther Brunner // add file icons 6959d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 6969d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 6976de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 69855efc227SAndreas Gohr } 6993685f775Sandi 70091df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 70191df343aSAndreas Gohr 7026fe20453SGina Haeussge //markup non existing files 7036fe20453SGina Haeussge if (!$exists) 7046fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7056fe20453SGina Haeussge 7063685f775Sandi //output formatted 707dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7082ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7090cecf9d5Sandi } 7100cecf9d5Sandi 7114826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 712dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 71391df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 714d98d4540SBen Coburn $noLink = false; 7158acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 716b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 717b739ff0fSPierre Spring 718b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7193685f775Sandi 720ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 721b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7222ca14335SEsther Brunner // link only jpeg images 72344881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7241c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7252ca14335SEsther Brunner // don't link flash movies 72644881bd0Shenning.noren $noLink = true; 7272ca14335SEsther Brunner }else{ 7282ca14335SEsther Brunner // add file icons 729d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7302ca14335SEsther Brunner } 7312ca14335SEsther Brunner 73291df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 73391df343aSAndreas Gohr 7343685f775Sandi //output formatted 735dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7362ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7370cecf9d5Sandi } 7380cecf9d5Sandi 7394826ab45Sandi /** 7403db95becSAndreas Gohr * Renders an RSS feed 741b625487dSandi * 742b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 743b625487dSandi */ 7443db95becSAndreas Gohr function rss ($url,$params){ 745b625487dSandi global $lang; 7463db95becSAndreas Gohr global $conf; 7473db95becSAndreas Gohr 7483db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7493db95becSAndreas Gohr $feed = new FeedParser(); 75000077af8SAndreas Gohr $feed->set_feed_url($url); 751b625487dSandi 752b625487dSandi //disable warning while fetching 753bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7543db95becSAndreas Gohr $rc = $feed->init(); 755bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 756b625487dSandi 7573db95becSAndreas Gohr //decide on start and end 7583db95becSAndreas Gohr if($params['reverse']){ 7593db95becSAndreas Gohr $mod = -1; 7603db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7613db95becSAndreas Gohr $end = $start - ($params['max']); 762b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7633db95becSAndreas Gohr }else{ 7643db95becSAndreas Gohr $mod = 1; 7653db95becSAndreas Gohr $start = 0; 7663db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7673db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7683db95becSAndreas Gohr } 7693db95becSAndreas Gohr 770a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7713db95becSAndreas Gohr if($rc){ 7723db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7731bde1582SAndreas Gohr $item = $feed->get_item($x); 7743db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 775d2ea3363SAndreas Gohr // support feeds without links 776d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 777d2ea3363SAndreas Gohr if($lnkurl){ 778*793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 779*793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 7801bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 781*793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 782d2ea3363SAndreas Gohr }else{ 783d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 784d2ea3363SAndreas Gohr } 7853db95becSAndreas Gohr if($params['author']){ 7861bde1582SAndreas Gohr $author = $item->get_author(0); 7871bde1582SAndreas Gohr if($author){ 7881bde1582SAndreas Gohr $name = $author->get_name(); 7891bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 7901bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 7911bde1582SAndreas Gohr } 7923db95becSAndreas Gohr } 7933db95becSAndreas Gohr if($params['date']){ 7942e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 7953db95becSAndreas Gohr } 7961bde1582SAndreas Gohr if($params['details']){ 7973db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 798173dccb7STom N Harris if($conf['htmlok']){ 7991bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8003db95becSAndreas Gohr }else{ 8011bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8023db95becSAndreas Gohr } 8033db95becSAndreas Gohr $this->doc .= '</div>'; 8043db95becSAndreas Gohr } 8053db95becSAndreas Gohr 8063db95becSAndreas Gohr $this->doc .= '</div></li>'; 807b625487dSandi } 808b625487dSandi }else{ 8093db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 810a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 811b625487dSandi $this->externallink($url); 81245e147ccSAndreas Gohr if($conf['allowdebug']){ 81345e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 81445e147ccSAndreas Gohr } 8153db95becSAndreas Gohr $this->doc .= '</div></li>'; 816b625487dSandi } 817a2d649c4Sandi $this->doc .= '</ul>'; 818b625487dSandi } 819b625487dSandi 8200cecf9d5Sandi // $numrows not yet implemented 8210cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 822b5742cedSPierre Spring // initialize the row counter used for classes 823b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 82459869a4bSAnika Henke $this->doc .= '<table class="inline">'.DOKU_LF; 8250cecf9d5Sandi } 8260cecf9d5Sandi 8270cecf9d5Sandi function table_close(){ 82859869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8290cecf9d5Sandi } 8300cecf9d5Sandi 8310cecf9d5Sandi function tablerow_open(){ 832b5742cedSPierre Spring // initialize the cell counter used for classes 833b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 834b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 835b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8360cecf9d5Sandi } 8370cecf9d5Sandi 8380cecf9d5Sandi function tablerow_close(){ 839a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8400cecf9d5Sandi } 8410cecf9d5Sandi 8420cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 843b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8440cecf9d5Sandi if ( !is_null($align) ) { 845b5742cedSPierre Spring $class .= ' '.$align.'align'; 8460cecf9d5Sandi } 847b5742cedSPierre Spring $class .= '"'; 848b5742cedSPierre Spring $this->doc .= '<th ' . $class; 8490cecf9d5Sandi if ( $colspan > 1 ) { 850a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 851a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8520cecf9d5Sandi } 853a2d649c4Sandi $this->doc .= '>'; 8540cecf9d5Sandi } 8550cecf9d5Sandi 8560cecf9d5Sandi function tableheader_close(){ 857a2d649c4Sandi $this->doc .= '</th>'; 8580cecf9d5Sandi } 8590cecf9d5Sandi 8600cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 861b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8620cecf9d5Sandi if ( !is_null($align) ) { 863b5742cedSPierre Spring $class .= ' '.$align.'align'; 8640cecf9d5Sandi } 865b5742cedSPierre Spring $class .= '"'; 866b5742cedSPierre Spring $this->doc .= '<td '.$class; 8670cecf9d5Sandi if ( $colspan > 1 ) { 868a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 869a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8700cecf9d5Sandi } 871a2d649c4Sandi $this->doc .= '>'; 8720cecf9d5Sandi } 8730cecf9d5Sandi 8740cecf9d5Sandi function tablecell_close(){ 875a2d649c4Sandi $this->doc .= '</td>'; 8760cecf9d5Sandi } 8770cecf9d5Sandi 8780cecf9d5Sandi //---------------------------------------------------------- 8790cecf9d5Sandi // Utils 8800cecf9d5Sandi 881ba11bd29Sandi /** 8823fd0b676Sandi * Build a link 8833fd0b676Sandi * 8843fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 885ba11bd29Sandi * 886ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 887ba11bd29Sandi */ 888433bef32Sandi function _formatLink($link){ 889ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 890ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 891ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 892ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 893ba11bd29Sandi } 894ba11bd29Sandi //remove double encodings in titles 895ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 896ba11bd29Sandi 897453493f2SAndreas Gohr // be sure there are no bad chars in url or title 898453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 899453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 900453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 901453493f2SAndreas Gohr 902ba11bd29Sandi $ret = ''; 903ba11bd29Sandi $ret .= $link['pre']; 904ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 905bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 906bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 907bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 908bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 90944a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 910bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 911ba11bd29Sandi $ret .= '>'; 912ba11bd29Sandi $ret .= $link['name']; 913ba11bd29Sandi $ret .= '</a>'; 914ba11bd29Sandi $ret .= $link['suf']; 915ba11bd29Sandi return $ret; 916ba11bd29Sandi } 917ba11bd29Sandi 918ba11bd29Sandi /** 9193fd0b676Sandi * Renders internal and external media 9203fd0b676Sandi * 9213fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9223fd0b676Sandi */ 9233fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 924b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9253fd0b676Sandi 9263fd0b676Sandi $ret = ''; 9273fd0b676Sandi 928ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 9293fd0b676Sandi if(substr($mime,0,5) == 'image'){ 930b739ff0fSPierre Spring // first get the $title 931b739ff0fSPierre Spring if (!is_null($title)) { 932b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 933b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 934b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 935b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 936b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 937b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 938b739ff0fSPierre Spring if($cap){ 939b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 940b739ff0fSPierre Spring } 941b739ff0fSPierre Spring } 942b739ff0fSPierre Spring if (!$render) { 943b739ff0fSPierre Spring // if the picture is not supposed to be rendered 944b739ff0fSPierre Spring // return the title of the picture 945b739ff0fSPierre Spring if (!$title) { 946b739ff0fSPierre Spring // just show the sourcename 947b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 948b739ff0fSPierre Spring } 949b739ff0fSPierre Spring return $title; 950b739ff0fSPierre Spring } 9513fd0b676Sandi //add image tag 9526de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9533fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9543fd0b676Sandi 9554ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 9564ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 9574ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 9584ab889eaSAndreas Gohr 959b739ff0fSPierre Spring if ($title) { 960b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 961b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 9623fd0b676Sandi }else{ 9633fd0b676Sandi $ret .= ' alt=""'; 9643fd0b676Sandi } 9653fd0b676Sandi 9663fd0b676Sandi if ( !is_null($width) ) 9673fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9683fd0b676Sandi 9693fd0b676Sandi if ( !is_null($height) ) 9703fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9713fd0b676Sandi 9723fd0b676Sandi $ret .= ' />'; 9733fd0b676Sandi 9743fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9751c882ba8SAndreas Gohr if (!$render) { 9761c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 9771c882ba8SAndreas Gohr // return the title of the flash 9781c882ba8SAndreas Gohr if (!$title) { 9791c882ba8SAndreas Gohr // just show the sourcename 98007bf32b2SAndreas Gohr $title = basename(noNS($src)); 9811c882ba8SAndreas Gohr } 98207bf32b2SAndreas Gohr return $this->_xmlEntities($title); 9831c882ba8SAndreas Gohr } 9841c882ba8SAndreas Gohr 98507bf32b2SAndreas Gohr $att = array(); 98607bf32b2SAndreas Gohr $att['class'] = "media$align"; 98707bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 98807bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 989109577f5SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 99007bf32b2SAndreas Gohr array('quality' => 'high'), 99107bf32b2SAndreas Gohr null, 99207bf32b2SAndreas Gohr $att, 99307bf32b2SAndreas Gohr $this->_xmlEntities($title)); 9940f428d7dSAndreas Gohr }elseif($title){ 9953fd0b676Sandi // well at least we have a title to display 9963fd0b676Sandi $ret .= $this->_xmlEntities($title); 9973fd0b676Sandi }else{ 9985291ca3aSAndreas Gohr // just show the sourcename 9990f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10003fd0b676Sandi } 10013fd0b676Sandi 10023fd0b676Sandi return $ret; 10033fd0b676Sandi } 10043fd0b676Sandi 1005433bef32Sandi function _xmlEntities($string) { 1006de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10070cecf9d5Sandi } 10080cecf9d5Sandi 10098a831f2bSAndreas Gohr /** 10108a831f2bSAndreas Gohr * Creates a linkid from a headline 1011c5a8fd96SAndreas Gohr * 1012c5a8fd96SAndreas Gohr * @param string $title The headline title 1013c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1014c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10158a831f2bSAndreas Gohr */ 1016c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1017c5a8fd96SAndreas Gohr if($create){ 10184ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10194ceab83fSAndreas Gohr }else{ 1020443d207bSAndreas Gohr $check = false; 1021443d207bSAndreas Gohr return sectionID($title,$check); 1022c5a8fd96SAndreas Gohr } 10230cecf9d5Sandi } 10240cecf9d5Sandi 1025af587fa8Sandi /** 10263fd0b676Sandi * Construct a title and handle images in titles 10273fd0b676Sandi * 10280b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10293fd0b676Sandi */ 1030fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1031bb0a59d4Sjan global $conf; 1032bb0a59d4Sjan 103344881bd0Shenning.noren $isImage = false; 1034a6f3bd20SAnika Henke if ( is_null($title) || trim($title)=='') { 1035fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1036fc18c0fbSchris $heading = p_get_first_heading($id,true); 1037bb0a59d4Sjan if ($heading) { 1038433bef32Sandi return $this->_xmlEntities($heading); 1039bb0a59d4Sjan } 1040bb0a59d4Sjan } 1041433bef32Sandi return $this->_xmlEntities($default); 10420cecf9d5Sandi } else if ( is_array($title) ) { 104344881bd0Shenning.noren $isImage = true; 1044433bef32Sandi return $this->_imageTitle($title); 104568c26e6dSMichael Klier } else { 104668c26e6dSMichael Klier return $this->_xmlEntities($title); 10470cecf9d5Sandi } 10480cecf9d5Sandi } 10490cecf9d5Sandi 10500cecf9d5Sandi /** 10513fd0b676Sandi * Returns an HTML code for images used in link titles 10523fd0b676Sandi * 10533fd0b676Sandi * @todo Resolve namespace on internal images 10543fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10550cecf9d5Sandi */ 1056433bef32Sandi function _imageTitle($img) { 1057433bef32Sandi return $this->_media($img['src'], 10584826ab45Sandi $img['title'], 10594826ab45Sandi $img['align'], 10604826ab45Sandi $img['width'], 10614826ab45Sandi $img['height'], 10624826ab45Sandi $img['cache']); 10630cecf9d5Sandi } 1064b739ff0fSPierre Spring 1065b739ff0fSPierre Spring /** 1066b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1067b739ff0fSPierre Spring * which returns a basic link to a media. 1068b739ff0fSPierre Spring * 1069b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1070b739ff0fSPierre Spring * @param string $src 1071b739ff0fSPierre Spring * @param string $title 1072b739ff0fSPierre Spring * @param string $align 1073b739ff0fSPierre Spring * @param string $width 1074b739ff0fSPierre Spring * @param string $height 1075b739ff0fSPierre Spring * @param string $cache 1076b739ff0fSPierre Spring * @param string $render 1077b739ff0fSPierre Spring * @access protected 1078b739ff0fSPierre Spring * @return array 1079b739ff0fSPierre Spring */ 1080b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1081b739ff0fSPierre Spring { 1082b739ff0fSPierre Spring global $conf; 1083b739ff0fSPierre Spring 1084b739ff0fSPierre Spring $link = array(); 1085b739ff0fSPierre Spring $link['class'] = 'media'; 1086b739ff0fSPierre Spring $link['style'] = ''; 1087b739ff0fSPierre Spring $link['pre'] = ''; 1088b739ff0fSPierre Spring $link['suf'] = ''; 1089b739ff0fSPierre Spring $link['more'] = ''; 1090b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1091b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1092b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1093b739ff0fSPierre Spring 1094b739ff0fSPierre Spring return $link; 1095b739ff0fSPierre Spring } 109691459163SAnika Henke 109791459163SAnika Henke 10980cecf9d5Sandi} 10990cecf9d5Sandi 11004826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1101