hookCrumbsPlugins.php in Crumbs, the Breadcrumbs suite 7
File
lib/InjectedAPI/hookCrumbsPlugins.php
View source
<?php
class crumbs_InjectedAPI_hookCrumbsPlugins {
protected $module;
protected $plugins;
protected $disabledKeys;
function __construct(&$plugins, &$disabled_keys) {
$this->plugins =& $plugins;
$this->disabledKeys =& $disabled_keys;
}
function setModule($module) {
$this->module = $module;
}
function monoPlugin($key = NULL, $plugin = NULL) {
if (!isset($key)) {
$class = $this->module . '_CrumbsMonoPlugin';
$plugin = new $class();
$key = $this->module;
}
elseif (!isset($plugin)) {
$class = $this->module . '_CrumbsMonoPlugin_' . $key;
$plugin = new $class();
$key = $this->module . '.' . $key;
}
else {
$class = get_class($plugin);
$key = $this->module . '.' . $key;
}
if (!$plugin instanceof crumbs_MonoPlugin) {
throw new Exception("{$class} must implement class_MonoPlugin.");
}
$this->plugins[$key] = $plugin;
if (method_exists($plugin, 'disabledByDefault')) {
$disabled_by_default = $plugin
->disabledByDefault();
if ($disabled_by_default === TRUE) {
$this->disabledKeys[$key] = $key;
}
elseif ($disabled_by_default !== FALSE && $disabled_by_default !== NULL) {
throw new Exception("{$class}::disabledByDefault() must return TRUE, FALSE or NULL.");
}
}
}
function multiPlugin($key, $plugin = NULL) {
if (!isset($key)) {
$class = $this->module . '_CrumbsMultiPlugin';
$plugin = new $class();
$plugin_key = $this->module;
}
elseif (!isset($plugin)) {
$class = $this->module . '_CrumbsMultiPlugin_' . $key;
$plugin = new $class();
$plugin_key = $this->module . '.' . $key;
}
else {
$class = get_class($plugin);
$plugin_key = $this->module . '.' . $key;
}
if (!$plugin instanceof crumbs_MultiPlugin) {
throw new Exception("{$class} must implement class_MultiPlugin.");
}
$this->plugins[$plugin_key] = $plugin;
if (method_exists($plugin, 'disabledByDefault')) {
$disabled_by_default = $plugin
->disabledByDefault();
if ($disabled_by_default !== NULL) {
if (!is_array($disabled_by_default)) {
throw new Exception("{$class}::disabledByDefault() must return an array or NULL.");
}
foreach ($disabled_by_default as $suffix) {
if (!isset($suffix) || $suffix === '') {
throw new Exception("{$class}::disabledByDefault() - returned array contains an empty key.");
}
else {
$key = $plugin_key . '.' . $suffix;
$disabled_keys[$key] = $key;
}
}
}
}
}
function disabledByDefault($keys = NULL) {
if (is_array($keys)) {
foreach ($keys as $key) {
$this
->_disabledByDefault($key);
}
}
else {
$this
->_disabledByDefault($keys);
}
}
protected function _disabledByDefault($key) {
$key = isset($key) ? $this->module . '.' . $key : $this->module;
$this->disabledKeys[$key] = $key;
}
}