xref: /dokuwiki/inc/parser/xhtml.php (revision 9864e7b158ed3f208e2e9df1696da5d446934ab8)
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
31c5a8fd96SAndreas Gohr
3290df9a4dSAdrian Lang    private $sectionedits = array(); // A stack of section edit data
330cecf9d5Sandi
340cecf9d5Sandi    var $headers = array();
350cecf9d5Sandi    var $footnotes = array();
3691459163SAnika Henke    var $lastlevel = 0;
3791459163SAnika Henke    var $node = array(0,0,0,0,0);
387764a90aSandi    var $store = '';
397764a90aSandi
40b5742cedSPierre Spring    var $_counter   = array(); // used as global counter, introduced for table classes
413d491f75SAndreas Gohr    var $_codeblock = 0; // counts the code and file blocks, used to provide download links
42b5742cedSPierre Spring
4390df9a4dSAdrian Lang    /**
4490df9a4dSAdrian Lang     * Register a new edit section range
4590df9a4dSAdrian Lang     *
4690df9a4dSAdrian Lang     * @param $type  string The section type identifier
4790df9a4dSAdrian Lang     * @param $title string The section title
4890df9a4dSAdrian Lang     * @param $start int    The byte position for the edit start
4990df9a4dSAdrian Lang     * @return string A marker class for the starting HTML element
5090df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
5190df9a4dSAdrian Lang     */
5240868f2fSAdrian Lang    protected function startSectionEdit($start, $type, $title = null) {
5390df9a4dSAdrian Lang        static $lastsecid = 0;
5490df9a4dSAdrian Lang        $this->sectionedits[] = array(++$lastsecid, $start, $type, $title);
5590df9a4dSAdrian Lang        return 'sectionedit' . $lastsecid;
5690df9a4dSAdrian Lang    }
5790df9a4dSAdrian Lang
5890df9a4dSAdrian Lang    /**
5990df9a4dSAdrian Lang     * Finish an edit section range
6090df9a4dSAdrian Lang     *
6190df9a4dSAdrian Lang     * @param $pos int The byte position for the edit end
6290df9a4dSAdrian Lang     * @author Adrian Lang <lang@cosmocode.de>
6390df9a4dSAdrian Lang     */
6490df9a4dSAdrian Lang    protected function finishSectionEdit($end) {
6590df9a4dSAdrian Lang        list($id, $start, $type, $title) = array_pop($this->sectionedits);
6600c13053SAdrian Lang        if ($end <= $start) {
6700c13053SAdrian Lang            return;
6800c13053SAdrian Lang        }
6940868f2fSAdrian Lang        $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' ';
7040868f2fSAdrian Lang        if (!is_null($title)) {
7140868f2fSAdrian Lang            $this->doc .= '"' . str_replace('"', '', $title) . '" ';
7240868f2fSAdrian Lang        }
7340868f2fSAdrian Lang        $this->doc .= "[$start-" . ($end === 0 ? '' : $end) . '] -->';
7490df9a4dSAdrian Lang    }
7590df9a4dSAdrian Lang
765f70445dSAndreas Gohr    function getFormat(){
775f70445dSAndreas Gohr        return 'xhtml';
785f70445dSAndreas Gohr    }
795f70445dSAndreas Gohr
805f70445dSAndreas Gohr
810cecf9d5Sandi    function document_start() {
82c5a8fd96SAndreas Gohr        //reset some internals
83c5a8fd96SAndreas Gohr        $this->toc     = array();
84c5a8fd96SAndreas Gohr        $this->headers = array();
850cecf9d5Sandi    }
860cecf9d5Sandi
870cecf9d5Sandi    function document_end() {
8890df9a4dSAdrian Lang        // Finish open section edits.
8990df9a4dSAdrian Lang        while (count($this->sectionedits) > 0) {
9090df9a4dSAdrian Lang            if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) {
9190df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
9290df9a4dSAdrian Lang                // marker.
9390df9a4dSAdrian Lang                array_pop($this->sectionedits);
9490df9a4dSAdrian Lang            } else {
9590df9a4dSAdrian Lang                $this->finishSectionEdit(0);
9690df9a4dSAdrian Lang            }
9790df9a4dSAdrian Lang        }
9890df9a4dSAdrian Lang
990cecf9d5Sandi        if ( count ($this->footnotes) > 0 ) {
100a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
101d74aace9Schris
102d74aace9Schris            $id = 0;
1030cecf9d5Sandi            foreach ( $this->footnotes as $footnote ) {
104d74aace9Schris                $id++;   // the number of the current footnote
105d74aace9Schris
106d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
107d74aace9Schris                if (substr($footnote, 0, 5) != "@@FNT") {
108d74aace9Schris
109d74aace9Schris                    // open the footnote and set the anchor and backlink
110d74aace9Schris                    $this->doc .= '<div class="fn">';
11129bfcd16SAndreas Gohr                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
11229bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
113d74aace9Schris
114d74aace9Schris                    // get any other footnotes that use the same markup
115d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
116d74aace9Schris
117d74aace9Schris                    if (count($alt)) {
118d74aace9Schris                      foreach ($alt as $ref) {
119d74aace9Schris                        // set anchor and backlink for the other footnotes
12029bfcd16SAndreas Gohr                        $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
12129bfcd16SAndreas Gohr                        $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF;
122d74aace9Schris                      }
123d74aace9Schris                    }
124d74aace9Schris
125d74aace9Schris                    // add footnote markup and close this footnote
126a2d649c4Sandi                    $this->doc .= $footnote;
127d74aace9Schris                    $this->doc .= '</div>' . DOKU_LF;
128d74aace9Schris                }
1290cecf9d5Sandi            }
130a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1310cecf9d5Sandi        }
132c5a8fd96SAndreas Gohr
133b8595a66SAndreas Gohr        // Prepare the TOC
134851f2e89SAnika Henke        global $conf;
135851f2e89SAnika Henke        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){
136b8595a66SAndreas Gohr            global $TOC;
137b8595a66SAndreas Gohr            $TOC = $this->toc;
1380cecf9d5Sandi        }
1393e55d035SAndreas Gohr
1403e55d035SAndreas Gohr        // make sure there are no empty paragraphs
14127918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
142e41c4da9SAndreas Gohr    }
1430cecf9d5Sandi
144e7856beaSchris    function toc_additem($id, $text, $level) {
145af587fa8Sandi        global $conf;
146af587fa8Sandi
147c5a8fd96SAndreas Gohr        //handle TOC
148c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
1497d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);
150c5a8fd96SAndreas Gohr        }
151e7856beaSchris    }
152e7856beaSchris
153e7856beaSchris    function header($text, $level, $pos) {
15490df9a4dSAdrian Lang        global $conf;
15590df9a4dSAdrian Lang
156bdd8111bSAndreas Gohr        if(!$text) return; //skip empty headlines
157e7856beaSchris
158e7856beaSchris        $hid = $this->_headerToLink($text,true);
159e7856beaSchris
160e7856beaSchris        //only add items within configured levels
161e7856beaSchris        $this->toc_additem($hid, $text, $level);
162c5a8fd96SAndreas Gohr
16391459163SAnika Henke        // adjust $node to reflect hierarchy of levels
16491459163SAnika Henke        $this->node[$level-1]++;
16591459163SAnika Henke        if ($level < $this->lastlevel) {
16691459163SAnika Henke            for ($i = 0; $i < $this->lastlevel-$level; $i++) {
16791459163SAnika Henke                $this->node[$this->lastlevel-$i-1] = 0;
16891459163SAnika Henke            }
16991459163SAnika Henke        }
17091459163SAnika Henke        $this->lastlevel = $level;
17191459163SAnika Henke
17290df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel'] &&
17390df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
17490df9a4dSAdrian Lang            $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') {
1756c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
17690df9a4dSAdrian Lang        }
17790df9a4dSAdrian Lang
178c5a8fd96SAndreas Gohr        // write the header
17990df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
18090df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel']) {
18190df9a4dSAdrian Lang            $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"';
18290df9a4dSAdrian Lang        }
18390df9a4dSAdrian Lang        $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">';
184a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
18559869a4bSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1860cecf9d5Sandi    }
1870cecf9d5Sandi
1880cecf9d5Sandi    function section_open($level) {
189*9864e7b1SAdrian Lang        $this->doc .= '<div class="level' . $level . '">' . DOKU_LF;
1900cecf9d5Sandi    }
1910cecf9d5Sandi
1920cecf9d5Sandi    function section_close() {
193a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1940cecf9d5Sandi    }
1950cecf9d5Sandi
1960cecf9d5Sandi    function cdata($text) {
197a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1980cecf9d5Sandi    }
1990cecf9d5Sandi
2000cecf9d5Sandi    function p_open() {
20159869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
2020cecf9d5Sandi    }
2030cecf9d5Sandi
2040cecf9d5Sandi    function p_close() {
20559869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2060cecf9d5Sandi    }
2070cecf9d5Sandi
2080cecf9d5Sandi    function linebreak() {
209a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2100cecf9d5Sandi    }
2110cecf9d5Sandi
2120cecf9d5Sandi    function hr() {
2134beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
2140cecf9d5Sandi    }
2150cecf9d5Sandi
2160cecf9d5Sandi    function strong_open() {
217a2d649c4Sandi        $this->doc .= '<strong>';
2180cecf9d5Sandi    }
2190cecf9d5Sandi
2200cecf9d5Sandi    function strong_close() {
221a2d649c4Sandi        $this->doc .= '</strong>';
2220cecf9d5Sandi    }
2230cecf9d5Sandi
2240cecf9d5Sandi    function emphasis_open() {
225a2d649c4Sandi        $this->doc .= '<em>';
2260cecf9d5Sandi    }
2270cecf9d5Sandi
2280cecf9d5Sandi    function emphasis_close() {
229a2d649c4Sandi        $this->doc .= '</em>';
2300cecf9d5Sandi    }
2310cecf9d5Sandi
2320cecf9d5Sandi    function underline_open() {
23302e51121SAnika Henke        $this->doc .= '<em class="u">';
2340cecf9d5Sandi    }
2350cecf9d5Sandi
2360cecf9d5Sandi    function underline_close() {
23702e51121SAnika Henke        $this->doc .= '</em>';
2380cecf9d5Sandi    }
2390cecf9d5Sandi
2400cecf9d5Sandi    function monospace_open() {
241a2d649c4Sandi        $this->doc .= '<code>';
2420cecf9d5Sandi    }
2430cecf9d5Sandi
2440cecf9d5Sandi    function monospace_close() {
245a2d649c4Sandi        $this->doc .= '</code>';
2460cecf9d5Sandi    }
2470cecf9d5Sandi
2480cecf9d5Sandi    function subscript_open() {
249a2d649c4Sandi        $this->doc .= '<sub>';
2500cecf9d5Sandi    }
2510cecf9d5Sandi
2520cecf9d5Sandi    function subscript_close() {
253a2d649c4Sandi        $this->doc .= '</sub>';
2540cecf9d5Sandi    }
2550cecf9d5Sandi
2560cecf9d5Sandi    function superscript_open() {
257a2d649c4Sandi        $this->doc .= '<sup>';
2580cecf9d5Sandi    }
2590cecf9d5Sandi
2600cecf9d5Sandi    function superscript_close() {
261a2d649c4Sandi        $this->doc .= '</sup>';
2620cecf9d5Sandi    }
2630cecf9d5Sandi
2640cecf9d5Sandi    function deleted_open() {
265a2d649c4Sandi        $this->doc .= '<del>';
2660cecf9d5Sandi    }
2670cecf9d5Sandi
2680cecf9d5Sandi    function deleted_close() {
269a2d649c4Sandi        $this->doc .= '</del>';
2700cecf9d5Sandi    }
2710cecf9d5Sandi
2723fd0b676Sandi    /**
2733fd0b676Sandi     * Callback for footnote start syntax
2743fd0b676Sandi     *
2753fd0b676Sandi     * All following content will go to the footnote instead of
276d74aace9Schris     * the document. To achieve this the previous rendered content
2773fd0b676Sandi     * is moved to $store and $doc is cleared
2783fd0b676Sandi     *
2793fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2803fd0b676Sandi     */
2810cecf9d5Sandi    function footnote_open() {
2827764a90aSandi
2837764a90aSandi        // move current content to store and record footnote
2847764a90aSandi        $this->store = $this->doc;
2857764a90aSandi        $this->doc   = '';
2860cecf9d5Sandi    }
2870cecf9d5Sandi
2883fd0b676Sandi    /**
2893fd0b676Sandi     * Callback for footnote end syntax
2903fd0b676Sandi     *
2913fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2923fd0b676Sandi     * content is restored from $store again
2933fd0b676Sandi     *
2943fd0b676Sandi     * @author Andreas Gohr
2953fd0b676Sandi     */
2960cecf9d5Sandi    function footnote_close() {
2977764a90aSandi
298d74aace9Schris        // recover footnote into the stack and restore old content
299d74aace9Schris        $footnote = $this->doc;
3007764a90aSandi        $this->doc = $this->store;
3017764a90aSandi        $this->store = '';
302d74aace9Schris
303d74aace9Schris        // check to see if this footnote has been seen before
304d74aace9Schris        $i = array_search($footnote, $this->footnotes);
305d74aace9Schris
306d74aace9Schris        if ($i === false) {
307d74aace9Schris            // its a new footnote, add it to the $footnotes array
308d74aace9Schris            $id = count($this->footnotes)+1;
309d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
310d74aace9Schris        } else {
311d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
312d74aace9Schris            $i++;
313d74aace9Schris            $id = count($this->footnotes)+1;
314d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
315d74aace9Schris        }
316d74aace9Schris
3176b379cbfSAndreas Gohr        // output the footnote reference and link
31829bfcd16SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>';
3190cecf9d5Sandi    }
3200cecf9d5Sandi
3210cecf9d5Sandi    function listu_open() {
322a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
3230cecf9d5Sandi    }
3240cecf9d5Sandi
3250cecf9d5Sandi    function listu_close() {
326a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
3270cecf9d5Sandi    }
3280cecf9d5Sandi
3290cecf9d5Sandi    function listo_open() {
330a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
3310cecf9d5Sandi    }
3320cecf9d5Sandi
3330cecf9d5Sandi    function listo_close() {
334a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
3350cecf9d5Sandi    }
3360cecf9d5Sandi
3370cecf9d5Sandi    function listitem_open($level) {
33859869a4bSAnika Henke        $this->doc .= '<li class="level'.$level.'">';
3390cecf9d5Sandi    }
3400cecf9d5Sandi
3410cecf9d5Sandi    function listitem_close() {
342a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
3430cecf9d5Sandi    }
3440cecf9d5Sandi
3450cecf9d5Sandi    function listcontent_open() {
34690db23d7Schris        $this->doc .= '<div class="li">';
3470cecf9d5Sandi    }
3480cecf9d5Sandi
3490cecf9d5Sandi    function listcontent_close() {
35059869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
3510cecf9d5Sandi    }
3520cecf9d5Sandi
3530cecf9d5Sandi    function unformatted($text) {
354a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3550cecf9d5Sandi    }
3560cecf9d5Sandi
3570cecf9d5Sandi    /**
3583fd0b676Sandi     * Execute PHP code if allowed
3593fd0b676Sandi     *
3605d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['phpok'] is okff
3615d568b99SChris Smith     *
3623fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3630cecf9d5Sandi     */
3645d568b99SChris Smith    function php($text, $wrapper='code') {
36535a56260SChris Smith        global $conf;
36635a56260SChris Smith
367d86d5af0SChris Smith        if($conf['phpok']){
368bad0b545Sandi          ob_start();
3694de671bcSandi          eval($text);
3703fd0b676Sandi          $this->doc .= ob_get_contents();
371bad0b545Sandi          ob_end_clean();
372d86d5af0SChris Smith        } else {
3735d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
374d86d5af0SChris Smith        }
3750cecf9d5Sandi    }
3760cecf9d5Sandi
37707f89c3cSAnika Henke    function phpblock($text) {
3785d568b99SChris Smith        $this->php($text, 'pre');
37907f89c3cSAnika Henke    }
38007f89c3cSAnika Henke
3810cecf9d5Sandi    /**
3823fd0b676Sandi     * Insert HTML if allowed
3833fd0b676Sandi     *
3845d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['htmlok'] is okff
3855d568b99SChris Smith     *
3863fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3870cecf9d5Sandi     */
3885d568b99SChris Smith    function html($text, $wrapper='code') {
38935a56260SChris Smith        global $conf;
39035a56260SChris Smith
391d86d5af0SChris Smith        if($conf['htmlok']){
392a2d649c4Sandi          $this->doc .= $text;
393d86d5af0SChris Smith        } else {
3945d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
395d86d5af0SChris Smith        }
3964de671bcSandi    }
3970cecf9d5Sandi
39807f89c3cSAnika Henke    function htmlblock($text) {
3995d568b99SChris Smith        $this->html($text, 'pre');
40007f89c3cSAnika Henke    }
40107f89c3cSAnika Henke
4020cecf9d5Sandi    function quote_open() {
40396331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
4040cecf9d5Sandi    }
4050cecf9d5Sandi
4060cecf9d5Sandi    function quote_close() {
40796331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
4080cecf9d5Sandi    }
4090cecf9d5Sandi
4103d491f75SAndreas Gohr    function preformatted($text) {
411c9250713SAnika Henke        $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF;
4123d491f75SAndreas Gohr    }
4133d491f75SAndreas Gohr
4143d491f75SAndreas Gohr    function file($text, $language=null, $filename=null) {
4153d491f75SAndreas Gohr        $this->_highlight('file',$text,$language,$filename);
4163d491f75SAndreas Gohr    }
4173d491f75SAndreas Gohr
4183d491f75SAndreas Gohr    function code($text, $language=null, $filename=null) {
4193d491f75SAndreas Gohr        $this->_highlight('code',$text,$language,$filename);
4203d491f75SAndreas Gohr    }
4213d491f75SAndreas Gohr
4220cecf9d5Sandi    /**
4233d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
4243fd0b676Sandi     *
4253fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
4260cecf9d5Sandi     */
4273d491f75SAndreas Gohr    function _highlight($type, $text, $language=null, $filename=null) {
4284de671bcSandi        global $conf;
4293d491f75SAndreas Gohr        global $ID;
4303d491f75SAndreas Gohr        global $lang;
4313d491f75SAndreas Gohr
4323d491f75SAndreas Gohr        if($filename){
433190c56e8SAndreas Gohr            // add icon
43427bf7924STom N Harris            list($ext) = mimetype($filename,false);
435190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
436190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
437190c56e8SAndreas Gohr
4383d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
439190c56e8SAndreas Gohr            $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
4403d491f75SAndreas Gohr            $this->doc .= hsc($filename);
4413d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
4423d491f75SAndreas Gohr        }
4430cecf9d5Sandi
4440cecf9d5Sandi        if ( is_null($language) ) {
4453d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
4460cecf9d5Sandi        } else {
4473d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
4483d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
4493d491f75SAndreas Gohr
4503d491f75SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;
4510cecf9d5Sandi        }
4523d491f75SAndreas Gohr
4533d491f75SAndreas Gohr        if($filename){
4543d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
4553d491f75SAndreas Gohr        }
4563d491f75SAndreas Gohr
4573d491f75SAndreas Gohr        $this->_codeblock++;
4580cecf9d5Sandi    }
4590cecf9d5Sandi
4600cecf9d5Sandi    function acronym($acronym) {
4610cecf9d5Sandi
4620cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
4630cecf9d5Sandi
464433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
4650cecf9d5Sandi
466a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
467433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
4680cecf9d5Sandi
4690cecf9d5Sandi        } else {
470a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4710cecf9d5Sandi        }
4720cecf9d5Sandi    }
4730cecf9d5Sandi
4740cecf9d5Sandi    function smiley($smiley) {
4750cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
476433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
477f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4784beabca9SAnika Henke                '" class="middle" alt="'.
479433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4800cecf9d5Sandi        } else {
481a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4820cecf9d5Sandi        }
4830cecf9d5Sandi    }
4840cecf9d5Sandi
485f62ea8a1Sandi    /*
4864de671bcSandi    * not used
4870cecf9d5Sandi    function wordblock($word) {
4880cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
489a2d649c4Sandi            $this->doc .= '** BLEEP **';
4900cecf9d5Sandi        } else {
491a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4920cecf9d5Sandi        }
4930cecf9d5Sandi    }
4944de671bcSandi    */
4950cecf9d5Sandi
4960cecf9d5Sandi    function entity($entity) {
4970cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
498a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4990cecf9d5Sandi        } else {
500a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
5010cecf9d5Sandi        }
5020cecf9d5Sandi    }
5030cecf9d5Sandi
5040cecf9d5Sandi    function multiplyentity($x, $y) {
505a2d649c4Sandi        $this->doc .= "$x&times;$y";
5060cecf9d5Sandi    }
5070cecf9d5Sandi
5080cecf9d5Sandi    function singlequoteopening() {
50971b40da2SAnika Henke        global $lang;
51071b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
5110cecf9d5Sandi    }
5120cecf9d5Sandi
5130cecf9d5Sandi    function singlequoteclosing() {
51471b40da2SAnika Henke        global $lang;
51571b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
5160cecf9d5Sandi    }
5170cecf9d5Sandi
51857d757d1SAndreas Gohr    function apostrophe() {
51957d757d1SAndreas Gohr        global $lang;
520a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
52157d757d1SAndreas Gohr    }
52257d757d1SAndreas Gohr
5230cecf9d5Sandi    function doublequoteopening() {
52471b40da2SAnika Henke        global $lang;
52571b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
5260cecf9d5Sandi    }
5270cecf9d5Sandi
5280cecf9d5Sandi    function doublequoteclosing() {
52971b40da2SAnika Henke        global $lang;
53071b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
5310cecf9d5Sandi    }
5320cecf9d5Sandi
5330cecf9d5Sandi    /**
5340cecf9d5Sandi    */
5350cecf9d5Sandi    function camelcaselink($link) {
53611d0aa47Sandi      $this->internallink($link,$link);
5370cecf9d5Sandi    }
5380cecf9d5Sandi
5390b7c14c2Sandi
5400b7c14c2Sandi    function locallink($hash, $name = NULL){
5410b7c14c2Sandi        global $ID;
5420b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
5430b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
5440b7c14c2Sandi        $title = $ID.' &crarr;';
5450b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
5460b7c14c2Sandi        $this->doc .= $name;
5470b7c14c2Sandi        $this->doc .= '</a>';
5480b7c14c2Sandi    }
5490b7c14c2Sandi
550cffcc403Sandi    /**
5513fd0b676Sandi     * Render an internal Wiki Link
5523fd0b676Sandi     *
553fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
554cffcc403Sandi     * elsewhere - no need to implement them in other renderers
5553fd0b676Sandi     *
5563fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
557cffcc403Sandi     */
558fe9ec250SChris Smith    function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') {
559ba11bd29Sandi        global $conf;
56037e34a5eSandi        global $ID;
5610339c872Sjan        // default name is based on $id as given
5620339c872Sjan        $default = $this->_simpleTitle($id);
563ad32e47eSAndreas Gohr
5640339c872Sjan        // now first resolve and clean up the $id
56537e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
566fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
5670e1c636eSandi        if ( !$isImage ) {
5680e1c636eSandi            if ( $exists ) {
569ba11bd29Sandi                $class='wikilink1';
5700cecf9d5Sandi            } else {
571ba11bd29Sandi                $class='wikilink2';
57244a6b4c7SAndreas Gohr                $link['rel']='nofollow';
5730cecf9d5Sandi            }
5740cecf9d5Sandi        } else {
575ba11bd29Sandi            $class='media';
5760cecf9d5Sandi        }
5770cecf9d5Sandi
578a1685bedSandi        //keep hash anchor
579ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
580943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
581a1685bedSandi
582ba11bd29Sandi        //prepare for formating
583ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
584ba11bd29Sandi        $link['style']  = '';
585ba11bd29Sandi        $link['pre']    = '';
586ba11bd29Sandi        $link['suf']    = '';
58740eb54bbSjan        // highlight link to current page
58840eb54bbSjan        if ($id == $ID) {
58992795d04Sandi            $link['pre']    = '<span class="curid">';
59092795d04Sandi            $link['suf']    = '</span>';
59140eb54bbSjan        }
5925e163278SAndreas Gohr        $link['more']   = '';
593ba11bd29Sandi        $link['class']  = $class;
594ba11bd29Sandi        $link['url']    = wl($id);
595ba11bd29Sandi        $link['name']   = $name;
596ba11bd29Sandi        $link['title']  = $id;
597723d78dbSandi        //add search string
598723d78dbSandi        if($search){
599546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
600546d3a99SAndreas Gohr            if(is_array($search)){
601546d3a99SAndreas Gohr                $search = array_map('rawurlencode',$search);
602546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
603546d3a99SAndreas Gohr            }else{
604546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
605546d3a99SAndreas Gohr            }
606723d78dbSandi        }
607723d78dbSandi
608a1685bedSandi        //keep hash
609a1685bedSandi        if($hash) $link['url'].='#'.$hash;
610a1685bedSandi
611ba11bd29Sandi        //output formatted
612cffcc403Sandi        if($returnonly){
613cffcc403Sandi            return $this->_formatLink($link);
614cffcc403Sandi        }else{
615a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
6160cecf9d5Sandi        }
617cffcc403Sandi    }
6180cecf9d5Sandi
619b625487dSandi    function externallink($url, $name = NULL) {
620b625487dSandi        global $conf;
6210cecf9d5Sandi
622433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
6236f0c5dbfSandi
6240cecf9d5Sandi        if ( !$isImage ) {
625b625487dSandi            $class='urlextern';
6260cecf9d5Sandi        } else {
627b625487dSandi            $class='media';
6280cecf9d5Sandi        }
6290cecf9d5Sandi
630b625487dSandi        //prepare for formating
631b625487dSandi        $link['target'] = $conf['target']['extern'];
632b625487dSandi        $link['style']  = '';
633b625487dSandi        $link['pre']    = '';
634b625487dSandi        $link['suf']    = '';
6355e163278SAndreas Gohr        $link['more']   = '';
636b625487dSandi        $link['class']  = $class;
637b625487dSandi        $link['url']    = $url;
638e1c10e4dSchris
639b625487dSandi        $link['name']   = $name;
640433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
641b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
6420cecf9d5Sandi
643b625487dSandi        //output formatted
644a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6450cecf9d5Sandi    }
6460cecf9d5Sandi
6470cecf9d5Sandi    /**
6480cecf9d5Sandi    */
64997a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
650b625487dSandi        global $conf;
6510cecf9d5Sandi
65297a3e4e3Sandi        $link = array();
65397a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
65497a3e4e3Sandi        $link['pre']    = '';
65597a3e4e3Sandi        $link['suf']    = '';
6565e163278SAndreas Gohr        $link['more']   = '';
657433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
6580cecf9d5Sandi
65997a3e4e3Sandi        //get interwiki URL
6601f82fabeSAndreas Gohr        $url = $this->_resolveInterWiki($wikiName,$wikiUri);
6610cecf9d5Sandi
66297a3e4e3Sandi        if ( !$isImage ) {
6639d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
6649d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
6651c2d1019SAndreas Gohr        } else {
6661c2d1019SAndreas Gohr            $link['class'] = 'media';
66797a3e4e3Sandi        }
6680cecf9d5Sandi
66997a3e4e3Sandi        //do we stay at the same server? Use local target
67097a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
67197a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
67297a3e4e3Sandi        }
6730cecf9d5Sandi
67497a3e4e3Sandi        $link['url'] = $url;
67597a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
67697a3e4e3Sandi
67797a3e4e3Sandi        //output formatted
678a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6790cecf9d5Sandi    }
6800cecf9d5Sandi
6810cecf9d5Sandi    /**
6820cecf9d5Sandi     */
6831d47afe1Sandi    function windowssharelink($url, $name = NULL) {
6841d47afe1Sandi        global $conf;
6851d47afe1Sandi        global $lang;
6861d47afe1Sandi        //simple setup
6871d47afe1Sandi        $link['target'] = $conf['target']['windows'];
6881d47afe1Sandi        $link['pre']    = '';
6891d47afe1Sandi        $link['suf']   = '';
6901d47afe1Sandi        $link['style']  = '';
6910cecf9d5Sandi
692433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6930cecf9d5Sandi        if ( !$isImage ) {
6941d47afe1Sandi            $link['class'] = 'windows';
6950cecf9d5Sandi        } else {
6961d47afe1Sandi            $link['class'] = 'media';
6970cecf9d5Sandi        }
6980cecf9d5Sandi
6990cecf9d5Sandi
700433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
7011d47afe1Sandi        $url = str_replace('\\','/',$url);
7021d47afe1Sandi        $url = 'file:///'.$url;
7031d47afe1Sandi        $link['url'] = $url;
7040cecf9d5Sandi
7051d47afe1Sandi        //output formatted
706a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7070cecf9d5Sandi    }
7080cecf9d5Sandi
70971352defSandi    function emaillink($address, $name = NULL) {
71071352defSandi        global $conf;
71171352defSandi        //simple setup
71271352defSandi        $link = array();
71371352defSandi        $link['target'] = '';
71471352defSandi        $link['pre']    = '';
71571352defSandi        $link['suf']   = '';
71671352defSandi        $link['style']  = '';
71771352defSandi        $link['more']   = '';
7180cecf9d5Sandi
719c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
7200cecf9d5Sandi        if ( !$isImage ) {
721776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
7220cecf9d5Sandi        } else {
723776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
7240cecf9d5Sandi        }
7250cecf9d5Sandi
72607738714SAndreas Gohr        $address = $this->_xmlEntities($address);
72700a7b5adSEsther Brunner        $address = obfuscate($address);
72800a7b5adSEsther Brunner        $title   = $address;
7298c128049SAndreas Gohr
73071352defSandi        if(empty($name)){
73100a7b5adSEsther Brunner            $name = $address;
73271352defSandi        }
7330cecf9d5Sandi
734776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
735776b36ecSAndreas Gohr
736776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
73771352defSandi        $link['name']  = $name;
73871352defSandi        $link['title'] = $title;
7390cecf9d5Sandi
74071352defSandi        //output formatted
741a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7420cecf9d5Sandi    }
7430cecf9d5Sandi
7444826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
745dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
74637e34a5eSandi        global $ID;
74791df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
74837e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
7490cecf9d5Sandi
750d98d4540SBen Coburn        $noLink = false;
7518acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
752b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
7533685f775Sandi
75427bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
755b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
756dc673a5bSjoe.lapp            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
7571c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
7582ca14335SEsther Brunner            // don't link flash movies
75944881bd0Shenning.noren            $noLink = true;
76055efc227SAndreas Gohr        }else{
7612ca14335SEsther Brunner            // add file icons
7629d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
7639d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
7646de3759aSAndreas Gohr            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
76555efc227SAndreas Gohr        }
7663685f775Sandi
76791df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
76891df343aSAndreas Gohr
7696fe20453SGina Haeussge        //markup non existing files
7706fe20453SGina Haeussge        if (!$exists)
7716fe20453SGina Haeussge          $link['class'] .= ' wikilink2';
7726fe20453SGina Haeussge
7733685f775Sandi        //output formatted
774dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7752ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7760cecf9d5Sandi    }
7770cecf9d5Sandi
7784826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
779dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
78091df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
781d98d4540SBen Coburn        $noLink = false;
7828acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
783b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
784b739ff0fSPierre Spring
785b739ff0fSPierre Spring        $link['url']    = ml($src,array('cache'=>$cache));
7863685f775Sandi
78727bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
788b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
7892ca14335SEsther Brunner            // link only jpeg images
79044881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7911c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
7922ca14335SEsther Brunner            // don't link flash movies
79344881bd0Shenning.noren            $noLink = true;
7942ca14335SEsther Brunner        }else{
7952ca14335SEsther Brunner            // add file icons
79627bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
79727bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
7982ca14335SEsther Brunner        }
7992ca14335SEsther Brunner
80091df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
80191df343aSAndreas Gohr
8023685f775Sandi        //output formatted
803dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
8042ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
8050cecf9d5Sandi    }
8060cecf9d5Sandi
8074826ab45Sandi    /**
8083db95becSAndreas Gohr     * Renders an RSS feed
809b625487dSandi     *
810b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
811b625487dSandi     */
8123db95becSAndreas Gohr    function rss ($url,$params){
813b625487dSandi        global $lang;
8143db95becSAndreas Gohr        global $conf;
8153db95becSAndreas Gohr
8163db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
8173db95becSAndreas Gohr        $feed = new FeedParser();
81800077af8SAndreas Gohr        $feed->set_feed_url($url);
819b625487dSandi
820b625487dSandi        //disable warning while fetching
821bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
8223db95becSAndreas Gohr        $rc = $feed->init();
823bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
824b625487dSandi
8253db95becSAndreas Gohr        //decide on start and end
8263db95becSAndreas Gohr        if($params['reverse']){
8273db95becSAndreas Gohr            $mod = -1;
8283db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
8293db95becSAndreas Gohr            $end   = $start - ($params['max']);
830b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
8313db95becSAndreas Gohr        }else{
8323db95becSAndreas Gohr            $mod   = 1;
8333db95becSAndreas Gohr            $start = 0;
8343db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
8353db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
8363db95becSAndreas Gohr        }
8373db95becSAndreas Gohr
838a2d649c4Sandi        $this->doc .= '<ul class="rss">';
8393db95becSAndreas Gohr        if($rc){
8403db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
8411bde1582SAndreas Gohr                $item = $feed->get_item($x);
8423db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
843d2ea3363SAndreas Gohr                // support feeds without links
844d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
845d2ea3363SAndreas Gohr                if($lnkurl){
846793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
847793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
8481bde1582SAndreas Gohr                    $this->externallink($item->get_permalink(),
849793361f8SAndreas Gohr                                        htmlspecialchars_decode($item->get_title()));
850d2ea3363SAndreas Gohr                }else{
851d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
852d2ea3363SAndreas Gohr                }
8533db95becSAndreas Gohr                if($params['author']){
8541bde1582SAndreas Gohr                    $author = $item->get_author(0);
8551bde1582SAndreas Gohr                    if($author){
8561bde1582SAndreas Gohr                        $name = $author->get_name();
8571bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
8581bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
8591bde1582SAndreas Gohr                    }
8603db95becSAndreas Gohr                }
8613db95becSAndreas Gohr                if($params['date']){
8622e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
8633db95becSAndreas Gohr                }
8641bde1582SAndreas Gohr                if($params['details']){
8653db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
866173dccb7STom N Harris                    if($conf['htmlok']){
8671bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
8683db95becSAndreas Gohr                    }else{
8691bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
8703db95becSAndreas Gohr                    }
8713db95becSAndreas Gohr                    $this->doc .= '</div>';
8723db95becSAndreas Gohr                }
8733db95becSAndreas Gohr
8743db95becSAndreas Gohr                $this->doc .= '</div></li>';
875b625487dSandi            }
876b625487dSandi        }else{
8773db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
878a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
879b625487dSandi            $this->externallink($url);
88045e147ccSAndreas Gohr            if($conf['allowdebug']){
88145e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
88245e147ccSAndreas Gohr            }
8833db95becSAndreas Gohr            $this->doc .= '</div></li>';
884b625487dSandi        }
885a2d649c4Sandi        $this->doc .= '</ul>';
886b625487dSandi    }
887b625487dSandi
8880cecf9d5Sandi    // $numrows not yet implemented
88990df9a4dSAdrian Lang    function table_open($maxcols = NULL, $numrows = NULL, $pos){
89090df9a4dSAdrian Lang        global $lang;
891b5742cedSPierre Spring        // initialize the row counter used for classes
892b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
89340868f2fSAdrian Lang        $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table') . '">'.DOKU_LF;
8940cecf9d5Sandi    }
8950cecf9d5Sandi
89690df9a4dSAdrian Lang    function table_close($pos){
89759869a4bSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
89890df9a4dSAdrian Lang        $this->finishSectionEdit($pos);
8990cecf9d5Sandi    }
9000cecf9d5Sandi
9010cecf9d5Sandi    function tablerow_open(){
902b5742cedSPierre Spring        // initialize the cell counter used for classes
903b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
904b5742cedSPierre Spring        $class = 'row' . $this->_counter['row_counter']++;
905b5742cedSPierre Spring        $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
9060cecf9d5Sandi    }
9070cecf9d5Sandi
9080cecf9d5Sandi    function tablerow_close(){
909a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
9100cecf9d5Sandi    }
9110cecf9d5Sandi
91225b97867Shakan.sandell    function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){
913b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9140cecf9d5Sandi        if ( !is_null($align) ) {
915b5742cedSPierre Spring            $class .= ' '.$align.'align';
9160cecf9d5Sandi        }
917b5742cedSPierre Spring        $class .= '"';
918b5742cedSPierre Spring        $this->doc .= '<th ' . $class;
9190cecf9d5Sandi        if ( $colspan > 1 ) {
920a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
921a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
9220cecf9d5Sandi        }
92325b97867Shakan.sandell        if ( $rowspan > 1 ) {
92425b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
92525b97867Shakan.sandell        }
926a2d649c4Sandi        $this->doc .= '>';
9270cecf9d5Sandi    }
9280cecf9d5Sandi
9290cecf9d5Sandi    function tableheader_close(){
930a2d649c4Sandi        $this->doc .= '</th>';
9310cecf9d5Sandi    }
9320cecf9d5Sandi
93325b97867Shakan.sandell    function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){
934b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9350cecf9d5Sandi        if ( !is_null($align) ) {
936b5742cedSPierre Spring            $class .= ' '.$align.'align';
9370cecf9d5Sandi        }
938b5742cedSPierre Spring        $class .= '"';
939b5742cedSPierre Spring        $this->doc .= '<td '.$class;
9400cecf9d5Sandi        if ( $colspan > 1 ) {
941a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
942a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
9430cecf9d5Sandi        }
94425b97867Shakan.sandell        if ( $rowspan > 1 ) {
94525b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
94625b97867Shakan.sandell        }
947a2d649c4Sandi        $this->doc .= '>';
9480cecf9d5Sandi    }
9490cecf9d5Sandi
9500cecf9d5Sandi    function tablecell_close(){
951a2d649c4Sandi        $this->doc .= '</td>';
9520cecf9d5Sandi    }
9530cecf9d5Sandi
9540cecf9d5Sandi    //----------------------------------------------------------
9550cecf9d5Sandi    // Utils
9560cecf9d5Sandi
957ba11bd29Sandi    /**
9583fd0b676Sandi     * Build a link
9593fd0b676Sandi     *
9603fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
961ba11bd29Sandi     *
962ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
963ba11bd29Sandi     */
964433bef32Sandi    function _formatLink($link){
965ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
966ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
967ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
968ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
969ba11bd29Sandi        }
970ba11bd29Sandi        //remove double encodings in titles
971ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
972ba11bd29Sandi
973453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
974453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
975453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
976453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
977453493f2SAndreas Gohr
978ba11bd29Sandi        $ret  = '';
979ba11bd29Sandi        $ret .= $link['pre'];
980ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
981bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
982bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
983bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
984bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
98544a6b4c7SAndreas Gohr        if(!empty($link['rel']))    $ret .= ' rel="'.$link['rel'].'"';
986bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
987ba11bd29Sandi        $ret .= '>';
988ba11bd29Sandi        $ret .= $link['name'];
989ba11bd29Sandi        $ret .= '</a>';
990ba11bd29Sandi        $ret .= $link['suf'];
991ba11bd29Sandi        return $ret;
992ba11bd29Sandi    }
993ba11bd29Sandi
994ba11bd29Sandi    /**
9953fd0b676Sandi     * Renders internal and external media
9963fd0b676Sandi     *
9973fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9983fd0b676Sandi     */
9993fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
1000b739ff0fSPierre Spring                      $height=NULL, $cache=NULL, $render = true) {
10013fd0b676Sandi
10023fd0b676Sandi        $ret = '';
10033fd0b676Sandi
1004ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
10053fd0b676Sandi        if(substr($mime,0,5) == 'image'){
1006b739ff0fSPierre Spring            // first get the $title
1007b739ff0fSPierre Spring            if (!is_null($title)) {
1008b739ff0fSPierre Spring                $title  = $this->_xmlEntities($title);
1009b739ff0fSPierre Spring            }elseif($ext == 'jpg' || $ext == 'jpeg'){
1010b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1011b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
101267f9913dSAndreas Gohr                $jpeg =new JpegMeta(mediaFN($src));
1013b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
1014b739ff0fSPierre Spring                if($cap){
1015b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1016b739ff0fSPierre Spring                }
1017b739ff0fSPierre Spring            }
1018b739ff0fSPierre Spring            if (!$render) {
1019b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1020b739ff0fSPierre Spring                // return the title of the picture
1021b739ff0fSPierre Spring                if (!$title) {
1022b739ff0fSPierre Spring                    // just show the sourcename
1023b739ff0fSPierre Spring                    $title = $this->_xmlEntities(basename(noNS($src)));
1024b739ff0fSPierre Spring                }
1025b739ff0fSPierre Spring                return $title;
1026b739ff0fSPierre Spring            }
10273fd0b676Sandi            //add image tag
10286de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
10293fd0b676Sandi            $ret .= ' class="media'.$align.'"';
10303fd0b676Sandi
10314ab889eaSAndreas Gohr            // make left/right alignment for no-CSS view work (feeds)
10324ab889eaSAndreas Gohr            if($align == 'right') $ret .= ' align="right"';
10334ab889eaSAndreas Gohr            if($align == 'left')  $ret .= ' align="left"';
10344ab889eaSAndreas Gohr
1035b739ff0fSPierre Spring            if ($title) {
1036b739ff0fSPierre Spring                $ret .= ' title="' . $title . '"';
1037b739ff0fSPierre Spring                $ret .= ' alt="'   . $title .'"';
10383fd0b676Sandi            }else{
10393fd0b676Sandi                $ret .= ' alt=""';
10403fd0b676Sandi            }
10413fd0b676Sandi
10423fd0b676Sandi            if ( !is_null($width) )
10433fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
10443fd0b676Sandi
10453fd0b676Sandi            if ( !is_null($height) )
10463fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
10473fd0b676Sandi
10483fd0b676Sandi            $ret .= ' />';
10493fd0b676Sandi
10503fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
10511c882ba8SAndreas Gohr            if (!$render) {
10521c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
10531c882ba8SAndreas Gohr                // return the title of the flash
10541c882ba8SAndreas Gohr                if (!$title) {
10551c882ba8SAndreas Gohr                    // just show the sourcename
105607bf32b2SAndreas Gohr                    $title = basename(noNS($src));
10571c882ba8SAndreas Gohr                }
105807bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
10591c882ba8SAndreas Gohr            }
10601c882ba8SAndreas Gohr
106107bf32b2SAndreas Gohr            $att = array();
106207bf32b2SAndreas Gohr            $att['class'] = "media$align";
106307bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
106407bf32b2SAndreas Gohr            if($align == 'left')  $att['align'] = 'left';
1065c471e6a6SAndreas Gohr            $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height,
106607bf32b2SAndreas Gohr                                     array('quality' => 'high'),
106707bf32b2SAndreas Gohr                                     null,
106807bf32b2SAndreas Gohr                                     $att,
106907bf32b2SAndreas Gohr                                     $this->_xmlEntities($title));
10700f428d7dSAndreas Gohr        }elseif($title){
10713fd0b676Sandi            // well at least we have a title to display
10723fd0b676Sandi            $ret .= $this->_xmlEntities($title);
10733fd0b676Sandi        }else{
10745291ca3aSAndreas Gohr            // just show the sourcename
10750f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
10763fd0b676Sandi        }
10773fd0b676Sandi
10783fd0b676Sandi        return $ret;
10793fd0b676Sandi    }
10803fd0b676Sandi
1081433bef32Sandi    function _xmlEntities($string) {
1082de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
10830cecf9d5Sandi    }
10840cecf9d5Sandi
10858a831f2bSAndreas Gohr    /**
10868a831f2bSAndreas Gohr     * Creates a linkid from a headline
1087c5a8fd96SAndreas Gohr     *
1088c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1089c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
1090c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
10918a831f2bSAndreas Gohr     */
1092c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
1093c5a8fd96SAndreas Gohr        if($create){
10944ceab83fSAndreas Gohr            return sectionID($title,$this->headers);
10954ceab83fSAndreas Gohr        }else{
1096443d207bSAndreas Gohr            $check = false;
1097443d207bSAndreas Gohr            return sectionID($title,$check);
1098c5a8fd96SAndreas Gohr        }
10990cecf9d5Sandi    }
11000cecf9d5Sandi
1101af587fa8Sandi    /**
11023fd0b676Sandi     * Construct a title and handle images in titles
11033fd0b676Sandi     *
11040b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
11053fd0b676Sandi     */
1106fe9ec250SChris Smith    function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') {
1107bb0a59d4Sjan        global $conf;
1108bb0a59d4Sjan
110944881bd0Shenning.noren        $isImage = false;
111029657f9eSAndreas Gohr        if ( is_array($title) ) {
111129657f9eSAndreas Gohr            $isImage = true;
111229657f9eSAndreas Gohr            return $this->_imageTitle($title);
111329657f9eSAndreas Gohr        } elseif ( is_null($title) || trim($title)=='') {
1114fe9ec250SChris Smith            if (useHeading($linktype) && $id) {
1115fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1116bb0a59d4Sjan                if ($heading) {
1117433bef32Sandi                    return $this->_xmlEntities($heading);
1118bb0a59d4Sjan                }
1119bb0a59d4Sjan            }
1120433bef32Sandi            return $this->_xmlEntities($default);
112168c26e6dSMichael Klier        } else {
112268c26e6dSMichael Klier            return $this->_xmlEntities($title);
11230cecf9d5Sandi        }
11240cecf9d5Sandi    }
11250cecf9d5Sandi
11260cecf9d5Sandi    /**
11273fd0b676Sandi     * Returns an HTML code for images used in link titles
11283fd0b676Sandi     *
11293fd0b676Sandi     * @todo Resolve namespace on internal images
11303fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
11310cecf9d5Sandi     */
1132433bef32Sandi    function _imageTitle($img) {
1133d9baf1a7SKazutaka Miyasaka        global $ID;
1134d9baf1a7SKazutaka Miyasaka
1135d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1136d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
1137d9baf1a7SKazutaka Miyasaka        list($img['src'],$hash) = explode('#',$img['src'],2);
1138d9baf1a7SKazutaka Miyasaka        if ($img['type'] == 'internalmedia') {
1139d9baf1a7SKazutaka Miyasaka            resolve_mediaid(getNS($ID),$img['src'],$exists);
1140d9baf1a7SKazutaka Miyasaka        }
1141d9baf1a7SKazutaka Miyasaka
1142433bef32Sandi        return $this->_media($img['src'],
11434826ab45Sandi                              $img['title'],
11444826ab45Sandi                              $img['align'],
11454826ab45Sandi                              $img['width'],
11464826ab45Sandi                              $img['height'],
11474826ab45Sandi                              $img['cache']);
11480cecf9d5Sandi    }
1149b739ff0fSPierre Spring
1150b739ff0fSPierre Spring    /**
1151b739ff0fSPierre Spring     * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia()
1152b739ff0fSPierre Spring     * which returns a basic link to a media.
1153b739ff0fSPierre Spring     *
1154b739ff0fSPierre Spring     * @author Pierre Spring <pierre.spring@liip.ch>
1155b739ff0fSPierre Spring     * @param string $src
1156b739ff0fSPierre Spring     * @param string $title
1157b739ff0fSPierre Spring     * @param string $align
1158b739ff0fSPierre Spring     * @param string $width
1159b739ff0fSPierre Spring     * @param string $height
1160b739ff0fSPierre Spring     * @param string $cache
1161b739ff0fSPierre Spring     * @param string $render
1162b739ff0fSPierre Spring     * @access protected
1163b739ff0fSPierre Spring     * @return array
1164b739ff0fSPierre Spring     */
1165b739ff0fSPierre Spring    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render)
1166b739ff0fSPierre Spring    {
1167b739ff0fSPierre Spring        global $conf;
1168b739ff0fSPierre Spring
1169b739ff0fSPierre Spring        $link = array();
1170b739ff0fSPierre Spring        $link['class']  = 'media';
1171b739ff0fSPierre Spring        $link['style']  = '';
1172b739ff0fSPierre Spring        $link['pre']    = '';
1173b739ff0fSPierre Spring        $link['suf']    = '';
1174b739ff0fSPierre Spring        $link['more']   = '';
1175b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1176b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1177b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1178b739ff0fSPierre Spring
1179b739ff0fSPierre Spring        return $link;
1180b739ff0fSPierre Spring    }
118191459163SAnika Henke
118291459163SAnika Henke
11830cecf9d5Sandi}
11840cecf9d5Sandi
11854826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1186