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. 92*2c2835c2SAndreas Gohr function nest_close() { 93*2c2835c2SAndreas Gohr } 945587e44cSchris 95*2c2835c2SAndreas Gohr function document_start() { 96*2c2835c2SAndreas Gohr } 970cecf9d5Sandi 98*2c2835c2SAndreas Gohr function document_end() { 99*2c2835c2SAndreas Gohr } 1000cecf9d5Sandi 101*2c2835c2SAndreas Gohr function render_TOC() { 102*2c2835c2SAndreas Gohr return ''; 103*2c2835c2SAndreas Gohr } 1040cecf9d5Sandi 105*2c2835c2SAndreas Gohr function toc_additem($id, $text, $level) { 106*2c2835c2SAndreas Gohr } 107e7856beaSchris 108*2c2835c2SAndreas Gohr function header($text, $level, $pos) { 109*2c2835c2SAndreas Gohr } 1100cecf9d5Sandi 111*2c2835c2SAndreas Gohr function section_open($level) { 112*2c2835c2SAndreas Gohr } 1130cecf9d5Sandi 114*2c2835c2SAndreas Gohr function section_close() { 115*2c2835c2SAndreas Gohr } 1160cecf9d5Sandi 117*2c2835c2SAndreas Gohr function cdata($text) { 118*2c2835c2SAndreas Gohr } 1190cecf9d5Sandi 120*2c2835c2SAndreas Gohr function p_open() { 121*2c2835c2SAndreas Gohr } 1220cecf9d5Sandi 123*2c2835c2SAndreas Gohr function p_close() { 124*2c2835c2SAndreas Gohr } 1250cecf9d5Sandi 126*2c2835c2SAndreas Gohr function linebreak() { 127*2c2835c2SAndreas Gohr } 1280cecf9d5Sandi 129*2c2835c2SAndreas Gohr function hr() { 130*2c2835c2SAndreas Gohr } 1310cecf9d5Sandi 132*2c2835c2SAndreas Gohr function strong_open() { 133*2c2835c2SAndreas Gohr } 1340cecf9d5Sandi 135*2c2835c2SAndreas Gohr function strong_close() { 136*2c2835c2SAndreas Gohr } 1370cecf9d5Sandi 138*2c2835c2SAndreas Gohr function emphasis_open() { 139*2c2835c2SAndreas Gohr } 1400cecf9d5Sandi 141*2c2835c2SAndreas Gohr function emphasis_close() { 142*2c2835c2SAndreas Gohr } 1430cecf9d5Sandi 144*2c2835c2SAndreas Gohr function underline_open() { 145*2c2835c2SAndreas Gohr } 1460cecf9d5Sandi 147*2c2835c2SAndreas Gohr function underline_close() { 148*2c2835c2SAndreas Gohr } 1490cecf9d5Sandi 150*2c2835c2SAndreas Gohr function monospace_open() { 151*2c2835c2SAndreas Gohr } 1520cecf9d5Sandi 153*2c2835c2SAndreas Gohr function monospace_close() { 154*2c2835c2SAndreas Gohr } 1550cecf9d5Sandi 156*2c2835c2SAndreas Gohr function subscript_open() { 157*2c2835c2SAndreas Gohr } 1580cecf9d5Sandi 159*2c2835c2SAndreas Gohr function subscript_close() { 160*2c2835c2SAndreas Gohr } 1610cecf9d5Sandi 162*2c2835c2SAndreas Gohr function superscript_open() { 163*2c2835c2SAndreas Gohr } 1640cecf9d5Sandi 165*2c2835c2SAndreas Gohr function superscript_close() { 166*2c2835c2SAndreas Gohr } 1670cecf9d5Sandi 168*2c2835c2SAndreas Gohr function deleted_open() { 169*2c2835c2SAndreas Gohr } 1700cecf9d5Sandi 171*2c2835c2SAndreas Gohr function deleted_close() { 172*2c2835c2SAndreas Gohr } 1730cecf9d5Sandi 174*2c2835c2SAndreas Gohr function footnote_open() { 175*2c2835c2SAndreas Gohr } 1760cecf9d5Sandi 177*2c2835c2SAndreas Gohr function footnote_close() { 178*2c2835c2SAndreas Gohr } 1790cecf9d5Sandi 180*2c2835c2SAndreas Gohr function listu_open() { 181*2c2835c2SAndreas Gohr } 1820cecf9d5Sandi 183*2c2835c2SAndreas Gohr function listu_close() { 184*2c2835c2SAndreas Gohr } 1850cecf9d5Sandi 186*2c2835c2SAndreas Gohr function listo_open() { 187*2c2835c2SAndreas Gohr } 1880cecf9d5Sandi 189*2c2835c2SAndreas Gohr function listo_close() { 190*2c2835c2SAndreas Gohr } 1910cecf9d5Sandi 192*2c2835c2SAndreas Gohr function listitem_open($level) { 193*2c2835c2SAndreas Gohr } 1940cecf9d5Sandi 195*2c2835c2SAndreas Gohr function listitem_close() { 196*2c2835c2SAndreas Gohr } 1970cecf9d5Sandi 198*2c2835c2SAndreas Gohr function listcontent_open() { 199*2c2835c2SAndreas Gohr } 2000cecf9d5Sandi 201*2c2835c2SAndreas Gohr function listcontent_close() { 202*2c2835c2SAndreas Gohr } 2030cecf9d5Sandi 204*2c2835c2SAndreas Gohr function unformatted($text) { 205*2c2835c2SAndreas Gohr } 2060cecf9d5Sandi 207*2c2835c2SAndreas Gohr function php($text) { 208*2c2835c2SAndreas Gohr } 2090cecf9d5Sandi 210*2c2835c2SAndreas Gohr function phpblock($text) { 211*2c2835c2SAndreas Gohr } 21207f89c3cSAnika Henke 213*2c2835c2SAndreas Gohr function html($text) { 214*2c2835c2SAndreas Gohr } 2150cecf9d5Sandi 216*2c2835c2SAndreas Gohr function htmlblock($text) { 217*2c2835c2SAndreas Gohr } 21807f89c3cSAnika Henke 219*2c2835c2SAndreas Gohr function preformatted($text) { 220*2c2835c2SAndreas Gohr } 2210cecf9d5Sandi 222*2c2835c2SAndreas Gohr function quote_open() { 223*2c2835c2SAndreas Gohr } 2240cecf9d5Sandi 225*2c2835c2SAndreas Gohr function quote_close() { 226*2c2835c2SAndreas Gohr } 2270cecf9d5Sandi 228*2c2835c2SAndreas Gohr function file($text, $lang = null, $file = null) { 229*2c2835c2SAndreas Gohr } 2303d491f75SAndreas Gohr 231*2c2835c2SAndreas Gohr function code($text, $lang = null, $file = null) { 232*2c2835c2SAndreas Gohr } 2330cecf9d5Sandi 234*2c2835c2SAndreas Gohr function acronym($acronym) { 235*2c2835c2SAndreas Gohr } 2360cecf9d5Sandi 237*2c2835c2SAndreas Gohr function smiley($smiley) { 238*2c2835c2SAndreas Gohr } 2390cecf9d5Sandi 240*2c2835c2SAndreas Gohr function wordblock($word) { 241*2c2835c2SAndreas Gohr } 2420cecf9d5Sandi 243*2c2835c2SAndreas Gohr function entity($entity) { 244*2c2835c2SAndreas Gohr } 2450cecf9d5Sandi 2460cecf9d5Sandi // 640x480 ($x=640, $y=480) 247*2c2835c2SAndreas Gohr function multiplyentity($x, $y) { 248*2c2835c2SAndreas Gohr } 2490cecf9d5Sandi 250*2c2835c2SAndreas Gohr function singlequoteopening() { 251*2c2835c2SAndreas Gohr } 2520cecf9d5Sandi 253*2c2835c2SAndreas Gohr function singlequoteclosing() { 254*2c2835c2SAndreas Gohr } 2550cecf9d5Sandi 256*2c2835c2SAndreas Gohr function apostrophe() { 257*2c2835c2SAndreas Gohr } 25857d757d1SAndreas Gohr 259*2c2835c2SAndreas Gohr function doublequoteopening() { 260*2c2835c2SAndreas Gohr } 2610cecf9d5Sandi 262*2c2835c2SAndreas Gohr function doublequoteclosing() { 263*2c2835c2SAndreas Gohr } 2640cecf9d5Sandi 2650cecf9d5Sandi // $link like 'SomePage' 266*2c2835c2SAndreas Gohr function camelcaselink($link) { 267*2c2835c2SAndreas Gohr } 2680cecf9d5Sandi 269*2c2835c2SAndreas Gohr function locallink($hash, $name = null) { 270*2c2835c2SAndreas Gohr } 271a939d432SAndreas Gohr 2720e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 273*2c2835c2SAndreas Gohr function internallink($link, $title = null) { 274*2c2835c2SAndreas Gohr } 2750cecf9d5Sandi 2760cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 277*2c2835c2SAndreas Gohr function externallink($link, $title = null) { 278*2c2835c2SAndreas Gohr } 2790cecf9d5Sandi 280*2c2835c2SAndreas Gohr function rss($url, $params) { 281*2c2835c2SAndreas Gohr } 282c5cfca61SAndreas Gohr 2830cecf9d5Sandi // $link is the original link - probably not much use 2840cecf9d5Sandi // $wikiName is an indentifier for the wiki 2850cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 286*2c2835c2SAndreas Gohr function interwikilink($link, $title = null, $wikiName, $wikiUri) { 287*2c2835c2SAndreas Gohr } 2880cecf9d5Sandi 2890cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 290*2c2835c2SAndreas Gohr function filelink($link, $title = null) { 291*2c2835c2SAndreas Gohr } 2920cecf9d5Sandi 2930cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 294*2c2835c2SAndreas Gohr function windowssharelink($link, $title = null) { 295*2c2835c2SAndreas Gohr } 2960cecf9d5Sandi 2970ea51e63SMatt Perry// function email($address, $title = null) {} 298*2c2835c2SAndreas Gohr function emaillink($address, $name = null) { 299*2c2835c2SAndreas Gohr } 3000cecf9d5Sandi 3010ea51e63SMatt Perry function internalmedia($src, $title = null, $align = null, $width = null, 302*2c2835c2SAndreas Gohr $height = null, $cache = null, $linking = null) { 303*2c2835c2SAndreas Gohr } 304a939d432SAndreas Gohr 3050ea51e63SMatt Perry function externalmedia($src, $title = null, $align = null, $width = null, 306*2c2835c2SAndreas Gohr $height = null, $cache = null, $linking = null) { 307*2c2835c2SAndreas Gohr } 308a939d432SAndreas Gohr 3090cecf9d5Sandi function internalmedialink( 3100ea51e63SMatt Perry $src, $title = null, $align = null, $width = null, $height = null, $cache = null 311*2c2835c2SAndreas Gohr ) { 312*2c2835c2SAndreas Gohr } 3130cecf9d5Sandi 3140cecf9d5Sandi function externalmedialink( 3150ea51e63SMatt Perry $src, $title = null, $align = null, $width = null, $height = null, $cache = null 316*2c2835c2SAndreas Gohr ) { 317*2c2835c2SAndreas Gohr } 3180cecf9d5Sandi 319*2c2835c2SAndreas Gohr function table_open($maxcols = null, $numrows = null, $pos = null) { 320*2c2835c2SAndreas Gohr } 3210cecf9d5Sandi 322*2c2835c2SAndreas Gohr function table_close($pos = null) { 323*2c2835c2SAndreas Gohr } 3240cecf9d5Sandi 325*2c2835c2SAndreas Gohr function tablethead_open() { 326*2c2835c2SAndreas Gohr } 327f05a1cc5SGerrit Uitslag 328*2c2835c2SAndreas Gohr function tablethead_close() { 329*2c2835c2SAndreas Gohr } 330f05a1cc5SGerrit Uitslag 331*2c2835c2SAndreas Gohr function tablerow_open() { 332*2c2835c2SAndreas Gohr } 3330cecf9d5Sandi 334*2c2835c2SAndreas Gohr function tablerow_close() { 335*2c2835c2SAndreas Gohr } 3360cecf9d5Sandi 337*2c2835c2SAndreas Gohr function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { 338*2c2835c2SAndreas Gohr } 3390cecf9d5Sandi 340*2c2835c2SAndreas Gohr function tableheader_close() { 341*2c2835c2SAndreas Gohr } 3420cecf9d5Sandi 343*2c2835c2SAndreas Gohr function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { 344*2c2835c2SAndreas Gohr } 3450cecf9d5Sandi 346*2c2835c2SAndreas Gohr function tablecell_close() { 347*2c2835c2SAndreas Gohr } 3482ea4044fSAndreas Gohr 3492ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 3502ea4044fSAndreas Gohr 3512ea4044fSAndreas Gohr /** 3522ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 3532ea4044fSAndreas Gohr * casing and special chars 3542ea4044fSAndreas Gohr * 3552ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 3562ea4044fSAndreas Gohr */ 3572ea4044fSAndreas Gohr function _simpleTitle($name) { 3582ea4044fSAndreas Gohr global $conf; 3592ea4044fSAndreas Gohr 3602ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 3616d2af55dSChristopher Smith @list($name, $hash) = explode('#', $name, 2); 3622ea4044fSAndreas Gohr if($hash) return $hash; 3632ea4044fSAndreas Gohr 3642ea4044fSAndreas Gohr if($conf['useslash']) { 3653755fc25STom N Harris $name = strtr($name, ';/', ';:'); 3663755fc25STom N Harris } else { 3673755fc25STom N Harris $name = strtr($name, ';', ':'); 3682ea4044fSAndreas Gohr } 3692ea4044fSAndreas Gohr 3709708106bSAdrian Lang return noNSorNS($name); 3712ea4044fSAndreas Gohr } 3722ea4044fSAndreas Gohr 3731f82fabeSAndreas Gohr /** 3741f82fabeSAndreas Gohr * Resolve an interwikilink 3751f82fabeSAndreas Gohr */ 3766496c33fSGerrit Uitslag function _resolveInterWiki(&$shortcut, $reference, &$exists = null) { 3771f82fabeSAndreas Gohr //get interwiki URL 3781f82fabeSAndreas Gohr if(isset($this->interwiki[$shortcut])) { 3791f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 3801f82fabeSAndreas Gohr } else { 3811f82fabeSAndreas Gohr // Default to Google I'm feeling lucky 3821f82fabeSAndreas Gohr $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 3831f82fabeSAndreas Gohr $shortcut = 'go'; 3841f82fabeSAndreas Gohr } 3852ea4044fSAndreas Gohr 3861f82fabeSAndreas Gohr //split into hash and url part 3876d2af55dSChristopher Smith @list($reference, $hash) = explode('#', $reference, 2); 3881f82fabeSAndreas Gohr 3891f82fabeSAndreas Gohr //replace placeholder 3901f82fabeSAndreas Gohr if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) { 3911f82fabeSAndreas Gohr //use placeholders 3921f82fabeSAndreas Gohr $url = str_replace('{URL}', rawurlencode($reference), $url); 3931f82fabeSAndreas Gohr $url = str_replace('{NAME}', $reference, $url); 3941f82fabeSAndreas Gohr $parsed = parse_url($reference); 3951f82fabeSAndreas Gohr if(!$parsed['port']) $parsed['port'] = 80; 3961f82fabeSAndreas Gohr $url = str_replace('{SCHEME}', $parsed['scheme'], $url); 3971f82fabeSAndreas Gohr $url = str_replace('{HOST}', $parsed['host'], $url); 3981f82fabeSAndreas Gohr $url = str_replace('{PORT}', $parsed['port'], $url); 3991f82fabeSAndreas Gohr $url = str_replace('{PATH}', $parsed['path'], $url); 4001f82fabeSAndreas Gohr $url = str_replace('{QUERY}', $parsed['query'], $url); 4011f82fabeSAndreas Gohr } else { 4021f82fabeSAndreas Gohr //default 4031f82fabeSAndreas Gohr $url = $url.rawurlencode($reference); 4041f82fabeSAndreas Gohr } 405f379edc2SGerrit Uitslag //handle as wiki links 4066496c33fSGerrit Uitslag if($url{0} === ':') { 4076496c33fSGerrit Uitslag list($id, $urlparam) = explode('?', $url, 2); 4086496c33fSGerrit Uitslag $url = wl(cleanID($id), $urlparam); 4096496c33fSGerrit Uitslag $exists = page_exists($id); 4102345e871SGerrit Uitslag } 4111f82fabeSAndreas Gohr if($hash) $url .= '#'.rawurlencode($hash); 4121f82fabeSAndreas Gohr 4131f82fabeSAndreas Gohr return $url; 4141f82fabeSAndreas Gohr } 4150cecf9d5Sandi} 4160cecf9d5Sandi 417340756e4Sandi 418e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 419