10cecf9d5Sandi<?php 2b625487dSandi/** 3b625487dSandi * Renderer for XHTML output 4b625487dSandi * 5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 7b625487dSandi */ 8b625487dSandi 90cecf9d5Sandiif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 100cecf9d5Sandi 110cecf9d5Sandiif ( !defined('DOKU_LF') ) { 120cecf9d5Sandi // Some whitespace to help View > Source 130cecf9d5Sandi define ('DOKU_LF',"\n"); 140cecf9d5Sandi} 150cecf9d5Sandi 160cecf9d5Sandiif ( !defined('DOKU_TAB') ) { 170cecf9d5Sandi // Some whitespace to help View > Source 180cecf9d5Sandi define ('DOKU_TAB',"\t"); 190cecf9d5Sandi} 200cecf9d5Sandi 210e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php'; 2256fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php'; 230e1c636eSandi 240cecf9d5Sandi/** 25b625487dSandi * The Renderer 260cecf9d5Sandi */ 27ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer { 280cecf9d5Sandi 29c5a8fd96SAndreas Gohr // @access public 30c5a8fd96SAndreas Gohr var $doc = ''; // will contain the whole document 31c5a8fd96SAndreas Gohr var $toc = array(); // will contain the Table of Contents 32c5a8fd96SAndreas Gohr 330cecf9d5Sandi 340cecf9d5Sandi var $headers = array(); 350cecf9d5Sandi var $footnotes = array(); 36af587fa8Sandi var $lastsec = 0; 377764a90aSandi var $store = ''; 387764a90aSandi 395f70445dSAndreas Gohr function getFormat(){ 405f70445dSAndreas Gohr return 'xhtml'; 415f70445dSAndreas Gohr } 425f70445dSAndreas Gohr 435f70445dSAndreas Gohr 440cecf9d5Sandi function document_start() { 45c5a8fd96SAndreas Gohr //reset some internals 46c5a8fd96SAndreas Gohr $this->toc = array(); 47c5a8fd96SAndreas Gohr $this->headers = array(); 480cecf9d5Sandi } 490cecf9d5Sandi 500cecf9d5Sandi function document_end() { 510cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 52a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 53d74aace9Schris 54d74aace9Schris $id = 0; 550cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 56d74aace9Schris $id++; // the number of the current footnote 57d74aace9Schris 58d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 59d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 60d74aace9Schris 61d74aace9Schris // open the footnote and set the anchor and backlink 62d74aace9Schris $this->doc .= '<div class="fn">'; 6324a33b42SAndreas Gohr $this->doc .= '<a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 64d74aace9Schris $this->doc .= $id.')</a> '.DOKU_LF; 65d74aace9Schris 66d74aace9Schris // get any other footnotes that use the same markup 67d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 68d74aace9Schris 69d74aace9Schris if (count($alt)) { 70d74aace9Schris foreach ($alt as $ref) { 71d74aace9Schris // set anchor and backlink for the other footnotes 7224a33b42SAndreas Gohr $this->doc .= ', <a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 73d74aace9Schris $this->doc .= ($ref+1).')</a> '.DOKU_LF; 74d74aace9Schris } 75d74aace9Schris } 76d74aace9Schris 77d74aace9Schris // add footnote markup and close this footnote 78a2d649c4Sandi $this->doc .= $footnote; 79d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 80d74aace9Schris } 810cecf9d5Sandi } 82a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 830cecf9d5Sandi } 84c5a8fd96SAndreas Gohr 85c5a8fd96SAndreas Gohr // prepend the TOC 86e41c4da9SAndreas Gohr if($this->info['toc']){ 87169c7240Schris $this->doc = $this->render_TOC($this->toc).$this->doc; 880cecf9d5Sandi } 893e55d035SAndreas Gohr 903e55d035SAndreas Gohr // make sure there are no empty paragraphs 9127918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 92e41c4da9SAndreas Gohr } 930cecf9d5Sandi 94c5a8fd96SAndreas Gohr /** 95c5a8fd96SAndreas Gohr * Return the TOC rendered to XHTML 96c5a8fd96SAndreas Gohr * 97c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 98c5a8fd96SAndreas Gohr */ 99dd5eee54SAndreas Gohr function render_TOC($toc=null){ 100dd5eee54SAndreas Gohr if(is_null($toc) && is_array($this->toc)) $toc = $this->toc; 101dd5eee54SAndreas Gohr 102169c7240Schris if(count($toc) < 3) return ''; 103c5a8fd96SAndreas Gohr global $lang; 104*4ab889eaSAndreas Gohr $out = '<!-- TOC START -->'.DOKU_LF; 105*4ab889eaSAndreas Gohr $out .= '<div class="toc">'.DOKU_LF; 106c5a8fd96SAndreas Gohr $out .= '<div class="tocheader toctoggle" id="toc__header">'; 107c5a8fd96SAndreas Gohr $out .= $lang['toc']; 108c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF; 109c5a8fd96SAndreas Gohr $out .= '<div id="toc__inside">'.DOKU_LF; 110169c7240Schris $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem')); 111c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 112*4ab889eaSAndreas Gohr $out .= '<!-- TOC END -->'.DOKU_LF; 113c5a8fd96SAndreas Gohr return $out; 114c5a8fd96SAndreas Gohr } 115c5a8fd96SAndreas Gohr 116c5a8fd96SAndreas Gohr /** 117c5a8fd96SAndreas Gohr * Callback for html_buildlist 118c5a8fd96SAndreas Gohr */ 119c5a8fd96SAndreas Gohr function _tocitem($item){ 120c5a8fd96SAndreas Gohr return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'. 121169c7240Schris Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>'; 122c5a8fd96SAndreas Gohr } 123c5a8fd96SAndreas Gohr 124e7856beaSchris function toc_additem($id, $text, $level) { 125af587fa8Sandi global $conf; 126af587fa8Sandi 127c5a8fd96SAndreas Gohr //handle TOC 128c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 129c5a8fd96SAndreas Gohr // the TOC is one of our standard ul list arrays ;-) 130e7856beaSchris $this->toc[] = array( 'hid' => $id, 131c5a8fd96SAndreas Gohr 'title' => $text, 132c5a8fd96SAndreas Gohr 'type' => 'ul', 13321ed2ba4Sjan 'level' => $level-$conf['toptoclevel']+1); 134c5a8fd96SAndreas Gohr } 135e7856beaSchris } 136e7856beaSchris 137e7856beaSchris function header($text, $level, $pos) { 138e7856beaSchris 139e7856beaSchris $hid = $this->_headerToLink($text,true); 140e7856beaSchris 141e7856beaSchris //only add items within configured levels 142e7856beaSchris $this->toc_additem($hid, $text, $level); 143c5a8fd96SAndreas Gohr 144c5a8fd96SAndreas Gohr // write the header 145c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 146a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 147c6a1c1bfSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1480cecf9d5Sandi } 1490cecf9d5Sandi 15035dae8b0SBen Coburn /** 15135dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 15235dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 15335dae8b0SBen Coburn * 15435dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 15535dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 15635dae8b0SBen Coburn */ 15735dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 15835dae8b0SBen Coburn global $conf; 15935dae8b0SBen Coburn 16035dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 16135dae8b0SBen Coburn $name = str_replace('"', '', $name); 16235dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 16335dae8b0SBen Coburn } 16435dae8b0SBen Coburn } 16535dae8b0SBen Coburn 1660cecf9d5Sandi function section_open($level) { 167a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1680cecf9d5Sandi } 1690cecf9d5Sandi 1700cecf9d5Sandi function section_close() { 171a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1720cecf9d5Sandi } 1730cecf9d5Sandi 1740cecf9d5Sandi function cdata($text) { 175a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1760cecf9d5Sandi } 1770cecf9d5Sandi 1780cecf9d5Sandi function p_open() { 179a2d649c4Sandi $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1800cecf9d5Sandi } 1810cecf9d5Sandi 1820cecf9d5Sandi function p_close() { 183a2d649c4Sandi $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1840cecf9d5Sandi } 1850cecf9d5Sandi 1860cecf9d5Sandi function linebreak() { 187a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1880cecf9d5Sandi } 1890cecf9d5Sandi 1900cecf9d5Sandi function hr() { 1914beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1920cecf9d5Sandi } 1930cecf9d5Sandi 1940cecf9d5Sandi function strong_open() { 195a2d649c4Sandi $this->doc .= '<strong>'; 1960cecf9d5Sandi } 1970cecf9d5Sandi 1980cecf9d5Sandi function strong_close() { 199a2d649c4Sandi $this->doc .= '</strong>'; 2000cecf9d5Sandi } 2010cecf9d5Sandi 2020cecf9d5Sandi function emphasis_open() { 203a2d649c4Sandi $this->doc .= '<em>'; 2040cecf9d5Sandi } 2050cecf9d5Sandi 2060cecf9d5Sandi function emphasis_close() { 207a2d649c4Sandi $this->doc .= '</em>'; 2080cecf9d5Sandi } 2090cecf9d5Sandi 2100cecf9d5Sandi function underline_open() { 21102e51121SAnika Henke $this->doc .= '<em class="u">'; 2120cecf9d5Sandi } 2130cecf9d5Sandi 2140cecf9d5Sandi function underline_close() { 21502e51121SAnika Henke $this->doc .= '</em>'; 2160cecf9d5Sandi } 2170cecf9d5Sandi 2180cecf9d5Sandi function monospace_open() { 219a2d649c4Sandi $this->doc .= '<code>'; 2200cecf9d5Sandi } 2210cecf9d5Sandi 2220cecf9d5Sandi function monospace_close() { 223a2d649c4Sandi $this->doc .= '</code>'; 2240cecf9d5Sandi } 2250cecf9d5Sandi 2260cecf9d5Sandi function subscript_open() { 227a2d649c4Sandi $this->doc .= '<sub>'; 2280cecf9d5Sandi } 2290cecf9d5Sandi 2300cecf9d5Sandi function subscript_close() { 231a2d649c4Sandi $this->doc .= '</sub>'; 2320cecf9d5Sandi } 2330cecf9d5Sandi 2340cecf9d5Sandi function superscript_open() { 235a2d649c4Sandi $this->doc .= '<sup>'; 2360cecf9d5Sandi } 2370cecf9d5Sandi 2380cecf9d5Sandi function superscript_close() { 239a2d649c4Sandi $this->doc .= '</sup>'; 2400cecf9d5Sandi } 2410cecf9d5Sandi 2420cecf9d5Sandi function deleted_open() { 243a2d649c4Sandi $this->doc .= '<del>'; 2440cecf9d5Sandi } 2450cecf9d5Sandi 2460cecf9d5Sandi function deleted_close() { 247a2d649c4Sandi $this->doc .= '</del>'; 2480cecf9d5Sandi } 2490cecf9d5Sandi 2503fd0b676Sandi /** 2513fd0b676Sandi * Callback for footnote start syntax 2523fd0b676Sandi * 2533fd0b676Sandi * All following content will go to the footnote instead of 254d74aace9Schris * the document. To achieve this the previous rendered content 2553fd0b676Sandi * is moved to $store and $doc is cleared 2563fd0b676Sandi * 2573fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2583fd0b676Sandi */ 2590cecf9d5Sandi function footnote_open() { 2607764a90aSandi 2617764a90aSandi // move current content to store and record footnote 2627764a90aSandi $this->store = $this->doc; 2637764a90aSandi $this->doc = ''; 2640cecf9d5Sandi } 2650cecf9d5Sandi 2663fd0b676Sandi /** 2673fd0b676Sandi * Callback for footnote end syntax 2683fd0b676Sandi * 2693fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2703fd0b676Sandi * content is restored from $store again 2713fd0b676Sandi * 2723fd0b676Sandi * @author Andreas Gohr 2733fd0b676Sandi */ 2740cecf9d5Sandi function footnote_close() { 2757764a90aSandi 276d74aace9Schris // recover footnote into the stack and restore old content 277d74aace9Schris $footnote = $this->doc; 2787764a90aSandi $this->doc = $this->store; 2797764a90aSandi $this->store = ''; 280d74aace9Schris 281d74aace9Schris // check to see if this footnote has been seen before 282d74aace9Schris $i = array_search($footnote, $this->footnotes); 283d74aace9Schris 284d74aace9Schris if ($i === false) { 285d74aace9Schris // its a new footnote, add it to the $footnotes array 286d74aace9Schris $id = count($this->footnotes)+1; 287d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 288d74aace9Schris } else { 289d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 290d74aace9Schris $i++; 291d74aace9Schris $id = count($this->footnotes)+1; 292d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 293d74aace9Schris } 294d74aace9Schris 2956b379cbfSAndreas Gohr // output the footnote reference and link 2966b379cbfSAndreas Gohr $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>'; 2970cecf9d5Sandi } 2980cecf9d5Sandi 2990cecf9d5Sandi function listu_open() { 300a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 3010cecf9d5Sandi } 3020cecf9d5Sandi 3030cecf9d5Sandi function listu_close() { 304a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3050cecf9d5Sandi } 3060cecf9d5Sandi 3070cecf9d5Sandi function listo_open() { 308a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3090cecf9d5Sandi } 3100cecf9d5Sandi 3110cecf9d5Sandi function listo_close() { 312a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3130cecf9d5Sandi } 3140cecf9d5Sandi 3150cecf9d5Sandi function listitem_open($level) { 316a2d649c4Sandi $this->doc .= '<li class="level'.$level.'">'; 3170cecf9d5Sandi } 3180cecf9d5Sandi 3190cecf9d5Sandi function listitem_close() { 320a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3210cecf9d5Sandi } 3220cecf9d5Sandi 3230cecf9d5Sandi function listcontent_open() { 32490db23d7Schris $this->doc .= '<div class="li">'; 3250cecf9d5Sandi } 3260cecf9d5Sandi 3270cecf9d5Sandi function listcontent_close() { 32890db23d7Schris $this->doc .= '</div>'.DOKU_LF; 3290cecf9d5Sandi } 3300cecf9d5Sandi 3310cecf9d5Sandi function unformatted($text) { 332a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3330cecf9d5Sandi } 3340cecf9d5Sandi 3350cecf9d5Sandi /** 3363fd0b676Sandi * Execute PHP code if allowed 3373fd0b676Sandi * 3383fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3390cecf9d5Sandi */ 3400cecf9d5Sandi function php($text) { 341bad0b545Sandi ob_start(); 3424de671bcSandi eval($text); 3433fd0b676Sandi $this->doc .= ob_get_contents(); 344bad0b545Sandi ob_end_clean(); 3450cecf9d5Sandi } 3460cecf9d5Sandi 34707f89c3cSAnika Henke function phpblock($text) { 34807f89c3cSAnika Henke $this->php($text); 34907f89c3cSAnika Henke } 35007f89c3cSAnika Henke 3510cecf9d5Sandi /** 3523fd0b676Sandi * Insert HTML if allowed 3533fd0b676Sandi * 3543fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3550cecf9d5Sandi */ 3560cecf9d5Sandi function html($text) { 357a2d649c4Sandi $this->doc .= $text; 3584de671bcSandi } 3590cecf9d5Sandi 36007f89c3cSAnika Henke function htmlblock($text) { 36107f89c3cSAnika Henke $this->html($text); 36207f89c3cSAnika Henke } 36307f89c3cSAnika Henke 3640cecf9d5Sandi function preformatted($text) { 365a2d649c4Sandi $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 3660cecf9d5Sandi } 3670cecf9d5Sandi 3680cecf9d5Sandi function file($text) { 369a2d649c4Sandi $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 3700cecf9d5Sandi } 3710cecf9d5Sandi 3720cecf9d5Sandi function quote_open() { 37396331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3740cecf9d5Sandi } 3750cecf9d5Sandi 3760cecf9d5Sandi function quote_close() { 37796331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3780cecf9d5Sandi } 3790cecf9d5Sandi 3800cecf9d5Sandi /** 3813fd0b676Sandi * Callback for code text 3823fd0b676Sandi * 3833fd0b676Sandi * Uses GeSHi to highlight language syntax 3843fd0b676Sandi * 3853fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3860cecf9d5Sandi */ 3870cecf9d5Sandi function code($text, $language = NULL) { 3884de671bcSandi global $conf; 3890cecf9d5Sandi 3900cecf9d5Sandi if ( is_null($language) ) { 3910cecf9d5Sandi $this->preformatted($text); 3920cecf9d5Sandi } else { 393852896daSAndreas Gohr //strip leading and trailing blank line 394313da78aSandi $text = preg_replace('/^\s*?\n/','',$text); 395852896daSAndreas Gohr $text = preg_replace('/\s*?\n$/','',$text); 3968f7d700cSchris $this->doc .= p_xhtml_cached_geshi($text, $language); 3970cecf9d5Sandi } 3980cecf9d5Sandi } 3990cecf9d5Sandi 4000cecf9d5Sandi function acronym($acronym) { 4010cecf9d5Sandi 4020cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4030cecf9d5Sandi 404433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4050cecf9d5Sandi 406a2d649c4Sandi $this->doc .= '<acronym title="'.$title 407433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4080cecf9d5Sandi 4090cecf9d5Sandi } else { 410a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4110cecf9d5Sandi } 4120cecf9d5Sandi } 4130cecf9d5Sandi 4140cecf9d5Sandi function smiley($smiley) { 4150cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 416433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 417f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4184beabca9SAnika Henke '" class="middle" alt="'. 419433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4200cecf9d5Sandi } else { 421a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4220cecf9d5Sandi } 4230cecf9d5Sandi } 4240cecf9d5Sandi 425f62ea8a1Sandi /* 4264de671bcSandi * not used 4270cecf9d5Sandi function wordblock($word) { 4280cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 429a2d649c4Sandi $this->doc .= '** BLEEP **'; 4300cecf9d5Sandi } else { 431a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4320cecf9d5Sandi } 4330cecf9d5Sandi } 4344de671bcSandi */ 4350cecf9d5Sandi 4360cecf9d5Sandi function entity($entity) { 4370cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 438a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4390cecf9d5Sandi } else { 440a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4410cecf9d5Sandi } 4420cecf9d5Sandi } 4430cecf9d5Sandi 4440cecf9d5Sandi function multiplyentity($x, $y) { 445a2d649c4Sandi $this->doc .= "$x×$y"; 4460cecf9d5Sandi } 4470cecf9d5Sandi 4480cecf9d5Sandi function singlequoteopening() { 44971b40da2SAnika Henke global $lang; 45071b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4510cecf9d5Sandi } 4520cecf9d5Sandi 4530cecf9d5Sandi function singlequoteclosing() { 45471b40da2SAnika Henke global $lang; 45571b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4560cecf9d5Sandi } 4570cecf9d5Sandi 45857d757d1SAndreas Gohr function apostrophe() { 45957d757d1SAndreas Gohr global $lang; 460a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 46157d757d1SAndreas Gohr } 46257d757d1SAndreas Gohr 4630cecf9d5Sandi function doublequoteopening() { 46471b40da2SAnika Henke global $lang; 46571b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4660cecf9d5Sandi } 4670cecf9d5Sandi 4680cecf9d5Sandi function doublequoteclosing() { 46971b40da2SAnika Henke global $lang; 47071b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4710cecf9d5Sandi } 4720cecf9d5Sandi 4730cecf9d5Sandi /** 4740cecf9d5Sandi */ 4750cecf9d5Sandi function camelcaselink($link) { 47611d0aa47Sandi $this->internallink($link,$link); 4770cecf9d5Sandi } 4780cecf9d5Sandi 4790b7c14c2Sandi 4800b7c14c2Sandi function locallink($hash, $name = NULL){ 4810b7c14c2Sandi global $ID; 4820b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4830b7c14c2Sandi $hash = $this->_headerToLink($hash); 4840b7c14c2Sandi $title = $ID.' ↵'; 4850b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 4860b7c14c2Sandi $this->doc .= $name; 4870b7c14c2Sandi $this->doc .= '</a>'; 4880b7c14c2Sandi } 4890b7c14c2Sandi 490cffcc403Sandi /** 4913fd0b676Sandi * Render an internal Wiki Link 4923fd0b676Sandi * 493cffcc403Sandi * $search and $returnonly are not for the renderer but are used 494cffcc403Sandi * elsewhere - no need to implement them in other renderers 4953fd0b676Sandi * 4963fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 497cffcc403Sandi */ 498cffcc403Sandi function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 499ba11bd29Sandi global $conf; 50037e34a5eSandi global $ID; 5010339c872Sjan // default name is based on $id as given 5020339c872Sjan $default = $this->_simpleTitle($id); 503ad32e47eSAndreas Gohr 5040339c872Sjan // now first resolve and clean up the $id 50537e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 5060339c872Sjan $name = $this->_getLinkTitle($name, $default, $isImage, $id); 5070e1c636eSandi if ( !$isImage ) { 5080e1c636eSandi if ( $exists ) { 509ba11bd29Sandi $class='wikilink1'; 5100cecf9d5Sandi } else { 511ba11bd29Sandi $class='wikilink2'; 5120cecf9d5Sandi } 5130cecf9d5Sandi } else { 514ba11bd29Sandi $class='media'; 5150cecf9d5Sandi } 5160cecf9d5Sandi 517a1685bedSandi //keep hash anchor 518ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 519943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 520a1685bedSandi 521ba11bd29Sandi //prepare for formating 522ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 523ba11bd29Sandi $link['style'] = ''; 524ba11bd29Sandi $link['pre'] = ''; 525ba11bd29Sandi $link['suf'] = ''; 52640eb54bbSjan // highlight link to current page 52740eb54bbSjan if ($id == $ID) { 52892795d04Sandi $link['pre'] = '<span class="curid">'; 52992795d04Sandi $link['suf'] = '</span>'; 53040eb54bbSjan } 5315e163278SAndreas Gohr $link['more'] = ''; 532ba11bd29Sandi $link['class'] = $class; 533ba11bd29Sandi $link['url'] = wl($id); 534ba11bd29Sandi $link['name'] = $name; 535ba11bd29Sandi $link['title'] = $id; 536723d78dbSandi //add search string 537723d78dbSandi if($search){ 538723d78dbSandi ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 539b6c6979fSAndreas Gohr $link['url'] .= rawurlencode($search); 540723d78dbSandi } 541723d78dbSandi 542a1685bedSandi //keep hash 543a1685bedSandi if($hash) $link['url'].='#'.$hash; 544a1685bedSandi 545ba11bd29Sandi //output formatted 546cffcc403Sandi if($returnonly){ 547cffcc403Sandi return $this->_formatLink($link); 548cffcc403Sandi }else{ 549a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5500cecf9d5Sandi } 551cffcc403Sandi } 5520cecf9d5Sandi 553b625487dSandi function externallink($url, $name = NULL) { 554b625487dSandi global $conf; 5550cecf9d5Sandi 556433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5576f0c5dbfSandi 5580cecf9d5Sandi if ( !$isImage ) { 559b625487dSandi $class='urlextern'; 5600cecf9d5Sandi } else { 561b625487dSandi $class='media'; 5620cecf9d5Sandi } 5630cecf9d5Sandi 564b625487dSandi //prepare for formating 565b625487dSandi $link['target'] = $conf['target']['extern']; 566b625487dSandi $link['style'] = ''; 567b625487dSandi $link['pre'] = ''; 568b625487dSandi $link['suf'] = ''; 5695e163278SAndreas Gohr $link['more'] = ''; 570b625487dSandi $link['class'] = $class; 571b625487dSandi $link['url'] = $url; 572e1c10e4dSchris 573b625487dSandi $link['name'] = $name; 574433bef32Sandi $link['title'] = $this->_xmlEntities($url); 575b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5760cecf9d5Sandi 577b625487dSandi //output formatted 578a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5790cecf9d5Sandi } 5800cecf9d5Sandi 5810cecf9d5Sandi /** 5820cecf9d5Sandi */ 58397a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 584b625487dSandi global $conf; 5850cecf9d5Sandi 58697a3e4e3Sandi $link = array(); 58797a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 58897a3e4e3Sandi $link['pre'] = ''; 58997a3e4e3Sandi $link['suf'] = ''; 5905e163278SAndreas Gohr $link['more'] = ''; 591433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5920cecf9d5Sandi 59397a3e4e3Sandi //get interwiki URL 5941f82fabeSAndreas Gohr $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 5950cecf9d5Sandi 59697a3e4e3Sandi if ( !$isImage ) { 5979d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5989d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5991c2d1019SAndreas Gohr } else { 6001c2d1019SAndreas Gohr $link['class'] = 'media'; 60197a3e4e3Sandi } 6020cecf9d5Sandi 60397a3e4e3Sandi //do we stay at the same server? Use local target 60497a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 60597a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 60697a3e4e3Sandi } 6070cecf9d5Sandi 60897a3e4e3Sandi $link['url'] = $url; 60997a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 61097a3e4e3Sandi 61197a3e4e3Sandi //output formatted 612a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6130cecf9d5Sandi } 6140cecf9d5Sandi 6150cecf9d5Sandi /** 6160cecf9d5Sandi */ 6171d47afe1Sandi function windowssharelink($url, $name = NULL) { 6181d47afe1Sandi global $conf; 6191d47afe1Sandi global $lang; 6201d47afe1Sandi //simple setup 6211d47afe1Sandi $link['target'] = $conf['target']['windows']; 6221d47afe1Sandi $link['pre'] = ''; 6231d47afe1Sandi $link['suf'] = ''; 6241d47afe1Sandi $link['style'] = ''; 6251d47afe1Sandi //Display error on browsers other than IE 6261d47afe1Sandi $link['more'] = 'onclick="if(document.all == null){alert(\''. 627b120b664SAndreas Gohr str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])). 6281d47afe1Sandi '\');}" onkeypress="if(document.all == null){alert(\''. 629b120b664SAndreas Gohr str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"'; 6300cecf9d5Sandi 631433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6320cecf9d5Sandi if ( !$isImage ) { 6331d47afe1Sandi $link['class'] = 'windows'; 6340cecf9d5Sandi } else { 6351d47afe1Sandi $link['class'] = 'media'; 6360cecf9d5Sandi } 6370cecf9d5Sandi 6380cecf9d5Sandi 639433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6401d47afe1Sandi $url = str_replace('\\','/',$url); 6411d47afe1Sandi $url = 'file:///'.$url; 6421d47afe1Sandi $link['url'] = $url; 6430cecf9d5Sandi 6441d47afe1Sandi //output formatted 645a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6460cecf9d5Sandi } 6470cecf9d5Sandi 64871352defSandi function emaillink($address, $name = NULL) { 64971352defSandi global $conf; 65071352defSandi //simple setup 65171352defSandi $link = array(); 65271352defSandi $link['target'] = ''; 65371352defSandi $link['pre'] = ''; 65471352defSandi $link['suf'] = ''; 65571352defSandi $link['style'] = ''; 65671352defSandi $link['more'] = ''; 6570cecf9d5Sandi 658c6e62e9fSchris $name = $this->_getLinkTitle($name, '', $isImage); 6590cecf9d5Sandi if ( !$isImage ) { 660776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6610cecf9d5Sandi } else { 662776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6630cecf9d5Sandi } 6640cecf9d5Sandi 66507738714SAndreas Gohr $address = $this->_xmlEntities($address); 66600a7b5adSEsther Brunner $address = obfuscate($address); 66700a7b5adSEsther Brunner $title = $address; 6688c128049SAndreas Gohr 66971352defSandi if(empty($name)){ 67000a7b5adSEsther Brunner $name = $address; 67171352defSandi } 6728c128049SAndreas Gohr#elseif($isImage{ 6738c128049SAndreas Gohr# $name = $this->_xmlEntities($name); 6748c128049SAndreas Gohr# } 6750cecf9d5Sandi 676776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 677776b36ecSAndreas Gohr 678776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 67971352defSandi $link['name'] = $name; 68071352defSandi $link['title'] = $title; 6810cecf9d5Sandi 68271352defSandi //output formatted 683a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6840cecf9d5Sandi } 6850cecf9d5Sandi 6864826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 687dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 6883685f775Sandi global $conf; 68937e34a5eSandi global $ID; 69037e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6910cecf9d5Sandi 6923685f775Sandi $link = array(); 6933685f775Sandi $link['class'] = 'media'; 6943685f775Sandi $link['style'] = ''; 6953685f775Sandi $link['pre'] = ''; 6963685f775Sandi $link['suf'] = ''; 6975e163278SAndreas Gohr $link['more'] = ''; 6983685f775Sandi $link['target'] = $conf['target']['media']; 699d98d4540SBen Coburn $noLink = false; 7003685f775Sandi 701433bef32Sandi $link['title'] = $this->_xmlEntities($src); 70255efc227SAndreas Gohr list($ext,$mime) = mimetype($src); 7035667eb65SAndreas Gohr if(substr($mime,0,5) == 'image'){ 704dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7052ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7062ca14335SEsther Brunner // don't link flash movies 70744881bd0Shenning.noren $noLink = true; 70855efc227SAndreas Gohr }else{ 7092ca14335SEsther Brunner // add file icons 7109d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7119d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7126de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 71355efc227SAndreas Gohr } 714433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 7153685f775Sandi 7163685f775Sandi //output formatted 717dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7182ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7190cecf9d5Sandi } 7200cecf9d5Sandi 7210cecf9d5Sandi /** 7224826ab45Sandi * @todo don't add link for flash 7230cecf9d5Sandi */ 7244826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 725dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 7263685f775Sandi global $conf; 7270cecf9d5Sandi 7283685f775Sandi $link = array(); 7293685f775Sandi $link['class'] = 'media'; 7303685f775Sandi $link['style'] = ''; 7313685f775Sandi $link['pre'] = ''; 7323685f775Sandi $link['suf'] = ''; 7335e163278SAndreas Gohr $link['more'] = ''; 7343685f775Sandi $link['target'] = $conf['target']['media']; 7353685f775Sandi 736433bef32Sandi $link['title'] = $this->_xmlEntities($src); 7376de3759aSAndreas Gohr $link['url'] = ml($src,array('cache'=>$cache)); 738433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 739d98d4540SBen Coburn $noLink = false; 7403685f775Sandi 7412ca14335SEsther Brunner list($ext,$mime) = mimetype($src); 7422ca14335SEsther Brunner if(substr($mime,0,5) == 'image'){ 7432ca14335SEsther Brunner // link only jpeg images 74444881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7452ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7462ca14335SEsther Brunner // don't link flash movies 74744881bd0Shenning.noren $noLink = true; 7482ca14335SEsther Brunner }else{ 7492ca14335SEsther Brunner // add file icons 750d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7512ca14335SEsther Brunner } 7522ca14335SEsther Brunner 7533685f775Sandi //output formatted 754dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7552ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7560cecf9d5Sandi } 7570cecf9d5Sandi 7584826ab45Sandi /** 7593db95becSAndreas Gohr * Renders an RSS feed 760b625487dSandi * 761b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 762b625487dSandi */ 7633db95becSAndreas Gohr function rss ($url,$params){ 764b625487dSandi global $lang; 7653db95becSAndreas Gohr global $conf; 7663db95becSAndreas Gohr 7673db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7683db95becSAndreas Gohr $feed = new FeedParser(); 7693db95becSAndreas Gohr $feed->feed_url($url); 770b625487dSandi 771b625487dSandi //disable warning while fetching 772bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7733db95becSAndreas Gohr $rc = $feed->init(); 774bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 775b625487dSandi 7763db95becSAndreas Gohr //decide on start and end 7773db95becSAndreas Gohr if($params['reverse']){ 7783db95becSAndreas Gohr $mod = -1; 7793db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7803db95becSAndreas Gohr $end = $start - ($params['max']); 781b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7823db95becSAndreas Gohr }else{ 7833db95becSAndreas Gohr $mod = 1; 7843db95becSAndreas Gohr $start = 0; 7853db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7863db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7873db95becSAndreas Gohr } 7883db95becSAndreas Gohr 789a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7903db95becSAndreas Gohr if($rc){ 7913db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7921bde1582SAndreas Gohr $item = $feed->get_item($x); 7933db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 7941bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 7951bde1582SAndreas Gohr $item->get_title()); 7963db95becSAndreas Gohr if($params['author']){ 7971bde1582SAndreas Gohr $author = $item->get_author(0); 7981bde1582SAndreas Gohr if($author){ 7991bde1582SAndreas Gohr $name = $author->get_name(); 8001bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 8011bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8021bde1582SAndreas Gohr } 8033db95becSAndreas Gohr } 8043db95becSAndreas Gohr if($params['date']){ 8051bde1582SAndreas Gohr $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 8063db95becSAndreas Gohr } 8071bde1582SAndreas Gohr if($params['details']){ 8083db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 8093db95becSAndreas Gohr if($htmlok){ 8101bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8113db95becSAndreas Gohr }else{ 8121bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8133db95becSAndreas Gohr } 8143db95becSAndreas Gohr $this->doc .= '</div>'; 8153db95becSAndreas Gohr } 8163db95becSAndreas Gohr 8173db95becSAndreas Gohr $this->doc .= '</div></li>'; 818b625487dSandi } 819b625487dSandi }else{ 8203db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 821a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 822b625487dSandi $this->externallink($url); 82345e147ccSAndreas Gohr if($conf['allowdebug']){ 82445e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 82545e147ccSAndreas Gohr } 8263db95becSAndreas Gohr $this->doc .= '</div></li>'; 827b625487dSandi } 828a2d649c4Sandi $this->doc .= '</ul>'; 829b625487dSandi } 830b625487dSandi 8310cecf9d5Sandi // $numrows not yet implemented 8320cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 833a2d649c4Sandi $this->doc .= '<table class="inline">'.DOKU_LF; 8340cecf9d5Sandi } 8350cecf9d5Sandi 8360cecf9d5Sandi function table_close(){ 837cb42b03dSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8380cecf9d5Sandi } 8390cecf9d5Sandi 8400cecf9d5Sandi function tablerow_open(){ 841a2d649c4Sandi $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8420cecf9d5Sandi } 8430cecf9d5Sandi 8440cecf9d5Sandi function tablerow_close(){ 845a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8460cecf9d5Sandi } 8470cecf9d5Sandi 8480cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 849a2d649c4Sandi $this->doc .= '<th'; 8500cecf9d5Sandi if ( !is_null($align) ) { 851a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8520cecf9d5Sandi } 8530cecf9d5Sandi if ( $colspan > 1 ) { 854a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8550cecf9d5Sandi } 856a2d649c4Sandi $this->doc .= '>'; 8570cecf9d5Sandi } 8580cecf9d5Sandi 8590cecf9d5Sandi function tableheader_close(){ 860a2d649c4Sandi $this->doc .= '</th>'; 8610cecf9d5Sandi } 8620cecf9d5Sandi 8630cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 864a2d649c4Sandi $this->doc .= '<td'; 8650cecf9d5Sandi if ( !is_null($align) ) { 866a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8670cecf9d5Sandi } 8680cecf9d5Sandi if ( $colspan > 1 ) { 869a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8700cecf9d5Sandi } 871a2d649c4Sandi $this->doc .= '>'; 8720cecf9d5Sandi } 8730cecf9d5Sandi 8740cecf9d5Sandi function tablecell_close(){ 875a2d649c4Sandi $this->doc .= '</td>'; 8760cecf9d5Sandi } 8770cecf9d5Sandi 8780cecf9d5Sandi //---------------------------------------------------------- 8790cecf9d5Sandi // Utils 8800cecf9d5Sandi 881ba11bd29Sandi /** 8823fd0b676Sandi * Build a link 8833fd0b676Sandi * 8843fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 885ba11bd29Sandi * 886ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 887ba11bd29Sandi */ 888433bef32Sandi function _formatLink($link){ 889ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 890ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 891ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 892ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 893ba11bd29Sandi } 894ba11bd29Sandi //remove double encodings in titles 895ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 896ba11bd29Sandi 897453493f2SAndreas Gohr // be sure there are no bad chars in url or title 898453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 899453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 900453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 901453493f2SAndreas Gohr 902ba11bd29Sandi $ret = ''; 903ba11bd29Sandi $ret .= $link['pre']; 904ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 905bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 906bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 907bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 908bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 909bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 910ba11bd29Sandi $ret .= '>'; 911ba11bd29Sandi $ret .= $link['name']; 912ba11bd29Sandi $ret .= '</a>'; 913ba11bd29Sandi $ret .= $link['suf']; 914ba11bd29Sandi return $ret; 915ba11bd29Sandi } 916ba11bd29Sandi 917ba11bd29Sandi /** 9183fd0b676Sandi * Renders internal and external media 9193fd0b676Sandi * 9203fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9213fd0b676Sandi */ 9223fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 9233fd0b676Sandi $height=NULL, $cache=NULL) { 9243fd0b676Sandi 9253fd0b676Sandi $ret = ''; 9263fd0b676Sandi 9273fd0b676Sandi list($ext,$mime) = mimetype($src); 9283fd0b676Sandi if(substr($mime,0,5) == 'image'){ 9293fd0b676Sandi //add image tag 9306de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9313fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9323fd0b676Sandi 933*4ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 934*4ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 935*4ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 936*4ab889eaSAndreas Gohr 9373fd0b676Sandi if (!is_null($title)) { 9383fd0b676Sandi $ret .= ' title="'.$this->_xmlEntities($title).'"'; 9393fd0b676Sandi $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 94055efc227SAndreas Gohr }elseif($ext == 'jpg' || $ext == 'jpeg'){ 94155efc227SAndreas Gohr //try to use the caption from IPTC/EXIF 94255efc227SAndreas Gohr require_once(DOKU_INC.'inc/JpegMeta.php'); 94355efc227SAndreas Gohr $jpeg =& new JpegMeta(mediaFN($src)); 94455efc227SAndreas Gohr if($jpeg !== false) $cap = $jpeg->getTitle(); 94555efc227SAndreas Gohr if($cap){ 94655efc227SAndreas Gohr $ret .= ' title="'.$this->_xmlEntities($cap).'"'; 94755efc227SAndreas Gohr $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; 948fcf1ccdcSAndreas Gohr }else{ 949fcf1ccdcSAndreas Gohr $ret .= ' alt=""'; 95055efc227SAndreas Gohr } 9513fd0b676Sandi }else{ 9523fd0b676Sandi $ret .= ' alt=""'; 9533fd0b676Sandi } 9543fd0b676Sandi 9553fd0b676Sandi if ( !is_null($width) ) 9563fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9573fd0b676Sandi 9583fd0b676Sandi if ( !is_null($height) ) 9593fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9603fd0b676Sandi 9613fd0b676Sandi $ret .= ' />'; 9623fd0b676Sandi 9633fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9643fd0b676Sandi $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 9653fd0b676Sandi ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 9663fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9673fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9683fd0b676Sandi $ret .= '>'.DOKU_LF; 9696de3759aSAndreas Gohr $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 9703fd0b676Sandi $ret .= '<param name="quality" value="high" />'.DOKU_LF; 9716de3759aSAndreas Gohr $ret .= '<embed src="'.ml($src).'"'. 9723fd0b676Sandi ' quality="high"'; 9733fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9743fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9753fd0b676Sandi $ret .= ' type="application/x-shockwave-flash"'. 9763fd0b676Sandi ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 9773fd0b676Sandi $ret .= '</object>'.DOKU_LF; 9783fd0b676Sandi 9790f428d7dSAndreas Gohr }elseif($title){ 9803fd0b676Sandi // well at least we have a title to display 9813fd0b676Sandi $ret .= $this->_xmlEntities($title); 9823fd0b676Sandi }else{ 9835291ca3aSAndreas Gohr // just show the sourcename 9840f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 9853fd0b676Sandi } 9863fd0b676Sandi 9873fd0b676Sandi return $ret; 9883fd0b676Sandi } 9893fd0b676Sandi 990433bef32Sandi function _xmlEntities($string) { 991de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 9920cecf9d5Sandi } 9930cecf9d5Sandi 9948a831f2bSAndreas Gohr /** 9958a831f2bSAndreas Gohr * Creates a linkid from a headline 996c5a8fd96SAndreas Gohr * 997c5a8fd96SAndreas Gohr * @param string $title The headline title 998c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 999c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 10008a831f2bSAndreas Gohr */ 1001c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1002501af51eSAndreas Gohr $title = str_replace(':','',cleanID($title)); 1003a9e0fd1bSAndreas Gohr $title = ltrim($title,'0123456789._-'); 10048a831f2bSAndreas Gohr if(empty($title)) $title='section'; 1005c5a8fd96SAndreas Gohr 1006c5a8fd96SAndreas Gohr if($create){ 1007c5a8fd96SAndreas Gohr // make sure tiles are unique 1008c5a8fd96SAndreas Gohr $num = ''; 1009c5a8fd96SAndreas Gohr while(in_array($title.$num,$this->headers)){ 10100affd488SAndreas Gohr ($num) ? $num++ : $num = 1; 1011c5a8fd96SAndreas Gohr } 1012c5a8fd96SAndreas Gohr $title = $title.$num; 1013c5a8fd96SAndreas Gohr $this->headers[] = $title; 1014c5a8fd96SAndreas Gohr } 1015c5a8fd96SAndreas Gohr 10168a831f2bSAndreas Gohr return $title; 10170cecf9d5Sandi } 10180cecf9d5Sandi 1019af587fa8Sandi /** 10203fd0b676Sandi * Construct a title and handle images in titles 10213fd0b676Sandi * 10220b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10233fd0b676Sandi */ 1024433bef32Sandi function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 1025bb0a59d4Sjan global $conf; 1026bb0a59d4Sjan 102744881bd0Shenning.noren $isImage = false; 10280cecf9d5Sandi if ( is_null($title) ) { 1029bb0a59d4Sjan if ($conf['useheading'] && $id) { 1030fc18c0fbSchris $heading = p_get_first_heading($id,true); 1031bb0a59d4Sjan if ($heading) { 1032433bef32Sandi return $this->_xmlEntities($heading); 1033bb0a59d4Sjan } 1034bb0a59d4Sjan } 1035433bef32Sandi return $this->_xmlEntities($default); 10360cecf9d5Sandi } else if ( is_string($title) ) { 1037433bef32Sandi return $this->_xmlEntities($title); 10380cecf9d5Sandi } else if ( is_array($title) ) { 103944881bd0Shenning.noren $isImage = true; 1040433bef32Sandi return $this->_imageTitle($title); 10410cecf9d5Sandi } 10420cecf9d5Sandi } 10430cecf9d5Sandi 10440cecf9d5Sandi /** 10453fd0b676Sandi * Returns an HTML code for images used in link titles 10463fd0b676Sandi * 10473fd0b676Sandi * @todo Resolve namespace on internal images 10483fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10490cecf9d5Sandi */ 1050433bef32Sandi function _imageTitle($img) { 1051433bef32Sandi return $this->_media($img['src'], 10524826ab45Sandi $img['title'], 10534826ab45Sandi $img['align'], 10544826ab45Sandi $img['width'], 10554826ab45Sandi $img['height'], 10564826ab45Sandi $img['cache']); 10570cecf9d5Sandi } 10580cecf9d5Sandi} 10590cecf9d5Sandi 10604826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1061