summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/pluginhost.php98
-rw-r--r--classes/pref/feeds.php2
-rw-r--r--classes/pref/prefs.php21
3 files changed, 115 insertions, 6 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index d97dfa666..d7db7481c 100644
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -5,6 +5,8 @@ class PluginHost {
private $plugins = array();
private $handlers = array();
private $commands = array();
+ private $storage = array();
+ private $owner_uid;
const HOOK_ARTICLE_BUTTON = 1;
const HOOK_ARTICLE_FILTER = 2;
@@ -21,6 +23,10 @@ class PluginHost {
function __construct($link) {
$this->link = $link;
+
+ $this->storage = $_SESSION["plugin_storage"];
+
+ if (!$this->storage) $this->storage = array();
}
private function register_plugin($name, $plugin) {
@@ -70,14 +76,16 @@ class PluginHost {
return array();
}
}
- function load_all($kind) {
+ function load_all($kind, $owner_uid = false) {
$plugins = array_map("basename", glob("plugins/*"));
- $this->load(join(",", $plugins), $kind);
+ $this->load(join(",", $plugins), $kind, $owner_uid);
}
- function load($classlist, $kind) {
+ function load($classlist, $kind, $owner_uid = false) {
$plugins = explode(",", $classlist);
+ $this->owner_uid = (int) $owner_uid;
+
foreach ($plugins as $class) {
$class = trim($class);
$class_file = strtolower(basename($class));
@@ -194,5 +202,89 @@ class PluginHost {
}
}
+ function load_data($force = false) {
+ if ($this->owner_uid && (!$_SESSION["plugin_storage"] || $force)) {
+ $plugin = db_escape_string($plugin);
+
+ $result = db_query($this->link, "SELECT name, content FROM ttrss_plugin_storage
+ WHERE owner_uid = '".$this->owner_uid."'");
+
+ while ($line = db_fetch_assoc($result)) {
+ $this->storage[$line["name"]] = unserialize($line["content"]);
+ }
+
+ $_SESSION["plugin_storage"] = $this->storage;
+ }
+ }
+
+ private function save_data($plugin) {
+ if ($this->owner_uid) {
+ $plugin = db_escape_string($plugin);
+
+ db_query($this->link, "BEGIN");
+
+ $result = db_query($this->link,"SELECT id FROM ttrss_plugin_storage WHERE
+ owner_uid= '".$this->owner_uid."' AND name = '$plugin'");
+
+ if (!isset($this->storage[$plugin]))
+ $this->storage[$plugin] = array();
+
+ $content = db_escape_string(serialize($this->storage[$plugin]));
+
+ if (db_num_rows($result) != 0) {
+ db_query($this->link, "UPDATE ttrss_plugin_storage SET content = '$content'
+ WHERE owner_uid= '".$this->owner_uid."' AND name = '$plugin'");
+
+ } else {
+ db_query($this->link, "INSERT INTO ttrss_plugin_storage
+ (name,owner_uid,content) VALUES
+ ('$plugin','".$this->owner_uid."','$content')");
+ }
+
+ db_query($this->link, "COMMIT");
+ }
+ }
+
+ function set($sender, $name, $value, $sync = true) {
+ $idx = get_class($sender);
+
+ if (!isset($this->storage[$idx]))
+ $this->storage[$idx] = array();
+
+ $this->storage[$idx][$name] = $value;
+
+ $_SESSION["plugin_storage"] = $this->storage;
+
+ if ($sync) $this->save_data(get_class($sender));
+ }
+
+ function get($sender, $name, $default_value = false) {
+ $idx = get_class($sender);
+
+ if (isset($this->storage[$idx][$name])) {
+ return $this->storage[$idx][$name];
+ } else {
+ return $default_value;
+ }
+ }
+
+ function get_all($sender) {
+ $idx = get_class($sender);
+
+ return $this->storage[$idx];
+ }
+
+ function clear_data($sender) {
+ if ($this->owner_uid) {
+ $idx = get_class($sender);
+
+ unset($this->storage[$idx]);
+
+ db_query($this->link, "DELETE FROM ttrss_plugin_storage WHERE name = '$idx'
+ AND owner_uid = " . $this->owner_uid);
+
+ $_SESSION["plugin_storage"] = $this->storage;
+ }
+ }
}
?>
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index b423eab95..452236a7e 100644
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -949,7 +949,7 @@ class Pref_Feeds extends Handler_Protected {
include_in_digest = $include_in_digest,
always_display_enclosures = $always_display_enclosures,
mark_unread_on_update = $mark_unread_on_update,
- update_on_checksum_change = $update_on_checksum_change,
+ update_on_checksum_change = $update_on_checksum_change
WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
} else {
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index 0922e43a8..bb82b355e 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -683,8 +683,9 @@ class Pref_Prefs extends Handler_Protected {
$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($tmppluginhost::KIND_ALL);
+ $tmppluginhost = new PluginHost($this->link);
+ $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
+ $tmppluginhost->load_data(true);
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
@@ -707,6 +708,11 @@ class Pref_Prefs extends Handler_Protected {
print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
print "<td>" . htmlspecialchars($about[2]) . "</td>";
+ if (count($tmppluginhost->get_all($plugin)) > 0) {
+ print "<td><a href='#' onclick=\"clearPluginData('$name')\"
+ class='visibleLink'>".__("Clear data")."</a></td>";
+ }
+
print "</tr>";
}
@@ -752,6 +758,10 @@ class Pref_Prefs extends Handler_Protected {
print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
print "<td>" . htmlspecialchars($about[2]) . "</td>";
+ if (count($tmppluginhost->get_all($plugin)) > 0) {
+ print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
+ }
+
print "</tr>";
@@ -846,5 +856,12 @@ class Pref_Prefs extends Handler_Protected {
set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
}
+
+ function clearplugindata() {
+ $name = db_escape_string($_REQUEST["name"]);
+
+ global $pluginhost;
+ $pluginhost->clear_data($pluginhost->get_plugin($name));
+ }
}
?>