prefs.php 37 KB

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