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