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.'); 9863befa1SAndreas Gohrrequire_once DOKU_INC . 'inc/plugin.php'; 1061faf446Schrisrequire_once DOKU_INC . 'inc/pluginutils.php'; 1161faf446Schris 12863befa1SAndreas Gohr/** 13863befa1SAndreas Gohr * An empty renderer, produces no output 14863befa1SAndreas Gohr * 15863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins 16863befa1SAndreas Gohr */ 17863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin { 189dc2c2afSandi var $info = array( 1944881bd0Shenning.noren 'cache' => true, // may the rendered result cached? 2044881bd0Shenning.noren 'toc' => true, // render the TOC? 219dc2c2afSandi ); 229dc2c2afSandi 230d16f6e3SMichael Hamann var $doc = ''; 240d16f6e3SMichael Hamann 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 32d968d3e5SChris Smith // allows renderer to be used again, clean out any per-use values 33d968d3e5SChris Smith function reset() { 34d968d3e5SChris Smith } 35d968d3e5SChris Smith 369dc2c2afSandi function nocache() { 3744881bd0Shenning.noren $this->info['cache'] = false; 389dc2c2afSandi } 390cecf9d5Sandi 40e41c4da9SAndreas Gohr function notoc() { 4144881bd0Shenning.noren $this->info['toc'] = false; 42e41c4da9SAndreas Gohr } 43e41c4da9SAndreas Gohr 445f70445dSAndreas Gohr /** 455f70445dSAndreas Gohr * Returns the format produced by this renderer. 465f70445dSAndreas Gohr * 475f70445dSAndreas Gohr * Has to be overidden by decendend classes 485f70445dSAndreas Gohr */ 495f70445dSAndreas Gohr function getFormat(){ 505f70445dSAndreas Gohr trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); 515f70445dSAndreas Gohr } 525f70445dSAndreas Gohr 53f6ec8df8SAdrian Lang /** 54f6ec8df8SAdrian Lang * Allow the plugin to prevent DokuWiki from reusing an instance 55f6ec8df8SAdrian Lang * 56f6ec8df8SAdrian Lang * @return bool false if the plugin has to be instantiated 57f6ec8df8SAdrian Lang */ 58f6ec8df8SAdrian Lang function isSingleton() { 59f6ec8df8SAdrian Lang return false; 60f6ec8df8SAdrian Lang } 61f6ec8df8SAdrian Lang 625f70445dSAndreas Gohr 6361faf446Schris //handle plugin rendering 6461faf446Schris function plugin($name,$data){ 65e8b5a4f9SAndreas Gohr $plugin = plugin_load('syntax',$name); 6661faf446Schris if($plugin != null){ 675f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 6861faf446Schris } 6961faf446Schris } 7061faf446Schris 715587e44cSchris /** 725587e44cSchris * handle nested render instructions 735587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 745587e44cSchris */ 755587e44cSchris function nest($instructions) { 765587e44cSchris 775587e44cSchris foreach ( $instructions as $instruction ) { 785587e44cSchris // execute the callback against ourself 79c2122b83SChristopher Smith if (method_exists($this,$instruction[0])) { 80d6a1a955SAndreas Gohr call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array()); 81c2122b83SChristopher Smith } 825587e44cSchris } 835587e44cSchris } 845587e44cSchris 855587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 865587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 875587e44cSchris // be able to - as their instructions require data. 885587e44cSchris function nest_close() {} 895587e44cSchris 900cecf9d5Sandi function document_start() {} 910cecf9d5Sandi 920cecf9d5Sandi function document_end() {} 930cecf9d5Sandi 944fced885SAndreas Gohr function render_TOC() { return ''; } 950cecf9d5Sandi 96e7856beaSchris function toc_additem($id, $text, $level) {} 97e7856beaSchris 98af587fa8Sandi function header($text, $level, $pos) {} 990cecf9d5Sandi 1000cecf9d5Sandi function section_open($level) {} 1010cecf9d5Sandi 1020cecf9d5Sandi function section_close() {} 1030cecf9d5Sandi 1040cecf9d5Sandi function cdata($text) {} 1050cecf9d5Sandi 1060cecf9d5Sandi function p_open() {} 1070cecf9d5Sandi 1080cecf9d5Sandi function p_close() {} 1090cecf9d5Sandi 1100cecf9d5Sandi function linebreak() {} 1110cecf9d5Sandi 1120cecf9d5Sandi function hr() {} 1130cecf9d5Sandi 1140cecf9d5Sandi function strong_open() {} 1150cecf9d5Sandi 1160cecf9d5Sandi function strong_close() {} 1170cecf9d5Sandi 1180cecf9d5Sandi function emphasis_open() {} 1190cecf9d5Sandi 1200cecf9d5Sandi function emphasis_close() {} 1210cecf9d5Sandi 1220cecf9d5Sandi function underline_open() {} 1230cecf9d5Sandi 1240cecf9d5Sandi function underline_close() {} 1250cecf9d5Sandi 1260cecf9d5Sandi function monospace_open() {} 1270cecf9d5Sandi 1280cecf9d5Sandi function monospace_close() {} 1290cecf9d5Sandi 1300cecf9d5Sandi function subscript_open() {} 1310cecf9d5Sandi 1320cecf9d5Sandi function subscript_close() {} 1330cecf9d5Sandi 1340cecf9d5Sandi function superscript_open() {} 1350cecf9d5Sandi 1360cecf9d5Sandi function superscript_close() {} 1370cecf9d5Sandi 1380cecf9d5Sandi function deleted_open() {} 1390cecf9d5Sandi 1400cecf9d5Sandi function deleted_close() {} 1410cecf9d5Sandi 1420cecf9d5Sandi function footnote_open() {} 1430cecf9d5Sandi 1440cecf9d5Sandi function footnote_close() {} 1450cecf9d5Sandi 1460cecf9d5Sandi function listu_open() {} 1470cecf9d5Sandi 1480cecf9d5Sandi function listu_close() {} 1490cecf9d5Sandi 1500cecf9d5Sandi function listo_open() {} 1510cecf9d5Sandi 1520cecf9d5Sandi function listo_close() {} 1530cecf9d5Sandi 1540cecf9d5Sandi function listitem_open($level) {} 1550cecf9d5Sandi 1560cecf9d5Sandi function listitem_close() {} 1570cecf9d5Sandi 158699afdebSchris function listcontent_open() {} 1590cecf9d5Sandi 1600cecf9d5Sandi function listcontent_close() {} 1610cecf9d5Sandi 1620cecf9d5Sandi function unformatted($text) {} 1630cecf9d5Sandi 1640cecf9d5Sandi function php($text) {} 1650cecf9d5Sandi 16607f89c3cSAnika Henke function phpblock($text) {} 16707f89c3cSAnika Henke 1680cecf9d5Sandi function html($text) {} 1690cecf9d5Sandi 17007f89c3cSAnika Henke function htmlblock($text) {} 17107f89c3cSAnika Henke 1720cecf9d5Sandi function preformatted($text) {} 1730cecf9d5Sandi 1740cecf9d5Sandi function quote_open() {} 1750cecf9d5Sandi 1760cecf9d5Sandi function quote_close() {} 1770cecf9d5Sandi 1783d491f75SAndreas Gohr function file($text, $lang = null, $file = null ) {} 1793d491f75SAndreas Gohr 1803d491f75SAndreas Gohr function code($text, $lang = null, $file = null ) {} 1810cecf9d5Sandi 1820cecf9d5Sandi function acronym($acronym) {} 1830cecf9d5Sandi 1840cecf9d5Sandi function smiley($smiley) {} 1850cecf9d5Sandi 1860cecf9d5Sandi function wordblock($word) {} 1870cecf9d5Sandi 1880cecf9d5Sandi function entity($entity) {} 1890cecf9d5Sandi 1900cecf9d5Sandi // 640x480 ($x=640, $y=480) 1910cecf9d5Sandi function multiplyentity($x, $y) {} 1920cecf9d5Sandi 1930cecf9d5Sandi function singlequoteopening() {} 1940cecf9d5Sandi 1950cecf9d5Sandi function singlequoteclosing() {} 1960cecf9d5Sandi 19757d757d1SAndreas Gohr function apostrophe() {} 19857d757d1SAndreas Gohr 1990cecf9d5Sandi function doublequoteopening() {} 2000cecf9d5Sandi 2010cecf9d5Sandi function doublequoteclosing() {} 2020cecf9d5Sandi 2030cecf9d5Sandi // $link like 'SomePage' 2040cecf9d5Sandi function camelcaselink($link) {} 2050cecf9d5Sandi 206a939d432SAndreas Gohr function locallink($hash, $name = NULL) {} 207a939d432SAndreas Gohr 2080e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 2090cecf9d5Sandi function internallink($link, $title = NULL) {} 2100cecf9d5Sandi 2110cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 2120cecf9d5Sandi function externallink($link, $title = NULL) {} 2130cecf9d5Sandi 214c5cfca61SAndreas Gohr function rss ($url,$params) {} 215c5cfca61SAndreas Gohr 2160cecf9d5Sandi // $link is the original link - probably not much use 2170cecf9d5Sandi // $wikiName is an indentifier for the wiki 2180cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2190cecf9d5Sandi function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 2200cecf9d5Sandi 2210cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2220cecf9d5Sandi function filelink($link, $title = NULL) {} 2230cecf9d5Sandi 2240cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2250cecf9d5Sandi function windowssharelink($link, $title = NULL) {} 2260cecf9d5Sandi 227699afdebSchris// function email($address, $title = NULL) {} 228699afdebSchris function emaillink($address, $name = NULL) {} 2290cecf9d5Sandi 230a939d432SAndreas Gohr function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 231a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 232a939d432SAndreas Gohr 233a939d432SAndreas Gohr function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 234a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 235a939d432SAndreas Gohr 2360cecf9d5Sandi function internalmedialink ( 2370cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2380cecf9d5Sandi ) {} 2390cecf9d5Sandi 2400cecf9d5Sandi function externalmedialink( 2410cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2420cecf9d5Sandi ) {} 2430cecf9d5Sandi 244619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){} 2450cecf9d5Sandi 246619736fdSAdrian Lang function table_close($pos = null){} 2470cecf9d5Sandi 2480cecf9d5Sandi function tablerow_open(){} 2490cecf9d5Sandi 2500cecf9d5Sandi function tablerow_close(){} 2510cecf9d5Sandi 25225b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} 2530cecf9d5Sandi 2540cecf9d5Sandi function tableheader_close(){} 2550cecf9d5Sandi 25625b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} 2570cecf9d5Sandi 2580cecf9d5Sandi function tablecell_close(){} 2590cecf9d5Sandi 2602ea4044fSAndreas Gohr 2612ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2622ea4044fSAndreas Gohr 2632ea4044fSAndreas Gohr 2642ea4044fSAndreas Gohr /** 2652ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2662ea4044fSAndreas Gohr * casing and special chars 2672ea4044fSAndreas Gohr * 2682ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2692ea4044fSAndreas Gohr */ 2702ea4044fSAndreas Gohr function _simpleTitle($name){ 2712ea4044fSAndreas Gohr global $conf; 2722ea4044fSAndreas Gohr 2732ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 2742ea4044fSAndreas Gohr list($name,$hash) = explode('#',$name,2); 2752ea4044fSAndreas Gohr if($hash) return $hash; 2762ea4044fSAndreas Gohr 2772ea4044fSAndreas Gohr if($conf['useslash']){ 278*3755fc25STom N Harris $name = strtr($name,';/',';:'); 279*3755fc25STom N Harris }else{ 280*3755fc25STom N Harris $name = strtr($name,';',':'); 2812ea4044fSAndreas Gohr } 2822ea4044fSAndreas Gohr 2839708106bSAdrian Lang return noNSorNS($name); 2842ea4044fSAndreas Gohr } 2852ea4044fSAndreas Gohr 2861f82fabeSAndreas Gohr /** 2871f82fabeSAndreas Gohr * Resolve an interwikilink 2881f82fabeSAndreas Gohr */ 2891f82fabeSAndreas Gohr function _resolveInterWiki(&$shortcut,$reference){ 2901f82fabeSAndreas Gohr //get interwiki URL 2911f82fabeSAndreas Gohr if ( isset($this->interwiki[$shortcut]) ) { 2921f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 2931f82fabeSAndreas Gohr } else { 2941f82fabeSAndreas Gohr // Default to Google I'm feeling lucky 2951f82fabeSAndreas Gohr $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 2961f82fabeSAndreas Gohr $shortcut = 'go'; 2971f82fabeSAndreas Gohr } 2982ea4044fSAndreas Gohr 2991f82fabeSAndreas Gohr //split into hash and url part 300ab6cf7dfSAdrian Lang list($reference,$hash) = explode('#',$reference,2); 3011f82fabeSAndreas Gohr 3021f82fabeSAndreas Gohr //replace placeholder 3031f82fabeSAndreas Gohr if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 3041f82fabeSAndreas Gohr //use placeholders 3051f82fabeSAndreas Gohr $url = str_replace('{URL}',rawurlencode($reference),$url); 3061f82fabeSAndreas Gohr $url = str_replace('{NAME}',$reference,$url); 3071f82fabeSAndreas Gohr $parsed = parse_url($reference); 3081f82fabeSAndreas Gohr if(!$parsed['port']) $parsed['port'] = 80; 3091f82fabeSAndreas Gohr $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 3101f82fabeSAndreas Gohr $url = str_replace('{HOST}',$parsed['host'],$url); 3111f82fabeSAndreas Gohr $url = str_replace('{PORT}',$parsed['port'],$url); 3121f82fabeSAndreas Gohr $url = str_replace('{PATH}',$parsed['path'],$url); 3131f82fabeSAndreas Gohr $url = str_replace('{QUERY}',$parsed['query'],$url); 3141f82fabeSAndreas Gohr }else{ 3151f82fabeSAndreas Gohr //default 3161f82fabeSAndreas Gohr $url = $url.rawurlencode($reference); 3171f82fabeSAndreas Gohr } 3181f82fabeSAndreas Gohr if($hash) $url .= '#'.rawurlencode($hash); 3191f82fabeSAndreas Gohr 3201f82fabeSAndreas Gohr return $url; 3211f82fabeSAndreas Gohr } 3220cecf9d5Sandi} 3230cecf9d5Sandi 324340756e4Sandi 325e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 326