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 431ca2719cSAndreas Gohr private $schemes = null; // protocol schemes 441ca2719cSAndreas 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 651*b52b1596SAndreas Gohr // url might be an attack vector, only allow registered protocols 652*b52b1596SAndreas Gohr if(is_null($this->schemes)) $this->schemes = getSchemes(); 653*b52b1596SAndreas Gohr list($scheme) = explode('://',$url); 654*b52b1596SAndreas Gohr $scheme = strtolower($scheme); 655*b52b1596SAndreas Gohr if(!in_array($scheme,$this->schemes)) $url = ''; 656*b52b1596SAndreas Gohr 657*b52b1596SAndreas Gohr // is there still an URL? 658*b52b1596SAndreas Gohr if(!$url){ 659*b52b1596SAndreas Gohr $this->doc .= $name; 660*b52b1596SAndreas Gohr return; 661*b52b1596SAndreas Gohr } 662*b52b1596SAndreas Gohr 663*b52b1596SAndreas Gohr // set class 6640cecf9d5Sandi if ( !$isImage ) { 665b625487dSandi $class='urlextern'; 6660cecf9d5Sandi } else { 667b625487dSandi $class='media'; 6680cecf9d5Sandi } 6690cecf9d5Sandi 670b625487dSandi //prepare for formating 671b625487dSandi $link['target'] = $conf['target']['extern']; 672b625487dSandi $link['style'] = ''; 673b625487dSandi $link['pre'] = ''; 674b625487dSandi $link['suf'] = ''; 6755e163278SAndreas Gohr $link['more'] = ''; 676b625487dSandi $link['class'] = $class; 677b625487dSandi $link['url'] = $url; 678e1c10e4dSchris 679b625487dSandi $link['name'] = $name; 680433bef32Sandi $link['title'] = $this->_xmlEntities($url); 681b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6820cecf9d5Sandi 683b625487dSandi //output formatted 684a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6850cecf9d5Sandi } 6860cecf9d5Sandi 6870cecf9d5Sandi /** 6880cecf9d5Sandi */ 68997a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 690b625487dSandi global $conf; 6910cecf9d5Sandi 69297a3e4e3Sandi $link = array(); 69397a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 69497a3e4e3Sandi $link['pre'] = ''; 69597a3e4e3Sandi $link['suf'] = ''; 6965e163278SAndreas Gohr $link['more'] = ''; 697433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6980cecf9d5Sandi 69997a3e4e3Sandi //get interwiki URL 7001f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 7010cecf9d5Sandi 70297a3e4e3Sandi if ( !$isImage ) { 7039d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 7049d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 7051c2d1019SAndreas Gohr } else { 7061c2d1019SAndreas Gohr $link['class'] = 'media'; 70797a3e4e3Sandi } 7080cecf9d5Sandi 70997a3e4e3Sandi //do we stay at the same server? Use local target 71097a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 71197a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 71297a3e4e3Sandi } 7130cecf9d5Sandi 71497a3e4e3Sandi $link['url'] = $url; 71597a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 71697a3e4e3Sandi 71797a3e4e3Sandi //output formatted 718a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7190cecf9d5Sandi } 7200cecf9d5Sandi 7210cecf9d5Sandi /** 7220cecf9d5Sandi */ 7231d47afe1Sandi function windowssharelink($url, $name = NULL) { 7241d47afe1Sandi global $conf; 7251d47afe1Sandi global $lang; 7261d47afe1Sandi //simple setup 7271d47afe1Sandi $link['target'] = $conf['target']['windows']; 7281d47afe1Sandi $link['pre'] = ''; 7291d47afe1Sandi $link['suf'] = ''; 7301d47afe1Sandi $link['style'] = ''; 7310cecf9d5Sandi 732433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 7330cecf9d5Sandi if ( !$isImage ) { 7341d47afe1Sandi $link['class'] = 'windows'; 7350cecf9d5Sandi } else { 7361d47afe1Sandi $link['class'] = 'media'; 7370cecf9d5Sandi } 7380cecf9d5Sandi 7390cecf9d5Sandi 740433bef32Sandi $link['title'] = $this->_xmlEntities($url); 7411d47afe1Sandi $url = str_replace('\\','/',$url); 7421d47afe1Sandi $url = 'file:///'.$url; 7431d47afe1Sandi $link['url'] = $url; 7440cecf9d5Sandi 7451d47afe1Sandi //output formatted 746a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7470cecf9d5Sandi } 7480cecf9d5Sandi 74971352defSandi function emaillink($address, $name = NULL) { 75071352defSandi global $conf; 75171352defSandi //simple setup 75271352defSandi $link = array(); 75371352defSandi $link['target'] = ''; 75471352defSandi $link['pre'] = ''; 75571352defSandi $link['suf'] = ''; 75671352defSandi $link['style'] = ''; 75771352defSandi $link['more'] = ''; 7580cecf9d5Sandi 759c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7600cecf9d5Sandi if ( !$isImage ) { 761be96545cSAnika Henke $link['class']='mail'; 7620cecf9d5Sandi } else { 763be96545cSAnika Henke $link['class']='media'; 7640cecf9d5Sandi } 7650cecf9d5Sandi 76607738714SAndreas Gohr $address = $this->_xmlEntities($address); 76700a7b5adSEsther Brunner $address = obfuscate($address); 76800a7b5adSEsther Brunner $title = $address; 7698c128049SAndreas Gohr 77071352defSandi if(empty($name)){ 77100a7b5adSEsther Brunner $name = $address; 77271352defSandi } 7730cecf9d5Sandi 774776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 775776b36ecSAndreas Gohr 776776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 77771352defSandi $link['name'] = $name; 77871352defSandi $link['title'] = $title; 7790cecf9d5Sandi 78071352defSandi //output formatted 781a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7820cecf9d5Sandi } 7830cecf9d5Sandi 7844826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 785dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 78637e34a5eSandi global $ID; 78791df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 78837e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7890cecf9d5Sandi 790d98d4540SBen Coburn $noLink = false; 7918acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 792b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7933685f775Sandi 79427bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 795b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 796dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7971c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7982ca14335SEsther Brunner // don't link flash movies 79944881bd0Shenning.noren $noLink = true; 80055efc227SAndreas Gohr }else{ 8012ca14335SEsther Brunner // add file icons 8029d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 8039d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 8046de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 80555efc227SAndreas Gohr } 8063685f775Sandi 80791df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 80891df343aSAndreas Gohr 8096fe20453SGina Haeussge //markup non existing files 8106fe20453SGina Haeussge if (!$exists) 8116fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 8126fe20453SGina Haeussge 8133685f775Sandi //output formatted 814dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8152ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8160cecf9d5Sandi } 8170cecf9d5Sandi 8184826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 819dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 82091df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 821d98d4540SBen Coburn $noLink = false; 8228acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 823b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 824b739ff0fSPierre Spring 825b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 8263685f775Sandi 82727bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 828b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 8292ca14335SEsther Brunner // link only jpeg images 83044881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 8311c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 8322ca14335SEsther Brunner // don't link flash movies 83344881bd0Shenning.noren $noLink = true; 8342ca14335SEsther Brunner }else{ 8352ca14335SEsther Brunner // add file icons 83627bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 83727bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 8382ca14335SEsther Brunner } 8392ca14335SEsther Brunner 84091df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 84191df343aSAndreas Gohr 8423685f775Sandi //output formatted 843dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8442ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8450cecf9d5Sandi } 8460cecf9d5Sandi 8474826ab45Sandi /** 8483db95becSAndreas Gohr * Renders an RSS feed 849b625487dSandi * 850b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 851b625487dSandi */ 8523db95becSAndreas Gohr function rss ($url,$params){ 853b625487dSandi global $lang; 8543db95becSAndreas Gohr global $conf; 8553db95becSAndreas Gohr 8563db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8573db95becSAndreas Gohr $feed = new FeedParser(); 85800077af8SAndreas Gohr $feed->set_feed_url($url); 859b625487dSandi 860b625487dSandi //disable warning while fetching 861bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8623db95becSAndreas Gohr $rc = $feed->init(); 863bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 864b625487dSandi 8653db95becSAndreas Gohr //decide on start and end 8663db95becSAndreas Gohr if($params['reverse']){ 8673db95becSAndreas Gohr $mod = -1; 8683db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8693db95becSAndreas Gohr $end = $start - ($params['max']); 870b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8713db95becSAndreas Gohr }else{ 8723db95becSAndreas Gohr $mod = 1; 8733db95becSAndreas Gohr $start = 0; 8743db95becSAndreas Gohr $end = $feed->get_item_quantity(); 8753db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 8763db95becSAndreas Gohr } 8773db95becSAndreas Gohr 878a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8793db95becSAndreas Gohr if($rc){ 8803db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8811bde1582SAndreas Gohr $item = $feed->get_item($x); 8823db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 883d2ea3363SAndreas Gohr // support feeds without links 884d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 885d2ea3363SAndreas Gohr if($lnkurl){ 8861ca2719cSAndreas Gohr // lnkurl might be an attack vector, only allow registered protocols 8871ca2719cSAndreas Gohr if(is_null($this->schemes)) $this->schemes = getSchemes(); 8881ca2719cSAndreas Gohr list($scheme) = explode('://',$lnkurl); 8891ca2719cSAndreas Gohr $scheme = strtolower($scheme); 8901ca2719cSAndreas Gohr if(!in_array($scheme,$this->schemes)) $lnkurl = ''; 8911ca2719cSAndreas Gohr } 8921ca2719cSAndreas Gohr 8931ca2719cSAndreas Gohr if($lnkurl){ 894793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 895793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8961bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 897793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 898d2ea3363SAndreas Gohr }else{ 899d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 900d2ea3363SAndreas Gohr } 9013db95becSAndreas Gohr if($params['author']){ 9021bde1582SAndreas Gohr $author = $item->get_author(0); 9031bde1582SAndreas Gohr if($author){ 9041bde1582SAndreas Gohr $name = $author->get_name(); 9051bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 9061bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 9071bde1582SAndreas Gohr } 9083db95becSAndreas Gohr } 9093db95becSAndreas Gohr if($params['date']){ 9102e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 9113db95becSAndreas Gohr } 9121bde1582SAndreas Gohr if($params['details']){ 9133db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 914173dccb7STom N Harris if($conf['htmlok']){ 9151bde1582SAndreas Gohr $this->doc .= $item->get_description(); 9163db95becSAndreas Gohr }else{ 9171bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 9183db95becSAndreas Gohr } 9193db95becSAndreas Gohr $this->doc .= '</div>'; 9203db95becSAndreas Gohr } 9213db95becSAndreas Gohr 9223db95becSAndreas Gohr $this->doc .= '</div></li>'; 923b625487dSandi } 924b625487dSandi }else{ 9253db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 926a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 927b625487dSandi $this->externallink($url); 92845e147ccSAndreas Gohr if($conf['allowdebug']){ 92945e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 93045e147ccSAndreas Gohr } 9313db95becSAndreas Gohr $this->doc .= '</div></li>'; 932b625487dSandi } 933a2d649c4Sandi $this->doc .= '</ul>'; 934b625487dSandi } 935b625487dSandi 9360cecf9d5Sandi // $numrows not yet implemented 937619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){ 93890df9a4dSAdrian Lang global $lang; 939b5742cedSPierre Spring // initialize the row counter used for classes 940b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 941619736fdSAdrian Lang $class = 'table'; 942619736fdSAdrian Lang if ($pos !== null) { 943619736fdSAdrian Lang $class .= ' ' . $this->startSectionEdit($pos, 'table'); 944619736fdSAdrian Lang } 945619736fdSAdrian Lang $this->doc .= '<div class="' . $class . '"><table class="inline">' . 946619736fdSAdrian Lang DOKU_LF; 9470cecf9d5Sandi } 9480cecf9d5Sandi 949619736fdSAdrian Lang function table_close($pos = null){ 950a8574918SAnika Henke $this->doc .= '</table></div>'.DOKU_LF; 951619736fdSAdrian Lang if ($pos !== null) { 95290df9a4dSAdrian Lang $this->finishSectionEdit($pos); 9530cecf9d5Sandi } 954619736fdSAdrian Lang } 9550cecf9d5Sandi 9560cecf9d5Sandi function tablerow_open(){ 957b5742cedSPierre Spring // initialize the cell counter used for classes 958b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 959b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 960b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9610cecf9d5Sandi } 9620cecf9d5Sandi 9630cecf9d5Sandi function tablerow_close(){ 964a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9650cecf9d5Sandi } 9660cecf9d5Sandi 96725b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 968b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9690cecf9d5Sandi if ( !is_null($align) ) { 970b5742cedSPierre Spring $class .= ' '.$align.'align'; 9710cecf9d5Sandi } 972b5742cedSPierre Spring $class .= '"'; 973b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9740cecf9d5Sandi if ( $colspan > 1 ) { 975a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 976a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9770cecf9d5Sandi } 97825b97867Shakan.sandell if ( $rowspan > 1 ) { 97925b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 98025b97867Shakan.sandell } 981a2d649c4Sandi $this->doc .= '>'; 9820cecf9d5Sandi } 9830cecf9d5Sandi 9840cecf9d5Sandi function tableheader_close(){ 985a2d649c4Sandi $this->doc .= '</th>'; 9860cecf9d5Sandi } 9870cecf9d5Sandi 98825b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 989b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9900cecf9d5Sandi if ( !is_null($align) ) { 991b5742cedSPierre Spring $class .= ' '.$align.'align'; 9920cecf9d5Sandi } 993b5742cedSPierre Spring $class .= '"'; 994b5742cedSPierre Spring $this->doc .= '<td '.$class; 9950cecf9d5Sandi if ( $colspan > 1 ) { 996a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 997a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9980cecf9d5Sandi } 99925b97867Shakan.sandell if ( $rowspan > 1 ) { 100025b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 100125b97867Shakan.sandell } 1002a2d649c4Sandi $this->doc .= '>'; 10030cecf9d5Sandi } 10040cecf9d5Sandi 10050cecf9d5Sandi function tablecell_close(){ 1006a2d649c4Sandi $this->doc .= '</td>'; 10070cecf9d5Sandi } 10080cecf9d5Sandi 10090cecf9d5Sandi //---------------------------------------------------------- 10100cecf9d5Sandi // Utils 10110cecf9d5Sandi 1012ba11bd29Sandi /** 10133fd0b676Sandi * Build a link 10143fd0b676Sandi * 10153fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 1016ba11bd29Sandi * 1017ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 1018ba11bd29Sandi */ 1019433bef32Sandi function _formatLink($link){ 1020ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 1021ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 1022ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 1023ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 1024ba11bd29Sandi } 1025ba11bd29Sandi //remove double encodings in titles 1026ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 1027ba11bd29Sandi 1028453493f2SAndreas Gohr // be sure there are no bad chars in url or title 1029453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 1030453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 1031453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 1032453493f2SAndreas Gohr 1033ba11bd29Sandi $ret = ''; 1034ba11bd29Sandi $ret .= $link['pre']; 1035ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 1036bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 1037bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 1038bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1039bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 104044a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 1041bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1042ba11bd29Sandi $ret .= '>'; 1043ba11bd29Sandi $ret .= $link['name']; 1044ba11bd29Sandi $ret .= '</a>'; 1045ba11bd29Sandi $ret .= $link['suf']; 1046ba11bd29Sandi return $ret; 1047ba11bd29Sandi } 1048ba11bd29Sandi 1049ba11bd29Sandi /** 10503fd0b676Sandi * Renders internal and external media 10513fd0b676Sandi * 10523fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10533fd0b676Sandi */ 10543fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 1055b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 10563fd0b676Sandi 10573fd0b676Sandi $ret = ''; 10583fd0b676Sandi 1059ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10603fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1061b739ff0fSPierre Spring // first get the $title 1062b739ff0fSPierre Spring if (!is_null($title)) { 1063b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1064b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1065b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1066b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 106767f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1068b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1069b739ff0fSPierre Spring if($cap){ 1070b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1071b739ff0fSPierre Spring } 1072b739ff0fSPierre Spring } 1073b739ff0fSPierre Spring if (!$render) { 1074b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1075b739ff0fSPierre Spring // return the title of the picture 1076b739ff0fSPierre Spring if (!$title) { 1077b739ff0fSPierre Spring // just show the sourcename 1078b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1079b739ff0fSPierre Spring } 1080b739ff0fSPierre Spring return $title; 1081b739ff0fSPierre Spring } 10823fd0b676Sandi //add image tag 10836de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10843fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10853fd0b676Sandi 10864ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10874ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10884ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10894ab889eaSAndreas Gohr 1090b739ff0fSPierre Spring if ($title) { 1091b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1092b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10933fd0b676Sandi }else{ 10943fd0b676Sandi $ret .= ' alt=""'; 10953fd0b676Sandi } 10963fd0b676Sandi 10973fd0b676Sandi if ( !is_null($width) ) 10983fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10993fd0b676Sandi 11003fd0b676Sandi if ( !is_null($height) ) 11013fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 11023fd0b676Sandi 11033fd0b676Sandi $ret .= ' />'; 11043fd0b676Sandi 11053fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 11061c882ba8SAndreas Gohr if (!$render) { 11071c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 11081c882ba8SAndreas Gohr // return the title of the flash 11091c882ba8SAndreas Gohr if (!$title) { 11101c882ba8SAndreas Gohr // just show the sourcename 111107bf32b2SAndreas Gohr $title = basename(noNS($src)); 11121c882ba8SAndreas Gohr } 111307bf32b2SAndreas Gohr return $this->_xmlEntities($title); 11141c882ba8SAndreas Gohr } 11151c882ba8SAndreas Gohr 111607bf32b2SAndreas Gohr $att = array(); 111707bf32b2SAndreas Gohr $att['class'] = "media$align"; 111807bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 111907bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1120c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 112107bf32b2SAndreas Gohr array('quality' => 'high'), 112207bf32b2SAndreas Gohr null, 112307bf32b2SAndreas Gohr $att, 112407bf32b2SAndreas Gohr $this->_xmlEntities($title)); 11250f428d7dSAndreas Gohr }elseif($title){ 11263fd0b676Sandi // well at least we have a title to display 11273fd0b676Sandi $ret .= $this->_xmlEntities($title); 11283fd0b676Sandi }else{ 11295291ca3aSAndreas Gohr // just show the sourcename 11300f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 11313fd0b676Sandi } 11323fd0b676Sandi 11333fd0b676Sandi return $ret; 11343fd0b676Sandi } 11353fd0b676Sandi 1136433bef32Sandi function _xmlEntities($string) { 1137de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 11380cecf9d5Sandi } 11390cecf9d5Sandi 11408a831f2bSAndreas Gohr /** 11418a831f2bSAndreas Gohr * Creates a linkid from a headline 1142c5a8fd96SAndreas Gohr * 1143c5a8fd96SAndreas Gohr * @param string $title The headline title 1144c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1145c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11468a831f2bSAndreas Gohr */ 1147c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1148c5a8fd96SAndreas Gohr if($create){ 11494ceab83fSAndreas Gohr return sectionID($title,$this->headers); 11504ceab83fSAndreas Gohr }else{ 1151443d207bSAndreas Gohr $check = false; 1152443d207bSAndreas Gohr return sectionID($title,$check); 1153c5a8fd96SAndreas Gohr } 11540cecf9d5Sandi } 11550cecf9d5Sandi 1156af587fa8Sandi /** 11573fd0b676Sandi * Construct a title and handle images in titles 11583fd0b676Sandi * 11590b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11603fd0b676Sandi */ 1161fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1162bb0a59d4Sjan global $conf; 1163bb0a59d4Sjan 116444881bd0Shenning.noren $isImage = false; 116529657f9eSAndreas Gohr if ( is_array($title) ) { 116629657f9eSAndreas Gohr $isImage = true; 116729657f9eSAndreas Gohr return $this->_imageTitle($title); 116829657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1169fe9ec250SChris Smith if (useHeading($linktype) && $id) { 117067c15eceSMichael Hamann $heading = p_get_first_heading($id); 1171bb0a59d4Sjan if ($heading) { 1172433bef32Sandi return $this->_xmlEntities($heading); 1173bb0a59d4Sjan } 1174bb0a59d4Sjan } 1175433bef32Sandi return $this->_xmlEntities($default); 117668c26e6dSMichael Klier } else { 117768c26e6dSMichael Klier return $this->_xmlEntities($title); 11780cecf9d5Sandi } 11790cecf9d5Sandi } 11800cecf9d5Sandi 11810cecf9d5Sandi /** 11823fd0b676Sandi * Returns an HTML code for images used in link titles 11833fd0b676Sandi * 11843fd0b676Sandi * @todo Resolve namespace on internal images 11853fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11860cecf9d5Sandi */ 1187433bef32Sandi function _imageTitle($img) { 1188d9baf1a7SKazutaka Miyasaka global $ID; 1189d9baf1a7SKazutaka Miyasaka 1190d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1191d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1192d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1193d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1194d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1195d9baf1a7SKazutaka Miyasaka } 1196d9baf1a7SKazutaka Miyasaka 1197433bef32Sandi return $this->_media($img['src'], 11984826ab45Sandi $img['title'], 11994826ab45Sandi $img['align'], 12004826ab45Sandi $img['width'], 12014826ab45Sandi $img['height'], 12024826ab45Sandi $img['cache']); 12030cecf9d5Sandi } 1204b739ff0fSPierre Spring 1205b739ff0fSPierre Spring /** 1206b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1207b739ff0fSPierre Spring * which returns a basic link to a media. 1208b739ff0fSPierre Spring * 1209b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1210b739ff0fSPierre Spring * @param string $src 1211b739ff0fSPierre Spring * @param string $title 1212b739ff0fSPierre Spring * @param string $align 1213b739ff0fSPierre Spring * @param string $width 1214b739ff0fSPierre Spring * @param string $height 1215b739ff0fSPierre Spring * @param string $cache 1216b739ff0fSPierre Spring * @param string $render 1217b739ff0fSPierre Spring * @access protected 1218b739ff0fSPierre Spring * @return array 1219b739ff0fSPierre Spring */ 1220b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1221b739ff0fSPierre Spring { 1222b739ff0fSPierre Spring global $conf; 1223b739ff0fSPierre Spring 1224b739ff0fSPierre Spring $link = array(); 1225b739ff0fSPierre Spring $link['class'] = 'media'; 1226b739ff0fSPierre Spring $link['style'] = ''; 1227b739ff0fSPierre Spring $link['pre'] = ''; 1228b739ff0fSPierre Spring $link['suf'] = ''; 1229b739ff0fSPierre Spring $link['more'] = ''; 1230b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1231b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1232b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1233b739ff0fSPierre Spring 1234b739ff0fSPierre Spring return $link; 1235b739ff0fSPierre Spring } 123691459163SAnika Henke 123791459163SAnika Henke 12380cecf9d5Sandi} 12390cecf9d5Sandi 1240e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1241