From e66e6c7ed1b39ab15b49c3601890ff63beb6a2f4 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 30 Apr 2006 17:23:08 +0200 Subject: improvements to common plugin i/f update comments to work with DokuWiki's auto generated API docs. slight restructure of configuration functions and comments - loadConfig now loads plugin config settings into $conf['plugin'][] & $this->conf. These are aliases ensuring only one copy is stored. - readDefaultSettings() reads the plugin's conf/default.php darcs-hash:20060430152308-9b6ab-9ec53e79ce5b07405acb84d19d81df9dd609612e.gz --- lib/plugins/syntax.php | 85 ++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 37 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index e5e6204c4..256bf7519 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -21,6 +21,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { var $localised = false; // set to true by setupLocale() after loading language dependent strings var $lang = array(); // array to hold language dependent strings, best accessed via ->getLang() var $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables + var $conf = array(); // array to hold plugin settings, best accessed via ->getConf() /** * General Info @@ -211,46 +212,56 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { $this->localised = true; } - // configuration methods - /** - * getConf($id) - * - * use this function to access plugin configuration variables - */ - function getConf($id){ - global $conf; - - $plugin = $this->getPluginName(); - - if (!$this->configloaded){ - if ($pconf = $this->loadConfig() !== false){ - foreach ($pconf as $key => $value){ - if (isset($conf['plugin'][$plugin][$key])) continue; - $conf['plugin'][$plugin][$key] = $value; - } - $this->configloaded = true; - } - } + // configuration methods + /** + * getConf($setting) + * + * use this function to access plugin configuration variables + */ + function getConf($setting){ + + if (!$this->configloaded){ $this->loadConfig(); } + + return $this->conf[$setting]; + } - return $conf['plugin'][$plugin][$id]; + /** + * loadConfig() + * merges the plugin's default settings with any local settings + * this function is automatically called through getConf() + */ + function loadConfig(){ + global $conf; + + $defaults = $this->readDefaultSettings(); + $plugin = $this->getPluginName(); + + foreach ($defaults as $key => $value) { + if (isset($conf['plugin'][$plugin][$key])) continue; + $conf['plugin'][$plugin][$key] = $value; } - - /** - * loadConfig() - * reads all plugin configuration variables into $this->conf - * this function is automatically called by getConf() - */ - function loadConfig(){ - $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; - $conf = array(); - - if (!@file_exists($path.'default.php')) return false; - - // load default config file + + $this->configloaded = true; + $this->conf =& $conf['plugin'][$plugin]; + } + + /** + * read the plugin's default configuration settings from conf/default.php + * this function is automatically called through getConf() + * + * @return array setting => value + */ + function readDefaultSettings() { + + $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; + $conf = array(); + + if (@file_exists($path.'default.php')) { include($path.'default.php'); - - return $conf; } - + + return $conf; + } + } //Setup VIM: ex: et ts=4 enc=utf-8 : -- cgit v1.2.3