-
chris authored
This patch adds events and a third plugin type, "action" plugins, to DokuWiki. The patch doesn't include any event signalling, that will be added in later patches. Action plugins are loaded before most Dokuwiki processing takes place and at the same time are given the opportunity to register handlers (or hooks) to receive specific dokuwiki events. Other parts of Dokuwiki (e.g. templates and syntax plugins) can also register handlers to receive events. Any part of Dokuwiki can create and signal events, including templates and plugins. This patch also revises the admin plugin class by making it an extension of a new class, DokuWiki_Plugin. The DokuWiki_Plugin_Action class also extends this new class. Further details of events, their signalling and handling, and of action plugins will be added to wiki.splitbrain.org in due course :-) darcs-hash:20060414193737-9b6ab-f23d3d9b93e4c50a3ad97ced03eabc6c0363650b.gz
chris authoredThis patch adds events and a third plugin type, "action" plugins, to DokuWiki. The patch doesn't include any event signalling, that will be added in later patches. Action plugins are loaded before most Dokuwiki processing takes place and at the same time are given the opportunity to register handlers (or hooks) to receive specific dokuwiki events. Other parts of Dokuwiki (e.g. templates and syntax plugins) can also register handlers to receive events. Any part of Dokuwiki can create and signal events, including templates and plugins. This patch also revises the admin plugin class by making it an extension of a new class, DokuWiki_Plugin. The DokuWiki_Plugin_Action class also extends this new class. Further details of events, their signalling and handling, and of action plugins will be added to wiki.splitbrain.org in due course :-) darcs-hash:20060414193737-9b6ab-f23d3d9b93e4c50a3ad97ced03eabc6c0363650b.gz
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
pluginutils.php 2.89 KiB
<?php
/**
* Utilities for handling plugins
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
// plugin related constants
$plugin_types = array('admin','syntax','action');
/**
* Returns a list of available plugins of given type
*
* @param $type string, plugin_type name;
* the type of plugin to return,
* use empty string for all types
* @param $all bool;
* false to only return enabled plugins,
* true to return both enabled and disabled plugins
*
* @return array of plugin names
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function plugin_list($type='',$all=false){
$plugins = array();
if ($dh = opendir(DOKU_PLUGIN)) {
while (false !== ($plugin = readdir($dh))) {
if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue;
if (is_file(DOKU_PLUGIN.$plugin)) continue;
// if required, skip disabled plugins
if (!$all && plugin_isdisabled($plugin)) continue;
if ($type=='' || @file_exists(DOKU_PLUGIN."$plugin/$type.php")){
$plugins[] = $plugin;
} else {
if ($dp = @opendir(DOKU_PLUGIN."$plugin/$type/")) {
while (false !== ($component = readdir($dp))) {
if ($component == '.' || $component == '..' || strtolower(substr($component, -4)) != ".php") continue;
if (is_file(DOKU_PLUGIN."$plugin/$type/$component")) {
$plugins[] = $plugin.'_'.substr($component, 0, -4);
}
}
closedir($dp);
}
}
}
closedir($dh);
}
return $plugins;
}
/**
* Loads the given plugin and creates an object of it
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param $type string type of plugin to load
* @param $name string name of the plugin to load
* @return objectreference the plugin object or null on failure
*/
function &plugin_load($type,$name){
//we keep all loaded plugins available in global scope for reuse
global $DOKU_PLUGINS;
//plugin already loaded?
if($DOKU_PLUGINS[$type][$name] != null){
return $DOKU_PLUGINS[$type][$name];
}
//try to load the wanted plugin file
if (file_exists(DOKU_PLUGIN."$name/$type.php")){
include_once(DOKU_PLUGIN."$name/$type.php");
}else{
list($plugin, $component) = preg_split("/_/",$name, 2);
if (!$component || !include_once(DOKU_PLUGIN."$plugin/$type/$component.php")) {
return null;
}
}
//construct class and instanciate
$class = $type.'_plugin_'.$name;
if (!class_exists($class)) return null;
$DOKU_PLUGINS[$type][$name] = new $class;
return $DOKU_PLUGINS[$type][$name];
}
function plugin_isdisabled($name) { return @file_exists(DOKU_PLUGIN.$name.'/disabled'); }
function plugin_enable($name) { return @unlink(DOKU_PLUGIN.$name.'/disabled'); }
function plugin_disable($name) { return @touch(DOKU_PLUGIN.$name.'/disabled'); }