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