xref: /dokuwiki/inc/parser/xhtml.php (revision 169c72406cf283b0bb8c7e6ec8ee17e6e0be4f8b)
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']){
82*169c7240Schris            $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*169c7240Schris    function render_TOC($toc){
95*169c7240Schris        if(count($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;
102*169c7240Schris        $out .= html_buildlist($toc,'toc',array(__CLASS__,'_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">'.
112*169c7240Schris               Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>';
113c5a8fd96SAndreas Gohr    }
114c5a8fd96SAndreas Gohr
115e7856beaSchris    function toc_additem($id, $text, $level) {
116af587fa8Sandi        global $conf;
117af587fa8Sandi
118c5a8fd96SAndreas Gohr        //handle TOC
119c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
120c5a8fd96SAndreas Gohr            // the TOC is one of our standard ul list arrays ;-)
121e7856beaSchris            $this->toc[] = array( 'hid'   => $id,
122c5a8fd96SAndreas Gohr                                  'title' => $text,
123c5a8fd96SAndreas Gohr                                  'type'  => 'ul',
12421ed2ba4Sjan                                  'level' => $level-$conf['toptoclevel']+1);
125c5a8fd96SAndreas Gohr        }
126e7856beaSchris		}
127e7856beaSchris
128e7856beaSchris    function header($text, $level, $pos) {
129e7856beaSchris
130e7856beaSchris        $hid = $this->_headerToLink($text,true);
131e7856beaSchris
132e7856beaSchris        //only add items within configured levels
133e7856beaSchris        $this->toc_additem($hid, $text, $level);
134c5a8fd96SAndreas Gohr
135c5a8fd96SAndreas Gohr        // write the header
136c5a8fd96SAndreas Gohr        $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
137a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
138c6a1c1bfSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1390cecf9d5Sandi    }
1400cecf9d5Sandi
14135dae8b0SBen Coburn     /**
14235dae8b0SBen Coburn     * Section edit marker is replaced by an edit button when
14335dae8b0SBen Coburn     * the page is editable. Replacement done in 'inc/html.php#html_secedit'
14435dae8b0SBen Coburn     *
14535dae8b0SBen Coburn     * @author Andreas Gohr <andi@splitbrain.org>
14635dae8b0SBen Coburn     * @author Ben Coburn   <btcoburn@silicodon.net>
14735dae8b0SBen Coburn     */
14835dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {
14935dae8b0SBen Coburn        global $conf;
15035dae8b0SBen Coburn
15135dae8b0SBen Coburn        if ($start!=-1 && $level<=$conf['maxseclevel']) {
15235dae8b0SBen Coburn            $name = str_replace('"', '', $name);
15335dae8b0SBen Coburn            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
15435dae8b0SBen Coburn        }
15535dae8b0SBen Coburn    }
15635dae8b0SBen Coburn
1570cecf9d5Sandi    function section_open($level) {
158a2d649c4Sandi        $this->doc .= "<div class=\"level$level\">".DOKU_LF;
1590cecf9d5Sandi    }
1600cecf9d5Sandi
1610cecf9d5Sandi    function section_close() {
162a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1630cecf9d5Sandi    }
1640cecf9d5Sandi
1650cecf9d5Sandi    function cdata($text) {
166a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1670cecf9d5Sandi    }
1680cecf9d5Sandi
1690cecf9d5Sandi    function p_open() {
170a2d649c4Sandi        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
1710cecf9d5Sandi    }
1720cecf9d5Sandi
1730cecf9d5Sandi    function p_close() {
174a2d649c4Sandi        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
1750cecf9d5Sandi    }
1760cecf9d5Sandi
1770cecf9d5Sandi    function linebreak() {
178a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
1790cecf9d5Sandi    }
1800cecf9d5Sandi
1810cecf9d5Sandi    function hr() {
1824beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
1830cecf9d5Sandi    }
1840cecf9d5Sandi
1850cecf9d5Sandi    function strong_open() {
186a2d649c4Sandi        $this->doc .= '<strong>';
1870cecf9d5Sandi    }
1880cecf9d5Sandi
1890cecf9d5Sandi    function strong_close() {
190a2d649c4Sandi        $this->doc .= '</strong>';
1910cecf9d5Sandi    }
1920cecf9d5Sandi
1930cecf9d5Sandi    function emphasis_open() {
194a2d649c4Sandi        $this->doc .= '<em>';
1950cecf9d5Sandi    }
1960cecf9d5Sandi
1970cecf9d5Sandi    function emphasis_close() {
198a2d649c4Sandi        $this->doc .= '</em>';
1990cecf9d5Sandi    }
2000cecf9d5Sandi
2010cecf9d5Sandi    function underline_open() {
20202e51121SAnika Henke        $this->doc .= '<em class="u">';
2030cecf9d5Sandi    }
2040cecf9d5Sandi
2050cecf9d5Sandi    function underline_close() {
20602e51121SAnika Henke        $this->doc .= '</em>';
2070cecf9d5Sandi    }
2080cecf9d5Sandi
2090cecf9d5Sandi    function monospace_open() {
210a2d649c4Sandi        $this->doc .= '<code>';
2110cecf9d5Sandi    }
2120cecf9d5Sandi
2130cecf9d5Sandi    function monospace_close() {
214a2d649c4Sandi        $this->doc .= '</code>';
2150cecf9d5Sandi    }
2160cecf9d5Sandi
2170cecf9d5Sandi    function subscript_open() {
218a2d649c4Sandi        $this->doc .= '<sub>';
2190cecf9d5Sandi    }
2200cecf9d5Sandi
2210cecf9d5Sandi    function subscript_close() {
222a2d649c4Sandi        $this->doc .= '</sub>';
2230cecf9d5Sandi    }
2240cecf9d5Sandi
2250cecf9d5Sandi    function superscript_open() {
226a2d649c4Sandi        $this->doc .= '<sup>';
2270cecf9d5Sandi    }
2280cecf9d5Sandi
2290cecf9d5Sandi    function superscript_close() {
230a2d649c4Sandi        $this->doc .= '</sup>';
2310cecf9d5Sandi    }
2320cecf9d5Sandi
2330cecf9d5Sandi    function deleted_open() {
234a2d649c4Sandi        $this->doc .= '<del>';
2350cecf9d5Sandi    }
2360cecf9d5Sandi
2370cecf9d5Sandi    function deleted_close() {
238a2d649c4Sandi        $this->doc .= '</del>';
2390cecf9d5Sandi    }
2400cecf9d5Sandi
2413fd0b676Sandi    /**
2423fd0b676Sandi     * Callback for footnote start syntax
2433fd0b676Sandi     *
2443fd0b676Sandi     * All following content will go to the footnote instead of
245d74aace9Schris     * the document. To achieve this the previous rendered content
2463fd0b676Sandi     * is moved to $store and $doc is cleared
2473fd0b676Sandi     *
2483fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2493fd0b676Sandi     */
2500cecf9d5Sandi    function footnote_open() {
2517764a90aSandi
2527764a90aSandi        // move current content to store and record footnote
2537764a90aSandi        $this->store = $this->doc;
2547764a90aSandi        $this->doc   = '';
2550cecf9d5Sandi    }
2560cecf9d5Sandi
2573fd0b676Sandi    /**
2583fd0b676Sandi     * Callback for footnote end syntax
2593fd0b676Sandi     *
2603fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2613fd0b676Sandi     * content is restored from $store again
2623fd0b676Sandi     *
2633fd0b676Sandi     * @author Andreas Gohr
2643fd0b676Sandi     */
2650cecf9d5Sandi    function footnote_close() {
2667764a90aSandi
267d74aace9Schris        // recover footnote into the stack and restore old content
268d74aace9Schris        $footnote = $this->doc;
2697764a90aSandi        $this->doc = $this->store;
2707764a90aSandi        $this->store = '';
271d74aace9Schris
272d74aace9Schris        // check to see if this footnote has been seen before
273d74aace9Schris        $i = array_search($footnote, $this->footnotes);
274d74aace9Schris
275d74aace9Schris        if ($i === false) {
276d74aace9Schris            // its a new footnote, add it to the $footnotes array
277d74aace9Schris            $id = count($this->footnotes)+1;
278d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
279d74aace9Schris        } else {
280d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
281d74aace9Schris            $i++;
282d74aace9Schris            $id = count($this->footnotes)+1;
283d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
284d74aace9Schris        }
285d74aace9Schris
2866b379cbfSAndreas Gohr        // output the footnote reference and link
2876b379cbfSAndreas Gohr        $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>';
2880cecf9d5Sandi    }
2890cecf9d5Sandi
2900cecf9d5Sandi    function listu_open() {
291a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
2920cecf9d5Sandi    }
2930cecf9d5Sandi
2940cecf9d5Sandi    function listu_close() {
295a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
2960cecf9d5Sandi    }
2970cecf9d5Sandi
2980cecf9d5Sandi    function listo_open() {
299a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
3000cecf9d5Sandi    }
3010cecf9d5Sandi
3020cecf9d5Sandi    function listo_close() {
303a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
3040cecf9d5Sandi    }
3050cecf9d5Sandi
3060cecf9d5Sandi    function listitem_open($level) {
307a2d649c4Sandi        $this->doc .= '<li class="level'.$level.'">';
3080cecf9d5Sandi    }
3090cecf9d5Sandi
3100cecf9d5Sandi    function listitem_close() {
311a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
3120cecf9d5Sandi    }
3130cecf9d5Sandi
3140cecf9d5Sandi    function listcontent_open() {
31590db23d7Schris        $this->doc .= '<div class="li">';
3160cecf9d5Sandi    }
3170cecf9d5Sandi
3180cecf9d5Sandi    function listcontent_close() {
31990db23d7Schris        $this->doc .= '</div>'.DOKU_LF;
3200cecf9d5Sandi    }
3210cecf9d5Sandi
3220cecf9d5Sandi    function unformatted($text) {
323a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3240cecf9d5Sandi    }
3250cecf9d5Sandi
3260cecf9d5Sandi    /**
3273fd0b676Sandi     * Execute PHP code if allowed
3283fd0b676Sandi     *
3293fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3300cecf9d5Sandi     */
3310cecf9d5Sandi    function php($text) {
3324de671bcSandi        global $conf;
3334de671bcSandi        if($conf['phpok']){
334bad0b545Sandi            ob_start();
3354de671bcSandi            eval($text);
3363fd0b676Sandi            $this->doc .= ob_get_contents();
337bad0b545Sandi            ob_end_clean();
3384de671bcSandi        }else{
3394de671bcSandi            $this->file($text);
3404de671bcSandi        }
3410cecf9d5Sandi    }
3420cecf9d5Sandi
3430cecf9d5Sandi    /**
3443fd0b676Sandi     * Insert HTML if allowed
3453fd0b676Sandi     *
3463fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3470cecf9d5Sandi     */
3480cecf9d5Sandi    function html($text) {
3494de671bcSandi        global $conf;
3504de671bcSandi        if($conf['htmlok']){
351a2d649c4Sandi          $this->doc .= $text;
3524de671bcSandi        }else{
3530cecf9d5Sandi          $this->file($text);
3540cecf9d5Sandi        }
3554de671bcSandi    }
3560cecf9d5Sandi
3570cecf9d5Sandi    function preformatted($text) {
358a2d649c4Sandi        $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
3590cecf9d5Sandi    }
3600cecf9d5Sandi
3610cecf9d5Sandi    function file($text) {
362a2d649c4Sandi        $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
3630cecf9d5Sandi    }
3640cecf9d5Sandi
3650cecf9d5Sandi    function quote_open() {
36696331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
3670cecf9d5Sandi    }
3680cecf9d5Sandi
3690cecf9d5Sandi    function quote_close() {
37096331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
3710cecf9d5Sandi    }
3720cecf9d5Sandi
3730cecf9d5Sandi    /**
3743fd0b676Sandi     * Callback for code text
3753fd0b676Sandi     *
3763fd0b676Sandi     * Uses GeSHi to highlight language syntax
3773fd0b676Sandi     *
3783fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3790cecf9d5Sandi     */
3800cecf9d5Sandi    function code($text, $language = NULL) {
3814de671bcSandi        global $conf;
3820cecf9d5Sandi
3830cecf9d5Sandi        if ( is_null($language) ) {
3840cecf9d5Sandi            $this->preformatted($text);
3850cecf9d5Sandi        } else {
386852896daSAndreas Gohr            //strip leading and trailing blank line
387313da78aSandi            $text = preg_replace('/^\s*?\n/','',$text);
388852896daSAndreas Gohr            $text = preg_replace('/\s*?\n$/','',$text);
3898f7d700cSchris            $this->doc .= p_xhtml_cached_geshi($text, $language);
3900cecf9d5Sandi        }
3910cecf9d5Sandi    }
3920cecf9d5Sandi
3930cecf9d5Sandi    function acronym($acronym) {
3940cecf9d5Sandi
3950cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
3960cecf9d5Sandi
397433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
3980cecf9d5Sandi
399a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
400433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
4010cecf9d5Sandi
4020cecf9d5Sandi        } else {
403a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4040cecf9d5Sandi        }
4050cecf9d5Sandi    }
4060cecf9d5Sandi
4070cecf9d5Sandi    function smiley($smiley) {
4080cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
409433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
410f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4114beabca9SAnika Henke                '" class="middle" alt="'.
412433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4130cecf9d5Sandi        } else {
414a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4150cecf9d5Sandi        }
4160cecf9d5Sandi    }
4170cecf9d5Sandi
418f62ea8a1Sandi    /*
4194de671bcSandi    * not used
4200cecf9d5Sandi    function wordblock($word) {
4210cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
422a2d649c4Sandi            $this->doc .= '** BLEEP **';
4230cecf9d5Sandi        } else {
424a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4250cecf9d5Sandi        }
4260cecf9d5Sandi    }
4274de671bcSandi    */
4280cecf9d5Sandi
4290cecf9d5Sandi    function entity($entity) {
4300cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
431a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4320cecf9d5Sandi        } else {
433a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4340cecf9d5Sandi        }
4350cecf9d5Sandi    }
4360cecf9d5Sandi
4370cecf9d5Sandi    function multiplyentity($x, $y) {
438a2d649c4Sandi        $this->doc .= "$x&times;$y";
4390cecf9d5Sandi    }
4400cecf9d5Sandi
4410cecf9d5Sandi    function singlequoteopening() {
442a2d649c4Sandi        $this->doc .= "&lsquo;";
4430cecf9d5Sandi    }
4440cecf9d5Sandi
4450cecf9d5Sandi    function singlequoteclosing() {
446a2d649c4Sandi        $this->doc .= "&rsquo;";
4470cecf9d5Sandi    }
4480cecf9d5Sandi
4490cecf9d5Sandi    function doublequoteopening() {
450a2d649c4Sandi        $this->doc .= "&ldquo;";
4510cecf9d5Sandi    }
4520cecf9d5Sandi
4530cecf9d5Sandi    function doublequoteclosing() {
454a2d649c4Sandi        $this->doc .= "&rdquo;";
4550cecf9d5Sandi    }
4560cecf9d5Sandi
4570cecf9d5Sandi    /**
4580cecf9d5Sandi    */
4590cecf9d5Sandi    function camelcaselink($link) {
46011d0aa47Sandi      $this->internallink($link,$link);
4610cecf9d5Sandi    }
4620cecf9d5Sandi
4630b7c14c2Sandi
4640b7c14c2Sandi    function locallink($hash, $name = NULL){
4650b7c14c2Sandi        global $ID;
4660b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
4670b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
4680b7c14c2Sandi        $title = $ID.' &crarr;';
4690b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
4700b7c14c2Sandi        $this->doc .= $name;
4710b7c14c2Sandi        $this->doc .= '</a>';
4720b7c14c2Sandi    }
4730b7c14c2Sandi
474cffcc403Sandi    /**
4753fd0b676Sandi     * Render an internal Wiki Link
4763fd0b676Sandi     *
477cffcc403Sandi     * $search and $returnonly are not for the renderer but are used
478cffcc403Sandi     * elsewhere - no need to implement them in other renderers
4793fd0b676Sandi     *
4803fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
481cffcc403Sandi     */
482cffcc403Sandi    function internallink($id, $name = NULL, $search=NULL,$returnonly=false) {
483ba11bd29Sandi        global $conf;
48437e34a5eSandi        global $ID;
4850339c872Sjan        // default name is based on $id as given
4860339c872Sjan        $default = $this->_simpleTitle($id);
4870339c872Sjan        // now first resolve and clean up the $id
48837e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
4890339c872Sjan        $name = $this->_getLinkTitle($name, $default, $isImage, $id);
4900e1c636eSandi        if ( !$isImage ) {
4910e1c636eSandi            if ( $exists ) {
492ba11bd29Sandi                $class='wikilink1';
4930cecf9d5Sandi            } else {
494ba11bd29Sandi                $class='wikilink2';
4950cecf9d5Sandi            }
4960cecf9d5Sandi        } else {
497ba11bd29Sandi            $class='media';
4980cecf9d5Sandi        }
4990cecf9d5Sandi
500a1685bedSandi        //keep hash anchor
501ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
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'].='&amp;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(\''.
609433bef32Sandi                        $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).
6101d47afe1Sandi                        '\');}" onkeypress="if(document.all == null){alert(\''.
611433bef32Sandi                        $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"';
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) {
6703685f775Sandi        global $conf;
67137e34a5eSandi        global $ID;
67237e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
6730cecf9d5Sandi
6743685f775Sandi        $link = array();
6753685f775Sandi        $link['class']  = 'media';
6763685f775Sandi        $link['style']  = '';
6773685f775Sandi        $link['pre']    = '';
6783685f775Sandi        $link['suf']    = '';
6795e163278SAndreas Gohr        $link['more']   = '';
6803685f775Sandi        $link['target'] = $conf['target']['media'];
681d98d4540SBen Coburn        $noLink = false;
6823685f775Sandi
683433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
68455efc227SAndreas Gohr        list($ext,$mime) = mimetype($src);
6855667eb65SAndreas Gohr        if(substr($mime,0,5) == 'image'){
686dc673a5bSjoe.lapp             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
6872ca14335SEsther Brunner         }elseif($mime == 'application/x-shockwave-flash'){
6882ca14335SEsther Brunner             // don't link flash movies
68944881bd0Shenning.noren             $noLink = true;
69055efc227SAndreas Gohr         }else{
6912ca14335SEsther Brunner             // add file icons
6929d2ddea4SAndreas Gohr             $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
6939d2ddea4SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$class;
6946de3759aSAndreas Gohr             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
69555efc227SAndreas Gohr         }
696433bef32Sandi         $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
6973685f775Sandi
6983685f775Sandi         //output formatted
699dc673a5bSjoe.lapp         if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7002ca14335SEsther Brunner         else $this->doc .= $this->_formatLink($link);
7010cecf9d5Sandi    }
7020cecf9d5Sandi
7030cecf9d5Sandi    /**
7044826ab45Sandi     * @todo don't add link for flash
7050cecf9d5Sandi     */
7064826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
707dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
7083685f775Sandi        global $conf;
7090cecf9d5Sandi
7103685f775Sandi        $link = array();
7113685f775Sandi        $link['class']  = 'media';
7123685f775Sandi        $link['style']  = '';
7133685f775Sandi        $link['pre']    = '';
7143685f775Sandi        $link['suf']    = '';
7155e163278SAndreas Gohr        $link['more']   = '';
7163685f775Sandi        $link['target'] = $conf['target']['media'];
7173685f775Sandi
718433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
7196de3759aSAndreas Gohr        $link['url']    = ml($src,array('cache'=>$cache));
720433bef32Sandi        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
721d98d4540SBen Coburn        $noLink = false;
7223685f775Sandi
7232ca14335SEsther Brunner        list($ext,$mime) = mimetype($src);
7242ca14335SEsther Brunner        if(substr($mime,0,5) == 'image'){
7252ca14335SEsther Brunner             // link only jpeg images
72644881bd0Shenning.noren             // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7272ca14335SEsther Brunner        }elseif($mime == 'application/x-shockwave-flash'){
7282ca14335SEsther Brunner             // don't link flash movies
72944881bd0Shenning.noren             $noLink = true;
7302ca14335SEsther Brunner        }else{
7312ca14335SEsther Brunner             // add file icons
732d15166e5SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$ext;
7332ca14335SEsther Brunner         }
7342ca14335SEsther Brunner
7353685f775Sandi        //output formatted
736dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7372ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7380cecf9d5Sandi    }
7390cecf9d5Sandi
7404826ab45Sandi    /**
7413db95becSAndreas Gohr     * Renders an RSS feed
742b625487dSandi     *
743b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
744b625487dSandi     */
7453db95becSAndreas Gohr    function rss ($url,$params){
746b625487dSandi        global $lang;
7473db95becSAndreas Gohr        global $conf;
7483db95becSAndreas Gohr
7493db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
7503db95becSAndreas Gohr        $feed = new FeedParser();
7513db95becSAndreas Gohr        $feed->feed_url($url);
752b625487dSandi
753b625487dSandi        //disable warning while fetching
754bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
7553db95becSAndreas Gohr        $rc = $feed->init();
756bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
757b625487dSandi
7583db95becSAndreas Gohr        //decide on start and end
7593db95becSAndreas Gohr        if($params['reverse']){
7603db95becSAndreas Gohr            $mod = -1;
7613db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
7623db95becSAndreas Gohr            $end   = $start - ($params['max']);
763b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
7643db95becSAndreas Gohr        }else{
7653db95becSAndreas Gohr            $mod   = 1;
7663db95becSAndreas Gohr            $start = 0;
7673db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
7683db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
7693db95becSAndreas Gohr        }
7703db95becSAndreas Gohr
771a2d649c4Sandi        $this->doc .= '<ul class="rss">';
7723db95becSAndreas Gohr        if($rc){
7733db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
7741bde1582SAndreas Gohr                $item = $feed->get_item($x);
7753db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
7761bde1582SAndreas Gohr                $this->externallink($item->get_permalink(),
7771bde1582SAndreas Gohr                                    $item->get_title());
7783db95becSAndreas Gohr                if($params['author']){
7791bde1582SAndreas Gohr                    $author = $item->get_author(0);
7801bde1582SAndreas Gohr                    if($author){
7811bde1582SAndreas Gohr                        $name = $author->get_name();
7821bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
7831bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
7841bde1582SAndreas Gohr                    }
7853db95becSAndreas Gohr                }
7863db95becSAndreas Gohr                if($params['date']){
7871bde1582SAndreas Gohr                    $this->doc .= ' ('.$item->get_date($conf['dformat']).')';
7883db95becSAndreas Gohr                }
7891bde1582SAndreas Gohr                if($params['details']){
7903db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
7913db95becSAndreas Gohr                    if($htmlok){
7921bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
7933db95becSAndreas Gohr                    }else{
7941bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
7953db95becSAndreas Gohr                    }
7963db95becSAndreas Gohr                    $this->doc .= '</div>';
7973db95becSAndreas Gohr                }
7983db95becSAndreas Gohr
7993db95becSAndreas Gohr                $this->doc .= '</div></li>';
800b625487dSandi            }
801b625487dSandi        }else{
8023db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
803a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
804b625487dSandi            $this->externallink($url);
8053db95becSAndreas Gohr            $this->doc .= '</div></li>';
806b625487dSandi        }
807a2d649c4Sandi        $this->doc .= '</ul>';
808b625487dSandi    }
809b625487dSandi
8100cecf9d5Sandi    // $numrows not yet implemented
8110cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){
812a2d649c4Sandi        $this->doc .= '<table class="inline">'.DOKU_LF;
8130cecf9d5Sandi    }
8140cecf9d5Sandi
8150cecf9d5Sandi    function table_close(){
816cb42b03dSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
8170cecf9d5Sandi    }
8180cecf9d5Sandi
8190cecf9d5Sandi    function tablerow_open(){
820a2d649c4Sandi        $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
8210cecf9d5Sandi    }
8220cecf9d5Sandi
8230cecf9d5Sandi    function tablerow_close(){
824a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
8250cecf9d5Sandi    }
8260cecf9d5Sandi
8270cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){
828a2d649c4Sandi        $this->doc .= '<th';
8290cecf9d5Sandi        if ( !is_null($align) ) {
830a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8310cecf9d5Sandi        }
8320cecf9d5Sandi        if ( $colspan > 1 ) {
833a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8340cecf9d5Sandi        }
835a2d649c4Sandi        $this->doc .= '>';
8360cecf9d5Sandi    }
8370cecf9d5Sandi
8380cecf9d5Sandi    function tableheader_close(){
839a2d649c4Sandi        $this->doc .= '</th>';
8400cecf9d5Sandi    }
8410cecf9d5Sandi
8420cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){
843a2d649c4Sandi        $this->doc .= '<td';
8440cecf9d5Sandi        if ( !is_null($align) ) {
845a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8460cecf9d5Sandi        }
8470cecf9d5Sandi        if ( $colspan > 1 ) {
848a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8490cecf9d5Sandi        }
850a2d649c4Sandi        $this->doc .= '>';
8510cecf9d5Sandi    }
8520cecf9d5Sandi
8530cecf9d5Sandi    function tablecell_close(){
854a2d649c4Sandi        $this->doc .= '</td>';
8550cecf9d5Sandi    }
8560cecf9d5Sandi
8570cecf9d5Sandi    //----------------------------------------------------------
8580cecf9d5Sandi    // Utils
8590cecf9d5Sandi
860ba11bd29Sandi    /**
8613fd0b676Sandi     * Build a link
8623fd0b676Sandi     *
8633fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
864ba11bd29Sandi     *
865ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
866ba11bd29Sandi     */
867433bef32Sandi    function _formatLink($link){
868ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
869ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
870ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
871ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
872ba11bd29Sandi        }
873ba11bd29Sandi        //remove double encodings in titles
874ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
875ba11bd29Sandi
876453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
877453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
878453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
879453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
880453493f2SAndreas Gohr
881ba11bd29Sandi        $ret  = '';
882ba11bd29Sandi        $ret .= $link['pre'];
883ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
884bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
885bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
886bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
887bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
888bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
889ba11bd29Sandi        $ret .= '>';
890ba11bd29Sandi        $ret .= $link['name'];
891ba11bd29Sandi        $ret .= '</a>';
892ba11bd29Sandi        $ret .= $link['suf'];
893ba11bd29Sandi        return $ret;
894ba11bd29Sandi    }
895ba11bd29Sandi
896ba11bd29Sandi    /**
8973fd0b676Sandi     * Renders internal and external media
8983fd0b676Sandi     *
8993fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9003fd0b676Sandi     */
9013fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
9023fd0b676Sandi                      $height=NULL, $cache=NULL) {
9033fd0b676Sandi
9043fd0b676Sandi        $ret = '';
9053fd0b676Sandi
9063fd0b676Sandi        list($ext,$mime) = mimetype($src);
9073fd0b676Sandi        if(substr($mime,0,5) == 'image'){
9083fd0b676Sandi            //add image tag
9096de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
9103fd0b676Sandi            $ret .= ' class="media'.$align.'"';
9113fd0b676Sandi
9123fd0b676Sandi            if (!is_null($title)) {
9133fd0b676Sandi                $ret .= ' title="'.$this->_xmlEntities($title).'"';
9143fd0b676Sandi                $ret .= ' alt="'.$this->_xmlEntities($title).'"';
91555efc227SAndreas Gohr            }elseif($ext == 'jpg' || $ext == 'jpeg'){
91655efc227SAndreas Gohr                //try to use the caption from IPTC/EXIF
91755efc227SAndreas Gohr                require_once(DOKU_INC.'inc/JpegMeta.php');
91855efc227SAndreas Gohr                $jpeg =& new JpegMeta(mediaFN($src));
91955efc227SAndreas Gohr                if($jpeg !== false) $cap = $jpeg->getTitle();
92055efc227SAndreas Gohr                if($cap){
92155efc227SAndreas Gohr                    $ret .= ' title="'.$this->_xmlEntities($cap).'"';
92255efc227SAndreas Gohr                    $ret .= ' alt="'.$this->_xmlEntities($cap).'"';
92355efc227SAndreas Gohr                }
9243fd0b676Sandi            }else{
9253fd0b676Sandi                $ret .= ' alt=""';
9263fd0b676Sandi            }
9273fd0b676Sandi
9283fd0b676Sandi            if ( !is_null($width) )
9293fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
9303fd0b676Sandi
9313fd0b676Sandi            if ( !is_null($height) )
9323fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
9333fd0b676Sandi
9343fd0b676Sandi            $ret .= ' />';
9353fd0b676Sandi
9363fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
9373fd0b676Sandi            $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
9383fd0b676Sandi                    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
9393fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9403fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9413fd0b676Sandi            $ret .= '>'.DOKU_LF;
9426de3759aSAndreas Gohr            $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
9433fd0b676Sandi            $ret .= '<param name="quality" value="high" />'.DOKU_LF;
9446de3759aSAndreas Gohr            $ret .= '<embed src="'.ml($src).'"'.
9453fd0b676Sandi                    ' quality="high"';
9463fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9473fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9483fd0b676Sandi            $ret .= ' type="application/x-shockwave-flash"'.
9493fd0b676Sandi                    ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF;
9503fd0b676Sandi            $ret .= '</object>'.DOKU_LF;
9513fd0b676Sandi
9520f428d7dSAndreas Gohr        }elseif($title){
9533fd0b676Sandi            // well at least we have a title to display
9543fd0b676Sandi            $ret .= $this->_xmlEntities($title);
9553fd0b676Sandi        }else{
9565291ca3aSAndreas Gohr            // just show the sourcename
9570f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
9583fd0b676Sandi        }
9593fd0b676Sandi
9603fd0b676Sandi        return $ret;
9613fd0b676Sandi    }
9623fd0b676Sandi
963433bef32Sandi    function _xmlEntities($string) {
9640cecf9d5Sandi        return htmlspecialchars($string);
9650cecf9d5Sandi    }
9660cecf9d5Sandi
9678a831f2bSAndreas Gohr    /**
9688a831f2bSAndreas Gohr     * Creates a linkid from a headline
969c5a8fd96SAndreas Gohr     *
970c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
971c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
972c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
9738a831f2bSAndreas Gohr     */
974c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
975501af51eSAndreas Gohr        $title = str_replace(':','',cleanID($title));
976a9e0fd1bSAndreas Gohr        $title = ltrim($title,'0123456789._-');
9778a831f2bSAndreas Gohr        if(empty($title)) $title='section';
978c5a8fd96SAndreas Gohr
979c5a8fd96SAndreas Gohr        if($create){
980c5a8fd96SAndreas Gohr            // make sure tiles are unique
981c5a8fd96SAndreas Gohr            $num = '';
982c5a8fd96SAndreas Gohr            while(in_array($title.$num,$this->headers)){
9830affd488SAndreas Gohr                ($num) ? $num++ : $num = 1;
984c5a8fd96SAndreas Gohr            }
985c5a8fd96SAndreas Gohr            $title = $title.$num;
986c5a8fd96SAndreas Gohr            $this->headers[] = $title;
987c5a8fd96SAndreas Gohr        }
988c5a8fd96SAndreas Gohr
9898a831f2bSAndreas Gohr        return $title;
9900cecf9d5Sandi    }
9910cecf9d5Sandi
992af587fa8Sandi    /**
9933fd0b676Sandi     * Construct a title and handle images in titles
9943fd0b676Sandi     *
9950b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
9963fd0b676Sandi     */
997433bef32Sandi    function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
998bb0a59d4Sjan        global $conf;
999bb0a59d4Sjan
100044881bd0Shenning.noren        $isImage = false;
10010cecf9d5Sandi        if ( is_null($title) ) {
1002bb0a59d4Sjan            if ($conf['useheading'] && $id) {
1003fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1004bb0a59d4Sjan                if ($heading) {
1005433bef32Sandi                    return $this->_xmlEntities($heading);
1006bb0a59d4Sjan                }
1007bb0a59d4Sjan            }
1008433bef32Sandi            return $this->_xmlEntities($default);
10090cecf9d5Sandi        } else if ( is_string($title) ) {
1010433bef32Sandi            return $this->_xmlEntities($title);
10110cecf9d5Sandi        } else if ( is_array($title) ) {
101244881bd0Shenning.noren            $isImage = true;
1013433bef32Sandi            return $this->_imageTitle($title);
10140cecf9d5Sandi        }
10150cecf9d5Sandi    }
10160cecf9d5Sandi
10170cecf9d5Sandi    /**
10183fd0b676Sandi     * Returns an HTML code for images used in link titles
10193fd0b676Sandi     *
10203fd0b676Sandi     * @todo Resolve namespace on internal images
10213fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10220cecf9d5Sandi     */
1023433bef32Sandi    function _imageTitle($img) {
1024433bef32Sandi        return $this->_media($img['src'],
10254826ab45Sandi                              $img['title'],
10264826ab45Sandi                              $img['align'],
10274826ab45Sandi                              $img['width'],
10284826ab45Sandi                              $img['height'],
10294826ab45Sandi                              $img['cache']);
10300cecf9d5Sandi    }
10310cecf9d5Sandi}
10320cecf9d5Sandi
10334826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1034