]> git.wh0rd.org Git - tt-rss.git/blob - classes/pref/prefs.php
fix duplicate RCHK check while appending headlines
[tt-rss.git] / classes / pref / prefs.php
1 <?php
2 class Pref_Prefs extends Handler_Protected {
3
4         function csrf_ignore($method) {
5                 $csrf_ignored = array("index", "updateself");
6
7                 return array_search($method, $csrf_ignored) !== false;
8         }
9
10         function changepassword() {
11
12                 $old_pw = $_POST["old_password"];
13                 $new_pw = $_POST["new_password"];
14                 $con_pw = $_POST["confirm_password"];
15
16                 if ($old_pw == "") {
17                         print "ERROR: ".__("Old password cannot be blank.");
18                         return;
19                 }
20
21                 if ($new_pw == "") {
22                         print "ERROR: ".__("New password cannot be blank.");
23                         return;
24                 }
25
26                 if ($new_pw != $con_pw) {
27                         print "ERROR: ".__("Entered passwords do not match.");
28                         return;
29                 }
30
31                 $module_class = "auth_" . $_SESSION["auth_module"];
32                 $authenticator = new $module_class($this->link);
33
34                 if (method_exists($authenticator, "change_password")) {
35                         print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
36                 } else {
37                         print "ERROR: ".__("Function not supported by authentication module.");
38                 }
39         }
40
41         function saveconfig() {
42
43                 $_SESSION["prefs_cache"] = false;
44
45                 $orig_theme = get_pref($this->link, "_THEME_ID");
46
47                 foreach (array_keys($_POST) as $pref_name) {
48
49                         $pref_name = db_escape_string($pref_name);
50                         $value = db_escape_string($_POST[$pref_name]);
51
52                         if ($pref_name == 'DIGEST_PREFERRED_TIME') {
53                                 if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
54
55                                         db_query($this->link, "UPDATE ttrss_users SET
56                                                 last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
57
58                                 }
59                         }
60
61                         set_pref($this->link, $pref_name, $value);
62
63                 }
64
65                 if ($orig_theme != get_pref($this->link, "_THEME_ID")) {
66                         print "PREFS_THEME_CHANGED";
67                 } else {
68                         print __("The configuration was saved.");
69                 }
70         }
71
72         function getHelp() {
73
74                 $pref_name = db_escape_string($_REQUEST["pn"]);
75
76                 $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs
77                         WHERE pref_name = '$pref_name'");
78
79                 if (db_num_rows($result) > 0) {
80                         $help_text = db_fetch_result($result, 0, "help_text");
81                         print $help_text;
82                 } else {
83                         printf(__("Unknown option: %s"), $pref_name);
84                 }
85         }
86
87         function changeemail() {
88
89                 $email = db_escape_string($_POST["email"]);
90                 $full_name = db_escape_string($_POST["full_name"]);
91
92                 $active_uid = $_SESSION["uid"];
93
94                 db_query($this->link, "UPDATE ttrss_users SET email = '$email',
95                         full_name = '$full_name' WHERE id = '$active_uid'");
96
97                 print __("Your personal data has been saved.");
98
99                 return;
100         }
101
102         function resetconfig() {
103
104                 $_SESSION["prefs_op_result"] = "reset-to-defaults";
105
106                 if ($_SESSION["profile"]) {
107                         $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
108                 } else {
109                         $profile_qpart = "profile IS NULL";
110                 }
111
112                 db_query($this->link, "DELETE FROM ttrss_user_prefs
113                         WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
114
115                 initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
116
117                 print "PREFS_THEME_CHANGED";
118         }
119
120         function index() {
121
122                 global $access_level_names;
123
124                 $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD",
125                                         "STRIP_UNSAFE_TAGS");
126
127                 $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
128                                         "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
129                                         "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
130                                         "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
131                                         "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
132
133
134                 $_SESSION["prefs_op_result"] = "";
135
136                 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
137                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
138
139                 print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
140
141                 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
142                 evt.preventDefault();
143                 if (this.validate()) {
144                         notify_progress('Saving data...', true);
145
146                         new Ajax.Request('backend.php', {
147                                 parameters: dojo.objectToQuery(this.getValues()),
148                                 onComplete: function(transport) {
149                                         notify_callback2(transport);
150                         } });
151
152                 }
153                 </script>";
154
155                 print "<table width=\"100%\" class=\"prefPrefsList\">";
156
157                 print "<h2>" . __("Personal data") . "</h2>";
158
159                 $result = db_query($this->link, "SELECT email,full_name,otp_enabled,
160                         access_level FROM ttrss_users
161                         WHERE id = ".$_SESSION["uid"]);
162
163                 $email = htmlspecialchars(db_fetch_result($result, 0, "email"));
164                 $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
165                 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
166
167                 print "<tr><td width=\"40%\">".__('Full name')."</td>";
168                 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
169                         value=\"$full_name\"></td></tr>";
170
171                 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
172                 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
173
174                 if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
175
176                         $access_level = db_fetch_result($result, 0, "access_level");
177                         print "<tr><td width=\"40%\">".__('Access level')."</td>";
178                         print "<td>" . $access_level_names[$access_level] . "</td></tr>";
179                 }
180
181                 print "</table>";
182
183                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
184                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
185
186                 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
187                         __("Save data")."</button>";
188
189                 print "</form>";
190
191                 if  ($_SESSION["auth_module"]) {
192                         $module_class = "auth_" . $_SESSION["auth_module"];
193                         $authenticator = new $module_class($this->link);
194                 } else {
195                         $authenticator = false;
196                 }
197
198                 if ($authenticator && method_exists($authenticator, "change_password")) {
199
200                         print "<h2>" . __("Password") . "</h2>";
201
202                         $result = db_query($this->link, "SELECT id FROM ttrss_users
203                                 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
204                                 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
205
206                         if (db_num_rows($result) != 0) {
207                                 print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
208                         }
209
210                         print "<form dojoType=\"dijit.form.Form\">";
211
212                         print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
213                         evt.preventDefault();
214                         if (this.validate()) {
215                                 notify_progress('Changing password...', true);
216
217                                 new Ajax.Request('backend.php', {
218                                         parameters: dojo.objectToQuery(this.getValues()),
219                                         onComplete: function(transport) {
220                                                 notify('');
221                                                 if (transport.responseText.indexOf('ERROR: ') == 0) {
222                                                         notify_error(transport.responseText.replace('ERROR: ', ''));
223                                                 } else {
224                                                         notify_info(transport.responseText);
225                                                         var warn = $('default_pass_warning');
226                                                         if (warn) Element.hide(warn);
227                                                 }
228                                 }});
229                                 this.reset();
230                         }
231                         </script>";
232
233                         if ($otp_enabled) {
234                                 print_notice("Changing your current password will disable OTP.");
235                         }
236
237                         print "<table width=\"100%\" class=\"prefPrefsList\">";
238
239                         print "<tr><td width=\"40%\">".__("Old password")."</td>";
240                         print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
241
242                         print "<tr><td width=\"40%\">".__("New password")."</td>";
243
244                         print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
245                                 name=\"new_password\"></td></tr>";
246
247                         print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
248
249                         print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
250
251                         print "</table>";
252
253                         print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
254                         print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
255
256                         print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
257                                 __("Change password")."</button>";
258
259                         print "</form>";
260
261                         if ($_SESSION["auth_module"] == "internal") {
262
263                                 print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
264
265                                 if ($otp_enabled) {
266
267                                         print_notice("One time passwords are currently enabled. Enter your current password below to disable.");
268
269                                         print "<form dojoType=\"dijit.form.Form\">";
270
271                                 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
272                                 evt.preventDefault();
273                                 if (this.validate()) {
274                                         notify_progress('Disabling OTP', true);
275
276                                         new Ajax.Request('backend.php', {
277                                                 parameters: dojo.objectToQuery(this.getValues()),
278                                                 onComplete: function(transport) {
279                                                         notify('');
280                                                         if (transport.responseText.indexOf('ERROR: ') == 0) {
281                                                                 notify_error(transport.responseText.replace('ERROR: ', ''));
282                                                         } else {
283                                                                 window.location.reload();
284                                                         }
285                                         }});
286                                         this.reset();
287                                 }
288                                 </script>";
289
290                                 print "<table width=\"100%\" class=\"prefPrefsList\">";
291
292                                 print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
293
294                                 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
295                                         name=\"password\"></td></tr>";
296
297                                 print "</table>";
298
299                                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
300                                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
301
302                                 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
303                                         __("Disable OTP")."</button>";
304
305                                 print "</form>";
306
307                                 } else {
308
309                                         print "<p>".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "</p>";
310
311                                         print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
312
313                                         $csrf_token = $_SESSION["csrf_token"];
314
315                                         print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
316
317                                         print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
318
319                                         print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
320                                         print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
321
322                                         print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
323                                         evt.preventDefault();
324                                         if (this.validate()) {
325                                                 notify_progress('Saving data...', true);
326
327                                                 new Ajax.Request('backend.php', {
328                                                         parameters: dojo.objectToQuery(this.getValues()),
329                                                         onComplete: function(transport) {
330                                                                 notify('');
331                                                                 if (transport.responseText.indexOf('ERROR: ') == 0) {
332                                                                         notify_error(transport.responseText.replace('ERROR: ', ''));
333                                                                 } else {
334                                                                         window.location.reload();
335                                                                 }
336                                                 } });
337
338                                         }
339                                         </script>";
340
341                                         print "<table width=\"100%\" class=\"prefPrefsList\">";
342
343                                         print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
344
345                                         print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
346                                                 name=\"password\"></td></tr>";
347
348                                         print "<tr><td colspan=\"2\">";
349
350                                         print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\"
351                                                 type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> ";
352                                         print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>";
353
354                                         print "</td></tr><tr><td colspan=\"2\">";
355
356                                         print "</td></tr>";
357                                         print "</table>";
358
359                                         print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
360                                                 __("Enable OTP")."</button>";
361
362                                         print "</form>";
363
364                                 }
365
366                         }
367                 }
368
369                 global $pluginhost;
370                 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
371                         "hook_prefs_tab_section", "prefPrefsAuth");
372
373                 print "</div>"; #pane
374
375                 print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
376
377                 print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
378
379                 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
380                 evt.preventDefault();
381                 if (this.validate()) {
382                         console.log(dojo.objectToQuery(this.getValues()));
383
384                         new Ajax.Request('backend.php', {
385                                 parameters: dojo.objectToQuery(this.getValues()),
386                                 onComplete: function(transport) {
387                                         var msg = transport.responseText;
388                                         if (msg.match('PREFS_THEME_CHANGED')) {
389                                                 window.location.reload();
390                                         } else {
391                                                 notify_info(msg);
392                                         }
393                         } });
394                 }
395                 </script>";
396
397                 print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
398
399                 print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
400
401                 if ($_SESSION["profile"]) {
402                         print_notice("Some preferences are only available in default profile.");
403                 }
404
405                 if ($_SESSION["profile"]) {
406                         initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
407                         $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
408                 } else {
409                         initialize_user_prefs($this->link, $_SESSION["uid"]);
410                         $profile_qpart = "profile IS NULL";
411                 }
412
413                 if ($_SESSION["prefs_show_advanced"])
414                         $access_query = "true";
415                 else
416                         $access_query = "(access_level = 0 AND section_id != 3)";
417
418                 $result = db_query($this->link, "SELECT DISTINCT
419                         ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
420                         ttrss_prefs_sections.order_id,
421                         section_name,def_value,section_id
422                         FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
423                         WHERE type_id = ttrss_prefs_types.id AND
424                                 $profile_qpart AND
425                                 section_id = ttrss_prefs_sections.id AND
426                                 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
427                                 $access_query AND
428                                 short_desc != '' AND
429                                 owner_uid = ".$_SESSION["uid"]."
430                         ORDER BY ttrss_prefs_sections.order_id,short_desc");
431
432                 $lnum = 0;
433
434                 $active_section = "";
435
436                 while ($line = db_fetch_assoc($result)) {
437
438                         if (in_array($line["pref_name"], $prefs_blacklist)) {
439                                 continue;
440                         }
441
442                         if ($_SESSION["profile"] && in_array($line["pref_name"],
443                                         $profile_blacklist)) {
444                                 continue;
445                         }
446
447                         if ($active_section != $line["section_name"]) {
448
449                                 if ($active_section != "") {
450                                         print "</table>";
451                                 }
452
453                                 print "<table width=\"100%\" class=\"prefPrefsList\">";
454
455                                 $active_section = $line["section_name"];
456
457                                 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
458
459                                 if ($line["section_id"] == 2) {
460                                         print "<tr><td width=\"40%\">".__("Select theme")."</td>";
461
462                                         $user_theme = get_pref($this->link, "_THEME_ID");
463                                         $themes = get_all_themes();
464
465                                         print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">";
466                                         print "<option value='Default'>".__('Default')."</option>";
467                                         print "<option value='----------------' disabled=\"1\">--------</option>";
468
469                                         foreach ($themes as $t) {
470                                                 $base = $t['base'];
471                                                 $name = $t['name'];
472
473                                                 if ($base == $user_theme) {
474                                                         $selected = "selected=\"1\"";
475                                                 } else {
476                                                         $selected = "";
477                                                 }
478
479                                                 print "<option $selected value='$base'>$name</option>";
480
481                                         }
482
483                                         print "</select></td></tr>";
484                                 }
485                                 $lnum = 0;
486                         }
487
488                         print "<tr>";
489
490                         $type_name = $line["type_name"];
491                         $pref_name = $line["pref_name"];
492                         $value = $line["value"];
493                         $def_value = $line["def_value"];
494                         $help_text = $line["help_text"];
495
496                         print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]);
497
498                         if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
499
500                         print "</td>";
501
502                         print "<td class=\"prefValue\">";
503
504                         if ($pref_name == "USER_TIMEZONE") {
505
506                                 $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
507
508                                 print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
509                         } else if ($pref_name == "USER_STYLESHEET") {
510
511                                 print "<button dojoType=\"dijit.form.Button\"
512                                         onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
513
514                         } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") {
515
516                                 $limits = array(15, 30, 45, 60);
517
518                                 print_select($pref_name, $value, $limits,
519                                         'dojoType="dijit.form.Select"');
520
521                         } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
522
523                                 global $update_intervals_nodefault;
524
525                                 print_select_hash($pref_name, $value, $update_intervals_nodefault,
526                                         'dojoType="dijit.form.Select"');
527
528                         } else if ($type_name == "bool") {
529
530                                 if ($value == "true") {
531                                         $value = __("Yes");
532                                 } else {
533                                         $value = __("No");
534                                 }
535
536                                 if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
537                                         $disabled = "disabled=\"1\"";
538                                         $value = __("Yes");
539                                 } else {
540                                         $disabled = "";
541                                 }
542
543                                 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")),
544                                         $disabled);
545
546                         } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT',
547                                         'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
548
549                                 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
550
551                                 if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
552                                         $disabled = "disabled=\"1\"";
553                                         $value = FORCE_ARTICLE_PURGE;
554                                 } else {
555                                         $disabled = "";
556                                 }
557
558                                 print "<input dojoType=\"dijit.form.ValidationTextBox\"
559                                         required=\"1\" $regexp $disabled
560                                         name=\"$pref_name\" value=\"$value\">";
561
562                         } else if ($pref_name == "SSL_CERT_SERIAL") {
563
564                                 print "<input dojoType=\"dijit.form.ValidationTextBox\"
565                                         id=\"SSL_CERT_SERIAL\" readonly=\"1\"
566                                         name=\"$pref_name\" value=\"$value\">";
567
568                                 $cert_serial = htmlspecialchars(get_ssl_certificate_id());
569                                 $has_serial = ($cert_serial) ? "false" : "true";
570
571                                 print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
572                                         onclick=\"insertSSLserial('$cert_serial')\">" .
573                                         __('Register') . "</button>";
574
575                                 print " <button dojoType=\"dijit.form.Button\"
576                                         onclick=\"insertSSLserial('')\">" .
577                                         __('Clear') . "</button>";
578
579                         } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
580                                 print "<input dojoType=\"dijit.form.ValidationTextBox\"
581                                         id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
582                                         name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
583                                         T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
584                         } else {
585                                 $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
586
587                                 print "<input dojoType=\"dijit.form.ValidationTextBox\"
588                                         $regexp
589                                         name=\"$pref_name\" value=\"$value\">";
590                         }
591
592                         print "</td>";
593
594                         print "</tr>";
595
596                         $lnum++;
597                 }
598
599                 print "</table>";
600
601                 global $pluginhost;
602                 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
603                         "hook_prefs_tab_section", "prefPrefsPrefsInside");
604
605                 print '</div>'; # inside pane
606                 print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
607
608                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
609                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
610
611                 print "<button dojoType=\"dijit.form.Button\" type=\"submit\">".
612                         __('Save configuration')."</button> ";
613
614                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
615                         __('Manage profiles')."</button> ";
616
617                 print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
618                         __('Reset to defaults')."</button>";
619
620                 print "&nbsp;";
621
622                 $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
623
624                 print "<input onclick='toggleAdvancedPrefs()'
625                                 id='prefs_show_advanced'
626                                 dojoType=\"dijit.form.CheckBox\"
627                                 $checked
628                                 type=\"checkbox\"></input>
629                                 <label for='prefs_show_advanced'>" .
630                                 __("Show additional preferences") . "</label>";
631
632                 global $pluginhost;
633                 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
634                         "hook_prefs_tab_section", "prefPrefsPrefsOutside");
635
636                 print "</form>";
637                 print '</div>'; # inner pane
638                 print '</div>'; # border container
639
640                 print "</div>"; #pane
641
642                 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
643
644                 print "<h2>".__("Plugins")."</h2>";
645
646                 print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect.");
647
648                 print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
649
650                 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
651                 evt.preventDefault();
652                 if (this.validate()) {
653                         notify_progress('Saving data...', true);
654
655                         new Ajax.Request('backend.php', {
656                                 parameters: dojo.objectToQuery(this.getValues()),
657                                 onComplete: function(transport) {
658                                         notify('');
659                                         if (confirm(__('Selected plugins have been enabled. Reload?'))) {
660                                                 window.location.reload();
661                                         }
662                         } });
663
664                 }
665                 </script>";
666
667                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
668                 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
669
670                 print "<table width='100%' class='prefPluginsList'>";
671
672                 print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
673
674                 print "<tr class=\"title\">
675                                 <td width=\"5%\">&nbsp;</td>
676                                 <td width='10%'>".__('Plugin')."</td>
677                                 <td width=''>".__('Description')."</td>
678                                 <td width='5%'>".__('Version')."</td>
679                                 <td width='10%'>".__('Author')."</td></tr>";
680
681                 $system_enabled = array_map("trim", explode(",", PLUGINS));
682                 $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
683
684                 $tmppluginhost = new PluginHost($link);
685                 $tmppluginhost->load_all($tmppluginhost::KIND_ALL);
686
687                 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
688                         $about = $plugin->about();
689
690                         if ($about[3] && strpos($name, "example") === FALSE) {
691                                 if (in_array($name, $system_enabled)) {
692                                         $checked = "checked='1'";
693                                 } else {
694                                         $checked = "";
695                                 }
696
697                                 print "<tr>";
698
699                                 print "<td align='center'><input disabled='1'
700                                                 dojoType=\"dijit.form.CheckBox\" $checked
701                                                 type=\"checkbox\"></td>";
702
703                                 print "<td>$name</td>";
704                                 print "<td>" . htmlspecialchars($about[1]) . "</td>";
705                                 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
706                                 print "<td>" . htmlspecialchars($about[2]) . "</td>";
707
708                                 print "</tr>";
709
710                         }
711                 }
712
713                 print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
714
715                 print "<tr class=\"title\">
716                                 <td width=\"5%\">&nbsp;</td>
717                                 <td width='10%'>".__('Plugin')."</td>
718                                 <td width=''>".__('Description')."</td>
719                                 <td width='5%'>".__('Version')."</td>
720                                 <td width='10%'>".__('Author')."</td></tr>";
721
722
723                 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
724                         $about = $plugin->about();
725
726                         if (!$about[3] && strpos($name, "example") === FALSE) {
727
728                                 if (in_array($name, $system_enabled)) {
729                                         $checked = "checked='1'";
730                                         $disabled = "disabled='1'";
731                                         $rowclass = '';
732                                 } else if (in_array($name, $user_enabled)) {
733                                         $checked = "checked='1'";
734                                         $disabled = "";
735                                         $rowclass = "Selected";
736                                 } else {
737                                         $checked = "";
738                                         $disabled = "";
739                                         $rowclass = '';
740                                 }
741
742                                 print "<tr class='$rowclass'>";
743
744                                 print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
745                                         dojoType=\"dijit.form.CheckBox\" $checked $disabled
746                                         type=\"checkbox\"></td>";
747
748                                 print "<td><label for='FPCHK-$name'>$name</label></td>";
749                                 print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label></td>";
750                                 print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
751                                 print "<td>" . htmlspecialchars($about[2]) . "</td>";
752
753                                 print "</tr>";
754
755
756
757                         }
758
759                 }
760
761                 print "</table>";
762
763                 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
764                         __("Enable selected plugins")."</button></p>";
765
766                 print "</form>";
767
768                 print "</div>"; #pane
769
770                 global $pluginhost;
771                 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
772                         "hook_prefs_tab", "prefPrefs");
773
774                 print "</div>"; #container
775         }
776
777         function toggleAdvanced() {
778                 $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
779         }
780
781         function otpqrcode() {
782                 require_once "lib/otphp/vendor/base32.php";
783                 require_once "lib/otphp/lib/otp.php";
784                 require_once "lib/otphp/lib/totp.php";
785                 require_once "lib/phpqrcode/phpqrcode.php";
786
787                 $result = db_query($this->link, "SELECT login,salt,otp_enabled
788                         FROM ttrss_users
789                         WHERE id = ".$_SESSION["uid"]);
790
791                 $base32 = new Base32();
792
793                 $login = db_fetch_result($result, 0, "login");
794                 $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
795
796                 if (!$otp_enabled) {
797                         $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
798                         $topt = new \OTPHP\TOTP($secret);
799                         print QRcode::png($topt->provisioning_uri($login));
800                 }
801         }
802
803         function otpenable() {
804                 $password = db_escape_string($_REQUEST["password"]);
805
806                 $module_class = "auth_" . $_SESSION["auth_module"];
807                 $authenticator = new $module_class($this->link);
808                 $enable_otp = $_REQUEST["enable_otp"] == "on";
809
810                 if ($authenticator->check_password($_SESSION["uid"], $password)) {
811
812                         if ($enable_otp) {
813                                 db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
814                                         id = " . $_SESSION["uid"]);
815
816                                 print "OK";
817                         }
818                 } else {
819                         print "ERROR: ".__("Incorrect password");
820                 }
821
822         }
823
824         function otpdisable() {
825                 $password = db_escape_string($_REQUEST["password"]);
826
827                 $module_class = "auth_" . $_SESSION["auth_module"];
828                 $authenticator = new $module_class($this->link);
829
830                 if ($authenticator->check_password($_SESSION["uid"], $password)) {
831
832                         db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
833                                 id = " . $_SESSION["uid"]);
834
835                         print "OK";
836                 } else {
837                         print "ERROR: ".__("Incorrect password");
838                 }
839
840         }
841
842         function setplugins() {
843                 $plugins = join(",", $_REQUEST["plugins"]);
844
845                 set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
846         }
847 }
848 ?>