*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kite
* @based_on "externallink" plugin by Otto Vainio
*/
if(!defined('DOKU_INC')) {
define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
}
if(!defined('DOKU_PLUGIN')) {
define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
}
require_once(DOKU_PLUGIN.'syntax.php');
function eval_form_php($arr) {
global $INFO;
if(0 and ($INFO['perm'] == AUTH_ADMIN)) { // Use debug output??
ob_start();
$content = "\n";
echo $content; // can't return this
}
ob_start();
if($INFO['perm'] == AUTH_ADMIN) {
eval("?>$arr"); // not $arr -- now allows parsing all PHP blocks
} else {
@eval("?>$arr"); // not $arr -- now allows parsing all PHP blocks
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_incl_form extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Kite',
'email' => 'kite@puzzlers.org',
'date' => '2006-09-02',
'name' => 'Include Form',
'desc' => 'Includes an approved form into a page.',
'url' => 'http://www.dokuwiki.org/wiki:plugins:incl_form',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
// Just before build in links
function getSort(){ return 299; }
/**
* What about paragraphs?
*/
function getPType(){
return 'block';
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~INCL_FORM[^~]*~~',$mode,'plugin_incl_form');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
// Remove the tag itself, and then separate the form name
// from the parameter set.
$match = preg_replace("%~~INCL_FORM(=(.*))?~~%u", "\\2", $match);
//echo "\n\t\n";
return $match;
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
$FORM_PARAMS = split(';', $data);
$text=$this->_inc_form($FORM_PARAMS[0], $FORM_PARAMS);
$renderer->doc .= $text;
return true;
}
return false;
}
//Translate an ID into a form file name
//path is relative to the DokuWiki root (I use data/forms)
function formFN($id,$rev=''){
global $conf;
if(empty($rev)){
$id = cleanID($id);
$id = str_replace(':','/',$id);
$fn = $conf['formdir'].'/'.utf8_encodeFN($id).'.php';
}
return $fn;
} // formFN()
function _inc_form($form, $PARAMS) {
global $FORM_PARAMS;
global $ID;
if(strlen($form) < 1) {
$form = $ID; // default to the current page ID
}
// Break the form parameters (if any) into name/values
$path = $this->formFN($form);
foreach($PARAMS as $item) {
// split the pair
$parts = explode('=', $item);
// Skip the $ID parameter
if(strlen($parts[0])>0) {
$FORM_PARAMS[$parts[0]] = $parts[1];
}
}
if(file_exists(DOKU_INC . $path)) {
//echo "\n";
$text = io_readFile($path);
$pattern = "/(<\?php)(.*?)(\?>)/is";
$text = eval_form_php($text);
} else {
$text = "\n\t\n";
}
return $text;
} // _inc_form()
} // syntax_plugin_INCL_FORM
?>
===== Sample Form =====
Member Email Changes
\n";
echo " \n";
echo " \n";
echo " \n";
} else { // Main IF() { form } else { thanks }
echo "Thank you.
\n";
echo "
\n";
echo "Your request has been sent to the \n";
echo "postmaster and \n";
echo "webmaster.
\n";
echo " Your request will be addressed as soon as possible.
\n";
echo "
\n";
echo "Webmaster@nomail.org \n";
echo "
\n";
} // End of the Main IF() { form } else { thanks }
?>
==== Some notes on the Sample ====
**Expanded** Sept 30, 2006