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 900976812SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',fullpath(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 39*b5742cedSPierre Spring var $_counter = array(); // used as global counter, introduced for table classes 40*b5742cedSPierre Spring 415f70445dSAndreas Gohr function getFormat(){ 425f70445dSAndreas Gohr return 'xhtml'; 435f70445dSAndreas Gohr } 445f70445dSAndreas Gohr 455f70445dSAndreas Gohr 460cecf9d5Sandi function document_start() { 47c5a8fd96SAndreas Gohr //reset some internals 48c5a8fd96SAndreas Gohr $this->toc = array(); 49c5a8fd96SAndreas Gohr $this->headers = array(); 500cecf9d5Sandi } 510cecf9d5Sandi 520cecf9d5Sandi function document_end() { 530cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 54a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 55d74aace9Schris 56d74aace9Schris $id = 0; 570cecf9d5Sandi foreach ( $this->footnotes as $footnote ) { 58d74aace9Schris $id++; // the number of the current footnote 59d74aace9Schris 60d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 61d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 62d74aace9Schris 63d74aace9Schris // open the footnote and set the anchor and backlink 64d74aace9Schris $this->doc .= '<div class="fn">'; 6529bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">'; 6629bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 67d74aace9Schris 68d74aace9Schris // get any other footnotes that use the same markup 69d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 70d74aace9Schris 71d74aace9Schris if (count($alt)) { 72d74aace9Schris foreach ($alt as $ref) { 73d74aace9Schris // set anchor and backlink for the other footnotes 7429bfcd16SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">'; 7529bfcd16SAndreas Gohr $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF; 76d74aace9Schris } 77d74aace9Schris } 78d74aace9Schris 79d74aace9Schris // add footnote markup and close this footnote 80a2d649c4Sandi $this->doc .= $footnote; 81d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 82d74aace9Schris } 830cecf9d5Sandi } 84a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 850cecf9d5Sandi } 86c5a8fd96SAndreas Gohr 87b8595a66SAndreas Gohr // Prepare the TOC 88b8595a66SAndreas Gohr if($this->info['toc'] && is_array($this->toc) && count($this->toc) > 2){ 89b8595a66SAndreas Gohr global $TOC; 90b8595a66SAndreas Gohr $TOC = $this->toc; 910cecf9d5Sandi } 923e55d035SAndreas Gohr 933e55d035SAndreas Gohr // make sure there are no empty paragraphs 9427918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 95e41c4da9SAndreas Gohr } 960cecf9d5Sandi 97e7856beaSchris function toc_additem($id, $text, $level) { 98af587fa8Sandi global $conf; 99af587fa8Sandi 100c5a8fd96SAndreas Gohr //handle TOC 101c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1027d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 103c5a8fd96SAndreas Gohr } 104e7856beaSchris } 105e7856beaSchris 106e7856beaSchris function header($text, $level, $pos) { 107e7856beaSchris 108e7856beaSchris $hid = $this->_headerToLink($text,true); 109e7856beaSchris 110e7856beaSchris //only add items within configured levels 111e7856beaSchris $this->toc_additem($hid, $text, $level); 112c5a8fd96SAndreas Gohr 113c5a8fd96SAndreas Gohr // write the header 114c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 115a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 116c6a1c1bfSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1170cecf9d5Sandi } 1180cecf9d5Sandi 11935dae8b0SBen Coburn /** 12035dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 12135dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 12235dae8b0SBen Coburn * 12335dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 12435dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 12535dae8b0SBen Coburn */ 12635dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 12735dae8b0SBen Coburn global $conf; 12835dae8b0SBen Coburn 12935dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 13035dae8b0SBen Coburn $name = str_replace('"', '', $name); 13135dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 13235dae8b0SBen Coburn } 13335dae8b0SBen Coburn } 13435dae8b0SBen Coburn 1350cecf9d5Sandi function section_open($level) { 136a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1370cecf9d5Sandi } 1380cecf9d5Sandi 1390cecf9d5Sandi function section_close() { 140a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1410cecf9d5Sandi } 1420cecf9d5Sandi 1430cecf9d5Sandi function cdata($text) { 144a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1450cecf9d5Sandi } 1460cecf9d5Sandi 1470cecf9d5Sandi function p_open() { 148a2d649c4Sandi $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1490cecf9d5Sandi } 1500cecf9d5Sandi 1510cecf9d5Sandi function p_close() { 152a2d649c4Sandi $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1530cecf9d5Sandi } 1540cecf9d5Sandi 1550cecf9d5Sandi function linebreak() { 156a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1570cecf9d5Sandi } 1580cecf9d5Sandi 1590cecf9d5Sandi function hr() { 1604beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1610cecf9d5Sandi } 1620cecf9d5Sandi 1630cecf9d5Sandi function strong_open() { 164a2d649c4Sandi $this->doc .= '<strong>'; 1650cecf9d5Sandi } 1660cecf9d5Sandi 1670cecf9d5Sandi function strong_close() { 168a2d649c4Sandi $this->doc .= '</strong>'; 1690cecf9d5Sandi } 1700cecf9d5Sandi 1710cecf9d5Sandi function emphasis_open() { 172a2d649c4Sandi $this->doc .= '<em>'; 1730cecf9d5Sandi } 1740cecf9d5Sandi 1750cecf9d5Sandi function emphasis_close() { 176a2d649c4Sandi $this->doc .= '</em>'; 1770cecf9d5Sandi } 1780cecf9d5Sandi 1790cecf9d5Sandi function underline_open() { 18002e51121SAnika Henke $this->doc .= '<em class="u">'; 1810cecf9d5Sandi } 1820cecf9d5Sandi 1830cecf9d5Sandi function underline_close() { 18402e51121SAnika Henke $this->doc .= '</em>'; 1850cecf9d5Sandi } 1860cecf9d5Sandi 1870cecf9d5Sandi function monospace_open() { 188a2d649c4Sandi $this->doc .= '<code>'; 1890cecf9d5Sandi } 1900cecf9d5Sandi 1910cecf9d5Sandi function monospace_close() { 192a2d649c4Sandi $this->doc .= '</code>'; 1930cecf9d5Sandi } 1940cecf9d5Sandi 1950cecf9d5Sandi function subscript_open() { 196a2d649c4Sandi $this->doc .= '<sub>'; 1970cecf9d5Sandi } 1980cecf9d5Sandi 1990cecf9d5Sandi function subscript_close() { 200a2d649c4Sandi $this->doc .= '</sub>'; 2010cecf9d5Sandi } 2020cecf9d5Sandi 2030cecf9d5Sandi function superscript_open() { 204a2d649c4Sandi $this->doc .= '<sup>'; 2050cecf9d5Sandi } 2060cecf9d5Sandi 2070cecf9d5Sandi function superscript_close() { 208a2d649c4Sandi $this->doc .= '</sup>'; 2090cecf9d5Sandi } 2100cecf9d5Sandi 2110cecf9d5Sandi function deleted_open() { 212a2d649c4Sandi $this->doc .= '<del>'; 2130cecf9d5Sandi } 2140cecf9d5Sandi 2150cecf9d5Sandi function deleted_close() { 216a2d649c4Sandi $this->doc .= '</del>'; 2170cecf9d5Sandi } 2180cecf9d5Sandi 2193fd0b676Sandi /** 2203fd0b676Sandi * Callback for footnote start syntax 2213fd0b676Sandi * 2223fd0b676Sandi * All following content will go to the footnote instead of 223d74aace9Schris * the document. To achieve this the previous rendered content 2243fd0b676Sandi * is moved to $store and $doc is cleared 2253fd0b676Sandi * 2263fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2273fd0b676Sandi */ 2280cecf9d5Sandi function footnote_open() { 2297764a90aSandi 2307764a90aSandi // move current content to store and record footnote 2317764a90aSandi $this->store = $this->doc; 2327764a90aSandi $this->doc = ''; 2330cecf9d5Sandi } 2340cecf9d5Sandi 2353fd0b676Sandi /** 2363fd0b676Sandi * Callback for footnote end syntax 2373fd0b676Sandi * 2383fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2393fd0b676Sandi * content is restored from $store again 2403fd0b676Sandi * 2413fd0b676Sandi * @author Andreas Gohr 2423fd0b676Sandi */ 2430cecf9d5Sandi function footnote_close() { 2447764a90aSandi 245d74aace9Schris // recover footnote into the stack and restore old content 246d74aace9Schris $footnote = $this->doc; 2477764a90aSandi $this->doc = $this->store; 2487764a90aSandi $this->store = ''; 249d74aace9Schris 250d74aace9Schris // check to see if this footnote has been seen before 251d74aace9Schris $i = array_search($footnote, $this->footnotes); 252d74aace9Schris 253d74aace9Schris if ($i === false) { 254d74aace9Schris // its a new footnote, add it to the $footnotes array 255d74aace9Schris $id = count($this->footnotes)+1; 256d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 257d74aace9Schris } else { 258d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 259d74aace9Schris $i++; 260d74aace9Schris $id = count($this->footnotes)+1; 261d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 262d74aace9Schris } 263d74aace9Schris 2646b379cbfSAndreas Gohr // output the footnote reference and link 26529bfcd16SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>'; 2660cecf9d5Sandi } 2670cecf9d5Sandi 2680cecf9d5Sandi function listu_open() { 269a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2700cecf9d5Sandi } 2710cecf9d5Sandi 2720cecf9d5Sandi function listu_close() { 273a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 2740cecf9d5Sandi } 2750cecf9d5Sandi 2760cecf9d5Sandi function listo_open() { 277a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 2780cecf9d5Sandi } 2790cecf9d5Sandi 2800cecf9d5Sandi function listo_close() { 281a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 2820cecf9d5Sandi } 2830cecf9d5Sandi 2840cecf9d5Sandi function listitem_open($level) { 285a2d649c4Sandi $this->doc .= '<li class="level'.$level.'">'; 2860cecf9d5Sandi } 2870cecf9d5Sandi 2880cecf9d5Sandi function listitem_close() { 289a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 2900cecf9d5Sandi } 2910cecf9d5Sandi 2920cecf9d5Sandi function listcontent_open() { 29390db23d7Schris $this->doc .= '<div class="li">'; 2940cecf9d5Sandi } 2950cecf9d5Sandi 2960cecf9d5Sandi function listcontent_close() { 29790db23d7Schris $this->doc .= '</div>'.DOKU_LF; 2980cecf9d5Sandi } 2990cecf9d5Sandi 3000cecf9d5Sandi function unformatted($text) { 301a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3020cecf9d5Sandi } 3030cecf9d5Sandi 3040cecf9d5Sandi /** 3053fd0b676Sandi * Execute PHP code if allowed 3063fd0b676Sandi * 3073fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3080cecf9d5Sandi */ 3090cecf9d5Sandi function php($text) { 31035a56260SChris Smith global $conf; 31135a56260SChris Smith 312d86d5af0SChris Smith if($conf['phpok']){ 313bad0b545Sandi ob_start(); 3144de671bcSandi eval($text); 3153fd0b676Sandi $this->doc .= ob_get_contents(); 316bad0b545Sandi ob_end_clean(); 317d86d5af0SChris Smith } else { 318d86d5af0SChris Smith $this->code($text, 'php'); 319d86d5af0SChris Smith } 3200cecf9d5Sandi } 3210cecf9d5Sandi 32207f89c3cSAnika Henke function phpblock($text) { 32307f89c3cSAnika Henke $this->php($text); 32407f89c3cSAnika Henke } 32507f89c3cSAnika Henke 3260cecf9d5Sandi /** 3273fd0b676Sandi * Insert HTML if allowed 3283fd0b676Sandi * 3293fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3300cecf9d5Sandi */ 3310cecf9d5Sandi function html($text) { 33235a56260SChris Smith global $conf; 33335a56260SChris Smith 334d86d5af0SChris Smith if($conf['htmlok']){ 335a2d649c4Sandi $this->doc .= $text; 336d86d5af0SChris Smith } else { 337d86d5af0SChris Smith $this->code($text, 'html4strict'); 338d86d5af0SChris Smith } 3394de671bcSandi } 3400cecf9d5Sandi 34107f89c3cSAnika Henke function htmlblock($text) { 34207f89c3cSAnika Henke $this->html($text); 34307f89c3cSAnika Henke } 34407f89c3cSAnika Henke 3450cecf9d5Sandi function preformatted($text) { 346a2d649c4Sandi $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 3470cecf9d5Sandi } 3480cecf9d5Sandi 3490cecf9d5Sandi function file($text) { 350a2d649c4Sandi $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 3510cecf9d5Sandi } 3520cecf9d5Sandi 3530cecf9d5Sandi function quote_open() { 35496331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3550cecf9d5Sandi } 3560cecf9d5Sandi 3570cecf9d5Sandi function quote_close() { 35896331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3590cecf9d5Sandi } 3600cecf9d5Sandi 3610cecf9d5Sandi /** 3623fd0b676Sandi * Callback for code text 3633fd0b676Sandi * 3643fd0b676Sandi * Uses GeSHi to highlight language syntax 3653fd0b676Sandi * 3663fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3670cecf9d5Sandi */ 3680cecf9d5Sandi function code($text, $language = NULL) { 3694de671bcSandi global $conf; 3700cecf9d5Sandi 3710cecf9d5Sandi if ( is_null($language) ) { 3720cecf9d5Sandi $this->preformatted($text); 3730cecf9d5Sandi } else { 374852896daSAndreas Gohr //strip leading and trailing blank line 375313da78aSandi $text = preg_replace('/^\s*?\n/','',$text); 376852896daSAndreas Gohr $text = preg_replace('/\s*?\n$/','',$text); 3778f7d700cSchris $this->doc .= p_xhtml_cached_geshi($text, $language); 3780cecf9d5Sandi } 3790cecf9d5Sandi } 3800cecf9d5Sandi 3810cecf9d5Sandi function acronym($acronym) { 3820cecf9d5Sandi 3830cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 3840cecf9d5Sandi 385433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 3860cecf9d5Sandi 387a2d649c4Sandi $this->doc .= '<acronym title="'.$title 388433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 3890cecf9d5Sandi 3900cecf9d5Sandi } else { 391a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 3920cecf9d5Sandi } 3930cecf9d5Sandi } 3940cecf9d5Sandi 3950cecf9d5Sandi function smiley($smiley) { 3960cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 397433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 398f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 3994beabca9SAnika Henke '" class="middle" alt="'. 400433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4010cecf9d5Sandi } else { 402a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4030cecf9d5Sandi } 4040cecf9d5Sandi } 4050cecf9d5Sandi 406f62ea8a1Sandi /* 4074de671bcSandi * not used 4080cecf9d5Sandi function wordblock($word) { 4090cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 410a2d649c4Sandi $this->doc .= '** BLEEP **'; 4110cecf9d5Sandi } else { 412a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4130cecf9d5Sandi } 4140cecf9d5Sandi } 4154de671bcSandi */ 4160cecf9d5Sandi 4170cecf9d5Sandi function entity($entity) { 4180cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 419a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4200cecf9d5Sandi } else { 421a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4220cecf9d5Sandi } 4230cecf9d5Sandi } 4240cecf9d5Sandi 4250cecf9d5Sandi function multiplyentity($x, $y) { 426a2d649c4Sandi $this->doc .= "$x×$y"; 4270cecf9d5Sandi } 4280cecf9d5Sandi 4290cecf9d5Sandi function singlequoteopening() { 43071b40da2SAnika Henke global $lang; 43171b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 4320cecf9d5Sandi } 4330cecf9d5Sandi 4340cecf9d5Sandi function singlequoteclosing() { 43571b40da2SAnika Henke global $lang; 43671b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 4370cecf9d5Sandi } 4380cecf9d5Sandi 43957d757d1SAndreas Gohr function apostrophe() { 44057d757d1SAndreas Gohr global $lang; 441a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 44257d757d1SAndreas Gohr } 44357d757d1SAndreas Gohr 4440cecf9d5Sandi function doublequoteopening() { 44571b40da2SAnika Henke global $lang; 44671b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 4470cecf9d5Sandi } 4480cecf9d5Sandi 4490cecf9d5Sandi function doublequoteclosing() { 45071b40da2SAnika Henke global $lang; 45171b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 4520cecf9d5Sandi } 4530cecf9d5Sandi 4540cecf9d5Sandi /** 4550cecf9d5Sandi */ 4560cecf9d5Sandi function camelcaselink($link) { 45711d0aa47Sandi $this->internallink($link,$link); 4580cecf9d5Sandi } 4590cecf9d5Sandi 4600b7c14c2Sandi 4610b7c14c2Sandi function locallink($hash, $name = NULL){ 4620b7c14c2Sandi global $ID; 4630b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4640b7c14c2Sandi $hash = $this->_headerToLink($hash); 4650b7c14c2Sandi $title = $ID.' ↵'; 4660b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 4670b7c14c2Sandi $this->doc .= $name; 4680b7c14c2Sandi $this->doc .= '</a>'; 4690b7c14c2Sandi } 4700b7c14c2Sandi 471cffcc403Sandi /** 4723fd0b676Sandi * Render an internal Wiki Link 4733fd0b676Sandi * 474cffcc403Sandi * $search and $returnonly are not for the renderer but are used 475cffcc403Sandi * elsewhere - no need to implement them in other renderers 4763fd0b676Sandi * 4773fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 478cffcc403Sandi */ 479cffcc403Sandi function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 480ba11bd29Sandi global $conf; 48137e34a5eSandi global $ID; 4820339c872Sjan // default name is based on $id as given 4830339c872Sjan $default = $this->_simpleTitle($id); 484ad32e47eSAndreas Gohr 4850339c872Sjan // now first resolve and clean up the $id 48637e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 4870339c872Sjan $name = $this->_getLinkTitle($name, $default, $isImage, $id); 4880e1c636eSandi if ( !$isImage ) { 4890e1c636eSandi if ( $exists ) { 490ba11bd29Sandi $class='wikilink1'; 4910cecf9d5Sandi } else { 492ba11bd29Sandi $class='wikilink2'; 49344a6b4c7SAndreas Gohr $link['rel']='nofollow'; 4940cecf9d5Sandi } 4950cecf9d5Sandi } else { 496ba11bd29Sandi $class='media'; 4970cecf9d5Sandi } 4980cecf9d5Sandi 499a1685bedSandi //keep hash anchor 500ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 501943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 502a1685bedSandi 503ba11bd29Sandi //prepare for formating 504ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 505ba11bd29Sandi $link['style'] = ''; 506ba11bd29Sandi $link['pre'] = ''; 507ba11bd29Sandi $link['suf'] = ''; 50840eb54bbSjan // highlight link to current page 50940eb54bbSjan if ($id == $ID) { 51092795d04Sandi $link['pre'] = '<span class="curid">'; 51192795d04Sandi $link['suf'] = '</span>'; 51240eb54bbSjan } 5135e163278SAndreas Gohr $link['more'] = ''; 514ba11bd29Sandi $link['class'] = $class; 515ba11bd29Sandi $link['url'] = wl($id); 516ba11bd29Sandi $link['name'] = $name; 517ba11bd29Sandi $link['title'] = $id; 518723d78dbSandi //add search string 519723d78dbSandi if($search){ 520723d78dbSandi ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 521b6c6979fSAndreas Gohr $link['url'] .= rawurlencode($search); 522723d78dbSandi } 523723d78dbSandi 524a1685bedSandi //keep hash 525a1685bedSandi if($hash) $link['url'].='#'.$hash; 526a1685bedSandi 527ba11bd29Sandi //output formatted 528cffcc403Sandi if($returnonly){ 529cffcc403Sandi return $this->_formatLink($link); 530cffcc403Sandi }else{ 531a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5320cecf9d5Sandi } 533cffcc403Sandi } 5340cecf9d5Sandi 535b625487dSandi function externallink($url, $name = NULL) { 536b625487dSandi global $conf; 5370cecf9d5Sandi 538433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5396f0c5dbfSandi 5400cecf9d5Sandi if ( !$isImage ) { 541b625487dSandi $class='urlextern'; 5420cecf9d5Sandi } else { 543b625487dSandi $class='media'; 5440cecf9d5Sandi } 5450cecf9d5Sandi 546b625487dSandi //prepare for formating 547b625487dSandi $link['target'] = $conf['target']['extern']; 548b625487dSandi $link['style'] = ''; 549b625487dSandi $link['pre'] = ''; 550b625487dSandi $link['suf'] = ''; 5515e163278SAndreas Gohr $link['more'] = ''; 552b625487dSandi $link['class'] = $class; 553b625487dSandi $link['url'] = $url; 554e1c10e4dSchris 555b625487dSandi $link['name'] = $name; 556433bef32Sandi $link['title'] = $this->_xmlEntities($url); 557b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5580cecf9d5Sandi 559b625487dSandi //output formatted 560a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5610cecf9d5Sandi } 5620cecf9d5Sandi 5630cecf9d5Sandi /** 5640cecf9d5Sandi */ 56597a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 566b625487dSandi global $conf; 5670cecf9d5Sandi 56897a3e4e3Sandi $link = array(); 56997a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 57097a3e4e3Sandi $link['pre'] = ''; 57197a3e4e3Sandi $link['suf'] = ''; 5725e163278SAndreas Gohr $link['more'] = ''; 573433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5740cecf9d5Sandi 57597a3e4e3Sandi //get interwiki URL 5761f82fabeSAndreas Gohr $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 5770cecf9d5Sandi 57897a3e4e3Sandi if ( !$isImage ) { 5799d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5809d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5811c2d1019SAndreas Gohr } else { 5821c2d1019SAndreas Gohr $link['class'] = 'media'; 58397a3e4e3Sandi } 5840cecf9d5Sandi 58597a3e4e3Sandi //do we stay at the same server? Use local target 58697a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 58797a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 58897a3e4e3Sandi } 5890cecf9d5Sandi 59097a3e4e3Sandi $link['url'] = $url; 59197a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 59297a3e4e3Sandi 59397a3e4e3Sandi //output formatted 594a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5950cecf9d5Sandi } 5960cecf9d5Sandi 5970cecf9d5Sandi /** 5980cecf9d5Sandi */ 5991d47afe1Sandi function windowssharelink($url, $name = NULL) { 6001d47afe1Sandi global $conf; 6011d47afe1Sandi global $lang; 6021d47afe1Sandi //simple setup 6031d47afe1Sandi $link['target'] = $conf['target']['windows']; 6041d47afe1Sandi $link['pre'] = ''; 6051d47afe1Sandi $link['suf'] = ''; 6061d47afe1Sandi $link['style'] = ''; 6071d47afe1Sandi //Display error on browsers other than IE 6081d47afe1Sandi $link['more'] = 'onclick="if(document.all == null){alert(\''. 609b120b664SAndreas Gohr str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])). 6101d47afe1Sandi '\');}" onkeypress="if(document.all == null){alert(\''. 611b120b664SAndreas Gohr str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"'; 6120cecf9d5Sandi 613433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6140cecf9d5Sandi if ( !$isImage ) { 6151d47afe1Sandi $link['class'] = 'windows'; 6160cecf9d5Sandi } else { 6171d47afe1Sandi $link['class'] = 'media'; 6180cecf9d5Sandi } 6190cecf9d5Sandi 6200cecf9d5Sandi 621433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6221d47afe1Sandi $url = str_replace('\\','/',$url); 6231d47afe1Sandi $url = 'file:///'.$url; 6241d47afe1Sandi $link['url'] = $url; 6250cecf9d5Sandi 6261d47afe1Sandi //output formatted 627a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6280cecf9d5Sandi } 6290cecf9d5Sandi 63071352defSandi function emaillink($address, $name = NULL) { 63171352defSandi global $conf; 63271352defSandi //simple setup 63371352defSandi $link = array(); 63471352defSandi $link['target'] = ''; 63571352defSandi $link['pre'] = ''; 63671352defSandi $link['suf'] = ''; 63771352defSandi $link['style'] = ''; 63871352defSandi $link['more'] = ''; 6390cecf9d5Sandi 640c6e62e9fSchris $name = $this->_getLinkTitle($name, '', $isImage); 6410cecf9d5Sandi if ( !$isImage ) { 642776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6430cecf9d5Sandi } else { 644776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6450cecf9d5Sandi } 6460cecf9d5Sandi 64707738714SAndreas Gohr $address = $this->_xmlEntities($address); 64800a7b5adSEsther Brunner $address = obfuscate($address); 64900a7b5adSEsther Brunner $title = $address; 6508c128049SAndreas Gohr 65171352defSandi if(empty($name)){ 65200a7b5adSEsther Brunner $name = $address; 65371352defSandi } 6548c128049SAndreas Gohr#elseif($isImage{ 6558c128049SAndreas Gohr# $name = $this->_xmlEntities($name); 6568c128049SAndreas Gohr# } 6570cecf9d5Sandi 658776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 659776b36ecSAndreas Gohr 660776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 66171352defSandi $link['name'] = $name; 66271352defSandi $link['title'] = $title; 6630cecf9d5Sandi 66471352defSandi //output formatted 665a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6660cecf9d5Sandi } 6670cecf9d5Sandi 6684826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 669dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 67037e34a5eSandi global $ID; 67137e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6720cecf9d5Sandi 673d98d4540SBen Coburn $noLink = false; 6748acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 675b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 6763685f775Sandi 67755efc227SAndreas Gohr list($ext,$mime) = mimetype($src); 678b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 679dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 6802ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 6812ca14335SEsther Brunner // don't link flash movies 68244881bd0Shenning.noren $noLink = true; 68355efc227SAndreas Gohr }else{ 6842ca14335SEsther Brunner // add file icons 6859d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 6869d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 6876de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 68855efc227SAndreas Gohr } 6893685f775Sandi 6903685f775Sandi //output formatted 691dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 6922ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 6930cecf9d5Sandi } 6940cecf9d5Sandi 6950cecf9d5Sandi /** 6964826ab45Sandi * @todo don't add link for flash 6970cecf9d5Sandi */ 6984826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 699dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 700d98d4540SBen Coburn $noLink = false; 7018acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 702b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 703b739ff0fSPierre Spring 704b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 7053685f775Sandi 7062ca14335SEsther Brunner list($ext,$mime) = mimetype($src); 707b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 7082ca14335SEsther Brunner // link only jpeg images 70944881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7102ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7112ca14335SEsther Brunner // don't link flash movies 71244881bd0Shenning.noren $noLink = true; 7132ca14335SEsther Brunner }else{ 7142ca14335SEsther Brunner // add file icons 715d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7162ca14335SEsther Brunner } 7172ca14335SEsther Brunner 7183685f775Sandi //output formatted 719dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7202ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7210cecf9d5Sandi } 7220cecf9d5Sandi 7234826ab45Sandi /** 7243db95becSAndreas Gohr * Renders an RSS feed 725b625487dSandi * 726b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 727b625487dSandi */ 7283db95becSAndreas Gohr function rss ($url,$params){ 729b625487dSandi global $lang; 7303db95becSAndreas Gohr global $conf; 7313db95becSAndreas Gohr 7323db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7333db95becSAndreas Gohr $feed = new FeedParser(); 73400077af8SAndreas Gohr $feed->set_feed_url($url); 735b625487dSandi 736b625487dSandi //disable warning while fetching 737bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7383db95becSAndreas Gohr $rc = $feed->init(); 739bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 740b625487dSandi 7413db95becSAndreas Gohr //decide on start and end 7423db95becSAndreas Gohr if($params['reverse']){ 7433db95becSAndreas Gohr $mod = -1; 7443db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7453db95becSAndreas Gohr $end = $start - ($params['max']); 746b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7473db95becSAndreas Gohr }else{ 7483db95becSAndreas Gohr $mod = 1; 7493db95becSAndreas Gohr $start = 0; 7503db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7513db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7523db95becSAndreas Gohr } 7533db95becSAndreas Gohr 754a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7553db95becSAndreas Gohr if($rc){ 7563db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7571bde1582SAndreas Gohr $item = $feed->get_item($x); 7583db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 7591bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 7601bde1582SAndreas Gohr $item->get_title()); 7613db95becSAndreas Gohr if($params['author']){ 7621bde1582SAndreas Gohr $author = $item->get_author(0); 7631bde1582SAndreas Gohr if($author){ 7641bde1582SAndreas Gohr $name = $author->get_name(); 7651bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 7661bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 7671bde1582SAndreas Gohr } 7683db95becSAndreas Gohr } 7693db95becSAndreas Gohr if($params['date']){ 7701bde1582SAndreas Gohr $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 7713db95becSAndreas Gohr } 7721bde1582SAndreas Gohr if($params['details']){ 7733db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 774173dccb7STom N Harris if($conf['htmlok']){ 7751bde1582SAndreas Gohr $this->doc .= $item->get_description(); 7763db95becSAndreas Gohr }else{ 7771bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 7783db95becSAndreas Gohr } 7793db95becSAndreas Gohr $this->doc .= '</div>'; 7803db95becSAndreas Gohr } 7813db95becSAndreas Gohr 7823db95becSAndreas Gohr $this->doc .= '</div></li>'; 783b625487dSandi } 784b625487dSandi }else{ 7853db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 786a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 787b625487dSandi $this->externallink($url); 78845e147ccSAndreas Gohr if($conf['allowdebug']){ 78945e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 79045e147ccSAndreas Gohr } 7913db95becSAndreas Gohr $this->doc .= '</div></li>'; 792b625487dSandi } 793a2d649c4Sandi $this->doc .= '</ul>'; 794b625487dSandi } 795b625487dSandi 7960cecf9d5Sandi // $numrows not yet implemented 7970cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 798*b5742cedSPierre Spring // initialize the row counter used for classes 799*b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 800a2d649c4Sandi $this->doc .= '<table class="inline">'.DOKU_LF; 8010cecf9d5Sandi } 8020cecf9d5Sandi 8030cecf9d5Sandi function table_close(){ 804cb42b03dSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8050cecf9d5Sandi } 8060cecf9d5Sandi 8070cecf9d5Sandi function tablerow_open(){ 808*b5742cedSPierre Spring // initialize the cell counter used for classes 809*b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 810*b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 811*b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8120cecf9d5Sandi } 8130cecf9d5Sandi 8140cecf9d5Sandi function tablerow_close(){ 815a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8160cecf9d5Sandi } 8170cecf9d5Sandi 8180cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 819*b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8200cecf9d5Sandi if ( !is_null($align) ) { 821*b5742cedSPierre Spring $class .= ' '.$align.'align'; 8220cecf9d5Sandi } 823*b5742cedSPierre Spring $class .= '"'; 824*b5742cedSPierre Spring $this->doc .= '<th ' . $class; 8250cecf9d5Sandi if ( $colspan > 1 ) { 826*b5742cedSPierre Spring $this->_counter['cell_counter'] += $colspan; 827a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8280cecf9d5Sandi } 829a2d649c4Sandi $this->doc .= '>'; 8300cecf9d5Sandi } 8310cecf9d5Sandi 8320cecf9d5Sandi function tableheader_close(){ 833a2d649c4Sandi $this->doc .= '</th>'; 8340cecf9d5Sandi } 8350cecf9d5Sandi 8360cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 837*b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 8380cecf9d5Sandi if ( !is_null($align) ) { 839*b5742cedSPierre Spring $class .= ' '.$align.'align'; 8400cecf9d5Sandi } 841*b5742cedSPierre Spring $class .= '"'; 842*b5742cedSPierre Spring $this->doc .= '<td '.$class; 8430cecf9d5Sandi if ( $colspan > 1 ) { 844*b5742cedSPierre Spring $this->_counter['cell_counter'] += $colspan; 845a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8460cecf9d5Sandi } 847a2d649c4Sandi $this->doc .= '>'; 8480cecf9d5Sandi } 8490cecf9d5Sandi 8500cecf9d5Sandi function tablecell_close(){ 851a2d649c4Sandi $this->doc .= '</td>'; 8520cecf9d5Sandi } 8530cecf9d5Sandi 8540cecf9d5Sandi //---------------------------------------------------------- 8550cecf9d5Sandi // Utils 8560cecf9d5Sandi 857ba11bd29Sandi /** 8583fd0b676Sandi * Build a link 8593fd0b676Sandi * 8603fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 861ba11bd29Sandi * 862ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 863ba11bd29Sandi */ 864433bef32Sandi function _formatLink($link){ 865ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 866ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 867ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 868ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 869ba11bd29Sandi } 870ba11bd29Sandi //remove double encodings in titles 871ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 872ba11bd29Sandi 873453493f2SAndreas Gohr // be sure there are no bad chars in url or title 874453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 875453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 876453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 877453493f2SAndreas Gohr 878ba11bd29Sandi $ret = ''; 879ba11bd29Sandi $ret .= $link['pre']; 880ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 881bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 882bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 883bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 884bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 88544a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 886bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 887ba11bd29Sandi $ret .= '>'; 888ba11bd29Sandi $ret .= $link['name']; 889ba11bd29Sandi $ret .= '</a>'; 890ba11bd29Sandi $ret .= $link['suf']; 891ba11bd29Sandi return $ret; 892ba11bd29Sandi } 893ba11bd29Sandi 894ba11bd29Sandi /** 8953fd0b676Sandi * Renders internal and external media 8963fd0b676Sandi * 8973fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 8983fd0b676Sandi */ 8993fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 900b739ff0fSPierre Spring $height=NULL, $cache=NULL, $render = true) { 9013fd0b676Sandi 9023fd0b676Sandi $ret = ''; 9033fd0b676Sandi 9043fd0b676Sandi list($ext,$mime) = mimetype($src); 9053fd0b676Sandi if(substr($mime,0,5) == 'image'){ 906b739ff0fSPierre Spring // first get the $title 907b739ff0fSPierre Spring if (!is_null($title)) { 908b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 909b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 910b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 911b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 912b739ff0fSPierre Spring $jpeg =& new JpegMeta(mediaFN($src)); 913b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 914b739ff0fSPierre Spring if($cap){ 915b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 916b739ff0fSPierre Spring } 917b739ff0fSPierre Spring } 918b739ff0fSPierre Spring if (!$render) { 919b739ff0fSPierre Spring // if the picture is not supposed to be rendered 920b739ff0fSPierre Spring // return the title of the picture 921b739ff0fSPierre Spring if (!$title) { 922b739ff0fSPierre Spring // just show the sourcename 923b739ff0fSPierre Spring $title = $this->_xmlEntities(basename(noNS($src))); 924b739ff0fSPierre Spring } 925b739ff0fSPierre Spring return $title; 926b739ff0fSPierre Spring } 9273fd0b676Sandi //add image tag 9286de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9293fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9303fd0b676Sandi 9314ab889eaSAndreas Gohr // make left/right alignment for no-CSS view work (feeds) 9324ab889eaSAndreas Gohr if($align == 'right') $ret .= ' align="right"'; 9334ab889eaSAndreas Gohr if($align == 'left') $ret .= ' align="left"'; 9344ab889eaSAndreas Gohr 935b739ff0fSPierre Spring if ($title) { 936b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 937b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 9383fd0b676Sandi }else{ 9393fd0b676Sandi $ret .= ' alt=""'; 9403fd0b676Sandi } 9413fd0b676Sandi 9423fd0b676Sandi if ( !is_null($width) ) 9433fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9443fd0b676Sandi 9453fd0b676Sandi if ( !is_null($height) ) 9463fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9473fd0b676Sandi 9483fd0b676Sandi $ret .= ' />'; 9493fd0b676Sandi 9503fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9513fd0b676Sandi $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 9523fd0b676Sandi ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 9533fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9543fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9553fd0b676Sandi $ret .= '>'.DOKU_LF; 9566de3759aSAndreas Gohr $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 9573fd0b676Sandi $ret .= '<param name="quality" value="high" />'.DOKU_LF; 9586de3759aSAndreas Gohr $ret .= '<embed src="'.ml($src).'"'. 9593fd0b676Sandi ' quality="high"'; 9603fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9613fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9623fd0b676Sandi $ret .= ' type="application/x-shockwave-flash"'. 9633fd0b676Sandi ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 9643fd0b676Sandi $ret .= '</object>'.DOKU_LF; 9653fd0b676Sandi 9660f428d7dSAndreas Gohr }elseif($title){ 9673fd0b676Sandi // well at least we have a title to display 9683fd0b676Sandi $ret .= $this->_xmlEntities($title); 9693fd0b676Sandi }else{ 9705291ca3aSAndreas Gohr // just show the sourcename 9710f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 9723fd0b676Sandi } 9733fd0b676Sandi 9743fd0b676Sandi return $ret; 9753fd0b676Sandi } 9763fd0b676Sandi 977433bef32Sandi function _xmlEntities($string) { 978de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 9790cecf9d5Sandi } 9800cecf9d5Sandi 9818a831f2bSAndreas Gohr /** 9828a831f2bSAndreas Gohr * Creates a linkid from a headline 983c5a8fd96SAndreas Gohr * 984c5a8fd96SAndreas Gohr * @param string $title The headline title 985c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 986c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 9878a831f2bSAndreas Gohr */ 988c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 989501af51eSAndreas Gohr $title = str_replace(':','',cleanID($title)); 990a9e0fd1bSAndreas Gohr $title = ltrim($title,'0123456789._-'); 9918a831f2bSAndreas Gohr if(empty($title)) $title='section'; 992c5a8fd96SAndreas Gohr 993c5a8fd96SAndreas Gohr if($create){ 994c5a8fd96SAndreas Gohr // make sure tiles are unique 995c5a8fd96SAndreas Gohr $num = ''; 996c5a8fd96SAndreas Gohr while(in_array($title.$num,$this->headers)){ 9970affd488SAndreas Gohr ($num) ? $num++ : $num = 1; 998c5a8fd96SAndreas Gohr } 999c5a8fd96SAndreas Gohr $title = $title.$num; 1000c5a8fd96SAndreas Gohr $this->headers[] = $title; 1001c5a8fd96SAndreas Gohr } 1002c5a8fd96SAndreas Gohr 10038a831f2bSAndreas Gohr return $title; 10040cecf9d5Sandi } 10050cecf9d5Sandi 1006af587fa8Sandi /** 10073fd0b676Sandi * Construct a title and handle images in titles 10083fd0b676Sandi * 10090b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 10103fd0b676Sandi */ 1011433bef32Sandi function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 1012bb0a59d4Sjan global $conf; 1013bb0a59d4Sjan 101444881bd0Shenning.noren $isImage = false; 10150cecf9d5Sandi if ( is_null($title) ) { 1016bb0a59d4Sjan if ($conf['useheading'] && $id) { 1017fc18c0fbSchris $heading = p_get_first_heading($id,true); 1018bb0a59d4Sjan if ($heading) { 1019433bef32Sandi return $this->_xmlEntities($heading); 1020bb0a59d4Sjan } 1021bb0a59d4Sjan } 1022433bef32Sandi return $this->_xmlEntities($default); 10230cecf9d5Sandi } else if ( is_string($title) ) { 1024433bef32Sandi return $this->_xmlEntities($title); 10250cecf9d5Sandi } else if ( is_array($title) ) { 102644881bd0Shenning.noren $isImage = true; 1027433bef32Sandi return $this->_imageTitle($title); 10280cecf9d5Sandi } 10290cecf9d5Sandi } 10300cecf9d5Sandi 10310cecf9d5Sandi /** 10323fd0b676Sandi * Returns an HTML code for images used in link titles 10333fd0b676Sandi * 10343fd0b676Sandi * @todo Resolve namespace on internal images 10353fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10360cecf9d5Sandi */ 1037433bef32Sandi function _imageTitle($img) { 1038433bef32Sandi return $this->_media($img['src'], 10394826ab45Sandi $img['title'], 10404826ab45Sandi $img['align'], 10414826ab45Sandi $img['width'], 10424826ab45Sandi $img['height'], 10434826ab45Sandi $img['cache']); 10440cecf9d5Sandi } 1045b739ff0fSPierre Spring 1046b739ff0fSPierre Spring /** 1047b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1048b739ff0fSPierre Spring * which returns a basic link to a media. 1049b739ff0fSPierre Spring * 1050b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1051b739ff0fSPierre Spring * @param string $src 1052b739ff0fSPierre Spring * @param string $title 1053b739ff0fSPierre Spring * @param string $align 1054b739ff0fSPierre Spring * @param string $width 1055b739ff0fSPierre Spring * @param string $height 1056b739ff0fSPierre Spring * @param string $cache 1057b739ff0fSPierre Spring * @param string $render 1058b739ff0fSPierre Spring * @access protected 1059b739ff0fSPierre Spring * @return array 1060b739ff0fSPierre Spring */ 1061b739ff0fSPierre Spring function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1062b739ff0fSPierre Spring { 1063b739ff0fSPierre Spring global $conf; 1064b739ff0fSPierre Spring 1065b739ff0fSPierre Spring $link = array(); 1066b739ff0fSPierre Spring $link['class'] = 'media'; 1067b739ff0fSPierre Spring $link['style'] = ''; 1068b739ff0fSPierre Spring $link['pre'] = ''; 1069b739ff0fSPierre Spring $link['suf'] = ''; 1070b739ff0fSPierre Spring $link['more'] = ''; 1071b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1072b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1073b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1074b739ff0fSPierre Spring 1075b739ff0fSPierre Spring return $link; 1076b739ff0fSPierre Spring } 10770cecf9d5Sandi} 10780cecf9d5Sandi 10794826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1080