prefs.php 35 KB

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