PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/www/wiki/inc/parser/renderer.php

https://github.com/micz/elencode
PHP | 322 lines | 163 code | 103 blank | 56 comment | 12 complexity | cbe280165a29d343c65174c611dd3d70 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Renderer output base class
  4. *
  5. * @author Harry Fuecks <hfuecks@gmail.com>
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. */
  8. if(!defined('DOKU_INC')) die('meh.');
  9. require_once DOKU_INC . 'inc/parser/renderer.php';
  10. require_once DOKU_INC . 'inc/plugin.php';
  11. require_once DOKU_INC . 'inc/pluginutils.php';
  12. /**
  13. * An empty renderer, produces no output
  14. *
  15. * Inherits from DokuWiki_Plugin for giving additional functions to render plugins
  16. */
  17. class Doku_Renderer extends DokuWiki_Plugin {
  18. var $info = array(
  19. 'cache' => true, // may the rendered result cached?
  20. 'toc' => true, // render the TOC?
  21. );
  22. // keep some config options
  23. var $acronyms = array();
  24. var $smileys = array();
  25. var $badwords = array();
  26. var $entities = array();
  27. var $interwiki = array();
  28. // allows renderer to be used again, clean out any per-use values
  29. function reset() {
  30. }
  31. function nocache() {
  32. $this->info['cache'] = false;
  33. }
  34. function notoc() {
  35. $this->info['toc'] = false;
  36. }
  37. /**
  38. * Returns the format produced by this renderer.
  39. *
  40. * Has to be overidden by decendend classes
  41. */
  42. function getFormat(){
  43. trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
  44. }
  45. //handle plugin rendering
  46. function plugin($name,$data){
  47. $plugin =& plugin_load('syntax',$name);
  48. if($plugin != null){
  49. $plugin->render($this->getFormat(),$this,$data);
  50. }
  51. }
  52. /**
  53. * handle nested render instructions
  54. * this method (and nest_close method) should not be overloaded in actual renderer output classes
  55. */
  56. function nest($instructions) {
  57. foreach ( $instructions as $instruction ) {
  58. // execute the callback against ourself
  59. call_user_func_array(array(&$this, $instruction[0]),$instruction[1]);
  60. }
  61. }
  62. // dummy closing instruction issued by Doku_Handler_Nest, normally the syntax mode should
  63. // override this instruction when instantiating Doku_Handler_Nest - however plugins will not
  64. // be able to - as their instructions require data.
  65. function nest_close() {}
  66. function document_start() {}
  67. function document_end() {}
  68. function render_TOC() { return ''; }
  69. function toc_additem($id, $text, $level) {}
  70. function header($text, $level, $pos) {}
  71. function section_edit($start, $end, $level, $name) {}
  72. function section_open($level) {}
  73. function section_close() {}
  74. function cdata($text) {}
  75. function p_open() {}
  76. function p_close() {}
  77. function linebreak() {}
  78. function hr() {}
  79. function strong_open() {}
  80. function strong_close() {}
  81. function emphasis_open() {}
  82. function emphasis_close() {}
  83. function underline_open() {}
  84. function underline_close() {}
  85. function monospace_open() {}
  86. function monospace_close() {}
  87. function subscript_open() {}
  88. function subscript_close() {}
  89. function superscript_open() {}
  90. function superscript_close() {}
  91. function deleted_open() {}
  92. function deleted_close() {}
  93. function footnote_open() {}
  94. function footnote_close() {}
  95. function listu_open() {}
  96. function listu_close() {}
  97. function listo_open() {}
  98. function listo_close() {}
  99. function listitem_open($level) {}
  100. function listitem_close() {}
  101. function listcontent_open() {}
  102. function listcontent_close() {}
  103. function unformatted($text) {}
  104. function php($text) {}
  105. function phpblock($text) {}
  106. function html($text) {}
  107. function htmlblock($text) {}
  108. function preformatted($text) {}
  109. function file($text) {}
  110. function quote_open() {}
  111. function quote_close() {}
  112. function code($text, $lang = NULL) {}
  113. function acronym($acronym) {}
  114. function smiley($smiley) {}
  115. function wordblock($word) {}
  116. function entity($entity) {}
  117. // 640x480 ($x=640, $y=480)
  118. function multiplyentity($x, $y) {}
  119. function singlequoteopening() {}
  120. function singlequoteclosing() {}
  121. function apostrophe() {}
  122. function doublequoteopening() {}
  123. function doublequoteclosing() {}
  124. // $link like 'SomePage'
  125. function camelcaselink($link) {}
  126. function locallink($hash, $name = NULL) {}
  127. // $link like 'wiki:syntax', $title could be an array (media)
  128. function internallink($link, $title = NULL) {}
  129. // $link is full URL with scheme, $title could be an array (media)
  130. function externallink($link, $title = NULL) {}
  131. function rss ($url,$params) {}
  132. // $link is the original link - probably not much use
  133. // $wikiName is an indentifier for the wiki
  134. // $wikiUri is the URL fragment to append to some known URL
  135. function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {}
  136. // Link to file on users OS, $title could be an array (media)
  137. function filelink($link, $title = NULL) {}
  138. // Link to a Windows share, , $title could be an array (media)
  139. function windowssharelink($link, $title = NULL) {}
  140. // function email($address, $title = NULL) {}
  141. function emaillink($address, $name = NULL) {}
  142. function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
  143. $height=NULL, $cache=NULL, $linking=NULL) {}
  144. function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
  145. $height=NULL, $cache=NULL, $linking=NULL) {}
  146. function internalmedialink (
  147. $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
  148. ) {}
  149. function externalmedialink(
  150. $src,$title=NULL,$align=NULL,$width=NULL,$height=NULL,$cache=NULL
  151. ) {}
  152. function table_open($maxcols = NULL, $numrows = NULL){}
  153. function table_close(){}
  154. function tablerow_open(){}
  155. function tablerow_close(){}
  156. function tableheader_open($colspan = 1, $align = NULL){}
  157. function tableheader_close(){}
  158. function tablecell_open($colspan = 1, $align = NULL){}
  159. function tablecell_close(){}
  160. // util functions follow, you probably won't need to reimplement them
  161. /**
  162. * Removes any Namespace from the given name but keeps
  163. * casing and special chars
  164. *
  165. * @author Andreas Gohr <andi@splitbrain.org>
  166. */
  167. function _simpleTitle($name){
  168. global $conf;
  169. //if there is a hash we use the ancor name only
  170. list($name,$hash) = explode('#',$name,2);
  171. if($hash) return $hash;
  172. //trim colons or slash of a namespace link
  173. $name = rtrim($name,':');
  174. if($conf['useslash'])
  175. $name = rtrim($name,'/');
  176. if($conf['useslash']){
  177. $nssep = '[:;/]';
  178. }else{
  179. $nssep = '[:;]';
  180. }
  181. $name = preg_replace('!.*'.$nssep.'!','',$name);
  182. if(!$name) return $this->_simpleTitle($conf['start']);
  183. return $name;
  184. }
  185. /**
  186. * Resolve an interwikilink
  187. */
  188. function _resolveInterWiki(&$shortcut,$reference){
  189. //get interwiki URL
  190. if ( isset($this->interwiki[$shortcut]) ) {
  191. $url = $this->interwiki[$shortcut];
  192. } else {
  193. // Default to Google I'm feeling lucky
  194. $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
  195. $shortcut = 'go';
  196. }
  197. //split into hash and url part
  198. list($wikiUri,$hash) = explode('#',$wikiUri,2);
  199. //replace placeholder
  200. if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
  201. //use placeholders
  202. $url = str_replace('{URL}',rawurlencode($reference),$url);
  203. $url = str_replace('{NAME}',$reference,$url);
  204. $parsed = parse_url($reference);
  205. if(!$parsed['port']) $parsed['port'] = 80;
  206. $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
  207. $url = str_replace('{HOST}',$parsed['host'],$url);
  208. $url = str_replace('{PORT}',$parsed['port'],$url);
  209. $url = str_replace('{PATH}',$parsed['path'],$url);
  210. $url = str_replace('{QUERY}',$parsed['query'],$url);
  211. }else{
  212. //default
  213. $url = $url.rawurlencode($reference);
  214. }
  215. if($hash) $url .= '#'.rawurlencode($hash);
  216. return $url;
  217. }
  218. }
  219. //Setup VIM: ex: et ts=4 enc=utf-8 :