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 390cecf9d5Sandi function document_start() { 40c5a8fd96SAndreas Gohr //reset some internals 41c5a8fd96SAndreas Gohr $this->toc = array(); 42c5a8fd96SAndreas Gohr $this->headers = array(); 430cecf9d5Sandi } 440cecf9d5Sandi 450cecf9d5Sandi function document_end() { 460cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 47a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 48d74aace9Schris 49d74aace9Schris $id = 0; 500cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 51d74aace9Schris $id++; // the number of the current footnote 52d74aace9Schris 53d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 54d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 55d74aace9Schris 56d74aace9Schris // open the footnote and set the anchor and backlink 57d74aace9Schris $this->doc .= '<div class="fn">'; 5824a33b42SAndreas Gohr $this->doc .= '<a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 59d74aace9Schris $this->doc .= $id.')</a> '.DOKU_LF; 60d74aace9Schris 61d74aace9Schris // get any other footnotes that use the same markup 62d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 63d74aace9Schris 64d74aace9Schris if (count($alt)) { 65d74aace9Schris foreach ($alt as $ref) { 66d74aace9Schris // set anchor and backlink for the other footnotes 6724a33b42SAndreas Gohr $this->doc .= ', <a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 68d74aace9Schris $this->doc .= ($ref+1).')</a> '.DOKU_LF; 69d74aace9Schris } 70d74aace9Schris } 71d74aace9Schris 72d74aace9Schris // add footnote markup and close this footnote 73a2d649c4Sandi $this->doc .= $footnote; 74d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 75d74aace9Schris } 760cecf9d5Sandi } 77a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 780cecf9d5Sandi } 79c5a8fd96SAndreas Gohr 80c5a8fd96SAndreas Gohr // prepend the TOC 81e41c4da9SAndreas Gohr if($this->info['toc']){ 82169c7240Schris $this->doc = $this->render_TOC($this->toc).$this->doc; 830cecf9d5Sandi } 843e55d035SAndreas Gohr 853e55d035SAndreas Gohr // make sure there are no empty paragraphs 8627918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 87e41c4da9SAndreas Gohr } 880cecf9d5Sandi 89c5a8fd96SAndreas Gohr /** 90c5a8fd96SAndreas Gohr * Return the TOC rendered to XHTML 91c5a8fd96SAndreas Gohr * 92c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 93c5a8fd96SAndreas Gohr */ 94*dd5eee54SAndreas Gohr function render_TOC($toc=null){ 95*dd5eee54SAndreas Gohr if(is_null($toc) && is_array($this->toc)) $toc = $this->toc; 96*dd5eee54SAndreas Gohr 97169c7240Schris if(count($toc) < 3) return ''; 98c5a8fd96SAndreas Gohr global $lang; 99c5a8fd96SAndreas Gohr $out = '<div class="toc">'.DOKU_LF; 100c5a8fd96SAndreas Gohr $out .= '<div class="tocheader toctoggle" id="toc__header">'; 101c5a8fd96SAndreas Gohr $out .= $lang['toc']; 102c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF; 103c5a8fd96SAndreas Gohr $out .= '<div id="toc__inside">'.DOKU_LF; 104169c7240Schris $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem')); 105c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 106c5a8fd96SAndreas Gohr return $out; 107c5a8fd96SAndreas Gohr } 108c5a8fd96SAndreas Gohr 109c5a8fd96SAndreas Gohr /** 110c5a8fd96SAndreas Gohr * Callback for html_buildlist 111c5a8fd96SAndreas Gohr */ 112c5a8fd96SAndreas Gohr function _tocitem($item){ 113c5a8fd96SAndreas Gohr return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'. 114169c7240Schris Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>'; 115c5a8fd96SAndreas Gohr } 116c5a8fd96SAndreas Gohr 117e7856beaSchris function toc_additem($id, $text, $level) { 118af587fa8Sandi global $conf; 119af587fa8Sandi 120c5a8fd96SAndreas Gohr //handle TOC 121c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 122c5a8fd96SAndreas Gohr // the TOC is one of our standard ul list arrays ;-) 123e7856beaSchris $this->toc[] = array( 'hid' => $id, 124c5a8fd96SAndreas Gohr 'title' => $text, 125c5a8fd96SAndreas Gohr 'type' => 'ul', 12621ed2ba4Sjan 'level' => $level-$conf['toptoclevel']+1); 127c5a8fd96SAndreas Gohr } 128e7856beaSchris } 129e7856beaSchris 130e7856beaSchris function header($text, $level, $pos) { 131e7856beaSchris 132e7856beaSchris $hid = $this->_headerToLink($text,true); 133e7856beaSchris 134e7856beaSchris //only add items within configured levels 135e7856beaSchris $this->toc_additem($hid, $text, $level); 136c5a8fd96SAndreas Gohr 137c5a8fd96SAndreas Gohr // write the header 138c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 139a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 140c6a1c1bfSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1410cecf9d5Sandi } 1420cecf9d5Sandi 14335dae8b0SBen Coburn /** 14435dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 14535dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 14635dae8b0SBen Coburn * 14735dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 14835dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 14935dae8b0SBen Coburn */ 15035dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 15135dae8b0SBen Coburn global $conf; 15235dae8b0SBen Coburn 15335dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 15435dae8b0SBen Coburn $name = str_replace('"', '', $name); 15535dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 15635dae8b0SBen Coburn } 15735dae8b0SBen Coburn } 15835dae8b0SBen Coburn 1590cecf9d5Sandi function section_open($level) { 160a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1610cecf9d5Sandi } 1620cecf9d5Sandi 1630cecf9d5Sandi function section_close() { 164a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1650cecf9d5Sandi } 1660cecf9d5Sandi 1670cecf9d5Sandi function cdata($text) { 168a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1690cecf9d5Sandi } 1700cecf9d5Sandi 1710cecf9d5Sandi function p_open() { 172a2d649c4Sandi $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1730cecf9d5Sandi } 1740cecf9d5Sandi 1750cecf9d5Sandi function p_close() { 176a2d649c4Sandi $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1770cecf9d5Sandi } 1780cecf9d5Sandi 1790cecf9d5Sandi function linebreak() { 180a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1810cecf9d5Sandi } 1820cecf9d5Sandi 1830cecf9d5Sandi function hr() { 1844beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1850cecf9d5Sandi } 1860cecf9d5Sandi 1870cecf9d5Sandi function strong_open() { 188a2d649c4Sandi $this->doc .= '<strong>'; 1890cecf9d5Sandi } 1900cecf9d5Sandi 1910cecf9d5Sandi function strong_close() { 192a2d649c4Sandi $this->doc .= '</strong>'; 1930cecf9d5Sandi } 1940cecf9d5Sandi 1950cecf9d5Sandi function emphasis_open() { 196a2d649c4Sandi $this->doc .= '<em>'; 1970cecf9d5Sandi } 1980cecf9d5Sandi 1990cecf9d5Sandi function emphasis_close() { 200a2d649c4Sandi $this->doc .= '</em>'; 2010cecf9d5Sandi } 2020cecf9d5Sandi 2030cecf9d5Sandi function underline_open() { 20402e51121SAnika Henke $this->doc .= '<em class="u">'; 2050cecf9d5Sandi } 2060cecf9d5Sandi 2070cecf9d5Sandi function underline_close() { 20802e51121SAnika Henke $this->doc .= '</em>'; 2090cecf9d5Sandi } 2100cecf9d5Sandi 2110cecf9d5Sandi function monospace_open() { 212a2d649c4Sandi $this->doc .= '<code>'; 2130cecf9d5Sandi } 2140cecf9d5Sandi 2150cecf9d5Sandi function monospace_close() { 216a2d649c4Sandi $this->doc .= '</code>'; 2170cecf9d5Sandi } 2180cecf9d5Sandi 2190cecf9d5Sandi function subscript_open() { 220a2d649c4Sandi $this->doc .= '<sub>'; 2210cecf9d5Sandi } 2220cecf9d5Sandi 2230cecf9d5Sandi function subscript_close() { 224a2d649c4Sandi $this->doc .= '</sub>'; 2250cecf9d5Sandi } 2260cecf9d5Sandi 2270cecf9d5Sandi function superscript_open() { 228a2d649c4Sandi $this->doc .= '<sup>'; 2290cecf9d5Sandi } 2300cecf9d5Sandi 2310cecf9d5Sandi function superscript_close() { 232a2d649c4Sandi $this->doc .= '</sup>'; 2330cecf9d5Sandi } 2340cecf9d5Sandi 2350cecf9d5Sandi function deleted_open() { 236a2d649c4Sandi $this->doc .= '<del>'; 2370cecf9d5Sandi } 2380cecf9d5Sandi 2390cecf9d5Sandi function deleted_close() { 240a2d649c4Sandi $this->doc .= '</del>'; 2410cecf9d5Sandi } 2420cecf9d5Sandi 2433fd0b676Sandi /** 2443fd0b676Sandi * Callback for footnote start syntax 2453fd0b676Sandi * 2463fd0b676Sandi * All following content will go to the footnote instead of 247d74aace9Schris * the document. To achieve this the previous rendered content 2483fd0b676Sandi * is moved to $store and $doc is cleared 2493fd0b676Sandi * 2503fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2513fd0b676Sandi */ 2520cecf9d5Sandi function footnote_open() { 2537764a90aSandi 2547764a90aSandi // move current content to store and record footnote 2557764a90aSandi $this->store = $this->doc; 2567764a90aSandi $this->doc = ''; 2570cecf9d5Sandi } 2580cecf9d5Sandi 2593fd0b676Sandi /** 2603fd0b676Sandi * Callback for footnote end syntax 2613fd0b676Sandi * 2623fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2633fd0b676Sandi * content is restored from $store again 2643fd0b676Sandi * 2653fd0b676Sandi * @author Andreas Gohr 2663fd0b676Sandi */ 2670cecf9d5Sandi function footnote_close() { 2687764a90aSandi 269d74aace9Schris // recover footnote into the stack and restore old content 270d74aace9Schris $footnote = $this->doc; 2717764a90aSandi $this->doc = $this->store; 2727764a90aSandi $this->store = ''; 273d74aace9Schris 274d74aace9Schris // check to see if this footnote has been seen before 275d74aace9Schris $i = array_search($footnote, $this->footnotes); 276d74aace9Schris 277d74aace9Schris if ($i === false) { 278d74aace9Schris // its a new footnote, add it to the $footnotes array 279d74aace9Schris $id = count($this->footnotes)+1; 280d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 281d74aace9Schris } else { 282d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 283d74aace9Schris $i++; 284d74aace9Schris $id = count($this->footnotes)+1; 285d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 286d74aace9Schris } 287d74aace9Schris 2886b379cbfSAndreas Gohr // output the footnote reference and link 2896b379cbfSAndreas Gohr $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>'; 2900cecf9d5Sandi } 2910cecf9d5Sandi 2920cecf9d5Sandi function listu_open() { 293a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2940cecf9d5Sandi } 2950cecf9d5Sandi 2960cecf9d5Sandi function listu_close() { 297a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 2980cecf9d5Sandi } 2990cecf9d5Sandi 3000cecf9d5Sandi function listo_open() { 301a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3020cecf9d5Sandi } 3030cecf9d5Sandi 3040cecf9d5Sandi function listo_close() { 305a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3060cecf9d5Sandi } 3070cecf9d5Sandi 3080cecf9d5Sandi function listitem_open($level) { 309a2d649c4Sandi $this->doc .= '<li class="level'.$level.'">'; 3100cecf9d5Sandi } 3110cecf9d5Sandi 3120cecf9d5Sandi function listitem_close() { 313a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3140cecf9d5Sandi } 3150cecf9d5Sandi 3160cecf9d5Sandi function listcontent_open() { 31790db23d7Schris $this->doc .= '<div class="li">'; 3180cecf9d5Sandi } 3190cecf9d5Sandi 3200cecf9d5Sandi function listcontent_close() { 32190db23d7Schris $this->doc .= '</div>'.DOKU_LF; 3220cecf9d5Sandi } 3230cecf9d5Sandi 3240cecf9d5Sandi function unformatted($text) { 325a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3260cecf9d5Sandi } 3270cecf9d5Sandi 3280cecf9d5Sandi /** 3293fd0b676Sandi * Execute PHP code if allowed 3303fd0b676Sandi * 3313fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3320cecf9d5Sandi */ 3330cecf9d5Sandi function php($text) { 3344de671bcSandi global $conf; 3354de671bcSandi if($conf['phpok']){ 336bad0b545Sandi ob_start(); 3374de671bcSandi eval($text); 3383fd0b676Sandi $this->doc .= ob_get_contents(); 339bad0b545Sandi ob_end_clean(); 3404de671bcSandi }else{ 3414de671bcSandi $this->file($text); 3424de671bcSandi } 3430cecf9d5Sandi } 3440cecf9d5Sandi 3450cecf9d5Sandi /** 3463fd0b676Sandi * Insert HTML if allowed 3473fd0b676Sandi * 3483fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3490cecf9d5Sandi */ 3500cecf9d5Sandi function html($text) { 3514de671bcSandi global $conf; 3524de671bcSandi if($conf['htmlok']){ 353a2d649c4Sandi $this->doc .= $text; 3544de671bcSandi }else{ 3550cecf9d5Sandi $this->file($text); 3560cecf9d5Sandi } 3574de671bcSandi } 3580cecf9d5Sandi 3590cecf9d5Sandi function preformatted($text) { 360a2d649c4Sandi $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 3610cecf9d5Sandi } 3620cecf9d5Sandi 3630cecf9d5Sandi function file($text) { 364a2d649c4Sandi $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 3650cecf9d5Sandi } 3660cecf9d5Sandi 3670cecf9d5Sandi function quote_open() { 36896331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3690cecf9d5Sandi } 3700cecf9d5Sandi 3710cecf9d5Sandi function quote_close() { 37296331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3730cecf9d5Sandi } 3740cecf9d5Sandi 3750cecf9d5Sandi /** 3763fd0b676Sandi * Callback for code text 3773fd0b676Sandi * 3783fd0b676Sandi * Uses GeSHi to highlight language syntax 3793fd0b676Sandi * 3803fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3810cecf9d5Sandi */ 3820cecf9d5Sandi function code($text, $language = NULL) { 3834de671bcSandi global $conf; 3840cecf9d5Sandi 3850cecf9d5Sandi if ( is_null($language) ) { 3860cecf9d5Sandi $this->preformatted($text); 3870cecf9d5Sandi } else { 388852896daSAndreas Gohr //strip leading and trailing blank line 389313da78aSandi $text = preg_replace('/^\s*?\n/','',$text); 390852896daSAndreas Gohr $text = preg_replace('/\s*?\n$/','',$text); 3918f7d700cSchris $this->doc .= p_xhtml_cached_geshi($text, $language); 3920cecf9d5Sandi } 3930cecf9d5Sandi } 3940cecf9d5Sandi 3950cecf9d5Sandi function acronym($acronym) { 3960cecf9d5Sandi 3970cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 3980cecf9d5Sandi 399433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4000cecf9d5Sandi 401a2d649c4Sandi $this->doc .= '<acronym title="'.$title 402433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 4030cecf9d5Sandi 4040cecf9d5Sandi } else { 405a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4060cecf9d5Sandi } 4070cecf9d5Sandi } 4080cecf9d5Sandi 4090cecf9d5Sandi function smiley($smiley) { 4100cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 411433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 412f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4134beabca9SAnika Henke '" class="middle" alt="'. 414433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4150cecf9d5Sandi } else { 416a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4170cecf9d5Sandi } 4180cecf9d5Sandi } 4190cecf9d5Sandi 420f62ea8a1Sandi /* 4214de671bcSandi * not used 4220cecf9d5Sandi function wordblock($word) { 4230cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 424a2d649c4Sandi $this->doc .= '** BLEEP **'; 4250cecf9d5Sandi } else { 426a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4270cecf9d5Sandi } 4280cecf9d5Sandi } 4294de671bcSandi */ 4300cecf9d5Sandi 4310cecf9d5Sandi function entity($entity) { 4320cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 433a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4340cecf9d5Sandi } else { 435a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4360cecf9d5Sandi } 4370cecf9d5Sandi } 4380cecf9d5Sandi 4390cecf9d5Sandi function multiplyentity($x, $y) { 440a2d649c4Sandi $this->doc .= "$x×$y"; 4410cecf9d5Sandi } 4420cecf9d5Sandi 4430cecf9d5Sandi function singlequoteopening() { 444a2d649c4Sandi $this->doc .= "‘"; 4450cecf9d5Sandi } 4460cecf9d5Sandi 4470cecf9d5Sandi function singlequoteclosing() { 448a2d649c4Sandi $this->doc .= "’"; 4490cecf9d5Sandi } 4500cecf9d5Sandi 4510cecf9d5Sandi function doublequoteopening() { 452a2d649c4Sandi $this->doc .= "“"; 4530cecf9d5Sandi } 4540cecf9d5Sandi 4550cecf9d5Sandi function doublequoteclosing() { 456a2d649c4Sandi $this->doc .= "”"; 4570cecf9d5Sandi } 4580cecf9d5Sandi 4590cecf9d5Sandi /** 4600cecf9d5Sandi */ 4610cecf9d5Sandi function camelcaselink($link) { 46211d0aa47Sandi $this->internallink($link,$link); 4630cecf9d5Sandi } 4640cecf9d5Sandi 4650b7c14c2Sandi 4660b7c14c2Sandi function locallink($hash, $name = NULL){ 4670b7c14c2Sandi global $ID; 4680b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4690b7c14c2Sandi $hash = $this->_headerToLink($hash); 4700b7c14c2Sandi $title = $ID.' ↵'; 4710b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 4720b7c14c2Sandi $this->doc .= $name; 4730b7c14c2Sandi $this->doc .= '</a>'; 4740b7c14c2Sandi } 4750b7c14c2Sandi 476cffcc403Sandi /** 4773fd0b676Sandi * Render an internal Wiki Link 4783fd0b676Sandi * 479cffcc403Sandi * $search and $returnonly are not for the renderer but are used 480cffcc403Sandi * elsewhere - no need to implement them in other renderers 4813fd0b676Sandi * 4823fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 483cffcc403Sandi */ 484cffcc403Sandi function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 485ba11bd29Sandi global $conf; 48637e34a5eSandi global $ID; 4870339c872Sjan // default name is based on $id as given 4880339c872Sjan $default = $this->_simpleTitle($id); 4890339c872Sjan // now first resolve and clean up the $id 49037e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 4910339c872Sjan $name = $this->_getLinkTitle($name, $default, $isImage, $id); 4920e1c636eSandi if ( !$isImage ) { 4930e1c636eSandi if ( $exists ) { 494ba11bd29Sandi $class='wikilink1'; 4950cecf9d5Sandi } else { 496ba11bd29Sandi $class='wikilink2'; 4970cecf9d5Sandi } 4980cecf9d5Sandi } else { 499ba11bd29Sandi $class='media'; 5000cecf9d5Sandi } 5010cecf9d5Sandi 502a1685bedSandi //keep hash anchor 503ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 504a1685bedSandi 505ba11bd29Sandi //prepare for formating 506ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 507ba11bd29Sandi $link['style'] = ''; 508ba11bd29Sandi $link['pre'] = ''; 509ba11bd29Sandi $link['suf'] = ''; 51040eb54bbSjan // highlight link to current page 51140eb54bbSjan if ($id == $ID) { 51292795d04Sandi $link['pre'] = '<span class="curid">'; 51392795d04Sandi $link['suf'] = '</span>'; 51440eb54bbSjan } 5155e163278SAndreas Gohr $link['more'] = ''; 516ba11bd29Sandi $link['class'] = $class; 517ba11bd29Sandi $link['url'] = wl($id); 518ba11bd29Sandi $link['name'] = $name; 519ba11bd29Sandi $link['title'] = $id; 520723d78dbSandi //add search string 521723d78dbSandi if($search){ 522723d78dbSandi ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 523b6c6979fSAndreas Gohr $link['url'] .= rawurlencode($search); 524723d78dbSandi } 525723d78dbSandi 526a1685bedSandi //keep hash 527a1685bedSandi if($hash) $link['url'].='#'.$hash; 528a1685bedSandi 529ba11bd29Sandi //output formatted 530cffcc403Sandi if($returnonly){ 531cffcc403Sandi return $this->_formatLink($link); 532cffcc403Sandi }else{ 533a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5340cecf9d5Sandi } 535cffcc403Sandi } 5360cecf9d5Sandi 537b625487dSandi function externallink($url, $name = NULL) { 538b625487dSandi global $conf; 5390cecf9d5Sandi 540433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5416f0c5dbfSandi 5420cecf9d5Sandi if ( !$isImage ) { 543b625487dSandi $class='urlextern'; 5440cecf9d5Sandi } else { 545b625487dSandi $class='media'; 5460cecf9d5Sandi } 5470cecf9d5Sandi 548b625487dSandi //prepare for formating 549b625487dSandi $link['target'] = $conf['target']['extern']; 550b625487dSandi $link['style'] = ''; 551b625487dSandi $link['pre'] = ''; 552b625487dSandi $link['suf'] = ''; 5535e163278SAndreas Gohr $link['more'] = ''; 554b625487dSandi $link['class'] = $class; 555b625487dSandi $link['url'] = $url; 556e1c10e4dSchris 557b625487dSandi $link['name'] = $name; 558433bef32Sandi $link['title'] = $this->_xmlEntities($url); 559b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5600cecf9d5Sandi 561b625487dSandi //output formatted 562a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5630cecf9d5Sandi } 5640cecf9d5Sandi 5650cecf9d5Sandi /** 5660cecf9d5Sandi */ 56797a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 568b625487dSandi global $conf; 5690cecf9d5Sandi 57097a3e4e3Sandi $link = array(); 57197a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 57297a3e4e3Sandi $link['pre'] = ''; 57397a3e4e3Sandi $link['suf'] = ''; 5745e163278SAndreas Gohr $link['more'] = ''; 575433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5760cecf9d5Sandi 57797a3e4e3Sandi //get interwiki URL 5781f82fabeSAndreas Gohr $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 5790cecf9d5Sandi 58097a3e4e3Sandi if ( !$isImage ) { 5819d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5829d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5831c2d1019SAndreas Gohr } else { 5841c2d1019SAndreas Gohr $link['class'] = 'media'; 58597a3e4e3Sandi } 5860cecf9d5Sandi 58797a3e4e3Sandi //do we stay at the same server? Use local target 58897a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 58997a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 59097a3e4e3Sandi } 5910cecf9d5Sandi 59297a3e4e3Sandi $link['url'] = $url; 59397a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 59497a3e4e3Sandi 59597a3e4e3Sandi //output formatted 596a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5970cecf9d5Sandi } 5980cecf9d5Sandi 5990cecf9d5Sandi /** 6000cecf9d5Sandi */ 6011d47afe1Sandi function windowssharelink($url, $name = NULL) { 6021d47afe1Sandi global $conf; 6031d47afe1Sandi global $lang; 6041d47afe1Sandi //simple setup 6051d47afe1Sandi $link['target'] = $conf['target']['windows']; 6061d47afe1Sandi $link['pre'] = ''; 6071d47afe1Sandi $link['suf'] = ''; 6081d47afe1Sandi $link['style'] = ''; 6091d47afe1Sandi //Display error on browsers other than IE 6101d47afe1Sandi $link['more'] = 'onclick="if(document.all == null){alert(\''. 611433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES). 6121d47afe1Sandi '\');}" onkeypress="if(document.all == null){alert(\''. 613433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"'; 6140cecf9d5Sandi 615433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6160cecf9d5Sandi if ( !$isImage ) { 6171d47afe1Sandi $link['class'] = 'windows'; 6180cecf9d5Sandi } else { 6191d47afe1Sandi $link['class'] = 'media'; 6200cecf9d5Sandi } 6210cecf9d5Sandi 6220cecf9d5Sandi 623433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6241d47afe1Sandi $url = str_replace('\\','/',$url); 6251d47afe1Sandi $url = 'file:///'.$url; 6261d47afe1Sandi $link['url'] = $url; 6270cecf9d5Sandi 6281d47afe1Sandi //output formatted 629a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6300cecf9d5Sandi } 6310cecf9d5Sandi 63271352defSandi function emaillink($address, $name = NULL) { 63371352defSandi global $conf; 63471352defSandi //simple setup 63571352defSandi $link = array(); 63671352defSandi $link['target'] = ''; 63771352defSandi $link['pre'] = ''; 63871352defSandi $link['suf'] = ''; 63971352defSandi $link['style'] = ''; 64071352defSandi $link['more'] = ''; 6410cecf9d5Sandi 642c6e62e9fSchris $name = $this->_getLinkTitle($name, '', $isImage); 6430cecf9d5Sandi if ( !$isImage ) { 644776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6450cecf9d5Sandi } else { 646776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6470cecf9d5Sandi } 6480cecf9d5Sandi 64907738714SAndreas Gohr $address = $this->_xmlEntities($address); 65000a7b5adSEsther Brunner $address = obfuscate($address); 65100a7b5adSEsther Brunner $title = $address; 6528c128049SAndreas Gohr 65371352defSandi if(empty($name)){ 65400a7b5adSEsther Brunner $name = $address; 65571352defSandi } 6568c128049SAndreas Gohr#elseif($isImage{ 6578c128049SAndreas Gohr# $name = $this->_xmlEntities($name); 6588c128049SAndreas Gohr# } 6590cecf9d5Sandi 660776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 661776b36ecSAndreas Gohr 662776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 66371352defSandi $link['name'] = $name; 66471352defSandi $link['title'] = $title; 6650cecf9d5Sandi 66671352defSandi //output formatted 667a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6680cecf9d5Sandi } 6690cecf9d5Sandi 6704826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 671dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 6723685f775Sandi global $conf; 67337e34a5eSandi global $ID; 67437e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6750cecf9d5Sandi 6763685f775Sandi $link = array(); 6773685f775Sandi $link['class'] = 'media'; 6783685f775Sandi $link['style'] = ''; 6793685f775Sandi $link['pre'] = ''; 6803685f775Sandi $link['suf'] = ''; 6815e163278SAndreas Gohr $link['more'] = ''; 6823685f775Sandi $link['target'] = $conf['target']['media']; 683d98d4540SBen Coburn $noLink = false; 6843685f775Sandi 685433bef32Sandi $link['title'] = $this->_xmlEntities($src); 68655efc227SAndreas Gohr list($ext,$mime) = mimetype($src); 6875667eb65SAndreas Gohr if(substr($mime,0,5) == 'image'){ 688dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 6892ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 6902ca14335SEsther Brunner // don't link flash movies 69144881bd0Shenning.noren $noLink = true; 69255efc227SAndreas Gohr }else{ 6932ca14335SEsther Brunner // add file icons 6949d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 6959d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 6966de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 69755efc227SAndreas Gohr } 698433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 6993685f775Sandi 7003685f775Sandi //output formatted 701dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7022ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7030cecf9d5Sandi } 7040cecf9d5Sandi 7050cecf9d5Sandi /** 7064826ab45Sandi * @todo don't add link for flash 7070cecf9d5Sandi */ 7084826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 709dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 7103685f775Sandi global $conf; 7110cecf9d5Sandi 7123685f775Sandi $link = array(); 7133685f775Sandi $link['class'] = 'media'; 7143685f775Sandi $link['style'] = ''; 7153685f775Sandi $link['pre'] = ''; 7163685f775Sandi $link['suf'] = ''; 7175e163278SAndreas Gohr $link['more'] = ''; 7183685f775Sandi $link['target'] = $conf['target']['media']; 7193685f775Sandi 720433bef32Sandi $link['title'] = $this->_xmlEntities($src); 7216de3759aSAndreas Gohr $link['url'] = ml($src,array('cache'=>$cache)); 722433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 723d98d4540SBen Coburn $noLink = false; 7243685f775Sandi 7252ca14335SEsther Brunner list($ext,$mime) = mimetype($src); 7262ca14335SEsther Brunner if(substr($mime,0,5) == 'image'){ 7272ca14335SEsther Brunner // link only jpeg images 72844881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7292ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7302ca14335SEsther Brunner // don't link flash movies 73144881bd0Shenning.noren $noLink = true; 7322ca14335SEsther Brunner }else{ 7332ca14335SEsther Brunner // add file icons 734d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7352ca14335SEsther Brunner } 7362ca14335SEsther Brunner 7373685f775Sandi //output formatted 738dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7392ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7400cecf9d5Sandi } 7410cecf9d5Sandi 7424826ab45Sandi /** 7433db95becSAndreas Gohr * Renders an RSS feed 744b625487dSandi * 745b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 746b625487dSandi */ 7473db95becSAndreas Gohr function rss ($url,$params){ 748b625487dSandi global $lang; 7493db95becSAndreas Gohr global $conf; 7503db95becSAndreas Gohr 7513db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7523db95becSAndreas Gohr $feed = new FeedParser(); 7533db95becSAndreas Gohr $feed->feed_url($url); 754b625487dSandi 755b625487dSandi //disable warning while fetching 756bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7573db95becSAndreas Gohr $rc = $feed->init(); 758bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 759b625487dSandi 7603db95becSAndreas Gohr //decide on start and end 7613db95becSAndreas Gohr if($params['reverse']){ 7623db95becSAndreas Gohr $mod = -1; 7633db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7643db95becSAndreas Gohr $end = $start - ($params['max']); 765b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7663db95becSAndreas Gohr }else{ 7673db95becSAndreas Gohr $mod = 1; 7683db95becSAndreas Gohr $start = 0; 7693db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7703db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7713db95becSAndreas Gohr } 7723db95becSAndreas Gohr 773a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7743db95becSAndreas Gohr if($rc){ 7753db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7761bde1582SAndreas Gohr $item = $feed->get_item($x); 7773db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 7781bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 7791bde1582SAndreas Gohr $item->get_title()); 7803db95becSAndreas Gohr if($params['author']){ 7811bde1582SAndreas Gohr $author = $item->get_author(0); 7821bde1582SAndreas Gohr if($author){ 7831bde1582SAndreas Gohr $name = $author->get_name(); 7841bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 7851bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 7861bde1582SAndreas Gohr } 7873db95becSAndreas Gohr } 7883db95becSAndreas Gohr if($params['date']){ 7891bde1582SAndreas Gohr $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 7903db95becSAndreas Gohr } 7911bde1582SAndreas Gohr if($params['details']){ 7923db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 7933db95becSAndreas Gohr if($htmlok){ 7941bde1582SAndreas Gohr $this->doc .= $item->get_description(); 7953db95becSAndreas Gohr }else{ 7961bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 7973db95becSAndreas Gohr } 7983db95becSAndreas Gohr $this->doc .= '</div>'; 7993db95becSAndreas Gohr } 8003db95becSAndreas Gohr 8013db95becSAndreas Gohr $this->doc .= '</div></li>'; 802b625487dSandi } 803b625487dSandi }else{ 8043db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 805a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 806b625487dSandi $this->externallink($url); 8073db95becSAndreas Gohr $this->doc .= '</div></li>'; 808b625487dSandi } 809a2d649c4Sandi $this->doc .= '</ul>'; 810b625487dSandi } 811b625487dSandi 8120cecf9d5Sandi // $numrows not yet implemented 8130cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 814a2d649c4Sandi $this->doc .= '<table class="inline">'.DOKU_LF; 8150cecf9d5Sandi } 8160cecf9d5Sandi 8170cecf9d5Sandi function table_close(){ 818cb42b03dSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8190cecf9d5Sandi } 8200cecf9d5Sandi 8210cecf9d5Sandi function tablerow_open(){ 822a2d649c4Sandi $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8230cecf9d5Sandi } 8240cecf9d5Sandi 8250cecf9d5Sandi function tablerow_close(){ 826a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8270cecf9d5Sandi } 8280cecf9d5Sandi 8290cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 830a2d649c4Sandi $this->doc .= '<th'; 8310cecf9d5Sandi if ( !is_null($align) ) { 832a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8330cecf9d5Sandi } 8340cecf9d5Sandi if ( $colspan > 1 ) { 835a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8360cecf9d5Sandi } 837a2d649c4Sandi $this->doc .= '>'; 8380cecf9d5Sandi } 8390cecf9d5Sandi 8400cecf9d5Sandi function tableheader_close(){ 841a2d649c4Sandi $this->doc .= '</th>'; 8420cecf9d5Sandi } 8430cecf9d5Sandi 8440cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 845a2d649c4Sandi $this->doc .= '<td'; 8460cecf9d5Sandi if ( !is_null($align) ) { 847a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8480cecf9d5Sandi } 8490cecf9d5Sandi if ( $colspan > 1 ) { 850a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8510cecf9d5Sandi } 852a2d649c4Sandi $this->doc .= '>'; 8530cecf9d5Sandi } 8540cecf9d5Sandi 8550cecf9d5Sandi function tablecell_close(){ 856a2d649c4Sandi $this->doc .= '</td>'; 8570cecf9d5Sandi } 8580cecf9d5Sandi 8590cecf9d5Sandi //---------------------------------------------------------- 8600cecf9d5Sandi // Utils 8610cecf9d5Sandi 862ba11bd29Sandi /** 8633fd0b676Sandi * Build a link 8643fd0b676Sandi * 8653fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 866ba11bd29Sandi * 867ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 868ba11bd29Sandi */ 869433bef32Sandi function _formatLink($link){ 870ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 871ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 872ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 873ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 874ba11bd29Sandi } 875ba11bd29Sandi //remove double encodings in titles 876ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 877ba11bd29Sandi 878453493f2SAndreas Gohr // be sure there are no bad chars in url or title 879453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 880453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 881453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 882453493f2SAndreas Gohr 883ba11bd29Sandi $ret = ''; 884ba11bd29Sandi $ret .= $link['pre']; 885ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 886bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 887bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 888bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 889bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 890bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 891ba11bd29Sandi $ret .= '>'; 892ba11bd29Sandi $ret .= $link['name']; 893ba11bd29Sandi $ret .= '</a>'; 894ba11bd29Sandi $ret .= $link['suf']; 895ba11bd29Sandi return $ret; 896ba11bd29Sandi } 897ba11bd29Sandi 898ba11bd29Sandi /** 8993fd0b676Sandi * Renders internal and external media 9003fd0b676Sandi * 9013fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 9023fd0b676Sandi */ 9033fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 9043fd0b676Sandi $height=NULL, $cache=NULL) { 9053fd0b676Sandi 9063fd0b676Sandi $ret = ''; 9073fd0b676Sandi 9083fd0b676Sandi list($ext,$mime) = mimetype($src); 9093fd0b676Sandi if(substr($mime,0,5) == 'image'){ 9103fd0b676Sandi //add image tag 9116de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9123fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9133fd0b676Sandi 9143fd0b676Sandi if (!is_null($title)) { 9153fd0b676Sandi $ret .= ' title="'.$this->_xmlEntities($title).'"'; 9163fd0b676Sandi $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 91755efc227SAndreas Gohr }elseif($ext == 'jpg' || $ext == 'jpeg'){ 91855efc227SAndreas Gohr //try to use the caption from IPTC/EXIF 91955efc227SAndreas Gohr require_once(DOKU_INC.'inc/JpegMeta.php'); 92055efc227SAndreas Gohr $jpeg =& new JpegMeta(mediaFN($src)); 92155efc227SAndreas Gohr if($jpeg !== false) $cap = $jpeg->getTitle(); 92255efc227SAndreas Gohr if($cap){ 92355efc227SAndreas Gohr $ret .= ' title="'.$this->_xmlEntities($cap).'"'; 92455efc227SAndreas Gohr $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; 92555efc227SAndreas Gohr } 9263fd0b676Sandi }else{ 9273fd0b676Sandi $ret .= ' alt=""'; 9283fd0b676Sandi } 9293fd0b676Sandi 9303fd0b676Sandi if ( !is_null($width) ) 9313fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9323fd0b676Sandi 9333fd0b676Sandi if ( !is_null($height) ) 9343fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9353fd0b676Sandi 9363fd0b676Sandi $ret .= ' />'; 9373fd0b676Sandi 9383fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9393fd0b676Sandi $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 9403fd0b676Sandi ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 9413fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9423fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9433fd0b676Sandi $ret .= '>'.DOKU_LF; 9446de3759aSAndreas Gohr $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 9453fd0b676Sandi $ret .= '<param name="quality" value="high" />'.DOKU_LF; 9466de3759aSAndreas Gohr $ret .= '<embed src="'.ml($src).'"'. 9473fd0b676Sandi ' quality="high"'; 9483fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9493fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9503fd0b676Sandi $ret .= ' type="application/x-shockwave-flash"'. 9513fd0b676Sandi ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 9523fd0b676Sandi $ret .= '</object>'.DOKU_LF; 9533fd0b676Sandi 9540f428d7dSAndreas Gohr }elseif($title){ 9553fd0b676Sandi // well at least we have a title to display 9563fd0b676Sandi $ret .= $this->_xmlEntities($title); 9573fd0b676Sandi }else{ 9585291ca3aSAndreas Gohr // just show the sourcename 9590f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 9603fd0b676Sandi } 9613fd0b676Sandi 9623fd0b676Sandi return $ret; 9633fd0b676Sandi } 9643fd0b676Sandi 965433bef32Sandi function _xmlEntities($string) { 966de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 9670cecf9d5Sandi } 9680cecf9d5Sandi 9698a831f2bSAndreas Gohr /** 9708a831f2bSAndreas Gohr * Creates a linkid from a headline 971c5a8fd96SAndreas Gohr * 972c5a8fd96SAndreas Gohr * @param string $title The headline title 973c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 974c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 9758a831f2bSAndreas Gohr */ 976c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 977501af51eSAndreas Gohr $title = str_replace(':','',cleanID($title)); 978a9e0fd1bSAndreas Gohr $title = ltrim($title,'0123456789._-'); 9798a831f2bSAndreas Gohr if(empty($title)) $title='section'; 980c5a8fd96SAndreas Gohr 981c5a8fd96SAndreas Gohr if($create){ 982c5a8fd96SAndreas Gohr // make sure tiles are unique 983c5a8fd96SAndreas Gohr $num = ''; 984c5a8fd96SAndreas Gohr while(in_array($title.$num,$this->headers)){ 9850affd488SAndreas Gohr ($num) ? $num++ : $num = 1; 986c5a8fd96SAndreas Gohr } 987c5a8fd96SAndreas Gohr $title = $title.$num; 988c5a8fd96SAndreas Gohr $this->headers[] = $title; 989c5a8fd96SAndreas Gohr } 990c5a8fd96SAndreas Gohr 9918a831f2bSAndreas Gohr return $title; 9920cecf9d5Sandi } 9930cecf9d5Sandi 994af587fa8Sandi /** 9953fd0b676Sandi * Construct a title and handle images in titles 9963fd0b676Sandi * 9970b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 9983fd0b676Sandi */ 999433bef32Sandi function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 1000bb0a59d4Sjan global $conf; 1001bb0a59d4Sjan 100244881bd0Shenning.noren $isImage = false; 10030cecf9d5Sandi if ( is_null($title) ) { 1004bb0a59d4Sjan if ($conf['useheading'] && $id) { 1005fc18c0fbSchris $heading = p_get_first_heading($id,true); 1006bb0a59d4Sjan if ($heading) { 1007433bef32Sandi return $this->_xmlEntities($heading); 1008bb0a59d4Sjan } 1009bb0a59d4Sjan } 1010433bef32Sandi return $this->_xmlEntities($default); 10110cecf9d5Sandi } else if ( is_string($title) ) { 1012433bef32Sandi return $this->_xmlEntities($title); 10130cecf9d5Sandi } else if ( is_array($title) ) { 101444881bd0Shenning.noren $isImage = true; 1015433bef32Sandi return $this->_imageTitle($title); 10160cecf9d5Sandi } 10170cecf9d5Sandi } 10180cecf9d5Sandi 10190cecf9d5Sandi /** 10203fd0b676Sandi * Returns an HTML code for images used in link titles 10213fd0b676Sandi * 10223fd0b676Sandi * @todo Resolve namespace on internal images 10233fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10240cecf9d5Sandi */ 1025433bef32Sandi function _imageTitle($img) { 1026433bef32Sandi return $this->_media($img['src'], 10274826ab45Sandi $img['title'], 10284826ab45Sandi $img['align'], 10294826ab45Sandi $img['width'], 10304826ab45Sandi $img['height'], 10314826ab45Sandi $img['cache']); 10320cecf9d5Sandi } 10330cecf9d5Sandi} 10340cecf9d5Sandi 10354826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1036