xref: /dokuwiki/inc/parser/xhtml.php (revision 8c6be208dcb4734cf5ad7e62ab5df1d42d46ad76)
10cecf9d5Sandi<?php
20c3a5702SAndreas Gohr
30c3a5702SAndreas Gohruse dokuwiki\ChangeLog\MediaChangeLog;
4*8c6be208SAndreas Gohruse dokuwiki\Utils\MediaResolver;
5*8c6be208SAndreas Gohruse dokuwiki\Utils\PageResolver;
60c3a5702SAndreas Gohr
7b625487dSandi/**
8b625487dSandi * Renderer for XHTML output
9b625487dSandi *
10b4f2363aSAndreas Gohr * This is DokuWiki's main renderer used to display page content in the wiki
11b4f2363aSAndreas Gohr *
12b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
13b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
143dd5c225SAndreas Gohr *
150cecf9d5Sandi */
16ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
173dd5c225SAndreas Gohr    /** @var array store the table of contents */
183dd5c225SAndreas Gohr    public $toc = array();
190cecf9d5Sandi
203dd5c225SAndreas Gohr    /** @var array A stack of section edit data */
213dd5c225SAndreas Gohr    protected $sectionedits = array();
22de369923SAndreas Gohr
23de369923SAndreas Gohr    /** @var string|int link pages and media against this revision */
24de369923SAndreas Gohr    public $date_at = '';
25c5a8fd96SAndreas Gohr
263dd5c225SAndreas Gohr    /** @var int last section edit id, used by startSectionEdit */
273dd5c225SAndreas Gohr    protected $lastsecid = 0;
280cecf9d5Sandi
2916ec3e37SAndreas Gohr    /** @var array a list of footnotes, list starts at 1! */
303dd5c225SAndreas Gohr    protected $footnotes = array();
317764a90aSandi
323dd5c225SAndreas Gohr    /** @var int current section level */
333dd5c225SAndreas Gohr    protected $lastlevel = 0;
343dd5c225SAndreas Gohr    /** @var array section node tracker */
353dd5c225SAndreas Gohr    protected $node = array(0, 0, 0, 0, 0);
363dd5c225SAndreas Gohr
373dd5c225SAndreas Gohr    /** @var string temporary $doc store */
383dd5c225SAndreas Gohr    protected $store = '';
393dd5c225SAndreas Gohr
403dd5c225SAndreas Gohr    /** @var array global counter, for table classes etc. */
413dd5c225SAndreas Gohr    protected $_counter = array(); //
423dd5c225SAndreas Gohr
433dd5c225SAndreas Gohr    /** @var int counts the code and file blocks, used to provide download links */
443dd5c225SAndreas Gohr    protected $_codeblock = 0;
453dd5c225SAndreas Gohr
463dd5c225SAndreas Gohr    /** @var array list of allowed URL schemes */
473dd5c225SAndreas Gohr    protected $schemes = null;
48b5742cedSPierre Spring
4990df9a4dSAdrian Lang    /**
5090df9a4dSAdrian Lang     * Register a new edit section range
5190df9a4dSAdrian Lang     *
5242ea7f44SGerrit Uitslag     * @param int    $start  The byte position for the edit start
53ec57f119SLarsDW223     * @param array  $data   Associative array with section data:
54ec57f119SLarsDW223     *                       Key 'name': the section name/title
55ec57f119SLarsDW223     *                       Key 'target': the target for the section edit,
56ec57f119SLarsDW223     *                                     e.g. 'section' or 'table'
57ec57f119SLarsDW223     *                       Key 'hid': header id
58ec57f119SLarsDW223     *                       Key 'codeblockOffset': actual code block index
59ec57f119SLarsDW223     *                       Key 'start': set in startSectionEdit(),
60ec57f119SLarsDW223     *                                    do not set yourself
61ec57f119SLarsDW223     *                       Key 'range': calculated from 'start' and
62ec57f119SLarsDW223     *                                    $key in finishSectionEdit(),
63ec57f119SLarsDW223     *                                    do not set yourself
6490df9a4dSAdrian Lang     * @return string  A marker class for the starting HTML element
6542ea7f44SGerrit Uitslag     *
6690df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
6790df9a4dSAdrian Lang     */
68ec57f119SLarsDW223    public function startSectionEdit($start, $data) {
69ec57f119SLarsDW223        if (!is_array($data)) {
70ac025fdfSAndreas Gohr            msg(
71ac025fdfSAndreas Gohr                sprintf(
72ac025fdfSAndreas Gohr                    'startSectionEdit: $data "%s" is NOT an array! One of your plugins needs an update.',
73ac025fdfSAndreas Gohr                    hsc((string) $data)
74ac025fdfSAndreas Gohr                ), -1
75ac025fdfSAndreas Gohr            );
76ac025fdfSAndreas Gohr
77ac025fdfSAndreas Gohr            // @deprecated 2018-04-14, backward compatibility
78ac025fdfSAndreas Gohr            $args = func_get_args();
79ac025fdfSAndreas Gohr            $data = array();
80ac025fdfSAndreas Gohr            if(isset($args[1])) $data['target'] = $args[1];
81ac025fdfSAndreas Gohr            if(isset($args[2])) $data['name'] = $args[2];
82ac025fdfSAndreas Gohr            if(isset($args[3])) $data['hid'] = $args[3];
83ec57f119SLarsDW223        }
84ec57f119SLarsDW223        $data['secid'] = ++$this->lastsecid;
85ec57f119SLarsDW223        $data['start'] = $start;
86ec57f119SLarsDW223        $this->sectionedits[] = $data;
87ec57f119SLarsDW223        return 'sectionedit'.$data['secid'];
8890df9a4dSAdrian Lang    }
8990df9a4dSAdrian Lang
9090df9a4dSAdrian Lang    /**
9190df9a4dSAdrian Lang     * Finish an edit section range
9290df9a4dSAdrian Lang     *
9342ea7f44SGerrit Uitslag     * @param int  $end     The byte position for the edit end; null for the rest of the page
9442ea7f44SGerrit Uitslag     *
9590df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
9690df9a4dSAdrian Lang     */
972571786cSLarsDW223    public function finishSectionEdit($end = null, $hid = null) {
98ec57f119SLarsDW223        $data = array_pop($this->sectionedits);
99ec57f119SLarsDW223        if(!is_null($end) && $end <= $data['start']) {
10000c13053SAdrian Lang            return;
10100c13053SAdrian Lang        }
1022571786cSLarsDW223        if(!is_null($hid)) {
103ec57f119SLarsDW223            $data['hid'] .= $hid;
1042571786cSLarsDW223        }
105ec57f119SLarsDW223        $data['range'] = $data['start'].'-'.(is_null($end) ? '' : $end);
106ec57f119SLarsDW223        unset($data['start']);
107ada0d779SMichael Hamann        $this->doc .= '<!-- EDIT'.hsc(json_encode ($data)).' -->';
10890df9a4dSAdrian Lang    }
10990df9a4dSAdrian Lang
1103dd5c225SAndreas Gohr    /**
1113dd5c225SAndreas Gohr     * Returns the format produced by this renderer.
1123dd5c225SAndreas Gohr     *
1133dd5c225SAndreas Gohr     * @return string always 'xhtml'
1143dd5c225SAndreas Gohr     */
115de369923SAndreas Gohr    public function getFormat() {
1165f70445dSAndreas Gohr        return 'xhtml';
1175f70445dSAndreas Gohr    }
1185f70445dSAndreas Gohr
1193dd5c225SAndreas Gohr    /**
1203dd5c225SAndreas Gohr     * Initialize the document
1213dd5c225SAndreas Gohr     */
122de369923SAndreas Gohr    public function document_start() {
123c5a8fd96SAndreas Gohr        //reset some internals
124c5a8fd96SAndreas Gohr        $this->toc     = array();
1250cecf9d5Sandi    }
1260cecf9d5Sandi
1273dd5c225SAndreas Gohr    /**
1283dd5c225SAndreas Gohr     * Finalize the document
1293dd5c225SAndreas Gohr     */
130de369923SAndreas Gohr    public function document_end() {
13190df9a4dSAdrian Lang        // Finish open section edits.
13290df9a4dSAdrian Lang        while(count($this->sectionedits) > 0) {
133ec57f119SLarsDW223            if($this->sectionedits[count($this->sectionedits) - 1]['start'] <= 1) {
13490df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
13590df9a4dSAdrian Lang                // marker.
13690df9a4dSAdrian Lang                array_pop($this->sectionedits);
13790df9a4dSAdrian Lang            } else {
138d9e36cbeSAdrian Lang                $this->finishSectionEdit();
13990df9a4dSAdrian Lang            }
14090df9a4dSAdrian Lang        }
14190df9a4dSAdrian Lang
1420cecf9d5Sandi        if(count($this->footnotes) > 0) {
143a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
144d74aace9Schris
14516ec3e37SAndreas Gohr            foreach($this->footnotes as $id => $footnote) {
146d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
147d74aace9Schris                if(substr($footnote, 0, 5) != "@@FNT") {
148d74aace9Schris
149d74aace9Schris                    // open the footnote and set the anchor and backlink
150d74aace9Schris                    $this->doc .= '<div class="fn">';
15116cc7ed7SAnika Henke                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">';
15229bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
153d74aace9Schris
154d74aace9Schris                    // get any other footnotes that use the same markup
155d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
156d74aace9Schris
157d74aace9Schris                    if(count($alt)) {
158d74aace9Schris                        foreach($alt as $ref) {
159d74aace9Schris                            // set anchor and backlink for the other footnotes
16016ec3e37SAndreas Gohr                            $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">';
16116ec3e37SAndreas Gohr                            $this->doc .= ($ref).')</a></sup> '.DOKU_LF;
162d74aace9Schris                        }
163d74aace9Schris                    }
164d74aace9Schris
165d74aace9Schris                    // add footnote markup and close this footnote
166694afa06SAnika Henke                    $this->doc .= '<div class="content">'.$footnote.'</div>';
167d74aace9Schris                    $this->doc .= '</div>'.DOKU_LF;
168d74aace9Schris                }
1690cecf9d5Sandi            }
170a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1710cecf9d5Sandi        }
172c5a8fd96SAndreas Gohr
173b8595a66SAndreas Gohr        // Prepare the TOC
174851f2e89SAnika Henke        global $conf;
17564159a61SAndreas Gohr        if(
17664159a61SAndreas Gohr            $this->info['toc'] &&
17764159a61SAndreas Gohr            is_array($this->toc) &&
17864159a61SAndreas Gohr            $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']
17964159a61SAndreas Gohr        ) {
180b8595a66SAndreas Gohr            global $TOC;
181b8595a66SAndreas Gohr            $TOC = $this->toc;
1820cecf9d5Sandi        }
1833e55d035SAndreas Gohr
1843e55d035SAndreas Gohr        // make sure there are no empty paragraphs
18527918226Schris        $this->doc = preg_replace('#<p>\s*</p>#', '', $this->doc);
186e41c4da9SAndreas Gohr    }
1870cecf9d5Sandi
1883dd5c225SAndreas Gohr    /**
1893dd5c225SAndreas Gohr     * Add an item to the TOC
1903dd5c225SAndreas Gohr     *
1913dd5c225SAndreas Gohr     * @param string $id       the hash link
1923dd5c225SAndreas Gohr     * @param string $text     the text to display
1933dd5c225SAndreas Gohr     * @param int    $level    the nesting level
1943dd5c225SAndreas Gohr     */
195de369923SAndreas Gohr    public function toc_additem($id, $text, $level) {
196af587fa8Sandi        global $conf;
197af587fa8Sandi
198c5a8fd96SAndreas Gohr        //handle TOC
199c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) {
2007d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1);
201c5a8fd96SAndreas Gohr        }
202e7856beaSchris    }
203e7856beaSchris
2043dd5c225SAndreas Gohr    /**
2053dd5c225SAndreas Gohr     * Render a heading
2063dd5c225SAndreas Gohr     *
2073dd5c225SAndreas Gohr     * @param string $text  the text to display
2083dd5c225SAndreas Gohr     * @param int    $level header level
2093dd5c225SAndreas Gohr     * @param int    $pos   byte position in the original source
2103dd5c225SAndreas Gohr     */
211de369923SAndreas Gohr    public function header($text, $level, $pos) {
21290df9a4dSAdrian Lang        global $conf;
21390df9a4dSAdrian Lang
214f515db7fSAndreas Gohr        if(blank($text)) return; //skip empty headlines
215e7856beaSchris
216e7856beaSchris        $hid = $this->_headerToLink($text, true);
217e7856beaSchris
218e7856beaSchris        //only add items within configured levels
219e7856beaSchris        $this->toc_additem($hid, $text, $level);
220c5a8fd96SAndreas Gohr
22191459163SAnika Henke        // adjust $node to reflect hierarchy of levels
22291459163SAnika Henke        $this->node[$level - 1]++;
22391459163SAnika Henke        if($level < $this->lastlevel) {
22491459163SAnika Henke            for($i = 0; $i < $this->lastlevel - $level; $i++) {
22591459163SAnika Henke                $this->node[$this->lastlevel - $i - 1] = 0;
22691459163SAnika Henke            }
22791459163SAnika Henke        }
22891459163SAnika Henke        $this->lastlevel = $level;
22991459163SAnika Henke
23090df9a4dSAdrian Lang        if($level <= $conf['maxseclevel'] &&
23190df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
232ec57f119SLarsDW223            $this->sectionedits[count($this->sectionedits) - 1]['target'] === 'section'
2333dd5c225SAndreas Gohr        ) {
2346c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
23590df9a4dSAdrian Lang        }
23690df9a4dSAdrian Lang
237c5a8fd96SAndreas Gohr        // write the header
23890df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
23990df9a4dSAdrian Lang        if($level <= $conf['maxseclevel']) {
240ec57f119SLarsDW223            $data = array();
241ec57f119SLarsDW223            $data['target'] = 'section';
242ec57f119SLarsDW223            $data['name'] = $text;
243ec57f119SLarsDW223            $data['hid'] = $hid;
244ec57f119SLarsDW223            $data['codeblockOffset'] = $this->_codeblock;
245ec57f119SLarsDW223            $this->doc .= ' class="'.$this->startSectionEdit($pos, $data).'"';
24690df9a4dSAdrian Lang        }
24716cc7ed7SAnika Henke        $this->doc .= ' id="'.$hid.'">';
248a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
24916cc7ed7SAnika Henke        $this->doc .= "</h$level>".DOKU_LF;
2500cecf9d5Sandi    }
2510cecf9d5Sandi
2523dd5c225SAndreas Gohr    /**
2533dd5c225SAndreas Gohr     * Open a new section
2543dd5c225SAndreas Gohr     *
2553dd5c225SAndreas Gohr     * @param int $level section level (as determined by the previous header)
2563dd5c225SAndreas Gohr     */
257de369923SAndreas Gohr    public function section_open($level) {
2589864e7b1SAdrian Lang        $this->doc .= '<div class="level'.$level.'">'.DOKU_LF;
2590cecf9d5Sandi    }
2600cecf9d5Sandi
2613dd5c225SAndreas Gohr    /**
2623dd5c225SAndreas Gohr     * Close the current section
2633dd5c225SAndreas Gohr     */
264de369923SAndreas Gohr    public function section_close() {
265a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
2660cecf9d5Sandi    }
2670cecf9d5Sandi
2683dd5c225SAndreas Gohr    /**
2693dd5c225SAndreas Gohr     * Render plain text data
2703dd5c225SAndreas Gohr     *
2713dd5c225SAndreas Gohr     * @param $text
2723dd5c225SAndreas Gohr     */
273de369923SAndreas Gohr    public function cdata($text) {
274a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
2750cecf9d5Sandi    }
2760cecf9d5Sandi
2773dd5c225SAndreas Gohr    /**
2783dd5c225SAndreas Gohr     * Open a paragraph
2793dd5c225SAndreas Gohr     */
280de369923SAndreas Gohr    public function p_open() {
28159869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
2820cecf9d5Sandi    }
2830cecf9d5Sandi
2843dd5c225SAndreas Gohr    /**
2853dd5c225SAndreas Gohr     * Close a paragraph
2863dd5c225SAndreas Gohr     */
287de369923SAndreas Gohr    public function p_close() {
28859869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2890cecf9d5Sandi    }
2900cecf9d5Sandi
2913dd5c225SAndreas Gohr    /**
2923dd5c225SAndreas Gohr     * Create a line break
2933dd5c225SAndreas Gohr     */
294de369923SAndreas Gohr    public function linebreak() {
295a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2960cecf9d5Sandi    }
2970cecf9d5Sandi
2983dd5c225SAndreas Gohr    /**
2993dd5c225SAndreas Gohr     * Create a horizontal line
3003dd5c225SAndreas Gohr     */
301de369923SAndreas Gohr    public function hr() {
3024beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
3030cecf9d5Sandi    }
3040cecf9d5Sandi
3053dd5c225SAndreas Gohr    /**
3063dd5c225SAndreas Gohr     * Start strong (bold) formatting
3073dd5c225SAndreas Gohr     */
308de369923SAndreas Gohr    public function strong_open() {
309a2d649c4Sandi        $this->doc .= '<strong>';
3100cecf9d5Sandi    }
3110cecf9d5Sandi
3123dd5c225SAndreas Gohr    /**
3133dd5c225SAndreas Gohr     * Stop strong (bold) formatting
3143dd5c225SAndreas Gohr     */
315de369923SAndreas Gohr    public function strong_close() {
316a2d649c4Sandi        $this->doc .= '</strong>';
3170cecf9d5Sandi    }
3180cecf9d5Sandi
3193dd5c225SAndreas Gohr    /**
3203dd5c225SAndreas Gohr     * Start emphasis (italics) formatting
3213dd5c225SAndreas Gohr     */
322de369923SAndreas Gohr    public function emphasis_open() {
323a2d649c4Sandi        $this->doc .= '<em>';
3240cecf9d5Sandi    }
3250cecf9d5Sandi
3263dd5c225SAndreas Gohr    /**
3273dd5c225SAndreas Gohr     * Stop emphasis (italics) formatting
3283dd5c225SAndreas Gohr     */
329de369923SAndreas Gohr    public function emphasis_close() {
330a2d649c4Sandi        $this->doc .= '</em>';
3310cecf9d5Sandi    }
3320cecf9d5Sandi
3333dd5c225SAndreas Gohr    /**
3343dd5c225SAndreas Gohr     * Start underline formatting
3353dd5c225SAndreas Gohr     */
336de369923SAndreas Gohr    public function underline_open() {
33702e51121SAnika Henke        $this->doc .= '<em class="u">';
3380cecf9d5Sandi    }
3390cecf9d5Sandi
3403dd5c225SAndreas Gohr    /**
3413dd5c225SAndreas Gohr     * Stop underline formatting
3423dd5c225SAndreas Gohr     */
343de369923SAndreas Gohr    public function underline_close() {
34402e51121SAnika Henke        $this->doc .= '</em>';
3450cecf9d5Sandi    }
3460cecf9d5Sandi
3473dd5c225SAndreas Gohr    /**
3483dd5c225SAndreas Gohr     * Start monospace formatting
3493dd5c225SAndreas Gohr     */
350de369923SAndreas Gohr    public function monospace_open() {
351a2d649c4Sandi        $this->doc .= '<code>';
3520cecf9d5Sandi    }
3530cecf9d5Sandi
3543dd5c225SAndreas Gohr    /**
3553dd5c225SAndreas Gohr     * Stop monospace formatting
3563dd5c225SAndreas Gohr     */
357de369923SAndreas Gohr    public function monospace_close() {
358a2d649c4Sandi        $this->doc .= '</code>';
3590cecf9d5Sandi    }
3600cecf9d5Sandi
3613dd5c225SAndreas Gohr    /**
3623dd5c225SAndreas Gohr     * Start a subscript
3633dd5c225SAndreas Gohr     */
364de369923SAndreas Gohr    public function subscript_open() {
365a2d649c4Sandi        $this->doc .= '<sub>';
3660cecf9d5Sandi    }
3670cecf9d5Sandi
3683dd5c225SAndreas Gohr    /**
3693dd5c225SAndreas Gohr     * Stop a subscript
3703dd5c225SAndreas Gohr     */
371de369923SAndreas Gohr    public function subscript_close() {
372a2d649c4Sandi        $this->doc .= '</sub>';
3730cecf9d5Sandi    }
3740cecf9d5Sandi
3753dd5c225SAndreas Gohr    /**
3763dd5c225SAndreas Gohr     * Start a superscript
3773dd5c225SAndreas Gohr     */
378de369923SAndreas Gohr    public function superscript_open() {
379a2d649c4Sandi        $this->doc .= '<sup>';
3800cecf9d5Sandi    }
3810cecf9d5Sandi
3823dd5c225SAndreas Gohr    /**
3833dd5c225SAndreas Gohr     * Stop a superscript
3843dd5c225SAndreas Gohr     */
385de369923SAndreas Gohr    public function superscript_close() {
386a2d649c4Sandi        $this->doc .= '</sup>';
3870cecf9d5Sandi    }
3880cecf9d5Sandi
3893dd5c225SAndreas Gohr    /**
3903dd5c225SAndreas Gohr     * Start deleted (strike-through) formatting
3913dd5c225SAndreas Gohr     */
392de369923SAndreas Gohr    public function deleted_open() {
393a2d649c4Sandi        $this->doc .= '<del>';
3940cecf9d5Sandi    }
3950cecf9d5Sandi
3963dd5c225SAndreas Gohr    /**
3973dd5c225SAndreas Gohr     * Stop deleted (strike-through) formatting
3983dd5c225SAndreas Gohr     */
399de369923SAndreas Gohr    public function deleted_close() {
400a2d649c4Sandi        $this->doc .= '</del>';
4010cecf9d5Sandi    }
4020cecf9d5Sandi
4033fd0b676Sandi    /**
4043fd0b676Sandi     * Callback for footnote start syntax
4053fd0b676Sandi     *
4063fd0b676Sandi     * All following content will go to the footnote instead of
407d74aace9Schris     * the document. To achieve this the previous rendered content
4083fd0b676Sandi     * is moved to $store and $doc is cleared
4093fd0b676Sandi     *
4103fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
4113fd0b676Sandi     */
412de369923SAndreas Gohr    public function footnote_open() {
4137764a90aSandi
4147764a90aSandi        // move current content to store and record footnote
4157764a90aSandi        $this->store = $this->doc;
4167764a90aSandi        $this->doc   = '';
4170cecf9d5Sandi    }
4180cecf9d5Sandi
4193fd0b676Sandi    /**
4203fd0b676Sandi     * Callback for footnote end syntax
4213fd0b676Sandi     *
4223fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
4233fd0b676Sandi     * content is restored from $store again
4243fd0b676Sandi     *
4253fd0b676Sandi     * @author Andreas Gohr
4263fd0b676Sandi     */
427de369923SAndreas Gohr    public function footnote_close() {
42816ec3e37SAndreas Gohr        /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */
42916ec3e37SAndreas Gohr        static $fnid = 0;
43016ec3e37SAndreas Gohr        // assign new footnote id (we start at 1)
43116ec3e37SAndreas Gohr        $fnid++;
4327764a90aSandi
433d74aace9Schris        // recover footnote into the stack and restore old content
434d74aace9Schris        $footnote    = $this->doc;
4357764a90aSandi        $this->doc   = $this->store;
4367764a90aSandi        $this->store = '';
437d74aace9Schris
438d74aace9Schris        // check to see if this footnote has been seen before
439d74aace9Schris        $i = array_search($footnote, $this->footnotes);
440d74aace9Schris
441d74aace9Schris        if($i === false) {
442d74aace9Schris            // its a new footnote, add it to the $footnotes array
44316ec3e37SAndreas Gohr            $this->footnotes[$fnid] = $footnote;
444d74aace9Schris        } else {
44516ec3e37SAndreas Gohr            // seen this one before, save a placeholder
44616ec3e37SAndreas Gohr            $this->footnotes[$fnid] = "@@FNT".($i);
447d74aace9Schris        }
448d74aace9Schris
4496b379cbfSAndreas Gohr        // output the footnote reference and link
45016ec3e37SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>';
4510cecf9d5Sandi    }
4520cecf9d5Sandi
4533dd5c225SAndreas Gohr    /**
4543dd5c225SAndreas Gohr     * Open an unordered list
4550c4c0281SGerrit Uitslag     *
4567d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
4573dd5c225SAndreas Gohr     */
458de369923SAndreas Gohr    public function listu_open($classes = null) {
4590c4c0281SGerrit Uitslag        $class = '';
4600c4c0281SGerrit Uitslag        if($classes !== null) {
4612e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
4620c4c0281SGerrit Uitslag            $class = " class=\"$classes\"";
4630c4c0281SGerrit Uitslag        }
4640c4c0281SGerrit Uitslag        $this->doc .= "<ul$class>".DOKU_LF;
4650cecf9d5Sandi    }
4660cecf9d5Sandi
4673dd5c225SAndreas Gohr    /**
4683dd5c225SAndreas Gohr     * Close an unordered list
4693dd5c225SAndreas Gohr     */
470de369923SAndreas Gohr    public function listu_close() {
471a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
4720cecf9d5Sandi    }
4730cecf9d5Sandi
4743dd5c225SAndreas Gohr    /**
4753dd5c225SAndreas Gohr     * Open an ordered list
4760c4c0281SGerrit Uitslag     *
4777d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
4783dd5c225SAndreas Gohr     */
479de369923SAndreas Gohr    public function listo_open($classes = null) {
4800c4c0281SGerrit Uitslag        $class = '';
4810c4c0281SGerrit Uitslag        if($classes !== null) {
4822e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
4830c4c0281SGerrit Uitslag            $class = " class=\"$classes\"";
4840c4c0281SGerrit Uitslag        }
4850c4c0281SGerrit Uitslag        $this->doc .= "<ol$class>".DOKU_LF;
4860cecf9d5Sandi    }
4870cecf9d5Sandi
4883dd5c225SAndreas Gohr    /**
4893dd5c225SAndreas Gohr     * Close an ordered list
4903dd5c225SAndreas Gohr     */
491de369923SAndreas Gohr    public function listo_close() {
492a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
4930cecf9d5Sandi    }
4940cecf9d5Sandi
4953dd5c225SAndreas Gohr    /**
4963dd5c225SAndreas Gohr     * Open a list item
4973dd5c225SAndreas Gohr     *
4983dd5c225SAndreas Gohr     * @param int $level the nesting level
499e3a24861SChristopher Smith     * @param bool $node true when a node; false when a leaf
5003dd5c225SAndreas Gohr     */
501de369923SAndreas Gohr    public function listitem_open($level, $node=false) {
502e3a24861SChristopher Smith        $branching = $node ? ' node' : '';
503e3a24861SChristopher Smith        $this->doc .= '<li class="level'.$level.$branching.'">';
5040cecf9d5Sandi    }
5050cecf9d5Sandi
5063dd5c225SAndreas Gohr    /**
5073dd5c225SAndreas Gohr     * Close a list item
5083dd5c225SAndreas Gohr     */
509de369923SAndreas Gohr    public function listitem_close() {
510a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
5110cecf9d5Sandi    }
5120cecf9d5Sandi
5133dd5c225SAndreas Gohr    /**
5143dd5c225SAndreas Gohr     * Start the content of a list item
5153dd5c225SAndreas Gohr     */
516de369923SAndreas Gohr    public function listcontent_open() {
51790db23d7Schris        $this->doc .= '<div class="li">';
5180cecf9d5Sandi    }
5190cecf9d5Sandi
5203dd5c225SAndreas Gohr    /**
5213dd5c225SAndreas Gohr     * Stop the content of a list item
5223dd5c225SAndreas Gohr     */
523de369923SAndreas Gohr    public function listcontent_close() {
52459869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
5250cecf9d5Sandi    }
5260cecf9d5Sandi
5273dd5c225SAndreas Gohr    /**
5283dd5c225SAndreas Gohr     * Output unformatted $text
5293dd5c225SAndreas Gohr     *
5303dd5c225SAndreas Gohr     * Defaults to $this->cdata()
5313dd5c225SAndreas Gohr     *
5323dd5c225SAndreas Gohr     * @param string $text
5333dd5c225SAndreas Gohr     */
534de369923SAndreas Gohr    public function unformatted($text) {
535a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
5360cecf9d5Sandi    }
5370cecf9d5Sandi
5380cecf9d5Sandi    /**
5393fd0b676Sandi     * Execute PHP code if allowed
5403fd0b676Sandi     *
541d9764001SMichael Hamann     * @param  string $text      PHP code that is either executed or printed
5425d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['phpok'] is okff
5435d568b99SChris Smith     *
5443fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5450cecf9d5Sandi     */
546de369923SAndreas Gohr    public function php($text, $wrapper = 'code') {
54735a56260SChris Smith        global $conf;
54835a56260SChris Smith
549d86d5af0SChris Smith        if($conf['phpok']) {
550bad0b545Sandi            ob_start();
5514de671bcSandi            eval($text);
5523fd0b676Sandi            $this->doc .= ob_get_contents();
553bad0b545Sandi            ob_end_clean();
554d86d5af0SChris Smith        } else {
5555d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
556d86d5af0SChris Smith        }
5570cecf9d5Sandi    }
5580cecf9d5Sandi
5593dd5c225SAndreas Gohr    /**
5603dd5c225SAndreas Gohr     * Output block level PHP code
5613dd5c225SAndreas Gohr     *
5623dd5c225SAndreas Gohr     * If $conf['phpok'] is true this should evaluate the given code and append the result
5633dd5c225SAndreas Gohr     * to $doc
5643dd5c225SAndreas Gohr     *
5653dd5c225SAndreas Gohr     * @param string $text The PHP code
5663dd5c225SAndreas Gohr     */
567de369923SAndreas Gohr    public function phpblock($text) {
5685d568b99SChris Smith        $this->php($text, 'pre');
56907f89c3cSAnika Henke    }
57007f89c3cSAnika Henke
5710cecf9d5Sandi    /**
5723fd0b676Sandi     * Insert HTML if allowed
5733fd0b676Sandi     *
574d9764001SMichael Hamann     * @param  string $text      html text
5755d568b99SChris Smith     * @param  string $wrapper   html element to wrap result if $conf['htmlok'] is okff
5765d568b99SChris Smith     *
5773fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
5780cecf9d5Sandi     */
579de369923SAndreas Gohr    public function html($text, $wrapper = 'code') {
58035a56260SChris Smith        global $conf;
58135a56260SChris Smith
582d86d5af0SChris Smith        if($conf['htmlok']) {
583a2d649c4Sandi            $this->doc .= $text;
584d86d5af0SChris Smith        } else {
5855d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
586d86d5af0SChris Smith        }
5874de671bcSandi    }
5880cecf9d5Sandi
5893dd5c225SAndreas Gohr    /**
5903dd5c225SAndreas Gohr     * Output raw block-level HTML
5913dd5c225SAndreas Gohr     *
5923dd5c225SAndreas Gohr     * If $conf['htmlok'] is true this should add the code as is to $doc
5933dd5c225SAndreas Gohr     *
5943dd5c225SAndreas Gohr     * @param string $text The HTML
5953dd5c225SAndreas Gohr     */
596de369923SAndreas Gohr    public function htmlblock($text) {
5975d568b99SChris Smith        $this->html($text, 'pre');
59807f89c3cSAnika Henke    }
59907f89c3cSAnika Henke
6003dd5c225SAndreas Gohr    /**
6013dd5c225SAndreas Gohr     * Start a block quote
6023dd5c225SAndreas Gohr     */
603de369923SAndreas Gohr    public function quote_open() {
60496331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
6050cecf9d5Sandi    }
6060cecf9d5Sandi
6073dd5c225SAndreas Gohr    /**
6083dd5c225SAndreas Gohr     * Stop a block quote
6093dd5c225SAndreas Gohr     */
610de369923SAndreas Gohr    public function quote_close() {
61196331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
6120cecf9d5Sandi    }
6130cecf9d5Sandi
6143dd5c225SAndreas Gohr    /**
6153dd5c225SAndreas Gohr     * Output preformatted text
6163dd5c225SAndreas Gohr     *
6173dd5c225SAndreas Gohr     * @param string $text
6183dd5c225SAndreas Gohr     */
619de369923SAndreas Gohr    public function preformatted($text) {
620c9250713SAnika Henke        $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.DOKU_LF;
6213d491f75SAndreas Gohr    }
6223d491f75SAndreas Gohr
6233dd5c225SAndreas Gohr    /**
6243dd5c225SAndreas Gohr     * Display text as file content, optionally syntax highlighted
6253dd5c225SAndreas Gohr     *
6263dd5c225SAndreas Gohr     * @param string $text     text to show
6273dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6283dd5c225SAndreas Gohr     * @param string $filename file path label
629e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6303dd5c225SAndreas Gohr     */
631de369923SAndreas Gohr    public function file($text, $language = null, $filename = null, $options=null) {
632e2d88156SLarsDW223        $this->_highlight('file', $text, $language, $filename, $options);
6333d491f75SAndreas Gohr    }
6343d491f75SAndreas Gohr
6353dd5c225SAndreas Gohr    /**
6363dd5c225SAndreas Gohr     * Display text as code content, optionally syntax highlighted
6373dd5c225SAndreas Gohr     *
6383dd5c225SAndreas Gohr     * @param string $text     text to show
6393dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6403dd5c225SAndreas Gohr     * @param string $filename file path label
641e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6423dd5c225SAndreas Gohr     */
643de369923SAndreas Gohr    public function code($text, $language = null, $filename = null, $options=null) {
644e2d88156SLarsDW223        $this->_highlight('code', $text, $language, $filename, $options);
6453d491f75SAndreas Gohr    }
6463d491f75SAndreas Gohr
6470cecf9d5Sandi    /**
6483d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
6493fd0b676Sandi     *
6503fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
6513dd5c225SAndreas Gohr     * @param string $type     code|file
6523dd5c225SAndreas Gohr     * @param string $text     text to show
6533dd5c225SAndreas Gohr     * @param string $language programming language to use for syntax highlighting
6543dd5c225SAndreas Gohr     * @param string $filename file path label
655e2d88156SLarsDW223     * @param array  $options  assoziative array with additional geshi options
6560cecf9d5Sandi     */
657de369923SAndreas Gohr    public function _highlight($type, $text, $language = null, $filename = null, $options = null) {
6583d491f75SAndreas Gohr        global $ID;
6593d491f75SAndreas Gohr        global $lang;
660ec57f119SLarsDW223        global $INPUT;
6613d491f75SAndreas Gohr
66256bd9509SPhy        $language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language);
66356bd9509SPhy
6643d491f75SAndreas Gohr        if($filename) {
665190c56e8SAndreas Gohr            // add icon
66627bf7924STom N Harris            list($ext) = mimetype($filename, false);
667190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
668190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
669190c56e8SAndreas Gohr
670ec57f119SLarsDW223            $offset = 0;
671ec57f119SLarsDW223            if ($INPUT->has('codeblockOffset')) {
672ec57f119SLarsDW223                $offset = $INPUT->str('codeblockOffset');
673ec57f119SLarsDW223            }
6743d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
67564159a61SAndreas Gohr            $this->doc .= '<dt><a href="' .
67664159a61SAndreas Gohr                exportlink(
67764159a61SAndreas Gohr                    $ID,
67864159a61SAndreas Gohr                    'code',
67964159a61SAndreas Gohr                    array('codeblock' => $offset + $this->_codeblock)
68064159a61SAndreas Gohr                ) . '" title="' . $lang['download'] . '" class="' . $class . '">';
6813d491f75SAndreas Gohr            $this->doc .= hsc($filename);
6823d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
6833d491f75SAndreas Gohr        }
6840cecf9d5Sandi
6852401f18dSSyntaxseed        if($text[0] == "\n") {
686d43aac1cSGina Haeussge            $text = substr($text, 1);
687d43aac1cSGina Haeussge        }
688d43aac1cSGina Haeussge        if(substr($text, -1) == "\n") {
689d43aac1cSGina Haeussge            $text = substr($text, 0, -1);
690d43aac1cSGina Haeussge        }
691d43aac1cSGina Haeussge
692a056e285SPhy        if(empty($language)) { // empty is faster than is_null and can prevent '' string
6933d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
6940cecf9d5Sandi        } else {
6953d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
6963d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
6973d491f75SAndreas Gohr
69864159a61SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">" .
69964159a61SAndreas Gohr                p_xhtml_cached_geshi($text, $language, '', $options) .
70064159a61SAndreas Gohr                '</pre>' . DOKU_LF;
7010cecf9d5Sandi        }
7023d491f75SAndreas Gohr
7033d491f75SAndreas Gohr        if($filename) {
7043d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
7053d491f75SAndreas Gohr        }
7063d491f75SAndreas Gohr
7073d491f75SAndreas Gohr        $this->_codeblock++;
7080cecf9d5Sandi    }
7090cecf9d5Sandi
7103dd5c225SAndreas Gohr    /**
7113dd5c225SAndreas Gohr     * Format an acronym
7123dd5c225SAndreas Gohr     *
7133dd5c225SAndreas Gohr     * Uses $this->acronyms
7143dd5c225SAndreas Gohr     *
7153dd5c225SAndreas Gohr     * @param string $acronym
7163dd5c225SAndreas Gohr     */
717de369923SAndreas Gohr    public function acronym($acronym) {
7180cecf9d5Sandi
7190cecf9d5Sandi        if(array_key_exists($acronym, $this->acronyms)) {
7200cecf9d5Sandi
721433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
7220cecf9d5Sandi
723940db3a3SAnika Henke            $this->doc .= '<abbr title="'.$title
724940db3a3SAnika Henke                .'">'.$this->_xmlEntities($acronym).'</abbr>';
7250cecf9d5Sandi
7260cecf9d5Sandi        } else {
727a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
7280cecf9d5Sandi        }
7290cecf9d5Sandi    }
7300cecf9d5Sandi
7313dd5c225SAndreas Gohr    /**
7323dd5c225SAndreas Gohr     * Format a smiley
7333dd5c225SAndreas Gohr     *
7343dd5c225SAndreas Gohr     * Uses $this->smiley
7353dd5c225SAndreas Gohr     *
7363dd5c225SAndreas Gohr     * @param string $smiley
7373dd5c225SAndreas Gohr     */
738de369923SAndreas Gohr    public function smiley($smiley) {
7390cecf9d5Sandi        if(array_key_exists($smiley, $this->smileys)) {
740f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
7418e38227fSAnika Henke                '" class="icon" alt="'.
742433bef32Sandi                $this->_xmlEntities($smiley).'" />';
7430cecf9d5Sandi        } else {
744a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
7450cecf9d5Sandi        }
7460cecf9d5Sandi    }
7470cecf9d5Sandi
7483dd5c225SAndreas Gohr    /**
7493dd5c225SAndreas Gohr     * Format an entity
7503dd5c225SAndreas Gohr     *
7513dd5c225SAndreas Gohr     * Entities are basically small text replacements
7523dd5c225SAndreas Gohr     *
7533dd5c225SAndreas Gohr     * Uses $this->entities
7543dd5c225SAndreas Gohr     *
7553dd5c225SAndreas Gohr     * @param string $entity
7564de671bcSandi     */
757de369923SAndreas Gohr    public function entity($entity) {
7580cecf9d5Sandi        if(array_key_exists($entity, $this->entities)) {
759a2d649c4Sandi            $this->doc .= $this->entities[$entity];
7600cecf9d5Sandi        } else {
761a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
7620cecf9d5Sandi        }
7630cecf9d5Sandi    }
7640cecf9d5Sandi
7653dd5c225SAndreas Gohr    /**
7663dd5c225SAndreas Gohr     * Typographically format a multiply sign
7673dd5c225SAndreas Gohr     *
7683dd5c225SAndreas Gohr     * Example: ($x=640, $y=480) should result in "640×480"
7693dd5c225SAndreas Gohr     *
7703dd5c225SAndreas Gohr     * @param string|int $x first value
7713dd5c225SAndreas Gohr     * @param string|int $y second value
7723dd5c225SAndreas Gohr     */
773de369923SAndreas Gohr    public function multiplyentity($x, $y) {
774a2d649c4Sandi        $this->doc .= "$x&times;$y";
7750cecf9d5Sandi    }
7760cecf9d5Sandi
7773dd5c225SAndreas Gohr    /**
7783dd5c225SAndreas Gohr     * Render an opening single quote char (language specific)
7793dd5c225SAndreas Gohr     */
780de369923SAndreas Gohr    public function singlequoteopening() {
78171b40da2SAnika Henke        global $lang;
78271b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
7830cecf9d5Sandi    }
7840cecf9d5Sandi
7853dd5c225SAndreas Gohr    /**
7863dd5c225SAndreas Gohr     * Render a closing single quote char (language specific)
7873dd5c225SAndreas Gohr     */
788de369923SAndreas Gohr    public function singlequoteclosing() {
78971b40da2SAnika Henke        global $lang;
79071b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
7910cecf9d5Sandi    }
7920cecf9d5Sandi
7933dd5c225SAndreas Gohr    /**
7943dd5c225SAndreas Gohr     * Render an apostrophe char (language specific)
7953dd5c225SAndreas Gohr     */
796de369923SAndreas Gohr    public function apostrophe() {
79757d757d1SAndreas Gohr        global $lang;
798a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
79957d757d1SAndreas Gohr    }
80057d757d1SAndreas Gohr
8013dd5c225SAndreas Gohr    /**
8023dd5c225SAndreas Gohr     * Render an opening double quote char (language specific)
8033dd5c225SAndreas Gohr     */
804de369923SAndreas Gohr    public function doublequoteopening() {
80571b40da2SAnika Henke        global $lang;
80671b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
8070cecf9d5Sandi    }
8080cecf9d5Sandi
8093dd5c225SAndreas Gohr    /**
8103dd5c225SAndreas Gohr     * Render an closinging double quote char (language specific)
8113dd5c225SAndreas Gohr     */
812de369923SAndreas Gohr    public function doublequoteclosing() {
81371b40da2SAnika Henke        global $lang;
81471b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
8150cecf9d5Sandi    }
8160cecf9d5Sandi
8170cecf9d5Sandi    /**
8183dd5c225SAndreas Gohr     * Render a CamelCase link
8193dd5c225SAndreas Gohr     *
8203dd5c225SAndreas Gohr     * @param string $link       The link name
821122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
8220c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
8230c4c0281SGerrit Uitslag     *
8243dd5c225SAndreas Gohr     * @see http://en.wikipedia.org/wiki/CamelCase
8250cecf9d5Sandi     */
826de369923SAndreas Gohr    public function camelcaselink($link, $returnonly = false) {
827122f2d46SAndreas Böhler        if($returnonly) {
828122f2d46SAndreas Böhler          return $this->internallink($link, $link, null, true);
829122f2d46SAndreas Böhler        } else {
83011d0aa47Sandi          $this->internallink($link, $link);
8310cecf9d5Sandi        }
832122f2d46SAndreas Böhler    }
8330cecf9d5Sandi
8343dd5c225SAndreas Gohr    /**
8353dd5c225SAndreas Gohr     * Render a page local link
8363dd5c225SAndreas Gohr     *
8373dd5c225SAndreas Gohr     * @param string $hash       hash link identifier
8383dd5c225SAndreas Gohr     * @param string $name       name for the link
839122f2d46SAndreas Böhler     * @param bool   $returnonly whether to return html or write to doc attribute
8400c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
8413dd5c225SAndreas Gohr     */
842de369923SAndreas Gohr    public function locallink($hash, $name = null, $returnonly = false) {
8430b7c14c2Sandi        global $ID;
8440b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
8450b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
846e260f93bSAnika Henke        $title = $ID.' ↵';
847122f2d46SAndreas Böhler
848122f2d46SAndreas Böhler        $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
849122f2d46SAndreas Böhler        $doc .= $name;
850122f2d46SAndreas Böhler        $doc .= '</a>';
851122f2d46SAndreas Böhler
852122f2d46SAndreas Böhler        if($returnonly) {
853122f2d46SAndreas Böhler          return $doc;
854122f2d46SAndreas Böhler        } else {
855122f2d46SAndreas Böhler          $this->doc .= $doc;
856122f2d46SAndreas Böhler        }
8570b7c14c2Sandi    }
8580b7c14c2Sandi
859cffcc403Sandi    /**
8603fd0b676Sandi     * Render an internal Wiki Link
8613fd0b676Sandi     *
862fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
863cffcc403Sandi     * elsewhere - no need to implement them in other renderers
8643fd0b676Sandi     *
8653dd5c225SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
866f23eef27SGerrit Uitslag     * @param string      $id         pageid
867f23eef27SGerrit Uitslag     * @param string|null $name       link name
868f23eef27SGerrit Uitslag     * @param string|null $search     adds search url param
869f23eef27SGerrit Uitslag     * @param bool        $returnonly whether to return html or write to doc attribute
870f23eef27SGerrit Uitslag     * @param string      $linktype   type to set use of headings
871f23eef27SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
872cffcc403Sandi     */
873de369923SAndreas Gohr    public function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
874ba11bd29Sandi        global $conf;
87537e34a5eSandi        global $ID;
876c4dda6afSAnika Henke        global $INFO;
87744653a53SAdrian Lang
8783d5e07d9SAdrian Lang        $params = '';
8793d5e07d9SAdrian Lang        $parts  = explode('?', $id, 2);
8803d5e07d9SAdrian Lang        if(count($parts) === 2) {
8813d5e07d9SAdrian Lang            $id     = $parts[0];
8823d5e07d9SAdrian Lang            $params = $parts[1];
88344653a53SAdrian Lang        }
88444653a53SAdrian Lang
885fda14ffcSIzidor Matušov        // For empty $id we need to know the current $ID
886fda14ffcSIzidor Matušov        // We need this check because _simpleTitle needs
887fda14ffcSIzidor Matušov        // correct $id and resolve_pageid() use cleanID($id)
888fda14ffcSIzidor Matušov        // (some things could be lost)
889fda14ffcSIzidor Matušov        if($id === '') {
890fda14ffcSIzidor Matušov            $id = $ID;
891fda14ffcSIzidor Matušov        }
892fda14ffcSIzidor Matušov
8930339c872Sjan        // default name is based on $id as given
8940339c872Sjan        $default = $this->_simpleTitle($id);
895ad32e47eSAndreas Gohr
8960339c872Sjan        // now first resolve and clean up the $id
897*8c6be208SAndreas Gohr        $id = (new PageResolver($ID))->resolveId($id, $this->date_at, true);
898*8c6be208SAndreas Gohr        $exists = page_exists($id, $this->date_at, false, true);
899fda14ffcSIzidor Matušov
90059bc3b48SGerrit Uitslag        $link = array();
901fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
9020e1c636eSandi        if(!$isImage) {
9030e1c636eSandi            if($exists) {
904ba11bd29Sandi                $class = 'wikilink1';
9050cecf9d5Sandi            } else {
906ba11bd29Sandi                $class       = 'wikilink2';
90744a6b4c7SAndreas Gohr                $link['rel'] = 'nofollow';
9080cecf9d5Sandi            }
9090cecf9d5Sandi        } else {
910ba11bd29Sandi            $class = 'media';
9110cecf9d5Sandi        }
9120cecf9d5Sandi
913a1685bedSandi        //keep hash anchor
9146d2af55dSChristopher Smith        @list($id, $hash) = explode('#', $id, 2);
915943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
916a1685bedSandi
917ba11bd29Sandi        //prepare for formating
918ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
919ba11bd29Sandi        $link['style']  = '';
920ba11bd29Sandi        $link['pre']    = '';
921ba11bd29Sandi        $link['suf']    = '';
922bbac1489SPhy        $link['more']   = 'data-wiki-id="'.$id.'"'; // id is already cleaned
923ba11bd29Sandi        $link['class']  = $class;
9245c2eed9aSlisps        if($this->date_at) {
925912a6d48SPhy            $params = $params.'&at='.rawurlencode($this->date_at);
9265c2eed9aSlisps        }
92744653a53SAdrian Lang        $link['url']    = wl($id, $params);
928ba11bd29Sandi        $link['name']   = $name;
929ba11bd29Sandi        $link['title']  = $id;
930723d78dbSandi        //add search string
931723d78dbSandi        if($search) {
932546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&amp;';
933546d3a99SAndreas Gohr            if(is_array($search)) {
934546d3a99SAndreas Gohr                $search = array_map('rawurlencode', $search);
935546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=', $search);
936546d3a99SAndreas Gohr            } else {
937546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
938546d3a99SAndreas Gohr            }
939723d78dbSandi        }
940723d78dbSandi
941a1685bedSandi        //keep hash
942a1685bedSandi        if($hash) $link['url'] .= '#'.$hash;
943a1685bedSandi
944ba11bd29Sandi        //output formatted
945cffcc403Sandi        if($returnonly) {
946cffcc403Sandi            return $this->_formatLink($link);
947cffcc403Sandi        } else {
948a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
9490cecf9d5Sandi        }
950cffcc403Sandi    }
9510cecf9d5Sandi
9523dd5c225SAndreas Gohr    /**
9533dd5c225SAndreas Gohr     * Render an external link
9543dd5c225SAndreas Gohr     *
9553dd5c225SAndreas Gohr     * @param string       $url        full URL with scheme
9563dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
957122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
9580c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
9593dd5c225SAndreas Gohr     */
960de369923SAndreas Gohr    public function externallink($url, $name = null, $returnonly = false) {
961b625487dSandi        global $conf;
9620cecf9d5Sandi
963433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
9646f0c5dbfSandi
965b52b1596SAndreas Gohr        // url might be an attack vector, only allow registered protocols
966b52b1596SAndreas Gohr        if(is_null($this->schemes)) $this->schemes = getSchemes();
967b52b1596SAndreas Gohr        list($scheme) = explode('://', $url);
968b52b1596SAndreas Gohr        $scheme = strtolower($scheme);
969b52b1596SAndreas Gohr        if(!in_array($scheme, $this->schemes)) $url = '';
970b52b1596SAndreas Gohr
971b52b1596SAndreas Gohr        // is there still an URL?
972b52b1596SAndreas Gohr        if(!$url) {
97349cef4fdSAndreas Böhler            if($returnonly) {
97449cef4fdSAndreas Böhler                return $name;
97549cef4fdSAndreas Böhler            } else {
976b52b1596SAndreas Gohr                $this->doc .= $name;
97749cef4fdSAndreas Böhler            }
978b52b1596SAndreas Gohr            return;
979b52b1596SAndreas Gohr        }
980b52b1596SAndreas Gohr
981b52b1596SAndreas Gohr        // set class
9820cecf9d5Sandi        if(!$isImage) {
983b625487dSandi            $class = 'urlextern';
9840cecf9d5Sandi        } else {
985b625487dSandi            $class = 'media';
9860cecf9d5Sandi        }
9870cecf9d5Sandi
988b625487dSandi        //prepare for formating
98959bc3b48SGerrit Uitslag        $link = array();
990b625487dSandi        $link['target'] = $conf['target']['extern'];
991b625487dSandi        $link['style']  = '';
992b625487dSandi        $link['pre']    = '';
993b625487dSandi        $link['suf']    = '';
9945e163278SAndreas Gohr        $link['more']   = '';
995b625487dSandi        $link['class']  = $class;
996b625487dSandi        $link['url']    = $url;
997914045f3SAndreas Gohr        $link['rel']    = '';
998e1c10e4dSchris
999b625487dSandi        $link['name']  = $name;
1000433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
10015ddd0bbbSStarArmy        if($conf['relnofollow']) $link['rel'] .= ' ugc nofollow';
1002914045f3SAndreas Gohr        if($conf['target']['extern']) $link['rel'] .= ' noopener';
10030cecf9d5Sandi
1004b625487dSandi        //output formatted
1005122f2d46SAndreas Böhler        if($returnonly) {
1006122f2d46SAndreas Böhler            return $this->_formatLink($link);
1007122f2d46SAndreas Böhler        } else {
1008a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
10090cecf9d5Sandi        }
1010122f2d46SAndreas Böhler    }
10110cecf9d5Sandi
10120cecf9d5Sandi    /**
10133dd5c225SAndreas Gohr     * Render an interwiki link
10143dd5c225SAndreas Gohr     *
10153dd5c225SAndreas Gohr     * You may want to use $this->_resolveInterWiki() here
10163dd5c225SAndreas Gohr     *
10173dd5c225SAndreas Gohr     * @param string       $match      original link - probably not much use
10183dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
10193dd5c225SAndreas Gohr     * @param string       $wikiName   indentifier (shortcut) for the remote wiki
10203dd5c225SAndreas Gohr     * @param string       $wikiUri    the fragment parsed from the original link
1021122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10220c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
10230cecf9d5Sandi     */
1024de369923SAndreas Gohr    public function interwikilink($match, $name, $wikiName, $wikiUri, $returnonly = false) {
1025b625487dSandi        global $conf;
10260cecf9d5Sandi
102797a3e4e3Sandi        $link           = array();
102897a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
102997a3e4e3Sandi        $link['pre']    = '';
103097a3e4e3Sandi        $link['suf']    = '';
10315e163278SAndreas Gohr        $link['more']   = '';
1032433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
1033914045f3SAndreas Gohr        $link['rel']    = '';
10340cecf9d5Sandi
103597a3e4e3Sandi        //get interwiki URL
10366496c33fSGerrit Uitslag        $exists = null;
10376496c33fSGerrit Uitslag        $url    = $this->_resolveInterWiki($wikiName, $wikiUri, $exists);
10380cecf9d5Sandi
103997a3e4e3Sandi        if(!$isImage) {
10409d2ddea4SAndreas Gohr            $class         = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName);
10419d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
10421c2d1019SAndreas Gohr        } else {
10431c2d1019SAndreas Gohr            $link['class'] = 'media';
104497a3e4e3Sandi        }
10450cecf9d5Sandi
104697a3e4e3Sandi        //do we stay at the same server? Use local target
10472345e871SGerrit Uitslag        if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) {
104897a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
104997a3e4e3Sandi        }
10506496c33fSGerrit Uitslag        if($exists !== null && !$isImage) {
10516496c33fSGerrit Uitslag            if($exists) {
10526496c33fSGerrit Uitslag                $link['class'] .= ' wikilink1';
10536496c33fSGerrit Uitslag            } else {
10546496c33fSGerrit Uitslag                $link['class'] .= ' wikilink2';
1055914045f3SAndreas Gohr                $link['rel'] .= ' nofollow';
10566496c33fSGerrit Uitslag            }
10576496c33fSGerrit Uitslag        }
1058914045f3SAndreas Gohr        if($conf['target']['interwiki']) $link['rel'] .= ' noopener';
10590cecf9d5Sandi
106097a3e4e3Sandi        $link['url']   = $url;
106197a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
106297a3e4e3Sandi
106397a3e4e3Sandi        // output formatted
1064122f2d46SAndreas Böhler        if($returnonly) {
1065abde5980SPhy            if($url == '') return $link['name'];
1066122f2d46SAndreas Böhler            return $this->_formatLink($link);
1067122f2d46SAndreas Böhler        } else {
1068abde5980SPhy            if($url == '') $this->doc .= $link['name'];
1069abde5980SPhy            else $this->doc .= $this->_formatLink($link);
10700cecf9d5Sandi        }
1071122f2d46SAndreas Böhler    }
10720cecf9d5Sandi
10730cecf9d5Sandi    /**
10743dd5c225SAndreas Gohr     * Link to windows share
10753dd5c225SAndreas Gohr     *
10763dd5c225SAndreas Gohr     * @param string       $url        the link
10773dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1078122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
10790c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
10800cecf9d5Sandi     */
1081de369923SAndreas Gohr    public function windowssharelink($url, $name = null, $returnonly = false) {
10821d47afe1Sandi        global $conf;
10833dd5c225SAndreas Gohr
10841d47afe1Sandi        //simple setup
108559bc3b48SGerrit Uitslag        $link = array();
10861d47afe1Sandi        $link['target'] = $conf['target']['windows'];
10871d47afe1Sandi        $link['pre']    = '';
10881d47afe1Sandi        $link['suf']    = '';
10891d47afe1Sandi        $link['style']  = '';
10900cecf9d5Sandi
1091433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
10920cecf9d5Sandi        if(!$isImage) {
10931d47afe1Sandi            $link['class'] = 'windows';
10940cecf9d5Sandi        } else {
10951d47afe1Sandi            $link['class'] = 'media';
10960cecf9d5Sandi        }
10970cecf9d5Sandi
1098433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
10991d47afe1Sandi        $url           = str_replace('\\', '/', $url);
11001d47afe1Sandi        $url           = 'file:///'.$url;
11011d47afe1Sandi        $link['url']   = $url;
11020cecf9d5Sandi
11031d47afe1Sandi        //output formatted
1104122f2d46SAndreas Böhler        if($returnonly) {
1105122f2d46SAndreas Böhler            return $this->_formatLink($link);
1106122f2d46SAndreas Böhler        } else {
1107a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
11080cecf9d5Sandi        }
1109122f2d46SAndreas Böhler    }
11100cecf9d5Sandi
11113dd5c225SAndreas Gohr    /**
11123dd5c225SAndreas Gohr     * Render a linked E-Mail Address
11133dd5c225SAndreas Gohr     *
11143dd5c225SAndreas Gohr     * Honors $conf['mailguard'] setting
11153dd5c225SAndreas Gohr     *
11163dd5c225SAndreas Gohr     * @param string       $address    Email-Address
11173dd5c225SAndreas Gohr     * @param string|array $name       name for the link, array for media file
1118122f2d46SAndreas Böhler     * @param bool         $returnonly whether to return html or write to doc attribute
11190c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $returnonly
11203dd5c225SAndreas Gohr     */
1121de369923SAndreas Gohr    public function emaillink($address, $name = null, $returnonly = false) {
112271352defSandi        global $conf;
112371352defSandi        //simple setup
112471352defSandi        $link           = array();
112571352defSandi        $link['target'] = '';
112671352defSandi        $link['pre']    = '';
112771352defSandi        $link['suf']    = '';
112871352defSandi        $link['style']  = '';
112971352defSandi        $link['more']   = '';
11300cecf9d5Sandi
1131c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
11320cecf9d5Sandi        if(!$isImage) {
1133be96545cSAnika Henke            $link['class'] = 'mail';
11340cecf9d5Sandi        } else {
1135be96545cSAnika Henke            $link['class'] = 'media';
11360cecf9d5Sandi        }
11370cecf9d5Sandi
113807738714SAndreas Gohr        $address = $this->_xmlEntities($address);
113900a7b5adSEsther Brunner        $address = obfuscate($address);
114000a7b5adSEsther Brunner        $title   = $address;
11418c128049SAndreas Gohr
114271352defSandi        if(empty($name)) {
114300a7b5adSEsther Brunner            $name = $address;
114471352defSandi        }
11450cecf9d5Sandi
1146776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
1147776b36ecSAndreas Gohr
1148776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
114971352defSandi        $link['name']  = $name;
115071352defSandi        $link['title'] = $title;
11510cecf9d5Sandi
115271352defSandi        //output formatted
1153122f2d46SAndreas Böhler        if($returnonly) {
1154122f2d46SAndreas Böhler            return $this->_formatLink($link);
1155122f2d46SAndreas Böhler        } else {
1156a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
11570cecf9d5Sandi        }
1158122f2d46SAndreas Böhler    }
11590cecf9d5Sandi
11603dd5c225SAndreas Gohr    /**
11613dd5c225SAndreas Gohr     * Render an internal media file
11623dd5c225SAndreas Gohr     *
11633dd5c225SAndreas Gohr     * @param string $src       media ID
11643dd5c225SAndreas Gohr     * @param string $title     descriptive text
11653dd5c225SAndreas Gohr     * @param string $align     left|center|right
11663dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
11673dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
11683dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
11693dd5c225SAndreas Gohr     * @param string $linking   linkonly|detail|nolink
11703dd5c225SAndreas Gohr     * @param bool   $return    return HTML instead of adding to $doc
11710c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $return
11723dd5c225SAndreas Gohr     */
1173de369923SAndreas Gohr    public function internalmedia($src, $title = null, $align = null, $width = null,
11743dd5c225SAndreas Gohr                           $height = null, $cache = null, $linking = null, $return = false) {
117537e34a5eSandi        global $ID;
11768f34cf3dSMichael Große        if (strpos($src, '#') !== false) {
117791df343aSAndreas Gohr            list($src, $hash) = explode('#', $src, 2);
11788f34cf3dSMichael Große        }
1179*8c6be208SAndreas Gohr        $src = (new MediaResolver($ID))->resolveId($src,$this->date_at,true);
1180*8c6be208SAndreas Gohr        $exists = media_exists($src);
11810cecf9d5Sandi
1182d98d4540SBen Coburn        $noLink = false;
11838acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1184b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
11853685f775Sandi
11863dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1187b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
118864159a61SAndreas Gohr            $link['url'] = ml(
118964159a61SAndreas Gohr                $src,
119064159a61SAndreas Gohr                array(
119164159a61SAndreas Gohr                    'id' => $ID,
119264159a61SAndreas Gohr                    'cache' => $cache,
119364159a61SAndreas Gohr                    'rev' => $this->_getLastMediaRevisionAt($src)
119464159a61SAndreas Gohr                ),
119564159a61SAndreas Gohr                ($linking == 'direct')
119664159a61SAndreas Gohr            );
1197f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
11982a2a2ba2SAnika Henke            // don't link movies
119944881bd0Shenning.noren            $noLink = true;
120055efc227SAndreas Gohr        } else {
12012ca14335SEsther Brunner            // add file icons
12029d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
12039d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
120464159a61SAndreas Gohr            $link['url'] = ml(
120564159a61SAndreas Gohr                $src,
120664159a61SAndreas Gohr                array(
120764159a61SAndreas Gohr                    'id' => $ID,
120864159a61SAndreas Gohr                    'cache' => $cache,
120964159a61SAndreas Gohr                    'rev' => $this->_getLastMediaRevisionAt($src)
121064159a61SAndreas Gohr                ),
121164159a61SAndreas Gohr                true
121264159a61SAndreas Gohr            );
121391328684SMichael Hamann            if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')';
121455efc227SAndreas Gohr        }
12153685f775Sandi
12168f34cf3dSMichael Große        if (!empty($hash)) $link['url'] .= '#'.$hash;
121791df343aSAndreas Gohr
12186fe20453SGina Haeussge        //markup non existing files
12194a24b459SKate Arzamastseva        if(!$exists) {
12206fe20453SGina Haeussge            $link['class'] .= ' wikilink2';
12214a24b459SKate Arzamastseva        }
12226fe20453SGina Haeussge
12233685f775Sandi        //output formatted
1224f50634f0SAnika Henke        if($return) {
1225f50634f0SAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1226f50634f0SAnika Henke            else return $this->_formatLink($link);
1227f50634f0SAnika Henke        } else {
1228dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
12292ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
12300cecf9d5Sandi        }
1231f50634f0SAnika Henke    }
12320cecf9d5Sandi
12333dd5c225SAndreas Gohr    /**
12343dd5c225SAndreas Gohr     * Render an external media file
12353dd5c225SAndreas Gohr     *
12363dd5c225SAndreas Gohr     * @param string $src     full media URL
12373dd5c225SAndreas Gohr     * @param string $title   descriptive text
12383dd5c225SAndreas Gohr     * @param string $align   left|center|right
12393dd5c225SAndreas Gohr     * @param int    $width   width of media in pixel
12403dd5c225SAndreas Gohr     * @param int    $height  height of media in pixel
12413dd5c225SAndreas Gohr     * @param string $cache   cache|recache|nocache
12423dd5c225SAndreas Gohr     * @param string $linking linkonly|detail|nolink
1243410ee62aSAnika Henke     * @param bool   $return  return HTML instead of adding to $doc
12440c4c0281SGerrit Uitslag     * @return void|string writes to doc attribute or returns html depends on $return
12453dd5c225SAndreas Gohr     */
1246de369923SAndreas Gohr    public function externalmedia($src, $title = null, $align = null, $width = null,
1247410ee62aSAnika Henke                           $height = null, $cache = null, $linking = null, $return = false) {
12486efc45a2SDmitry Katsubo        if(link_isinterwiki($src)){
12496efc45a2SDmitry Katsubo            list($shortcut, $reference) = explode('>', $src, 2);
12506efc45a2SDmitry Katsubo            $exists = null;
12516efc45a2SDmitry Katsubo            $src = $this->_resolveInterWiki($shortcut, $reference, $exists);
1252abde5980SPhy            if($src == '' && empty($title)){
1253abde5980SPhy                // make sure at least something will be shown in this case
1254abde5980SPhy                $title = $reference;
1255abde5980SPhy            }
12566efc45a2SDmitry Katsubo        }
125791df343aSAndreas Gohr        list($src, $hash) = explode('#', $src, 2);
1258d98d4540SBen Coburn        $noLink = false;
1259abde5980SPhy        if($src == '') {
1260abde5980SPhy            // only output plaintext without link if there is no src
1261abde5980SPhy            $noLink = true;
1262abde5980SPhy        }
12638acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
1264b739ff0fSPierre Spring        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
1265b739ff0fSPierre Spring
1266b739ff0fSPierre Spring        $link['url'] = ml($src, array('cache' => $cache));
12673685f775Sandi
12683dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src, false);
1269b739ff0fSPierre Spring        if(substr($mime, 0, 5) == 'image' && $render) {
12702ca14335SEsther Brunner            // link only jpeg images
127144881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
1272f50634f0SAnika Henke        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
12732a2a2ba2SAnika Henke            // don't link movies
127444881bd0Shenning.noren            $noLink = true;
12752ca14335SEsther Brunner        } else {
12762ca14335SEsther Brunner            // add file icons
127727bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
127827bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
12792ca14335SEsther Brunner        }
12802ca14335SEsther Brunner
128191df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
128291df343aSAndreas Gohr
12833685f775Sandi        //output formatted
1284410ee62aSAnika Henke        if($return) {
1285410ee62aSAnika Henke            if($linking == 'nolink' || $noLink) return $link['name'];
1286410ee62aSAnika Henke            else return $this->_formatLink($link);
1287410ee62aSAnika Henke        } else {
1288dc673a5bSjoe.lapp            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
12892ca14335SEsther Brunner            else $this->doc .= $this->_formatLink($link);
12900cecf9d5Sandi        }
1291410ee62aSAnika Henke    }
12920cecf9d5Sandi
12934826ab45Sandi    /**
12943db95becSAndreas Gohr     * Renders an RSS feed
1295b625487dSandi     *
12960c4c0281SGerrit Uitslag     * @param string $url    URL of the feed
12970c4c0281SGerrit Uitslag     * @param array  $params Finetuning of the output
12980c4c0281SGerrit Uitslag     *
1299b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
1300b625487dSandi     */
1301de369923SAndreas Gohr    public function rss($url, $params) {
1302b625487dSandi        global $lang;
13033db95becSAndreas Gohr        global $conf;
13043db95becSAndreas Gohr
13053db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
13063db95becSAndreas Gohr        $feed = new FeedParser();
130700077af8SAndreas Gohr        $feed->set_feed_url($url);
1308b625487dSandi
1309b625487dSandi        //disable warning while fetching
13103dd5c225SAndreas Gohr        if(!defined('DOKU_E_LEVEL')) {
13113dd5c225SAndreas Gohr            $elvl = error_reporting(E_ERROR);
13123dd5c225SAndreas Gohr        }
13133db95becSAndreas Gohr        $rc = $feed->init();
13143dd5c225SAndreas Gohr        if(isset($elvl)) {
13153dd5c225SAndreas Gohr            error_reporting($elvl);
13163dd5c225SAndreas Gohr        }
1317b625487dSandi
131838c6f603SRobin H. Johnson        if($params['nosort']) $feed->enable_order_by_date(false);
131938c6f603SRobin H. Johnson
13203db95becSAndreas Gohr        //decide on start and end
13213db95becSAndreas Gohr        if($params['reverse']) {
13223db95becSAndreas Gohr            $mod   = -1;
13233db95becSAndreas Gohr            $start = $feed->get_item_quantity() - 1;
13243db95becSAndreas Gohr            $end   = $start - ($params['max']);
1325b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
13263db95becSAndreas Gohr        } else {
13273db95becSAndreas Gohr            $mod   = 1;
13283db95becSAndreas Gohr            $start = 0;
13293db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
1330d91ab76fSMatt Perry            $end   = ($end > $params['max']) ? $params['max'] : $end;
13313db95becSAndreas Gohr        }
13323db95becSAndreas Gohr
1333a2d649c4Sandi        $this->doc .= '<ul class="rss">';
13343db95becSAndreas Gohr        if($rc) {
13353db95becSAndreas Gohr            for($x = $start; $x != $end; $x += $mod) {
13361bde1582SAndreas Gohr                $item = $feed->get_item($x);
13373db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
1338d2ea3363SAndreas Gohr                // support feeds without links
1339d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
1340d2ea3363SAndreas Gohr                if($lnkurl) {
1341793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
1342793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
13433dd5c225SAndreas Gohr                    $this->externallink(
13443dd5c225SAndreas Gohr                        $item->get_permalink(),
13453dd5c225SAndreas Gohr                        html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')
13463dd5c225SAndreas Gohr                    );
1347d2ea3363SAndreas Gohr                } else {
1348d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
1349d2ea3363SAndreas Gohr                }
13503db95becSAndreas Gohr                if($params['author']) {
13511bde1582SAndreas Gohr                    $author = $item->get_author(0);
13521bde1582SAndreas Gohr                    if($author) {
13531bde1582SAndreas Gohr                        $name = $author->get_name();
13541bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
1355163c2842SPhy                        if($name) $this->doc .= ' '.$lang['by'].' '.hsc($name);
13561bde1582SAndreas Gohr                    }
13573db95becSAndreas Gohr                }
13583db95becSAndreas Gohr                if($params['date']) {
13592e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
13603db95becSAndreas Gohr                }
13611bde1582SAndreas Gohr                if($params['details']) {
13623db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
1363173dccb7STom N Harris                    if($conf['htmlok']) {
13641bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
13653db95becSAndreas Gohr                    } else {
13661bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
13673db95becSAndreas Gohr                    }
13683db95becSAndreas Gohr                    $this->doc .= '</div>';
13693db95becSAndreas Gohr                }
13703db95becSAndreas Gohr
13713db95becSAndreas Gohr                $this->doc .= '</div></li>';
1372b625487dSandi            }
1373b625487dSandi        } else {
13743db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
1375a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
1376b625487dSandi            $this->externallink($url);
137745e147ccSAndreas Gohr            if($conf['allowdebug']) {
137845e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
137945e147ccSAndreas Gohr            }
13803db95becSAndreas Gohr            $this->doc .= '</div></li>';
1381b625487dSandi        }
1382a2d649c4Sandi        $this->doc .= '</ul>';
1383b625487dSandi    }
1384b625487dSandi
13853dd5c225SAndreas Gohr    /**
13863dd5c225SAndreas Gohr     * Start a table
13873dd5c225SAndreas Gohr     *
13883dd5c225SAndreas Gohr     * @param int $maxcols maximum number of columns
13893dd5c225SAndreas Gohr     * @param int $numrows NOT IMPLEMENTED
13903dd5c225SAndreas Gohr     * @param int $pos byte position in the original source
13917d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
13923dd5c225SAndreas Gohr     */
1393de369923SAndreas Gohr    public function table_open($maxcols = null, $numrows = null, $pos = null, $classes = null) {
1394b5742cedSPierre Spring        // initialize the row counter used for classes
1395b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
1396619736fdSAdrian Lang        $class                         = 'table';
13970c4c0281SGerrit Uitslag        if($classes !== null) {
13982e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
13990c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
14000c4c0281SGerrit Uitslag        }
1401619736fdSAdrian Lang        if($pos !== null) {
140206917fceSMichael Große            $hid = $this->_headerToLink($class, true);
1403ec57f119SLarsDW223            $data = array();
1404ec57f119SLarsDW223            $data['target'] = 'table';
1405ec57f119SLarsDW223            $data['name'] = '';
1406ec57f119SLarsDW223            $data['hid'] = $hid;
1407ec57f119SLarsDW223            $class .= ' '.$this->startSectionEdit($pos, $data);
1408619736fdSAdrian Lang        }
1409619736fdSAdrian Lang        $this->doc .= '<div class="'.$class.'"><table class="inline">'.
1410619736fdSAdrian Lang            DOKU_LF;
14110cecf9d5Sandi    }
14120cecf9d5Sandi
14133dd5c225SAndreas Gohr    /**
14143dd5c225SAndreas Gohr     * Close a table
14153dd5c225SAndreas Gohr     *
14163dd5c225SAndreas Gohr     * @param int $pos byte position in the original source
14173dd5c225SAndreas Gohr     */
1418de369923SAndreas Gohr    public function table_close($pos = null) {
1419a8574918SAnika Henke        $this->doc .= '</table></div>'.DOKU_LF;
1420619736fdSAdrian Lang        if($pos !== null) {
142190df9a4dSAdrian Lang            $this->finishSectionEdit($pos);
14220cecf9d5Sandi        }
1423619736fdSAdrian Lang    }
14240cecf9d5Sandi
14253dd5c225SAndreas Gohr    /**
14263dd5c225SAndreas Gohr     * Open a table header
14273dd5c225SAndreas Gohr     */
1428de369923SAndreas Gohr    public function tablethead_open() {
1429f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF;
1430f05a1cc5SGerrit Uitslag    }
1431f05a1cc5SGerrit Uitslag
14323dd5c225SAndreas Gohr    /**
14333dd5c225SAndreas Gohr     * Close a table header
14343dd5c225SAndreas Gohr     */
1435de369923SAndreas Gohr    public function tablethead_close() {
1436f05a1cc5SGerrit Uitslag        $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF;
1437f05a1cc5SGerrit Uitslag    }
1438f05a1cc5SGerrit Uitslag
14393dd5c225SAndreas Gohr    /**
14405a93f869SAnika Henke     * Open a table body
14415a93f869SAnika Henke     */
1442de369923SAndreas Gohr    public function tabletbody_open() {
14435a93f869SAnika Henke        $this->doc .= DOKU_TAB.'<tbody>'.DOKU_LF;
14445a93f869SAnika Henke    }
14455a93f869SAnika Henke
14465a93f869SAnika Henke    /**
14475a93f869SAnika Henke     * Close a table body
14485a93f869SAnika Henke     */
1449de369923SAndreas Gohr    public function tabletbody_close() {
14505a93f869SAnika Henke        $this->doc .= DOKU_TAB.'</tbody>'.DOKU_LF;
14515a93f869SAnika Henke    }
14525a93f869SAnika Henke
14535a93f869SAnika Henke    /**
1454d2a99739SAndreas Gohr     * Open a table footer
1455d2a99739SAndreas Gohr     */
1456de369923SAndreas Gohr    public function tabletfoot_open() {
145744f5d1c1SAndreas Gohr        $this->doc .= DOKU_TAB.'<tfoot>'.DOKU_LF;
1458d2a99739SAndreas Gohr    }
1459d2a99739SAndreas Gohr
1460d2a99739SAndreas Gohr    /**
1461d2a99739SAndreas Gohr     * Close a table footer
1462d2a99739SAndreas Gohr     */
1463de369923SAndreas Gohr    public function tabletfoot_close() {
146444f5d1c1SAndreas Gohr        $this->doc .= DOKU_TAB.'</tfoot>'.DOKU_LF;
1465d2a99739SAndreas Gohr    }
1466d2a99739SAndreas Gohr
1467d2a99739SAndreas Gohr    /**
14683dd5c225SAndreas Gohr     * Open a table row
14690c4c0281SGerrit Uitslag     *
14707d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
14713dd5c225SAndreas Gohr     */
1472de369923SAndreas Gohr    public function tablerow_open($classes = null) {
1473b5742cedSPierre Spring        // initialize the cell counter used for classes
1474b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
1475b5742cedSPierre Spring        $class                          = 'row'.$this->_counter['row_counter']++;
14760c4c0281SGerrit Uitslag        if($classes !== null) {
14772e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
14780c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
14790c4c0281SGerrit Uitslag        }
1480b5742cedSPierre Spring        $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB;
14810cecf9d5Sandi    }
14820cecf9d5Sandi
14833dd5c225SAndreas Gohr    /**
14843dd5c225SAndreas Gohr     * Close a table row
14853dd5c225SAndreas Gohr     */
1486de369923SAndreas Gohr    public function tablerow_close() {
1487a2d649c4Sandi        $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
14880cecf9d5Sandi    }
14890cecf9d5Sandi
14903dd5c225SAndreas Gohr    /**
14913dd5c225SAndreas Gohr     * Open a table header cell
14923dd5c225SAndreas Gohr     *
14933dd5c225SAndreas Gohr     * @param int    $colspan
14943dd5c225SAndreas Gohr     * @param string $align left|center|right
14953dd5c225SAndreas Gohr     * @param int    $rowspan
14967d769f75SAndreas Gohr     * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input
14973dd5c225SAndreas Gohr     */
1498de369923SAndreas Gohr    public function tableheader_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) {
1499b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
15000cecf9d5Sandi        if(!is_null($align)) {
1501b5742cedSPierre Spring            $class .= ' '.$align.'align';
15020cecf9d5Sandi        }
15030c4c0281SGerrit Uitslag        if($classes !== null) {
15042e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
15050c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
15060c4c0281SGerrit Uitslag        }
1507b5742cedSPierre Spring        $class .= '"';
1508b5742cedSPierre Spring        $this->doc .= '<th '.$class;
15090cecf9d5Sandi        if($colspan > 1) {
1510a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1511a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
15120cecf9d5Sandi        }
151325b97867Shakan.sandell        if($rowspan > 1) {
151425b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
151525b97867Shakan.sandell        }
1516a2d649c4Sandi        $this->doc .= '>';
15170cecf9d5Sandi    }
15180cecf9d5Sandi
15193dd5c225SAndreas Gohr    /**
15203dd5c225SAndreas Gohr     * Close a table header cell
15213dd5c225SAndreas Gohr     */
1522de369923SAndreas Gohr    public function tableheader_close() {
1523a2d649c4Sandi        $this->doc .= '</th>';
15240cecf9d5Sandi    }
15250cecf9d5Sandi
15263dd5c225SAndreas Gohr    /**
15273dd5c225SAndreas Gohr     * Open a table cell
15283dd5c225SAndreas Gohr     *
15293dd5c225SAndreas Gohr     * @param int       $colspan
15303dd5c225SAndreas Gohr     * @param string    $align left|center|right
15313dd5c225SAndreas Gohr     * @param int       $rowspan
15327d769f75SAndreas Gohr     * @param string|string[]    $classes css classes - have to be valid, do not pass unfiltered user input
15333dd5c225SAndreas Gohr     */
1534de369923SAndreas Gohr    public function tablecell_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) {
1535b5742cedSPierre Spring        $class = 'class="col'.$this->_counter['cell_counter']++;
15360cecf9d5Sandi        if(!is_null($align)) {
1537b5742cedSPierre Spring            $class .= ' '.$align.'align';
15380cecf9d5Sandi        }
15390c4c0281SGerrit Uitslag        if($classes !== null) {
15402e0ebe60SAndreas Gohr            if(is_array($classes)) $classes = join(' ', $classes);
15410c4c0281SGerrit Uitslag            $class .= ' ' . $classes;
15420c4c0281SGerrit Uitslag        }
1543b5742cedSPierre Spring        $class .= '"';
1544b5742cedSPierre Spring        $this->doc .= '<td '.$class;
15450cecf9d5Sandi        if($colspan > 1) {
1546a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan - 1;
1547a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
15480cecf9d5Sandi        }
154925b97867Shakan.sandell        if($rowspan > 1) {
155025b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
155125b97867Shakan.sandell        }
1552a2d649c4Sandi        $this->doc .= '>';
15530cecf9d5Sandi    }
15540cecf9d5Sandi
15553dd5c225SAndreas Gohr    /**
15563dd5c225SAndreas Gohr     * Close a table cell
15573dd5c225SAndreas Gohr     */
1558de369923SAndreas Gohr    public function tablecell_close() {
1559a2d649c4Sandi        $this->doc .= '</td>';
15600cecf9d5Sandi    }
15610cecf9d5Sandi
1562cea664bdSLarsDW223    /**
1563cea664bdSLarsDW223     * Returns the current header level.
1564cea664bdSLarsDW223     * (required e.g. by the filelist plugin)
1565cea664bdSLarsDW223     *
1566cea664bdSLarsDW223     * @return int The current header level
1567cea664bdSLarsDW223     */
1568de369923SAndreas Gohr    public function getLastlevel() {
1569cea664bdSLarsDW223        return $this->lastlevel;
1570cea664bdSLarsDW223    }
1571cea664bdSLarsDW223
15723dd5c225SAndreas Gohr    #region Utility functions
15730cecf9d5Sandi
1574ba11bd29Sandi    /**
15753fd0b676Sandi     * Build a link
15763fd0b676Sandi     *
15773fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
1578ba11bd29Sandi     *
15790c4c0281SGerrit Uitslag     * @param array $link attributes of a link
15800c4c0281SGerrit Uitslag     * @return string
15810c4c0281SGerrit Uitslag     *
1582ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1583ba11bd29Sandi     */
1584de369923SAndreas Gohr    public function _formatLink($link) {
1585ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
1586ba11bd29Sandi        if(substr($link['url'], 0, 7) != 'mailto:') {
1587ba11bd29Sandi            $link['url'] = str_replace('&', '&amp;', $link['url']);
1588ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;', '&amp;', $link['url']);
1589ba11bd29Sandi        }
1590ba11bd29Sandi        //remove double encodings in titles
1591ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;', '&amp;', $link['title']);
1592ba11bd29Sandi
1593453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
1594453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
1595453493f2SAndreas Gohr        $link['url']   = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22'));
1596453493f2SAndreas Gohr        $link['title'] = strtr($link['title'], array('>' => '&gt;', '<' => '&lt;', '"' => '&quot;'));
1597453493f2SAndreas Gohr
1598ba11bd29Sandi        $ret = '';
1599ba11bd29Sandi        $ret .= $link['pre'];
1600ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
1601bb4866bdSchris        if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"';
1602bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
1603bb4866bdSchris        if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"';
1604bb4866bdSchris        if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"';
1605914045f3SAndreas Gohr        if(!empty($link['rel'])) $ret .= ' rel="'.trim($link['rel']).'"';
1606bb4866bdSchris        if(!empty($link['more'])) $ret .= ' '.$link['more'];
1607ba11bd29Sandi        $ret .= '>';
1608ba11bd29Sandi        $ret .= $link['name'];
1609ba11bd29Sandi        $ret .= '</a>';
1610ba11bd29Sandi        $ret .= $link['suf'];
1611ba11bd29Sandi        return $ret;
1612ba11bd29Sandi    }
1613ba11bd29Sandi
1614ba11bd29Sandi    /**
16153fd0b676Sandi     * Renders internal and external media
16163fd0b676Sandi     *
16173fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
16183dd5c225SAndreas Gohr     * @param string $src       media ID
16193dd5c225SAndreas Gohr     * @param string $title     descriptive text
16203dd5c225SAndreas Gohr     * @param string $align     left|center|right
16213dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
16223dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
16233dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
16243dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
16253dd5c225SAndreas Gohr     * @return string
16263fd0b676Sandi     */
1627de369923SAndreas Gohr    public function _media($src, $title = null, $align = null, $width = null,
16280ea51e63SMatt Perry                    $height = null, $cache = null, $render = true) {
16293fd0b676Sandi
16303fd0b676Sandi        $ret = '';
16313fd0b676Sandi
16323dd5c225SAndreas Gohr        list($ext, $mime) = mimetype($src);
16333fd0b676Sandi        if(substr($mime, 0, 5) == 'image') {
1634b739ff0fSPierre Spring            // first get the $title
1635b739ff0fSPierre Spring            if(!is_null($title)) {
1636b739ff0fSPierre Spring                $title = $this->_xmlEntities($title);
1637b739ff0fSPierre Spring            } elseif($ext == 'jpg' || $ext == 'jpeg') {
1638b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1639b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
164067f9913dSAndreas Gohr                $jpeg = new JpegMeta(mediaFN($src));
1641b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
16423dd5c225SAndreas Gohr                if(!empty($cap)) {
1643b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1644b739ff0fSPierre Spring                }
1645b739ff0fSPierre Spring            }
1646b739ff0fSPierre Spring            if(!$render) {
1647b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1648b739ff0fSPierre Spring                // return the title of the picture
1649768be5a3SPhy                if($title === null || $title === "") {
1650b739ff0fSPierre Spring                    // just show the sourcename
16518cbc5ee8SAndreas Gohr                    $title = $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($src)));
1652b739ff0fSPierre Spring                }
1653b739ff0fSPierre Spring                return $title;
1654b739ff0fSPierre Spring            }
16553fd0b676Sandi            //add image tag
165664159a61SAndreas Gohr            $ret .= '<img src="' . ml(
165764159a61SAndreas Gohr                    $src,
165864159a61SAndreas Gohr                    array(
165964159a61SAndreas Gohr                        'w' => $width, 'h' => $height,
166064159a61SAndreas Gohr                        'cache' => $cache,
166164159a61SAndreas Gohr                        'rev' => $this->_getLastMediaRevisionAt($src)
166264159a61SAndreas Gohr                    )
166364159a61SAndreas Gohr                ) . '"';
16643fd0b676Sandi            $ret .= ' class="media'.$align.'"';
16653fd0b676Sandi
1666b739ff0fSPierre Spring            if($title) {
1667b739ff0fSPierre Spring                $ret .= ' title="'.$title.'"';
1668b739ff0fSPierre Spring                $ret .= ' alt="'.$title.'"';
16693fd0b676Sandi            } else {
16703fd0b676Sandi                $ret .= ' alt=""';
16713fd0b676Sandi            }
16723fd0b676Sandi
16733fd0b676Sandi            if(!is_null($width))
16743fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
16753fd0b676Sandi
16763fd0b676Sandi            if(!is_null($height))
16773fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
16783fd0b676Sandi
16793fd0b676Sandi            $ret .= ' />';
16803fd0b676Sandi
168117954bb5SAnika Henke        } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) {
16822a2a2ba2SAnika Henke            // first get the $title
1683a8dcb874Sbleistivt            $title = !is_null($title) ? $title : false;
16842a2a2ba2SAnika Henke            if(!$render) {
168517954bb5SAnika Henke                // if the file is not supposed to be rendered
168617954bb5SAnika Henke                // return the title of the file (just the sourcename if there is no title)
1687a8dcb874Sbleistivt                return $this->_xmlEntities($title ? $title : \dokuwiki\Utf8\PhpString::basename(noNS($src)));
16882a2a2ba2SAnika Henke            }
16892a2a2ba2SAnika Henke
16902a2a2ba2SAnika Henke            $att          = array();
16912a2a2ba2SAnika Henke            $att['class'] = "media$align";
169217954bb5SAnika Henke            if($title) {
169317954bb5SAnika Henke                $att['title'] = $title;
169417954bb5SAnika Henke            }
16952a2a2ba2SAnika Henke
169617954bb5SAnika Henke            if(media_supportedav($mime, 'video')) {
169717954bb5SAnika Henke                //add video
169879e53fe5SAnika Henke                $ret .= $this->_video($src, $width, $height, $att);
1699b44a5dceSAnika Henke            }
170017954bb5SAnika Henke            if(media_supportedav($mime, 'audio')) {
1701b44a5dceSAnika Henke                //add audio
1702b44a5dceSAnika Henke                $ret .= $this->_audio($src, $att);
170317954bb5SAnika Henke            }
1704b44a5dceSAnika Henke
17053fd0b676Sandi        } elseif($mime == 'application/x-shockwave-flash') {
17061c882ba8SAndreas Gohr            if(!$render) {
17071c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
17081c882ba8SAndreas Gohr                // return the title of the flash
17091c882ba8SAndreas Gohr                if(!$title) {
17101c882ba8SAndreas Gohr                    // just show the sourcename
17118cbc5ee8SAndreas Gohr                    $title = \dokuwiki\Utf8\PhpString::basename(noNS($src));
17121c882ba8SAndreas Gohr                }
171307bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
17141c882ba8SAndreas Gohr            }
17151c882ba8SAndreas Gohr
171607bf32b2SAndreas Gohr            $att          = array();
171707bf32b2SAndreas Gohr            $att['class'] = "media$align";
171807bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
171907bf32b2SAndreas Gohr            if($align == 'left') $att['align'] = 'left';
17203dd5c225SAndreas Gohr            $ret .= html_flashobject(
17213dd5c225SAndreas Gohr                ml($src, array('cache' => $cache), true, '&'), $width, $height,
172207bf32b2SAndreas Gohr                array('quality' => 'high'),
172307bf32b2SAndreas Gohr                null,
172407bf32b2SAndreas Gohr                $att,
17253dd5c225SAndreas Gohr                $this->_xmlEntities($title)
17263dd5c225SAndreas Gohr            );
17270f428d7dSAndreas Gohr        } elseif($title) {
17283fd0b676Sandi            // well at least we have a title to display
17293fd0b676Sandi            $ret .= $this->_xmlEntities($title);
17303fd0b676Sandi        } else {
17315291ca3aSAndreas Gohr            // just show the sourcename
17328cbc5ee8SAndreas Gohr            $ret .= $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($src)));
17333fd0b676Sandi        }
17343fd0b676Sandi
17353fd0b676Sandi        return $ret;
17363fd0b676Sandi    }
17373fd0b676Sandi
17383dd5c225SAndreas Gohr    /**
17393dd5c225SAndreas Gohr     * Escape string for output
17403dd5c225SAndreas Gohr     *
17413dd5c225SAndreas Gohr     * @param $string
17423dd5c225SAndreas Gohr     * @return string
17433dd5c225SAndreas Gohr     */
1744de369923SAndreas Gohr    public function _xmlEntities($string) {
1745de117061Schris        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
17460cecf9d5Sandi    }
17470cecf9d5Sandi
1748de369923SAndreas Gohr
17490cecf9d5Sandi
1750af587fa8Sandi    /**
17513fd0b676Sandi     * Construct a title and handle images in titles
17523fd0b676Sandi     *
17530b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
17543dd5c225SAndreas Gohr     * @param string|array $title    either string title or media array
17553dd5c225SAndreas Gohr     * @param string       $default  default title if nothing else is found
17563dd5c225SAndreas Gohr     * @param bool         $isImage  will be set to true if it's a media file
17573dd5c225SAndreas Gohr     * @param null|string  $id       linked page id (used to extract title from first heading)
17583dd5c225SAndreas Gohr     * @param string       $linktype content|navigation
17593dd5c225SAndreas Gohr     * @return string      HTML of the title, might be full image tag or just escaped text
17603fd0b676Sandi     */
1761de369923SAndreas Gohr    public function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') {
176244881bd0Shenning.noren        $isImage = false;
176329657f9eSAndreas Gohr        if(is_array($title)) {
176429657f9eSAndreas Gohr            $isImage = true;
176529657f9eSAndreas Gohr            return $this->_imageTitle($title);
176629657f9eSAndreas Gohr        } elseif(is_null($title) || trim($title) == '') {
1767fe9ec250SChris Smith            if(useHeading($linktype) && $id) {
176867c15eceSMichael Hamann                $heading = p_get_first_heading($id);
1769f515db7fSAndreas Gohr                if(!blank($heading)) {
1770433bef32Sandi                    return $this->_xmlEntities($heading);
1771bb0a59d4Sjan                }
1772bb0a59d4Sjan            }
1773433bef32Sandi            return $this->_xmlEntities($default);
177468c26e6dSMichael Klier        } else {
177568c26e6dSMichael Klier            return $this->_xmlEntities($title);
17760cecf9d5Sandi        }
17770cecf9d5Sandi    }
17780cecf9d5Sandi
17790cecf9d5Sandi    /**
17803dd5c225SAndreas Gohr     * Returns HTML code for images used in link titles
17813fd0b676Sandi     *
17823fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1783e0c26282SGerrit Uitslag     * @param array $img
17843dd5c225SAndreas Gohr     * @return string HTML img tag or similar
17850cecf9d5Sandi     */
1786de369923SAndreas Gohr    public function _imageTitle($img) {
1787d9baf1a7SKazutaka Miyasaka        global $ID;
1788d9baf1a7SKazutaka Miyasaka
1789d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1790d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
17913dd5c225SAndreas Gohr        list($img['src']) = explode('#', $img['src'], 2);
1792d9baf1a7SKazutaka Miyasaka        if($img['type'] == 'internalmedia') {
1793*8c6be208SAndreas Gohr            $img['src'] = (new MediaResolver($ID))->resolveId($img['src'], $this->date_at, true);
1794d9baf1a7SKazutaka Miyasaka        }
1795d9baf1a7SKazutaka Miyasaka
17963dd5c225SAndreas Gohr        return $this->_media(
17973dd5c225SAndreas Gohr            $img['src'],
17984826ab45Sandi            $img['title'],
17994826ab45Sandi            $img['align'],
18004826ab45Sandi            $img['width'],
18014826ab45Sandi            $img['height'],
18023dd5c225SAndreas Gohr            $img['cache']
18033dd5c225SAndreas Gohr        );
18040cecf9d5Sandi    }
1805b739ff0fSPierre Spring
1806b739ff0fSPierre Spring    /**
18073dd5c225SAndreas Gohr     * helperfunction to return a basic link to a media
18083dd5c225SAndreas Gohr     *
18093dd5c225SAndreas Gohr     * used in internalmedia() and externalmedia()
1810b739ff0fSPierre Spring     *
1811b739ff0fSPierre Spring     * @author   Pierre Spring <pierre.spring@liip.ch>
18123dd5c225SAndreas Gohr     * @param string $src       media ID
18133dd5c225SAndreas Gohr     * @param string $title     descriptive text
18143dd5c225SAndreas Gohr     * @param string $align     left|center|right
18153dd5c225SAndreas Gohr     * @param int    $width     width of media in pixel
18163dd5c225SAndreas Gohr     * @param int    $height    height of media in pixel
18173dd5c225SAndreas Gohr     * @param string $cache     cache|recache|nocache
18183dd5c225SAndreas Gohr     * @param bool   $render    should the media be embedded inline or just linked
18193dd5c225SAndreas Gohr     * @return array associative array with link config
1820b739ff0fSPierre Spring     */
1821de369923SAndreas Gohr    public function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) {
1822b739ff0fSPierre Spring        global $conf;
1823b739ff0fSPierre Spring
1824b739ff0fSPierre Spring        $link           = array();
1825b739ff0fSPierre Spring        $link['class']  = 'media';
1826b739ff0fSPierre Spring        $link['style']  = '';
1827b739ff0fSPierre Spring        $link['pre']    = '';
1828b739ff0fSPierre Spring        $link['suf']    = '';
1829b739ff0fSPierre Spring        $link['more']   = '';
1830b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1831bc3d2252SAndreas Gohr        if($conf['target']['media']) $link['rel'] = 'noopener';
1832b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1833b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1834b739ff0fSPierre Spring
1835b739ff0fSPierre Spring        return $link;
1836b739ff0fSPierre Spring    }
183791459163SAnika Henke
18382a2a2ba2SAnika Henke    /**
18392a2a2ba2SAnika Henke     * Embed video(s) in HTML
18402a2a2ba2SAnika Henke     *
18412a2a2ba2SAnika Henke     * @author Anika Henke <anika@selfthinker.org>
18420877a1f1SSchplurtz le Déboulonné     * @author Schplurtz le Déboulonné <Schplurtz@laposte.net>
18432a2a2ba2SAnika Henke     *
18442a2a2ba2SAnika Henke     * @param string $src         - ID of video to embed
18452a2a2ba2SAnika Henke     * @param int    $width       - width of the video in pixels
18462a2a2ba2SAnika Henke     * @param int    $height      - height of the video in pixels
18472a2a2ba2SAnika Henke     * @param array  $atts        - additional attributes for the <video> tag
1848f50634f0SAnika Henke     * @return string
18492a2a2ba2SAnika Henke     */
1850de369923SAndreas Gohr    public function _video($src, $width, $height, $atts = null) {
18512a2a2ba2SAnika Henke        // prepare width and height
18522a2a2ba2SAnika Henke        if(is_null($atts)) $atts = array();
18532a2a2ba2SAnika Henke        $atts['width']  = (int) $width;
18542a2a2ba2SAnika Henke        $atts['height'] = (int) $height;
18552a2a2ba2SAnika Henke        if(!$atts['width']) $atts['width'] = 320;
18562a2a2ba2SAnika Henke        if(!$atts['height']) $atts['height'] = 240;
18572a2a2ba2SAnika Henke
1858410ee62aSAnika Henke        $posterUrl = '';
1859410ee62aSAnika Henke        $files = array();
18600877a1f1SSchplurtz le Déboulonné        $tracks = array();
1861410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1862410ee62aSAnika Henke
1863410ee62aSAnika Henke        if ($isExternal) {
1864410ee62aSAnika Henke            // take direct source for external files
1865702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1866410ee62aSAnika Henke            $files[$srcMime] = $src;
1867410ee62aSAnika Henke        } else {
18683d7a9e0aSAnika Henke            // prepare alternative formats
18693d7a9e0aSAnika Henke            $extensions   = array('webm', 'ogv', 'mp4');
1870410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
187159bc3b48SGerrit Uitslag            $poster       = media_alternativefiles($src, array('jpg', 'png'));
18720877a1f1SSchplurtz le Déboulonné            $tracks       = media_trackfiles($src);
187399f943f6SAnika Henke            if(!empty($poster)) {
18742d338eabSAndreas Gohr                $posterUrl = ml(reset($poster), '', true, '&');
187599f943f6SAnika Henke            }
1876410ee62aSAnika Henke        }
18772a2a2ba2SAnika Henke
1878f50634f0SAnika Henke        $out = '';
187979e53fe5SAnika Henke        // open video tag
1880f50634f0SAnika Henke        $out .= '<video '.buildAttributes($atts).' controls="controls"';
18813641199aSAnika Henke        if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"';
1882f50634f0SAnika Henke        $out .= '>'.NL;
18833641199aSAnika Henke        $fallback = '';
188479e53fe5SAnika Henke
188579e53fe5SAnika Henke        // output source for each alternative video format
1886410ee62aSAnika Henke        foreach($files as $mime => $file) {
1887410ee62aSAnika Henke            if ($isExternal) {
1888410ee62aSAnika Henke                $url = $file;
1889410ee62aSAnika Henke                $linkType = 'externalmedia';
1890410ee62aSAnika Henke            } else {
18912d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1892410ee62aSAnika Henke                $linkType = 'internalmedia';
1893410ee62aSAnika Henke            }
18948cbc5ee8SAndreas Gohr            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($file)));
18953d7a9e0aSAnika Henke
1896f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
189779e53fe5SAnika Henke            // alternative content (just a link to the file)
189864159a61SAndreas Gohr            $fallback .= $this->$linkType(
189964159a61SAndreas Gohr                $file,
190064159a61SAndreas Gohr                $title,
190164159a61SAndreas Gohr                null,
190264159a61SAndreas Gohr                null,
190364159a61SAndreas Gohr                null,
190464159a61SAndreas Gohr                $cache = null,
190564159a61SAndreas Gohr                $linking = 'linkonly',
190664159a61SAndreas Gohr                $return = true
190764159a61SAndreas Gohr            );
19083d7a9e0aSAnika Henke        }
19092a2a2ba2SAnika Henke
19100877a1f1SSchplurtz le Déboulonné        // output each track if any
19110877a1f1SSchplurtz le Déboulonné        foreach( $tracks as $trackid => $info ) {
191223c61bbeSSchplurtz le Déboulonné            list( $kind, $srclang ) = array_map( 'hsc', $info );
191323c61bbeSSchplurtz le Déboulonné            $out .= "<track kind=\"$kind\" srclang=\"$srclang\" ";
191423c61bbeSSchplurtz le Déboulonné            $out .= "label=\"$srclang\" ";
19150877a1f1SSchplurtz le Déboulonné            $out .= 'src="'.ml($trackid, '', true).'">'.NL;
19160877a1f1SSchplurtz le Déboulonné        }
19170877a1f1SSchplurtz le Déboulonné
19182a2a2ba2SAnika Henke        // finish
19193641199aSAnika Henke        $out .= $fallback;
1920f50634f0SAnika Henke        $out .= '</video>'.NL;
1921f50634f0SAnika Henke        return $out;
19222a2a2ba2SAnika Henke    }
19232a2a2ba2SAnika Henke
1924b44a5dceSAnika Henke    /**
1925b44a5dceSAnika Henke     * Embed audio in HTML
1926b44a5dceSAnika Henke     *
1927b44a5dceSAnika Henke     * @author Anika Henke <anika@selfthinker.org>
1928b44a5dceSAnika Henke     *
1929b44a5dceSAnika Henke     * @param string $src       - ID of audio to embed
19306d4af72aSAnika Henke     * @param array  $atts      - additional attributes for the <audio> tag
1931f50634f0SAnika Henke     * @return string
1932b44a5dceSAnika Henke     */
1933de369923SAndreas Gohr    public function _audio($src, $atts = array()) {
1934702e97d3SAnika Henke        $files = array();
1935410ee62aSAnika Henke        $isExternal = media_isexternal($src);
1936b44a5dceSAnika Henke
1937410ee62aSAnika Henke        if ($isExternal) {
1938410ee62aSAnika Henke            // take direct source for external files
1939702e97d3SAnika Henke            list(/*ext*/, $srcMime) = mimetype($src);
1940410ee62aSAnika Henke            $files[$srcMime] = $src;
1941410ee62aSAnika Henke        } else {
1942b44a5dceSAnika Henke            // prepare alternative formats
1943b44a5dceSAnika Henke            $extensions   = array('ogg', 'mp3', 'wav');
1944410ee62aSAnika Henke            $files        = media_alternativefiles($src, $extensions);
1945410ee62aSAnika Henke        }
1946b44a5dceSAnika Henke
1947f50634f0SAnika Henke        $out = '';
1948b44a5dceSAnika Henke        // open audio tag
1949f50634f0SAnika Henke        $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL;
19503641199aSAnika Henke        $fallback = '';
1951b44a5dceSAnika Henke
1952b44a5dceSAnika Henke        // output source for each alternative audio format
1953410ee62aSAnika Henke        foreach($files as $mime => $file) {
1954410ee62aSAnika Henke            if ($isExternal) {
1955410ee62aSAnika Henke                $url = $file;
1956410ee62aSAnika Henke                $linkType = 'externalmedia';
1957410ee62aSAnika Henke            } else {
19582d338eabSAndreas Gohr                $url = ml($file, '', true, '&');
1959410ee62aSAnika Henke                $linkType = 'internalmedia';
1960410ee62aSAnika Henke            }
19618cbc5ee8SAndreas Gohr            $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($file)));
1962b44a5dceSAnika Henke
1963f50634f0SAnika Henke            $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL;
1964b44a5dceSAnika Henke            // alternative content (just a link to the file)
196564159a61SAndreas Gohr            $fallback .= $this->$linkType(
196664159a61SAndreas Gohr                $file,
196764159a61SAndreas Gohr                $title,
196864159a61SAndreas Gohr                null,
196964159a61SAndreas Gohr                null,
197064159a61SAndreas Gohr                null,
197164159a61SAndreas Gohr                $cache = null,
197264159a61SAndreas Gohr                $linking = 'linkonly',
197364159a61SAndreas Gohr                $return = true
197464159a61SAndreas Gohr            );
1975b44a5dceSAnika Henke        }
1976b44a5dceSAnika Henke
1977b44a5dceSAnika Henke        // finish
19783641199aSAnika Henke        $out .= $fallback;
1979f50634f0SAnika Henke        $out .= '</audio>'.NL;
1980f50634f0SAnika Henke        return $out;
1981b44a5dceSAnika Henke    }
1982b44a5dceSAnika Henke
19835c2eed9aSlisps    /**
198452dc5eadSlisps     * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media()
19855c2eed9aSlisps     * which returns an existing media revision less or equal to rev or date_at
19865c2eed9aSlisps     *
19875c2eed9aSlisps     * @author lisps
19885c2eed9aSlisps     * @param string $media_id
19895c2eed9aSlisps     * @access protected
19905c2eed9aSlisps     * @return string revision ('' for current)
19915c2eed9aSlisps     */
1992de369923SAndreas Gohr    protected function _getLastMediaRevisionAt($media_id){
199352dc5eadSlisps        if(!$this->date_at || media_isexternal($media_id)) return '';
199478b874e6Slisps        $pagelog = new MediaChangeLog($media_id);
199578b874e6Slisps        return $pagelog->getLastRevisionAt($this->date_at);
19965c2eed9aSlisps    }
19975c2eed9aSlisps
19983dd5c225SAndreas Gohr    #endregion
19990cecf9d5Sandi}
20000cecf9d5Sandi
2001e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
2002