prefs.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  489. "hook_prefs_tab_section", "prefPrefsPrefsOutside");
  490. print "</form>";
  491. print '</div>'; # inner pane
  492. print '</div>'; # border container
  493. print "</div>"; #pane
  494. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
  495. print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
  496. 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>."));
  497. if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) {
  498. print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly.");
  499. }
  500. print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
  501. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  502. evt.preventDefault();
  503. if (this.validate()) {
  504. notify_progress('Saving data...', true);
  505. new Ajax.Request('backend.php', {
  506. parameters: dojo.objectToQuery(this.getValues()),
  507. onComplete: function(transport) {
  508. notify('');
  509. if (confirm(__('Selected plugins have been enabled. Reload?'))) {
  510. window.location.reload();
  511. }
  512. } });
  513. }
  514. </script>";
  515. print_hidden("op", "pref-prefs");
  516. print_hidden("method", "setplugins");
  517. print "<table width='100%' class='prefPluginsList'>";
  518. print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
  519. print "<tr class=\"title\">
  520. <td width=\"5%\">&nbsp;</td>
  521. <td width='10%'>".__('Plugin')."</td>
  522. <td width=''>".__('Description')."</td>
  523. <td width='5%'>".__('Version')."</td>
  524. <td width='10%'>".__('Author')."</td></tr>";
  525. $system_enabled = array_map("trim", explode(",", PLUGINS));
  526. $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
  527. $tmppluginhost = new PluginHost();
  528. $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
  529. $tmppluginhost->load_data(true);
  530. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  531. $about = $plugin->about();
  532. if ($about[3]) {
  533. if (in_array($name, $system_enabled)) {
  534. $checked = "checked='1'";
  535. } else {
  536. $checked = "";
  537. }
  538. print "<tr>";
  539. print "<td align='center'><input disabled='1'
  540. dojoType=\"dijit.form.CheckBox\" $checked
  541. type=\"checkbox\"></td>";
  542. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  543. print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
  544. print "<td>" . htmlspecialchars($about[1]);
  545. if (@$about[4]) {
  546. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  547. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  548. }
  549. print "</td>";
  550. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  551. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  552. if (count($tmppluginhost->get_all($plugin)) > 0) {
  553. if (in_array($name, $system_enabled)) {
  554. print "<td><a href='#' onclick=\"clearPluginData('$name')\"
  555. class='visibleLink'>".__("Clear data")."</a></td>";
  556. }
  557. }
  558. print "</tr>";
  559. }
  560. }
  561. print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
  562. print "<tr class=\"title\">
  563. <td width=\"5%\">&nbsp;</td>
  564. <td width='10%'>".__('Plugin')."</td>
  565. <td width=''>".__('Description')."</td>
  566. <td width='5%'>".__('Version')."</td>
  567. <td width='10%'>".__('Author')."</td></tr>";
  568. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  569. $about = $plugin->about();
  570. if (!$about[3]) {
  571. if (in_array($name, $system_enabled)) {
  572. $checked = "checked='1'";
  573. $disabled = "disabled='1'";
  574. $rowclass = '';
  575. } else if (in_array($name, $user_enabled)) {
  576. $checked = "checked='1'";
  577. $disabled = "";
  578. $rowclass = "Selected";
  579. } else {
  580. $checked = "";
  581. $disabled = "";
  582. $rowclass = '';
  583. }
  584. print "<tr class='$rowclass'>";
  585. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  586. print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
  587. dojoType=\"dijit.form.CheckBox\" $checked $disabled
  588. type=\"checkbox\"></td>";
  589. print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
  590. print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
  591. if (@$about[4]) {
  592. print " &mdash; <a target=\"_blank\" rel=\"noopener noreferrer\" class=\"visibleLink\"
  593. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  594. }
  595. print "</td>";
  596. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  597. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  598. if (count($tmppluginhost->get_all($plugin)) > 0) {
  599. if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
  600. print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
  601. }
  602. }
  603. print "</tr>";
  604. }
  605. }
  606. print "</table>";
  607. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  608. __("Enable selected plugins")."</button></p>";
  609. print "</form>";
  610. print "</div>"; #pane
  611. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  612. "hook_prefs_tab", "prefPrefs");
  613. print "</div>"; #container
  614. }
  615. function toggleAdvanced() {
  616. $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
  617. }
  618. function otpqrcode() {
  619. require_once "lib/otphp/vendor/base32.php";
  620. require_once "lib/otphp/lib/otp.php";
  621. require_once "lib/otphp/lib/totp.php";
  622. require_once "lib/phpqrcode/phpqrcode.php";
  623. $result = $this->dbh->query("SELECT login,salt,otp_enabled
  624. FROM ttrss_users
  625. WHERE id = ".$_SESSION["uid"]);
  626. $base32 = new Base32();
  627. $login = $this->dbh->fetch_result($result, 0, "login");
  628. $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
  629. if (!$otp_enabled) {
  630. $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
  631. print QRcode::png("otpauth://totp/".urlencode($login).
  632. "?secret=$secret&issuer=".urlencode("Tiny Tiny RSS"));
  633. }
  634. }
  635. function otpenable() {
  636. require_once "lib/otphp/vendor/base32.php";
  637. require_once "lib/otphp/lib/otp.php";
  638. require_once "lib/otphp/lib/totp.php";
  639. $password = $_REQUEST["password"];
  640. $otp = $_REQUEST["otp"];
  641. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  642. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  643. $result = $this->dbh->query("SELECT salt
  644. FROM ttrss_users
  645. WHERE id = ".$_SESSION["uid"]);
  646. $base32 = new Base32();
  647. $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
  648. $topt = new \OTPHP\TOTP($secret);
  649. $otp_check = $topt->now();
  650. if ($otp == $otp_check) {
  651. $this->dbh->query("UPDATE ttrss_users SET otp_enabled = true WHERE
  652. id = " . $_SESSION["uid"]);
  653. print "OK";
  654. } else {
  655. print "ERROR:".__("Incorrect one time password");
  656. }
  657. } else {
  658. print "ERROR:".__("Incorrect password");
  659. }
  660. }
  661. function otpdisable() {
  662. $password = $this->dbh->escape_string($_REQUEST["password"]);
  663. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  664. if ($authenticator->check_password($_SESSION["uid"], $password)) {
  665. $this->dbh->query("UPDATE ttrss_users SET otp_enabled = false WHERE
  666. id = " . $_SESSION["uid"]);
  667. print "OK";
  668. } else {
  669. print "ERROR: ".__("Incorrect password");
  670. }
  671. }
  672. function setplugins() {
  673. if (is_array($_REQUEST["plugins"]))
  674. $plugins = join(",", $_REQUEST["plugins"]);
  675. else
  676. $plugins = "";
  677. set_pref("_ENABLED_PLUGINS", $plugins);
  678. }
  679. function clearplugindata() {
  680. $name = $this->dbh->escape_string($_REQUEST["name"]);
  681. PluginHost::getInstance()->clear_data(PluginHost::getInstance()->get_plugin($name));
  682. }
  683. function customizeCSS() {
  684. $value = get_pref("USER_STYLESHEET");
  685. $value = str_replace("<br/>", "\n", $value);
  686. 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"));
  687. print_hidden("op", "rpc");
  688. print_hidden("method", "setpref");
  689. print_hidden("key", "USER_STYLESHEET");
  690. print "<table width='100%'><tr><td>";
  691. print "<textarea dojoType=\"dijit.form.SimpleTextarea\"
  692. style='font-size : 12px; width : 98%; height: 200px;'
  693. placeHolder='body#ttrssMain { font-size : 14px; };'
  694. name='value'>$value</textarea>";
  695. print "</td></tr></table>";
  696. print "<div class='dlgButtons'>";
  697. print "<button dojoType=\"dijit.form.Button\"
  698. onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> ";
  699. print "<button dojoType=\"dijit.form.Button\"
  700. onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>";
  701. print "</div>";
  702. }
  703. function editPrefProfiles() {
  704. print "<div dojoType=\"dijit.Toolbar\">";
  705. print "<div dojoType=\"dijit.form.DropDownButton\">".
  706. "<span>" . __('Select')."</span>";
  707. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  708. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\"
  709. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  710. print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\"
  711. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  712. print "</div></div>";
  713. print "<div style=\"float : right\">";
  714. print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\"
  715. required=\"1\">
  716. <button dojoType=\"dijit.form.Button\"
  717. onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
  718. __('Create profile')."</button></div>";
  719. print "</div>";
  720. $result = $this->dbh->query("SELECT title,id FROM ttrss_settings_profiles
  721. WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
  722. print "<div class=\"prefProfileHolder\">";
  723. print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
  724. print "<table width=\"100%\" class=\"prefFeedProfileList\"
  725. cellspacing=\"0\" id=\"prefFeedProfileList\">";
  726. print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd
  727. print "<td width='5%' align='center'><input
  728. id='FCATC-0'
  729. onclick='toggleSelectRow2(this);'
  730. dojoType=\"dijit.form.CheckBox\"
  731. type=\"checkbox\"></td>";
  732. if (!$_SESSION["profile"]) {
  733. $is_active = __("(active)");
  734. } else {
  735. $is_active = "";
  736. }
  737. print "<td><span>" .
  738. __("Default profile") . " $is_active</span></td>";
  739. print "</tr>";
  740. $lnum = 1;
  741. while ($line = $this->dbh->fetch_assoc($result)) {
  742. $profile_id = $line["id"];
  743. $this_row_id = "id=\"FCATR-$profile_id\"";
  744. print "<tr class=\"placeholder\" $this_row_id>";
  745. $edit_title = htmlspecialchars($line["title"]);
  746. print "<td width='5%' align='center'><input
  747. onclick='toggleSelectRow2(this);'
  748. id='FCATC-$profile_id'
  749. dojoType=\"dijit.form.CheckBox\"
  750. type=\"checkbox\"></td>";
  751. if ($_SESSION["profile"] == $line["id"]) {
  752. $is_active = __("(active)");
  753. } else {
  754. $is_active = "";
  755. }
  756. print "<td><span dojoType=\"dijit.InlineEditBox\"
  757. width=\"300px\" autoSave=\"false\"
  758. profile-id=\"$profile_id\">" . $edit_title .
  759. "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
  760. var elem = this;
  761. dojo.xhrPost({
  762. url: 'backend.php',
  763. content: {op: 'rpc', method: 'saveprofile',
  764. value: this.value,
  765. id: this.srcNodeRef.getAttribute('profile-id')},
  766. load: function(response) {
  767. elem.attr('value', response);
  768. }
  769. });
  770. </script>
  771. </span> $is_active</td>";
  772. print "</tr>";
  773. ++$lnum;
  774. }
  775. print "</table>";
  776. print "</form>";
  777. print "</div>";
  778. print "<div class='dlgButtons'>
  779. <div style='float : left'>
  780. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">".
  781. __('Remove selected profiles')."</button>
  782. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">".
  783. __('Activate profile')."</button>
  784. </div>";
  785. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">".
  786. __('Close this window')."</button>";
  787. print "</div>";
  788. }
  789. private function getShortDesc($pref_name) {
  790. if (isset($this->pref_help[$pref_name])) {
  791. return $this->pref_help[$pref_name][0];
  792. }
  793. return "";
  794. }
  795. private function getHelpText($pref_name) {
  796. if (isset($this->pref_help[$pref_name])) {
  797. return $this->pref_help[$pref_name][1];
  798. }
  799. return "";
  800. }
  801. private function getSectionName($id) {
  802. if (isset($this->pref_sections[$id])) {
  803. return $this->pref_sections[$id];
  804. }
  805. return "";
  806. }
  807. }