1<?php 2/** 3 * PHP-Wikify plugin: lets the parser wikify output of php scripts 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Kasper Sandberg <redeeman@metanurb.dk> 7 * @author Schplurtz le Déboulonné <Schplurtz@laposte.net> 8 * @author Trailjeep <trailjeep@gmail.com> 9 */ 10 11// must be run within Dokuwiki 12if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14require_once(DOKU_PLUGIN.'syntax.php'); 15 16/** 17 * All DokuWiki plugins to extend the parser/rendering mechanism 18 * need to inherit from this class 19 */ 20class syntax_plugin_phpwikify extends DokuWiki_Syntax_Plugin { 21 function syntax_plugin_phpwikify() { global $PARSER_MODES; $this->allowedModes = $PARSER_MODES['formatting']; } 22 function getType() { return "protected"; } 23 function getPType() { return "normal"; } 24 function getSort() { return 0; } 25 function connectTo( $mode ) { $this->Lexer->addEntryPattern("<phpwikify>(?=.*?</phpwikify>)",$mode,"plugin_phpwikify"); } 26 function postConnect() { $this->Lexer->addExitPattern( "</phpwikify>","plugin_phpwikify"); } 27 28 /** 29 * Handle the match 30 */ 31 function handle( $match, $state, $pos, Doku_Handler $handler ) { 32 switch($state) { 33 case DOKU_LEXER_UNMATCHED : 34 return array($state,$match); 35 } 36 } 37 38 /** 39 * Create output 40 */ 41 function render( $mode, Doku_Renderer $renderer, $data ) { 42 if($mode == 'xhtml'){ 43 list($state, $data) = $data; 44 ob_start(); 45 eval( $data ); 46 $renderer->doc .= p_render( "xhtml", p_get_instructions( ob_get_contents() ), $info ); 47 ob_end_clean(); 48 return true; 49 } 50 return false; 51 } 52} 53//Setup VIM: ex: et ts=4 enc=utf-8 : 54