remove hook-based plugins
parent
23d2471c92
commit
9aceda3afc
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
class Plugin {
|
||||
protected $link;
|
||||
protected $handler;
|
||||
|
||||
function __construct($link, $handler) {
|
||||
$this->link = $link;
|
||||
$this->handler = $handler;
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function add_listener($hook) {
|
||||
$this->handler->add_listener($hook, $this);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,11 +0,0 @@
|
||||
<?
|
||||
class Plugin_Example extends Plugin {
|
||||
function initialize() {
|
||||
$this->add_listener('article_before');
|
||||
}
|
||||
|
||||
function article_before(&$line) {
|
||||
$line["title"] = "EXAMPLE/REPLACED:" . $line["title"];
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
class Plugins {
|
||||
protected $link;
|
||||
protected $plugins;
|
||||
protected $listeners;
|
||||
|
||||
function __construct($link) {
|
||||
$this->link = $link;
|
||||
$this->listeners = array();
|
||||
$this->load_plugins();
|
||||
}
|
||||
|
||||
function load_plugins() {
|
||||
if (defined('_ENABLE_PLUGINS')) {
|
||||
$plugins = explode(",", _ENABLE_PLUGINS);
|
||||
|
||||
foreach ($plugins as $p) {
|
||||
$plugin_class = "plugin_$p";
|
||||
if (class_exists($plugin_class)) {
|
||||
$plugin = new $plugin_class($this->link, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function add_listener($hook_name, $plugin) {
|
||||
if (!is_array($this->listeners[$hook_name]))
|
||||
$this->listeners[$hook_name] = array();
|
||||
|
||||
array_push($this->listeners[$hook_name], $plugin);
|
||||
}
|
||||
|
||||
function hook($hook_name, &$params) {
|
||||
if (is_array($this->listeners[$hook_name])) {
|
||||
foreach ($this->listeners[$hook_name] as $p) {
|
||||
if (method_exists($p, $hook_name)) {
|
||||
$p->$hook_name($params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue