xref: /dokuwiki/inc/parser/xhtml.php (revision 49cef4fdcf4c8c1eba59bc3a00aff004599f4a58)
10cecf9d5Sandi<?php
2b625487dSandi/**
3b625487dSandi * Renderer for XHTML output
4b625487dSandi *
5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
7b625487dSandi */
8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
90cecf9d5Sandi
100cecf9d5Sandiif(!defined('DOKU_LF')) {
110cecf9d5Sandi    // Some whitespace to help View > Source
120cecf9d5Sandi    define ('DOKU_LF', "\n");
130cecf9d5Sandi}
140cecf9d5Sandi
150cecf9d5Sandiif(!defined('DOKU_TAB')) {
160cecf9d5Sandi    // Some whitespace to help View > Source
170cecf9d5Sandi    define ('DOKU_TAB', "\t");
180cecf9d5Sandi}
190cecf9d5Sandi
200cecf9d5Sandi/**
213dd5c225SAndreas Gohr * The XHTML Renderer
223dd5c225SAndreas Gohr *
233dd5c225SAndreas Gohr * This is DokuWiki's main renderer used to display page content in the wiki
240cecf9d5Sandi */
25ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
263dd5c225SAndreas Gohr    /** @var array store the table of contents */
273dd5c225SAndreas Gohr    public $toc = array();
280cecf9d5Sandi
293dd5c225SAndreas Gohr    /** @var array A stack of section edit data */
303dd5c225SAndreas Gohr    protected $sectionedits = array();
314bde2196Slisps    var $date_at = '';    // link pages and media against this revision
32c5a8fd96SAndreas Gohr
333dd5c225SAndreas Gohr    /** @var int last section edit id, used by startSectionEdit */
343dd5c225SAndreas Gohr    protected $lastsecid = 0;
350cecf9d5Sandi
363dd5c225SAndreas Gohr    /** @var array the list of headers used to create unique link ids */
373dd5c225SAndreas Gohr    protected $headers = array();
383dd5c225SAndreas Gohr
3916ec3e37SAndreas Gohr    /** @var array a list of footnotes, list starts at 1! */
403dd5c225SAndreas Gohr    protected $footnotes = array();
417764a90aSandi
423dd5c225SAndreas Gohr    /** @var int current section level */
433dd5c225SAndreas Gohr    protected $lastlevel = 0;
443dd5c225SAndreas Gohr    /** @var array section node tracker */
453dd5c225SAndreas Gohr    protected $node = array(0, 0, 0, 0, 0);
463dd5c225SAndreas Gohr
473dd5c225SAndreas Gohr    /** @var string temporary $doc store */
483dd5c225SAndreas Gohr    protected $store = '';
493dd5c225SAndreas Gohr
503dd5c225SAndreas Gohr    /** @var array global counter, for table classes etc. */
513dd5c225SAndreas Gohr    protected $_counter = array(); //
523dd5c225SAndreas Gohr
533dd5c225SAndreas Gohr    /** @var int counts the code and file blocks, used to provide download links */
543dd5c225SAndreas Gohr    protected $_codeblock = 0;
553dd5c225SAndreas Gohr
563dd5c225SAndreas Gohr    /** @var array list of allowed URL schemes */
573dd5c225SAndreas Gohr    protected $schemes = null;
58b5742cedSPierre Spring
5990df9a4dSAdrian Lang    /**
6090df9a4dSAdrian Lang     * Register a new edit section range
6190df9a4dSAdrian Lang     *
6242ea7f44SGerrit Uitslag     * @param string $type   The section type identifier
6342ea7f44SGerrit Uitslag     * @param string $title  The section title
6442ea7f44SGerrit Uitslag     * @param int    $start  The byte position for the edit start
6590df9a4dSAdrian Lang     * @return string  A marker class for the starting HTML element
6642ea7f44SGerrit Uitslag     *
6790df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
6890df9a4dSAdrian Lang     */
693f9e3215SAdrian Lang    public function startSectionEdit($start, $type, $title = null) {
70b04a190dSMichael Hamann        $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title);
71b04a190dSMichael Hamann        return 'sectionedit'.$this->lastsecid;
7290df9a4dSAdrian Lang    }
7390df9a4dSAdrian Lang
7490df9a4dSAdrian Lang    /**
7590df9a4dSAdrian Lang     * Finish an edit section range
7690df9a4dSAdrian Lang     *
7742ea7f44SGerrit Uitslag     * @param int  $end     The byte position for the edit end; null for the rest of the page
7842ea7f44SGerrit Uitslag     *
7990df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
8090df9a4dSAdrian Lang     */
813f9e3215SAdrian Lang    public function finishSectionEdit($end = null) {
8290df9a4dSAdrian Lang        list($id, $start, $type, $title) = array_pop($this->sectionedits);
83d9e36cbeSAdrian Lang        if(!is_null($end) && $end <= $start) {
8400c13053SAdrian Lang            return;
8500c13053SAdrian Lang        }
8640868f2fSAdrian Lang        $this->doc .= "<!-- EDIT$id ".strtoupper($type).' ';
8740868f2fSAdrian Lang        if(!is_null($title)) {
8840868f2fSAdrian Lang            $this->doc .= '"'.str_replace('"', '', $title).'" ';
8940868f2fSAdrian Lang        }
90d9e36cbeSAdrian Lang        $this->doc .= "[$start-".(is_null($end) ? '' : $end).'] -->';
9190df9a4dSAdrian Lang    }
9290df9a4dSAdrian Lang
933dd5c225SAndreas Gohr    /**
943dd5c225SAndreas Gohr     * Returns the format produced by this renderer.
953dd5c225SAndreas Gohr     *
963dd5c225SAndreas Gohr     * @return string always 'xhtml'
973dd5c225SAndreas Gohr     */
985f70445dSAndreas Gohr    function getFormat() {
995f70445dSAndreas Gohr        return 'xhtml';
1005f70445dSAndreas Gohr    }
1015f70445dSAndreas Gohr
1023dd5c225SAndreas Gohr    /**
1033dd5c225SAndreas Gohr     * Initialize the document
1043dd5c225SAndreas Gohr     */
1050cecf9d5Sandi    function document_start() {
106c5a8fd96SAndreas Gohr        //reset some internals
107c5a8fd96SAndreas Gohr        $this->toc     = array();
108c5a8fd96SAndreas Gohr        $this->headers = array();
1090cecf9d5Sandi    }
1100cecf9d5Sandi
1113dd5c225SAndreas Gohr    /**
1123dd5c225SAndreas Gohr     * Finalize the document
1133dd5c225SAndreas Gohr     */
1140cecf9d5Sandi    function document_end() {
11590df9a4dSAdrian Lang        // Finish open section edits.
11690df9a4dSAdrian Lang        while(count($this->sectionedits) > 0) {
11790df9a4dSAdrian Lang            if($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) {
11890df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
11990df9a4dSAdrian Lang                // marker.
12090df9a4dSAdrian Lang                array_pop($this->sectionedits);
12190df9a4dSAdrian Lang            } else {
122d9e36cbeSAdrian Lang                $this->finishSectionEdit();
12390df9a4dSAdrian Lang            }
12490df9a4dSAdrian Lang        }
12590df9a4dSAdrian Lang
1260cecf9d5Sandi        if(count($this->footnotes) > 0) {
127a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
128d74aace9Schris
12916ec3e37SAndreas Gohr            foreach($this->footnotes as $id => $footnote) {
130d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
131d74aace9Schris                if(substr($footnote, 0, 5) != "@@FNT") {
132d74aace9Schris
133d74aace9Schris                    // open the footnote and set the anchor and backlink
134d74aace9Schris                    $this->doc .= '<div class="fn">';
13516cc7ed7SAnika Henke                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">';
13629bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
137d74aace9Schris
138d74aace9Schris                    // get any other footnotes that use the same markup
139d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
140d74aace9Schris
141d74aace9Schris                    if(count($alt)) {
142d74aace9Schris                        foreach($alt as $ref) {
143d74aace9Schris                            // set anchor and backlink for the other footnotes
14416ec3e37SAndreas Gohr                            $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">';
14516ec3e37SAndreas Gohr                            $this->doc .= ($ref).')</a></sup> '.DOKU_LF;
146d74aace9Schris                        }
147d74aace9Schris                    }
148d74aace9Schris
149d74aace9Schris                    // add footnote markup and close this footnote
150a2d649c4Sandi                    $this->doc .= $footnote;
151d74aace9Schris                    $this->doc .= '</div>'.DOKU_LF;
152d74aace9Schris                }
1530cecf9d5Sandi            }
154a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1550cecf9d5Sandi        }
156c5a8fd96SAndreas Gohr
157b8595a66SAndreas Gohr        // Prepare the TOC
158851f2e89SAnika Henke        global $conf;
159851f2e89SAnika Henke        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']) {
160b8595a66SAndreas Gohr            global $TOC;
161b8595a66SAndreas Gohr            $TOC = $this->toc;
1620cecf9d5Sandi        }
1633e55d035SAndreas Gohr
1643e55d035SAndreas Gohr        // make sure there are no empty paragraphs
16527918226Schris        $this->doc = preg_replace('#<p>\s*</p>#', '', $this->doc);
166e41c4da9SAndreas Gohr    }
1670cecf9d5Sandi
1683dd5c225SAndreas Gohr    /**
1693dd5c225SAndreas Gohr     * Add an item to the TOC
1703dd5c225SAndreas Gohr     *
1713dd5c225SAndreas Gohr     * @param string $id       the hash link
1723dd5c225SAndreas Gohr     * @param string $text     the text to display
1733dd5c225SAndreas Gohr     * @param int    $level    the nesting level
1743dd5c225SAndreas Gohr     */
175e7856beaSchris    function toc_additem($id, $text, $level) {
176af587fa8Sandi        global $conf;
177af587fa8Sandi
178c5a8fd96SAndreas Gohr        //handle TOC
179c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) {
1807d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1);
181c5a8fd96SAndreas Gohr        }
182e7856beaSchris    }
183e7856beaSchris
1843dd5c225SAndreas Gohr    /**
1853dd5c225SAndreas Gohr     * Render a heading
1863dd5c225SAndreas Gohr     *
1873dd5c225SAndreas Gohr     * @param string $text  the text to display
1883dd5c225SAndreas Gohr     * @param int    $level header level
1893dd5c225SAndreas Gohr     * @param int    $pos   byte position in the original source
1903dd5c225SAndreas Gohr     */
191e7856beaSchris    function header($text, $level, $pos) {
19290df9a4dSAdrian Lang        global $conf;
19390df9a4dSAdrian Lang
194bdd8111bSAndreas Gohr        if(!$text) return; //skip empty headlines
195e7856beaSchris
196e7856beaSchris        $hid = $this->_headerToLink($text, true);
197e7856beaSchris
198e7856beaSchris        //only add items within configured levels
199e7856beaSchris        $this->toc_additem($hid, $text, $level);
200c5a8fd96SAndreas Gohr
20191459163SAnika Henke        // adjust $node to reflect hierarchy of levels
20291459163SAnika Henke        $this->node[$level - 1]++;
20391459163SAnika Henke        if($level < $this->lastlevel) {
20491459163SAnika Henke            for($i = 0; $i < $this->lastlevel - $level; $i++) {
20591459163SAnika Henke                $this->node[$this->lastlevel - $i - 1] = 0;
20691459163SAnika Henke            }
20791459163SAnika Henke        }
20891459163SAnika Henke        $this->lastlevel = $level;
20991459163SAnika Henke
21090df9a4dSAdrian Lang        if($level <= $conf['maxseclevel'] &&
21190df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
2123dd5c225SAndreas Gohr            $this->sectionedits[count($this->sectionedits) - 1][2] === 'section'
2133dd5c225SAndreas Gohr        ) {
2146c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
21590df9a4dSAdrian Lang        }
21690df9a4dSAdrian Lang
217c5a8fd96SAndreas Gohr        // write the header
21890df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
21990df9a4dSAdrian Lang        if($level <= $conf['maxseclevel']) {
22090df9a4dSAdrian Lang            $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text).'"';
22190df9a4dSAdrian Lang        }
22216cc7ed7SAnika Henke        $this->doc .= ' id="'.$hid.'">';
223a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
22416cc7ed7SAnika Henke        $this->doc .= "</h$level>".DOKU_LF;
2250cecf9d5Sandi    }
2260cecf9d5Sandi
2273dd5c225SAndreas Gohr    /**
2283dd5c225SAndreas Gohr     * Open a new section
2293dd5c225SAndreas Gohr     *
2303dd5c225SAndreas Gohr     * @param int $level section level (as determined by the previous header)
2313dd5c225SAndreas Gohr     */
2320cecf9d5Sandi    function section_open($level) {
2339864e7b1SAdrian Lang        $this->doc .= '<div class="level'.$level.'">'.DOKU_LF;
2340cecf9d5Sandi    }
2350cecf9d5Sandi
2363dd5c225SAndreas Gohr    /**
2373dd5c225SAndreas Gohr     * Close the current section
2383dd5c225SAndreas Gohr     */
2390cecf9d5Sandi    function section_close() {
240a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
2410cecf9d5Sandi    }
2420cecf9d5Sandi
2433dd5c225SAndreas Gohr    /**
2443dd5c225SAndreas Gohr     * Render plain text data
2453dd5c225SAndreas Gohr     *
2463dd5c225SAndreas Gohr     * @param $text
2473dd5c225SAndreas Gohr     */
2480cecf9d5Sandi    function cdata($text) {
249a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
2500cecf9d5Sandi    }
2510cecf9d5Sandi
2523dd5c225SAndreas Gohr    /**
2533dd5c225SAndreas Gohr     * Open a paragraph
2543dd5c225SAndreas Gohr     */
2550cecf9d5Sandi    function p_open() {
25659869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
2570cecf9d5Sandi    }
2580cecf9d5Sandi
2593dd5c225SAndreas Gohr    /**
2603dd5c225SAndreas Gohr     * Close a paragraph
2613dd5c225SAndreas Gohr     */
2620cecf9d5Sandi    function p_close() {
26359869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2640cecf9d5Sandi    }
2650cecf9d5Sandi
2663dd5c225SAndreas Gohr    /**
2673dd5c225SAndreas Gohr     * Create a line break
2683dd5c225SAndreas Gohr     */
2690cecf9d5Sandi    function linebreak() {
270a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2710cecf9d5Sandi    }
2720cecf9d5Sandi
2733dd5c225SAndreas Gohr    /**
2743dd5c225SAndreas Gohr     * Create a horizontal line
2753dd5c225SAndreas Gohr     */
2760cecf9d5Sandi    function hr() {
2774beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
2780cecf9d5Sandi    }
2790cecf9d5Sandi
2803dd5c225SAndreas Gohr    /**
2813dd5c225SAndreas Gohr     * Start strong (bold) formatting
2823dd5c225SAndreas Gohr     */
2830cecf9d5Sandi    function strong_open() {
284a2d649c4Sandi        $this->doc .= '<strong>';
2850cecf9d5Sandi    }
2860cecf9d5Sandi
2873dd5c225SAndreas Gohr    /**
2883dd5c225SAndreas Gohr     * Stop strong (bold) formatting
2893dd5c225SAndreas Gohr     */
2900cecf9d5Sandi    function strong_close() {
291a2d649c4Sandi        $this->doc .= '</strong>';
2920cecf9d5Sandi    }
2930cecf9d5Sandi
2943dd5c225SAndreas Gohr    /**
2953dd5c225SAndreas Gohr     * Start emphasis (italics) formatting
2963dd5c225SAndreas Gohr     */
2970cecf9d5Sandi    function emphasis_open() {
298a2d649c4Sandi        $this->doc .= '<em>';
2990cecf9d5Sandi    }
3000cecf9d5Sandi
3013dd5c225SAndreas Gohr    /**
3023dd5c225SAndreas Gohr     * Stop emphasis (italics) formatting
3033dd5c225SAndreas Gohr     */
3040cecf9d5Sandi    function emphasis_close() {
305a2d649c4Sandi        $this->doc .= '</em>';
3060cecf9d5Sandi    }
3070cecf9d5Sandi
3083dd5c225SAndreas Gohr    /**
3093dd5c225SAndreas Gohr     * Start underline formatting
3103dd5c225SAndreas Gohr     */
3110cecf9d5Sandi    function underline_open() {
31202e51121SAnika Henke        $this->doc .= '<em class="u">';
3130cecf9d5Sandi    }
3140cecf9d5Sandi
3153dd5c225SAndreas Gohr    /**
3163dd5c225SAndreas Gohr     * Stop underline formatting
3173dd5c225SAndreas Gohr     */
3180cecf9d5Sandi    function underline_close() {
31902e51121SAnika Henke        $this->doc .= '</em>';
3200cecf9d5Sandi    }
3210cecf9d5Sandi
3223dd5c225SAndreas Gohr    /**
3233dd5c225SAndreas Gohr     * Start monospace formatting
3243dd5c225SAndreas Gohr     */
3250cecf9d5Sandi    function monospace_open() {
326a2d649c4Sandi        $this->doc .= '<code>';
3270cecf9d5Sandi    }
3280cecf9d5Sandi
3293dd5c225SAndreas Gohr    /**
3303dd5c225SAndreas Gohr     * Stop monospace formatting
3313dd5c225SAndreas Gohr     */
3320cecf9d5Sandi    function monospace_close() {
333a2d649c4Sandi        $this->doc .= '</code>';
3340cecf9d5Sandi    }
3350cecf9d5Sandi
3363dd5c225SAndreas Gohr    /**
3373dd5c225SAndreas Gohr     * Start a subscript
3383dd5c225SAndreas Gohr     */
3390cecf9d5Sandi    function subscript_open() {
340a2d649c4Sandi        $this->doc .= '<sub>';
3410cecf9d5Sandi    }
3420cecf9d5Sandi
3433dd5c225SAndreas Gohr    /**
3443dd5c225SAndreas Gohr     * Stop a subscript
3453dd5c225SAndreas Gohr     */
3460cecf9d5Sandi    function subscript_close() {
347a2d649c4Sandi        $this->doc .= '</sub>';
3480cecf9d5Sandi    }
3490cecf9d5Sandi
3503dd5c225SAndreas Gohr    /**
3513dd5c225SAndreas Gohr     * Start a superscript
3523dd5c225SAndreas Gohr     */
3530cecf9d5Sandi    function superscript_open() {
354a2d649c4Sandi        $this->doc .= '<sup>';
3550cecf9d5Sandi    }
3560cecf9d5Sandi
3573dd5c225SAndreas Gohr    /**
3583dd5c225SAndreas Gohr     * Stop a superscript
3593dd5c225SAndreas Gohr     */
3600cecf9d5Sandi    function superscript_close() {
361a2d649c4Sandi        $this->doc .= '</sup>';
3620cecf9d5Sandi    }
3630cecf9d5Sandi
3643dd5c225SAndreas Gohr    /**
3653dd5c225SAndreas Gohr     * Start deleted (strike-through) formatting
3663dd5c225SAndreas Gohr     */
3670cecf9d5Sandi    function deleted_open() {
368a2d649c4Sandi        $this->doc .= '<del>';
3690cecf9d5Sandi    }
3700cecf9d5Sandi
3713dd5c225SAndreas Gohr    /**
3723dd5c225SAndreas Gohr     * Stop deleted (strike-through) formatting
3733dd5c225SAndreas Gohr     */
3740cecf9d5Sandi    function deleted_close() {
375a2d649c4Sandi        $this->doc .= '</del>';
3760cecf9d5Sandi    }
3770cecf9d5Sandi
3783fd0b676Sandi    /**
3793fd0b676Sandi     * Callback for footnote start syntax
3803fd0b676Sandi     *
3813fd0b676Sandi     * All following content will go to the footnote instead of
382d74aace9Schris     * the document. To achieve this the previous rendered content
3833fd0b676Sandi     * is moved to $store and $doc is cleared
3843fd0b676Sandi     *
3853fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3863fd0b676Sandi     */
3870cecf9d5Sandi    function footnote_open() {
3887764a90aSandi
3897764a90aSandi        // move current content to store and record footnote
3907764a90aSandi        $this->store = $this->doc;
3917764a90aSandi        $this->doc   = '';
3920cecf9d5Sandi    }
3930cecf9d5Sandi
3943fd0b676Sandi    /**
3953fd0b676Sandi     * Callback for footnote end syntax
3963fd0b676Sandi     *
3973fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
3983fd0b676Sandi     * content is restored from $store again
3993fd0b676Sandi     *
4003fd0b676Sandi     * @author Andreas Gohr
4013fd0b676Sandi     */
4020cecf9d5Sandi    function footnote_close() {
40316ec3e37SAndreas Gohr        /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */
40416ec3e37SAndreas Gohr        static $fnid = 0;
40516ec3e37SAndreas Gohr        // assign new footnote id (we start at 1)
40616ec3e37SAndreas Gohr        $fnid++;
4077764a90aSandi
408d74aace9Schris        // recover footnote into the stack and restore old content
409d74aace9Schris        $footnote    = $this->doc;
4107764a90aSandi        $this->doc   = $this->store;
4117764a90aSandi        $this->store = '';
412d74aace9Schris
413d74aace9Schris        // check to see if this footnote has been seen before
414d74aace9Schris        $i = array_search($footnote, $this->footnotes);
415d74aace9Schris
416d74aace9Schris        if($i === false) {
417d74aace9Schris            // its a new footnote, add it to the $footnotes array
41816ec3e37SAndreas Gohr            $this->footnotes[$fnid] = $footnote;
419d74aace9Schris        } else {
42016ec3e37SAndreas Gohr            // seen this one before, save a placeholder
42116ec3e37SAndreas Gohr            $this->footnotes[$fnid] = "@@FNT".($i);
422d74aace9Schris        }
423d74aace9Schris
4246b379cbfSAndreas Gohr        // output the footnote reference and link
42516ec3e37SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>';
4260cecf9d5Sandi    }
4270cecf9d5Sandi
4283dd5c225SAndreas Gohr    /**
4293dd5c225SAndreas Gohr     * Open an unordered list
4303dd5c225SAndreas Gohr     */
4310cecf9d5Sandi    function listu_open() {
432a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
4330cecf9d5Sandi    }
4340cecf9d5Sandi
4353dd5c225SAndreas Gohr    /**
4363dd5c225SAndreas Gohr     * Close an unordered list
4373dd5c225SAndreas Gohr     */
4380cecf9d5Sandi    function listu_close() {
439a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
4400cecf9d5Sandi    }
4410cecf9d5Sandi
4423dd5c225SAndreas Gohr    /**
4433dd5c225SAndreas Gohr     * Open an ordered list
4443dd5c225SAndreas Gohr     */
4450cecf9d5Sandi    function listo_open() {
446a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
4470cecf9d5Sandi    }
4480cecf9d5Sandi
4493dd5c225SAndreas Gohr    /**
4503dd5c225SAndreas Gohr     * Close an ordered list
4513dd5c225SAndreas Gohr     */
4520cecf9d5Sandi    function listo_close() {
453a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
4540cecf9d5Sandi    }
4550cecf9d5Sandi
4563dd5c225SAndreas Gohr    /**
4573dd5c225SAndreas Gohr     * Open a list item
4583dd5c225SAndreas Gohr     *
4593dd5c225SAndreas Gohr     * @param int $level the nesting level
460e3a24861SChristopher Smith     * @param bool $node true when a node; false when a leaf
4613dd5c225SAndreas Gohr     */
462e3a24861SChristopher Smith    function listitem_open($level, $node=false) {
463e3a24861SChristopher Smith        $branching = $node ? ' node' : '';
464e3a24861SChristopher Smith        $this->doc .= '<li class="level'.$level.$branching.'">';
4650cecf9d5Sandi    }
4660cecf9d5Sandi
4673dd5c225SAndreas Gohr    /**
4683dd5c225SAndreas Gohr     * Close a list item
4693dd5c225SAndreas Gohr     */
4700cecf9d5Sandi    function listitem_close() {
471a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
4720cecf9d5Sandi    }
4730cecf9d5Sandi
4743dd5c225SAndreas Gohr    /**
4753dd5c225SAndreas Gohr     * Start the content of a list item
4763dd5c225SAndreas Gohr     */
4770cecf9d5Sandi    function listcontent_open() {
47890db23d7Schris        $this->doc .= '<div class="li">';
4790cecf9d5Sandi    }
4800cecf9d5Sandi
4813dd5c225SAndreas Gohr    /**
4823dd5c225SAndreas Gohr     * Stop the content of a list item
4833dd5c225SAndreas Gohr     */
4840cecf9d5Sandi    function listcontent_close() {
48559869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
4860cecf9d5Sandi    }
4870cecf9d5Sandi
4883dd5c225SAndreas Gohr    /**
4893dd5c225SAndreas Gohr     * Output unformatted $text
4903dd5c225SAndreas Gohr     *
4913dd5c225SAndreas Gohr     * Defaults to $this->cdata()
4923dd5c225SAndreas Gohr     *
4933dd5c225SAndreas Gohr     * @param string $text
4943dd5c225SAndreas Gohr     */
4950cecf9d5Sandi    function unformatted($text) {
496a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
4970cecf9d5Sandi    }
4980cecf9d5Sandi
4990cecf9d5Sandi    /**
5003fd0b676Sandi     * Execute PHP code if allowed
5013fd0b676Sandi     *
502d9764001SMichael Hamann     * @param  string $text      PHP code that is either executed or printed
5035d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['phpok'] is okff
5045d568b99SChris Smith     *
5053fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5060cecf9d5Sandi     */
5075d568b99SChris Smith    function php($text, $wrapper = 'code') {
50835a56260SChris Smith        global $conf;
50935a56260SChris Smith
510d86d5af0SChris Smith        if($conf['phpok']) {
511bad0b545Sandi            ob_start();
5124de671bcSandi            eval($text);
5133fd0b676Sandi            $this->doc .= ob_get_contents();
514bad0b545Sandi            ob_end_clean();
515d86d5af0SChris Smith        } else {
5165d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
517d86d5af0SChris Smith        }
5180cecf9d5Sandi    }
5190cecf9d5Sandi
5203dd5c225SAndreas Gohr    /**
5213dd5c225SAndreas Gohr     * Output block level PHP code
5223dd5c225SAndreas Gohr     *
5233dd5c225SAndreas Gohr     * If $conf['phpok'] is true this should evaluate the given code and append the result
5243dd5c225SAndreas Gohr     * to $doc
5253dd5c225SAndreas Gohr     *
5263dd5c225SAndreas Gohr     * @param string $text The PHP code
5273dd5c225SAndreas Gohr     */
52807f89c3cSAnika Henke    function phpblock($text) {
5295d568b99SChris Smith        $this->php($text, 'pre');
53007f89c3cSAnika Henke    }
53107f89c3cSAnika Henke
5320cecf9d5Sandi    /**
5333fd0b676Sandi     * Insert HTML if allowed
5343fd0b676Sandi     *
535d9764001SMichael Hamann     * @param  string $text      html text
5365d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['htmlok'] is okff
5375d568b99SChris Smith     *
5383fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5390cecf9d5Sandi     */
5405d568b99SChris Smith    function html($text, $wrapper = 'code') {
54135a56260SChris Smith        global $conf;
54235a56260SChris Smith
543d86d5af0SChris Smith        if($conf['htmlok']) {
544a2d649c4Sandi            $this->doc .= $text;
545d86d5af0SChris Smith        } else {
5465d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
547d86d5af0SChris Smith        }
5484de671bcSandi    }
5490cecf9d5Sandi
5503dd5c225SAndreas Gohr    /**
5513dd5c225SAndreas Gohr     * Output raw block-level HTML
5523dd5c225SAndreas Gohr     *
5533dd5c225SAndreas Gohr     * If $conf['htmlok'] is true this should add the code as is to $doc
5543dd5c225SAndreas Gohr     *
5553dd5c225SAndreas Gohr     * @param string $text The HTML
5563dd5c225SAndreas Gohr     */
55707f89c3cSAnika Henke    function htmlblock($text) {
5585d568b99SChris Smith        $this->html($text, 'pre');
55907f89c3cSAnika Henke    }
56007f89c3cSAnika Henke
5613dd5c225SAndreas Gohr    /**
5623dd5c225SAndreas Gohr     * Start a block quote
5633dd5c225SAndreas Gohr     */
5640cecf9d5Sandi    function quote_open() {
56596331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
5660cecf9d5Sandi    }
5670cecf9d5Sandi
5683dd5c225SAndreas Gohr    /**
5693dd5c225SAndreas Gohr     * Stop a block quote
5703dd5c225SAndreas Gohr     */
5710cecf9d5Sandi    function quote_close() {
57296331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
5730cecf9d5Sandi    }
5740cecf9d5Sandi
5753dd5c225SAndreas Gohr    /**
5763dd5c225SAndreas Gohr     * Output preformatted text
5773dd5c225SAndreas Gohr     *
5783dd5c225SAndreas Gohr     * @param string $text
5793dd5c225SAndreas Gohr     */
5803d491f75SAndreas Gohr    function preformatted($text) {
581c9250713SAnika Henke        $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.DOKU_LF;
5823d491f75SAndreas Gohr    }
5833d491f75SAndreas Gohr
5843dd5c225SAndreas Gohr    /**
5853dd5c225SAndreas Gohr     * Display text as file content, optionally syntax highlighted
5863dd5c225SAndreas Gohr     *
5873dd5c225SAndreas Gohr     * @param string $text     text to show
5883dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
5893dd5c225SAndreas Gohr     * @param string $filename file path label
5903dd5c225SAndreas Gohr     */
5913d491f75SAndreas Gohr    function file($text, $language = null, $filename = null) {
5923d491f75SAndreas Gohr        $this->_highlight('file', $text, $language, $filename);
5933d491f75SAndreas Gohr    }
5943d491f75SAndreas Gohr
5953dd5c225SAndreas Gohr    /**
5963dd5c225SAndreas Gohr     * Display text as code content, optionally syntax highlighted
5973dd5c225SAndreas Gohr     *
5983dd5c225SAndreas Gohr     * @param string $text     text to show
5993dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6003dd5c225SAndreas Gohr     * @param string $filename file path label
6013dd5c225SAndreas Gohr     */
6023d491f75SAndreas Gohr    function code($text, $language = null, $filename = null) {
6033d491f75SAndreas Gohr        $this->_highlight('code', $text, $language, $filename);
6043d491f75SAndreas Gohr    }
6053d491f75SAndreas Gohr
6060cecf9d5Sandi    /**
6073d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
6083fd0b676Sandi     *
6093fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
6103dd5c225SAndreas Gohr     * @param string $type     code|file
6113dd5c225SAndreas Gohr     * @param string $text     text to show
6123dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6133dd5c225SAndreas Gohr     * @param string $filename file path label
6140cecf9d5Sandi     */
6153d491f75SAndreas Gohr    function _highlight($type, $text, $language = null, $filename = null) {
6163d491f75SAndreas Gohr        global $ID;
6173d491f75SAndreas Gohr        global $lang;
6183d491f75SAndreas Gohr
6193d491f75SAndreas Gohr        if($filename) {
620190c56e8SAndreas Gohr            // add icon
62127bf7924STom N Harris            list($ext) = mimetype($filename, false);
622190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
623190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
624190c56e8SAndreas Gohr
6253d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
626190c56e8SAndreas Gohr            $this->doc .= '<dt><a href="'.exportlink($ID, 'code', array('codeblock' => $this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
6273d491f75SAndreas Gohr            $this->doc .= hsc($filename);
6283d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
6293d491f75SAndreas Gohr        }
6300cecf9d5Sandi
631d43aac1cSGina Haeussge        if($text{0} == "\n") {
632d43aac1cSGina Haeussge            $text = substr($text, 1);
633d43aac1cSGina Haeussge        }
634d43aac1cSGina Haeussge        if(substr($text, -1) == "\n") {
635d43aac1cSGina Haeussge            $text = substr($text, 0, -1);
636d43aac1cSGina Haeussge        }
637d43aac1cSGina Haeussge
6380cecf9d5Sandi        if(is_null($language)) {
6393d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
6400cecf9d5Sandi        } else {
6413d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
6423d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
6433d491f75SAndreas Gohr
6443d491f75SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;
6450cecf9d5Sandi        }
6463d491f75SAndreas Gohr
6473d491f75SAndreas Gohr        if($filename) {
6483d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
6493d491f75SAndreas Gohr        }
6503d491f75SAndreas Gohr
6513d491f75SAndreas Gohr        $this->_codeblock++;
6520cecf9d5Sandi    }
6530cecf9d5Sandi
6543dd5c225SAndreas Gohr    /**
6553dd5c225SAndreas Gohr     * Format an acronym
6563dd5c225SAndreas Gohr     *
6573dd5c225SAndreas Gohr     * Uses $this->acronyms
6583dd5c225SAndreas Gohr     *
6593dd5c225SAndreas Gohr     * @param string $acronym
6603dd5c225SAndreas Gohr     */
6610cecf9d5Sandi    function acronym($acronym) {
6620cecf9d5Sandi
6630cecf9d5Sandi        if(array_key_exists($acronym, $this->acronyms)) {
6640cecf9d5Sandi
665433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
6660cecf9d5Sandi
667940db3a3SAnika Henke            $this->doc .= '<abbr title="'.$title
668940db3a3SAnika Henke                .'">'.$this->_xmlEntities($acronym).'</abbr>';
6690cecf9d5Sandi
6700cecf9d5Sandi        } else {
671a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
6720cecf9d5Sandi        }
6730cecf9d5Sandi    }
6740cecf9d5Sandi
6753dd5c225SAndreas Gohr    /**
6763dd5c225SAndreas Gohr     * Format a smiley
6773dd5c225SAndreas Gohr     *
6783dd5c225SAndreas Gohr     * Uses $this->smiley
6793dd5c225SAndreas Gohr     *
6803dd5c225SAndreas Gohr     * @param string $smiley
6813dd5c225SAndreas Gohr     */
6820cecf9d5Sandi    function smiley($smiley) {
6830cecf9d5Sandi        if(array_key_exists($smiley, $this->smileys)) {
684f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
6858e38227fSAnika Henke                '" class="icon" alt="'.
686433bef32Sandi                $this->_xmlEntities($smiley).'" />';
6870cecf9d5Sandi        } else {
688a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
6890cecf9d5Sandi        }
6900cecf9d5Sandi    }
6910cecf9d5Sandi
6923dd5c225SAndreas Gohr    /**
6933dd5c225SAndreas Gohr     * Format an entity
6943dd5c225SAndreas Gohr     *
6953dd5c225SAndreas Gohr     * Entities are basically small text replacements
6963dd5c225SAndreas Gohr     *
6973dd5c225SAndreas Gohr     * Uses $this->entities
6983dd5c225SAndreas Gohr     *
6993dd5c225SAndreas Gohr     * @param string $entity
7004de671bcSandi     */
7010cecf9d5Sandi    function entity($entity) {
7020cecf9d5Sandi        if(array_key_exists($entity, $this->entities)) {
703a2d649c4Sandi            $this->doc .= $this->entities[$entity];
7040cecf9d5Sandi        } else {
705a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
7060cecf9d5Sandi        }
7070cecf9d5Sandi    }
7080cecf9d5Sandi
7093dd5c225SAndreas Gohr    /**
7103dd5c225SAndreas Gohr     * Typographically format a multiply sign
7113dd5c225SAndreas Gohr     *
7123dd5c225SAndreas Gohr     * Example: ($x=640, $y=480) should result in "640×480"
7133dd5c225SAndreas Gohr     *
7143dd5c225SAndreas Gohr     * @param string|int $x first value
7153dd5c225SAndreas Gohr     * @param string|int $y second value
7163dd5c225SAndreas Gohr     */
7170cecf9d5Sandi    function multiplyentity($x, $y) {
718a2d649c4Sandi        $this->doc .= "$x&times;$y";
7190cecf9d5Sandi    }
7200cecf9d5Sandi
7213dd5c225SAndreas Gohr    /**
7223dd5c225SAndreas Gohr     * Render an opening single quote char (language specific)
7233dd5c225SAndreas Gohr     */
7240cecf9d5Sandi    function singlequoteopening() {
72571b40da2SAnika Henke        global $lang;
72671b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
7270cecf9d5Sandi    }
7280cecf9d5Sandi
7293dd5c225SAndreas Gohr    /**
7303dd5c225SAndreas Gohr     * Render a closing single quote char (language specific)
7313dd5c225SAndreas Gohr     */
7320cecf9d5Sandi    function singlequoteclosing() {
73371b40da2SAnika Henke        global $lang;
73471b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
7350cecf9d5Sandi    }
7360cecf9d5Sandi
7373dd5c225SAndreas Gohr    /**
7383dd5c225SAndreas Gohr     * Render an apostrophe char (language specific)
7393dd5c225SAndreas Gohr     */
74057d757d1SAndreas Gohr    function apostrophe() {
74157d757d1SAndreas Gohr        global $lang;
742a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
74357d757d1SAndreas Gohr    }
74457d757d1SAndreas Gohr
7453dd5c225SAndreas Gohr    /**
7463dd5c225SAndreas Gohr     * Render an opening double quote char (language specific)
7473dd5c225SAndreas Gohr     */
7480cecf9d5Sandi    function doublequoteopening() {
74971b40da2SAnika Henke        global $lang;
75071b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
7510cecf9d5Sandi    }
7520cecf9d5Sandi
7533dd5c225SAndreas Gohr    /**
7543dd5c225SAndreas Gohr     * Render an closinging double quote char (language specific)
7553dd5c225SAndreas Gohr     */
7560cecf9d5Sandi    function doublequoteclosing() {
75771b40da2SAnika Henke        global $lang;
75871b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
7590cecf9d5Sandi    }
7600cecf9d5Sandi
7610cecf9d5Sandi    /**
7623dd5c225SAndreas Gohr     * Render a CamelCase link
7633dd5c225SAndreas Gohr     *
7643dd5c225SAndreas Gohr     * @param string $link       The link name
765122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
7663dd5c225SAndreas Gohr     * @see http://en.wikipedia.org/wiki/CamelCase
7670cecf9d5Sandi     */
768122f2d46SAndreas Böhler    function camelcaselink($link, $returnonly = false) {
769122f2d46SAndreas Böhler        if($returnonly) {
770122f2d46SAndreas Böhler          return $this->internallink($link, $link, null, true);
771122f2d46SAndreas Böhler        } else {
77211d0aa47Sandi          $this->internallink($link, $link);
7730cecf9d5Sandi        }
774122f2d46SAndreas Böhler    }
7750cecf9d5Sandi
7763dd5c225SAndreas Gohr    /**
7773dd5c225SAndreas Gohr     * Render a page local link
7783dd5c225SAndreas Gohr     *
7793dd5c225SAndreas Gohr     * @param string $hash       hash link identifier
7803dd5c225SAndreas Gohr     * @param string $name       name for the link
781122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
7823dd5c225SAndreas Gohr     */
783122f2d46SAndreas Böhler    function locallink($hash, $name = null, $returnonly = false) {
7840b7c14c2Sandi        global $ID;
7850b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
7860b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
787e260f93bSAnika Henke        $title = $ID.' ↵';
788122f2d46SAndreas Böhler
789122f2d46SAndreas Böhler        $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
790122f2d46SAndreas Böhler        $doc .= $name;
791122f2d46SAndreas Böhler        $doc .= '</a>';
792122f2d46SAndreas Böhler
793122f2d46SAndreas Böhler        if($returnonly) {
794122f2d46SAndreas Böhler          return $doc;
795122f2d46SAndreas Böhler        } else {
796122f2d46SAndreas Böhler          $this->doc .= $doc;
797122f2d46SAndreas Böhler        }
7980b7c14c2Sandi    }
7990b7c14c2Sandi
800cffcc403Sandi    /**
8013fd0b676Sandi     * Render an internal Wiki Link
8023fd0b676Sandi     *
803fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
804cffcc403Sandi     * elsewhere - no need to implement them in other renderers
8053fd0b676Sandi     *
8063dd5c225SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
807f23eef27SGerrit Uitslag     * @param string      $id         pageid
808f23eef27SGerrit Uitslag     * @param string|null $name       link name
809f23eef27SGerrit Uitslag     * @param string|null $search     adds search url param
810f23eef27SGerrit Uitslag     * @param bool        $returnonly whether to return html or write to doc attribute
811f23eef27SGerrit Uitslag     * @param string      $linktype   type to set use of headings
812f23eef27SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
813cffcc403Sandi     */
8140ea51e63SMatt Perry    function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
815ba11bd29Sandi        global $conf;
81637e34a5eSandi        global $ID;
817c4dda6afSAnika Henke        global $INFO;
81844653a53SAdrian Lang
8193d5e07d9SAdrian Lang        $params = '';
8203d5e07d9SAdrian Lang        $parts  = explode('?', $id, 2);
8213d5e07d9SAdrian Lang        if(count($parts) === 2) {
8223d5e07d9SAdrian Lang            $id     = $parts[0];
8233d5e07d9SAdrian Lang            $params = $parts[1];
82444653a53SAdrian Lang        }
82544653a53SAdrian Lang
826fda14ffcSIzidor Matušov        // For empty $id we need to know the current $ID
827fda14ffcSIzidor Matušov        // We need this check because _simpleTitle needs
828fda14ffcSIzidor Matušov        // correct $id and resolve_pageid() use cleanID($id)
829fda14ffcSIzidor Matušov        // (some things could be lost)
830fda14ffcSIzidor Matušov        if($id === '') {
831fda14ffcSIzidor Matušov            $id = $ID;
832fda14ffcSIzidor Matušov        }
833fda14ffcSIzidor Matušov
8340339c872Sjan        // default name is based on $id as given
8350339c872Sjan        $default = $this->_simpleTitle($id);
836ad32e47eSAndreas Gohr
8370339c872Sjan        // now first resolve and clean up the $id
83890bee600Slisps        resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true);
839fda14ffcSIzidor Matušov
84059bc3b48SGerrit Uitslag        $link = array();
841fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
8420e1c636eSandi        if(!$isImage) {
8430e1c636eSandi            if($exists) {
844ba11bd29Sandi                $class = 'wikilink1';
8450cecf9d5Sandi            } else {
846ba11bd29Sandi                $class       = 'wikilink2';
84744a6b4c7SAndreas Gohr                $link['rel'] = 'nofollow';
8480cecf9d5Sandi            }
8490cecf9d5Sandi        } else {
850ba11bd29Sandi            $class = 'media';
8510cecf9d5Sandi        }
8520cecf9d5Sandi
853a1685bedSandi        //keep hash anchor
8546d2af55dSChristopher Smith        @list($id, $hash) = explode('#', $id, 2);
855943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
856a1685bedSandi
857ba11bd29Sandi        //prepare for formating
858ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
859ba11bd29Sandi        $link['style']  = '';
860ba11bd29Sandi        $link['pre']    = '';
861ba11bd29Sandi        $link['suf']    = '';
86240eb54bbSjan        // highlight link to current page
863c4dda6afSAnika Henke        if($id == $INFO['id']) {
86492795d04Sandi            $link['pre'] = '<span class="curid">';
86592795d04Sandi            $link['suf'] = '</span>';
86640eb54bbSjan        }
8675e163278SAndreas Gohr        $link['more']   = '';
868ba11bd29Sandi        $link['class']  = $class;
8695c2eed9aSlisps        if($this->date_at) {
8705c2eed9aSlisps            $params['at'] = $this->date_at;
8715c2eed9aSlisps        }
87244653a53SAdrian Lang        $link['url']    = wl($id, $params);
873ba11bd29Sandi        $link['name']   = $name;
874ba11bd29Sandi        $link['title']  = $id;
875723d78dbSandi        //add search string
876723d78dbSandi        if($search) {
877546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&amp;';
878546d3a99SAndreas Gohr            if(is_array($search)) {
879546d3a99SAndreas Gohr                $search = array_map('rawurlencode', $search);
880546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=', $search);
881546d3a99SAndreas Gohr            } else {
882546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
883546d3a99SAndreas Gohr            }
884723d78dbSandi        }
885723d78dbSandi
886a1685bedSandi        //keep hash
887a1685bedSandi        if($hash) $link['url'] .= '#'.$hash;
888a1685bedSandi
889ba11bd29Sandi        //output formatted
890cffcc403Sandi        if($returnonly) {
891cffcc403Sandi            return $this->_formatLink($link);
892cffcc403Sandi        } else {
893a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
8940cecf9d5Sandi        }
895cffcc403Sandi    }
8960cecf9d5Sandi
8973dd5c225SAndreas Gohr    /**
8983dd5c225SAndreas Gohr     * Render an external link
8993dd5c225SAndreas Gohr     *
9003dd5c225SAndreas Gohr     * @param string       $url        full URL with scheme
9013dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
902122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
9033dd5c225SAndreas Gohr     */
904122f2d46SAndreas Böhler    function externallink($url, $name = null, $returnonly = false) {
905b625487dSandi        global $conf;
9060cecf9d5Sandi
907433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
9086f0c5dbfSandi
909b52b1596SAndreas Gohr        // url might be an attack vector, only allow registered protocols
910b52b1596SAndreas Gohr        if(is_null($this->schemes)) $this->schemes = getSchemes();
911b52b1596SAndreas Gohr        list($scheme) = explode('://', $url);
912b52b1596SAndreas Gohr        $scheme = strtolower($scheme);
913b52b1596SAndreas Gohr        if(!in_array($scheme, $this->schemes)) $url = '';
914b52b1596SAndreas Gohr
915b52b1596SAndreas Gohr        // is there still an URL?
916b52b1596SAndreas Gohr        if(!$url) {
917*49cef4fdSAndreas Böhler            if($returnonly) {
918*49cef4fdSAndreas Böhler                return $name;
919*49cef4fdSAndreas Böhler            } else {
920b52b1596SAndreas Gohr                $this->doc .= $name;
921*49cef4fdSAndreas Böhler            }
922b52b1596SAndreas Gohr            return;
923b52b1596SAndreas Gohr        }
924b52b1596SAndreas Gohr
925b52b1596SAndreas Gohr        // set class
9260cecf9d5Sandi        if(!$isImage) {
927b625487dSandi            $class = 'urlextern';
9280cecf9d5Sandi        } else {
929b625487dSandi            $class = 'media';
9300cecf9d5Sandi        }
9310cecf9d5Sandi
932b625487dSandi        //prepare for formating
93359bc3b48SGerrit Uitslag        $link = array();
934b625487dSandi        $link['target'] = $conf['target']['extern'];
935b625487dSandi        $link['style']  = '';
936b625487dSandi        $link['pre']    = '';
937b625487dSandi        $link['suf']    = '';
9385e163278SAndreas Gohr        $link['more']   = '';
939b625487dSandi        $link['class']  = $class;
940b625487dSandi        $link['url']    = $url;
941e1c10e4dSchris
942b625487dSandi        $link['name']  = $name;
943433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
944b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
9450cecf9d5Sandi
946b625487dSandi        //output formatted
947122f2d46SAndreas Böhler        if($returnonly) {
948122f2d46SAndreas Böhler            return $this->_formatLink($link);
949122f2d46SAndreas Böhler        } else {
950a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
9510cecf9d5Sandi        }
952122f2d46SAndreas Böhler    }
9530cecf9d5Sandi
9540cecf9d5Sandi    /**
9553dd5c225SAndreas Gohr     * Render an interwiki link
9563dd5c225SAndreas Gohr     *
9573dd5c225SAndreas Gohr     * You may want to use $this->_resolveInterWiki() here
9583dd5c225SAndreas Gohr     *
9593dd5c225SAndreas Gohr     * @param string       $match      original link - probably not much use
9603dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
9613dd5c225SAndreas Gohr     * @param string       $wikiName   indentifier (shortcut) for the remote wiki
9623dd5c225SAndreas Gohr     * @param string       $wikiUri    the fragment parsed from the original link
963122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
9640cecf9d5Sandi     */
965122f2d46SAndreas Böhler    function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) {
966b625487dSandi        global $conf;
9670cecf9d5Sandi
96897a3e4e3Sandi        $link           = array();
96997a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
97097a3e4e3Sandi        $link['pre']    = '';
97197a3e4e3Sandi        $link['suf']    = '';
9725e163278SAndreas Gohr        $link['more']   = '';
973433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
9740cecf9d5Sandi
97597a3e4e3Sandi        //get interwiki URL
9766496c33fSGerrit Uitslag        $exists = null;
9776496c33fSGerrit Uitslag        $url    = $this->_resolveInterWiki($wikiName, $wikiUri, $exists);
9780cecf9d5Sandi
97997a3e4e3Sandi        if(!$isImage) {
9809d2ddea4SAndreas Gohr            $class         = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName);
9819d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
9821c2d1019SAndreas Gohr        } else {
9831c2d1019SAndreas Gohr            $link['class'] = 'media';
98497a3e4e3Sandi        }
9850cecf9d5Sandi
98697a3e4e3Sandi        //do we stay at the same server? Use local target
9872345e871SGerrit Uitslag        if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) {
98897a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
98997a3e4e3Sandi        }
9906496c33fSGerrit Uitslag        if($exists !== null && !$isImage) {
9916496c33fSGerrit Uitslag            if($exists) {
9926496c33fSGerrit Uitslag                $link['class'] .= ' wikilink1';
9936496c33fSGerrit Uitslag            } else {
9946496c33fSGerrit Uitslag                $link['class'] .= ' wikilink2';
9956496c33fSGerrit Uitslag                $link['rel'] = 'nofollow';
9966496c33fSGerrit Uitslag            }
9976496c33fSGerrit Uitslag        }
9980cecf9d5Sandi
99997a3e4e3Sandi        $link['url']   = $url;
100097a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
100197a3e4e3Sandi
100297a3e4e3Sandi        //output formatted
1003122f2d46SAndreas Böhler        if($returnonly) {
1004122f2d46SAndreas Böhler            return $this->_formatLink($link);
1005122f2d46SAndreas Böhler        } else {
1006a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10070cecf9d5Sandi        }
1008122f2d46SAndreas Böhler    }
10090cecf9d5Sandi
10100cecf9d5Sandi    /**
10113dd5c225SAndreas Gohr     * Link to windows share
10123dd5c225SAndreas Gohr     *
10133dd5c225SAndreas Gohr     * @param string       $url        the link
10143dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1015122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10160cecf9d5Sandi     */
1017122f2d46SAndreas Böhler    function windowssharelink($url, $name = null, $returnonly = false) {
10181d47afe1Sandi        global $conf;
10193dd5c225SAndreas Gohr
10201d47afe1Sandi        //simple setup
102159bc3b48SGerrit Uitslag        $link = array();
10221d47afe1Sandi        $link['target'] = $conf['target']['windows'];
10231d47afe1Sandi        $link['pre']    = '';
10241d47afe1Sandi        $link['suf']    = '';
10251d47afe1Sandi        $link['style']  = '';
10260cecf9d5Sandi
1027433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
10280cecf9d5Sandi        if(!$isImage) {
10291d47afe1Sandi            $link['class'] = 'windows';
10300cecf9d5Sandi        } else {
10311d47afe1Sandi            $link['class'] = 'media';
10320cecf9d5Sandi        }
10330cecf9d5Sandi
1034433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
10351d47afe1Sandi        $url           = str_replace('\\', '/', $url);
103683b7e38dSMichael Große        $url           = ltrim($url,'/');
10371d47afe1Sandi        $url           = 'file:///'.$url;
10381d47afe1Sandi        $link['url']   = $url;
10390cecf9d5Sandi
10401d47afe1Sandi        //output formatted
1041122f2d46SAndreas Böhler        if($returnonly) {
1042122f2d46SAndreas Böhler            return $this->_formatLink($link);
1043122f2d46SAndreas Böhler        } else {
1044a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10450cecf9d5Sandi        }
1046122f2d46SAndreas Böhler    }
10470cecf9d5Sandi
10483dd5c225SAndreas Gohr    /**
10493dd5c225SAndreas Gohr     * Render a linked E-Mail Address
10503dd5c225SAndreas Gohr     *
10513dd5c225SAndreas Gohr     * Honors $conf['mailguard'] setting
10523dd5c225SAndreas Gohr     *
10533dd5c225SAndreas Gohr     * @param string       $address    Email-Address
10543dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1055122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10563dd5c225SAndreas Gohr     */
1057122f2d46SAndreas Böhler    function emaillink($address, $name = null, $returnonly = false) {
105871352defSandi        global $conf;
105971352defSandi        //simple setup
106071352defSandi        $link           = array();
106171352defSandi        $link['target'] = '';
106271352defSandi        $link['pre']    = '';
106371352defSandi        $link['suf']    = '';
106471352defSandi        $link['style']  = '';
106571352defSandi        $link['more']   = '';
10660cecf9d5Sandi
1067c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
10680cecf9d5Sandi        if(!$isImage) {
1069be96545cSAnika Henke            $link['class'] = 'mail';
10700cecf9d5Sandi        } else {
1071be96545cSAnika Henke            $link['class'] = 'media';
10720cecf9d5Sandi        }
10730cecf9d5Sandi
107407738714SAndreas Gohr        $address = $this->_xmlEntities($address);
107500a7b5adSEsther Brunner        $address = obfuscate($address);
107600a7b5adSEsther Brunner        $title   = $address;
10778c128049SAndreas Gohr
107871352defSandi        if(empty($name)) {
107900a7b5adSEsther Brunner            $name = $address;
108071352defSandi        }
10810cecf9d5Sandi
1082776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
1083776b36ecSAndreas Gohr
1084776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
108571352defSandi        $link['name']  = $name;
108671352defSandi        $link['title'] = $title;
10870cecf9d5Sandi
108871352defSandi        //output formatted
1089122f2d46SAndreas Böhler        if($returnonly) {
1090122f2d46SAndreas Böhler            return $this->_formatLink($link);
1091122f2d46SAndreas Böhler        } else {
1092a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10930cecf9d5Sandi        }
1094122f2d46SAndreas Böhler    }
10950cecf9d5Sandi
10963dd5c225SAndreas Gohr    /**
10973dd5c225SAndreas Gohr     * Render an internal media file
10983dd5c225SAndreas Gohr     *
10993dd5c225SAndreas Gohr     * @param string $src       media ID
11003dd5c225SAndreas Gohr     * @param string $title     descriptive text
11013dd5c225SAndreas Gohr     * @param string $align     left|center|right
11023dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
11033dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
11043dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
11053dd5c225SAndreas Gohr     * @param string $linking   linkonly|detail|nolink
11063dd5c225SAndreas Gohr     * @param bool   $return    return HTML instead of adding to $doc
11073dd5c225SAndreas Gohr     * @return void|string
11083dd5c225SAndreas Gohr     */
11090ea51e63SMatt Perry    function internalmedia($src, $title = null, $align = null, $width = null,
11103dd5c225SAndreas Gohr                           $height = null, $cache = null, $linking = null, $return = false) {
111137e34a5eSandi        global $ID;
111291df343aSAndreas Gohr        list($src, $hash) = explode('#', $src, 2);
1113cdb5e961Slisps        resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true);
11140cecf9d5Sandi
1115d98d4540SBen Coburn        $noLink = false;
11168acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1117b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
11183685f775Sandi
11193dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1120b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
112152dc5eadSlisps            $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
1122f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
11232a2a2ba2SAnika Henke            // don't link movies
112444881bd0Shenning.noren            $noLink = true;
112555efc227SAndreas Gohr        } else {
11262ca14335SEsther Brunner            // add file icons
11279d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
11289d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
112952dc5eadSlisps            $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true);
113091328684SMichael Hamann            if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')';
113155efc227SAndreas Gohr        }
11323685f775Sandi
113391df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
113491df343aSAndreas Gohr
11356fe20453SGina Haeussge        //markup non existing files
11364a24b459SKate Arzamastseva        if(!$exists) {
11376fe20453SGina Haeussge            $link['class'] .= ' wikilink2';
11384a24b459SKate Arzamastseva        }
11396fe20453SGina Haeussge
11403685f775Sandi        //output formatted
1141f50634f0SAnika Henke        if($return) {
1142f50634f0SAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1143f50634f0SAnika Henke            else return $this->_formatLink($link);
1144f50634f0SAnika Henke        } else {
1145dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
11462ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
11470cecf9d5Sandi        }
1148f50634f0SAnika Henke    }
11490cecf9d5Sandi
11503dd5c225SAndreas Gohr    /**
11513dd5c225SAndreas Gohr     * Render an external media file
11523dd5c225SAndreas Gohr     *
11533dd5c225SAndreas Gohr     * @param string $src     full media URL
11543dd5c225SAndreas Gohr     * @param string $title   descriptive text
11553dd5c225SAndreas Gohr     * @param string $align   left|center|right
11563dd5c225SAndreas Gohr     * @param int    $width   width of media in pixel
11573dd5c225SAndreas Gohr     * @param int    $height  height of media in pixel
11583dd5c225SAndreas Gohr     * @param string $cache   cache|recache|nocache
11593dd5c225SAndreas Gohr     * @param string $linking linkonly|detail|nolink
1160410ee62aSAnika Henke     * @param bool   $return  return HTML instead of adding to $doc
11613dd5c225SAndreas Gohr     */
11620ea51e63SMatt Perry    function externalmedia($src, $title = null, $align = null, $width = null,
1163410ee62aSAnika Henke                           $height = null, $cache = null, $linking = null, $return = false) {
116491df343aSAndreas Gohr        list($src, $hash) = explode('#', $src, 2);
1165d98d4540SBen Coburn        $noLink = false;
11668acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1167b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
1168b739ff0fSPierre Spring
1169b739ff0fSPierre Spring        $link['url'] = ml($src, array('cache' => $cache));
11703685f775Sandi
11713dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1172b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
11732ca14335SEsther Brunner            // link only jpeg images
117444881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
1175f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
11762a2a2ba2SAnika Henke            // don't link movies
117744881bd0Shenning.noren            $noLink = true;
11782ca14335SEsther Brunner        } else {
11792ca14335SEsther Brunner            // add file icons
118027bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
118127bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
11822ca14335SEsther Brunner        }
11832ca14335SEsther Brunner
118491df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
118591df343aSAndreas Gohr
11863685f775Sandi        //output formatted
1187410ee62aSAnika Henke        if($return) {
1188410ee62aSAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1189410ee62aSAnika Henke            else return $this->_formatLink($link);
1190410ee62aSAnika Henke        } else {
1191dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
11922ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
11930cecf9d5Sandi        }
1194410ee62aSAnika Henke    }
11950cecf9d5Sandi
11964826ab45Sandi    /**
11973db95becSAndreas Gohr     * Renders an RSS feed
1198b625487dSandi     *
1199b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
1200b625487dSandi     */
12013db95becSAndreas Gohr    function rss($url, $params) {
1202b625487dSandi        global $lang;
12033db95becSAndreas Gohr        global $conf;
12043db95becSAndreas Gohr
12053db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
12063db95becSAndreas Gohr        $feed = new FeedParser();
120700077af8SAndreas Gohr        $feed->set_feed_url($url);
1208b625487dSandi
1209b625487dSandi        //disable warning while fetching
12103dd5c225SAndreas Gohr        if(!defined('DOKU_E_LEVEL')) {
12113dd5c225SAndreas Gohr            $elvl = error_reporting(E_ERROR);
12123dd5c225SAndreas Gohr        }
12133db95becSAndreas Gohr        $rc = $feed->init();
12143dd5c225SAndreas Gohr        if(isset($elvl)) {
12153dd5c225SAndreas Gohr            error_reporting($elvl);
12163dd5c225SAndreas Gohr        }
1217b625487dSandi
121838c6f603SRobin H. Johnson        if($params['nosort']) $feed->enable_order_by_date(false);
121938c6f603SRobin H. Johnson
12203db95becSAndreas Gohr        //decide on start and end
12213db95becSAndreas Gohr        if($params['reverse']) {
12223db95becSAndreas Gohr            $mod   = -1;
12233db95becSAndreas Gohr            $start = $feed->get_item_quantity() - 1;
12243db95becSAndreas Gohr            $end   = $start - ($params['max']);
1225b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
12263db95becSAndreas Gohr        } else {
12273db95becSAndreas Gohr            $mod   = 1;
12283db95becSAndreas Gohr            $start = 0;
12293db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
1230d91ab76fSMatt Perry            $end   = ($end > $params['max']) ? $params['max'] : $end;
12313db95becSAndreas Gohr        }
12323db95becSAndreas Gohr
1233a2d649c4Sandi        $this->doc .= '<ul class="rss">';
12343db95becSAndreas Gohr        if($rc) {
12353db95becSAndreas Gohr            for($x = $start; $x != $end; $x += $mod) {
12361bde1582SAndreas Gohr                $item = $feed->get_item($x);
12373db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
1238d2ea3363SAndreas Gohr                // support feeds without links
1239d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
1240d2ea3363SAndreas Gohr                if($lnkurl) {
1241793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
1242793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
12433dd5c225SAndreas Gohr                    $this->externallink(
12443dd5c225SAndreas Gohr                        $item->get_permalink(),
12453dd5c225SAndreas Gohr                        html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')
12463dd5c225SAndreas Gohr                    );
1247d2ea3363SAndreas Gohr                } else {
1248d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
1249d2ea3363SAndreas Gohr                }
12503db95becSAndreas Gohr                if($params['author']) {
12511bde1582SAndreas Gohr                    $author = $item->get_author(0);
12521bde1582SAndreas Gohr                    if($author) {
12531bde1582SAndreas Gohr                        $name = $author->get_name();
12541bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
12551bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
12561bde1582SAndreas Gohr                    }
12573db95becSAndreas Gohr                }
12583db95becSAndreas Gohr                if($params['date']) {
12592e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
12603db95becSAndreas Gohr                }
12611bde1582SAndreas Gohr                if($params['details']) {
12623db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
1263173dccb7STom N Harris                    if($conf['htmlok']) {
12641bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
12653db95becSAndreas Gohr                    } else {
12661bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
12673db95becSAndreas Gohr                    }
12683db95becSAndreas Gohr                    $this->doc .= '</div>';
12693db95becSAndreas Gohr                }
12703db95becSAndreas Gohr
12713db95becSAndreas Gohr                $this->doc .= '</div></li>';
1272b625487dSandi            }
1273b625487dSandi        } else {
12743db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
1275a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
1276b625487dSandi            $this->externallink($url);
127745e147ccSAndreas Gohr            if($conf['allowdebug']) {
127845e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
127945e147ccSAndreas Gohr            }
12803db95becSAndreas Gohr            $this->doc .= '</div></li>';
1281b625487dSandi        }
1282a2d649c4Sandi        $this->doc .= '</ul>';
1283b625487dSandi    }
1284b625487dSandi
12853dd5c225SAndreas Gohr    /**
12863dd5c225SAndreas Gohr     * Start a table
12873dd5c225SAndreas Gohr     *
12883dd5c225SAndreas Gohr     * @param int $maxcols maximum number of columns
12893dd5c225SAndreas Gohr     * @param int $numrows NOT IMPLEMENTED
12903dd5c225SAndreas Gohr     * @param int $pos     byte position in the original source
12913dd5c225SAndreas Gohr     */
1292619736fdSAdrian Lang    function table_open($maxcols = null, $numrows = null, $pos = null) {
1293b5742cedSPierre Spring        // initialize the row counter used for classes
1294b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
1295619736fdSAdrian Lang        $class                         = 'table';
1296619736fdSAdrian Lang        if($pos !== null) {
1297619736fdSAdrian Lang            $class .= ' '.$this->startSectionEdit($pos, 'table');
1298619736fdSAdrian Lang        }
1299619736fdSAdrian Lang        $this->doc .= '<div class="'.$class.'"><table class="inline">'.
1300619736fdSAdrian Lang            DOKU_LF;
13010cecf9d5Sandi    }
13020cecf9d5Sandi
13033dd5c225SAndreas Gohr    /**
13043dd5c225SAndreas Gohr     * Close a table
13053dd5c225SAndreas Gohr     *
13063dd5c225SAndreas Gohr     * @param int $pos byte position in the original source
13073dd5c225SAndreas Gohr     */
1308619736fdSAdrian Lang    function table_close($pos = null) {
1309a8574918SAnika Henke        $this->doc .= '</table></div>'.DOKU_LF;
1310619736fdSAdrian Lang        if($pos !== null) {
131190df9a4dSAdrian Lang            $this->finishSectionEdit($pos);
13120cecf9d5Sandi        }
1313619736fdSAdrian Lang    }
13140cecf9d5Sandi
13153dd5c225SAndreas Gohr    /**
13163dd5c225SAndreas Gohr     * Open a table header
13173dd5c225SAndreas Gohr     */
1318f05a1cc5SGerrit Uitslag    function tablethead_open() {
1319f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF;
1320f05a1cc5SGerrit Uitslag    }
1321f05a1cc5SGerrit Uitslag
13223dd5c225SAndreas Gohr    /**
13233dd5c225SAndreas Gohr     * Close a table header
13243dd5c225SAndreas Gohr     */
1325f05a1cc5SGerrit Uitslag    function tablethead_close() {
1326f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF;
1327f05a1cc5SGerrit Uitslag    }
1328f05a1cc5SGerrit Uitslag
13293dd5c225SAndreas Gohr    /**
13305a93f869SAnika Henke     * Open a table body
13315a93f869SAnika Henke     */
13325a93f869SAnika Henke    function tabletbody_open() {
13335a93f869SAnika Henke        $this->doc .= DOKU_TAB.'<tbody>'.DOKU_LF;
13345a93f869SAnika Henke    }
13355a93f869SAnika Henke
13365a93f869SAnika Henke    /**
13375a93f869SAnika Henke     * Close a table body
13385a93f869SAnika Henke     */
13395a93f869SAnika Henke    function tabletbody_close() {
13405a93f869SAnika Henke        $this->doc .= DOKU_TAB.'</tbody>'.DOKU_LF;
13415a93f869SAnika Henke    }
13425a93f869SAnika Henke
13435a93f869SAnika Henke    /**
13443dd5c225SAndreas Gohr     * Open a table row
13453dd5c225SAndreas Gohr     */
13460cecf9d5Sandi    function tablerow_open() {
1347b5742cedSPierre Spring        // initialize the cell counter used for classes
1348b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
1349b5742cedSPierre Spring        $class                          = 'row'.$this->_counter['row_counter']++;
1350b5742cedSPierre Spring        $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB;
13510cecf9d5Sandi    }
13520cecf9d5Sandi
13533dd5c225SAndreas Gohr    /**
13543dd5c225SAndreas Gohr     * Close a table row
13553dd5c225SAndreas Gohr     */
13560cecf9d5Sandi    function tablerow_close() {
1357a2d649c4Sandi        $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
13580cecf9d5Sandi    }
13590cecf9d5Sandi
13603dd5c225SAndreas Gohr    /**
13613dd5c225SAndreas Gohr     * Open a table header cell
13623dd5c225SAndreas Gohr     *
13633dd5c225SAndreas Gohr     * @param int    $colspan
13643dd5c225SAndreas Gohr     * @param string $align left|center|right
13653dd5c225SAndreas Gohr     * @param int    $rowspan
13663dd5c225SAndreas Gohr     */
13670ea51e63SMatt Perry    function tableheader_open($colspan = 1, $align = null, $rowspan = 1) {
1368b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
13690cecf9d5Sandi        if(!is_null($align)) {
1370b5742cedSPierre Spring            $class .= ' '.$align.'align';
13710cecf9d5Sandi        }
1372b5742cedSPierre Spring        $class .= '"';
1373b5742cedSPierre Spring        $this->doc .= '<th '.$class;
13740cecf9d5Sandi        if($colspan > 1) {
1375a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1376a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
13770cecf9d5Sandi        }
137825b97867Shakan.sandell        if($rowspan > 1) {
137925b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
138025b97867Shakan.sandell        }
1381a2d649c4Sandi        $this->doc .= '>';
13820cecf9d5Sandi    }
13830cecf9d5Sandi
13843dd5c225SAndreas Gohr    /**
13853dd5c225SAndreas Gohr     * Close a table header cell
13863dd5c225SAndreas Gohr     */
13870cecf9d5Sandi    function tableheader_close() {
1388a2d649c4Sandi        $this->doc .= '</th>';
13890cecf9d5Sandi    }
13900cecf9d5Sandi
13913dd5c225SAndreas Gohr    /**
13923dd5c225SAndreas Gohr     * Open a table cell
13933dd5c225SAndreas Gohr     *
13943dd5c225SAndreas Gohr     * @param int    $colspan
13953dd5c225SAndreas Gohr     * @param string $align left|center|right
13963dd5c225SAndreas Gohr     * @param int    $rowspan
13973dd5c225SAndreas Gohr     */
13980ea51e63SMatt Perry    function tablecell_open($colspan = 1, $align = null, $rowspan = 1) {
1399b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
14000cecf9d5Sandi        if(!is_null($align)) {
1401b5742cedSPierre Spring            $class .= ' '.$align.'align';
14020cecf9d5Sandi        }
1403b5742cedSPierre Spring        $class .= '"';
1404b5742cedSPierre Spring        $this->doc .= '<td '.$class;
14050cecf9d5Sandi        if($colspan > 1) {
1406a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1407a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
14080cecf9d5Sandi        }
140925b97867Shakan.sandell        if($rowspan > 1) {
141025b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
141125b97867Shakan.sandell        }
1412a2d649c4Sandi        $this->doc .= '>';
14130cecf9d5Sandi    }
14140cecf9d5Sandi
14153dd5c225SAndreas Gohr    /**
14163dd5c225SAndreas Gohr     * Close a table cell
14173dd5c225SAndreas Gohr     */
14180cecf9d5Sandi    function tablecell_close() {
1419a2d649c4Sandi        $this->doc .= '</td>';
14200cecf9d5Sandi    }
14210cecf9d5Sandi
14223dd5c225SAndreas Gohr    #region Utility functions
14230cecf9d5Sandi
1424ba11bd29Sandi    /**
14253fd0b676Sandi     * Build a link
14263fd0b676Sandi     *
14273fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
1428ba11bd29Sandi     *
1429ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1430ba11bd29Sandi     */
1431433bef32Sandi    function _formatLink($link) {
1432ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
1433ba11bd29Sandi        if(substr($link['url'], 0, 7) != 'mailto:') {
1434ba11bd29Sandi            $link['url'] = str_replace('&', '&amp;', $link['url']);
1435ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;', '&amp;', $link['url']);
1436ba11bd29Sandi        }
1437ba11bd29Sandi        //remove double encodings in titles
1438ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;', '&amp;', $link['title']);
1439ba11bd29Sandi
1440453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
1441453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
1442453493f2SAndreas Gohr        $link['url']   = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22'));
1443453493f2SAndreas Gohr        $link['title'] = strtr($link['title'], array('>' => '&gt;', '<' => '&lt;', '"' => '&quot;'));
1444453493f2SAndreas Gohr
1445ba11bd29Sandi        $ret = '';
1446ba11bd29Sandi        $ret .= $link['pre'];
1447ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
1448bb4866bdSchris        if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"';
1449bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
1450bb4866bdSchris        if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"';
1451bb4866bdSchris        if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"';
145244a6b4c7SAndreas Gohr        if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"';
1453bb4866bdSchris        if(!empty($link['more'])) $ret .= ' '.$link['more'];
1454ba11bd29Sandi        $ret .= '>';
1455ba11bd29Sandi        $ret .= $link['name'];
1456ba11bd29Sandi        $ret .= '</a>';
1457ba11bd29Sandi        $ret .= $link['suf'];
1458ba11bd29Sandi        return $ret;
1459ba11bd29Sandi    }
1460ba11bd29Sandi
1461ba11bd29Sandi    /**
14623fd0b676Sandi     * Renders internal and external media
14633fd0b676Sandi     *
14643fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
14653dd5c225SAndreas Gohr     * @param string $src       media ID
14663dd5c225SAndreas Gohr     * @param string $title     descriptive text
14673dd5c225SAndreas Gohr     * @param string $align     left|center|right
14683dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
14693dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
14703dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
14713dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
14723dd5c225SAndreas Gohr     * @return string
14733fd0b676Sandi     */
14740ea51e63SMatt Perry    function _media($src, $title = null, $align = null, $width = null,
14750ea51e63SMatt Perry                    $height = null, $cache = null, $render = true) {
14763fd0b676Sandi
14773fd0b676Sandi        $ret = '';
14783fd0b676Sandi
14793dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src);
14803fd0b676Sandi        if(substr($mime, 0, 5) == 'image') {
1481b739ff0fSPierre Spring            // first get the $title
1482b739ff0fSPierre Spring            if(!is_null($title)) {
1483b739ff0fSPierre Spring                $title = $this->_xmlEntities($title);
1484b739ff0fSPierre Spring            } elseif($ext == 'jpg' || $ext == 'jpeg') {
1485b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1486b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
148767f9913dSAndreas Gohr                $jpeg = new JpegMeta(mediaFN($src));
1488b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
14893dd5c225SAndreas Gohr                if(!empty($cap)) {
1490b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1491b739ff0fSPierre Spring                }
1492b739ff0fSPierre Spring            }
1493b739ff0fSPierre Spring            if(!$render) {
1494b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1495b739ff0fSPierre Spring                // return the title of the picture
1496b739ff0fSPierre Spring                if(!$title) {
1497b739ff0fSPierre Spring                    // just show the sourcename
14983009a773SAndreas Gohr                    $title = $this->_xmlEntities(utf8_basename(noNS($src)));
1499b739ff0fSPierre Spring                }
1500b739ff0fSPierre Spring                return $title;
1501b739ff0fSPierre Spring            }
15023fd0b676Sandi            //add image tag
150352dc5eadSlisps            $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"';
15043fd0b676Sandi            $ret .= ' class="media'.$align.'"';
15053fd0b676Sandi
1506b739ff0fSPierre Spring            if($title) {
1507b739ff0fSPierre Spring                $ret .= ' title="'.$title.'"';
1508b739ff0fSPierre Spring                $ret .= ' alt="'.$title.'"';
15093fd0b676Sandi            } else {
15103fd0b676Sandi                $ret .= ' alt=""';
15113fd0b676Sandi            }
15123fd0b676Sandi
15133fd0b676Sandi            if(!is_null($width))
15143fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
15153fd0b676Sandi
15163fd0b676Sandi            if(!is_null($height))
15173fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
15183fd0b676Sandi
15193fd0b676Sandi            $ret .= ' />';
15203fd0b676Sandi
152117954bb5SAnika Henke        } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) {
15222a2a2ba2SAnika Henke            // first get the $title
152317954bb5SAnika Henke            $title = !is_null($title) ? $this->_xmlEntities($title) : false;
15242a2a2ba2SAnika Henke            if(!$render) {
152517954bb5SAnika Henke                // if the file is not supposed to be rendered
152617954bb5SAnika Henke                // return the title of the file (just the sourcename if there is no title)
152717954bb5SAnika Henke                return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src)));
15282a2a2ba2SAnika Henke            }
15292a2a2ba2SAnika Henke
15302a2a2ba2SAnika Henke            $att          = array();
15312a2a2ba2SAnika Henke            $att['class'] = "media$align";
153217954bb5SAnika Henke            if($title) {
153317954bb5SAnika Henke                $att['title'] = $title;
153417954bb5SAnika Henke            }
15352a2a2ba2SAnika Henke
153617954bb5SAnika Henke            if(media_supportedav($mime, 'video')) {
153717954bb5SAnika Henke                //add video
153879e53fe5SAnika Henke                $ret .= $this->_video($src, $width, $height, $att);
1539b44a5dceSAnika Henke            }
154017954bb5SAnika Henke            if(media_supportedav($mime, 'audio')) {
1541b44a5dceSAnika Henke                //add audio
1542b44a5dceSAnika Henke                $ret .= $this->_audio($src, $att);
154317954bb5SAnika Henke            }
1544b44a5dceSAnika Henke
15453fd0b676Sandi        } elseif($mime == 'application/x-shockwave-flash') {
15461c882ba8SAndreas Gohr            if(!$render) {
15471c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
15481c882ba8SAndreas Gohr                // return the title of the flash
15491c882ba8SAndreas Gohr                if(!$title) {
15501c882ba8SAndreas Gohr                    // just show the sourcename
15513009a773SAndreas Gohr                    $title = utf8_basename(noNS($src));
15521c882ba8SAndreas Gohr                }
155307bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
15541c882ba8SAndreas Gohr            }
15551c882ba8SAndreas Gohr
155607bf32b2SAndreas Gohr            $att          = array();
155707bf32b2SAndreas Gohr            $att['class'] = "media$align";
155807bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
155907bf32b2SAndreas Gohr            if($align == 'left') $att['align'] = 'left';
15603dd5c225SAndreas Gohr            $ret .= html_flashobject(
15613dd5c225SAndreas Gohr                ml($src, array('cache' => $cache), true, '&'), $width, $height,
156207bf32b2SAndreas Gohr                array('quality' => 'high'),
156307bf32b2SAndreas Gohr                null,
156407bf32b2SAndreas Gohr                $att,
15653dd5c225SAndreas Gohr                $this->_xmlEntities($title)
15663dd5c225SAndreas Gohr            );
15670f428d7dSAndreas Gohr        } elseif($title) {
15683fd0b676Sandi            // well at least we have a title to display
15693fd0b676Sandi            $ret .= $this->_xmlEntities($title);
15703fd0b676Sandi        } else {
15715291ca3aSAndreas Gohr            // just show the sourcename
15723009a773SAndreas Gohr            $ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
15733fd0b676Sandi        }
15743fd0b676Sandi
15753fd0b676Sandi        return $ret;
15763fd0b676Sandi    }
15773fd0b676Sandi
15783dd5c225SAndreas Gohr    /**
15793dd5c225SAndreas Gohr     * Escape string for output
15803dd5c225SAndreas Gohr     *
15813dd5c225SAndreas Gohr     * @param $string
15823dd5c225SAndreas Gohr     * @return string
15833dd5c225SAndreas Gohr     */
1584433bef32Sandi    function _xmlEntities($string) {
1585de117061Schris        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
15860cecf9d5Sandi    }
15870cecf9d5Sandi
15888a831f2bSAndreas Gohr    /**
15898a831f2bSAndreas Gohr     * Creates a linkid from a headline
1590c5a8fd96SAndreas Gohr     *
15913dd5c225SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
1592c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1593c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
15943dd5c225SAndreas Gohr     * @return string
15958a831f2bSAndreas Gohr     */
1596c5a8fd96SAndreas Gohr    function _headerToLink($title, $create = false) {
1597c5a8fd96SAndreas Gohr        if($create) {
15984ceab83fSAndreas Gohr            return sectionID($title, $this->headers);
15994ceab83fSAndreas Gohr        } else {
1600443d207bSAndreas Gohr            $check = false;
1601443d207bSAndreas Gohr            return sectionID($title, $check);
1602c5a8fd96SAndreas Gohr        }
16030cecf9d5Sandi    }
16040cecf9d5Sandi
1605af587fa8Sandi    /**
16063fd0b676Sandi     * Construct a title and handle images in titles
16073fd0b676Sandi     *
16080b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
16093dd5c225SAndreas Gohr     * @param string|array $title    either string title or media array
16103dd5c225SAndreas Gohr     * @param string       $default  default title if nothing else is found
16113dd5c225SAndreas Gohr     * @param bool         $isImage  will be set to true if it's a media file
16123dd5c225SAndreas Gohr     * @param null|string  $id       linked page id (used to extract title from first heading)
16133dd5c225SAndreas Gohr     * @param string       $linktype content|navigation
16143dd5c225SAndreas Gohr     * @return string      HTML of the title, might be full image tag or just escaped text
16153fd0b676Sandi     */
16160ea51e63SMatt Perry    function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') {
161744881bd0Shenning.noren        $isImage = false;
161829657f9eSAndreas Gohr        if(is_array($title)) {
161929657f9eSAndreas Gohr            $isImage = true;
162029657f9eSAndreas Gohr            return $this->_imageTitle($title);
162129657f9eSAndreas Gohr        } elseif(is_null($title) || trim($title) == '') {
1622fe9ec250SChris Smith            if(useHeading($linktype) && $id) {
162367c15eceSMichael Hamann                $heading = p_get_first_heading($id);
1624bb0a59d4Sjan                if($heading) {
1625433bef32Sandi                    return $this->_xmlEntities($heading);
1626bb0a59d4Sjan                }
1627bb0a59d4Sjan            }
1628433bef32Sandi            return $this->_xmlEntities($default);
162968c26e6dSMichael Klier        } else {
163068c26e6dSMichael Klier            return $this->_xmlEntities($title);
16310cecf9d5Sandi        }
16320cecf9d5Sandi    }
16330cecf9d5Sandi
16340cecf9d5Sandi    /**
16353dd5c225SAndreas Gohr     * Returns HTML code for images used in link titles
16363fd0b676Sandi     *
16373fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1638e0c26282SGerrit Uitslag     * @param array $img
16393dd5c225SAndreas Gohr     * @return string HTML img tag or similar
16400cecf9d5Sandi     */
1641433bef32Sandi    function _imageTitle($img) {
1642d9baf1a7SKazutaka Miyasaka        global $ID;
1643d9baf1a7SKazutaka Miyasaka
1644d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1645d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
16463dd5c225SAndreas Gohr        list($img['src']) = explode('#', $img['src'], 2);
1647d9baf1a7SKazutaka Miyasaka        if($img['type'] == 'internalmedia') {
1648cdb5e961Slisps            resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true);
1649d9baf1a7SKazutaka Miyasaka        }
1650d9baf1a7SKazutaka Miyasaka
16513dd5c225SAndreas Gohr        return $this->_media(
16523dd5c225SAndreas Gohr            $img['src'],
16534826ab45Sandi            $img['title'],
16544826ab45Sandi            $img['align'],
16554826ab45Sandi            $img['width'],
16564826ab45Sandi            $img['height'],
16573dd5c225SAndreas Gohr            $img['cache']
16583dd5c225SAndreas Gohr        );
16590cecf9d5Sandi    }
1660b739ff0fSPierre Spring
1661b739ff0fSPierre Spring    /**
16623dd5c225SAndreas Gohr     * helperfunction to return a basic link to a media
16633dd5c225SAndreas Gohr     *
16643dd5c225SAndreas Gohr     * used in internalmedia() and externalmedia()
1665b739ff0fSPierre Spring     *
1666b739ff0fSPierre Spring     * @author   Pierre Spring <pierre.spring@liip.ch>
16673dd5c225SAndreas Gohr     * @param string $src       media ID
16683dd5c225SAndreas Gohr     * @param string $title     descriptive text
16693dd5c225SAndreas Gohr     * @param string $align     left|center|right
16703dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
16713dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
16723dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
16733dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
16743dd5c225SAndreas Gohr     * @return array associative array with link config
1675b739ff0fSPierre Spring     */
1676d91ab76fSMatt Perry    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) {
1677b739ff0fSPierre Spring        global $conf;
1678b739ff0fSPierre Spring
1679b739ff0fSPierre Spring        $link           = array();
1680b739ff0fSPierre Spring        $link['class']  = 'media';
1681b739ff0fSPierre Spring        $link['style']  = '';
1682b739ff0fSPierre Spring        $link['pre']    = '';
1683b739ff0fSPierre Spring        $link['suf']    = '';
1684b739ff0fSPierre Spring        $link['more']   = '';
1685b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1686b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1687b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1688b739ff0fSPierre Spring
1689b739ff0fSPierre Spring        return $link;
1690b739ff0fSPierre Spring    }
169191459163SAnika Henke
16922a2a2ba2SAnika Henke    /**
16932a2a2ba2SAnika Henke     * Embed video(s) in HTML
16942a2a2ba2SAnika Henke     *
16952a2a2ba2SAnika Henke     * @author Anika Henke <anika@selfthinker.org>
16962a2a2ba2SAnika Henke     *
16972a2a2ba2SAnika Henke     * @param string $src         - ID of video to embed
16982a2a2ba2SAnika Henke     * @param int    $width       - width of the video in pixels
16992a2a2ba2SAnika Henke     * @param int    $height      - height of the video in pixels
17002a2a2ba2SAnika Henke     * @param array  $atts        - additional attributes for the <video> tag
1701f50634f0SAnika Henke     * @return string
17022a2a2ba2SAnika Henke     */
170379e53fe5SAnika Henke    function _video($src, $width, $height, $atts = null) {
17042a2a2ba2SAnika Henke        // prepare width and height
17052a2a2ba2SAnika Henke        if(is_null($atts)) $atts = array();
17062a2a2ba2SAnika Henke        $atts['width']  = (int) $width;
17072a2a2ba2SAnika Henke        $atts['height'] = (int) $height;
17082a2a2ba2SAnika Henke        if(!$atts['width']) $atts['width'] = 320;
17092a2a2ba2SAnika Henke        if(!$atts['height']) $atts['height'] = 240;
17102a2a2ba2SAnika Henke
1711410ee62aSAnika Henke        $posterUrl = '';
1712410ee62aSAnika Henke        $files = array();
1713410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1714410ee62aSAnika Henke
1715410ee62aSAnika Henke        if ($isExternal) {
1716410ee62aSAnika Henke            // take direct source for external files
1717702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1718410ee62aSAnika Henke            $files[$srcMime] = $src;
1719410ee62aSAnika Henke        } else {
17203d7a9e0aSAnika Henke            // prepare alternative formats
17213d7a9e0aSAnika Henke            $extensions   = array('webm', 'ogv', 'mp4');
1722410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
172359bc3b48SGerrit Uitslag            $poster       = media_alternativefiles($src, array('jpg', 'png'));
172499f943f6SAnika Henke            if(!empty($poster)) {
17252d338eabSAndreas Gohr                $posterUrl = ml(reset($poster), '', true, '&');
172699f943f6SAnika Henke            }
1727410ee62aSAnika Henke        }
17282a2a2ba2SAnika Henke
1729f50634f0SAnika Henke        $out = '';
173079e53fe5SAnika Henke        // open video tag
1731f50634f0SAnika Henke        $out .= '<video '.buildAttributes($atts).' controls="controls"';
17323641199aSAnika Henke        if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"';
1733f50634f0SAnika Henke        $out .= '>'.NL;
17343641199aSAnika Henke        $fallback = '';
173579e53fe5SAnika Henke
173679e53fe5SAnika Henke        // output source for each alternative video format
1737410ee62aSAnika Henke        foreach($files as $mime => $file) {
1738410ee62aSAnika Henke            if ($isExternal) {
1739410ee62aSAnika Henke                $url = $file;
1740410ee62aSAnika Henke                $linkType = 'externalmedia';
1741410ee62aSAnika Henke            } else {
17422d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1743410ee62aSAnika Henke                $linkType = 'internalmedia';
1744410ee62aSAnika Henke            }
174517954bb5SAnika Henke            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
17463d7a9e0aSAnika Henke
1747f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
174879e53fe5SAnika Henke            // alternative content (just a link to the file)
1749410ee62aSAnika Henke            $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
17503d7a9e0aSAnika Henke        }
17512a2a2ba2SAnika Henke
17522a2a2ba2SAnika Henke        // finish
17533641199aSAnika Henke        $out .= $fallback;
1754f50634f0SAnika Henke        $out .= '</video>'.NL;
1755f50634f0SAnika Henke        return $out;
17562a2a2ba2SAnika Henke    }
17572a2a2ba2SAnika Henke
1758b44a5dceSAnika Henke    /**
1759b44a5dceSAnika Henke     * Embed audio in HTML
1760b44a5dceSAnika Henke     *
1761b44a5dceSAnika Henke     * @author Anika Henke <anika@selfthinker.org>
1762b44a5dceSAnika Henke     *
1763b44a5dceSAnika Henke     * @param string $src       - ID of audio to embed
17646d4af72aSAnika Henke     * @param array  $atts      - additional attributes for the <audio> tag
1765f50634f0SAnika Henke     * @return string
1766b44a5dceSAnika Henke     */
176759bc3b48SGerrit Uitslag    function _audio($src, $atts = array()) {
1768702e97d3SAnika Henke        $files = array();
1769410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1770b44a5dceSAnika Henke
1771410ee62aSAnika Henke        if ($isExternal) {
1772410ee62aSAnika Henke            // take direct source for external files
1773702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1774410ee62aSAnika Henke            $files[$srcMime] = $src;
1775410ee62aSAnika Henke        } else {
1776b44a5dceSAnika Henke            // prepare alternative formats
1777b44a5dceSAnika Henke            $extensions   = array('ogg', 'mp3', 'wav');
1778410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
1779410ee62aSAnika Henke        }
1780b44a5dceSAnika Henke
1781f50634f0SAnika Henke        $out = '';
1782b44a5dceSAnika Henke        // open audio tag
1783f50634f0SAnika Henke        $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL;
17843641199aSAnika Henke        $fallback = '';
1785b44a5dceSAnika Henke
1786b44a5dceSAnika Henke        // output source for each alternative audio format
1787410ee62aSAnika Henke        foreach($files as $mime => $file) {
1788410ee62aSAnika Henke            if ($isExternal) {
1789410ee62aSAnika Henke                $url = $file;
1790410ee62aSAnika Henke                $linkType = 'externalmedia';
1791410ee62aSAnika Henke            } else {
17922d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1793410ee62aSAnika Henke                $linkType = 'internalmedia';
1794410ee62aSAnika Henke            }
179517954bb5SAnika Henke            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file)));
1796b44a5dceSAnika Henke
1797f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
1798b44a5dceSAnika Henke            // alternative content (just a link to the file)
1799410ee62aSAnika Henke            $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
1800b44a5dceSAnika Henke        }
1801b44a5dceSAnika Henke
1802b44a5dceSAnika Henke        // finish
18033641199aSAnika Henke        $out .= $fallback;
1804f50634f0SAnika Henke        $out .= '</audio>'.NL;
1805f50634f0SAnika Henke        return $out;
1806b44a5dceSAnika Henke    }
1807b44a5dceSAnika Henke
18085c2eed9aSlisps    /**
180952dc5eadSlisps     * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media()
18105c2eed9aSlisps     * which returns an existing media revision less or equal to rev or date_at
18115c2eed9aSlisps     *
18125c2eed9aSlisps     * @author lisps
18135c2eed9aSlisps     * @param string $media_id
18145c2eed9aSlisps     * @access protected
18155c2eed9aSlisps     * @return string revision ('' for current)
18165c2eed9aSlisps     */
181752dc5eadSlisps    function _getLastMediaRevisionAt($media_id){
181852dc5eadSlisps        if(!$this->date_at || media_isexternal($media_id)) return '';
181978b874e6Slisps        $pagelog = new MediaChangeLog($media_id);
182078b874e6Slisps        return $pagelog->getLastRevisionAt($this->date_at);
18215c2eed9aSlisps    }
18225c2eed9aSlisps
18233dd5c225SAndreas Gohr    #endregion
18240cecf9d5Sandi}
18250cecf9d5Sandi
1826e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1827