Hi,
I have to modify a Plugin and for this, I first have to investigate how does it work. My Knowledge in php is low and I don't know how Plugins in dokuwiki works exactly.
In the Code below I added two lines for debugging.
The first below entry
function Register()
dbglog("PLUGIN REGEX_TEMPLATE REGISTERED!");
The second below entry
function regex_template()
dbglog("PLUGIN REGEX_TEMPLATE CALLED!");
Then I tried to use the Plugin ...
Now my Question: The debug.log only shows me entries for PLUGIN REGEX_TEMPLATE REGISTERED! but I never see an entry for PLUGIN REGEX_TEMPLATE CALLED!
This means, that the Plugin would not be invoked?
Why?
Any help are welcome.
Kind regards,
Roland
<?php
/**
* Regex Template plugin, Choose template from regex on $ID
* @author Cédric Villemain <cedric.villemain@dalibo.com>
*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_regextemplate extends DokuWiki_Action_Plugin {
/**
* return some info
*/
function getInfo(){
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
/**
* register the eventhandlers
*/
function register(Doku_Event_Handler $controller){
$controller->register_hook('COMMON_PAGETPL_LOAD', 'BEFORE', $this, 'regex_template', array());
dbglog("PLUGIN REGEX_TEMPLATE REGISTERED!");
}
function regex_template(Doku_Event $event, $param) {
global $ID;
global $conf;
global $INFO;
dbglog("PLUGIN REGEX_TEMPLATE CALLED!");
$path = dirname(wikiFN($ID));
if(@file_exists($path.'/_template.txt')){
$tpl = io_readFile($path.'/_template.txt');
}else{
// search upper namespaces for templates
$len = strlen(rtrim($conf['datadir'],'/'));
while (strlen($path) >= $len){
if(@file_exists($path.'/__template.txt')){
$tpl = io_readFile($path.'/__template.txt');
break;
}
$path = substr($path, 0, strrpos($path, '/'));
}
}
$array_regex = (array)explode("\n",$conf['plugin']['regex_template']['reg_tpl_regex']);
reset($array_regex);
foreach ($array_regex as $regex) {
list($pattern, $replacement) = explode(',', $regex);
$my_new_ID = @preg_replace($pattern, $replacement, $event->data['id']);
$my_new_file = wikiFN($my_new_ID);
if(@file_exists($my_new_file)){
$tpl = io_readFile($my_new_file);
break;
}
}
//if(!$tpl) return '';
if($tpl) $event->data['tpl'] = $tpl;
// replace placeholders
$tpl = str_replace('@ID@',$ID,$tpl);
$tpl = str_replace('@NS@',getNS($ID),$tpl);
$tpl = str_replace('@PAGE@',strtr(noNS($ID),'_',' '),$tpl);
$tpl = str_replace('@USER@',$_SERVER['REMOTE_USER'],$tpl);
$tpl = str_replace('@NAME@',$INFO['userinfo']['name'],$tpl);
$tpl = str_replace('@MAIL@',$INFO['userinfo']['mail'],$tpl);
$tpl = str_replace('@DATE@',$conf['dformat'],$tpl);
// we need the callback to work around strftime's char limit
$tpl = preg_replace_callback('/%./',create_function('$m','return strftime($m[0]);'),$tpl);
$event->result=$tpl;
$event->preventDefault();
}
}