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 32*90df9a4dSAdrian 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 43*90df9a4dSAdrian Lang /** 44*90df9a4dSAdrian Lang * Register a new edit section range 45*90df9a4dSAdrian Lang * 46*90df9a4dSAdrian Lang * @param $type string The section type identifier 47*90df9a4dSAdrian Lang * @param $title string The section title 48*90df9a4dSAdrian Lang * @param $start int The byte position for the edit start 49*90df9a4dSAdrian Lang * @return string A marker class for the starting HTML element 50*90df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 51*90df9a4dSAdrian Lang */ 52*90df9a4dSAdrian Lang protected function startSectionEdit($start, $type, $title) { 53*90df9a4dSAdrian Lang static $lastsecid = 0; 54*90df9a4dSAdrian Lang $this->sectionedits[] = array(++$lastsecid, $start, $type, $title); 55*90df9a4dSAdrian Lang return 'sectionedit' . $lastsecid; 56*90df9a4dSAdrian Lang } 57*90df9a4dSAdrian Lang 58*90df9a4dSAdrian Lang /** 59*90df9a4dSAdrian Lang * Finish an edit section range 60*90df9a4dSAdrian Lang * 61*90df9a4dSAdrian Lang * @param $pos int The byte position for the edit end 62*90df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 63*90df9a4dSAdrian Lang */ 64*90df9a4dSAdrian Lang protected function finishSectionEdit($end) { 65*90df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 66*90df9a4dSAdrian Lang $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' "' . 67*90df9a4dSAdrian Lang str_replace('"', '', $title) . "\" [$start-" . 68*90df9a4dSAdrian Lang ($end === 0 ? '' : $end) . "] -->"; 69*90df9a4dSAdrian Lang } 70*90df9a4dSAdrian Lang 715f70445dSAndreas Gohr function getFormat(){ 725f70445dSAndreas Gohr return 'xhtml'; 735f70445dSAndreas Gohr } 745f70445dSAndreas Gohr 755f70445dSAndreas Gohr 760cecf9d5Sandi function document_start() { 77c5a8fd96SAndreas Gohr //reset some internals 78c5a8fd96SAndreas Gohr $this->toc = array(); 79c5a8fd96SAndreas Gohr $this->headers = array(); 800cecf9d5Sandi } 810cecf9d5Sandi 820cecf9d5Sandi function document_end() { 83*90df9a4dSAdrian Lang // Finish open section edits. 84*90df9a4dSAdrian Lang while (count($this->sectionedits) > 0) { 85*90df9a4dSAdrian Lang if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 86*90df9a4dSAdrian Lang // If there is only one section, do not write a section edit 87*90df9a4dSAdrian Lang // marker. 88*90df9a4dSAdrian Lang array_pop($this->sectionedits); 89*90df9a4dSAdrian Lang } else { 90*90df9a4dSAdrian Lang $this->finishSectionEdit(0); 91*90df9a4dSAdrian Lang } 92*90df9a4dSAdrian Lang } 93*90df9a4dSAdrian Lang 940cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 95a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 96d74aace9Schris 97d74aace9Schris $id = 0; 980cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 99d74aace9Schris $id++; // the number of the current footnote 100d74aace9Schris 101d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 102d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 103d74aace9Schris 104d74aace9Schris // open the footnote and set the anchor and backlink 105d74aace9Schris $this->doc .= '<div class="fn">'; 10629bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 10729bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 108d74aace9Schris 109d74aace9Schris // get any other footnotes that use the same markup 110d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 111d74aace9Schris 112d74aace9Schris if (count($alt)) { 113d74aace9Schris foreach ($alt as $ref) { 114d74aace9Schris // set anchor and backlink for the other footnotes 11529bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 11629bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 117d74aace9Schris } 118d74aace9Schris } 119d74aace9Schris 120d74aace9Schris // add footnote markup and close this footnote 121a2d649c4Sandi $this->doc .= $footnote; 122d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 123d74aace9Schris } 1240cecf9d5Sandi } 125a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 1260cecf9d5Sandi } 127c5a8fd96SAndreas Gohr 128b8595a66SAndreas Gohr // Prepare the TOC 129851f2e89SAnika Henke global $conf; 130851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 131b8595a66SAndreas Gohr global $TOC; 132b8595a66SAndreas Gohr $TOC = $this->toc; 1330cecf9d5Sandi } 1343e55d035SAndreas Gohr 1353e55d035SAndreas Gohr // make sure there are no empty paragraphs 13627918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 137e41c4da9SAndreas Gohr } 1380cecf9d5Sandi 139e7856beaSchris function toc_additem($id, $text, $level) { 140af587fa8Sandi global $conf; 141af587fa8Sandi 142c5a8fd96SAndreas Gohr //handle TOC 143c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1447d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 145c5a8fd96SAndreas Gohr } 146e7856beaSchris } 147e7856beaSchris 148e7856beaSchris function header($text, $level, $pos) { 149*90df9a4dSAdrian Lang global $conf; 150*90df9a4dSAdrian Lang 151bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 152e7856beaSchris 153e7856beaSchris $hid = $this->_headerToLink($text,true); 154e7856beaSchris 155e7856beaSchris //only add items within configured levels 156e7856beaSchris $this->toc_additem($hid, $text, $level); 157c5a8fd96SAndreas Gohr 15891459163SAnika Henke // adjust $node to reflect hierarchy of levels 15991459163SAnika Henke $this->node[$level-1]++; 16091459163SAnika Henke if ($level < $this->lastlevel) { 16191459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 16291459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 16391459163SAnika Henke } 16491459163SAnika Henke } 16591459163SAnika Henke $this->lastlevel = $level; 16691459163SAnika Henke 167*90df9a4dSAdrian Lang if ($level <= $conf['maxseclevel'] && 168*90df9a4dSAdrian Lang count($this->sectionedits) > 0 && 169*90df9a4dSAdrian Lang $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { 170*90df9a4dSAdrian Lang $this->finishSectionEdit($pos); 171*90df9a4dSAdrian Lang } 172*90df9a4dSAdrian Lang 173c5a8fd96SAndreas Gohr // write the header 174*90df9a4dSAdrian Lang $this->doc .= DOKU_LF.'<h'.$level; 175*90df9a4dSAdrian Lang if ($level <= $conf['maxseclevel']) { 176*90df9a4dSAdrian Lang $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; 177*90df9a4dSAdrian Lang } 178*90df9a4dSAdrian Lang $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">'; 179a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 18059869a4bSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1810cecf9d5Sandi } 1820cecf9d5Sandi 1830cecf9d5Sandi function section_open($level) { 184*90df9a4dSAdrian Lang $this->doc .= "<div class='level$level'>".DOKU_LF; 1850cecf9d5Sandi } 1860cecf9d5Sandi 1870cecf9d5Sandi function section_close() { 188a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1890cecf9d5Sandi } 1900cecf9d5Sandi 1910cecf9d5Sandi function cdata($text) { 192a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1930cecf9d5Sandi } 1940cecf9d5Sandi 1950cecf9d5Sandi function p_open() { 19659869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1970cecf9d5Sandi } 1980cecf9d5Sandi 1990cecf9d5Sandi function p_close() { 20059869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 2010cecf9d5Sandi } 2020cecf9d5Sandi 2030cecf9d5Sandi function linebreak() { 204a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 2050cecf9d5Sandi } 2060cecf9d5Sandi 2070cecf9d5Sandi function hr() { 2084beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 2090cecf9d5Sandi } 2100cecf9d5Sandi 2110cecf9d5Sandi function strong_open() { 212a2d649c4Sandi $this->doc .= '<strong>'; 2130cecf9d5Sandi } 2140cecf9d5Sandi 2150cecf9d5Sandi function strong_close() { 216a2d649c4Sandi $this->doc .= '</strong>'; 2170cecf9d5Sandi } 2180cecf9d5Sandi 2190cecf9d5Sandi function emphasis_open() { 220a2d649c4Sandi $this->doc .= '<em>'; 2210cecf9d5Sandi } 2220cecf9d5Sandi 2230cecf9d5Sandi function emphasis_close() { 224a2d649c4Sandi $this->doc .= '</em>'; 2250cecf9d5Sandi } 2260cecf9d5Sandi 2270cecf9d5Sandi function underline_open() { 22802e51121SAnika Henke $this->doc .= '<em class="u">'; 2290cecf9d5Sandi } 2300cecf9d5Sandi 2310cecf9d5Sandi function underline_close() { 23202e51121SAnika Henke $this->doc .= '</em>'; 2330cecf9d5Sandi } 2340cecf9d5Sandi 2350cecf9d5Sandi function monospace_open() { 236a2d649c4Sandi $this->doc .= '<code>'; 2370cecf9d5Sandi } 2380cecf9d5Sandi 2390cecf9d5Sandi function monospace_close() { 240a2d649c4Sandi $this->doc .= '</code>'; 2410cecf9d5Sandi } 2420cecf9d5Sandi 2430cecf9d5Sandi function subscript_open() { 244a2d649c4Sandi $this->doc .= '<sub>'; 2450cecf9d5Sandi } 2460cecf9d5Sandi 2470cecf9d5Sandi function subscript_close() { 248a2d649c4Sandi $this->doc .= '</sub>'; 2490cecf9d5Sandi } 2500cecf9d5Sandi 2510cecf9d5Sandi function superscript_open() { 252a2d649c4Sandi $this->doc .= '<sup>'; 2530cecf9d5Sandi } 2540cecf9d5Sandi 2550cecf9d5Sandi function superscript_close() { 256a2d649c4Sandi $this->doc .= '</sup>'; 2570cecf9d5Sandi } 2580cecf9d5Sandi 2590cecf9d5Sandi function deleted_open() { 260a2d649c4Sandi $this->doc .= '<del>'; 2610cecf9d5Sandi } 2620cecf9d5Sandi 2630cecf9d5Sandi function deleted_close() { 264a2d649c4Sandi $this->doc .= '</del>'; 2650cecf9d5Sandi } 2660cecf9d5Sandi 2673fd0b676Sandi /** 2683fd0b676Sandi * Callback for footnote start syntax 2693fd0b676Sandi * 2703fd0b676Sandi * All following content will go to the footnote instead of 271d74aace9Schris * the document. To achieve this the previous rendered content 2723fd0b676Sandi * is moved to $store and $doc is cleared 2733fd0b676Sandi * 2743fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2753fd0b676Sandi */ 2760cecf9d5Sandi function footnote_open() { 2777764a90aSandi 2787764a90aSandi // move current content to store and record footnote 2797764a90aSandi $this->store = $this->doc; 2807764a90aSandi $this->doc = ''; 2810cecf9d5Sandi } 2820cecf9d5Sandi 2833fd0b676Sandi /** 2843fd0b676Sandi * Callback for footnote end syntax 2853fd0b676Sandi * 2863fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2873fd0b676Sandi * content is restored from $store again 2883fd0b676Sandi * 2893fd0b676Sandi * @author Andreas Gohr 2903fd0b676Sandi */ 2910cecf9d5Sandi function footnote_close() { 2927764a90aSandi 293d74aace9Schris // recover footnote into the stack and restore old content 294d74aace9Schris $footnote = $this->doc; 2957764a90aSandi $this->doc = $this->store; 2967764a90aSandi $this->store = ''; 297d74aace9Schris 298d74aace9Schris // check to see if this footnote has been seen before 299d74aace9Schris $i = array_search($footnote, $this->footnotes); 300d74aace9Schris 301d74aace9Schris if ($i === false) { 302d74aace9Schris // its a new footnote, add it to the $footnotes array 303d74aace9Schris $id = count($this->footnotes)+1; 304d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 305d74aace9Schris } else { 306d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 307d74aace9Schris $i++; 308d74aace9Schris $id = count($this->footnotes)+1; 309d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 310d74aace9Schris } 311d74aace9Schris 3126b379cbfSAndreas Gohr // output the footnote reference and link 31329bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 3140cecf9d5Sandi } 3150cecf9d5Sandi 3160cecf9d5Sandi function listu_open() { 317a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 3180cecf9d5Sandi } 3190cecf9d5Sandi 3200cecf9d5Sandi function listu_close() { 321a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3220cecf9d5Sandi } 3230cecf9d5Sandi 3240cecf9d5Sandi function listo_open() { 325a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3260cecf9d5Sandi } 3270cecf9d5Sandi 3280cecf9d5Sandi function listo_close() { 329a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3300cecf9d5Sandi } 3310cecf9d5Sandi 3320cecf9d5Sandi function listitem_open($level) { 33359869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 3340cecf9d5Sandi } 3350cecf9d5Sandi 3360cecf9d5Sandi function listitem_close() { 337a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3380cecf9d5Sandi } 3390cecf9d5Sandi 3400cecf9d5Sandi function listcontent_open() { 34190db23d7Schris $this->doc .= '<div class="li">'; 3420cecf9d5Sandi } 3430cecf9d5Sandi 3440cecf9d5Sandi function listcontent_close() { 34559869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3460cecf9d5Sandi } 3470cecf9d5Sandi 3480cecf9d5Sandi function unformatted($text) { 349a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3500cecf9d5Sandi } 3510cecf9d5Sandi 3520cecf9d5Sandi /** 3533fd0b676Sandi * Execute PHP code if allowed 3543fd0b676Sandi * 3555d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3565d568b99SChris Smith * 3573fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3580cecf9d5Sandi */ 3595d568b99SChris Smith function php($text, $wrapper='code') { 36035a56260SChris Smith global $conf; 36135a56260SChris Smith 362d86d5af0SChris Smith if($conf['phpok']){ 363bad0b545Sandi ob_start(); 3644de671bcSandi eval($text); 3653fd0b676Sandi $this->doc .= ob_get_contents(); 366bad0b545Sandi ob_end_clean(); 367d86d5af0SChris Smith } else { 3685d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 369d86d5af0SChris Smith } 3700cecf9d5Sandi } 3710cecf9d5Sandi 37207f89c3cSAnika Henke function phpblock($text) { 3735d568b99SChris Smith $this->php($text, 'pre'); 37407f89c3cSAnika Henke } 37507f89c3cSAnika Henke 3760cecf9d5Sandi /** 3773fd0b676Sandi * Insert HTML if allowed 3783fd0b676Sandi * 3795d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3805d568b99SChris Smith * 3813fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3820cecf9d5Sandi */ 3835d568b99SChris Smith function html($text, $wrapper='code') { 38435a56260SChris Smith global $conf; 38535a56260SChris Smith 386d86d5af0SChris Smith if($conf['htmlok']){ 387a2d649c4Sandi $this->doc .= $text; 388d86d5af0SChris Smith } else { 3895d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 390d86d5af0SChris Smith } 3914de671bcSandi } 3920cecf9d5Sandi 39307f89c3cSAnika Henke function htmlblock($text) { 3945d568b99SChris Smith $this->html($text, 'pre'); 39507f89c3cSAnika Henke } 39607f89c3cSAnika Henke 3970cecf9d5Sandi function quote_open() { 39896331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3990cecf9d5Sandi } 4000cecf9d5Sandi 4010cecf9d5Sandi function quote_close() { 40296331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 4030cecf9d5Sandi } 4040cecf9d5Sandi 4053d491f75SAndreas Gohr function preformatted($text) { 406c9250713SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 4073d491f75SAndreas Gohr } 4083d491f75SAndreas Gohr 4093d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 4103d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 4113d491f75SAndreas Gohr } 4123d491f75SAndreas Gohr 4133d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 4143d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 4153d491f75SAndreas Gohr } 4163d491f75SAndreas Gohr 4170cecf9d5Sandi /** 4183d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 4193fd0b676Sandi * 4203fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 4210cecf9d5Sandi */ 4223d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 4234de671bcSandi global $conf; 4243d491f75SAndreas Gohr global $ID; 4253d491f75SAndreas Gohr global $lang; 4263d491f75SAndreas Gohr 4273d491f75SAndreas Gohr if($filename){ 428190c56e8SAndreas Gohr // add icon 42927bf7924STom N Harris list($ext) = mimetype($filename,false); 430190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 431190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 432190c56e8SAndreas Gohr 4333d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 434190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 4353d491f75SAndreas Gohr $this->doc .= hsc($filename); 4363d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 4373d491f75SAndreas Gohr } 4380cecf9d5Sandi 4390cecf9d5Sandi if ( is_null($language) ) { 4403d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4410cecf9d5Sandi } else { 4423d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4433d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4443d491f75SAndreas Gohr 4453d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4460cecf9d5Sandi } 4473d491f75SAndreas Gohr 4483d491f75SAndreas Gohr if($filename){ 4493d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4503d491f75SAndreas Gohr } 4513d491f75SAndreas Gohr 4523d491f75SAndreas Gohr $this->_codeblock++; 4530cecf9d5Sandi } 4540cecf9d5Sandi 4550cecf9d5Sandi function acronym($acronym) { 4560cecf9d5Sandi 4570cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4580cecf9d5Sandi 459433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4600cecf9d5Sandi 461a2d649c4Sandi $this->doc .= '<acronym title="'.$title 462433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4630cecf9d5Sandi 4640cecf9d5Sandi } else { 465a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4660cecf9d5Sandi } 4670cecf9d5Sandi } 4680cecf9d5Sandi 4690cecf9d5Sandi function smiley($smiley) { 4700cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 471433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 472f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4734beabca9SAnika Henke '" class="middle" alt="'. 474433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4750cecf9d5Sandi } else { 476a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4770cecf9d5Sandi } 4780cecf9d5Sandi } 4790cecf9d5Sandi 480f62ea8a1Sandi /* 4814de671bcSandi * not used 4820cecf9d5Sandi function wordblock($word) { 4830cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 484a2d649c4Sandi $this->doc .= '** BLEEP **'; 4850cecf9d5Sandi } else { 486a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4870cecf9d5Sandi } 4880cecf9d5Sandi } 4894de671bcSandi */ 4900cecf9d5Sandi 4910cecf9d5Sandi function entity($entity) { 4920cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 493a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4940cecf9d5Sandi } else { 495a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4960cecf9d5Sandi } 4970cecf9d5Sandi } 4980cecf9d5Sandi 4990cecf9d5Sandi function multiplyentity($x, $y) { 500a2d649c4Sandi $this->doc .= "$x×$y"; 5010cecf9d5Sandi } 5020cecf9d5Sandi 5030cecf9d5Sandi function singlequoteopening() { 50471b40da2SAnika Henke global $lang; 50571b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 5060cecf9d5Sandi } 5070cecf9d5Sandi 5080cecf9d5Sandi function singlequoteclosing() { 50971b40da2SAnika Henke global $lang; 51071b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 5110cecf9d5Sandi } 5120cecf9d5Sandi 51357d757d1SAndreas Gohr function apostrophe() { 51457d757d1SAndreas Gohr global $lang; 515a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 51657d757d1SAndreas Gohr } 51757d757d1SAndreas Gohr 5180cecf9d5Sandi function doublequoteopening() { 51971b40da2SAnika Henke global $lang; 52071b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 5210cecf9d5Sandi } 5220cecf9d5Sandi 5230cecf9d5Sandi function doublequoteclosing() { 52471b40da2SAnika Henke global $lang; 52571b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 5260cecf9d5Sandi } 5270cecf9d5Sandi 5280cecf9d5Sandi /** 5290cecf9d5Sandi */ 5300cecf9d5Sandi function camelcaselink($link) { 53111d0aa47Sandi $this->internallink($link,$link); 5320cecf9d5Sandi } 5330cecf9d5Sandi 5340b7c14c2Sandi 5350b7c14c2Sandi function locallink($hash, $name = NULL){ 5360b7c14c2Sandi global $ID; 5370b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5380b7c14c2Sandi $hash = $this->_headerToLink($hash); 5390b7c14c2Sandi $title = $ID.' ↵'; 5400b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5410b7c14c2Sandi $this->doc .= $name; 5420b7c14c2Sandi $this->doc .= '</a>'; 5430b7c14c2Sandi } 5440b7c14c2Sandi 545cffcc403Sandi /** 5463fd0b676Sandi * Render an internal Wiki Link 5473fd0b676Sandi * 548fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 549cffcc403Sandi * elsewhere - no need to implement them in other renderers 5503fd0b676Sandi * 5513fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 552cffcc403Sandi */ 553fe9ec250SChris Smith function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') { 554ba11bd29Sandi global $conf; 55537e34a5eSandi global $ID; 5560339c872Sjan // default name is based on $id as given 5570339c872Sjan $default = $this->_simpleTitle($id); 558ad32e47eSAndreas Gohr 5590339c872Sjan // now first resolve and clean up the $id 56037e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 561fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5620e1c636eSandi if ( !$isImage ) { 5630e1c636eSandi if ( $exists ) { 564ba11bd29Sandi $class='wikilink1'; 5650cecf9d5Sandi } else { 566ba11bd29Sandi $class='wikilink2'; 56744a6b4c7SAndreas Gohr $link['rel']='nofollow'; 5680cecf9d5Sandi } 5690cecf9d5Sandi } else { 570ba11bd29Sandi $class='media'; 5710cecf9d5Sandi } 5720cecf9d5Sandi 573a1685bedSandi //keep hash anchor 574ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 575943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 576a1685bedSandi 577ba11bd29Sandi //prepare for formating 578ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 579ba11bd29Sandi $link['style'] = ''; 580ba11bd29Sandi $link['pre'] = ''; 581ba11bd29Sandi $link['suf'] = ''; 58240eb54bbSjan // highlight link to current page 58340eb54bbSjan if ($id == $ID) { 58492795d04Sandi $link['pre'] = '<span class="curid">'; 58592795d04Sandi $link['suf'] = '</span>'; 58640eb54bbSjan } 5875e163278SAndreas Gohr $link['more'] = ''; 588ba11bd29Sandi $link['class'] = $class; 589ba11bd29Sandi $link['url'] = wl($id); 590ba11bd29Sandi $link['name'] = $name; 591ba11bd29Sandi $link['title'] = $id; 592723d78dbSandi //add search string 593723d78dbSandi if($search){ 594546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 595546d3a99SAndreas Gohr if(is_array($search)){ 596546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 597546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 598546d3a99SAndreas Gohr }else{ 599546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 600546d3a99SAndreas Gohr } 601723d78dbSandi } 602723d78dbSandi 603a1685bedSandi //keep hash 604a1685bedSandi if($hash) $link['url'].='#'.$hash; 605a1685bedSandi 606ba11bd29Sandi //output formatted 607cffcc403Sandi if($returnonly){ 608cffcc403Sandi return $this->_formatLink($link); 609cffcc403Sandi }else{ 610a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6110cecf9d5Sandi } 612cffcc403Sandi } 6130cecf9d5Sandi 614b625487dSandi function externallink($url, $name = NULL) { 615b625487dSandi global $conf; 6160cecf9d5Sandi 617433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 6186f0c5dbfSandi 6190cecf9d5Sandi if ( !$isImage ) { 620b625487dSandi $class='urlextern'; 6210cecf9d5Sandi } else { 622b625487dSandi $class='media'; 6230cecf9d5Sandi } 6240cecf9d5Sandi 625b625487dSandi //prepare for formating 626b625487dSandi $link['target'] = $conf['target']['extern']; 627b625487dSandi $link['style'] = ''; 628b625487dSandi $link['pre'] = ''; 629b625487dSandi $link['suf'] = ''; 6305e163278SAndreas Gohr $link['more'] = ''; 631b625487dSandi $link['class'] = $class; 632b625487dSandi $link['url'] = $url; 633e1c10e4dSchris 634b625487dSandi $link['name'] = $name; 635433bef32Sandi $link['title'] = $this->_xmlEntities($url); 636b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6370cecf9d5Sandi 638b625487dSandi //output formatted 639a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6400cecf9d5Sandi } 6410cecf9d5Sandi 6420cecf9d5Sandi /** 6430cecf9d5Sandi */ 64497a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 645b625487dSandi global $conf; 6460cecf9d5Sandi 64797a3e4e3Sandi $link = array(); 64897a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 64997a3e4e3Sandi $link['pre'] = ''; 65097a3e4e3Sandi $link['suf'] = ''; 6515e163278SAndreas Gohr $link['more'] = ''; 652433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 6530cecf9d5Sandi 65497a3e4e3Sandi //get interwiki URL 6551f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 6560cecf9d5Sandi 65797a3e4e3Sandi if ( !$isImage ) { 6589d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 6599d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 6601c2d1019SAndreas Gohr } else { 6611c2d1019SAndreas Gohr $link['class'] = 'media'; 66297a3e4e3Sandi } 6630cecf9d5Sandi 66497a3e4e3Sandi //do we stay at the same server? Use local target 66597a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 66697a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 66797a3e4e3Sandi } 6680cecf9d5Sandi 66997a3e4e3Sandi $link['url'] = $url; 67097a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 67197a3e4e3Sandi 67297a3e4e3Sandi //output formatted 673a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6740cecf9d5Sandi } 6750cecf9d5Sandi 6760cecf9d5Sandi /** 6770cecf9d5Sandi */ 6781d47afe1Sandi function windowssharelink($url, $name = NULL) { 6791d47afe1Sandi global $conf; 6801d47afe1Sandi global $lang; 6811d47afe1Sandi //simple setup 6821d47afe1Sandi $link['target'] = $conf['target']['windows']; 6831d47afe1Sandi $link['pre'] = ''; 6841d47afe1Sandi $link['suf'] = ''; 6851d47afe1Sandi $link['style'] = ''; 6860cecf9d5Sandi 687433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6880cecf9d5Sandi if ( !$isImage ) { 6891d47afe1Sandi $link['class'] = 'windows'; 6900cecf9d5Sandi } else { 6911d47afe1Sandi $link['class'] = 'media'; 6920cecf9d5Sandi } 6930cecf9d5Sandi 6940cecf9d5Sandi 695433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6961d47afe1Sandi $url = str_replace('\\','/',$url); 6971d47afe1Sandi $url = 'file:///'.$url; 6981d47afe1Sandi $link['url'] = $url; 6990cecf9d5Sandi 7001d47afe1Sandi //output formatted 701a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7020cecf9d5Sandi } 7030cecf9d5Sandi 70471352defSandi function emaillink($address, $name = NULL) { 70571352defSandi global $conf; 70671352defSandi //simple setup 70771352defSandi $link = array(); 70871352defSandi $link['target'] = ''; 70971352defSandi $link['pre'] = ''; 71071352defSandi $link['suf'] = ''; 71171352defSandi $link['style'] = ''; 71271352defSandi $link['more'] = ''; 7130cecf9d5Sandi 714c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7150cecf9d5Sandi if ( !$isImage ) { 716776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 7170cecf9d5Sandi } else { 718776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 7190cecf9d5Sandi } 7200cecf9d5Sandi 72107738714SAndreas Gohr $address = $this->_xmlEntities($address); 72200a7b5adSEsther Brunner $address = obfuscate($address); 72300a7b5adSEsther Brunner $title = $address; 7248c128049SAndreas Gohr 72571352defSandi if(empty($name)){ 72600a7b5adSEsther Brunner $name = $address; 72771352defSandi } 7280cecf9d5Sandi 729776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 730776b36ecSAndreas Gohr 731776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 73271352defSandi $link['name'] = $name; 73371352defSandi $link['title'] = $title; 7340cecf9d5Sandi 73571352defSandi //output formatted 736a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7370cecf9d5Sandi } 7380cecf9d5Sandi 7394826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 740dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 74137e34a5eSandi global $ID; 74291df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 74337e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 7440cecf9d5Sandi 745d98d4540SBen Coburn $noLink = false; 7468acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 747b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7483685f775Sandi 74927bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 750b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 751dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7521c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7532ca14335SEsther Brunner // don't link flash movies 75444881bd0Shenning.noren $noLink = true; 75555efc227SAndreas Gohr }else{ 7562ca14335SEsther Brunner // add file icons 7579d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7589d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7596de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 76055efc227SAndreas Gohr } 7613685f775Sandi 76291df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 76391df343aSAndreas Gohr 7646fe20453SGina Haeussge //markup non existing files 7656fe20453SGina Haeussge if (!$exists) 7666fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 7676fe20453SGina Haeussge 7683685f775Sandi //output formatted 769dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7702ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7710cecf9d5Sandi } 7720cecf9d5Sandi 7734826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 774dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 77591df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 776d98d4540SBen Coburn $noLink = false; 7778acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 778b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 779b739ff0fSPierre Spring 780b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7813685f775Sandi 78227bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 783b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7842ca14335SEsther Brunner // link only jpeg images 78544881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7861c882ba8SAndreas Gohr }elseif($mime == 'application/x-shockwave-flash' && $render){ 7872ca14335SEsther Brunner // don't link flash movies 78844881bd0Shenning.noren $noLink = true; 7892ca14335SEsther Brunner }else{ 7902ca14335SEsther Brunner // add file icons 79127bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 79227bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 7932ca14335SEsther Brunner } 7942ca14335SEsther Brunner 79591df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 79691df343aSAndreas Gohr 7973685f775Sandi //output formatted 798dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7992ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8000cecf9d5Sandi } 8010cecf9d5Sandi 8024826ab45Sandi /** 8033db95becSAndreas Gohr * Renders an RSS feed 804b625487dSandi * 805b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 806b625487dSandi */ 8073db95becSAndreas Gohr function rss ($url,$params){ 808b625487dSandi global $lang; 8093db95becSAndreas Gohr global $conf; 8103db95becSAndreas Gohr 8113db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8123db95becSAndreas Gohr $feed = new FeedParser(); 81300077af8SAndreas Gohr $feed->set_feed_url($url); 814b625487dSandi 815b625487dSandi //disable warning while fetching 816bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8173db95becSAndreas Gohr $rc = $feed->init(); 818bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 819b625487dSandi 8203db95becSAndreas Gohr //decide on start and end 8213db95becSAndreas Gohr if($params['reverse']){ 8223db95becSAndreas Gohr $mod = -1; 8233db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8243db95becSAndreas Gohr $end = $start - ($params['max']); 825b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8263db95becSAndreas Gohr }else{ 8273db95becSAndreas Gohr $mod = 1; 8283db95becSAndreas Gohr $start = 0; 8293db95becSAndreas Gohr $end = $feed->get_item_quantity(); 8303db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 8313db95becSAndreas Gohr } 8323db95becSAndreas Gohr 833a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8343db95becSAndreas Gohr if($rc){ 8353db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8361bde1582SAndreas Gohr $item = $feed->get_item($x); 8373db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 838d2ea3363SAndreas Gohr // support feeds without links 839d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 840d2ea3363SAndreas Gohr if($lnkurl){ 841793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 842793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8431bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 844793361f8SAndreas Gohr htmlspecialchars_decode($item->get_title())); 845d2ea3363SAndreas Gohr }else{ 846d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 847d2ea3363SAndreas Gohr } 8483db95becSAndreas Gohr if($params['author']){ 8491bde1582SAndreas Gohr $author = $item->get_author(0); 8501bde1582SAndreas Gohr if($author){ 8511bde1582SAndreas Gohr $name = $author->get_name(); 8521bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8531bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8541bde1582SAndreas Gohr } 8553db95becSAndreas Gohr } 8563db95becSAndreas Gohr if($params['date']){ 8572e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 8583db95becSAndreas Gohr } 8591bde1582SAndreas Gohr if($params['details']){ 8603db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 861173dccb7STom N Harris if($conf['htmlok']){ 8621bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8633db95becSAndreas Gohr }else{ 8641bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8653db95becSAndreas Gohr } 8663db95becSAndreas Gohr $this->doc .= '</div>'; 8673db95becSAndreas Gohr } 8683db95becSAndreas Gohr 8693db95becSAndreas Gohr $this->doc .= '</div></li>'; 870b625487dSandi } 871b625487dSandi }else{ 8723db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 873a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 874b625487dSandi $this->externallink($url); 87545e147ccSAndreas Gohr if($conf['allowdebug']){ 87645e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 87745e147ccSAndreas Gohr } 8783db95becSAndreas Gohr $this->doc .= '</div></li>'; 879b625487dSandi } 880a2d649c4Sandi $this->doc .= '</ul>'; 881b625487dSandi } 882b625487dSandi 8830cecf9d5Sandi // $numrows not yet implemented 884*90df9a4dSAdrian Lang function table_open($maxcols = NULL, $numrows = NULL, $pos){ 885*90df9a4dSAdrian Lang global $lang; 886b5742cedSPierre Spring // initialize the row counter used for classes 887b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 888*90df9a4dSAdrian Lang $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table', $lang['table_edit_title']) . '">'.DOKU_LF; 8890cecf9d5Sandi } 8900cecf9d5Sandi 891*90df9a4dSAdrian Lang function table_close($pos){ 89259869a4bSAnika Henke $this->doc .= '</table>'.DOKU_LF; 893*90df9a4dSAdrian Lang $this->finishSectionEdit($pos); 8940cecf9d5Sandi } 8950cecf9d5Sandi 8960cecf9d5Sandi function tablerow_open(){ 897b5742cedSPierre Spring // initialize the cell counter used for classes 898b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 899b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 900b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9010cecf9d5Sandi } 9020cecf9d5Sandi 9030cecf9d5Sandi function tablerow_close(){ 904a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9050cecf9d5Sandi } 9060cecf9d5Sandi 90725b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ 908b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9090cecf9d5Sandi if ( !is_null($align) ) { 910b5742cedSPierre Spring $class .= ' '.$align.'align'; 9110cecf9d5Sandi } 912b5742cedSPierre Spring $class .= '"'; 913b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9140cecf9d5Sandi if ( $colspan > 1 ) { 915a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 916a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9170cecf9d5Sandi } 91825b97867Shakan.sandell if ( $rowspan > 1 ) { 91925b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 92025b97867Shakan.sandell } 921a2d649c4Sandi $this->doc .= '>'; 9220cecf9d5Sandi } 9230cecf9d5Sandi 9240cecf9d5Sandi function tableheader_close(){ 925a2d649c4Sandi $this->doc .= '</th>'; 9260cecf9d5Sandi } 9270cecf9d5Sandi 92825b97867Shakan.sandell function tablecell_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 .= '<td '.$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 tablecell_close(){ 946a2d649c4Sandi $this->doc .= '</td>'; 9470cecf9d5Sandi } 9480cecf9d5Sandi 9490cecf9d5Sandi //---------------------------------------------------------- 9500cecf9d5Sandi // Utils 9510cecf9d5Sandi 952ba11bd29Sandi /** 9533fd0b676Sandi * Build a link 9543fd0b676Sandi * 9553fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 956ba11bd29Sandi * 957ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 958ba11bd29Sandi */ 959433bef32Sandi function _formatLink($link){ 960ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 961ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 962ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 963ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 964ba11bd29Sandi } 965ba11bd29Sandi //remove double encodings in titles 966ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 967ba11bd29Sandi 968453493f2SAndreas Gohr // be sure there are no bad chars in url or title 969453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 970453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 971453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 972453493f2SAndreas Gohr 973ba11bd29Sandi $ret = ''; 974ba11bd29Sandi $ret .= $link['pre']; 975ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 976bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 977bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 978bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 979bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 98044a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 981bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 982ba11bd29Sandi $ret .= '>'; 983ba11bd29Sandi $ret .= $link['name']; 984ba11bd29Sandi $ret .= '</a>'; 985ba11bd29Sandi $ret .= $link['suf']; 986ba11bd29Sandi return $ret; 987ba11bd29Sandi } 988ba11bd29Sandi 989ba11bd29Sandi /** 9903fd0b676Sandi * Renders internal and external media 9913fd0b676Sandi * 9923fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9933fd0b676Sandi */ 9943fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 995b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9963fd0b676Sandi 9973fd0b676Sandi $ret = ''; 9983fd0b676Sandi 999ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10003fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1001b739ff0fSPierre Spring // first get the $title 1002b739ff0fSPierre Spring if (!is_null($title)) { 1003b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1004b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1005b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1006b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 100767f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1008b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1009b739ff0fSPierre Spring if($cap){ 1010b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1011b739ff0fSPierre Spring } 1012b739ff0fSPierre Spring } 1013b739ff0fSPierre Spring if (!$render) { 1014b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1015b739ff0fSPierre Spring // return the title of the picture 1016b739ff0fSPierre Spring if (!$title) { 1017b739ff0fSPierre Spring // just show the sourcename 1018b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 1019b739ff0fSPierre Spring } 1020b739ff0fSPierre Spring return $title; 1021b739ff0fSPierre Spring } 10223fd0b676Sandi //add image tag 10236de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 10243fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10253fd0b676Sandi 10264ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 10274ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 10284ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 10294ab889eaSAndreas Gohr 1030b739ff0fSPierre Spring if ($title) { 1031b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1032b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10333fd0b676Sandi }else{ 10343fd0b676Sandi $ret .= ' alt=""'; 10353fd0b676Sandi } 10363fd0b676Sandi 10373fd0b676Sandi if ( !is_null($width) ) 10383fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10393fd0b676Sandi 10403fd0b676Sandi if ( !is_null($height) ) 10413fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 10423fd0b676Sandi 10433fd0b676Sandi $ret .= ' />'; 10443fd0b676Sandi 10453fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 10461c882ba8SAndreas Gohr if (!$render) { 10471c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 10481c882ba8SAndreas Gohr // return the title of the flash 10491c882ba8SAndreas Gohr if (!$title) { 10501c882ba8SAndreas Gohr // just show the sourcename 105107bf32b2SAndreas Gohr $title = basename(noNS($src)); 10521c882ba8SAndreas Gohr } 105307bf32b2SAndreas Gohr return $this->_xmlEntities($title); 10541c882ba8SAndreas Gohr } 10551c882ba8SAndreas Gohr 105607bf32b2SAndreas Gohr $att = array(); 105707bf32b2SAndreas Gohr $att['class'] = "media$align"; 105807bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 105907bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1060c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 106107bf32b2SAndreas Gohr array('quality' => 'high'), 106207bf32b2SAndreas Gohr null, 106307bf32b2SAndreas Gohr $att, 106407bf32b2SAndreas Gohr $this->_xmlEntities($title)); 10650f428d7dSAndreas Gohr }elseif($title){ 10663fd0b676Sandi // well at least we have a title to display 10673fd0b676Sandi $ret .= $this->_xmlEntities($title); 10683fd0b676Sandi }else{ 10695291ca3aSAndreas Gohr // just show the sourcename 10700f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 10713fd0b676Sandi } 10723fd0b676Sandi 10733fd0b676Sandi return $ret; 10743fd0b676Sandi } 10753fd0b676Sandi 1076433bef32Sandi function _xmlEntities($string) { 1077de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 10780cecf9d5Sandi } 10790cecf9d5Sandi 10808a831f2bSAndreas Gohr /** 10818a831f2bSAndreas Gohr * Creates a linkid from a headline 1082c5a8fd96SAndreas Gohr * 1083c5a8fd96SAndreas Gohr * @param string $title The headline title 1084c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1085c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10868a831f2bSAndreas Gohr */ 1087c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1088c5a8fd96SAndreas Gohr if($create){ 10894ceab83fSAndreas Gohr return sectionID($title,$this->headers); 10904ceab83fSAndreas Gohr }else{ 1091443d207bSAndreas Gohr $check = false; 1092443d207bSAndreas Gohr return sectionID($title,$check); 1093c5a8fd96SAndreas Gohr } 10940cecf9d5Sandi } 10950cecf9d5Sandi 1096af587fa8Sandi /** 10973fd0b676Sandi * Construct a title and handle images in titles 10983fd0b676Sandi * 10990b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 11003fd0b676Sandi */ 1101fe9ec250SChris Smith function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1102bb0a59d4Sjan global $conf; 1103bb0a59d4Sjan 110444881bd0Shenning.noren $isImage = false; 110529657f9eSAndreas Gohr if ( is_array($title) ) { 110629657f9eSAndreas Gohr $isImage = true; 110729657f9eSAndreas Gohr return $this->_imageTitle($title); 110829657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1109fe9ec250SChris Smith if (useHeading($linktype) && $id) { 1110fc18c0fbSchris $heading = p_get_first_heading($id,true); 1111bb0a59d4Sjan if ($heading) { 1112433bef32Sandi return $this->_xmlEntities($heading); 1113bb0a59d4Sjan } 1114bb0a59d4Sjan } 1115433bef32Sandi return $this->_xmlEntities($default); 111668c26e6dSMichael Klier } else { 111768c26e6dSMichael Klier return $this->_xmlEntities($title); 11180cecf9d5Sandi } 11190cecf9d5Sandi } 11200cecf9d5Sandi 11210cecf9d5Sandi /** 11223fd0b676Sandi * Returns an HTML code for images used in link titles 11233fd0b676Sandi * 11243fd0b676Sandi * @todo Resolve namespace on internal images 11253fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 11260cecf9d5Sandi */ 1127433bef32Sandi function _imageTitle($img) { 1128d9baf1a7SKazutaka Miyasaka global $ID; 1129d9baf1a7SKazutaka Miyasaka 1130d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1131d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1132d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1133d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1134d9baf1a7SKazutaka Miyasaka resolve_mediaid(getNS($ID),$img['src'],$exists); 1135d9baf1a7SKazutaka Miyasaka } 1136d9baf1a7SKazutaka Miyasaka 1137433bef32Sandi return $this->_media($img['src'], 11384826ab45Sandi $img['title'], 11394826ab45Sandi $img['align'], 11404826ab45Sandi $img['width'], 11414826ab45Sandi $img['height'], 11424826ab45Sandi $img['cache']); 11430cecf9d5Sandi } 1144b739ff0fSPierre Spring 1145b739ff0fSPierre Spring /** 1146b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1147b739ff0fSPierre Spring * which returns a basic link to a media. 1148b739ff0fSPierre Spring * 1149b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1150b739ff0fSPierre Spring * @param string $src 1151b739ff0fSPierre Spring * @param string $title 1152b739ff0fSPierre Spring * @param string $align 1153b739ff0fSPierre Spring * @param string $width 1154b739ff0fSPierre Spring * @param string $height 1155b739ff0fSPierre Spring * @param string $cache 1156b739ff0fSPierre Spring * @param string $render 1157b739ff0fSPierre Spring * @access protected 1158b739ff0fSPierre Spring * @return array 1159b739ff0fSPierre Spring */ 1160b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1161b739ff0fSPierre Spring { 1162b739ff0fSPierre Spring global $conf; 1163b739ff0fSPierre Spring 1164b739ff0fSPierre Spring $link = array(); 1165b739ff0fSPierre Spring $link['class'] = 'media'; 1166b739ff0fSPierre Spring $link['style'] = ''; 1167b739ff0fSPierre Spring $link['pre'] = ''; 1168b739ff0fSPierre Spring $link['suf'] = ''; 1169b739ff0fSPierre Spring $link['more'] = ''; 1170b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1171b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1172b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1173b739ff0fSPierre Spring 1174b739ff0fSPierre Spring return $link; 1175b739ff0fSPierre Spring } 117691459163SAnika Henke 117791459163SAnika Henke 11780cecf9d5Sandi} 11790cecf9d5Sandi 11804826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1181