xref: /dokuwiki/inc/parser/xhtml.php (revision 29bfcd16ff6df2bbd7371cb73689464136bbe987)
10cecf9d5Sandi<?php
2b625487dSandi/**
3b625487dSandi * Renderer for XHTML output
4b625487dSandi *
5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
7b625487dSandi */
8b625487dSandi
900976812SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
100cecf9d5Sandi
110cecf9d5Sandiif ( !defined('DOKU_LF') ) {
120cecf9d5Sandi    // Some whitespace to help View > Source
130cecf9d5Sandi    define ('DOKU_LF',"\n");
140cecf9d5Sandi}
150cecf9d5Sandi
160cecf9d5Sandiif ( !defined('DOKU_TAB') ) {
170cecf9d5Sandi    // Some whitespace to help View > Source
180cecf9d5Sandi    define ('DOKU_TAB',"\t");
190cecf9d5Sandi}
200cecf9d5Sandi
210e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php';
2256fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php';
230e1c636eSandi
240cecf9d5Sandi/**
25b625487dSandi * The Renderer
260cecf9d5Sandi */
27ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
280cecf9d5Sandi
29c5a8fd96SAndreas Gohr    // @access public
30c5a8fd96SAndreas Gohr    var $doc = '';        // will contain the whole document
31c5a8fd96SAndreas Gohr    var $toc = array();   // will contain the Table of Contents
32c5a8fd96SAndreas Gohr
330cecf9d5Sandi
340cecf9d5Sandi    var $headers = array();
350cecf9d5Sandi    var $footnotes = array();
36af587fa8Sandi    var $lastsec = 0;
377764a90aSandi    var $store = '';
387764a90aSandi
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">';
63*29bfcd16SAndreas Gohr                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
64*29bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.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
72*29bfcd16SAndreas Gohr                        $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
73*29bfcd16SAndreas Gohr                        $this->doc .= ($ref+1).')</a></sup> '.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
85b8595a66SAndreas Gohr        // Prepare the TOC
86b8595a66SAndreas Gohr        if($this->info['toc'] && is_array($this->toc) && count($this->toc) > 2){
87b8595a66SAndreas Gohr            global $TOC;
88b8595a66SAndreas Gohr            $TOC = $this->toc;
890cecf9d5Sandi        }
903e55d035SAndreas Gohr
913e55d035SAndreas Gohr        // make sure there are no empty paragraphs
9227918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
93e41c4da9SAndreas Gohr    }
940cecf9d5Sandi
95e7856beaSchris    function toc_additem($id, $text, $level) {
96af587fa8Sandi        global $conf;
97af587fa8Sandi
98c5a8fd96SAndreas Gohr        //handle TOC
99c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
1007d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);
101c5a8fd96SAndreas Gohr        }
102e7856beaSchris    }
103e7856beaSchris
104e7856beaSchris    function header($text, $level, $pos) {
105e7856beaSchris
106e7856beaSchris        $hid = $this->_headerToLink($text,true);
107e7856beaSchris
108e7856beaSchris        //only add items within configured levels
109e7856beaSchris        $this->toc_additem($hid, $text, $level);
110c5a8fd96SAndreas Gohr
111c5a8fd96SAndreas Gohr        // write the header
112c5a8fd96SAndreas Gohr        $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
113a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
114c6a1c1bfSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1150cecf9d5Sandi    }
1160cecf9d5Sandi
11735dae8b0SBen Coburn     /**
11835dae8b0SBen Coburn     * Section edit marker is replaced by an edit button when
11935dae8b0SBen Coburn     * the page is editable. Replacement done in 'inc/html.php#html_secedit'
12035dae8b0SBen Coburn     *
12135dae8b0SBen Coburn     * @author Andreas Gohr <andi@splitbrain.org>
12235dae8b0SBen Coburn     * @author Ben Coburn   <btcoburn@silicodon.net>
12335dae8b0SBen Coburn     */
12435dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {
12535dae8b0SBen Coburn        global $conf;
12635dae8b0SBen Coburn
12735dae8b0SBen Coburn        if ($start!=-1 && $level<=$conf['maxseclevel']) {
12835dae8b0SBen Coburn            $name = str_replace('"', '', $name);
12935dae8b0SBen Coburn            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
13035dae8b0SBen Coburn        }
13135dae8b0SBen Coburn    }
13235dae8b0SBen Coburn
1330cecf9d5Sandi    function section_open($level) {
134a2d649c4Sandi        $this->doc .= "<div class=\"level$level\">".DOKU_LF;
1350cecf9d5Sandi    }
1360cecf9d5Sandi
1370cecf9d5Sandi    function section_close() {
138a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1390cecf9d5Sandi    }
1400cecf9d5Sandi
1410cecf9d5Sandi    function cdata($text) {
142a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1430cecf9d5Sandi    }
1440cecf9d5Sandi
1450cecf9d5Sandi    function p_open() {
146a2d649c4Sandi        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
1470cecf9d5Sandi    }
1480cecf9d5Sandi
1490cecf9d5Sandi    function p_close() {
150a2d649c4Sandi        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
1510cecf9d5Sandi    }
1520cecf9d5Sandi
1530cecf9d5Sandi    function linebreak() {
154a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
1550cecf9d5Sandi    }
1560cecf9d5Sandi
1570cecf9d5Sandi    function hr() {
1584beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
1590cecf9d5Sandi    }
1600cecf9d5Sandi
1610cecf9d5Sandi    function strong_open() {
162a2d649c4Sandi        $this->doc .= '<strong>';
1630cecf9d5Sandi    }
1640cecf9d5Sandi
1650cecf9d5Sandi    function strong_close() {
166a2d649c4Sandi        $this->doc .= '</strong>';
1670cecf9d5Sandi    }
1680cecf9d5Sandi
1690cecf9d5Sandi    function emphasis_open() {
170a2d649c4Sandi        $this->doc .= '<em>';
1710cecf9d5Sandi    }
1720cecf9d5Sandi
1730cecf9d5Sandi    function emphasis_close() {
174a2d649c4Sandi        $this->doc .= '</em>';
1750cecf9d5Sandi    }
1760cecf9d5Sandi
1770cecf9d5Sandi    function underline_open() {
17802e51121SAnika Henke        $this->doc .= '<em class="u">';
1790cecf9d5Sandi    }
1800cecf9d5Sandi
1810cecf9d5Sandi    function underline_close() {
18202e51121SAnika Henke        $this->doc .= '</em>';
1830cecf9d5Sandi    }
1840cecf9d5Sandi
1850cecf9d5Sandi    function monospace_open() {
186a2d649c4Sandi        $this->doc .= '<code>';
1870cecf9d5Sandi    }
1880cecf9d5Sandi
1890cecf9d5Sandi    function monospace_close() {
190a2d649c4Sandi        $this->doc .= '</code>';
1910cecf9d5Sandi    }
1920cecf9d5Sandi
1930cecf9d5Sandi    function subscript_open() {
194a2d649c4Sandi        $this->doc .= '<sub>';
1950cecf9d5Sandi    }
1960cecf9d5Sandi
1970cecf9d5Sandi    function subscript_close() {
198a2d649c4Sandi        $this->doc .= '</sub>';
1990cecf9d5Sandi    }
2000cecf9d5Sandi
2010cecf9d5Sandi    function superscript_open() {
202a2d649c4Sandi        $this->doc .= '<sup>';
2030cecf9d5Sandi    }
2040cecf9d5Sandi
2050cecf9d5Sandi    function superscript_close() {
206a2d649c4Sandi        $this->doc .= '</sup>';
2070cecf9d5Sandi    }
2080cecf9d5Sandi
2090cecf9d5Sandi    function deleted_open() {
210a2d649c4Sandi        $this->doc .= '<del>';
2110cecf9d5Sandi    }
2120cecf9d5Sandi
2130cecf9d5Sandi    function deleted_close() {
214a2d649c4Sandi        $this->doc .= '</del>';
2150cecf9d5Sandi    }
2160cecf9d5Sandi
2173fd0b676Sandi    /**
2183fd0b676Sandi     * Callback for footnote start syntax
2193fd0b676Sandi     *
2203fd0b676Sandi     * All following content will go to the footnote instead of
221d74aace9Schris     * the document. To achieve this the previous rendered content
2223fd0b676Sandi     * is moved to $store and $doc is cleared
2233fd0b676Sandi     *
2243fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2253fd0b676Sandi     */
2260cecf9d5Sandi    function footnote_open() {
2277764a90aSandi
2287764a90aSandi        // move current content to store and record footnote
2297764a90aSandi        $this->store = $this->doc;
2307764a90aSandi        $this->doc   = '';
2310cecf9d5Sandi    }
2320cecf9d5Sandi
2333fd0b676Sandi    /**
2343fd0b676Sandi     * Callback for footnote end syntax
2353fd0b676Sandi     *
2363fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2373fd0b676Sandi     * content is restored from $store again
2383fd0b676Sandi     *
2393fd0b676Sandi     * @author Andreas Gohr
2403fd0b676Sandi     */
2410cecf9d5Sandi    function footnote_close() {
2427764a90aSandi
243d74aace9Schris        // recover footnote into the stack and restore old content
244d74aace9Schris        $footnote = $this->doc;
2457764a90aSandi        $this->doc = $this->store;
2467764a90aSandi        $this->store = '';
247d74aace9Schris
248d74aace9Schris        // check to see if this footnote has been seen before
249d74aace9Schris        $i = array_search($footnote, $this->footnotes);
250d74aace9Schris
251d74aace9Schris        if ($i === false) {
252d74aace9Schris            // its a new footnote, add it to the $footnotes array
253d74aace9Schris            $id = count($this->footnotes)+1;
254d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
255d74aace9Schris        } else {
256d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
257d74aace9Schris            $i++;
258d74aace9Schris            $id = count($this->footnotes)+1;
259d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
260d74aace9Schris        }
261d74aace9Schris
2626b379cbfSAndreas Gohr        // output the footnote reference and link
263*29bfcd16SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>';
2640cecf9d5Sandi    }
2650cecf9d5Sandi
2660cecf9d5Sandi    function listu_open() {
267a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
2680cecf9d5Sandi    }
2690cecf9d5Sandi
2700cecf9d5Sandi    function listu_close() {
271a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
2720cecf9d5Sandi    }
2730cecf9d5Sandi
2740cecf9d5Sandi    function listo_open() {
275a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
2760cecf9d5Sandi    }
2770cecf9d5Sandi
2780cecf9d5Sandi    function listo_close() {
279a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
2800cecf9d5Sandi    }
2810cecf9d5Sandi
2820cecf9d5Sandi    function listitem_open($level) {
283a2d649c4Sandi        $this->doc .= '<li class="level'.$level.'">';
2840cecf9d5Sandi    }
2850cecf9d5Sandi
2860cecf9d5Sandi    function listitem_close() {
287a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
2880cecf9d5Sandi    }
2890cecf9d5Sandi
2900cecf9d5Sandi    function listcontent_open() {
29190db23d7Schris        $this->doc .= '<div class="li">';
2920cecf9d5Sandi    }
2930cecf9d5Sandi
2940cecf9d5Sandi    function listcontent_close() {
29590db23d7Schris        $this->doc .= '</div>'.DOKU_LF;
2960cecf9d5Sandi    }
2970cecf9d5Sandi
2980cecf9d5Sandi    function unformatted($text) {
299a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3000cecf9d5Sandi    }
3010cecf9d5Sandi
3020cecf9d5Sandi    /**
3033fd0b676Sandi     * Execute PHP code if allowed
3043fd0b676Sandi     *
3053fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3060cecf9d5Sandi     */
3070cecf9d5Sandi    function php($text) {
308bad0b545Sandi        ob_start();
3094de671bcSandi        eval($text);
3103fd0b676Sandi        $this->doc .= ob_get_contents();
311bad0b545Sandi        ob_end_clean();
3120cecf9d5Sandi    }
3130cecf9d5Sandi
31407f89c3cSAnika Henke    function phpblock($text) {
31507f89c3cSAnika Henke        $this->php($text);
31607f89c3cSAnika Henke    }
31707f89c3cSAnika Henke
3180cecf9d5Sandi    /**
3193fd0b676Sandi     * Insert HTML if allowed
3203fd0b676Sandi     *
3213fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3220cecf9d5Sandi     */
3230cecf9d5Sandi    function html($text) {
324a2d649c4Sandi        $this->doc .= $text;
3254de671bcSandi    }
3260cecf9d5Sandi
32707f89c3cSAnika Henke    function htmlblock($text) {
32807f89c3cSAnika Henke        $this->html($text);
32907f89c3cSAnika Henke    }
33007f89c3cSAnika Henke
3310cecf9d5Sandi    function preformatted($text) {
332a2d649c4Sandi        $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
3330cecf9d5Sandi    }
3340cecf9d5Sandi
3350cecf9d5Sandi    function file($text) {
336a2d649c4Sandi        $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
3370cecf9d5Sandi    }
3380cecf9d5Sandi
3390cecf9d5Sandi    function quote_open() {
34096331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
3410cecf9d5Sandi    }
3420cecf9d5Sandi
3430cecf9d5Sandi    function quote_close() {
34496331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
3450cecf9d5Sandi    }
3460cecf9d5Sandi
3470cecf9d5Sandi    /**
3483fd0b676Sandi     * Callback for code text
3493fd0b676Sandi     *
3503fd0b676Sandi     * Uses GeSHi to highlight language syntax
3513fd0b676Sandi     *
3523fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3530cecf9d5Sandi     */
3540cecf9d5Sandi    function code($text, $language = NULL) {
3554de671bcSandi        global $conf;
3560cecf9d5Sandi
3570cecf9d5Sandi        if ( is_null($language) ) {
3580cecf9d5Sandi            $this->preformatted($text);
3590cecf9d5Sandi        } else {
360852896daSAndreas Gohr            //strip leading and trailing blank line
361313da78aSandi            $text = preg_replace('/^\s*?\n/','',$text);
362852896daSAndreas Gohr            $text = preg_replace('/\s*?\n$/','',$text);
3638f7d700cSchris            $this->doc .= p_xhtml_cached_geshi($text, $language);
3640cecf9d5Sandi        }
3650cecf9d5Sandi    }
3660cecf9d5Sandi
3670cecf9d5Sandi    function acronym($acronym) {
3680cecf9d5Sandi
3690cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
3700cecf9d5Sandi
371433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
3720cecf9d5Sandi
373a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
374433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
3750cecf9d5Sandi
3760cecf9d5Sandi        } else {
377a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
3780cecf9d5Sandi        }
3790cecf9d5Sandi    }
3800cecf9d5Sandi
3810cecf9d5Sandi    function smiley($smiley) {
3820cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
383433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
384f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
3854beabca9SAnika Henke                '" class="middle" alt="'.
386433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
3870cecf9d5Sandi        } else {
388a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
3890cecf9d5Sandi        }
3900cecf9d5Sandi    }
3910cecf9d5Sandi
392f62ea8a1Sandi    /*
3934de671bcSandi    * not used
3940cecf9d5Sandi    function wordblock($word) {
3950cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
396a2d649c4Sandi            $this->doc .= '** BLEEP **';
3970cecf9d5Sandi        } else {
398a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
3990cecf9d5Sandi        }
4000cecf9d5Sandi    }
4014de671bcSandi    */
4020cecf9d5Sandi
4030cecf9d5Sandi    function entity($entity) {
4040cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
405a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4060cecf9d5Sandi        } else {
407a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4080cecf9d5Sandi        }
4090cecf9d5Sandi    }
4100cecf9d5Sandi
4110cecf9d5Sandi    function multiplyentity($x, $y) {
412a2d649c4Sandi        $this->doc .= "$x&times;$y";
4130cecf9d5Sandi    }
4140cecf9d5Sandi
4150cecf9d5Sandi    function singlequoteopening() {
41671b40da2SAnika Henke        global $lang;
41771b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
4180cecf9d5Sandi    }
4190cecf9d5Sandi
4200cecf9d5Sandi    function singlequoteclosing() {
42171b40da2SAnika Henke        global $lang;
42271b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
4230cecf9d5Sandi    }
4240cecf9d5Sandi
42557d757d1SAndreas Gohr    function apostrophe() {
42657d757d1SAndreas Gohr        global $lang;
427a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
42857d757d1SAndreas Gohr    }
42957d757d1SAndreas Gohr
4300cecf9d5Sandi    function doublequoteopening() {
43171b40da2SAnika Henke        global $lang;
43271b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
4330cecf9d5Sandi    }
4340cecf9d5Sandi
4350cecf9d5Sandi    function doublequoteclosing() {
43671b40da2SAnika Henke        global $lang;
43771b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
4380cecf9d5Sandi    }
4390cecf9d5Sandi
4400cecf9d5Sandi    /**
4410cecf9d5Sandi    */
4420cecf9d5Sandi    function camelcaselink($link) {
44311d0aa47Sandi      $this->internallink($link,$link);
4440cecf9d5Sandi    }
4450cecf9d5Sandi
4460b7c14c2Sandi
4470b7c14c2Sandi    function locallink($hash, $name = NULL){
4480b7c14c2Sandi        global $ID;
4490b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
4500b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
4510b7c14c2Sandi        $title = $ID.' &crarr;';
4520b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
4530b7c14c2Sandi        $this->doc .= $name;
4540b7c14c2Sandi        $this->doc .= '</a>';
4550b7c14c2Sandi    }
4560b7c14c2Sandi
457cffcc403Sandi    /**
4583fd0b676Sandi     * Render an internal Wiki Link
4593fd0b676Sandi     *
460cffcc403Sandi     * $search and $returnonly are not for the renderer but are used
461cffcc403Sandi     * elsewhere - no need to implement them in other renderers
4623fd0b676Sandi     *
4633fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
464cffcc403Sandi     */
465cffcc403Sandi    function internallink($id, $name = NULL, $search=NULL,$returnonly=false) {
466ba11bd29Sandi        global $conf;
46737e34a5eSandi        global $ID;
4680339c872Sjan        // default name is based on $id as given
4690339c872Sjan        $default = $this->_simpleTitle($id);
470ad32e47eSAndreas Gohr
4710339c872Sjan        // now first resolve and clean up the $id
47237e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
4730339c872Sjan        $name = $this->_getLinkTitle($name, $default, $isImage, $id);
4740e1c636eSandi        if ( !$isImage ) {
4750e1c636eSandi            if ( $exists ) {
476ba11bd29Sandi                $class='wikilink1';
4770cecf9d5Sandi            } else {
478ba11bd29Sandi                $class='wikilink2';
47944a6b4c7SAndreas Gohr                $link['rel']='nofollow';
4800cecf9d5Sandi            }
4810cecf9d5Sandi        } else {
482ba11bd29Sandi            $class='media';
4830cecf9d5Sandi        }
4840cecf9d5Sandi
485a1685bedSandi        //keep hash anchor
486ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
487943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
488a1685bedSandi
489ba11bd29Sandi        //prepare for formating
490ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
491ba11bd29Sandi        $link['style']  = '';
492ba11bd29Sandi        $link['pre']    = '';
493ba11bd29Sandi        $link['suf']    = '';
49440eb54bbSjan        // highlight link to current page
49540eb54bbSjan        if ($id == $ID) {
49692795d04Sandi            $link['pre']    = '<span class="curid">';
49792795d04Sandi            $link['suf']    = '</span>';
49840eb54bbSjan        }
4995e163278SAndreas Gohr        $link['more']   = '';
500ba11bd29Sandi        $link['class']  = $class;
501ba11bd29Sandi        $link['url']    = wl($id);
502ba11bd29Sandi        $link['name']   = $name;
503ba11bd29Sandi        $link['title']  = $id;
504723d78dbSandi        //add search string
505723d78dbSandi        if($search){
506723d78dbSandi            ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
507b6c6979fSAndreas Gohr            $link['url'] .= rawurlencode($search);
508723d78dbSandi        }
509723d78dbSandi
510a1685bedSandi        //keep hash
511a1685bedSandi        if($hash) $link['url'].='#'.$hash;
512a1685bedSandi
513ba11bd29Sandi        //output formatted
514cffcc403Sandi        if($returnonly){
515cffcc403Sandi            return $this->_formatLink($link);
516cffcc403Sandi        }else{
517a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
5180cecf9d5Sandi        }
519cffcc403Sandi    }
5200cecf9d5Sandi
521b625487dSandi    function externallink($url, $name = NULL) {
522b625487dSandi        global $conf;
5230cecf9d5Sandi
524433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
5256f0c5dbfSandi
5260cecf9d5Sandi        if ( !$isImage ) {
527b625487dSandi            $class='urlextern';
5280cecf9d5Sandi        } else {
529b625487dSandi            $class='media';
5300cecf9d5Sandi        }
5310cecf9d5Sandi
532b625487dSandi        //prepare for formating
533b625487dSandi        $link['target'] = $conf['target']['extern'];
534b625487dSandi        $link['style']  = '';
535b625487dSandi        $link['pre']    = '';
536b625487dSandi        $link['suf']    = '';
5375e163278SAndreas Gohr        $link['more']   = '';
538b625487dSandi        $link['class']  = $class;
539b625487dSandi        $link['url']    = $url;
540e1c10e4dSchris
541b625487dSandi        $link['name']   = $name;
542433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
543b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
5440cecf9d5Sandi
545b625487dSandi        //output formatted
546a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
5470cecf9d5Sandi    }
5480cecf9d5Sandi
5490cecf9d5Sandi    /**
5500cecf9d5Sandi    */
55197a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
552b625487dSandi        global $conf;
5530cecf9d5Sandi
55497a3e4e3Sandi        $link = array();
55597a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
55697a3e4e3Sandi        $link['pre']    = '';
55797a3e4e3Sandi        $link['suf']    = '';
5585e163278SAndreas Gohr        $link['more']   = '';
559433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
5600cecf9d5Sandi
56197a3e4e3Sandi        //get interwiki URL
5621f82fabeSAndreas Gohr        $url = $this-> _resolveInterWiki($wikiName,$wikiUri);
5630cecf9d5Sandi
56497a3e4e3Sandi        if ( !$isImage ) {
5659d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
5669d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
5671c2d1019SAndreas Gohr        } else {
5681c2d1019SAndreas Gohr            $link['class'] = 'media';
56997a3e4e3Sandi        }
5700cecf9d5Sandi
57197a3e4e3Sandi        //do we stay at the same server? Use local target
57297a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
57397a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
57497a3e4e3Sandi        }
5750cecf9d5Sandi
57697a3e4e3Sandi        $link['url'] = $url;
57797a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
57897a3e4e3Sandi
57997a3e4e3Sandi        //output formatted
580a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
5810cecf9d5Sandi    }
5820cecf9d5Sandi
5830cecf9d5Sandi    /**
5840cecf9d5Sandi     */
5851d47afe1Sandi    function windowssharelink($url, $name = NULL) {
5861d47afe1Sandi        global $conf;
5871d47afe1Sandi        global $lang;
5881d47afe1Sandi        //simple setup
5891d47afe1Sandi        $link['target'] = $conf['target']['windows'];
5901d47afe1Sandi        $link['pre']    = '';
5911d47afe1Sandi        $link['suf']   = '';
5921d47afe1Sandi        $link['style']  = '';
5931d47afe1Sandi        //Display error on browsers other than IE
5941d47afe1Sandi        $link['more'] = 'onclick="if(document.all == null){alert(\''.
595b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).
5961d47afe1Sandi                        '\');}" onkeypress="if(document.all == null){alert(\''.
597b120b664SAndreas Gohr                        str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"';
5980cecf9d5Sandi
599433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6000cecf9d5Sandi        if ( !$isImage ) {
6011d47afe1Sandi            $link['class'] = 'windows';
6020cecf9d5Sandi        } else {
6031d47afe1Sandi            $link['class'] = 'media';
6040cecf9d5Sandi        }
6050cecf9d5Sandi
6060cecf9d5Sandi
607433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
6081d47afe1Sandi        $url = str_replace('\\','/',$url);
6091d47afe1Sandi        $url = 'file:///'.$url;
6101d47afe1Sandi        $link['url'] = $url;
6110cecf9d5Sandi
6121d47afe1Sandi        //output formatted
613a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6140cecf9d5Sandi    }
6150cecf9d5Sandi
61671352defSandi    function emaillink($address, $name = NULL) {
61771352defSandi        global $conf;
61871352defSandi        //simple setup
61971352defSandi        $link = array();
62071352defSandi        $link['target'] = '';
62171352defSandi        $link['pre']    = '';
62271352defSandi        $link['suf']   = '';
62371352defSandi        $link['style']  = '';
62471352defSandi        $link['more']   = '';
6250cecf9d5Sandi
626c6e62e9fSchris        $name = $this->_getLinkTitle($name, '', $isImage);
6270cecf9d5Sandi        if ( !$isImage ) {
628776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
6290cecf9d5Sandi        } else {
630776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
6310cecf9d5Sandi        }
6320cecf9d5Sandi
63307738714SAndreas Gohr        $address = $this->_xmlEntities($address);
63400a7b5adSEsther Brunner        $address = obfuscate($address);
63500a7b5adSEsther Brunner        $title   = $address;
6368c128049SAndreas Gohr
63771352defSandi        if(empty($name)){
63800a7b5adSEsther Brunner            $name = $address;
63971352defSandi        }
6408c128049SAndreas Gohr#elseif($isImage{
6418c128049SAndreas Gohr#            $name = $this->_xmlEntities($name);
6428c128049SAndreas Gohr#        }
6430cecf9d5Sandi
644776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
645776b36ecSAndreas Gohr
646776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
64771352defSandi        $link['name']  = $name;
64871352defSandi        $link['title'] = $title;
6490cecf9d5Sandi
65071352defSandi        //output formatted
651a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6520cecf9d5Sandi    }
6530cecf9d5Sandi
6544826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
655dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
6563685f775Sandi        global $conf;
65737e34a5eSandi        global $ID;
65837e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
6590cecf9d5Sandi
6603685f775Sandi        $link = array();
6613685f775Sandi        $link['class']  = 'media';
6623685f775Sandi        $link['style']  = '';
6633685f775Sandi        $link['pre']    = '';
6643685f775Sandi        $link['suf']    = '';
6655e163278SAndreas Gohr        $link['more']   = '';
6663685f775Sandi        $link['target'] = $conf['target']['media'];
667d98d4540SBen Coburn        $noLink = false;
6683685f775Sandi
669433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
67055efc227SAndreas Gohr        list($ext,$mime) = mimetype($src);
6715667eb65SAndreas Gohr        if(substr($mime,0,5) == 'image'){
672dc673a5bSjoe.lapp             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
6732ca14335SEsther Brunner         }elseif($mime == 'application/x-shockwave-flash'){
6742ca14335SEsther Brunner             // don't link flash movies
67544881bd0Shenning.noren             $noLink = true;
67655efc227SAndreas Gohr         }else{
6772ca14335SEsther Brunner             // add file icons
6789d2ddea4SAndreas Gohr             $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
6799d2ddea4SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$class;
6806de3759aSAndreas Gohr             $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
68155efc227SAndreas Gohr         }
682433bef32Sandi         $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
6833685f775Sandi
6843685f775Sandi         //output formatted
685dc673a5bSjoe.lapp         if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
6862ca14335SEsther Brunner         else $this->doc .= $this->_formatLink($link);
6870cecf9d5Sandi    }
6880cecf9d5Sandi
6890cecf9d5Sandi    /**
6904826ab45Sandi     * @todo don't add link for flash
6910cecf9d5Sandi     */
6924826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
693dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
6943685f775Sandi        global $conf;
6950cecf9d5Sandi
6963685f775Sandi        $link = array();
6973685f775Sandi        $link['class']  = 'media';
6983685f775Sandi        $link['style']  = '';
6993685f775Sandi        $link['pre']    = '';
7003685f775Sandi        $link['suf']    = '';
7015e163278SAndreas Gohr        $link['more']   = '';
7023685f775Sandi        $link['target'] = $conf['target']['media'];
7033685f775Sandi
704433bef32Sandi        $link['title']  = $this->_xmlEntities($src);
7056de3759aSAndreas Gohr        $link['url']    = ml($src,array('cache'=>$cache));
706433bef32Sandi        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
707d98d4540SBen Coburn        $noLink = false;
7083685f775Sandi
7092ca14335SEsther Brunner        list($ext,$mime) = mimetype($src);
7102ca14335SEsther Brunner        if(substr($mime,0,5) == 'image'){
7112ca14335SEsther Brunner             // link only jpeg images
71244881bd0Shenning.noren             // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7132ca14335SEsther Brunner        }elseif($mime == 'application/x-shockwave-flash'){
7142ca14335SEsther Brunner             // don't link flash movies
71544881bd0Shenning.noren             $noLink = true;
7162ca14335SEsther Brunner        }else{
7172ca14335SEsther Brunner             // add file icons
718d15166e5SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$ext;
7192ca14335SEsther Brunner         }
7202ca14335SEsther Brunner
7213685f775Sandi        //output formatted
722dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7232ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7240cecf9d5Sandi    }
7250cecf9d5Sandi
7264826ab45Sandi    /**
7273db95becSAndreas Gohr     * Renders an RSS feed
728b625487dSandi     *
729b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
730b625487dSandi     */
7313db95becSAndreas Gohr    function rss ($url,$params){
732b625487dSandi        global $lang;
7333db95becSAndreas Gohr        global $conf;
7343db95becSAndreas Gohr
7353db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
7363db95becSAndreas Gohr        $feed = new FeedParser();
73700077af8SAndreas Gohr        $feed->set_feed_url($url);
738b625487dSandi
739b625487dSandi        //disable warning while fetching
740bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
7413db95becSAndreas Gohr        $rc = $feed->init();
742bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
743b625487dSandi
7443db95becSAndreas Gohr        //decide on start and end
7453db95becSAndreas Gohr        if($params['reverse']){
7463db95becSAndreas Gohr            $mod = -1;
7473db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
7483db95becSAndreas Gohr            $end   = $start - ($params['max']);
749b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
7503db95becSAndreas Gohr        }else{
7513db95becSAndreas Gohr            $mod   = 1;
7523db95becSAndreas Gohr            $start = 0;
7533db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
7543db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
7553db95becSAndreas Gohr        }
7563db95becSAndreas Gohr
757a2d649c4Sandi        $this->doc .= '<ul class="rss">';
7583db95becSAndreas Gohr        if($rc){
7593db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
7601bde1582SAndreas Gohr                $item = $feed->get_item($x);
7613db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
7621bde1582SAndreas Gohr                $this->externallink($item->get_permalink(),
7631bde1582SAndreas Gohr                                    $item->get_title());
7643db95becSAndreas Gohr                if($params['author']){
7651bde1582SAndreas Gohr                    $author = $item->get_author(0);
7661bde1582SAndreas Gohr                    if($author){
7671bde1582SAndreas Gohr                        $name = $author->get_name();
7681bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
7691bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
7701bde1582SAndreas Gohr                    }
7713db95becSAndreas Gohr                }
7723db95becSAndreas Gohr                if($params['date']){
7731bde1582SAndreas Gohr                    $this->doc .= ' ('.$item->get_date($conf['dformat']).')';
7743db95becSAndreas Gohr                }
7751bde1582SAndreas Gohr                if($params['details']){
7763db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
777173dccb7STom N Harris                    if($conf['htmlok']){
7781bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
7793db95becSAndreas Gohr                    }else{
7801bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
7813db95becSAndreas Gohr                    }
7823db95becSAndreas Gohr                    $this->doc .= '</div>';
7833db95becSAndreas Gohr                }
7843db95becSAndreas Gohr
7853db95becSAndreas Gohr                $this->doc .= '</div></li>';
786b625487dSandi            }
787b625487dSandi        }else{
7883db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
789a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
790b625487dSandi            $this->externallink($url);
79145e147ccSAndreas Gohr            if($conf['allowdebug']){
79245e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
79345e147ccSAndreas Gohr            }
7943db95becSAndreas Gohr            $this->doc .= '</div></li>';
795b625487dSandi        }
796a2d649c4Sandi        $this->doc .= '</ul>';
797b625487dSandi    }
798b625487dSandi
7990cecf9d5Sandi    // $numrows not yet implemented
8000cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){
801a2d649c4Sandi        $this->doc .= '<table class="inline">'.DOKU_LF;
8020cecf9d5Sandi    }
8030cecf9d5Sandi
8040cecf9d5Sandi    function table_close(){
805cb42b03dSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
8060cecf9d5Sandi    }
8070cecf9d5Sandi
8080cecf9d5Sandi    function tablerow_open(){
809a2d649c4Sandi        $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
8100cecf9d5Sandi    }
8110cecf9d5Sandi
8120cecf9d5Sandi    function tablerow_close(){
813a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
8140cecf9d5Sandi    }
8150cecf9d5Sandi
8160cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){
817a2d649c4Sandi        $this->doc .= '<th';
8180cecf9d5Sandi        if ( !is_null($align) ) {
819a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8200cecf9d5Sandi        }
8210cecf9d5Sandi        if ( $colspan > 1 ) {
822a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8230cecf9d5Sandi        }
824a2d649c4Sandi        $this->doc .= '>';
8250cecf9d5Sandi    }
8260cecf9d5Sandi
8270cecf9d5Sandi    function tableheader_close(){
828a2d649c4Sandi        $this->doc .= '</th>';
8290cecf9d5Sandi    }
8300cecf9d5Sandi
8310cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){
832a2d649c4Sandi        $this->doc .= '<td';
8330cecf9d5Sandi        if ( !is_null($align) ) {
834a2d649c4Sandi            $this->doc .= ' class="'.$align.'align"';
8350cecf9d5Sandi        }
8360cecf9d5Sandi        if ( $colspan > 1 ) {
837a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8380cecf9d5Sandi        }
839a2d649c4Sandi        $this->doc .= '>';
8400cecf9d5Sandi    }
8410cecf9d5Sandi
8420cecf9d5Sandi    function tablecell_close(){
843a2d649c4Sandi        $this->doc .= '</td>';
8440cecf9d5Sandi    }
8450cecf9d5Sandi
8460cecf9d5Sandi    //----------------------------------------------------------
8470cecf9d5Sandi    // Utils
8480cecf9d5Sandi
849ba11bd29Sandi    /**
8503fd0b676Sandi     * Build a link
8513fd0b676Sandi     *
8523fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
853ba11bd29Sandi     *
854ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
855ba11bd29Sandi     */
856433bef32Sandi    function _formatLink($link){
857ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
858ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
859ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
860ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
861ba11bd29Sandi        }
862ba11bd29Sandi        //remove double encodings in titles
863ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
864ba11bd29Sandi
865453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
866453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
867453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
868453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
869453493f2SAndreas Gohr
870ba11bd29Sandi        $ret  = '';
871ba11bd29Sandi        $ret .= $link['pre'];
872ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
873bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
874bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
875bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
876bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
87744a6b4c7SAndreas Gohr        if(!empty($link['rel']))    $ret .= ' rel="'.$link['rel'].'"';
878bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
879ba11bd29Sandi        $ret .= '>';
880ba11bd29Sandi        $ret .= $link['name'];
881ba11bd29Sandi        $ret .= '</a>';
882ba11bd29Sandi        $ret .= $link['suf'];
883ba11bd29Sandi        return $ret;
884ba11bd29Sandi    }
885ba11bd29Sandi
886ba11bd29Sandi    /**
8873fd0b676Sandi     * Renders internal and external media
8883fd0b676Sandi     *
8893fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
8903fd0b676Sandi     */
8913fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
8923fd0b676Sandi                      $height=NULL, $cache=NULL) {
8933fd0b676Sandi
8943fd0b676Sandi        $ret = '';
8953fd0b676Sandi
8963fd0b676Sandi        list($ext,$mime) = mimetype($src);
8973fd0b676Sandi        if(substr($mime,0,5) == 'image'){
8983fd0b676Sandi            //add image tag
8996de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
9003fd0b676Sandi            $ret .= ' class="media'.$align.'"';
9013fd0b676Sandi
9024ab889eaSAndreas Gohr            // make left/right alignment for no-CSS view work (feeds)
9034ab889eaSAndreas Gohr            if($align == 'right') $ret .= ' align="right"';
9044ab889eaSAndreas Gohr            if($align == 'left')  $ret .= ' align="left"';
9054ab889eaSAndreas Gohr
9063fd0b676Sandi            if (!is_null($title)) {
9073fd0b676Sandi                $ret .= ' title="'.$this->_xmlEntities($title).'"';
9083fd0b676Sandi                $ret .= ' alt="'.$this->_xmlEntities($title).'"';
90955efc227SAndreas Gohr            }elseif($ext == 'jpg' || $ext == 'jpeg'){
91055efc227SAndreas Gohr                //try to use the caption from IPTC/EXIF
91155efc227SAndreas Gohr                require_once(DOKU_INC.'inc/JpegMeta.php');
91255efc227SAndreas Gohr                $jpeg =& new JpegMeta(mediaFN($src));
91355efc227SAndreas Gohr                if($jpeg !== false) $cap = $jpeg->getTitle();
91455efc227SAndreas Gohr                if($cap){
91555efc227SAndreas Gohr                    $ret .= ' title="'.$this->_xmlEntities($cap).'"';
91655efc227SAndreas Gohr                    $ret .= ' alt="'.$this->_xmlEntities($cap).'"';
917fcf1ccdcSAndreas Gohr                }else{
918fcf1ccdcSAndreas Gohr                    $ret .= ' alt=""';
91955efc227SAndreas Gohr                }
9203fd0b676Sandi            }else{
9213fd0b676Sandi                $ret .= ' alt=""';
9223fd0b676Sandi            }
9233fd0b676Sandi
9243fd0b676Sandi            if ( !is_null($width) )
9253fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
9263fd0b676Sandi
9273fd0b676Sandi            if ( !is_null($height) )
9283fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
9293fd0b676Sandi
9303fd0b676Sandi            $ret .= ' />';
9313fd0b676Sandi
9323fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
9333fd0b676Sandi            $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
9343fd0b676Sandi                    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
9353fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9363fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9373fd0b676Sandi            $ret .= '>'.DOKU_LF;
9386de3759aSAndreas Gohr            $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
9393fd0b676Sandi            $ret .= '<param name="quality" value="high" />'.DOKU_LF;
9406de3759aSAndreas Gohr            $ret .= '<embed src="'.ml($src).'"'.
9413fd0b676Sandi                    ' quality="high"';
9423fd0b676Sandi            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
9433fd0b676Sandi            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
9443fd0b676Sandi            $ret .= ' type="application/x-shockwave-flash"'.
9453fd0b676Sandi                    ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF;
9463fd0b676Sandi            $ret .= '</object>'.DOKU_LF;
9473fd0b676Sandi
9480f428d7dSAndreas Gohr        }elseif($title){
9493fd0b676Sandi            // well at least we have a title to display
9503fd0b676Sandi            $ret .= $this->_xmlEntities($title);
9513fd0b676Sandi        }else{
9525291ca3aSAndreas Gohr            // just show the sourcename
9530f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
9543fd0b676Sandi        }
9553fd0b676Sandi
9563fd0b676Sandi        return $ret;
9573fd0b676Sandi    }
9583fd0b676Sandi
959433bef32Sandi    function _xmlEntities($string) {
960de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
9610cecf9d5Sandi    }
9620cecf9d5Sandi
9638a831f2bSAndreas Gohr    /**
9648a831f2bSAndreas Gohr     * Creates a linkid from a headline
965c5a8fd96SAndreas Gohr     *
966c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
967c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
968c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
9698a831f2bSAndreas Gohr     */
970c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
971501af51eSAndreas Gohr        $title = str_replace(':','',cleanID($title));
972a9e0fd1bSAndreas Gohr        $title = ltrim($title,'0123456789._-');
9738a831f2bSAndreas Gohr        if(empty($title)) $title='section';
974c5a8fd96SAndreas Gohr
975c5a8fd96SAndreas Gohr        if($create){
976c5a8fd96SAndreas Gohr            // make sure tiles are unique
977c5a8fd96SAndreas Gohr            $num = '';
978c5a8fd96SAndreas Gohr            while(in_array($title.$num,$this->headers)){
9790affd488SAndreas Gohr                ($num) ? $num++ : $num = 1;
980c5a8fd96SAndreas Gohr            }
981c5a8fd96SAndreas Gohr            $title = $title.$num;
982c5a8fd96SAndreas Gohr            $this->headers[] = $title;
983c5a8fd96SAndreas Gohr        }
984c5a8fd96SAndreas Gohr
9858a831f2bSAndreas Gohr        return $title;
9860cecf9d5Sandi    }
9870cecf9d5Sandi
988af587fa8Sandi    /**
9893fd0b676Sandi     * Construct a title and handle images in titles
9903fd0b676Sandi     *
9910b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
9923fd0b676Sandi     */
993433bef32Sandi    function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
994bb0a59d4Sjan        global $conf;
995bb0a59d4Sjan
99644881bd0Shenning.noren        $isImage = false;
9970cecf9d5Sandi        if ( is_null($title) ) {
998bb0a59d4Sjan            if ($conf['useheading'] && $id) {
999fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1000bb0a59d4Sjan                if ($heading) {
1001433bef32Sandi                    return $this->_xmlEntities($heading);
1002bb0a59d4Sjan                }
1003bb0a59d4Sjan            }
1004433bef32Sandi            return $this->_xmlEntities($default);
10050cecf9d5Sandi        } else if ( is_string($title) ) {
1006433bef32Sandi            return $this->_xmlEntities($title);
10070cecf9d5Sandi        } else if ( is_array($title) ) {
100844881bd0Shenning.noren            $isImage = true;
1009433bef32Sandi            return $this->_imageTitle($title);
10100cecf9d5Sandi        }
10110cecf9d5Sandi    }
10120cecf9d5Sandi
10130cecf9d5Sandi    /**
10143fd0b676Sandi     * Returns an HTML code for images used in link titles
10153fd0b676Sandi     *
10163fd0b676Sandi     * @todo Resolve namespace on internal images
10173fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10180cecf9d5Sandi     */
1019433bef32Sandi    function _imageTitle($img) {
1020433bef32Sandi        return $this->_media($img['src'],
10214826ab45Sandi                              $img['title'],
10224826ab45Sandi                              $img['align'],
10234826ab45Sandi                              $img['width'],
10244826ab45Sandi                              $img['height'],
10254826ab45Sandi                              $img['cache']);
10260cecf9d5Sandi    }
10270cecf9d5Sandi}
10280cecf9d5Sandi
10294826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1030