prefs.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. <?php
  2. class Pref_Prefs extends Handler_Protected {
  3. private $pref_help = array();
  4. private $pref_sections = array();
  5. function csrf_ignore($method) {
  6. $csrf_ignored = array("index", "updateself", "customizecss", "editprefprofiles");
  7. return array_search($method, $csrf_ignored) !== false;
  8. }
  9. function __construct($args) {
  10. parent::__construct($args);
  11. $this->pref_sections = array(
  12. 1 => __('General'),
  13. 2 => __('Interface'),
  14. 3 => __('Advanced'),
  15. 4 => __('Digest')
  16. );
  17. $this->pref_help = array(
  18. "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""),
  19. "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), __("When auto-detecting tags in articles these tags will not be applied (comma-separated list).")),
  20. "CDM_AUTO_CATCHUP" => array(__("Automatically mark articles as read"), __("This option enables marking articles as read automatically while you scroll article list.")),
  21. "CDM_EXPANDED" => array(__("Automatically expand articles in combined mode"), ""),
  22. "COMBINED_DISPLAY_MODE" => array(__("Combined feed display"), __("Display expanded list of feed articles, instead of separate displays for headlines and article content")),
  23. "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feed as read"), ""),
  24. "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once"), ""),
  25. "DEFAULT_UPDATE_INTERVAL" => array(__("Default feed update interval"), __("Shortest interval at which a feed will be checked for updates regardless of update method")),
  26. "DIGEST_CATCHUP" => array(__("Mark articles in e-mail digest as read"), ""),
  27. "DIGEST_ENABLE" => array(__("Enable e-mail digest"), __("This option enables sending daily digest of new (and unread) headlines on your configured e-mail address")),
  28. "DIGEST_PREFERRED_TIME" => array(__("Try to send digests around specified time"), __("Uses UTC timezone")),
  29. "ENABLE_API_ACCESS" => array(__("Enable API access"), __("Allows external clients to access this account through the API")),
  30. "ENABLE_FEED_CATS" => array(__("Enable feed categories"), ""),
  31. "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""),
  32. "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles (in hours)"), ""),
  33. "HIDE_READ_FEEDS" => array(__("Hide feeds with no unread articles"), ""),
  34. "HIDE_READ_SHOWS_SPECIAL" => array(__("Show special feeds when hiding read feeds"), ""),
  35. "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.")),
  36. "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("On catchup show next feed"), __("Automatically open next feed with unread articles after marking one as read")),
  37. "PURGE_OLD_DAYS" => array(__("Purge articles after this number of days (0 - disables)"), ""),
  38. "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles"), ""),
  39. "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)"), ""),
  40. "SHORT_DATE_FORMAT" => array(__("Short date format"), ""),
  41. "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines list"), ""),
  42. "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")),
  43. "SSL_CERT_SERIAL" => array(__("Login with an SSL certificate"), __("Click to register your SSL client certificate with tt-rss")),
  44. "STRIP_IMAGES" => array(__("Do not embed images in articles"), ""),
  45. "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")),
  46. "USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
  47. "USER_TIMEZONE" => array(__("Time zone"), ""),
  48. "VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
  49. "USER_LANGUAGE" => array(__("Language")),
  50. "USER_CSS_THEME" => array(__("Theme"), __("Select one of the available CSS themes"))
  51. );
  52. }
  53. function changepassword() {
  54. $old_pw = $_POST["old_password"];
  55. $new_pw = $_POST["new_password"];
  56. $con_pw = $_POST["confirm_password"];
  57. if ($old_pw == "") {
  58. print "ERROR: ".format_error("Old password cannot be blank.");
  59. return;
  60. }
  61. if ($new_pw == "") {
  62. print "ERROR: ".format_error("New password cannot be blank.");
  63. return;
  64. }
  65. if ($new_pw != $con_pw) {
  66. print "ERROR: ".format_error("Entered passwords do not match.");
  67. return;
  68. }
  69. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  70. if (method_exists($authenticator, "change_password")) {
  71. print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw));
  72. } else {
  73. print "ERROR: ".format_error("Function not supported by authentication module.");
  74. }
  75. }
  76. function saveconfig() {
  77. $boolean_prefs = explode(",", $_POST["boolean_prefs"]);
  78. foreach ($boolean_prefs as $pref) {
  79. if (!isset($_POST[$pref])) $_POST[$pref] = 'false';
  80. }
  81. $need_reload = false;
  82. foreach (array_keys($_POST) as $pref_name) {
  83. $pref_name = $this->dbh->escape_string($pref_name);
  84. $value = $this->dbh->escape_string($_POST[$pref_name]);
  85. if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  86. if (get_pref('DIGEST_PREFERRED_TIME') != $value) {
  87. $this->dbh->query("UPDATE ttrss_users SET
  88. last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
  89. }
  90. }
  91. if ($pref_name == "USER_LANGUAGE") {
  92. if ($_SESSION["language"] != $value) {
  93. $need_reload = true;
  94. }
  95. }
  96. set_pref($pref_name, $value);
  97. }
  98. if ($need_reload) {
  99. print "PREFS_NEED_RELOAD";
  100. } else {
  101. print __("The configuration was saved.");
  102. }
  103. }
  104. function changeemail() {
  105. $email = $this->dbh->escape_string($_POST["email"]);
  106. $full_name = $this->dbh->escape_string($_POST["full_name"]);
  107. $active_uid = $_SESSION["uid"];
  108. $this->dbh->query("UPDATE ttrss_users SET email = '$email',
  109. full_name = '$full_name' WHERE id = '$active_uid'");
  110. print __("Your personal data has been saved.");
  111. return;
  112. }
  113. function resetconfig() {
  114. $_SESSION["prefs_op_result"] = "reset-to-defaults";
  115. if ($_SESSION["profile"]) {
  116. $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
  117. } else {
  118. $profile_qpart = "profile IS NULL";
  119. }
  120. $this->dbh->query("DELETE FROM ttrss_user_prefs
  121. WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
  122. initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
  123. echo __("Your preferences are now set to default values.");
  124. }
  125. function index() {
  126. global $access_level_names;
  127. $prefs_blacklist = array("ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES",
  128. "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT",
  129. "FEEDS_SORT_BY_UNREAD");
  130. /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
  131. $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
  132. "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
  133. "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
  134. "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
  135. "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
  136. $_SESSION["prefs_op_result"] = "";
  137. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  138. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
  139. print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
  140. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  141. evt.preventDefault();
  142. if (this.validate()) {
  143. notify_progress('Saving data...', true);
  144. new Ajax.Request('backend.php', {
  145. parameters: dojo.objectToQuery(this.getValues()),
  146. onComplete: function(transport) {
  147. notify_callback2(transport);
  148. } });
  149. }
  150. </script>";
  151. print "<table width=\"100%\" class=\"prefPrefsList\">";
  152. print "<h2>" . __("Personal data") . "</h2>";
  153. $result = $this->dbh->query("SELECT email,full_name,otp_enabled,
  154. access_level FROM ttrss_users
  155. WHERE id = ".$_SESSION["uid"]);
  156. $email = htmlspecialchars($this->dbh->fetch_result($result, 0, "email"));
  157. $full_name = htmlspecialchars($this->dbh->fetch_result($result, 0, "full_name"));
  158. $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
  159. print "<tr><td width=\"40%\">".__('Full name')."</td>";
  160. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
  161. value=\"$full_name\"></td></tr>";
  162. print "<tr><td width=\"40%\">".__('E-mail')."</td>";
  163. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
  164. if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
  165. $access_level = $this->dbh->fetch_result($result, 0, "access_level");
  166. print "<tr><td width=\"40%\">".__('Access level')."</td>";
  167. print "<td>" . $access_level_names[$access_level] . "</td></tr>";
  168. }
  169. print "</table>";
  170. print_hidden("op", "pref-prefs");
  171. print_hidden("method", "changeemail");
  172. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  173. __("Save data")."</button>";
  174. print "</form>";
  175. if ($_SESSION["auth_module"]) {
  176. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  177. } else {
  178. $authenticator = false;
  179. }
  180. if ($authenticator && method_exists($authenticator, "change_password")) {
  181. print "<h2>" . __("Password") . "</h2>";
  182. print "<div style='display : none' id='pwd_change_infobox'></div>";
  183. $result = $this->dbh->query("SELECT id FROM ttrss_users
  184. WHERE id = ".$_SESSION["uid"]." AND pwd_hash
  185. = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
  186. if ($this->dbh->num_rows($result) != 0) {
  187. print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
  188. }
  189. print "<form dojoType=\"dijit.form.Form\">";
  190. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  191. evt.preventDefault();
  192. if (this.validate()) {
  193. notify_progress('Changing password...', true);
  194. new Ajax.Request('backend.php', {
  195. parameters: dojo.objectToQuery(this.getValues()),
  196. onComplete: function(transport) {
  197. notify('');
  198. if (transport.responseText.indexOf('ERROR: ') == 0) {
  199. $('pwd_change_infobox').innerHTML =
  200. transport.responseText.replace('ERROR: ', '');
  201. } else {
  202. $('pwd_change_infobox').innerHTML =
  203. transport.responseText.replace('ERROR: ', '');
  204. var warn = $('default_pass_warning');
  205. if (warn) Element.hide(warn);
  206. }
  207. new Effect.Appear('pwd_change_infobox');
  208. }});
  209. this.reset();
  210. }
  211. </script>";
  212. if ($otp_enabled) {
  213. print_notice(__("Changing your current password will disable OTP."));
  214. }
  215. print "<table width=\"100%\" class=\"prefPrefsList\">";
  216. print "<tr><td width=\"40%\">".__("Old password")."</td>";
  217. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
  218. print "<tr><td width=\"40%\">".__("New password")."</td>";
  219. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  220. name=\"new_password\"></td></tr>";
  221. print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
  222. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
  223. print "</table>";
  224. print_hidden("op", "pref-prefs");
  225. print_hidden("method", "changepassword");
  226. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  227. __("Change password")."</button>";
  228. print "</form>";
  229. if ($_SESSION["auth_module"] == "auth_internal") {
  230. print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
  231. if ($otp_enabled) {
  232. print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
  233. print "<form dojoType=\"dijit.form.Form\">";
  234. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  235. evt.preventDefault();
  236. if (this.validate()) {
  237. notify_progress('Disabling OTP', true);
  238. new Ajax.Request('backend.php', {
  239. parameters: dojo.objectToQuery(this.getValues()),
  240. onComplete: function(transport) {
  241. notify('');
  242. if (transport.responseText.indexOf('ERROR: ') == 0) {
  243. notify_error(transport.responseText.replace('ERROR: ', ''));
  244. } else {
  245. window.location.reload();
  246. }
  247. }});
  248. this.reset();
  249. }
  250. </script>";
  251. print "<table width=\"100%\" class=\"prefPrefsList\">";
  252. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  253. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  254. name=\"password\"></td></tr>";
  255. print "</table>";
  256. print_hidden("op", "pref-prefs");
  257. print_hidden("method", "otpdisable");
  258. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  259. __("Disable OTP")."</button>";
  260. print "</form>";
  261. } else if (function_exists("imagecreatefromstring")) {
  262. print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."));
  263. print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
  264. $csrf_token = $_SESSION["csrf_token"];
  265. print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
  266. print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
  267. print_hidden("op", "pref-prefs");
  268. print_hidden("method", "otpenable");
  269. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  270. evt.preventDefault();
  271. if (this.validate()) {
  272. notify_progress('Saving data...', true);
  273. new Ajax.Request('backend.php', {
  274. parameters: dojo.objectToQuery(this.getValues()),
  275. onComplete: function(transport) {
  276. notify('');
  277. if (transport.responseText.indexOf('ERROR:') == 0) {
  278. notify_error(transport.responseText.replace('ERROR:', ''));
  279. } else {
  280. window.location.reload();
  281. }
  282. } });
  283. }
  284. </script>";
  285. print "<table width=\"100%\" class=\"prefPrefsList\">";
  286. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  287. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  288. name=\"password\"></td></tr>";
  289. print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
  290. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
  291. required=\"1\"
  292. name=\"otp\"></td></tr>";
  293. print "<tr><td colspan=\"2\">";
  294. print "</td></tr><tr><td colspan=\"2\">";
  295. print "</td></tr>";
  296. print "</table>";
  297. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  298. __("Enable OTP")."</button>";
  299. print "</form>";
  300. } else {
  301. print_notice(__("PHP GD functions are required for OTP support."));
  302. }
  303. }
  304. }
  305. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  306. "hook_prefs_tab_section", "prefPrefsAuth");
  307. print "</div>"; #pane
  308. print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
  309. print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">";
  310. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt, quit\">
  311. if (evt) evt.preventDefault();
  312. if (this.validate()) {
  313. console.log(dojo.objectToQuery(this.getValues()));
  314. new Ajax.Request('backend.php', {
  315. parameters: dojo.objectToQuery(this.getValues()),
  316. onComplete: function(transport) {
  317. var msg = transport.responseText;
  318. if (quit) {
  319. gotoMain();
  320. } else {
  321. if (msg == 'PREFS_NEED_RELOAD') {
  322. window.location.reload();
  323. } else {
  324. notify_info(msg);
  325. }
  326. }
  327. } });
  328. }
  329. </script>";
  330. print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
  331. print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
  332. if ($_SESSION["profile"]) {
  333. print_notice(__("Some preferences are only available in default profile."));
  334. }
  335. if ($_SESSION["profile"]) {
  336. initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
  337. $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
  338. } else {
  339. initialize_user_prefs($_SESSION["uid"]);
  340. $profile_qpart = "profile IS NULL";
  341. }
  342. /* if ($_SESSION["prefs_show_advanced"])
  343. $access_query = "true";
  344. else
  345. $access_query = "(access_level = 0 AND section_id != 3)"; */
  346. $access_query = 'true';
  347. $result = $this->dbh->query("SELECT DISTINCT
  348. ttrss_user_prefs.pref_name,value,type_name,
  349. ttrss_prefs_sections.order_id,
  350. def_value,section_id
  351. FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
  352. WHERE type_id = ttrss_prefs_types.id AND
  353. $profile_qpart AND
  354. section_id = ttrss_prefs_sections.id AND
  355. ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
  356. $access_query AND
  357. owner_uid = ".$_SESSION["uid"]."
  358. ORDER BY ttrss_prefs_sections.order_id,pref_name");
  359. $lnum = 0;
  360. $active_section = "";
  361. $listed_boolean_prefs = array();
  362. while ($line = $this->dbh->fetch_assoc($result)) {
  363. if (in_array($line["pref_name"], $prefs_blacklist)) {
  364. continue;
  365. }
  366. $type_name = $line["type_name"];
  367. $pref_name = $line["pref_name"];
  368. $section_name = $this->getSectionName($line["section_id"]);
  369. $value = $line["value"];
  370. $short_desc = $this->getShortDesc($pref_name);
  371. $help_text = $this->getHelpText($pref_name);
  372. if (!$short_desc) continue;
  373. if ($_SESSION["profile"] && in_array($line["pref_name"],
  374. $profile_blacklist)) {
  375. continue;
  376. }
  377. if ($active_section != $line["section_id"]) {
  378. if ($active_section != "") {
  379. print "</table>";
  380. }
  381. print "<table width=\"100%\" class=\"prefPrefsList\">";
  382. $active_section = $line["section_id"];
  383. print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
  384. $lnum = 0;
  385. }
  386. print "<tr>";
  387. print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
  388. print "<label for='CB_$pref_name'>";
  389. print $short_desc;
  390. print "</label>";
  391. if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
  392. print "</td>";
  393. print "<td class=\"prefValue\">";
  394. if ($pref_name == "USER_LANGUAGE") {
  395. print_select_hash($pref_name, $value, get_translations(),
  396. "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
  397. } else if ($pref_name == "USER_TIMEZONE") {
  398. $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
  399. print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
  400. } else if ($pref_name == "USER_STYLESHEET") {
  401. print "<button dojoType=\"dijit.form.Button\"
  402. onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
  403. } else if ($pref_name == "USER_CSS_THEME") {
  404. $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css"));
  405. $themes = array_map("basename", $themes);
  406. $themes = array_filter($themes, "theme_valid");
  407. asort($themes);
  408. if (!theme_valid($value)) $value = "default.php";
  409. print_select($pref_name, $value, $themes,
  410. 'dojoType="dijit.form.Select"');
  411. } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
  412. global $update_intervals_nodefault;
  413. print_select_hash($pref_name, $value, $update_intervals_nodefault,
  414. 'dojoType="dijit.form.Select"');
  415. } else if ($type_name == "bool") {
  416. array_push($listed_boolean_prefs, $pref_name);
  417. $checked = ($value == "true") ? "checked=\"checked\"" : "";
  418. if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
  419. $disabled = "disabled=\"1\"";
  420. $checked = "checked=\"checked\"";
  421. } else {
  422. $disabled = "";
  423. }
  424. print "<input type='checkbox' name='$pref_name' $checked $disabled
  425. dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
  426. } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
  427. 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
  428. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  429. if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
  430. $disabled = "disabled=\"1\"";
  431. $value = FORCE_ARTICLE_PURGE;
  432. } else {
  433. $disabled = "";
  434. }
  435. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  436. required=\"1\" $regexp $disabled
  437. name=\"$pref_name\" value=\"$value\">";
  438. } else if ($pref_name == "SSL_CERT_SERIAL") {
  439. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  440. id=\"SSL_CERT_SERIAL\" readonly=\"1\"
  441. name=\"$pref_name\" value=\"$value\">";
  442. $cert_serial = htmlspecialchars(get_ssl_certificate_id());
  443. $has_serial = ($cert_serial) ? "false" : "true";
  444. print "<br/>";
  445. print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
  446. onclick=\"insertSSLserial('$cert_serial')\">" .
  447. __('Register') . "</button>";
  448. print " <button dojoType=\"dijit.form.Button\"
  449. onclick=\"insertSSLserial('')\">" .
  450. __('Clear') . "</button>";
  451. } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  452. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  453. id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
  454. name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
  455. T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
  456. } else {
  457. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  458. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  459. $regexp
  460. name=\"$pref_name\" value=\"$value\">";
  461. }
  462. print "</td>";
  463. print "</tr>";
  464. $lnum++;
  465. }
  466. print "</table>";
  467. $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
  468. print_hidden("boolean_prefs", "$listed_boolean_prefs");
  469. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  470. "hook_prefs_tab_section", "prefPrefsPrefsInside");
  471. print '</div>'; # inside pane
  472. print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
  473. print_hidden("op", "pref-prefs");
  474. print_hidden("method", "saveconfig");
  475. print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
  476. <span>".__('Save configuration')."</span>
  477. <div dojoType=\"dijit.DropDownMenu\">
  478. <div dojoType=\"dijit.MenuItem\"
  479. onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
  480. __("Save and exit preferences")."</div>
  481. </div>
  482. </div>";
  483. print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
  484. __('Manage profiles')."</button> ";
  485. print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
  486. __('Reset to defaults')."</button>";
  487. print "&nbsp;";
  488. /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
  489. print "<input onclick='toggleAdvancedPrefs()'
  490. id='prefs_show_advanced'
  491. dojoType=\"dijit.form.CheckBox\"
  492. $checked
  493. type=\"checkbox\"></input>
  494. <label for='prefs_show_advanced'>" .
  495. __("Show additional preferences") . "</label>"; */
  496. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  497. "hook_prefs_tab_section", "prefPrefsPrefsOutside");
  498. print "</form>";
  499. print '</div>'; # inner pane
  500. print '</div>'; # border container
  501. print "</div>"; #pane
  502. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
  503. print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
  504. 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>."));
  505. if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) {
  506. print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly.");
  507. }
  508. print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
  509. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  510. evt.preventDefault();
  511. if (this.validate()) {
  512. notify_progress('Saving data...', true);
  513. new Ajax.Request('backend.php', {
  514. parameters: dojo.objectToQuery(this.getValues()),
  515. onComplete: function(transport) {
  516. notify('');
  517. if (confirm(__('Selected plugins have been enabled. Reload?'))) {
  518. window.location.reload();
  519. }
  520. } });
  521. }
  522. </script>";
  523. print_hidden("op", "pref-prefs");
  524. print_hidden("method", "setplugins");
  525. print "<table width='100%' class='prefPluginsList'>";
  526. print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
  527. print "<tr class=\"title\">
  528. <td width=\"5%\">&nbsp;</td>
  529. <td width='10%'>".__('Plugin')."</td>
  530. <td width=''>".__('Description')."</td>
  531. <td width='5%'>".__('Version')."</td>
  532. <td width='10%'>".__('Author')."</td></tr>";
  533. $system_enabled = array_map("trim", explode(",", PLUGINS));
  534. $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
  535. $tmppluginhost = new PluginHost();
  536. $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
  537. $tmppluginhost->load_data(true);
  538. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  539. $about = $plugin->about();
  540. if ($about[3]) {
  541. if (in_array($name, $system_enabled)) {
  542. $checked = "checked='1'";
  543. } else {
  544. $checked = "";
  545. }
  546. print "<tr>";
  547. print "<td align='center'><input disabled='1'
  548. dojoType=\"dijit.form.CheckBox\" $checked
  549. type=\"checkbox\"></td>";
  550. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  551. print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
  552. print "<td>" . htmlspecialchars($about[1]);
  553. if (@$about[4]) {
  554. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  555. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  556. }
  557. print "</td>";
  558. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  559. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  560. if (count($tmppluginhost->get_all($plugin)) > 0) {
  561. if (in_array($name, $system_enabled)) {
  562. print "<td><a href='#' onclick=\"clearPluginData('$name')\"
  563. class='visibleLink'>".__("Clear data")."</a></td>";
  564. }
  565. }
  566. print "</tr>";
  567. }
  568. }
  569. print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
  570. print "<tr class=\"title\">
  571. <td width=\"5%\">&nbsp;</td>
  572. <td width='10%'>".__('Plugin')."</td>
  573. <td width=''>".__('Description')."</td>
  574. <td width='5%'>".__('Version')."</td>
  575. <td width='10%'>".__('Author')."</td></tr>";
  576. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  577. $about = $plugin->about();
  578. if (!$about[3]) {
  579. if (in_array($name, $system_enabled)) {
  580. $checked = "checked='1'";
  581. $disabled = "disabled='1'";
  582. $rowclass = '';
  583. } else if (in_array($name, $user_enabled)) {
  584. $checked = "checked='1'";
  585. $disabled = "";
  586. $rowclass = "Selected";
  587. } else {
  588. $checked = "";
  589. $disabled = "";
  590. $rowclass = '';
  591. }
  592. print "<tr class='$rowclass'>";
  593. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  594. print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
  595. dojoType=\"dijit.form.CheckBox\" $checked $disabled
  596. type=\"checkbox\"></td>";
  597. print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
  598. print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
  599. if (@$about[4]) {
  600. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  601. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  602. }
  603. print "</td>";
  604. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  605. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  606. if (count($tmppluginhost->get_all($plugin)) > 0) {
  607. if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
  608. print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
  609. }
  610. }
  611. print "</tr>";
  612. }
  613. }
  614. print "</table>";
  615. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  616. __("Enable selected plugins")."</button></p>";
  617. print "</form>";
  618. print "</div>"; #pane
  619. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  620. "hook_prefs_tab", "prefPrefs");
  621. print "</div>"; #container
  622. }
  623. function toggleAdvanced() {
  624. $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
  625. }
  626. function otpqrcode() {
  627. require_once "lib/otphp/vendor/base32.php";
  628. require_once "lib/otphp/lib/otp.php";
  629. require_once "lib/otphp/lib/totp.php";
  630. require_once "lib/phpqrcode/phpqrcode.php";
  631. $result = $this->dbh->query("SELECT login,salt,otp_enabled
  632. FROM ttrss_users
  633. WHERE id = ".$_SESSION["uid"]);
  634. $base32 = new Base32();
  635. $login = $this->dbh->fetch_result($result, 0, "login");
  636. $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
  637. if (!$otp_enabled) {
  638. $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
  639. print QRcode::png("otpauth://totp/".urlencode($login).
  640. "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS"));
  641. }
  642. }
  643. function otpenable() {
  644. require_once "lib/otphp/vendor/base32.php";
  645. require_once "lib/otphp/lib/otp.php";
  646. require_once "lib/otphp/lib/totp.php";
  647. $password = $_REQUEST["password"];
  648. $otp = $_REQUEST["otp"];
  649. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  650. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  651. $result = $this->dbh->query("SELECT salt
  652. FROM ttrss_users
  653. WHERE id = ".$_SESSION["uid"]);
  654. $base32 = new Base32();
  655. $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
  656. $topt = new \OTPHP\TOTP($secret);
  657. $otp_check = $topt->now();
  658. if ($otp == $otp_check) {
  659. $this->dbh->query("UPDATE ttrss_users SET otp_enabled = true WHERE
  660. id = " . $_SESSION["uid"]);
  661. print "OK";
  662. } else {
  663. print "ERROR:".__("Incorrect one time password");
  664. }
  665. } else {
  666. print "ERROR:".__("Incorrect password");
  667. }
  668. }
  669. function otpdisable() {
  670. $password = $this->dbh->escape_string($_REQUEST["password"]);
  671. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  672. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  673. $this->dbh->query("UPDATE ttrss_users SET otp_enabled = false WHERE
  674. id = " . $_SESSION["uid"]);
  675. print "OK";
  676. } else {
  677. print "ERROR: ".__("Incorrect password");
  678. }
  679. }
  680. function setplugins() {
  681. if (is_array($_REQUEST["plugins"]))
  682. $plugins = join(",", $_REQUEST["plugins"]);
  683. else
  684. $plugins = "";
  685. set_pref("_ENABLED_PLUGINS", $plugins);
  686. }
  687. function clearplugindata() {
  688. $name = $this->dbh->escape_string($_REQUEST["name"]);
  689. PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
  690. }
  691. function customizeCSS() {
  692. $value = get_pref("USER_STYLESHEET");
  693. $value = str_replace("<br/>", "\n", $value);
  694. 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"));
  695. print_hidden("op", "rpc");
  696. print_hidden("method", "setpref");
  697. print_hidden("key", "USER_STYLESHEET");
  698. print "<table width='100%'><tr><td>";
  699. print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
  700. style='font-size : 12px; width : 98%; height: 200px;'
  701. placeHolder='body#ttrssMain { font-size : 14px; };'
  702. name='value'>$value</textarea>";
  703. print "</td></tr></table>";
  704. print "<div class='dlgButtons'>";
  705. print "<button dojoType=\"dijit.form.Button\"
  706. onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
  707. print "<button dojoType=\"dijit.form.Button\"
  708. onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
  709. print "</div>";
  710. }
  711. function editPrefProfiles() {
  712. print "<div dojoType=\"dijit.Toolbar\">";
  713. print "<div dojoType=\"dijit.form.DropDownButton\">".
  714. "<span>" . __('Select')."</span>";
  715. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  716. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
  717. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  718. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
  719. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  720. print "</div></div>";
  721. print "<div style=\"float : right\">";
  722. print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
  723. required=\"1\">
  724. <button dojoType=\"dijit.form.Button\"
  725. onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
  726. __('Create profile')."</button></div>";
  727. print "</div>";
  728. $result = $this->dbh->query("SELECT title,id FROM ttrss_settings_profiles
  729. WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
  730. print "<div class=\"prefProfileHolder\">";
  731. print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
  732. print "<table width=\"100%\" class=\"prefFeedProfileList\"
  733. cellspacing=\"0\" id=\"prefFeedProfileList\">";
  734. print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
  735. print "<td width='5%' align='center'><input
  736. id='FCATC-0'
  737. onclick='toggleSelectRow2(this);'
  738. dojoType=\"dijit.form.CheckBox\"
  739. type=\"checkbox\"></td>";
  740. if (!$_SESSION["profile"]) {
  741. $is_active = __("(active)");
  742. } else {
  743. $is_active = "";
  744. }
  745. print "<td><span>" .
  746. __("Default profile") . " $is_active</span></td>";
  747. print "</tr>";
  748. $lnum = 1;
  749. while ($line = $this->dbh->fetch_assoc($result)) {
  750. $profile_id = $line["id"];
  751. $this_row_id = "id=\"FCATR-$profile_id\"";
  752. print "<tr class=\"placeholder\" $this_row_id>";
  753. $edit_title = htmlspecialchars($line["title"]);
  754. print "<td width='5%' align='center'><input
  755. onclick='toggleSelectRow2(this);'
  756. id='FCATC-$profile_id'
  757. dojoType=\"dijit.form.CheckBox\"
  758. type=\"checkbox\"></td>";
  759. if ($_SESSION["profile"] == $line["id"]) {
  760. $is_active = __("(active)");
  761. } else {
  762. $is_active = "";
  763. }
  764. print "<td><span dojoType=\"dijit.InlineEditBox\"
  765. width=\"300px\" autoSave=\"false\"
  766. profile-id=\"$profile_id\">" . $edit_title .
  767. "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
  768. var elem = this;
  769. dojo.xhrPost({
  770. url: 'backend.php',
  771. content: {op: 'rpc', method: 'saveprofile',
  772. value: this.value,
  773. id: this.srcNodeRef.getAttribute('profile-id')},
  774. load: function(response) {
  775. elem.attr('value', response);
  776. }
  777. });
  778. </script>
  779. </span> $is_active</td>";
  780. print "</tr>";
  781. ++$lnum;
  782. }
  783. print "</table>";
  784. print "</form>";
  785. print "</div>";
  786. print "<div class='dlgButtons'>
  787. <div style='float : left'>
  788. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
  789. __('Remove selected profiles')."</button>
  790. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
  791. __('Activate profile')."</button>
  792. </div>";
  793. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
  794. __('Close this window')."</button>";
  795. print "</div>";
  796. }
  797. private function getShortDesc($pref_name) {
  798. if (isset($this->pref_help[$pref_name])) {
  799. return $this->pref_help[$pref_name][0];
  800. }
  801. return "";
  802. }
  803. private function getHelpText($pref_name) {
  804. if (isset($this->pref_help[$pref_name])) {
  805. return $this->pref_help[$pref_name][1];
  806. }
  807. return "";
  808. }
  809. private function getSectionName($id) {
  810. if (isset($this->pref_sections[$id])) {
  811. return $this->pref_sections[$id];
  812. }
  813. return "";
  814. }
  815. }
  816. ?>