* * Suggested new PmWiki setup/initialisation system, to replace current system * which is highly dependend on the order in which script are included * * To test, download this file to your cookbook and rename as 'setup.php', * then add the following to your config file: include_once("$FarmD/cookbook/setup.php"); * Next, use ?action=setuprules on any wiki page for a demonstration * * For more information, please see the PITS entry at * http://www.pmwiki.org/wiki/PITS/01132 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License, * Version 2, as published by the Free Software Foundation. * http://www.gnu.org/copyleft/gpl.html */ $SetupTable['_begin']['seq'] = 'B'; $SetupTable['_end']['seq'] = 'E'; Setup('fulltext','>_begin'); Setup('split','>fulltext',"$FarmD/scripts/version.php",'one'); Setup('directives','>split'); Setup('inline','>directives'); Setup('links','>inline'); Setup('block','>links'); Setup('style','>block'); Setup('closeall', '_begin','',"two"); Setup('[=','_begin','',"three"); Setup('restore','<_end','','four'); Setup('<:', '>restore','','five'); Setup('', '

', '<', '',"seven"); Setup('\\r','<[=','','eight'); Setup('$[phrase]', '>[=', "$FarmD/cookbook/setup.php","nine"); Setup('{$var}', '>$[phrase]', '',"ten"); function one() { echo "fn:one\n"; } function two() { echo "fn:two\n"; } function three() { echo "fn:three\n"; } function four() { echo "fn:four\n"; } function five() { echo "fn:five\n"; } function six() { echo "fn:six\n"; } function seven() { echo "fn:seven\n"; } function eight() { echo "fn:eight\n"; } function nine() { echo "fn:nine\n"; } function ten() { echo "fn:ten\n"; } function Setup($id, $when, $inc=NULL, $fn=NULL) { global $SetupTable; if (preg_match('/^([<>])?(.+)$/', $when, $m)) { $SetupTable[$id]['cmd'] = $when; $SetupTable[$m[2]]['dep'][$id] = $m[1]; if (!$m[1]) $m[1] = '='; if (@$SetupTable[$m[2]]['seq']) { $SetupTable[$id]['seq'] = $SetupTable[$m[2]]['seq'].$m[1]; foreach((array)@$SetupTable[$id]['dep'] as $i=>$m) Setup($i,"$m$id"); unset($SetupTable[$id]['dep']); } } if (($inc||$fn) && !isset($SetupTable[$id]['fn'])) { $SetupTable[$id]['inc'] = $inc; $SetupTable[$id]['fn'] = $fn; } } function DisableSetup() { global $SetupTable; $idlist = func_get_args(); while (count($idlist)>0) { $id = array_shift($idlist); if (is_array($id)) { $idlist = array_merge($idlist, $id); continue; } $SetupTable[$id] = array('inc' => '','fn' => ''); } } function RunSetup() { global $SetupTable; uasort($SetupTable,'mpcmp'); foreach($SetupTable as $id=>$m) { if (!empty($m['inc'])) include_once($m['inc']); if (!empty($m['fn'])) $m['fn'](); } } $HandleActions['setuprules'] = 'HandleSetupRuleset'; function HandleSetupRuleset($pagename) { global $SetupTable; header("Content-type: text/plain"); RunSetup(); echo "\n"; foreach($SetupTable as $id=>$m) printf("%-16s %-16s %-16s %-16s %-16s\n",$id,@$m['cmd'],@$m['seq'],@$m['fn'],@$m['inc']); }