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 3290df9a4dSAdrian Lang 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 4390df9a4dSAdrian Lang /** 4490df9a4dSAdrian Lang * Register a new edit section range 4590df9a4dSAdrian Lang * 4690df9a4dSAdrian Lang * @param $type string The section type identifier 4790df9a4dSAdrian Lang * @param $title string The section title 4890df9a4dSAdrian Lang * @param $start int The byte position for the edit start 4990df9a4dSAdrian Lang * @return string A marker class for the starting HTML element 5090df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 5190df9a4dSAdrian Lang */ 523f9e3215SAdrian Lang public function startSectionEdit($start, $type, $title = null) { 5390df9a4dSAdrian Lang static $lastsecid = 0; 5490df9a4dSAdrian Lang $this->sectionedits[] = array(++$lastsecid, $start, $type, $title); 5590df9a4dSAdrian Lang return 'sectionedit' . $lastsecid; 5690df9a4dSAdrian Lang } 5790df9a4dSAdrian Lang 5890df9a4dSAdrian Lang /** 5990df9a4dSAdrian Lang * Finish an edit section range 6090df9a4dSAdrian Lang * 61d9e36cbeSAdrian Lang * @param $end int The byte position for the edit end; null for the rest of 62d9e36cbeSAdrian Lang the page 6390df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 6490df9a4dSAdrian Lang */ 653f9e3215SAdrian Lang public function finishSectionEdit($end = null) { 6690df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 67d9e36cbeSAdrian Lang if (!is_null($end) && $end <= $start) { 6800c13053SAdrian Lang return; 6900c13053SAdrian Lang } 7040868f2fSAdrian Lang $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' '; 7140868f2fSAdrian Lang if (!is_null($title)) { 7240868f2fSAdrian Lang $this->doc .= '"' . str_replace('"', '', $title) . '" '; 7340868f2fSAdrian Lang } 74d9e36cbeSAdrian Lang $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->'; 7590df9a4dSAdrian Lang } 7690df9a4dSAdrian Lang 775f70445dSAndreas Gohr function getFormat(){ 785f70445dSAndreas Gohr return 'xhtml'; 795f70445dSAndreas Gohr } 805f70445dSAndreas Gohr 815f70445dSAndreas Gohr 820cecf9d5Sandi function document_start() { 83c5a8fd96SAndreas Gohr //reset some internals 84c5a8fd96SAndreas Gohr $this->toc = array(); 85c5a8fd96SAndreas Gohr $this->headers = array(); 860cecf9d5Sandi } 870cecf9d5Sandi 880cecf9d5Sandi function document_end() { 8990df9a4dSAdrian Lang // Finish open section edits. 9090df9a4dSAdrian Lang while (count($this->sectionedits) > 0) { 9190df9a4dSAdrian Lang if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 9290df9a4dSAdrian Lang // If there is only one section, do not write a section edit 9390df9a4dSAdrian Lang // marker. 9490df9a4dSAdrian Lang array_pop($this->sectionedits); 9590df9a4dSAdrian Lang } else { 96d9e36cbeSAdrian Lang $this->finishSectionEdit(); 9790df9a4dSAdrian Lang } 9890df9a4dSAdrian Lang } 9990df9a4dSAdrian Lang 1000cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 101a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 102d74aace9Schris 103d74aace9Schris $id = 0; 1040cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 105d74aace9Schris $id++; // the number of the current footnote 106d74aace9Schris 107d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 108d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 109d74aace9Schris 110d74aace9Schris // open the footnote and set the anchor and backlink 111d74aace9Schris $this->doc .= '<div class="fn">'; 11229bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 11329bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 114d74aace9Schris 115d74aace9Schris // get any other footnotes that use the same markup 116d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 117d74aace9Schris 118d74aace9Schris if (count($alt)) { 119d74aace9Schris foreach ($alt as $ref) { 120d74aace9Schris // set anchor and backlink for the other footnotes 12129bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 12229bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 123d74aace9Schris } 124d74aace9Schris } 125d74aace9Schris 126d74aace9Schris // add footnote markup and close this footnote 127a2d649c4Sandi $this->doc .= $footnote; 128d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 129d74aace9Schris } 1300cecf9d5Sandi } 131a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 1320cecf9d5Sandi } 133c5a8fd96SAndreas Gohr 134b8595a66SAndreas Gohr // Prepare the TOC 135851f2e89SAnika Henke global $conf; 136851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 137b8595a66SAndreas Gohr global $TOC; 138b8595a66SAndreas Gohr $TOC = $this->toc; 1390cecf9d5Sandi } 1403e55d035SAndreas Gohr 1413e55d035SAndreas Gohr // make sure there are no empty paragraphs 14227918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 143e41c4da9SAndreas Gohr } 1440cecf9d5Sandi 145e7856beaSchris function toc_additem($id, $text, $level) { 146af587fa8Sandi global $conf; 147af587fa8Sandi 148c5a8fd96SAndreas Gohr //handle TOC 149c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1507d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 151c5a8fd96SAndreas Gohr } 152e7856beaSchris } 153e7856beaSchris 154e7856beaSchris function header($text, $level, $pos) { 15590df9a4dSAdrian Lang global $conf; 15690df9a4dSAdrian Lang 157bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 158e7856beaSchris 159e7856beaSchris $hid = $this->_headerToLink($text,true); 160e7856beaSchris 161e7856beaSchris //only add items within configured levels 162e7856beaSchris $this->toc_additem($hid, $text, $level); 163c5a8fd96SAndreas Gohr 16491459163SAnika Henke // adjust $node to reflect hierarchy of levels 16591459163SAnika Henke $this->node[$level-1]++; 16691459163SAnika Henke if ($level < $this->lastlevel) { 16791459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 16891459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 16991459163SAnika Henke } 17091459163SAnika Henke } 17191459163SAnika Henke $this->lastlevel = $level; 17291459163SAnika Henke 17390df9a4dSAdrian Lang if ($level <= $conf['maxseclevel'] && 17490df9a4dSAdrian Lang count($this->sectionedits) > 0 && 17590df9a4dSAdrian Lang $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { 1766c1f778cSAdrian Lang $this->finishSectionEdit($pos - 1); 17790df9a4dSAdrian Lang } 17890df9a4dSAdrian Lang 179c5a8fd96SAndreas Gohr // write the header 18090df9a4dSAdrian Lang $this->doc .= DOKU_LF.'<h'.$level; 18190df9a4dSAdrian Lang if ($level <= $conf['maxseclevel']) { 18290df9a4dSAdrian Lang $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; 18390df9a4dSAdrian Lang } 18490df9a4dSAdrian Lang $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">'; 185a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 18659869a4bSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1870cecf9d5Sandi } 1880cecf9d5Sandi 1890cecf9d5Sandi function section_open($level) { 1909864e7b1SAdrian Lang $this->doc .= '<div class="level' . $level . '">' . DOKU_LF; 1910cecf9d5Sandi } 1920cecf9d5Sandi 1930cecf9d5Sandi function section_close() { 194a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1950cecf9d5Sandi } 1960cecf9d5Sandi 1970cecf9d5Sandi function cdata($text) { 198a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1990cecf9d5Sandi } 2000cecf9d5Sandi 2010cecf9d5Sandi function p_open() { 20259869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 2030cecf9d5Sandi } 2040cecf9d5Sandi 2050cecf9d5Sandi function p_close() { 20659869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 2070cecf9d5Sandi } 2080cecf9d5Sandi 2090cecf9d5Sandi function linebreak() { 210a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 2110cecf9d5Sandi } 2120cecf9d5Sandi 2130cecf9d5Sandi function hr() { 2144beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 2150cecf9d5Sandi } 2160cecf9d5Sandi 2170cecf9d5Sandi function strong_open() { 218a2d649c4Sandi $this->doc .= '<strong>'; 2190cecf9d5Sandi } 2200cecf9d5Sandi 2210cecf9d5Sandi function strong_close() { 222a2d649c4Sandi $this->doc .= '</strong>'; 2230cecf9d5Sandi } 2240cecf9d5Sandi 2250cecf9d5Sandi function emphasis_open() { 226a2d649c4Sandi $this->doc .= '<em>'; 2270cecf9d5Sandi } 2280cecf9d5Sandi 2290cecf9d5Sandi function emphasis_close() { 230a2d649c4Sandi $this->doc .= '</em>'; 2310cecf9d5Sandi } 2320cecf9d5Sandi 2330cecf9d5Sandi function underline_open() { 23402e51121SAnika Henke $this->doc .= '<em class="u">'; 2350cecf9d5Sandi } 2360cecf9d5Sandi 2370cecf9d5Sandi function underline_close() { 23802e51121SAnika Henke $this->doc .= '</em>'; 2390cecf9d5Sandi } 2400cecf9d5Sandi 2410cecf9d5Sandi function monospace_open() { 242a2d649c4Sandi $this->doc .= '<code>'; 2430cecf9d5Sandi } 2440cecf9d5Sandi 2450cecf9d5Sandi function monospace_close() { 246a2d649c4Sandi $this->doc .= '</code>'; 2470cecf9d5Sandi } 2480cecf9d5Sandi 2490cecf9d5Sandi function subscript_open() { 250a2d649c4Sandi $this->doc .= '<sub>'; 2510cecf9d5Sandi } 2520cecf9d5Sandi 2530cecf9d5Sandi function subscript_close() { 254a2d649c4Sandi $this->doc .= '</sub>'; 2550cecf9d5Sandi } 2560cecf9d5Sandi 2570cecf9d5Sandi function superscript_open() { 258a2d649c4Sandi $this->doc .= '<sup>'; 2590cecf9d5Sandi } 2600cecf9d5Sandi 2610cecf9d5Sandi function superscript_close() { 262a2d649c4Sandi $this->doc .= '</sup>'; 2630cecf9d5Sandi } 2640cecf9d5Sandi 2650cecf9d5Sandi function deleted_open() { 266a2d649c4Sandi $this->doc .= '<del>'; 2670cecf9d5Sandi } 2680cecf9d5Sandi 2690cecf9d5Sandi function deleted_close() { 270a2d649c4Sandi $this->doc .= '</del>'; 2710cecf9d5Sandi } 2720cecf9d5Sandi 2733fd0b676Sandi /** 2743fd0b676Sandi * Callback for footnote start syntax 2753fd0b676Sandi * 2763fd0b676Sandi * All following content will go to the footnote instead of 277d74aace9Schris * the document. To achieve this the previous rendered content 2783fd0b676Sandi * is moved to $store and $doc is cleared 2793fd0b676Sandi * 2803fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2813fd0b676Sandi */ 2820cecf9d5Sandi function footnote_open() { 2837764a90aSandi 2847764a90aSandi // move current content to store and record footnote 2857764a90aSandi $this->store = $this->doc; 2867764a90aSandi $this->doc = ''; 2870cecf9d5Sandi } 2880cecf9d5Sandi 2893fd0b676Sandi /** 2903fd0b676Sandi * Callback for footnote end syntax 2913fd0b676Sandi * 2923fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2933fd0b676Sandi * content is restored from $store again 2943fd0b676Sandi * 2953fd0b676Sandi * @author Andreas Gohr 2963fd0b676Sandi */ 2970cecf9d5Sandi function footnote_close() { 2987764a90aSandi 299d74aace9Schris // recover footnote into the stack and restore old content 300d74aace9Schris $footnote = $this->doc; 3017764a90aSandi $this->doc = $this->store; 3027764a90aSandi $this->store = ''; 303d74aace9Schris 304d74aace9Schris // check to see if this footnote has been seen before 305d74aace9Schris $i = array_search($footnote, $this->footnotes); 306d74aace9Schris 307d74aace9Schris if ($i === false) { 308d74aace9Schris // its a new footnote, add it to the $footnotes array 309d74aace9Schris $id = count($this->footnotes)+1; 310d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 311d74aace9Schris } else { 312d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 313d74aace9Schris $i++; 314d74aace9Schris $id = count($this->footnotes)+1; 315d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 316d74aace9Schris } 317d74aace9Schris 3186b379cbfSAndreas Gohr // output the footnote reference and link 31929bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 3200cecf9d5Sandi } 3210cecf9d5Sandi 3220cecf9d5Sandi function listu_open() { 323a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 3240cecf9d5Sandi } 3250cecf9d5Sandi 3260cecf9d5Sandi function listu_close() { 327a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3280cecf9d5Sandi } 3290cecf9d5Sandi 3300cecf9d5Sandi function listo_open() { 331a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3320cecf9d5Sandi } 3330cecf9d5Sandi 3340cecf9d5Sandi function listo_close() { 335a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3360cecf9d5Sandi } 3370cecf9d5Sandi 3380cecf9d5Sandi function listitem_open($level) { 33959869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 3400cecf9d5Sandi } 3410cecf9d5Sandi 3420cecf9d5Sandi function listitem_close() { 343a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3440cecf9d5Sandi } 3450cecf9d5Sandi 3460cecf9d5Sandi function listcontent_open() { 34790db23d7Schris $this->doc .= '<div class="li">'; 3480cecf9d5Sandi } 3490cecf9d5Sandi 3500cecf9d5Sandi function listcontent_close() { 35159869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3520cecf9d5Sandi } 3530cecf9d5Sandi 3540cecf9d5Sandi function unformatted($text) { 355a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3560cecf9d5Sandi } 3570cecf9d5Sandi 3580cecf9d5Sandi /** 3593fd0b676Sandi * Execute PHP code if allowed 3603fd0b676Sandi * 3615d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3625d568b99SChris Smith * 3633fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3640cecf9d5Sandi */ 3655d568b99SChris Smith function php($text, $wrapper='code') { 36635a56260SChris Smith global $conf; 36735a56260SChris Smith 368d86d5af0SChris Smith if($conf['phpok']){ 369bad0b545Sandi ob_start(); 3704de671bcSandi eval($text); 3713fd0b676Sandi $this->doc .= ob_get_contents(); 372bad0b545Sandi ob_end_clean(); 373d86d5af0SChris Smith } else { 3745d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 375d86d5af0SChris Smith } 3760cecf9d5Sandi } 3770cecf9d5Sandi 37807f89c3cSAnika Henke function phpblock($text) { 3795d568b99SChris Smith $this->php($text, 'pre'); 38007f89c3cSAnika Henke } 38107f89c3cSAnika Henke 3820cecf9d5Sandi /** 3833fd0b676Sandi * Insert HTML if allowed 3843fd0b676Sandi * 3855d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3865d568b99SChris Smith * 3873fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3880cecf9d5Sandi */ 3895d568b99SChris Smith function html($text, $wrapper='code') { 39035a56260SChris Smith global $conf; 39135a56260SChris Smith 392d86d5af0SChris Smith if($conf['htmlok']){ 393a2d649c4Sandi $this->doc .= $text; 394d86d5af0SChris Smith } else { 3955d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 396d86d5af0SChris Smith } 3974de671bcSandi } 3980cecf9d5Sandi 39907f89c3cSAnika Henke function htmlblock($text) { 4005d568b99SChris Smith $this->html($text, 'pre'); 40107f89c3cSAnika Henke } 40207f89c3cSAnika Henke 4030cecf9d5Sandi function quote_open() { 40496331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 4050cecf9d5Sandi } 4060cecf9d5Sandi 4070cecf9d5Sandi function quote_close() { 40896331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 4090cecf9d5Sandi } 4100cecf9d5Sandi 4113d491f75SAndreas Gohr function preformatted($text) { 412c9250713SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 4133d491f75SAndreas Gohr } 4143d491f75SAndreas Gohr 4153d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 4163d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 4173d491f75SAndreas Gohr } 4183d491f75SAndreas Gohr 4193d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 4203d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 4213d491f75SAndreas Gohr } 4223d491f75SAndreas Gohr 4230cecf9d5Sandi /** 4243d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 4253fd0b676Sandi * 4263fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 4270cecf9d5Sandi */ 4283d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 4294de671bcSandi global $conf; 4303d491f75SAndreas Gohr global $ID; 4313d491f75SAndreas Gohr global $lang; 4323d491f75SAndreas Gohr 4333d491f75SAndreas Gohr if($filename){ 434190c56e8SAndreas Gohr // add icon 43527bf7924STom N Harris list($ext) = mimetype($filename,false); 436190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 437190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 438190c56e8SAndreas Gohr 4393d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 440190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 4413d491f75SAndreas Gohr $this->doc .= hsc($filename); 4423d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 4433d491f75SAndreas Gohr } 4440cecf9d5Sandi 445*d43aac1cSGina Haeussge if ($text{0} == "\n") { 446*d43aac1cSGina Haeussge $text = substr($text, 1); 447*d43aac1cSGina Haeussge } 448*d43aac1cSGina Haeussge if (substr($text, -1) == "\n") { 449*d43aac1cSGina Haeussge $text = substr($text, 0, -1); 450*d43aac1cSGina Haeussge } 451*d43aac1cSGina Haeussge 4520cecf9d5Sandi if ( is_null($language) ) { 4533d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4540cecf9d5Sandi } else { 4553d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4563d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4573d491f75SAndreas Gohr 4583d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4590cecf9d5Sandi } 4603d491f75SAndreas Gohr 4613d491f75SAndreas Gohr if($filename){ 4623d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4633d491f75SAndreas Gohr } 4643d491f75SAndreas Gohr 4653d491f75SAndreas Gohr $this->_codeblock++; 4660cecf9d5Sandi } 4670cecf9d5Sandi 4680cecf9d5Sandi function acronym($acronym) { 4690cecf9d5Sandi 4700cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4710cecf9d5Sandi 472433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4730cecf9d5Sandi 474a2d649c4Sandi $this->doc .= '<acronym title="'.$title 475433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4760cecf9d5Sandi 4770cecf9d5Sandi } else { 478a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4790cecf9d5Sandi } 4800cecf9d5Sandi } 4810cecf9d5Sandi 4820cecf9d5Sandi function smiley($smiley) { 4830cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 484433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 485f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4864beabca9SAnika Henke '" class="middle" alt="'. 487433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4880cecf9d5Sandi } else { 489a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4900cecf9d5Sandi } 4910cecf9d5Sandi } 4920cecf9d5Sandi 493f62ea8a1Sandi /* 4944de671bcSandi * not used 4950cecf9d5Sandi function wordblock($word) { 4960cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 497a2d649c4Sandi $this->doc .= '** BLEEP **'; 4980cecf9d5Sandi } else { 499a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 5000cecf9d5Sandi } 5010cecf9d5Sandi } 5024de671bcSandi */ 5030cecf9d5Sandi 5040cecf9d5Sandi function entity($entity) { 5050cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 506a2d649c4Sandi $this->doc .= $this->entities[$entity]; 5070cecf9d5Sandi } else { 508a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 5090cecf9d5Sandi } 5100cecf9d5Sandi } 5110cecf9d5Sandi 5120cecf9d5Sandi function multiplyentity($x, $y) { 513a2d649c4Sandi $this->doc .= "$x×$y"; 5140cecf9d5Sandi } 5150cecf9d5Sandi 5160cecf9d5Sandi function singlequoteopening() { 51771b40da2SAnika Henke global $lang; 51871b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 5190cecf9d5Sandi } 5200cecf9d5Sandi 5210cecf9d5Sandi function singlequoteclosing() { 52271b40da2SAnika Henke global $lang; 52371b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 5240cecf9d5Sandi } 5250cecf9d5Sandi 52657d757d1SAndreas Gohr function apostrophe() { 52757d757d1SAndreas Gohr global $lang; 528a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 52957d757d1SAndreas Gohr } 53057d757d1SAndreas Gohr 5310cecf9d5Sandi function doublequoteopening() { 53271b40da2SAnika Henke global $lang; 53371b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 5340cecf9d5Sandi } 5350cecf9d5Sandi 5360cecf9d5Sandi function doublequoteclosing() { 53771b40da2SAnika Henke global $lang; 53871b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 5390cecf9d5Sandi } 5400cecf9d5Sandi 5410cecf9d5Sandi /** 5420cecf9d5Sandi */ 5430cecf9d5Sandi function camelcaselink($link) { 54411d0aa47Sandi $this->internallink($link,$link); 5450cecf9d5Sandi } 5460cecf9d5Sandi 5470b7c14c2Sandi 5480b7c14c2Sandi function locallink($hash, $name = NULL){ 5490b7c14c2Sandi global $ID; 5500b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5510b7c14c2Sandi $hash = $this->_headerToLink($hash); 5520b7c14c2Sandi $title = $ID.' ↵'; 5530b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5540b7c14c2Sandi $this->doc .= $name; 5550b7c14c2Sandi $this->doc .= '</a>'; 5560b7c14c2Sandi } 5570b7c14c2Sandi 558cffcc403Sandi /** 5593fd0b676Sandi * Render an internal Wiki Link 5603fd0b676Sandi * 561fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 562cffcc403Sandi * elsewhere - no need to implement them in other renderers 5633fd0b676Sandi * 5643fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 565cffcc403Sandi */ 566fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 567ba11bd29Sandi global $conf; 56837e34a5eSandi global $ID; 56944653a53SAdrian Lang 5703d5e07d9SAdrian Lang $params = ''; 5713d5e07d9SAdrian Lang $parts = explode('?', $id, 2); 5723d5e07d9SAdrian Lang if (count($parts) === 2) { 5733d5e07d9SAdrian Lang $id = $parts[0]; 5743d5e07d9SAdrian Lang $params = $parts[1]; 57544653a53SAdrian Lang } 57644653a53SAdrian Lang 5770339c872Sjan // default name is based on $id as given 5780339c872Sjan $default = $this->_simpleTitle($id); 579ad32e47eSAndreas Gohr 5800339c872Sjan // now first resolve and clean up the $id 58137e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 582fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5830e1c636eSandi if ( !$isImage ) { 5840e1c636eSandi if ( $exists ) { 585ba11bd29Sandi $class='wikilink1'; 5860cecf9d5Sandi } else { 587ba11bd29Sandi $class='wikilink2'; 58844a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5890cecf9d5Sandi } 5900cecf9d5Sandi } else { 591ba11bd29Sandi $class='media'; 5920cecf9d5Sandi } 5930cecf9d5Sandi 594a1685bedSandi //keep hash anchor 595ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 596943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 597a1685bedSandi 598ba11bd29Sandi //prepare for formating 599ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 600ba11bd29Sandi $link['style'] = ''; 601ba11bd29Sandi $link['pre'] = ''; 602ba11bd29Sandi $link['suf'] = ''; 60340eb54bbSjan // highlight link to current page 60440eb54bbSjan if ($id == $ID) { 60592795d04Sandi $link['pre'] = '<span class="curid">'; 60692795d04Sandi $link['suf'] = '</span>'; 60740eb54bbSjan } 6085e163278SAndreas Gohr $link['more'] = ''; 609ba11bd29Sandi $link['class'] = $class; 61044653a53SAdrian Lang $link['url'] = wl($id, $params); 611ba11bd29Sandi $link['name'] = $name; 612ba11bd29Sandi $link['title'] = $id; 613723d78dbSandi //add search string 614723d78dbSandi if($search){ 615546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 616546d3a99SAndreas Gohr if(is_array($search)){ 617546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 618546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 619546d3a99SAndreas Gohr }else{ 620546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 621546d3a99SAndreas Gohr } 622723d78dbSandi } 623723d78dbSandi 624a1685bedSandi //keep hash 625a1685bedSandi if($hash) $link['url'].='#'.$hash; 626a1685bedSandi 627ba11bd29Sandi //output formatted 628cffcc403Sandi if($returnonly){ 629cffcc403Sandi return $this->_formatLink($link); 630cffcc403Sandi }else{ 631a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6320cecf9d5Sandi } 633cffcc403Sandi } 6340cecf9d5Sandi 635b625487dSandi function externallink($url, $name = NULL) { 636b625487dSandi global $conf; 6370cecf9d5Sandi 638433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 6396f0c5dbfSandi 6400cecf9d5Sandi if ( !$isImage ) { 641b625487dSandi $class='urlextern'; 6420cecf9d5Sandi } else { 643b625487dSandi $class='media'; 6440cecf9d5Sandi } 6450cecf9d5Sandi 646b625487dSandi //prepare for formating 647b625487dSandi $link['target'] = $conf['target']['extern']; 648b625487dSandi $link['style'] = ''; 649b625487dSandi $link['pre'] = ''; 650b625487dSandi $link['suf'] = ''; 6515e163278SAndreas Gohr $link['more'] = ''; 652b625487dSandi $link['class'] = $class; 653b625487dSandi $link['url'] = $url; 654e1c10e4dSchris 655b625487dSandi $link['name'] = $name; 656433bef32Sandi $link['title'] = $this->_xmlEntities($url); 657b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6580cecf9d5Sandi 659b625487dSandi //output formatted 660a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6610cecf9d5Sandi } 6620cecf9d5Sandi 6630cecf9d5Sandi /** 6640cecf9d5Sandi */ 66597a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 666b625487dSandi global $conf; 6670cecf9d5Sandi 66897a3e4e3Sandi $link = array(); 66997a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 67097a3e4e3Sandi $link['pre'] = ''; 67197a3e4e3Sandi $link['suf'] = ''; 6725e163278SAndreas Gohr $link['more'] = ''; 673433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6740cecf9d5Sandi 67597a3e4e3Sandi //get interwiki URL 6761f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6770cecf9d5Sandi 67897a3e4e3Sandi if ( !$isImage ) { 6799d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6809d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6811c2d1019SAndreas Gohr } else { 6821c2d1019SAndreas Gohr $link['class'] = 'media'; 68397a3e4e3Sandi } 6840cecf9d5Sandi 68597a3e4e3Sandi //do we stay at the same server? Use local target 68697a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 68797a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 68897a3e4e3Sandi } 6890cecf9d5Sandi 69097a3e4e3Sandi $link['url'] = $url; 69197a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 69297a3e4e3Sandi 69397a3e4e3Sandi //output formatted 694a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6950cecf9d5Sandi } 6960cecf9d5Sandi 6970cecf9d5Sandi /** 6980cecf9d5Sandi */ 6991d47afe1Sandi function windowssharelink($url, $name = NULL) { 7001d47afe1Sandi global $conf; 7011d47afe1Sandi global $lang; 7021d47afe1Sandi //simple setup 7031d47afe1Sandi $link['target'] = $conf['target']['windows']; 7041d47afe1Sandi $link['pre'] = ''; 7051d47afe1Sandi $link['suf'] = ''; 7061d47afe1Sandi $link['style'] = ''; 7070cecf9d5Sandi 708433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 7090cecf9d5Sandi if ( !$isImage ) { 7101d47afe1Sandi $link['class'] = 'windows'; 7110cecf9d5Sandi } else { 7121d47afe1Sandi $link['class'] = 'media'; 7130cecf9d5Sandi } 7140cecf9d5Sandi 7150cecf9d5Sandi 716433bef32Sandi $link['title'] = $this->_xmlEntities($url); 7171d47afe1Sandi $url = str_replace('\\','/',$url); 7181d47afe1Sandi $url = 'file:///'.$url; 7191d47afe1Sandi $link['url'] = $url; 7200cecf9d5Sandi 7211d47afe1Sandi //output formatted 722a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7230cecf9d5Sandi } 7240cecf9d5Sandi 72571352defSandi function emaillink($address, $name = NULL) { 72671352defSandi global $conf; 72771352defSandi //simple setup 72871352defSandi $link = array(); 72971352defSandi $link['target'] = ''; 73071352defSandi $link['pre'] = ''; 73171352defSandi $link['suf'] = ''; 73271352defSandi $link['style'] = ''; 73371352defSandi $link['more'] = ''; 7340cecf9d5Sandi 735c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7360cecf9d5Sandi if ( !$isImage ) { 737776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 7380cecf9d5Sandi } else { 739776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 7400cecf9d5Sandi } 7410cecf9d5Sandi 74207738714SAndreas Gohr $address = $this->_xmlEntities($address); 74300a7b5adSEsther Brunner $address = obfuscate($address); 74400a7b5adSEsther Brunner $title = $address; 7458c128049SAndreas Gohr 74671352defSandi if(empty($name)){ 74700a7b5adSEsther Brunner $name = $address; 74871352defSandi } 7490cecf9d5Sandi 750776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 751776b36ecSAndreas Gohr 752776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 75371352defSandi $link['name'] = $name; 75471352defSandi $link['title'] = $title; 7550cecf9d5Sandi 75671352defSandi //output formatted 757a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7580cecf9d5Sandi } 7590cecf9d5Sandi 7604826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 761dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 76237e34a5eSandi global $ID; 76391df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 76437e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7650cecf9d5Sandi 766d98d4540SBen Coburn $noLink = false; 7678acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 768b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7693685f775Sandi 77027bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 771b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 772dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7731c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7742ca14335SEsther Brunner // don't link flash movies 77544881bd0Shenning.noren $noLink = true; 77655efc227SAndreas Gohr }else{ 7772ca14335SEsther Brunner // add file icons 7789d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7799d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7806de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 78155efc227SAndreas Gohr } 7823685f775Sandi 78391df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 78491df343aSAndreas Gohr 7856fe20453SGina Haeussge //markup non existing files 7866fe20453SGina Haeussge if (!$exists) 7876fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7886fe20453SGina Haeussge 7893685f775Sandi //output formatted 790dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7912ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7920cecf9d5Sandi } 7930cecf9d5Sandi 7944826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 795dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 79691df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 797d98d4540SBen Coburn $noLink = false; 7988acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 799b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 800b739ff0fSPierre Spring 801b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 8023685f775Sandi 80327bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 804b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 8052ca14335SEsther Brunner // link only jpeg images 80644881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 8071c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 8082ca14335SEsther Brunner // don't link flash movies 80944881bd0Shenning.noren $noLink = true; 8102ca14335SEsther Brunner }else{ 8112ca14335SEsther Brunner // add file icons 81227bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 81327bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 8142ca14335SEsther Brunner } 8152ca14335SEsther Brunner 81691df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 81791df343aSAndreas Gohr 8183685f775Sandi //output formatted 819dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8202ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8210cecf9d5Sandi } 8220cecf9d5Sandi 8234826ab45Sandi /** 8243db95becSAndreas Gohr * Renders an RSS feed 825b625487dSandi * 826b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 827b625487dSandi */ 8283db95becSAndreas Gohr function rss ($url,$params){ 829b625487dSandi global $lang; 8303db95becSAndreas Gohr global $conf; 8313db95becSAndreas Gohr 8323db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8333db95becSAndreas Gohr $feed = new FeedParser(); 83400077af8SAndreas Gohr $feed->set_feed_url($url); 835b625487dSandi 836b625487dSandi //disable warning while fetching 837bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8383db95becSAndreas Gohr $rc = $feed->init(); 839bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 840b625487dSandi 8413db95becSAndreas Gohr //decide on start and end 8423db95becSAndreas Gohr if($params['reverse']){ 8433db95becSAndreas Gohr $mod = -1; 8443db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8453db95becSAndreas Gohr $end = $start - ($params['max']); 846b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8473db95becSAndreas Gohr }else{ 8483db95becSAndreas Gohr $mod = 1; 8493db95becSAndreas Gohr $start = 0; 8503db95becSAndreas Gohr $end = $feed->get_item_quantity(); 8513db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 8523db95becSAndreas Gohr } 8533db95becSAndreas Gohr 854a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8553db95becSAndreas Gohr if($rc){ 8563db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8571bde1582SAndreas Gohr $item = $feed->get_item($x); 8583db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 859d2ea3363SAndreas Gohr // support feeds without links 860d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 861d2ea3363SAndreas Gohr if($lnkurl){ 862793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 863793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8641bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 865793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 866d2ea3363SAndreas Gohr }else{ 867d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 868d2ea3363SAndreas Gohr } 8693db95becSAndreas Gohr if($params['author']){ 8701bde1582SAndreas Gohr $author = $item->get_author(0); 8711bde1582SAndreas Gohr if($author){ 8721bde1582SAndreas Gohr $name = $author->get_name(); 8731bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8741bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8751bde1582SAndreas Gohr } 8763db95becSAndreas Gohr } 8773db95becSAndreas Gohr if($params['date']){ 8782e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8793db95becSAndreas Gohr } 8801bde1582SAndreas Gohr if($params['details']){ 8813db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 882173dccb7STom N Harris if($conf['htmlok']){ 8831bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8843db95becSAndreas Gohr }else{ 8851bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8863db95becSAndreas Gohr } 8873db95becSAndreas Gohr $this->doc .= '</div>'; 8883db95becSAndreas Gohr } 8893db95becSAndreas Gohr 8903db95becSAndreas Gohr $this->doc .= '</div></li>'; 891b625487dSandi } 892b625487dSandi }else{ 8933db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 894a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 895b625487dSandi $this->externallink($url); 89645e147ccSAndreas Gohr if($conf['allowdebug']){ 89745e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 89845e147ccSAndreas Gohr } 8993db95becSAndreas Gohr $this->doc .= '</div></li>'; 900b625487dSandi } 901a2d649c4Sandi $this->doc .= '</ul>'; 902b625487dSandi } 903b625487dSandi 9040cecf9d5Sandi // $numrows not yet implemented 90590df9a4dSAdrian Lang function table_open($maxcols = NULL, $numrows = NULL, $pos){ 90690df9a4dSAdrian Lang global $lang; 907b5742cedSPierre Spring // initialize the row counter used for classes 908b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 90940868f2fSAdrian Lang $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table') . '">'.DOKU_LF; 9100cecf9d5Sandi } 9110cecf9d5Sandi 91290df9a4dSAdrian Lang function table_close($pos){ 91359869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 91490df9a4dSAdrian Lang $this->finishSectionEdit($pos); 9150cecf9d5Sandi } 9160cecf9d5Sandi 9170cecf9d5Sandi function tablerow_open(){ 918b5742cedSPierre Spring // initialize the cell counter used for classes 919b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 920b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 921b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9220cecf9d5Sandi } 9230cecf9d5Sandi 9240cecf9d5Sandi function tablerow_close(){ 925a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9260cecf9d5Sandi } 9270cecf9d5Sandi 92825b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 929b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9300cecf9d5Sandi if ( !is_null($align) ) { 931b5742cedSPierre Spring $class .= ' '.$align.'align'; 9320cecf9d5Sandi } 933b5742cedSPierre Spring $class .= '"'; 934b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9350cecf9d5Sandi if ( $colspan > 1 ) { 936a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 937a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9380cecf9d5Sandi } 93925b97867Shakan.sandell if ( $rowspan > 1 ) { 94025b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 94125b97867Shakan.sandell } 942a2d649c4Sandi $this->doc .= '>'; 9430cecf9d5Sandi } 9440cecf9d5Sandi 9450cecf9d5Sandi function tableheader_close(){ 946a2d649c4Sandi $this->doc .= '</th>'; 9470cecf9d5Sandi } 9480cecf9d5Sandi 94925b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 950b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9510cecf9d5Sandi if ( !is_null($align) ) { 952b5742cedSPierre Spring $class .= ' '.$align.'align'; 9530cecf9d5Sandi } 954b5742cedSPierre Spring $class .= '"'; 955b5742cedSPierre Spring $this->doc .= '<td '.$class; 9560cecf9d5Sandi if ( $colspan > 1 ) { 957a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 958a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9590cecf9d5Sandi } 96025b97867Shakan.sandell if ( $rowspan > 1 ) { 96125b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 96225b97867Shakan.sandell } 963a2d649c4Sandi $this->doc .= '>'; 9640cecf9d5Sandi } 9650cecf9d5Sandi 9660cecf9d5Sandi function tablecell_close(){ 967a2d649c4Sandi $this->doc .= '</td>'; 9680cecf9d5Sandi } 9690cecf9d5Sandi 9700cecf9d5Sandi //---------------------------------------------------------- 9710cecf9d5Sandi // Utils 9720cecf9d5Sandi 973ba11bd29Sandi /** 9743fd0b676Sandi * Build a link 9753fd0b676Sandi * 9763fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 977ba11bd29Sandi * 978ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 979ba11bd29Sandi */ 980433bef32Sandi function _formatLink($link){ 981ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 982ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 983ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 984ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 985ba11bd29Sandi } 986ba11bd29Sandi //remove double encodings in titles 987ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 988ba11bd29Sandi 989453493f2SAndreas Gohr // be sure there are no bad chars in url or title 990453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 991453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 992453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 993453493f2SAndreas Gohr 994ba11bd29Sandi $ret = ''; 995ba11bd29Sandi $ret .= $link['pre']; 996ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 997bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 998bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 999bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1000bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 100144a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 1002bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1003ba11bd29Sandi $ret .= '>'; 1004ba11bd29Sandi $ret .= $link['name']; 1005ba11bd29Sandi $ret .= '</a>'; 1006ba11bd29Sandi $ret .= $link['suf']; 1007ba11bd29Sandi return $ret; 1008ba11bd29Sandi } 1009ba11bd29Sandi 1010ba11bd29Sandi /** 10113fd0b676Sandi * Renders internal and external media 10123fd0b676Sandi * 10133fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10143fd0b676Sandi */ 10153fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 1016b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 10173fd0b676Sandi 10183fd0b676Sandi $ret = ''; 10193fd0b676Sandi 1020ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10213fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1022b739ff0fSPierre Spring // first get the $title 1023b739ff0fSPierre Spring if (!is_null($title)) { 1024b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1025b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1026b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1027b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 102867f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1029b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1030b739ff0fSPierre Spring if($cap){ 1031b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1032b739ff0fSPierre Spring } 1033b739ff0fSPierre Spring } 1034b739ff0fSPierre Spring if (!$render) { 1035b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1036b739ff0fSPierre Spring // return the title of the picture 1037b739ff0fSPierre Spring if (!$title) { 1038b739ff0fSPierre Spring // just show the sourcename 1039b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1040b739ff0fSPierre Spring } 1041b739ff0fSPierre Spring return $title; 1042b739ff0fSPierre Spring } 10433fd0b676Sandi //add image tag 10446de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10453fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10463fd0b676Sandi 10474ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10484ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10494ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10504ab889eaSAndreas Gohr 1051b739ff0fSPierre Spring if ($title) { 1052b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1053b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10543fd0b676Sandi }else{ 10553fd0b676Sandi $ret .= ' alt=""'; 10563fd0b676Sandi } 10573fd0b676Sandi 10583fd0b676Sandi if ( !is_null($width) ) 10593fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10603fd0b676Sandi 10613fd0b676Sandi if ( !is_null($height) ) 10623fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10633fd0b676Sandi 10643fd0b676Sandi $ret .= ' />'; 10653fd0b676Sandi 10663fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10671c882ba8SAndreas Gohr if (!$render) { 10681c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10691c882ba8SAndreas Gohr // return the title of the flash 10701c882ba8SAndreas Gohr if (!$title) { 10711c882ba8SAndreas Gohr // just show the sourcename 107207bf32b2SAndreas Gohr $title = basename(noNS($src)); 10731c882ba8SAndreas Gohr } 107407bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10751c882ba8SAndreas Gohr } 10761c882ba8SAndreas Gohr 107707bf32b2SAndreas Gohr $att = array(); 107807bf32b2SAndreas Gohr $att['class'] = "media$align"; 107907bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 108007bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1081c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 108207bf32b2SAndreas Gohr array('quality' => 'high'), 108307bf32b2SAndreas Gohr null, 108407bf32b2SAndreas Gohr $att, 108507bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10860f428d7dSAndreas Gohr }elseif($title){ 10873fd0b676Sandi // well at least we have a title to display 10883fd0b676Sandi $ret .= $this->_xmlEntities($title); 10893fd0b676Sandi }else{ 10905291ca3aSAndreas Gohr // just show the sourcename 10910f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10923fd0b676Sandi } 10933fd0b676Sandi 10943fd0b676Sandi return $ret; 10953fd0b676Sandi } 10963fd0b676Sandi 1097433bef32Sandi function _xmlEntities($string) { 1098de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10990cecf9d5Sandi } 11000cecf9d5Sandi 11018a831f2bSAndreas Gohr /** 11028a831f2bSAndreas Gohr * Creates a linkid from a headline 1103c5a8fd96SAndreas Gohr * 1104c5a8fd96SAndreas Gohr * @param string $title The headline title 1105c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1106c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11078a831f2bSAndreas Gohr */ 1108c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1109c5a8fd96SAndreas Gohr if($create){ 11104ceab83fSAndreas Gohr return sectionID($title,$this->headers); 11114ceab83fSAndreas Gohr }else{ 1112443d207bSAndreas Gohr $check = false; 1113443d207bSAndreas Gohr return sectionID($title,$check); 1114c5a8fd96SAndreas Gohr } 11150cecf9d5Sandi } 11160cecf9d5Sandi 1117af587fa8Sandi /** 11183fd0b676Sandi * Construct a title and handle images in titles 11193fd0b676Sandi * 11200b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11213fd0b676Sandi */ 1122fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1123bb0a59d4Sjan global $conf; 1124bb0a59d4Sjan 112544881bd0Shenning.noren $isImage = false; 112629657f9eSAndreas Gohr if ( is_array($title) ) { 112729657f9eSAndreas Gohr $isImage = true; 112829657f9eSAndreas Gohr return $this->_imageTitle($title); 112929657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1130fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1131fc18c0fbSchris $heading = p_get_first_heading($id,true); 1132bb0a59d4Sjan if ($heading) { 1133433bef32Sandi return $this->_xmlEntities($heading); 1134bb0a59d4Sjan } 1135bb0a59d4Sjan } 1136433bef32Sandi return $this->_xmlEntities($default); 113768c26e6dSMichael Klier } else { 113868c26e6dSMichael Klier return $this->_xmlEntities($title); 11390cecf9d5Sandi } 11400cecf9d5Sandi } 11410cecf9d5Sandi 11420cecf9d5Sandi /** 11433fd0b676Sandi * Returns an HTML code for images used in link titles 11443fd0b676Sandi * 11453fd0b676Sandi * @todo Resolve namespace on internal images 11463fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11470cecf9d5Sandi */ 1148433bef32Sandi function _imageTitle($img) { 1149d9baf1a7SKazutaka Miyasaka global $ID; 1150d9baf1a7SKazutaka Miyasaka 1151d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1152d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1153d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1154d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1155d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1156d9baf1a7SKazutaka Miyasaka } 1157d9baf1a7SKazutaka Miyasaka 1158433bef32Sandi return $this->_media($img['src'], 11594826ab45Sandi $img['title'], 11604826ab45Sandi $img['align'], 11614826ab45Sandi $img['width'], 11624826ab45Sandi $img['height'], 11634826ab45Sandi $img['cache']); 11640cecf9d5Sandi } 1165b739ff0fSPierre Spring 1166b739ff0fSPierre Spring /** 1167b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1168b739ff0fSPierre Spring * which returns a basic link to a media. 1169b739ff0fSPierre Spring * 1170b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1171b739ff0fSPierre Spring * @param string $src 1172b739ff0fSPierre Spring * @param string $title 1173b739ff0fSPierre Spring * @param string $align 1174b739ff0fSPierre Spring * @param string $width 1175b739ff0fSPierre Spring * @param string $height 1176b739ff0fSPierre Spring * @param string $cache 1177b739ff0fSPierre Spring * @param string $render 1178b739ff0fSPierre Spring * @access protected 1179b739ff0fSPierre Spring * @return array 1180b739ff0fSPierre Spring */ 1181b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1182b739ff0fSPierre Spring { 1183b739ff0fSPierre Spring global $conf; 1184b739ff0fSPierre Spring 1185b739ff0fSPierre Spring $link = array(); 1186b739ff0fSPierre Spring $link['class'] = 'media'; 1187b739ff0fSPierre Spring $link['style'] = ''; 1188b739ff0fSPierre Spring $link['pre'] = ''; 1189b739ff0fSPierre Spring $link['suf'] = ''; 1190b739ff0fSPierre Spring $link['more'] = ''; 1191b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1192b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1193b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1194b739ff0fSPierre Spring 1195b739ff0fSPierre Spring return $link; 1196b739ff0fSPierre Spring } 119791459163SAnika Henke 119891459163SAnika Henke 11990cecf9d5Sandi} 12000cecf9d5Sandi 12014826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1202