Skip to content
Snippets Groups Projects
xhtml.php 39.4 KiB
Newer Older
/**
 * Renderer for XHTML output
 *
 * @author Harry Fuecks <hfuecks@gmail.com>
 * @author Andreas Gohr <andi@splitbrain.org>
 */
if(!defined('DOKU_INC')) die('meh.');

if ( !defined('DOKU_LF') ) {
    // Some whitespace to help View > Source
    define ('DOKU_LF',"\n");
}

if ( !defined('DOKU_TAB') ) {
    // Some whitespace to help View > Source
    define ('DOKU_TAB',"\t");
}

require_once DOKU_INC . 'inc/parser/renderer.php';
require_once DOKU_INC . 'inc/html.php';
Andreas Gohr's avatar
Andreas Gohr committed
 * The Renderer
andi's avatar
andi committed
class Doku_Renderer_xhtml extends Doku_Renderer {
    // @access public
    var $doc = '';        // will contain the whole document
    var $toc = array();   // will contain the Table of Contents

    var $sectionedits = array(); // A stack of section edit data
    private $lastsecid = 0; // last section edit id, used by startSectionEdit
Andreas Gohr's avatar
Andreas Gohr committed

    var $headers = array();
    var $footnotes = array();
    var $lastlevel = 0;
    var $node = array(0,0,0,0,0);
andi's avatar
andi committed
    var $store = '';

