xref: /dokuwiki/inc/parser/xhtml.php (revision 943dedc690b7b8e32e00f7ae3d64e51cfe9a44b2)
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
3500cecf9d5Sandi    /**
3513fd0b676Sandi     * Insert HTML if allowed
3523fd0b676Sandi     *
3533fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3540cecf9d5Sandi     */
3550cecf9d5Sandi    function html($text) {
3564de671bcSandi        global $conf;
3574de671bcSandi        if($conf['htmlok']){
358a2d649c4Sandi          $this->doc .= $text;
3594de671bcSandi        }else{
3600cecf9d5Sandi          $this->file($text);
3610cecf9d5Sandi        }
3624de671bcSandi    }
3630cecf9d5Sandi
3640cecf9d5Sandi    function preformatted($text) {
365a2d649c4Sandi        $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
3660cecf9d5Sandi    }
3670cecf9d5Sandi
3680cecf9d5Sandi    function file($text) {
369a2d649c4Sandi        $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
3700cecf9d5Sandi    }
3710cecf9d5Sandi
3720cecf9d5Sandi    function quote_open() {
37396331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
3740cecf9d5Sandi    }
3750cecf9d5Sandi
3760cecf9d5Sandi    function quote_close() {
37796331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
3780cecf9d5Sandi    }
3790cecf9d5Sandi
3800cecf9d5Sandi    /**
3813fd0b676Sandi     * Callback for code text
3823fd0b676Sandi     *
3833fd0b676Sandi     * Uses GeSHi to highlight language syntax
3843fd0b676Sandi     *
3853fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3860cecf9d5Sandi     */
3870cecf9d5Sandi    function code($text, $language = NULL) {
3884de671bcSandi        global $conf;
3890cecf9d5Sandi
3900cecf9d5Sandi        if ( is_null($language) ) {
3910cecf9d5Sandi            $this->preformatted($text);
3920cecf9d5Sandi        } else {
393852896daSAndreas Gohr            //strip leading and trailing blank line
394313da78aSandi            $text = preg_replace('/^\s*?\n/','',$text);
395852896daSAndreas Gohr            $text = preg_replace('/\s*?\n$/','',$text);
3968f7d700cSchris            $this->doc .= p_xhtml_cached_geshi($text, $language);
3970cecf9d5Sandi        }
3980cecf9d5Sandi    }
3990cecf9d5Sandi
4000cecf9d5Sandi    function acronym($acronym) {
4010cecf9d5Sandi
4020cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
4030cecf9d5Sandi
404433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
4050cecf9d5Sandi
406a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
407433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
4080cecf9d5Sandi
4090cecf9d5Sandi        } else {
410a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4110cecf9d5Sandi        }
4120cecf9d5Sandi    }
4130cecf9d5Sandi
4140cecf9d5Sandi    function smiley($smiley) {
4150cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
416433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
417f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4184beabca9SAnika Henke                '" class="middle" alt="'.
419433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4200cecf9d5Sandi        } else {
421a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4220cecf9d5Sandi        }
4230cecf9d5Sandi    }
4240cecf9d5Sandi
425f62ea8a1Sandi    /*
4264de671bcSandi    * not used
4270cecf9d5Sandi    function wordblock($word) {
4280cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
429a2d649c4Sandi            $this->doc .= '** BLEEP **';
4300cecf9d5Sandi        } else {
431a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4320cecf9d5Sandi        }
4330cecf9d5Sandi    }
4344de671bcSandi    */
4350cecf9d5Sandi
4360cecf9d5Sandi    function entity($entity) {
4370cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
438a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4390cecf9d5Sandi        } else {
440a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4410cecf9d5Sandi        }
4420cecf9d5Sandi    }
4430cecf9d5Sandi
4440cecf9d5Sandi    function multiplyentity($x, $y) {
445a2d649c4Sandi        $this->doc .= "$x&times;$y";
4460cecf9d5Sandi    }
4470cecf9d5Sandi
4480cecf9d5Sandi    function singlequoteopening() {
44971b40da2SAnika Henke        global $lang;
45071b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
4510cecf9d5Sandi    }
4520cecf9d5Sandi
4530cecf9d5Sandi    function singlequoteclosing() {
45471b40da2SAnika Henke        global $lang;
45571b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
4560cecf9d5Sandi    }
4570cecf9d5Sandi
45857d757d1SAndreas Gohr    function apostrophe() {
45957d757d1SAndreas Gohr        global $lang;
460a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
46157d757d1SAndreas Gohr    }
46257d757d1SAndreas Gohr
4630cecf9d5Sandi    function doublequoteopening() {
46471b40da2SAnika Henke        global $lang;
46571b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
4660cecf9d5Sandi    }
4670cecf9d5Sandi
4680cecf9d5Sandi    function doublequoteclosing() {
46971b40da2SAnika Henke        global $lang;
47071b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
4710cecf9d5Sandi    }
4720cecf9d5Sandi
4730cecf9d5Sandi    /**
4740cecf9d5Sandi    */
4750cecf9d5Sandi    function camelcaselink($link) {
47611d0aa47Sandi      $this->internallink($link,$link);
4770cecf9d5Sandi    }
4780cecf9d5Sandi
4790b7c14c2Sandi
4800b7c14c2Sandi    function locallink($hash, $name = NULL){
4810b7c14c2Sandi        global $ID;
4820b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
4830b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
4840b7c14c2Sandi        $title = $ID.' &crarr;';
4850b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
4860b7c14c2Sandi        $this->doc .= $name;
4870b7c14c2Sandi        $this->doc .= '</a>';
4880b7c14c2Sandi    }
4890b7c14c2Sandi
490cffcc403Sandi    /**
4913fd0b676Sandi     * Render an internal Wiki Link
4923fd0b676Sandi     *
493cffcc403Sandi     * $search and $returnonly are not for the renderer but are used
494cffcc403Sandi     * elsewhere - no need to implement them in other renderers
4953fd0b676Sandi     *
4963fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
497cffcc403Sandi     */
498cffcc403Sandi    function internallink($id, $name = NULL, $search=NULL,$returnonly=false) {
499ba11bd29Sandi        global $conf;
50037e34a5eSandi        global $ID;
5010339c872Sjan        // default name is based on $id as given
5020339c872Sjan        $default = $this->_simpleTitle($id);
503ad32e47eSAndreas Gohr
5040339c872Sjan        // now first resolve and clean up the $id
50537e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
5060339c872Sjan        $name = $this->_getLinkTitle($name, $default, $isImage, $id);
5070e1c636eSandi        if ( !$isImage ) {
5080e1c636eSandi            if ( $exists ) {
509ba11bd29Sandi                $class='wikilink1';
5100cecf9d5Sandi            } else {
511ba11bd29Sandi                $class='wikilink2';
5120cecf9d5Sandi            }
5130cecf9d5Sandi        } else {
514ba11bd29Sandi            $class='media';
5150cecf9d5Sandi        }
5160cecf9d5Sandi
517a1685bedSandi        //keep hash anchor
518ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
519*943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
520a1685bedSandi
521ba11bd29Sandi        //prepare for formating
522ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
523ba11bd29Sandi        $link['style']  = '';
524ba11bd29Sandi        $link['pre']    = '';
525ba11bd29Sandi        $link['suf']    = '';
52640eb54bbSjan        // highlight link to current page
52740eb54bbSjan        if ($id == $ID) {
52892795d04Sandi            $link['pre']    = '<span class="curid">';
52992795d04Sandi            $link['suf']    = '</span>';
53040eb54bbSjan        }
5315e163278SAndreas Gohr        $link['more']   = '';
532ba11bd29Sandi        $link['class']  = $class;
533ba11bd29Sandi        $link['url']    = wl($id);
534ba11bd29Sandi        $link['name']   = $name;
535ba11bd29Sandi        $link['title']  = $id;
536723d78dbSandi        //add search string
537723d78dbSandi        if($search){
538723d78dbSandi            ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
539b6c6979fSAndreas Gohr            $link['url'] .= rawurlencode($search);
540723d78dbSandi        }
541723d78dbSandi
542a1685bedSandi        //keep hash
543a1685bedSandi        if($hash) $link['url'].='#'.$hash;
544a1685bedSandi
545ba11bd29Sandi        //output formatted
546cffcc403Sandi        if($returnonly){
547cffcc403Sandi            return $this->_formatLink($link);
548cffcc403Sandi        }else{
549a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
5500cecf9d5Sandi        }
551cffcc403Sandi    }
5520cecf9d5Sandi
553b625487dSandi    function externallink($url, $name = NULL) {
554b625487dSandi        global $conf;
5550cecf9d5Sandi
556433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
5576f0c5dbfSandi
5580cecf9d5Sandi        if ( !$isImage ) {
559b625487dSandi            $class='urlextern';
5600cecf9d5Sandi        } else {
561b625487dSandi            $class='media';
5620cecf9d5Sandi        }
5630cecf9d5Sandi
564b625487dSandi        //prepare for formating
565b625487dSandi        $link['target'] = $conf['target']['extern'];
566b625487dSandi        $link['style']  = '';
567b625487dSandi        $link['pre']    = '';
568b625487dSandi        $link['suf']    = '';
5695e163278SAndreas Gohr        $link['more']   = '';
570b625487dSandi        $link['class']  = $class;
571b625487dSandi        $link['url']    = $url;
572e1c10e4dSchris
573b625487dSandi        $link['name']   = $name;
574433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
575b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
5760cecf9d5Sandi
577b625487dSandi        //output formatted
578a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
5790cecf9d5Sandi    }
5800cecf9d5Sandi
5810cecf9d5Sandi    /**
5820cecf9d5Sandi    */
58397a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
584b625487dSandi        global $conf;
5850cecf9d5Sandi
58697a3e4e3Sandi        $link = array();
58797a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
58897a3e4e3Sandi        $link['pre']    = '';
58997a3e4e3Sandi        $link['suf']    = '';
5905e163278SAndreas Gohr        $link['more']   = '';
591433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
5920cecf9d5Sandi
59397a3e4e3Sandi        //get interwiki URL
5941f82fabeSAndreas Gohr        $url = $this-> _resolveInterWiki($wikiName,$wikiUri);
5950cecf9d5Sandi
59697a3e4e3Sandi        if ( !$isImage ) {
5979d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
5989d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
5991c2d1019SAndreas Gohr        } else {
6001c2d1019SAndreas Gohr            $link['class'] = 'media';
60197a3e4e3Sandi        }
6020cecf9d5Sandi
60397a3e4e3Sandi        //do we stay at the same server? Use local target
60497a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
60597a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
60697a3e4e3Sandi        }
6070cecf9d5Sandi
60897a3e4e3Sandi        $link['url'] = $url;
60997a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
61097a3e4e3Sandi
61197a3e4e3Sandi        //output formatted
612a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6130cecf9d5Sandi    }
6140cecf9d5Sandi
6150cecf9d5Sandi    /**
6160cecf9d5Sandi     */
6171d47afe1Sandi    function windowssharelink($url, $name = NULL) {
6181d47afe1Sandi        global $conf;
6191d47afe1Sandi        global $lang;
6201d47afe1Sandi        //simple setup
6211d47afe1Sandi        $link['target'] = $conf['target']['windows'];
6221d47afe1Sandi        $link['pre']    = '';
6231d47afe1Sandi        $link['suf']   = '';
6241d47afe1Sandi        $link['style']  = '';
6251d47afe1Sandi        //Display error on browsers other than IE
6261d47afe1Sandi        $link['more'] = 'onclick="if(document.all == null){alert(\''.
627b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).
6281d47afe1Sandi                        '\');}" onkeypress="if(document.all == null){alert(\''.
629b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"';
6300cecf9d5Sandi
631433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6320cecf9d5Sandi        if ( !$isImage ) {
6331d47afe1Sandi            $link['class'] = 'windows';
6340cecf9d5Sandi        } else {
6351d47afe1Sandi            $link['class'] = 'media';
6360cecf9d5Sandi        }
6370cecf9d5Sandi
6380cecf9d5Sandi
639433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
6401d47afe1Sandi        $url = str_replace('\\','/',$url);
6411d47afe1Sandi        $url = 'file:///'.$url;
6421d47afe1Sandi        $link['url'] = $url;
6430cecf9d5Sandi
6441d47afe1Sandi        //output formatted
645a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6460cecf9d5Sandi    }
6470cecf9d5Sandi
64871352defSandi    function emaillink($address, $name = NULL) {
64971352defSandi        global $conf;
65071352defSandi        //simple setup
65171352defSandi        $link = array();
65271352defSandi        $link['target'] = '';
65371352defSandi        $link['pre']    = '';
65471352defSandi        $link['suf']   = '';
65571352defSandi        $link['style']  = '';
65671352defSandi        $link['more']   = '';
6570cecf9d5Sandi
658c6e62e9fSchris        $name = $this->_getLinkTitle($name, '', $isImage);
6590cecf9d5Sandi        if ( !$isImage ) {
660776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
6610cecf9d5Sandi        } else {
662776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
6630cecf9d5Sandi        }
6640cecf9d5Sandi
66507738714SAndreas Gohr        $address = $this->_xmlEntities($address);
66600a7b5adSEsther Brunner        $address = obfuscate($address);
66700a7b5adSEsther Brunner        $title   = $address;
6688c128049SAndreas Gohr
66971352defSandi        if(empty($name)){
67000a7b5adSEsther Brunner            $name = $address;
67171352defSandi        }
6728c128049SAndreas Gohr#elseif($isImage{
6738c128049SAndreas Gohr#            $name = $this->_xmlEntities($name);
6748c128049SAndreas Gohr#        }
6750cecf9d5Sandi
676776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
677776b36ecSAndreas Gohr
678776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
67971352defSandi        $link['name']  = $name;
68071352defSandi        $link['title'] = $title;
6810cecf9d5Sandi
68271352defSandi        //output formatted
683a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6840cecf9d5Sandi    }
6850cecf9d5Sandi
6864826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
687dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
6883685f775Sandi        global $conf;
68937e34a5eSandi        global $ID;
69037e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
6910cecf9d5Sandi
6923685f775Sandi        $link = array();
6933685f775Sandi        $link['class']  = 'media';
6943685f775Sandi        $link['style']  = '';
6953685f775Sandi        $link['pre']    = '';
6963685f775Sandi        $link['suf']    = '';
6975e163278SAndreas Gohr        $link['more']   = '';
6983685f775Sandi        $link['target'] = $conf['target']['media'];
699d98d4540SBen Coburn        $noLink = false;
7003685f775Sandi
701433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
70255efc227SAndreas Gohr        list($ext,$mime) = mimetype($src);
7035667eb65SAndreas Gohr        if(substr($mime,0,5) == 'image'){
704dc673a5bSjoe.lapp             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
7052ca14335SEsther Brunner         }elseif($mime == 'application/x-shockwave-flash'){
7062ca14335SEsther Brunner             // don't link flash movies
70744881bd0Shenning.noren             $noLink = true;
70855efc227SAndreas Gohr         }else{
7092ca14335SEsther Brunner             // add file icons
7109d2ddea4SAndreas Gohr             $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
7119d2ddea4SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$class;
7126de3759aSAndreas Gohr             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
71355efc227SAndreas Gohr         }
714433bef32Sandi         $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
7153685f775Sandi
7163685f775Sandi         //output formatted
717dc673a5bSjoe.lapp         if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7182ca14335SEsther Brunner         else $this->doc .= $this->_formatLink($link);
7190cecf9d5Sandi    }
7200cecf9d5Sandi
7210cecf9d5Sandi    /**
7224826ab45Sandi     * @todo don't add link for flash
7230cecf9d5Sandi     */
7244826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
725dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
7263685f775Sandi        global $conf;
7270cecf9d5Sandi
7283685f775Sandi        $link = array();
7293685f775Sandi        $link['class']  = 'media';
7303685f775Sandi        $link['style']  = '';
7313685f775Sandi        $link['pre']    = '';
7323685f775Sandi        $link['suf']    = '';
7335e163278SAndreas Gohr        $link['more']   = '';
7343685f775Sandi        $link['target'] = $conf['target']['media'];
7353685f775Sandi
736433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
7376de3759aSAndreas Gohr        $link['url']    = ml($src,array('cache'=>$cache));
738433bef32Sandi        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
739d98d4540SBen Coburn        $noLink = false;
7403685f775Sandi
7412ca14335SEsther Brunner        list($ext,$mime) = mimetype($src);
7422ca14335SEsther Brunner        if(substr($mime,0,5) == 'image'){
7432ca14335SEsther Brunner             // link only jpeg images
74444881bd0Shenning.noren             // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7452ca14335SEsther Brunner        }elseif($mime == 'application/x-shockwave-flash'){
7462ca14335SEsther Brunner             // don't link flash movies
74744881bd0Shenning.noren             $noLink = true;
7482ca14335SEsther Brunner        }else{
7492ca14335SEsther Brunner             // add file icons
750d15166e5SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$ext;
7512ca14335SEsther Brunner         }
7522ca14335SEsther Brunner
7533685f775Sandi        //output formatted
754dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7552ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7560cecf9d5Sandi    }
7570cecf9d5Sandi
7584826ab45Sandi    /**
7593db95becSAndreas Gohr     * Renders an RSS feed
760b625487dSandi     *
761b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
762b625487dSandi     */
7633db95becSAndreas Gohr    function rss ($url,$params){
764b625487dSandi        global $lang;
7653db95becSAndreas Gohr        global $conf;
7663db95becSAndreas Gohr
7673db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
7683db95becSAndreas Gohr        $feed = new FeedParser();
7693db95becSAndreas Gohr        $feed->feed_url($url);
770b625487dSandi
771b625487dSandi        //disable warning while fetching
772bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
7733db95becSAndreas Gohr        $rc = $feed->init();
774bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
775b625487dSandi
7763db95becSAndreas Gohr        //decide on start and end
7773db95becSAndreas Gohr        if($params['reverse']){
7783db95becSAndreas Gohr            $mod = -1;
7793db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
7803db95becSAndreas Gohr            $end   = $start - ($params['max']);
781b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
7823db95becSAndreas Gohr        }else{
7833db95becSAndreas Gohr            $mod   = 1;
7843db95becSAndreas Gohr            $start = 0;
7853db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
7863db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
7873db95becSAndreas Gohr        }
7883db95becSAndreas Gohr
789a2d649c4Sandi        $this->doc .= '<ul class="rss">';
7903db95becSAndreas Gohr        if($rc){
7913db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
7921bde1582SAndreas Gohr                $item = $feed->get_item($x);
7933db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
7941bde1582SAndreas Gohr                $this->externallink($item->get_permalink(),
7951bde1582SAndreas Gohr                                    $item->get_title());
7963db95becSAndreas Gohr                if($params['author']){
7971bde1582SAndreas Gohr                    $author = $item->get_author(0);
7981bde1582SAndreas Gohr                    if($author){
7991bde1582SAndreas Gohr                        $name = $author->get_name();
8001bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
8011bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
8021bde1582SAndreas Gohr                    }
8033db95becSAndreas Gohr                }
8043db95becSAndreas Gohr                if($params['date']){
8051bde1582SAndreas Gohr                    $this->doc .= ' ('.$item->get_date($conf['dformat']).')';
8063db95becSAndreas Gohr                }
8071bde1582SAndreas Gohr                if($params['details']){
8083db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
8093db95becSAndreas Gohr                    if($htmlok){
8101bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
8113db95becSAndreas Gohr                    }else{
8121bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
8133db95becSAndreas Gohr                    }
8143db95becSAndreas Gohr                    $this->doc .= '</div>';
8153db95becSAndreas Gohr                }
8163db95becSAndreas Gohr
8173db95becSAndreas Gohr                $this->doc .= '</div></li>';
818b625487dSandi            }
819b625487dSandi        }else{
8203db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
821a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
822b625487dSandi            $this->externallink($url);
82345e147ccSAndreas Gohr            if($conf['allowdebug']){
82445e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
82545e147ccSAndreas Gohr            }
8263db95becSAndreas Gohr            $this->doc .= '</div></li>';
827b625487dSandi        }
828a2d649c4Sandi        $this->doc .= '</ul>';
829b625487dSandi    }
830b625487dSandi
8310cecf9d5Sandi    // $numrows not yet implemented
8320cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){
833a2d649c4Sandi        $this->doc .= '<table class="inline">'.DOKU_LF;
8340cecf9d5Sandi    }
8350cecf9d5Sandi
8360cecf9d5Sandi    function table_close(){
837cb42b03dSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
8380cecf9d5Sandi    }
8390cecf9d5Sandi
8400cecf9d5Sandi    function tablerow_open(){
841a2d649c4Sandi        $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
8420cecf9d5Sandi    }
8430cecf9d5Sandi
8440cecf9d5Sandi    function tablerow_close(){
845a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
8460cecf9d5Sandi    }
8470cecf9d5Sandi
8480cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){
849a2d649c4Sandi        $this->doc .= '<th';
8500cecf9d5Sandi        if ( !is_null($align) ) {
851a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8520cecf9d5Sandi        }
8530cecf9d5Sandi        if ( $colspan > 1 ) {
854a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8550cecf9d5Sandi        }
856a2d649c4Sandi        $this->doc .= '>';
8570cecf9d5Sandi    }
8580cecf9d5Sandi
8590cecf9d5Sandi    function tableheader_close(){
860a2d649c4Sandi        $this->doc .= '</th>';
8610cecf9d5Sandi    }
8620cecf9d5Sandi
8630cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){
864a2d649c4Sandi        $this->doc .= '<td';
8650cecf9d5Sandi        if ( !is_null($align) ) {
866a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8670cecf9d5Sandi        }
8680cecf9d5Sandi        if ( $colspan > 1 ) {
869a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8700cecf9d5Sandi        }
871a2d649c4Sandi        $this->doc .= '>';
8720cecf9d5Sandi    }
8730cecf9d5Sandi
8740cecf9d5Sandi    function tablecell_close(){
875a2d649c4Sandi        $this->doc .= '</td>';
8760cecf9d5Sandi    }
8770cecf9d5Sandi
8780cecf9d5Sandi    //----------------------------------------------------------
8790cecf9d5Sandi    // Utils
8800cecf9d5Sandi
881ba11bd29Sandi    /**
8823fd0b676Sandi     * Build a link
8833fd0b676Sandi     *
8843fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
885ba11bd29Sandi     *
886ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
887ba11bd29Sandi     */
888433bef32Sandi    function _formatLink($link){
889ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
890ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
891ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
892ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
893ba11bd29Sandi        }
894ba11bd29Sandi        //remove double encodings in titles
895ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
896ba11bd29Sandi
897453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
898453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
899453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
900453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
901453493f2SAndreas Gohr
902ba11bd29Sandi        $ret  = '';
903ba11bd29Sandi        $ret .= $link['pre'];
904ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
905bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
906bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
907bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
908bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
909bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
910ba11bd29Sandi        $ret .= '>';
911ba11bd29Sandi        $ret .= $link['name'];
912ba11bd29Sandi        $ret .= '</a>';
913ba11bd29Sandi        $ret .= $link['suf'];
914ba11bd29Sandi        return $ret;
915ba11bd29Sandi    }
916ba11bd29Sandi
917ba11bd29Sandi    /**
9183fd0b676Sandi     * Renders internal and external media
9193fd0b676Sandi     *
9203fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9213fd0b676Sandi     */
9223fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
9233fd0b676Sandi                      $height=NULL, $cache=NULL) {
9243fd0b676Sandi
9253fd0b676Sandi        $ret = '';
9263fd0b676Sandi
9273fd0b676Sandi        list($ext,$mime) = mimetype($src);
9283fd0b676Sandi        if(substr($mime,0,5) == 'image'){
9293fd0b676Sandi            //add image tag
9306de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
9313fd0b676Sandi            $ret .= ' class="media'.$align.'"';
9323fd0b676Sandi
9333fd0b676Sandi            if (!is_null($title)) {
9343fd0b676Sandi                $ret .= ' title="'.$this->_xmlEntities($title).'"';
9353fd0b676Sandi                $ret .= ' alt="'.$this->_xmlEntities($title).'"';
93655efc227SAndreas Gohr            }elseif($ext == 'jpg' || $ext == 'jpeg'){
93755efc227SAndreas Gohr                //try to use the caption from IPTC/EXIF
93855efc227SAndreas Gohr                require_once(DOKU_INC.'inc/JpegMeta.php');
93955efc227SAndreas Gohr                $jpeg =& new JpegMeta(mediaFN($src));
94055efc227SAndreas Gohr                if($jpeg !== false) $cap = $jpeg->getTitle();
94155efc227SAndreas Gohr                if($cap){
94255efc227SAndreas Gohr                    $ret .= ' title="'.$this->_xmlEntities($cap).'"';
94355efc227SAndreas Gohr                    $ret .= ' alt="'.$this->_xmlEntities($cap).'"';
944fcf1ccdcSAndreas Gohr                }else{
945fcf1ccdcSAndreas Gohr                    $ret .= ' alt=""';
94655efc227SAndreas Gohr                }
9473fd0b676Sandi            }else{
9483fd0b676Sandi                $ret .= ' alt=""';
9493fd0b676Sandi            }
9503fd0b676Sandi
9513fd0b676Sandi            if ( !is_null($width) )
9523fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
9533fd0b676Sandi
9543fd0b676Sandi            if ( !is_null($height) )
9553fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
9563fd0b676Sandi
9573fd0b676Sandi            $ret .= ' />';
9583fd0b676Sandi
9593fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
9603fd0b676Sandi            $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
9613fd0b676Sandi                    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
9623fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9633fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9643fd0b676Sandi            $ret .= '>'.DOKU_LF;
9656de3759aSAndreas Gohr            $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
9663fd0b676Sandi            $ret .= '<param name="quality" value="high" />'.DOKU_LF;
9676de3759aSAndreas Gohr            $ret .= '<embed src="'.ml($src).'"'.
9683fd0b676Sandi                    ' quality="high"';
9693fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9703fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9713fd0b676Sandi            $ret .= ' type="application/x-shockwave-flash"'.
9723fd0b676Sandi                    ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF;
9733fd0b676Sandi            $ret .= '</object>'.DOKU_LF;
9743fd0b676Sandi
9750f428d7dSAndreas Gohr        }elseif($title){
9763fd0b676Sandi            // well at least we have a title to display
9773fd0b676Sandi            $ret .= $this->_xmlEntities($title);
9783fd0b676Sandi        }else{
9795291ca3aSAndreas Gohr            // just show the sourcename
9800f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
9813fd0b676Sandi        }
9823fd0b676Sandi
9833fd0b676Sandi        return $ret;
9843fd0b676Sandi    }
9853fd0b676Sandi
986433bef32Sandi    function _xmlEntities($string) {
987de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
9880cecf9d5Sandi    }
9890cecf9d5Sandi
9908a831f2bSAndreas Gohr    /**
9918a831f2bSAndreas Gohr     * Creates a linkid from a headline
992c5a8fd96SAndreas Gohr     *
993c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
994c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
995c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
9968a831f2bSAndreas Gohr     */
997c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
998501af51eSAndreas Gohr        $title = str_replace(':','',cleanID($title));
999a9e0fd1bSAndreas Gohr        $title = ltrim($title,'0123456789._-');
10008a831f2bSAndreas Gohr        if(empty($title)) $title='section';
1001c5a8fd96SAndreas Gohr
1002c5a8fd96SAndreas Gohr        if($create){
1003c5a8fd96SAndreas Gohr            // make sure tiles are unique
1004c5a8fd96SAndreas Gohr            $num = '';
1005c5a8fd96SAndreas Gohr            while(in_array($title.$num,$this->headers)){
10060affd488SAndreas Gohr                ($num) ? $num++ : $num = 1;
1007c5a8fd96SAndreas Gohr            }
1008c5a8fd96SAndreas Gohr            $title = $title.$num;
1009c5a8fd96SAndreas Gohr            $this->headers[] = $title;
1010c5a8fd96SAndreas Gohr        }
1011c5a8fd96SAndreas Gohr
10128a831f2bSAndreas Gohr        return $title;
10130cecf9d5Sandi    }
10140cecf9d5Sandi
1015af587fa8Sandi    /**
10163fd0b676Sandi     * Construct a title and handle images in titles
10173fd0b676Sandi     *
10180b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
10193fd0b676Sandi     */
1020433bef32Sandi    function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
1021bb0a59d4Sjan        global $conf;
1022bb0a59d4Sjan
102344881bd0Shenning.noren        $isImage = false;
10240cecf9d5Sandi        if ( is_null($title) ) {
1025bb0a59d4Sjan            if ($conf['useheading'] && $id) {
1026fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1027bb0a59d4Sjan                if ($heading) {
1028433bef32Sandi                    return $this->_xmlEntities($heading);
1029bb0a59d4Sjan                }
1030bb0a59d4Sjan            }
1031433bef32Sandi            return $this->_xmlEntities($default);
10320cecf9d5Sandi        } else if ( is_string($title) ) {
1033433bef32Sandi            return $this->_xmlEntities($title);
10340cecf9d5Sandi        } else if ( is_array($title) ) {
103544881bd0Shenning.noren            $isImage = true;
1036433bef32Sandi            return $this->_imageTitle($title);
10370cecf9d5Sandi        }
10380cecf9d5Sandi    }
10390cecf9d5Sandi
10400cecf9d5Sandi    /**
10413fd0b676Sandi     * Returns an HTML code for images used in link titles
10423fd0b676Sandi     *
10433fd0b676Sandi     * @todo Resolve namespace on internal images
10443fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10450cecf9d5Sandi     */
1046433bef32Sandi    function _imageTitle($img) {
1047433bef32Sandi        return $this->_media($img['src'],
10484826ab45Sandi                              $img['title'],
10494826ab45Sandi                              $img['align'],
10504826ab45Sandi                              $img['width'],
10514826ab45Sandi                              $img['height'],
10524826ab45Sandi                              $img['cache']);
10530cecf9d5Sandi    }
10540cecf9d5Sandi}
10550cecf9d5Sandi
10564826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1057