mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-02-10 16:01:33 +00:00
add plugin storage table to schema; add ability to clear plugin data
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
<?php
|
||||
/* create table ttrss_plugin_storage
|
||||
(id serial not null primary key, name varchar(100) not null,
|
||||
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
|
||||
content text not null) - not in schema yet
|
||||
*/
|
||||
class PluginHost {
|
||||
private $link;
|
||||
private $hooks = array();
|
||||
@@ -81,9 +76,9 @@ 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, $owner_uid = false) {
|
||||
@@ -263,7 +258,7 @@ class PluginHost {
|
||||
if ($sync) $this->save_data(get_class($sender));
|
||||
}
|
||||
|
||||
function get($sender, $name, $default_value) {
|
||||
function get($sender, $name, $default_value = false) {
|
||||
$idx = get_class($sender);
|
||||
|
||||
if (isset($this->storage[$idx][$name])) {
|
||||
@@ -278,5 +273,18 @@ class PluginHost {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user