]>
git.wh0rd.org - tt-rss.git/blob - classes/pref_prefs.php
2 class Pref_Prefs
extends Protected_Handler
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index");
7 return array_search($method, $csrf_ignored) !== false;
10 function changepassword() {
12 $old_pw = $_POST["old_password"];
13 $new_pw = $_POST["new_password"];
14 $con_pw = $_POST["confirm_password"];
17 print "ERROR: ".__("Old password cannot be blank.");
22 print "ERROR: ".__("New password cannot be blank.");
26 if ($new_pw != $con_pw) {
27 print "ERROR: ".__("Entered passwords do not match.");
31 $result = db_query($this->link
, "SELECT salt FROM ttrss_users WHERE
32 id = " . $_SESSION['uid']);
34 $salt = db_fetch_result($result, 0, "salt");
37 $old_pw_hash1 = encrypt_password($old_pw);
38 $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]);
40 $query = "SELECT id FROM ttrss_users WHERE
41 id = ".$_SESSION['uid']." AND (pwd_hash = '$old_pw_hash1' OR
42 pwd_hash = '$old_pw_hash2')";
45 $old_pw_hash = encrypt_password($old_pw, $salt, true);
47 $query = "SELECT id FROM ttrss_users WHERE
48 id = ".$_SESSION['uid']." AND pwd_hash = '$old_pw_hash'";
51 $result = db_query($this->link
, $query);
53 if (db_num_rows($result) == 1) {
55 $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
56 $new_pw_hash = encrypt_password($new_pw, $new_salt, true);
58 db_query($this->link
, "UPDATE ttrss_users SET
59 pwd_hash = '$new_pw_hash', salt = '$new_salt'
60 WHERE id = ".$_SESSION['uid']);
62 $_SESSION["pwd_hash"] = $new_pw_hash;
64 print __("Password has been changed.");
66 print "ERROR: ".__('Old password is incorrect.');
70 function saveconfig() {
72 $_SESSION["prefs_cache"] = false;
74 $orig_theme = get_pref($this->link
, "_THEME_ID");
76 foreach (array_keys($_POST) as $pref_name) {
78 $pref_name = db_escape_string($pref_name);
79 $value = db_escape_string($_POST[$pref_name]);
81 set_pref($this->link
, $pref_name, $value);
85 if ($orig_theme != get_pref($this->link
, "_THEME_ID")) {
86 print "PREFS_THEME_CHANGED";
88 print __("The configuration was saved.");
94 $pref_name = db_escape_string($_REQUEST["pn"]);
96 $result = db_query($this->link
, "SELECT help_text FROM ttrss_prefs
97 WHERE pref_name = '$pref_name'");
99 if (db_num_rows($result) > 0) {
100 $help_text = db_fetch_result($result, 0, "help_text");
103 printf(__("Unknown option: %s"), $pref_name);
107 function changeemail() {
109 $email = db_escape_string($_POST["email"]);
110 $full_name = db_escape_string($_POST["full_name"]);
112 $active_uid = $_SESSION["uid"];
114 db_query($this->link
, "UPDATE ttrss_users SET email = '$email',
115 full_name = '$full_name' WHERE id = '$active_uid'");
117 print __("Your personal data has been saved.");
122 function resetconfig() {
124 $_SESSION["prefs_op_result"] = "reset-to-defaults";
126 if ($_SESSION["profile"]) {
127 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
129 $profile_qpart = "profile IS NULL";
132 db_query($this->link
, "DELETE FROM ttrss_user_prefs
133 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
135 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
137 print "PREFS_THEME_CHANGED";
142 global $access_level_names;
144 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
145 "STRIP_UNSAFE_TAGS");
147 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
148 "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
149 "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
150 "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
151 "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
154 if (!SINGLE_USER_MODE
) {
156 $_SESSION["prefs_op_result"] = "";
158 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
159 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
161 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
163 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
164 evt.preventDefault();
165 if (this.validate()) {
166 notify_progress('Saving data...', true);
168 new Ajax.Request('backend.php', {
169 parameters: dojo.objectToQuery(this.getValues()),
170 onComplete: function(transport) {
171 notify_callback2(transport);
177 print "<table width=\"100%\" class=\"prefPrefsList\">";
179 $result = db_query($this->link
, "SELECT email,full_name,
180 access_level FROM ttrss_users
181 WHERE id = ".$_SESSION["uid"]);
183 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
184 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
186 print "<tr><td width=\"40%\">".__('Full name')."</td>";
187 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
188 value=\"$full_name\"></td></tr>";
190 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
191 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
193 if (!SINGLE_USER_MODE
) {
194 $access_level = db_fetch_result($result, 0, "access_level");
195 print "<tr><td width=\"40%\">".__('Access level')."</td>";
196 print "<td>" . $access_level_names[$access_level] . "</td></tr>";
201 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
202 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
204 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
205 __("Save data")."</button>";
209 $result = db_query($this->link
, "SELECT id FROM ttrss_users
210 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
211 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
213 if (db_num_rows($result) != 0) {
214 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
217 print "<form dojoType=\"dijit.form.Form\">";
219 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
220 evt.preventDefault();
221 if (this.validate()) {
222 notify_progress('Changing password...', true);
224 new Ajax.Request('backend.php', {
225 parameters: dojo.objectToQuery(this.getValues()),
226 onComplete: function(transport) {
228 if (transport.responseText.indexOf('ERROR: ') == 0) {
229 notify_error(transport.responseText.replace('ERROR: ', ''));
231 notify_info(transport.responseText);
232 var warn = $('default_pass_warning');
233 if (warn) Element.hide(warn);
240 print "<table width=\"100%\" class=\"prefPrefsList\">";
242 print "<tr><td width=\"40%\">".__("Old password")."</td>";
243 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
245 print "<tr><td width=\"40%\">".__("New password")."</td>";
247 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
248 name=\"new_password\"></td></tr>";
250 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
252 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
256 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
257 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
259 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
260 __("Change password")."</button>";
264 print "</div>"; #pane
267 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
269 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
271 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
272 evt.preventDefault();
273 if (this.validate()) {
274 console.log(dojo.objectToQuery(this.getValues()));
276 new Ajax.Request('backend.php', {
277 parameters: dojo.objectToQuery(this.getValues()),
278 onComplete: function(transport) {
279 var msg = transport.responseText;
280 if (msg.match('PREFS_THEME_CHANGED')) {
281 window.location.reload();
289 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
291 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
293 if ($_SESSION["profile"]) {
294 print_notice("Some preferences are only available in default profile.");
297 if ($_SESSION["profile"]) {
298 initialize_user_prefs($this->link
, $_SESSION["uid"], $_SESSION["profile"]);
299 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
301 initialize_user_prefs($this->link
, $_SESSION["uid"]);
302 $profile_qpart = "profile IS NULL";
305 $result = db_query($this->link
, "SELECT
306 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
307 section_name,def_value,section_id
308 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
309 WHERE type_id = ttrss_prefs_types.id AND
311 section_id = ttrss_prefs_sections.id AND
312 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
314 owner_uid = ".$_SESSION["uid"]."
315 ORDER BY section_id,short_desc");
319 $active_section = "";
321 while ($line = db_fetch_assoc($result)) {
323 if (in_array($line["pref_name"], $prefs_blacklist)) {
327 if ($_SESSION["profile"] && in_array($line["pref_name"],
328 $profile_blacklist)) {
332 if ($active_section != $line["section_name"]) {
334 if ($active_section != "") {
338 print "<table width=\"100%\" class=\"prefPrefsList\">";
340 $active_section = $line["section_name"];
342 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
344 if ($line["section_id"] == 2) {
345 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
347 $user_theme = get_pref($this->link
, "_THEME_ID");
348 $themes = get_all_themes();
350 print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
351 print "<option value='Default'>".__('Default')."</option>";
352 print "<option value='----------------' disabled=\"1\">--------</option>";
354 foreach ($themes as $t) {
358 if ($base == $user_theme) {
359 $selected = "selected=\"1\"";
364 print "<option $selected value='$base'>$name</option>";
368 print "</select></td></tr>";
375 $type_name = $line["type_name"];
376 $pref_name = $line["pref_name"];
377 $value = $line["value"];
378 $def_value = $line["def_value"];
379 $help_text = $line["help_text"];
381 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
383 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
387 print "<td class=\"prefValue\">";
389 if ($pref_name == "USER_TIMEZONE") {
391 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
393 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
394 } else if ($pref_name == "USER_STYLESHEET") {
396 print "<button dojoType=\"dijit.form.Button\"
397 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
399 } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
401 $limits = array(15, 30, 45, 60);
403 print_select($pref_name, $value, $limits,
404 'dojoType="dijit.form.Select"');
406 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
408 global $update_intervals_nodefault;
410 print_select_hash($pref_name, $value, $update_intervals_nodefault,
411 'dojoType="dijit.form.Select"');
413 } else if ($type_name == "bool") {
415 if ($value == "true") {
421 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE
!= 0) {
422 $disabled = "disabled=\"1\"";
428 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
431 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
432 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
434 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
436 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE
!= 0) {
437 $disabled = "disabled=\"1\"";
438 $value = FORCE_ARTICLE_PURGE
;
443 print "<input dojoType=\"dijit.form.ValidationTextBox\"
444 required=\"1\" $regexp $disabled
445 name=\"$pref_name\" value=\"$value\">";
447 } else if ($pref_name == "SSL_CERT_SERIAL") {
449 print "<input dojoType=\"dijit.form.ValidationTextBox\"
450 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
451 name=\"$pref_name\" value=\"$value\">";
453 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
454 $has_serial = ($cert_serial) ?
"false" : "true";
456 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
457 onclick=\"insertSSLserial('$cert_serial')\">" .
458 __('Register') . "</button>";
460 print " <button dojoType=\"dijit.form.Button\"
461 onclick=\"insertSSLserial('')\">" .
462 __('Clear') . "</button>";
464 } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
465 print "<input dojoType=\"dijit.form.ValidationTextBox\"
466 id=\"$pref_name\" regexp=\"[012]\d:\d\d\" placeHolder=\"12:00\"
467 name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
468 T_sprintf("Current server time: %s", date("H:i")) . "</div>";
470 $regexp = ($type_name == 'integer') ?
'regexp="^\d*$"' : '';
472 print "<input dojoType=\"dijit.form.ValidationTextBox\"
474 name=\"$pref_name\" value=\"$value\">";
486 print '</div>'; # inside pane
487 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
489 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
490 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
492 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
493 __('Save configuration')."</button> ";
495 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
496 __('Manage profiles')."</button> ";
498 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
499 __('Reset to defaults')."</button>";
501 print '</div>'; # inner pane
502 print '</div>'; # border container
506 print "</div>"; #pane
507 print "</div>"; #container