xref: /dokuwiki/inc/parser/xhtml.php (revision 5c2eed9a193e9341fbfee63d4a973898acdc5ee5)
10cecf9d5Sandi<?php
2b625487dSandi/**
3b625487dSandi * Renderer for XHTML output
4b625487dSandi *
5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com>
6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org>
7b625487dSandi */
8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
90cecf9d5Sandi
100cecf9d5Sandiif ( !defined('DOKU_LF') ) {
110cecf9d5Sandi    // Some whitespace to help View > Source
120cecf9d5Sandi    define ('DOKU_LF',"\n");
130cecf9d5Sandi}
140cecf9d5Sandi
150cecf9d5Sandiif ( !defined('DOKU_TAB') ) {
160cecf9d5Sandi    // Some whitespace to help View > Source
170cecf9d5Sandi    define ('DOKU_TAB',"\t");
180cecf9d5Sandi}
190cecf9d5Sandi
200e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php';
2156fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php';
220e1c636eSandi
230cecf9d5Sandi/**
24b625487dSandi * The Renderer
250cecf9d5Sandi */
26ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer {
270cecf9d5Sandi
28c5a8fd96SAndreas Gohr    // @access public
29c5a8fd96SAndreas Gohr    var $doc = '';        // will contain the whole document
30c5a8fd96SAndreas Gohr    var $toc = array();   // will contain the Table of Contents
31*5c2eed9aSlisps    var $rev = '';
32*5c2eed9aSlisps    var $date_at = '';
33c5a8fd96SAndreas Gohr
34fb838798SDanny    var $sectionedits = array(); // A stack of section edit data
35b04a190dSMichael Hamann    private $lastsecid = 0; // last section edit id, used by startSectionEdit
360cecf9d5Sandi
370cecf9d5Sandi    var $headers = array();
3816ec3e37SAndreas Gohr    /** @var array a list of footnotes, list starts at 1! */
390cecf9d5Sandi    var $footnotes = array();
4091459163SAnika Henke    var $lastlevel = 0;
4191459163SAnika Henke    var $node = array(0,0,0,0,0);
427764a90aSandi    var $store = '';
437764a90aSandi
44b5742cedSPierre Spring    var $_counter   = array(); // used as global counter, introduced for table classes
453d491f75SAndreas Gohr    var $_codeblock = 0; // counts the code and file blocks, used to provide download links
46b5742cedSPierre Spring
4790df9a4dSAdrian Lang    /**
4890df9a4dSAdrian Lang     * Register a new edit section range
4990df9a4dSAdrian Lang     *
5090df9a4dSAdrian Lang     * @param $type  string The section type identifier
5190df9a4dSAdrian Lang     * @param $title string The section title
5290df9a4dSAdrian Lang     * @param $start int    The byte position for the edit start
5390df9a4dSAdrian Lang     * @return string A marker class for the starting HTML element
5490df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
5590df9a4dSAdrian Lang     */
563f9e3215SAdrian Lang    public function startSectionEdit($start, $type, $title = null) {
57b04a190dSMichael Hamann        $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title);
58b04a190dSMichael Hamann        return 'sectionedit' . $this->lastsecid;
5990df9a4dSAdrian Lang    }
6090df9a4dSAdrian Lang
6190df9a4dSAdrian Lang    /**
6290df9a4dSAdrian Lang     * Finish an edit section range
6390df9a4dSAdrian Lang     *
64d9e36cbeSAdrian Lang     * @param $end int The byte position for the edit end; null for the rest of
65c404cb3bSMatt Perry     *                 the page
6690df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
6790df9a4dSAdrian Lang     */
683f9e3215SAdrian Lang    public function finishSectionEdit($end = null) {
6990df9a4dSAdrian Lang        list($id, $start, $type, $title) = array_pop($this->sectionedits);
70d9e36cbeSAdrian Lang        if (!is_null($end) && $end <= $start) {
7100c13053SAdrian Lang            return;
7200c13053SAdrian Lang        }
7340868f2fSAdrian Lang        $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' ';
7440868f2fSAdrian Lang        if (!is_null($title)) {
7540868f2fSAdrian Lang            $this->doc .= '"' . str_replace('"', '', $title) . '" ';
7640868f2fSAdrian Lang        }
77d9e36cbeSAdrian Lang        $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->';
7890df9a4dSAdrian Lang    }
7990df9a4dSAdrian Lang
805f70445dSAndreas Gohr    function getFormat(){
815f70445dSAndreas Gohr        return 'xhtml';
825f70445dSAndreas Gohr    }
835f70445dSAndreas Gohr
845f70445dSAndreas Gohr
850cecf9d5Sandi    function document_start() {
86c5a8fd96SAndreas Gohr        //reset some internals
87c5a8fd96SAndreas Gohr        $this->toc     = array();
88c5a8fd96SAndreas Gohr        $this->headers = array();
890cecf9d5Sandi    }
900cecf9d5Sandi
910cecf9d5Sandi    function document_end() {
9290df9a4dSAdrian Lang        // Finish open section edits.
9390df9a4dSAdrian Lang        while (count($this->sectionedits) > 0) {
9490df9a4dSAdrian Lang            if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) {
9590df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
9690df9a4dSAdrian Lang                // marker.
9790df9a4dSAdrian Lang                array_pop($this->sectionedits);
9890df9a4dSAdrian Lang            } else {
99d9e36cbeSAdrian Lang                $this->finishSectionEdit();
10090df9a4dSAdrian Lang            }
10190df9a4dSAdrian Lang        }
10290df9a4dSAdrian Lang
1030cecf9d5Sandi        if ( count ($this->footnotes) > 0 ) {
104a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
105d74aace9Schris
10616ec3e37SAndreas Gohr            foreach ( $this->footnotes as $id => $footnote ) {
107d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
108d74aace9Schris                if (substr($footnote, 0, 5) != "@@FNT") {
109d74aace9Schris
110d74aace9Schris                    // open the footnote and set the anchor and backlink
111d74aace9Schris                    $this->doc .= '<div class="fn">';
11216cc7ed7SAnika Henke                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">';
11329bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
114d74aace9Schris
115d74aace9Schris                    // get any other footnotes that use the same markup
116d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
117d74aace9Schris
118d74aace9Schris                    if (count($alt)) {
119d74aace9Schris                        foreach ($alt as $ref) {
120d74aace9Schris                            // set anchor and backlink for the other footnotes
12116ec3e37SAndreas Gohr                            $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">';
12216ec3e37SAndreas Gohr                            $this->doc .= ($ref).')</a></sup> '.DOKU_LF;
123d74aace9Schris                        }
124d74aace9Schris                    }
125d74aace9Schris
126d74aace9Schris                    // add footnote markup and close this footnote
127a2d649c4Sandi                    $this->doc .= $footnote;
128d74aace9Schris                    $this->doc .= '</div>' . DOKU_LF;
129d74aace9Schris                }
1300cecf9d5Sandi            }
131a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1320cecf9d5Sandi        }
133c5a8fd96SAndreas Gohr
134b8595a66SAndreas Gohr        // Prepare the TOC
135851f2e89SAnika Henke        global $conf;
136851f2e89SAnika Henke        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){
137b8595a66SAndreas Gohr            global $TOC;
138b8595a66SAndreas Gohr            $TOC = $this->toc;
1390cecf9d5Sandi        }
1403e55d035SAndreas Gohr
1413e55d035SAndreas Gohr        // make sure there are no empty paragraphs
14227918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
143e41c4da9SAndreas Gohr    }
1440cecf9d5Sandi
145e7856beaSchris    function toc_additem($id, $text, $level) {
146af587fa8Sandi        global $conf;
147af587fa8Sandi
148c5a8fd96SAndreas Gohr        //handle TOC
149c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
1507d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);
151c5a8fd96SAndreas Gohr        }
152e7856beaSchris    }
153e7856beaSchris
154e7856beaSchris    function header($text, $level, $pos) {
15590df9a4dSAdrian Lang        global $conf;
15690df9a4dSAdrian Lang
157bdd8111bSAndreas Gohr        if(!$text) return; //skip empty headlines
158e7856beaSchris
159e7856beaSchris        $hid = $this->_headerToLink($text,true);
160e7856beaSchris
161e7856beaSchris        //only add items within configured levels
162e7856beaSchris        $this->toc_additem($hid, $text, $level);
163c5a8fd96SAndreas Gohr
16491459163SAnika Henke        // adjust $node to reflect hierarchy of levels
16591459163SAnika Henke        $this->node[$level-1]++;
16691459163SAnika Henke        if ($level < $this->lastlevel) {
16791459163SAnika Henke            for ($i = 0; $i < $this->lastlevel-$level; $i++) {
16891459163SAnika Henke                $this->node[$this->lastlevel-$i-1] = 0;
16991459163SAnika Henke            }
17091459163SAnika Henke        }
17191459163SAnika Henke        $this->lastlevel = $level;
17291459163SAnika Henke
17390df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel'] &&
17490df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
17590df9a4dSAdrian Lang            $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') {
1766c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
17790df9a4dSAdrian Lang        }
17890df9a4dSAdrian Lang
179c5a8fd96SAndreas Gohr        // write the header
18090df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
18190df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel']) {
18290df9a4dSAdrian Lang            $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"';
18390df9a4dSAdrian Lang        }
18416cc7ed7SAnika Henke        $this->doc .= ' id="'.$hid.'">';
185a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
18616cc7ed7SAnika Henke        $this->doc .= "</h$level>".DOKU_LF;
1870cecf9d5Sandi    }
1880cecf9d5Sandi
1890cecf9d5Sandi    function section_open($level) {
1909864e7b1SAdrian Lang        $this->doc .= '<div class="level' . $level . '">' . DOKU_LF;
1910cecf9d5Sandi    }
1920cecf9d5Sandi
1930cecf9d5Sandi    function section_close() {
194a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1950cecf9d5Sandi    }
1960cecf9d5Sandi
1970cecf9d5Sandi    function cdata($text) {
198a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1990cecf9d5Sandi    }
2000cecf9d5Sandi
2010cecf9d5Sandi    function p_open() {
20259869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
2030cecf9d5Sandi    }
2040cecf9d5Sandi
2050cecf9d5Sandi    function p_close() {
20659869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2070cecf9d5Sandi    }
2080cecf9d5Sandi
2090cecf9d5Sandi    function linebreak() {
210a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2110cecf9d5Sandi    }
2120cecf9d5Sandi
2130cecf9d5Sandi    function hr() {
2144beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
2150cecf9d5Sandi    }
2160cecf9d5Sandi
2170cecf9d5Sandi    function strong_open() {
218a2d649c4Sandi        $this->doc .= '<strong>';
2190cecf9d5Sandi    }
2200cecf9d5Sandi
2210cecf9d5Sandi    function strong_close() {
222a2d649c4Sandi        $this->doc .= '</strong>';
2230cecf9d5Sandi    }
2240cecf9d5Sandi
2250cecf9d5Sandi    function emphasis_open() {
226a2d649c4Sandi        $this->doc .= '<em>';
2270cecf9d5Sandi    }
2280cecf9d5Sandi
2290cecf9d5Sandi    function emphasis_close() {
230a2d649c4Sandi        $this->doc .= '</em>';
2310cecf9d5Sandi    }
2320cecf9d5Sandi
2330cecf9d5Sandi    function underline_open() {
23402e51121SAnika Henke        $this->doc .= '<em class="u">';
2350cecf9d5Sandi    }
2360cecf9d5Sandi
2370cecf9d5Sandi    function underline_close() {
23802e51121SAnika Henke        $this->doc .= '</em>';
2390cecf9d5Sandi    }
2400cecf9d5Sandi
2410cecf9d5Sandi    function monospace_open() {
242a2d649c4Sandi        $this->doc .= '<code>';
2430cecf9d5Sandi    }
2440cecf9d5Sandi
2450cecf9d5Sandi    function monospace_close() {
246a2d649c4Sandi        $this->doc .= '</code>';
2470cecf9d5Sandi    }
2480cecf9d5Sandi
2490cecf9d5Sandi    function subscript_open() {
250a2d649c4Sandi        $this->doc .= '<sub>';
2510cecf9d5Sandi    }
2520cecf9d5Sandi
2530cecf9d5Sandi    function subscript_close() {
254a2d649c4Sandi        $this->doc .= '</sub>';
2550cecf9d5Sandi    }
2560cecf9d5Sandi
2570cecf9d5Sandi    function superscript_open() {
258a2d649c4Sandi        $this->doc .= '<sup>';
2590cecf9d5Sandi    }
2600cecf9d5Sandi
2610cecf9d5Sandi    function superscript_close() {
262a2d649c4Sandi        $this->doc .= '</sup>';
2630cecf9d5Sandi    }
2640cecf9d5Sandi
2650cecf9d5Sandi    function deleted_open() {
266a2d649c4Sandi        $this->doc .= '<del>';
2670cecf9d5Sandi    }
2680cecf9d5Sandi
2690cecf9d5Sandi    function deleted_close() {
270a2d649c4Sandi        $this->doc .= '</del>';
2710cecf9d5Sandi    }
2720cecf9d5Sandi
2733fd0b676Sandi    /**
2743fd0b676Sandi     * Callback for footnote start syntax
2753fd0b676Sandi     *
2763fd0b676Sandi     * All following content will go to the footnote instead of
277d74aace9Schris     * the document. To achieve this the previous rendered content
2783fd0b676Sandi     * is moved to $store and $doc is cleared
2793fd0b676Sandi     *
2803fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2813fd0b676Sandi     */
2820cecf9d5Sandi    function footnote_open() {
2837764a90aSandi
2847764a90aSandi        // move current content to store and record footnote
2857764a90aSandi        $this->store = $this->doc;
2867764a90aSandi        $this->doc   = '';
2870cecf9d5Sandi    }
2880cecf9d5Sandi
2893fd0b676Sandi    /**
2903fd0b676Sandi     * Callback for footnote end syntax
2913fd0b676Sandi     *
2923fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2933fd0b676Sandi     * content is restored from $store again
2943fd0b676Sandi     *
2953fd0b676Sandi     * @author Andreas Gohr
2963fd0b676Sandi     */
2970cecf9d5Sandi    function footnote_close() {
29816ec3e37SAndreas Gohr        /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */
29916ec3e37SAndreas Gohr        static $fnid = 0;
30016ec3e37SAndreas Gohr        // assign new footnote id (we start at 1)
30116ec3e37SAndreas Gohr        $fnid++;
3027764a90aSandi
303d74aace9Schris        // recover footnote into the stack and restore old content
304d74aace9Schris        $footnote = $this->doc;
3057764a90aSandi        $this->doc = $this->store;
3067764a90aSandi        $this->store = '';
307d74aace9Schris
308d74aace9Schris        // check to see if this footnote has been seen before
309d74aace9Schris        $i = array_search($footnote, $this->footnotes);
310d74aace9Schris
311d74aace9Schris        if ($i === false) {
312d74aace9Schris            // its a new footnote, add it to the $footnotes array
31316ec3e37SAndreas Gohr            $this->footnotes[$fnid] = $footnote;
314d74aace9Schris        } else {
31516ec3e37SAndreas Gohr            // seen this one before, save a placeholder
31616ec3e37SAndreas Gohr            $this->footnotes[$fnid] = "@@FNT".($i);
317d74aace9Schris        }
318d74aace9Schris
3196b379cbfSAndreas Gohr        // output the footnote reference and link
32016ec3e37SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>';
3210cecf9d5Sandi    }
3220cecf9d5Sandi
3230cecf9d5Sandi    function listu_open() {
324a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
3250cecf9d5Sandi    }
3260cecf9d5Sandi
3270cecf9d5Sandi    function listu_close() {
328a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
3290cecf9d5Sandi    }
3300cecf9d5Sandi
3310cecf9d5Sandi    function listo_open() {
332a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
3330cecf9d5Sandi    }
3340cecf9d5Sandi
3350cecf9d5Sandi    function listo_close() {
336a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
3370cecf9d5Sandi    }
3380cecf9d5Sandi
3390cecf9d5Sandi    function listitem_open($level) {
34059869a4bSAnika Henke        $this->doc .= '<li class="level'.$level.'">';
3410cecf9d5Sandi    }
3420cecf9d5Sandi
3430cecf9d5Sandi    function listitem_close() {
344a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
3450cecf9d5Sandi    }
3460cecf9d5Sandi
3470cecf9d5Sandi    function listcontent_open() {
34890db23d7Schris        $this->doc .= '<div class="li">';
3490cecf9d5Sandi    }
3500cecf9d5Sandi
3510cecf9d5Sandi    function listcontent_close() {
35259869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
3530cecf9d5Sandi    }
3540cecf9d5Sandi
3550cecf9d5Sandi    function unformatted($text) {
356a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3570cecf9d5Sandi    }
3580cecf9d5Sandi
3590cecf9d5Sandi    /**
3603fd0b676Sandi     * Execute PHP code if allowed
3613fd0b676Sandi     *
362d9764001SMichael Hamann     * @param  string   $text      PHP code that is either executed or printed
3635d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['phpok'] is okff
3645d568b99SChris Smith     *
3653fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3660cecf9d5Sandi     */
3675d568b99SChris Smith    function php($text, $wrapper='code') {
36835a56260SChris Smith        global $conf;
36935a56260SChris Smith
370d86d5af0SChris Smith        if($conf['phpok']){
371bad0b545Sandi            ob_start();
3724de671bcSandi            eval($text);
3733fd0b676Sandi            $this->doc .= ob_get_contents();
374bad0b545Sandi            ob_end_clean();
375d86d5af0SChris Smith        } else {
3765d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
377d86d5af0SChris Smith        }
3780cecf9d5Sandi    }
3790cecf9d5Sandi
38007f89c3cSAnika Henke    function phpblock($text) {
3815d568b99SChris Smith        $this->php($text, 'pre');
38207f89c3cSAnika Henke    }
38307f89c3cSAnika Henke
3840cecf9d5Sandi    /**
3853fd0b676Sandi     * Insert HTML if allowed
3863fd0b676Sandi     *
387d9764001SMichael Hamann     * @param  string   $text      html text
3885d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['htmlok'] is okff
3895d568b99SChris Smith     *
3903fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3910cecf9d5Sandi     */
3925d568b99SChris Smith    function html($text, $wrapper='code') {
39335a56260SChris Smith        global $conf;
39435a56260SChris Smith
395d86d5af0SChris Smith        if($conf['htmlok']){
396a2d649c4Sandi            $this->doc .= $text;
397d86d5af0SChris Smith        } else {
3985d568b99SChris Smith            $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
399d86d5af0SChris Smith        }
4004de671bcSandi    }
4010cecf9d5Sandi
40207f89c3cSAnika Henke    function htmlblock($text) {
4035d568b99SChris Smith        $this->html($text, 'pre');
40407f89c3cSAnika Henke    }
40507f89c3cSAnika Henke
4060cecf9d5Sandi    function quote_open() {
40796331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
4080cecf9d5Sandi    }
4090cecf9d5Sandi
4100cecf9d5Sandi    function quote_close() {
41196331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
4120cecf9d5Sandi    }
4130cecf9d5Sandi
4143d491f75SAndreas Gohr    function preformatted($text) {
415c9250713SAnika Henke        $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF;
4163d491f75SAndreas Gohr    }
4173d491f75SAndreas Gohr
4183d491f75SAndreas Gohr    function file($text, $language=null, $filename=null) {
4193d491f75SAndreas Gohr        $this->_highlight('file',$text,$language,$filename);
4203d491f75SAndreas Gohr    }
4213d491f75SAndreas Gohr
4223d491f75SAndreas Gohr    function code($text, $language=null, $filename=null) {
4233d491f75SAndreas Gohr        $this->_highlight('code',$text,$language,$filename);
4243d491f75SAndreas Gohr    }
4253d491f75SAndreas Gohr
4260cecf9d5Sandi    /**
4273d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
4283fd0b676Sandi     *
4293fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
4300cecf9d5Sandi     */
4313d491f75SAndreas Gohr    function _highlight($type, $text, $language=null, $filename=null) {
4324de671bcSandi        global $conf;
4333d491f75SAndreas Gohr        global $ID;
4343d491f75SAndreas Gohr        global $lang;
4353d491f75SAndreas Gohr
4363d491f75SAndreas Gohr        if($filename){
437190c56e8SAndreas Gohr            // add icon
43827bf7924STom N Harris            list($ext) = mimetype($filename,false);
439190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
440190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
441190c56e8SAndreas Gohr
4423d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
443190c56e8SAndreas Gohr            $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
4443d491f75SAndreas Gohr            $this->doc .= hsc($filename);
4453d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
4463d491f75SAndreas Gohr        }
4470cecf9d5Sandi
448d43aac1cSGina Haeussge        if ($text{0} == "\n") {
449d43aac1cSGina Haeussge            $text = substr($text, 1);
450d43aac1cSGina Haeussge        }
451d43aac1cSGina Haeussge        if (substr($text, -1) == "\n") {
452d43aac1cSGina Haeussge            $text = substr($text, 0, -1);
453d43aac1cSGina Haeussge        }
454d43aac1cSGina Haeussge
4550cecf9d5Sandi        if ( is_null($language) ) {
4563d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
4570cecf9d5Sandi        } else {
4583d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
4593d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
4603d491f75SAndreas Gohr
4613d491f75SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;
4620cecf9d5Sandi        }
4633d491f75SAndreas Gohr
4643d491f75SAndreas Gohr        if($filename){
4653d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
4663d491f75SAndreas Gohr        }
4673d491f75SAndreas Gohr
4683d491f75SAndreas Gohr        $this->_codeblock++;
4690cecf9d5Sandi    }
4700cecf9d5Sandi
4710cecf9d5Sandi    function acronym($acronym) {
4720cecf9d5Sandi
4730cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
4740cecf9d5Sandi
475433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
4760cecf9d5Sandi
477940db3a3SAnika Henke            $this->doc .= '<abbr title="'.$title
478940db3a3SAnika Henke                .'">'.$this->_xmlEntities($acronym).'</abbr>';
4790cecf9d5Sandi
4800cecf9d5Sandi        } else {
481a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4820cecf9d5Sandi        }
4830cecf9d5Sandi    }
4840cecf9d5Sandi
4850cecf9d5Sandi    function smiley($smiley) {
4860cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
487433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
488f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4898e38227fSAnika Henke                '" class="icon" alt="'.
490433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4910cecf9d5Sandi        } else {
492a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4930cecf9d5Sandi        }
4940cecf9d5Sandi    }
4950cecf9d5Sandi
496f62ea8a1Sandi    /*
4974de671bcSandi    * not used
4980cecf9d5Sandi    function wordblock($word) {
4990cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
500a2d649c4Sandi            $this->doc .= '** BLEEP **';
5010cecf9d5Sandi        } else {
502a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
5030cecf9d5Sandi        }
5040cecf9d5Sandi    }
5054de671bcSandi    */
5060cecf9d5Sandi
5070cecf9d5Sandi    function entity($entity) {
5080cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
509a2d649c4Sandi            $this->doc .= $this->entities[$entity];
5100cecf9d5Sandi        } else {
511a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
5120cecf9d5Sandi        }
5130cecf9d5Sandi    }
5140cecf9d5Sandi
5150cecf9d5Sandi    function multiplyentity($x, $y) {
516a2d649c4Sandi        $this->doc .= "$x&times;$y";
5170cecf9d5Sandi    }
5180cecf9d5Sandi
5190cecf9d5Sandi    function singlequoteopening() {
52071b40da2SAnika Henke        global $lang;
52171b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
5220cecf9d5Sandi    }
5230cecf9d5Sandi
5240cecf9d5Sandi    function singlequoteclosing() {
52571b40da2SAnika Henke        global $lang;
52671b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
5270cecf9d5Sandi    }
5280cecf9d5Sandi
52957d757d1SAndreas Gohr    function apostrophe() {
53057d757d1SAndreas Gohr        global $lang;
531a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
53257d757d1SAndreas Gohr    }
53357d757d1SAndreas Gohr
5340cecf9d5Sandi    function doublequoteopening() {
53571b40da2SAnika Henke        global $lang;
53671b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
5370cecf9d5Sandi    }
5380cecf9d5Sandi
5390cecf9d5Sandi    function doublequoteclosing() {
54071b40da2SAnika Henke        global $lang;
54171b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
5420cecf9d5Sandi    }
5430cecf9d5Sandi
5440cecf9d5Sandi    /**
5450cecf9d5Sandi     */
5460cecf9d5Sandi    function camelcaselink($link) {
54711d0aa47Sandi        $this->internallink($link,$link);
5480cecf9d5Sandi    }
5490cecf9d5Sandi
5500b7c14c2Sandi
5510ea51e63SMatt Perry    function locallink($hash, $name = null){
5520b7c14c2Sandi        global $ID;
5530b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
5540b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
555e260f93bSAnika Henke        $title = $ID.' ↵';
5560b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
5570b7c14c2Sandi        $this->doc .= $name;
5580b7c14c2Sandi        $this->doc .= '</a>';
5590b7c14c2Sandi    }
5600b7c14c2Sandi
561cffcc403Sandi    /**
5623fd0b676Sandi     * Render an internal Wiki Link
5633fd0b676Sandi     *
564fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
565cffcc403Sandi     * elsewhere - no need to implement them in other renderers
5663fd0b676Sandi     *
5673fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
568cffcc403Sandi     */
5690ea51e63SMatt Perry    function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') {
570ba11bd29Sandi        global $conf;
57137e34a5eSandi        global $ID;
572c4dda6afSAnika Henke        global $INFO;
57344653a53SAdrian Lang
5743d5e07d9SAdrian Lang        $params = '';
5753d5e07d9SAdrian Lang        $parts = explode('?', $id, 2);
5763d5e07d9SAdrian Lang        if (count($parts) === 2) {
5773d5e07d9SAdrian Lang            $id = $parts[0];
5783d5e07d9SAdrian Lang            $params = $parts[1];
57944653a53SAdrian Lang        }
58044653a53SAdrian Lang
581fda14ffcSIzidor Matušov        // For empty $id we need to know the current $ID
582fda14ffcSIzidor Matušov        // We need this check because _simpleTitle needs
583fda14ffcSIzidor Matušov        // correct $id and resolve_pageid() use cleanID($id)
584fda14ffcSIzidor Matušov        // (some things could be lost)
585fda14ffcSIzidor Matušov        if ($id === '') {
586fda14ffcSIzidor Matušov            $id = $ID;
587fda14ffcSIzidor Matušov        }
588fda14ffcSIzidor Matušov
5890339c872Sjan        // default name is based on $id as given
5900339c872Sjan        $default = $this->_simpleTitle($id);
591ad32e47eSAndreas Gohr
5920339c872Sjan        // now first resolve and clean up the $id
59337e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
594fda14ffcSIzidor Matušov
595fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
5960e1c636eSandi        if ( !$isImage ) {
5970e1c636eSandi            if ( $exists ) {
598ba11bd29Sandi                $class='wikilink1';
5990cecf9d5Sandi            } else {
600ba11bd29Sandi                $class='wikilink2';
60144a6b4c7SAndreas Gohr                $link['rel']='nofollow';
6020cecf9d5Sandi            }
6030cecf9d5Sandi        } else {
604ba11bd29Sandi            $class='media';
6050cecf9d5Sandi        }
6060cecf9d5Sandi
607a1685bedSandi        //keep hash anchor
608ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
609943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
610a1685bedSandi
611ba11bd29Sandi        //prepare for formating
612ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
613ba11bd29Sandi        $link['style']  = '';
614ba11bd29Sandi        $link['pre']    = '';
615ba11bd29Sandi        $link['suf']    = '';
61640eb54bbSjan        // highlight link to current page
617c4dda6afSAnika Henke        if ($id == $INFO['id']) {
61892795d04Sandi            $link['pre']    = '<span class="curid">';
61992795d04Sandi            $link['suf']    = '</span>';
62040eb54bbSjan        }
6215e163278SAndreas Gohr        $link['more']   = '';
622ba11bd29Sandi        $link['class']  = $class;
623*5c2eed9aSlisps        if($this->date_at) {
624*5c2eed9aSlisps            $params['at'] = $this->date_at;
625*5c2eed9aSlisps        } else if($this->rev) {
626*5c2eed9aSlisps            //$params['at'] = $this->rev;
627*5c2eed9aSlisps        }
62844653a53SAdrian Lang        $link['url']    = wl($id, $params);
629ba11bd29Sandi        $link['name']   = $name;
630ba11bd29Sandi        $link['title']  = $id;
631723d78dbSandi        //add search string
632723d78dbSandi        if($search){
633546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
634546d3a99SAndreas Gohr            if(is_array($search)){
635546d3a99SAndreas Gohr                $search = array_map('rawurlencode',$search);
636546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
637546d3a99SAndreas Gohr            }else{
638546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
639546d3a99SAndreas Gohr            }
640723d78dbSandi        }
641723d78dbSandi
642a1685bedSandi        //keep hash
643a1685bedSandi        if($hash) $link['url'].='#'.$hash;
644a1685bedSandi
645ba11bd29Sandi        //output formatted
646cffcc403Sandi        if($returnonly){
647cffcc403Sandi            return $this->_formatLink($link);
648cffcc403Sandi        }else{
649a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
6500cecf9d5Sandi        }
651cffcc403Sandi    }
6520cecf9d5Sandi
6530ea51e63SMatt Perry    function externallink($url, $name = null) {
654b625487dSandi        global $conf;
6550cecf9d5Sandi
656433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
6576f0c5dbfSandi
658b52b1596SAndreas Gohr        // url might be an attack vector, only allow registered protocols
659b52b1596SAndreas Gohr        if(is_null($this->schemes)) $this->schemes = getSchemes();
660b52b1596SAndreas Gohr        list($scheme) = explode('://',$url);
661b52b1596SAndreas Gohr        $scheme = strtolower($scheme);
662b52b1596SAndreas Gohr        if(!in_array($scheme,$this->schemes)) $url = '';
663b52b1596SAndreas Gohr
664b52b1596SAndreas Gohr        // is there still an URL?
665b52b1596SAndreas Gohr        if(!$url){
666b52b1596SAndreas Gohr            $this->doc .= $name;
667b52b1596SAndreas Gohr            return;
668b52b1596SAndreas Gohr        }
669b52b1596SAndreas Gohr
670b52b1596SAndreas Gohr        // set class
6710cecf9d5Sandi        if ( !$isImage ) {
672b625487dSandi            $class='urlextern';
6730cecf9d5Sandi        } else {
674b625487dSandi            $class='media';
6750cecf9d5Sandi        }
6760cecf9d5Sandi
677b625487dSandi        //prepare for formating
678b625487dSandi        $link['target'] = $conf['target']['extern'];
679b625487dSandi        $link['style']  = '';
680b625487dSandi        $link['pre']    = '';
681b625487dSandi        $link['suf']    = '';
6825e163278SAndreas Gohr        $link['more']   = '';
683b625487dSandi        $link['class']  = $class;
684b625487dSandi        $link['url']    = $url;
685e1c10e4dSchris
686b625487dSandi        $link['name']   = $name;
687433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
688b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
6890cecf9d5Sandi
690b625487dSandi        //output formatted
691a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6920cecf9d5Sandi    }
6930cecf9d5Sandi
6940cecf9d5Sandi    /**
6950cecf9d5Sandi    */
6960ea51e63SMatt Perry    function interwikilink($match, $name = null, $wikiName, $wikiUri) {
697b625487dSandi        global $conf;
6980cecf9d5Sandi
69997a3e4e3Sandi        $link = array();
70097a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
70197a3e4e3Sandi        $link['pre']    = '';
70297a3e4e3Sandi        $link['suf']    = '';
7035e163278SAndreas Gohr        $link['more']   = '';
704433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
7050cecf9d5Sandi
70697a3e4e3Sandi        //get interwiki URL
7071f82fabeSAndreas Gohr        $url = $this->_resolveInterWiki($wikiName,$wikiUri);
7080cecf9d5Sandi
70997a3e4e3Sandi        if ( !$isImage ) {
7109d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
7119d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
7121c2d1019SAndreas Gohr        } else {
7131c2d1019SAndreas Gohr            $link['class'] = 'media';
71497a3e4e3Sandi        }
7150cecf9d5Sandi
71697a3e4e3Sandi        //do we stay at the same server? Use local target
71797a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
71897a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
71997a3e4e3Sandi        }
7200cecf9d5Sandi
72197a3e4e3Sandi        $link['url'] = $url;
72297a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
72397a3e4e3Sandi
72497a3e4e3Sandi        //output formatted
725a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7260cecf9d5Sandi    }
7270cecf9d5Sandi
7280cecf9d5Sandi    /**
7290cecf9d5Sandi     */
7300ea51e63SMatt Perry    function windowssharelink($url, $name = null) {
7311d47afe1Sandi        global $conf;
7321d47afe1Sandi        global $lang;
7331d47afe1Sandi        //simple setup
7341d47afe1Sandi        $link['target'] = $conf['target']['windows'];
7351d47afe1Sandi        $link['pre']    = '';
7361d47afe1Sandi        $link['suf']   = '';
7371d47afe1Sandi        $link['style']  = '';
7380cecf9d5Sandi
739433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
7400cecf9d5Sandi        if ( !$isImage ) {
7411d47afe1Sandi            $link['class'] = 'windows';
7420cecf9d5Sandi        } else {
7431d47afe1Sandi            $link['class'] = 'media';
7440cecf9d5Sandi        }
7450cecf9d5Sandi
746433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
7471d47afe1Sandi        $url = str_replace('\\','/',$url);
7481d47afe1Sandi        $url = 'file:///'.$url;
7491d47afe1Sandi        $link['url'] = $url;
7500cecf9d5Sandi
7511d47afe1Sandi        //output formatted
752a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7530cecf9d5Sandi    }
7540cecf9d5Sandi
7550ea51e63SMatt Perry    function emaillink($address, $name = null) {
75671352defSandi        global $conf;
75771352defSandi        //simple setup
75871352defSandi        $link = array();
75971352defSandi        $link['target'] = '';
76071352defSandi        $link['pre']    = '';
76171352defSandi        $link['suf']   = '';
76271352defSandi        $link['style']  = '';
76371352defSandi        $link['more']   = '';
7640cecf9d5Sandi
765c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
7660cecf9d5Sandi        if ( !$isImage ) {
767be96545cSAnika Henke            $link['class']='mail';
7680cecf9d5Sandi        } else {
769be96545cSAnika Henke            $link['class']='media';
7700cecf9d5Sandi        }
7710cecf9d5Sandi
77207738714SAndreas Gohr        $address = $this->_xmlEntities($address);
77300a7b5adSEsther Brunner        $address = obfuscate($address);
77400a7b5adSEsther Brunner        $title   = $address;
7758c128049SAndreas Gohr
77671352defSandi        if(empty($name)){
77700a7b5adSEsther Brunner            $name = $address;
77871352defSandi        }
7790cecf9d5Sandi
780776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
781776b36ecSAndreas Gohr
782776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
78371352defSandi        $link['name']  = $name;
78471352defSandi        $link['title'] = $title;
7850cecf9d5Sandi
78671352defSandi        //output formatted
787a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7880cecf9d5Sandi    }
7890cecf9d5Sandi
7900ea51e63SMatt Perry    function internalmedia ($src, $title=null, $align=null, $width=null,
7910ea51e63SMatt Perry                            $height=null, $cache=null, $linking=null) {
79237e34a5eSandi        global $ID;
79391df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
79437e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
7950cecf9d5Sandi
796d98d4540SBen Coburn        $noLink = false;
7978acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
798b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
7993685f775Sandi
80027bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
801b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
802*5c2eed9aSlisps            if(($this->rev||$this->date_at)) {
803*5c2eed9aSlisps                $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),($linking=='direct'));
804*5c2eed9aSlisps            } else {
805dc673a5bSjoe.lapp                $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
806*5c2eed9aSlisps            }
8071c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
8082ca14335SEsther Brunner            // don't link flash movies
80944881bd0Shenning.noren            $noLink = true;
81055efc227SAndreas Gohr        }else{
8112ca14335SEsther Brunner            // add file icons
8129d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
8139d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
814*5c2eed9aSlisps            if(($this->rev||$this->date_at)) {
815*5c2eed9aSlisps                $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src)),true);
816*5c2eed9aSlisps            } else {
8176de3759aSAndreas Gohr                $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
818*5c2eed9aSlisps            }
81991328684SMichael Hamann            if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')';
82055efc227SAndreas Gohr        }
8213685f775Sandi
82291df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
82391df343aSAndreas Gohr
8246fe20453SGina Haeussge        //markup non existing files
8254a24b459SKate Arzamastseva        if (!$exists) {
8266fe20453SGina Haeussge            $link['class'] .= ' wikilink2';
8274a24b459SKate Arzamastseva        }
8286fe20453SGina Haeussge
8293685f775Sandi        //output formatted
830dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
8312ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
8320cecf9d5Sandi    }
8330cecf9d5Sandi
8340ea51e63SMatt Perry    function externalmedia ($src, $title=null, $align=null, $width=null,
8350ea51e63SMatt Perry                            $height=null, $cache=null, $linking=null) {
83691df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
837d98d4540SBen Coburn        $noLink = false;
8388acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
839b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
840b739ff0fSPierre Spring
841b739ff0fSPierre Spring        $link['url']    = ml($src,array('cache'=>$cache));
8423685f775Sandi
84327bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
844b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
8452ca14335SEsther Brunner            // link only jpeg images
84644881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
8471c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
8482ca14335SEsther Brunner            // don't link flash movies
84944881bd0Shenning.noren            $noLink = true;
8502ca14335SEsther Brunner        }else{
8512ca14335SEsther Brunner            // add file icons
85227bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
85327bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
8542ca14335SEsther Brunner        }
8552ca14335SEsther Brunner
85691df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
85791df343aSAndreas Gohr
8583685f775Sandi        //output formatted
859dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
8602ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
8610cecf9d5Sandi    }
8620cecf9d5Sandi
8634826ab45Sandi    /**
8643db95becSAndreas Gohr     * Renders an RSS feed
865b625487dSandi     *
866b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
867b625487dSandi     */
8683db95becSAndreas Gohr    function rss ($url,$params){
869b625487dSandi        global $lang;
8703db95becSAndreas Gohr        global $conf;
8713db95becSAndreas Gohr
8723db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
8733db95becSAndreas Gohr        $feed = new FeedParser();
87400077af8SAndreas Gohr        $feed->set_feed_url($url);
875b625487dSandi
876b625487dSandi        //disable warning while fetching
877bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
8783db95becSAndreas Gohr        $rc = $feed->init();
879bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
880b625487dSandi
8813db95becSAndreas Gohr        //decide on start and end
8823db95becSAndreas Gohr        if($params['reverse']){
8833db95becSAndreas Gohr            $mod = -1;
8843db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
8853db95becSAndreas Gohr            $end   = $start - ($params['max']);
886b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
8873db95becSAndreas Gohr        }else{
8883db95becSAndreas Gohr            $mod   = 1;
8893db95becSAndreas Gohr            $start = 0;
8903db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
891d91ab76fSMatt Perry            $end   = ($end > $params['max']) ? $params['max'] : $end;
8923db95becSAndreas Gohr        }
8933db95becSAndreas Gohr
894a2d649c4Sandi        $this->doc .= '<ul class="rss">';
8953db95becSAndreas Gohr        if($rc){
8963db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
8971bde1582SAndreas Gohr                $item = $feed->get_item($x);
8983db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
899d2ea3363SAndreas Gohr                // support feeds without links
900d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
901d2ea3363SAndreas Gohr                if($lnkurl){
902793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
903793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
9041bde1582SAndreas Gohr                    $this->externallink($item->get_permalink(),
905b9b9b28bSMichael Hamann                                        html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8'));
906d2ea3363SAndreas Gohr                }else{
907d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
908d2ea3363SAndreas Gohr                }
9093db95becSAndreas Gohr                if($params['author']){
9101bde1582SAndreas Gohr                    $author = $item->get_author(0);
9111bde1582SAndreas Gohr                    if($author){
9121bde1582SAndreas Gohr                        $name = $author->get_name();
9131bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
9141bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
9151bde1582SAndreas Gohr                    }
9163db95becSAndreas Gohr                }
9173db95becSAndreas Gohr                if($params['date']){
9182e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
9193db95becSAndreas Gohr                }
9201bde1582SAndreas Gohr                if($params['details']){
9213db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
922173dccb7STom N Harris                    if($conf['htmlok']){
9231bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
9243db95becSAndreas Gohr                    }else{
9251bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
9263db95becSAndreas Gohr                    }
9273db95becSAndreas Gohr                    $this->doc .= '</div>';
9283db95becSAndreas Gohr                }
9293db95becSAndreas Gohr
9303db95becSAndreas Gohr                $this->doc .= '</div></li>';
931b625487dSandi            }
932b625487dSandi        }else{
9333db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
934a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
935b625487dSandi            $this->externallink($url);
93645e147ccSAndreas Gohr            if($conf['allowdebug']){
93745e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
93845e147ccSAndreas Gohr            }
9393db95becSAndreas Gohr            $this->doc .= '</div></li>';
940b625487dSandi        }
941a2d649c4Sandi        $this->doc .= '</ul>';
942b625487dSandi    }
943b625487dSandi
9440cecf9d5Sandi    // $numrows not yet implemented
945619736fdSAdrian Lang    function table_open($maxcols = null, $numrows = null, $pos = null){
94690df9a4dSAdrian Lang        global $lang;
947b5742cedSPierre Spring        // initialize the row counter used for classes
948b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
949619736fdSAdrian Lang        $class = 'table';
950619736fdSAdrian Lang        if ($pos !== null) {
951619736fdSAdrian Lang            $class .= ' ' . $this->startSectionEdit($pos, 'table');
952619736fdSAdrian Lang        }
953619736fdSAdrian Lang        $this->doc .= '<div class="' . $class . '"><table class="inline">' .
954619736fdSAdrian Lang                      DOKU_LF;
9550cecf9d5Sandi    }
9560cecf9d5Sandi
957619736fdSAdrian Lang    function table_close($pos = null){
958a8574918SAnika Henke        $this->doc .= '</table></div>'.DOKU_LF;
959619736fdSAdrian Lang        if ($pos !== null) {
96090df9a4dSAdrian Lang            $this->finishSectionEdit($pos);
9610cecf9d5Sandi        }
962619736fdSAdrian Lang    }
9630cecf9d5Sandi
9640cecf9d5Sandi    function tablerow_open(){
965b5742cedSPierre Spring        // initialize the cell counter used for classes
966b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
967b5742cedSPierre Spring        $class = 'row' . $this->_counter['row_counter']++;
968b5742cedSPierre Spring        $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
9690cecf9d5Sandi    }
9700cecf9d5Sandi
9710cecf9d5Sandi    function tablerow_close(){
972a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
9730cecf9d5Sandi    }
9740cecf9d5Sandi
9750ea51e63SMatt Perry    function tableheader_open($colspan = 1, $align = null, $rowspan = 1){
976b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9770cecf9d5Sandi        if ( !is_null($align) ) {
978b5742cedSPierre Spring            $class .= ' '.$align.'align';
9790cecf9d5Sandi        }
980b5742cedSPierre Spring        $class .= '"';
981b5742cedSPierre Spring        $this->doc .= '<th ' . $class;
9820cecf9d5Sandi        if ( $colspan > 1 ) {
983a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
984a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
9850cecf9d5Sandi        }
98625b97867Shakan.sandell        if ( $rowspan > 1 ) {
98725b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
98825b97867Shakan.sandell        }
989a2d649c4Sandi        $this->doc .= '>';
9900cecf9d5Sandi    }
9910cecf9d5Sandi
9920cecf9d5Sandi    function tableheader_close(){
993a2d649c4Sandi        $this->doc .= '</th>';
9940cecf9d5Sandi    }
9950cecf9d5Sandi
9960ea51e63SMatt Perry    function tablecell_open($colspan = 1, $align = null, $rowspan = 1){
997b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9980cecf9d5Sandi        if ( !is_null($align) ) {
999b5742cedSPierre Spring            $class .= ' '.$align.'align';
10000cecf9d5Sandi        }
1001b5742cedSPierre Spring        $class .= '"';
1002b5742cedSPierre Spring        $this->doc .= '<td '.$class;
10030cecf9d5Sandi        if ( $colspan > 1 ) {
1004a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
1005a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
10060cecf9d5Sandi        }
100725b97867Shakan.sandell        if ( $rowspan > 1 ) {
100825b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
100925b97867Shakan.sandell        }
1010a2d649c4Sandi        $this->doc .= '>';
10110cecf9d5Sandi    }
10120cecf9d5Sandi
10130cecf9d5Sandi    function tablecell_close(){
1014a2d649c4Sandi        $this->doc .= '</td>';
10150cecf9d5Sandi    }
10160cecf9d5Sandi
10170cecf9d5Sandi    //----------------------------------------------------------
10180cecf9d5Sandi    // Utils
10190cecf9d5Sandi
1020ba11bd29Sandi    /**
10213fd0b676Sandi     * Build a link
10223fd0b676Sandi     *
10233fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
1024ba11bd29Sandi     *
1025ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
1026ba11bd29Sandi     */
1027433bef32Sandi    function _formatLink($link){
1028ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
1029ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
1030ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
1031ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
1032ba11bd29Sandi        }
1033ba11bd29Sandi        //remove double encodings in titles
1034ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
1035ba11bd29Sandi
1036453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
1037453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
1038453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
1039453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
1040453493f2SAndreas Gohr
1041ba11bd29Sandi        $ret  = '';
1042ba11bd29Sandi        $ret .= $link['pre'];
1043ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
1044bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
1045bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
1046bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
1047bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
104844a6b4c7SAndreas Gohr        if(!empty($link['rel']))    $ret .= ' rel="'.$link['rel'].'"';
1049bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
1050ba11bd29Sandi        $ret .= '>';
1051ba11bd29Sandi        $ret .= $link['name'];
1052ba11bd29Sandi        $ret .= '</a>';
1053ba11bd29Sandi        $ret .= $link['suf'];
1054ba11bd29Sandi        return $ret;
1055ba11bd29Sandi    }
1056ba11bd29Sandi
1057ba11bd29Sandi    /**
10583fd0b676Sandi     * Renders internal and external media
10593fd0b676Sandi     *
10603fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10613fd0b676Sandi     */
10620ea51e63SMatt Perry    function _media ($src, $title=null, $align=null, $width=null,
10630ea51e63SMatt Perry                      $height=null, $cache=null, $render = true) {
10643fd0b676Sandi
10653fd0b676Sandi        $ret = '';
1066*5c2eed9aSlisps        $intern = !is_externalmedia($src);
1067ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
10683fd0b676Sandi        if(substr($mime,0,5) == 'image'){
1069b739ff0fSPierre Spring            // first get the $title
1070b739ff0fSPierre Spring            if (!is_null($title)) {
1071b739ff0fSPierre Spring                $title  = $this->_xmlEntities($title);
1072b739ff0fSPierre Spring            }elseif($ext == 'jpg' || $ext == 'jpeg'){
1073b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1074b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
107567f9913dSAndreas Gohr                $jpeg =new JpegMeta(mediaFN($src));
1076b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
1077b739ff0fSPierre Spring                if($cap){
1078b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1079b739ff0fSPierre Spring                }
1080b739ff0fSPierre Spring            }
1081b739ff0fSPierre Spring            if (!$render) {
1082b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1083b739ff0fSPierre Spring                // return the title of the picture
1084b739ff0fSPierre Spring                if (!$title) {
1085b739ff0fSPierre Spring                    // just show the sourcename
10863009a773SAndreas Gohr                    $title = $this->_xmlEntities(utf8_basename(noNS($src)));
1087b739ff0fSPierre Spring                }
1088b739ff0fSPierre Spring                return $title;
1089b739ff0fSPierre Spring            }
10903fd0b676Sandi            //add image tag
1091*5c2eed9aSlisps            if($intern && ($this->rev||$this->date_at)) {
1092*5c2eed9aSlisps                $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache,'rev'=>$this->_getProperMediaRevision($src))).'"';
1093*5c2eed9aSlisps            } else {
10946de3759aSAndreas Gohr                $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
1095*5c2eed9aSlisps            }
10963fd0b676Sandi            $ret .= ' class="media'.$align.'"';
10973fd0b676Sandi
1098b739ff0fSPierre Spring            if ($title) {
1099b739ff0fSPierre Spring                $ret .= ' title="' . $title . '"';
1100b739ff0fSPierre Spring                $ret .= ' alt="'   . $title .'"';
11013fd0b676Sandi            }else{
11023fd0b676Sandi                $ret .= ' alt=""';
11033fd0b676Sandi            }
11043fd0b676Sandi
11053fd0b676Sandi            if ( !is_null($width) )
11063fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
11073fd0b676Sandi
11083fd0b676Sandi            if ( !is_null($height) )
11093fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
11103fd0b676Sandi
11113fd0b676Sandi            $ret .= ' />';
11123fd0b676Sandi
11133fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
11141c882ba8SAndreas Gohr            if (!$render) {
11151c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
11161c882ba8SAndreas Gohr                // return the title of the flash
11171c882ba8SAndreas Gohr                if (!$title) {
11181c882ba8SAndreas Gohr                    // just show the sourcename
11193009a773SAndreas Gohr                    $title = utf8_basename(noNS($src));
11201c882ba8SAndreas Gohr                }
112107bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
11221c882ba8SAndreas Gohr            }
11231c882ba8SAndreas Gohr
112407bf32b2SAndreas Gohr            $att = array();
112507bf32b2SAndreas Gohr            $att['class'] = "media$align";
112607bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
112707bf32b2SAndreas Gohr            if($align == 'left')  $att['align'] = 'left';
1128c471e6a6SAndreas Gohr            $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height,
112907bf32b2SAndreas Gohr                                     array('quality' => 'high'),
113007bf32b2SAndreas Gohr                                     null,
113107bf32b2SAndreas Gohr                                     $att,
113207bf32b2SAndreas Gohr                                     $this->_xmlEntities($title));
11330f428d7dSAndreas Gohr        }elseif($title){
11343fd0b676Sandi            // well at least we have a title to display
11353fd0b676Sandi            $ret .= $this->_xmlEntities($title);
11363fd0b676Sandi        }else{
11375291ca3aSAndreas Gohr            // just show the sourcename
11383009a773SAndreas Gohr            $ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
11393fd0b676Sandi        }
11403fd0b676Sandi
11413fd0b676Sandi        return $ret;
11423fd0b676Sandi    }
11433fd0b676Sandi
1144433bef32Sandi    function _xmlEntities($string) {
1145de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
11460cecf9d5Sandi    }
11470cecf9d5Sandi
11488a831f2bSAndreas Gohr    /**
11498a831f2bSAndreas Gohr     * Creates a linkid from a headline
1150c5a8fd96SAndreas Gohr     *
1151c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1152c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
1153c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
11548a831f2bSAndreas Gohr     */
1155c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
1156c5a8fd96SAndreas Gohr        if($create){
11574ceab83fSAndreas Gohr            return sectionID($title,$this->headers);
11584ceab83fSAndreas Gohr        }else{
1159443d207bSAndreas Gohr            $check = false;
1160443d207bSAndreas Gohr            return sectionID($title,$check);
1161c5a8fd96SAndreas Gohr        }
11620cecf9d5Sandi    }
11630cecf9d5Sandi
1164af587fa8Sandi    /**
11653fd0b676Sandi     * Construct a title and handle images in titles
11663fd0b676Sandi     *
11670b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
11683fd0b676Sandi     */
11690ea51e63SMatt Perry    function _getLinkTitle($title, $default, & $isImage, $id=null, $linktype='content') {
1170bb0a59d4Sjan        global $conf;
1171bb0a59d4Sjan
117244881bd0Shenning.noren        $isImage = false;
117329657f9eSAndreas Gohr        if ( is_array($title) ) {
117429657f9eSAndreas Gohr            $isImage = true;
117529657f9eSAndreas Gohr            return $this->_imageTitle($title);
117629657f9eSAndreas Gohr        } elseif ( is_null($title) || trim($title)=='') {
1177fe9ec250SChris Smith            if (useHeading($linktype) && $id) {
117867c15eceSMichael Hamann                $heading = p_get_first_heading($id);
1179bb0a59d4Sjan                if ($heading) {
1180433bef32Sandi                    return $this->_xmlEntities($heading);
1181bb0a59d4Sjan                }
1182bb0a59d4Sjan            }
1183433bef32Sandi            return $this->_xmlEntities($default);
118468c26e6dSMichael Klier        } else {
118568c26e6dSMichael Klier            return $this->_xmlEntities($title);
11860cecf9d5Sandi        }
11870cecf9d5Sandi    }
11880cecf9d5Sandi
11890cecf9d5Sandi    /**
11903fd0b676Sandi     * Returns an HTML code for images used in link titles
11913fd0b676Sandi     *
11923fd0b676Sandi     * @todo Resolve namespace on internal images
11933fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
11940cecf9d5Sandi     */
1195433bef32Sandi    function _imageTitle($img) {
1196d9baf1a7SKazutaka Miyasaka        global $ID;
1197d9baf1a7SKazutaka Miyasaka
1198d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1199d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
1200d9baf1a7SKazutaka Miyasaka        list($img['src'],$hash) = explode('#',$img['src'],2);
1201d9baf1a7SKazutaka Miyasaka        if ($img['type'] == 'internalmedia') {
1202d9baf1a7SKazutaka Miyasaka            resolve_mediaid(getNS($ID),$img['src'],$exists);
1203d9baf1a7SKazutaka Miyasaka        }
1204d9baf1a7SKazutaka Miyasaka
1205433bef32Sandi        return $this->_media($img['src'],
12064826ab45Sandi                              $img['title'],
12074826ab45Sandi                              $img['align'],
12084826ab45Sandi                              $img['width'],
12094826ab45Sandi                              $img['height'],
12104826ab45Sandi                              $img['cache']);
12110cecf9d5Sandi    }
1212b739ff0fSPierre Spring
1213b739ff0fSPierre Spring    /**
1214b739ff0fSPierre Spring     * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia()
1215b739ff0fSPierre Spring     * which returns a basic link to a media.
1216b739ff0fSPierre Spring     *
1217b739ff0fSPierre Spring     * @author Pierre Spring <pierre.spring@liip.ch>
1218b739ff0fSPierre Spring     * @param string $src
1219b739ff0fSPierre Spring     * @param string $title
1220b739ff0fSPierre Spring     * @param string $align
1221b739ff0fSPierre Spring     * @param string $width
1222b739ff0fSPierre Spring     * @param string $height
1223b739ff0fSPierre Spring     * @param string $cache
1224b739ff0fSPierre Spring     * @param string $render
1225b739ff0fSPierre Spring     * @access protected
1226b739ff0fSPierre Spring     * @return array
1227b739ff0fSPierre Spring     */
1228d91ab76fSMatt Perry    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) {
1229b739ff0fSPierre Spring        global $conf;
1230b739ff0fSPierre Spring
1231b739ff0fSPierre Spring        $link = array();
1232b739ff0fSPierre Spring        $link['class']  = 'media';
1233b739ff0fSPierre Spring        $link['style']  = '';
1234b739ff0fSPierre Spring        $link['pre']    = '';
1235b739ff0fSPierre Spring        $link['suf']    = '';
1236b739ff0fSPierre Spring        $link['more']   = '';
1237b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1238b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1239b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1240b739ff0fSPierre Spring
1241b739ff0fSPierre Spring        return $link;
1242b739ff0fSPierre Spring    }
124391459163SAnika Henke
1244*5c2eed9aSlisps    /**
1245*5c2eed9aSlisps     * _getProperMediaRevision is a helperfunction to internalmedia() and _media()
1246*5c2eed9aSlisps     * which returns an existing media revision less or equal to rev or date_at
1247*5c2eed9aSlisps     *
1248*5c2eed9aSlisps     * @author lisps
1249*5c2eed9aSlisps     * @param string $media_id
1250*5c2eed9aSlisps     * @access protected
1251*5c2eed9aSlisps     * @return string revision ('' for current)
1252*5c2eed9aSlisps     */
1253*5c2eed9aSlisps    function _getProperMediaRevision($media_id){
1254*5c2eed9aSlisps        $rev = $this->rev;
1255*5c2eed9aSlisps        if($this->date_at){
1256*5c2eed9aSlisps            $rev = $this->date_at;
1257*5c2eed9aSlisps        }
1258*5c2eed9aSlisps        return getProperRevision($media_id,$rev,true);
1259*5c2eed9aSlisps    }
1260*5c2eed9aSlisps
126191459163SAnika Henke
12620cecf9d5Sandi}
12630cecf9d5Sandi
1264e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1265