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