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 200cecf9d5Sandi/** 213dd5c225SAndreas Gohr * The XHTML Renderer 223dd5c225SAndreas Gohr * 233dd5c225SAndreas Gohr * This is DokuWiki's main renderer used to display page content in the wiki 240cecf9d5Sandi */ 25ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer { 263dd5c225SAndreas Gohr /** @var array store the table of contents */ 273dd5c225SAndreas Gohr public $toc = array(); 280cecf9d5Sandi 293dd5c225SAndreas Gohr /** @var array A stack of section edit data */ 303dd5c225SAndreas Gohr protected $sectionedits = array(); 314bde2196Slisps var $date_at = ''; // link pages and media against this revision 32c5a8fd96SAndreas Gohr 333dd5c225SAndreas Gohr /** @var int last section edit id, used by startSectionEdit */ 343dd5c225SAndreas Gohr protected $lastsecid = 0; 350cecf9d5Sandi 363dd5c225SAndreas Gohr /** @var array the list of headers used to create unique link ids */ 373dd5c225SAndreas Gohr protected $headers = array(); 383dd5c225SAndreas Gohr 3916ec3e37SAndreas Gohr /** @var array a list of footnotes, list starts at 1! */ 403dd5c225SAndreas Gohr protected $footnotes = array(); 417764a90aSandi 423dd5c225SAndreas Gohr /** @var int current section level */ 433dd5c225SAndreas Gohr protected $lastlevel = 0; 443dd5c225SAndreas Gohr /** @var array section node tracker */ 453dd5c225SAndreas Gohr protected $node = array(0, 0, 0, 0, 0); 463dd5c225SAndreas Gohr 473dd5c225SAndreas Gohr /** @var string temporary $doc store */ 483dd5c225SAndreas Gohr protected $store = ''; 493dd5c225SAndreas Gohr 503dd5c225SAndreas Gohr /** @var array global counter, for table classes etc. */ 513dd5c225SAndreas Gohr protected $_counter = array(); // 523dd5c225SAndreas Gohr 533dd5c225SAndreas Gohr /** @var int counts the code and file blocks, used to provide download links */ 543dd5c225SAndreas Gohr protected $_codeblock = 0; 553dd5c225SAndreas Gohr 563dd5c225SAndreas Gohr /** @var array list of allowed URL schemes */ 573dd5c225SAndreas Gohr protected $schemes = null; 58b5742cedSPierre Spring 5990df9a4dSAdrian Lang /** 6090df9a4dSAdrian Lang * Register a new edit section range 6190df9a4dSAdrian Lang * 6242ea7f44SGerrit Uitslag * @param string $type The section type identifier 6342ea7f44SGerrit Uitslag * @param string $title The section title 6442ea7f44SGerrit Uitslag * @param int $start The byte position for the edit start 6590df9a4dSAdrian Lang * @return string A marker class for the starting HTML element 6642ea7f44SGerrit Uitslag * 6790df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 6890df9a4dSAdrian Lang */ 693f9e3215SAdrian Lang public function startSectionEdit($start, $type, $title = null) { 70b04a190dSMichael Hamann $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title); 71b04a190dSMichael Hamann return 'sectionedit'.$this->lastsecid; 7290df9a4dSAdrian Lang } 7390df9a4dSAdrian Lang 7490df9a4dSAdrian Lang /** 7590df9a4dSAdrian Lang * Finish an edit section range 7690df9a4dSAdrian Lang * 7742ea7f44SGerrit Uitslag * @param int $end The byte position for the edit end; null for the rest of the page 7842ea7f44SGerrit Uitslag * 7990df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 8090df9a4dSAdrian Lang */ 813f9e3215SAdrian Lang public function finishSectionEdit($end = null) { 8290df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 83d9e36cbeSAdrian Lang if(!is_null($end) && $end <= $start) { 8400c13053SAdrian Lang return; 8500c13053SAdrian Lang } 8640868f2fSAdrian Lang $this->doc .= "<!-- EDIT$id ".strtoupper($type).' '; 8740868f2fSAdrian Lang if(!is_null($title)) { 8840868f2fSAdrian Lang $this->doc .= '"'.str_replace('"', '', $title).'" '; 8940868f2fSAdrian Lang } 90d9e36cbeSAdrian Lang $this->doc .= "[$start-".(is_null($end) ? '' : $end).'] -->'; 9190df9a4dSAdrian Lang } 9290df9a4dSAdrian Lang 933dd5c225SAndreas Gohr /** 943dd5c225SAndreas Gohr * Returns the format produced by this renderer. 953dd5c225SAndreas Gohr * 963dd5c225SAndreas Gohr * @return string always 'xhtml' 973dd5c225SAndreas Gohr */ 985f70445dSAndreas Gohr function getFormat() { 995f70445dSAndreas Gohr return 'xhtml'; 1005f70445dSAndreas Gohr } 1015f70445dSAndreas Gohr 1023dd5c225SAndreas Gohr /** 1033dd5c225SAndreas Gohr * Initialize the document 1043dd5c225SAndreas Gohr */ 1050cecf9d5Sandi function document_start() { 106c5a8fd96SAndreas Gohr //reset some internals 107c5a8fd96SAndreas Gohr $this->toc = array(); 108c5a8fd96SAndreas Gohr $this->headers = array(); 1090cecf9d5Sandi } 1100cecf9d5Sandi 1113dd5c225SAndreas Gohr /** 1123dd5c225SAndreas Gohr * Finalize the document 1133dd5c225SAndreas Gohr */ 1140cecf9d5Sandi function document_end() { 11590df9a4dSAdrian Lang // Finish open section edits. 11690df9a4dSAdrian Lang while(count($this->sectionedits) > 0) { 11790df9a4dSAdrian Lang if($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 11890df9a4dSAdrian Lang // If there is only one section, do not write a section edit 11990df9a4dSAdrian Lang // marker. 12090df9a4dSAdrian Lang array_pop($this->sectionedits); 12190df9a4dSAdrian Lang } else { 122d9e36cbeSAdrian Lang $this->finishSectionEdit(); 12390df9a4dSAdrian Lang } 12490df9a4dSAdrian Lang } 12590df9a4dSAdrian Lang 1260cecf9d5Sandi if(count($this->footnotes) > 0) { 127a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 128d74aace9Schris 12916ec3e37SAndreas Gohr foreach($this->footnotes as $id => $footnote) { 130d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 131d74aace9Schris if(substr($footnote, 0, 5) != "@@FNT") { 132d74aace9Schris 133d74aace9Schris // open the footnote and set the anchor and backlink 134d74aace9Schris $this->doc .= '<div class="fn">'; 13516cc7ed7SAnika Henke $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">'; 13629bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 137d74aace9Schris 138d74aace9Schris // get any other footnotes that use the same markup 139d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 140d74aace9Schris 141d74aace9Schris if(count($alt)) { 142d74aace9Schris foreach($alt as $ref) { 143d74aace9Schris // set anchor and backlink for the other footnotes 14416ec3e37SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">'; 14516ec3e37SAndreas Gohr $this->doc .= ($ref).')</a></sup> '.DOKU_LF; 146d74aace9Schris } 147d74aace9Schris } 148d74aace9Schris 149d74aace9Schris // add footnote markup and close this footnote 150a2d649c4Sandi $this->doc .= $footnote; 151d74aace9Schris $this->doc .= '</div>'.DOKU_LF; 152d74aace9Schris } 1530cecf9d5Sandi } 154a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 1550cecf9d5Sandi } 156c5a8fd96SAndreas Gohr 157b8595a66SAndreas Gohr // Prepare the TOC 158851f2e89SAnika Henke global $conf; 159851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']) { 160b8595a66SAndreas Gohr global $TOC; 161b8595a66SAndreas Gohr $TOC = $this->toc; 1620cecf9d5Sandi } 1633e55d035SAndreas Gohr 1643e55d035SAndreas Gohr // make sure there are no empty paragraphs 16527918226Schris $this->doc = preg_replace('#<p>\s*</p>#', '', $this->doc); 166e41c4da9SAndreas Gohr } 1670cecf9d5Sandi 1683dd5c225SAndreas Gohr /** 1693dd5c225SAndreas Gohr * Add an item to the TOC 1703dd5c225SAndreas Gohr * 1713dd5c225SAndreas Gohr * @param string $id the hash link 1723dd5c225SAndreas Gohr * @param string $text the text to display 1733dd5c225SAndreas Gohr * @param int $level the nesting level 1743dd5c225SAndreas Gohr */ 175e7856beaSchris function toc_additem($id, $text, $level) { 176af587fa8Sandi global $conf; 177af587fa8Sandi 178c5a8fd96SAndreas Gohr //handle TOC 179c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) { 1807d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1); 181c5a8fd96SAndreas Gohr } 182e7856beaSchris } 183e7856beaSchris 1843dd5c225SAndreas Gohr /** 1853dd5c225SAndreas Gohr * Render a heading 1863dd5c225SAndreas Gohr * 1873dd5c225SAndreas Gohr * @param string $text the text to display 1883dd5c225SAndreas Gohr * @param int $level header level 1893dd5c225SAndreas Gohr * @param int $pos byte position in the original source 1903dd5c225SAndreas Gohr */ 191e7856beaSchris function header($text, $level, $pos) { 19290df9a4dSAdrian Lang global $conf; 19390df9a4dSAdrian Lang 194bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 195e7856beaSchris 196e7856beaSchris $hid = $this->_headerToLink($text, true); 197e7856beaSchris 198e7856beaSchris //only add items within configured levels 199e7856beaSchris $this->toc_additem($hid, $text, $level); 200c5a8fd96SAndreas Gohr 20191459163SAnika Henke // adjust $node to reflect hierarchy of levels 20291459163SAnika Henke $this->node[$level - 1]++; 20391459163SAnika Henke if($level < $this->lastlevel) { 20491459163SAnika Henke for($i = 0; $i < $this->lastlevel - $level; $i++) { 20591459163SAnika Henke $this->node[$this->lastlevel - $i - 1] = 0; 20691459163SAnika Henke } 20791459163SAnika Henke } 20891459163SAnika Henke $this->lastlevel = $level; 20991459163SAnika Henke 21090df9a4dSAdrian Lang if($level <= $conf['maxseclevel'] && 21190df9a4dSAdrian Lang count($this->sectionedits) > 0 && 2123dd5c225SAndreas Gohr $this->sectionedits[count($this->sectionedits) - 1][2] === 'section' 2133dd5c225SAndreas Gohr ) { 2146c1f778cSAdrian Lang $this->finishSectionEdit($pos - 1); 21590df9a4dSAdrian Lang } 21690df9a4dSAdrian Lang 217c5a8fd96SAndreas Gohr // write the header 21890df9a4dSAdrian Lang $this->doc .= DOKU_LF.'<h'.$level; 21990df9a4dSAdrian Lang if($level <= $conf['maxseclevel']) { 22090df9a4dSAdrian Lang $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text).'"'; 22190df9a4dSAdrian Lang } 22216cc7ed7SAnika Henke $this->doc .= ' id="'.$hid.'">'; 223a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 22416cc7ed7SAnika Henke $this->doc .= "</h$level>".DOKU_LF; 2250cecf9d5Sandi } 2260cecf9d5Sandi 2273dd5c225SAndreas Gohr /** 2283dd5c225SAndreas Gohr * Open a new section 2293dd5c225SAndreas Gohr * 2303dd5c225SAndreas Gohr * @param int $level section level (as determined by the previous header) 2313dd5c225SAndreas Gohr */ 2320cecf9d5Sandi function section_open($level) { 2339864e7b1SAdrian Lang $this->doc .= '<div class="level'.$level.'">'.DOKU_LF; 2340cecf9d5Sandi } 2350cecf9d5Sandi 2363dd5c225SAndreas Gohr /** 2373dd5c225SAndreas Gohr * Close the current section 2383dd5c225SAndreas Gohr */ 2390cecf9d5Sandi function section_close() { 240a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 2410cecf9d5Sandi } 2420cecf9d5Sandi 2433dd5c225SAndreas Gohr /** 2443dd5c225SAndreas Gohr * Render plain text data 2453dd5c225SAndreas Gohr * 2463dd5c225SAndreas Gohr * @param $text 2473dd5c225SAndreas Gohr */ 2480cecf9d5Sandi function cdata($text) { 249a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 2500cecf9d5Sandi } 2510cecf9d5Sandi 2523dd5c225SAndreas Gohr /** 2533dd5c225SAndreas Gohr * Open a paragraph 2543dd5c225SAndreas Gohr */ 2550cecf9d5Sandi function p_open() { 25659869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 2570cecf9d5Sandi } 2580cecf9d5Sandi 2593dd5c225SAndreas Gohr /** 2603dd5c225SAndreas Gohr * Close a paragraph 2613dd5c225SAndreas Gohr */ 2620cecf9d5Sandi function p_close() { 26359869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 2640cecf9d5Sandi } 2650cecf9d5Sandi 2663dd5c225SAndreas Gohr /** 2673dd5c225SAndreas Gohr * Create a line break 2683dd5c225SAndreas Gohr */ 2690cecf9d5Sandi function linebreak() { 270a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 2710cecf9d5Sandi } 2720cecf9d5Sandi 2733dd5c225SAndreas Gohr /** 2743dd5c225SAndreas Gohr * Create a horizontal line 2753dd5c225SAndreas Gohr */ 2760cecf9d5Sandi function hr() { 2774beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 2780cecf9d5Sandi } 2790cecf9d5Sandi 2803dd5c225SAndreas Gohr /** 2813dd5c225SAndreas Gohr * Start strong (bold) formatting 2823dd5c225SAndreas Gohr */ 2830cecf9d5Sandi function strong_open() { 284a2d649c4Sandi $this->doc .= '<strong>'; 2850cecf9d5Sandi } 2860cecf9d5Sandi 2873dd5c225SAndreas Gohr /** 2883dd5c225SAndreas Gohr * Stop strong (bold) formatting 2893dd5c225SAndreas Gohr */ 2900cecf9d5Sandi function strong_close() { 291a2d649c4Sandi $this->doc .= '</strong>'; 2920cecf9d5Sandi } 2930cecf9d5Sandi 2943dd5c225SAndreas Gohr /** 2953dd5c225SAndreas Gohr * Start emphasis (italics) formatting 2963dd5c225SAndreas Gohr */ 2970cecf9d5Sandi function emphasis_open() { 298a2d649c4Sandi $this->doc .= '<em>'; 2990cecf9d5Sandi } 3000cecf9d5Sandi 3013dd5c225SAndreas Gohr /** 3023dd5c225SAndreas Gohr * Stop emphasis (italics) formatting 3033dd5c225SAndreas Gohr */ 3040cecf9d5Sandi function emphasis_close() { 305a2d649c4Sandi $this->doc .= '</em>'; 3060cecf9d5Sandi } 3070cecf9d5Sandi 3083dd5c225SAndreas Gohr /** 3093dd5c225SAndreas Gohr * Start underline formatting 3103dd5c225SAndreas Gohr */ 3110cecf9d5Sandi function underline_open() { 31202e51121SAnika Henke $this->doc .= '<em class="u">'; 3130cecf9d5Sandi } 3140cecf9d5Sandi 3153dd5c225SAndreas Gohr /** 3163dd5c225SAndreas Gohr * Stop underline formatting 3173dd5c225SAndreas Gohr */ 3180cecf9d5Sandi function underline_close() { 31902e51121SAnika Henke $this->doc .= '</em>'; 3200cecf9d5Sandi } 3210cecf9d5Sandi 3223dd5c225SAndreas Gohr /** 3233dd5c225SAndreas Gohr * Start monospace formatting 3243dd5c225SAndreas Gohr */ 3250cecf9d5Sandi function monospace_open() { 326a2d649c4Sandi $this->doc .= '<code>'; 3270cecf9d5Sandi } 3280cecf9d5Sandi 3293dd5c225SAndreas Gohr /** 3303dd5c225SAndreas Gohr * Stop monospace formatting 3313dd5c225SAndreas Gohr */ 3320cecf9d5Sandi function monospace_close() { 333a2d649c4Sandi $this->doc .= '</code>'; 3340cecf9d5Sandi } 3350cecf9d5Sandi 3363dd5c225SAndreas Gohr /** 3373dd5c225SAndreas Gohr * Start a subscript 3383dd5c225SAndreas Gohr */ 3390cecf9d5Sandi function subscript_open() { 340a2d649c4Sandi $this->doc .= '<sub>'; 3410cecf9d5Sandi } 3420cecf9d5Sandi 3433dd5c225SAndreas Gohr /** 3443dd5c225SAndreas Gohr * Stop a subscript 3453dd5c225SAndreas Gohr */ 3460cecf9d5Sandi function subscript_close() { 347a2d649c4Sandi $this->doc .= '</sub>'; 3480cecf9d5Sandi } 3490cecf9d5Sandi 3503dd5c225SAndreas Gohr /** 3513dd5c225SAndreas Gohr * Start a superscript 3523dd5c225SAndreas Gohr */ 3530cecf9d5Sandi function superscript_open() { 354a2d649c4Sandi $this->doc .= '<sup>'; 3550cecf9d5Sandi } 3560cecf9d5Sandi 3573dd5c225SAndreas Gohr /** 3583dd5c225SAndreas Gohr * Stop a superscript 3593dd5c225SAndreas Gohr */ 3600cecf9d5Sandi function superscript_close() { 361a2d649c4Sandi $this->doc .= '</sup>'; 3620cecf9d5Sandi } 3630cecf9d5Sandi 3643dd5c225SAndreas Gohr /** 3653dd5c225SAndreas Gohr * Start deleted (strike-through) formatting 3663dd5c225SAndreas Gohr */ 3670cecf9d5Sandi function deleted_open() { 368a2d649c4Sandi $this->doc .= '<del>'; 3690cecf9d5Sandi } 3700cecf9d5Sandi 3713dd5c225SAndreas Gohr /** 3723dd5c225SAndreas Gohr * Stop deleted (strike-through) formatting 3733dd5c225SAndreas Gohr */ 3740cecf9d5Sandi function deleted_close() { 375a2d649c4Sandi $this->doc .= '</del>'; 3760cecf9d5Sandi } 3770cecf9d5Sandi 3783fd0b676Sandi /** 3793fd0b676Sandi * Callback for footnote start syntax 3803fd0b676Sandi * 3813fd0b676Sandi * All following content will go to the footnote instead of 382d74aace9Schris * the document. To achieve this the previous rendered content 3833fd0b676Sandi * is moved to $store and $doc is cleared 3843fd0b676Sandi * 3853fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3863fd0b676Sandi */ 3870cecf9d5Sandi function footnote_open() { 3887764a90aSandi 3897764a90aSandi // move current content to store and record footnote 3907764a90aSandi $this->store = $this->doc; 3917764a90aSandi $this->doc = ''; 3920cecf9d5Sandi } 3930cecf9d5Sandi 3943fd0b676Sandi /** 3953fd0b676Sandi * Callback for footnote end syntax 3963fd0b676Sandi * 3973fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 3983fd0b676Sandi * content is restored from $store again 3993fd0b676Sandi * 4003fd0b676Sandi * @author Andreas Gohr 4013fd0b676Sandi */ 4020cecf9d5Sandi function footnote_close() { 40316ec3e37SAndreas Gohr /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */ 40416ec3e37SAndreas Gohr static $fnid = 0; 40516ec3e37SAndreas Gohr // assign new footnote id (we start at 1) 40616ec3e37SAndreas Gohr $fnid++; 4077764a90aSandi 408d74aace9Schris // recover footnote into the stack and restore old content 409d74aace9Schris $footnote = $this->doc; 4107764a90aSandi $this->doc = $this->store; 4117764a90aSandi $this->store = ''; 412d74aace9Schris 413d74aace9Schris // check to see if this footnote has been seen before 414d74aace9Schris $i = array_search($footnote, $this->footnotes); 415d74aace9Schris 416d74aace9Schris if($i === false) { 417d74aace9Schris // its a new footnote, add it to the $footnotes array 41816ec3e37SAndreas Gohr $this->footnotes[$fnid] = $footnote; 419d74aace9Schris } else { 42016ec3e37SAndreas Gohr // seen this one before, save a placeholder 42116ec3e37SAndreas Gohr $this->footnotes[$fnid] = "@@FNT".($i); 422d74aace9Schris } 423d74aace9Schris 4246b379cbfSAndreas Gohr // output the footnote reference and link 42516ec3e37SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>'; 4260cecf9d5Sandi } 4270cecf9d5Sandi 4283dd5c225SAndreas Gohr /** 4293dd5c225SAndreas Gohr * Open an unordered list 4300c4c0281SGerrit Uitslag * 4317d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 4323dd5c225SAndreas Gohr */ 4330c4c0281SGerrit Uitslag function listu_open($classes = null) { 4340c4c0281SGerrit Uitslag $class = ''; 4350c4c0281SGerrit Uitslag if($classes !== null) { 4362e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 4370c4c0281SGerrit Uitslag $class = " class=\"$classes\""; 4380c4c0281SGerrit Uitslag } 4390c4c0281SGerrit Uitslag $this->doc .= "<ul$class>".DOKU_LF; 4400cecf9d5Sandi } 4410cecf9d5Sandi 4423dd5c225SAndreas Gohr /** 4433dd5c225SAndreas Gohr * Close an unordered list 4443dd5c225SAndreas Gohr */ 4450cecf9d5Sandi function listu_close() { 446a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 4470cecf9d5Sandi } 4480cecf9d5Sandi 4493dd5c225SAndreas Gohr /** 4503dd5c225SAndreas Gohr * Open an ordered list 4510c4c0281SGerrit Uitslag * 4527d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 4533dd5c225SAndreas Gohr */ 4540c4c0281SGerrit Uitslag function listo_open($classes = null) { 4550c4c0281SGerrit Uitslag $class = ''; 4560c4c0281SGerrit Uitslag if($classes !== null) { 4572e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 4580c4c0281SGerrit Uitslag $class = " class=\"$classes\""; 4590c4c0281SGerrit Uitslag } 4600c4c0281SGerrit Uitslag $this->doc .= "<ol$class>".DOKU_LF; 4610cecf9d5Sandi } 4620cecf9d5Sandi 4633dd5c225SAndreas Gohr /** 4643dd5c225SAndreas Gohr * Close an ordered list 4653dd5c225SAndreas Gohr */ 4660cecf9d5Sandi function listo_close() { 467a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 4680cecf9d5Sandi } 4690cecf9d5Sandi 4703dd5c225SAndreas Gohr /** 4713dd5c225SAndreas Gohr * Open a list item 4723dd5c225SAndreas Gohr * 4733dd5c225SAndreas Gohr * @param int $level the nesting level 474e3a24861SChristopher Smith * @param bool $node true when a node; false when a leaf 4753dd5c225SAndreas Gohr */ 476e3a24861SChristopher Smith function listitem_open($level, $node=false) { 477e3a24861SChristopher Smith $branching = $node ? ' node' : ''; 478e3a24861SChristopher Smith $this->doc .= '<li class="level'.$level.$branching.'">'; 4790cecf9d5Sandi } 4800cecf9d5Sandi 4813dd5c225SAndreas Gohr /** 4823dd5c225SAndreas Gohr * Close a list item 4833dd5c225SAndreas Gohr */ 4840cecf9d5Sandi function listitem_close() { 485a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 4860cecf9d5Sandi } 4870cecf9d5Sandi 4883dd5c225SAndreas Gohr /** 4893dd5c225SAndreas Gohr * Start the content of a list item 4903dd5c225SAndreas Gohr */ 4910cecf9d5Sandi function listcontent_open() { 49290db23d7Schris $this->doc .= '<div class="li">'; 4930cecf9d5Sandi } 4940cecf9d5Sandi 4953dd5c225SAndreas Gohr /** 4963dd5c225SAndreas Gohr * Stop the content of a list item 4973dd5c225SAndreas Gohr */ 4980cecf9d5Sandi function listcontent_close() { 49959869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 5000cecf9d5Sandi } 5010cecf9d5Sandi 5023dd5c225SAndreas Gohr /** 5033dd5c225SAndreas Gohr * Output unformatted $text 5043dd5c225SAndreas Gohr * 5053dd5c225SAndreas Gohr * Defaults to $this->cdata() 5063dd5c225SAndreas Gohr * 5073dd5c225SAndreas Gohr * @param string $text 5083dd5c225SAndreas Gohr */ 5090cecf9d5Sandi function unformatted($text) { 510a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 5110cecf9d5Sandi } 5120cecf9d5Sandi 5130cecf9d5Sandi /** 5143fd0b676Sandi * Execute PHP code if allowed 5153fd0b676Sandi * 516d9764001SMichael Hamann * @param string $text PHP code that is either executed or printed 5175d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 5185d568b99SChris Smith * 5193fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 5200cecf9d5Sandi */ 5215d568b99SChris Smith function php($text, $wrapper = 'code') { 52235a56260SChris Smith global $conf; 52335a56260SChris Smith 524d86d5af0SChris Smith if($conf['phpok']) { 525bad0b545Sandi ob_start(); 5264de671bcSandi eval($text); 5273fd0b676Sandi $this->doc .= ob_get_contents(); 528bad0b545Sandi ob_end_clean(); 529d86d5af0SChris Smith } else { 5305d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 531d86d5af0SChris Smith } 5320cecf9d5Sandi } 5330cecf9d5Sandi 5343dd5c225SAndreas Gohr /** 5353dd5c225SAndreas Gohr * Output block level PHP code 5363dd5c225SAndreas Gohr * 5373dd5c225SAndreas Gohr * If $conf['phpok'] is true this should evaluate the given code and append the result 5383dd5c225SAndreas Gohr * to $doc 5393dd5c225SAndreas Gohr * 5403dd5c225SAndreas Gohr * @param string $text The PHP code 5413dd5c225SAndreas Gohr */ 54207f89c3cSAnika Henke function phpblock($text) { 5435d568b99SChris Smith $this->php($text, 'pre'); 54407f89c3cSAnika Henke } 54507f89c3cSAnika Henke 5460cecf9d5Sandi /** 5473fd0b676Sandi * Insert HTML if allowed 5483fd0b676Sandi * 549d9764001SMichael Hamann * @param string $text html text 5505d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 5515d568b99SChris Smith * 5523fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 5530cecf9d5Sandi */ 5545d568b99SChris Smith function html($text, $wrapper = 'code') { 55535a56260SChris Smith global $conf; 55635a56260SChris Smith 557d86d5af0SChris Smith if($conf['htmlok']) { 558a2d649c4Sandi $this->doc .= $text; 559d86d5af0SChris Smith } else { 5605d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 561d86d5af0SChris Smith } 5624de671bcSandi } 5630cecf9d5Sandi 5643dd5c225SAndreas Gohr /** 5653dd5c225SAndreas Gohr * Output raw block-level HTML 5663dd5c225SAndreas Gohr * 5673dd5c225SAndreas Gohr * If $conf['htmlok'] is true this should add the code as is to $doc 5683dd5c225SAndreas Gohr * 5693dd5c225SAndreas Gohr * @param string $text The HTML 5703dd5c225SAndreas Gohr */ 57107f89c3cSAnika Henke function htmlblock($text) { 5725d568b99SChris Smith $this->html($text, 'pre'); 57307f89c3cSAnika Henke } 57407f89c3cSAnika Henke 5753dd5c225SAndreas Gohr /** 5763dd5c225SAndreas Gohr * Start a block quote 5773dd5c225SAndreas Gohr */ 5780cecf9d5Sandi function quote_open() { 57996331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 5800cecf9d5Sandi } 5810cecf9d5Sandi 5823dd5c225SAndreas Gohr /** 5833dd5c225SAndreas Gohr * Stop a block quote 5843dd5c225SAndreas Gohr */ 5850cecf9d5Sandi function quote_close() { 58696331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 5870cecf9d5Sandi } 5880cecf9d5Sandi 5893dd5c225SAndreas Gohr /** 5903dd5c225SAndreas Gohr * Output preformatted text 5913dd5c225SAndreas Gohr * 5923dd5c225SAndreas Gohr * @param string $text 5933dd5c225SAndreas Gohr */ 5943d491f75SAndreas Gohr function preformatted($text) { 595c9250713SAnika Henke $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.DOKU_LF; 5963d491f75SAndreas Gohr } 5973d491f75SAndreas Gohr 5983dd5c225SAndreas Gohr /** 5993dd5c225SAndreas Gohr * Display text as file content, optionally syntax highlighted 6003dd5c225SAndreas Gohr * 6013dd5c225SAndreas Gohr * @param string $text text to show 6023dd5c225SAndreas Gohr * @param string $language programming language to use for syntax highlighting 6033dd5c225SAndreas Gohr * @param string $filename file path label 6043dd5c225SAndreas Gohr */ 6053d491f75SAndreas Gohr function file($text, $language = null, $filename = null) { 6063d491f75SAndreas Gohr $this->_highlight('file', $text, $language, $filename); 6073d491f75SAndreas Gohr } 6083d491f75SAndreas Gohr 6093dd5c225SAndreas Gohr /** 6103dd5c225SAndreas Gohr * Display text as code content, optionally syntax highlighted 6113dd5c225SAndreas Gohr * 6123dd5c225SAndreas Gohr * @param string $text text to show 6133dd5c225SAndreas Gohr * @param string $language programming language to use for syntax highlighting 6143dd5c225SAndreas Gohr * @param string $filename file path label 6153dd5c225SAndreas Gohr */ 6163d491f75SAndreas Gohr function code($text, $language = null, $filename = null) { 6173d491f75SAndreas Gohr $this->_highlight('code', $text, $language, $filename); 6183d491f75SAndreas Gohr } 6193d491f75SAndreas Gohr 6200cecf9d5Sandi /** 6213d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 6223fd0b676Sandi * 6233fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 6243dd5c225SAndreas Gohr * @param string $type code|file 6253dd5c225SAndreas Gohr * @param string $text text to show 6263dd5c225SAndreas Gohr * @param string $language programming language to use for syntax highlighting 6273dd5c225SAndreas Gohr * @param string $filename file path label 6280cecf9d5Sandi */ 6293d491f75SAndreas Gohr function _highlight($type, $text, $language = null, $filename = null) { 6303d491f75SAndreas Gohr global $ID; 6313d491f75SAndreas Gohr global $lang; 6323d491f75SAndreas Gohr 6333d491f75SAndreas Gohr if($filename) { 634190c56e8SAndreas Gohr // add icon 63527bf7924STom N Harris list($ext) = mimetype($filename, false); 636190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 637190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 638190c56e8SAndreas Gohr 6393d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 640190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID, 'code', array('codeblock' => $this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 6413d491f75SAndreas Gohr $this->doc .= hsc($filename); 6423d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 6433d491f75SAndreas Gohr } 6440cecf9d5Sandi 645d43aac1cSGina Haeussge if($text{0} == "\n") { 646d43aac1cSGina Haeussge $text = substr($text, 1); 647d43aac1cSGina Haeussge } 648d43aac1cSGina Haeussge if(substr($text, -1) == "\n") { 649d43aac1cSGina Haeussge $text = substr($text, 0, -1); 650d43aac1cSGina Haeussge } 651d43aac1cSGina Haeussge 6520cecf9d5Sandi if(is_null($language)) { 6533d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 6540cecf9d5Sandi } else { 6553d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 6563d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 6573d491f75SAndreas Gohr 6583d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 6590cecf9d5Sandi } 6603d491f75SAndreas Gohr 6613d491f75SAndreas Gohr if($filename) { 6623d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 6633d491f75SAndreas Gohr } 6643d491f75SAndreas Gohr 6653d491f75SAndreas Gohr $this->_codeblock++; 6660cecf9d5Sandi } 6670cecf9d5Sandi 6683dd5c225SAndreas Gohr /** 6693dd5c225SAndreas Gohr * Format an acronym 6703dd5c225SAndreas Gohr * 6713dd5c225SAndreas Gohr * Uses $this->acronyms 6723dd5c225SAndreas Gohr * 6733dd5c225SAndreas Gohr * @param string $acronym 6743dd5c225SAndreas Gohr */ 6750cecf9d5Sandi function acronym($acronym) { 6760cecf9d5Sandi 6770cecf9d5Sandi if(array_key_exists($acronym, $this->acronyms)) { 6780cecf9d5Sandi 679433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 6800cecf9d5Sandi 681940db3a3SAnika Henke $this->doc .= '<abbr title="'.$title 682940db3a3SAnika Henke .'">'.$this->_xmlEntities($acronym).'</abbr>'; 6830cecf9d5Sandi 6840cecf9d5Sandi } else { 685a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 6860cecf9d5Sandi } 6870cecf9d5Sandi } 6880cecf9d5Sandi 6893dd5c225SAndreas Gohr /** 6903dd5c225SAndreas Gohr * Format a smiley 6913dd5c225SAndreas Gohr * 6923dd5c225SAndreas Gohr * Uses $this->smiley 6933dd5c225SAndreas Gohr * 6943dd5c225SAndreas Gohr * @param string $smiley 6953dd5c225SAndreas Gohr */ 6960cecf9d5Sandi function smiley($smiley) { 6970cecf9d5Sandi if(array_key_exists($smiley, $this->smileys)) { 698f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 6998e38227fSAnika Henke '" class="icon" alt="'. 700433bef32Sandi $this->_xmlEntities($smiley).'" />'; 7010cecf9d5Sandi } else { 702a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 7030cecf9d5Sandi } 7040cecf9d5Sandi } 7050cecf9d5Sandi 7063dd5c225SAndreas Gohr /** 7073dd5c225SAndreas Gohr * Format an entity 7083dd5c225SAndreas Gohr * 7093dd5c225SAndreas Gohr * Entities are basically small text replacements 7103dd5c225SAndreas Gohr * 7113dd5c225SAndreas Gohr * Uses $this->entities 7123dd5c225SAndreas Gohr * 7133dd5c225SAndreas Gohr * @param string $entity 7144de671bcSandi */ 7150cecf9d5Sandi function entity($entity) { 7160cecf9d5Sandi if(array_key_exists($entity, $this->entities)) { 717a2d649c4Sandi $this->doc .= $this->entities[$entity]; 7180cecf9d5Sandi } else { 719a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 7200cecf9d5Sandi } 7210cecf9d5Sandi } 7220cecf9d5Sandi 7233dd5c225SAndreas Gohr /** 7243dd5c225SAndreas Gohr * Typographically format a multiply sign 7253dd5c225SAndreas Gohr * 7263dd5c225SAndreas Gohr * Example: ($x=640, $y=480) should result in "640×480" 7273dd5c225SAndreas Gohr * 7283dd5c225SAndreas Gohr * @param string|int $x first value 7293dd5c225SAndreas Gohr * @param string|int $y second value 7303dd5c225SAndreas Gohr */ 7310cecf9d5Sandi function multiplyentity($x, $y) { 732a2d649c4Sandi $this->doc .= "$x×$y"; 7330cecf9d5Sandi } 7340cecf9d5Sandi 7353dd5c225SAndreas Gohr /** 7363dd5c225SAndreas Gohr * Render an opening single quote char (language specific) 7373dd5c225SAndreas Gohr */ 7380cecf9d5Sandi function singlequoteopening() { 73971b40da2SAnika Henke global $lang; 74071b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 7410cecf9d5Sandi } 7420cecf9d5Sandi 7433dd5c225SAndreas Gohr /** 7443dd5c225SAndreas Gohr * Render a closing single quote char (language specific) 7453dd5c225SAndreas Gohr */ 7460cecf9d5Sandi function singlequoteclosing() { 74771b40da2SAnika Henke global $lang; 74871b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 7490cecf9d5Sandi } 7500cecf9d5Sandi 7513dd5c225SAndreas Gohr /** 7523dd5c225SAndreas Gohr * Render an apostrophe char (language specific) 7533dd5c225SAndreas Gohr */ 75457d757d1SAndreas Gohr function apostrophe() { 75557d757d1SAndreas Gohr global $lang; 756a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 75757d757d1SAndreas Gohr } 75857d757d1SAndreas Gohr 7593dd5c225SAndreas Gohr /** 7603dd5c225SAndreas Gohr * Render an opening double quote char (language specific) 7613dd5c225SAndreas Gohr */ 7620cecf9d5Sandi function doublequoteopening() { 76371b40da2SAnika Henke global $lang; 76471b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 7650cecf9d5Sandi } 7660cecf9d5Sandi 7673dd5c225SAndreas Gohr /** 7683dd5c225SAndreas Gohr * Render an closinging double quote char (language specific) 7693dd5c225SAndreas Gohr */ 7700cecf9d5Sandi function doublequoteclosing() { 77171b40da2SAnika Henke global $lang; 77271b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 7730cecf9d5Sandi } 7740cecf9d5Sandi 7750cecf9d5Sandi /** 7763dd5c225SAndreas Gohr * Render a CamelCase link 7773dd5c225SAndreas Gohr * 7783dd5c225SAndreas Gohr * @param string $link The link name 779122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 7800c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 7810c4c0281SGerrit Uitslag * 7823dd5c225SAndreas Gohr * @see http://en.wikipedia.org/wiki/CamelCase 7830cecf9d5Sandi */ 784122f2d46SAndreas Böhler function camelcaselink($link, $returnonly = false) { 785122f2d46SAndreas Böhler if($returnonly) { 786122f2d46SAndreas Böhler return $this->internallink($link, $link, null, true); 787122f2d46SAndreas Böhler } else { 78811d0aa47Sandi $this->internallink($link, $link); 7890cecf9d5Sandi } 790122f2d46SAndreas Böhler } 7910cecf9d5Sandi 7923dd5c225SAndreas Gohr /** 7933dd5c225SAndreas Gohr * Render a page local link 7943dd5c225SAndreas Gohr * 7953dd5c225SAndreas Gohr * @param string $hash hash link identifier 7963dd5c225SAndreas Gohr * @param string $name name for the link 797122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 7980c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 7993dd5c225SAndreas Gohr */ 800122f2d46SAndreas Böhler function locallink($hash, $name = null, $returnonly = false) { 8010b7c14c2Sandi global $ID; 8020b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 8030b7c14c2Sandi $hash = $this->_headerToLink($hash); 804e260f93bSAnika Henke $title = $ID.' ↵'; 805122f2d46SAndreas Böhler 806122f2d46SAndreas Böhler $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 807122f2d46SAndreas Böhler $doc .= $name; 808122f2d46SAndreas Böhler $doc .= '</a>'; 809122f2d46SAndreas Böhler 810122f2d46SAndreas Böhler if($returnonly) { 811122f2d46SAndreas Böhler return $doc; 812122f2d46SAndreas Böhler } else { 813122f2d46SAndreas Böhler $this->doc .= $doc; 814122f2d46SAndreas Böhler } 8150b7c14c2Sandi } 8160b7c14c2Sandi 817cffcc403Sandi /** 8183fd0b676Sandi * Render an internal Wiki Link 8193fd0b676Sandi * 820fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 821cffcc403Sandi * elsewhere - no need to implement them in other renderers 8223fd0b676Sandi * 8233dd5c225SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 824f23eef27SGerrit Uitslag * @param string $id pageid 825f23eef27SGerrit Uitslag * @param string|null $name link name 826f23eef27SGerrit Uitslag * @param string|null $search adds search url param 827f23eef27SGerrit Uitslag * @param bool $returnonly whether to return html or write to doc attribute 828f23eef27SGerrit Uitslag * @param string $linktype type to set use of headings 829f23eef27SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 830cffcc403Sandi */ 8310ea51e63SMatt Perry function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { 832ba11bd29Sandi global $conf; 83337e34a5eSandi global $ID; 834c4dda6afSAnika Henke global $INFO; 83544653a53SAdrian Lang 8363d5e07d9SAdrian Lang $params = ''; 8373d5e07d9SAdrian Lang $parts = explode('?', $id, 2); 8383d5e07d9SAdrian Lang if(count($parts) === 2) { 8393d5e07d9SAdrian Lang $id = $parts[0]; 8403d5e07d9SAdrian Lang $params = $parts[1]; 84144653a53SAdrian Lang } 84244653a53SAdrian Lang 843fda14ffcSIzidor Matušov // For empty $id we need to know the current $ID 844fda14ffcSIzidor Matušov // We need this check because _simpleTitle needs 845fda14ffcSIzidor Matušov // correct $id and resolve_pageid() use cleanID($id) 846fda14ffcSIzidor Matušov // (some things could be lost) 847fda14ffcSIzidor Matušov if($id === '') { 848fda14ffcSIzidor Matušov $id = $ID; 849fda14ffcSIzidor Matušov } 850fda14ffcSIzidor Matušov 8510339c872Sjan // default name is based on $id as given 8520339c872Sjan $default = $this->_simpleTitle($id); 853ad32e47eSAndreas Gohr 8540339c872Sjan // now first resolve and clean up the $id 85590bee600Slisps resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true); 856fda14ffcSIzidor Matušov 85759bc3b48SGerrit Uitslag $link = array(); 858fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 8590e1c636eSandi if(!$isImage) { 8600e1c636eSandi if($exists) { 861ba11bd29Sandi $class = 'wikilink1'; 8620cecf9d5Sandi } else { 863ba11bd29Sandi $class = 'wikilink2'; 86444a6b4c7SAndreas Gohr $link['rel'] = 'nofollow'; 8650cecf9d5Sandi } 8660cecf9d5Sandi } else { 867ba11bd29Sandi $class = 'media'; 8680cecf9d5Sandi } 8690cecf9d5Sandi 870a1685bedSandi //keep hash anchor 8716d2af55dSChristopher Smith @list($id, $hash) = explode('#', $id, 2); 872943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 873a1685bedSandi 874ba11bd29Sandi //prepare for formating 875ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 876ba11bd29Sandi $link['style'] = ''; 877ba11bd29Sandi $link['pre'] = ''; 878ba11bd29Sandi $link['suf'] = ''; 87940eb54bbSjan // highlight link to current page 880c4dda6afSAnika Henke if($id == $INFO['id']) { 88192795d04Sandi $link['pre'] = '<span class="curid">'; 88292795d04Sandi $link['suf'] = '</span>'; 88340eb54bbSjan } 8845e163278SAndreas Gohr $link['more'] = ''; 885ba11bd29Sandi $link['class'] = $class; 8865c2eed9aSlisps if($this->date_at) { 8875c2eed9aSlisps $params['at'] = $this->date_at; 8885c2eed9aSlisps } 88944653a53SAdrian Lang $link['url'] = wl($id, $params); 890ba11bd29Sandi $link['name'] = $name; 891ba11bd29Sandi $link['title'] = $id; 892723d78dbSandi //add search string 893723d78dbSandi if($search) { 894546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&'; 895546d3a99SAndreas Gohr if(is_array($search)) { 896546d3a99SAndreas Gohr $search = array_map('rawurlencode', $search); 897546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=', $search); 898546d3a99SAndreas Gohr } else { 899546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 900546d3a99SAndreas Gohr } 901723d78dbSandi } 902723d78dbSandi 903a1685bedSandi //keep hash 904a1685bedSandi if($hash) $link['url'] .= '#'.$hash; 905a1685bedSandi 906ba11bd29Sandi //output formatted 907cffcc403Sandi if($returnonly) { 908cffcc403Sandi return $this->_formatLink($link); 909cffcc403Sandi } else { 910a2d649c4Sandi $this->doc .= $this->_formatLink($link); 9110cecf9d5Sandi } 912cffcc403Sandi } 9130cecf9d5Sandi 9143dd5c225SAndreas Gohr /** 9153dd5c225SAndreas Gohr * Render an external link 9163dd5c225SAndreas Gohr * 9173dd5c225SAndreas Gohr * @param string $url full URL with scheme 9183dd5c225SAndreas Gohr * @param string|array $name name for the link, array for media file 919122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 9200c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 9213dd5c225SAndreas Gohr */ 922122f2d46SAndreas Böhler function externallink($url, $name = null, $returnonly = false) { 923b625487dSandi global $conf; 9240cecf9d5Sandi 925433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 9266f0c5dbfSandi 927b52b1596SAndreas Gohr // url might be an attack vector, only allow registered protocols 928b52b1596SAndreas Gohr if(is_null($this->schemes)) $this->schemes = getSchemes(); 929b52b1596SAndreas Gohr list($scheme) = explode('://', $url); 930b52b1596SAndreas Gohr $scheme = strtolower($scheme); 931b52b1596SAndreas Gohr if(!in_array($scheme, $this->schemes)) $url = ''; 932b52b1596SAndreas Gohr 933b52b1596SAndreas Gohr // is there still an URL? 934b52b1596SAndreas Gohr if(!$url) { 93549cef4fdSAndreas Böhler if($returnonly) { 93649cef4fdSAndreas Böhler return $name; 93749cef4fdSAndreas Böhler } else { 938b52b1596SAndreas Gohr $this->doc .= $name; 93949cef4fdSAndreas Böhler } 940b52b1596SAndreas Gohr return; 941b52b1596SAndreas Gohr } 942b52b1596SAndreas Gohr 943b52b1596SAndreas Gohr // set class 9440cecf9d5Sandi if(!$isImage) { 945b625487dSandi $class = 'urlextern'; 9460cecf9d5Sandi } else { 947b625487dSandi $class = 'media'; 9480cecf9d5Sandi } 9490cecf9d5Sandi 950b625487dSandi //prepare for formating 95159bc3b48SGerrit Uitslag $link = array(); 952b625487dSandi $link['target'] = $conf['target']['extern']; 953b625487dSandi $link['style'] = ''; 954b625487dSandi $link['pre'] = ''; 955b625487dSandi $link['suf'] = ''; 9565e163278SAndreas Gohr $link['more'] = ''; 957b625487dSandi $link['class'] = $class; 958b625487dSandi $link['url'] = $url; 959914045f3SAndreas Gohr $link['rel'] = ''; 960e1c10e4dSchris 961b625487dSandi $link['name'] = $name; 962433bef32Sandi $link['title'] = $this->_xmlEntities($url); 963914045f3SAndreas Gohr if($conf['relnofollow']) $link['rel'] .= ' nofollow'; 964914045f3SAndreas Gohr if($conf['target']['extern']) $link['rel'] .= ' noopener'; 9650cecf9d5Sandi 966b625487dSandi //output formatted 967122f2d46SAndreas Böhler if($returnonly) { 968122f2d46SAndreas Böhler return $this->_formatLink($link); 969122f2d46SAndreas Böhler } else { 970a2d649c4Sandi $this->doc .= $this->_formatLink($link); 9710cecf9d5Sandi } 972122f2d46SAndreas Böhler } 9730cecf9d5Sandi 9740cecf9d5Sandi /** 9753dd5c225SAndreas Gohr * Render an interwiki link 9763dd5c225SAndreas Gohr * 9773dd5c225SAndreas Gohr * You may want to use $this->_resolveInterWiki() here 9783dd5c225SAndreas Gohr * 9793dd5c225SAndreas Gohr * @param string $match original link - probably not much use 9803dd5c225SAndreas Gohr * @param string|array $name name for the link, array for media file 9813dd5c225SAndreas Gohr * @param string $wikiName indentifier (shortcut) for the remote wiki 9823dd5c225SAndreas Gohr * @param string $wikiUri the fragment parsed from the original link 983122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 9840c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 9850cecf9d5Sandi */ 986122f2d46SAndreas Böhler function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) { 987b625487dSandi global $conf; 9880cecf9d5Sandi 98997a3e4e3Sandi $link = array(); 99097a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 99197a3e4e3Sandi $link['pre'] = ''; 99297a3e4e3Sandi $link['suf'] = ''; 9935e163278SAndreas Gohr $link['more'] = ''; 994433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 995914045f3SAndreas Gohr $link['rel'] = ''; 9960cecf9d5Sandi 99797a3e4e3Sandi //get interwiki URL 9986496c33fSGerrit Uitslag $exists = null; 9996496c33fSGerrit Uitslag $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); 10000cecf9d5Sandi 100197a3e4e3Sandi if(!$isImage) { 10029d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); 10039d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 10041c2d1019SAndreas Gohr } else { 10051c2d1019SAndreas Gohr $link['class'] = 'media'; 100697a3e4e3Sandi } 10070cecf9d5Sandi 100897a3e4e3Sandi //do we stay at the same server? Use local target 10092345e871SGerrit Uitslag if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) { 101097a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 101197a3e4e3Sandi } 10126496c33fSGerrit Uitslag if($exists !== null && !$isImage) { 10136496c33fSGerrit Uitslag if($exists) { 10146496c33fSGerrit Uitslag $link['class'] .= ' wikilink1'; 10156496c33fSGerrit Uitslag } else { 10166496c33fSGerrit Uitslag $link['class'] .= ' wikilink2'; 1017914045f3SAndreas Gohr $link['rel'] .= ' nofollow'; 10186496c33fSGerrit Uitslag } 10196496c33fSGerrit Uitslag } 1020914045f3SAndreas Gohr if($conf['target']['interwiki']) $link['rel'] .= ' noopener'; 10210cecf9d5Sandi 102297a3e4e3Sandi $link['url'] = $url; 102397a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 102497a3e4e3Sandi 102597a3e4e3Sandi //output formatted 1026122f2d46SAndreas Böhler if($returnonly) { 1027122f2d46SAndreas Böhler return $this->_formatLink($link); 1028122f2d46SAndreas Böhler } else { 1029a2d649c4Sandi $this->doc .= $this->_formatLink($link); 10300cecf9d5Sandi } 1031122f2d46SAndreas Böhler } 10320cecf9d5Sandi 10330cecf9d5Sandi /** 10343dd5c225SAndreas Gohr * Link to windows share 10353dd5c225SAndreas Gohr * 10363dd5c225SAndreas Gohr * @param string $url the link 10373dd5c225SAndreas Gohr * @param string|array $name name for the link, array for media file 1038122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 10390c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 10400cecf9d5Sandi */ 1041122f2d46SAndreas Böhler function windowssharelink($url, $name = null, $returnonly = false) { 10421d47afe1Sandi global $conf; 10433dd5c225SAndreas Gohr 10441d47afe1Sandi //simple setup 104559bc3b48SGerrit Uitslag $link = array(); 10461d47afe1Sandi $link['target'] = $conf['target']['windows']; 10471d47afe1Sandi $link['pre'] = ''; 10481d47afe1Sandi $link['suf'] = ''; 10491d47afe1Sandi $link['style'] = ''; 10500cecf9d5Sandi 1051433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 10520cecf9d5Sandi if(!$isImage) { 10531d47afe1Sandi $link['class'] = 'windows'; 10540cecf9d5Sandi } else { 10551d47afe1Sandi $link['class'] = 'media'; 10560cecf9d5Sandi } 10570cecf9d5Sandi 1058433bef32Sandi $link['title'] = $this->_xmlEntities($url); 10591d47afe1Sandi $url = str_replace('\\', '/', $url); 10601d47afe1Sandi $url = 'file:///'.$url; 10611d47afe1Sandi $link['url'] = $url; 10620cecf9d5Sandi 10631d47afe1Sandi //output formatted 1064122f2d46SAndreas Böhler if($returnonly) { 1065122f2d46SAndreas Böhler return $this->_formatLink($link); 1066122f2d46SAndreas Böhler } else { 1067a2d649c4Sandi $this->doc .= $this->_formatLink($link); 10680cecf9d5Sandi } 1069122f2d46SAndreas Böhler } 10700cecf9d5Sandi 10713dd5c225SAndreas Gohr /** 10723dd5c225SAndreas Gohr * Render a linked E-Mail Address 10733dd5c225SAndreas Gohr * 10743dd5c225SAndreas Gohr * Honors $conf['mailguard'] setting 10753dd5c225SAndreas Gohr * 10763dd5c225SAndreas Gohr * @param string $address Email-Address 10773dd5c225SAndreas Gohr * @param string|array $name name for the link, array for media file 1078122f2d46SAndreas Böhler * @param bool $returnonly whether to return html or write to doc attribute 10790c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $returnonly 10803dd5c225SAndreas Gohr */ 1081122f2d46SAndreas Böhler function emaillink($address, $name = null, $returnonly = false) { 108271352defSandi global $conf; 108371352defSandi //simple setup 108471352defSandi $link = array(); 108571352defSandi $link['target'] = ''; 108671352defSandi $link['pre'] = ''; 108771352defSandi $link['suf'] = ''; 108871352defSandi $link['style'] = ''; 108971352defSandi $link['more'] = ''; 10900cecf9d5Sandi 1091c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 10920cecf9d5Sandi if(!$isImage) { 1093be96545cSAnika Henke $link['class'] = 'mail'; 10940cecf9d5Sandi } else { 1095be96545cSAnika Henke $link['class'] = 'media'; 10960cecf9d5Sandi } 10970cecf9d5Sandi 109807738714SAndreas Gohr $address = $this->_xmlEntities($address); 109900a7b5adSEsther Brunner $address = obfuscate($address); 110000a7b5adSEsther Brunner $title = $address; 11018c128049SAndreas Gohr 110271352defSandi if(empty($name)) { 110300a7b5adSEsther Brunner $name = $address; 110471352defSandi } 11050cecf9d5Sandi 1106776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 1107776b36ecSAndreas Gohr 1108776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 110971352defSandi $link['name'] = $name; 111071352defSandi $link['title'] = $title; 11110cecf9d5Sandi 111271352defSandi //output formatted 1113122f2d46SAndreas Böhler if($returnonly) { 1114122f2d46SAndreas Böhler return $this->_formatLink($link); 1115122f2d46SAndreas Böhler } else { 1116a2d649c4Sandi $this->doc .= $this->_formatLink($link); 11170cecf9d5Sandi } 1118122f2d46SAndreas Böhler } 11190cecf9d5Sandi 11203dd5c225SAndreas Gohr /** 11213dd5c225SAndreas Gohr * Render an internal media file 11223dd5c225SAndreas Gohr * 11233dd5c225SAndreas Gohr * @param string $src media ID 11243dd5c225SAndreas Gohr * @param string $title descriptive text 11253dd5c225SAndreas Gohr * @param string $align left|center|right 11263dd5c225SAndreas Gohr * @param int $width width of media in pixel 11273dd5c225SAndreas Gohr * @param int $height height of media in pixel 11283dd5c225SAndreas Gohr * @param string $cache cache|recache|nocache 11293dd5c225SAndreas Gohr * @param string $linking linkonly|detail|nolink 11303dd5c225SAndreas Gohr * @param bool $return return HTML instead of adding to $doc 11310c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $return 11323dd5c225SAndreas Gohr */ 11330ea51e63SMatt Perry function internalmedia($src, $title = null, $align = null, $width = null, 11343dd5c225SAndreas Gohr $height = null, $cache = null, $linking = null, $return = false) { 113537e34a5eSandi global $ID; 113691df343aSAndreas Gohr list($src, $hash) = explode('#', $src, 2); 1137cdb5e961Slisps resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true); 11380cecf9d5Sandi 1139d98d4540SBen Coburn $noLink = false; 11408acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 1141b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 11423685f775Sandi 11433dd5c225SAndreas Gohr list($ext, $mime) = mimetype($src, false); 1144b739ff0fSPierre Spring if(substr($mime, 0, 5) == 'image' && $render) { 114552dc5eadSlisps $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct')); 1146f50634f0SAnika Henke } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { 11472a2a2ba2SAnika Henke // don't link movies 114844881bd0Shenning.noren $noLink = true; 114955efc227SAndreas Gohr } else { 11502ca14335SEsther Brunner // add file icons 11519d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 11529d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 115352dc5eadSlisps $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true); 115491328684SMichael Hamann if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')'; 115555efc227SAndreas Gohr } 11563685f775Sandi 115791df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 115891df343aSAndreas Gohr 11596fe20453SGina Haeussge //markup non existing files 11604a24b459SKate Arzamastseva if(!$exists) { 11616fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 11624a24b459SKate Arzamastseva } 11636fe20453SGina Haeussge 11643685f775Sandi //output formatted 1165f50634f0SAnika Henke if($return) { 1166f50634f0SAnika Henke if($linking == 'nolink' || $noLink) return $link['name']; 1167f50634f0SAnika Henke else return $this->_formatLink($link); 1168f50634f0SAnika Henke } else { 1169dc673a5bSjoe.lapp if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 11702ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 11710cecf9d5Sandi } 1172f50634f0SAnika Henke } 11730cecf9d5Sandi 11743dd5c225SAndreas Gohr /** 11753dd5c225SAndreas Gohr * Render an external media file 11763dd5c225SAndreas Gohr * 11773dd5c225SAndreas Gohr * @param string $src full media URL 11783dd5c225SAndreas Gohr * @param string $title descriptive text 11793dd5c225SAndreas Gohr * @param string $align left|center|right 11803dd5c225SAndreas Gohr * @param int $width width of media in pixel 11813dd5c225SAndreas Gohr * @param int $height height of media in pixel 11823dd5c225SAndreas Gohr * @param string $cache cache|recache|nocache 11833dd5c225SAndreas Gohr * @param string $linking linkonly|detail|nolink 1184410ee62aSAnika Henke * @param bool $return return HTML instead of adding to $doc 11850c4c0281SGerrit Uitslag * @return void|string writes to doc attribute or returns html depends on $return 11863dd5c225SAndreas Gohr */ 11870ea51e63SMatt Perry function externalmedia($src, $title = null, $align = null, $width = null, 1188410ee62aSAnika Henke $height = null, $cache = null, $linking = null, $return = false) { 11896efc45a2SDmitry Katsubo if(link_isinterwiki($src)){ 11906efc45a2SDmitry Katsubo list($shortcut, $reference) = explode('>', $src, 2); 11916efc45a2SDmitry Katsubo $exists = null; 11926efc45a2SDmitry Katsubo $src = $this->_resolveInterWiki($shortcut, $reference, $exists); 11936efc45a2SDmitry Katsubo } 119491df343aSAndreas Gohr list($src, $hash) = explode('#', $src, 2); 1195d98d4540SBen Coburn $noLink = false; 11968acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 1197b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 1198b739ff0fSPierre Spring 1199b739ff0fSPierre Spring $link['url'] = ml($src, array('cache' => $cache)); 12003685f775Sandi 12013dd5c225SAndreas Gohr list($ext, $mime) = mimetype($src, false); 1202b739ff0fSPierre Spring if(substr($mime, 0, 5) == 'image' && $render) { 12032ca14335SEsther Brunner // link only jpeg images 120444881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 1205f50634f0SAnika Henke } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { 12062a2a2ba2SAnika Henke // don't link movies 120744881bd0Shenning.noren $noLink = true; 12082ca14335SEsther Brunner } else { 12092ca14335SEsther Brunner // add file icons 121027bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 121127bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 12122ca14335SEsther Brunner } 12132ca14335SEsther Brunner 121491df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 121591df343aSAndreas Gohr 12163685f775Sandi //output formatted 1217410ee62aSAnika Henke if($return) { 1218410ee62aSAnika Henke if($linking == 'nolink' || $noLink) return $link['name']; 1219410ee62aSAnika Henke else return $this->_formatLink($link); 1220410ee62aSAnika Henke } else { 1221dc673a5bSjoe.lapp if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 12222ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 12230cecf9d5Sandi } 1224410ee62aSAnika Henke } 12250cecf9d5Sandi 12264826ab45Sandi /** 12273db95becSAndreas Gohr * Renders an RSS feed 1228b625487dSandi * 12290c4c0281SGerrit Uitslag * @param string $url URL of the feed 12300c4c0281SGerrit Uitslag * @param array $params Finetuning of the output 12310c4c0281SGerrit Uitslag * 1232b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 1233b625487dSandi */ 12343db95becSAndreas Gohr function rss($url, $params) { 1235b625487dSandi global $lang; 12363db95becSAndreas Gohr global $conf; 12373db95becSAndreas Gohr 12383db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 12393db95becSAndreas Gohr $feed = new FeedParser(); 124000077af8SAndreas Gohr $feed->set_feed_url($url); 1241b625487dSandi 1242b625487dSandi //disable warning while fetching 12433dd5c225SAndreas Gohr if(!defined('DOKU_E_LEVEL')) { 12443dd5c225SAndreas Gohr $elvl = error_reporting(E_ERROR); 12453dd5c225SAndreas Gohr } 12463db95becSAndreas Gohr $rc = $feed->init(); 12473dd5c225SAndreas Gohr if(isset($elvl)) { 12483dd5c225SAndreas Gohr error_reporting($elvl); 12493dd5c225SAndreas Gohr } 1250b625487dSandi 125138c6f603SRobin H. Johnson if($params['nosort']) $feed->enable_order_by_date(false); 125238c6f603SRobin H. Johnson 12533db95becSAndreas Gohr //decide on start and end 12543db95becSAndreas Gohr if($params['reverse']) { 12553db95becSAndreas Gohr $mod = -1; 12563db95becSAndreas Gohr $start = $feed->get_item_quantity() - 1; 12573db95becSAndreas Gohr $end = $start - ($params['max']); 1258b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 12593db95becSAndreas Gohr } else { 12603db95becSAndreas Gohr $mod = 1; 12613db95becSAndreas Gohr $start = 0; 12623db95becSAndreas Gohr $end = $feed->get_item_quantity(); 1263d91ab76fSMatt Perry $end = ($end > $params['max']) ? $params['max'] : $end; 12643db95becSAndreas Gohr } 12653db95becSAndreas Gohr 1266a2d649c4Sandi $this->doc .= '<ul class="rss">'; 12673db95becSAndreas Gohr if($rc) { 12683db95becSAndreas Gohr for($x = $start; $x != $end; $x += $mod) { 12691bde1582SAndreas Gohr $item = $feed->get_item($x); 12703db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 1271d2ea3363SAndreas Gohr // support feeds without links 1272d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 1273d2ea3363SAndreas Gohr if($lnkurl) { 1274793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 1275793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 12763dd5c225SAndreas Gohr $this->externallink( 12773dd5c225SAndreas Gohr $item->get_permalink(), 12783dd5c225SAndreas Gohr html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8') 12793dd5c225SAndreas Gohr ); 1280d2ea3363SAndreas Gohr } else { 1281d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 1282d2ea3363SAndreas Gohr } 12833db95becSAndreas Gohr if($params['author']) { 12841bde1582SAndreas Gohr $author = $item->get_author(0); 12851bde1582SAndreas Gohr if($author) { 12861bde1582SAndreas Gohr $name = $author->get_name(); 12871bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 12881bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 12891bde1582SAndreas Gohr } 12903db95becSAndreas Gohr } 12913db95becSAndreas Gohr if($params['date']) { 12922e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 12933db95becSAndreas Gohr } 12941bde1582SAndreas Gohr if($params['details']) { 12953db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 1296173dccb7STom N Harris if($conf['htmlok']) { 12971bde1582SAndreas Gohr $this->doc .= $item->get_description(); 12983db95becSAndreas Gohr } else { 12991bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 13003db95becSAndreas Gohr } 13013db95becSAndreas Gohr $this->doc .= '</div>'; 13023db95becSAndreas Gohr } 13033db95becSAndreas Gohr 13043db95becSAndreas Gohr $this->doc .= '</div></li>'; 1305b625487dSandi } 1306b625487dSandi } else { 13073db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 1308a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 1309b625487dSandi $this->externallink($url); 131045e147ccSAndreas Gohr if($conf['allowdebug']) { 131145e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 131245e147ccSAndreas Gohr } 13133db95becSAndreas Gohr $this->doc .= '</div></li>'; 1314b625487dSandi } 1315a2d649c4Sandi $this->doc .= '</ul>'; 1316b625487dSandi } 1317b625487dSandi 13183dd5c225SAndreas Gohr /** 13193dd5c225SAndreas Gohr * Start a table 13203dd5c225SAndreas Gohr * 13213dd5c225SAndreas Gohr * @param int $maxcols maximum number of columns 13223dd5c225SAndreas Gohr * @param int $numrows NOT IMPLEMENTED 13233dd5c225SAndreas Gohr * @param int $pos byte position in the original source 13247d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 13253dd5c225SAndreas Gohr */ 13260c4c0281SGerrit Uitslag function table_open($maxcols = null, $numrows = null, $pos = null, $classes = null) { 1327b5742cedSPierre Spring // initialize the row counter used for classes 1328b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 1329619736fdSAdrian Lang $class = 'table'; 13300c4c0281SGerrit Uitslag if($classes !== null) { 13312e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 13320c4c0281SGerrit Uitslag $class .= ' ' . $classes; 13330c4c0281SGerrit Uitslag } 1334619736fdSAdrian Lang if($pos !== null) { 1335619736fdSAdrian Lang $class .= ' '.$this->startSectionEdit($pos, 'table'); 1336619736fdSAdrian Lang } 1337619736fdSAdrian Lang $this->doc .= '<div class="'.$class.'"><table class="inline">'. 1338619736fdSAdrian Lang DOKU_LF; 13390cecf9d5Sandi } 13400cecf9d5Sandi 13413dd5c225SAndreas Gohr /** 13423dd5c225SAndreas Gohr * Close a table 13433dd5c225SAndreas Gohr * 13443dd5c225SAndreas Gohr * @param int $pos byte position in the original source 13453dd5c225SAndreas Gohr */ 1346619736fdSAdrian Lang function table_close($pos = null) { 1347a8574918SAnika Henke $this->doc .= '</table></div>'.DOKU_LF; 1348619736fdSAdrian Lang if($pos !== null) { 134990df9a4dSAdrian Lang $this->finishSectionEdit($pos); 13500cecf9d5Sandi } 1351619736fdSAdrian Lang } 13520cecf9d5Sandi 13533dd5c225SAndreas Gohr /** 13543dd5c225SAndreas Gohr * Open a table header 13553dd5c225SAndreas Gohr */ 1356f05a1cc5SGerrit Uitslag function tablethead_open() { 1357f05a1cc5SGerrit Uitslag $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF; 1358f05a1cc5SGerrit Uitslag } 1359f05a1cc5SGerrit Uitslag 13603dd5c225SAndreas Gohr /** 13613dd5c225SAndreas Gohr * Close a table header 13623dd5c225SAndreas Gohr */ 1363f05a1cc5SGerrit Uitslag function tablethead_close() { 1364f05a1cc5SGerrit Uitslag $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF; 1365f05a1cc5SGerrit Uitslag } 1366f05a1cc5SGerrit Uitslag 13673dd5c225SAndreas Gohr /** 13685a93f869SAnika Henke * Open a table body 13695a93f869SAnika Henke */ 13705a93f869SAnika Henke function tabletbody_open() { 13715a93f869SAnika Henke $this->doc .= DOKU_TAB.'<tbody>'.DOKU_LF; 13725a93f869SAnika Henke } 13735a93f869SAnika Henke 13745a93f869SAnika Henke /** 13755a93f869SAnika Henke * Close a table body 13765a93f869SAnika Henke */ 13775a93f869SAnika Henke function tabletbody_close() { 13785a93f869SAnika Henke $this->doc .= DOKU_TAB.'</tbody>'.DOKU_LF; 13795a93f869SAnika Henke } 13805a93f869SAnika Henke 13815a93f869SAnika Henke /** 1382*d2a99739SAndreas Gohr * Open a table footer 1383*d2a99739SAndreas Gohr */ 1384*d2a99739SAndreas Gohr function tabletfoot_open() { 1385*d2a99739SAndreas Gohr $this->doc .= DOKU_TAB.'<tfood>'.DOKU_LF; 1386*d2a99739SAndreas Gohr } 1387*d2a99739SAndreas Gohr 1388*d2a99739SAndreas Gohr /** 1389*d2a99739SAndreas Gohr * Close a table footer 1390*d2a99739SAndreas Gohr */ 1391*d2a99739SAndreas Gohr function tabletfoot_close() { 1392*d2a99739SAndreas Gohr $this->doc .= DOKU_TAB.'</tfood>'.DOKU_LF; 1393*d2a99739SAndreas Gohr } 1394*d2a99739SAndreas Gohr 1395*d2a99739SAndreas Gohr /** 13963dd5c225SAndreas Gohr * Open a table row 13970c4c0281SGerrit Uitslag * 13987d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 13993dd5c225SAndreas Gohr */ 14000c4c0281SGerrit Uitslag function tablerow_open($classes = null) { 1401b5742cedSPierre Spring // initialize the cell counter used for classes 1402b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 1403b5742cedSPierre Spring $class = 'row'.$this->_counter['row_counter']++; 14040c4c0281SGerrit Uitslag if($classes !== null) { 14052e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 14060c4c0281SGerrit Uitslag $class .= ' ' . $classes; 14070c4c0281SGerrit Uitslag } 1408b5742cedSPierre Spring $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB; 14090cecf9d5Sandi } 14100cecf9d5Sandi 14113dd5c225SAndreas Gohr /** 14123dd5c225SAndreas Gohr * Close a table row 14133dd5c225SAndreas Gohr */ 14140cecf9d5Sandi function tablerow_close() { 1415a2d649c4Sandi $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF; 14160cecf9d5Sandi } 14170cecf9d5Sandi 14183dd5c225SAndreas Gohr /** 14193dd5c225SAndreas Gohr * Open a table header cell 14203dd5c225SAndreas Gohr * 14213dd5c225SAndreas Gohr * @param int $colspan 14223dd5c225SAndreas Gohr * @param string $align left|center|right 14233dd5c225SAndreas Gohr * @param int $rowspan 14247d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 14253dd5c225SAndreas Gohr */ 14260c4c0281SGerrit Uitslag function tableheader_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { 1427b5742cedSPierre Spring $class = 'class="col'.$this->_counter['cell_counter']++; 14280cecf9d5Sandi if(!is_null($align)) { 1429b5742cedSPierre Spring $class .= ' '.$align.'align'; 14300cecf9d5Sandi } 14310c4c0281SGerrit Uitslag if($classes !== null) { 14322e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 14330c4c0281SGerrit Uitslag $class .= ' ' . $classes; 14340c4c0281SGerrit Uitslag } 1435b5742cedSPierre Spring $class .= '"'; 1436b5742cedSPierre Spring $this->doc .= '<th '.$class; 14370cecf9d5Sandi if($colspan > 1) { 1438a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan - 1; 1439a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 14400cecf9d5Sandi } 144125b97867Shakan.sandell if($rowspan > 1) { 144225b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 144325b97867Shakan.sandell } 1444a2d649c4Sandi $this->doc .= '>'; 14450cecf9d5Sandi } 14460cecf9d5Sandi 14473dd5c225SAndreas Gohr /** 14483dd5c225SAndreas Gohr * Close a table header cell 14493dd5c225SAndreas Gohr */ 14500cecf9d5Sandi function tableheader_close() { 1451a2d649c4Sandi $this->doc .= '</th>'; 14520cecf9d5Sandi } 14530cecf9d5Sandi 14543dd5c225SAndreas Gohr /** 14553dd5c225SAndreas Gohr * Open a table cell 14563dd5c225SAndreas Gohr * 14573dd5c225SAndreas Gohr * @param int $colspan 14583dd5c225SAndreas Gohr * @param string $align left|center|right 14593dd5c225SAndreas Gohr * @param int $rowspan 14607d769f75SAndreas Gohr * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input 14613dd5c225SAndreas Gohr */ 14620c4c0281SGerrit Uitslag function tablecell_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { 1463b5742cedSPierre Spring $class = 'class="col'.$this->_counter['cell_counter']++; 14640cecf9d5Sandi if(!is_null($align)) { 1465b5742cedSPierre Spring $class .= ' '.$align.'align'; 14660cecf9d5Sandi } 14670c4c0281SGerrit Uitslag if($classes !== null) { 14682e0ebe60SAndreas Gohr if(is_array($classes)) $classes = join(' ', $classes); 14690c4c0281SGerrit Uitslag $class .= ' ' . $classes; 14700c4c0281SGerrit Uitslag } 1471b5742cedSPierre Spring $class .= '"'; 1472b5742cedSPierre Spring $this->doc .= '<td '.$class; 14730cecf9d5Sandi if($colspan > 1) { 1474a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan - 1; 1475a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 14760cecf9d5Sandi } 147725b97867Shakan.sandell if($rowspan > 1) { 147825b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 147925b97867Shakan.sandell } 1480a2d649c4Sandi $this->doc .= '>'; 14810cecf9d5Sandi } 14820cecf9d5Sandi 14833dd5c225SAndreas Gohr /** 14843dd5c225SAndreas Gohr * Close a table cell 14853dd5c225SAndreas Gohr */ 14860cecf9d5Sandi function tablecell_close() { 1487a2d649c4Sandi $this->doc .= '</td>'; 14880cecf9d5Sandi } 14890cecf9d5Sandi 1490cea664bdSLarsDW223 /** 1491cea664bdSLarsDW223 * Returns the current header level. 1492cea664bdSLarsDW223 * (required e.g. by the filelist plugin) 1493cea664bdSLarsDW223 * 1494cea664bdSLarsDW223 * @return int The current header level 1495cea664bdSLarsDW223 */ 1496cea664bdSLarsDW223 function getLastlevel() { 1497cea664bdSLarsDW223 return $this->lastlevel; 1498cea664bdSLarsDW223 } 1499cea664bdSLarsDW223 15003dd5c225SAndreas Gohr #region Utility functions 15010cecf9d5Sandi 1502ba11bd29Sandi /** 15033fd0b676Sandi * Build a link 15043fd0b676Sandi * 15053fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 1506ba11bd29Sandi * 15070c4c0281SGerrit Uitslag * @param array $link attributes of a link 15080c4c0281SGerrit Uitslag * @return string 15090c4c0281SGerrit Uitslag * 1510ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 1511ba11bd29Sandi */ 1512433bef32Sandi function _formatLink($link) { 1513ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 1514ba11bd29Sandi if(substr($link['url'], 0, 7) != 'mailto:') { 1515ba11bd29Sandi $link['url'] = str_replace('&', '&', $link['url']); 1516ba11bd29Sandi $link['url'] = str_replace('&amp;', '&', $link['url']); 1517ba11bd29Sandi } 1518ba11bd29Sandi //remove double encodings in titles 1519ba11bd29Sandi $link['title'] = str_replace('&amp;', '&', $link['title']); 1520ba11bd29Sandi 1521453493f2SAndreas Gohr // be sure there are no bad chars in url or title 1522453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 1523453493f2SAndreas Gohr $link['url'] = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22')); 1524453493f2SAndreas Gohr $link['title'] = strtr($link['title'], array('>' => '>', '<' => '<', '"' => '"')); 1525453493f2SAndreas Gohr 1526ba11bd29Sandi $ret = ''; 1527ba11bd29Sandi $ret .= $link['pre']; 1528ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 1529bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 1530bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 1531bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1532bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 1533914045f3SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.trim($link['rel']).'"'; 1534bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1535ba11bd29Sandi $ret .= '>'; 1536ba11bd29Sandi $ret .= $link['name']; 1537ba11bd29Sandi $ret .= '</a>'; 1538ba11bd29Sandi $ret .= $link['suf']; 1539ba11bd29Sandi return $ret; 1540ba11bd29Sandi } 1541ba11bd29Sandi 1542ba11bd29Sandi /** 15433fd0b676Sandi * Renders internal and external media 15443fd0b676Sandi * 15453fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 15463dd5c225SAndreas Gohr * @param string $src media ID 15473dd5c225SAndreas Gohr * @param string $title descriptive text 15483dd5c225SAndreas Gohr * @param string $align left|center|right 15493dd5c225SAndreas Gohr * @param int $width width of media in pixel 15503dd5c225SAndreas Gohr * @param int $height height of media in pixel 15513dd5c225SAndreas Gohr * @param string $cache cache|recache|nocache 15523dd5c225SAndreas Gohr * @param bool $render should the media be embedded inline or just linked 15533dd5c225SAndreas Gohr * @return string 15543fd0b676Sandi */ 15550ea51e63SMatt Perry function _media($src, $title = null, $align = null, $width = null, 15560ea51e63SMatt Perry $height = null, $cache = null, $render = true) { 15573fd0b676Sandi 15583fd0b676Sandi $ret = ''; 15593fd0b676Sandi 15603dd5c225SAndreas Gohr list($ext, $mime) = mimetype($src); 15613fd0b676Sandi if(substr($mime, 0, 5) == 'image') { 1562b739ff0fSPierre Spring // first get the $title 1563b739ff0fSPierre Spring if(!is_null($title)) { 1564b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1565b739ff0fSPierre Spring } elseif($ext == 'jpg' || $ext == 'jpeg') { 1566b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1567b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 156867f9913dSAndreas Gohr $jpeg = new JpegMeta(mediaFN($src)); 1569b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 15703dd5c225SAndreas Gohr if(!empty($cap)) { 1571b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1572b739ff0fSPierre Spring } 1573b739ff0fSPierre Spring } 1574b739ff0fSPierre Spring if(!$render) { 1575b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1576b739ff0fSPierre Spring // return the title of the picture 1577b739ff0fSPierre Spring if(!$title) { 1578b739ff0fSPierre Spring // just show the sourcename 15793009a773SAndreas Gohr $title = $this->_xmlEntities(utf8_basename(noNS($src))); 1580b739ff0fSPierre Spring } 1581b739ff0fSPierre Spring return $title; 1582b739ff0fSPierre Spring } 15833fd0b676Sandi //add image tag 158452dc5eadSlisps $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"'; 15853fd0b676Sandi $ret .= ' class="media'.$align.'"'; 15863fd0b676Sandi 1587b739ff0fSPierre Spring if($title) { 1588b739ff0fSPierre Spring $ret .= ' title="'.$title.'"'; 1589b739ff0fSPierre Spring $ret .= ' alt="'.$title.'"'; 15903fd0b676Sandi } else { 15913fd0b676Sandi $ret .= ' alt=""'; 15923fd0b676Sandi } 15933fd0b676Sandi 15943fd0b676Sandi if(!is_null($width)) 15953fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 15963fd0b676Sandi 15973fd0b676Sandi if(!is_null($height)) 15983fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 15993fd0b676Sandi 16003fd0b676Sandi $ret .= ' />'; 16013fd0b676Sandi 160217954bb5SAnika Henke } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) { 16032a2a2ba2SAnika Henke // first get the $title 160417954bb5SAnika Henke $title = !is_null($title) ? $this->_xmlEntities($title) : false; 16052a2a2ba2SAnika Henke if(!$render) { 160617954bb5SAnika Henke // if the file is not supposed to be rendered 160717954bb5SAnika Henke // return the title of the file (just the sourcename if there is no title) 160817954bb5SAnika Henke return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src))); 16092a2a2ba2SAnika Henke } 16102a2a2ba2SAnika Henke 16112a2a2ba2SAnika Henke $att = array(); 16122a2a2ba2SAnika Henke $att['class'] = "media$align"; 161317954bb5SAnika Henke if($title) { 161417954bb5SAnika Henke $att['title'] = $title; 161517954bb5SAnika Henke } 16162a2a2ba2SAnika Henke 161717954bb5SAnika Henke if(media_supportedav($mime, 'video')) { 161817954bb5SAnika Henke //add video 161979e53fe5SAnika Henke $ret .= $this->_video($src, $width, $height, $att); 1620b44a5dceSAnika Henke } 162117954bb5SAnika Henke if(media_supportedav($mime, 'audio')) { 1622b44a5dceSAnika Henke //add audio 1623b44a5dceSAnika Henke $ret .= $this->_audio($src, $att); 162417954bb5SAnika Henke } 1625b44a5dceSAnika Henke 16263fd0b676Sandi } elseif($mime == 'application/x-shockwave-flash') { 16271c882ba8SAndreas Gohr if(!$render) { 16281c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 16291c882ba8SAndreas Gohr // return the title of the flash 16301c882ba8SAndreas Gohr if(!$title) { 16311c882ba8SAndreas Gohr // just show the sourcename 16323009a773SAndreas Gohr $title = utf8_basename(noNS($src)); 16331c882ba8SAndreas Gohr } 163407bf32b2SAndreas Gohr return $this->_xmlEntities($title); 16351c882ba8SAndreas Gohr } 16361c882ba8SAndreas Gohr 163707bf32b2SAndreas Gohr $att = array(); 163807bf32b2SAndreas Gohr $att['class'] = "media$align"; 163907bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 164007bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 16413dd5c225SAndreas Gohr $ret .= html_flashobject( 16423dd5c225SAndreas Gohr ml($src, array('cache' => $cache), true, '&'), $width, $height, 164307bf32b2SAndreas Gohr array('quality' => 'high'), 164407bf32b2SAndreas Gohr null, 164507bf32b2SAndreas Gohr $att, 16463dd5c225SAndreas Gohr $this->_xmlEntities($title) 16473dd5c225SAndreas Gohr ); 16480f428d7dSAndreas Gohr } elseif($title) { 16493fd0b676Sandi // well at least we have a title to display 16503fd0b676Sandi $ret .= $this->_xmlEntities($title); 16513fd0b676Sandi } else { 16525291ca3aSAndreas Gohr // just show the sourcename 16533009a773SAndreas Gohr $ret .= $this->_xmlEntities(utf8_basename(noNS($src))); 16543fd0b676Sandi } 16553fd0b676Sandi 16563fd0b676Sandi return $ret; 16573fd0b676Sandi } 16583fd0b676Sandi 16593dd5c225SAndreas Gohr /** 16603dd5c225SAndreas Gohr * Escape string for output 16613dd5c225SAndreas Gohr * 16623dd5c225SAndreas Gohr * @param $string 16633dd5c225SAndreas Gohr * @return string 16643dd5c225SAndreas Gohr */ 1665433bef32Sandi function _xmlEntities($string) { 1666de117061Schris return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); 16670cecf9d5Sandi } 16680cecf9d5Sandi 16698a831f2bSAndreas Gohr /** 16708a831f2bSAndreas Gohr * Creates a linkid from a headline 1671c5a8fd96SAndreas Gohr * 16723dd5c225SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1673c5a8fd96SAndreas Gohr * @param string $title The headline title 1674c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 16753dd5c225SAndreas Gohr * @return string 16768a831f2bSAndreas Gohr */ 1677c5a8fd96SAndreas Gohr function _headerToLink($title, $create = false) { 1678c5a8fd96SAndreas Gohr if($create) { 16794ceab83fSAndreas Gohr return sectionID($title, $this->headers); 16804ceab83fSAndreas Gohr } else { 1681443d207bSAndreas Gohr $check = false; 1682443d207bSAndreas Gohr return sectionID($title, $check); 1683c5a8fd96SAndreas Gohr } 16840cecf9d5Sandi } 16850cecf9d5Sandi 1686af587fa8Sandi /** 16873fd0b676Sandi * Construct a title and handle images in titles 16883fd0b676Sandi * 16890b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 16903dd5c225SAndreas Gohr * @param string|array $title either string title or media array 16913dd5c225SAndreas Gohr * @param string $default default title if nothing else is found 16923dd5c225SAndreas Gohr * @param bool $isImage will be set to true if it's a media file 16933dd5c225SAndreas Gohr * @param null|string $id linked page id (used to extract title from first heading) 16943dd5c225SAndreas Gohr * @param string $linktype content|navigation 16953dd5c225SAndreas Gohr * @return string HTML of the title, might be full image tag or just escaped text 16963fd0b676Sandi */ 16970ea51e63SMatt Perry function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { 169844881bd0Shenning.noren $isImage = false; 169929657f9eSAndreas Gohr if(is_array($title)) { 170029657f9eSAndreas Gohr $isImage = true; 170129657f9eSAndreas Gohr return $this->_imageTitle($title); 170229657f9eSAndreas Gohr } elseif(is_null($title) || trim($title) == '') { 1703fe9ec250SChris Smith if(useHeading($linktype) && $id) { 170467c15eceSMichael Hamann $heading = p_get_first_heading($id); 1705bb0a59d4Sjan if($heading) { 1706433bef32Sandi return $this->_xmlEntities($heading); 1707bb0a59d4Sjan } 1708bb0a59d4Sjan } 1709433bef32Sandi return $this->_xmlEntities($default); 171068c26e6dSMichael Klier } else { 171168c26e6dSMichael Klier return $this->_xmlEntities($title); 17120cecf9d5Sandi } 17130cecf9d5Sandi } 17140cecf9d5Sandi 17150cecf9d5Sandi /** 17163dd5c225SAndreas Gohr * Returns HTML code for images used in link titles 17173fd0b676Sandi * 17183fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 1719e0c26282SGerrit Uitslag * @param array $img 17203dd5c225SAndreas Gohr * @return string HTML img tag or similar 17210cecf9d5Sandi */ 1722433bef32Sandi function _imageTitle($img) { 1723d9baf1a7SKazutaka Miyasaka global $ID; 1724d9baf1a7SKazutaka Miyasaka 1725d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1726d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 17273dd5c225SAndreas Gohr list($img['src']) = explode('#', $img['src'], 2); 1728d9baf1a7SKazutaka Miyasaka if($img['type'] == 'internalmedia') { 1729cdb5e961Slisps resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true); 1730d9baf1a7SKazutaka Miyasaka } 1731d9baf1a7SKazutaka Miyasaka 17323dd5c225SAndreas Gohr return $this->_media( 17333dd5c225SAndreas Gohr $img['src'], 17344826ab45Sandi $img['title'], 17354826ab45Sandi $img['align'], 17364826ab45Sandi $img['width'], 17374826ab45Sandi $img['height'], 17383dd5c225SAndreas Gohr $img['cache'] 17393dd5c225SAndreas Gohr ); 17400cecf9d5Sandi } 1741b739ff0fSPierre Spring 1742b739ff0fSPierre Spring /** 17433dd5c225SAndreas Gohr * helperfunction to return a basic link to a media 17443dd5c225SAndreas Gohr * 17453dd5c225SAndreas Gohr * used in internalmedia() and externalmedia() 1746b739ff0fSPierre Spring * 1747b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 17483dd5c225SAndreas Gohr * @param string $src media ID 17493dd5c225SAndreas Gohr * @param string $title descriptive text 17503dd5c225SAndreas Gohr * @param string $align left|center|right 17513dd5c225SAndreas Gohr * @param int $width width of media in pixel 17523dd5c225SAndreas Gohr * @param int $height height of media in pixel 17533dd5c225SAndreas Gohr * @param string $cache cache|recache|nocache 17543dd5c225SAndreas Gohr * @param bool $render should the media be embedded inline or just linked 17553dd5c225SAndreas Gohr * @return array associative array with link config 1756b739ff0fSPierre Spring */ 1757d91ab76fSMatt Perry function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { 1758b739ff0fSPierre Spring global $conf; 1759b739ff0fSPierre Spring 1760b739ff0fSPierre Spring $link = array(); 1761b739ff0fSPierre Spring $link['class'] = 'media'; 1762b739ff0fSPierre Spring $link['style'] = ''; 1763b739ff0fSPierre Spring $link['pre'] = ''; 1764b739ff0fSPierre Spring $link['suf'] = ''; 1765b739ff0fSPierre Spring $link['more'] = ''; 1766b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1767bc3d2252SAndreas Gohr if($conf['target']['media']) $link['rel'] = 'noopener'; 1768b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1769b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1770b739ff0fSPierre Spring 1771b739ff0fSPierre Spring return $link; 1772b739ff0fSPierre Spring } 177391459163SAnika Henke 17742a2a2ba2SAnika Henke /** 17752a2a2ba2SAnika Henke * Embed video(s) in HTML 17762a2a2ba2SAnika Henke * 17772a2a2ba2SAnika Henke * @author Anika Henke <anika@selfthinker.org> 17782a2a2ba2SAnika Henke * 17792a2a2ba2SAnika Henke * @param string $src - ID of video to embed 17802a2a2ba2SAnika Henke * @param int $width - width of the video in pixels 17812a2a2ba2SAnika Henke * @param int $height - height of the video in pixels 17822a2a2ba2SAnika Henke * @param array $atts - additional attributes for the <video> tag 1783f50634f0SAnika Henke * @return string 17842a2a2ba2SAnika Henke */ 178579e53fe5SAnika Henke function _video($src, $width, $height, $atts = null) { 17862a2a2ba2SAnika Henke // prepare width and height 17872a2a2ba2SAnika Henke if(is_null($atts)) $atts = array(); 17882a2a2ba2SAnika Henke $atts['width'] = (int) $width; 17892a2a2ba2SAnika Henke $atts['height'] = (int) $height; 17902a2a2ba2SAnika Henke if(!$atts['width']) $atts['width'] = 320; 17912a2a2ba2SAnika Henke if(!$atts['height']) $atts['height'] = 240; 17922a2a2ba2SAnika Henke 1793410ee62aSAnika Henke $posterUrl = ''; 1794410ee62aSAnika Henke $files = array(); 1795410ee62aSAnika Henke $isExternal = media_isexternal($src); 1796410ee62aSAnika Henke 1797410ee62aSAnika Henke if ($isExternal) { 1798410ee62aSAnika Henke // take direct source for external files 1799702e97d3SAnika Henke list(/*ext*/, $srcMime) = mimetype($src); 1800410ee62aSAnika Henke $files[$srcMime] = $src; 1801410ee62aSAnika Henke } else { 18023d7a9e0aSAnika Henke // prepare alternative formats 18033d7a9e0aSAnika Henke $extensions = array('webm', 'ogv', 'mp4'); 1804410ee62aSAnika Henke $files = media_alternativefiles($src, $extensions); 180559bc3b48SGerrit Uitslag $poster = media_alternativefiles($src, array('jpg', 'png')); 180699f943f6SAnika Henke if(!empty($poster)) { 18072d338eabSAndreas Gohr $posterUrl = ml(reset($poster), '', true, '&'); 180899f943f6SAnika Henke } 1809410ee62aSAnika Henke } 18102a2a2ba2SAnika Henke 1811f50634f0SAnika Henke $out = ''; 181279e53fe5SAnika Henke // open video tag 1813f50634f0SAnika Henke $out .= '<video '.buildAttributes($atts).' controls="controls"'; 18143641199aSAnika Henke if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"'; 1815f50634f0SAnika Henke $out .= '>'.NL; 18163641199aSAnika Henke $fallback = ''; 181779e53fe5SAnika Henke 181879e53fe5SAnika Henke // output source for each alternative video format 1819410ee62aSAnika Henke foreach($files as $mime => $file) { 1820410ee62aSAnika Henke if ($isExternal) { 1821410ee62aSAnika Henke $url = $file; 1822410ee62aSAnika Henke $linkType = 'externalmedia'; 1823410ee62aSAnika Henke } else { 18242d338eabSAndreas Gohr $url = ml($file, '', true, '&'); 1825410ee62aSAnika Henke $linkType = 'internalmedia'; 1826410ee62aSAnika Henke } 182717954bb5SAnika Henke $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); 18283d7a9e0aSAnika Henke 1829f50634f0SAnika Henke $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; 183079e53fe5SAnika Henke // alternative content (just a link to the file) 1831410ee62aSAnika Henke $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); 18323d7a9e0aSAnika Henke } 18332a2a2ba2SAnika Henke 18342a2a2ba2SAnika Henke // finish 18353641199aSAnika Henke $out .= $fallback; 1836f50634f0SAnika Henke $out .= '</video>'.NL; 1837f50634f0SAnika Henke return $out; 18382a2a2ba2SAnika Henke } 18392a2a2ba2SAnika Henke 1840b44a5dceSAnika Henke /** 1841b44a5dceSAnika Henke * Embed audio in HTML 1842b44a5dceSAnika Henke * 1843b44a5dceSAnika Henke * @author Anika Henke <anika@selfthinker.org> 1844b44a5dceSAnika Henke * 1845b44a5dceSAnika Henke * @param string $src - ID of audio to embed 18466d4af72aSAnika Henke * @param array $atts - additional attributes for the <audio> tag 1847f50634f0SAnika Henke * @return string 1848b44a5dceSAnika Henke */ 184959bc3b48SGerrit Uitslag function _audio($src, $atts = array()) { 1850702e97d3SAnika Henke $files = array(); 1851410ee62aSAnika Henke $isExternal = media_isexternal($src); 1852b44a5dceSAnika Henke 1853410ee62aSAnika Henke if ($isExternal) { 1854410ee62aSAnika Henke // take direct source for external files 1855702e97d3SAnika Henke list(/*ext*/, $srcMime) = mimetype($src); 1856410ee62aSAnika Henke $files[$srcMime] = $src; 1857410ee62aSAnika Henke } else { 1858b44a5dceSAnika Henke // prepare alternative formats 1859b44a5dceSAnika Henke $extensions = array('ogg', 'mp3', 'wav'); 1860410ee62aSAnika Henke $files = media_alternativefiles($src, $extensions); 1861410ee62aSAnika Henke } 1862b44a5dceSAnika Henke 1863f50634f0SAnika Henke $out = ''; 1864b44a5dceSAnika Henke // open audio tag 1865f50634f0SAnika Henke $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; 18663641199aSAnika Henke $fallback = ''; 1867b44a5dceSAnika Henke 1868b44a5dceSAnika Henke // output source for each alternative audio format 1869410ee62aSAnika Henke foreach($files as $mime => $file) { 1870410ee62aSAnika Henke if ($isExternal) { 1871410ee62aSAnika Henke $url = $file; 1872410ee62aSAnika Henke $linkType = 'externalmedia'; 1873410ee62aSAnika Henke } else { 18742d338eabSAndreas Gohr $url = ml($file, '', true, '&'); 1875410ee62aSAnika Henke $linkType = 'internalmedia'; 1876410ee62aSAnika Henke } 187717954bb5SAnika Henke $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); 1878b44a5dceSAnika Henke 1879f50634f0SAnika Henke $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; 1880b44a5dceSAnika Henke // alternative content (just a link to the file) 1881410ee62aSAnika Henke $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); 1882b44a5dceSAnika Henke } 1883b44a5dceSAnika Henke 1884b44a5dceSAnika Henke // finish 18853641199aSAnika Henke $out .= $fallback; 1886f50634f0SAnika Henke $out .= '</audio>'.NL; 1887f50634f0SAnika Henke return $out; 1888b44a5dceSAnika Henke } 1889b44a5dceSAnika Henke 18905c2eed9aSlisps /** 189152dc5eadSlisps * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() 18925c2eed9aSlisps * which returns an existing media revision less or equal to rev or date_at 18935c2eed9aSlisps * 18945c2eed9aSlisps * @author lisps 18955c2eed9aSlisps * @param string $media_id 18965c2eed9aSlisps * @access protected 18975c2eed9aSlisps * @return string revision ('' for current) 18985c2eed9aSlisps */ 189952dc5eadSlisps function _getLastMediaRevisionAt($media_id){ 190052dc5eadSlisps if(!$this->date_at || media_isexternal($media_id)) return ''; 190178b874e6Slisps $pagelog = new MediaChangeLog($media_id); 190278b874e6Slisps return $pagelog->getLastRevisionAt($this->date_at); 19035c2eed9aSlisps } 19045c2eed9aSlisps 19053dd5c225SAndreas Gohr #endregion 19060cecf9d5Sandi} 19070cecf9d5Sandi 1908e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1909