]> git.wh0rd.org - tt-rss.git/blob - classes/pref/prefs.php
move db-prefs to OO
[tt-rss.git] / classes / pref / prefs.php
1 <?php
2
3 class Pref_Prefs extends Handler_Protected {
4
5 private $pref_help = array();
6 private $pref_sections = array();
7
8 function csrf_ignore($method) {
9 $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
10
11 return array_search($method, $csrf_ignored) !== false;
12 }
13
14 function __construct($link, $args) {
15 parent::__construct($link, $args);
16
17 $this->pref_sections = array(
18 1 => __('General'),
19 2 => __('Interface'),
20 3 => __('Advanced'),
21 4 => __('Digest')
22 );
23
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"))
58 );
59 }
60
61 function changepassword() {
62
63 $old_pw = $_POST["old_password"];
64 $new_pw = $_POST["new_password"];
65 $con_pw = $_POST["confirm_password"];
66
67 if ($old_pw == "") {
68 print "ERROR: ".__("Old password cannot be blank.");
69 return;
70 }
71
72 if ($new_pw == "") {
73 print "ERROR: ".__("New password cannot be blank.");
74 return;
75 }
76
77 if ($new_pw != $con_pw) {
78 print "ERROR: ".__("Entered passwords do not match.");
79 return;
80 }
81
82 global $pluginhost;
83 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
84
85 if (method_exists($authenticator, "change_password")) {
86 print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
87 } else {
88 print "ERROR: ".__("Function not supported by authentication module.");
89 }
90 }
91
92 function saveconfig() {
93 $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
94
95 foreach ($boolean_prefs as $pref) {
96 if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
97 }
98
99 $need_reload = false;
100
101 foreach (array_keys($_POST) as $pref_name) {
102
103 $pref_name = $this->dbh->escape_string($pref_name);
104 $value = $this->dbh->escape_string($_POST[$pref_name]);
105
106 if ($pref_name == 'DIGEST_PREFERRED_TIME') {
107 if (get_pref('DIGEST_PREFERRED_TIME') != $value) {
108
109 $this->dbh->query("UPDATE ttrss_users SET
110 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
111
112 }
113 }
114
115 if ($pref_name == "language") {
116 if ($_SESSION["language"] != $value) {
117 setcookie("ttrss_lang", $value,
118 time() + SESSION_COOKIE_LIFETIME);
119 $_SESSION["language"] = $value;
120
121 $need_reload = true;
122 }
123 } else {
124 set_pref($pref_name, $value);
125 }
126
127 }
128
129 if ($need_reload) {
130 print "PREFS_NEED_RELOAD";
131 } else {
132 print __("The configuration was saved.");
133 }
134 }
135
136 function getHelp() {
137
138 $pref_name = $this->dbh->escape_string($_REQUEST["pn"]);
139
140 $result = $this->dbh->query("SELECT help_text FROM ttrss_prefs
141 WHERE pref_name = '$pref_name'");
142
143 if ($this->dbh->num_rows($result) > 0) {
144 $help_text = $this->dbh->fetch_result($result, 0, "help_text");
145 print $help_text;
146 } else {
147 printf(__("Unknown option: %s"), $pref_name);
148 }
149 }
150
151 function changeemail() {
152
153 $email = $this->dbh->escape_string($_POST["email"]);
154 $full_name = $this->dbh->escape_string($_POST["full_name"]);
155
156 $active_uid = $_SESSION["uid"];
157
158 $this->dbh->query("UPDATE ttrss_users SET email = '$email',
159 full_name = '$full_name' WHERE id = '$active_uid'");
160
161 print __("Your personal data has been saved.");
162
163 return;
164 }
165
166 function resetconfig() {
167
168 $_SESSION["prefs_op_result"] = "reset-to-defaults";
169
170 if ($_SESSION["profile"]) {
171 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
172 } else {
173 $profile_qpart = "profile IS NULL";
174 }
175
176 $this->dbh->query("DELETE FROM ttrss_user_prefs
177 WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
178
179 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
180
181 echo __("Your preferences are now set to default values.");
182 }
183
184 function index() {
185
186 global $access_level_names;
187
188 $prefs_blacklist = array("STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
189 "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT");
190
191 /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
192
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");
198
199
200 $_SESSION["prefs_op_result"] = "";
201
202 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
203 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
204
205 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
206
207 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
208 evt.preventDefault();
209 if (this.validate()) {
210 notify_progress('Saving data...', true);
211
212 new Ajax.Request('backend.php', {
213 parameters: dojo.objectToQuery(this.getValues()),
214 onComplete: function(transport) {
215 notify_callback2(transport);
216 } });
217
218 }
219 </script>";
220
221 print "<table width=\"100%\" class=\"prefPrefsList\">";
222
223 print "<h2>" . __("Personal data") . "</h2>";
224
225 $result = $this->dbh->query("SELECT email,full_name,otp_enabled,
226 access_level FROM ttrss_users
227 WHERE id = ".$_SESSION["uid"]);
228
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"));
232
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>";
236
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>";
239
240 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
241
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>";
245 }
246
247 print "</table>";
248
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\">";
251
252 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
253 __("Save data")."</button>";
254
255 print "</form>";
256
257 if ($_SESSION["auth_module"]) {
258 global $pluginhost;
259
260 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
261
262 } else {
263 $authenticator = false;
264 }
265
266 if ($authenticator && method_exists($authenticator, "change_password")) {
267
268 print "<h2>" . __("Password") . "</h2>";
269
270 $result = $this->dbh->query("SELECT id FROM ttrss_users
271 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
272 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
273
274 if ($this->dbh->num_rows($result) != 0) {
275 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
276 }
277
278 print "<form dojoType=\"dijit.form.Form\">";
279
280 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
281 evt.preventDefault();
282 if (this.validate()) {
283 notify_progress('Changing password...', true);
284
285 new Ajax.Request('backend.php', {
286 parameters: dojo.objectToQuery(this.getValues()),
287 onComplete: function(transport) {
288 notify('');
289 if (transport.responseText.indexOf('ERROR: ') == 0) {
290 notify_error(transport.responseText.replace('ERROR: ', ''));
291 } else {
292 notify_info(transport.responseText);
293 var warn = $('default_pass_warning');
294 if (warn) Element.hide(warn);
295 }
296 }});
297 this.reset();
298 }
299 </script>";
300
301 if ($otp_enabled) {
302 print_notice(__("Changing your current password will disable OTP."));
303 }
304
305 print "<table width=\"100%\" class=\"prefPrefsList\">";
306
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>";
309
310 print "<tr><td width=\"40%\">".__("New password")."</td>";
311
312 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
313 name=\"new_password\"></td></tr>";
314
315 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
316
317 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
318
319 print "</table>";
320
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\">";
323
324 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
325 __("Change password")."</button>";
326
327 print "</form>";
328
329 if ($_SESSION["auth_module"] == "auth_internal") {
330
331 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
332
333 if ($otp_enabled) {
334
335 print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
336
337 print "<form dojoType=\"dijit.form.Form\">";
338
339 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
340 evt.preventDefault();
341 if (this.validate()) {
342 notify_progress('Disabling OTP', true);
343
344 new Ajax.Request('backend.php', {
345 parameters: dojo.objectToQuery(this.getValues()),
346 onComplete: function(transport) {
347 notify('');
348 if (transport.responseText.indexOf('ERROR: ') == 0) {
349 notify_error(transport.responseText.replace('ERROR: ', ''));
350 } else {
351 window.location.reload();
352 }
353 }});
354 this.reset();
355 }
356 </script>";
357
358 print "<table width=\"100%\" class=\"prefPrefsList\">";
359
360 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
361
362 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
363 name=\"password\"></td></tr>";
364
365 print "</table>";
366
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\">";
369
370 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
371 __("Disable OTP")."</button>";
372
373 print "</form>";
374
375 } else {
376
377 print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
378
379 print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
380
381 $csrf_token = $_SESSION["csrf_token"];
382
383 print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
384
385 print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
386
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\">";
389
390 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
391 evt.preventDefault();
392 if (this.validate()) {
393 notify_progress('Saving data...', true);
394
395 new Ajax.Request('backend.php', {
396 parameters: dojo.objectToQuery(this.getValues()),
397 onComplete: function(transport) {
398 notify('');
399 if (transport.responseText.indexOf('ERROR:') == 0) {
400 notify_error(transport.responseText.replace('ERROR:', ''));
401 } else {
402 window.location.reload();
403 }
404 } });
405
406 }
407 </script>";
408
409 print "<table width=\"100%\" class=\"prefPrefsList\">";
410
411 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
412
413 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
414 name=\"password\"></td></tr>";
415
416 print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
417
418 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
419 required=\"1\"
420 name=\"otp\"></td></tr>";
421
422 print "<tr><td colspan=\"2\">";
423
424 print "</td></tr><tr><td colspan=\"2\">";
425
426 print "</td></tr>";
427 print "</table>";
428
429 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
430 __("Enable OTP")."</button>";
431
432 print "</form>";
433
434 }
435
436 }
437 }
438
439 global $pluginhost;
440 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
441 "hook_prefs_tab_section", "prefPrefsAuth");
442
443 print "</div>"; #pane
444
445 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
446
447 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
448
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()));
453
454 new Ajax.Request('backend.php', {
455 parameters: dojo.objectToQuery(this.getValues()),
456 onComplete: function(transport) {
457 var msg = transport.responseText;
458 if (quit) {
459 gotoMain();
460 } else {
461 if (msg == 'PREFS_NEED_RELOAD') {
462 window.location.reload();
463 } else {
464 notify_info(msg);
465 }
466 }
467 } });
468 }
469 </script>";
470
471 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
472
473 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
474
475 if ($_SESSION["profile"]) {
476 print_notice(__("Some preferences are only available in default profile."));
477 }
478
479 if ($_SESSION["profile"]) {
480 initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
481 $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
482 } else {
483 initialize_user_prefs($_SESSION["uid"]);
484 $profile_qpart = "profile IS NULL";
485 }
486
487 /* if ($_SESSION["prefs_show_advanced"])
488 $access_query = "true";
489 else
490 $access_query = "(access_level = 0 AND section_id != 3)"; */
491
492 $access_query = 'true';
493
494 $result = $this->dbh->query("SELECT DISTINCT
495 ttrss_user_prefs.pref_name,value,type_name,
496 ttrss_prefs_sections.order_id,
497 def_value,section_id
498 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
499 WHERE type_id = ttrss_prefs_types.id AND
500 $profile_qpart AND
501 section_id = ttrss_prefs_sections.id AND
502 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
503 $access_query AND
504 owner_uid = ".$_SESSION["uid"]."
505 ORDER BY ttrss_prefs_sections.order_id,pref_name");
506
507 $lnum = 0;
508
509 $active_section = "";
510
511 $listed_boolean_prefs = array();
512
513 while ($line = $this->dbh->fetch_assoc($result)) {
514
515 if (in_array($line["pref_name"], $prefs_blacklist)) {
516 continue;
517 }
518
519 $type_name = $line["type_name"];
520 $pref_name = $line["pref_name"];
521 $section_name = $this->getSectionName($line["section_id"]);
522 $value = $line["value"];
523
524 $short_desc = $this->getShortDesc($pref_name);
525 $help_text = $this->getHelpText($pref_name);
526
527 if (!$short_desc) continue;
528
529 if ($_SESSION["profile"] && in_array($line["pref_name"],
530 $profile_blacklist)) {
531 continue;
532 }
533
534 if ($active_section != $line["section_id"]) {
535
536 if ($active_section != "") {
537 print "</table>";
538 }
539
540 print "<table width=\"100%\" class=\"prefPrefsList\">";
541
542 $active_section = $line["section_id"];
543
544 print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
545
546 $lnum = 0;
547
548 if ($active_section == 2) {
549 print "<tr>";
550
551 print "<td width=\"40%\" class=\"prefName\">";
552 print "<label>";
553 print __("Language:");
554 print "</label>";
555
556 print "<td>";
557 print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
558 "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
559 print "</td>";
560 print "</tr>";
561 }
562
563 }
564
565 print "<tr>";
566
567 print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
568 print "<label for='CB_$pref_name'>";
569 print $short_desc;
570 print "</label>";
571
572 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
573
574 print "</td>";
575
576 print "<td class=\"prefValue\">";
577
578 if ($pref_name == "USER_TIMEZONE") {
579
580 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
581
582 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
583 } else if ($pref_name == "USER_STYLESHEET") {
584
585 print "<button dojoType=\"dijit.form.Button\"
586 onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
587
588 } else if ($pref_name == "USER_CSS_THEME") {
589
590 $themes = array_map("basename", glob("themes/*.css"));
591
592 print_select($pref_name, $value, $themes,
593 'dojoType="dijit.form.Select"');
594
595
596 } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
597
598 global $update_intervals_nodefault;
599
600 print_select_hash($pref_name, $value, $update_intervals_nodefault,
601 'dojoType="dijit.form.Select"');
602
603 } else if ($type_name == "bool") {
604
605 array_push($listed_boolean_prefs, $pref_name);
606
607 $checked = ($value == "true") ? "checked=\"checked\"" : "";
608
609 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
610 $disabled = "disabled=\"1\"";
611 $checked = "checked=\"checked\"";
612 } else {
613 $disabled = "";
614 }
615
616 print "<input type='checkbox' name='$pref_name' $checked $disabled
617 dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
618
619 } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
620 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
621
622 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
623
624 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
625 $disabled = "disabled=\"1\"";
626 $value = FORCE_ARTICLE_PURGE;
627 } else {
628 $disabled = "";
629 }
630
631 print "<input dojoType=\"dijit.form.ValidationTextBox\"
632 required=\"1\" $regexp $disabled
633 name=\"$pref_name\" value=\"$value\">";
634
635 } else if ($pref_name == "SSL_CERT_SERIAL") {
636
637 print "<input dojoType=\"dijit.form.ValidationTextBox\"
638 id=\"SSL_CERT_SERIAL\" readonly=\"1\"
639 name=\"$pref_name\" value=\"$value\">";
640
641 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
642 $has_serial = ($cert_serial) ? "false" : "true";
643
644 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
645 onclick=\"insertSSLserial('$cert_serial')\">" .
646 __('Register') . "</button>";
647
648 print " <button dojoType=\"dijit.form.Button\"
649 onclick=\"insertSSLserial('')\">" .
650 __('Clear') . "</button>";
651
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>";
657 } else {
658 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
659
660 print "<input dojoType=\"dijit.form.ValidationTextBox\"
661 $regexp
662 name=\"$pref_name\" value=\"$value\">";
663 }
664
665 print "</td>";
666
667 print "</tr>";
668
669 $lnum++;
670 }
671
672 print "</table>";
673
674 $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
675
676 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
677
678 global $pluginhost;
679 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
680 "hook_prefs_tab_section", "prefPrefsPrefsInside");
681
682 print '</div>'; # inside pane
683 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
684
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\">";
687
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>
694 </div>
695 </div>";
696
697 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
698 __('Manage profiles')."</button> ";
699
700 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
701 __('Reset to defaults')."</button>";
702
703 print "&nbsp;";
704
705 /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
706
707 print "<input onclick='toggleAdvancedPrefs()'
708 id='prefs_show_advanced'
709 dojoType=\"dijit.form.CheckBox\"
710 $checked
711 type=\"checkbox\"></input>
712 <label for='prefs_show_advanced'>" .
713 __("Show additional preferences") . "</label>"; */
714
715 global $pluginhost;
716 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
717 "hook_prefs_tab_section", "prefPrefsPrefsOutside");
718
719 print "</form>";
720 print '</div>'; # inner pane
721 print '</div>'; # border container
722
723 print "</div>"; #pane
724
725 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
726
727 print "<h2>".__("Plugins")."</h2>";
728
729 print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
730
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>."));
732
733 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
734
735 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
736 evt.preventDefault();
737 if (this.validate()) {
738 notify_progress('Saving data...', true);
739
740 new Ajax.Request('backend.php', {
741 parameters: dojo.objectToQuery(this.getValues()),
742 onComplete: function(transport) {
743 notify('');
744 if (confirm(__('Selected plugins have been enabled. Reload?'))) {
745 window.location.reload();
746 }
747 } });
748
749 }
750 </script>";
751
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\">";
754
755 print "<table width='100%' class='prefPluginsList'>";
756
757 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
758
759 print "<tr class=\"title\">
760 <td width=\"5%\">&nbsp;</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>";
765
766 $system_enabled = array_map("trim", explode(",", PLUGINS));
767 $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
768
769 $tmppluginhost = new PluginHost(Db::get());
770 $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
771 $tmppluginhost->load_data(true);
772
773 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
774 $about = $plugin->about();
775
776 if ($about[3] && strpos($name, "example") === FALSE) {
777 if (in_array($name, $system_enabled)) {
778 $checked = "checked='1'";
779 } else {
780 $checked = "";
781 }
782
783 print "<tr>";
784
785 print "<td align='center'><input disabled='1'
786 dojoType=\"dijit.form.CheckBox\" $checked
787 type=\"checkbox\"></td>";
788
789 print "<td>$name</td>";
790 print "<td>" . htmlspecialchars($about[1]);
791 if (@$about[4]) {
792 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
793 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
794 }
795 print "</td>";
796 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
797 print "<td>" . htmlspecialchars($about[2]) . "</td>";
798
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>";
803 }
804 }
805
806 print "</tr>";
807
808 }
809 }
810
811 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
812
813 print "<tr class=\"title\">
814 <td width=\"5%\">&nbsp;</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>";
819
820
821 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
822 $about = $plugin->about();
823
824 if (!$about[3] && strpos($name, "example") === FALSE) {
825
826 if (in_array($name, $system_enabled)) {
827 $checked = "checked='1'";
828 $disabled = "disabled='1'";
829 $rowclass = '';
830 } else if (in_array($name, $user_enabled)) {
831 $checked = "checked='1'";
832 $disabled = "";
833 $rowclass = "Selected";
834 } else {
835 $checked = "";
836 $disabled = "";
837 $rowclass = '';
838 }
839
840 print "<tr class='$rowclass'>";
841
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>";
845
846 print "<td><label for='FPCHK-$name'>$name</label></td>";
847 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
848 if (@$about[4]) {
849 print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
850 href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
851 }
852 print "</td>";
853
854 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
855 print "<td>" . htmlspecialchars($about[2]) . "</td>";
856
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>";
860 }
861 }
862
863 print "</tr>";
864
865
866
867 }
868
869 }
870
871 print "</table>";
872
873 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
874 __("Enable selected plugins")."</button></p>";
875
876 print "</form>";
877
878 print "</div>"; #pane
879
880 global $pluginhost;
881 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
882 "hook_prefs_tab", "prefPrefs");
883
884 print "</div>"; #container
885 }
886
887 function toggleAdvanced() {
888 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
889 }
890
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";
896
897 $result = $this->dbh->query("SELECT login,salt,otp_enabled
898 FROM ttrss_users
899 WHERE id = ".$_SESSION["uid"]);
900
901 $base32 = new Base32();
902
903 $login = $this->dbh->fetch_result($result, 0, "login");
904 $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
905
906 if (!$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));
910 }
911 }
912
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";
917
918 $password = $_REQUEST["password"];
919 $otp = $_REQUEST["otp"];
920
921 global $pluginhost;
922 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
923
924 if ($authenticator->check_password($_SESSION["uid"], $password)) {
925
926 $result = $this->dbh->query("SELECT salt
927 FROM ttrss_users
928 WHERE id = ".$_SESSION["uid"]);
929
930 $base32 = new Base32();
931
932 $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
933 $topt = new \OTPHP\TOTP($secret);
934
935 $otp_check = $topt->now();
936
937 if ($otp == $otp_check) {
938 $this->dbh->query("UPDATE ttrss_users SET otp_enabled = true WHERE
939 id = " . $_SESSION["uid"]);
940
941 print "OK";
942 } else {
943 print "ERROR:".__("Incorrect one time password");
944 }
945 } else {
946 print "ERROR:".__("Incorrect password");
947 }
948
949 }
950
951 function otpdisable() {
952 $password = $this->dbh->escape_string($_REQUEST["password"]);
953
954 global $pluginhost;
955 $authenticator = $pluginhost->get_plugin($_SESSION["auth_module"]);
956
957 if ($authenticator->check_password($_SESSION["uid"], $password)) {
958
959 $this->dbh->query("UPDATE ttrss_users SET otp_enabled = false WHERE
960 id = " . $_SESSION["uid"]);
961
962 print "OK";
963 } else {
964 print "ERROR: ".__("Incorrect password");
965 }
966
967 }
968
969 function setplugins() {
970 if (is_array($_REQUEST["plugins"]))
971 $plugins = join(",", $_REQUEST["plugins"]);
972 else
973 $plugins = "";
974
975 set_pref("_ENABLED_PLUGINS", $plugins);
976 }
977
978 function clearplugindata() {
979 $name = $this->dbh->escape_string($_REQUEST["name"]);
980
981 global $pluginhost;
982 $pluginhost->clear_data($pluginhost->get_plugin($name));
983 }
984
985 function customizeCSS() {
986 $value = get_pref("USER_STYLESHEET");
987
988 $value = str_replace("<br/>", "\n", $value);
989
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"));
991
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\">";
995
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>";
1002
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>";
1008 print "</div>";
1009
1010 }
1011
1012 function editPrefProfiles() {
1013 print "<div dojoType=\"dijit.Toolbar\">";
1014
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>";
1023
1024 print "<div style=\"float : right\">";
1025
1026 print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
1027 required=\"1\">
1028 <button dojoType=\"dijit.form.Button\"
1029 onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
1030 __('Create profile')."</button></div>";
1031
1032 print "</div>";
1033
1034 $result = $this->dbh->query("SELECT title,id FROM ttrss_settings_profiles
1035 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1036
1037 print "<div class=\"prefProfileHolder\">";
1038
1039 print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
1040
1041 print "<table width=\"100%\" class=\"prefFeedProfileList\"
1042 cellspacing=\"0\" id=\"prefFeedProfileList\">";
1043
1044 print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
1045
1046 print "<td width='5%' align='center'><input
1047 id='FCATC-0'
1048 onclick='toggleSelectRow2(this);'
1049 dojoType=\"dijit.form.CheckBox\"
1050 type=\"checkbox\"></td>";
1051
1052 if (!$_SESSION["profile"]) {
1053 $is_active = __("(active)");
1054 } else {
1055 $is_active = "";
1056 }
1057
1058 print "<td><span>" .
1059 __("Default profile") . " $is_active</span></td>";
1060
1061 print "</tr>";
1062
1063 $lnum = 1;
1064
1065 while ($line = $this->dbh->fetch_assoc($result)) {
1066
1067 $class = ($lnum % 2) ? "even" : "odd";
1068
1069 $profile_id = $line["id"];
1070 $this_row_id = "id=\"FCATR-$profile_id\"";
1071
1072 print "<tr class=\"placeholder\" $this_row_id>";
1073
1074 $edit_title = htmlspecialchars($line["title"]);
1075
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>";
1081
1082 if ($_SESSION["profile"] == $line["id"]) {
1083 $is_active = __("(active)");
1084 } else {
1085 $is_active = "";
1086 }
1087
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\">
1092 var elem = this;
1093 dojo.xhrPost({
1094 url: 'backend.php',
1095 content: {op: 'rpc', method: 'saveprofile',
1096 value: this.value,
1097 id: this.srcNodeRef.getAttribute('profile-id')},
1098 load: function(response) {
1099 elem.attr('value', response);
1100 }
1101 });
1102 </script>
1103 </span> $is_active</td>";
1104
1105 print "</tr>";
1106
1107 ++$lnum;
1108 }
1109
1110 print "</table>";
1111 print "</form>";
1112 print "</div>";
1113
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>
1120 </div>";
1121
1122 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
1123 __('Close this window')."</button>";
1124 print "</div>";
1125
1126 }
1127
1128 private function getShortDesc($pref_name) {
1129 if (isset($this->pref_help[$pref_name])) {
1130 return $this->pref_help[$pref_name][0];
1131 }
1132 return "";
1133 }
1134
1135 private function getHelpText($pref_name) {
1136 if (isset($this->pref_help[$pref_name])) {
1137 return $this->pref_help[$pref_name][1];
1138 }
1139 return "";
1140 }
1141
1142 private function getSectionName($id) {
1143 if (isset($this->pref_sections[$id])) {
1144 return $this->pref_sections[$id];
1145 }
1146
1147 return "";
1148 }
1149 }
1150 ?>