xref: /dokuwiki/inc/parser/renderer.php (revision 5f70445d51e06ae1a3d1bf820f97238942985fde)
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
40*5f70445dSAndreas Gohr    /**
41*5f70445dSAndreas Gohr     * Returns the format produced by this renderer.
42*5f70445dSAndreas Gohr     *
43*5f70445dSAndreas Gohr     * Has to be overidden by decendend classes
44*5f70445dSAndreas Gohr     */
45*5f70445dSAndreas Gohr    function getFormat(){
46*5f70445dSAndreas Gohr        trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
47*5f70445dSAndreas Gohr    }
48*5f70445dSAndreas Gohr
49*5f70445dSAndreas Gohr
5061faf446Schris    //handle plugin rendering
5161faf446Schris    function plugin($name,$data){
5261faf446Schris        $plugin =& plugin_load('syntax',$name);
5361faf446Schris        if($plugin != null){
54*5f70445dSAndreas Gohr            $plugin->render($this->getFormat(),$this,$data);
5561faf446Schris        }
5661faf446Schris    }
5761faf446Schris
585587e44cSchris    /**
595587e44cSchris     * handle nested render instructions
605587e44cSchris     * this method (and nest_close method) should not be overloaded in actual renderer output classes
615587e44cSchris     */
625587e44cSchris    function nest($instructions) {
635587e44cSchris
645587e44cSchris      foreach ( $instructions as $instruction ) {
655587e44cSchris        // execute the callback against ourself
665587e44cSchris        call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
675587e44cSchris      }
685587e44cSchris    }
695587e44cSchris
705587e44cSchris    // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
715587e44cSchris    // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
725587e44cSchris    // be able to - as their instructions require data.
735587e44cSchris    function nest_close() {}
745587e44cSchris
750cecf9d5Sandi    function document_start() {}
760cecf9d5Sandi
770cecf9d5Sandi    function document_end() {}
780cecf9d5Sandi
794fced885SAndreas Gohr    function render_TOC() { return ''; }
800cecf9d5Sandi
81e7856beaSchris    function toc_additem($id, $text, $level) {}
82e7856beaSchris
83af587fa8Sandi    function header($text, $level, $pos) {}
840cecf9d5Sandi
8535dae8b0SBen Coburn    function section_edit($start, $end, $level, $name) {}
8635dae8b0SBen Coburn
870cecf9d5Sandi    function section_open($level) {}
880cecf9d5Sandi
890cecf9d5Sandi    function section_close() {}
900cecf9d5Sandi
910cecf9d5Sandi    function cdata($text) {}
920cecf9d5Sandi
930cecf9d5Sandi    function p_open() {}
940cecf9d5Sandi
950cecf9d5Sandi    function p_close() {}
960cecf9d5Sandi
970cecf9d5Sandi    function linebreak() {}
980cecf9d5Sandi
990cecf9d5Sandi    function hr() {}
1000cecf9d5Sandi
1010cecf9d5Sandi    function strong_open() {}
1020cecf9d5Sandi
1030cecf9d5Sandi    function strong_close() {}
1040cecf9d5Sandi
1050cecf9d5Sandi    function emphasis_open() {}
1060cecf9d5Sandi
1070cecf9d5Sandi    function emphasis_close() {}
1080cecf9d5Sandi
1090cecf9d5Sandi    function underline_open() {}
1100cecf9d5Sandi
1110cecf9d5Sandi    function underline_close() {}
1120cecf9d5Sandi
1130cecf9d5Sandi    function monospace_open() {}
1140cecf9d5Sandi
1150cecf9d5Sandi    function monospace_close() {}
1160cecf9d5Sandi
1170cecf9d5Sandi    function subscript_open() {}
1180cecf9d5Sandi
1190cecf9d5Sandi    function subscript_close() {}
1200cecf9d5Sandi
1210cecf9d5Sandi    function superscript_open() {}
1220cecf9d5Sandi
1230cecf9d5Sandi    function superscript_close() {}
1240cecf9d5Sandi
1250cecf9d5Sandi    function deleted_open() {}
1260cecf9d5Sandi
1270cecf9d5Sandi    function deleted_close() {}
1280cecf9d5Sandi
1290cecf9d5Sandi    function footnote_open() {}
1300cecf9d5Sandi
1310cecf9d5Sandi    function footnote_close() {}
1320cecf9d5Sandi
1330cecf9d5Sandi    function listu_open() {}
1340cecf9d5Sandi
1350cecf9d5Sandi    function listu_close() {}
1360cecf9d5Sandi
1370cecf9d5Sandi    function listo_open() {}
1380cecf9d5Sandi
1390cecf9d5Sandi    function listo_close() {}
1400cecf9d5Sandi
1410cecf9d5Sandi    function listitem_open($level) {}
1420cecf9d5Sandi
1430cecf9d5Sandi    function listitem_close() {}
1440cecf9d5Sandi
145699afdebSchris    function listcontent_open() {}
1460cecf9d5Sandi
1470cecf9d5Sandi    function listcontent_close() {}
1480cecf9d5Sandi
1490cecf9d5Sandi    function unformatted($text) {}
1500cecf9d5Sandi
1510cecf9d5Sandi    function php($text) {}
1520cecf9d5Sandi
1530cecf9d5Sandi    function html($text) {}
1540cecf9d5Sandi
1550cecf9d5Sandi    function preformatted($text) {}
1560cecf9d5Sandi
1570cecf9d5Sandi    function file($text) {}
1580cecf9d5Sandi
1590cecf9d5Sandi    function quote_open() {}
1600cecf9d5Sandi
1610cecf9d5Sandi    function quote_close() {}
1620cecf9d5Sandi
1630cecf9d5Sandi    function code($text, $lang = NULL) {}
1640cecf9d5Sandi
1650cecf9d5Sandi    function acronym($acronym) {}
1660cecf9d5Sandi
1670cecf9d5Sandi    function smiley($smiley) {}
1680cecf9d5Sandi
1690cecf9d5Sandi    function wordblock($word) {}
1700cecf9d5Sandi
1710cecf9d5Sandi    function entity($entity) {}
1720cecf9d5Sandi
1730cecf9d5Sandi    // 640x480 ($x=640, $y=480)
1740cecf9d5Sandi    function multiplyentity($x, $y) {}
1750cecf9d5Sandi
1760cecf9d5Sandi    function singlequoteopening() {}
1770cecf9d5Sandi
1780cecf9d5Sandi    function singlequoteclosing() {}
1790cecf9d5Sandi
1800cecf9d5Sandi    function doublequoteopening() {}
1810cecf9d5Sandi
1820cecf9d5Sandi    function doublequoteclosing() {}
1830cecf9d5Sandi
1840cecf9d5Sandi    // $link like 'SomePage'
1850cecf9d5Sandi    function camelcaselink($link) {}
1860cecf9d5Sandi
187a939d432SAndreas Gohr    function locallink($hash, $name = NULL) {}
188a939d432SAndreas Gohr
1890e1c636eSandi    // $link like 'wiki:syntax', $title could be an array (media)
1900cecf9d5Sandi    function internallink($link, $title = NULL) {}
1910cecf9d5Sandi
1920cecf9d5Sandi    // $link is full URL with scheme, $title could be an array (media)
1930cecf9d5Sandi    function externallink($link, $title = NULL) {}
1940cecf9d5Sandi
1950cecf9d5Sandi    // $link is the original link - probably not much use
1960cecf9d5Sandi    // $wikiName is an indentifier for the wiki
1970cecf9d5Sandi    // $wikiUri is the URL fragment to append to some known URL
1980cecf9d5Sandi    function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
1990cecf9d5Sandi
2000cecf9d5Sandi    // Link to file on users OS, $title could be an array (media)
2010cecf9d5Sandi    function filelink($link, $title = NULL) {}
2020cecf9d5Sandi
2030cecf9d5Sandi    // Link to a Windows share, , $title could be an array (media)
2040cecf9d5Sandi    function windowssharelink($link, $title = NULL) {}
2050cecf9d5Sandi
206699afdebSchris//  function email($address, $title = NULL) {}
207699afdebSchris    function emaillink($address, $name = NULL) {}
2080cecf9d5Sandi
209a939d432SAndreas Gohr    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
210a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
211a939d432SAndreas Gohr
212a939d432SAndreas Gohr    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
213a939d432SAndreas Gohr                            $height=NULL, $cache=NULL, $linking=NULL) {}
214a939d432SAndreas Gohr
2150cecf9d5Sandi    function internalmedialink (
2160cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2170cecf9d5Sandi        ) {}
2180cecf9d5Sandi
2190cecf9d5Sandi    function externalmedialink(
2200cecf9d5Sandi        $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
2210cecf9d5Sandi        ) {}
2220cecf9d5Sandi
2230cecf9d5Sandi    function table_open($maxcols = NULL, $numrows = NULL){}
2240cecf9d5Sandi
2250cecf9d5Sandi    function table_close(){}
2260cecf9d5Sandi
2270cecf9d5Sandi    function tablerow_open(){}
2280cecf9d5Sandi
2290cecf9d5Sandi    function tablerow_close(){}
2300cecf9d5Sandi
2310cecf9d5Sandi    function tableheader_open($colspan = 1, $align = NULL){}
2320cecf9d5Sandi
2330cecf9d5Sandi    function tableheader_close(){}
2340cecf9d5Sandi
2350cecf9d5Sandi    function tablecell_open($colspan = 1, $align = NULL){}
2360cecf9d5Sandi
2370cecf9d5Sandi    function tablecell_close(){}
2380cecf9d5Sandi
2392ea4044fSAndreas Gohr
2402ea4044fSAndreas Gohr    // util functions follow, you probably won't need to reimplement them
2412ea4044fSAndreas Gohr
2422ea4044fSAndreas Gohr
2432ea4044fSAndreas Gohr    /**
2442ea4044fSAndreas Gohr     * Removes any Namespace from the given name but keeps
2452ea4044fSAndreas Gohr     * casing and special chars
2462ea4044fSAndreas Gohr     *
2472ea4044fSAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
2482ea4044fSAndreas Gohr     */
2492ea4044fSAndreas Gohr    function _simpleTitle($name){
2502ea4044fSAndreas Gohr        global $conf;
2512ea4044fSAndreas Gohr
2522ea4044fSAndreas Gohr        //if there is a hash we use the ancor name only
2532ea4044fSAndreas Gohr        list($name,$hash) = explode('#',$name,2);
2542ea4044fSAndreas Gohr        if($hash) return $hash;
2552ea4044fSAndreas Gohr
2561179df0eSGuy Brand        //trim colons or slash of a namespace link
2572ea4044fSAndreas Gohr        $name = rtrim($name,':');
2581179df0eSGuy Brand        if($conf['useslash'])
2591179df0eSGuy Brand          $name = rtrim($name,'/');
2602ea4044fSAndreas Gohr
2612ea4044fSAndreas Gohr        if($conf['useslash']){
2622ea4044fSAndreas Gohr            $nssep = '[:;/]';
2632ea4044fSAndreas Gohr        }else{
2642ea4044fSAndreas Gohr            $nssep = '[:;]';
2652ea4044fSAndreas Gohr        }
2662ea4044fSAndreas Gohr        $name = preg_replace('!.*'.$nssep.'!','',$name);
2672ea4044fSAndreas Gohr
2682ea4044fSAndreas Gohr        if(!$name) return $this->_simpleTitle($conf['start']);
2692ea4044fSAndreas Gohr        return $name;
2702ea4044fSAndreas Gohr    }
2712ea4044fSAndreas Gohr
2721f82fabeSAndreas Gohr    /**
2731f82fabeSAndreas Gohr     * Resolve an interwikilink
2741f82fabeSAndreas Gohr     */
2751f82fabeSAndreas Gohr    function _resolveInterWiki(&$shortcut,$reference){
2761f82fabeSAndreas Gohr        //get interwiki URL
2771f82fabeSAndreas Gohr        if ( isset($this->interwiki[$shortcut]) ) {
2781f82fabeSAndreas Gohr            $url = $this->interwiki[$shortcut];
2791f82fabeSAndreas Gohr        } else {
2801f82fabeSAndreas Gohr            // Default to Google I'm feeling lucky
2811f82fabeSAndreas Gohr            $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
2821f82fabeSAndreas Gohr            $shortcut = 'go';
2831f82fabeSAndreas Gohr        }
2842ea4044fSAndreas Gohr
2851f82fabeSAndreas Gohr        //split into hash and url part
2861f82fabeSAndreas Gohr        list($wikiUri,$hash) = explode('#',$wikiUri,2);
2871f82fabeSAndreas Gohr
2881f82fabeSAndreas Gohr        //replace placeholder
2891f82fabeSAndreas Gohr        if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
2901f82fabeSAndreas Gohr            //use placeholders
2911f82fabeSAndreas Gohr            $url = str_replace('{URL}',rawurlencode($reference),$url);
2921f82fabeSAndreas Gohr            $url = str_replace('{NAME}',$reference,$url);
2931f82fabeSAndreas Gohr            $parsed = parse_url($reference);
2941f82fabeSAndreas Gohr            if(!$parsed['port']) $parsed['port'] = 80;
2951f82fabeSAndreas Gohr            $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
2961f82fabeSAndreas Gohr            $url = str_replace('{HOST}',$parsed['host'],$url);
2971f82fabeSAndreas Gohr            $url = str_replace('{PORT}',$parsed['port'],$url);
2981f82fabeSAndreas Gohr            $url = str_replace('{PATH}',$parsed['path'],$url);
2991f82fabeSAndreas Gohr            $url = str_replace('{QUERY}',$parsed['query'],$url);
3001f82fabeSAndreas Gohr        }else{
3011f82fabeSAndreas Gohr            //default
3021f82fabeSAndreas Gohr            $url = $url.rawurlencode($reference);
3031f82fabeSAndreas Gohr        }
3041f82fabeSAndreas Gohr        if($hash) $url .= '#'.rawurlencode($hash);
3051f82fabeSAndreas Gohr
3061f82fabeSAndreas Gohr        return $url;
3071f82fabeSAndreas Gohr    }
3080cecf9d5Sandi}
3090cecf9d5Sandi
310340756e4Sandi
3119dc2c2afSandi//Setup VIM: ex: et ts=4 enc=utf-8 :
312