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