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