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 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 605f70445dSAndreas Gohr 6161faf446Schris //handle plugin rendering 6261faf446Schris function plugin($name,$data){ 6361faf446Schris $plugin =& plugin_load('syntax',$name); 6461faf446Schris if($plugin != null){ 655f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 6661faf446Schris } 6761faf446Schris } 6861faf446Schris 695587e44cSchris /** 705587e44cSchris * handle nested render instructions 715587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 725587e44cSchris */ 735587e44cSchris function nest($instructions) { 745587e44cSchris 755587e44cSchris foreach ( $instructions as $instruction ) { 765587e44cSchris // execute the callback against ourself 77c2122b83SChristopher Smith if (method_exists($this,$instruction[0])) { 78c2122b83SChristopher Smith call_user_func_array(array($this, $instruction[0]),$instruction[1]); 79c2122b83SChristopher Smith } 805587e44cSchris } 815587e44cSchris } 825587e44cSchris 835587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 845587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 855587e44cSchris // be able to - as their instructions require data. 865587e44cSchris function nest_close() {} 875587e44cSchris 880cecf9d5Sandi function document_start() {} 890cecf9d5Sandi 900cecf9d5Sandi function document_end() {} 910cecf9d5Sandi 924fced885SAndreas Gohr function render_TOC() { return ''; } 930cecf9d5Sandi 94e7856beaSchris function toc_additem($id, $text, $level) {} 95e7856beaSchris 96af587fa8Sandi function header($text, $level, $pos) {} 970cecf9d5Sandi 980cecf9d5Sandi function section_open($level) {} 990cecf9d5Sandi 1000cecf9d5Sandi function section_close() {} 1010cecf9d5Sandi 1020cecf9d5Sandi function cdata($text) {} 1030cecf9d5Sandi 1040cecf9d5Sandi function p_open() {} 1050cecf9d5Sandi 1060cecf9d5Sandi function p_close() {} 1070cecf9d5Sandi 1080cecf9d5Sandi function linebreak() {} 1090cecf9d5Sandi 1100cecf9d5Sandi function hr() {} 1110cecf9d5Sandi 1120cecf9d5Sandi function strong_open() {} 1130cecf9d5Sandi 1140cecf9d5Sandi function strong_close() {} 1150cecf9d5Sandi 1160cecf9d5Sandi function emphasis_open() {} 1170cecf9d5Sandi 1180cecf9d5Sandi function emphasis_close() {} 1190cecf9d5Sandi 1200cecf9d5Sandi function underline_open() {} 1210cecf9d5Sandi 1220cecf9d5Sandi function underline_close() {} 1230cecf9d5Sandi 1240cecf9d5Sandi function monospace_open() {} 1250cecf9d5Sandi 1260cecf9d5Sandi function monospace_close() {} 1270cecf9d5Sandi 1280cecf9d5Sandi function subscript_open() {} 1290cecf9d5Sandi 1300cecf9d5Sandi function subscript_close() {} 1310cecf9d5Sandi 1320cecf9d5Sandi function superscript_open() {} 1330cecf9d5Sandi 1340cecf9d5Sandi function superscript_close() {} 1350cecf9d5Sandi 1360cecf9d5Sandi function deleted_open() {} 1370cecf9d5Sandi 1380cecf9d5Sandi function deleted_close() {} 1390cecf9d5Sandi 1400cecf9d5Sandi function footnote_open() {} 1410cecf9d5Sandi 1420cecf9d5Sandi function footnote_close() {} 1430cecf9d5Sandi 1440cecf9d5Sandi function listu_open() {} 1450cecf9d5Sandi 1460cecf9d5Sandi function listu_close() {} 1470cecf9d5Sandi 1480cecf9d5Sandi function listo_open() {} 1490cecf9d5Sandi 1500cecf9d5Sandi function listo_close() {} 1510cecf9d5Sandi 1520cecf9d5Sandi function listitem_open($level) {} 1530cecf9d5Sandi 1540cecf9d5Sandi function listitem_close() {} 1550cecf9d5Sandi 156699afdebSchris function listcontent_open() {} 1570cecf9d5Sandi 1580cecf9d5Sandi function listcontent_close() {} 1590cecf9d5Sandi 1600cecf9d5Sandi function unformatted($text) {} 1610cecf9d5Sandi 1620cecf9d5Sandi function php($text) {} 1630cecf9d5Sandi 16407f89c3cSAnika Henke function phpblock($text) {} 16507f89c3cSAnika Henke 1660cecf9d5Sandi function html($text) {} 1670cecf9d5Sandi 16807f89c3cSAnika Henke function htmlblock($text) {} 16907f89c3cSAnika Henke 1700cecf9d5Sandi function preformatted($text) {} 1710cecf9d5Sandi 1720cecf9d5Sandi function quote_open() {} 1730cecf9d5Sandi 1740cecf9d5Sandi function quote_close() {} 1750cecf9d5Sandi 1763d491f75SAndreas Gohr function file($text, $lang = null, $file = null ) {} 1773d491f75SAndreas Gohr 1783d491f75SAndreas Gohr function code($text, $lang = null, $file = null ) {} 1790cecf9d5Sandi 1800cecf9d5Sandi function acronym($acronym) {} 1810cecf9d5Sandi 1820cecf9d5Sandi function smiley($smiley) {} 1830cecf9d5Sandi 1840cecf9d5Sandi function wordblock($word) {} 1850cecf9d5Sandi 1860cecf9d5Sandi function entity($entity) {} 1870cecf9d5Sandi 1880cecf9d5Sandi // 640x480 ($x=640, $y=480) 1890cecf9d5Sandi function multiplyentity($x, $y) {} 1900cecf9d5Sandi 1910cecf9d5Sandi function singlequoteopening() {} 1920cecf9d5Sandi 1930cecf9d5Sandi function singlequoteclosing() {} 1940cecf9d5Sandi 19557d757d1SAndreas Gohr function apostrophe() {} 19657d757d1SAndreas Gohr 1970cecf9d5Sandi function doublequoteopening() {} 1980cecf9d5Sandi 1990cecf9d5Sandi function doublequoteclosing() {} 2000cecf9d5Sandi 2010cecf9d5Sandi // $link like 'SomePage' 2020cecf9d5Sandi function camelcaselink($link) {} 2030cecf9d5Sandi 204a939d432SAndreas Gohr function locallink($hash, $name = NULL) {} 205a939d432SAndreas Gohr 2060e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 2070cecf9d5Sandi function internallink($link, $title = NULL) {} 2080cecf9d5Sandi 2090cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 2100cecf9d5Sandi function externallink($link, $title = NULL) {} 2110cecf9d5Sandi 212c5cfca61SAndreas Gohr function rss ($url,$params) {} 213c5cfca61SAndreas Gohr 2140cecf9d5Sandi // $link is the original link - probably not much use 2150cecf9d5Sandi // $wikiName is an indentifier for the wiki 2160cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2170cecf9d5Sandi function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 2180cecf9d5Sandi 2190cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2200cecf9d5Sandi function filelink($link, $title = NULL) {} 2210cecf9d5Sandi 2220cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2230cecf9d5Sandi function windowssharelink($link, $title = NULL) {} 2240cecf9d5Sandi 225699afdebSchris// function email($address, $title = NULL) {} 226699afdebSchris function emaillink($address, $name = NULL) {} 2270cecf9d5Sandi 228a939d432SAndreas Gohr function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 229a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 230a939d432SAndreas Gohr 231a939d432SAndreas Gohr function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 232a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 233a939d432SAndreas Gohr 2340cecf9d5Sandi function internalmedialink ( 2350cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2360cecf9d5Sandi ) {} 2370cecf9d5Sandi 2380cecf9d5Sandi function externalmedialink( 2390cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2400cecf9d5Sandi ) {} 2410cecf9d5Sandi 242*619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){} 2430cecf9d5Sandi 244*619736fdSAdrian Lang function table_close($pos = null){} 2450cecf9d5Sandi 2460cecf9d5Sandi function tablerow_open(){} 2470cecf9d5Sandi 2480cecf9d5Sandi function tablerow_close(){} 2490cecf9d5Sandi 25025b97867Shakan.sandell function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} 2510cecf9d5Sandi 2520cecf9d5Sandi function tableheader_close(){} 2530cecf9d5Sandi 25425b97867Shakan.sandell function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} 2550cecf9d5Sandi 2560cecf9d5Sandi function tablecell_close(){} 2570cecf9d5Sandi 2582ea4044fSAndreas Gohr 2592ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2602ea4044fSAndreas Gohr 2612ea4044fSAndreas Gohr 2622ea4044fSAndreas Gohr /** 2632ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2642ea4044fSAndreas Gohr * casing and special chars 2652ea4044fSAndreas Gohr * 2662ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2672ea4044fSAndreas Gohr */ 2682ea4044fSAndreas Gohr function _simpleTitle($name){ 2692ea4044fSAndreas Gohr global $conf; 2702ea4044fSAndreas Gohr 2712ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 2722ea4044fSAndreas Gohr list($name,$hash) = explode('#',$name,2); 2732ea4044fSAndreas Gohr if($hash) return $hash; 2742ea4044fSAndreas Gohr 2759708106bSAdrian Lang $name = strtr($name,';',':'); 2762ea4044fSAndreas Gohr if($conf['useslash']){ 2779708106bSAdrian Lang $name = strtr($name,'/',':'); 2782ea4044fSAndreas Gohr } 2792ea4044fSAndreas Gohr 2809708106bSAdrian Lang return noNSorNS($name); 2812ea4044fSAndreas Gohr } 2822ea4044fSAndreas Gohr 2831f82fabeSAndreas Gohr /** 2841f82fabeSAndreas Gohr * Resolve an interwikilink 2851f82fabeSAndreas Gohr */ 2861f82fabeSAndreas Gohr function _resolveInterWiki(&$shortcut,$reference){ 2871f82fabeSAndreas Gohr //get interwiki URL 2881f82fabeSAndreas Gohr if ( isset($this->interwiki[$shortcut]) ) { 2891f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 2901f82fabeSAndreas Gohr } else { 2911f82fabeSAndreas Gohr // Default to Google I'm feeling lucky 2921f82fabeSAndreas Gohr $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 2931f82fabeSAndreas Gohr $shortcut = 'go'; 2941f82fabeSAndreas Gohr } 2952ea4044fSAndreas Gohr 2961f82fabeSAndreas Gohr //split into hash and url part 297ab6cf7dfSAdrian Lang list($reference,$hash) = explode('#',$reference,2); 2981f82fabeSAndreas Gohr 2991f82fabeSAndreas Gohr //replace placeholder 3001f82fabeSAndreas Gohr if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 3011f82fabeSAndreas Gohr //use placeholders 3021f82fabeSAndreas Gohr $url = str_replace('{URL}',rawurlencode($reference),$url); 3031f82fabeSAndreas Gohr $url = str_replace('{NAME}',$reference,$url); 3041f82fabeSAndreas Gohr $parsed = parse_url($reference); 3051f82fabeSAndreas Gohr if(!$parsed['port']) $parsed['port'] = 80; 3061f82fabeSAndreas Gohr $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 3071f82fabeSAndreas Gohr $url = str_replace('{HOST}',$parsed['host'],$url); 3081f82fabeSAndreas Gohr $url = str_replace('{PORT}',$parsed['port'],$url); 3091f82fabeSAndreas Gohr $url = str_replace('{PATH}',$parsed['path'],$url); 3101f82fabeSAndreas Gohr $url = str_replace('{QUERY}',$parsed['query'],$url); 3111f82fabeSAndreas Gohr }else{ 3121f82fabeSAndreas Gohr //default 3131f82fabeSAndreas Gohr $url = $url.rawurlencode($reference); 3141f82fabeSAndreas Gohr } 3151f82fabeSAndreas Gohr if($hash) $url .= '#'.rawurlencode($hash); 3161f82fabeSAndreas Gohr 3171f82fabeSAndreas Gohr return $url; 3181f82fabeSAndreas Gohr } 3190cecf9d5Sandi} 3200cecf9d5Sandi 321340756e4Sandi 3229dc2c2afSandi//Setup VIM: ex: et ts=4 enc=utf-8 : 323