    var $_counter   = array(); // used as global counter, introduced for table classes
    var $_codeblock = 0; // counts the code and file blocks, used to provide download links
    /**
     * Register a new edit section range
     *
     * @param $type  string The section type identifier
     * @param $title string The section title
     * @param $start int    The byte position for the edit start
     * @return string A marker class for the starting HTML element
     * @author Adrian Lang <lang@cosmocode.de>
     */
    public function startSectionEdit($start, $type, $title = null) {
        $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title);
        return 'sectionedit' . $this->lastsecid;
    }

    /**
     * Finish an edit section range
     *
     * @param $end int The byte position for the edit end; null for the rest of
                       the page
     * @author Adrian Lang <lang@cosmocode.de>
     */
    public function finishSectionEdit($end = null) {
        list($id, $start, $type, $title) = array_pop($this->sectionedits);
        if (!is_null($end) && $end <= $start) {
Adrian Lang's avatar
Adrian Lang committed
            return;
        }
        $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' ';
        if (!is_null($title)) {
            $this->doc .= '"' . str_replace('"', '', $title) . '" ';
        }
        $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->';
    function getFormat(){
        return 'xhtml';
    }


    function document_start() {
        //reset some internals
        $this->toc     = array();
        $this->headers = array();
Andreas Gohr's avatar
Andreas Gohr committed

    function document_end() {
        // Finish open section edits.
        while (count($this->sectionedits) > 0) {
            if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) {
                // If there is only one section, do not write a section edit
                // marker.
                array_pop($this->sectionedits);
            } else {
                $this->finishSectionEdit();
        if ( count ($this->footnotes) > 0 ) {
            $this->doc .= '<div class="footnotes">'.DOKU_LF;
            foreach ( $this->footnotes as $footnote ) {
                $id++;   // the number of the current footnote
Andreas Gohr's avatar
Andreas Gohr committed

                // check its not a placeholder that indicates actual footnote text is elsewhere
                if (substr($footnote, 0, 5) != "@@FNT") {

                    // open the footnote and set the anchor and backlink
                    $this->doc .= '<div class="fn">';
                    $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">';
                    $this->doc .= $id.')</a></sup> '.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

                    // get any other footnotes that use the same markup
                    $alt = array_keys($this->footnotes, "@@FNT$id");
Andreas Gohr's avatar
Andreas Gohr committed

                    if (count($alt)) {
                      foreach ($alt as $ref) {
                        // set anchor and backlink for the other footnotes
                        $this->doc .= ', <sup><a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" class="fn_bot">';
                        $this->doc .= ($ref+1).')</a></sup> '.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

                    // add footnote markup and close this footnote
                    $this->doc .= $footnote;
                    $this->doc .= '</div>' . DOKU_LF;
                }
            $this->doc .= '</div>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed
        // Prepare the TOC
        global $conf;
        if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){
Andreas Gohr's avatar
Andreas Gohr committed
            global $TOC;
            $TOC = $this->toc;
Andreas Gohr's avatar
Andreas Gohr committed
        }

        // make sure there are no empty paragraphs
        $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
    function toc_additem($id, $text, $level) {
        global $conf;

        //handle TOC
        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
Andreas Gohr's avatar
Andreas Gohr committed
            $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1);

    function header($text, $level, $pos) {
        if(!$text) return; //skip empty headlines

        $hid = $this->_headerToLink($text,true);

        //only add items within configured levels
        $this->toc_additem($hid, $text, $level);
        // adjust $node to reflect hierarchy of levels
        $this->node[$level-1]++;
        if ($level < $this->lastlevel) {
            for ($i = 0; $i < $this->lastlevel-$level; $i++) {
                $this->node[$this->lastlevel-$i-1] = 0;
            }
        }
        $this->lastlevel = $level;

        if ($level <= $conf['maxseclevel'] &&
            count($this->sectionedits) > 0 &&
            $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') {
            $this->finishSectionEdit($pos - 1);
        // write the header
        $this->doc .= DOKU_LF.'<h'.$level;
        if ($level <= $conf['maxseclevel']) {
            $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"';
        }
        $this->doc .= $this->_xmlEntities($text);
        $this->doc .= "</h$level>".DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function section_open($level) {
        $this->doc .= '<div class="level' . $level . '">' . DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function section_close() {
        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function cdata($text) {
        $this->doc .= $this->_xmlEntities($text);
Andreas Gohr's avatar
Andreas Gohr committed

    function p_open() {
Anika Henke's avatar
Anika Henke committed
        $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function p_close() {
Anika Henke's avatar
Anika Henke committed
        $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function linebreak() {
        $this->doc .= '<br/>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

        $this->doc .= '<hr />'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function strong_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function strong_close() {
        $this->doc .= '</strong>';
Andreas Gohr's avatar
Andreas Gohr committed

    function emphasis_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function emphasis_close() {
Andreas Gohr's avatar
Andreas Gohr committed

    function underline_open() {
        $this->doc .= '<em class="u">';
Andreas Gohr's avatar
Andreas Gohr committed

    function underline_close() {
        $this->doc .= '</em>';
Andreas Gohr's avatar
Andreas Gohr committed

    function monospace_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function monospace_close() {
Andreas Gohr's avatar
Andreas Gohr committed

    function subscript_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function subscript_close() {
Andreas Gohr's avatar
Andreas Gohr committed

    function superscript_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function superscript_close() {
Andreas Gohr's avatar
Andreas Gohr committed

    function deleted_open() {
Andreas Gohr's avatar
Andreas Gohr committed

    function deleted_close() {
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
    /**
     * Callback for footnote start syntax
     *
     * All following content will go to the footnote instead of
     * the document. To achieve this the previous rendered content
andi's avatar
andi committed
     * is moved to $store and $doc is cleared
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    function footnote_open() {
andi's avatar
andi committed

        // move current content to store and record footnote
        $this->store = $this->doc;
        $this->doc   = '';
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
    /**
     * Callback for footnote end syntax
     *
     * All rendered content is moved to the $footnotes array and the old
     * content is restored from $store again
     *
     * @author Andreas Gohr
     */
    function footnote_close() {
andi's avatar
andi committed

        // recover footnote into the stack and restore old content
        $footnote = $this->doc;
andi's avatar
andi committed
        $this->doc = $this->store;
        $this->store = '';
Andreas Gohr's avatar
Andreas Gohr committed

        // check to see if this footnote has been seen before
        $i = array_search($footnote, $this->footnotes);
Andreas Gohr's avatar
Andreas Gohr committed

        if ($i === false) {
            // its a new footnote, add it to the $footnotes array
            $id = count($this->footnotes)+1;
            $this->footnotes[count($this->footnotes)] = $footnote;
        } else {
            // seen this one before, translate the index to an id and save a placeholder
            $i++;
            $id = count($this->footnotes)+1;
            $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
        }

Andreas Gohr's avatar
Andreas Gohr committed
        // output the footnote reference and link
        $this->doc .= '<sup><a href="#fn__'.$id.'" id="fnt__'.$id.'" class="fn_top">'.$id.')</a></sup>';
Andreas Gohr's avatar
Andreas Gohr committed

    function listu_open() {
        $this->doc .= '<ul>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function listu_close() {
        $this->doc .= '</ul>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function listo_open() {
        $this->doc .= '<ol>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function listo_close() {
        $this->doc .= '</ol>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function listitem_open($level) {
Anika Henke's avatar
Anika Henke committed
        $this->doc .= '<li class="level'.$level.'">';
Andreas Gohr's avatar
Andreas Gohr committed

    function listitem_close() {
        $this->doc .= '</li>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function listcontent_open() {
        $this->doc .= '<div class="li">';
Andreas Gohr's avatar
Andreas Gohr committed

    function listcontent_close() {
Anika Henke's avatar
Anika Henke committed
        $this->doc .= '</div>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function unformatted($text) {
        $this->doc .= $this->_xmlEntities($text);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
     * Execute PHP code if allowed
     *
     * @param  string   $text      PHP code that is either executed or printed
Chris Smith's avatar
Chris Smith committed
     * @param  string   $wrapper   html element to wrap result if $conf['phpok'] is okff
     *
andi's avatar
andi committed
     * @author Andreas Gohr <andi@splitbrain.org>
     */
Chris Smith's avatar
Chris Smith committed
    function php($text, $wrapper='code') {
        global $conf;

        if($conf['phpok']){
          ob_start();
          eval($text);
          $this->doc .= ob_get_contents();
          ob_end_clean();
        } else {
Chris Smith's avatar
Chris Smith committed
          $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper);
Andreas Gohr's avatar
Andreas Gohr committed

Chris Smith's avatar
Chris Smith committed
        $this->php($text, 'pre');
andi's avatar
andi committed
     * Insert HTML if allowed
     *
     * @param  string   $text      html text
Chris Smith's avatar
Chris Smith committed
     * @param  string   $wrapper   html element to wrap result if $conf['htmlok'] is okff
     *
andi's avatar
andi committed
     * @author Andreas Gohr <andi@splitbrain.org>
     */
Chris Smith's avatar
Chris Smith committed
    function html($text, $wrapper='code') {
        global $conf;

        if($conf['htmlok']){
          $this->doc .= $text;
        } else {
Chris Smith's avatar
Chris Smith committed
          $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
Andreas Gohr's avatar
Andreas Gohr committed

Chris Smith's avatar
Chris Smith committed
        $this->html($text, 'pre');
    function quote_open() {
        $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function quote_close() {
        $this->doc .= '</div></blockquote>'.DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function preformatted($text) {
        $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF;
    }

    function file($text, $language=null, $filename=null) {
        $this->_highlight('file',$text,$language,$filename);
    }

    function code($text, $language=null, $filename=null) {
        $this->_highlight('code',$text,$language,$filename);
    }

     * Use GeSHi to highlight language syntax in code and file blocks
andi's avatar
andi committed
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
    function _highlight($type, $text, $language=null, $filename=null) {
        global $conf;
        global $ID;
        global $lang;

        if($filename){
            // add icon
            list($ext) = mimetype($filename,false);
            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
            $class = 'mediafile mf_'.$class;

            $this->doc .= '<dl class="'.$type.'">'.DOKU_LF;
            $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">';
            $this->doc .= hsc($filename);
            $this->doc .= '</a></dt>'.DOKU_LF.'<dd>';
        }
Andreas Gohr's avatar
Andreas Gohr committed

        if ($text{0} == "\n") {
            $text = substr($text, 1);
        }
        if (substr($text, -1) == "\n") {
            $text = substr($text, 0, -1);
        }

        if ( is_null($language) ) {
            $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF;
            $class = 'code'; //we always need the code class to make the syntax highlighting apply
            if($type != 'code') $class .= ' '.$type;

            $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF;

        if($filename){
            $this->doc .= '</dd></dl>'.DOKU_LF;
        }

        $this->_codeblock++;
Andreas Gohr's avatar
Andreas Gohr committed

    function acronym($acronym) {
Andreas Gohr's avatar
Andreas Gohr committed

        if ( array_key_exists($acronym, $this->acronyms) ) {
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
            $title = $this->_xmlEntities($this->acronyms[$acronym]);
Andreas Gohr's avatar
Andreas Gohr committed

            $this->doc .= '<abbr title="'.$title
                .'">'.$this->_xmlEntities($acronym).'</abbr>';
Andreas Gohr's avatar
Andreas Gohr committed

            $this->doc .= $this->_xmlEntities($acronym);
Andreas Gohr's avatar
Andreas Gohr committed

    function smiley($smiley) {
        if ( array_key_exists($smiley, $this->smileys) ) {
andi's avatar
andi committed
            $title = $this->_xmlEntities($this->smileys[$smiley]);
            $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
                '" class="icon" alt="'.
andi's avatar
andi committed
                    $this->_xmlEntities($smiley).'" />';
            $this->doc .= $this->_xmlEntities($smiley);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
    * not used
    function wordblock($word) {
        if ( array_key_exists($word, $this->badwords) ) {
            $this->doc .= '** BLEEP **';
            $this->doc .= $this->_xmlEntities($word);
andi's avatar
andi committed
    */
Andreas Gohr's avatar
Andreas Gohr committed

    function entity($entity) {
        if ( array_key_exists($entity, $this->entities) ) {
            $this->doc .= $this->entities[$entity];
            $this->doc .= $this->_xmlEntities($entity);
Andreas Gohr's avatar
Andreas Gohr committed

    function multiplyentity($x, $y) {
        $this->doc .= "$x&times;$y";
Andreas Gohr's avatar
Andreas Gohr committed

    function singlequoteopening() {
        global $lang;
        $this->doc .= $lang['singlequoteopening'];
Andreas Gohr's avatar
Andreas Gohr committed

    function singlequoteclosing() {
        global $lang;
        $this->doc .= $lang['singlequoteclosing'];
Andreas Gohr's avatar
Andreas Gohr committed

    function apostrophe() {
        global $lang;
        $this->doc .= $lang['apostrophe'];
    function doublequoteopening() {
        global $lang;
        $this->doc .= $lang['doublequoteopening'];
Andreas Gohr's avatar
Andreas Gohr committed

    function doublequoteclosing() {
        global $lang;
        $this->doc .= $lang['doublequoteclosing'];
Andreas Gohr's avatar
Andreas Gohr committed

    /**
    */
    function camelcaselink($link) {
Andreas Gohr's avatar
Andreas Gohr committed
      $this->internallink($link,$link);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed

    function locallink($hash, $name = NULL){
        global $ID;
        $name  = $this->_getLinkTitle($name, $hash, $isImage);
        $hash  = $this->_headerToLink($hash);
andi's avatar
andi committed
        $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
        $this->doc .= $name;
        $this->doc .= '</a>';
    }

andi's avatar
andi committed
     * Render an internal Wiki Link
     *
     * $search,$returnonly & $linktype are not for the renderer but are used
     * elsewhere - no need to implement them in other renderers
andi's avatar
andi committed
     *
     * @author Andreas Gohr <andi@splitbrain.org>
    function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') {
        global $conf;
        global $ID;
        $params = '';
        $parts = explode('?', $id, 2);
        if (count($parts) === 2) {
            $id = $parts[0];
            $params = $parts[1];
        // For empty $id we need to know the current $ID
        // We need this check because _simpleTitle needs
        // correct $id and resolve_pageid() use cleanID($id)
        // (some things could be lost)
        if ($id === '') {
            $id = $ID;
        }

        // default name is based on $id as given
        $default = $this->_simpleTitle($id);
        // now first resolve and clean up the $id
        resolve_pageid(getNS($ID),$id,$exists);
        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
        if ( !$isImage ) {
            if ( $exists ) {
                $class='wikilink1';
                $class='wikilink2';
Andreas Gohr's avatar
Andreas Gohr committed
                $link['rel']='nofollow';
            $class='media';
Andreas Gohr's avatar
Andreas Gohr committed

        //keep hash anchor
        list($id,$hash) = explode('#',$id,2);
        if(!empty($hash)) $hash = $this->_headerToLink($hash);
Andreas Gohr's avatar
Andreas Gohr committed

        //prepare for formating
        $link['target'] = $conf['target']['wiki'];
        $link['style']  = '';
        $link['pre']    = '';
        $link['suf']    = '';
jan's avatar
jan committed
        // highlight link to current page
andi's avatar
andi committed
            $link['pre']    = '<span class="curid">';
            $link['suf']    = '</span>';
        }
        $link['more']   = '';
        $link['class']  = $class;
        $link['url']    = wl($id, $params);
        $link['name']   = $name;
        $link['title']  = $id;
andi's avatar
andi committed
        //add search string
        if($search){
            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
            if(is_array($search)){
                $search = array_map('rawurlencode',$search);
                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
            }else{
                $link['url'] .= 's='.rawurlencode($search);
            }
andi's avatar
andi committed
        }

        //keep hash
        if($hash) $link['url'].='#'.$hash;

        //output formatted
        if($returnonly){
            return $this->_formatLink($link);
        }else{
            $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

    function externallink($url, $name = NULL) {
        global $conf;

andi's avatar
andi committed
        $name = $this->_getLinkTitle($name, $url, $isImage);
        // url might be an attack vector, only allow registered protocols
        if(is_null($this->schemes)) $this->schemes = getSchemes();
        list($scheme) = explode('://',$url);
        $scheme = strtolower($scheme);
        if(!in_array($scheme,$this->schemes)) $url = '';

        // is there still an URL?
        if(!$url){
            $this->doc .= $name;
            return;
        }

        // set class
        if ( !$isImage ) {
            $class='urlextern';
            $class='media';
Andreas Gohr's avatar
Andreas Gohr committed

        //prepare for formating
        $link['target'] = $conf['target']['extern'];
        $link['style']  = '';
        $link['pre']    = '';
        $link['suf']    = '';
        $link['more']   = '';
        $link['class']  = $class;
        $link['url']    = $url;
chris's avatar
chris committed

        $link['name']   = $name;
andi's avatar
andi committed
        $link['title']  = $this->_xmlEntities($url);
        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';

        //output formatted
        $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
        global $conf;
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
        $link = array();
        $link['target'] = $conf['target']['interwiki'];
        $link['pre']    = '';
        $link['suf']    = '';
        $link['more']   = '';
andi's avatar
andi committed
        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
andi's avatar
andi committed

        //get interwiki URL
Michael Klier's avatar
Michael Klier committed
        $url = $this->_resolveInterWiki($wikiName,$wikiUri);
            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
            $link['class'] = "interwiki iw_$class";
        } else {
            $link['class'] = 'media';
andi's avatar
andi committed

        //do we stay at the same server? Use local target
        if( strpos($url,DOKU_URL) === 0 ){
            $link['target'] = $conf['target']['wiki'];
andi's avatar
andi committed

andi's avatar
andi committed
        $link['title'] = htmlspecialchars($link['url']);

        //output formatted
        $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
     */
    function windowssharelink($url, $name = NULL) {
        global $conf;
        global $lang;
        //simple setup
        $link['target'] = $conf['target']['windows'];
        $link['pre']    = '';
        $link['suf']   = '';
        $link['style']  = '';

andi's avatar
andi committed
        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
        if ( !$isImage ) {
andi's avatar
andi committed
        $link['title'] = $this->_xmlEntities($url);
        $url = str_replace('\\','/',$url);
        $url = 'file:///'.$url;
        $link['url'] = $url;

        //output formatted
        $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
    function emaillink($address, $name = NULL) {
        global $conf;
        //simple setup
        $link = array();
        $link['target'] = '';
        $link['pre']    = '';
        $link['suf']   = '';
        $link['style']  = '';
        $link['more']   = '';
Andreas Gohr's avatar
Andreas Gohr committed

        $name = $this->_getLinkTitle($name, '', $isImage);
        if ( !$isImage ) {
            $link['class']='mail';
            $link['class']='media';
andi's avatar
andi committed
        }

Andreas Gohr's avatar
Andreas Gohr committed
        $address = $this->_xmlEntities($address);
        $address = obfuscate($address);
        $title   = $address;
Andreas Gohr's avatar
Andreas Gohr committed

        if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
Andreas Gohr's avatar
Andreas Gohr committed

        $link['url']   = 'mailto:'.$address;
andi's avatar
andi committed
        $link['name']  = $name;
        $link['title'] = $title;

        //output formatted
        $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
                            $height=NULL, $cache=NULL, $linking=NULL) {
        global $ID;
        list($src,$hash) = explode('#',$src,2);
        resolve_mediaid(getNS($ID),$src, $exists);
Ben Coburn's avatar
Ben Coburn committed
        $noLink = false;
        $render = ($linking == 'linkonly') ? false : true;
Pierre Spring's avatar
Pierre Spring committed
        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
andi's avatar
andi committed

        list($ext,$mime,$dl) = mimetype($src,false);
Pierre Spring's avatar
Pierre Spring committed
        if(substr($mime,0,5) == 'image' && $render){
            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
        }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){
            // don't link movies
Pierre Spring's avatar
Pierre Spring committed
            $noLink = true;
        }else{
            // add file icons
            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
            $link['class'] .= ' mediafile mf_'.$class;
            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
            if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')';
Pierre Spring's avatar
Pierre Spring committed
        }
        if($hash) $link['url'] .= '#'.$hash;

Gina Haeussge's avatar
Gina Haeussge committed
        //markup non existing files
        if (!$exists) {
            $link['class'] .= ' wikilink2';
        }
Gina Haeussge's avatar
Gina Haeussge committed

Pierre Spring's avatar
Pierre Spring committed
        //output formatted
        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
        else $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed

    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
                            $height=NULL, $cache=NULL, $linking=NULL) {
        list($src,$hash) = explode('#',$src,2);
Pierre Spring's avatar
Pierre Spring committed
        $noLink = false;
        $render = ($linking == 'linkonly') ? false : true;
Pierre Spring's avatar
Pierre Spring committed
        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
andi's avatar
andi committed

        $link['url']    = ml($src,array('cache'=>$cache));
andi's avatar
andi committed

        list($ext,$mime,$dl) = mimetype($src,false);
Pierre Spring's avatar
Pierre Spring committed
        if(substr($mime,0,5) == 'image' && $render){
            // link only jpeg images
            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
        }elseif(($mime == 'application/x-shockwave-flash' || substr($mime,0,5) == 'video') && $render){
            // don't link movies
            // add file icons
            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
            $link['class'] .= ' mediafile mf_'.$class;
        }

        if($hash) $link['url'] .= '#'.$hash;
andi's avatar
andi committed
        //output formatted
        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
        else $this->doc .= $this->_formatLink($link);
Andreas Gohr's avatar
Andreas Gohr committed
     * Renders an RSS feed
Andreas Gohr's avatar
Andreas Gohr committed
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     */
Andreas Gohr's avatar
Andreas Gohr committed
    function rss ($url,$params){
        global $lang;
Andreas Gohr's avatar
Andreas Gohr committed
        global $conf;

        require_once(DOKU_INC.'inc/FeedParser.php');
        $feed = new FeedParser();
Andreas Gohr's avatar
Andreas Gohr committed
        $feed->set_feed_url($url);

        //disable warning while fetching
Ben Coburn's avatar
Ben Coburn committed
        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
Andreas Gohr's avatar
Andreas Gohr committed
        $rc = $feed->init();
Ben Coburn's avatar
Ben Coburn committed
        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
Andreas Gohr's avatar
Andreas Gohr committed
        //decide on start and end
        if($params['reverse']){
            $mod = -1;
            $start = $feed->get_item_quantity()-1;
            $end   = $start - ($params['max']);
            $end   = ($end < -1) ? -1 : $end;
Andreas Gohr's avatar
Andreas Gohr committed
        }else{
            $mod   = 1;
            $start = 0;
            $end   = $feed->get_item_quantity();
            $end   = ($end > $params['max']) ? $params['max'] : $end;;
        }

        $this->doc .= '<ul class="rss">';
Andreas Gohr's avatar
Andreas Gohr committed
        if($rc){
            for ($x = $start; $x != $end; $x += $mod) {
Andreas Gohr's avatar
Andreas Gohr committed
                $item = $feed->get_item($x);
Andreas Gohr's avatar
Andreas Gohr committed
                $this->doc .= '<li><div class="li">';
                // support feeds without links
                $lnkurl = $item->get_permalink();
                if($lnkurl){
                    // title is escaped by SimplePie, we unescape here because it
                    // is escaped again in externallink() FS#1705
                    $this->externallink($item->get_permalink(),
                                        html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8'));
                }else{
                    $this->doc .= ' '.$item->get_title();
                }
Andreas Gohr's avatar
Andreas Gohr committed
                if($params['author']){
Andreas Gohr's avatar
Andreas Gohr committed
                    $author = $item->get_author(0);
                    if($author){
                        $name = $author->get_name();
                        if(!$name) $name = $author->get_email();
                        if($name) $this->doc .= ' '.$lang['by'].' '.$name;
                    }
Andreas Gohr's avatar
Andreas Gohr committed
                }
                if($params['date']){
                    $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')';
Andreas Gohr's avatar
Andreas Gohr committed
                if($params['details']){
Andreas Gohr's avatar
Andreas Gohr committed
                    $this->doc .= '<div class="detail">';
                    if($conf['htmlok']){
Andreas Gohr's avatar
Andreas Gohr committed
                        $this->doc .= $item->get_description();
Andreas Gohr's avatar
Andreas Gohr committed
                    }else{
Andreas Gohr's avatar
Andreas Gohr committed
                        $this->doc .= strip_tags($item->get_description());
Andreas Gohr's avatar
Andreas Gohr committed
                    }
                    $this->doc .= '</div>';
                }

                $this->doc .= '</div></li>';
Andreas Gohr's avatar
Andreas Gohr committed
            $this->doc .= '<li><div class="li">';
            $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
            $this->externallink($url);
            if($conf['allowdebug']){
                $this->doc .= '<!--'.hsc($feed->error).'-->';
            }
Andreas Gohr's avatar
Andreas Gohr committed
            $this->doc .= '</div></li>';
    // $numrows not yet implemented
    function table_open($maxcols = null, $numrows = null, $pos = null){
Pierre Spring's avatar
Pierre Spring committed
        // initialize the row counter used for classes
        $this->_counter['row_counter'] = 0;
        $class = 'table';
        if ($pos !== null) {
            $class .= ' ' . $this->startSectionEdit($pos, 'table');
        }
        $this->doc .= '<div class="' . $class . '"><table class="inline">' .
                      DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function table_close($pos = null){
        if ($pos !== null) {
            $this->finishSectionEdit($pos);
        }
Andreas Gohr's avatar
Andreas Gohr committed

    function tablerow_open(){
Pierre Spring's avatar
Pierre Spring committed
        // initialize the cell counter used for classes
        $this->_counter['cell_counter'] = 0;
        $class = 'row' . $this->_counter['row_counter']++;
        $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB;
Andreas Gohr's avatar
Andreas Gohr committed

    function tablerow_close(){
        $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
Andreas Gohr's avatar
Andreas Gohr committed

    function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){
Pierre Spring's avatar
Pierre Spring committed
        $class = 'class="col' . $this->_counter['cell_counter']++;
        if ( !is_null($align) ) {
Pierre Spring's avatar
Pierre Spring committed
            $class .= ' '.$align.'align';
Pierre Spring's avatar
Pierre Spring committed
        $class .= '"';
        $this->doc .= '<th ' . $class;
        if ( $colspan > 1 ) {
            $this->_counter['cell_counter'] += $colspan-1;
            $this->doc .= ' colspan="'.$colspan.'"';
        if ( $rowspan > 1 ) {
            $this->doc .= ' rowspan="'.$rowspan.'"';
        }
Andreas Gohr's avatar
Andreas Gohr committed

    function tableheader_close(){
Andreas Gohr's avatar
Andreas Gohr committed

    function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){
Pierre Spring's avatar
Pierre Spring committed
        $class = 'class="col' . $this->_counter['cell_counter']++;
        if ( !is_null($align) ) {
Pierre Spring's avatar
Pierre Spring committed
            $class .= ' '.$align.'align';
Pierre Spring's avatar
Pierre Spring committed
        $class .= '"';
        $this->doc .= '<td '.$class;
        if ( $colspan > 1 ) {
            $this->_counter['cell_counter'] += $colspan-1;
            $this->doc .= ' colspan="'.$colspan.'"';
        if ( $rowspan > 1 ) {
            $this->doc .= ' rowspan="'.$rowspan.'"';
        }
Andreas Gohr's avatar
Andreas Gohr committed

    function tablecell_close(){