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']){ 82c5a8fd96SAndreas Gohr $this->doc = $this->render_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 */ 94c5a8fd96SAndreas Gohr function render_TOC(){ 95e41c4da9SAndreas Gohr if(count($this->toc) < 3) return ''; 96c5a8fd96SAndreas Gohr global $lang; 97c5a8fd96SAndreas Gohr $out = '<div class="toc">'.DOKU_LF; 98c5a8fd96SAndreas Gohr $out .= '<div class="tocheader toctoggle" id="toc__header">'; 99c5a8fd96SAndreas Gohr $out .= $lang['toc']; 100c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF; 101c5a8fd96SAndreas Gohr $out .= '<div id="toc__inside">'.DOKU_LF; 102c5a8fd96SAndreas Gohr $out .= html_buildlist($this->toc,'toc',array($this,'_tocitem')); 103c5a8fd96SAndreas Gohr $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 104c5a8fd96SAndreas Gohr return $out; 105c5a8fd96SAndreas Gohr } 106c5a8fd96SAndreas Gohr 107c5a8fd96SAndreas Gohr /** 108c5a8fd96SAndreas Gohr * Callback for html_buildlist 109c5a8fd96SAndreas Gohr */ 110c5a8fd96SAndreas Gohr function _tocitem($item){ 111c5a8fd96SAndreas Gohr return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'. 112c5a8fd96SAndreas Gohr $this->_xmlEntities($item['title']).'</a></span>'; 113c5a8fd96SAndreas Gohr } 114c5a8fd96SAndreas Gohr 115af587fa8Sandi function header($text, $level, $pos) { 116af587fa8Sandi global $conf; 117af587fa8Sandi 118c5a8fd96SAndreas Gohr // create a unique header id 119c5a8fd96SAndreas Gohr $hid = $this->_headerToLink($text,'true'); 120c5a8fd96SAndreas Gohr 121c5a8fd96SAndreas Gohr //handle TOC 122c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 123c5a8fd96SAndreas Gohr // the TOC is one of our standard ul list arrays ;-) 124c5a8fd96SAndreas Gohr $this->toc[] = array( 'hid' => $hid, 125c5a8fd96SAndreas Gohr 'title' => $text, 126c5a8fd96SAndreas Gohr 'type' => 'ul', 12721ed2ba4Sjan 'level' => $level-$conf['toptoclevel']+1); 128c5a8fd96SAndreas Gohr } 129c5a8fd96SAndreas Gohr 130c5a8fd96SAndreas Gohr // write the header 131c5a8fd96SAndreas Gohr $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">'; 132a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 133c6a1c1bfSAnika Henke $this->doc .= "</a></h$level>".DOKU_LF; 1340cecf9d5Sandi } 1350cecf9d5Sandi 13635dae8b0SBen Coburn /** 13735dae8b0SBen Coburn * Section edit marker is replaced by an edit button when 13835dae8b0SBen Coburn * the page is editable. Replacement done in 'inc/html.php#html_secedit' 13935dae8b0SBen Coburn * 14035dae8b0SBen Coburn * @author Andreas Gohr <andi@splitbrain.org> 14135dae8b0SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net> 14235dae8b0SBen Coburn */ 14335dae8b0SBen Coburn function section_edit($start, $end, $level, $name) { 14435dae8b0SBen Coburn global $conf; 14535dae8b0SBen Coburn 14635dae8b0SBen Coburn if ($start!=-1 && $level<=$conf['maxseclevel']) { 14735dae8b0SBen Coburn $name = str_replace('"', '', $name); 14835dae8b0SBen Coburn $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->'; 14935dae8b0SBen Coburn } 15035dae8b0SBen Coburn } 15135dae8b0SBen Coburn 1520cecf9d5Sandi function section_open($level) { 153a2d649c4Sandi $this->doc .= "<div class=\"level$level\">".DOKU_LF; 1540cecf9d5Sandi } 1550cecf9d5Sandi 1560cecf9d5Sandi function section_close() { 157a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1580cecf9d5Sandi } 1590cecf9d5Sandi 1600cecf9d5Sandi function cdata($text) { 161a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1620cecf9d5Sandi } 1630cecf9d5Sandi 1640cecf9d5Sandi function p_open() { 165a2d649c4Sandi $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 1660cecf9d5Sandi } 1670cecf9d5Sandi 1680cecf9d5Sandi function p_close() { 169a2d649c4Sandi $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 1700cecf9d5Sandi } 1710cecf9d5Sandi 1720cecf9d5Sandi function linebreak() { 173a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 1740cecf9d5Sandi } 1750cecf9d5Sandi 1760cecf9d5Sandi function hr() { 1774beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 1780cecf9d5Sandi } 1790cecf9d5Sandi 1800cecf9d5Sandi function strong_open() { 181a2d649c4Sandi $this->doc .= '<strong>'; 1820cecf9d5Sandi } 1830cecf9d5Sandi 1840cecf9d5Sandi function strong_close() { 185a2d649c4Sandi $this->doc .= '</strong>'; 1860cecf9d5Sandi } 1870cecf9d5Sandi 1880cecf9d5Sandi function emphasis_open() { 189a2d649c4Sandi $this->doc .= '<em>'; 1900cecf9d5Sandi } 1910cecf9d5Sandi 1920cecf9d5Sandi function emphasis_close() { 193a2d649c4Sandi $this->doc .= '</em>'; 1940cecf9d5Sandi } 1950cecf9d5Sandi 1960cecf9d5Sandi function underline_open() { 19702e51121SAnika Henke $this->doc .= '<em class="u">'; 1980cecf9d5Sandi } 1990cecf9d5Sandi 2000cecf9d5Sandi function underline_close() { 20102e51121SAnika Henke $this->doc .= '</em>'; 2020cecf9d5Sandi } 2030cecf9d5Sandi 2040cecf9d5Sandi function monospace_open() { 205a2d649c4Sandi $this->doc .= '<code>'; 2060cecf9d5Sandi } 2070cecf9d5Sandi 2080cecf9d5Sandi function monospace_close() { 209a2d649c4Sandi $this->doc .= '</code>'; 2100cecf9d5Sandi } 2110cecf9d5Sandi 2120cecf9d5Sandi function subscript_open() { 213a2d649c4Sandi $this->doc .= '<sub>'; 2140cecf9d5Sandi } 2150cecf9d5Sandi 2160cecf9d5Sandi function subscript_close() { 217a2d649c4Sandi $this->doc .= '</sub>'; 2180cecf9d5Sandi } 2190cecf9d5Sandi 2200cecf9d5Sandi function superscript_open() { 221a2d649c4Sandi $this->doc .= '<sup>'; 2220cecf9d5Sandi } 2230cecf9d5Sandi 2240cecf9d5Sandi function superscript_close() { 225a2d649c4Sandi $this->doc .= '</sup>'; 2260cecf9d5Sandi } 2270cecf9d5Sandi 2280cecf9d5Sandi function deleted_open() { 229a2d649c4Sandi $this->doc .= '<del>'; 2300cecf9d5Sandi } 2310cecf9d5Sandi 2320cecf9d5Sandi function deleted_close() { 233a2d649c4Sandi $this->doc .= '</del>'; 2340cecf9d5Sandi } 2350cecf9d5Sandi 2363fd0b676Sandi /** 2373fd0b676Sandi * Callback for footnote start syntax 2383fd0b676Sandi * 2393fd0b676Sandi * All following content will go to the footnote instead of 240d74aace9Schris * the document. To achieve this the previous rendered content 2413fd0b676Sandi * is moved to $store and $doc is cleared 2423fd0b676Sandi * 2433fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2443fd0b676Sandi */ 2450cecf9d5Sandi function footnote_open() { 2467764a90aSandi 2477764a90aSandi // move current content to store and record footnote 2487764a90aSandi $this->store = $this->doc; 2497764a90aSandi $this->doc = ''; 2500cecf9d5Sandi } 2510cecf9d5Sandi 2523fd0b676Sandi /** 2533fd0b676Sandi * Callback for footnote end syntax 2543fd0b676Sandi * 2553fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2563fd0b676Sandi * content is restored from $store again 2573fd0b676Sandi * 2583fd0b676Sandi * @author Andreas Gohr 2593fd0b676Sandi */ 2600cecf9d5Sandi function footnote_close() { 2617764a90aSandi 262d74aace9Schris // recover footnote into the stack and restore old content 263d74aace9Schris $footnote = $this->doc; 2647764a90aSandi $this->doc = $this->store; 2657764a90aSandi $this->store = ''; 266d74aace9Schris 267d74aace9Schris // check to see if this footnote has been seen before 268d74aace9Schris $i = array_search($footnote, $this->footnotes); 269d74aace9Schris 270d74aace9Schris if ($i === false) { 271d74aace9Schris // its a new footnote, add it to the $footnotes array 272d74aace9Schris $id = count($this->footnotes)+1; 273d74aace9Schris $this->footnotes[count($this->footnotes)] = $footnote; 274d74aace9Schris } else { 275d74aace9Schris // seen this one before, translate the index to an id and save a placeholder 276d74aace9Schris $i++; 277d74aace9Schris $id = count($this->footnotes)+1; 278d74aace9Schris $this->footnotes[count($this->footnotes)] = "@@FNT".($i); 279d74aace9Schris } 280d74aace9Schris 2816b379cbfSAndreas Gohr // output the footnote reference and link 2826b379cbfSAndreas Gohr $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>'; 2830cecf9d5Sandi } 2840cecf9d5Sandi 2850cecf9d5Sandi function listu_open() { 286a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 2870cecf9d5Sandi } 2880cecf9d5Sandi 2890cecf9d5Sandi function listu_close() { 290a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 2910cecf9d5Sandi } 2920cecf9d5Sandi 2930cecf9d5Sandi function listo_open() { 294a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 2950cecf9d5Sandi } 2960cecf9d5Sandi 2970cecf9d5Sandi function listo_close() { 298a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 2990cecf9d5Sandi } 3000cecf9d5Sandi 3010cecf9d5Sandi function listitem_open($level) { 302a2d649c4Sandi $this->doc .= '<li class="level'.$level.'">'; 3030cecf9d5Sandi } 3040cecf9d5Sandi 3050cecf9d5Sandi function listitem_close() { 306a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3070cecf9d5Sandi } 3080cecf9d5Sandi 3090cecf9d5Sandi function listcontent_open() { 31090db23d7Schris $this->doc .= '<div class="li">'; 3110cecf9d5Sandi } 3120cecf9d5Sandi 3130cecf9d5Sandi function listcontent_close() { 31490db23d7Schris $this->doc .= '</div>'.DOKU_LF; 3150cecf9d5Sandi } 3160cecf9d5Sandi 3170cecf9d5Sandi function unformatted($text) { 318a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3190cecf9d5Sandi } 3200cecf9d5Sandi 3210cecf9d5Sandi /** 3223fd0b676Sandi * Execute PHP code if allowed 3233fd0b676Sandi * 3243fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3250cecf9d5Sandi */ 3260cecf9d5Sandi function php($text) { 3274de671bcSandi global $conf; 3284de671bcSandi if($conf['phpok']){ 329bad0b545Sandi ob_start(); 3304de671bcSandi eval($text); 3313fd0b676Sandi $this->doc .= ob_get_contents(); 332bad0b545Sandi ob_end_clean(); 3334de671bcSandi }else{ 3344de671bcSandi $this->file($text); 3354de671bcSandi } 3360cecf9d5Sandi } 3370cecf9d5Sandi 3380cecf9d5Sandi /** 3393fd0b676Sandi * Insert HTML if allowed 3403fd0b676Sandi * 3413fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3420cecf9d5Sandi */ 3430cecf9d5Sandi function html($text) { 3444de671bcSandi global $conf; 3454de671bcSandi if($conf['htmlok']){ 346a2d649c4Sandi $this->doc .= $text; 3474de671bcSandi }else{ 3480cecf9d5Sandi $this->file($text); 3490cecf9d5Sandi } 3504de671bcSandi } 3510cecf9d5Sandi 3520cecf9d5Sandi function preformatted($text) { 353a2d649c4Sandi $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 3540cecf9d5Sandi } 3550cecf9d5Sandi 3560cecf9d5Sandi function file($text) { 357a2d649c4Sandi $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 3580cecf9d5Sandi } 3590cecf9d5Sandi 3600cecf9d5Sandi function quote_open() { 36196331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 3620cecf9d5Sandi } 3630cecf9d5Sandi 3640cecf9d5Sandi function quote_close() { 36596331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 3660cecf9d5Sandi } 3670cecf9d5Sandi 3680cecf9d5Sandi /** 3693fd0b676Sandi * Callback for code text 3703fd0b676Sandi * 3713fd0b676Sandi * Uses GeSHi to highlight language syntax 3723fd0b676Sandi * 3733fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3740cecf9d5Sandi */ 3750cecf9d5Sandi function code($text, $language = NULL) { 3764de671bcSandi global $conf; 3770cecf9d5Sandi 3780cecf9d5Sandi if ( is_null($language) ) { 3790cecf9d5Sandi $this->preformatted($text); 3800cecf9d5Sandi } else { 381852896daSAndreas Gohr //strip leading and trailing blank line 382313da78aSandi $text = preg_replace('/^\s*?\n/','',$text); 383852896daSAndreas Gohr $text = preg_replace('/\s*?\n$/','',$text); 3848f7d700cSchris $this->doc .= p_xhtml_cached_geshi($text, $language); 3850cecf9d5Sandi } 3860cecf9d5Sandi } 3870cecf9d5Sandi 3880cecf9d5Sandi function acronym($acronym) { 3890cecf9d5Sandi 3900cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 3910cecf9d5Sandi 392433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 3930cecf9d5Sandi 394a2d649c4Sandi $this->doc .= '<acronym title="'.$title 395433bef32Sandi .'">'.$this->_xmlEntities($acronym).'</acronym>'; 3960cecf9d5Sandi 3970cecf9d5Sandi } else { 398a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 3990cecf9d5Sandi } 4000cecf9d5Sandi } 4010cecf9d5Sandi 4020cecf9d5Sandi function smiley($smiley) { 4030cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 404433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 405f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4064beabca9SAnika Henke '" class="middle" alt="'. 407433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4080cecf9d5Sandi } else { 409a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4100cecf9d5Sandi } 4110cecf9d5Sandi } 4120cecf9d5Sandi 413f62ea8a1Sandi /* 4144de671bcSandi * not used 4150cecf9d5Sandi function wordblock($word) { 4160cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 417a2d649c4Sandi $this->doc .= '** BLEEP **'; 4180cecf9d5Sandi } else { 419a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 4200cecf9d5Sandi } 4210cecf9d5Sandi } 4224de671bcSandi */ 4230cecf9d5Sandi 4240cecf9d5Sandi function entity($entity) { 4250cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 426a2d649c4Sandi $this->doc .= $this->entities[$entity]; 4270cecf9d5Sandi } else { 428a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 4290cecf9d5Sandi } 4300cecf9d5Sandi } 4310cecf9d5Sandi 4320cecf9d5Sandi function multiplyentity($x, $y) { 433a2d649c4Sandi $this->doc .= "$x×$y"; 4340cecf9d5Sandi } 4350cecf9d5Sandi 4360cecf9d5Sandi function singlequoteopening() { 437a2d649c4Sandi $this->doc .= "‘"; 4380cecf9d5Sandi } 4390cecf9d5Sandi 4400cecf9d5Sandi function singlequoteclosing() { 441a2d649c4Sandi $this->doc .= "’"; 4420cecf9d5Sandi } 4430cecf9d5Sandi 4440cecf9d5Sandi function doublequoteopening() { 445a2d649c4Sandi $this->doc .= "“"; 4460cecf9d5Sandi } 4470cecf9d5Sandi 4480cecf9d5Sandi function doublequoteclosing() { 449a2d649c4Sandi $this->doc .= "”"; 4500cecf9d5Sandi } 4510cecf9d5Sandi 4520cecf9d5Sandi /** 4530cecf9d5Sandi */ 4540cecf9d5Sandi function camelcaselink($link) { 45511d0aa47Sandi $this->internallink($link,$link); 4560cecf9d5Sandi } 4570cecf9d5Sandi 4580b7c14c2Sandi 4590b7c14c2Sandi function locallink($hash, $name = NULL){ 4600b7c14c2Sandi global $ID; 4610b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 4620b7c14c2Sandi $hash = $this->_headerToLink($hash); 4630b7c14c2Sandi $title = $ID.' ↵'; 4640b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 4650b7c14c2Sandi $this->doc .= $name; 4660b7c14c2Sandi $this->doc .= '</a>'; 4670b7c14c2Sandi } 4680b7c14c2Sandi 469cffcc403Sandi /** 4703fd0b676Sandi * Render an internal Wiki Link 4713fd0b676Sandi * 472cffcc403Sandi * $search and $returnonly are not for the renderer but are used 473cffcc403Sandi * elsewhere - no need to implement them in other renderers 4743fd0b676Sandi * 4753fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 476cffcc403Sandi */ 477cffcc403Sandi function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 478ba11bd29Sandi global $conf; 47937e34a5eSandi global $ID; 4800339c872Sjan // default name is based on $id as given 4810339c872Sjan $default = $this->_simpleTitle($id); 4820339c872Sjan // now first resolve and clean up the $id 48337e34a5eSandi resolve_pageid(getNS($ID),$id,$exists); 4840339c872Sjan $name = $this->_getLinkTitle($name, $default, $isImage, $id); 4850e1c636eSandi if ( !$isImage ) { 4860e1c636eSandi if ( $exists ) { 487ba11bd29Sandi $class='wikilink1'; 4880cecf9d5Sandi } else { 489ba11bd29Sandi $class='wikilink2'; 4900cecf9d5Sandi } 4910cecf9d5Sandi } else { 492ba11bd29Sandi $class='media'; 4930cecf9d5Sandi } 4940cecf9d5Sandi 495a1685bedSandi //keep hash anchor 496ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 497a1685bedSandi 498ba11bd29Sandi //prepare for formating 499ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 500ba11bd29Sandi $link['style'] = ''; 501ba11bd29Sandi $link['pre'] = ''; 502ba11bd29Sandi $link['suf'] = ''; 50340eb54bbSjan // highlight link to current page 50440eb54bbSjan if ($id == $ID) { 50592795d04Sandi $link['pre'] = '<span class="curid">'; 50692795d04Sandi $link['suf'] = '</span>'; 50740eb54bbSjan } 5085e163278SAndreas Gohr $link['more'] = ''; 509ba11bd29Sandi $link['class'] = $class; 510ba11bd29Sandi $link['url'] = wl($id); 511ba11bd29Sandi $link['name'] = $name; 512ba11bd29Sandi $link['title'] = $id; 513723d78dbSandi //add search string 514723d78dbSandi if($search){ 515723d78dbSandi ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 516b6c6979fSAndreas Gohr $link['url'] .= rawurlencode($search); 517723d78dbSandi } 518723d78dbSandi 519a1685bedSandi //keep hash 520a1685bedSandi if($hash) $link['url'].='#'.$hash; 521a1685bedSandi 522ba11bd29Sandi //output formatted 523cffcc403Sandi if($returnonly){ 524cffcc403Sandi return $this->_formatLink($link); 525cffcc403Sandi }else{ 526a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5270cecf9d5Sandi } 528cffcc403Sandi } 5290cecf9d5Sandi 530b625487dSandi function externallink($url, $name = NULL) { 531b625487dSandi global $conf; 5320cecf9d5Sandi 533433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 5346f0c5dbfSandi 5350cecf9d5Sandi if ( !$isImage ) { 536b625487dSandi $class='urlextern'; 5370cecf9d5Sandi } else { 538b625487dSandi $class='media'; 5390cecf9d5Sandi } 5400cecf9d5Sandi 541b625487dSandi //prepare for formating 542b625487dSandi $link['target'] = $conf['target']['extern']; 543b625487dSandi $link['style'] = ''; 544b625487dSandi $link['pre'] = ''; 545b625487dSandi $link['suf'] = ''; 5465e163278SAndreas Gohr $link['more'] = ''; 547b625487dSandi $link['class'] = $class; 548b625487dSandi $link['url'] = $url; 549e1c10e4dSchris 550b625487dSandi $link['name'] = $name; 551433bef32Sandi $link['title'] = $this->_xmlEntities($url); 552b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 5530cecf9d5Sandi 554b625487dSandi //output formatted 555a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5560cecf9d5Sandi } 5570cecf9d5Sandi 5580cecf9d5Sandi /** 5590cecf9d5Sandi */ 56097a3e4e3Sandi function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 561b625487dSandi global $conf; 5620cecf9d5Sandi 56397a3e4e3Sandi $link = array(); 56497a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 56597a3e4e3Sandi $link['pre'] = ''; 56697a3e4e3Sandi $link['suf'] = ''; 5675e163278SAndreas Gohr $link['more'] = ''; 568433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 5690cecf9d5Sandi 57097a3e4e3Sandi //get interwiki URL 571*1f82fabeSAndreas Gohr $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 5720cecf9d5Sandi 57397a3e4e3Sandi if ( !$isImage ) { 5749d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 5759d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 5761c2d1019SAndreas Gohr } else { 5771c2d1019SAndreas Gohr $link['class'] = 'media'; 57897a3e4e3Sandi } 5790cecf9d5Sandi 58097a3e4e3Sandi //do we stay at the same server? Use local target 58197a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 58297a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 58397a3e4e3Sandi } 5840cecf9d5Sandi 58597a3e4e3Sandi $link['url'] = $url; 58697a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 58797a3e4e3Sandi 58897a3e4e3Sandi //output formatted 589a2d649c4Sandi $this->doc .= $this->_formatLink($link); 5900cecf9d5Sandi } 5910cecf9d5Sandi 5920cecf9d5Sandi /** 5930cecf9d5Sandi */ 5941d47afe1Sandi function windowssharelink($url, $name = NULL) { 5951d47afe1Sandi global $conf; 5961d47afe1Sandi global $lang; 5971d47afe1Sandi //simple setup 5981d47afe1Sandi $link['target'] = $conf['target']['windows']; 5991d47afe1Sandi $link['pre'] = ''; 6001d47afe1Sandi $link['suf'] = ''; 6011d47afe1Sandi $link['style'] = ''; 6021d47afe1Sandi //Display error on browsers other than IE 6031d47afe1Sandi $link['more'] = 'onclick="if(document.all == null){alert(\''. 604433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES). 6051d47afe1Sandi '\');}" onkeypress="if(document.all == null){alert(\''. 606433bef32Sandi $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"'; 6070cecf9d5Sandi 608433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 6090cecf9d5Sandi if ( !$isImage ) { 6101d47afe1Sandi $link['class'] = 'windows'; 6110cecf9d5Sandi } else { 6121d47afe1Sandi $link['class'] = 'media'; 6130cecf9d5Sandi } 6140cecf9d5Sandi 6150cecf9d5Sandi 616433bef32Sandi $link['title'] = $this->_xmlEntities($url); 6171d47afe1Sandi $url = str_replace('\\','/',$url); 6181d47afe1Sandi $url = 'file:///'.$url; 6191d47afe1Sandi $link['url'] = $url; 6200cecf9d5Sandi 6211d47afe1Sandi //output formatted 622a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6230cecf9d5Sandi } 6240cecf9d5Sandi 62571352defSandi function emaillink($address, $name = NULL) { 62671352defSandi global $conf; 62771352defSandi //simple setup 62871352defSandi $link = array(); 62971352defSandi $link['target'] = ''; 63071352defSandi $link['pre'] = ''; 63171352defSandi $link['suf'] = ''; 63271352defSandi $link['style'] = ''; 63371352defSandi $link['more'] = ''; 6340cecf9d5Sandi 635c6e62e9fSchris $name = $this->_getLinkTitle($name, '', $isImage); 6360cecf9d5Sandi if ( !$isImage ) { 637776b36ecSAndreas Gohr $link['class']='mail JSnocheck'; 6380cecf9d5Sandi } else { 639776b36ecSAndreas Gohr $link['class']='media JSnocheck'; 6400cecf9d5Sandi } 6410cecf9d5Sandi 64207738714SAndreas Gohr $address = $this->_xmlEntities($address); 64300a7b5adSEsther Brunner $address = obfuscate($address); 64400a7b5adSEsther Brunner $title = $address; 6458c128049SAndreas Gohr 64671352defSandi if(empty($name)){ 64700a7b5adSEsther Brunner $name = $address; 64871352defSandi } 6498c128049SAndreas Gohr#elseif($isImage{ 6508c128049SAndreas Gohr# $name = $this->_xmlEntities($name); 6518c128049SAndreas Gohr# } 6520cecf9d5Sandi 653776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 654776b36ecSAndreas Gohr 655776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 65671352defSandi $link['name'] = $name; 65771352defSandi $link['title'] = $title; 6580cecf9d5Sandi 65971352defSandi //output formatted 660a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6610cecf9d5Sandi } 6620cecf9d5Sandi 6634826ab45Sandi function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 664dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 6653685f775Sandi global $conf; 66637e34a5eSandi global $ID; 66737e34a5eSandi resolve_mediaid(getNS($ID),$src, $exists); 6680cecf9d5Sandi 6693685f775Sandi $link = array(); 6703685f775Sandi $link['class'] = 'media'; 6713685f775Sandi $link['style'] = ''; 6723685f775Sandi $link['pre'] = ''; 6733685f775Sandi $link['suf'] = ''; 6745e163278SAndreas Gohr $link['more'] = ''; 6753685f775Sandi $link['target'] = $conf['target']['media']; 676d98d4540SBen Coburn $noLink = false; 6773685f775Sandi 678433bef32Sandi $link['title'] = $this->_xmlEntities($src); 67955efc227SAndreas Gohr list($ext,$mime) = mimetype($src); 6805667eb65SAndreas Gohr if(substr($mime,0,5) == 'image'){ 681dc673a5bSjoe.lapp $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 6822ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 6832ca14335SEsther Brunner // don't link flash movies 68444881bd0Shenning.noren $noLink = true; 68555efc227SAndreas Gohr }else{ 6862ca14335SEsther Brunner // add file icons 6879d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 6889d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 6896de3759aSAndreas Gohr $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 69055efc227SAndreas Gohr } 691433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 6923685f775Sandi 6933685f775Sandi //output formatted 694dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 6952ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 6960cecf9d5Sandi } 6970cecf9d5Sandi 6980cecf9d5Sandi /** 6994826ab45Sandi * @todo don't add link for flash 7000cecf9d5Sandi */ 7014826ab45Sandi function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 702dc673a5bSjoe.lapp $height=NULL, $cache=NULL, $linking=NULL) { 7033685f775Sandi global $conf; 7040cecf9d5Sandi 7053685f775Sandi $link = array(); 7063685f775Sandi $link['class'] = 'media'; 7073685f775Sandi $link['style'] = ''; 7083685f775Sandi $link['pre'] = ''; 7093685f775Sandi $link['suf'] = ''; 7105e163278SAndreas Gohr $link['more'] = ''; 7113685f775Sandi $link['target'] = $conf['target']['media']; 7123685f775Sandi 713433bef32Sandi $link['title'] = $this->_xmlEntities($src); 7146de3759aSAndreas Gohr $link['url'] = ml($src,array('cache'=>$cache)); 715433bef32Sandi $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 716d98d4540SBen Coburn $noLink = false; 7173685f775Sandi 7182ca14335SEsther Brunner list($ext,$mime) = mimetype($src); 7192ca14335SEsther Brunner if(substr($mime,0,5) == 'image'){ 7202ca14335SEsther Brunner // link only jpeg images 72144881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 7222ca14335SEsther Brunner }elseif($mime == 'application/x-shockwave-flash'){ 7232ca14335SEsther Brunner // don't link flash movies 72444881bd0Shenning.noren $noLink = true; 7252ca14335SEsther Brunner }else{ 7262ca14335SEsther Brunner // add file icons 727d15166e5SAndreas Gohr $link['class'] .= ' mediafile mf_'.$ext; 7282ca14335SEsther Brunner } 7292ca14335SEsther Brunner 7303685f775Sandi //output formatted 731dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 7322ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 7330cecf9d5Sandi } 7340cecf9d5Sandi 7354826ab45Sandi /** 7363db95becSAndreas Gohr * Renders an RSS feed 737b625487dSandi * 738b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 739b625487dSandi */ 7403db95becSAndreas Gohr function rss ($url,$params){ 741b625487dSandi global $lang; 7423db95becSAndreas Gohr global $conf; 7433db95becSAndreas Gohr 7443db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 7453db95becSAndreas Gohr $feed = new FeedParser(); 7463db95becSAndreas Gohr $feed->feed_url($url); 747b625487dSandi 748b625487dSandi //disable warning while fetching 749bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 7503db95becSAndreas Gohr $rc = $feed->init(); 751bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 752b625487dSandi 7533db95becSAndreas Gohr //decide on start and end 7543db95becSAndreas Gohr if($params['reverse']){ 7553db95becSAndreas Gohr $mod = -1; 7563db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 7573db95becSAndreas Gohr $end = $start - ($params['max']); 758b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 7593db95becSAndreas Gohr }else{ 7603db95becSAndreas Gohr $mod = 1; 7613db95becSAndreas Gohr $start = 0; 7623db95becSAndreas Gohr $end = $feed->get_item_quantity(); 7633db95becSAndreas Gohr $end = ($end > $params['max']) ? $params['max'] : $end;; 7643db95becSAndreas Gohr } 7653db95becSAndreas Gohr 766a2d649c4Sandi $this->doc .= '<ul class="rss">'; 7673db95becSAndreas Gohr if($rc){ 7683db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 7691bde1582SAndreas Gohr $item = $feed->get_item($x); 7703db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 7711bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 7721bde1582SAndreas Gohr $item->get_title()); 7733db95becSAndreas Gohr if($params['author']){ 7741bde1582SAndreas Gohr $author = $item->get_author(0); 7751bde1582SAndreas Gohr if($author){ 7761bde1582SAndreas Gohr $name = $author->get_name(); 7771bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 7781bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 7791bde1582SAndreas Gohr } 7803db95becSAndreas Gohr } 7813db95becSAndreas Gohr if($params['date']){ 7821bde1582SAndreas Gohr $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 7833db95becSAndreas Gohr } 7841bde1582SAndreas Gohr if($params['details']){ 7853db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 7863db95becSAndreas Gohr if($htmlok){ 7871bde1582SAndreas Gohr $this->doc .= $item->get_description(); 7883db95becSAndreas Gohr }else{ 7891bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 7903db95becSAndreas Gohr } 7913db95becSAndreas Gohr $this->doc .= '</div>'; 7923db95becSAndreas Gohr } 7933db95becSAndreas Gohr 7943db95becSAndreas Gohr $this->doc .= '</div></li>'; 795b625487dSandi } 796b625487dSandi }else{ 7973db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 798a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 799b625487dSandi $this->externallink($url); 8003db95becSAndreas Gohr $this->doc .= '</div></li>'; 801b625487dSandi } 802a2d649c4Sandi $this->doc .= '</ul>'; 803b625487dSandi } 804b625487dSandi 8050cecf9d5Sandi // $numrows not yet implemented 8060cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){ 807a2d649c4Sandi $this->doc .= '<table class="inline">'.DOKU_LF; 8080cecf9d5Sandi } 8090cecf9d5Sandi 8100cecf9d5Sandi function table_close(){ 811cb42b03dSAnika Henke $this->doc .= '</table>'.DOKU_LF; 8120cecf9d5Sandi } 8130cecf9d5Sandi 8140cecf9d5Sandi function tablerow_open(){ 815a2d649c4Sandi $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 8160cecf9d5Sandi } 8170cecf9d5Sandi 8180cecf9d5Sandi function tablerow_close(){ 819a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 8200cecf9d5Sandi } 8210cecf9d5Sandi 8220cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){ 823a2d649c4Sandi $this->doc .= '<th'; 8240cecf9d5Sandi if ( !is_null($align) ) { 825a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8260cecf9d5Sandi } 8270cecf9d5Sandi if ( $colspan > 1 ) { 828a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8290cecf9d5Sandi } 830a2d649c4Sandi $this->doc .= '>'; 8310cecf9d5Sandi } 8320cecf9d5Sandi 8330cecf9d5Sandi function tableheader_close(){ 834a2d649c4Sandi $this->doc .= '</th>'; 8350cecf9d5Sandi } 8360cecf9d5Sandi 8370cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){ 838a2d649c4Sandi $this->doc .= '<td'; 8390cecf9d5Sandi if ( !is_null($align) ) { 840a2d649c4Sandi $this->doc .= ' class="'.$align.'align"'; 8410cecf9d5Sandi } 8420cecf9d5Sandi if ( $colspan > 1 ) { 843a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 8440cecf9d5Sandi } 845a2d649c4Sandi $this->doc .= '>'; 8460cecf9d5Sandi } 8470cecf9d5Sandi 8480cecf9d5Sandi function tablecell_close(){ 849a2d649c4Sandi $this->doc .= '</td>'; 8500cecf9d5Sandi } 8510cecf9d5Sandi 8520cecf9d5Sandi //---------------------------------------------------------- 8530cecf9d5Sandi // Utils 8540cecf9d5Sandi 855ba11bd29Sandi /** 8563fd0b676Sandi * Build a link 8573fd0b676Sandi * 8583fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 859ba11bd29Sandi * 860ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 861ba11bd29Sandi */ 862433bef32Sandi function _formatLink($link){ 863ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 864ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 865ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 866ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 867ba11bd29Sandi } 868ba11bd29Sandi //remove double encodings in titles 869ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 870ba11bd29Sandi 871453493f2SAndreas Gohr // be sure there are no bad chars in url or title 872453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 873453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 874453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 875453493f2SAndreas Gohr 876ba11bd29Sandi $ret = ''; 877ba11bd29Sandi $ret .= $link['pre']; 878ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 879bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 880bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 881bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 882bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 883bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 884ba11bd29Sandi $ret .= '>'; 885ba11bd29Sandi $ret .= $link['name']; 886ba11bd29Sandi $ret .= '</a>'; 887ba11bd29Sandi $ret .= $link['suf']; 888ba11bd29Sandi return $ret; 889ba11bd29Sandi } 890ba11bd29Sandi 891ba11bd29Sandi /** 8923fd0b676Sandi * Renders internal and external media 8933fd0b676Sandi * 8943fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 8953fd0b676Sandi */ 8963fd0b676Sandi function _media ($src, $title=NULL, $align=NULL, $width=NULL, 8973fd0b676Sandi $height=NULL, $cache=NULL) { 8983fd0b676Sandi 8993fd0b676Sandi $ret = ''; 9003fd0b676Sandi 9013fd0b676Sandi list($ext,$mime) = mimetype($src); 9023fd0b676Sandi if(substr($mime,0,5) == 'image'){ 9033fd0b676Sandi //add image tag 9046de3759aSAndreas Gohr $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 9053fd0b676Sandi $ret .= ' class="media'.$align.'"'; 9063fd0b676Sandi 9073fd0b676Sandi if (!is_null($title)) { 9083fd0b676Sandi $ret .= ' title="'.$this->_xmlEntities($title).'"'; 9093fd0b676Sandi $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 91055efc227SAndreas Gohr }elseif($ext == 'jpg' || $ext == 'jpeg'){ 91155efc227SAndreas Gohr //try to use the caption from IPTC/EXIF 91255efc227SAndreas Gohr require_once(DOKU_INC.'inc/JpegMeta.php'); 91355efc227SAndreas Gohr $jpeg =& new JpegMeta(mediaFN($src)); 91455efc227SAndreas Gohr if($jpeg !== false) $cap = $jpeg->getTitle(); 91555efc227SAndreas Gohr if($cap){ 91655efc227SAndreas Gohr $ret .= ' title="'.$this->_xmlEntities($cap).'"'; 91755efc227SAndreas Gohr $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; 91855efc227SAndreas Gohr } 9193fd0b676Sandi }else{ 9203fd0b676Sandi $ret .= ' alt=""'; 9213fd0b676Sandi } 9223fd0b676Sandi 9233fd0b676Sandi if ( !is_null($width) ) 9243fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9253fd0b676Sandi 9263fd0b676Sandi if ( !is_null($height) ) 9273fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9283fd0b676Sandi 9293fd0b676Sandi $ret .= ' />'; 9303fd0b676Sandi 9313fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 9323fd0b676Sandi $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 9333fd0b676Sandi ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 9343fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9353fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9363fd0b676Sandi $ret .= '>'.DOKU_LF; 9376de3759aSAndreas Gohr $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 9383fd0b676Sandi $ret .= '<param name="quality" value="high" />'.DOKU_LF; 9396de3759aSAndreas Gohr $ret .= '<embed src="'.ml($src).'"'. 9403fd0b676Sandi ' quality="high"'; 9413fd0b676Sandi if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 9423fd0b676Sandi if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 9433fd0b676Sandi $ret .= ' type="application/x-shockwave-flash"'. 9443fd0b676Sandi ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 9453fd0b676Sandi $ret .= '</object>'.DOKU_LF; 9463fd0b676Sandi 9470f428d7dSAndreas Gohr }elseif($title){ 9483fd0b676Sandi // well at least we have a title to display 9493fd0b676Sandi $ret .= $this->_xmlEntities($title); 9503fd0b676Sandi }else{ 9515291ca3aSAndreas Gohr // just show the sourcename 9520f428d7dSAndreas Gohr $ret .= $this->_xmlEntities(basename(noNS($src))); 9533fd0b676Sandi } 9543fd0b676Sandi 9553fd0b676Sandi return $ret; 9563fd0b676Sandi } 9573fd0b676Sandi 958433bef32Sandi function _xmlEntities($string) { 9590cecf9d5Sandi return htmlspecialchars($string); 9600cecf9d5Sandi } 9610cecf9d5Sandi 9628a831f2bSAndreas Gohr /** 9638a831f2bSAndreas Gohr * Creates a linkid from a headline 964c5a8fd96SAndreas Gohr * 965c5a8fd96SAndreas Gohr * @param string $title The headline title 966c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 967c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 9688a831f2bSAndreas Gohr */ 969c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 970501af51eSAndreas Gohr $title = str_replace(':','',cleanID($title)); 971a9e0fd1bSAndreas Gohr $title = ltrim($title,'0123456789._-'); 9728a831f2bSAndreas Gohr if(empty($title)) $title='section'; 973c5a8fd96SAndreas Gohr 974c5a8fd96SAndreas Gohr if($create){ 975c5a8fd96SAndreas Gohr // make sure tiles are unique 976c5a8fd96SAndreas Gohr $num = ''; 977c5a8fd96SAndreas Gohr while(in_array($title.$num,$this->headers)){ 9780affd488SAndreas Gohr ($num) ? $num++ : $num = 1; 979c5a8fd96SAndreas Gohr } 980c5a8fd96SAndreas Gohr $title = $title.$num; 981c5a8fd96SAndreas Gohr $this->headers[] = $title; 982c5a8fd96SAndreas Gohr } 983c5a8fd96SAndreas Gohr 9848a831f2bSAndreas Gohr return $title; 9850cecf9d5Sandi } 9860cecf9d5Sandi 987af587fa8Sandi /** 9883fd0b676Sandi * Construct a title and handle images in titles 9893fd0b676Sandi * 9900b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 9913fd0b676Sandi */ 992433bef32Sandi function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 993bb0a59d4Sjan global $conf; 994bb0a59d4Sjan 99544881bd0Shenning.noren $isImage = false; 9960cecf9d5Sandi if ( is_null($title) ) { 997bb0a59d4Sjan if ($conf['useheading'] && $id) { 998bb0a59d4Sjan $heading = p_get_first_heading($id); 999bb0a59d4Sjan if ($heading) { 1000433bef32Sandi return $this->_xmlEntities($heading); 1001bb0a59d4Sjan } 1002bb0a59d4Sjan } 1003433bef32Sandi return $this->_xmlEntities($default); 10040cecf9d5Sandi } else if ( is_string($title) ) { 1005433bef32Sandi return $this->_xmlEntities($title); 10060cecf9d5Sandi } else if ( is_array($title) ) { 100744881bd0Shenning.noren $isImage = true; 1008433bef32Sandi return $this->_imageTitle($title); 10090cecf9d5Sandi } 10100cecf9d5Sandi } 10110cecf9d5Sandi 10120cecf9d5Sandi /** 10133fd0b676Sandi * Returns an HTML code for images used in link titles 10143fd0b676Sandi * 10153fd0b676Sandi * @todo Resolve namespace on internal images 10163fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10170cecf9d5Sandi */ 1018433bef32Sandi function _imageTitle($img) { 1019433bef32Sandi return $this->_media($img['src'], 10204826ab45Sandi $img['title'], 10214826ab45Sandi $img['align'], 10224826ab45Sandi $img['width'], 10234826ab45Sandi $img['height'], 10244826ab45Sandi $img['cache']); 10250cecf9d5Sandi } 10260cecf9d5Sandi} 10270cecf9d5Sandi 10284826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 : 1029