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");
  142. /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */
  143. $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS",
  144. "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP",
  145. "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE",
  146. "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE",
  147. "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME");
  148. $_SESSION["prefs_op_result"] = "";
  149. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  150. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data / Authentication')."\">";
  151. print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">";
  152. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  153. evt.preventDefault();
  154. if (this.validate()) {
  155. notify_progress('Saving data...', true);
  156. new Ajax.Request('backend.php', {
  157. parameters: dojo.objectToQuery(this.getValues()),
  158. onComplete: function(transport) {
  159. notify_callback2(transport);
  160. } });
  161. }
  162. </script>";
  163. print "<table width=\"100%\" class=\"prefPrefsList\">";
  164. print "<h2>" . __("Personal data") . "</h2>";
  165. $result = $this->dbh->query("SELECT email,full_name,otp_enabled,
  166. access_level FROM ttrss_users
  167. WHERE id = ".$_SESSION["uid"]);
  168. $email = htmlspecialchars($this->dbh->fetch_result($result, 0, "email"));
  169. $full_name = htmlspecialchars($this->dbh->fetch_result($result, 0, "full_name"));
  170. $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
  171. print "<tr><td width=\"40%\">".__('Full name')."</td>";
  172. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\"
  173. value=\"$full_name\"></td></tr>";
  174. print "<tr><td width=\"40%\">".__('E-mail')."</td>";
  175. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>";
  176. if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) {
  177. $access_level = $this->dbh->fetch_result($result, 0, "access_level");
  178. print "<tr><td width=\"40%\">".__('Access level')."</td>";
  179. print "<td>" . $access_level_names[$access_level] . "</td></tr>";
  180. }
  181. print "</table>";
  182. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  183. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">";
  184. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  185. __("Save data")."</button>";
  186. print "</form>";
  187. if ($_SESSION["auth_module"]) {
  188. $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
  189. } else {
  190. $authenticator = false;
  191. }
  192. if ($authenticator && method_exists($authenticator, "change_password")) {
  193. print "<h2>" . __("Password") . "</h2>";
  194. $result = $this->dbh->query("SELECT id FROM ttrss_users
  195. WHERE id = ".$_SESSION["uid"]." AND pwd_hash
  196. = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
  197. if ($this->dbh->num_rows($result) != 0) {
  198. print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
  199. }
  200. print "<form dojoType=\"dijit.form.Form\">";
  201. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  202. evt.preventDefault();
  203. if (this.validate()) {
  204. notify_progress('Changing password...', true);
  205. new Ajax.Request('backend.php', {
  206. parameters: dojo.objectToQuery(this.getValues()),
  207. onComplete: function(transport) {
  208. notify('');
  209. if (transport.responseText.indexOf('ERROR: ') == 0) {
  210. notify_error(transport.responseText.replace('ERROR: ', ''));
  211. } else {
  212. notify_info(transport.responseText);
  213. var warn = $('default_pass_warning');
  214. if (warn) Element.hide(warn);
  215. }
  216. }});
  217. this.reset();
  218. }
  219. </script>";
  220. if ($otp_enabled) {
  221. print_notice(__("Changing your current password will disable OTP."));
  222. }
  223. print "<table width=\"100%\" class=\"prefPrefsList\">";
  224. print "<tr><td width=\"40%\">".__("Old password")."</td>";
  225. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>";
  226. print "<tr><td width=\"40%\">".__("New password")."</td>";
  227. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  228. name=\"new_password\"></td></tr>";
  229. print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
  230. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>";
  231. print "</table>";
  232. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  233. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">";
  234. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  235. __("Change password")."</button>";
  236. print "</form>";
  237. if ($_SESSION["auth_module"] == "auth_internal") {
  238. print "<h2>" . __("One time passwords / Authenticator") . "</h2>";
  239. if ($otp_enabled) {
  240. print_notice(__("One time passwords are currently enabled. Enter your current password below to disable."));
  241. print "<form dojoType=\"dijit.form.Form\">";
  242. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  243. evt.preventDefault();
  244. if (this.validate()) {
  245. notify_progress('Disabling OTP', true);
  246. new Ajax.Request('backend.php', {
  247. parameters: dojo.objectToQuery(this.getValues()),
  248. onComplete: function(transport) {
  249. notify('');
  250. if (transport.responseText.indexOf('ERROR: ') == 0) {
  251. notify_error(transport.responseText.replace('ERROR: ', ''));
  252. } else {
  253. window.location.reload();
  254. }
  255. }});
  256. this.reset();
  257. }
  258. </script>";
  259. print "<table width=\"100%\" class=\"prefPrefsList\">";
  260. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  261. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  262. name=\"password\"></td></tr>";
  263. print "</table>";
  264. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  265. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
  266. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  267. __("Disable OTP")."</button>";
  268. print "</form>";
  269. } else if (function_exists("imagecreatefromstring")) {
  270. print_warning(__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."));
  271. print "<p>".__("Scan the following code by the Authenticator application:")."</p>";
  272. $csrf_token = $_SESSION["csrf_token"];
  273. print "<img src=\"backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token\">";
  274. print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
  275. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  276. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
  277. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  278. evt.preventDefault();
  279. if (this.validate()) {
  280. notify_progress('Saving data...', true);
  281. new Ajax.Request('backend.php', {
  282. parameters: dojo.objectToQuery(this.getValues()),
  283. onComplete: function(transport) {
  284. notify('');
  285. if (transport.responseText.indexOf('ERROR:') == 0) {
  286. notify_error(transport.responseText.replace('ERROR:', ''));
  287. } else {
  288. window.location.reload();
  289. }
  290. } });
  291. }
  292. </script>";
  293. print "<table width=\"100%\" class=\"prefPrefsList\">";
  294. print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
  295. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
  296. name=\"password\"></td></tr>";
  297. print "<tr><td width=\"40%\">".__("Enter the generated one time password")."</td>";
  298. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" autocomplete=\"off\"
  299. required=\"1\"
  300. name=\"otp\"></td></tr>";
  301. print "<tr><td colspan=\"2\">";
  302. print "</td></tr><tr><td colspan=\"2\">";
  303. print "</td></tr>";
  304. print "</table>";
  305. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  306. __("Enable OTP")."</button>";
  307. print "</form>";
  308. } else {
  309. print_notice(__("PHP GD functions are required for OTP support."));
  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. }
  394. print "<tr>";
  395. print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">";
  396. print "<label for='CB_$pref_name'>";
  397. print $short_desc;
  398. print "</label>";
  399. if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
  400. print "</td>";
  401. print "<td class=\"prefValue\">";
  402. if ($pref_name == "USER_LANGUAGE") {
  403. print_select_hash($pref_name, $value, get_translations(),
  404. "style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
  405. } else if ($pref_name == "USER_TIMEZONE") {
  406. $timezones = explode("\n", file_get_contents("lib/timezones.txt"));
  407. print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
  408. } else if ($pref_name == "USER_STYLESHEET") {
  409. print "<button dojoType=\"dijit.form.Button\"
  410. onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
  411. } else if ($pref_name == "USER_CSS_THEME") {
  412. $themes = array_map("basename", glob("themes/*.css"));
  413. print_select($pref_name, $value, $themes,
  414. 'dojoType="dijit.form.Select"');
  415. } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
  416. global $update_intervals_nodefault;
  417. print_select_hash($pref_name, $value, $update_intervals_nodefault,
  418. 'dojoType="dijit.form.Select"');
  419. } else if ($type_name == "bool") {
  420. array_push($listed_boolean_prefs, $pref_name);
  421. $checked = ($value == "true") ? "checked=\"checked\"" : "";
  422. if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
  423. $disabled = "disabled=\"1\"";
  424. $checked = "checked=\"checked\"";
  425. } else {
  426. $disabled = "";
  427. }
  428. print "<input type='checkbox' name='$pref_name' $checked $disabled
  429. dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
  430. } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE',
  431. 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) {
  432. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  433. if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
  434. $disabled = "disabled=\"1\"";
  435. $value = FORCE_ARTICLE_PURGE;
  436. } else {
  437. $disabled = "";
  438. }
  439. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  440. required=\"1\" $regexp $disabled
  441. name=\"$pref_name\" value=\"$value\">";
  442. } else if ($pref_name == "SSL_CERT_SERIAL") {
  443. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  444. id=\"SSL_CERT_SERIAL\" readonly=\"1\"
  445. name=\"$pref_name\" value=\"$value\">";
  446. $cert_serial = htmlspecialchars(get_ssl_certificate_id());
  447. $has_serial = ($cert_serial) ? "false" : "true";
  448. print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
  449. onclick=\"insertSSLserial('$cert_serial')\">" .
  450. __('Register') . "</button>";
  451. print " <button dojoType=\"dijit.form.Button\"
  452. onclick=\"insertSSLserial('')\">" .
  453. __('Clear') . "</button>";
  454. } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
  455. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  456. id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
  457. name=\"$pref_name\" value=\"$value\"><div class=\"insensitive\">".
  458. T_sprintf("Current server time: %s (UTC)", date("H:i")) . "</div>";
  459. } else {
  460. $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
  461. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  462. $regexp
  463. name=\"$pref_name\" value=\"$value\">";
  464. }
  465. print "</td>";
  466. print "</tr>";
  467. $lnum++;
  468. }
  469. print "</table>";
  470. $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
  471. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"boolean_prefs\" value=\"$listed_boolean_prefs\">";
  472. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  473. "hook_prefs_tab_section", "prefPrefsPrefsInside");
  474. print '</div>'; # inside pane
  475. print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
  476. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  477. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">";
  478. print "<div dojoType=\"dijit.form.ComboButton\" type=\"submit\">
  479. <span>".__('Save configuration')."</span>
  480. <div dojoType=\"dijit.DropDownMenu\">
  481. <div dojoType=\"dijit.MenuItem\"
  482. onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
  483. __("Save and exit preferences")."</div>
  484. </div>
  485. </div>";
  486. print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
  487. __('Manage profiles')."</button> ";
  488. print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">".
  489. __('Reset to defaults')."</button>";
  490. print "&nbsp;";
  491. /* $checked = $_SESSION["prefs_show_advanced"] ? "checked='1'" : "";
  492. print "<input onclick='toggleAdvancedPrefs()'
  493. id='prefs_show_advanced'
  494. dojoType=\"dijit.form.CheckBox\"
  495. $checked
  496. type=\"checkbox\"></input>
  497. <label for='prefs_show_advanced'>" .
  498. __("Show additional preferences") . "</label>"; */
  499. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  500. "hook_prefs_tab_section", "prefPrefsPrefsOutside");
  501. print "</form>";
  502. print '</div>'; # inner pane
  503. print '</div>'; # border container
  504. print "</div>"; #pane
  505. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
  506. print "<p>" . __("You will need to reload Tiny Tiny RSS for plugin changes to take effect.") . "</p>";
  507. 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>."));
  508. print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
  509. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  510. evt.preventDefault();
  511. if (this.validate()) {
  512. notify_progress('Saving data...', true);
  513. new Ajax.Request('backend.php', {
  514. parameters: dojo.objectToQuery(this.getValues()),
  515. onComplete: function(transport) {
  516. notify('');
  517. if (confirm(__('Selected plugins have been enabled. Reload?'))) {
  518. window.location.reload();
  519. }
  520. } });
  521. }
  522. </script>";
  523. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
  524. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
  525. print "<table width='100%' class='prefPluginsList'>";
  526. print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
  527. print "<tr class=\"title\">
  528. <td width=\"5%\">&nbsp;</td>
  529. <td width='10%'>".__('Plugin')."</td>
  530. <td width=''>".__('Description')."</td>
  531. <td width='5%'>".__('Version')."</td>
  532. <td width='10%'>".__('Author')."</td></tr>";
  533. $system_enabled = array_map("trim", explode(",", PLUGINS));
  534. $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
  535. $tmppluginhost = new PluginHost();
  536. $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]);
  537. $tmppluginhost->load_data(true);
  538. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  539. $about = $plugin->about();
  540. if ($about[3] && strpos($name, "example") === FALSE) {
  541. if (in_array($name, $system_enabled)) {
  542. $checked = "checked='1'";
  543. } else {
  544. $checked = "";
  545. }
  546. print "<tr>";
  547. print "<td align='center'><input disabled='1'
  548. dojoType=\"dijit.form.CheckBox\" $checked
  549. type=\"checkbox\"></td>";
  550. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  551. print "<td><label><img src='images/$plugin_icon' alt=''> $name</label></td>";
  552. print "<td>" . htmlspecialchars($about[1]);
  553. if (@$about[4]) {
  554. print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
  555. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  556. }
  557. print "</td>";
  558. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  559. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  560. if (count($tmppluginhost->get_all($plugin)) > 0) {
  561. if (in_array($name, $system_enabled)) {
  562. print "<td><a href='#' onclick=\"clearPluginData('$name')\"
  563. class='visibleLink'>".__("Clear data")."</a></td>";
  564. }
  565. }
  566. print "</tr>";
  567. }
  568. }
  569. print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
  570. print "<tr class=\"title\">
  571. <td width=\"5%\">&nbsp;</td>
  572. <td width='10%'>".__('Plugin')."</td>
  573. <td width=''>".__('Description')."</td>
  574. <td width='5%'>".__('Version')."</td>
  575. <td width='10%'>".__('Author')."</td></tr>";
  576. foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
  577. $about = $plugin->about();
  578. if (!$about[3] && strpos($name, "example") === FALSE) {
  579. if (in_array($name, $system_enabled)) {
  580. $checked = "checked='1'";
  581. $disabled = "disabled='1'";
  582. $rowclass = '';
  583. } else if (in_array($name, $user_enabled)) {
  584. $checked = "checked='1'";
  585. $disabled = "";
  586. $rowclass = "Selected";
  587. } else {
  588. $checked = "";
  589. $disabled = "";
  590. $rowclass = '';
  591. }
  592. print "<tr class='$rowclass'>";
  593. $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png";
  594. print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
  595. dojoType=\"dijit.form.CheckBox\" $checked $disabled
  596. type=\"checkbox\"></td>";
  597. print "<td><label for='FPCHK-$name'><img src='images/$plugin_icon' alt=''> $name</label></td>";
  598. print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label>";
  599. if (@$about[4]) {
  600. print " &mdash; <a target=\"_blank\" class=\"visibleLink\"
  601. href=\"".htmlspecialchars($about[4])."\">".__("more info")."</a>";
  602. }
  603. print "</td>";
  604. print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
  605. print "<td>" . htmlspecialchars($about[2]) . "</td>";
  606. if (count($tmppluginhost->get_all($plugin)) > 0) {
  607. if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
  608. print "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
  609. }
  610. }
  611. print "</tr>";
  612. }
  613. }
  614. print "</table>";
  615. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  616. __("Enable selected plugins")."</button></p>";
  617. print "</form>";
  618. print "</div>"; #pane
  619. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  620. "hook_prefs_tab", "prefPrefs");
  621. print "</div>"; #container
  622. }
  623. function toggleAdvanced() {
  624. $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"];
  625. }
  626. function otpqrcode() {
  627. require_once "lib/otphp/vendor/base32.php";
  628. require_once "lib/otphp/lib/otp.php";
  629. require_once "lib/otphp/lib/totp.php";
  630. require_once "lib/phpqrcode/phpqrcode.php";
  631. $result = $this->dbh->query("SELECT login,salt,otp_enabled
  632. FROM ttrss_users
  633. WHERE id = ".$_SESSION["uid"]);
  634. $base32 = new Base32();
  635. $login = $this->dbh->fetch_result($result, 0, "login");
  636. $otp_enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "otp_enabled"));
  637. if (!$otp_enabled) {
  638. $secret = $base32->encode(sha1($this->dbh->fetch_result($result, 0, "salt")));
  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. ?>