]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/prefs.php
fix broken article processing if ALLOW_DUPLICATE_POSTS is enabled
[tt-rss.git] / classes / pref / prefs.php
index d8b8ecc756841c6704cbb5fc933e6042a3c66d0c..9cbc425c6115d299efb9d8463744816831311e41 100644 (file)
@@ -11,8 +11,8 @@ class Pref_Prefs extends Handler_Protected {
                return array_search($method, $csrf_ignored) !== false;
        }
 
-       function __construct($link, $args) {
-               parent::__construct($link, $args);
+       function __construct($args) {
+               parent::__construct($args);
 
                $this->pref_sections = array(
                        1 => __('General'),
@@ -23,7 +23,6 @@ class Pref_Prefs extends Handler_Protected {
 
                $this->pref_help = array(
                        "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
-                       "AUTO_ASSIGN_LABELS" => array(__("Assign articles to labels automatically"), ""),
                        "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
                        "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
                        "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
@@ -40,7 +39,7 @@ class Pref_Prefs extends Handler_Protected {
                        "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
                        "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
                        "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
-                       "LONG_DATE_FORMAT" => array(__("Long date format"), ""),
+                       "LONG_DATE_FORMAT" => array(__("Long date format"), __("The syntax used is identical to the PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")),
                        "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
                        "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
                        "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
@@ -52,9 +51,10 @@ class Pref_Prefs extends Handler_Protected {
                        "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
                        "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
                        "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
-                       "USER_TIMEZONE" => array(__("User timezone"), ""),
+                       "USER_TIMEZONE" => array(__("Time zone"), ""),
                        "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
-                       "USER_CSS_THEME" => array(__("Select theme"), __("Select one of the available CSS themes"))
+                       "USER_LANGUAGE" => array(__("Language")),
+                       "USER_CSS_THEME" => array(__("Theme"), __("Select one of the available CSS themes"))
                );
        }
 
@@ -65,27 +65,26 @@ class Pref_Prefs extends Handler_Protected {
                $con_pw = $_POST["confirm_password"];
 
                if ($old_pw == "") {
-                       print "ERROR: ".__("Old password cannot be blank.");
+                       print "ERROR: ".format_error("Old password cannot be blank.");
                        return;
                }
 
                if ($new_pw == "") {
-                       print "ERROR: ".__("New password cannot be blank.");
+                       print "ERROR: ".format_error("New password cannot be blank.");
                        return;
                }
 
                if ($new_pw != $con_pw) {
-                       print "ERROR: ".__("Entered passwords do not match.");
+                       print "ERROR: ".format_error("Entered passwords do not match.");
                        return;
                }
 
-               global $pluginhost;
-               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
+               $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
 
                if (method_exists($authenticator, "change_password")) {
-                       print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
+                       print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw));
                } else {
-                       print "ERROR: ".__("Function not supported by authentication module.");
+                       print "ERROR: ".format_error("Function not supported by authentication module.");
                }
        }
 
@@ -112,18 +111,13 @@ class Pref_Prefs extends Handler_Protected {
                                }
                        }
 
-                       if ($pref_name == "language") {
+                       if ($pref_name == "USER_LANGUAGE") {
                                if ($_SESSION["language"] != $value) {
-                                       setcookie("ttrss_lang", $value,
-                                               time() + SESSION_COOKIE_LIFETIME);
-                                       $_SESSION["language"] = $value;
-
                                        $need_reload = true;
                                }
-                       } else {
-                               set_pref($pref_name, $value);
                        }
 
+                       set_pref($pref_name, $value);
                }
 
                if ($need_reload) {
@@ -133,21 +127,6 @@ class Pref_Prefs extends Handler_Protected {
                }
        }
 
-       function getHelp() {
-
-               $pref_name = $this->dbh->escape_string($_REQUEST["pn"]);
-
-               $result = $this->dbh->query("SELECT help_text FROM ttrss_prefs
-                       WHERE pref_name = '$pref_name'");
-
-               if ($this->dbh->num_rows($result) > 0) {
-                       $help_text = $this->dbh->fetch_result($result, 0, "help_text");
-                       print $help_text;
-               } else {
-                       printf(__("Unknown option: %s"), $pref_name);
-               }
-       }
-
        function changeemail() {
 
                $email = $this->dbh->escape_string($_POST["email"]);
@@ -186,7 +165,8 @@ class Pref_Prefs extends Handler_Protected {
                global $access_level_names;
 
                $prefs_blacklist = array("STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
-                       "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT");
+                       "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT",
+                       "FEEDS_SORT_BY_UNREAD");
 
                /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
 
@@ -255,10 +235,7 @@ class Pref_Prefs extends Handler_Protected {
                print "</form>";
 
                if ($_SESSION["auth_module"]) {
-                       global $pluginhost;
-
-                       $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
-
+                       $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
                } else {
                        $authenticator = false;
                }
@@ -267,6 +244,8 @@ class Pref_Prefs extends Handler_Protected {
 
                        print "<h2>" . __("Password") . "</h2>";
 
+                       print "<div style='display : none' id='pwd_change_infobox'></div>";
+
                        $result = $this->dbh->query("SELECT id FROM ttrss_users
                                WHERE id = ".$_SESSION["uid"]." AND pwd_hash
                                = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
@@ -287,12 +266,20 @@ class Pref_Prefs extends Handler_Protected {
                                        onComplete: function(transport) {
                                                notify('');
                                                if (transport.responseText.indexOf('ERROR: ') == 0) {
-                                                       notify_error(transport.responseText.replace('ERROR: ', ''));
+
+                                                       $('pwd_change_infobox').innerHTML =
+                                                               transport.responseText.replace('ERROR: ', '');
+
                                                } else {
-                                                       notify_info(transport.responseText);
+                                                       $('pwd_change_infobox').innerHTML =
+                                                               transport.responseText.replace('ERROR: ', '');
+
                                                        var warn = $('default_pass_warning');
                                                        if (warn) Element.hide(warn);
                                                }
+
+                                               new Effect.Appear('pwd_change_infobox');
+
                                }});
                                this.reset();
                        }
@@ -372,9 +359,9 @@ class Pref_Prefs extends Handler_Protected {
 
                                print "</form>";
 
-                               } else {
+                               } else if (function_exists("imagecreatefromstring")) {
 
-                                       print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
+                                       print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."));
 
                                        print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
 
@@ -431,13 +418,16 @@ class Pref_Prefs extends Handler_Protected {
 
                                        print "</form>";
 
+                               } else {
+
+                                       print_notice(__("PHP GD functions are required for OTP support."));
+
                                }
 
                        }
                }
 
-               global $pluginhost;
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefPrefsAuth");
 
                print "</div>"; #pane
@@ -544,22 +534,6 @@ class Pref_Prefs extends Handler_Protected {
                                print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
 
                                $lnum = 0;
-
-                               if ($active_section == 2) {
-                                       print "<tr>";
-
-                                       print "<td width=\"40%\" class=\"prefName\">";
-                                       print "<label>";
-                                       print __("Language:");
-                                       print "</label>";
-
-                                       print "<td>";
-                                       print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
-                                               "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
-                                       print "</td>";
-                                       print "</tr>";
-                               }
-
                        }
 
                        print "<tr>";
@@ -575,7 +549,11 @@ class Pref_Prefs extends Handler_Protected {
 
                        print "<td class=\"prefValue\">";
 
-                       if ($pref_name == "USER_TIMEZONE") {
+                       if ($pref_name == "USER_LANGUAGE") {
+                               print_select_hash($pref_name, $value, get_translations(),
+                                       "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
+
+                       } else if ($pref_name == "USER_TIMEZONE") {
 
                                $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
 
@@ -587,7 +565,10 @@ class Pref_Prefs extends Handler_Protected {
 
                        } else if ($pref_name == "USER_CSS_THEME") {
 
-                               $themes = array_map("basename", glob("themes/*.css"));
+                               $themes = array_merge(glob("themes/*.css"), glob("themes.local/*.css"));
+                               $themes = array_map("basename", $themes);
+                               $themes = array_filter($themes, "theme_valid");
+                               asort($themes);
 
                                print_select($pref_name, $value, $themes,
                                        'dojoType="dijit.form.Select"');
@@ -641,6 +622,8 @@ class Pref_Prefs extends Handler_Protected {
                                $cert_serial = htmlspecialchars(get_ssl_certificate_id());
                                $has_serial = ($cert_serial) ? "false" : "true";
 
+                               print "<br/>";
+
                                print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
                                        onclick=\"insertSSLserial('$cert_serial')\">" .
                                        __('Register') . "</button>";
@@ -675,8 +658,7 @@ class Pref_Prefs extends Handler_Protected {
 
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
 
-               global $pluginhost;
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefPrefsPrefsInside");
 
                print '</div>'; # inside pane
@@ -712,8 +694,7 @@ 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,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefPrefsPrefsOutside");
 
                print "</form>";
@@ -724,8 +705,6 @@ class Pref_Prefs extends Handler_Protected {
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
 
-               print "<h2>".__("Plugins")."</h2>";
-
                print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
 
                print_notice(__("Download more plugins at tt-rss.org <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/forum/viewforum.php?f=22\">forums</a> or <a target=\"_blank\" class=\"visibleLink\" href=\"http://tt-rss.org/wiki/Plugins\">wiki</a>."));
@@ -766,14 +745,14 @@ class Pref_Prefs extends Handler_Protected {
                $system_enabled = array_map("trim", explode(",", PLUGINS));
                $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
 
-               $tmppluginhost = new PluginHost(Db::get());
-               $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
+               $tmppluginhost = new PluginHost();
+               $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
                $tmppluginhost->load_data(true);
 
                foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
                        $about = $plugin->about();
 
-                       if ($about[3] && strpos($name, "example") === FALSE) {
+                       if ($about[3]) {
                                if (in_array($name, $system_enabled)) {
                                        $checked = "checked='1'";
                                } else {
@@ -786,7 +765,9 @@ class Pref_Prefs extends Handler_Protected {
                                                dojoType=\"dijit.form.CheckBox\" $checked
                                                type=\"checkbox\"></td>";
 
-                               print "<td>$name</td>";
+                               $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
+
+                               print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
                                print "<td>" . htmlspecialchars($about[1]);
                                if (@$about[4]) {
                                        print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
@@ -821,7 +802,7 @@ class Pref_Prefs extends Handler_Protected {
                foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
                        $about = $plugin->about();
 
-                       if (!$about[3] && strpos($name, "example") === FALSE) {
+                       if (!$about[3]) {
 
                                if (in_array($name, $system_enabled)) {
                                        $checked = "checked='1'";
@@ -839,11 +820,13 @@ class Pref_Prefs extends Handler_Protected {
 
                                print "<tr class='$rowclass'>";
 
+                               $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
+
                                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><label for='FPCHK-$name'>$name</label></td>";
+                               print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
                                print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
                                if (@$about[4]) {
                                        print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
@@ -877,8 +860,7 @@ class Pref_Prefs extends Handler_Protected {
 
                print "</div>"; #pane
 
-               global $pluginhost;
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
                        "hook_prefs_tab", "prefPrefs");
 
                print "</div>"; #container
@@ -905,8 +887,9 @@ class Pref_Prefs extends Handler_Protected {
 
                if (!$otp_enabled) {
                        $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
-                       $topt = new \OTPHP\TOTP($secret);
-                       print QRcode::png($topt->provisioning_uri($login));
+             print QRcode::png("otpauth://totp/".urlencode($login).
+                               "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS"));
+
                }
        }
 
@@ -918,8 +901,7 @@ class Pref_Prefs extends Handler_Protected {
                $password = $_REQUEST["password"];
                $otp = $_REQUEST["otp"];
 
-               global $pluginhost;
-               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
+               $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
 
                if ($authenticator->check_password($_SESSION["uid"], $password)) {
 
@@ -951,8 +933,7 @@ class Pref_Prefs extends Handler_Protected {
        function otpdisable() {
                $password = $this->dbh->escape_string($_REQUEST["password"]);
 
-               global $pluginhost;
-               $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
+               $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
 
                if ($authenticator->check_password($_SESSION["uid"], $password)) {
 
@@ -978,8 +959,7 @@ class Pref_Prefs extends Handler_Protected {
        function clearplugindata() {
                $name = $this->dbh->escape_string($_REQUEST["name"]);
 
-               global $pluginhost;
-               $pluginhost->clear_data($pluginhost->get_plugin($name));
+               PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
        }
 
        function customizeCSS() {
@@ -987,7 +967,7 @@ class Pref_Prefs extends Handler_Protected {
 
                $value = str_replace("<br/>", "\n", $value);
 
-               print_notice(T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "tt-rss.css"));
+               print_notice(T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "css/tt-rss.css"));
 
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">";
@@ -995,7 +975,7 @@ class Pref_Prefs extends Handler_Protected {
 
                print "<table width='100%'><tr><td>";
                print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
-                       style='font-size : 12px; width : 100%; height: 200px;'
+                       style='font-size : 12px; width : 98%; height: 200px;'
                        placeHolder='body#ttrssMain { font-size : 14px; };'
                        name='value'>$value</textarea>";
                print "</td></tr></table>";
@@ -1064,8 +1044,6 @@ class Pref_Prefs extends Handler_Protected {
 
                while ($line = $this->dbh->fetch_assoc($result)) {
 
-                       $class = ($lnum % 2) ? "even" : "odd";
-
                        $profile_id = $line["id"];
                        $this_row_id = "id=\"FCATR-$profile_id\"";