10cecf9d5Sandi<?php 261faf446Schris/** 35587e44cSchris * Renderer output base class 461faf446Schris * 561faf446Schris * @author Harry Fuecks <hfuecks@gmail.com> 661faf446Schris * @author Andreas Gohr <andi@splitbrain.org> 761faf446Schris */ 8*00976812SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/'); 961faf446Schris 1061faf446Schrisrequire_once DOKU_INC . 'inc/parser/renderer.php'; 11863befa1SAndreas Gohrrequire_once DOKU_INC . 'inc/plugin.php'; 1261faf446Schrisrequire_once DOKU_INC . 'inc/pluginutils.php'; 1361faf446Schris 14863befa1SAndreas Gohr/** 15863befa1SAndreas Gohr * An empty renderer, produces no output 16863befa1SAndreas Gohr * 17863befa1SAndreas Gohr * Inherits from DokuWiki_Plugin for giving additional functions to render plugins 18863befa1SAndreas Gohr */ 19863befa1SAndreas Gohrclass Doku_Renderer extends DokuWiki_Plugin { 209dc2c2afSandi var $info = array( 2144881bd0Shenning.noren 'cache' => true, // may the rendered result cached? 2244881bd0Shenning.noren 'toc' => true, // render the TOC? 239dc2c2afSandi ); 249dc2c2afSandi 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 329dc2c2afSandi function nocache() { 3344881bd0Shenning.noren $this->info['cache'] = false; 349dc2c2afSandi } 350cecf9d5Sandi 36e41c4da9SAndreas Gohr function notoc() { 3744881bd0Shenning.noren $this->info['toc'] = false; 38e41c4da9SAndreas Gohr } 39e41c4da9SAndreas Gohr 405f70445dSAndreas Gohr /** 415f70445dSAndreas Gohr * Returns the format produced by this renderer. 425f70445dSAndreas Gohr * 435f70445dSAndreas Gohr * Has to be overidden by decendend classes 445f70445dSAndreas Gohr */ 455f70445dSAndreas Gohr function getFormat(){ 465f70445dSAndreas Gohr trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING); 475f70445dSAndreas Gohr } 485f70445dSAndreas Gohr 495f70445dSAndreas Gohr 5061faf446Schris //handle plugin rendering 5161faf446Schris function plugin($name,$data){ 5261faf446Schris $plugin =& plugin_load('syntax',$name); 5361faf446Schris if($plugin != null){ 545f70445dSAndreas Gohr $plugin->render($this->getFormat(),$this,$data); 5561faf446Schris } 5661faf446Schris } 5761faf446Schris 585587e44cSchris /** 595587e44cSchris * handle nested render instructions 605587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 615587e44cSchris */ 625587e44cSchris function nest($instructions) { 635587e44cSchris 645587e44cSchris foreach ( $instructions as $instruction ) { 655587e44cSchris // execute the callback against ourself 665587e44cSchris call_user_func_array(array(&$this, $instruction[0]),$instruction[1]); 675587e44cSchris } 685587e44cSchris } 695587e44cSchris 705587e44cSchris // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should 715587e44cSchris // override this instruction when instantiating Doku_Handler_Nest - however plugins will not 725587e44cSchris // be able to - as their instructions require data. 735587e44cSchris function nest_close() {} 745587e44cSchris 750cecf9d5Sandi function document_start() {} 760cecf9d5Sandi 770cecf9d5Sandi function document_end() {} 780cecf9d5Sandi 794fced885SAndreas Gohr function render_TOC() { return ''; } 800cecf9d5Sandi 81e7856beaSchris function toc_additem($id, $text, $level) {} 82e7856beaSchris 83af587fa8Sandi function header($text, $level, $pos) {} 840cecf9d5Sandi 8535dae8b0SBen Coburn function section_edit($start, $end, $level, $name) {} 8635dae8b0SBen Coburn 870cecf9d5Sandi function section_open($level) {} 880cecf9d5Sandi 890cecf9d5Sandi function section_close() {} 900cecf9d5Sandi 910cecf9d5Sandi function cdata($text) {} 920cecf9d5Sandi 930cecf9d5Sandi function p_open() {} 940cecf9d5Sandi 950cecf9d5Sandi function p_close() {} 960cecf9d5Sandi 970cecf9d5Sandi function linebreak() {} 980cecf9d5Sandi 990cecf9d5Sandi function hr() {} 1000cecf9d5Sandi 1010cecf9d5Sandi function strong_open() {} 1020cecf9d5Sandi 1030cecf9d5Sandi function strong_close() {} 1040cecf9d5Sandi 1050cecf9d5Sandi function emphasis_open() {} 1060cecf9d5Sandi 1070cecf9d5Sandi function emphasis_close() {} 1080cecf9d5Sandi 1090cecf9d5Sandi function underline_open() {} 1100cecf9d5Sandi 1110cecf9d5Sandi function underline_close() {} 1120cecf9d5Sandi 1130cecf9d5Sandi function monospace_open() {} 1140cecf9d5Sandi 1150cecf9d5Sandi function monospace_close() {} 1160cecf9d5Sandi 1170cecf9d5Sandi function subscript_open() {} 1180cecf9d5Sandi 1190cecf9d5Sandi function subscript_close() {} 1200cecf9d5Sandi 1210cecf9d5Sandi function superscript_open() {} 1220cecf9d5Sandi 1230cecf9d5Sandi function superscript_close() {} 1240cecf9d5Sandi 1250cecf9d5Sandi function deleted_open() {} 1260cecf9d5Sandi 1270cecf9d5Sandi function deleted_close() {} 1280cecf9d5Sandi 1290cecf9d5Sandi function footnote_open() {} 1300cecf9d5Sandi 1310cecf9d5Sandi function footnote_close() {} 1320cecf9d5Sandi 1330cecf9d5Sandi function listu_open() {} 1340cecf9d5Sandi 1350cecf9d5Sandi function listu_close() {} 1360cecf9d5Sandi 1370cecf9d5Sandi function listo_open() {} 1380cecf9d5Sandi 1390cecf9d5Sandi function listo_close() {} 1400cecf9d5Sandi 1410cecf9d5Sandi function listitem_open($level) {} 1420cecf9d5Sandi 1430cecf9d5Sandi function listitem_close() {} 1440cecf9d5Sandi 145699afdebSchris function listcontent_open() {} 1460cecf9d5Sandi 1470cecf9d5Sandi function listcontent_close() {} 1480cecf9d5Sandi 1490cecf9d5Sandi function unformatted($text) {} 1500cecf9d5Sandi 1510cecf9d5Sandi function php($text) {} 1520cecf9d5Sandi 15307f89c3cSAnika Henke function phpblock($text) {} 15407f89c3cSAnika Henke 1550cecf9d5Sandi function html($text) {} 1560cecf9d5Sandi 15707f89c3cSAnika Henke function htmlblock($text) {} 15807f89c3cSAnika Henke 1590cecf9d5Sandi function preformatted($text) {} 1600cecf9d5Sandi 1610cecf9d5Sandi function file($text) {} 1620cecf9d5Sandi 1630cecf9d5Sandi function quote_open() {} 1640cecf9d5Sandi 1650cecf9d5Sandi function quote_close() {} 1660cecf9d5Sandi 1670cecf9d5Sandi function code($text, $lang = NULL) {} 1680cecf9d5Sandi 1690cecf9d5Sandi function acronym($acronym) {} 1700cecf9d5Sandi 1710cecf9d5Sandi function smiley($smiley) {} 1720cecf9d5Sandi 1730cecf9d5Sandi function wordblock($word) {} 1740cecf9d5Sandi 1750cecf9d5Sandi function entity($entity) {} 1760cecf9d5Sandi 1770cecf9d5Sandi // 640x480 ($x=640, $y=480) 1780cecf9d5Sandi function multiplyentity($x, $y) {} 1790cecf9d5Sandi 1800cecf9d5Sandi function singlequoteopening() {} 1810cecf9d5Sandi 1820cecf9d5Sandi function singlequoteclosing() {} 1830cecf9d5Sandi 18457d757d1SAndreas Gohr function apostrophe() {} 18557d757d1SAndreas Gohr 1860cecf9d5Sandi function doublequoteopening() {} 1870cecf9d5Sandi 1880cecf9d5Sandi function doublequoteclosing() {} 1890cecf9d5Sandi 1900cecf9d5Sandi // $link like 'SomePage' 1910cecf9d5Sandi function camelcaselink($link) {} 1920cecf9d5Sandi 193a939d432SAndreas Gohr function locallink($hash, $name = NULL) {} 194a939d432SAndreas Gohr 1950e1c636eSandi // $link like 'wiki:syntax', $title could be an array (media) 1960cecf9d5Sandi function internallink($link, $title = NULL) {} 1970cecf9d5Sandi 1980cecf9d5Sandi // $link is full URL with scheme, $title could be an array (media) 1990cecf9d5Sandi function externallink($link, $title = NULL) {} 2000cecf9d5Sandi 2010cecf9d5Sandi // $link is the original link - probably not much use 2020cecf9d5Sandi // $wikiName is an indentifier for the wiki 2030cecf9d5Sandi // $wikiUri is the URL fragment to append to some known URL 2040cecf9d5Sandi function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {} 2050cecf9d5Sandi 2060cecf9d5Sandi // Link to file on users OS, $title could be an array (media) 2070cecf9d5Sandi function filelink($link, $title = NULL) {} 2080cecf9d5Sandi 2090cecf9d5Sandi // Link to a Windows share, , $title could be an array (media) 2100cecf9d5Sandi function windowssharelink($link, $title = NULL) {} 2110cecf9d5Sandi 212699afdebSchris// function email($address, $title = NULL) {} 213699afdebSchris function emaillink($address, $name = NULL) {} 2140cecf9d5Sandi 215a939d432SAndreas Gohr function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 216a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 217a939d432SAndreas Gohr 218a939d432SAndreas Gohr function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 219a939d432SAndreas Gohr $height=NULL, $cache=NULL, $linking=NULL) {} 220a939d432SAndreas Gohr 2210cecf9d5Sandi function internalmedialink ( 2220cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2230cecf9d5Sandi ) {} 2240cecf9d5Sandi 2250cecf9d5Sandi function externalmedialink( 2260cecf9d5Sandi $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL 2270cecf9d5Sandi ) {} 2280cecf9d5Sandi 2290cecf9d5Sandi function table_open($maxcols = NULL, $numrows = NULL){} 2300cecf9d5Sandi 2310cecf9d5Sandi function table_close(){} 2320cecf9d5Sandi 2330cecf9d5Sandi function tablerow_open(){} 2340cecf9d5Sandi 2350cecf9d5Sandi function tablerow_close(){} 2360cecf9d5Sandi 2370cecf9d5Sandi function tableheader_open($colspan = 1, $align = NULL){} 2380cecf9d5Sandi 2390cecf9d5Sandi function tableheader_close(){} 2400cecf9d5Sandi 2410cecf9d5Sandi function tablecell_open($colspan = 1, $align = NULL){} 2420cecf9d5Sandi 2430cecf9d5Sandi function tablecell_close(){} 2440cecf9d5Sandi 2452ea4044fSAndreas Gohr 2462ea4044fSAndreas Gohr // util functions follow, you probably won't need to reimplement them 2472ea4044fSAndreas Gohr 2482ea4044fSAndreas Gohr 2492ea4044fSAndreas Gohr /** 2502ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 2512ea4044fSAndreas Gohr * casing and special chars 2522ea4044fSAndreas Gohr * 2532ea4044fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2542ea4044fSAndreas Gohr */ 2552ea4044fSAndreas Gohr function _simpleTitle($name){ 2562ea4044fSAndreas Gohr global $conf; 2572ea4044fSAndreas Gohr 2582ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 2592ea4044fSAndreas Gohr list($name,$hash) = explode('#',$name,2); 2602ea4044fSAndreas Gohr if($hash) return $hash; 2612ea4044fSAndreas Gohr 2621179df0eSGuy Brand //trim colons or slash of a namespace link 2632ea4044fSAndreas Gohr $name = rtrim($name,':'); 2641179df0eSGuy Brand if($conf['useslash']) 2651179df0eSGuy Brand $name = rtrim($name,'/'); 2662ea4044fSAndreas Gohr 2672ea4044fSAndreas Gohr if($conf['useslash']){ 2682ea4044fSAndreas Gohr $nssep = '[:;/]'; 2692ea4044fSAndreas Gohr }else{ 2702ea4044fSAndreas Gohr $nssep = '[:;]'; 2712ea4044fSAndreas Gohr } 2722ea4044fSAndreas Gohr $name = preg_replace('!.*'.$nssep.'!','',$name); 2732ea4044fSAndreas Gohr 2742ea4044fSAndreas Gohr if(!$name) return $this->_simpleTitle($conf['start']); 2752ea4044fSAndreas Gohr return $name; 2762ea4044fSAndreas Gohr } 2772ea4044fSAndreas Gohr 2781f82fabeSAndreas Gohr /** 2791f82fabeSAndreas Gohr * Resolve an interwikilink 2801f82fabeSAndreas Gohr */ 2811f82fabeSAndreas Gohr function _resolveInterWiki(&$shortcut,$reference){ 2821f82fabeSAndreas Gohr //get interwiki URL 2831f82fabeSAndreas Gohr if ( isset($this->interwiki[$shortcut]) ) { 2841f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 2851f82fabeSAndreas Gohr } else { 2861f82fabeSAndreas Gohr // Default to Google I'm feeling lucky 2871f82fabeSAndreas Gohr $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 2881f82fabeSAndreas Gohr $shortcut = 'go'; 2891f82fabeSAndreas Gohr } 2902ea4044fSAndreas Gohr 2911f82fabeSAndreas Gohr //split into hash and url part 2921f82fabeSAndreas Gohr list($wikiUri,$hash) = explode('#',$wikiUri,2); 2931f82fabeSAndreas Gohr 2941f82fabeSAndreas Gohr //replace placeholder 2951f82fabeSAndreas Gohr if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 2961f82fabeSAndreas Gohr //use placeholders 2971f82fabeSAndreas Gohr $url = str_replace('{URL}',rawurlencode($reference),$url); 2981f82fabeSAndreas Gohr $url = str_replace('{NAME}',$reference,$url); 2991f82fabeSAndreas Gohr $parsed = parse_url($reference); 3001f82fabeSAndreas Gohr if(!$parsed['port']) $parsed['port'] = 80; 3011f82fabeSAndreas Gohr $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 3021f82fabeSAndreas Gohr $url = str_replace('{HOST}',$parsed['host'],$url); 3031f82fabeSAndreas Gohr $url = str_replace('{PORT}',$parsed['port'],$url); 3041f82fabeSAndreas Gohr $url = str_replace('{PATH}',$parsed['path'],$url); 3051f82fabeSAndreas Gohr $url = str_replace('{QUERY}',$parsed['query'],$url); 3061f82fabeSAndreas Gohr }else{ 3071f82fabeSAndreas Gohr //default 3081f82fabeSAndreas Gohr $url = $url.rawurlencode($reference); 3091f82fabeSAndreas Gohr } 3101f82fabeSAndreas Gohr if($hash) $url .= '#'.rawurlencode($hash); 3111f82fabeSAndreas Gohr 3121f82fabeSAndreas Gohr return $url; 3131f82fabeSAndreas Gohr } 3140cecf9d5Sandi} 3150cecf9d5Sandi 316340756e4Sandi 3179dc2c2afSandi//Setup VIM: ex: et ts=4 enc=utf-8 : 318