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.'); 961faf446Schris 10863befa1SAndreas Gohr/** 11863befa1SAndreas Gohr * An empty renderer, produces no output 12863befa1SAndreas Gohr * 13863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins 14863befa1SAndreas Gohr */ 15863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin { 169dc2c2afSandi var $info = array( 1744881bd0Shenning.noren 'cache' => true, // may the rendered result cached? 1844881bd0Shenning.noren 'toc' => true, // render the TOC? 199dc2c2afSandi ); 209dc2c2afSandi 210d16f6e3SMichael Hamann var $doc = ''; 220d16f6e3SMichael Hamann 231f82fabeSAndreas Gohr // keep some config options 241f82fabeSAndreas Gohr var $acronyms = array(); 251f82fabeSAndreas Gohr var $smileys = array(); 261f82fabeSAndreas Gohr var $badwords = array(); 271f82fabeSAndreas Gohr var $entities = array(); 281f82fabeSAndreas Gohr var $interwiki = array(); 299dc2c2afSandi 30d968d3e5SChris Smith // allows renderer to be used again, clean out any per-use values 31d968d3e5SChris Smith function reset() { 32d968d3e5SChris Smith } 33d968d3e5SChris Smith 349dc2c2afSandi function nocache() { 3544881bd0Shenning.noren $this->info['cache'] = false; 369dc2c2afSandi } 370cecf9d5Sandi 38e41c4da9SAndreas Gohr function notoc() { 3944881bd0Shenning.noren $this->info['toc'] = false; 40e41c4da9SAndreas Gohr } 41e41c4da9SAndreas Gohr 425f70445dSAndreas Gohr /** 435f70445dSAndreas Gohr * Returns the format produced by this renderer. 445f70445dSAndreas Gohr * 455f70445dSAndreas Gohr * Has to be overidden by decendend classes 465f70445dSAndreas Gohr */ 475f70445dSAndreas Gohr function getFormat(){ 485f70445dSAndreas Gohr trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); 495f70445dSAndreas Gohr } 505f70445dSAndreas Gohr 51f6ec8df8SAdrian Lang /** 52f6ec8df8SAdrian Lang * Allow the plugin to prevent DokuWiki from reusing an instance 53f6ec8df8SAdrian Lang * 54f6ec8df8SAdrian Lang * @return bool false if the plugin has to be instantiated 55f6ec8df8SAdrian Lang */ 56f6ec8df8SAdrian Lang function isSingleton() { 57f6ec8df8SAdrian Lang return false; 58f6ec8df8SAdrian Lang } 59f6ec8df8SAdrian Lang 608cc41db0SAndreas Gohr /** 618cc41db0SAndreas Gohr * handle plugin rendering 628cc41db0SAndreas Gohr * 638cc41db0SAndreas Gohr * @param string $name Plugin name 648cc41db0SAndreas Gohr * @param mixed $data custom data set by handler 658cc41db0SAndreas Gohr * @param string $state matched state if any 668cc41db0SAndreas Gohr * @param string $match raw matched syntax 678cc41db0SAndreas Gohr */ 688cc41db0SAndreas Gohr function plugin($name,$data,$state='',$match=''){ 69e8b5a4f9SAndreas Gohr $plugin = plugin_load('syntax',$name); 7061faf446Schris if($plugin != null){ 715f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 7261faf446Schris } 7361faf446Schris } 7461faf446Schris 755587e44cSchris /** 765587e44cSchris * handle nested render instructions 775587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 785587e44cSchris */ 795587e44cSchris function nest($instructions) { 805587e44cSchris 815587e44cSchris foreach ( $instructions as $instruction ) { 825587e44cSchris // execute the callback against ourself 83c2122b83SChristopher Smith if (method_exists($this,$instruction[0])) { 84d6a1a955SAndreas Gohr call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array()); 85c2122b83SChristopher Smith } 865587e44cSchris } 875587e44cSchris } 885587e44cSchris 895587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 905587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 915587e44cSchris // be able to - as their instructions require data. 925587e44cSchris function nest_close() {} 935587e44cSchris 940cecf9d5Sandi function document_start() {} 950cecf9d5Sandi 960cecf9d5Sandi function document_end() {} 970cecf9d5Sandi 984fced885SAndreas Gohr function render_TOC() { return ''; } 990cecf9d5Sandi 100e7856beaSchris function toc_additem($id, $text, $level) {} 101e7856beaSchris 102af587fa8Sandi function header($text, $level, $pos) {} 1030cecf9d5Sandi 1040cecf9d5Sandi function section_open($level) {} 1050cecf9d5Sandi 1060cecf9d5Sandi function section_close() {} 1070cecf9d5Sandi 1080cecf9d5Sandi function cdata($text) {} 1090cecf9d5Sandi 1100cecf9d5Sandi function p_open() {} 1110cecf9d5Sandi 1120cecf9d5Sandi function p_close() {} 1130cecf9d5Sandi 1140cecf9d5Sandi function linebreak() {} 1150cecf9d5Sandi 1160cecf9d5Sandi function hr() {} 1170cecf9d5Sandi 1180cecf9d5Sandi function strong_open() {} 1190cecf9d5Sandi 1200cecf9d5Sandi function strong_close() {} 1210cecf9d5Sandi 1220cecf9d5Sandi function emphasis_open() {} 1230cecf9d5Sandi 1240cecf9d5Sandi function emphasis_close() {} 1250cecf9d5Sandi 1260cecf9d5Sandi function underline_open() {} 1270cecf9d5Sandi 1280cecf9d5Sandi function underline_close() {} 1290cecf9d5Sandi 1300cecf9d5Sandi function monospace_open() {} 1310cecf9d5Sandi 1320cecf9d5Sandi function monospace_close() {} 1330cecf9d5Sandi 1340cecf9d5Sandi function subscript_open() {} 1350cecf9d5Sandi 1360cecf9d5Sandi function subscript_close() {} 1370cecf9d5Sandi 1380cecf9d5Sandi function superscript_open() {} 1390cecf9d5Sandi 1400cecf9d5Sandi function superscript_close() {} 1410cecf9d5Sandi 1420cecf9d5Sandi function deleted_open() {} 1430cecf9d5Sandi 1440cecf9d5Sandi function deleted_close() {} 1450cecf9d5Sandi 1460cecf9d5Sandi function footnote_open() {} 1470cecf9d5Sandi 1480cecf9d5Sandi function footnote_close() {} 1490cecf9d5Sandi 1500cecf9d5Sandi function listu_open() {} 1510cecf9d5Sandi 1520cecf9d5Sandi function listu_close() {} 1530cecf9d5Sandi 1540cecf9d5Sandi function listo_open() {} 1550cecf9d5Sandi 1560cecf9d5Sandi function listo_close() {} 1570cecf9d5Sandi 1580cecf9d5Sandi function listitem_open($level) {} 1590cecf9d5Sandi 1600cecf9d5Sandi function listitem_close() {} 1610cecf9d5Sandi 162699afdebSchris function listcontent_open() {} 1630cecf9d5Sandi 1640cecf9d5Sandi function listcontent_close() {} 1650cecf9d5Sandi 1660cecf9d5Sandi function unformatted($text) {} 1670cecf9d5Sandi 1680cecf9d5Sandi function php($text) {} 1690cecf9d5Sandi 17007f89c3cSAnika Henke function phpblock($text) {} 17107f89c3cSAnika Henke 1720cecf9d5Sandi function html($text) {} 1730cecf9d5Sandi 17407f89c3cSAnika Henke function htmlblock($text) {} 17507f89c3cSAnika Henke 1760cecf9d5Sandi function preformatted($text) {} 1770cecf9d5Sandi 1780cecf9d5Sandi function quote_open() {} 1790cecf9d5Sandi 1800cecf9d5Sandi function quote_close() {} 1810cecf9d5Sandi 1823d491f75SAndreas Gohr function file($text, $lang = null, $file = null ) {} 1833d491f75SAndreas Gohr 1843d491f75SAndreas Gohr function code($text, $lang = null, $file = null ) {} 1850cecf9d5Sandi 1860cecf9d5Sandi function acronym($acronym) {} 1870cecf9d5Sandi 1880cecf9d5Sandi function smiley($smiley) {} 1890cecf9d5Sandi 1900cecf9d5Sandi function wordblock($word) {} 1910cecf9d5Sandi 1920cecf9d5Sandi function entity($entity) {} 1930cecf9d5Sandi 1940cecf9d5Sandi // 640x480 ($x=640, $y=480) 1950cecf9d5Sandi function multiplyentity($x, $y) {} 1960cecf9d5Sandi 1970cecf9d5Sandi function singlequoteopening() {} 1980cecf9d5Sandi 1990cecf9d5Sandi function singlequoteclosing() {} 2000cecf9d5Sandi 20157d757d1SAndreas Gohr function apostrophe() {} 20257d757d1SAndreas Gohr 2030cecf9d5Sandi function doublequoteopening() {} 2040cecf9d5Sandi 2050cecf9d5Sandi function doublequoteclosing() {} 2060cecf9d5Sandi 2070cecf9d5Sandi // $link like 'SomePage' 2080cecf9d5Sandi function camelcaselink($link) {} 2090cecf9d5Sandi 2100ea51e63SMatt Perry function locallink($hash, $name = null) {} 211a939d432SAndreas Gohr 2120e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 2130ea51e63SMatt Perry function internallink($link, $title = null) {} 2140cecf9d5Sandi 2150cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 2160ea51e63SMatt Perry function externallink($link, $title = null) {} 2170cecf9d5Sandi 218c5cfca61SAndreas Gohr function rss ($url,$params) {} 219c5cfca61SAndreas Gohr 2200cecf9d5Sandi // $link is the original link - probably not much use 2210cecf9d5Sandi // $wikiName is an indentifier for the wiki 2220cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2230ea51e63SMatt Perry function interwikilink($link, $title = null, $wikiName, $wikiUri) {} 2240cecf9d5Sandi 2250cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2260ea51e63SMatt Perry function filelink($link, $title = null) {} 2270cecf9d5Sandi 2280cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2290ea51e63SMatt Perry function windowssharelink($link, $title = null) {} 2300cecf9d5Sandi 2310ea51e63SMatt Perry// function email($address, $title = null) {} 2320ea51e63SMatt Perry function emaillink($address, $name = null) {} 2330cecf9d5Sandi 2340ea51e63SMatt Perry function internalmedia ($src, $title=null, $align=null, $width=null, 2350ea51e63SMatt Perry $height=null, $cache=null, $linking=null) {} 236a939d432SAndreas Gohr 2370ea51e63SMatt Perry function externalmedia ($src, $title=null, $align=null, $width=null, 2380ea51e63SMatt Perry $height=null, $cache=null, $linking=null) {} 239a939d432SAndreas Gohr 2400cecf9d5Sandi function internalmedialink ( 2410ea51e63SMatt Perry $src,$title=null,$align=null,$width=null,$height=null,$cache=null 2420cecf9d5Sandi ) {} 2430cecf9d5Sandi 2440cecf9d5Sandi function externalmedialink( 2450ea51e63SMatt Perry $src,$title=null,$align=null,$width=null,$height=null,$cache=null 2460cecf9d5Sandi ) {} 2470cecf9d5Sandi 248619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){} 2490cecf9d5Sandi 250619736fdSAdrian Lang function table_close($pos = null){} 2510cecf9d5Sandi 2520cecf9d5Sandi function tablerow_open(){} 2530cecf9d5Sandi 2540cecf9d5Sandi function tablerow_close(){} 2550cecf9d5Sandi 2560ea51e63SMatt Perry function tableheader_open($colspan = 1, $align = null, $rowspan = 1){} 2570cecf9d5Sandi 2580cecf9d5Sandi function tableheader_close(){} 2590cecf9d5Sandi 2600ea51e63SMatt Perry function tablecell_open($colspan = 1, $align = null, $rowspan = 1){} 2610cecf9d5Sandi 2620cecf9d5Sandi function tablecell_close(){} 2630cecf9d5Sandi 2642ea4044fSAndreas Gohr 2652ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2662ea4044fSAndreas Gohr 2672ea4044fSAndreas Gohr 2682ea4044fSAndreas Gohr /** 2692ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2702ea4044fSAndreas Gohr * casing and special chars 2712ea4044fSAndreas Gohr * 2722ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2732ea4044fSAndreas Gohr */ 2742ea4044fSAndreas Gohr function _simpleTitle($name){ 2752ea4044fSAndreas Gohr global $conf; 2762ea4044fSAndreas Gohr 277*6d2af55dSChristopher Smith //if there is a hash we use the anchor name only 278*6d2af55dSChristopher Smith @list($name,$hash) = explode('#',$name,2); 2792ea4044fSAndreas Gohr if($hash) return $hash; 2802ea4044fSAndreas Gohr 2812ea4044fSAndreas Gohr if($conf['useslash']){ 2823755fc25STom N Harris $name = strtr($name,';/',';:'); 2833755fc25STom N Harris }else{ 2843755fc25STom N Harris $name = strtr($name,';',':'); 2852ea4044fSAndreas Gohr } 2862ea4044fSAndreas Gohr 2879708106bSAdrian Lang return noNSorNS($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}&btnI=lucky'; 3001f82fabeSAndreas Gohr $shortcut = 'go'; 3011f82fabeSAndreas Gohr } 3022ea4044fSAndreas Gohr 3031f82fabeSAndreas Gohr //split into hash and url part 304*6d2af55dSChristopher Smith @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 329e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 330