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; 104c5a8fd96SAndreas Gohr $out = '<div class="toc">'.DOKU_LF; 105c5a8fd96SAndreas Gohr $out .= '<div class="tocheader toctoggle" id="toc__header">'; 106c5a8fd96SAndreas Gohr $out .= $lang['toc']; 107c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF; 108c5a8fd96SAndreas Gohr $out .= '<div id="toc__inside">'.DOKU_LF; 109169c7240Schris $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem')); 110c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 111c5a8fd96SAndreas Gohr return $out; 112c5a8fd96SAndreas Gohr } 113c5a8fd96SAndreas Gohr 114c5a8fd96SAndreas Gohr /** 115c5a8fd96SAndreas Gohr * Callback for html_buildlist 116c5a8fd96SAndreas Gohr */ 117c5a8fd96SAndreas Gohr function _tocitem($item){ 118c5a8fd96SAndreas Gohr return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'. 119169c7240Schris Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>'; 120c5a8fd96SAndreas Gohr } 121c5a8fd96SAndreas Gohr 122e7856beaSchris function toc_additem($id, $text, $level) { 123af587fa8Sandi global $conf; 124af587fa8Sandi 125c5a8fd96SAndreas Gohr //handle TOC 126c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 127c5a8fd96SAndreas Gohr // the TOC is one of our standard ul list arrays ;-) 128e7856beaSchris $this->toc[] = array( 'hid' => $id, 129c5a8fd96SAndreas Gohr 'title' => $text, 130c5a8fd96SAndreas Gohr 'type' => 'ul', 13121ed2ba4Sjan 'level' => $level-$conf['toptoclevel']+1); 132c5a8fd96SAndreas Gohr } 133e7856beaSchris } 134e7856beaSchris 135e7856beaSchris function header($text, $level, $pos) { 136e7856beaSchris 137e7856beaSchris $hid = $this->_headerToLink($text,true); 138e7856beaSchris 139e7856beaSchris //only add items within configured levels 140e7856beaSchris $this->toc_additem($hid, $text, $level); 141c5a8fd96SAndreas Gohr 142c5a8fd96SAndreas Gohr // write the header 143c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 144a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 145c6a1c1bfSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1460cecf9d5Sandi } 1470cecf9d5Sandi 14835dae8b0SBen Coburn /** 14935dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 15035dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 15135dae8b0SBen Coburn * 15235dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 15335dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 15435dae8b0SBen Coburn */ 15535dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 15635dae8b0SBen Coburn global $conf; 15735dae8b0SBen Coburn 15835dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 15935dae8b0SBen Coburn $name = str_replace('"', '', $name); 16035dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 16135dae8b0SBen Coburn } 16235dae8b0SBen Coburn } 16335dae8b0SBen Coburn 1640cecf9d5Sandi function section_open($level) { 165a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1660cecf9d5Sandi } 1670cecf9d5Sandi 1680cecf9d5Sandi function section_close() { 169a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1700cecf9d5Sandi } 1710cecf9d5Sandi 1720cecf9d5Sandi function cdata($text) { 173a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1740cecf9d5Sandi } 1750cecf9d5Sandi 1760cecf9d5Sandi function p_open() { 177a2d649c4Sandi $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1780cecf9d5Sandi } 1790cecf9d5Sandi 1800cecf9d5Sandi function p_close() { 181a2d649c4Sandi $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1820cecf9d5Sandi } 1830cecf9d5Sandi 1840cecf9d5Sandi function linebreak() { 185a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1860cecf9d5Sandi } 1870cecf9d5Sandi 1880cecf9d5Sandi function hr() { 1894beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1900cecf9d5Sandi } 1910cecf9d5Sandi 1920cecf9d5Sandi function strong_open() { 193a2d649c4Sandi $this->doc .= '<strong>'; 1940cecf9d5Sandi } 1950cecf9d5Sandi 1960cecf9d5Sandi function strong_close() { 197a2d649c4Sandi $this->doc .= '</strong>'; 1980cecf9d5Sandi } 1990cecf9d5Sandi 2000cecf9d5Sandi function emphasis_open() { 201a2d649c4Sandi $this->doc .= '<em>'; 2020cecf9d5Sandi } 2030cecf9d5Sandi 2040cecf9d5Sandi function emphasis_close() { 205a2d649c4Sandi $this->doc .= '</em>'; 2060cecf9d5Sandi } 2070cecf9d5Sandi 2080cecf9d5Sandi function underline_open() { 20902e51121SAnika Henke $this->doc .= '<em class="u">'; 2100cecf9d5Sandi } 2110cecf9d5Sandi 2120cecf9d5Sandi function underline_close() { 21302e51121SAnika Henke $this->doc .= '</em>'; 2140cecf9d5Sandi } 2150cecf9d5Sandi 2160cecf9d5Sandi function monospace_open() { 217a2d649c4Sandi $this->doc .= '<code>'; 2180cecf9d5Sandi } 2190cecf9d5Sandi 2200cecf9d5Sandi function monospace_close() { 221a2d649c4Sandi $this->doc .= '</code>'; 2220cecf9d5Sandi } 2230cecf9d5Sandi 2240cecf9d5Sandi function subscript_open() { 225a2d649c4Sandi $this->doc .= '<sub>'; 2260cecf9d5Sandi } 2270cecf9d5Sandi 2280cecf9d5Sandi function subscript_close() { 229a2d649c4Sandi $this->doc .= '</sub>'; 2300cecf9d5Sandi } 2310cecf9d5Sandi 2320cecf9d5Sandi function superscript_open() { 233a2d649c4Sandi $this->doc .= '<sup>'; 2340cecf9d5Sandi } 2350cecf9d5Sandi 2360cecf9d5Sandi function superscript_close() { 237a2d649c4Sandi $this->doc .= '</sup>'; 2380cecf9d5Sandi } 2390cecf9d5Sandi 2400cecf9d5Sandi function deleted_open() { 241a2d649c4Sandi $this->doc .= '<del>'; 2420cecf9d5Sandi } 2430cecf9d5Sandi 2440cecf9d5Sandi function deleted_close() { 245a2d649c4Sandi $this->doc .= '</del>'; 2460cecf9d5Sandi } 2470cecf9d5Sandi 2483fd0b676Sandi /** 2493fd0b676Sandi * Callback for footnote start syntax 2503fd0b676Sandi * 2513fd0b676Sandi * All following content will go to the footnote instead of 252d74aace9Schris * the document. To achieve this the previous rendered content 2533fd0b676Sandi * is moved to $store and $doc is cleared 2543fd0b676Sandi * 2553fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2563fd0b676Sandi */ 2570cecf9d5Sandi function footnote_open() { 2587764a90aSandi 2597764a90aSandi // move current content to store and record footnote 2607764a90aSandi $this->store = $this->doc; 2617764a90aSandi $this->doc = ''; 2620cecf9d5Sandi } 2630cecf9d5Sandi 2643fd0b676Sandi /** 2653fd0b676Sandi * Callback for footnote end syntax 2663fd0b676Sandi * 2673fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2683fd0b676Sandi * content is restored from $store again 2693fd0b676Sandi * 2703fd0b676Sandi * @author Andreas Gohr 2713fd0b676Sandi */ 2720cecf9d5Sandi function footnote_close() { 2737764a90aSandi 274d74aace9Schris // recover footnote into the stack and restore old content 275d74aace9Schris $footnote = $this->doc; 2767764a90aSandi $this->doc = $this->store; 2777764a90aSandi $this->store = ''; 278d74aace9Schris 279d74aace9Schris // check to see if this footnote has been seen before 280d74aace9Schris $i = array_search($footnote, $this->footnotes); 281d74aace9Schris 282d74aace9Schris if ($i === false) { 283d74aace9Schris // its a new footnote, add it to the $footnotes array 284d74aace9Schris $id = count($this->footnotes)+1; 285d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 286d74aace9Schris } else { 287d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 288d74aace9Schris $i++; 289d74aace9Schris $id = count($this->footnotes)+1; 290d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 291d74aace9Schris } 292d74aace9Schris 2936b379cbfSAndreas Gohr // output the footnote reference and link 2946b379cbfSAndreas Gohr $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>'; 2950cecf9d5Sandi } 2960cecf9d5Sandi 2970cecf9d5Sandi function listu_open() { 298a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2990cecf9d5Sandi } 3000cecf9d5Sandi 3010cecf9d5Sandi function listu_close() { 302a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3030cecf9d5Sandi } 3040cecf9d5Sandi 3050cecf9d5Sandi function listo_open() { 306a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3070cecf9d5Sandi } 3080cecf9d5Sandi 3090cecf9d5Sandi function listo_close() { 310a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3110cecf9d5Sandi } 3120cecf9d5Sandi 3130cecf9d5Sandi function listitem_open($level) { 314a2d649c4Sandi $this->doc .= '<li class="level'.$level.'">'; 3150cecf9d5Sandi } 3160cecf9d5Sandi 3170cecf9d5Sandi function listitem_close() { 318a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3190cecf9d5Sandi } 3200cecf9d5Sandi 3210cecf9d5Sandi function listcontent_open() { 32290db23d7Schris $this->doc .= '<div class="li">'; 3230cecf9d5Sandi } 3240cecf9d5Sandi 3250cecf9d5Sandi function listcontent_close() { 32690db23d7Schris $this->doc .= '</div>'.DOKU_LF; 3270cecf9d5Sandi } 3280cecf9d5Sandi 3290cecf9d5Sandi function unformatted($text) { 330a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3310cecf9d5Sandi } 3320cecf9d5Sandi 3330cecf9d5Sandi /** 3343fd0b676Sandi * Execute PHP code if allowed 3353fd0b676Sandi * 3363fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3370cecf9d5Sandi */ 3380cecf9d5Sandi function php($text) { 3394de671bcSandi global $conf; 3404de671bcSandi if($conf['phpok']){ 341bad0b545Sandi ob_start(); 3424de671bcSandi eval($text); 3433fd0b676Sandi $this->doc .= ob_get_contents(); 344bad0b545Sandi ob_end_clean(); 3454de671bcSandi }else{ 3464de671bcSandi $this->file($text); 3474de671bcSandi } 3480cecf9d5Sandi } 3490cecf9d5Sandi 3500cecf9d5Sandi /** 3513fd0b676Sandi * Insert HTML if allowed 3523fd0b676Sandi * 3533fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3540cecf9d5Sandi */ 3550cecf9d5Sandi function html($text) { 3564de671bcSandi global $conf; 3574de671bcSandi if($conf['htmlok']){ 358a2d649c4Sandi $this->doc .= $text; 3594de671bcSandi }else{ 3600cecf9d5Sandi $this->file($text); 3610cecf9d5Sandi } 3624de671bcSandi } 3630cecf9d5Sandi 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 458*57d757d1SAndreas Gohr function apostrophe() { 459*57d757d1SAndreas Gohr global $lang; 460*57d757d1SAndreas Gohr $this->doc .= $lang['singlequoteclosing']; 461*57d757d1SAndreas Gohr } 462*57d757d1SAndreas 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); 5030339c872Sjan // now first resolve and clean up the $id 50437e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 5050339c872Sjan $name = $this->_getLinkTitle($name, $default, $isImage, $id); 5060e1c636eSandi if ( !$isImage ) { 5070e1c636eSandi if ( $exists ) { 508ba11bd29Sandi $class='wikilink1'; 5090cecf9d5Sandi } else { 510ba11bd29Sandi $class='wikilink2'; 5110cecf9d5Sandi } 5120cecf9d5Sandi } else { 513ba11bd29Sandi $class='media'; 5140cecf9d5Sandi } 5150cecf9d5Sandi 516a1685bedSandi //keep hash anchor 517ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 518a1685bedSandi 519ba11bd29Sandi //prepare for formating 520ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 521ba11bd29Sandi $link['style'] = ''; 522ba11bd29Sandi $link['pre'] = ''; 523ba11bd29Sandi $link['suf'] = ''; 52440eb54bbSjan // highlight link to current page 52540eb54bbSjan if ($id == $ID) { 52692795d04Sandi $link['pre'] = '<span class="curid">'; 52792795d04Sandi $link['suf'] = '</span>'; 52840eb54bbSjan } 5295e163278SAndreas Gohr $link['more'] = ''; 530ba11bd29Sandi $link['class'] = $class; 531ba11bd29Sandi $link['url'] = wl($id); 532ba11bd29Sandi $link['name'] = $name; 533ba11bd29Sandi $link['title'] = $id; 534723d78dbSandi //add search string 535723d78dbSandi if($search){ 536723d78dbSandi ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 537b6c6979fSAndreas Gohr $link['url'] .= rawurlencode($search); 538723d78dbSandi } 539723d78dbSandi 540a1685bedSandi //keep hash 541a1685bedSandi if($hash) $link['url'].='#'.$hash; 542a1685bedSandi 543ba11bd29Sandi //output formatted 544cffcc403Sandi if($returnonly){ 545cffcc403Sandi return $this->_formatLink($link); 546cffcc403Sandi }else{ 547a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5480cecf9d5Sandi } 549cffcc403Sandi } 5500cecf9d5Sandi 551b625487dSandi function externallink($url, $name = NULL) { 552b625487dSandi global $conf; 5530cecf9d5Sandi 554433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5556f0c5dbfSandi 5560cecf9d5Sandi if ( !$isImage ) { 557b625487dSandi $class='urlextern'; 5580cecf9d5Sandi } else { 559b625487dSandi $class='media'; 5600cecf9d5Sandi } 5610cecf9d5Sandi 562b625487dSandi //prepare for formating 563b625487dSandi $link['target'] = $conf['target']['extern']; 564b625487dSandi $link['style'] = ''; 565b625487dSandi $link['pre'] = ''; 566b625487dSandi $link['suf'] = ''; 5675e163278SAndreas Gohr $link['more'] = ''; 568b625487dSandi $link['class'] = $class; 569b625487dSandi $link['url'] = $url; 570e1c10e4dSchris 571b625487dSandi $link['name'] = $name; 572433bef32Sandi $link['title'] = $this->_xmlEntities($url); 573b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5740cecf9d5Sandi 575b625487dSandi //output formatted 576a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5770cecf9d5Sandi } 5780cecf9d5Sandi 5790cecf9d5Sandi /** 5800cecf9d5Sandi */ 58197a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 582b625487dSandi global $conf; 5830cecf9d5Sandi 58497a3e4e3Sandi $link = array(); 58597a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 58697a3e4e3Sandi $link['pre'] = ''; 58797a3e4e3Sandi $link['suf'] = ''; 5885e163278SAndreas Gohr $link['more'] = ''; 589433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5900cecf9d5Sandi 59197a3e4e3Sandi //get interwiki URL 5921f82fabeSAndreas Gohr $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 5930cecf9d5Sandi 59497a3e4e3Sandi if ( !$isImage ) { 5959d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5969d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5971c2d1019SAndreas Gohr } else { 5981c2d1019SAndreas Gohr $link['class'] = 'media'; 59997a3e4e3Sandi } 6000cecf9d5Sandi 60197a3e4e3Sandi //do we stay at the same server? Use local target 60297a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 60397a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 60497a3e4e3Sandi } 6050cecf9d5Sandi 60697a3e4e3Sandi $link['url'] = $url; 60797a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 60897a3e4e3Sandi 60997a3e4e3Sandi //output formatted 610a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6110cecf9d5Sandi } 6120cecf9d5Sandi 6130cecf9d5Sandi /** 6140cecf9d5Sandi */ 6151d47afe1Sandi function windowssharelink($url, $name = NULL) { 6161d47afe1Sandi global $conf; 6171d47afe1Sandi global $lang; 6181d47afe1Sandi //simple setup 6191d47afe1Sandi $link['target'] = $conf['target']['windows']; 6201d47afe1Sandi $link['pre'] = ''; 6211d47afe1Sandi $link['suf'] = ''; 6221d47afe1Sandi $link['style'] = ''; 6231d47afe1Sandi //Display error on browsers other than IE 6241d47afe1Sandi $link['more'] = 'onclick="if(document.all == null){alert(\''. 625433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES). 6261d47afe1Sandi '\');}" onkeypress="if(document.all == null){alert(\''. 627433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"'; 6280cecf9d5Sandi 629433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6300cecf9d5Sandi if ( !$isImage ) { 6311d47afe1Sandi $link['class'] = 'windows'; 6320cecf9d5Sandi } else { 6331d47afe1Sandi $link['class'] = 'media'; 6340cecf9d5Sandi } 6350cecf9d5Sandi 6360cecf9d5Sandi 637433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6381d47afe1Sandi $url = str_replace('\\','/',$url); 6391d47afe1Sandi $url = 'file:///'.$url; 6401d47afe1Sandi $link['url'] = $url; 6410cecf9d5Sandi 6421d47afe1Sandi //output formatted 643a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6440cecf9d5Sandi } 6450cecf9d5Sandi 64671352defSandi function emaillink($address, $name = NULL) { 64771352defSandi global $conf; 64871352defSandi //simple setup 64971352defSandi $link = array(); 65071352defSandi $link['target'] = ''; 65171352defSandi $link['pre'] = ''; 65271352defSandi $link['suf'] = ''; 65371352defSandi $link['style'] = ''; 65471352defSandi $link['more'] = ''; 6550cecf9d5Sandi 656c6e62e9fSchris $name = $this->_getLinkTitle($name, '', $isImage); 6570cecf9d5Sandi if ( !$isImage ) { 658776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6590cecf9d5Sandi } else { 660776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6610cecf9d5Sandi } 6620cecf9d5Sandi 66307738714SAndreas Gohr $address = $this->_xmlEntities($address); 66400a7b5adSEsther Brunner $address = obfuscate($address); 66500a7b5adSEsther Brunner $title = $address; 6668c128049SAndreas Gohr 66771352defSandi if(empty($name)){ 66800a7b5adSEsther Brunner $name = $address; 66971352defSandi } 6708c128049SAndreas Gohr#elseif($isImage{ 6718c128049SAndreas Gohr# $name = $this->_xmlEntities($name); 6728c128049SAndreas Gohr# } 6730cecf9d5Sandi 674776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 675776b36ecSAndreas Gohr 676776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 67771352defSandi $link['name'] = $name; 67871352defSandi $link['title'] = $title; 6790cecf9d5Sandi 68071352defSandi //output formatted 681a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6820cecf9d5Sandi } 6830cecf9d5Sandi 6844826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 685dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 6863685f775Sandi global $conf; 68737e34a5eSandi global $ID; 68837e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6890cecf9d5Sandi 6903685f775Sandi $link = array(); 6913685f775Sandi $link['class'] = 'media'; 6923685f775Sandi $link['style'] = ''; 6933685f775Sandi $link['pre'] = ''; 6943685f775Sandi $link['suf'] = ''; 6955e163278SAndreas Gohr $link['more'] = ''; 6963685f775Sandi $link['target'] = $conf['target']['media']; 697d98d4540SBen Coburn $noLink = false; 6983685f775Sandi 699433bef32Sandi $link['title'] = $this->_xmlEntities($src); 70055efc227SAndreas Gohr list($ext,$mime) = mimetype($src); 7015667eb65SAndreas Gohr if(substr($mime,0,5) == 'image'){ 702dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 7032ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7042ca14335SEsther Brunner // don't link flash movies 70544881bd0Shenning.noren $noLink = true; 70655efc227SAndreas Gohr }else{ 7072ca14335SEsther Brunner // add file icons 7089d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 7099d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 7106de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 71155efc227SAndreas Gohr } 712433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 7133685f775Sandi 7143685f775Sandi //output formatted 715dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7162ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7170cecf9d5Sandi } 7180cecf9d5Sandi 7190cecf9d5Sandi /** 7204826ab45Sandi * @todo don't add link for flash 7210cecf9d5Sandi */ 7224826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 723dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 7243685f775Sandi global $conf; 7250cecf9d5Sandi 7263685f775Sandi $link = array(); 7273685f775Sandi $link['class'] = 'media'; 7283685f775Sandi $link['style'] = ''; 7293685f775Sandi $link['pre'] = ''; 7303685f775Sandi $link['suf'] = ''; 7315e163278SAndreas Gohr $link['more'] = ''; 7323685f775Sandi $link['target'] = $conf['target']['media']; 7333685f775Sandi 734433bef32Sandi $link['title'] = $this->_xmlEntities($src); 7356de3759aSAndreas Gohr $link['url'] = ml($src,array('cache'=>$cache)); 736433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 737d98d4540SBen Coburn $noLink = false; 7383685f775Sandi 7392ca14335SEsther Brunner list($ext,$mime) = mimetype($src); 7402ca14335SEsther Brunner if(substr($mime,0,5) == 'image'){ 7412ca14335SEsther Brunner // link only jpeg images 74244881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7432ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7442ca14335SEsther Brunner // don't link flash movies 74544881bd0Shenning.noren $noLink = true; 7462ca14335SEsther Brunner }else{ 7472ca14335SEsther Brunner // add file icons 748d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7492ca14335SEsther Brunner } 7502ca14335SEsther Brunner 7513685f775Sandi //output formatted 752dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7532ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7540cecf9d5Sandi } 7550cecf9d5Sandi 7564826ab45Sandi /** 7573db95becSAndreas Gohr * Renders an RSS feed 758b625487dSandi * 759b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 760b625487dSandi */ 7613db95becSAndreas Gohr function rss ($url,$params){ 762b625487dSandi global $lang; 7633db95becSAndreas Gohr global $conf; 7643db95becSAndreas Gohr 7653db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7663db95becSAndreas Gohr $feed = new FeedParser(); 7673db95becSAndreas Gohr $feed->feed_url($url); 768b625487dSandi 769b625487dSandi //disable warning while fetching 770bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7713db95becSAndreas Gohr $rc = $feed->init(); 772bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 773b625487dSandi 7743db95becSAndreas Gohr //decide on start and end 7753db95becSAndreas Gohr if($params['reverse']){ 7763db95becSAndreas Gohr $mod = -1; 7773db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7783db95becSAndreas Gohr $end = $start - ($params['max']); 779b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7803db95becSAndreas Gohr }else{ 7813db95becSAndreas Gohr $mod = 1; 7823db95becSAndreas Gohr $start = 0; 7833db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7843db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7853db95becSAndreas Gohr } 7863db95becSAndreas Gohr 787a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7883db95becSAndreas Gohr if($rc){ 7893db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7901bde1582SAndreas Gohr $item = $feed->get_item($x); 7913db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 7921bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 7931bde1582SAndreas Gohr $item->get_title()); 7943db95becSAndreas Gohr if($params['author']){ 7951bde1582SAndreas Gohr $author = $item->get_author(0); 7961bde1582SAndreas Gohr if($author){ 7971bde1582SAndreas Gohr $name = $author->get_name(); 7981bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 7991bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 8001bde1582SAndreas Gohr } 8013db95becSAndreas Gohr } 8023db95becSAndreas Gohr if($params['date']){ 8031bde1582SAndreas Gohr $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 8043db95becSAndreas Gohr } 8051bde1582SAndreas Gohr if($params['details']){ 8063db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 8073db95becSAndreas Gohr if($htmlok){ 8081bde1582SAndreas Gohr $this->doc .= $item->get_description(); 8093db95becSAndreas Gohr }else{ 8101bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 8113db95becSAndreas Gohr } 8123db95becSAndreas Gohr $this->doc .= '</div>'; 8133db95becSAndreas Gohr } 8143db95becSAndreas Gohr 8153db95becSAndreas Gohr $this->doc .= '</div></li>'; 816b625487dSandi } 817b625487dSandi }else{ 8183db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 819a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 820b625487dSandi $this->externallink($url); 8213db95becSAndreas Gohr $this->doc .= '</div></li>'; 822b625487dSandi } 823a2d649c4Sandi $this->doc .= '</ul>'; 824b625487dSandi } 825b625487dSandi 8260cecf9d5Sandi // $numrows not yet implemented 8270cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 828a2d649c4Sandi $this->doc .= '<table class="inline">'.DOKU_LF; 8290cecf9d5Sandi } 8300cecf9d5Sandi 8310cecf9d5Sandi function table_close(){ 832cb42b03dSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8330cecf9d5Sandi } 8340cecf9d5Sandi 8350cecf9d5Sandi function tablerow_open(){ 836a2d649c4Sandi $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8370cecf9d5Sandi } 8380cecf9d5Sandi 8390cecf9d5Sandi function tablerow_close(){ 840a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8410cecf9d5Sandi } 8420cecf9d5Sandi 8430cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 844a2d649c4Sandi $this->doc .= '<th'; 8450cecf9d5Sandi if ( !is_null($align) ) { 846a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8470cecf9d5Sandi } 8480cecf9d5Sandi if ( $colspan > 1 ) { 849a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8500cecf9d5Sandi } 851a2d649c4Sandi $this->doc .= '>'; 8520cecf9d5Sandi } 8530cecf9d5Sandi 8540cecf9d5Sandi function tableheader_close(){ 855a2d649c4Sandi $this->doc .= '</th>'; 8560cecf9d5Sandi } 8570cecf9d5Sandi 8580cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 859a2d649c4Sandi $this->doc .= '<td'; 8600cecf9d5Sandi if ( !is_null($align) ) { 861a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8620cecf9d5Sandi } 8630cecf9d5Sandi if ( $colspan > 1 ) { 864a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8650cecf9d5Sandi } 866a2d649c4Sandi $this->doc .= '>'; 8670cecf9d5Sandi } 8680cecf9d5Sandi 8690cecf9d5Sandi function tablecell_close(){ 870a2d649c4Sandi $this->doc .= '</td>'; 8710cecf9d5Sandi } 8720cecf9d5Sandi 8730cecf9d5Sandi //---------------------------------------------------------- 8740cecf9d5Sandi // Utils 8750cecf9d5Sandi 876ba11bd29Sandi /** 8773fd0b676Sandi * Build a link 8783fd0b676Sandi * 8793fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 880ba11bd29Sandi * 881ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 882ba11bd29Sandi */ 883433bef32Sandi function _formatLink($link){ 884ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 885ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 886ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 887ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 888ba11bd29Sandi } 889ba11bd29Sandi //remove double encodings in titles 890ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 891ba11bd29Sandi 892453493f2SAndreas Gohr // be sure there are no bad chars in url or title 893453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 894453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 895453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 896453493f2SAndreas Gohr 897ba11bd29Sandi $ret = ''; 898ba11bd29Sandi $ret .= $link['pre']; 899ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 900bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 901bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 902bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 903bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 904bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 905ba11bd29Sandi $ret .= '>'; 906ba11bd29Sandi $ret .= $link['name']; 907ba11bd29Sandi $ret .= '</a>'; 908ba11bd29Sandi $ret .= $link['suf']; 909ba11bd29Sandi return $ret; 910ba11bd29Sandi } 911ba11bd29Sandi 912ba11bd29Sandi /** 9133fd0b676Sandi * Renders internal and external media 9143fd0b676Sandi * 9153fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9163fd0b676Sandi */ 9173fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 9183fd0b676Sandi $height=NULL, $cache=NULL) { 9193fd0b676Sandi 9203fd0b676Sandi $ret = ''; 9213fd0b676Sandi 9223fd0b676Sandi list($ext,$mime) = mimetype($src); 9233fd0b676Sandi if(substr($mime,0,5) == 'image'){ 9243fd0b676Sandi //add image tag 9256de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9263fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9273fd0b676Sandi 9283fd0b676Sandi if (!is_null($title)) { 9293fd0b676Sandi $ret .= ' title="'.$this->_xmlEntities($title).'"'; 9303fd0b676Sandi $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 93155efc227SAndreas Gohr }elseif($ext == 'jpg' || $ext == 'jpeg'){ 93255efc227SAndreas Gohr //try to use the caption from IPTC/EXIF 93355efc227SAndreas Gohr require_once(DOKU_INC.'inc/JpegMeta.php'); 93455efc227SAndreas Gohr $jpeg =& new JpegMeta(mediaFN($src)); 93555efc227SAndreas Gohr if($jpeg !== false) $cap = $jpeg->getTitle(); 93655efc227SAndreas Gohr if($cap){ 93755efc227SAndreas Gohr $ret .= ' title="'.$this->_xmlEntities($cap).'"'; 93855efc227SAndreas Gohr $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; 939fcf1ccdcSAndreas Gohr }else{ 940fcf1ccdcSAndreas Gohr $ret .= ' alt=""'; 94155efc227SAndreas Gohr } 9423fd0b676Sandi }else{ 9433fd0b676Sandi $ret .= ' alt=""'; 9443fd0b676Sandi } 9453fd0b676Sandi 9463fd0b676Sandi if ( !is_null($width) ) 9473fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9483fd0b676Sandi 9493fd0b676Sandi if ( !is_null($height) ) 9503fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9513fd0b676Sandi 9523fd0b676Sandi $ret .= ' />'; 9533fd0b676Sandi 9543fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9553fd0b676Sandi $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 9563fd0b676Sandi ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 9573fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9583fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9593fd0b676Sandi $ret .= '>'.DOKU_LF; 9606de3759aSAndreas Gohr $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 9613fd0b676Sandi $ret .= '<param name="quality" value="high" />'.DOKU_LF; 9626de3759aSAndreas Gohr $ret .= '<embed src="'.ml($src).'"'. 9633fd0b676Sandi ' quality="high"'; 9643fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9653fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9663fd0b676Sandi $ret .= ' type="application/x-shockwave-flash"'. 9673fd0b676Sandi ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 9683fd0b676Sandi $ret .= '</object>'.DOKU_LF; 9693fd0b676Sandi 9700f428d7dSAndreas Gohr }elseif($title){ 9713fd0b676Sandi // well at least we have a title to display 9723fd0b676Sandi $ret .= $this->_xmlEntities($title); 9733fd0b676Sandi }else{ 9745291ca3aSAndreas Gohr // just show the sourcename 9750f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 9763fd0b676Sandi } 9773fd0b676Sandi 9783fd0b676Sandi return $ret; 9793fd0b676Sandi } 9803fd0b676Sandi 981433bef32Sandi function _xmlEntities($string) { 982de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 9830cecf9d5Sandi } 9840cecf9d5Sandi 9858a831f2bSAndreas Gohr /** 9868a831f2bSAndreas Gohr * Creates a linkid from a headline 987c5a8fd96SAndreas Gohr * 988c5a8fd96SAndreas Gohr * @param string $title The headline title 989c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 990c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 9918a831f2bSAndreas Gohr */ 992c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 993501af51eSAndreas Gohr $title = str_replace(':','',cleanID($title)); 994a9e0fd1bSAndreas Gohr $title = ltrim($title,'0123456789._-'); 9958a831f2bSAndreas Gohr if(empty($title)) $title='section'; 996c5a8fd96SAndreas Gohr 997c5a8fd96SAndreas Gohr if($create){ 998c5a8fd96SAndreas Gohr // make sure tiles are unique 999c5a8fd96SAndreas Gohr $num = ''; 1000c5a8fd96SAndreas Gohr while(in_array($title.$num,$this->headers)){ 10010affd488SAndreas Gohr ($num) ? $num++ : $num = 1; 1002c5a8fd96SAndreas Gohr } 1003c5a8fd96SAndreas Gohr $title = $title.$num; 1004c5a8fd96SAndreas Gohr $this->headers[] = $title; 1005c5a8fd96SAndreas Gohr } 1006c5a8fd96SAndreas Gohr 10078a831f2bSAndreas Gohr return $title; 10080cecf9d5Sandi } 10090cecf9d5Sandi 1010af587fa8Sandi /** 10113fd0b676Sandi * Construct a title and handle images in titles 10123fd0b676Sandi * 10130b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10143fd0b676Sandi */ 1015433bef32Sandi function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 1016bb0a59d4Sjan global $conf; 1017bb0a59d4Sjan 101844881bd0Shenning.noren $isImage = false; 10190cecf9d5Sandi if ( is_null($title) ) { 1020bb0a59d4Sjan if ($conf['useheading'] && $id) { 1021fc18c0fbSchris $heading = p_get_first_heading($id,true); 1022bb0a59d4Sjan if ($heading) { 1023433bef32Sandi return $this->_xmlEntities($heading); 1024bb0a59d4Sjan } 1025bb0a59d4Sjan } 1026433bef32Sandi return $this->_xmlEntities($default); 10270cecf9d5Sandi } else if ( is_string($title) ) { 1028433bef32Sandi return $this->_xmlEntities($title); 10290cecf9d5Sandi } else if ( is_array($title) ) { 103044881bd0Shenning.noren $isImage = true; 1031433bef32Sandi return $this->_imageTitle($title); 10320cecf9d5Sandi } 10330cecf9d5Sandi } 10340cecf9d5Sandi 10350cecf9d5Sandi /** 10363fd0b676Sandi * Returns an HTML code for images used in link titles 10373fd0b676Sandi * 10383fd0b676Sandi * @todo Resolve namespace on internal images 10393fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10400cecf9d5Sandi */ 1041433bef32Sandi function _imageTitle($img) { 1042433bef32Sandi return $this->_media($img['src'], 10434826ab45Sandi $img['title'], 10444826ab45Sandi $img['align'], 10454826ab45Sandi $img['width'], 10464826ab45Sandi $img['height'], 10474826ab45Sandi $img['cache']); 10480cecf9d5Sandi } 10490cecf9d5Sandi} 10500cecf9d5Sandi 10514826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1052