1*1db3bf9aScziehr<?php 2*1db3bf9aScziehr/** 3*1db3bf9aScziehr * Plugin Include Form: include external, approved PHP forms 4*1db3bf9aScziehr * Updated April 19, 2007 by Kite <Kite@puzzlers.org> 5*1db3bf9aScziehr * 6*1db3bf9aScziehr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7*1db3bf9aScziehr * @author Kite <Kite@puzzlers.org> 8*1db3bf9aScziehr * @based_on "externallink" plugin by Otto Vainio <plugins@valjakko.net> 9*1db3bf9aScziehr */ 10*1db3bf9aScziehr 11*1db3bf9aScziehrif(!defined('DOKU_INC')) { 12*1db3bf9aScziehr define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 13*1db3bf9aScziehr} 14*1db3bf9aScziehrif(!defined('DOKU_PLUGIN')) { 15*1db3bf9aScziehr define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 16*1db3bf9aScziehr} 17*1db3bf9aScziehr 18*1db3bf9aScziehrrequire_once(DOKU_PLUGIN.'syntax.php'); 19*1db3bf9aScziehr 20*1db3bf9aScziehr 21*1db3bf9aScziehrfunction eval_form_php($arr) { 22*1db3bf9aScziehr global $INFO; 23*1db3bf9aScziehr 24*1db3bf9aScziehr if(0 and ($INFO['perm'] == AUTH_ADMIN)) { // Use debug output?? 25*1db3bf9aScziehr ob_start(); 26*1db3bf9aScziehr $content = "<!-- Content: "; 27*1db3bf9aScziehr print_r( $arr ); 28*1db3bf9aScziehr $content .= ob_get_contents(); 29*1db3bf9aScziehr ob_end_clean(); 30*1db3bf9aScziehr $content .= " -->\n"; 31*1db3bf9aScziehr echo $content; // can't return this 32*1db3bf9aScziehr } 33*1db3bf9aScziehr ob_start(); 34*1db3bf9aScziehr if($INFO['perm'] == AUTH_ADMIN) { 35*1db3bf9aScziehr eval("?>$arr"); // not $arr -- now allows parsing all PHP blocks 36*1db3bf9aScziehr } else { 37*1db3bf9aScziehr @eval("?>$arr"); // not $arr -- now allows parsing all PHP blocks 38*1db3bf9aScziehr } 39*1db3bf9aScziehr $content = ob_get_contents(); 40*1db3bf9aScziehr ob_end_clean(); 41*1db3bf9aScziehr return $content; 42*1db3bf9aScziehr} 43*1db3bf9aScziehr 44*1db3bf9aScziehr/** 45*1db3bf9aScziehr * All DokuWiki plugins to extend the parser/rendering mechanism 46*1db3bf9aScziehr * need to inherit from this class 47*1db3bf9aScziehr */ 48*1db3bf9aScziehrclass syntax_plugin_inclform extends DokuWiki_Syntax_Plugin { 49*1db3bf9aScziehr 50*1db3bf9aScziehr /** 51*1db3bf9aScziehr * return some info 52*1db3bf9aScziehr */ 53*1db3bf9aScziehr function getInfo(){ 54*1db3bf9aScziehr return array( 55*1db3bf9aScziehr 'author' => 'Kite', 56*1db3bf9aScziehr 'email' => 'kite@puzzlers.org', 57*1db3bf9aScziehr 'date' => '2006-09-02', 58*1db3bf9aScziehr 'name' => 'Include Form', 59*1db3bf9aScziehr 'desc' => 'Includes an approved form into a page.', 60*1db3bf9aScziehr 'url' => 'http://www.dokuwiki.org/wiki:plugins:incl_form', 61*1db3bf9aScziehr ); 62*1db3bf9aScziehr } 63*1db3bf9aScziehr 64*1db3bf9aScziehr /** 65*1db3bf9aScziehr * What kind of syntax are we? 66*1db3bf9aScziehr */ 67*1db3bf9aScziehr function getType(){ 68*1db3bf9aScziehr return 'substition'; 69*1db3bf9aScziehr } 70*1db3bf9aScziehr 71*1db3bf9aScziehr // Just before build in links 72*1db3bf9aScziehr function getSort(){ return 299; } 73*1db3bf9aScziehr 74*1db3bf9aScziehr /** 75*1db3bf9aScziehr * What about paragraphs? 76*1db3bf9aScziehr */ 77*1db3bf9aScziehr function getPType(){ 78*1db3bf9aScziehr return 'block'; 79*1db3bf9aScziehr } 80*1db3bf9aScziehr 81*1db3bf9aScziehr function connectTo($mode) { 82*1db3bf9aScziehr $this->Lexer->addSpecialPattern('~~INCLFORM[^~]*~~',$mode,'plugin_inclform'); 83*1db3bf9aScziehr } 84*1db3bf9aScziehr 85*1db3bf9aScziehr 86*1db3bf9aScziehr /** 87*1db3bf9aScziehr * Handle the match 88*1db3bf9aScziehr */ 89*1db3bf9aScziehr function handle($match, $state, $pos, Doku_Handler $handler){ 90*1db3bf9aScziehr // Remove the tag itself, and then separate the form name 91*1db3bf9aScziehr // from the parameter set. 92*1db3bf9aScziehr $match = preg_replace("%~~INCLFORM(=(.*))?~~%u", "\\2", $match); 93*1db3bf9aScziehr //echo "\n\t<!-- syntax_plugin_INCLFORM.handle() found >> $match << -->\n"; 94*1db3bf9aScziehr return $match; 95*1db3bf9aScziehr } 96*1db3bf9aScziehr 97*1db3bf9aScziehr /** 98*1db3bf9aScziehr * Create output 99*1db3bf9aScziehr */ 100*1db3bf9aScziehr function render($mode, Doku_Renderer $renderer, $data) { 101*1db3bf9aScziehr if($mode == 'xhtml'){ 102*1db3bf9aScziehr $FORM_PARAMS = explode(';', $data); 103*1db3bf9aScziehr $text=$this->_inc_form($FORM_PARAMS[0], $FORM_PARAMS); 104*1db3bf9aScziehr $renderer->doc .= $text; 105*1db3bf9aScziehr return true; 106*1db3bf9aScziehr } 107*1db3bf9aScziehr return false; 108*1db3bf9aScziehr } 109*1db3bf9aScziehr 110*1db3bf9aScziehr 111*1db3bf9aScziehr //Translate an ID into a form file name 112*1db3bf9aScziehr //path is relative to the DokuWiki root (I use data/forms) 113*1db3bf9aScziehr function formFN($id,$rev=''){ 114*1db3bf9aScziehr global $conf; 115*1db3bf9aScziehr if(empty($rev)){ 116*1db3bf9aScziehr $id = cleanID($id); 117*1db3bf9aScziehr $id = str_replace(':','/',$id); 118*1db3bf9aScziehr $fn = $conf['formdir'].'/'.utf8_encodeFN($id).'.php'; 119*1db3bf9aScziehr } 120*1db3bf9aScziehr return $fn; 121*1db3bf9aScziehr } // formFN() 122*1db3bf9aScziehr 123*1db3bf9aScziehr function _inc_form($form, $PARAMS) { 124*1db3bf9aScziehr global $FORM_PARAMS; 125*1db3bf9aScziehr global $ID; 126*1db3bf9aScziehr if(strlen($form) < 1) { 127*1db3bf9aScziehr $form = $ID; // default to the current page ID 128*1db3bf9aScziehr } 129*1db3bf9aScziehr // Break the form parameters (if any) into name/values 130*1db3bf9aScziehr $path = $this->formFN($form); 131*1db3bf9aScziehr foreach($PARAMS as $item) { 132*1db3bf9aScziehr // split the pair 133*1db3bf9aScziehr $parts = explode('=', $item); 134*1db3bf9aScziehr // Skip the $ID parameter 135*1db3bf9aScziehr if(strlen($parts[0])>0) { 136*1db3bf9aScziehr $FORM_PARAMS[$parts[0]] = $parts[1]; 137*1db3bf9aScziehr } 138*1db3bf9aScziehr } 139*1db3bf9aScziehr if(file_exists(DOKU_INC . $path)) { 140*1db3bf9aScziehr //echo "<!-- form was found -->\n"; 141*1db3bf9aScziehr $text = io_readFile($path); 142*1db3bf9aScziehr $pattern = "/(<\?php)(.*?)(\?>)/is"; 143*1db3bf9aScziehr $text = eval_form_php($text); 144*1db3bf9aScziehr } else { 145*1db3bf9aScziehr $text = "\n\t<!-- No form found for '$form'-->\n"; 146*1db3bf9aScziehr } 147*1db3bf9aScziehr return $text; 148*1db3bf9aScziehr } // _inc_form() 149*1db3bf9aScziehr} // syntax_plugin_INCLFORM 150*1db3bf9aScziehr?> 151