prefs.php 36 KB

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