xref: /dokuwiki/inc/parser/renderer.php (revision f6ec8df813b28547ca3b04bb39f0ce670a6bb990)
10cecf9d5Sandi<?php
261faf446Schris/**
35587e44cSchris * Renderer output base class
461faf446Schris *
561faf446Schris * @author Harry Fuecks <hfuecks@gmail.com>
661faf446Schris * @author Andreas Gohr <andi@splitbrain.org>
761faf446Schris */
8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
961faf446Schrisrequire_once DOKU_INC . 'inc/parser/renderer.php';
10863befa1SAndreas Gohrrequire_once DOKU_INC . 'inc/plugin.php';
1161faf446Schrisrequire_once DOKU_INC . 'inc/pluginutils.php';
1261faf446Schris
13863befa1SAndreas Gohr/**
14863befa1SAndreas Gohr * An empty renderer, produces no output
15863befa1SAndreas Gohr *
16863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
17863befa1SAndreas Gohr */
18863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin {
199dc2c2afSandi    var $info = array(
2044881bd0Shenning.noren        'cache' => true, // may the rendered result cached?
2144881bd0Shenning.noren        'toc'   => true, // render the TOC?
229dc2c2afSandi    );
239dc2c2afSandi
241f82fabeSAndreas Gohr    // keep some config options
251f82fabeSAndreas Gohr    var $acronyms = array();
261f82fabeSAndreas Gohr    var $smileys = array();
271f82fabeSAndreas Gohr    var $badwords = array();
281f82fabeSAndreas Gohr    var $entities = array();
291f82fabeSAndreas Gohr    var $interwiki = array();
309dc2c2afSandi
31d968d3e5SChris Smith    // allows renderer to be used again, clean out any per-use values
32d968d3e5SChris Smith    function reset() {
33d968d3e5SChris Smith    }
34d968d3e5SChris Smith
359dc2c2afSandi    function nocache() {
3644881bd0Shenning.noren        $this->info['cache'] = false;
379dc2c2afSandi    }
380cecf9d5Sandi
39e41c4da9SAndreas Gohr    function notoc() {
4044881bd0Shenning.noren        $this->info['toc'] = false;
41e41c4da9SAndreas Gohr    }
42e41c4da9SAndreas Gohr
435f70445dSAndreas Gohr    /**
445f70445dSAndreas Gohr     * Returns the format produced by this renderer.
455f70445dSAndreas Gohr     *
465f70445dSAndreas Gohr     * Has to be overidden by decendend classes
475f70445dSAndreas Gohr     */
485f70445dSAndreas Gohr    function getFormat(){
495f70445dSAndreas Gohr        trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
505f70445dSAndreas Gohr    }
515f70445dSAndreas Gohr
52*f6ec8df8SAdrian Lang    /**
53*f6ec8df8SAdrian Lang     * Allow the plugin to prevent DokuWiki from reusing an instance
54*f6ec8df8SAdrian Lang     *
55*f6ec8df8SAdrian Lang     * @return bool   false if the plugin has to be instantiated
56*f6ec8df8SAdrian Lang     */
57*f6ec8df8SAdrian Lang    function isSingleton() {
58*f6ec8df8SAdrian Lang        return false;
59*f6ec8df8SAdrian Lang    }
60*f6ec8df8SAdrian Lang
615f70445dSAndreas Gohr
6261faf446Schris    //handle plugin rendering
6361faf446Schris    function plugin($name,$data){
6461faf446Schris        $plugin =& plugin_load('syntax',$name);
6561faf446Schris        if($plugin != null){
665f70445dSAndreas Gohr            $plugin->render($this->getFormat(),$this,$data);
6761faf446Schris        }
6861faf446Schris    }
6961faf446Schris
705587e44cSchris    /**
715587e44cSchris     * handle nested render instructions
725587e44cSchris     * this method (and nest_close method) should not be overloaded in actual renderer output classes
735587e44cSchris     */
745587e44cSchris    function nest($instructions) {
755587e44cSchris
765587e44cSchris      foreach ( $instructions as $instruction ) {
775587e44cSchris        // execute the callback against ourself
785587e44cSchris        call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
795587e44cSchris      }
805587e44cSchris    }
815587e44cSchris
825587e44cSchris    // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
835587e44cSchris    // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
845587e44cSchris    // be able to - as their instructions require data.
855587e44cSchris    function nest_close() {}
865587e44cSchris
870cecf9d5Sandi    function document_start() {}
880cecf9d5Sandi
890cecf9d5Sandi    function document_end() {}
900cecf9d5Sandi
914fced885SAndreas Gohr    function render_TOC() { return ''; }
920cecf9d5Sandi
93e7856beaSchris    function toc_additem($id, $text, $level) {}
94e7856beaSchris
95af587fa8Sandi    function header($text, $level, $pos) {}
960cecf9d5Sandi
970cecf9d5Sandi    function section_open($level) {}
980cecf9d5Sandi
990cecf9d5Sandi    function section_close() {}
1000cecf9d5Sandi
1010cecf9d5Sandi    function cdata($text) {}
1020cecf9d5Sandi
1030cecf9d5Sandi    function p_open() {}
1040cecf9d5Sandi
1050cecf9d5Sandi    function p_close() {}
1060cecf9d5Sandi
1070cecf9d5Sandi    function linebreak() {}
1080cecf9d5Sandi
1090cecf9d5Sandi    function hr() {}
1100cecf9d5Sandi
1110cecf9d5Sandi    function strong_open() {}
1120cecf9d5Sandi
1130cecf9d5Sandi    function strong_close() {}
1140cecf9d5Sandi
1150cecf9d5Sandi    function emphasis_open() {}
1160cecf9d5Sandi
1170cecf9d5Sandi    function emphasis_close() {}
1180cecf9d5Sandi
1190cecf9d5Sandi    function underline_open() {}
1200cecf9d5Sandi
1210cecf9d5Sandi    function underline_close() {}
1220cecf9d5Sandi
1230cecf9d5Sandi    function monospace_open() {}
1240cecf9d5Sandi
1250cecf9d5Sandi    function monospace_close() {}
1260cecf9d5Sandi
1270cecf9d5Sandi    function subscript_open() {}
1280cecf9d5Sandi
1290cecf9d5Sandi    function subscript_close() {}
1300cecf9d5Sandi
1310cecf9d5Sandi    function superscript_open() {}
1320cecf9d5Sandi
1330cecf9d5Sandi    function superscript_close() {}
1340cecf9d5Sandi
1350cecf9d5Sandi    function deleted_open() {}
1360cecf9d5Sandi
1370cecf9d5Sandi    function deleted_close() {}
1380cecf9d5Sandi
1390cecf9d5Sandi    function footnote_open() {}
1400cecf9d5Sandi
1410cecf9d5Sandi    function footnote_close() {}
1420cecf9d5Sandi
1430cecf9d5Sandi    function listu_open() {}
1440cecf9d5Sandi
1450cecf9d5Sandi    function listu_close() {}
1460cecf9d5Sandi
1470cecf9d5Sandi    function listo_open() {}
1480cecf9d5Sandi
1490cecf9d5Sandi    function listo_close() {}
1500cecf9d5Sandi
1510cecf9d5Sandi    function listitem_open($level) {}
1520cecf9d5Sandi
1530cecf9d5Sandi    function listitem_close() {}
1540cecf9d5Sandi
155699afdebSchris    function listcontent_open() {}
1560cecf9d5Sandi
1570cecf9d5Sandi    function listcontent_close() {}
1580cecf9d5Sandi
1590cecf9d5Sandi    function unformatted($text) {}
1600cecf9d5Sandi
1610cecf9d5Sandi    function php($text) {}
1620cecf9d5Sandi
16307f89c3cSAnika Henke    function phpblock($text) {}
16407f89c3cSAnika Henke
1650cecf9d5Sandi    function html($text) {}
1660cecf9d5Sandi
16707f89c3cSAnika Henke    function htmlblock($text) {}
16807f89c3cSAnika Henke
1690cecf9d5Sandi    function preformatted($text) {}
1700cecf9d5Sandi
1710cecf9d5Sandi    function quote_open() {}
1720cecf9d5Sandi
1730cecf9d5Sandi    function quote_close() {}
1740cecf9d5Sandi
1753d491f75SAndreas Gohr    function file($text, $lang = null, $file = null ) {}
1763d491f75SAndreas Gohr
1773d491f75SAndreas Gohr    function code($text, $lang = null, $file = null ) {}
1780cecf9d5Sandi
1790cecf9d5Sandi    function acronym($acronym) {}
1800cecf9d5Sandi
1810cecf9d5Sandi    function smiley($smiley) {}
1820cecf9d5Sandi
1830cecf9d5Sandi    function wordblock($word) {}
1840cecf9d5Sandi
1850cecf9d5Sandi    function entity($entity) {}
1860cecf9d5Sandi
1870cecf9d5Sandi    // 640x480 ($x=640, $y=480)
1880cecf9d5Sandi    function multiplyentity($x, $y) {}
1890cecf9d5Sandi
1900cecf9d5Sandi    function singlequoteopening() {}
1910cecf9d5Sandi
1920cecf9d5Sandi    function singlequoteclosing() {}
1930cecf9d5Sandi
19457d757d1SAndreas Gohr    function apostrophe() {}
19557d757d1SAndreas Gohr
1960cecf9d5Sandi    function doublequoteopening() {}
1970cecf9d5Sandi
1980cecf9d5Sandi    function doublequoteclosing() {}
1990cecf9d5Sandi
2000cecf9d5Sandi    // $link like 'SomePage'
2010cecf9d5Sandi    function camelcaselink($link) {}
2020cecf9d5Sandi
203a939d432SAndreas Gohr    function locallink($hash, $name = NULL) {}
204a939d432SAndreas Gohr
2050e1c636eSandi    // $link like 'wiki:syntax', $title could be an array (media)
2060cecf9d5Sandi    function internallink($link, $title = NULL) {}
2070cecf9d5Sandi
2080cecf9d5Sandi    // $link is full URL with scheme, $title could be an array (media)
2090cecf9d5Sandi    function externallink($link, $title = NULL) {}
2100cecf9d5Sandi
211c5cfca61SAndreas Gohr    function rss ($url,$params) {}
212c5cfca61SAndreas Gohr
2130cecf9d5Sandi    // $link is the original link - probably not much use
2140cecf9d5Sandi    // $wikiName is an indentifier for the wiki
2150cecf9d5Sandi    // $wikiUri is the URL fragment to append to some known URL
2160cecf9d5Sandi    function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
2170cecf9d5Sandi
2180cecf9d5Sandi    // Link to file on users OS, $title could be an array (media)
2190cecf9d5Sandi    function filelink($link, $title = NULL) {}
2200cecf9d5Sandi
2210cecf9d5Sandi    // Link to a Windows share, , $title could be an array (media)
2220cecf9d5Sandi    function windowssharelink($link, $title = NULL) {}
2230cecf9d5Sandi
224699afdebSchris//  function email($address, $title = NULL) {}
225699afdebSchris    function emaillink($address, $name = NULL) {}
2260cecf9d5Sandi
227a939d432SAndreas Gohr    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
228a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
229a939d432SAndreas Gohr
230a939d432SAndreas Gohr    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
231a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
232a939d432SAndreas Gohr
2330cecf9d5Sandi    function internalmedialink (
2340cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2350cecf9d5Sandi        ) {}
2360cecf9d5Sandi
2370cecf9d5Sandi    function externalmedialink(
2380cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2390cecf9d5Sandi        ) {}
2400cecf9d5Sandi
24190df9a4dSAdrian Lang    function table_open($maxcols = NULL, $numrows = NULL, $pos){}
2420cecf9d5Sandi
24390df9a4dSAdrian Lang    function table_close($pos){}
2440cecf9d5Sandi
2450cecf9d5Sandi    function tablerow_open(){}
2460cecf9d5Sandi
2470cecf9d5Sandi    function tablerow_close(){}
2480cecf9d5Sandi
24925b97867Shakan.sandell    function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){}
2500cecf9d5Sandi
2510cecf9d5Sandi    function tableheader_close(){}
2520cecf9d5Sandi
25325b97867Shakan.sandell    function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){}
2540cecf9d5Sandi
2550cecf9d5Sandi    function tablecell_close(){}
2560cecf9d5Sandi
2572ea4044fSAndreas Gohr
2582ea4044fSAndreas Gohr    // util functions follow, you probably won't need to reimplement them
2592ea4044fSAndreas Gohr
2602ea4044fSAndreas Gohr
2612ea4044fSAndreas Gohr    /**
2622ea4044fSAndreas Gohr     * Removes any Namespace from the given name but keeps
2632ea4044fSAndreas Gohr     * casing and special chars
2642ea4044fSAndreas Gohr     *
2652ea4044fSAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
2662ea4044fSAndreas Gohr     */
2672ea4044fSAndreas Gohr    function _simpleTitle($name){
2682ea4044fSAndreas Gohr        global $conf;
2692ea4044fSAndreas Gohr
2702ea4044fSAndreas Gohr        //if there is a hash we use the ancor name only
2712ea4044fSAndreas Gohr        list($name,$hash) = explode('#',$name,2);
2722ea4044fSAndreas Gohr        if($hash) return $hash;
2732ea4044fSAndreas Gohr
2741179df0eSGuy Brand        //trim colons or slash of a namespace link
2752ea4044fSAndreas Gohr        $name = rtrim($name,':');
2761179df0eSGuy Brand        if($conf['useslash'])
2771179df0eSGuy Brand          $name = rtrim($name,'/');
2782ea4044fSAndreas Gohr
2792ea4044fSAndreas Gohr        if($conf['useslash']){
2802ea4044fSAndreas Gohr            $nssep = '[:;/]';
2812ea4044fSAndreas Gohr        }else{
2822ea4044fSAndreas Gohr            $nssep = '[:;]';
2832ea4044fSAndreas Gohr        }
2842ea4044fSAndreas Gohr        $name = preg_replace('!.*'.$nssep.'!','',$name);
2852ea4044fSAndreas Gohr
2862ea4044fSAndreas Gohr        if(!$name) return $this->_simpleTitle($conf['start']);
2872ea4044fSAndreas Gohr        return $name;
2882ea4044fSAndreas Gohr    }
2892ea4044fSAndreas Gohr
2901f82fabeSAndreas Gohr    /**
2911f82fabeSAndreas Gohr     * Resolve an interwikilink
2921f82fabeSAndreas Gohr     */
2931f82fabeSAndreas Gohr    function _resolveInterWiki(&$shortcut,$reference){
2941f82fabeSAndreas Gohr        //get interwiki URL
2951f82fabeSAndreas Gohr        if ( isset($this->interwiki[$shortcut]) ) {
2961f82fabeSAndreas Gohr            $url = $this->interwiki[$shortcut];
2971f82fabeSAndreas Gohr        } else {
2981f82fabeSAndreas Gohr            // Default to Google I'm feeling lucky
2991f82fabeSAndreas Gohr            $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
3001f82fabeSAndreas Gohr            $shortcut = 'go';
3011f82fabeSAndreas Gohr        }
3022ea4044fSAndreas Gohr
3031f82fabeSAndreas Gohr        //split into hash and url part
304ab6cf7dfSAdrian Lang        list($reference,$hash) = explode('#',$reference,2);
3051f82fabeSAndreas Gohr
3061f82fabeSAndreas Gohr        //replace placeholder
3071f82fabeSAndreas Gohr        if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
3081f82fabeSAndreas Gohr            //use placeholders
3091f82fabeSAndreas Gohr            $url = str_replace('{URL}',rawurlencode($reference),$url);
3101f82fabeSAndreas Gohr            $url = str_replace('{NAME}',$reference,$url);
3111f82fabeSAndreas Gohr            $parsed = parse_url($reference);
3121f82fabeSAndreas Gohr            if(!$parsed['port']) $parsed['port'] = 80;
3131f82fabeSAndreas Gohr            $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
3141f82fabeSAndreas Gohr            $url = str_replace('{HOST}',$parsed['host'],$url);
3151f82fabeSAndreas Gohr            $url = str_replace('{PORT}',$parsed['port'],$url);
3161f82fabeSAndreas Gohr            $url = str_replace('{PATH}',$parsed['path'],$url);
3171f82fabeSAndreas Gohr            $url = str_replace('{QUERY}',$parsed['query'],$url);
3181f82fabeSAndreas Gohr        }else{
3191f82fabeSAndreas Gohr            //default
3201f82fabeSAndreas Gohr            $url = $url.rawurlencode($reference);
3211f82fabeSAndreas Gohr        }
3221f82fabeSAndreas Gohr        if($hash) $url .= '#'.rawurlencode($hash);
3231f82fabeSAndreas Gohr
3241f82fabeSAndreas Gohr        return $url;
3251f82fabeSAndreas Gohr    }
3260cecf9d5Sandi}
3270cecf9d5Sandi
328340756e4Sandi
3299dc2c2afSandi//Setup VIM: ex: et ts=4 enc=utf-8 :
330