diff options
Diffstat (limited to 'inc/plugin.php')
-rw-r--r-- | inc/plugin.php | 147 |
1 files changed, 106 insertions, 41 deletions
diff --git a/inc/plugin.php b/inc/plugin.php index dccd37bd9..f2ad95e2e 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -30,33 +30,45 @@ class DokuWiki_Plugin { * desc - Short description of the plugin (Text only) * url - Website with more information on the plugin (eg. syntax description) */ - function getInfo(){ - $parts = explode('_',get_class($this)); - $info = DOKU_PLUGIN.'/'.$parts[2].'/plugin.info.txt'; - if(@file_exists($info)) return confToHash($info); - - msg('getInfo() not implemented in '.get_class($this). - ' and '.$info.' not found.<br />This is a bug in the '. - $parts[2].' plugin and should be reported to the '. - 'plugin author.',-1); + public function getInfo(){ + $parts = explode('_', get_class($this)); + $info = DOKU_PLUGIN . '/' . $parts[2] . '/plugin.info.txt'; + if(file_exists($info)) return confToHash($info); + + msg( + 'getInfo() not implemented in ' . get_class($this) . ' and ' . $info . ' not found.<br />' . + 'Verify you\'re running the latest version of the plugin. If the problem persists, send a ' . + 'bug report to the author of the ' . $parts[2] . ' plugin.', -1 + ); return array( - 'date' => '0000-00-00', - 'name' => $parts[2].' plugin', + 'date' => '0000-00-00', + 'name' => $parts[2] . ' plugin', ); } // plugin introspection methods // extract from class name, format = <plugin type>_plugin_<name>[_<component name>] - function getPluginType() { + /** + * @return string plugin type + */ + public function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } - function getPluginName() { - list($t, $p, $n) = explode('_', get_class($this), 4); + + /** + * @return string plugin name + */ + public function getPluginName() { + list(/* $t */, /* $p */, $n) = explode('_', get_class($this), 4); return $n; } - function getPluginComponent() { - list($t, $p, $n, $c) = explode('_', get_class($this), 4); + + /** + * @return string component name + */ + public function getPluginComponent() { + list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } @@ -70,7 +82,7 @@ class DokuWiki_Plugin { * @param string $id id of the string to be retrieved * @return string string in appropriate language or english if not available */ - function getLang($id) { + public function getLang($id) { if (!$this->localised) $this->setupLocale(); return (isset($this->lang[$id]) ? $this->lang[$id] : ''); @@ -85,22 +97,24 @@ class DokuWiki_Plugin { * @param string $id id of language dependent wiki page * @return string parsed contents of the wiki page in xhtml format */ - function locale_xhtml($id) { + public function locale_xhtml($id) { return p_cached_output($this->localFN($id)); } /** - * localFN($id) - * prepends appropriate path for a language dependent filename + * Prepends appropriate path for a language dependent filename * plugin equivalent of localFN() + * + * @param string $id id of localization file + * @return string wiki text */ - function localFN($id) { + public function localFN($id) { global $conf; $plugin = $this->getPluginName(); $file = DOKU_CONF.'plugin_lang/'.$plugin.'/'.$conf['lang'].'/'.$id.'.txt'; - if (!@file_exists($file)){ + if (!file_exists($file)){ $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; - if(!@file_exists($file)){ + if(!file_exists($file)){ //fall back to english $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; } @@ -109,21 +123,33 @@ class DokuWiki_Plugin { } /** - * setupLocale() - * reads all the plugins language dependent strings into $this->lang - * this function is automatically called by getLang() + * Reads all the plugins language dependent strings into $this->lang + * this function is automatically called by getLang() */ function setupLocale() { - if ($this->localised) return; + if($this->localised) return; - global $conf; // definitely don't invoke "global $lang" - $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; + global $conf, $config_cascade; // definitely don't invoke "global $lang" + $path = DOKU_PLUGIN . $this->getPluginName() . '/lang/'; $lang = array(); // don't include once, in case several plugin components require the same language file - @include($path.'en/lang.php'); - if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); + @include($path . 'en/lang.php'); + foreach($config_cascade['lang']['plugin'] as $config_file) { + if(file_exists($config_file . $this->getPluginName() . '/en/lang.php')) { + include($config_file . $this->getPluginName() . '/en/lang.php'); + } + } + + if($conf['lang'] != 'en') { + @include($path . $conf['lang'] . '/lang.php'); + foreach($config_cascade['lang']['plugin'] as $config_file) { + if(file_exists($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php')) { + include($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php'); + } + } + } $this->lang = $lang; $this->localised = true; @@ -139,7 +165,7 @@ class DokuWiki_Plugin { * @param mixed $notset what to return if the setting is not available * @return mixed */ - function getConf($setting, $notset=false){ + public function getConf($setting, $notset=false){ if (!$this->configloaded){ $this->loadConfig(); } @@ -176,12 +202,12 @@ class DokuWiki_Plugin { * * @return array setting => value */ - function readDefaultSettings() { + protected function readDefaultSettings() { $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; $conf = array(); - if (@file_exists($path.'default.php')) { + if (file_exists($path.'default.php')) { include($path.'default.php'); } @@ -195,10 +221,9 @@ class DokuWiki_Plugin { * * @param string $name name of plugin to load * @param bool $msg if a message should be displayed in case the plugin is not available - * - * @return object helper plugin object + * @return DokuWiki_Plugin|null helper plugin object */ - function loadHelper($name, $msg = true){ + public function loadHelper($name, $msg = true){ $obj = plugin_load('helper',$name); if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1); return $obj; @@ -210,8 +235,14 @@ class DokuWiki_Plugin { /** * email * standardised function to generate an email link according to obfuscation settings + * + * @param string $email + * @param string $name + * @param string $class + * @param string $more + * @return string html */ - function email($email, $name='', $class='', $more='') { + public function email($email, $name='', $class='', $more='') { if (!$email) return $name; $email = obfuscate($email); if (!$name) $name = $email; @@ -222,8 +253,15 @@ class DokuWiki_Plugin { /** * external_link * standardised function to generate an external link according to conf settings + * + * @param string $link + * @param string $title + * @param string $class + * @param string $target + * @param string $more + * @return string */ - function external_link($link, $title='', $class='', $target='', $more='') { + public function external_link($link, $title='', $class='', $target='', $more='') { global $conf; $link = htmlentities($link); @@ -239,10 +277,37 @@ class DokuWiki_Plugin { } /** + * A fallback to provide access to the old render() method + * + * Since syntax plugins provide their own render method with a different signature and they now + * inherit from Doku_Plugin we can no longer have a render() method here (Strict Standards Violation). + * Instead use render_text() + * + * @deprecated 2014-01-22 + * + * @param string $name + * @param array $arguments + * @return null|string + */ + public function __call($name, $arguments) { + if($name == 'render'){ + dbg_deprecated('render_text()'); + if(!isset($arguments[1])) $arguments[1] = 'xhtml'; + return $this->render_text($arguments[0], $arguments[1]); + } + trigger_error("no such method $name", E_USER_ERROR); + return null; + } + + /** * output text string through the parser, allows dokuwiki markup to be used * very ineffecient for small pieces of data - try not to use + * + * @param string $text wiki markup to parse + * @param string $format output format + * @return null|string */ - function render($text, $format='xhtml') { + public function render_text($text, $format='xhtml') { return p_render($format, p_get_instructions($text),$info); } @@ -251,7 +316,7 @@ class DokuWiki_Plugin { * * @return bool false if the plugin has to be instantiated */ - function isSingleton() { + public function isSingleton() { return true; } } |