xref: /dokuwiki/inc/parser/xhtml.php (revision bdd8111b81ffd9c4f9b8cdbb8075c7088bbcf230)
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
320cecf9d5Sandi
330cecf9d5Sandi    var $headers = array();
340cecf9d5Sandi    var $footnotes = array();
35af587fa8Sandi    var $lastsec = 0;
367764a90aSandi    var $store = '';
377764a90aSandi
38b5742cedSPierre Spring    var $_counter = array(); // used as global counter, introduced for table classes
39b5742cedSPierre Spring
405f70445dSAndreas Gohr    function getFormat(){
415f70445dSAndreas Gohr        return 'xhtml';
425f70445dSAndreas Gohr    }
435f70445dSAndreas Gohr
445f70445dSAndreas Gohr
450cecf9d5Sandi    function document_start() {
46c5a8fd96SAndreas Gohr        //reset some internals
47c5a8fd96SAndreas Gohr        $this->toc     = array();
48c5a8fd96SAndreas Gohr        $this->headers = array();
490cecf9d5Sandi    }
500cecf9d5Sandi
510cecf9d5Sandi    function document_end() {
520cecf9d5Sandi        if ( count ($this->footnotes) > 0 ) {
53a2d649c4Sandi            $this->doc .= '<div class="footnotes">'.DOKU_LF;
54d74aace9Schris
55d74aace9Schris            $id = 0;
560cecf9d5Sandi            foreach ( $this->footnotes as $footnote ) {
57d74aace9Schris                $id++;   // the number of the current footnote
58d74aace9Schris
59d74aace9Schris                // check its not a placeholder that indicates actual footnote text is elsewhere
60d74aace9Schris                if (substr($footnote, 0, 5) != "@@FNT") {
61d74aace9Schris
62d74aace9Schris                    // open the footnote and set the anchor and backlink
63d74aace9Schris                    $this->doc .= '<div class="fn">';
6429bfcd16SAndreas Gohr                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
6529bfcd16SAndreas Gohr                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
66d74aace9Schris
67d74aace9Schris                    // get any other footnotes that use the same markup
68d74aace9Schris                    $alt = array_keys($this->footnotes, "@@FNT$id");
69d74aace9Schris
70d74aace9Schris                    if (count($alt)) {
71d74aace9Schris                      foreach ($alt as $ref) {
72d74aace9Schris                        // set anchor and backlink for the other footnotes
7329bfcd16SAndreas Gohr                        $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
7429bfcd16SAndreas Gohr                        $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF;
75d74aace9Schris                      }
76d74aace9Schris                    }
77d74aace9Schris
78d74aace9Schris                    // add footnote markup and close this footnote
79a2d649c4Sandi                    $this->doc .= $footnote;
80d74aace9Schris                    $this->doc .= '</div>' . DOKU_LF;
81d74aace9Schris                }
820cecf9d5Sandi            }
83a2d649c4Sandi            $this->doc .= '</div>'.DOKU_LF;
840cecf9d5Sandi        }
85c5a8fd96SAndreas Gohr
86b8595a66SAndreas Gohr        // Prepare the TOC
87851f2e89SAnika Henke        global $conf;
88851f2e89SAnika Henke        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){
89b8595a66SAndreas Gohr            global $TOC;
90b8595a66SAndreas Gohr            $TOC = $this->toc;
910cecf9d5Sandi        }
923e55d035SAndreas Gohr
933e55d035SAndreas Gohr        // make sure there are no empty paragraphs
9427918226Schris        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
95e41c4da9SAndreas Gohr    }
960cecf9d5Sandi
97e7856beaSchris    function toc_additem($id, $text, $level) {
98af587fa8Sandi        global $conf;
99af587fa8Sandi
100c5a8fd96SAndreas Gohr        //handle TOC
101c5a8fd96SAndreas Gohr        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
1027d91652aSAndreas Gohr            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);
103c5a8fd96SAndreas Gohr        }
104e7856beaSchris    }
105e7856beaSchris
106e7856beaSchris    function header($text, $level, $pos) {
107*bdd8111bSAndreas Gohr        if(!$text) return; //skip empty headlines
108e7856beaSchris
109e7856beaSchris        $hid = $this->_headerToLink($text,true);
110e7856beaSchris
111e7856beaSchris        //only add items within configured levels
112e7856beaSchris        $this->toc_additem($hid, $text, $level);
113c5a8fd96SAndreas Gohr
114c5a8fd96SAndreas Gohr        // write the header
115c5a8fd96SAndreas Gohr        $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
116a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
117c6a1c1bfSAnika Henke        $this->doc .= "</a></h$level>".DOKU_LF;
1180cecf9d5Sandi    }
1190cecf9d5Sandi
12035dae8b0SBen Coburn     /**
12135dae8b0SBen Coburn     * Section edit marker is replaced by an edit button when
12235dae8b0SBen Coburn     * the page is editable. Replacement done in 'inc/html.php#html_secedit'
12335dae8b0SBen Coburn     *
12435dae8b0SBen Coburn     * @author Andreas Gohr <andi@splitbrain.org>
12535dae8b0SBen Coburn     * @author Ben Coburn   <btcoburn@silicodon.net>
12635dae8b0SBen Coburn     */
12735dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {
12835dae8b0SBen Coburn        global $conf;
12935dae8b0SBen Coburn
13035dae8b0SBen Coburn        if ($start!=-1 && $level<=$conf['maxseclevel']) {
13135dae8b0SBen Coburn            $name = str_replace('"', '', $name);
13235dae8b0SBen Coburn            $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
13335dae8b0SBen Coburn        }
13435dae8b0SBen Coburn    }
13535dae8b0SBen Coburn
1360cecf9d5Sandi    function section_open($level) {
137a2d649c4Sandi        $this->doc .= "<div class=\"level$level\">".DOKU_LF;
1380cecf9d5Sandi    }
1390cecf9d5Sandi
1400cecf9d5Sandi    function section_close() {
141a2d649c4Sandi        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
1420cecf9d5Sandi    }
1430cecf9d5Sandi
1440cecf9d5Sandi    function cdata($text) {
145a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
1460cecf9d5Sandi    }
1470cecf9d5Sandi
1480cecf9d5Sandi    function p_open() {
149a2d649c4Sandi        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
1500cecf9d5Sandi    }
1510cecf9d5Sandi
1520cecf9d5Sandi    function p_close() {
153a2d649c4Sandi        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
1540cecf9d5Sandi    }
1550cecf9d5Sandi
1560cecf9d5Sandi    function linebreak() {
157a2d649c4Sandi        $this->doc .= '<br/>'.DOKU_LF;
1580cecf9d5Sandi    }
1590cecf9d5Sandi
1600cecf9d5Sandi    function hr() {
1614beabca9SAnika Henke        $this->doc .= '<hr />'.DOKU_LF;
1620cecf9d5Sandi    }
1630cecf9d5Sandi
1640cecf9d5Sandi    function strong_open() {
165a2d649c4Sandi        $this->doc .= '<strong>';
1660cecf9d5Sandi    }
1670cecf9d5Sandi
1680cecf9d5Sandi    function strong_close() {
169a2d649c4Sandi        $this->doc .= '</strong>';
1700cecf9d5Sandi    }
1710cecf9d5Sandi
1720cecf9d5Sandi    function emphasis_open() {
173a2d649c4Sandi        $this->doc .= '<em>';
1740cecf9d5Sandi    }
1750cecf9d5Sandi
1760cecf9d5Sandi    function emphasis_close() {
177a2d649c4Sandi        $this->doc .= '</em>';
1780cecf9d5Sandi    }
1790cecf9d5Sandi
1800cecf9d5Sandi    function underline_open() {
18102e51121SAnika Henke        $this->doc .= '<em class="u">';
1820cecf9d5Sandi    }
1830cecf9d5Sandi
1840cecf9d5Sandi    function underline_close() {
18502e51121SAnika Henke        $this->doc .= '</em>';
1860cecf9d5Sandi    }
1870cecf9d5Sandi
1880cecf9d5Sandi    function monospace_open() {
189a2d649c4Sandi        $this->doc .= '<code>';
1900cecf9d5Sandi    }
1910cecf9d5Sandi
1920cecf9d5Sandi    function monospace_close() {
193a2d649c4Sandi        $this->doc .= '</code>';
1940cecf9d5Sandi    }
1950cecf9d5Sandi
1960cecf9d5Sandi    function subscript_open() {
197a2d649c4Sandi        $this->doc .= '<sub>';
1980cecf9d5Sandi    }
1990cecf9d5Sandi
2000cecf9d5Sandi    function subscript_close() {
201a2d649c4Sandi        $this->doc .= '</sub>';
2020cecf9d5Sandi    }
2030cecf9d5Sandi
2040cecf9d5Sandi    function superscript_open() {
205a2d649c4Sandi        $this->doc .= '<sup>';
2060cecf9d5Sandi    }
2070cecf9d5Sandi
2080cecf9d5Sandi    function superscript_close() {
209a2d649c4Sandi        $this->doc .= '</sup>';
2100cecf9d5Sandi    }
2110cecf9d5Sandi
2120cecf9d5Sandi    function deleted_open() {
213a2d649c4Sandi        $this->doc .= '<del>';
2140cecf9d5Sandi    }
2150cecf9d5Sandi
2160cecf9d5Sandi    function deleted_close() {
217a2d649c4Sandi        $this->doc .= '</del>';
2180cecf9d5Sandi    }
2190cecf9d5Sandi
2203fd0b676Sandi    /**
2213fd0b676Sandi     * Callback for footnote start syntax
2223fd0b676Sandi     *
2233fd0b676Sandi     * All following content will go to the footnote instead of
224d74aace9Schris     * the document. To achieve this the previous rendered content
2253fd0b676Sandi     * is moved to $store and $doc is cleared
2263fd0b676Sandi     *
2273fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
2283fd0b676Sandi     */
2290cecf9d5Sandi    function footnote_open() {
2307764a90aSandi
2317764a90aSandi        // move current content to store and record footnote
2327764a90aSandi        $this->store = $this->doc;
2337764a90aSandi        $this->doc   = '';
2340cecf9d5Sandi    }
2350cecf9d5Sandi
2363fd0b676Sandi    /**
2373fd0b676Sandi     * Callback for footnote end syntax
2383fd0b676Sandi     *
2393fd0b676Sandi     * All rendered content is moved to the $footnotes array and the old
2403fd0b676Sandi     * content is restored from $store again
2413fd0b676Sandi     *
2423fd0b676Sandi     * @author Andreas Gohr
2433fd0b676Sandi     */
2440cecf9d5Sandi    function footnote_close() {
2457764a90aSandi
246d74aace9Schris        // recover footnote into the stack and restore old content
247d74aace9Schris        $footnote = $this->doc;
2487764a90aSandi        $this->doc = $this->store;
2497764a90aSandi        $this->store = '';
250d74aace9Schris
251d74aace9Schris        // check to see if this footnote has been seen before
252d74aace9Schris        $i = array_search($footnote, $this->footnotes);
253d74aace9Schris
254d74aace9Schris        if ($i === false) {
255d74aace9Schris            // its a new footnote, add it to the $footnotes array
256d74aace9Schris            $id = count($this->footnotes)+1;
257d74aace9Schris            $this->footnotes[count($this->footnotes)] = $footnote;
258d74aace9Schris        } else {
259d74aace9Schris            // seen this one before, translate the index to an id and save a placeholder
260d74aace9Schris            $i++;
261d74aace9Schris            $id = count($this->footnotes)+1;
262d74aace9Schris            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
263d74aace9Schris        }
264d74aace9Schris
2656b379cbfSAndreas Gohr        // output the footnote reference and link
26629bfcd16SAndreas Gohr        $this->doc .= '<sup><a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>';
2670cecf9d5Sandi    }
2680cecf9d5Sandi
2690cecf9d5Sandi    function listu_open() {
270a2d649c4Sandi        $this->doc .= '<ul>'.DOKU_LF;
2710cecf9d5Sandi    }
2720cecf9d5Sandi
2730cecf9d5Sandi    function listu_close() {
274a2d649c4Sandi        $this->doc .= '</ul>'.DOKU_LF;
2750cecf9d5Sandi    }
2760cecf9d5Sandi
2770cecf9d5Sandi    function listo_open() {
278a2d649c4Sandi        $this->doc .= '<ol>'.DOKU_LF;
2790cecf9d5Sandi    }
2800cecf9d5Sandi
2810cecf9d5Sandi    function listo_close() {
282a2d649c4Sandi        $this->doc .= '</ol>'.DOKU_LF;
2830cecf9d5Sandi    }
2840cecf9d5Sandi
2850cecf9d5Sandi    function listitem_open($level) {
286a2d649c4Sandi        $this->doc .= '<li class="level'.$level.'">';
2870cecf9d5Sandi    }
2880cecf9d5Sandi
2890cecf9d5Sandi    function listitem_close() {
290a2d649c4Sandi        $this->doc .= '</li>'.DOKU_LF;
2910cecf9d5Sandi    }
2920cecf9d5Sandi
2930cecf9d5Sandi    function listcontent_open() {
29490db23d7Schris        $this->doc .= '<div class="li">';
2950cecf9d5Sandi    }
2960cecf9d5Sandi
2970cecf9d5Sandi    function listcontent_close() {
29890db23d7Schris        $this->doc .= '</div>'.DOKU_LF;
2990cecf9d5Sandi    }
3000cecf9d5Sandi
3010cecf9d5Sandi    function unformatted($text) {
302a2d649c4Sandi        $this->doc .= $this->_xmlEntities($text);
3030cecf9d5Sandi    }
3040cecf9d5Sandi
3050cecf9d5Sandi    /**
3063fd0b676Sandi     * Execute PHP code if allowed
3073fd0b676Sandi     *
3085d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['phpok'] is okff
3095d568b99SChris Smith     *
3103fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3110cecf9d5Sandi     */
3125d568b99SChris Smith    function php($text, $wrapper='code') {
31335a56260SChris Smith        global $conf;
31435a56260SChris Smith
315d86d5af0SChris Smith        if($conf['phpok']){
316bad0b545Sandi          ob_start();
3174de671bcSandi          eval($text);
3183fd0b676Sandi          $this->doc .= ob_get_contents();
319bad0b545Sandi          ob_end_clean();
320d86d5af0SChris Smith        } else {
3215d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
322d86d5af0SChris Smith        }
3230cecf9d5Sandi    }
3240cecf9d5Sandi
32507f89c3cSAnika Henke    function phpblock($text) {
3265d568b99SChris Smith        $this->php($text, 'pre');
32707f89c3cSAnika Henke    }
32807f89c3cSAnika Henke
3290cecf9d5Sandi    /**
3303fd0b676Sandi     * Insert HTML if allowed
3313fd0b676Sandi     *
3325d568b99SChris Smith     * @param  string   $wrapper   html element to wrap result if $conf['htmlok'] is okff
3335d568b99SChris Smith     *
3343fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3350cecf9d5Sandi     */
3365d568b99SChris Smith    function html($text, $wrapper='code') {
33735a56260SChris Smith        global $conf;
33835a56260SChris Smith
339d86d5af0SChris Smith        if($conf['htmlok']){
340a2d649c4Sandi          $this->doc .= $text;
341d86d5af0SChris Smith        } else {
3425d568b99SChris Smith          $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
343d86d5af0SChris Smith        }
3444de671bcSandi    }
3450cecf9d5Sandi
34607f89c3cSAnika Henke    function htmlblock($text) {
3475d568b99SChris Smith        $this->html($text, 'pre');
34807f89c3cSAnika Henke    }
34907f89c3cSAnika Henke
3500cecf9d5Sandi    function preformatted($text) {
351a2d649c4Sandi        $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
3520cecf9d5Sandi    }
3530cecf9d5Sandi
3540cecf9d5Sandi    function file($text) {
355a2d649c4Sandi        $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
3560cecf9d5Sandi    }
3570cecf9d5Sandi
3580cecf9d5Sandi    function quote_open() {
35996331712SAnika Henke        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
3600cecf9d5Sandi    }
3610cecf9d5Sandi
3620cecf9d5Sandi    function quote_close() {
36396331712SAnika Henke        $this->doc .= '</div></blockquote>'.DOKU_LF;
3640cecf9d5Sandi    }
3650cecf9d5Sandi
3660cecf9d5Sandi    /**
3673fd0b676Sandi     * Callback for code text
3683fd0b676Sandi     *
3693fd0b676Sandi     * Uses GeSHi to highlight language syntax
3703fd0b676Sandi     *
3713fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
3720cecf9d5Sandi     */
3730cecf9d5Sandi    function code($text, $language = NULL) {
3744de671bcSandi        global $conf;
3750cecf9d5Sandi
3760cecf9d5Sandi        if ( is_null($language) ) {
3770cecf9d5Sandi            $this->preformatted($text);
3780cecf9d5Sandi        } else {
3798f7d700cSchris            $this->doc .= p_xhtml_cached_geshi($text, $language);
3800cecf9d5Sandi        }
3810cecf9d5Sandi    }
3820cecf9d5Sandi
3830cecf9d5Sandi    function acronym($acronym) {
3840cecf9d5Sandi
3850cecf9d5Sandi        if ( array_key_exists($acronym, $this->acronyms) ) {
3860cecf9d5Sandi
387433bef32Sandi            $title = $this->_xmlEntities($this->acronyms[$acronym]);
3880cecf9d5Sandi
389a2d649c4Sandi            $this->doc .= '<acronym title="'.$title
390433bef32Sandi                .'">'.$this->_xmlEntities($acronym).'</acronym>';
3910cecf9d5Sandi
3920cecf9d5Sandi        } else {
393a2d649c4Sandi            $this->doc .= $this->_xmlEntities($acronym);
3940cecf9d5Sandi        }
3950cecf9d5Sandi    }
3960cecf9d5Sandi
3970cecf9d5Sandi    function smiley($smiley) {
3980cecf9d5Sandi        if ( array_key_exists($smiley, $this->smileys) ) {
399433bef32Sandi            $title = $this->_xmlEntities($this->smileys[$smiley]);
400f62ea8a1Sandi            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
4014beabca9SAnika Henke                '" class="middle" alt="'.
402433bef32Sandi                    $this->_xmlEntities($smiley).'" />';
4030cecf9d5Sandi        } else {
404a2d649c4Sandi            $this->doc .= $this->_xmlEntities($smiley);
4050cecf9d5Sandi        }
4060cecf9d5Sandi    }
4070cecf9d5Sandi
408f62ea8a1Sandi    /*
4094de671bcSandi    * not used
4100cecf9d5Sandi    function wordblock($word) {
4110cecf9d5Sandi        if ( array_key_exists($word, $this->badwords) ) {
412a2d649c4Sandi            $this->doc .= '** BLEEP **';
4130cecf9d5Sandi        } else {
414a2d649c4Sandi            $this->doc .= $this->_xmlEntities($word);
4150cecf9d5Sandi        }
4160cecf9d5Sandi    }
4174de671bcSandi    */
4180cecf9d5Sandi
4190cecf9d5Sandi    function entity($entity) {
4200cecf9d5Sandi        if ( array_key_exists($entity, $this->entities) ) {
421a2d649c4Sandi            $this->doc .= $this->entities[$entity];
4220cecf9d5Sandi        } else {
423a2d649c4Sandi            $this->doc .= $this->_xmlEntities($entity);
4240cecf9d5Sandi        }
4250cecf9d5Sandi    }
4260cecf9d5Sandi
4270cecf9d5Sandi    function multiplyentity($x, $y) {
428a2d649c4Sandi        $this->doc .= "$x&times;$y";
4290cecf9d5Sandi    }
4300cecf9d5Sandi
4310cecf9d5Sandi    function singlequoteopening() {
43271b40da2SAnika Henke        global $lang;
43371b40da2SAnika Henke        $this->doc .= $lang['singlequoteopening'];
4340cecf9d5Sandi    }
4350cecf9d5Sandi
4360cecf9d5Sandi    function singlequoteclosing() {
43771b40da2SAnika Henke        global $lang;
43871b40da2SAnika Henke        $this->doc .= $lang['singlequoteclosing'];
4390cecf9d5Sandi    }
4400cecf9d5Sandi
44157d757d1SAndreas Gohr    function apostrophe() {
44257d757d1SAndreas Gohr        global $lang;
443a8bd192aSAndreas Gohr        $this->doc .= $lang['apostrophe'];
44457d757d1SAndreas Gohr    }
44557d757d1SAndreas Gohr
4460cecf9d5Sandi    function doublequoteopening() {
44771b40da2SAnika Henke        global $lang;
44871b40da2SAnika Henke        $this->doc .= $lang['doublequoteopening'];
4490cecf9d5Sandi    }
4500cecf9d5Sandi
4510cecf9d5Sandi    function doublequoteclosing() {
45271b40da2SAnika Henke        global $lang;
45371b40da2SAnika Henke        $this->doc .= $lang['doublequoteclosing'];
4540cecf9d5Sandi    }
4550cecf9d5Sandi
4560cecf9d5Sandi    /**
4570cecf9d5Sandi    */
4580cecf9d5Sandi    function camelcaselink($link) {
45911d0aa47Sandi      $this->internallink($link,$link);
4600cecf9d5Sandi    }
4610cecf9d5Sandi
4620b7c14c2Sandi
4630b7c14c2Sandi    function locallink($hash, $name = NULL){
4640b7c14c2Sandi        global $ID;
4650b7c14c2Sandi        $name  = $this->_getLinkTitle($name, $hash, $isImage);
4660b7c14c2Sandi        $hash  = $this->_headerToLink($hash);
4670b7c14c2Sandi        $title = $ID.' &crarr;';
4680b7c14c2Sandi        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
4690b7c14c2Sandi        $this->doc .= $name;
4700b7c14c2Sandi        $this->doc .= '</a>';
4710b7c14c2Sandi    }
4720b7c14c2Sandi
473cffcc403Sandi    /**
4743fd0b676Sandi     * Render an internal Wiki Link
4753fd0b676Sandi     *
476fe9ec250SChris Smith     * $search,$returnonly & $linktype are not for the renderer but are used
477cffcc403Sandi     * elsewhere - no need to implement them in other renderers
4783fd0b676Sandi     *
4793fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
480cffcc403Sandi     */
481fe9ec250SChris Smith    function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') {
482ba11bd29Sandi        global $conf;
48337e34a5eSandi        global $ID;
4840339c872Sjan        // default name is based on $id as given
4850339c872Sjan        $default = $this->_simpleTitle($id);
486ad32e47eSAndreas Gohr
4870339c872Sjan        // now first resolve and clean up the $id
48837e34a5eSandi        resolve_pageid(getNS($ID),$id,$exists);
489fe9ec250SChris Smith        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
4900e1c636eSandi        if ( !$isImage ) {
4910e1c636eSandi            if ( $exists ) {
492ba11bd29Sandi                $class='wikilink1';
4930cecf9d5Sandi            } else {
494ba11bd29Sandi                $class='wikilink2';
49544a6b4c7SAndreas Gohr                $link['rel']='nofollow';
4960cecf9d5Sandi            }
4970cecf9d5Sandi        } else {
498ba11bd29Sandi            $class='media';
4990cecf9d5Sandi        }
5000cecf9d5Sandi
501a1685bedSandi        //keep hash anchor
502ce6b63d9Schris        list($id,$hash) = explode('#',$id,2);
503943dedc6SAndreas Gohr        if(!empty($hash)) $hash = $this->_headerToLink($hash);
504a1685bedSandi
505ba11bd29Sandi        //prepare for formating
506ba11bd29Sandi        $link['target'] = $conf['target']['wiki'];
507ba11bd29Sandi        $link['style']  = '';
508ba11bd29Sandi        $link['pre']    = '';
509ba11bd29Sandi        $link['suf']    = '';
51040eb54bbSjan        // highlight link to current page
51140eb54bbSjan        if ($id == $ID) {
51292795d04Sandi            $link['pre']    = '<span class="curid">';
51392795d04Sandi            $link['suf']    = '</span>';
51440eb54bbSjan        }
5155e163278SAndreas Gohr        $link['more']   = '';
516ba11bd29Sandi        $link['class']  = $class;
517ba11bd29Sandi        $link['url']    = wl($id);
518ba11bd29Sandi        $link['name']   = $name;
519ba11bd29Sandi        $link['title']  = $id;
520723d78dbSandi        //add search string
521723d78dbSandi        if($search){
522546d3a99SAndreas Gohr            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
523546d3a99SAndreas Gohr            if(is_array($search)){
524546d3a99SAndreas Gohr                $search = array_map('rawurlencode',$search);
525546d3a99SAndreas Gohr                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
526546d3a99SAndreas Gohr            }else{
527546d3a99SAndreas Gohr                $link['url'] .= 's='.rawurlencode($search);
528546d3a99SAndreas Gohr            }
529723d78dbSandi        }
530723d78dbSandi
531a1685bedSandi        //keep hash
532a1685bedSandi        if($hash) $link['url'].='#'.$hash;
533a1685bedSandi
534ba11bd29Sandi        //output formatted
535cffcc403Sandi        if($returnonly){
536cffcc403Sandi            return $this->_formatLink($link);
537cffcc403Sandi        }else{
538a2d649c4Sandi            $this->doc .= $this->_formatLink($link);
5390cecf9d5Sandi        }
540cffcc403Sandi    }
5410cecf9d5Sandi
542b625487dSandi    function externallink($url, $name = NULL) {
543b625487dSandi        global $conf;
5440cecf9d5Sandi
545433bef32Sandi        $name = $this->_getLinkTitle($name, $url, $isImage);
5466f0c5dbfSandi
5470cecf9d5Sandi        if ( !$isImage ) {
548b625487dSandi            $class='urlextern';
5490cecf9d5Sandi        } else {
550b625487dSandi            $class='media';
5510cecf9d5Sandi        }
5520cecf9d5Sandi
553b625487dSandi        //prepare for formating
554b625487dSandi        $link['target'] = $conf['target']['extern'];
555b625487dSandi        $link['style']  = '';
556b625487dSandi        $link['pre']    = '';
557b625487dSandi        $link['suf']    = '';
5585e163278SAndreas Gohr        $link['more']   = '';
559b625487dSandi        $link['class']  = $class;
560b625487dSandi        $link['url']    = $url;
561e1c10e4dSchris
562b625487dSandi        $link['name']   = $name;
563433bef32Sandi        $link['title']  = $this->_xmlEntities($url);
564b625487dSandi        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
5650cecf9d5Sandi
566b625487dSandi        //output formatted
567a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
5680cecf9d5Sandi    }
5690cecf9d5Sandi
5700cecf9d5Sandi    /**
5710cecf9d5Sandi    */
57297a3e4e3Sandi    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
573b625487dSandi        global $conf;
5740cecf9d5Sandi
57597a3e4e3Sandi        $link = array();
57697a3e4e3Sandi        $link['target'] = $conf['target']['interwiki'];
57797a3e4e3Sandi        $link['pre']    = '';
57897a3e4e3Sandi        $link['suf']    = '';
5795e163278SAndreas Gohr        $link['more']   = '';
580433bef32Sandi        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
5810cecf9d5Sandi
58297a3e4e3Sandi        //get interwiki URL
5831f82fabeSAndreas Gohr        $url = $this->_resolveInterWiki($wikiName,$wikiUri);
5840cecf9d5Sandi
58597a3e4e3Sandi        if ( !$isImage ) {
5869d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
5879d2ddea4SAndreas Gohr            $link['class'] = "interwiki iw_$class";
5881c2d1019SAndreas Gohr        } else {
5891c2d1019SAndreas Gohr            $link['class'] = 'media';
59097a3e4e3Sandi        }
5910cecf9d5Sandi
59297a3e4e3Sandi        //do we stay at the same server? Use local target
59397a3e4e3Sandi        if( strpos($url,DOKU_URL) === 0 ){
59497a3e4e3Sandi            $link['target'] = $conf['target']['wiki'];
59597a3e4e3Sandi        }
5960cecf9d5Sandi
59797a3e4e3Sandi        $link['url'] = $url;
59897a3e4e3Sandi        $link['title'] = htmlspecialchars($link['url']);
59997a3e4e3Sandi
60097a3e4e3Sandi        //output formatted
601a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6020cecf9d5Sandi    }
6030cecf9d5Sandi
6040cecf9d5Sandi    /**
6050cecf9d5Sandi     */
6061d47afe1Sandi    function windowssharelink($url, $name = NULL) {
6071d47afe1Sandi        global $conf;
6081d47afe1Sandi        global $lang;
6091d47afe1Sandi        //simple setup
6101d47afe1Sandi        $link['target'] = $conf['target']['windows'];
6111d47afe1Sandi        $link['pre']    = '';
6121d47afe1Sandi        $link['suf']   = '';
6131d47afe1Sandi        $link['style']  = '';
6140cecf9d5Sandi
615433bef32Sandi        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
6160cecf9d5Sandi        if ( !$isImage ) {
6171d47afe1Sandi            $link['class'] = 'windows';
6180cecf9d5Sandi        } else {
6191d47afe1Sandi            $link['class'] = 'media';
6200cecf9d5Sandi        }
6210cecf9d5Sandi
6220cecf9d5Sandi
623433bef32Sandi        $link['title'] = $this->_xmlEntities($url);
6241d47afe1Sandi        $url = str_replace('\\','/',$url);
6251d47afe1Sandi        $url = 'file:///'.$url;
6261d47afe1Sandi        $link['url'] = $url;
6270cecf9d5Sandi
6281d47afe1Sandi        //output formatted
629a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6300cecf9d5Sandi    }
6310cecf9d5Sandi
63271352defSandi    function emaillink($address, $name = NULL) {
63371352defSandi        global $conf;
63471352defSandi        //simple setup
63571352defSandi        $link = array();
63671352defSandi        $link['target'] = '';
63771352defSandi        $link['pre']    = '';
63871352defSandi        $link['suf']   = '';
63971352defSandi        $link['style']  = '';
64071352defSandi        $link['more']   = '';
6410cecf9d5Sandi
642704fb054SAnika Henke        $name = $this->_getLinkTitle($name, $address, $isImage);
6430cecf9d5Sandi        if ( !$isImage ) {
644776b36ecSAndreas Gohr            $link['class']='mail JSnocheck';
6450cecf9d5Sandi        } else {
646776b36ecSAndreas Gohr            $link['class']='media JSnocheck';
6470cecf9d5Sandi        }
6480cecf9d5Sandi
64907738714SAndreas Gohr        $address = $this->_xmlEntities($address);
65000a7b5adSEsther Brunner        $address = obfuscate($address);
65100a7b5adSEsther Brunner        $title   = $address;
6528c128049SAndreas Gohr
65371352defSandi        if(empty($name)){
65400a7b5adSEsther Brunner            $name = $address;
65571352defSandi        }
6568c128049SAndreas Gohr#elseif($isImage{
6578c128049SAndreas Gohr#            $name = $this->_xmlEntities($name);
6588c128049SAndreas Gohr#        }
6590cecf9d5Sandi
660776b36ecSAndreas Gohr        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
661776b36ecSAndreas Gohr
662776b36ecSAndreas Gohr        $link['url']   = 'mailto:'.$address;
66371352defSandi        $link['name']  = $name;
66471352defSandi        $link['title'] = $title;
6650cecf9d5Sandi
66671352defSandi        //output formatted
667a2d649c4Sandi        $this->doc .= $this->_formatLink($link);
6680cecf9d5Sandi    }
6690cecf9d5Sandi
6704826ab45Sandi    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
671dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
67237e34a5eSandi        global $ID;
67391df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
67437e34a5eSandi        resolve_mediaid(getNS($ID),$src, $exists);
6750cecf9d5Sandi
676d98d4540SBen Coburn        $noLink = false;
6778acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
678b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
6793685f775Sandi
680ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
681b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
682dc673a5bSjoe.lapp            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
6831c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
6842ca14335SEsther Brunner            // don't link flash movies
68544881bd0Shenning.noren            $noLink = true;
68655efc227SAndreas Gohr        }else{
6872ca14335SEsther Brunner            // add file icons
6889d2ddea4SAndreas Gohr            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
6899d2ddea4SAndreas Gohr            $link['class'] .= ' mediafile mf_'.$class;
6906de3759aSAndreas Gohr            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
69155efc227SAndreas Gohr        }
6923685f775Sandi
69391df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
69491df343aSAndreas Gohr
6956fe20453SGina Haeussge        //markup non existing files
6966fe20453SGina Haeussge        if (!$exists)
6976fe20453SGina Haeussge          $link['class'] .= ' wikilink2';
6986fe20453SGina Haeussge
6993685f775Sandi        //output formatted
700dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7012ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7020cecf9d5Sandi    }
7030cecf9d5Sandi
7044826ab45Sandi    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
705dc673a5bSjoe.lapp                            $height=NULL, $cache=NULL, $linking=NULL) {
70691df343aSAndreas Gohr        list($src,$hash) = explode('#',$src,2);
707d98d4540SBen Coburn        $noLink = false;
7088acb3108SAndreas Gohr        $render = ($linking == 'linkonly') ? false : true;
709b739ff0fSPierre Spring        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
710b739ff0fSPierre Spring
711b739ff0fSPierre Spring        $link['url']    = ml($src,array('cache'=>$cache));
7123685f775Sandi
713ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
714b739ff0fSPierre Spring        if(substr($mime,0,5) == 'image' && $render){
7152ca14335SEsther Brunner             // link only jpeg images
71644881bd0Shenning.noren             // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
7171c882ba8SAndreas Gohr        }elseif($mime == 'application/x-shockwave-flash' && $render){
7182ca14335SEsther Brunner             // don't link flash movies
71944881bd0Shenning.noren             $noLink = true;
7202ca14335SEsther Brunner        }else{
7212ca14335SEsther Brunner             // add file icons
722d15166e5SAndreas Gohr             $link['class'] .= ' mediafile mf_'.$ext;
7232ca14335SEsther Brunner        }
7242ca14335SEsther Brunner
72591df343aSAndreas Gohr        if($hash) $link['url'] .= '#'.$hash;
72691df343aSAndreas Gohr
7273685f775Sandi        //output formatted
728dc673a5bSjoe.lapp        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
7292ca14335SEsther Brunner        else $this->doc .= $this->_formatLink($link);
7300cecf9d5Sandi    }
7310cecf9d5Sandi
7324826ab45Sandi    /**
7333db95becSAndreas Gohr     * Renders an RSS feed
734b625487dSandi     *
735b625487dSandi     * @author Andreas Gohr <andi@splitbrain.org>
736b625487dSandi     */
7373db95becSAndreas Gohr    function rss ($url,$params){
738b625487dSandi        global $lang;
7393db95becSAndreas Gohr        global $conf;
7403db95becSAndreas Gohr
7413db95becSAndreas Gohr        require_once(DOKU_INC.'inc/FeedParser.php');
7423db95becSAndreas Gohr        $feed = new FeedParser();
74300077af8SAndreas Gohr        $feed->set_feed_url($url);
744b625487dSandi
745b625487dSandi        //disable warning while fetching
746bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
7473db95becSAndreas Gohr        $rc = $feed->init();
748bad905f1SBen Coburn        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
749b625487dSandi
7503db95becSAndreas Gohr        //decide on start and end
7513db95becSAndreas Gohr        if($params['reverse']){
7523db95becSAndreas Gohr            $mod = -1;
7533db95becSAndreas Gohr            $start = $feed->get_item_quantity()-1;
7543db95becSAndreas Gohr            $end   = $start - ($params['max']);
755b2a412b0SAndreas Gohr            $end   = ($end < -1) ? -1 : $end;
7563db95becSAndreas Gohr        }else{
7573db95becSAndreas Gohr            $mod   = 1;
7583db95becSAndreas Gohr            $start = 0;
7593db95becSAndreas Gohr            $end   = $feed->get_item_quantity();
7603db95becSAndreas Gohr            $end   = ($end > $params['max']) ? $params['max'] : $end;;
7613db95becSAndreas Gohr        }
7623db95becSAndreas Gohr
763a2d649c4Sandi        $this->doc .= '<ul class="rss">';
7643db95becSAndreas Gohr        if($rc){
7653db95becSAndreas Gohr            for ($x = $start; $x != $end; $x += $mod) {
7661bde1582SAndreas Gohr                $item = $feed->get_item($x);
7673db95becSAndreas Gohr                $this->doc .= '<li><div class="li">';
768d2ea3363SAndreas Gohr                // support feeds without links
769d2ea3363SAndreas Gohr                $lnkurl = $item->get_permalink();
770d2ea3363SAndreas Gohr                if($lnkurl){
7711bde1582SAndreas Gohr                    $this->externallink($item->get_permalink(),
7721bde1582SAndreas Gohr                                        $item->get_title());
773d2ea3363SAndreas Gohr                }else{
774d2ea3363SAndreas Gohr                    $this->doc .= ' '.$item->get_title();
775d2ea3363SAndreas Gohr                }
7763db95becSAndreas Gohr                if($params['author']){
7771bde1582SAndreas Gohr                    $author = $item->get_author(0);
7781bde1582SAndreas Gohr                    if($author){
7791bde1582SAndreas Gohr                        $name = $author->get_name();
7801bde1582SAndreas Gohr                        if(!$name) $name = $author->get_email();
7811bde1582SAndreas Gohr                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
7821bde1582SAndreas Gohr                    }
7833db95becSAndreas Gohr                }
7843db95becSAndreas Gohr                if($params['date']){
7852e7e0c29SAndreas Gohr                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
7863db95becSAndreas Gohr                }
7871bde1582SAndreas Gohr                if($params['details']){
7883db95becSAndreas Gohr                    $this->doc .= '<div class="detail">';
789173dccb7STom N Harris                    if($conf['htmlok']){
7901bde1582SAndreas Gohr                        $this->doc .= $item->get_description();
7913db95becSAndreas Gohr                    }else{
7921bde1582SAndreas Gohr                        $this->doc .= strip_tags($item->get_description());
7933db95becSAndreas Gohr                    }
7943db95becSAndreas Gohr                    $this->doc .= '</div>';
7953db95becSAndreas Gohr                }
7963db95becSAndreas Gohr
7973db95becSAndreas Gohr                $this->doc .= '</div></li>';
798b625487dSandi            }
799b625487dSandi        }else{
8003db95becSAndreas Gohr            $this->doc .= '<li><div class="li">';
801a2d649c4Sandi            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
802b625487dSandi            $this->externallink($url);
80345e147ccSAndreas Gohr            if($conf['allowdebug']){
80445e147ccSAndreas Gohr                $this->doc .= '<!--'.hsc($feed->error).'-->';
80545e147ccSAndreas Gohr            }
8063db95becSAndreas Gohr            $this->doc .= '</div></li>';
807b625487dSandi        }
808a2d649c4Sandi        $this->doc .= '</ul>';
809b625487dSandi    }
810b625487dSandi
8110cecf9d5Sandi    // $numrows not yet implemented
8120cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){
813b5742cedSPierre Spring        // initialize the row counter used for classes
814b5742cedSPierre Spring        $this->_counter['row_counter'] = 0;
815a2d649c4Sandi        $this->doc .= '<table class="inline">'.DOKU_LF;
8160cecf9d5Sandi    }
8170cecf9d5Sandi
8180cecf9d5Sandi    function table_close(){
819cb42b03dSAnika Henke        $this->doc .= '</table>'.DOKU_LF;
8200cecf9d5Sandi    }
8210cecf9d5Sandi
8220cecf9d5Sandi    function tablerow_open(){
823b5742cedSPierre Spring        // initialize the cell counter used for classes
824b5742cedSPierre Spring        $this->_counter['cell_counter'] = 0;
825b5742cedSPierre Spring        $class = 'row' . $this->_counter['row_counter']++;
826b5742cedSPierre Spring        $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
8270cecf9d5Sandi    }
8280cecf9d5Sandi
8290cecf9d5Sandi    function tablerow_close(){
830a2d649c4Sandi        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
8310cecf9d5Sandi    }
8320cecf9d5Sandi
8330cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){
834b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
8350cecf9d5Sandi        if ( !is_null($align) ) {
836b5742cedSPierre Spring            $class .= ' '.$align.'align';
8370cecf9d5Sandi        }
838b5742cedSPierre Spring        $class .= '"';
839b5742cedSPierre Spring        $this->doc .= '<th ' . $class;
8400cecf9d5Sandi        if ( $colspan > 1 ) {
841a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
842a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8430cecf9d5Sandi        }
844a2d649c4Sandi        $this->doc .= '>';
8450cecf9d5Sandi    }
8460cecf9d5Sandi
8470cecf9d5Sandi    function tableheader_close(){
848a2d649c4Sandi        $this->doc .= '</th>';
8490cecf9d5Sandi    }
8500cecf9d5Sandi
8510cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){
852b5742cedSPierre Spring        $class = 'class="col' . $this->_counter['cell_counter']++;
8530cecf9d5Sandi        if ( !is_null($align) ) {
854b5742cedSPierre Spring            $class .= ' '.$align.'align';
8550cecf9d5Sandi        }
856b5742cedSPierre Spring        $class .= '"';
857b5742cedSPierre Spring        $this->doc .= '<td '.$class;
8580cecf9d5Sandi        if ( $colspan > 1 ) {
859a28fd914SAndreas Gohr            $this->_counter['cell_counter'] += $colspan-1;
860a2d649c4Sandi            $this->doc .= ' colspan="'.$colspan.'"';
8610cecf9d5Sandi        }
862a2d649c4Sandi        $this->doc .= '>';
8630cecf9d5Sandi    }
8640cecf9d5Sandi
8650cecf9d5Sandi    function tablecell_close(){
866a2d649c4Sandi        $this->doc .= '</td>';
8670cecf9d5Sandi    }
8680cecf9d5Sandi
8690cecf9d5Sandi    //----------------------------------------------------------
8700cecf9d5Sandi    // Utils
8710cecf9d5Sandi
872ba11bd29Sandi    /**
8733fd0b676Sandi     * Build a link
8743fd0b676Sandi     *
8753fd0b676Sandi     * Assembles all parts defined in $link returns HTML for the link
876ba11bd29Sandi     *
877ba11bd29Sandi     * @author Andreas Gohr <andi@splitbrain.org>
878ba11bd29Sandi     */
879433bef32Sandi    function _formatLink($link){
880ba11bd29Sandi        //make sure the url is XHTML compliant (skip mailto)
881ba11bd29Sandi        if(substr($link['url'],0,7) != 'mailto:'){
882ba11bd29Sandi            $link['url'] = str_replace('&','&amp;',$link['url']);
883ba11bd29Sandi            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
884ba11bd29Sandi        }
885ba11bd29Sandi        //remove double encodings in titles
886ba11bd29Sandi        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
887ba11bd29Sandi
888453493f2SAndreas Gohr        // be sure there are no bad chars in url or title
889453493f2SAndreas Gohr        // (we can't do this for name because it can contain an img tag)
890453493f2SAndreas Gohr        $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
891453493f2SAndreas Gohr        $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
892453493f2SAndreas Gohr
893ba11bd29Sandi        $ret  = '';
894ba11bd29Sandi        $ret .= $link['pre'];
895ba11bd29Sandi        $ret .= '<a href="'.$link['url'].'"';
896bb4866bdSchris        if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
897bb4866bdSchris        if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
898bb4866bdSchris        if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
899bb4866bdSchris        if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
90044a6b4c7SAndreas Gohr        if(!empty($link['rel']))    $ret .= ' rel="'.$link['rel'].'"';
901bb4866bdSchris        if(!empty($link['more']))   $ret .= ' '.$link['more'];
902ba11bd29Sandi        $ret .= '>';
903ba11bd29Sandi        $ret .= $link['name'];
904ba11bd29Sandi        $ret .= '</a>';
905ba11bd29Sandi        $ret .= $link['suf'];
906ba11bd29Sandi        return $ret;
907ba11bd29Sandi    }
908ba11bd29Sandi
909ba11bd29Sandi    /**
9103fd0b676Sandi     * Renders internal and external media
9113fd0b676Sandi     *
9123fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
9133fd0b676Sandi     */
9143fd0b676Sandi    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
915b739ff0fSPierre Spring                      $height=NULL, $cache=NULL, $render = true) {
9163fd0b676Sandi
9173fd0b676Sandi        $ret = '';
9183fd0b676Sandi
919ecebf3a8SAndreas Gohr        list($ext,$mime,$dl) = mimetype($src);
9203fd0b676Sandi        if(substr($mime,0,5) == 'image'){
921b739ff0fSPierre Spring            // first get the $title
922b739ff0fSPierre Spring            if (!is_null($title)) {
923b739ff0fSPierre Spring                $title  = $this->_xmlEntities($title);
924b739ff0fSPierre Spring            }elseif($ext == 'jpg' || $ext == 'jpeg'){
925b739ff0fSPierre Spring                //try to use the caption from IPTC/EXIF
926b739ff0fSPierre Spring                require_once(DOKU_INC.'inc/JpegMeta.php');
927b739ff0fSPierre Spring                $jpeg =& new JpegMeta(mediaFN($src));
928b739ff0fSPierre Spring                if($jpeg !== false) $cap = $jpeg->getTitle();
929b739ff0fSPierre Spring                if($cap){
930b739ff0fSPierre Spring                    $title = $this->_xmlEntities($cap);
931b739ff0fSPierre Spring                }
932b739ff0fSPierre Spring            }
933b739ff0fSPierre Spring            if (!$render) {
934b739ff0fSPierre Spring                // if the picture is not supposed to be rendered
935b739ff0fSPierre Spring                // return the title of the picture
936b739ff0fSPierre Spring                if (!$title) {
937b739ff0fSPierre Spring                    // just show the sourcename
938b739ff0fSPierre Spring                    $title = $this->_xmlEntities(basename(noNS($src)));
939b739ff0fSPierre Spring                }
940b739ff0fSPierre Spring                return $title;
941b739ff0fSPierre Spring            }
9423fd0b676Sandi            //add image tag
9436de3759aSAndreas Gohr            $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
9443fd0b676Sandi            $ret .= ' class="media'.$align.'"';
9453fd0b676Sandi
9464ab889eaSAndreas Gohr            // make left/right alignment for no-CSS view work (feeds)
9474ab889eaSAndreas Gohr            if($align == 'right') $ret .= ' align="right"';
9484ab889eaSAndreas Gohr            if($align == 'left')  $ret .= ' align="left"';
9494ab889eaSAndreas Gohr
950b739ff0fSPierre Spring            if ($title) {
951b739ff0fSPierre Spring                $ret .= ' title="' . $title . '"';
952b739ff0fSPierre Spring                $ret .= ' alt="'   . $title .'"';
9533fd0b676Sandi            }else{
9543fd0b676Sandi                $ret .= ' alt=""';
9553fd0b676Sandi            }
9563fd0b676Sandi
9573fd0b676Sandi            if ( !is_null($width) )
9583fd0b676Sandi                $ret .= ' width="'.$this->_xmlEntities($width).'"';
9593fd0b676Sandi
9603fd0b676Sandi            if ( !is_null($height) )
9613fd0b676Sandi                $ret .= ' height="'.$this->_xmlEntities($height).'"';
9623fd0b676Sandi
9633fd0b676Sandi            $ret .= ' />';
9643fd0b676Sandi
9653fd0b676Sandi        }elseif($mime == 'application/x-shockwave-flash'){
9661c882ba8SAndreas Gohr            if (!$render) {
9671c882ba8SAndreas Gohr                // if the flash is not supposed to be rendered
9681c882ba8SAndreas Gohr                // return the title of the flash
9691c882ba8SAndreas Gohr                if (!$title) {
9701c882ba8SAndreas Gohr                    // just show the sourcename
97107bf32b2SAndreas Gohr                    $title = basename(noNS($src));
9721c882ba8SAndreas Gohr                }
97307bf32b2SAndreas Gohr                return $this->_xmlEntities($title);
9741c882ba8SAndreas Gohr            }
9751c882ba8SAndreas Gohr
97607bf32b2SAndreas Gohr            $att = array();
97707bf32b2SAndreas Gohr            $att['class'] = "media$align";
97807bf32b2SAndreas Gohr            if($align == 'right') $att['align'] = 'right';
97907bf32b2SAndreas Gohr            if($align == 'left')  $att['align'] = 'left';
980109577f5SAndreas Gohr            $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height,
98107bf32b2SAndreas Gohr                                     array('quality' => 'high'),
98207bf32b2SAndreas Gohr                                     null,
98307bf32b2SAndreas Gohr                                     $att,
98407bf32b2SAndreas Gohr                                     $this->_xmlEntities($title));
9850f428d7dSAndreas Gohr        }elseif($title){
9863fd0b676Sandi            // well at least we have a title to display
9873fd0b676Sandi            $ret .= $this->_xmlEntities($title);
9883fd0b676Sandi        }else{
9895291ca3aSAndreas Gohr            // just show the sourcename
9900f428d7dSAndreas Gohr            $ret .= $this->_xmlEntities(basename(noNS($src)));
9913fd0b676Sandi        }
9923fd0b676Sandi
9933fd0b676Sandi        return $ret;
9943fd0b676Sandi    }
9953fd0b676Sandi
996433bef32Sandi    function _xmlEntities($string) {
997de117061Schris        return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
9980cecf9d5Sandi    }
9990cecf9d5Sandi
10008a831f2bSAndreas Gohr    /**
10018a831f2bSAndreas Gohr     * Creates a linkid from a headline
1002c5a8fd96SAndreas Gohr     *
1003c5a8fd96SAndreas Gohr     * @param string  $title   The headline title
1004c5a8fd96SAndreas Gohr     * @param boolean $create  Create a new unique ID?
1005c5a8fd96SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
10068a831f2bSAndreas Gohr     */
1007c5a8fd96SAndreas Gohr    function _headerToLink($title,$create=false) {
1008c5a8fd96SAndreas Gohr        if($create){
10094ceab83fSAndreas Gohr            return sectionID($title,$this->headers);
10104ceab83fSAndreas Gohr        }else{
1011443d207bSAndreas Gohr            $check = false;
1012443d207bSAndreas Gohr            return sectionID($title,$check);
1013c5a8fd96SAndreas Gohr        }
10140cecf9d5Sandi    }
10150cecf9d5Sandi
1016af587fa8Sandi    /**
10173fd0b676Sandi     * Construct a title and handle images in titles
10183fd0b676Sandi     *
10190b7c14c2Sandi     * @author Harry Fuecks <hfuecks@gmail.com>
10203fd0b676Sandi     */
1021fe9ec250SChris Smith    function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') {
1022bb0a59d4Sjan        global $conf;
1023bb0a59d4Sjan
102444881bd0Shenning.noren        $isImage = false;
1025a6f3bd20SAnika Henke        if ( is_null($title) || trim($title)=='') {
1026fe9ec250SChris Smith            if (useHeading($linktype) && $id) {
1027fc18c0fbSchris                $heading = p_get_first_heading($id,true);
1028bb0a59d4Sjan                if ($heading) {
1029433bef32Sandi                    return $this->_xmlEntities($heading);
1030bb0a59d4Sjan                }
1031bb0a59d4Sjan            }
1032433bef32Sandi            return $this->_xmlEntities($default);
10330cecf9d5Sandi        } else if ( is_array($title) ) {
103444881bd0Shenning.noren            $isImage = true;
1035433bef32Sandi            return $this->_imageTitle($title);
103668c26e6dSMichael Klier        } else {
103768c26e6dSMichael Klier            return $this->_xmlEntities($title);
10380cecf9d5Sandi        }
10390cecf9d5Sandi    }
10400cecf9d5Sandi
10410cecf9d5Sandi    /**
10423fd0b676Sandi     * Returns an HTML code for images used in link titles
10433fd0b676Sandi     *
10443fd0b676Sandi     * @todo Resolve namespace on internal images
10453fd0b676Sandi     * @author Andreas Gohr <andi@splitbrain.org>
10460cecf9d5Sandi     */
1047433bef32Sandi    function _imageTitle($img) {
1048433bef32Sandi        return $this->_media($img['src'],
10494826ab45Sandi                              $img['title'],
10504826ab45Sandi                              $img['align'],
10514826ab45Sandi                              $img['width'],
10524826ab45Sandi                              $img['height'],
10534826ab45Sandi                              $img['cache']);
10540cecf9d5Sandi    }
1055b739ff0fSPierre Spring
1056b739ff0fSPierre Spring    /**
1057b739ff0fSPierre Spring     * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia()
1058b739ff0fSPierre Spring     * which returns a basic link to a media.
1059b739ff0fSPierre Spring     *
1060b739ff0fSPierre Spring     * @author Pierre Spring <pierre.spring@liip.ch>
1061b739ff0fSPierre Spring     * @param string $src
1062b739ff0fSPierre Spring     * @param string $title
1063b739ff0fSPierre Spring     * @param string $align
1064b739ff0fSPierre Spring     * @param string $width
1065b739ff0fSPierre Spring     * @param string $height
1066b739ff0fSPierre Spring     * @param string $cache
1067b739ff0fSPierre Spring     * @param string $render
1068b739ff0fSPierre Spring     * @access protected
1069b739ff0fSPierre Spring     * @return array
1070b739ff0fSPierre Spring     */
1071b739ff0fSPierre Spring    function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render)
1072b739ff0fSPierre Spring    {
1073b739ff0fSPierre Spring        global $conf;
1074b739ff0fSPierre Spring
1075b739ff0fSPierre Spring        $link = array();
1076b739ff0fSPierre Spring        $link['class']  = 'media';
1077b739ff0fSPierre Spring        $link['style']  = '';
1078b739ff0fSPierre Spring        $link['pre']    = '';
1079b739ff0fSPierre Spring        $link['suf']    = '';
1080b739ff0fSPierre Spring        $link['more']   = '';
1081b739ff0fSPierre Spring        $link['target'] = $conf['target']['media'];
1082b739ff0fSPierre Spring        $link['title']  = $this->_xmlEntities($src);
1083b739ff0fSPierre Spring        $link['name']   = $this->_media($src, $title, $align, $width, $height, $cache, $render);
1084b739ff0fSPierre Spring
1085b739ff0fSPierre Spring        return $link;
1086b739ff0fSPierre Spring    }
10870cecf9d5Sandi}
10880cecf9d5Sandi
10894826ab45Sandi//Setup VIM: ex: et ts=4 enc=utf-8 :
1090