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 */ 5240868f2fSAdrian Lang protected 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 * 61*d9e36cbeSAdrian Lang * @param $end int The byte position for the edit end; null for the rest of 62*d9e36cbeSAdrian Lang the page 6390df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 6490df9a4dSAdrian Lang */ 65*d9e36cbeSAdrian Lang protected function finishSectionEdit($end = null) { 6690df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 67*d9e36cbeSAdrian 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 } 74*d9e36cbeSAdrian 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 { 96*d9e36cbeSAdrian 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 4450cecf9d5Sandi if ( is_null($language) ) { 4463d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4470cecf9d5Sandi } else { 4483d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4493d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4503d491f75SAndreas Gohr 4513d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4520cecf9d5Sandi } 4533d491f75SAndreas Gohr 4543d491f75SAndreas Gohr if($filename){ 4553d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4563d491f75SAndreas Gohr } 4573d491f75SAndreas Gohr 4583d491f75SAndreas Gohr $this->_codeblock++; 4590cecf9d5Sandi } 4600cecf9d5Sandi 4610cecf9d5Sandi function acronym($acronym) { 4620cecf9d5Sandi 4630cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4640cecf9d5Sandi 465433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4660cecf9d5Sandi 467a2d649c4Sandi $this->doc .= '<acronym title="'.$title 468433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4690cecf9d5Sandi 4700cecf9d5Sandi } else { 471a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4720cecf9d5Sandi } 4730cecf9d5Sandi } 4740cecf9d5Sandi 4750cecf9d5Sandi function smiley($smiley) { 4760cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 477433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 478f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4794beabca9SAnika Henke '" class="middle" alt="'. 480433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4810cecf9d5Sandi } else { 482a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4830cecf9d5Sandi } 4840cecf9d5Sandi } 4850cecf9d5Sandi 486f62ea8a1Sandi /* 4874de671bcSandi * not used 4880cecf9d5Sandi function wordblock($word) { 4890cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 490a2d649c4Sandi $this->doc .= '** BLEEP **'; 4910cecf9d5Sandi } else { 492a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4930cecf9d5Sandi } 4940cecf9d5Sandi } 4954de671bcSandi */ 4960cecf9d5Sandi 4970cecf9d5Sandi function entity($entity) { 4980cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 499a2d649c4Sandi $this->doc .= $this->entities[$entity]; 5000cecf9d5Sandi } else { 501a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 5020cecf9d5Sandi } 5030cecf9d5Sandi } 5040cecf9d5Sandi 5050cecf9d5Sandi function multiplyentity($x, $y) { 506a2d649c4Sandi $this->doc .= "$x×$y"; 5070cecf9d5Sandi } 5080cecf9d5Sandi 5090cecf9d5Sandi function singlequoteopening() { 51071b40da2SAnika Henke global $lang; 51171b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 5120cecf9d5Sandi } 5130cecf9d5Sandi 5140cecf9d5Sandi function singlequoteclosing() { 51571b40da2SAnika Henke global $lang; 51671b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 5170cecf9d5Sandi } 5180cecf9d5Sandi 51957d757d1SAndreas Gohr function apostrophe() { 52057d757d1SAndreas Gohr global $lang; 521a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 52257d757d1SAndreas Gohr } 52357d757d1SAndreas Gohr 5240cecf9d5Sandi function doublequoteopening() { 52571b40da2SAnika Henke global $lang; 52671b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 5270cecf9d5Sandi } 5280cecf9d5Sandi 5290cecf9d5Sandi function doublequoteclosing() { 53071b40da2SAnika Henke global $lang; 53171b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 5320cecf9d5Sandi } 5330cecf9d5Sandi 5340cecf9d5Sandi /** 5350cecf9d5Sandi */ 5360cecf9d5Sandi function camelcaselink($link) { 53711d0aa47Sandi $this->internallink($link,$link); 5380cecf9d5Sandi } 5390cecf9d5Sandi 5400b7c14c2Sandi 5410b7c14c2Sandi function locallink($hash, $name = NULL){ 5420b7c14c2Sandi global $ID; 5430b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5440b7c14c2Sandi $hash = $this->_headerToLink($hash); 5450b7c14c2Sandi $title = $ID.' ↵'; 5460b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5470b7c14c2Sandi $this->doc .= $name; 5480b7c14c2Sandi $this->doc .= '</a>'; 5490b7c14c2Sandi } 5500b7c14c2Sandi 551cffcc403Sandi /** 5523fd0b676Sandi * Render an internal Wiki Link 5533fd0b676Sandi * 554fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 555cffcc403Sandi * elsewhere - no need to implement them in other renderers 5563fd0b676Sandi * 5573fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 558cffcc403Sandi */ 559fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 560ba11bd29Sandi global $conf; 56137e34a5eSandi global $ID; 5620339c872Sjan // default name is based on $id as given 5630339c872Sjan $default = $this->_simpleTitle($id); 564ad32e47eSAndreas Gohr 5650339c872Sjan // now first resolve and clean up the $id 56637e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 567fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5680e1c636eSandi if ( !$isImage ) { 5690e1c636eSandi if ( $exists ) { 570ba11bd29Sandi $class='wikilink1'; 5710cecf9d5Sandi } else { 572ba11bd29Sandi $class='wikilink2'; 57344a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5740cecf9d5Sandi } 5750cecf9d5Sandi } else { 576ba11bd29Sandi $class='media'; 5770cecf9d5Sandi } 5780cecf9d5Sandi 579a1685bedSandi //keep hash anchor 580ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 581943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 582a1685bedSandi 583ba11bd29Sandi //prepare for formating 584ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 585ba11bd29Sandi $link['style'] = ''; 586ba11bd29Sandi $link['pre'] = ''; 587ba11bd29Sandi $link['suf'] = ''; 58840eb54bbSjan // highlight link to current page 58940eb54bbSjan if ($id == $ID) { 59092795d04Sandi $link['pre'] = '<span class="curid">'; 59192795d04Sandi $link['suf'] = '</span>'; 59240eb54bbSjan } 5935e163278SAndreas Gohr $link['more'] = ''; 594ba11bd29Sandi $link['class'] = $class; 595ba11bd29Sandi $link['url'] = wl($id); 596ba11bd29Sandi $link['name'] = $name; 597ba11bd29Sandi $link['title'] = $id; 598723d78dbSandi //add search string 599723d78dbSandi if($search){ 600546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 601546d3a99SAndreas Gohr if(is_array($search)){ 602546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 603546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 604546d3a99SAndreas Gohr }else{ 605546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 606546d3a99SAndreas Gohr } 607723d78dbSandi } 608723d78dbSandi 609a1685bedSandi //keep hash 610a1685bedSandi if($hash) $link['url'].='#'.$hash; 611a1685bedSandi 612ba11bd29Sandi //output formatted 613cffcc403Sandi if($returnonly){ 614cffcc403Sandi return $this->_formatLink($link); 615cffcc403Sandi }else{ 616a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6170cecf9d5Sandi } 618cffcc403Sandi } 6190cecf9d5Sandi 620b625487dSandi function externallink($url, $name = NULL) { 621b625487dSandi global $conf; 6220cecf9d5Sandi 623433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 6246f0c5dbfSandi 6250cecf9d5Sandi if ( !$isImage ) { 626b625487dSandi $class='urlextern'; 6270cecf9d5Sandi } else { 628b625487dSandi $class='media'; 6290cecf9d5Sandi } 6300cecf9d5Sandi 631b625487dSandi //prepare for formating 632b625487dSandi $link['target'] = $conf['target']['extern']; 633b625487dSandi $link['style'] = ''; 634b625487dSandi $link['pre'] = ''; 635b625487dSandi $link['suf'] = ''; 6365e163278SAndreas Gohr $link['more'] = ''; 637b625487dSandi $link['class'] = $class; 638b625487dSandi $link['url'] = $url; 639e1c10e4dSchris 640b625487dSandi $link['name'] = $name; 641433bef32Sandi $link['title'] = $this->_xmlEntities($url); 642b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6430cecf9d5Sandi 644b625487dSandi //output formatted 645a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6460cecf9d5Sandi } 6470cecf9d5Sandi 6480cecf9d5Sandi /** 6490cecf9d5Sandi */ 65097a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 651b625487dSandi global $conf; 6520cecf9d5Sandi 65397a3e4e3Sandi $link = array(); 65497a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 65597a3e4e3Sandi $link['pre'] = ''; 65697a3e4e3Sandi $link['suf'] = ''; 6575e163278SAndreas Gohr $link['more'] = ''; 658433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6590cecf9d5Sandi 66097a3e4e3Sandi //get interwiki URL 6611f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6620cecf9d5Sandi 66397a3e4e3Sandi if ( !$isImage ) { 6649d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6659d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6661c2d1019SAndreas Gohr } else { 6671c2d1019SAndreas Gohr $link['class'] = 'media'; 66897a3e4e3Sandi } 6690cecf9d5Sandi 67097a3e4e3Sandi //do we stay at the same server? Use local target 67197a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 67297a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 67397a3e4e3Sandi } 6740cecf9d5Sandi 67597a3e4e3Sandi $link['url'] = $url; 67697a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 67797a3e4e3Sandi 67897a3e4e3Sandi //output formatted 679a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6800cecf9d5Sandi } 6810cecf9d5Sandi 6820cecf9d5Sandi /** 6830cecf9d5Sandi */ 6841d47afe1Sandi function windowssharelink($url, $name = NULL) { 6851d47afe1Sandi global $conf; 6861d47afe1Sandi global $lang; 6871d47afe1Sandi //simple setup 6881d47afe1Sandi $link['target'] = $conf['target']['windows']; 6891d47afe1Sandi $link['pre'] = ''; 6901d47afe1Sandi $link['suf'] = ''; 6911d47afe1Sandi $link['style'] = ''; 6920cecf9d5Sandi 693433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6940cecf9d5Sandi if ( !$isImage ) { 6951d47afe1Sandi $link['class'] = 'windows'; 6960cecf9d5Sandi } else { 6971d47afe1Sandi $link['class'] = 'media'; 6980cecf9d5Sandi } 6990cecf9d5Sandi 7000cecf9d5Sandi 701433bef32Sandi $link['title'] = $this->_xmlEntities($url); 7021d47afe1Sandi $url = str_replace('\\','/',$url); 7031d47afe1Sandi $url = 'file:///'.$url; 7041d47afe1Sandi $link['url'] = $url; 7050cecf9d5Sandi 7061d47afe1Sandi //output formatted 707a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7080cecf9d5Sandi } 7090cecf9d5Sandi 71071352defSandi function emaillink($address, $name = NULL) { 71171352defSandi global $conf; 71271352defSandi //simple setup 71371352defSandi $link = array(); 71471352defSandi $link['target'] = ''; 71571352defSandi $link['pre'] = ''; 71671352defSandi $link['suf'] = ''; 71771352defSandi $link['style'] = ''; 71871352defSandi $link['more'] = ''; 7190cecf9d5Sandi 720c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7210cecf9d5Sandi if ( !$isImage ) { 722776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 7230cecf9d5Sandi } else { 724776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 7250cecf9d5Sandi } 7260cecf9d5Sandi 72707738714SAndreas Gohr $address = $this->_xmlEntities($address); 72800a7b5adSEsther Brunner $address = obfuscate($address); 72900a7b5adSEsther Brunner $title = $address; 7308c128049SAndreas Gohr 73171352defSandi if(empty($name)){ 73200a7b5adSEsther Brunner $name = $address; 73371352defSandi } 7340cecf9d5Sandi 735776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 736776b36ecSAndreas Gohr 737776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 73871352defSandi $link['name'] = $name; 73971352defSandi $link['title'] = $title; 7400cecf9d5Sandi 74171352defSandi //output formatted 742a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7430cecf9d5Sandi } 7440cecf9d5Sandi 7454826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 746dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 74737e34a5eSandi global $ID; 74891df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 74937e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7500cecf9d5Sandi 751d98d4540SBen Coburn $noLink = false; 7528acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 753b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7543685f775Sandi 75527bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 756b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 757dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7581c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7592ca14335SEsther Brunner // don't link flash movies 76044881bd0Shenning.noren $noLink = true; 76155efc227SAndreas Gohr }else{ 7622ca14335SEsther Brunner // add file icons 7639d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7649d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7656de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 76655efc227SAndreas Gohr } 7673685f775Sandi 76891df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 76991df343aSAndreas Gohr 7706fe20453SGina Haeussge //markup non existing files 7716fe20453SGina Haeussge if (!$exists) 7726fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7736fe20453SGina Haeussge 7743685f775Sandi //output formatted 775dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7762ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7770cecf9d5Sandi } 7780cecf9d5Sandi 7794826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 780dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 78191df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 782d98d4540SBen Coburn $noLink = false; 7838acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 784b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 785b739ff0fSPierre Spring 786b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7873685f775Sandi 78827bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 789b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7902ca14335SEsther Brunner // link only jpeg images 79144881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7921c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7932ca14335SEsther Brunner // don't link flash movies 79444881bd0Shenning.noren $noLink = true; 7952ca14335SEsther Brunner }else{ 7962ca14335SEsther Brunner // add file icons 79727bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 79827bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 7992ca14335SEsther Brunner } 8002ca14335SEsther Brunner 80191df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 80291df343aSAndreas Gohr 8033685f775Sandi //output formatted 804dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8052ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8060cecf9d5Sandi } 8070cecf9d5Sandi 8084826ab45Sandi /** 8093db95becSAndreas Gohr * Renders an RSS feed 810b625487dSandi * 811b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 812b625487dSandi */ 8133db95becSAndreas Gohr function rss ($url,$params){ 814b625487dSandi global $lang; 8153db95becSAndreas Gohr global $conf; 8163db95becSAndreas Gohr 8173db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8183db95becSAndreas Gohr $feed = new FeedParser(); 81900077af8SAndreas Gohr $feed->set_feed_url($url); 820b625487dSandi 821b625487dSandi //disable warning while fetching 822bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8233db95becSAndreas Gohr $rc = $feed->init(); 824bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 825b625487dSandi 8263db95becSAndreas Gohr //decide on start and end 8273db95becSAndreas Gohr if($params['reverse']){ 8283db95becSAndreas Gohr $mod = -1; 8293db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8303db95becSAndreas Gohr $end = $start - ($params['max']); 831b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8323db95becSAndreas Gohr }else{ 8333db95becSAndreas Gohr $mod = 1; 8343db95becSAndreas Gohr $start = 0; 8353db95becSAndreas Gohr $end = $feed->get_item_quantity(); 8363db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 8373db95becSAndreas Gohr } 8383db95becSAndreas Gohr 839a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8403db95becSAndreas Gohr if($rc){ 8413db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8421bde1582SAndreas Gohr $item = $feed->get_item($x); 8433db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 844d2ea3363SAndreas Gohr // support feeds without links 845d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 846d2ea3363SAndreas Gohr if($lnkurl){ 847793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 848793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8491bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 850793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 851d2ea3363SAndreas Gohr }else{ 852d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 853d2ea3363SAndreas Gohr } 8543db95becSAndreas Gohr if($params['author']){ 8551bde1582SAndreas Gohr $author = $item->get_author(0); 8561bde1582SAndreas Gohr if($author){ 8571bde1582SAndreas Gohr $name = $author->get_name(); 8581bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8591bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8601bde1582SAndreas Gohr } 8613db95becSAndreas Gohr } 8623db95becSAndreas Gohr if($params['date']){ 8632e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8643db95becSAndreas Gohr } 8651bde1582SAndreas Gohr if($params['details']){ 8663db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 867173dccb7STom N Harris if($conf['htmlok']){ 8681bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8693db95becSAndreas Gohr }else{ 8701bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8713db95becSAndreas Gohr } 8723db95becSAndreas Gohr $this->doc .= '</div>'; 8733db95becSAndreas Gohr } 8743db95becSAndreas Gohr 8753db95becSAndreas Gohr $this->doc .= '</div></li>'; 876b625487dSandi } 877b625487dSandi }else{ 8783db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 879a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 880b625487dSandi $this->externallink($url); 88145e147ccSAndreas Gohr if($conf['allowdebug']){ 88245e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 88345e147ccSAndreas Gohr } 8843db95becSAndreas Gohr $this->doc .= '</div></li>'; 885b625487dSandi } 886a2d649c4Sandi $this->doc .= '</ul>'; 887b625487dSandi } 888b625487dSandi 8890cecf9d5Sandi // $numrows not yet implemented 89090df9a4dSAdrian Lang function table_open($maxcols = NULL, $numrows = NULL, $pos){ 89190df9a4dSAdrian Lang global $lang; 892b5742cedSPierre Spring // initialize the row counter used for classes 893b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 89440868f2fSAdrian Lang $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table') . '">'.DOKU_LF; 8950cecf9d5Sandi } 8960cecf9d5Sandi 89790df9a4dSAdrian Lang function table_close($pos){ 89859869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 89990df9a4dSAdrian Lang $this->finishSectionEdit($pos); 9000cecf9d5Sandi } 9010cecf9d5Sandi 9020cecf9d5Sandi function tablerow_open(){ 903b5742cedSPierre Spring // initialize the cell counter used for classes 904b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 905b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 906b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9070cecf9d5Sandi } 9080cecf9d5Sandi 9090cecf9d5Sandi function tablerow_close(){ 910a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9110cecf9d5Sandi } 9120cecf9d5Sandi 91325b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 914b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9150cecf9d5Sandi if ( !is_null($align) ) { 916b5742cedSPierre Spring $class .= ' '.$align.'align'; 9170cecf9d5Sandi } 918b5742cedSPierre Spring $class .= '"'; 919b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9200cecf9d5Sandi if ( $colspan > 1 ) { 921a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 922a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9230cecf9d5Sandi } 92425b97867Shakan.sandell if ( $rowspan > 1 ) { 92525b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 92625b97867Shakan.sandell } 927a2d649c4Sandi $this->doc .= '>'; 9280cecf9d5Sandi } 9290cecf9d5Sandi 9300cecf9d5Sandi function tableheader_close(){ 931a2d649c4Sandi $this->doc .= '</th>'; 9320cecf9d5Sandi } 9330cecf9d5Sandi 93425b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ 935b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9360cecf9d5Sandi if ( !is_null($align) ) { 937b5742cedSPierre Spring $class .= ' '.$align.'align'; 9380cecf9d5Sandi } 939b5742cedSPierre Spring $class .= '"'; 940b5742cedSPierre Spring $this->doc .= '<td '.$class; 9410cecf9d5Sandi if ( $colspan > 1 ) { 942a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 943a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9440cecf9d5Sandi } 94525b97867Shakan.sandell if ( $rowspan > 1 ) { 94625b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 94725b97867Shakan.sandell } 948a2d649c4Sandi $this->doc .= '>'; 9490cecf9d5Sandi } 9500cecf9d5Sandi 9510cecf9d5Sandi function tablecell_close(){ 952a2d649c4Sandi $this->doc .= '</td>'; 9530cecf9d5Sandi } 9540cecf9d5Sandi 9550cecf9d5Sandi //---------------------------------------------------------- 9560cecf9d5Sandi // Utils 9570cecf9d5Sandi 958ba11bd29Sandi /** 9593fd0b676Sandi * Build a link 9603fd0b676Sandi * 9613fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 962ba11bd29Sandi * 963ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 964ba11bd29Sandi */ 965433bef32Sandi function _formatLink($link){ 966ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 967ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 968ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 969ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 970ba11bd29Sandi } 971ba11bd29Sandi //remove double encodings in titles 972ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 973ba11bd29Sandi 974453493f2SAndreas Gohr // be sure there are no bad chars in url or title 975453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 976453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 977453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 978453493f2SAndreas Gohr 979ba11bd29Sandi $ret = ''; 980ba11bd29Sandi $ret .= $link['pre']; 981ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 982bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 983bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 984bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 985bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 98644a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 987bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 988ba11bd29Sandi $ret .= '>'; 989ba11bd29Sandi $ret .= $link['name']; 990ba11bd29Sandi $ret .= '</a>'; 991ba11bd29Sandi $ret .= $link['suf']; 992ba11bd29Sandi return $ret; 993ba11bd29Sandi } 994ba11bd29Sandi 995ba11bd29Sandi /** 9963fd0b676Sandi * Renders internal and external media 9973fd0b676Sandi * 9983fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9993fd0b676Sandi */ 10003fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 1001b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 10023fd0b676Sandi 10033fd0b676Sandi $ret = ''; 10043fd0b676Sandi 1005ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10063fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1007b739ff0fSPierre Spring // first get the $title 1008b739ff0fSPierre Spring if (!is_null($title)) { 1009b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1010b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1011b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1012b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 101367f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1014b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1015b739ff0fSPierre Spring if($cap){ 1016b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1017b739ff0fSPierre Spring } 1018b739ff0fSPierre Spring } 1019b739ff0fSPierre Spring if (!$render) { 1020b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1021b739ff0fSPierre Spring // return the title of the picture 1022b739ff0fSPierre Spring if (!$title) { 1023b739ff0fSPierre Spring // just show the sourcename 1024b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1025b739ff0fSPierre Spring } 1026b739ff0fSPierre Spring return $title; 1027b739ff0fSPierre Spring } 10283fd0b676Sandi //add image tag 10296de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10303fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10313fd0b676Sandi 10324ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10334ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10344ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10354ab889eaSAndreas Gohr 1036b739ff0fSPierre Spring if ($title) { 1037b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1038b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10393fd0b676Sandi }else{ 10403fd0b676Sandi $ret .= ' alt=""'; 10413fd0b676Sandi } 10423fd0b676Sandi 10433fd0b676Sandi if ( !is_null($width) ) 10443fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10453fd0b676Sandi 10463fd0b676Sandi if ( !is_null($height) ) 10473fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10483fd0b676Sandi 10493fd0b676Sandi $ret .= ' />'; 10503fd0b676Sandi 10513fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10521c882ba8SAndreas Gohr if (!$render) { 10531c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10541c882ba8SAndreas Gohr // return the title of the flash 10551c882ba8SAndreas Gohr if (!$title) { 10561c882ba8SAndreas Gohr // just show the sourcename 105707bf32b2SAndreas Gohr $title = basename(noNS($src)); 10581c882ba8SAndreas Gohr } 105907bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10601c882ba8SAndreas Gohr } 10611c882ba8SAndreas Gohr 106207bf32b2SAndreas Gohr $att = array(); 106307bf32b2SAndreas Gohr $att['class'] = "media$align"; 106407bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 106507bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1066c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 106707bf32b2SAndreas Gohr array('quality' => 'high'), 106807bf32b2SAndreas Gohr null, 106907bf32b2SAndreas Gohr $att, 107007bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10710f428d7dSAndreas Gohr }elseif($title){ 10723fd0b676Sandi // well at least we have a title to display 10733fd0b676Sandi $ret .= $this->_xmlEntities($title); 10743fd0b676Sandi }else{ 10755291ca3aSAndreas Gohr // just show the sourcename 10760f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10773fd0b676Sandi } 10783fd0b676Sandi 10793fd0b676Sandi return $ret; 10803fd0b676Sandi } 10813fd0b676Sandi 1082433bef32Sandi function _xmlEntities($string) { 1083de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10840cecf9d5Sandi } 10850cecf9d5Sandi 10868a831f2bSAndreas Gohr /** 10878a831f2bSAndreas Gohr * Creates a linkid from a headline 1088c5a8fd96SAndreas Gohr * 1089c5a8fd96SAndreas Gohr * @param string $title The headline title 1090c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1091c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10928a831f2bSAndreas Gohr */ 1093c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1094c5a8fd96SAndreas Gohr if($create){ 10954ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10964ceab83fSAndreas Gohr }else{ 1097443d207bSAndreas Gohr $check = false; 1098443d207bSAndreas Gohr return sectionID($title,$check); 1099c5a8fd96SAndreas Gohr } 11000cecf9d5Sandi } 11010cecf9d5Sandi 1102af587fa8Sandi /** 11033fd0b676Sandi * Construct a title and handle images in titles 11043fd0b676Sandi * 11050b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11063fd0b676Sandi */ 1107fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1108bb0a59d4Sjan global $conf; 1109bb0a59d4Sjan 111044881bd0Shenning.noren $isImage = false; 111129657f9eSAndreas Gohr if ( is_array($title) ) { 111229657f9eSAndreas Gohr $isImage = true; 111329657f9eSAndreas Gohr return $this->_imageTitle($title); 111429657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1115fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1116fc18c0fbSchris $heading = p_get_first_heading($id,true); 1117bb0a59d4Sjan if ($heading) { 1118433bef32Sandi return $this->_xmlEntities($heading); 1119bb0a59d4Sjan } 1120bb0a59d4Sjan } 1121433bef32Sandi return $this->_xmlEntities($default); 112268c26e6dSMichael Klier } else { 112368c26e6dSMichael Klier return $this->_xmlEntities($title); 11240cecf9d5Sandi } 11250cecf9d5Sandi } 11260cecf9d5Sandi 11270cecf9d5Sandi /** 11283fd0b676Sandi * Returns an HTML code for images used in link titles 11293fd0b676Sandi * 11303fd0b676Sandi * @todo Resolve namespace on internal images 11313fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11320cecf9d5Sandi */ 1133433bef32Sandi function _imageTitle($img) { 1134d9baf1a7SKazutaka Miyasaka global $ID; 1135d9baf1a7SKazutaka Miyasaka 1136d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1137d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1138d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1139d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1140d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1141d9baf1a7SKazutaka Miyasaka } 1142d9baf1a7SKazutaka Miyasaka 1143433bef32Sandi return $this->_media($img['src'], 11444826ab45Sandi $img['title'], 11454826ab45Sandi $img['align'], 11464826ab45Sandi $img['width'], 11474826ab45Sandi $img['height'], 11484826ab45Sandi $img['cache']); 11490cecf9d5Sandi } 1150b739ff0fSPierre Spring 1151b739ff0fSPierre Spring /** 1152b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1153b739ff0fSPierre Spring * which returns a basic link to a media. 1154b739ff0fSPierre Spring * 1155b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1156b739ff0fSPierre Spring * @param string $src 1157b739ff0fSPierre Spring * @param string $title 1158b739ff0fSPierre Spring * @param string $align 1159b739ff0fSPierre Spring * @param string $width 1160b739ff0fSPierre Spring * @param string $height 1161b739ff0fSPierre Spring * @param string $cache 1162b739ff0fSPierre Spring * @param string $render 1163b739ff0fSPierre Spring * @access protected 1164b739ff0fSPierre Spring * @return array 1165b739ff0fSPierre Spring */ 1166b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1167b739ff0fSPierre Spring { 1168b739ff0fSPierre Spring global $conf; 1169b739ff0fSPierre Spring 1170b739ff0fSPierre Spring $link = array(); 1171b739ff0fSPierre Spring $link['class'] = 'media'; 1172b739ff0fSPierre Spring $link['style'] = ''; 1173b739ff0fSPierre Spring $link['pre'] = ''; 1174b739ff0fSPierre Spring $link['suf'] = ''; 1175b739ff0fSPierre Spring $link['more'] = ''; 1176b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1177b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1178b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1179b739ff0fSPierre Spring 1180b739ff0fSPierre Spring return $link; 1181b739ff0fSPierre Spring } 118291459163SAnika Henke 118391459163SAnika Henke 11840cecf9d5Sandi} 11850cecf9d5Sandi 11864826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1187