]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/prefs.php
add plugin storage table to schema; add ability to clear plugin data
[tt-rss.git] / classes / pref / prefs.php
index bb1b44ece899795bcb2660f7a3f0f5779eaab80b..bb82b355edac60376e5539cbed5d8d9273939ecb 100644 (file)
@@ -28,8 +28,8 @@ class Pref_Prefs extends Handler_Protected {
                        return;
                }
 
-               $module_class = "auth_" . $_SESSION["auth_module"];
-               $authenticator = new $module_class($this->link);
+               global $pluginhost;
+               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
 
                if (method_exists($authenticator, "change_password")) {
                        print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
@@ -188,9 +188,11 @@ class Pref_Prefs extends Handler_Protected {
 
                print "</form>";
 
-               if  ($_SESSION["auth_module"]) {
-                       $module_class = "auth_" . $_SESSION["auth_module"];
-                       $authenticator = new $module_class($this->link);
+               if ($_SESSION["auth_module"]) {
+                       global $pluginhost;
+
+                       $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
+
                } else {
                        $authenticator = false;
                }
@@ -258,7 +260,7 @@ class Pref_Prefs extends Handler_Protected {
 
                        print "</form>";
 
-                       if ($_SESSION["auth_module"] == "internal") {
+                       if ($_SESSION["auth_module"] == "auth_internal") {
 
                                print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
 
@@ -366,6 +368,10 @@ class Pref_Prefs extends Handler_Protected {
                        }
                }
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsAuth");
+
                print "</div>"; #pane
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
@@ -594,6 +600,10 @@ class Pref_Prefs extends Handler_Protected {
 
                print "</table>";
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsPrefsInside");
+
                print '</div>'; # inside pane
                print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
 
@@ -621,6 +631,10 @@ class Pref_Prefs extends Handler_Protected {
                                <label for='prefs_show_advanced'>" .
                                __("Show additional preferences") . "</label>";
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsPrefsOutside");
+
                print "</form>";
                print '</div>'; # inner pane
                print '</div>'; # border container
@@ -655,7 +669,7 @@ class Pref_Prefs extends Handler_Protected {
                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 "<table width='100%' class='prefPluginsList'>";
 
                print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
 
@@ -669,13 +683,14 @@ 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 = 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();
+                       $about = $plugin->about();
 
-                       if ($about[3]) {
+                       if ($about[3] && strpos($name, "example") === FALSE) {
                                if (in_array($name, $system_enabled)) {
                                        $checked = "checked='1'";
                                } else {
@@ -693,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>";
 
                        }
@@ -709,32 +729,39 @@ class Pref_Prefs extends Handler_Protected {
 
 
                foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
-                       $about = $plugin->_about();
+                       $about = $plugin->about();
 
-                       if (!$about[3]) {
+                       if (!$about[3] && strpos($name, "example") === FALSE) {
 
                                if (in_array($name, $system_enabled)) {
                                        $checked = "checked='1'";
                                        $disabled = "disabled='1'";
+                                       $rowclass = '';
                                } else if (in_array($name, $user_enabled)) {
                                        $checked = "checked='1'";
                                        $disabled = "";
+                                       $rowclass = "Selected";
                                } else {
                                        $checked = "";
                                        $disabled = "";
+                                       $rowclass = '';
                                }
 
-                               print "<tr>";
+                               print "<tr class='$rowclass'>";
 
                                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><label for='FPCHK-$name'>$name</label></td>";
+                               print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label></td>";
                                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>";
 
 
@@ -787,11 +814,11 @@ class Pref_Prefs extends Handler_Protected {
 
        function otpenable() {
                $password = db_escape_string($_REQUEST["password"]);
-
-               $module_class = "auth_" . $_SESSION["auth_module"];
-               $authenticator = new $module_class($this->link);
                $enable_otp = $_REQUEST["enable_otp"] == "on";
 
+               global $pluginhost;
+               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
+
                if ($authenticator->check_password($_SESSION["uid"], $password)) {
 
                        if ($enable_otp) {
@@ -809,8 +836,8 @@ class Pref_Prefs extends Handler_Protected {
        function otpdisable() {
                $password = db_escape_string($_REQUEST["password"]);
 
-               $module_class = "auth_" . $_SESSION["auth_module"];
-               $authenticator = new $module_class($this->link);
+               global $pluginhost;
+               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
 
                if ($authenticator->check_password($_SESSION["uid"], $password)) {
 
@@ -829,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));
+       }
 }
 ?>