xref: /dokuwiki/inc/parser/xhtml.php (revision 07f89c3c8f7bdf32c835189da7cd6e8393ab8570)
10cecf9d5Sandi<?php
2b625487dSandi/**
3b625487dSandi * Renderer for XHTML output
4b625487dSandi *
5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
7b625487dSandi */
8b625487dSandi
90cecf9d5Sandiif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
100cecf9d5Sandi
110cecf9d5Sandiif ( !defined('DOKU_LF') ) {
120cecf9d5Sandi    // Some whitespace to help View > Source
130cecf9d5Sandi    define ('DOKU_LF',"\n");
140cecf9d5Sandi}
150cecf9d5Sandi
160cecf9d5Sandiif ( !defined('DOKU_TAB') ) {
170cecf9d5Sandi    // Some whitespace to help View > Source
180cecf9d5Sandi    define ('DOKU_TAB',"\t");
190cecf9d5Sandi}
200cecf9d5Sandi
210e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php';
2256fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php';
230e1c636eSandi
240cecf9d5Sandi/**
25b625487dSandi * The Renderer
260cecf9d5Sandi */
27ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
280cecf9d5Sandi
29c5a8fd96SAndreas Gohr    // @access public
30c5a8fd96SAndreas Gohr    var $doc = '';        // will contain the whole document
31c5a8fd96SAndreas Gohr    var $toc = array();   // will contain the Table of Contents
32c5a8fd96SAndreas Gohr
330cecf9d5Sandi
340cecf9d5Sandi    var $headers = array();
350cecf9d5Sandi    var $footnotes = array();
36af587fa8Sandi    var $lastsec = 0;
377764a90aSandi    var $store = '';
387764a90aSandi
395f70445dSAndreas Gohr    function getFormat(){
405f70445dSAndreas Gohr        return 'xhtml';
415f70445dSAndreas Gohr    }
425f70445dSAndreas Gohr
435f70445dSAndreas Gohr
440cecf9d5Sandi    function document_start() {
45c5a8fd96SAndreas Gohr        //reset some internals
46c5a8fd96SAndreas Gohr        $this->toc     = array();
47c5a8fd96SAndreas Gohr        $this->headers = array();
480cecf9d5Sandi    }
490cecf9d5Sandi
500cecf9d5Sandi    function document_end() {
510cecf9d5Sandi        if ( count ($this->footnotes) > 0 ) {
52a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
53d74aace9Schris
54d74aace9Schris            $id = 0;
550cecf9d5Sandi            foreach ( $this->footnotes as $footnote ) {
56d74aace9Schris                $id++;   // the number of the current footnote
57d74aace9Schris
58d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
59d74aace9Schris                if (substr($footnote, 0, 5) != "@@FNT") {
60d74aace9Schris
61d74aace9Schris                    // open the footnote and set the anchor and backlink
62d74aace9Schris                    $this->doc .= '<div class="fn">';
6324a33b42SAndreas Gohr                    $this->doc .= '<a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
64d74aace9Schris                    $this->doc .= $id.')</a> '.DOKU_LF;
65d74aace9Schris
66d74aace9Schris                    // get any other footnotes that use the same markup
67d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
68d74aace9Schris
69d74aace9Schris                    if (count($alt)) {
70d74aace9Schris                      foreach ($alt as $ref) {
71d74aace9Schris                        // set anchor and backlink for the other footnotes
7224a33b42SAndreas Gohr                        $this->doc .= ', <a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
73d74aace9Schris                        $this->doc .= ($ref+1).')</a> '.DOKU_LF;
74d74aace9Schris                      }
75d74aace9Schris                    }
76d74aace9Schris
77d74aace9Schris                    // add footnote markup and close this footnote
78a2d649c4Sandi                    $this->doc .= $footnote;
79d74aace9Schris                    $this->doc .= '</div>' . DOKU_LF;
80d74aace9Schris                }
810cecf9d5Sandi            }
82a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
830cecf9d5Sandi        }
84c5a8fd96SAndreas Gohr
85c5a8fd96SAndreas Gohr        // prepend the TOC
86e41c4da9SAndreas Gohr        if($this->info['toc']){
87169c7240Schris            $this->doc = $this->render_TOC($this->toc).$this->doc;
880cecf9d5Sandi        }
893e55d035SAndreas Gohr
903e55d035SAndreas Gohr        // make sure there are no empty paragraphs
9127918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
92e41c4da9SAndreas Gohr    }
930cecf9d5Sandi
94c5a8fd96SAndreas Gohr    /**
95c5a8fd96SAndreas Gohr     * Return the TOC rendered to XHTML
96c5a8fd96SAndreas Gohr     *
97c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
98c5a8fd96SAndreas Gohr     */
99dd5eee54SAndreas Gohr    function render_TOC($toc=null){
100dd5eee54SAndreas Gohr        if(is_null($toc) && is_array($this->toc)) $toc = $this->toc;
101dd5eee54SAndreas Gohr
102169c7240Schris        if(count($toc) < 3) return '';
103c5a8fd96SAndreas Gohr        global $lang;
104c5a8fd96SAndreas Gohr        $out  = '<div class="toc">'.DOKU_LF;
105c5a8fd96SAndreas Gohr        $out .= '<div class="tocheader toctoggle" id="toc__header">';
106c5a8fd96SAndreas Gohr        $out .= $lang['toc'];
107c5a8fd96SAndreas Gohr        $out .= '</div>'.DOKU_LF;
108c5a8fd96SAndreas Gohr        $out .= '<div id="toc__inside">'.DOKU_LF;
109169c7240Schris        $out .= html_buildlist($toc,'toc',array(__CLASS__,'_tocitem'));
110c5a8fd96SAndreas Gohr        $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
111c5a8fd96SAndreas Gohr        return $out;
112c5a8fd96SAndreas Gohr    }
113c5a8fd96SAndreas Gohr
114c5a8fd96SAndreas Gohr    /**
115c5a8fd96SAndreas Gohr     * Callback for html_buildlist
116c5a8fd96SAndreas Gohr     */
117c5a8fd96SAndreas Gohr    function _tocitem($item){
118c5a8fd96SAndreas Gohr        return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'.
119169c7240Schris               Doku_Renderer_xhtml::_xmlEntities($item['title']).'</a></span>';
120c5a8fd96SAndreas Gohr    }
121c5a8fd96SAndreas Gohr
122e7856beaSchris    function toc_additem($id, $text, $level) {
123af587fa8Sandi        global $conf;
124af587fa8Sandi
125c5a8fd96SAndreas Gohr        //handle TOC
126c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
127c5a8fd96SAndreas Gohr            // the TOC is one of our standard ul list arrays ;-)
128e7856beaSchris            $this->toc[] = array( 'hid'   => $id,
129c5a8fd96SAndreas Gohr                                  'title' => $text,
130c5a8fd96SAndreas Gohr                                  'type'  => 'ul',
13121ed2ba4Sjan                                  'level' => $level-$conf['toptoclevel']+1);
132c5a8fd96SAndreas Gohr        }
133e7856beaSchris    }
134e7856beaSchris
135e7856beaSchris    function header($text, $level, $pos) {
136e7856beaSchris
137e7856beaSchris        $hid = $this->_headerToLink($text,true);
138e7856beaSchris
139e7856beaSchris        //only add items within configured levels
140e7856beaSchris        $this->toc_additem($hid, $text, $level);
141c5a8fd96SAndreas Gohr
142c5a8fd96SAndreas Gohr        // write the header
143c5a8fd96SAndreas Gohr        $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
144a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
145c6a1c1bfSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1460cecf9d5Sandi    }
1470cecf9d5Sandi
14835dae8b0SBen Coburn     /**
14935dae8b0SBen Coburn     * Section edit marker is replaced by an edit button when
15035dae8b0SBen Coburn     * the page is editable. Replacement done in 'inc/html.php#html_secedit'
15135dae8b0SBen Coburn     *
15235dae8b0SBen Coburn     * @author Andreas Gohr <andi@splitbrain.org>
15335dae8b0SBen Coburn     * @author Ben Coburn   <btcoburn@silicodon.net>
15435dae8b0SBen Coburn     */
15535dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {
15635dae8b0SBen Coburn        global $conf;
15735dae8b0SBen Coburn
15835dae8b0SBen Coburn        if ($start!=-1 && $level<=$conf['maxseclevel']) {
15935dae8b0SBen Coburn            $name = str_replace('"', '', $name);
16035dae8b0SBen Coburn            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
16135dae8b0SBen Coburn        }
16235dae8b0SBen Coburn    }
16335dae8b0SBen Coburn
1640cecf9d5Sandi    function section_open($level) {
165a2d649c4Sandi        $this->doc .= "<div class=\"level$level\">".DOKU_LF;
1660cecf9d5Sandi    }
1670cecf9d5Sandi
1680cecf9d5Sandi    function section_close() {
169a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1700cecf9d5Sandi    }
1710cecf9d5Sandi
1720cecf9d5Sandi    function cdata($text) {
173a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1740cecf9d5Sandi    }
1750cecf9d5Sandi
1760cecf9d5Sandi    function p_open() {
177a2d649c4Sandi        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
1780cecf9d5Sandi    }
1790cecf9d5Sandi
1800cecf9d5Sandi    function p_close() {
181a2d649c4Sandi        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
1820cecf9d5Sandi    }
1830cecf9d5Sandi
1840cecf9d5Sandi    function linebreak() {
185a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
1860cecf9d5Sandi    }
1870cecf9d5Sandi
1880cecf9d5Sandi    function hr() {
1894beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
1900cecf9d5Sandi    }
1910cecf9d5Sandi
1920cecf9d5Sandi    function strong_open() {
193a2d649c4Sandi        $this->doc .= '<strong>';
1940cecf9d5Sandi    }
1950cecf9d5Sandi
1960cecf9d5Sandi    function strong_close() {
197a2d649c4Sandi        $this->doc .= '</strong>';
1980cecf9d5Sandi    }
1990cecf9d5Sandi
2000cecf9d5Sandi    function emphasis_open() {
201a2d649c4Sandi        $this->doc .= '<em>';
2020cecf9d5Sandi    }
2030cecf9d5Sandi
2040cecf9d5Sandi    function emphasis_close() {
205a2d649c4Sandi        $this->doc .= '</em>';
2060cecf9d5Sandi    }
2070cecf9d5Sandi
2080cecf9d5Sandi    function underline_open() {
20902e51121SAnika Henke        $this->doc .= '<em class="u">';
2100cecf9d5Sandi    }
2110cecf9d5Sandi
2120cecf9d5Sandi    function underline_close() {
21302e51121SAnika Henke        $this->doc .= '</em>';
2140cecf9d5Sandi    }
2150cecf9d5Sandi
2160cecf9d5Sandi    function monospace_open() {
217a2d649c4Sandi        $this->doc .= '<code>';
2180cecf9d5Sandi    }
2190cecf9d5Sandi
2200cecf9d5Sandi    function monospace_close() {
221a2d649c4Sandi        $this->doc .= '</code>';
2220cecf9d5Sandi    }
2230cecf9d5Sandi
2240cecf9d5Sandi    function subscript_open() {
225a2d649c4Sandi        $this->doc .= '<sub>';
2260cecf9d5Sandi    }
2270cecf9d5Sandi
2280cecf9d5Sandi    function subscript_close() {
229a2d649c4Sandi        $this->doc .= '</sub>';
2300cecf9d5Sandi    }
2310cecf9d5Sandi
2320cecf9d5Sandi    function superscript_open() {
233a2d649c4Sandi        $this->doc .= '<sup>';
2340cecf9d5Sandi    }
2350cecf9d5Sandi
2360cecf9d5Sandi    function superscript_close() {
237a2d649c4Sandi        $this->doc .= '</sup>';
2380cecf9d5Sandi    }
2390cecf9d5Sandi
2400cecf9d5Sandi    function deleted_open() {
241a2d649c4Sandi        $this->doc .= '<del>';
2420cecf9d5Sandi    }
2430cecf9d5Sandi
2440cecf9d5Sandi    function deleted_close() {
245a2d649c4Sandi        $this->doc .= '</del>';
2460cecf9d5Sandi    }
2470cecf9d5Sandi
2483fd0b676Sandi    /**
2493fd0b676Sandi     * Callback for footnote start syntax
2503fd0b676Sandi     *
2513fd0b676Sandi     * All following content will go to the footnote instead of
252d74aace9Schris     * the document. To achieve this the previous rendered content
2533fd0b676Sandi     * is moved to $store and $doc is cleared
2543fd0b676Sandi     *
2553fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2563fd0b676Sandi     */
2570cecf9d5Sandi    function footnote_open() {
2587764a90aSandi
2597764a90aSandi        // move current content to store and record footnote
2607764a90aSandi        $this->store = $this->doc;
2617764a90aSandi        $this->doc   = '';
2620cecf9d5Sandi    }
2630cecf9d5Sandi
2643fd0b676Sandi    /**
2653fd0b676Sandi     * Callback for footnote end syntax
2663fd0b676Sandi     *
2673fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2683fd0b676Sandi     * content is restored from $store again
2693fd0b676Sandi     *
2703fd0b676Sandi     * @author Andreas Gohr
2713fd0b676Sandi     */
2720cecf9d5Sandi    function footnote_close() {
2737764a90aSandi
274d74aace9Schris        // recover footnote into the stack and restore old content
275d74aace9Schris        $footnote = $this->doc;
2767764a90aSandi        $this->doc = $this->store;
2777764a90aSandi        $this->store = '';
278d74aace9Schris
279d74aace9Schris        // check to see if this footnote has been seen before
280d74aace9Schris        $i = array_search($footnote, $this->footnotes);
281d74aace9Schris
282d74aace9Schris        if ($i === false) {
283d74aace9Schris            // its a new footnote, add it to the $footnotes array
284d74aace9Schris            $id = count($this->footnotes)+1;
285d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
286d74aace9Schris        } else {
287d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
288d74aace9Schris            $i++;
289d74aace9Schris            $id = count($this->footnotes)+1;
290d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
291d74aace9Schris        }
292d74aace9Schris
2936b379cbfSAndreas Gohr        // output the footnote reference and link
2946b379cbfSAndreas Gohr        $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a>';
2950cecf9d5Sandi    }
2960cecf9d5Sandi
2970cecf9d5Sandi    function listu_open() {
298a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
2990cecf9d5Sandi    }
3000cecf9d5Sandi
3010cecf9d5Sandi    function listu_close() {
302a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
3030cecf9d5Sandi    }
3040cecf9d5Sandi
3050cecf9d5Sandi    function listo_open() {
306a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
3070cecf9d5Sandi    }
3080cecf9d5Sandi
3090cecf9d5Sandi    function listo_close() {
310a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
3110cecf9d5Sandi    }
3120cecf9d5Sandi
3130cecf9d5Sandi    function listitem_open($level) {
314a2d649c4Sandi        $this->doc .= '<li class="level'.$level.'">';
3150cecf9d5Sandi    }
3160cecf9d5Sandi
3170cecf9d5Sandi    function listitem_close() {
318a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
3190cecf9d5Sandi    }
3200cecf9d5Sandi
3210cecf9d5Sandi    function listcontent_open() {
32290db23d7Schris        $this->doc .= '<div class="li">';
3230cecf9d5Sandi    }
3240cecf9d5Sandi
3250cecf9d5Sandi    function listcontent_close() {
32690db23d7Schris        $this->doc .= '</div>'.DOKU_LF;
3270cecf9d5Sandi    }
3280cecf9d5Sandi
3290cecf9d5Sandi    function unformatted($text) {
330a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3310cecf9d5Sandi    }
3320cecf9d5Sandi
3330cecf9d5Sandi    /**
3343fd0b676Sandi     * Execute PHP code if allowed
3353fd0b676Sandi     *
3363fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3370cecf9d5Sandi     */
3380cecf9d5Sandi    function php($text) {
3394de671bcSandi        global $conf;
3404de671bcSandi        if($conf['phpok']){
341bad0b545Sandi            ob_start();
3424de671bcSandi            eval($text);
3433fd0b676Sandi            $this->doc .= ob_get_contents();
344bad0b545Sandi            ob_end_clean();
3454de671bcSandi        }else{
3464de671bcSandi            $this->file($text);
3474de671bcSandi        }
3480cecf9d5Sandi    }
3490cecf9d5Sandi
350*07f89c3cSAnika Henke    function phpblock($text) {
351*07f89c3cSAnika Henke        $this->php($text);
352*07f89c3cSAnika Henke    }
353*07f89c3cSAnika Henke
3540cecf9d5Sandi    /**
3553fd0b676Sandi     * Insert HTML if allowed
3563fd0b676Sandi     *
3573fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3580cecf9d5Sandi     */
3590cecf9d5Sandi    function html($text) {
3604de671bcSandi        global $conf;
3614de671bcSandi        if($conf['htmlok']){
362a2d649c4Sandi          $this->doc .= $text;
3634de671bcSandi        }else{
3640cecf9d5Sandi          $this->file($text);
3650cecf9d5Sandi        }
3664de671bcSandi    }
3670cecf9d5Sandi
368*07f89c3cSAnika Henke    function htmlblock($text) {
369*07f89c3cSAnika Henke        $this->html($text);
370*07f89c3cSAnika Henke    }
371*07f89c3cSAnika Henke
3720cecf9d5Sandi    function preformatted($text) {
373a2d649c4Sandi        $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
3740cecf9d5Sandi    }
3750cecf9d5Sandi
3760cecf9d5Sandi    function file($text) {
377a2d649c4Sandi        $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
3780cecf9d5Sandi    }
3790cecf9d5Sandi
3800cecf9d5Sandi    function quote_open() {
38196331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
3820cecf9d5Sandi    }
3830cecf9d5Sandi
3840cecf9d5Sandi    function quote_close() {
38596331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
3860cecf9d5Sandi    }
3870cecf9d5Sandi
3880cecf9d5Sandi    /**
3893fd0b676Sandi     * Callback for code text
3903fd0b676Sandi     *
3913fd0b676Sandi     * Uses GeSHi to highlight language syntax
3923fd0b676Sandi     *
3933fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3940cecf9d5Sandi     */
3950cecf9d5Sandi    function code($text, $language = NULL) {
3964de671bcSandi        global $conf;
3970cecf9d5Sandi
3980cecf9d5Sandi        if ( is_null($language) ) {
3990cecf9d5Sandi            $this->preformatted($text);
4000cecf9d5Sandi        } else {
401852896daSAndreas Gohr            //strip leading and trailing blank line
402313da78aSandi            $text = preg_replace('/^\s*?\n/','',$text);
403852896daSAndreas Gohr            $text = preg_replace('/\s*?\n$/','',$text);
4048f7d700cSchris            $this->doc .= p_xhtml_cached_geshi($text, $language);
4050cecf9d5Sandi        }
4060cecf9d5Sandi    }
4070cecf9d5Sandi
4080cecf9d5Sandi    function acronym($acronym) {
4090cecf9d5Sandi
4100cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
4110cecf9d5Sandi
412433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
4130cecf9d5Sandi
414a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
415433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
4160cecf9d5Sandi
4170cecf9d5Sandi        } else {
418a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4190cecf9d5Sandi        }
4200cecf9d5Sandi    }
4210cecf9d5Sandi
4220cecf9d5Sandi    function smiley($smiley) {
4230cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
424433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
425f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4264beabca9SAnika Henke                '" class="middle" alt="'.
427433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4280cecf9d5Sandi        } else {
429a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4300cecf9d5Sandi        }
4310cecf9d5Sandi    }
4320cecf9d5Sandi
433f62ea8a1Sandi    /*
4344de671bcSandi    * not used
4350cecf9d5Sandi    function wordblock($word) {
4360cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
437a2d649c4Sandi            $this->doc .= '** BLEEP **';
4380cecf9d5Sandi        } else {
439a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4400cecf9d5Sandi        }
4410cecf9d5Sandi    }
4424de671bcSandi    */
4430cecf9d5Sandi
4440cecf9d5Sandi    function entity($entity) {
4450cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
446a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4470cecf9d5Sandi        } else {
448a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4490cecf9d5Sandi        }
4500cecf9d5Sandi    }
4510cecf9d5Sandi
4520cecf9d5Sandi    function multiplyentity($x, $y) {
453a2d649c4Sandi        $this->doc .= "$x&times;$y";
4540cecf9d5Sandi    }
4550cecf9d5Sandi
4560cecf9d5Sandi    function singlequoteopening() {
45771b40da2SAnika Henke        global $lang;
45871b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
4590cecf9d5Sandi    }
4600cecf9d5Sandi
4610cecf9d5Sandi    function singlequoteclosing() {
46271b40da2SAnika Henke        global $lang;
46371b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
4640cecf9d5Sandi    }
4650cecf9d5Sandi
46657d757d1SAndreas Gohr    function apostrophe() {
46757d757d1SAndreas Gohr        global $lang;
468a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
46957d757d1SAndreas Gohr    }
47057d757d1SAndreas Gohr
4710cecf9d5Sandi    function doublequoteopening() {
47271b40da2SAnika Henke        global $lang;
47371b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
4740cecf9d5Sandi    }
4750cecf9d5Sandi
4760cecf9d5Sandi    function doublequoteclosing() {
47771b40da2SAnika Henke        global $lang;
47871b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
4790cecf9d5Sandi    }
4800cecf9d5Sandi
4810cecf9d5Sandi    /**
4820cecf9d5Sandi    */
4830cecf9d5Sandi    function camelcaselink($link) {
48411d0aa47Sandi      $this->internallink($link,$link);
4850cecf9d5Sandi    }
4860cecf9d5Sandi
4870b7c14c2Sandi
4880b7c14c2Sandi    function locallink($hash, $name = NULL){
4890b7c14c2Sandi        global $ID;
4900b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
4910b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
4920b7c14c2Sandi        $title = $ID.' &crarr;';
4930b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
4940b7c14c2Sandi        $this->doc .= $name;
4950b7c14c2Sandi        $this->doc .= '</a>';
4960b7c14c2Sandi    }
4970b7c14c2Sandi
498cffcc403Sandi    /**
4993fd0b676Sandi     * Render an internal Wiki Link
5003fd0b676Sandi     *
501cffcc403Sandi     * $search and $returnonly are not for the renderer but are used
502cffcc403Sandi     * elsewhere - no need to implement them in other renderers
5033fd0b676Sandi     *
5043fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
505cffcc403Sandi     */
506cffcc403Sandi    function internallink($id, $name = NULL, $search=NULL,$returnonly=false) {
507ba11bd29Sandi        global $conf;
50837e34a5eSandi        global $ID;
5090339c872Sjan        // default name is based on $id as given
5100339c872Sjan        $default = $this->_simpleTitle($id);
511ad32e47eSAndreas Gohr
5120339c872Sjan        // now first resolve and clean up the $id
51337e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
5140339c872Sjan        $name = $this->_getLinkTitle($name, $default, $isImage, $id);
5150e1c636eSandi        if ( !$isImage ) {
5160e1c636eSandi            if ( $exists ) {
517ba11bd29Sandi                $class='wikilink1';
5180cecf9d5Sandi            } else {
519ba11bd29Sandi                $class='wikilink2';
5200cecf9d5Sandi            }
5210cecf9d5Sandi        } else {
522ba11bd29Sandi            $class='media';
5230cecf9d5Sandi        }
5240cecf9d5Sandi
525a1685bedSandi        //keep hash anchor
526ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
527943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
528a1685bedSandi
529ba11bd29Sandi        //prepare for formating
530ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
531ba11bd29Sandi        $link['style']  = '';
532ba11bd29Sandi        $link['pre']    = '';
533ba11bd29Sandi        $link['suf']    = '';
53440eb54bbSjan        // highlight link to current page
53540eb54bbSjan        if ($id == $ID) {
53692795d04Sandi            $link['pre']    = '<span class="curid">';
53792795d04Sandi            $link['suf']    = '</span>';
53840eb54bbSjan        }
5395e163278SAndreas Gohr        $link['more']   = '';
540ba11bd29Sandi        $link['class']  = $class;
541ba11bd29Sandi        $link['url']    = wl($id);
542ba11bd29Sandi        $link['name']   = $name;
543ba11bd29Sandi        $link['title']  = $id;
544723d78dbSandi        //add search string
545723d78dbSandi        if($search){
546723d78dbSandi            ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
547b6c6979fSAndreas Gohr            $link['url'] .= rawurlencode($search);
548723d78dbSandi        }
549723d78dbSandi
550a1685bedSandi        //keep hash
551a1685bedSandi        if($hash) $link['url'].='#'.$hash;
552a1685bedSandi
553ba11bd29Sandi        //output formatted
554cffcc403Sandi        if($returnonly){
555cffcc403Sandi            return $this->_formatLink($link);
556cffcc403Sandi        }else{
557a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
5580cecf9d5Sandi        }
559cffcc403Sandi    }
5600cecf9d5Sandi
561b625487dSandi    function externallink($url, $name = NULL) {
562b625487dSandi        global $conf;
5630cecf9d5Sandi
564433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
5656f0c5dbfSandi
5660cecf9d5Sandi        if ( !$isImage ) {
567b625487dSandi            $class='urlextern';
5680cecf9d5Sandi        } else {
569b625487dSandi            $class='media';
5700cecf9d5Sandi        }
5710cecf9d5Sandi
572b625487dSandi        //prepare for formating
573b625487dSandi        $link['target'] = $conf['target']['extern'];
574b625487dSandi        $link['style']  = '';
575b625487dSandi        $link['pre']    = '';
576b625487dSandi        $link['suf']    = '';
5775e163278SAndreas Gohr        $link['more']   = '';
578b625487dSandi        $link['class']  = $class;
579b625487dSandi        $link['url']    = $url;
580e1c10e4dSchris
581b625487dSandi        $link['name']   = $name;
582433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
583b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
5840cecf9d5Sandi
585b625487dSandi        //output formatted
586a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
5870cecf9d5Sandi    }
5880cecf9d5Sandi
5890cecf9d5Sandi    /**
5900cecf9d5Sandi    */
59197a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
592b625487dSandi        global $conf;
5930cecf9d5Sandi
59497a3e4e3Sandi        $link = array();
59597a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
59697a3e4e3Sandi        $link['pre']    = '';
59797a3e4e3Sandi        $link['suf']    = '';
5985e163278SAndreas Gohr        $link['more']   = '';
599433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
6000cecf9d5Sandi
60197a3e4e3Sandi        //get interwiki URL
6021f82fabeSAndreas Gohr        $url = $this-> _resolveInterWiki($wikiName,$wikiUri);
6030cecf9d5Sandi
60497a3e4e3Sandi        if ( !$isImage ) {
6059d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
6069d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
6071c2d1019SAndreas Gohr        } else {
6081c2d1019SAndreas Gohr            $link['class'] = 'media';
60997a3e4e3Sandi        }
6100cecf9d5Sandi
61197a3e4e3Sandi        //do we stay at the same server? Use local target
61297a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
61397a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
61497a3e4e3Sandi        }
6150cecf9d5Sandi
61697a3e4e3Sandi        $link['url'] = $url;
61797a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
61897a3e4e3Sandi
61997a3e4e3Sandi        //output formatted
620a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6210cecf9d5Sandi    }
6220cecf9d5Sandi
6230cecf9d5Sandi    /**
6240cecf9d5Sandi     */
6251d47afe1Sandi    function windowssharelink($url, $name = NULL) {
6261d47afe1Sandi        global $conf;
6271d47afe1Sandi        global $lang;
6281d47afe1Sandi        //simple setup
6291d47afe1Sandi        $link['target'] = $conf['target']['windows'];
6301d47afe1Sandi        $link['pre']    = '';
6311d47afe1Sandi        $link['suf']   = '';
6321d47afe1Sandi        $link['style']  = '';
6331d47afe1Sandi        //Display error on browsers other than IE
6341d47afe1Sandi        $link['more'] = 'onclick="if(document.all == null){alert(\''.
635b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).
6361d47afe1Sandi                        '\');}" onkeypress="if(document.all == null){alert(\''.
637b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"';
6380cecf9d5Sandi
639433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6400cecf9d5Sandi        if ( !$isImage ) {
6411d47afe1Sandi            $link['class'] = 'windows';
6420cecf9d5Sandi        } else {
6431d47afe1Sandi            $link['class'] = 'media';
6440cecf9d5Sandi        }
6450cecf9d5Sandi
6460cecf9d5Sandi
647433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
6481d47afe1Sandi        $url = str_replace('\\','/',$url);
6491d47afe1Sandi        $url = 'file:///'.$url;
6501d47afe1Sandi        $link['url'] = $url;
6510cecf9d5Sandi
6521d47afe1Sandi        //output formatted
653a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6540cecf9d5Sandi    }
6550cecf9d5Sandi
65671352defSandi    function emaillink($address, $name = NULL) {
65771352defSandi        global $conf;
65871352defSandi        //simple setup
65971352defSandi        $link = array();
66071352defSandi        $link['target'] = '';
66171352defSandi        $link['pre']    = '';
66271352defSandi        $link['suf']   = '';
66371352defSandi        $link['style']  = '';
66471352defSandi        $link['more']   = '';
6650cecf9d5Sandi
666c6e62e9fSchris        $name = $this->_getLinkTitle($name, '', $isImage);
6670cecf9d5Sandi        if ( !$isImage ) {
668776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
6690cecf9d5Sandi        } else {
670776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
6710cecf9d5Sandi        }
6720cecf9d5Sandi
67307738714SAndreas Gohr        $address = $this->_xmlEntities($address);
67400a7b5adSEsther Brunner        $address = obfuscate($address);
67500a7b5adSEsther Brunner        $title   = $address;
6768c128049SAndreas Gohr
67771352defSandi        if(empty($name)){
67800a7b5adSEsther Brunner            $name = $address;
67971352defSandi        }
6808c128049SAndreas Gohr#elseif($isImage{
6818c128049SAndreas Gohr#            $name = $this->_xmlEntities($name);
6828c128049SAndreas Gohr#        }
6830cecf9d5Sandi
684776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
685776b36ecSAndreas Gohr
686776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
68771352defSandi        $link['name']  = $name;
68871352defSandi        $link['title'] = $title;
6890cecf9d5Sandi
69071352defSandi        //output formatted
691a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6920cecf9d5Sandi    }
6930cecf9d5Sandi
6944826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
695dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
6963685f775Sandi        global $conf;
69737e34a5eSandi        global $ID;
69837e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
6990cecf9d5Sandi
7003685f775Sandi        $link = array();
7013685f775Sandi        $link['class']  = 'media';
7023685f775Sandi        $link['style']  = '';
7033685f775Sandi        $link['pre']    = '';
7043685f775Sandi        $link['suf']    = '';
7055e163278SAndreas Gohr        $link['more']   = '';
7063685f775Sandi        $link['target'] = $conf['target']['media'];
707d98d4540SBen Coburn        $noLink = false;
7083685f775Sandi
709433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
71055efc227SAndreas Gohr        list($ext,$mime) = mimetype($src);
7115667eb65SAndreas Gohr        if(substr($mime,0,5) == 'image'){
712dc673a5bSjoe.lapp             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
7132ca14335SEsther Brunner         }elseif($mime == 'application/x-shockwave-flash'){
7142ca14335SEsther Brunner             // don't link flash movies
71544881bd0Shenning.noren             $noLink = true;
71655efc227SAndreas Gohr         }else{
7172ca14335SEsther Brunner             // add file icons
7189d2ddea4SAndreas Gohr             $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
7199d2ddea4SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$class;
7206de3759aSAndreas Gohr             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
72155efc227SAndreas Gohr         }
722433bef32Sandi         $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
7233685f775Sandi
7243685f775Sandi         //output formatted
725dc673a5bSjoe.lapp         if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7262ca14335SEsther Brunner         else $this->doc .= $this->_formatLink($link);
7270cecf9d5Sandi    }
7280cecf9d5Sandi
7290cecf9d5Sandi    /**
7304826ab45Sandi     * @todo don't add link for flash
7310cecf9d5Sandi     */
7324826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
733dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
7343685f775Sandi        global $conf;
7350cecf9d5Sandi
7363685f775Sandi        $link = array();
7373685f775Sandi        $link['class']  = 'media';
7383685f775Sandi        $link['style']  = '';
7393685f775Sandi        $link['pre']    = '';
7403685f775Sandi        $link['suf']    = '';
7415e163278SAndreas Gohr        $link['more']   = '';
7423685f775Sandi        $link['target'] = $conf['target']['media'];
7433685f775Sandi
744433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
7456de3759aSAndreas Gohr        $link['url']    = ml($src,array('cache'=>$cache));
746433bef32Sandi        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
747d98d4540SBen Coburn        $noLink = false;
7483685f775Sandi
7492ca14335SEsther Brunner        list($ext,$mime) = mimetype($src);
7502ca14335SEsther Brunner        if(substr($mime,0,5) == 'image'){
7512ca14335SEsther Brunner             // link only jpeg images
75244881bd0Shenning.noren             // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7532ca14335SEsther Brunner        }elseif($mime == 'application/x-shockwave-flash'){
7542ca14335SEsther Brunner             // don't link flash movies
75544881bd0Shenning.noren             $noLink = true;
7562ca14335SEsther Brunner        }else{
7572ca14335SEsther Brunner             // add file icons
758d15166e5SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$ext;
7592ca14335SEsther Brunner         }
7602ca14335SEsther Brunner
7613685f775Sandi        //output formatted
762dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7632ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7640cecf9d5Sandi    }
7650cecf9d5Sandi
7664826ab45Sandi    /**
7673db95becSAndreas Gohr     * Renders an RSS feed
768b625487dSandi     *
769b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
770b625487dSandi     */
7713db95becSAndreas Gohr    function rss ($url,$params){
772b625487dSandi        global $lang;
7733db95becSAndreas Gohr        global $conf;
7743db95becSAndreas Gohr
7753db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
7763db95becSAndreas Gohr        $feed = new FeedParser();
7773db95becSAndreas Gohr        $feed->feed_url($url);
778b625487dSandi
779b625487dSandi        //disable warning while fetching
780bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
7813db95becSAndreas Gohr        $rc = $feed->init();
782bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
783b625487dSandi
7843db95becSAndreas Gohr        //decide on start and end
7853db95becSAndreas Gohr        if($params['reverse']){
7863db95becSAndreas Gohr            $mod = -1;
7873db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
7883db95becSAndreas Gohr            $end   = $start - ($params['max']);
789b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
7903db95becSAndreas Gohr        }else{
7913db95becSAndreas Gohr            $mod   = 1;
7923db95becSAndreas Gohr            $start = 0;
7933db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
7943db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
7953db95becSAndreas Gohr        }
7963db95becSAndreas Gohr
797a2d649c4Sandi        $this->doc .= '<ul class="rss">';
7983db95becSAndreas Gohr        if($rc){
7993db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
8001bde1582SAndreas Gohr                $item = $feed->get_item($x);
8013db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
8021bde1582SAndreas Gohr                $this->externallink($item->get_permalink(),
8031bde1582SAndreas Gohr                                    $item->get_title());
8043db95becSAndreas Gohr                if($params['author']){
8051bde1582SAndreas Gohr                    $author = $item->get_author(0);
8061bde1582SAndreas Gohr                    if($author){
8071bde1582SAndreas Gohr                        $name = $author->get_name();
8081bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
8091bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
8101bde1582SAndreas Gohr                    }
8113db95becSAndreas Gohr                }
8123db95becSAndreas Gohr                if($params['date']){
8131bde1582SAndreas Gohr                    $this->doc .= ' ('.$item->get_date($conf['dformat']).')';
8143db95becSAndreas Gohr                }
8151bde1582SAndreas Gohr                if($params['details']){
8163db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
8173db95becSAndreas Gohr                    if($htmlok){
8181bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
8193db95becSAndreas Gohr                    }else{
8201bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
8213db95becSAndreas Gohr                    }
8223db95becSAndreas Gohr                    $this->doc .= '</div>';
8233db95becSAndreas Gohr                }
8243db95becSAndreas Gohr
8253db95becSAndreas Gohr                $this->doc .= '</div></li>';
826b625487dSandi            }
827b625487dSandi        }else{
8283db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
829a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
830b625487dSandi            $this->externallink($url);
83145e147ccSAndreas Gohr            if($conf['allowdebug']){
83245e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
83345e147ccSAndreas Gohr            }
8343db95becSAndreas Gohr            $this->doc .= '</div></li>';
835b625487dSandi        }
836a2d649c4Sandi        $this->doc .= '</ul>';
837b625487dSandi    }
838b625487dSandi
8390cecf9d5Sandi    // $numrows not yet implemented
8400cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){
841a2d649c4Sandi        $this->doc .= '<table class="inline">'.DOKU_LF;
8420cecf9d5Sandi    }
8430cecf9d5Sandi
8440cecf9d5Sandi    function table_close(){
845cb42b03dSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
8460cecf9d5Sandi    }
8470cecf9d5Sandi
8480cecf9d5Sandi    function tablerow_open(){
849a2d649c4Sandi        $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
8500cecf9d5Sandi    }
8510cecf9d5Sandi
8520cecf9d5Sandi    function tablerow_close(){
853a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
8540cecf9d5Sandi    }
8550cecf9d5Sandi
8560cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){
857a2d649c4Sandi        $this->doc .= '<th';
8580cecf9d5Sandi        if ( !is_null($align) ) {
859a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8600cecf9d5Sandi        }
8610cecf9d5Sandi        if ( $colspan > 1 ) {
862a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8630cecf9d5Sandi        }
864a2d649c4Sandi        $this->doc .= '>';
8650cecf9d5Sandi    }
8660cecf9d5Sandi
8670cecf9d5Sandi    function tableheader_close(){
868a2d649c4Sandi        $this->doc .= '</th>';
8690cecf9d5Sandi    }
8700cecf9d5Sandi
8710cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){
872a2d649c4Sandi        $this->doc .= '<td';
8730cecf9d5Sandi        if ( !is_null($align) ) {
874a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8750cecf9d5Sandi        }
8760cecf9d5Sandi        if ( $colspan > 1 ) {
877a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8780cecf9d5Sandi        }
879a2d649c4Sandi        $this->doc .= '>';
8800cecf9d5Sandi    }
8810cecf9d5Sandi
8820cecf9d5Sandi    function tablecell_close(){
883a2d649c4Sandi        $this->doc .= '</td>';
8840cecf9d5Sandi    }
8850cecf9d5Sandi
8860cecf9d5Sandi    //----------------------------------------------------------
8870cecf9d5Sandi    // Utils
8880cecf9d5Sandi
889ba11bd29Sandi    /**
8903fd0b676Sandi     * Build a link
8913fd0b676Sandi     *
8923fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
893ba11bd29Sandi     *
894ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
895ba11bd29Sandi     */
896433bef32Sandi    function _formatLink($link){
897ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
898ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
899ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
900ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
901ba11bd29Sandi        }
902ba11bd29Sandi        //remove double encodings in titles
903ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
904ba11bd29Sandi
905453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
906453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
907453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
908453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
909453493f2SAndreas Gohr
910ba11bd29Sandi        $ret  = '';
911ba11bd29Sandi        $ret .= $link['pre'];
912ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
913bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
914bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
915bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
916bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
917bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
918ba11bd29Sandi        $ret .= '>';
919ba11bd29Sandi        $ret .= $link['name'];
920ba11bd29Sandi        $ret .= '</a>';
921ba11bd29Sandi        $ret .= $link['suf'];
922ba11bd29Sandi        return $ret;
923ba11bd29Sandi    }
924ba11bd29Sandi
925ba11bd29Sandi    /**
9263fd0b676Sandi     * Renders internal and external media
9273fd0b676Sandi     *
9283fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9293fd0b676Sandi     */
9303fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
9313fd0b676Sandi                      $height=NULL, $cache=NULL) {
9323fd0b676Sandi
9333fd0b676Sandi        $ret = '';
9343fd0b676Sandi
9353fd0b676Sandi        list($ext,$mime) = mimetype($src);
9363fd0b676Sandi        if(substr($mime,0,5) == 'image'){
9373fd0b676Sandi            //add image tag
9386de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
9393fd0b676Sandi            $ret .= ' class="media'.$align.'"';
9403fd0b676Sandi
9413fd0b676Sandi            if (!is_null($title)) {
9423fd0b676Sandi                $ret .= ' title="'.$this->_xmlEntities($title).'"';
9433fd0b676Sandi                $ret .= ' alt="'.$this->_xmlEntities($title).'"';
94455efc227SAndreas Gohr            }elseif($ext == 'jpg' || $ext == 'jpeg'){
94555efc227SAndreas Gohr                //try to use the caption from IPTC/EXIF
94655efc227SAndreas Gohr                require_once(DOKU_INC.'inc/JpegMeta.php');
94755efc227SAndreas Gohr                $jpeg =& new JpegMeta(mediaFN($src));
94855efc227SAndreas Gohr                if($jpeg !== false) $cap = $jpeg->getTitle();
94955efc227SAndreas Gohr                if($cap){
95055efc227SAndreas Gohr                    $ret .= ' title="'.$this->_xmlEntities($cap).'"';
95155efc227SAndreas Gohr                    $ret .= ' alt="'.$this->_xmlEntities($cap).'"';
952fcf1ccdcSAndreas Gohr                }else{
953fcf1ccdcSAndreas Gohr                    $ret .= ' alt=""';
95455efc227SAndreas Gohr                }
9553fd0b676Sandi            }else{
9563fd0b676Sandi                $ret .= ' alt=""';
9573fd0b676Sandi            }
9583fd0b676Sandi
9593fd0b676Sandi            if ( !is_null($width) )
9603fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
9613fd0b676Sandi
9623fd0b676Sandi            if ( !is_null($height) )
9633fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
9643fd0b676Sandi
9653fd0b676Sandi            $ret .= ' />';
9663fd0b676Sandi
9673fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
9683fd0b676Sandi            $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
9693fd0b676Sandi                    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
9703fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9713fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9723fd0b676Sandi            $ret .= '>'.DOKU_LF;
9736de3759aSAndreas Gohr            $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
9743fd0b676Sandi            $ret .= '<param name="quality" value="high" />'.DOKU_LF;
9756de3759aSAndreas Gohr            $ret .= '<embed src="'.ml($src).'"'.
9763fd0b676Sandi                    ' quality="high"';
9773fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9783fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9793fd0b676Sandi            $ret .= ' type="application/x-shockwave-flash"'.
9803fd0b676Sandi                    ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF;
9813fd0b676Sandi            $ret .= '</object>'.DOKU_LF;
9823fd0b676Sandi
9830f428d7dSAndreas Gohr        }elseif($title){
9843fd0b676Sandi            // well at least we have a title to display
9853fd0b676Sandi            $ret .= $this->_xmlEntities($title);
9863fd0b676Sandi        }else{
9875291ca3aSAndreas Gohr            // just show the sourcename
9880f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
9893fd0b676Sandi        }
9903fd0b676Sandi
9913fd0b676Sandi        return $ret;
9923fd0b676Sandi    }
9933fd0b676Sandi
994433bef32Sandi    function _xmlEntities($string) {
995de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
9960cecf9d5Sandi    }
9970cecf9d5Sandi
9988a831f2bSAndreas Gohr    /**
9998a831f2bSAndreas Gohr     * Creates a linkid from a headline
1000c5a8fd96SAndreas Gohr     *
1001c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1002c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
1003c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
10048a831f2bSAndreas Gohr     */
1005c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
1006501af51eSAndreas Gohr        $title = str_replace(':','',cleanID($title));
1007a9e0fd1bSAndreas Gohr        $title = ltrim($title,'0123456789._-');
10088a831f2bSAndreas Gohr        if(empty($title)) $title='section';
1009c5a8fd96SAndreas Gohr
1010c5a8fd96SAndreas Gohr        if($create){
1011c5a8fd96SAndreas Gohr            // make sure tiles are unique
1012c5a8fd96SAndreas Gohr            $num = '';
1013c5a8fd96SAndreas Gohr            while(in_array($title.$num,$this->headers)){
10140affd488SAndreas Gohr                ($num) ? $num++ : $num = 1;
1015c5a8fd96SAndreas Gohr            }
1016c5a8fd96SAndreas Gohr            $title = $title.$num;
1017c5a8fd96SAndreas Gohr            $this->headers[] = $title;
1018c5a8fd96SAndreas Gohr        }
1019c5a8fd96SAndreas Gohr
10208a831f2bSAndreas Gohr        return $title;
10210cecf9d5Sandi    }
10220cecf9d5Sandi
1023af587fa8Sandi    /**
10243fd0b676Sandi     * Construct a title and handle images in titles
10253fd0b676Sandi     *
10260b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
10273fd0b676Sandi     */
1028433bef32Sandi    function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
1029bb0a59d4Sjan        global $conf;
1030bb0a59d4Sjan
103144881bd0Shenning.noren        $isImage = false;
10320cecf9d5Sandi        if ( is_null($title) ) {
1033bb0a59d4Sjan            if ($conf['useheading'] && $id) {
1034fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1035bb0a59d4Sjan                if ($heading) {
1036433bef32Sandi                    return $this->_xmlEntities($heading);
1037bb0a59d4Sjan                }
1038bb0a59d4Sjan            }
1039433bef32Sandi            return $this->_xmlEntities($default);
10400cecf9d5Sandi        } else if ( is_string($title) ) {
1041433bef32Sandi            return $this->_xmlEntities($title);
10420cecf9d5Sandi        } else if ( is_array($title) ) {
104344881bd0Shenning.noren            $isImage = true;
1044433bef32Sandi            return $this->_imageTitle($title);
10450cecf9d5Sandi        }
10460cecf9d5Sandi    }
10470cecf9d5Sandi
10480cecf9d5Sandi    /**
10493fd0b676Sandi     * Returns an HTML code for images used in link titles
10503fd0b676Sandi     *
10513fd0b676Sandi     * @todo Resolve namespace on internal images
10523fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10530cecf9d5Sandi     */
1054433bef32Sandi    function _imageTitle($img) {
1055433bef32Sandi        return $this->_media($img['src'],
10564826ab45Sandi                              $img['title'],
10574826ab45Sandi                              $img['align'],
10584826ab45Sandi                              $img['width'],
10594826ab45Sandi                              $img['height'],
10604826ab45Sandi                              $img['cache']);
10610cecf9d5Sandi    }
10620cecf9d5Sandi}
10630cecf9d5Sandi
10644826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1065