xref: /dokuwiki/inc/parser/xhtml.php (revision 40868f2faa85215dfea2fa0c82274a4806d042ab)
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     */
52*40868f2fSAdrian 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);
66*40868f2fSAdrian Lang        $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' ';
67*40868f2fSAdrian Lang        if (!is_null($title)) {
68*40868f2fSAdrian Lang            $this->doc .= '"' . str_replace('"', '', $title) . '" ';
69*40868f2fSAdrian Lang        }
70*40868f2fSAdrian Lang        $this->doc .= "[$start-" . ($end === 0 ? '' : $end) . '] -->';
7190df9a4dSAdrian Lang    }
7290df9a4dSAdrian Lang
735f70445dSAndreas Gohr    function getFormat(){
745f70445dSAndreas Gohr        return 'xhtml';
755f70445dSAndreas Gohr    }
765f70445dSAndreas Gohr
775f70445dSAndreas Gohr
780cecf9d5Sandi    function document_start() {
79c5a8fd96SAndreas Gohr        //reset some internals
80c5a8fd96SAndreas Gohr        $this->toc     = array();
81c5a8fd96SAndreas Gohr        $this->headers = array();
820cecf9d5Sandi    }
830cecf9d5Sandi
840cecf9d5Sandi    function document_end() {
8590df9a4dSAdrian Lang        // Finish open section edits.
8690df9a4dSAdrian Lang        while (count($this->sectionedits) > 0) {
8790df9a4dSAdrian Lang            if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) {
8890df9a4dSAdrian Lang                // If there is only one section, do not write a section edit
8990df9a4dSAdrian Lang                // marker.
9090df9a4dSAdrian Lang                array_pop($this->sectionedits);
9190df9a4dSAdrian Lang            } else {
9290df9a4dSAdrian Lang                $this->finishSectionEdit(0);
9390df9a4dSAdrian Lang            }
9490df9a4dSAdrian Lang        }
9590df9a4dSAdrian Lang
960cecf9d5Sandi        if ( count ($this->footnotes) > 0 ) {
97a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
98d74aace9Schris
99d74aace9Schris            $id = 0;
1000cecf9d5Sandi            foreach ( $this->footnotes as $footnote ) {
101d74aace9Schris                $id++;   // the number of the current footnote
102d74aace9Schris
103d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
104d74aace9Schris                if (substr($footnote, 0, 5) != "@@FNT") {
105d74aace9Schris
106d74aace9Schris                    // open the footnote and set the anchor and backlink
107d74aace9Schris                    $this->doc .= '<div class="fn">';
10829bfcd16SAndreas Gohr                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
10929bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
110d74aace9Schris
111d74aace9Schris                    // get any other footnotes that use the same markup
112d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
113d74aace9Schris
114d74aace9Schris                    if (count($alt)) {
115d74aace9Schris                      foreach ($alt as $ref) {
116d74aace9Schris                        // set anchor and backlink for the other footnotes
11729bfcd16SAndreas Gohr                        $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
11829bfcd16SAndreas Gohr                        $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF;
119d74aace9Schris                      }
120d74aace9Schris                    }
121d74aace9Schris
122d74aace9Schris                    // add footnote markup and close this footnote
123a2d649c4Sandi                    $this->doc .= $footnote;
124d74aace9Schris                    $this->doc .= '</div>' . DOKU_LF;
125d74aace9Schris                }
1260cecf9d5Sandi            }
127a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
1280cecf9d5Sandi        }
129c5a8fd96SAndreas Gohr
130b8595a66SAndreas Gohr        // Prepare the TOC
131851f2e89SAnika Henke        global $conf;
132851f2e89SAnika Henke        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){
133b8595a66SAndreas Gohr            global $TOC;
134b8595a66SAndreas Gohr            $TOC = $this->toc;
1350cecf9d5Sandi        }
1363e55d035SAndreas Gohr
1373e55d035SAndreas Gohr        // make sure there are no empty paragraphs
13827918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
139e41c4da9SAndreas Gohr    }
1400cecf9d5Sandi
141e7856beaSchris    function toc_additem($id, $text, $level) {
142af587fa8Sandi        global $conf;
143af587fa8Sandi
144c5a8fd96SAndreas Gohr        //handle TOC
145c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
1467d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);
147c5a8fd96SAndreas Gohr        }
148e7856beaSchris    }
149e7856beaSchris
150e7856beaSchris    function header($text, $level, $pos) {
15190df9a4dSAdrian Lang        global $conf;
15290df9a4dSAdrian Lang
153bdd8111bSAndreas Gohr        if(!$text) return; //skip empty headlines
154e7856beaSchris
155e7856beaSchris        $hid = $this->_headerToLink($text,true);
156e7856beaSchris
157e7856beaSchris        //only add items within configured levels
158e7856beaSchris        $this->toc_additem($hid, $text, $level);
159c5a8fd96SAndreas Gohr
16091459163SAnika Henke        // adjust $node to reflect hierarchy of levels
16191459163SAnika Henke        $this->node[$level-1]++;
16291459163SAnika Henke        if ($level < $this->lastlevel) {
16391459163SAnika Henke            for ($i = 0; $i < $this->lastlevel-$level; $i++) {
16491459163SAnika Henke                $this->node[$this->lastlevel-$i-1] = 0;
16591459163SAnika Henke            }
16691459163SAnika Henke        }
16791459163SAnika Henke        $this->lastlevel = $level;
16891459163SAnika Henke
16990df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel'] &&
17090df9a4dSAdrian Lang            count($this->sectionedits) > 0 &&
17190df9a4dSAdrian Lang            $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') {
1726c1f778cSAdrian Lang            $this->finishSectionEdit($pos - 1);
17390df9a4dSAdrian Lang        }
17490df9a4dSAdrian Lang
175c5a8fd96SAndreas Gohr        // write the header
17690df9a4dSAdrian Lang        $this->doc .= DOKU_LF.'<h'.$level;
17790df9a4dSAdrian Lang        if ($level <= $conf['maxseclevel']) {
17890df9a4dSAdrian Lang            $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"';
17990df9a4dSAdrian Lang        }
18090df9a4dSAdrian Lang        $this->doc .= '><a name="'.$hid.'" id="'.$hid.'">';
181a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
18259869a4bSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1830cecf9d5Sandi    }
1840cecf9d5Sandi
1850cecf9d5Sandi    function section_open($level) {
18690df9a4dSAdrian Lang        $this->doc .= "<div class='level$level'>".DOKU_LF;
1870cecf9d5Sandi    }
1880cecf9d5Sandi
1890cecf9d5Sandi    function section_close() {
190a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1910cecf9d5Sandi    }
1920cecf9d5Sandi
1930cecf9d5Sandi    function cdata($text) {
194a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1950cecf9d5Sandi    }
1960cecf9d5Sandi
1970cecf9d5Sandi    function p_open() {
19859869a4bSAnika Henke        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
1990cecf9d5Sandi    }
2000cecf9d5Sandi
2010cecf9d5Sandi    function p_close() {
20259869a4bSAnika Henke        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
2030cecf9d5Sandi    }
2040cecf9d5Sandi
2050cecf9d5Sandi    function linebreak() {
206a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
2070cecf9d5Sandi    }
2080cecf9d5Sandi
2090cecf9d5Sandi    function hr() {
2104beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
2110cecf9d5Sandi    }
2120cecf9d5Sandi
2130cecf9d5Sandi    function strong_open() {
214a2d649c4Sandi        $this->doc .= '<strong>';
2150cecf9d5Sandi    }
2160cecf9d5Sandi
2170cecf9d5Sandi    function strong_close() {
218a2d649c4Sandi        $this->doc .= '</strong>';
2190cecf9d5Sandi    }
2200cecf9d5Sandi
2210cecf9d5Sandi    function emphasis_open() {
222a2d649c4Sandi        $this->doc .= '<em>';
2230cecf9d5Sandi    }
2240cecf9d5Sandi
2250cecf9d5Sandi    function emphasis_close() {
226a2d649c4Sandi        $this->doc .= '</em>';
2270cecf9d5Sandi    }
2280cecf9d5Sandi
2290cecf9d5Sandi    function underline_open() {
23002e51121SAnika Henke        $this->doc .= '<em class="u">';
2310cecf9d5Sandi    }
2320cecf9d5Sandi
2330cecf9d5Sandi    function underline_close() {
23402e51121SAnika Henke        $this->doc .= '</em>';
2350cecf9d5Sandi    }
2360cecf9d5Sandi
2370cecf9d5Sandi    function monospace_open() {
238a2d649c4Sandi        $this->doc .= '<code>';
2390cecf9d5Sandi    }
2400cecf9d5Sandi
2410cecf9d5Sandi    function monospace_close() {
242a2d649c4Sandi        $this->doc .= '</code>';
2430cecf9d5Sandi    }
2440cecf9d5Sandi
2450cecf9d5Sandi    function subscript_open() {
246a2d649c4Sandi        $this->doc .= '<sub>';
2470cecf9d5Sandi    }
2480cecf9d5Sandi
2490cecf9d5Sandi    function subscript_close() {
250a2d649c4Sandi        $this->doc .= '</sub>';
2510cecf9d5Sandi    }
2520cecf9d5Sandi
2530cecf9d5Sandi    function superscript_open() {
254a2d649c4Sandi        $this->doc .= '<sup>';
2550cecf9d5Sandi    }
2560cecf9d5Sandi
2570cecf9d5Sandi    function superscript_close() {
258a2d649c4Sandi        $this->doc .= '</sup>';
2590cecf9d5Sandi    }
2600cecf9d5Sandi
2610cecf9d5Sandi    function deleted_open() {
262a2d649c4Sandi        $this->doc .= '<del>';
2630cecf9d5Sandi    }
2640cecf9d5Sandi
2650cecf9d5Sandi    function deleted_close() {
266a2d649c4Sandi        $this->doc .= '</del>';
2670cecf9d5Sandi    }
2680cecf9d5Sandi
2693fd0b676Sandi    /**
2703fd0b676Sandi     * Callback for footnote start syntax
2713fd0b676Sandi     *
2723fd0b676Sandi     * All following content will go to the footnote instead of
273d74aace9Schris     * the document. To achieve this the previous rendered content
2743fd0b676Sandi     * is moved to $store and $doc is cleared
2753fd0b676Sandi     *
2763fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2773fd0b676Sandi     */
2780cecf9d5Sandi    function footnote_open() {
2797764a90aSandi
2807764a90aSandi        // move current content to store and record footnote
2817764a90aSandi        $this->store = $this->doc;
2827764a90aSandi        $this->doc   = '';
2830cecf9d5Sandi    }
2840cecf9d5Sandi
2853fd0b676Sandi    /**
2863fd0b676Sandi     * Callback for footnote end syntax
2873fd0b676Sandi     *
2883fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2893fd0b676Sandi     * content is restored from $store again
2903fd0b676Sandi     *
2913fd0b676Sandi     * @author Andreas Gohr
2923fd0b676Sandi     */
2930cecf9d5Sandi    function footnote_close() {
2947764a90aSandi
295d74aace9Schris        // recover footnote into the stack and restore old content
296d74aace9Schris        $footnote = $this->doc;
2977764a90aSandi        $this->doc = $this->store;
2987764a90aSandi        $this->store = '';
299d74aace9Schris
300d74aace9Schris        // check to see if this footnote has been seen before
301d74aace9Schris        $i = array_search($footnote, $this->footnotes);
302d74aace9Schris
303d74aace9Schris        if ($i === false) {
304d74aace9Schris            // its a new footnote, add it to the $footnotes array
305d74aace9Schris            $id = count($this->footnotes)+1;
306d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
307d74aace9Schris        } else {
308d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
309d74aace9Schris            $i++;
310d74aace9Schris            $id = count($this->footnotes)+1;
311d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
312d74aace9Schris        }
313d74aace9Schris
3146b379cbfSAndreas Gohr        // output the footnote reference and link
31529bfcd16SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>';
3160cecf9d5Sandi    }
3170cecf9d5Sandi
3180cecf9d5Sandi    function listu_open() {
319a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
3200cecf9d5Sandi    }
3210cecf9d5Sandi
3220cecf9d5Sandi    function listu_close() {
323a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
3240cecf9d5Sandi    }
3250cecf9d5Sandi
3260cecf9d5Sandi    function listo_open() {
327a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
3280cecf9d5Sandi    }
3290cecf9d5Sandi
3300cecf9d5Sandi    function listo_close() {
331a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
3320cecf9d5Sandi    }
3330cecf9d5Sandi
3340cecf9d5Sandi    function listitem_open($level) {
33559869a4bSAnika Henke        $this->doc .= '<li class="level'.$level.'">';
3360cecf9d5Sandi    }
3370cecf9d5Sandi
3380cecf9d5Sandi    function listitem_close() {
339a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
3400cecf9d5Sandi    }
3410cecf9d5Sandi
3420cecf9d5Sandi    function listcontent_open() {
34390db23d7Schris        $this->doc .= '<div class="li">';
3440cecf9d5Sandi    }
3450cecf9d5Sandi
3460cecf9d5Sandi    function listcontent_close() {
34759869a4bSAnika Henke        $this->doc .= '</div>'.DOKU_LF;
3480cecf9d5Sandi    }
3490cecf9d5Sandi
3500cecf9d5Sandi    function unformatted($text) {
351a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3520cecf9d5Sandi    }
3530cecf9d5Sandi
3540cecf9d5Sandi    /**
3553fd0b676Sandi     * Execute PHP code if allowed
3563fd0b676Sandi     *
3575d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['phpok'] is okff
3585d568b99SChris Smith     *
3593fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3600cecf9d5Sandi     */
3615d568b99SChris Smith    function php($text, $wrapper='code') {
36235a56260SChris Smith        global $conf;
36335a56260SChris Smith
364d86d5af0SChris Smith        if($conf['phpok']){
365bad0b545Sandi          ob_start();
3664de671bcSandi          eval($text);
3673fd0b676Sandi          $this->doc .= ob_get_contents();
368bad0b545Sandi          ob_end_clean();
369d86d5af0SChris Smith        } else {
3705d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
371d86d5af0SChris Smith        }
3720cecf9d5Sandi    }
3730cecf9d5Sandi
37407f89c3cSAnika Henke    function phpblock($text) {
3755d568b99SChris Smith        $this->php($text, 'pre');
37607f89c3cSAnika Henke    }
37707f89c3cSAnika Henke
3780cecf9d5Sandi    /**
3793fd0b676Sandi     * Insert HTML if allowed
3803fd0b676Sandi     *
3815d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['htmlok'] is okff
3825d568b99SChris Smith     *
3833fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3840cecf9d5Sandi     */
3855d568b99SChris Smith    function html($text, $wrapper='code') {
38635a56260SChris Smith        global $conf;
38735a56260SChris Smith
388d86d5af0SChris Smith        if($conf['htmlok']){
389a2d649c4Sandi          $this->doc .= $text;
390d86d5af0SChris Smith        } else {
3915d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
392d86d5af0SChris Smith        }
3934de671bcSandi    }
3940cecf9d5Sandi
39507f89c3cSAnika Henke    function htmlblock($text) {
3965d568b99SChris Smith        $this->html($text, 'pre');
39707f89c3cSAnika Henke    }
39807f89c3cSAnika Henke
3990cecf9d5Sandi    function quote_open() {
40096331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
4010cecf9d5Sandi    }
4020cecf9d5Sandi
4030cecf9d5Sandi    function quote_close() {
40496331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
4050cecf9d5Sandi    }
4060cecf9d5Sandi
4073d491f75SAndreas Gohr    function preformatted($text) {
408c9250713SAnika Henke        $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF;
4093d491f75SAndreas Gohr    }
4103d491f75SAndreas Gohr
4113d491f75SAndreas Gohr    function file($text, $language=null, $filename=null) {
4123d491f75SAndreas Gohr        $this->_highlight('file',$text,$language,$filename);
4133d491f75SAndreas Gohr    }
4143d491f75SAndreas Gohr
4153d491f75SAndreas Gohr    function code($text, $language=null, $filename=null) {
4163d491f75SAndreas Gohr        $this->_highlight('code',$text,$language,$filename);
4173d491f75SAndreas Gohr    }
4183d491f75SAndreas Gohr
4190cecf9d5Sandi    /**
4203d491f75SAndreas Gohr     * Use GeSHi to highlight language syntax in code and file blocks
4213fd0b676Sandi     *
4223fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
4230cecf9d5Sandi     */
4243d491f75SAndreas Gohr    function _highlight($type, $text, $language=null, $filename=null) {
4254de671bcSandi        global $conf;
4263d491f75SAndreas Gohr        global $ID;
4273d491f75SAndreas Gohr        global $lang;
4283d491f75SAndreas Gohr
4293d491f75SAndreas Gohr        if($filename){
430190c56e8SAndreas Gohr            // add icon
43127bf7924STom N Harris            list($ext) = mimetype($filename,false);
432190c56e8SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
433190c56e8SAndreas Gohr            $class = 'mediafile mf_'.$class;
434190c56e8SAndreas Gohr
4353d491f75SAndreas Gohr            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
436190c56e8SAndreas Gohr            $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
4373d491f75SAndreas Gohr            $this->doc .= hsc($filename);
4383d491f75SAndreas Gohr            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
4393d491f75SAndreas Gohr        }
4400cecf9d5Sandi
4410cecf9d5Sandi        if ( is_null($language) ) {
4423d491f75SAndreas Gohr            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
4430cecf9d5Sandi        } else {
4443d491f75SAndreas Gohr            $class = 'code'; //we always need the code class to make the syntax highlighting apply
4453d491f75SAndreas Gohr            if($type != 'code') $class .= ' '.$type;
4463d491f75SAndreas Gohr
4473d491f75SAndreas Gohr            $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;
4480cecf9d5Sandi        }
4493d491f75SAndreas Gohr
4503d491f75SAndreas Gohr        if($filename){
4513d491f75SAndreas Gohr            $this->doc .= '</dd></dl>'.DOKU_LF;
4523d491f75SAndreas Gohr        }
4533d491f75SAndreas Gohr
4543d491f75SAndreas Gohr        $this->_codeblock++;
4550cecf9d5Sandi    }
4560cecf9d5Sandi
4570cecf9d5Sandi    function acronym($acronym) {
4580cecf9d5Sandi
4590cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
4600cecf9d5Sandi
461433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
4620cecf9d5Sandi
463a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
464433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
4650cecf9d5Sandi
4660cecf9d5Sandi        } else {
467a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
4680cecf9d5Sandi        }
4690cecf9d5Sandi    }
4700cecf9d5Sandi
4710cecf9d5Sandi    function smiley($smiley) {
4720cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
473433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
474f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4754beabca9SAnika Henke                '" class="middle" alt="'.
476433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4770cecf9d5Sandi        } else {
478a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4790cecf9d5Sandi        }
4800cecf9d5Sandi    }
4810cecf9d5Sandi
482f62ea8a1Sandi    /*
4834de671bcSandi    * not used
4840cecf9d5Sandi    function wordblock($word) {
4850cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
486a2d649c4Sandi            $this->doc .= '** BLEEP **';
4870cecf9d5Sandi        } else {
488a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4890cecf9d5Sandi        }
4900cecf9d5Sandi    }
4914de671bcSandi    */
4920cecf9d5Sandi
4930cecf9d5Sandi    function entity($entity) {
4940cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
495a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4960cecf9d5Sandi        } else {
497a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4980cecf9d5Sandi        }
4990cecf9d5Sandi    }
5000cecf9d5Sandi
5010cecf9d5Sandi    function multiplyentity($x, $y) {
502a2d649c4Sandi        $this->doc .= "$x&times;$y";
5030cecf9d5Sandi    }
5040cecf9d5Sandi
5050cecf9d5Sandi    function singlequoteopening() {
50671b40da2SAnika Henke        global $lang;
50771b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
5080cecf9d5Sandi    }
5090cecf9d5Sandi
5100cecf9d5Sandi    function singlequoteclosing() {
51171b40da2SAnika Henke        global $lang;
51271b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
5130cecf9d5Sandi    }
5140cecf9d5Sandi
51557d757d1SAndreas Gohr    function apostrophe() {
51657d757d1SAndreas Gohr        global $lang;
517a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
51857d757d1SAndreas Gohr    }
51957d757d1SAndreas Gohr
5200cecf9d5Sandi    function doublequoteopening() {
52171b40da2SAnika Henke        global $lang;
52271b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
5230cecf9d5Sandi    }
5240cecf9d5Sandi
5250cecf9d5Sandi    function doublequoteclosing() {
52671b40da2SAnika Henke        global $lang;
52771b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
5280cecf9d5Sandi    }
5290cecf9d5Sandi
5300cecf9d5Sandi    /**
5310cecf9d5Sandi    */
5320cecf9d5Sandi    function camelcaselink($link) {
53311d0aa47Sandi      $this->internallink($link,$link);
5340cecf9d5Sandi    }
5350cecf9d5Sandi
5360b7c14c2Sandi
5370b7c14c2Sandi    function locallink($hash, $name = NULL){
5380b7c14c2Sandi        global $ID;
5390b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
5400b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
5410b7c14c2Sandi        $title = $ID.' &crarr;';
5420b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
5430b7c14c2Sandi        $this->doc .= $name;
5440b7c14c2Sandi        $this->doc .= '</a>';
5450b7c14c2Sandi    }
5460b7c14c2Sandi
547cffcc403Sandi    /**
5483fd0b676Sandi     * Render an internal Wiki Link
5493fd0b676Sandi     *
550fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
551cffcc403Sandi     * elsewhere - no need to implement them in other renderers
5523fd0b676Sandi     *
5533fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
554cffcc403Sandi     */
555fe9ec250SChris Smith    function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') {
556ba11bd29Sandi        global $conf;
55737e34a5eSandi        global $ID;
5580339c872Sjan        // default name is based on $id as given
5590339c872Sjan        $default = $this->_simpleTitle($id);
560ad32e47eSAndreas Gohr
5610339c872Sjan        // now first resolve and clean up the $id
56237e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
563fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
5640e1c636eSandi        if ( !$isImage ) {
5650e1c636eSandi            if ( $exists ) {
566ba11bd29Sandi                $class='wikilink1';
5670cecf9d5Sandi            } else {
568ba11bd29Sandi                $class='wikilink2';
56944a6b4c7SAndreas Gohr                $link['rel']='nofollow';
5700cecf9d5Sandi            }
5710cecf9d5Sandi        } else {
572ba11bd29Sandi            $class='media';
5730cecf9d5Sandi        }
5740cecf9d5Sandi
575a1685bedSandi        //keep hash anchor
576ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
577943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
578a1685bedSandi
579ba11bd29Sandi        //prepare for formating
580ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
581ba11bd29Sandi        $link['style']  = '';
582ba11bd29Sandi        $link['pre']    = '';
583ba11bd29Sandi        $link['suf']    = '';
58440eb54bbSjan        // highlight link to current page
58540eb54bbSjan        if ($id == $ID) {
58692795d04Sandi            $link['pre']    = '<span class="curid">';
58792795d04Sandi            $link['suf']    = '</span>';
58840eb54bbSjan        }
5895e163278SAndreas Gohr        $link['more']   = '';
590ba11bd29Sandi        $link['class']  = $class;
591ba11bd29Sandi        $link['url']    = wl($id);
592ba11bd29Sandi        $link['name']   = $name;
593ba11bd29Sandi        $link['title']  = $id;
594723d78dbSandi        //add search string
595723d78dbSandi        if($search){
596546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
597546d3a99SAndreas Gohr            if(is_array($search)){
598546d3a99SAndreas Gohr                $search = array_map('rawurlencode',$search);
599546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
600546d3a99SAndreas Gohr            }else{
601546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
602546d3a99SAndreas Gohr            }
603723d78dbSandi        }
604723d78dbSandi
605a1685bedSandi        //keep hash
606a1685bedSandi        if($hash) $link['url'].='#'.$hash;
607a1685bedSandi
608ba11bd29Sandi        //output formatted
609cffcc403Sandi        if($returnonly){
610cffcc403Sandi            return $this->_formatLink($link);
611cffcc403Sandi        }else{
612a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
6130cecf9d5Sandi        }
614cffcc403Sandi    }
6150cecf9d5Sandi
616b625487dSandi    function externallink($url, $name = NULL) {
617b625487dSandi        global $conf;
6180cecf9d5Sandi
619433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
6206f0c5dbfSandi
6210cecf9d5Sandi        if ( !$isImage ) {
622b625487dSandi            $class='urlextern';
6230cecf9d5Sandi        } else {
624b625487dSandi            $class='media';
6250cecf9d5Sandi        }
6260cecf9d5Sandi
627b625487dSandi        //prepare for formating
628b625487dSandi        $link['target'] = $conf['target']['extern'];
629b625487dSandi        $link['style']  = '';
630b625487dSandi        $link['pre']    = '';
631b625487dSandi        $link['suf']    = '';
6325e163278SAndreas Gohr        $link['more']   = '';
633b625487dSandi        $link['class']  = $class;
634b625487dSandi        $link['url']    = $url;
635e1c10e4dSchris
636b625487dSandi        $link['name']   = $name;
637433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
638b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
6390cecf9d5Sandi
640b625487dSandi        //output formatted
641a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6420cecf9d5Sandi    }
6430cecf9d5Sandi
6440cecf9d5Sandi    /**
6450cecf9d5Sandi    */
64697a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
647b625487dSandi        global $conf;
6480cecf9d5Sandi
64997a3e4e3Sandi        $link = array();
65097a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
65197a3e4e3Sandi        $link['pre']    = '';
65297a3e4e3Sandi        $link['suf']    = '';
6535e163278SAndreas Gohr        $link['more']   = '';
654433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
6550cecf9d5Sandi
65697a3e4e3Sandi        //get interwiki URL
6571f82fabeSAndreas Gohr        $url = $this->_resolveInterWiki($wikiName,$wikiUri);
6580cecf9d5Sandi
65997a3e4e3Sandi        if ( !$isImage ) {
6609d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
6619d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
6621c2d1019SAndreas Gohr        } else {
6631c2d1019SAndreas Gohr            $link['class'] = 'media';
66497a3e4e3Sandi        }
6650cecf9d5Sandi
66697a3e4e3Sandi        //do we stay at the same server? Use local target
66797a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
66897a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
66997a3e4e3Sandi        }
6700cecf9d5Sandi
67197a3e4e3Sandi        $link['url'] = $url;
67297a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
67397a3e4e3Sandi
67497a3e4e3Sandi        //output formatted
675a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6760cecf9d5Sandi    }
6770cecf9d5Sandi
6780cecf9d5Sandi    /**
6790cecf9d5Sandi     */
6801d47afe1Sandi    function windowssharelink($url, $name = NULL) {
6811d47afe1Sandi        global $conf;
6821d47afe1Sandi        global $lang;
6831d47afe1Sandi        //simple setup
6841d47afe1Sandi        $link['target'] = $conf['target']['windows'];
6851d47afe1Sandi        $link['pre']    = '';
6861d47afe1Sandi        $link['suf']   = '';
6871d47afe1Sandi        $link['style']  = '';
6880cecf9d5Sandi
689433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6900cecf9d5Sandi        if ( !$isImage ) {
6911d47afe1Sandi            $link['class'] = 'windows';
6920cecf9d5Sandi        } else {
6931d47afe1Sandi            $link['class'] = 'media';
6940cecf9d5Sandi        }
6950cecf9d5Sandi
6960cecf9d5Sandi
697433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
6981d47afe1Sandi        $url = str_replace('\\','/',$url);
6991d47afe1Sandi        $url = 'file:///'.$url;
7001d47afe1Sandi        $link['url'] = $url;
7010cecf9d5Sandi
7021d47afe1Sandi        //output formatted
703a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7040cecf9d5Sandi    }
7050cecf9d5Sandi
70671352defSandi    function emaillink($address, $name = NULL) {
70771352defSandi        global $conf;
70871352defSandi        //simple setup
70971352defSandi        $link = array();
71071352defSandi        $link['target'] = '';
71171352defSandi        $link['pre']    = '';
71271352defSandi        $link['suf']   = '';
71371352defSandi        $link['style']  = '';
71471352defSandi        $link['more']   = '';
7150cecf9d5Sandi
716c078fc55SAndreas Gohr        $name = $this->_getLinkTitle($name, '', $isImage);
7170cecf9d5Sandi        if ( !$isImage ) {
718776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
7190cecf9d5Sandi        } else {
720776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
7210cecf9d5Sandi        }
7220cecf9d5Sandi
72307738714SAndreas Gohr        $address = $this->_xmlEntities($address);
72400a7b5adSEsther Brunner        $address = obfuscate($address);
72500a7b5adSEsther Brunner        $title   = $address;
7268c128049SAndreas Gohr
72771352defSandi        if(empty($name)){
72800a7b5adSEsther Brunner            $name = $address;
72971352defSandi        }
7300cecf9d5Sandi
731776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
732776b36ecSAndreas Gohr
733776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
73471352defSandi        $link['name']  = $name;
73571352defSandi        $link['title'] = $title;
7360cecf9d5Sandi
73771352defSandi        //output formatted
738a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
7390cecf9d5Sandi    }
7400cecf9d5Sandi
7414826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
742dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
74337e34a5eSandi        global $ID;
74491df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
74537e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
7460cecf9d5Sandi
747d98d4540SBen Coburn        $noLink = false;
7488acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
749b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
7503685f775Sandi
75127bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
752b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
753dc673a5bSjoe.lapp            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
7541c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
7552ca14335SEsther Brunner            // don't link flash movies
75644881bd0Shenning.noren            $noLink = true;
75755efc227SAndreas Gohr        }else{
7582ca14335SEsther Brunner            // add file icons
7599d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
7609d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
7616de3759aSAndreas Gohr            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
76255efc227SAndreas Gohr        }
7633685f775Sandi
76491df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
76591df343aSAndreas Gohr
7666fe20453SGina Haeussge        //markup non existing files
7676fe20453SGina Haeussge        if (!$exists)
7686fe20453SGina Haeussge          $link['class'] .= ' wikilink2';
7696fe20453SGina Haeussge
7703685f775Sandi        //output formatted
771dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7722ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7730cecf9d5Sandi    }
7740cecf9d5Sandi
7754826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
776dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
77791df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
778d98d4540SBen Coburn        $noLink = false;
7798acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
780b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
781b739ff0fSPierre Spring
782b739ff0fSPierre Spring        $link['url']    = ml($src,array('cache'=>$cache));
7833685f775Sandi
78427bf7924STom N Harris        list($ext,$mime,$dl) = mimetype($src,false);
785b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
7862ca14335SEsther Brunner            // link only jpeg images
78744881bd0Shenning.noren            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7881c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
7892ca14335SEsther Brunner            // don't link flash movies
79044881bd0Shenning.noren            $noLink = true;
7912ca14335SEsther Brunner        }else{
7922ca14335SEsther Brunner            // add file icons
79327bf7924STom N Harris            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
79427bf7924STom N Harris            $link['class'] .= ' mediafile mf_'.$class;
7952ca14335SEsther Brunner        }
7962ca14335SEsther Brunner
79791df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
79891df343aSAndreas Gohr
7993685f775Sandi        //output formatted
800dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
8012ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
8020cecf9d5Sandi    }
8030cecf9d5Sandi
8044826ab45Sandi    /**
8053db95becSAndreas Gohr     * Renders an RSS feed
806b625487dSandi     *
807b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
808b625487dSandi     */
8093db95becSAndreas Gohr    function rss ($url,$params){
810b625487dSandi        global $lang;
8113db95becSAndreas Gohr        global $conf;
8123db95becSAndreas Gohr
8133db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
8143db95becSAndreas Gohr        $feed = new FeedParser();
81500077af8SAndreas Gohr        $feed->set_feed_url($url);
816b625487dSandi
817b625487dSandi        //disable warning while fetching
818bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
8193db95becSAndreas Gohr        $rc = $feed->init();
820bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
821b625487dSandi
8223db95becSAndreas Gohr        //decide on start and end
8233db95becSAndreas Gohr        if($params['reverse']){
8243db95becSAndreas Gohr            $mod = -1;
8253db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
8263db95becSAndreas Gohr            $end   = $start - ($params['max']);
827b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
8283db95becSAndreas Gohr        }else{
8293db95becSAndreas Gohr            $mod   = 1;
8303db95becSAndreas Gohr            $start = 0;
8313db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
8323db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
8333db95becSAndreas Gohr        }
8343db95becSAndreas Gohr
835a2d649c4Sandi        $this->doc .= '<ul class="rss">';
8363db95becSAndreas Gohr        if($rc){
8373db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
8381bde1582SAndreas Gohr                $item = $feed->get_item($x);
8393db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
840d2ea3363SAndreas Gohr                // support feeds without links
841d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
842d2ea3363SAndreas Gohr                if($lnkurl){
843793361f8SAndreas Gohr                    // title is escaped by SimplePie, we unescape here because it
844793361f8SAndreas Gohr                    // is escaped again in externallink() FS#1705
8451bde1582SAndreas Gohr                    $this->externallink($item->get_permalink(),
846793361f8SAndreas Gohr                                        htmlspecialchars_decode($item->get_title()));
847d2ea3363SAndreas Gohr                }else{
848d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
849d2ea3363SAndreas Gohr                }
8503db95becSAndreas Gohr                if($params['author']){
8511bde1582SAndreas Gohr                    $author = $item->get_author(0);
8521bde1582SAndreas Gohr                    if($author){
8531bde1582SAndreas Gohr                        $name = $author->get_name();
8541bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
8551bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
8561bde1582SAndreas Gohr                    }
8573db95becSAndreas Gohr                }
8583db95becSAndreas Gohr                if($params['date']){
8592e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
8603db95becSAndreas Gohr                }
8611bde1582SAndreas Gohr                if($params['details']){
8623db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
863173dccb7STom N Harris                    if($conf['htmlok']){
8641bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
8653db95becSAndreas Gohr                    }else{
8661bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
8673db95becSAndreas Gohr                    }
8683db95becSAndreas Gohr                    $this->doc .= '</div>';
8693db95becSAndreas Gohr                }
8703db95becSAndreas Gohr
8713db95becSAndreas Gohr                $this->doc .= '</div></li>';
872b625487dSandi            }
873b625487dSandi        }else{
8743db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
875a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
876b625487dSandi            $this->externallink($url);
87745e147ccSAndreas Gohr            if($conf['allowdebug']){
87845e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
87945e147ccSAndreas Gohr            }
8803db95becSAndreas Gohr            $this->doc .= '</div></li>';
881b625487dSandi        }
882a2d649c4Sandi        $this->doc .= '</ul>';
883b625487dSandi    }
884b625487dSandi
8850cecf9d5Sandi    // $numrows not yet implemented
88690df9a4dSAdrian Lang    function table_open($maxcols = NULL, $numrows = NULL, $pos){
88790df9a4dSAdrian Lang        global $lang;
888b5742cedSPierre Spring        // initialize the row counter used for classes
889b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
890*40868f2fSAdrian Lang        $this->doc .= '<table class="inline ' . $this->startSectionEdit($pos, 'table') . '">'.DOKU_LF;
8910cecf9d5Sandi    }
8920cecf9d5Sandi
89390df9a4dSAdrian Lang    function table_close($pos){
89459869a4bSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
89590df9a4dSAdrian Lang        $this->finishSectionEdit($pos);
8960cecf9d5Sandi    }
8970cecf9d5Sandi
8980cecf9d5Sandi    function tablerow_open(){
899b5742cedSPierre Spring        // initialize the cell counter used for classes
900b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
901b5742cedSPierre Spring        $class = 'row' . $this->_counter['row_counter']++;
902b5742cedSPierre Spring        $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
9030cecf9d5Sandi    }
9040cecf9d5Sandi
9050cecf9d5Sandi    function tablerow_close(){
906a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
9070cecf9d5Sandi    }
9080cecf9d5Sandi
90925b97867Shakan.sandell    function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){
910b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9110cecf9d5Sandi        if ( !is_null($align) ) {
912b5742cedSPierre Spring            $class .= ' '.$align.'align';
9130cecf9d5Sandi        }
914b5742cedSPierre Spring        $class .= '"';
915b5742cedSPierre Spring        $this->doc .= '<th ' . $class;
9160cecf9d5Sandi        if ( $colspan > 1 ) {
917a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
918a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
9190cecf9d5Sandi        }
92025b97867Shakan.sandell        if ( $rowspan > 1 ) {
92125b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
92225b97867Shakan.sandell        }
923a2d649c4Sandi        $this->doc .= '>';
9240cecf9d5Sandi    }
9250cecf9d5Sandi
9260cecf9d5Sandi    function tableheader_close(){
927a2d649c4Sandi        $this->doc .= '</th>';
9280cecf9d5Sandi    }
9290cecf9d5Sandi
93025b97867Shakan.sandell    function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){
931b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
9320cecf9d5Sandi        if ( !is_null($align) ) {
933b5742cedSPierre Spring            $class .= ' '.$align.'align';
9340cecf9d5Sandi        }
935b5742cedSPierre Spring        $class .= '"';
936b5742cedSPierre Spring        $this->doc .= '<td '.$class;
9370cecf9d5Sandi        if ( $colspan > 1 ) {
938a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
939a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
9400cecf9d5Sandi        }
94125b97867Shakan.sandell        if ( $rowspan > 1 ) {
94225b97867Shakan.sandell            $this->doc .= ' rowspan="'.$rowspan.'"';
94325b97867Shakan.sandell        }
944a2d649c4Sandi        $this->doc .= '>';
9450cecf9d5Sandi    }
9460cecf9d5Sandi
9470cecf9d5Sandi    function tablecell_close(){
948a2d649c4Sandi        $this->doc .= '</td>';
9490cecf9d5Sandi    }
9500cecf9d5Sandi
9510cecf9d5Sandi    //----------------------------------------------------------
9520cecf9d5Sandi    // Utils
9530cecf9d5Sandi
954ba11bd29Sandi    /**
9553fd0b676Sandi     * Build a link
9563fd0b676Sandi     *
9573fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
958ba11bd29Sandi     *
959ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
960ba11bd29Sandi     */
961433bef32Sandi    function _formatLink($link){
962ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
963ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
964ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
965ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
966ba11bd29Sandi        }
967ba11bd29Sandi        //remove double encodings in titles
968ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
969ba11bd29Sandi
970453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
971453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
972453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
973453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
974453493f2SAndreas Gohr
975ba11bd29Sandi        $ret  = '';
976ba11bd29Sandi        $ret .= $link['pre'];
977ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
978bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
979bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
980bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
981bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
98244a6b4c7SAndreas Gohr        if(!empty($link['rel']))    $ret .= ' rel="'.$link['rel'].'"';
983bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
984ba11bd29Sandi        $ret .= '>';
985ba11bd29Sandi        $ret .= $link['name'];
986ba11bd29Sandi        $ret .= '</a>';
987ba11bd29Sandi        $ret .= $link['suf'];
988ba11bd29Sandi        return $ret;
989ba11bd29Sandi    }
990ba11bd29Sandi
991ba11bd29Sandi    /**
9923fd0b676Sandi     * Renders internal and external media
9933fd0b676Sandi     *
9943fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9953fd0b676Sandi     */
9963fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
997b739ff0fSPierre Spring                      $height=NULL, $cache=NULL, $render = true) {
9983fd0b676Sandi
9993fd0b676Sandi        $ret = '';
10003fd0b676Sandi
1001ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
10023fd0b676Sandi        if(substr($mime,0,5) == 'image'){
1003b739ff0fSPierre Spring            // first get the $title
1004b739ff0fSPierre Spring            if (!is_null($title)) {
1005b739ff0fSPierre Spring                $title  = $this->_xmlEntities($title);
1006b739ff0fSPierre Spring            }elseif($ext == 'jpg' || $ext == 'jpeg'){
1007b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
1008b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
100967f9913dSAndreas Gohr                $jpeg =new JpegMeta(mediaFN($src));
1010b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
1011b739ff0fSPierre Spring                if($cap){
1012b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
1013b739ff0fSPierre Spring                }
1014b739ff0fSPierre Spring            }
1015b739ff0fSPierre Spring            if (!$render) {
1016b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
1017b739ff0fSPierre Spring                // return the title of the picture
1018b739ff0fSPierre Spring                if (!$title) {
1019b739ff0fSPierre Spring                    // just show the sourcename
1020b739ff0fSPierre Spring                    $title = $this->_xmlEntities(basename(noNS($src)));
1021b739ff0fSPierre Spring                }
1022b739ff0fSPierre Spring                return $title;
1023b739ff0fSPierre Spring            }
10243fd0b676Sandi            //add image tag
10256de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
10263fd0b676Sandi            $ret .= ' class="media'.$align.'"';
10273fd0b676Sandi
10284ab889eaSAndreas Gohr            // make left/right alignment for no-CSS view work (feeds)
10294ab889eaSAndreas Gohr            if($align == 'right') $ret .= ' align="right"';
10304ab889eaSAndreas Gohr            if($align == 'left')  $ret .= ' align="left"';
10314ab889eaSAndreas Gohr
1032b739ff0fSPierre Spring            if ($title) {
1033b739ff0fSPierre Spring                $ret .= ' title="' . $title . '"';
1034b739ff0fSPierre Spring                $ret .= ' alt="'   . $title .'"';
10353fd0b676Sandi            }else{
10363fd0b676Sandi                $ret .= ' alt=""';
10373fd0b676Sandi            }
10383fd0b676Sandi
10393fd0b676Sandi            if ( !is_null($width) )
10403fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
10413fd0b676Sandi
10423fd0b676Sandi            if ( !is_null($height) )
10433fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
10443fd0b676Sandi
10453fd0b676Sandi            $ret .= ' />';
10463fd0b676Sandi
10473fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
10481c882ba8SAndreas Gohr            if (!$render) {
10491c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
10501c882ba8SAndreas Gohr                // return the title of the flash
10511c882ba8SAndreas Gohr                if (!$title) {
10521c882ba8SAndreas Gohr                    // just show the sourcename
105307bf32b2SAndreas Gohr                    $title = basename(noNS($src));
10541c882ba8SAndreas Gohr                }
105507bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
10561c882ba8SAndreas Gohr            }
10571c882ba8SAndreas Gohr
105807bf32b2SAndreas Gohr            $att = array();
105907bf32b2SAndreas Gohr            $att['class'] = "media$align";
106007bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
106107bf32b2SAndreas Gohr            if($align == 'left')  $att['align'] = 'left';
1062c471e6a6SAndreas Gohr            $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height,
106307bf32b2SAndreas Gohr                                     array('quality' => 'high'),
106407bf32b2SAndreas Gohr                                     null,
106507bf32b2SAndreas Gohr                                     $att,
106607bf32b2SAndreas Gohr                                     $this->_xmlEntities($title));
10670f428d7dSAndreas Gohr        }elseif($title){
10683fd0b676Sandi            // well at least we have a title to display
10693fd0b676Sandi            $ret .= $this->_xmlEntities($title);
10703fd0b676Sandi        }else{
10715291ca3aSAndreas Gohr            // just show the sourcename
10720f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
10733fd0b676Sandi        }
10743fd0b676Sandi
10753fd0b676Sandi        return $ret;
10763fd0b676Sandi    }
10773fd0b676Sandi
1078433bef32Sandi    function _xmlEntities($string) {
1079de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
10800cecf9d5Sandi    }
10810cecf9d5Sandi
10828a831f2bSAndreas Gohr    /**
10838a831f2bSAndreas Gohr     * Creates a linkid from a headline
1084c5a8fd96SAndreas Gohr     *
1085c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1086c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
1087c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
10888a831f2bSAndreas Gohr     */
1089c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
1090c5a8fd96SAndreas Gohr        if($create){
10914ceab83fSAndreas Gohr            return sectionID($title,$this->headers);
10924ceab83fSAndreas Gohr        }else{
1093443d207bSAndreas Gohr            $check = false;
1094443d207bSAndreas Gohr            return sectionID($title,$check);
1095c5a8fd96SAndreas Gohr        }
10960cecf9d5Sandi    }
10970cecf9d5Sandi
1098af587fa8Sandi    /**
10993fd0b676Sandi     * Construct a title and handle images in titles
11003fd0b676Sandi     *
11010b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
11023fd0b676Sandi     */
1103fe9ec250SChris Smith    function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') {
1104bb0a59d4Sjan        global $conf;
1105bb0a59d4Sjan
110644881bd0Shenning.noren        $isImage = false;
110729657f9eSAndreas Gohr        if ( is_array($title) ) {
110829657f9eSAndreas Gohr            $isImage = true;
110929657f9eSAndreas Gohr            return $this->_imageTitle($title);
111029657f9eSAndreas Gohr        } elseif ( is_null($title) || trim($title)=='') {
1111fe9ec250SChris Smith            if (useHeading($linktype) && $id) {
1112fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1113bb0a59d4Sjan                if ($heading) {
1114433bef32Sandi                    return $this->_xmlEntities($heading);
1115bb0a59d4Sjan                }
1116bb0a59d4Sjan            }
1117433bef32Sandi            return $this->_xmlEntities($default);
111868c26e6dSMichael Klier        } else {
111968c26e6dSMichael Klier            return $this->_xmlEntities($title);
11200cecf9d5Sandi        }
11210cecf9d5Sandi    }
11220cecf9d5Sandi
11230cecf9d5Sandi    /**
11243fd0b676Sandi     * Returns an HTML code for images used in link titles
11253fd0b676Sandi     *
11263fd0b676Sandi     * @todo Resolve namespace on internal images
11273fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
11280cecf9d5Sandi     */
1129433bef32Sandi    function _imageTitle($img) {
1130d9baf1a7SKazutaka Miyasaka        global $ID;
1131d9baf1a7SKazutaka Miyasaka
1132d9baf1a7SKazutaka Miyasaka        // some fixes on $img['src']
1133d9baf1a7SKazutaka Miyasaka        // see internalmedia() and externalmedia()
1134d9baf1a7SKazutaka Miyasaka        list($img['src'],$hash) = explode('#',$img['src'],2);
1135d9baf1a7SKazutaka Miyasaka        if ($img['type'] == 'internalmedia') {
1136d9baf1a7SKazutaka Miyasaka            resolve_mediaid(getNS($ID),$img['src'],$exists);
1137d9baf1a7SKazutaka Miyasaka        }
1138d9baf1a7SKazutaka Miyasaka
1139433bef32Sandi        return $this->_media($img['src'],
11404826ab45Sandi                              $img['title'],
11414826ab45Sandi                              $img['align'],
11424826ab45Sandi                              $img['width'],
11434826ab45Sandi                              $img['height'],
11444826ab45Sandi                              $img['cache']);
11450cecf9d5Sandi    }
1146b739ff0fSPierre Spring
1147b739ff0fSPierre Spring    /**
1148b739ff0fSPierre Spring     * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia()
1149b739ff0fSPierre Spring     * which returns a basic link to a media.
1150b739ff0fSPierre Spring     *
1151b739ff0fSPierre Spring     * @author Pierre Spring <pierre.spring@liip.ch>
1152b739ff0fSPierre Spring     * @param string $src
1153b739ff0fSPierre Spring     * @param string $title
1154b739ff0fSPierre Spring     * @param string $align
1155b739ff0fSPierre Spring     * @param string $width
1156b739ff0fSPierre Spring     * @param string $height
1157b739ff0fSPierre Spring     * @param string $cache
1158b739ff0fSPierre Spring     * @param string $render
1159b739ff0fSPierre Spring     * @access protected
1160b739ff0fSPierre Spring     * @return array
1161b739ff0fSPierre Spring     */
1162b739ff0fSPierre Spring    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render)
1163b739ff0fSPierre Spring    {
1164b739ff0fSPierre Spring        global $conf;
1165b739ff0fSPierre Spring
1166b739ff0fSPierre Spring        $link = array();
1167b739ff0fSPierre Spring        $link['class']  = 'media';
1168b739ff0fSPierre Spring        $link['style']  = '';
1169b739ff0fSPierre Spring        $link['pre']    = '';
1170b739ff0fSPierre Spring        $link['suf']    = '';
1171b739ff0fSPierre Spring        $link['more']   = '';
1172b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1173b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1174b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1175b739ff0fSPierre Spring
1176b739ff0fSPierre Spring        return $link;
1177b739ff0fSPierre Spring    }
117891459163SAnika Henke
117991459163SAnika Henke
11800cecf9d5Sandi}
11810cecf9d5Sandi
11824826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1183