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.'); 961faf446Schrisrequire_once DOKU_INC . 'inc/parser/renderer.php'; 10863befa1SAndreas Gohrrequire_once DOKU_INC . 'inc/plugin.php'; 1161faf446Schrisrequire_once DOKU_INC . 'inc/pluginutils.php'; 1261faf446Schris 13863befa1SAndreas Gohr/** 14863befa1SAndreas Gohr * An empty renderer, produces no output 15863befa1SAndreas Gohr * 16863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins 17863befa1SAndreas Gohr */ 18863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin { 199dc2c2afSandi var $info = array( 2044881bd0Shenning.noren 'cache' => true, // may the rendered result cached? 2144881bd0Shenning.noren 'toc' => true, // render the TOC? 229dc2c2afSandi ); 239dc2c2afSandi 241f82fabeSAndreas Gohr // keep some config options 251f82fabeSAndreas Gohr var $acronyms = array(); 261f82fabeSAndreas Gohr var $smileys = array(); 271f82fabeSAndreas Gohr var $badwords = array(); 281f82fabeSAndreas Gohr var $entities = array(); 291f82fabeSAndreas Gohr var $interwiki = array(); 309dc2c2afSandi 31d968d3e5SChris Smith // allows renderer to be used again, clean out any per-use values 32d968d3e5SChris Smith function reset() { 33d968d3e5SChris Smith } 34d968d3e5SChris Smith 359dc2c2afSandi function nocache() { 3644881bd0Shenning.noren $this->info['cache'] = false; 379dc2c2afSandi } 380cecf9d5Sandi 39e41c4da9SAndreas Gohr function notoc() { 4044881bd0Shenning.noren $this->info['toc'] = false; 41e41c4da9SAndreas Gohr } 42e41c4da9SAndreas Gohr 435f70445dSAndreas Gohr /** 445f70445dSAndreas Gohr * Returns the format produced by this renderer. 455f70445dSAndreas Gohr * 465f70445dSAndreas Gohr * Has to be overidden by decendend classes 475f70445dSAndreas Gohr */ 485f70445dSAndreas Gohr function getFormat(){ 495f70445dSAndreas Gohr trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); 505f70445dSAndreas Gohr } 515f70445dSAndreas Gohr 525f70445dSAndreas Gohr 5361faf446Schris //handle plugin rendering 5461faf446Schris function plugin($name,$data){ 5561faf446Schris $plugin =& plugin_load('syntax',$name); 5661faf446Schris if($plugin != null){ 575f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 5861faf446Schris } 5961faf446Schris } 6061faf446Schris 615587e44cSchris /** 625587e44cSchris * handle nested render instructions 635587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 645587e44cSchris */ 655587e44cSchris function nest($instructions) { 665587e44cSchris 675587e44cSchris foreach ( $instructions as $instruction ) { 685587e44cSchris // execute the callback against ourself 695587e44cSchris call_user_func_array(array(&$this, $instruction[0]),$instruction[1]); 705587e44cSchris } 715587e44cSchris } 725587e44cSchris 735587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 745587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 755587e44cSchris // be able to - as their instructions require data. 765587e44cSchris function nest_close() {} 775587e44cSchris 780cecf9d5Sandi function document_start() {} 790cecf9d5Sandi 800cecf9d5Sandi function document_end() {} 810cecf9d5Sandi 824fced885SAndreas Gohr function render_TOC() { return ''; } 830cecf9d5Sandi 84e7856beaSchris function toc_additem($id, $text, $level) {} 85e7856beaSchris 86af587fa8Sandi function header($text, $level, $pos) {} 870cecf9d5Sandi 8835dae8b0SBen Coburn function section_edit($start, $end, $level, $name) {} 8935dae8b0SBen Coburn 900cecf9d5Sandi function section_open($level) {} 910cecf9d5Sandi 920cecf9d5Sandi function section_close() {} 930cecf9d5Sandi 940cecf9d5Sandi function cdata($text) {} 950cecf9d5Sandi 960cecf9d5Sandi function p_open() {} 970cecf9d5Sandi 980cecf9d5Sandi function p_close() {} 990cecf9d5Sandi 1000cecf9d5Sandi function linebreak() {} 1010cecf9d5Sandi 1020cecf9d5Sandi function hr() {} 1030cecf9d5Sandi 1040cecf9d5Sandi function strong_open() {} 1050cecf9d5Sandi 1060cecf9d5Sandi function strong_close() {} 1070cecf9d5Sandi 1080cecf9d5Sandi function emphasis_open() {} 1090cecf9d5Sandi 1100cecf9d5Sandi function emphasis_close() {} 1110cecf9d5Sandi 1120cecf9d5Sandi function underline_open() {} 1130cecf9d5Sandi 1140cecf9d5Sandi function underline_close() {} 1150cecf9d5Sandi 1160cecf9d5Sandi function monospace_open() {} 1170cecf9d5Sandi 1180cecf9d5Sandi function monospace_close() {} 1190cecf9d5Sandi 1200cecf9d5Sandi function subscript_open() {} 1210cecf9d5Sandi 1220cecf9d5Sandi function subscript_close() {} 1230cecf9d5Sandi 1240cecf9d5Sandi function superscript_open() {} 1250cecf9d5Sandi 1260cecf9d5Sandi function superscript_close() {} 1270cecf9d5Sandi 1280cecf9d5Sandi function deleted_open() {} 1290cecf9d5Sandi 1300cecf9d5Sandi function deleted_close() {} 1310cecf9d5Sandi 1320cecf9d5Sandi function footnote_open() {} 1330cecf9d5Sandi 1340cecf9d5Sandi function footnote_close() {} 1350cecf9d5Sandi 1360cecf9d5Sandi function listu_open() {} 1370cecf9d5Sandi 1380cecf9d5Sandi function listu_close() {} 1390cecf9d5Sandi 1400cecf9d5Sandi function listo_open() {} 1410cecf9d5Sandi 1420cecf9d5Sandi function listo_close() {} 1430cecf9d5Sandi 1440cecf9d5Sandi function listitem_open($level) {} 1450cecf9d5Sandi 1460cecf9d5Sandi function listitem_close() {} 1470cecf9d5Sandi 148699afdebSchris function listcontent_open() {} 1490cecf9d5Sandi 1500cecf9d5Sandi function listcontent_close() {} 1510cecf9d5Sandi 1520cecf9d5Sandi function unformatted($text) {} 1530cecf9d5Sandi 1540cecf9d5Sandi function php($text) {} 1550cecf9d5Sandi 15607f89c3cSAnika Henke function phpblock($text) {} 15707f89c3cSAnika Henke 1580cecf9d5Sandi function html($text) {} 1590cecf9d5Sandi 16007f89c3cSAnika Henke function htmlblock($text) {} 16107f89c3cSAnika Henke 1620cecf9d5Sandi function preformatted($text) {} 1630cecf9d5Sandi 1640cecf9d5Sandi function quote_open() {} 1650cecf9d5Sandi 1660cecf9d5Sandi function quote_close() {} 1670cecf9d5Sandi 168*3d491f75SAndreas Gohr function file($text, $lang = null, $file = null ) {} 169*3d491f75SAndreas Gohr 170*3d491f75SAndreas Gohr function code($text, $lang = null, $file = null ) {} 1710cecf9d5Sandi 1720cecf9d5Sandi function acronym($acronym) {} 1730cecf9d5Sandi 1740cecf9d5Sandi function smiley($smiley) {} 1750cecf9d5Sandi 1760cecf9d5Sandi function wordblock($word) {} 1770cecf9d5Sandi 1780cecf9d5Sandi function entity($entity) {} 1790cecf9d5Sandi 1800cecf9d5Sandi // 640x480 ($x=640, $y=480) 1810cecf9d5Sandi function multiplyentity($x, $y) {} 1820cecf9d5Sandi 1830cecf9d5Sandi function singlequoteopening() {} 1840cecf9d5Sandi 1850cecf9d5Sandi function singlequoteclosing() {} 1860cecf9d5Sandi 18757d757d1SAndreas Gohr function apostrophe() {} 18857d757d1SAndreas Gohr 1890cecf9d5Sandi function doublequoteopening() {} 1900cecf9d5Sandi 1910cecf9d5Sandi function doublequoteclosing() {} 1920cecf9d5Sandi 1930cecf9d5Sandi // $link like 'SomePage' 1940cecf9d5Sandi function camelcaselink($link) {} 1950cecf9d5Sandi 196a939d432SAndreas Gohr function locallink($hash, $name = NULL) {} 197a939d432SAndreas Gohr 1980e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 1990cecf9d5Sandi function internallink($link, $title = NULL) {} 2000cecf9d5Sandi 2010cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 2020cecf9d5Sandi function externallink($link, $title = NULL) {} 2030cecf9d5Sandi 204c5cfca61SAndreas Gohr function rss ($url,$params) {} 205c5cfca61SAndreas Gohr 2060cecf9d5Sandi // $link is the original link - probably not much use 2070cecf9d5Sandi // $wikiName is an indentifier for the wiki 2080cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2090cecf9d5Sandi function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 2100cecf9d5Sandi 2110cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2120cecf9d5Sandi function filelink($link, $title = NULL) {} 2130cecf9d5Sandi 2140cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2150cecf9d5Sandi function windowssharelink($link, $title = NULL) {} 2160cecf9d5Sandi 217699afdebSchris// function email($address, $title = NULL) {} 218699afdebSchris function emaillink($address, $name = NULL) {} 2190cecf9d5Sandi 220a939d432SAndreas Gohr function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 221a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 222a939d432SAndreas Gohr 223a939d432SAndreas Gohr function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 224a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 225a939d432SAndreas Gohr 2260cecf9d5Sandi function internalmedialink ( 2270cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2280cecf9d5Sandi ) {} 2290cecf9d5Sandi 2300cecf9d5Sandi function externalmedialink( 2310cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2320cecf9d5Sandi ) {} 2330cecf9d5Sandi 2340cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){} 2350cecf9d5Sandi 2360cecf9d5Sandi function table_close(){} 2370cecf9d5Sandi 2380cecf9d5Sandi function tablerow_open(){} 2390cecf9d5Sandi 2400cecf9d5Sandi function tablerow_close(){} 2410cecf9d5Sandi 2420cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){} 2430cecf9d5Sandi 2440cecf9d5Sandi function tableheader_close(){} 2450cecf9d5Sandi 2460cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){} 2470cecf9d5Sandi 2480cecf9d5Sandi function tablecell_close(){} 2490cecf9d5Sandi 2502ea4044fSAndreas Gohr 2512ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2522ea4044fSAndreas Gohr 2532ea4044fSAndreas Gohr 2542ea4044fSAndreas Gohr /** 2552ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2562ea4044fSAndreas Gohr * casing and special chars 2572ea4044fSAndreas Gohr * 2582ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2592ea4044fSAndreas Gohr */ 2602ea4044fSAndreas Gohr function _simpleTitle($name){ 2612ea4044fSAndreas Gohr global $conf; 2622ea4044fSAndreas Gohr 2632ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 2642ea4044fSAndreas Gohr list($name,$hash) = explode('#',$name,2); 2652ea4044fSAndreas Gohr if($hash) return $hash; 2662ea4044fSAndreas Gohr 2671179df0eSGuy Brand //trim colons or slash of a namespace link 2682ea4044fSAndreas Gohr $name = rtrim($name,':'); 2691179df0eSGuy Brand if($conf['useslash']) 2701179df0eSGuy Brand $name = rtrim($name,'/'); 2712ea4044fSAndreas Gohr 2722ea4044fSAndreas Gohr if($conf['useslash']){ 2732ea4044fSAndreas Gohr $nssep = '[:;/]'; 2742ea4044fSAndreas Gohr }else{ 2752ea4044fSAndreas Gohr $nssep = '[:;]'; 2762ea4044fSAndreas Gohr } 2772ea4044fSAndreas Gohr $name = preg_replace('!.*'.$nssep.'!','',$name); 2782ea4044fSAndreas Gohr 2792ea4044fSAndreas Gohr if(!$name) return $this->_simpleTitle($conf['start']); 2802ea4044fSAndreas Gohr return $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 2971f82fabeSAndreas Gohr list($wikiUri,$hash) = explode('#',$wikiUri,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