3 class Pref_Prefs
extends Handler_Protected
{
5 private $pref_help = array();
6 private $pref_sections = array();
8 function csrf_ignore($method) {
9 $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
11 return array_search($method, $csrf_ignored) !== false;
14 function __construct($link, $args) {
15 parent
::__construct($link, $args);
17 $this->pref_sections
= array(
24 $this->pref_help
= array(
25 "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
26 "AUTO_ASSIGN_LABELS" => array(__("Assign articles to labels automatically"), ""),
27 "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
28 "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
29 "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
30 "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")),
31 "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""),
32 "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""),
33 "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")),
34 "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""),
35 "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")),
36 "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")),
37 "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")),
38 "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""),
39 "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""),
40 "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
41 "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
42 "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
43 "LONG_DATE_FORMAT" => array(__("Long date format"), ""),
44 "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
45 "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
46 "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
47 "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""),
48 "SHORT_DATE_FORMAT" => array(__("Short date format"), ""),
49 "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""),
50 "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")),
51 "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")),
52 "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
53 "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
54 "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
55 "USER_TIMEZONE" => array(__("User timezone"), ""),
56 "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
57 "USER_CSS_THEME" => array(__("Select theme"), __("Select one of the available CSS themes"))
61 function changepassword() {
63 $old_pw = $_POST["old_password"];
64 $new_pw = $_POST["new_password"];
65 $con_pw = $_POST["confirm_password"];
68 print "ERROR: ".__("Old password cannot be blank.");
73 print "ERROR: ".__("New password cannot be blank.");
77 if ($new_pw != $con_pw) {
78 print "ERROR: ".__("Entered passwords do not match.");
83 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
85 if (method_exists($authenticator, "change_password")) {
86 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
88 print "ERROR: ".__("Function not supported by authentication module.");
92 function saveconfig() {
93 $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
95 foreach ($boolean_prefs as $pref) {
96 if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
101 foreach (array_keys($_POST) as $pref_name) {
103 $pref_name = $this->dbh
->escape_string($pref_name);
104 $value = $this->dbh
->escape_string($_POST[$pref_name]);
106 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
107 if (get_pref('DIGEST_PREFERRED_TIME') != $value) {
109 $this->dbh
->query("UPDATE ttrss_users SET
110 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
115 if ($pref_name == "language") {
116 if ($_SESSION["language"] != $value) {
117 setcookie("ttrss_lang", $value,
118 time() + SESSION_COOKIE_LIFETIME
);
119 $_SESSION["language"] = $value;
124 set_pref($pref_name, $value);
130 print "PREFS_NEED_RELOAD";
132 print __("The configuration was saved.");
138 $pref_name = $this->dbh
->escape_string($_REQUEST["pn"]);
140 $result = $this->dbh
->query("SELECT help_text FROM ttrss_prefs
141 WHERE pref_name = '$pref_name'");
143 if ($this->dbh
->num_rows($result) > 0) {
144 $help_text = $this->dbh
->fetch_result($result, 0, "help_text");
147 printf(__("Unknown option: %s"), $pref_name);
151 function changeemail() {
153 $email = $this->dbh
->escape_string($_POST["email"]);
154 $full_name = $this->dbh
->escape_string($_POST["full_name"]);
156 $active_uid = $_SESSION["uid"];
158 $this->dbh
->query("UPDATE ttrss_users SET email = '$email',
159 full_name = '$full_name' WHERE id = '$active_uid'");
161 print __("Your personal data has been saved.");
166 function resetconfig() {
168 $_SESSION["prefs_op_result"] = "reset-to-defaults";
170 if ($_SESSION["profile"]) {
171 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
173 $profile_qpart = "profile IS NULL";
176 $this->dbh
->query("DELETE FROM ttrss_user_prefs
177 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
179 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
181 echo __("Your preferences are now set to default values.");
186 global $access_level_names;
188 $prefs_blacklist = array("STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
189 "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT");
191 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
193 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
194 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
195 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
196 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
197 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
200 $_SESSION["prefs_op_result"] = "";
202 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
203 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
205 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
207 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
208 evt.preventDefault();
209 if (this.validate()) {
210 notify_progress('Saving data...', true);
212 new Ajax.Request('backend.php', {
213 parameters: dojo.objectToQuery(this.getValues()),
214 onComplete: function(transport) {
215 notify_callback2(transport);
221 print "<table width=\"100%\" class=\"prefPrefsList\">";
223 print "<h2>" . __("Personal data") . "</h2>";
225 $result = $this->dbh
->query("SELECT email,full_name,otp_enabled,
226 access_level FROM ttrss_users
227 WHERE id = ".$_SESSION["uid"]);
229 $email = htmlspecialchars($this->dbh
->fetch_result($result, 0, "email"));
230 $full_name = htmlspecialchars($this->dbh
->fetch_result($result, 0, "full_name"));
231 $otp_enabled = sql_bool_to_bool($this->dbh
->fetch_result($result, 0, "otp_enabled"));
233 print "<tr><td width=\"40%\">".__('Full name')."</td>";
234 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
235 value=\"$full_name\"></td></tr>";
237 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
238 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
240 if (!SINGLE_USER_MODE
&& !$_SESSION["hide_hello"]) {
242 $access_level = $this->dbh
->fetch_result($result, 0, "access_level");
243 print "<tr><td width=\"40%\">".__('Access level')."</td>";
244 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
249 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
250 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
252 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
253 __("Save data")."</button>";
257 if ($_SESSION["auth_module"]) {
260 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
263 $authenticator = false;
266 if ($authenticator && method_exists($authenticator, "change_password")) {
268 print "<h2>" . __("Password") . "</h2>";
270 $result = $this->dbh
->query("SELECT id FROM ttrss_users
271 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
272 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
274 if ($this->dbh
->num_rows($result) != 0) {
275 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
278 print "<form dojoType=\"dijit.form.Form\">";
280 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
281 evt.preventDefault();
282 if (this.validate()) {
283 notify_progress('Changing password...', true);
285 new Ajax.Request('backend.php', {
286 parameters: dojo.objectToQuery(this.getValues()),
287 onComplete: function(transport) {
289 if (transport.responseText.indexOf('ERROR: ') == 0) {
290 notify_error(transport.responseText.replace('ERROR: ', ''));
292 notify_info(transport.responseText);
293 var warn = $('default_pass_warning');
294 if (warn) Element.hide(warn);
302 print_notice(__("Changing your current password will disable OTP."));
305 print "<table width=\"100%\" class=\"prefPrefsList\">";
307 print "<tr><td width=\"40%\">".__("Old password")."</td>";
308 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
310 print "<tr><td width=\"40%\">".__("New password")."</td>";
312 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
313 name=\"new_password\"></td></tr>";
315 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
317 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
321 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
322 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
324 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
325 __("Change password")."</button>";
329 if ($_SESSION["auth_module"] == "auth_internal") {
331 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
335 print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
337 print "<form dojoType=\"dijit.form.Form\">";
339 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
340 evt.preventDefault();
341 if (this.validate()) {
342 notify_progress('Disabling OTP', true);
344 new Ajax.Request('backend.php', {
345 parameters: dojo.objectToQuery(this.getValues()),
346 onComplete: function(transport) {
348 if (transport.responseText.indexOf('ERROR: ') == 0) {
349 notify_error(transport.responseText.replace('ERROR: ', ''));
351 window.location.reload();
358 print "<table width=\"100%\" class=\"prefPrefsList\">";
360 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
362 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
363 name=\"password\"></td></tr>";
367 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
368 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
370 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
371 __("Disable OTP")."</button>";
377 print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
379 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
381 $csrf_token = $_SESSION["csrf_token"];
383 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
385 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
387 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
388 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
390 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
391 evt.preventDefault();
392 if (this.validate()) {
393 notify_progress('Saving data...', true);
395 new Ajax.Request('backend.php', {
396 parameters: dojo.objectToQuery(this.getValues()),
397 onComplete: function(transport) {
399 if (transport.responseText.indexOf('ERROR:') == 0) {
400 notify_error(transport.responseText.replace('ERROR:', ''));
402 window.location.reload();
409 print "<table width=\"100%\" class=\"prefPrefsList\">";
411 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
413 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
414 name=\"password\"></td></tr>";
416 print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
418 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
420 name=\"otp\"></td></tr>";
422 print "<tr><td colspan=\"2\">";
424 print "</td></tr><tr><td colspan=\"2\">";
429 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
430 __("Enable OTP")."</button>";
440 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION
,
441 "hook_prefs_tab_section", "prefPrefsAuth");
443 print "</div>"; #pane
445 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
447 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
449 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\">
450 if (evt) evt.preventDefault();
451 if (this.validate()) {
452 console.log(dojo.objectToQuery(this.getValues()));
454 new Ajax.Request('backend.php', {
455 parameters: dojo.objectToQuery(this.getValues()),
456 onComplete: function(transport) {
457 var msg = transport.responseText;
461 if (msg == 'PREFS_NEED_RELOAD') {
462 window.location.reload();
471 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
473 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
475 if ($_SESSION["profile"]) {
476 print_notice(__("Some preferences are only available in default profile."));
479 if ($_SESSION["profile"]) {
480 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
481 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
483 initialize_user_prefs($_SESSION["uid"]);
484 $profile_qpart = "profile IS NULL";
487 /* if ($_SESSION["prefs_show_advanced"])
488 $access_query = "true";
490 $access_query = "(access_level = 0 AND section_id != 3)"; */
492 $access_query = 'true';
494 $result = $this->dbh
->query("SELECT DISTINCT
495 ttrss_user_prefs.pref_name,value,type_name,
496 ttrss_prefs_sections.order_id,
498 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
499 WHERE type_id = ttrss_prefs_types.id AND
501 section_id = ttrss_prefs_sections.id AND
502 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
504 owner_uid = ".$_SESSION["uid"]."
505 ORDER BY ttrss_prefs_sections.order_id,pref_name");
509 $active_section = "";
511 $listed_boolean_prefs = array();
513 while ($line = $this->dbh
->fetch_assoc($result)) {
515 if (in_array($line["pref_name"], $prefs_blacklist)) {
519 $type_name = $line["type_name"];
520 $pref_name = $line["pref_name"];
521 $section_name = $this->getSectionName($line["section_id"]);
522 $value = $line["value"];
524 $short_desc = $this->getShortDesc($pref_name);
525 $help_text = $this->getHelpText($pref_name);
527 if (!$short_desc) continue;
529 if ($_SESSION["profile"] && in_array($line["pref_name"],
530 $profile_blacklist)) {
534 if ($active_section != $line["section_id"]) {
536 if ($active_section != "") {
540 print "<table width=\"100%\" class=\"prefPrefsList\">";
542 $active_section = $line["section_id"];
544 print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
548 if ($active_section == 2) {
551 print "<td width=\"40%\" class=\"prefName\">";
553 print __("Language:");
557 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
558 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
567 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
568 print "<label for='CB_$pref_name'>";
572 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
576 print "<td class=\"prefValue\">";
578 if ($pref_name == "USER_TIMEZONE") {
580 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
582 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
583 } else if ($pref_name == "USER_STYLESHEET") {
585 print "<button dojoType=\"dijit.form.Button\"
586 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
588 } else if ($pref_name == "USER_CSS_THEME") {
590 $themes = array_map("basename", glob("themes/*.css"));
592 print_select($pref_name, $value, $themes,
593 'dojoType="dijit.form.Select"');
596 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
598 global $update_intervals_nodefault;
600 print_select_hash($pref_name, $value, $update_intervals_nodefault,
601 'dojoType="dijit.form.Select"');
603 } else if ($type_name == "bool") {
605 array_push($listed_boolean_prefs, $pref_name);
607 $checked = ($value == "true") ?
"checked=\"checked\"" : "";
609 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
610 $disabled = "disabled=\"1\"";
611 $checked = "checked=\"checked\"";
616 print "<input type='checkbox' name='$pref_name' $checked $disabled
617 dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
619 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
620 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
622 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
624 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
625 $disabled = "disabled=\"1\"";
626 $value = FORCE_ARTICLE_PURGE
;
631 print "<input dojoType=\"dijit.form.ValidationTextBox\"
632 required=\"1\" $regexp $disabled
633 name=\"$pref_name\" value=\"$value\">";
635 } else if ($pref_name == "SSL_CERT_SERIAL") {
637 print "<input dojoType=\"dijit.form.ValidationTextBox\"
638 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
639 name=\"$pref_name\" value=\"$value\">";
641 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
642 $has_serial = ($cert_serial) ?
"false" : "true";
644 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
645 onclick=\"insertSSLserial('$cert_serial')\">" .
646 __('Register') . "</button>";
648 print " <button dojoType=\"dijit.form.Button\"
649 onclick=\"insertSSLserial('')\">" .
650 __('Clear') . "</button>";
652 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
653 print "<input dojoType=\"dijit.form.ValidationTextBox\"
654 id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
655 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
656 T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
658 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
660 print "<input dojoType=\"dijit.form.ValidationTextBox\"
662 name=\"$pref_name\" value=\"$value\">";
674 $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
676 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
679 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION
,
680 "hook_prefs_tab_section", "prefPrefsPrefsInside");
682 print '</div>'; # inside pane
683 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
685 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
686 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
688 print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
689 <span>".__('Save configuration')."</span>
690 <div dojoType=\"dijit.DropDownMenu\">
691 <div dojoType=\"dijit.MenuItem\"
692 onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
693 __("Save and exit preferences")."</div>
697 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
698 __('Manage profiles')."</button> ";
700 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
701 __('Reset to defaults')."</button>";
705 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
707 print "<input onclick='toggleAdvancedPrefs()'
708 id='prefs_show_advanced'
709 dojoType=\"dijit.form.CheckBox\"
711 type=\"checkbox\"></input>
712 <label for='prefs_show_advanced'>" .
713 __("Show additional preferences") . "</label>"; */
716 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION
,
717 "hook_prefs_tab_section", "prefPrefsPrefsOutside");
720 print '</div>'; # inner pane
721 print '</div>'; # border container
723 print "</div>"; #pane
725 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
727 print "<h2>".__("Plugins")."</h2>";
729 print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
731 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>."));
733 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
735 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
736 evt.preventDefault();
737 if (this.validate()) {
738 notify_progress('Saving data...', true);
740 new Ajax.Request('backend.php', {
741 parameters: dojo.objectToQuery(this.getValues()),
742 onComplete: function(transport) {
744 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
745 window.location.reload();
752 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
753 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
755 print "<table width='100%' class='prefPluginsList'>";
757 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
759 print "<tr class=\"title\">
760 <td width=\"5%\"> </td>
761 <td width='10%'>".__('Plugin')."</td>
762 <td width=''>".__('Description')."</td>
763 <td width='5%'>".__('Version')."</td>
764 <td width='10%'>".__('Author')."</td></tr>";
766 $system_enabled = array_map("trim", explode(",", PLUGINS
));
767 $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
769 $tmppluginhost = new PluginHost(Db
::get());
770 $tmppluginhost->load_all($tmppluginhost::KIND_ALL
, $_SESSION["uid"]);
771 $tmppluginhost->load_data(true);
773 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
774 $about = $plugin->about();
776 if ($about[3] && strpos($name, "example") === FALSE) {
777 if (in_array($name, $system_enabled)) {
778 $checked = "checked='1'";
785 print "<td align='center'><input disabled='1'
786 dojoType=\"dijit.form.CheckBox\" $checked
787 type=\"checkbox\"></td>";
789 print "<td>$name</td>";
790 print "<td>" . htmlspecialchars($about[1]);
792 print " — <a target=\"_blank\" class=\"visibleLink\"
793 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
796 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
797 print "<td>" . htmlspecialchars($about[2]) . "</td>";
799 if (count($tmppluginhost->get_all($plugin)) > 0) {
800 if (in_array($name, $system_enabled)) {
801 print "<td><a href='#' onclick=\"clearPluginData('$name')\"
802 class='visibleLink'>".__("Clear data")."</a></td>";
811 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
813 print "<tr class=\"title\">
814 <td width=\"5%\"> </td>
815 <td width='10%'>".__('Plugin')."</td>
816 <td width=''>".__('Description')."</td>
817 <td width='5%'>".__('Version')."</td>
818 <td width='10%'>".__('Author')."</td></tr>";
821 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
822 $about = $plugin->about();
824 if (!$about[3] && strpos($name, "example") === FALSE) {
826 if (in_array($name, $system_enabled)) {
827 $checked = "checked='1'";
828 $disabled = "disabled='1'";
830 } else if (in_array($name, $user_enabled)) {
831 $checked = "checked='1'";
833 $rowclass = "Selected";
840 print "<tr class='$rowclass'>";
842 print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
843 dojoType=\"dijit.form.CheckBox\" $checked $disabled
844 type=\"checkbox\"></td>";
846 print "<td><label for='FPCHK-$name'>$name</label></td>";
847 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
849 print " — <a target=\"_blank\" class=\"visibleLink\"
850 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
854 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
855 print "<td>" . htmlspecialchars($about[2]) . "</td>";
857 if (count($tmppluginhost->get_all($plugin)) > 0) {
858 if (in_array($name, $system_enabled) ||
in_array($name, $user_enabled)) {
859 print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
873 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
874 __("Enable selected plugins")."</button></p>";
878 print "</div>"; #pane
881 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB
,
882 "hook_prefs_tab", "prefPrefs");
884 print "</div>"; #container
887 function toggleAdvanced() {
888 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
891 function otpqrcode() {
892 require_once "lib/otphp/vendor/base32.php";
893 require_once "lib/otphp/lib/otp.php";
894 require_once "lib/otphp/lib/totp.php";
895 require_once "lib/phpqrcode/phpqrcode.php";
897 $result = $this->dbh
->query("SELECT login,salt,otp_enabled
899 WHERE id = ".$_SESSION["uid"]);
901 $base32 = new Base32();
903 $login = $this->dbh
->fetch_result($result, 0, "login");
904 $otp_enabled = sql_bool_to_bool($this->dbh
->fetch_result($result, 0, "otp_enabled"));
907 $secret = $base32->encode(sha1($this->dbh
->fetch_result($result, 0, "salt")));
908 $topt = new \OTPHP\
TOTP($secret);
909 print QRcode
::png($topt->provisioning_uri($login));
913 function otpenable() {
914 require_once "lib/otphp/vendor/base32.php";
915 require_once "lib/otphp/lib/otp.php";
916 require_once "lib/otphp/lib/totp.php";
918 $password = $_REQUEST["password"];
919 $otp = $_REQUEST["otp"];
922 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
924 if ($authenticator->check_password($_SESSION["uid"], $password)) {
926 $result = $this->dbh
->query("SELECT salt
928 WHERE id = ".$_SESSION["uid"]);
930 $base32 = new Base32();
932 $secret = $base32->encode(sha1($this->dbh
->fetch_result($result, 0, "salt")));
933 $topt = new \OTPHP\
TOTP($secret);
935 $otp_check = $topt->now();
937 if ($otp == $otp_check) {
938 $this->dbh
->query("UPDATE ttrss_users SET otp_enabled = true WHERE
939 id = " . $_SESSION["uid"]);
943 print "ERROR:".__("Incorrect one time password");
946 print "ERROR:".__("Incorrect password");
951 function otpdisable() {
952 $password = $this->dbh
->escape_string($_REQUEST["password"]);
955 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
957 if ($authenticator->check_password($_SESSION["uid"], $password)) {
959 $this->dbh
->query("UPDATE ttrss_users SET otp_enabled = false WHERE
960 id = " . $_SESSION["uid"]);
964 print "ERROR: ".__("Incorrect password");
969 function setplugins() {
970 if (is_array($_REQUEST["plugins"]))
971 $plugins = join(",", $_REQUEST["plugins"]);
975 set_pref("_ENABLED_PLUGINS", $plugins);
978 function clearplugindata() {
979 $name = $this->dbh
->escape_string($_REQUEST["name"]);
982 $pluginhost->clear_data($pluginhost->get_plugin($name));
985 function customizeCSS() {
986 $value = get_pref("USER_STYLESHEET");
988 $value = str_replace("<br/>", "\n", $value);
990 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"));
992 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
993 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">";
994 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">";
996 print "<table width='100%'><tr><td>";
997 print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
998 style='font-size : 12px; width : 100%; height: 200px;'
999 placeHolder='body#ttrssMain { font-size : 14px; };'
1000 name='value'>$value</textarea>";
1001 print "</td></tr></table>";
1003 print "<div class='dlgButtons'>";
1004 print "<button dojoType=\"dijit.form.Button\"
1005 onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
1006 print "<button dojoType=\"dijit.form.Button\"
1007 onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
1012 function editPrefProfiles() {
1013 print "<div dojoType=\"dijit.Toolbar\">";
1015 print "<div dojoType=\"dijit.form.DropDownButton\">".
1016 "<span>" . __('Select')."</span>";
1017 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1018 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
1019 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1020 print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
1021 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1022 print "</div></div>";
1024 print "<div style=\"float : right\">";
1026 print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
1028 <button dojoType=\"dijit.form.Button\"
1029 onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
1030 __('Create profile')."</button></div>";
1034 $result = $this->dbh
->query("SELECT title,id FROM ttrss_settings_profiles
1035 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1037 print "<div class=\"prefProfileHolder\">";
1039 print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
1041 print "<table width=\"100%\" class=\"prefFeedProfileList\"
1042 cellspacing=\"0\" id=\"prefFeedProfileList\">";
1044 print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
1046 print "<td width='5%' align='center'><input
1048 onclick='toggleSelectRow2(this);'
1049 dojoType=\"dijit.form.CheckBox\"
1050 type=\"checkbox\"></td>";
1052 if (!$_SESSION["profile"]) {
1053 $is_active = __("(active)");
1058 print "<td><span>" .
1059 __("Default profile") . " $is_active</span></td>";
1065 while ($line = $this->dbh
->fetch_assoc($result)) {
1067 $class = ($lnum %
2) ?
"even" : "odd";
1069 $profile_id = $line["id"];
1070 $this_row_id = "id=\"FCATR-$profile_id\"";
1072 print "<tr class=\"placeholder\" $this_row_id>";
1074 $edit_title = htmlspecialchars($line["title"]);
1076 print "<td width='5%' align='center'><input
1077 onclick='toggleSelectRow2(this);'
1078 id='FCATC-$profile_id'
1079 dojoType=\"dijit.form.CheckBox\"
1080 type=\"checkbox\"></td>";
1082 if ($_SESSION["profile"] == $line["id"]) {
1083 $is_active = __("(active)");
1088 print "<td><span dojoType=\"dijit.InlineEditBox\"
1089 width=\"300px\" autoSave=\"false\"
1090 profile-id=\"$profile_id\">" . $edit_title .
1091 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1095 content: {op: 'rpc', method: 'saveprofile',
1097 id: this.srcNodeRef.getAttribute('profile-id')},
1098 load: function(response) {
1099 elem.attr('value', response);
1103 </span> $is_active</td>";
1114 print "<div class='dlgButtons'>
1115 <div style='float : left'>
1116 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
1117 __('Remove selected profiles')."</button>
1118 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
1119 __('Activate profile')."</button>
1122 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
1123 __('Close this window')."</button>";
1128 private function getShortDesc($pref_name) {
1129 if (isset($this->pref_help
[$pref_name])) {
1130 return $this->pref_help
[$pref_name][0];
1135 private function getHelpText($pref_name) {
1136 if (isset($this->pref_help
[$pref_name])) {
1137 return $this->pref_help
[$pref_name][1];
1142 private function getSectionName($id) {
1143 if (isset($this->pref_sections
[$id])) {
1144 return $this->pref_sections
[$id];