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