xref: /dokuwiki/inc/parser/renderer.php (revision 1179df0e99996b3a67245ef9efa7b71b8b9cad74)
10cecf9d5Sandi<?php
261faf446Schris/**
35587e44cSchris * Renderer output base class
461faf446Schris *
561faf446Schris * @author Harry Fuecks <hfuecks@gmail.com>
661faf446Schris * @author Andreas Gohr <andi@splitbrain.org>
761faf446Schris */
861faf446Schrisif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
961faf446Schris
1061faf446Schrisrequire_once DOKU_INC . 'inc/parser/renderer.php';
11863befa1SAndreas Gohrrequire_once DOKU_INC . 'inc/plugin.php';
1261faf446Schrisrequire_once DOKU_INC . 'inc/pluginutils.php';
1361faf446Schris
14863befa1SAndreas Gohr/**
15863befa1SAndreas Gohr * An empty renderer, produces no output
16863befa1SAndreas Gohr *
17863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
18863befa1SAndreas Gohr */
19863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin {
209dc2c2afSandi    var $info = array(
2144881bd0Shenning.noren        'cache' => true, // may the rendered result cached?
2244881bd0Shenning.noren        'toc'   => true, // render the TOC?
239dc2c2afSandi    );
249dc2c2afSandi
251f82fabeSAndreas Gohr    // keep some config options
261f82fabeSAndreas Gohr    var $acronyms = array();
271f82fabeSAndreas Gohr    var $smileys = array();
281f82fabeSAndreas Gohr    var $badwords = array();
291f82fabeSAndreas Gohr    var $entities = array();
301f82fabeSAndreas Gohr    var $interwiki = array();
319dc2c2afSandi
329dc2c2afSandi    function nocache() {
3344881bd0Shenning.noren        $this->info['cache'] = false;
349dc2c2afSandi    }
350cecf9d5Sandi
36e41c4da9SAndreas Gohr    function notoc() {
3744881bd0Shenning.noren        $this->info['toc'] = false;
38e41c4da9SAndreas Gohr    }
39e41c4da9SAndreas Gohr
4061faf446Schris    //handle plugin rendering
4161faf446Schris    function plugin($name,$data){
4261faf446Schris        $plugin =& plugin_load('syntax',$name);
4361faf446Schris        if($plugin != null){
4461faf446Schris            // determine mode from renderer class name - format = "Doku_Renderer_<mode>"
4561faf446Schris            $mode = substr(get_class($this), 14);
4661faf446Schris            $plugin->render($mode,$this,$data);
4761faf446Schris        }
4861faf446Schris    }
4961faf446Schris
505587e44cSchris    /**
515587e44cSchris     * handle nested render instructions
525587e44cSchris     * this method (and nest_close method) should not be overloaded in actual renderer output classes
535587e44cSchris     */
545587e44cSchris    function nest($instructions) {
555587e44cSchris
565587e44cSchris      foreach ( $instructions as $instruction ) {
575587e44cSchris        // execute the callback against ourself
585587e44cSchris        call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
595587e44cSchris      }
605587e44cSchris    }
615587e44cSchris
625587e44cSchris    // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
635587e44cSchris    // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
645587e44cSchris    // be able to - as their instructions require data.
655587e44cSchris    function nest_close() {}
665587e44cSchris
670cecf9d5Sandi    function document_start() {}
680cecf9d5Sandi
690cecf9d5Sandi    function document_end() {}
700cecf9d5Sandi
714fced885SAndreas Gohr    function render_TOC() { return ''; }
720cecf9d5Sandi
73e7856beaSchris    function toc_additem($id, $text, $level) {}
74e7856beaSchris
75af587fa8Sandi    function header($text, $level, $pos) {}
760cecf9d5Sandi
7735dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {}
7835dae8b0SBen Coburn
790cecf9d5Sandi    function section_open($level) {}
800cecf9d5Sandi
810cecf9d5Sandi    function section_close() {}
820cecf9d5Sandi
830cecf9d5Sandi    function cdata($text) {}
840cecf9d5Sandi
850cecf9d5Sandi    function p_open() {}
860cecf9d5Sandi
870cecf9d5Sandi    function p_close() {}
880cecf9d5Sandi
890cecf9d5Sandi    function linebreak() {}
900cecf9d5Sandi
910cecf9d5Sandi    function hr() {}
920cecf9d5Sandi
930cecf9d5Sandi    function strong_open() {}
940cecf9d5Sandi
950cecf9d5Sandi    function strong_close() {}
960cecf9d5Sandi
970cecf9d5Sandi    function emphasis_open() {}
980cecf9d5Sandi
990cecf9d5Sandi    function emphasis_close() {}
1000cecf9d5Sandi
1010cecf9d5Sandi    function underline_open() {}
1020cecf9d5Sandi
1030cecf9d5Sandi    function underline_close() {}
1040cecf9d5Sandi
1050cecf9d5Sandi    function monospace_open() {}
1060cecf9d5Sandi
1070cecf9d5Sandi    function monospace_close() {}
1080cecf9d5Sandi
1090cecf9d5Sandi    function subscript_open() {}
1100cecf9d5Sandi
1110cecf9d5Sandi    function subscript_close() {}
1120cecf9d5Sandi
1130cecf9d5Sandi    function superscript_open() {}
1140cecf9d5Sandi
1150cecf9d5Sandi    function superscript_close() {}
1160cecf9d5Sandi
1170cecf9d5Sandi    function deleted_open() {}
1180cecf9d5Sandi
1190cecf9d5Sandi    function deleted_close() {}
1200cecf9d5Sandi
1210cecf9d5Sandi    function footnote_open() {}
1220cecf9d5Sandi
1230cecf9d5Sandi    function footnote_close() {}
1240cecf9d5Sandi
1250cecf9d5Sandi    function listu_open() {}
1260cecf9d5Sandi
1270cecf9d5Sandi    function listu_close() {}
1280cecf9d5Sandi
1290cecf9d5Sandi    function listo_open() {}
1300cecf9d5Sandi
1310cecf9d5Sandi    function listo_close() {}
1320cecf9d5Sandi
1330cecf9d5Sandi    function listitem_open($level) {}
1340cecf9d5Sandi
1350cecf9d5Sandi    function listitem_close() {}
1360cecf9d5Sandi
137699afdebSchris    function listcontent_open() {}
1380cecf9d5Sandi
1390cecf9d5Sandi    function listcontent_close() {}
1400cecf9d5Sandi
1410cecf9d5Sandi    function unformatted($text) {}
1420cecf9d5Sandi
1430cecf9d5Sandi    function php($text) {}
1440cecf9d5Sandi
1450cecf9d5Sandi    function html($text) {}
1460cecf9d5Sandi
1470cecf9d5Sandi    function preformatted($text) {}
1480cecf9d5Sandi
1490cecf9d5Sandi    function file($text) {}
1500cecf9d5Sandi
1510cecf9d5Sandi    function quote_open() {}
1520cecf9d5Sandi
1530cecf9d5Sandi    function quote_close() {}
1540cecf9d5Sandi
1550cecf9d5Sandi    function code($text, $lang = NULL) {}
1560cecf9d5Sandi
1570cecf9d5Sandi    function acronym($acronym) {}
1580cecf9d5Sandi
1590cecf9d5Sandi    function smiley($smiley) {}
1600cecf9d5Sandi
1610cecf9d5Sandi    function wordblock($word) {}
1620cecf9d5Sandi
1630cecf9d5Sandi    function entity($entity) {}
1640cecf9d5Sandi
1650cecf9d5Sandi    // 640x480 ($x=640, $y=480)
1660cecf9d5Sandi    function multiplyentity($x, $y) {}
1670cecf9d5Sandi
1680cecf9d5Sandi    function singlequoteopening() {}
1690cecf9d5Sandi
1700cecf9d5Sandi    function singlequoteclosing() {}
1710cecf9d5Sandi
1720cecf9d5Sandi    function doublequoteopening() {}
1730cecf9d5Sandi
1740cecf9d5Sandi    function doublequoteclosing() {}
1750cecf9d5Sandi
1760cecf9d5Sandi    // $link like 'SomePage'
1770cecf9d5Sandi    function camelcaselink($link) {}
1780cecf9d5Sandi
179a939d432SAndreas Gohr    function locallink($hash, $name = NULL) {}
180a939d432SAndreas Gohr
1810e1c636eSandi    // $link like 'wiki:syntax', $title could be an array (media)
1820cecf9d5Sandi    function internallink($link, $title = NULL) {}
1830cecf9d5Sandi
1840cecf9d5Sandi    // $link is full URL with scheme, $title could be an array (media)
1850cecf9d5Sandi    function externallink($link, $title = NULL) {}
1860cecf9d5Sandi
1870cecf9d5Sandi    // $link is the original link - probably not much use
1880cecf9d5Sandi    // $wikiName is an indentifier for the wiki
1890cecf9d5Sandi    // $wikiUri is the URL fragment to append to some known URL
1900cecf9d5Sandi    function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
1910cecf9d5Sandi
1920cecf9d5Sandi    // Link to file on users OS, $title could be an array (media)
1930cecf9d5Sandi    function filelink($link, $title = NULL) {}
1940cecf9d5Sandi
1950cecf9d5Sandi    // Link to a Windows share, , $title could be an array (media)
1960cecf9d5Sandi    function windowssharelink($link, $title = NULL) {}
1970cecf9d5Sandi
198699afdebSchris//  function email($address, $title = NULL) {}
199699afdebSchris    function emaillink($address, $name = NULL) {}
2000cecf9d5Sandi
201a939d432SAndreas Gohr    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
202a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
203a939d432SAndreas Gohr
204a939d432SAndreas Gohr    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
205a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
206a939d432SAndreas Gohr
2070cecf9d5Sandi    function internalmedialink (
2080cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2090cecf9d5Sandi        ) {}
2100cecf9d5Sandi
2110cecf9d5Sandi    function externalmedialink(
2120cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2130cecf9d5Sandi        ) {}
2140cecf9d5Sandi
2150cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){}
2160cecf9d5Sandi
2170cecf9d5Sandi    function table_close(){}
2180cecf9d5Sandi
2190cecf9d5Sandi    function tablerow_open(){}
2200cecf9d5Sandi
2210cecf9d5Sandi    function tablerow_close(){}
2220cecf9d5Sandi
2230cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){}
2240cecf9d5Sandi
2250cecf9d5Sandi    function tableheader_close(){}
2260cecf9d5Sandi
2270cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){}
2280cecf9d5Sandi
2290cecf9d5Sandi    function tablecell_close(){}
2300cecf9d5Sandi
2312ea4044fSAndreas Gohr
2322ea4044fSAndreas Gohr    // util functions follow, you probably won't need to reimplement them
2332ea4044fSAndreas Gohr
2342ea4044fSAndreas Gohr
2352ea4044fSAndreas Gohr    /**
2362ea4044fSAndreas Gohr     * Removes any Namespace from the given name but keeps
2372ea4044fSAndreas Gohr     * casing and special chars
2382ea4044fSAndreas Gohr     *
2392ea4044fSAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
2402ea4044fSAndreas Gohr     */
2412ea4044fSAndreas Gohr    function _simpleTitle($name){
2422ea4044fSAndreas Gohr        global $conf;
2432ea4044fSAndreas Gohr
2442ea4044fSAndreas Gohr        //if there is a hash we use the ancor name only
2452ea4044fSAndreas Gohr        list($name,$hash) = explode('#',$name,2);
2462ea4044fSAndreas Gohr        if($hash) return $hash;
2472ea4044fSAndreas Gohr
248*1179df0eSGuy Brand        //trim colons or slash of a namespace link
2492ea4044fSAndreas Gohr        $name = rtrim($name,':');
250*1179df0eSGuy Brand        if($conf['useslash'])
251*1179df0eSGuy Brand          $name = rtrim($name,'/');
2522ea4044fSAndreas Gohr
2532ea4044fSAndreas Gohr        if($conf['useslash']){
2542ea4044fSAndreas Gohr            $nssep = '[:;/]';
2552ea4044fSAndreas Gohr        }else{
2562ea4044fSAndreas Gohr            $nssep = '[:;]';
2572ea4044fSAndreas Gohr        }
2582ea4044fSAndreas Gohr        $name = preg_replace('!.*'.$nssep.'!','',$name);
2592ea4044fSAndreas Gohr
2602ea4044fSAndreas Gohr        if(!$name) return $this->_simpleTitle($conf['start']);
2612ea4044fSAndreas Gohr        return $name;
2622ea4044fSAndreas Gohr    }
2632ea4044fSAndreas Gohr
2641f82fabeSAndreas Gohr    /**
2651f82fabeSAndreas Gohr     * Resolve an interwikilink
2661f82fabeSAndreas Gohr     */
2671f82fabeSAndreas Gohr    function _resolveInterWiki(&$shortcut,$reference){
2681f82fabeSAndreas Gohr        //get interwiki URL
2691f82fabeSAndreas Gohr        if ( isset($this->interwiki[$shortcut]) ) {
2701f82fabeSAndreas Gohr            $url = $this->interwiki[$shortcut];
2711f82fabeSAndreas Gohr        } else {
2721f82fabeSAndreas Gohr            // Default to Google I'm feeling lucky
2731f82fabeSAndreas Gohr            $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
2741f82fabeSAndreas Gohr            $shortcut = 'go';
2751f82fabeSAndreas Gohr        }
2762ea4044fSAndreas Gohr
2771f82fabeSAndreas Gohr        //split into hash and url part
2781f82fabeSAndreas Gohr        list($wikiUri,$hash) = explode('#',$wikiUri,2);
2791f82fabeSAndreas Gohr
2801f82fabeSAndreas Gohr        //replace placeholder
2811f82fabeSAndreas Gohr        if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
2821f82fabeSAndreas Gohr            //use placeholders
2831f82fabeSAndreas Gohr            $url = str_replace('{URL}',rawurlencode($reference),$url);
2841f82fabeSAndreas Gohr            $url = str_replace('{NAME}',$reference,$url);
2851f82fabeSAndreas Gohr            $parsed = parse_url($reference);
2861f82fabeSAndreas Gohr            if(!$parsed['port']) $parsed['port'] = 80;
2871f82fabeSAndreas Gohr            $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
2881f82fabeSAndreas Gohr            $url = str_replace('{HOST}',$parsed['host'],$url);
2891f82fabeSAndreas Gohr            $url = str_replace('{PORT}',$parsed['port'],$url);
2901f82fabeSAndreas Gohr            $url = str_replace('{PATH}',$parsed['path'],$url);
2911f82fabeSAndreas Gohr            $url = str_replace('{QUERY}',$parsed['query'],$url);
2921f82fabeSAndreas Gohr        }else{
2931f82fabeSAndreas Gohr            //default
2941f82fabeSAndreas Gohr            $url = $url.rawurlencode($reference);
2951f82fabeSAndreas Gohr        }
2961f82fabeSAndreas Gohr        if($hash) $url .= '#'.rawurlencode($hash);
2971f82fabeSAndreas Gohr
2981f82fabeSAndreas Gohr        return $url;
2991f82fabeSAndreas Gohr    }
3000cecf9d5Sandi}
3010cecf9d5Sandi
302340756e4Sandi
3039dc2c2afSandi//Setup VIM: ex: et ts=4 enc=utf-8 :
304