summaryrefslogtreecommitdiff
path: root/inc/common.php
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2011-02-03 16:12:32 +0100
committerAndreas Gohr <gohr@cosmocode.de>2011-02-03 16:17:23 +0100
commit7b84afa2e557a05fcd900a1cbf5715a6988828dc (patch)
treedd6ddc1f0dba8bf170efcde421390ef787dc9da0 /inc/common.php
parente24ab4ab794093b0d9ca1095e321b04f9cd956d6 (diff)
downloadrpg-7b84afa2e557a05fcd900a1cbf5715a6988828dc.tar.gz
rpg-7b84afa2e557a05fcd900a1cbf5715a6988828dc.tar.bz2
Replace COMMON_PAGE_FROMTEMPLATE with COMMON_PAGETPL_LOAD event
As discussed on the mailing list [1] this patch replaces the COMMON_PAGE_FROMTEMPLATE with a more flexible event to better intercept page template use. Plugin authors need to change their plugins. Details on the event are available at [2] [1] http://www.freelists.org/post/dokuwiki/COMMON-PAGE-FROMTEMPLATE-event [2] http://www.dokuwiki.org/devel:event:common_pagetpl_load
Diffstat (limited to 'inc/common.php')
-rw-r--r--inc/common.php53
1 files changed, 37 insertions, 16 deletions
diff --git a/inc/common.php b/inc/common.php
index b4866bccf..eab5f1129 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -804,7 +804,7 @@ function rawWiki($id,$rev=''){
/**
* Returns the pagetemplate contents for the ID's namespace
*
- * @triggers COMMON_PAGE_FROMTEMPLATE
+ * @triggers COMMON_PAGETPL_LOAD
* @author Andreas Gohr <andi@splitbrain.org>
*/
function pageTemplate($id){
@@ -812,29 +812,50 @@ function pageTemplate($id){
if (is_array($id)) $id = $id[0];
- $path = dirname(wikiFN($id));
- $tpl = '';
- 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;
+ // prepare initial event data
+ $data = array(
+ 'id' => $id, // the id of the page to be created
+ 'tpl' => '', // the text used as template
+ 'tplfile' => '', // the file above text was/should be loaded from
+ 'doreplace' => true // should wildcard replacements be done on the text?
+ );
+
+ $evt = new Doku_Event('COMMON_PAGETPL_LOAD',$data);
+ if($evt->advise_before(true)){
+ // the before event might have loaded the content already
+ if(empty($data['tpl'])){
+ // if the before event did not set a template file, try to find one
+ if(empty($data['tplfile'])){
+ $path = dirname(wikiFN($id));
+ $tpl = '';
+ if(@file_exists($path.'/_template.txt')){
+ $data['tplfile'] = $path.'/_template.txt';
+ }else{
+ // search upper namespaces for templates
+ $len = strlen(rtrim($conf['datadir'],'/'));
+ while (strlen($path) >= $len){
+ if(@file_exists($path.'/__template.txt')){
+ $data['tplfile'] = $path.'/__template.txt';
+ break;
+ }
+ $path = substr($path, 0, strrpos($path, '/'));
+ }
+ }
}
- $path = substr($path, 0, strrpos($path, '/'));
+ // load the content
+ $data['tpl'] = io_readFile($data['tpl']);
}
+ if($data['doreplace']) parsePageTemplate(&$data);
}
- $data = compact('tpl', 'id');
- trigger_event('COMMON_PAGE_FROMTEMPLATE', $data, 'parsePageTemplate', true);
+ $evt->advise_after();
+ unset($evt);
+
return $data['tpl'];
}
/**
* Performs common page template replacements
- * This is the default action for COMMON_PAGE_FROMTEMPLATE
+ * This works on data from COMMON_PAGETPL_LOAD
*
* @author Andreas Gohr <andi@splitbrain.org>
*/