prefs.php 37 KB

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