diff options
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/action.php | 4 | ||||
-rw-r--r-- | lib/plugins/admin.php | 2 | ||||
-rw-r--r-- | lib/plugins/base.php | 211 | ||||
-rw-r--r-- | lib/plugins/syntax.php | 44 |
4 files changed, 25 insertions, 236 deletions
diff --git a/lib/plugins/action.php b/lib/plugins/action.php index 05d8735b9..4891349cb 100644 --- a/lib/plugins/action.php +++ b/lib/plugins/action.php @@ -9,7 +9,7 @@ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); -require_once(DOKU_PLUGIN.'base.php'); +require_once(DOKU_INC.'inc/plugin.php'); /** * All DokuWiki plugins to extend the admin function @@ -21,4 +21,4 @@ class DokuWiki_Action_Plugin extends DokuWiki_Plugin { trigger_error('register() not implemented in '.get_class($this), E_USER_WARNING); } -}
\ No newline at end of file +} diff --git a/lib/plugins/admin.php b/lib/plugins/admin.php index 22867a93d..00a07a054 100644 --- a/lib/plugins/admin.php +++ b/lib/plugins/admin.php @@ -9,7 +9,7 @@ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); -require_once(DOKU_PLUGIN.'base.php'); +require_once(DOKU_INC.'inc/plugin.php'); /** * All DokuWiki plugins to extend the admin function diff --git a/lib/plugins/base.php b/lib/plugins/base.php deleted file mode 100644 index a895166e6..000000000 --- a/lib/plugins/base.php +++ /dev/null @@ -1,211 +0,0 @@ -<?php -/** - * Admin Plugin Prototype - * - * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * @author Christopher Smith <chris@jalakai.co.uk> - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); - -if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); - -/** - * All DokuWiki plugins to extend the admin function - * need to inherit from this class - */ -class DokuWiki_Plugin { - - 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 - * - * Needs to return a associative array with the following values: - * - * author - Author of the plugin - * email - Email address to contact the author - * date - Last modified date of the plugin in YYYY-MM-DD format - * name - Name of the plugin - * desc - Short description of the plugin (Text only) - * url - Website with more information on the plugin (eg. syntax description) - */ - function getInfo(){ - trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING); - } - - // plugin introspection methods - // extract from class name, format = <plugin type>_plugin_<name>[_<component name>] - function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } - 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 (isset($c)?$c:''); } - - // localisation methods - /** - * getLang($id) - * use this function to access plugin language strings - * to try to minimise unnecessary loading of the strings when the plugin doesn't require them - * e.g. when info plugin is querying plugins for information about themselves. - * - * @param $id id of the string to be retrieved - * @return string string in appropriate language or english if not available - */ - function getLang($id) { - if (!$this->localised) $this->setupLocale(); - - return (isset($this->lang[$id]) ? $this->lang[$id] : ''); - } - - /** - * locale_xhtml($id) - * - * retrieve a language dependent file and pass to xhtml renderer for display - * plugin equivalent of p_locale_xhtml() - * - * @param $id id of language dependent wiki page - * @return string parsed contents of the wiki page in xhtml format - */ - function locale_xhtml($id) { - return p_cached_output($this->localFN($id)); - } - - /** - * localFN($id) - * prepends appropriate path for a language dependent filename - * plugin equivalent of localFN() - */ - function localFN($id) { - global $conf; - $plugin = $this->getPluginName(); - $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; - if(!@file_exists($file)){ - //fall back to english - $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; - } - return $file; - } - - /** - * setupLocale() - * reads all the plugins language dependent strings into $this->lang - * this function is automatically called by getLang() - */ - function setupLocale() { - if ($this->localised) return; - - global $conf; // 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'); - - $this->lang = $lang; - $this->localised = 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]; - } - - /** - * 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; - } - - $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; - } - - // 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 - - /** - * email - * standardised function to generate an email link according to obfuscation settings - */ - function email($email, $name='', $class='', $more='') { - if (!$email) return $name; - $email = obfuscate($email); - if (!$name) $name = $email; - $class = "class='".($class ? $class : 'mail')."'"; - return "<a href='mailto:$email' $class title='$email' $more>$name</a>"; - } - - /** - * external_link - * standardised function to generate an external link according to conf settings - */ - function external_link($link, $title='', $class='', $target='', $more='') { - global $conf; - - $link = htmlentities($link); - if (!$title) $title = $link; - if (!$target) $target = $conf['target']['extern']; - if ($conf['relnofollow']) $more .= ' rel="nofollow"'; - - if ($class) $class = " class='$class'"; - if ($target) $target = " target='$target'"; - if ($more) $more = " ".trim($more); - - return "<a href='$link'$class$target$more>$title</a>"; - } - - /** - * output text string through the parser, allows dokuwiki markup to be used - * very ineffecient for small pieces of data - try not to use - */ - function render($text, $format='xhtml') { - return p_render($format, p_get_instructions($text),$info); - } - - // deprecated functions - function plugin_localFN($id) { return $this->localFN($id); } - function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); } - function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); } - function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); } - function plugin_render($t, $f='xhtml') { return $this->render($t, $f); } -}
\ No newline at end of file diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 770356c3a..eb70dd1ff 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -1,7 +1,7 @@ <?php /** * Syntax Plugin Prototype - * + * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ @@ -47,12 +47,12 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { function getType(){ trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); } - + /** * Allowed Mode Types * - * Defines the mode types for other dokuwiki markup that maybe nested within the - * plugin's own markup. Needs to return an array of one or more of the mode types + * Defines the mode types for other dokuwiki markup that maybe nested within the + * plugin's own markup. Needs to return an array of one or more of the mode types * defined in $PARSER_MODES in parser.php */ function getAllowedTypes() { @@ -95,7 +95,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { /** * Handles the actual output creation. - * + * * The function must not assume any other of the classes methods have been run * during the object's current life. The only reliable data it receives are its * parameters. @@ -120,7 +120,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); } - + /** * There should be no need to override these functions */ @@ -132,7 +132,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { $allowedModeTypes = $this->getAllowedTypes(); foreach($allowedModeTypes as $mt) { $this->allowedModes = array_merge($this->allowedModes, $PARSER_MODES[$mt]); - } + } $idx = array_search(substr(get_class($this), 7), $this->allowedModes); if ($idx !== false) { @@ -140,8 +140,8 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { } $this->allowedModesSetup = true; } - - return parent::accepts($mode); + + return parent::accepts($mode); } // plugin introspection methods @@ -163,10 +163,10 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { */ function getLang($id) { if (!$this->localised) $this->setupLocale(); - + return (isset($this->lang[$id]) ? $this->lang[$id] : ''); } - + /** * locale_xhtml($id) * @@ -179,7 +179,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { function locale_xhtml($id) { return p_cached_output($this->localFN($id)); } - + /** * localFN($id) * prepends appropriate path for a language dependent filename @@ -195,30 +195,30 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { } return $file; } - + /** - * setupLocale() + * setupLocale() * reads all the plugins language dependent strings into $this->lang * this function is automatically called by getLang() */ function setupLocale() { if ($this->localised) return; - + global $conf; // definitely don't invoke "global $lang" $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; - + // don't include once, in case several plugin components require the same language file - @include($path.'en/lang.php'); + @include($path.'en/lang.php'); if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); - + $this->lang = $lang; $this->localised = true; } - + // configuration methods /** * getConf($setting) - * + * * use this function to access plugin configuration variables */ function getConf($setting){ @@ -227,7 +227,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { return $this->conf[$setting]; } - + /** * loadConfig() * merges the plugin's default settings with any local settings @@ -245,7 +245,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { } $this->configloaded = true; - $this->conf =& $conf['plugin'][$plugin]; + $this->conf =& $conf['plugin'][$plugin]; } /** |