prefs.php 36 KB

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