Skip to content
Snippets Groups Projects
Commit f1f77134 authored by Esther Brunner's avatar Esther Brunner
Browse files

methods for loading config variables in syntax and amin plugins

darcs-hash:20060322110832-283c4-d8e56c241f8a34827f1c188c4db7162ef658e010.gz
parent 902ea3be
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ class DokuWiki_Admin_Plugin { ...@@ -16,6 +16,7 @@ class DokuWiki_Admin_Plugin {
var $localised = false; // set to true by setupLocale() after loading language dependent strings 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 $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
/** /**
* General Info * General Info
...@@ -129,6 +130,48 @@ class DokuWiki_Admin_Plugin { ...@@ -129,6 +130,48 @@ class DokuWiki_Admin_Plugin {
$this->localised = true; $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;
}
}
return $conf['plugin'][$plugin][$id];
}
/**
* 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
include($path.'default.php');
return $conf;
}
// standard functions for outputing email addresses and links // standard functions for outputing email addresses and links
// use these to avoid having to duplicate code to produce links in line with the installation configuration // use these to avoid having to duplicate code to produce links in line with the installation configuration
function email($email, $name='', $class='', $more='') { function email($email, $name='', $class='', $more='') {
......
...@@ -94,7 +94,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ...@@ -94,7 +94,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
global $ID; global $ID;
if (is_null($this->_config)) { $this->_config = new configuration($this->_file); } if (is_null($this->_config)) { $this->_config = new configuration($this->_file); }
$this->setupLocale(true); $this->setupLocale(true);
print $this->locale_xhtml('intro'); print $this->locale_xhtml('intro');
...@@ -190,7 +190,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ...@@ -190,7 +190,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
$langfile = '/lang/'.$conf[lang].'/settings.php'; $langfile = '/lang/'.$conf[lang].'/settings.php';
$enlangfile = '/lang/en/settings.php'; $enlangfile = '/lang/en/settings.php';
$lang = array(); $lang = array();
if ($dh = opendir(DOKU_PLUGIN)) { if ($dh = opendir(DOKU_PLUGIN)) {
while (false !== ($plugin = readdir($dh))) { while (false !== ($plugin = readdir($dh))) {
...@@ -198,13 +198,15 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ...@@ -198,13 +198,15 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
if (is_file(DOKU_PLUGIN.$plugin)) continue; if (is_file(DOKU_PLUGIN.$plugin)) continue;
if (@file_exists(DOKU_PLUGIN.$plugin.$enlangfile)){ if (@file_exists(DOKU_PLUGIN.$plugin.$enlangfile)){
$lang = array();
@include(DOKU_PLUGIN.$plugin.$enlangfile); @include(DOKU_PLUGIN.$plugin.$enlangfile);
if ($conf['lang'] != 'en') @include(DOKU_PLUGIN.$plugin.$langfile); if ($conf['lang'] != 'en') @include(DOKU_PLUGIN.$plugin.$langfile);
foreach ($lang as $key => $value){
$this->lang['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
}
} }
} }
closedir($dh); closedir($dh);
$this->lang = array_merge($lang, $this->lang);
} }
return true; return true;
......
...@@ -17,8 +17,9 @@ require_once(DOKU_INC.'inc/parser/parser.php'); ...@@ -17,8 +17,9 @@ require_once(DOKU_INC.'inc/parser/parser.php');
class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode {
var $allowedModesSetup = false; var $allowedModesSetup = false;
var $localised = false; // set to true by setupLocale() after loading language dependent strings 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 $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
/** /**
* General Info * General Info
...@@ -208,6 +209,47 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { ...@@ -208,6 +209,47 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode {
$this->lang = $lang; $this->lang = $lang;
$this->localised = true; $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;
}
}
return $conf['plugin'][$plugin][$id];
}
/**
* 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
include($path.'default.php');
return $conf;
}
} }
//Setup VIM: ex: et ts=4 enc=utf-8 : //Setup VIM: ex: et ts=4 enc=utf-8 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment