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 3214739a20SAndreas Gohr private $sectionedits = array(); // A stack of section edit data 330cecf9d5Sandi 340cecf9d5Sandi var $headers = array(); 350cecf9d5Sandi var $footnotes = array(); 3691459163SAnika Henke var $lastlevel = 0; 3791459163SAnika Henke var $node = array(0,0,0,0,0); 387764a90aSandi var $store = ''; 397764a90aSandi 40b5742cedSPierre Spring var $_counter = array(); // used as global counter, introduced for table classes 413d491f75SAndreas Gohr var $_codeblock = 0; // counts the code and file blocks, used to provide download links 42b5742cedSPierre Spring 43*1ca2719cSAndreas Gohr private $schemes = null; // protocol schemes 44*1ca2719cSAndreas Gohr 4590df9a4dSAdrian Lang /** 4690df9a4dSAdrian Lang * Register a new edit section range 4790df9a4dSAdrian Lang * 4890df9a4dSAdrian Lang * @param $type string The section type identifier 4990df9a4dSAdrian Lang * @param $title string The section title 5090df9a4dSAdrian Lang * @param $start int The byte position for the edit start 5190df9a4dSAdrian Lang * @return string A marker class for the starting HTML element 5290df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 5390df9a4dSAdrian Lang */ 543f9e3215SAdrian Lang public function startSectionEdit($start, $type, $title = null) { 5590df9a4dSAdrian Lang static $lastsecid = 0; 5690df9a4dSAdrian Lang $this->sectionedits[] = array(++$lastsecid, $start, $type, $title); 5790df9a4dSAdrian Lang return 'sectionedit' . $lastsecid; 5890df9a4dSAdrian Lang } 5990df9a4dSAdrian Lang 6090df9a4dSAdrian Lang /** 6190df9a4dSAdrian Lang * Finish an edit section range 6290df9a4dSAdrian Lang * 63d9e36cbeSAdrian Lang * @param $end int The byte position for the edit end; null for the rest of 64d9e36cbeSAdrian Lang the page 6590df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 6690df9a4dSAdrian Lang */ 673f9e3215SAdrian Lang public function finishSectionEdit($end = null) { 6890df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 69d9e36cbeSAdrian Lang if (!is_null($end) && $end <= $start) { 7000c13053SAdrian Lang return; 7100c13053SAdrian Lang } 7240868f2fSAdrian Lang $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' '; 7340868f2fSAdrian Lang if (!is_null($title)) { 7440868f2fSAdrian Lang $this->doc .= '"' . str_replace('"', '', $title) . '" '; 7540868f2fSAdrian Lang } 76d9e36cbeSAdrian Lang $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->'; 7790df9a4dSAdrian Lang } 7890df9a4dSAdrian Lang 795f70445dSAndreas Gohr function getFormat(){ 805f70445dSAndreas Gohr return 'xhtml'; 815f70445dSAndreas Gohr } 825f70445dSAndreas Gohr 835f70445dSAndreas Gohr 840cecf9d5Sandi function document_start() { 85c5a8fd96SAndreas Gohr //reset some internals 86c5a8fd96SAndreas Gohr $this->toc = array(); 87c5a8fd96SAndreas Gohr $this->headers = array(); 880cecf9d5Sandi } 890cecf9d5Sandi 900cecf9d5Sandi function document_end() { 9190df9a4dSAdrian Lang // Finish open section edits. 9290df9a4dSAdrian Lang while (count($this->sectionedits) > 0) { 9390df9a4dSAdrian Lang if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 9490df9a4dSAdrian Lang // If there is only one section, do not write a section edit 9590df9a4dSAdrian Lang // marker. 9690df9a4dSAdrian Lang array_pop($this->sectionedits); 9790df9a4dSAdrian Lang } else { 98d9e36cbeSAdrian Lang $this->finishSectionEdit(); 9990df9a4dSAdrian Lang } 10090df9a4dSAdrian Lang } 10190df9a4dSAdrian Lang 1020cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 103a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 104d74aace9Schris 105d74aace9Schris $id = 0; 1060cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 107d74aace9Schris $id++; // the number of the current footnote 108d74aace9Schris 109d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 110d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 111d74aace9Schris 112d74aace9Schris // open the footnote and set the anchor and backlink 113d74aace9Schris $this->doc .= '<div class="fn">'; 11429bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 11529bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 116d74aace9Schris 117d74aace9Schris // get any other footnotes that use the same markup 118d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 119d74aace9Schris 120d74aace9Schris if (count($alt)) { 121d74aace9Schris foreach ($alt as $ref) { 122d74aace9Schris // set anchor and backlink for the other footnotes 12329bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 12429bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 125d74aace9Schris } 126d74aace9Schris } 127d74aace9Schris 128d74aace9Schris // add footnote markup and close this footnote 129a2d649c4Sandi $this->doc .= $footnote; 130d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 131d74aace9Schris } 1320cecf9d5Sandi } 133a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 1340cecf9d5Sandi } 135c5a8fd96SAndreas Gohr 136b8595a66SAndreas Gohr // Prepare the TOC 137851f2e89SAnika Henke global $conf; 138851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 139b8595a66SAndreas Gohr global $TOC; 140b8595a66SAndreas Gohr $TOC = $this->toc; 1410cecf9d5Sandi } 1423e55d035SAndreas Gohr 1433e55d035SAndreas Gohr // make sure there are no empty paragraphs 14427918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 145e41c4da9SAndreas Gohr } 1460cecf9d5Sandi 147e7856beaSchris function toc_additem($id, $text, $level) { 148af587fa8Sandi global $conf; 149af587fa8Sandi 150c5a8fd96SAndreas Gohr //handle TOC 151c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1527d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 153c5a8fd96SAndreas Gohr } 154e7856beaSchris } 155e7856beaSchris 156e7856beaSchris function header($text, $level, $pos) { 15790df9a4dSAdrian Lang global $conf; 15890df9a4dSAdrian Lang 159bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 160e7856beaSchris 161e7856beaSchris $hid = $this->_headerToLink($text,true); 162e7856beaSchris 163e7856beaSchris //only add items within configured levels 164e7856beaSchris $this->toc_additem($hid, $text, $level); 165c5a8fd96SAndreas Gohr 16691459163SAnika Henke // adjust $node to reflect hierarchy of levels 16791459163SAnika Henke $this->node[$level-1]++; 16891459163SAnika Henke if ($level < $this->lastlevel) { 16991459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 17091459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 17191459163SAnika Henke } 17291459163SAnika Henke } 17391459163SAnika Henke $this->lastlevel = $level; 17491459163SAnika Henke 17590df9a4dSAdrian Lang if ($level <= $conf['maxseclevel'] && 17690df9a4dSAdrian Lang count($this->sectionedits) > 0 && 17790df9a4dSAdrian Lang $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { 1786c1f778cSAdrian Lang $this->finishSectionEdit($pos - 1); 17990df9a4dSAdrian Lang } 18090df9a4dSAdrian Lang 181c5a8fd96SAndreas Gohr // write the header 18290df9a4dSAdrian Lang $this->doc .= DOKU_LF.'<h'.$level; 18390df9a4dSAdrian Lang if ($level <= $conf['maxseclevel']) { 18490df9a4dSAdrian Lang $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; 18590df9a4dSAdrian Lang } 18690df9a4dSAdrian Lang $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">'; 187a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 18859869a4bSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1890cecf9d5Sandi } 1900cecf9d5Sandi 1910cecf9d5Sandi function section_open($level) { 1929864e7b1SAdrian Lang $this->doc .= '<div class="level' . $level . '">' . DOKU_LF; 1930cecf9d5Sandi } 1940cecf9d5Sandi 1950cecf9d5Sandi function section_close() { 196a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1970cecf9d5Sandi } 1980cecf9d5Sandi 1990cecf9d5Sandi function cdata($text) { 200a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 2010cecf9d5Sandi } 2020cecf9d5Sandi 2030cecf9d5Sandi function p_open() { 20459869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 2050cecf9d5Sandi } 2060cecf9d5Sandi 2070cecf9d5Sandi function p_close() { 20859869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 2090cecf9d5Sandi } 2100cecf9d5Sandi 2110cecf9d5Sandi function linebreak() { 212a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 2130cecf9d5Sandi } 2140cecf9d5Sandi 2150cecf9d5Sandi function hr() { 2164beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 2170cecf9d5Sandi } 2180cecf9d5Sandi 2190cecf9d5Sandi function strong_open() { 220a2d649c4Sandi $this->doc .= '<strong>'; 2210cecf9d5Sandi } 2220cecf9d5Sandi 2230cecf9d5Sandi function strong_close() { 224a2d649c4Sandi $this->doc .= '</strong>'; 2250cecf9d5Sandi } 2260cecf9d5Sandi 2270cecf9d5Sandi function emphasis_open() { 228a2d649c4Sandi $this->doc .= '<em>'; 2290cecf9d5Sandi } 2300cecf9d5Sandi 2310cecf9d5Sandi function emphasis_close() { 232a2d649c4Sandi $this->doc .= '</em>'; 2330cecf9d5Sandi } 2340cecf9d5Sandi 2350cecf9d5Sandi function underline_open() { 23602e51121SAnika Henke $this->doc .= '<em class="u">'; 2370cecf9d5Sandi } 2380cecf9d5Sandi 2390cecf9d5Sandi function underline_close() { 24002e51121SAnika Henke $this->doc .= '</em>'; 2410cecf9d5Sandi } 2420cecf9d5Sandi 2430cecf9d5Sandi function monospace_open() { 244a2d649c4Sandi $this->doc .= '<code>'; 2450cecf9d5Sandi } 2460cecf9d5Sandi 2470cecf9d5Sandi function monospace_close() { 248a2d649c4Sandi $this->doc .= '</code>'; 2490cecf9d5Sandi } 2500cecf9d5Sandi 2510cecf9d5Sandi function subscript_open() { 252a2d649c4Sandi $this->doc .= '<sub>'; 2530cecf9d5Sandi } 2540cecf9d5Sandi 2550cecf9d5Sandi function subscript_close() { 256a2d649c4Sandi $this->doc .= '</sub>'; 2570cecf9d5Sandi } 2580cecf9d5Sandi 2590cecf9d5Sandi function superscript_open() { 260a2d649c4Sandi $this->doc .= '<sup>'; 2610cecf9d5Sandi } 2620cecf9d5Sandi 2630cecf9d5Sandi function superscript_close() { 264a2d649c4Sandi $this->doc .= '</sup>'; 2650cecf9d5Sandi } 2660cecf9d5Sandi 2670cecf9d5Sandi function deleted_open() { 268a2d649c4Sandi $this->doc .= '<del>'; 2690cecf9d5Sandi } 2700cecf9d5Sandi 2710cecf9d5Sandi function deleted_close() { 272a2d649c4Sandi $this->doc .= '</del>'; 2730cecf9d5Sandi } 2740cecf9d5Sandi 2753fd0b676Sandi /** 2763fd0b676Sandi * Callback for footnote start syntax 2773fd0b676Sandi * 2783fd0b676Sandi * All following content will go to the footnote instead of 279d74aace9Schris * the document. To achieve this the previous rendered content 2803fd0b676Sandi * is moved to $store and $doc is cleared 2813fd0b676Sandi * 2823fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2833fd0b676Sandi */ 2840cecf9d5Sandi function footnote_open() { 2857764a90aSandi 2867764a90aSandi // move current content to store and record footnote 2877764a90aSandi $this->store = $this->doc; 2887764a90aSandi $this->doc = ''; 2890cecf9d5Sandi } 2900cecf9d5Sandi 2913fd0b676Sandi /** 2923fd0b676Sandi * Callback for footnote end syntax 2933fd0b676Sandi * 2943fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2953fd0b676Sandi * content is restored from $store again 2963fd0b676Sandi * 2973fd0b676Sandi * @author Andreas Gohr 2983fd0b676Sandi */ 2990cecf9d5Sandi function footnote_close() { 3007764a90aSandi 301d74aace9Schris // recover footnote into the stack and restore old content 302d74aace9Schris $footnote = $this->doc; 3037764a90aSandi $this->doc = $this->store; 3047764a90aSandi $this->store = ''; 305d74aace9Schris 306d74aace9Schris // check to see if this footnote has been seen before 307d74aace9Schris $i = array_search($footnote, $this->footnotes); 308d74aace9Schris 309d74aace9Schris if ($i === false) { 310d74aace9Schris // its a new footnote, add it to the $footnotes array 311d74aace9Schris $id = count($this->footnotes)+1; 312d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 313d74aace9Schris } else { 314d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 315d74aace9Schris $i++; 316d74aace9Schris $id = count($this->footnotes)+1; 317d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 318d74aace9Schris } 319d74aace9Schris 3206b379cbfSAndreas Gohr // output the footnote reference and link 32129bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 3220cecf9d5Sandi } 3230cecf9d5Sandi 3240cecf9d5Sandi function listu_open() { 325a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 3260cecf9d5Sandi } 3270cecf9d5Sandi 3280cecf9d5Sandi function listu_close() { 329a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3300cecf9d5Sandi } 3310cecf9d5Sandi 3320cecf9d5Sandi function listo_open() { 333a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3340cecf9d5Sandi } 3350cecf9d5Sandi 3360cecf9d5Sandi function listo_close() { 337a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3380cecf9d5Sandi } 3390cecf9d5Sandi 3400cecf9d5Sandi function listitem_open($level) { 34159869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 3420cecf9d5Sandi } 3430cecf9d5Sandi 3440cecf9d5Sandi function listitem_close() { 345a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3460cecf9d5Sandi } 3470cecf9d5Sandi 3480cecf9d5Sandi function listcontent_open() { 34990db23d7Schris $this->doc .= '<div class="li">'; 3500cecf9d5Sandi } 3510cecf9d5Sandi 3520cecf9d5Sandi function listcontent_close() { 35359869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3540cecf9d5Sandi } 3550cecf9d5Sandi 3560cecf9d5Sandi function unformatted($text) { 357a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3580cecf9d5Sandi } 3590cecf9d5Sandi 3600cecf9d5Sandi /** 3613fd0b676Sandi * Execute PHP code if allowed 3623fd0b676Sandi * 3635d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3645d568b99SChris Smith * 3653fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3660cecf9d5Sandi */ 3675d568b99SChris Smith function php($text, $wrapper='code') { 36835a56260SChris Smith global $conf; 36935a56260SChris Smith 370d86d5af0SChris Smith if($conf['phpok']){ 371bad0b545Sandi ob_start(); 3724de671bcSandi eval($text); 3733fd0b676Sandi $this->doc .= ob_get_contents(); 374bad0b545Sandi ob_end_clean(); 375d86d5af0SChris Smith } else { 3765d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 377d86d5af0SChris Smith } 3780cecf9d5Sandi } 3790cecf9d5Sandi 38007f89c3cSAnika Henke function phpblock($text) { 3815d568b99SChris Smith $this->php($text, 'pre'); 38207f89c3cSAnika Henke } 38307f89c3cSAnika Henke 3840cecf9d5Sandi /** 3853fd0b676Sandi * Insert HTML if allowed 3863fd0b676Sandi * 3875d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3885d568b99SChris Smith * 3893fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3900cecf9d5Sandi */ 3915d568b99SChris Smith function html($text, $wrapper='code') { 39235a56260SChris Smith global $conf; 39335a56260SChris Smith 394d86d5af0SChris Smith if($conf['htmlok']){ 395a2d649c4Sandi $this->doc .= $text; 396d86d5af0SChris Smith } else { 3975d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 398d86d5af0SChris Smith } 3994de671bcSandi } 4000cecf9d5Sandi 40107f89c3cSAnika Henke function htmlblock($text) { 4025d568b99SChris Smith $this->html($text, 'pre'); 40307f89c3cSAnika Henke } 40407f89c3cSAnika Henke 4050cecf9d5Sandi function quote_open() { 40696331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 4070cecf9d5Sandi } 4080cecf9d5Sandi 4090cecf9d5Sandi function quote_close() { 41096331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 4110cecf9d5Sandi } 4120cecf9d5Sandi 4133d491f75SAndreas Gohr function preformatted($text) { 414c9250713SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 4153d491f75SAndreas Gohr } 4163d491f75SAndreas Gohr 4173d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 4183d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 4193d491f75SAndreas Gohr } 4203d491f75SAndreas Gohr 4213d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 4223d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 4233d491f75SAndreas Gohr } 4243d491f75SAndreas Gohr 4250cecf9d5Sandi /** 4263d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 4273fd0b676Sandi * 4283fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 4290cecf9d5Sandi */ 4303d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 4314de671bcSandi global $conf; 4323d491f75SAndreas Gohr global $ID; 4333d491f75SAndreas Gohr global $lang; 4343d491f75SAndreas Gohr 4353d491f75SAndreas Gohr if($filename){ 436190c56e8SAndreas Gohr // add icon 43727bf7924STom N Harris list($ext) = mimetype($filename,false); 438190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 439190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 440190c56e8SAndreas Gohr 4413d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 442190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 4433d491f75SAndreas Gohr $this->doc .= hsc($filename); 4443d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 4453d491f75SAndreas Gohr } 4460cecf9d5Sandi 447d43aac1cSGina Haeussge if ($text{0} == "\n") { 448d43aac1cSGina Haeussge $text = substr($text, 1); 449d43aac1cSGina Haeussge } 450d43aac1cSGina Haeussge if (substr($text, -1) == "\n") { 451d43aac1cSGina Haeussge $text = substr($text, 0, -1); 452d43aac1cSGina Haeussge } 453d43aac1cSGina Haeussge 4540cecf9d5Sandi if ( is_null($language) ) { 4553d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4560cecf9d5Sandi } else { 4573d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4583d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4593d491f75SAndreas Gohr 4603d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4610cecf9d5Sandi } 4623d491f75SAndreas Gohr 4633d491f75SAndreas Gohr if($filename){ 4643d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4653d491f75SAndreas Gohr } 4663d491f75SAndreas Gohr 4673d491f75SAndreas Gohr $this->_codeblock++; 4680cecf9d5Sandi } 4690cecf9d5Sandi 4700cecf9d5Sandi function acronym($acronym) { 4710cecf9d5Sandi 4720cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4730cecf9d5Sandi 474433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4750cecf9d5Sandi 476a2d649c4Sandi $this->doc .= '<acronym title="'.$title 477433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4780cecf9d5Sandi 4790cecf9d5Sandi } else { 480a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4810cecf9d5Sandi } 4820cecf9d5Sandi } 4830cecf9d5Sandi 4840cecf9d5Sandi function smiley($smiley) { 4850cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 486433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 487f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4884beabca9SAnika Henke '" class="middle" alt="'. 489433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4900cecf9d5Sandi } else { 491a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4920cecf9d5Sandi } 4930cecf9d5Sandi } 4940cecf9d5Sandi 495f62ea8a1Sandi /* 4964de671bcSandi * not used 4970cecf9d5Sandi function wordblock($word) { 4980cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 499a2d649c4Sandi $this->doc .= '** BLEEP **'; 5000cecf9d5Sandi } else { 501a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 5020cecf9d5Sandi } 5030cecf9d5Sandi } 5044de671bcSandi */ 5050cecf9d5Sandi 5060cecf9d5Sandi function entity($entity) { 5070cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 508a2d649c4Sandi $this->doc .= $this->entities[$entity]; 5090cecf9d5Sandi } else { 510a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 5110cecf9d5Sandi } 5120cecf9d5Sandi } 5130cecf9d5Sandi 5140cecf9d5Sandi function multiplyentity($x, $y) { 515a2d649c4Sandi $this->doc .= "$x×$y"; 5160cecf9d5Sandi } 5170cecf9d5Sandi 5180cecf9d5Sandi function singlequoteopening() { 51971b40da2SAnika Henke global $lang; 52071b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 5210cecf9d5Sandi } 5220cecf9d5Sandi 5230cecf9d5Sandi function singlequoteclosing() { 52471b40da2SAnika Henke global $lang; 52571b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 5260cecf9d5Sandi } 5270cecf9d5Sandi 52857d757d1SAndreas Gohr function apostrophe() { 52957d757d1SAndreas Gohr global $lang; 530a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 53157d757d1SAndreas Gohr } 53257d757d1SAndreas Gohr 5330cecf9d5Sandi function doublequoteopening() { 53471b40da2SAnika Henke global $lang; 53571b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 5360cecf9d5Sandi } 5370cecf9d5Sandi 5380cecf9d5Sandi function doublequoteclosing() { 53971b40da2SAnika Henke global $lang; 54071b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 5410cecf9d5Sandi } 5420cecf9d5Sandi 5430cecf9d5Sandi /** 5440cecf9d5Sandi */ 5450cecf9d5Sandi function camelcaselink($link) { 54611d0aa47Sandi $this->internallink($link,$link); 5470cecf9d5Sandi } 5480cecf9d5Sandi 5490b7c14c2Sandi 5500b7c14c2Sandi function locallink($hash, $name = NULL){ 5510b7c14c2Sandi global $ID; 5520b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5530b7c14c2Sandi $hash = $this->_headerToLink($hash); 5540b7c14c2Sandi $title = $ID.' ↵'; 5550b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5560b7c14c2Sandi $this->doc .= $name; 5570b7c14c2Sandi $this->doc .= '</a>'; 5580b7c14c2Sandi } 5590b7c14c2Sandi 560cffcc403Sandi /** 5613fd0b676Sandi * Render an internal Wiki Link 5623fd0b676Sandi * 563fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 564cffcc403Sandi * elsewhere - no need to implement them in other renderers 5653fd0b676Sandi * 5663fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 567cffcc403Sandi */ 568fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 569ba11bd29Sandi global $conf; 57037e34a5eSandi global $ID; 57144653a53SAdrian Lang 5723d5e07d9SAdrian Lang $params = ''; 5733d5e07d9SAdrian Lang $parts = explode('?', $id, 2); 5743d5e07d9SAdrian Lang if (count($parts) === 2) { 5753d5e07d9SAdrian Lang $id = $parts[0]; 5763d5e07d9SAdrian Lang $params = $parts[1]; 57744653a53SAdrian Lang } 57844653a53SAdrian Lang 579fda14ffcSIzidor Matušov // For empty $id we need to know the current $ID 580fda14ffcSIzidor Matušov // We need this check because _simpleTitle needs 581fda14ffcSIzidor Matušov // correct $id and resolve_pageid() use cleanID($id) 582fda14ffcSIzidor Matušov // (some things could be lost) 583fda14ffcSIzidor Matušov if ($id === '') { 584fda14ffcSIzidor Matušov $id = $ID; 585fda14ffcSIzidor Matušov } 586fda14ffcSIzidor Matušov 5870339c872Sjan // default name is based on $id as given 5880339c872Sjan $default = $this->_simpleTitle($id); 589ad32e47eSAndreas Gohr 5900339c872Sjan // now first resolve and clean up the $id 59137e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 592fda14ffcSIzidor Matušov 593fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5940e1c636eSandi if ( !$isImage ) { 5950e1c636eSandi if ( $exists ) { 596ba11bd29Sandi $class='wikilink1'; 5970cecf9d5Sandi } else { 598ba11bd29Sandi $class='wikilink2'; 59944a6b4c7SAndreas Gohr $link['rel']='nofollow'; 6000cecf9d5Sandi } 6010cecf9d5Sandi } else { 602ba11bd29Sandi $class='media'; 6030cecf9d5Sandi } 6040cecf9d5Sandi 605a1685bedSandi //keep hash anchor 606ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 607943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 608a1685bedSandi 609ba11bd29Sandi //prepare for formating 610ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 611ba11bd29Sandi $link['style'] = ''; 612ba11bd29Sandi $link['pre'] = ''; 613ba11bd29Sandi $link['suf'] = ''; 61440eb54bbSjan // highlight link to current page 61540eb54bbSjan if ($id == $ID) { 61692795d04Sandi $link['pre'] = '<span class="curid">'; 61792795d04Sandi $link['suf'] = '</span>'; 61840eb54bbSjan } 6195e163278SAndreas Gohr $link['more'] = ''; 620ba11bd29Sandi $link['class'] = $class; 62144653a53SAdrian Lang $link['url'] = wl($id, $params); 622ba11bd29Sandi $link['name'] = $name; 623ba11bd29Sandi $link['title'] = $id; 624723d78dbSandi //add search string 625723d78dbSandi if($search){ 626546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 627546d3a99SAndreas Gohr if(is_array($search)){ 628546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 629546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 630546d3a99SAndreas Gohr }else{ 631546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 632546d3a99SAndreas Gohr } 633723d78dbSandi } 634723d78dbSandi 635a1685bedSandi //keep hash 636a1685bedSandi if($hash) $link['url'].='#'.$hash; 637a1685bedSandi 638ba11bd29Sandi //output formatted 639cffcc403Sandi if($returnonly){ 640cffcc403Sandi return $this->_formatLink($link); 641cffcc403Sandi }else{ 642a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6430cecf9d5Sandi } 644cffcc403Sandi } 6450cecf9d5Sandi 646b625487dSandi function externallink($url, $name = NULL) { 647b625487dSandi global $conf; 6480cecf9d5Sandi 649433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 6506f0c5dbfSandi 6510cecf9d5Sandi if ( !$isImage ) { 652b625487dSandi $class='urlextern'; 6530cecf9d5Sandi } else { 654b625487dSandi $class='media'; 6550cecf9d5Sandi } 6560cecf9d5Sandi 657b625487dSandi //prepare for formating 658b625487dSandi $link['target'] = $conf['target']['extern']; 659b625487dSandi $link['style'] = ''; 660b625487dSandi $link['pre'] = ''; 661b625487dSandi $link['suf'] = ''; 6625e163278SAndreas Gohr $link['more'] = ''; 663b625487dSandi $link['class'] = $class; 664b625487dSandi $link['url'] = $url; 665e1c10e4dSchris 666b625487dSandi $link['name'] = $name; 667433bef32Sandi $link['title'] = $this->_xmlEntities($url); 668b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6690cecf9d5Sandi 670b625487dSandi //output formatted 671a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6720cecf9d5Sandi } 6730cecf9d5Sandi 6740cecf9d5Sandi /** 6750cecf9d5Sandi */ 67697a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 677b625487dSandi global $conf; 6780cecf9d5Sandi 67997a3e4e3Sandi $link = array(); 68097a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 68197a3e4e3Sandi $link['pre'] = ''; 68297a3e4e3Sandi $link['suf'] = ''; 6835e163278SAndreas Gohr $link['more'] = ''; 684433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6850cecf9d5Sandi 68697a3e4e3Sandi //get interwiki URL 6871f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6880cecf9d5Sandi 68997a3e4e3Sandi if ( !$isImage ) { 6909d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6919d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6921c2d1019SAndreas Gohr } else { 6931c2d1019SAndreas Gohr $link['class'] = 'media'; 69497a3e4e3Sandi } 6950cecf9d5Sandi 69697a3e4e3Sandi //do we stay at the same server? Use local target 69797a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 69897a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 69997a3e4e3Sandi } 7000cecf9d5Sandi 70197a3e4e3Sandi $link['url'] = $url; 70297a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 70397a3e4e3Sandi 70497a3e4e3Sandi //output formatted 705a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7060cecf9d5Sandi } 7070cecf9d5Sandi 7080cecf9d5Sandi /** 7090cecf9d5Sandi */ 7101d47afe1Sandi function windowssharelink($url, $name = NULL) { 7111d47afe1Sandi global $conf; 7121d47afe1Sandi global $lang; 7131d47afe1Sandi //simple setup 7141d47afe1Sandi $link['target'] = $conf['target']['windows']; 7151d47afe1Sandi $link['pre'] = ''; 7161d47afe1Sandi $link['suf'] = ''; 7171d47afe1Sandi $link['style'] = ''; 7180cecf9d5Sandi 719433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 7200cecf9d5Sandi if ( !$isImage ) { 7211d47afe1Sandi $link['class'] = 'windows'; 7220cecf9d5Sandi } else { 7231d47afe1Sandi $link['class'] = 'media'; 7240cecf9d5Sandi } 7250cecf9d5Sandi 7260cecf9d5Sandi 727433bef32Sandi $link['title'] = $this->_xmlEntities($url); 7281d47afe1Sandi $url = str_replace('\\','/',$url); 7291d47afe1Sandi $url = 'file:///'.$url; 7301d47afe1Sandi $link['url'] = $url; 7310cecf9d5Sandi 7321d47afe1Sandi //output formatted 733a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7340cecf9d5Sandi } 7350cecf9d5Sandi 73671352defSandi function emaillink($address, $name = NULL) { 73771352defSandi global $conf; 73871352defSandi //simple setup 73971352defSandi $link = array(); 74071352defSandi $link['target'] = ''; 74171352defSandi $link['pre'] = ''; 74271352defSandi $link['suf'] = ''; 74371352defSandi $link['style'] = ''; 74471352defSandi $link['more'] = ''; 7450cecf9d5Sandi 746c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7470cecf9d5Sandi if ( !$isImage ) { 748be96545cSAnika Henke $link['class']='mail'; 7490cecf9d5Sandi } else { 750be96545cSAnika Henke $link['class']='media'; 7510cecf9d5Sandi } 7520cecf9d5Sandi 75307738714SAndreas Gohr $address = $this->_xmlEntities($address); 75400a7b5adSEsther Brunner $address = obfuscate($address); 75500a7b5adSEsther Brunner $title = $address; 7568c128049SAndreas Gohr 75771352defSandi if(empty($name)){ 75800a7b5adSEsther Brunner $name = $address; 75971352defSandi } 7600cecf9d5Sandi 761776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 762776b36ecSAndreas Gohr 763776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 76471352defSandi $link['name'] = $name; 76571352defSandi $link['title'] = $title; 7660cecf9d5Sandi 76771352defSandi //output formatted 768a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7690cecf9d5Sandi } 7700cecf9d5Sandi 7714826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 772dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 77337e34a5eSandi global $ID; 77491df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 77537e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7760cecf9d5Sandi 777d98d4540SBen Coburn $noLink = false; 7788acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 779b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7803685f775Sandi 78127bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 782b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 783dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7841c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7852ca14335SEsther Brunner // don't link flash movies 78644881bd0Shenning.noren $noLink = true; 78755efc227SAndreas Gohr }else{ 7882ca14335SEsther Brunner // add file icons 7899d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7909d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7916de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 79255efc227SAndreas Gohr } 7933685f775Sandi 79491df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 79591df343aSAndreas Gohr 7966fe20453SGina Haeussge //markup non existing files 7976fe20453SGina Haeussge if (!$exists) 7986fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7996fe20453SGina Haeussge 8003685f775Sandi //output formatted 801dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8022ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8030cecf9d5Sandi } 8040cecf9d5Sandi 8054826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 806dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 80791df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 808d98d4540SBen Coburn $noLink = false; 8098acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 810b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 811b739ff0fSPierre Spring 812b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 8133685f775Sandi 81427bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 815b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 8162ca14335SEsther Brunner // link only jpeg images 81744881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 8181c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 8192ca14335SEsther Brunner // don't link flash movies 82044881bd0Shenning.noren $noLink = true; 8212ca14335SEsther Brunner }else{ 8222ca14335SEsther Brunner // add file icons 82327bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 82427bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 8252ca14335SEsther Brunner } 8262ca14335SEsther Brunner 82791df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 82891df343aSAndreas Gohr 8293685f775Sandi //output formatted 830dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8312ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8320cecf9d5Sandi } 8330cecf9d5Sandi 8344826ab45Sandi /** 8353db95becSAndreas Gohr * Renders an RSS feed 836b625487dSandi * 837b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 838b625487dSandi */ 8393db95becSAndreas Gohr function rss ($url,$params){ 840b625487dSandi global $lang; 8413db95becSAndreas Gohr global $conf; 8423db95becSAndreas Gohr 8433db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8443db95becSAndreas Gohr $feed = new FeedParser(); 84500077af8SAndreas Gohr $feed->set_feed_url($url); 846b625487dSandi 847b625487dSandi //disable warning while fetching 848bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8493db95becSAndreas Gohr $rc = $feed->init(); 850bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 851b625487dSandi 8523db95becSAndreas Gohr //decide on start and end 8533db95becSAndreas Gohr if($params['reverse']){ 8543db95becSAndreas Gohr $mod = -1; 8553db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8563db95becSAndreas Gohr $end = $start - ($params['max']); 857b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8583db95becSAndreas Gohr }else{ 8593db95becSAndreas Gohr $mod = 1; 8603db95becSAndreas Gohr $start = 0; 8613db95becSAndreas Gohr $end = $feed->get_item_quantity(); 8623db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 8633db95becSAndreas Gohr } 8643db95becSAndreas Gohr 865a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8663db95becSAndreas Gohr if($rc){ 8673db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8681bde1582SAndreas Gohr $item = $feed->get_item($x); 8693db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 870d2ea3363SAndreas Gohr // support feeds without links 871d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 872d2ea3363SAndreas Gohr if($lnkurl){ 873*1ca2719cSAndreas Gohr // lnkurl might be an attack vector, only allow registered protocols 874*1ca2719cSAndreas Gohr if(is_null($this->schemes)) $this->schemes = getSchemes(); 875*1ca2719cSAndreas Gohr list($scheme) = explode('://',$lnkurl); 876*1ca2719cSAndreas Gohr $scheme = strtolower($scheme); 877*1ca2719cSAndreas Gohr if(!in_array($scheme,$this->schemes)) $lnkurl = ''; 878*1ca2719cSAndreas Gohr } 879*1ca2719cSAndreas Gohr 880*1ca2719cSAndreas Gohr if($lnkurl){ 881793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 882793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8831bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 884793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 885d2ea3363SAndreas Gohr }else{ 886d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 887d2ea3363SAndreas Gohr } 8883db95becSAndreas Gohr if($params['author']){ 8891bde1582SAndreas Gohr $author = $item->get_author(0); 8901bde1582SAndreas Gohr if($author){ 8911bde1582SAndreas Gohr $name = $author->get_name(); 8921bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8931bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8941bde1582SAndreas Gohr } 8953db95becSAndreas Gohr } 8963db95becSAndreas Gohr if($params['date']){ 8972e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8983db95becSAndreas Gohr } 8991bde1582SAndreas Gohr if($params['details']){ 9003db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 901173dccb7STom N Harris if($conf['htmlok']){ 9021bde1582SAndreas Gohr $this->doc .= $item->get_description(); 9033db95becSAndreas Gohr }else{ 9041bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 9053db95becSAndreas Gohr } 9063db95becSAndreas Gohr $this->doc .= '</div>'; 9073db95becSAndreas Gohr } 9083db95becSAndreas Gohr 9093db95becSAndreas Gohr $this->doc .= '</div></li>'; 910b625487dSandi } 911b625487dSandi }else{ 9123db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 913a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 914b625487dSandi $this->externallink($url); 91545e147ccSAndreas Gohr if($conf['allowdebug']){ 91645e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 91745e147ccSAndreas Gohr } 9183db95becSAndreas Gohr $this->doc .= '</div></li>'; 919b625487dSandi } 920a2d649c4Sandi $this->doc .= '</ul>'; 921b625487dSandi } 922b625487dSandi 9230cecf9d5Sandi // $numrows not yet implemented 924619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){ 92590df9a4dSAdrian Lang global $lang; 926b5742cedSPierre Spring // initialize the row counter used for classes 927b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 928619736fdSAdrian Lang $class = 'table'; 929619736fdSAdrian Lang if ($pos !== null) { 930619736fdSAdrian Lang $class .= ' ' . $this->startSectionEdit($pos, 'table'); 931619736fdSAdrian Lang } 932619736fdSAdrian Lang $this->doc .= '<div class="' . $class . '"><table class="inline">' . 933619736fdSAdrian Lang DOKU_LF; 9340cecf9d5Sandi } 9350cecf9d5Sandi 936619736fdSAdrian Lang function table_close($pos = null){ 937a8574918SAnika Henke $this->doc .= '</table></div>'.DOKU_LF; 938619736fdSAdrian Lang if ($pos !== null) { 93990df9a4dSAdrian Lang $this->finishSectionEdit($pos); 9400cecf9d5Sandi } 941619736fdSAdrian Lang } 9420cecf9d5Sandi 9430cecf9d5Sandi function tablerow_open(){ 944b5742cedSPierre Spring // initialize the cell counter used for classes 945b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 946b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 947b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9480cecf9d5Sandi } 9490cecf9d5Sandi 9500cecf9d5Sandi function tablerow_close(){ 951a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9520cecf9d5Sandi } 9530cecf9d5Sandi 95425b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 955b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9560cecf9d5Sandi if ( !is_null($align) ) { 957b5742cedSPierre Spring $class .= ' '.$align.'align'; 9580cecf9d5Sandi } 959b5742cedSPierre Spring $class .= '"'; 960b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9610cecf9d5Sandi if ( $colspan > 1 ) { 962a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 963a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9640cecf9d5Sandi } 96525b97867Shakan.sandell if ( $rowspan > 1 ) { 96625b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 96725b97867Shakan.sandell } 968a2d649c4Sandi $this->doc .= '>'; 9690cecf9d5Sandi } 9700cecf9d5Sandi 9710cecf9d5Sandi function tableheader_close(){ 972a2d649c4Sandi $this->doc .= '</th>'; 9730cecf9d5Sandi } 9740cecf9d5Sandi 97525b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 976b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9770cecf9d5Sandi if ( !is_null($align) ) { 978b5742cedSPierre Spring $class .= ' '.$align.'align'; 9790cecf9d5Sandi } 980b5742cedSPierre Spring $class .= '"'; 981b5742cedSPierre Spring $this->doc .= '<td '.$class; 9820cecf9d5Sandi if ( $colspan > 1 ) { 983a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 984a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9850cecf9d5Sandi } 98625b97867Shakan.sandell if ( $rowspan > 1 ) { 98725b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 98825b97867Shakan.sandell } 989a2d649c4Sandi $this->doc .= '>'; 9900cecf9d5Sandi } 9910cecf9d5Sandi 9920cecf9d5Sandi function tablecell_close(){ 993a2d649c4Sandi $this->doc .= '</td>'; 9940cecf9d5Sandi } 9950cecf9d5Sandi 9960cecf9d5Sandi //---------------------------------------------------------- 9970cecf9d5Sandi // Utils 9980cecf9d5Sandi 999ba11bd29Sandi /** 10003fd0b676Sandi * Build a link 10013fd0b676Sandi * 10023fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 1003ba11bd29Sandi * 1004ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 1005ba11bd29Sandi */ 1006433bef32Sandi function _formatLink($link){ 1007ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 1008ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 1009ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 1010ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 1011ba11bd29Sandi } 1012ba11bd29Sandi //remove double encodings in titles 1013ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 1014ba11bd29Sandi 1015453493f2SAndreas Gohr // be sure there are no bad chars in url or title 1016453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 1017453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 1018453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 1019453493f2SAndreas Gohr 1020ba11bd29Sandi $ret = ''; 1021ba11bd29Sandi $ret .= $link['pre']; 1022ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 1023bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 1024bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 1025bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1026bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 102744a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 1028bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1029ba11bd29Sandi $ret .= '>'; 1030ba11bd29Sandi $ret .= $link['name']; 1031ba11bd29Sandi $ret .= '</a>'; 1032ba11bd29Sandi $ret .= $link['suf']; 1033ba11bd29Sandi return $ret; 1034ba11bd29Sandi } 1035ba11bd29Sandi 1036ba11bd29Sandi /** 10373fd0b676Sandi * Renders internal and external media 10383fd0b676Sandi * 10393fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10403fd0b676Sandi */ 10413fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 1042b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 10433fd0b676Sandi 10443fd0b676Sandi $ret = ''; 10453fd0b676Sandi 1046ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10473fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1048b739ff0fSPierre Spring // first get the $title 1049b739ff0fSPierre Spring if (!is_null($title)) { 1050b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1051b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1052b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1053b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 105467f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1055b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1056b739ff0fSPierre Spring if($cap){ 1057b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1058b739ff0fSPierre Spring } 1059b739ff0fSPierre Spring } 1060b739ff0fSPierre Spring if (!$render) { 1061b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1062b739ff0fSPierre Spring // return the title of the picture 1063b739ff0fSPierre Spring if (!$title) { 1064b739ff0fSPierre Spring // just show the sourcename 1065b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1066b739ff0fSPierre Spring } 1067b739ff0fSPierre Spring return $title; 1068b739ff0fSPierre Spring } 10693fd0b676Sandi //add image tag 10706de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10713fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10723fd0b676Sandi 10734ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10744ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10754ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10764ab889eaSAndreas Gohr 1077b739ff0fSPierre Spring if ($title) { 1078b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1079b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10803fd0b676Sandi }else{ 10813fd0b676Sandi $ret .= ' alt=""'; 10823fd0b676Sandi } 10833fd0b676Sandi 10843fd0b676Sandi if ( !is_null($width) ) 10853fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10863fd0b676Sandi 10873fd0b676Sandi if ( !is_null($height) ) 10883fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10893fd0b676Sandi 10903fd0b676Sandi $ret .= ' />'; 10913fd0b676Sandi 10923fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10931c882ba8SAndreas Gohr if (!$render) { 10941c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10951c882ba8SAndreas Gohr // return the title of the flash 10961c882ba8SAndreas Gohr if (!$title) { 10971c882ba8SAndreas Gohr // just show the sourcename 109807bf32b2SAndreas Gohr $title = basename(noNS($src)); 10991c882ba8SAndreas Gohr } 110007bf32b2SAndreas Gohr return $this->_xmlEntities($title); 11011c882ba8SAndreas Gohr } 11021c882ba8SAndreas Gohr 110307bf32b2SAndreas Gohr $att = array(); 110407bf32b2SAndreas Gohr $att['class'] = "media$align"; 110507bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 110607bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1107c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 110807bf32b2SAndreas Gohr array('quality' => 'high'), 110907bf32b2SAndreas Gohr null, 111007bf32b2SAndreas Gohr $att, 111107bf32b2SAndreas Gohr $this->_xmlEntities($title)); 11120f428d7dSAndreas Gohr }elseif($title){ 11133fd0b676Sandi // well at least we have a title to display 11143fd0b676Sandi $ret .= $this->_xmlEntities($title); 11153fd0b676Sandi }else{ 11165291ca3aSAndreas Gohr // just show the sourcename 11170f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 11183fd0b676Sandi } 11193fd0b676Sandi 11203fd0b676Sandi return $ret; 11213fd0b676Sandi } 11223fd0b676Sandi 1123433bef32Sandi function _xmlEntities($string) { 1124de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 11250cecf9d5Sandi } 11260cecf9d5Sandi 11278a831f2bSAndreas Gohr /** 11288a831f2bSAndreas Gohr * Creates a linkid from a headline 1129c5a8fd96SAndreas Gohr * 1130c5a8fd96SAndreas Gohr * @param string $title The headline title 1131c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1132c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11338a831f2bSAndreas Gohr */ 1134c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1135c5a8fd96SAndreas Gohr if($create){ 11364ceab83fSAndreas Gohr return sectionID($title,$this->headers); 11374ceab83fSAndreas Gohr }else{ 1138443d207bSAndreas Gohr $check = false; 1139443d207bSAndreas Gohr return sectionID($title,$check); 1140c5a8fd96SAndreas Gohr } 11410cecf9d5Sandi } 11420cecf9d5Sandi 1143af587fa8Sandi /** 11443fd0b676Sandi * Construct a title and handle images in titles 11453fd0b676Sandi * 11460b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11473fd0b676Sandi */ 1148fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1149bb0a59d4Sjan global $conf; 1150bb0a59d4Sjan 115144881bd0Shenning.noren $isImage = false; 115229657f9eSAndreas Gohr if ( is_array($title) ) { 115329657f9eSAndreas Gohr $isImage = true; 115429657f9eSAndreas Gohr return $this->_imageTitle($title); 115529657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1156fe9ec250SChris Smith if (useHeading($linktype) && $id) { 115767c15eceSMichael Hamann $heading = p_get_first_heading($id); 1158bb0a59d4Sjan if ($heading) { 1159433bef32Sandi return $this->_xmlEntities($heading); 1160bb0a59d4Sjan } 1161bb0a59d4Sjan } 1162433bef32Sandi return $this->_xmlEntities($default); 116368c26e6dSMichael Klier } else { 116468c26e6dSMichael Klier return $this->_xmlEntities($title); 11650cecf9d5Sandi } 11660cecf9d5Sandi } 11670cecf9d5Sandi 11680cecf9d5Sandi /** 11693fd0b676Sandi * Returns an HTML code for images used in link titles 11703fd0b676Sandi * 11713fd0b676Sandi * @todo Resolve namespace on internal images 11723fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11730cecf9d5Sandi */ 1174433bef32Sandi function _imageTitle($img) { 1175d9baf1a7SKazutaka Miyasaka global $ID; 1176d9baf1a7SKazutaka Miyasaka 1177d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1178d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1179d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1180d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1181d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1182d9baf1a7SKazutaka Miyasaka } 1183d9baf1a7SKazutaka Miyasaka 1184433bef32Sandi return $this->_media($img['src'], 11854826ab45Sandi $img['title'], 11864826ab45Sandi $img['align'], 11874826ab45Sandi $img['width'], 11884826ab45Sandi $img['height'], 11894826ab45Sandi $img['cache']); 11900cecf9d5Sandi } 1191b739ff0fSPierre Spring 1192b739ff0fSPierre Spring /** 1193b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1194b739ff0fSPierre Spring * which returns a basic link to a media. 1195b739ff0fSPierre Spring * 1196b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1197b739ff0fSPierre Spring * @param string $src 1198b739ff0fSPierre Spring * @param string $title 1199b739ff0fSPierre Spring * @param string $align 1200b739ff0fSPierre Spring * @param string $width 1201b739ff0fSPierre Spring * @param string $height 1202b739ff0fSPierre Spring * @param string $cache 1203b739ff0fSPierre Spring * @param string $render 1204b739ff0fSPierre Spring * @access protected 1205b739ff0fSPierre Spring * @return array 1206b739ff0fSPierre Spring */ 1207b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1208b739ff0fSPierre Spring { 1209b739ff0fSPierre Spring global $conf; 1210b739ff0fSPierre Spring 1211b739ff0fSPierre Spring $link = array(); 1212b739ff0fSPierre Spring $link['class'] = 'media'; 1213b739ff0fSPierre Spring $link['style'] = ''; 1214b739ff0fSPierre Spring $link['pre'] = ''; 1215b739ff0fSPierre Spring $link['suf'] = ''; 1216b739ff0fSPierre Spring $link['more'] = ''; 1217b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1218b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1219b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1220b739ff0fSPierre Spring 1221b739ff0fSPierre Spring return $link; 1222b739ff0fSPierre Spring } 122391459163SAnika Henke 122491459163SAnika Henke 12250cecf9d5Sandi} 12260cecf9d5Sandi 1227e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1228