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 628cc41db0SAndreas Gohr /** 638cc41db0SAndreas Gohr * handle plugin rendering 648cc41db0SAndreas Gohr * 658cc41db0SAndreas Gohr * @param string $name Plugin name 668cc41db0SAndreas Gohr * @param mixed $data custom data set by handler 678cc41db0SAndreas Gohr * @param string $state matched state if any 688cc41db0SAndreas Gohr * @param string $match raw matched syntax 698cc41db0SAndreas Gohr */ 708cc41db0SAndreas Gohr function plugin($name,$data,$state='',$match=''){ 71e8b5a4f9SAndreas Gohr $plugin = plugin_load('syntax',$name); 7261faf446Schris if($plugin != null){ 735f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 7461faf446Schris } 7561faf446Schris } 7661faf446Schris 775587e44cSchris /** 785587e44cSchris * handle nested render instructions 795587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 805587e44cSchris */ 815587e44cSchris function nest($instructions) { 825587e44cSchris 835587e44cSchris foreach ( $instructions as $instruction ) { 845587e44cSchris // execute the callback against ourself 85c2122b83SChristopher Smith if (method_exists($this,$instruction[0])) { 86d6a1a955SAndreas Gohr call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array()); 87c2122b83SChristopher Smith } 885587e44cSchris } 895587e44cSchris } 905587e44cSchris 915587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 925587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 935587e44cSchris // be able to - as their instructions require data. 945587e44cSchris function nest_close() {} 955587e44cSchris 960cecf9d5Sandi function document_start() {} 970cecf9d5Sandi 980cecf9d5Sandi function document_end() {} 990cecf9d5Sandi 1004fced885SAndreas Gohr function render_TOC() { return ''; } 1010cecf9d5Sandi 102e7856beaSchris function toc_additem($id, $text, $level) {} 103e7856beaSchris 104af587fa8Sandi function header($text, $level, $pos) {} 1050cecf9d5Sandi 1060cecf9d5Sandi function section_open($level) {} 1070cecf9d5Sandi 1080cecf9d5Sandi function section_close() {} 1090cecf9d5Sandi 1100cecf9d5Sandi function cdata($text) {} 1110cecf9d5Sandi 1120cecf9d5Sandi function p_open() {} 1130cecf9d5Sandi 1140cecf9d5Sandi function p_close() {} 1150cecf9d5Sandi 1160cecf9d5Sandi function linebreak() {} 1170cecf9d5Sandi 1180cecf9d5Sandi function hr() {} 1190cecf9d5Sandi 1200cecf9d5Sandi function strong_open() {} 1210cecf9d5Sandi 1220cecf9d5Sandi function strong_close() {} 1230cecf9d5Sandi 1240cecf9d5Sandi function emphasis_open() {} 1250cecf9d5Sandi 1260cecf9d5Sandi function emphasis_close() {} 1270cecf9d5Sandi 1280cecf9d5Sandi function underline_open() {} 1290cecf9d5Sandi 1300cecf9d5Sandi function underline_close() {} 1310cecf9d5Sandi 1320cecf9d5Sandi function monospace_open() {} 1330cecf9d5Sandi 1340cecf9d5Sandi function monospace_close() {} 1350cecf9d5Sandi 1360cecf9d5Sandi function subscript_open() {} 1370cecf9d5Sandi 1380cecf9d5Sandi function subscript_close() {} 1390cecf9d5Sandi 1400cecf9d5Sandi function superscript_open() {} 1410cecf9d5Sandi 1420cecf9d5Sandi function superscript_close() {} 1430cecf9d5Sandi 1440cecf9d5Sandi function deleted_open() {} 1450cecf9d5Sandi 1460cecf9d5Sandi function deleted_close() {} 1470cecf9d5Sandi 1480cecf9d5Sandi function footnote_open() {} 1490cecf9d5Sandi 1500cecf9d5Sandi function footnote_close() {} 1510cecf9d5Sandi 1520cecf9d5Sandi function listu_open() {} 1530cecf9d5Sandi 1540cecf9d5Sandi function listu_close() {} 1550cecf9d5Sandi 1560cecf9d5Sandi function listo_open() {} 1570cecf9d5Sandi 1580cecf9d5Sandi function listo_close() {} 1590cecf9d5Sandi 1600cecf9d5Sandi function listitem_open($level) {} 1610cecf9d5Sandi 1620cecf9d5Sandi function listitem_close() {} 1630cecf9d5Sandi 164699afdebSchris function listcontent_open() {} 1650cecf9d5Sandi 1660cecf9d5Sandi function listcontent_close() {} 1670cecf9d5Sandi 1680cecf9d5Sandi function unformatted($text) {} 1690cecf9d5Sandi 1700cecf9d5Sandi function php($text) {} 1710cecf9d5Sandi 17207f89c3cSAnika Henke function phpblock($text) {} 17307f89c3cSAnika Henke 1740cecf9d5Sandi function html($text) {} 1750cecf9d5Sandi 17607f89c3cSAnika Henke function htmlblock($text) {} 17707f89c3cSAnika Henke 1780cecf9d5Sandi function preformatted($text) {} 1790cecf9d5Sandi 1800cecf9d5Sandi function quote_open() {} 1810cecf9d5Sandi 1820cecf9d5Sandi function quote_close() {} 1830cecf9d5Sandi 1843d491f75SAndreas Gohr function file($text, $lang = null, $file = null ) {} 1853d491f75SAndreas Gohr 1863d491f75SAndreas Gohr function code($text, $lang = null, $file = null ) {} 1870cecf9d5Sandi 1880cecf9d5Sandi function acronym($acronym) {} 1890cecf9d5Sandi 1900cecf9d5Sandi function smiley($smiley) {} 1910cecf9d5Sandi 1920cecf9d5Sandi function wordblock($word) {} 1930cecf9d5Sandi 1940cecf9d5Sandi function entity($entity) {} 1950cecf9d5Sandi 1960cecf9d5Sandi // 640x480 ($x=640, $y=480) 1970cecf9d5Sandi function multiplyentity($x, $y) {} 1980cecf9d5Sandi 1990cecf9d5Sandi function singlequoteopening() {} 2000cecf9d5Sandi 2010cecf9d5Sandi function singlequoteclosing() {} 2020cecf9d5Sandi 20357d757d1SAndreas Gohr function apostrophe() {} 20457d757d1SAndreas Gohr 2050cecf9d5Sandi function doublequoteopening() {} 2060cecf9d5Sandi 2070cecf9d5Sandi function doublequoteclosing() {} 2080cecf9d5Sandi 2090cecf9d5Sandi // $link like 'SomePage' 2100cecf9d5Sandi function camelcaselink($link) {} 2110cecf9d5Sandi 2120ea51e63SMatt Perry function locallink($hash, $name = null) {} 213a939d432SAndreas Gohr 2140e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 2150ea51e63SMatt Perry function internallink($link, $title = null) {} 2160cecf9d5Sandi 2170cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 2180ea51e63SMatt Perry function externallink($link, $title = null) {} 2190cecf9d5Sandi 220c5cfca61SAndreas Gohr function rss ($url,$params) {} 221c5cfca61SAndreas Gohr 2220cecf9d5Sandi // $link is the original link - probably not much use 2230cecf9d5Sandi // $wikiName is an indentifier for the wiki 2240cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2250ea51e63SMatt Perry function interwikilink($link, $title = null, $wikiName, $wikiUri) {} 2260cecf9d5Sandi 2270cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2280ea51e63SMatt Perry function filelink($link, $title = null) {} 2290cecf9d5Sandi 2300cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2310ea51e63SMatt Perry function windowssharelink($link, $title = null) {} 2320cecf9d5Sandi 2330ea51e63SMatt Perry// function email($address, $title = null) {} 2340ea51e63SMatt Perry function emaillink($address, $name = null) {} 2350cecf9d5Sandi 2360ea51e63SMatt Perry function internalmedia ($src, $title=null, $align=null, $width=null, 2370ea51e63SMatt Perry $height=null, $cache=null, $linking=null) {} 238a939d432SAndreas Gohr 2390ea51e63SMatt Perry function externalmedia ($src, $title=null, $align=null, $width=null, 2400ea51e63SMatt Perry $height=null, $cache=null, $linking=null) {} 241a939d432SAndreas Gohr 2420cecf9d5Sandi function internalmedialink ( 2430ea51e63SMatt Perry $src,$title=null,$align=null,$width=null,$height=null,$cache=null 2440cecf9d5Sandi ) {} 2450cecf9d5Sandi 2460cecf9d5Sandi function externalmedialink( 2470ea51e63SMatt Perry $src,$title=null,$align=null,$width=null,$height=null,$cache=null 2480cecf9d5Sandi ) {} 2490cecf9d5Sandi 250619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){} 2510cecf9d5Sandi 252619736fdSAdrian Lang function table_close($pos = null){} 2530cecf9d5Sandi 2540cecf9d5Sandi function tablerow_open(){} 2550cecf9d5Sandi 2560cecf9d5Sandi function tablerow_close(){} 2570cecf9d5Sandi 2580ea51e63SMatt Perry function tableheader_open($colspan = 1, $align = null, $rowspan = 1){} 2590cecf9d5Sandi 2600cecf9d5Sandi function tableheader_close(){} 2610cecf9d5Sandi 2620ea51e63SMatt Perry function tablecell_open($colspan = 1, $align = null, $rowspan = 1){} 2630cecf9d5Sandi 2640cecf9d5Sandi function tablecell_close(){} 2650cecf9d5Sandi 2662ea4044fSAndreas Gohr 2672ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2682ea4044fSAndreas Gohr 2692ea4044fSAndreas Gohr 2702ea4044fSAndreas Gohr /** 2712ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2722ea4044fSAndreas Gohr * casing and special chars 2732ea4044fSAndreas Gohr * 2742ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2752ea4044fSAndreas Gohr */ 2762ea4044fSAndreas Gohr function _simpleTitle($name) { 2772ea4044fSAndreas Gohr global $conf; 2782ea4044fSAndreas Gohr 2792ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 2802ea4044fSAndreas Gohr list($name, $hash) = explode('#', $name, 2); 2812ea4044fSAndreas Gohr if($hash) return $hash; 2822ea4044fSAndreas Gohr 2832ea4044fSAndreas Gohr if($conf['useslash']) { 2843755fc25STom N Harris $name = strtr($name, ';/', ';:'); 2853755fc25STom N Harris } else { 2863755fc25STom N Harris $name = strtr($name, ';', ':'); 2872ea4044fSAndreas Gohr } 2882ea4044fSAndreas Gohr 2899708106bSAdrian Lang return noNSorNS($name); 2902ea4044fSAndreas Gohr } 2912ea4044fSAndreas Gohr 2921f82fabeSAndreas Gohr /** 2931f82fabeSAndreas Gohr * Resolve an interwikilink 2941f82fabeSAndreas Gohr */ 2956496c33fSGerrit Uitslag function _resolveInterWiki(&$shortcut, $reference, &$exists=null) { 2961f82fabeSAndreas Gohr //get interwiki URL 2971f82fabeSAndreas Gohr if(isset($this->interwiki[$shortcut])) { 2981f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 2991f82fabeSAndreas Gohr } else { 3001f82fabeSAndreas Gohr // Default to Google I'm feeling lucky 3011f82fabeSAndreas Gohr $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 3021f82fabeSAndreas Gohr $shortcut = 'go'; 3031f82fabeSAndreas Gohr } 3042ea4044fSAndreas Gohr 3051f82fabeSAndreas Gohr //split into hash and url part 306ab6cf7dfSAdrian Lang list($reference, $hash) = explode('#', $reference, 2); 3071f82fabeSAndreas Gohr 3081f82fabeSAndreas Gohr //replace placeholder 3091f82fabeSAndreas Gohr if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) { 3101f82fabeSAndreas Gohr //use placeholders 3111f82fabeSAndreas Gohr $url = str_replace('{URL}', rawurlencode($reference), $url); 3121f82fabeSAndreas Gohr $url = str_replace('{NAME}', $reference, $url); 3131f82fabeSAndreas Gohr $parsed = parse_url($reference); 3141f82fabeSAndreas Gohr if(!$parsed['port']) $parsed['port'] = 80; 3151f82fabeSAndreas Gohr $url = str_replace('{SCHEME}', $parsed['scheme'], $url); 3161f82fabeSAndreas Gohr $url = str_replace('{HOST}', $parsed['host'], $url); 3171f82fabeSAndreas Gohr $url = str_replace('{PORT}', $parsed['port'], $url); 3181f82fabeSAndreas Gohr $url = str_replace('{PATH}', $parsed['path'], $url); 3191f82fabeSAndreas Gohr $url = str_replace('{QUERY}', $parsed['query'], $url); 3201f82fabeSAndreas Gohr } else { 3211f82fabeSAndreas Gohr //default 3221f82fabeSAndreas Gohr $url = $url . rawurlencode($reference); 3231f82fabeSAndreas Gohr } 324*f379edc2SGerrit Uitslag //handle as wiki links 3256496c33fSGerrit Uitslag if($url{0} === ':') { 3266496c33fSGerrit Uitslag list($id, $urlparam) = explode('?', $url, 2); 3276496c33fSGerrit Uitslag $url = wl(cleanID($id), $urlparam); 3286496c33fSGerrit Uitslag $exists = page_exists($id); 3292345e871SGerrit Uitslag } 3301f82fabeSAndreas Gohr if($hash) $url .= '#' . rawurlencode($hash); 3311f82fabeSAndreas Gohr 3321f82fabeSAndreas Gohr return $url; 3331f82fabeSAndreas Gohr } 3340cecf9d5Sandi} 3350cecf9d5Sandi 336340756e4Sandi 337e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 338