rework class system to use subdirectories

add placeholder plugin/hook system
This commit is contained in:
Andrew Dolgov
2012-08-17 14:20:55 +04:00
parent 3d2c9f5adf
commit 369dbc19d6
29 changed files with 131 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
<?php
class Article extends Protected_Handler {
class Article extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("redirect");

View File

@@ -1,5 +1,5 @@
<?php
class Plugin_Button {
class Button {
protected $link;

View File

@@ -1,5 +1,5 @@
<?php
class Mail_Button extends Plugin_Button {
class Button_Mail extends Button {
function render($article_id) {
return "<img src=\"".theme_image($link, 'images/art-email.png')."\"
class='tagsPic' style=\"cursor : pointer\"

View File

@@ -1,5 +1,5 @@
<?php
class Note_Button extends Plugin_Button {
class Button_Note extends Button {
function render($article_id) {
return "<img src=\"".theme_image($this->link, "images/art-pub-note.png")."\"
style=\"cursor : pointer\" style=\"cursor : pointer\"

View File

@@ -1,5 +1,5 @@
<?php
class Share_Button extends Plugin_Button {
class Button_Share extends Button {
function render($article_id, $line) {
return "<img src=\"".theme_image($this->link, 'images/art-share.png')."\"
class='tagsPic' style=\"cursor : pointer\"

View File

@@ -1,5 +1,5 @@
<?php
class Tweet_Button extends Plugin_Button {
class Button_Tweet extends Button {
function render($article_id) {
$rv = "<img src=\"".theme_image($this->link, 'images/art-tweet.png')."\"
class='tagsPic' style=\"cursor : pointer\"

View File

@@ -1,5 +1,5 @@
<?php
class Feeds extends Protected_Handler {
class Feeds extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index");
@@ -121,6 +121,8 @@ class Feeds extends Protected_Handler {
$next_unread_feed, $offset, $vgr_last_feed = false,
$override_order = false, $include_children = false) {
global $plugins;
$disable_cache = false;
$reply = array();
@@ -220,10 +222,12 @@ class Feeds extends Protected_Handler {
$headlines_count = db_num_rows($result);
$plugins->hook('headlines_before', $reply);
if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
$button_plugins = array();
foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
$pclass = trim("${p}_button");
$pclass = trim("button_${p}");
if (class_exists($pclass)) {
$plugin = new $pclass($link);
@@ -245,6 +249,12 @@ class Feeds extends Protected_Handler {
while ($line = db_fetch_assoc($result)) {
if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
$plugins->hook('cdm_article_before', $line);
} else {
$plugins->hook('headlines_row', $line);
}
$class = ($lnum % 2) ? "even" : "odd";
$id = $line["id"];
@@ -673,11 +683,15 @@ class Feeds extends Protected_Handler {
$reply['content'] .= "</div>";
$plugins->hook('cdm_article_after', $reply['content']);
}
++$lnum;
}
$plugins->hook('headlines_after', $reply);
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
} else {

View File

@@ -1,5 +1,5 @@
<?php
class Protected_Handler extends Handler {
class Handler_Protected extends Handler {
function before($method) {
return parent::before($method) && $_SESSION['uid'];

View File

@@ -1,5 +1,5 @@
<?php
class Public_Handler extends Handler {
class Handler_Public extends Handler {
private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
$limit, $search, $search_mode, $match_on, $view_mode = false) {

View File

@@ -1,5 +1,5 @@
<?php
class Opml extends Protected_Handler {
class Opml extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("export", "import");

21
classes/plugin.php Normal file
View File

@@ -0,0 +1,21 @@
<?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);
}
}
?>

View File

@@ -0,0 +1,11 @@
<?
class Plugin_Example extends Plugin {
function initialize() {
$this->add_listener('article_before');
}
function article_before(&$line) {
$line["title"] = "EXAMPLE/REPLACED:" . $line["title"];
}
}
?>

44
classes/plugins.php Normal file
View File

@@ -0,0 +1,44 @@
<?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);
}
}
}
}
}
?>

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Feeds extends Protected_Handler {
class Pref_Feeds extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Filters extends Protected_Handler {
class Pref_Filters extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfiltertree", "edit");

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Instances extends Protected_Handler {
class Pref_Instances extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "edit");

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Labels extends Protected_Handler {
class Pref_Labels extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "getlabeltree", "edit");

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Prefs extends Protected_Handler {
class Pref_Prefs extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index");

View File

@@ -1,5 +1,5 @@
<?php
class Pref_Users extends Protected_Handler {
class Pref_Users extends Handler_Protected {
function before($method) {
if (parent::before($method)) {
if ($_SESSION["access_level"] < 10) {

View File

@@ -1,5 +1,5 @@
<?php
class RPC extends Protected_Handler {
class RPC extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("sanitycheck", "buttonplugin", "exportget");
@@ -766,7 +766,7 @@ class RPC extends Protected_Handler {
}
function buttonPlugin() {
$pclass = basename($_REQUEST['plugin']) . "_button";
$pclass = "button_" . basename($_REQUEST['plugin']);
$method = $_REQUEST['plugin_method'];
if (class_exists($pclass)) {