summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-12-25 00:45:10 +0400
committerAndrew Dolgov <[email protected]>2012-12-25 00:45:10 +0400
commitde612e7a3850d3053c7038e94098c0681d46983b (patch)
tree3e983cc930f18bd3d18d6536801929c733f7bf6c /classes
parent57e97294259f8d14806764d7a65083c2b84f1ea7 (diff)
experimental support for per-user plugins (bump schema)
Diffstat (limited to 'classes')
-rw-r--r--classes/pluginhost.php42
-rw-r--r--classes/pref/feeds.php2
-rw-r--r--classes/pref/prefs.php131
3 files changed, 162 insertions, 13 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index a637a5216..d8df6db49 100644
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -78,32 +78,45 @@ class PluginHost {
$class_file = strtolower(basename($class));
$file = dirname(__FILE__)."/../plugins/$class_file/$class_file.php";
- if (file_exists($file)) require_once $file;
+ if (!isset($this->plugins[$class])) {
+ if (file_exists($file)) require_once $file;
- if (class_exists($class) && is_subclass_of($class, "Plugin")) {
- $plugin = new $class($this);
+ if (class_exists($class) && is_subclass_of($class, "Plugin")) {
+ $plugin = new $class($this);
- $this->register_plugin($class, $plugin);
+ $this->register_plugin($class, $plugin);
+ }
}
}
}
+ function is_system($plugin) {
+ $about = $plugin->_about();
+
+ return @$about[3];
+ }
+
+ // only system plugins are allowed to modify routing
function add_handler($handler, $method, $sender) {
$handler = str_replace("-", "_", strtolower($handler));
$method = strtolower($method);
- if (!is_array($this->handlers[$handler])) {
- $this->handlers[$handler] = array();
- }
+ if ($this->is_system($sender)) {
+ if (!is_array($this->handlers[$handler])) {
+ $this->handlers[$handler] = array();
+ }
- $this->handlers[$handler][$method] = $sender;
+ $this->handlers[$handler][$method] = $sender;
+ }
}
function del_handler($handler, $method) {
$handler = str_replace("-", "_", strtolower($handler));
$method = strtolower($method);
- unset($this->handlers[$handler][$method]);
+ if ($this->is_system($sender)) {
+ unset($this->handlers[$handler][$method]);
+ }
}
function lookup_handler($handler, $method) {
@@ -121,17 +134,22 @@ class PluginHost {
return false;
}
+ // only system plugins are allowed to modify commands
function add_command($command, $description, $sender) {
$command = "-" . str_replace("-", "_", strtolower($command));
- $this->commands[$command] = array("description" => $description,
- "class" => $sender);
+ if ($this->is_system($sender)) {
+ $this->commands[$command] = array("description" => $description,
+ "class" => $sender);
+ }
}
function del_command($command) {
$command = "-" . strtolower($command);
- unset($this->commands[$command]);
+ if ($this->is_system($sender)) {
+ unset($this->commands[$command]);
+ }
}
function lookup_command($command) {
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 447aa8947..b28bd5491 100644
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1480,11 +1480,11 @@ class Pref_Feeds extends Handler_Protected {
print "</div>"; #pane
global $pluginhost;
+
$pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
"hook_prefs_tab", "prefFeeds");
print "</div>"; #container
-
}
private function feedlist_init_cat($cat_id, $hidden = false) {
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index db7a3e04f..bb1b44ece 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -621,8 +621,133 @@ class Pref_Prefs extends Handler_Protected {
<label for='prefs_show_advanced'>" .
__("Show additional preferences") . "</label>";
+ print "</form>";
print '</div>'; # inner pane
print '</div>'; # border container
+
+ print "</div>"; #pane
+
+ print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
+
+ print "<h2>".__("Plugins")."</h2>";
+
+ print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect.");
+
+ print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
+
+ print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+ evt.preventDefault();
+ if (this.validate()) {
+ notify_progress('Saving data...', true);
+
+ new Ajax.Request('backend.php', {
+ parameters: dojo.objectToQuery(this.getValues()),
+ onComplete: function(transport) {
+ notify('');
+ if (confirm(__('Selected plugins have been enabled. Reload?'))) {
+ window.location.reload();
+ }
+ } });
+
+ }
+ </script>";
+
+ print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
+ print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
+
+ print "<table width='100%'>";
+
+ print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
+
+ print "<tr class=\"title\">
+ <td width=\"5%\">&nbsp;</td>
+ <td width='10%'>".__('Plugin')."</td>
+ <td width=''>".__('Description')."</td>
+ <td width='5%'>".__('Version')."</td>
+ <td width='10%'>".__('Author')."</td></tr>";
+
+ $system_enabled = array_map("trim", explode(",", PLUGINS));
+ $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
+
+ $tmppluginhost = new PluginHost($link);
+ $tmppluginhost->load_all();
+
+ foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
+ $about = $plugin->_about();
+
+ if ($about[3]) {
+ if (in_array($name, $system_enabled)) {
+ $checked = "checked='1'";
+ } else {
+ $checked = "";
+ }
+
+ print "<tr>";
+
+ print "<td align='center'><input disabled='1'
+ dojoType=\"dijit.form.CheckBox\" $checked
+ type=\"checkbox\"></td>";
+
+ print "<td>$name</td>";
+ print "<td>" . htmlspecialchars($about[1]) . "</td>";
+ print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
+ print "<td>" . htmlspecialchars($about[2]) . "</td>";
+
+ print "</tr>";
+
+ }
+ }
+
+ print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
+
+ print "<tr class=\"title\">
+ <td width=\"5%\">&nbsp;</td>
+ <td width='10%'>".__('Plugin')."</td>
+ <td width=''>".__('Description')."</td>
+ <td width='5%'>".__('Version')."</td>
+ <td width='10%'>".__('Author')."</td></tr>";
+
+
+ foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
+ $about = $plugin->_about();
+
+ if (!$about[3]) {
+
+ if (in_array($name, $system_enabled)) {
+ $checked = "checked='1'";
+ $disabled = "disabled='1'";
+ } else if (in_array($name, $user_enabled)) {
+ $checked = "checked='1'";
+ $disabled = "";
+ } else {
+ $checked = "";
+ $disabled = "";
+ }
+
+ print "<tr>";
+
+ print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
+ dojoType=\"dijit.form.CheckBox\" $checked $disabled
+ type=\"checkbox\"></td>";
+
+ print "<td>$name</td>";
+ print "<td>" . htmlspecialchars($about[1]) . "</td>";
+ print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
+ print "<td>" . htmlspecialchars($about[2]) . "</td>";
+
+ print "</tr>";
+
+
+
+ }
+
+ }
+
+ print "</table>";
+
+ print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
+ __("Enable selected plugins")."</button></p>";
+
print "</form>";
print "</div>"; #pane
@@ -698,5 +823,11 @@ class Pref_Prefs extends Handler_Protected {
}
}
+
+ function setplugins() {
+ $plugins = join(",", $_REQUEST["plugins"]);
+
+ set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
+ }
}
?>