feeds.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. <?php
  2. class Pref_Feeds extends Handler_Protected {
  3. function csrf_ignore($method) {
  4. $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
  5. "savefeedorder", "uploadicon");
  6. return array_search($method, $csrf_ignored) !== false;
  7. }
  8. function batch_edit_cbox($elem, $label = false) {
  9. print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
  10. onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">";
  11. }
  12. function renamecat() {
  13. $title = db_escape_string($_REQUEST['title']);
  14. $id = db_escape_string($_REQUEST['id']);
  15. if ($title) {
  16. db_query($this->link, "UPDATE ttrss_feed_categories SET
  17. title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
  18. }
  19. return;
  20. }
  21. function remtwitterinfo() {
  22. db_query($this->link, "UPDATE ttrss_users SET twitter_oauth = NULL
  23. WHERE id = " . $_SESSION['uid']);
  24. return;
  25. }
  26. private function get_category_items($cat_id) {
  27. $show_empty_cats = $_REQUEST['mode'] != 2 &&
  28. get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
  29. $items = array();
  30. $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
  31. WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title");
  32. while ($line = db_fetch_assoc($result)) {
  33. $cat = array();
  34. $cat['id'] = 'CAT:' . $line['id'];
  35. $cat['bare_id'] = (int)$line['id'];
  36. $cat['name'] = $line['title'];
  37. $cat['items'] = array();
  38. $cat['checkbox'] = false;
  39. $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
  40. $cat['type'] = 'category';
  41. $cat['unread'] = 0;
  42. $cat['child_unread'] = 0;
  43. $cat['items'] = $this->get_category_items($line['id']);
  44. $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
  45. if (count($cat['items']) > 0 || $show_empty_cats)
  46. array_push($items, $cat);
  47. }
  48. $feed_result = db_query($this->link, "SELECT id, title, last_error,
  49. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  50. FROM ttrss_feeds
  51. WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"].
  52. "$search_qpart ORDER BY order_id, title");
  53. while ($feed_line = db_fetch_assoc($feed_result)) {
  54. $feed = array();
  55. $feed['id'] = 'FEED:' . $feed_line['id'];
  56. $feed['bare_id'] = (int)$feed_line['id'];
  57. $feed['name'] = $feed_line['title'];
  58. $feed['checkbox'] = false;
  59. $feed['unread'] = 0;
  60. $feed['error'] = $feed_line['last_error'];
  61. $feed['icon'] = getFeedIcon($feed_line['id']);
  62. $feed['param'] = make_local_datetime($this->link,
  63. $feed_line['last_updated'], true);
  64. array_push($items, $feed);
  65. }
  66. return $items;
  67. }
  68. function getfeedtree() {
  69. $search = $_SESSION["prefs_feed_search"];
  70. if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
  71. $root = array();
  72. $root['id'] = 'root';
  73. $root['name'] = __('Feeds');
  74. $root['items'] = array();
  75. $root['type'] = 'category';
  76. $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
  77. if ($_REQUEST['mode'] == 2) {
  78. if ($enable_cats) {
  79. $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
  80. $cat = $this->feedlist_init_cat(-1, $cat_hidden);
  81. } else {
  82. $cat['items'] = array();
  83. }
  84. foreach (array(-4, -3, -1, -2, 0) as $i) {
  85. array_push($cat['items'], $this->feedlist_init_feed($i));
  86. }
  87. if ($enable_cats) {
  88. array_push($root['items'], $cat);
  89. } else {
  90. $root['items'] = array_merge($root['items'], $cat['items']);
  91. }
  92. $result = db_query($this->link, "SELECT * FROM
  93. ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
  94. if (db_num_rows($result) > 0) {
  95. if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
  96. $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
  97. $cat = $this->feedlist_init_cat(-2, $cat_hidden);
  98. } else {
  99. $cat['items'] = array();
  100. }
  101. while ($line = db_fetch_assoc($result)) {
  102. $label_id = -$line['id'] - 11;
  103. $count = getFeedUnread($this->link, $label_id);
  104. $feed = $this->feedlist_init_feed($label_id, false, $count);
  105. $feed['fg_color'] = $line['fg_color'];
  106. $feed['bg_color'] = $line['bg_color'];
  107. array_push($cat['items'], $feed);
  108. }
  109. if ($enable_cats) {
  110. array_push($root['items'], $cat);
  111. } else {
  112. $root['items'] = array_merge($root['items'], $cat['items']);
  113. }
  114. }
  115. }
  116. if ($enable_cats) {
  117. $show_empty_cats = $_REQUEST['mode'] != 2 &&
  118. get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
  119. $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
  120. WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
  121. while ($line = db_fetch_assoc($result)) {
  122. $cat = array();
  123. $cat['id'] = 'CAT:' . $line['id'];
  124. $cat['bare_id'] = (int)$line['id'];
  125. $cat['name'] = $line['title'];
  126. $cat['items'] = array();
  127. $cat['checkbox'] = false;
  128. $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
  129. $cat['type'] = 'category';
  130. $cat['unread'] = 0;
  131. $cat['child_unread'] = 0;
  132. $cat['items'] = $this->get_category_items($line['id']);
  133. $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
  134. if (count($cat['items']) > 0 || $show_empty_cats)
  135. array_push($root['items'], $cat);
  136. $root['param'] += count($cat['items']);
  137. }
  138. /* Uncategorized is a special case */
  139. $cat = array();
  140. $cat['id'] = 'CAT:0';
  141. $cat['bare_id'] = 0;
  142. $cat['name'] = __("Uncategorized");
  143. $cat['items'] = array();
  144. $cat['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT");
  145. $cat['type'] = 'category';
  146. $cat['checkbox'] = false;
  147. $cat['unread'] = 0;
  148. $cat['child_unread'] = 0;
  149. $feed_result = db_query($this->link, "SELECT id, title,last_error,
  150. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  151. FROM ttrss_feeds
  152. WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
  153. "$search_qpart ORDER BY order_id, title");
  154. while ($feed_line = db_fetch_assoc($feed_result)) {
  155. $feed = array();
  156. $feed['id'] = 'FEED:' . $feed_line['id'];
  157. $feed['bare_id'] = (int)$feed_line['id'];
  158. $feed['name'] = $feed_line['title'];
  159. $feed['checkbox'] = false;
  160. $feed['error'] = $feed_line['last_error'];
  161. $feed['icon'] = getFeedIcon($feed_line['id']);
  162. $feed['param'] = make_local_datetime($this->link,
  163. $feed_line['last_updated'], true);
  164. $feed['unread'] = 0;
  165. $feed['type'] = 'feed';
  166. array_push($cat['items'], $feed);
  167. }
  168. $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
  169. if (count($cat['items']) > 0 || $show_empty_cats)
  170. array_push($root['items'], $cat);
  171. $root['param'] += count($cat['items']);
  172. $root['param'] = T_sprintf('(%d feeds)', $root['param']);
  173. } else {
  174. $feed_result = db_query($this->link, "SELECT id, title, last_error,
  175. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  176. FROM ttrss_feeds
  177. WHERE owner_uid = ".$_SESSION["uid"].
  178. "$search_qpart ORDER BY order_id, title");
  179. while ($feed_line = db_fetch_assoc($feed_result)) {
  180. $feed = array();
  181. $feed['id'] = 'FEED:' . $feed_line['id'];
  182. $feed['bare_id'] = (int)$feed_line['id'];
  183. $feed['name'] = $feed_line['title'];
  184. $feed['checkbox'] = false;
  185. $feed['error'] = $feed_line['last_error'];
  186. $feed['icon'] = getFeedIcon($feed_line['id']);
  187. $feed['param'] = make_local_datetime($this->link,
  188. $feed_line['last_updated'], true);
  189. $feed['unread'] = 0;
  190. $feed['type'] = 'feed';
  191. array_push($root['items'], $feed);
  192. }
  193. $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
  194. }
  195. $fl = array();
  196. $fl['identifier'] = 'id';
  197. $fl['label'] = 'name';
  198. if ($_REQUEST['mode'] != 2) {
  199. $fl['items'] = array($root);
  200. } else {
  201. $fl['items'] =& $root['items'];
  202. }
  203. print json_encode($fl);
  204. return;
  205. }
  206. function catsortreset() {
  207. db_query($this->link, "UPDATE ttrss_feed_categories
  208. SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
  209. return;
  210. }
  211. function feedsortreset() {
  212. db_query($this->link, "UPDATE ttrss_feeds
  213. SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
  214. return;
  215. }
  216. function togglehiddenfeedcats() {
  217. set_pref($this->link, '_PREFS_SHOW_EMPTY_CATS',
  218. (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
  219. }
  220. private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
  221. $debug = isset($_REQUEST["debug"]);
  222. $prefix = "";
  223. for ($i = 0; $i < $nest_level; $i++)
  224. $prefix .= " ";
  225. if ($debug) _debug("$prefix C: $item_id P: $parent_id");
  226. $bare_item_id = substr($item_id, strpos($item_id, ':')+1);
  227. if ($item_id != 'root') {
  228. if ($parent_id && $parent_id != 'root') {
  229. $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
  230. $parent_qpart = db_escape_string($parent_bare_id);
  231. } else {
  232. $parent_qpart = 'NULL';
  233. }
  234. db_query($this->link, "UPDATE ttrss_feed_categories
  235. SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
  236. owner_uid = " . $_SESSION["uid"]);
  237. }
  238. $order_id = 0;
  239. $cat = $data_map[$item_id];
  240. if ($cat && is_array($cat)) {
  241. foreach ($cat as $item) {
  242. $id = $item['_reference'];
  243. $bare_id = substr($id, strpos($id, ':')+1);
  244. if ($debug) _debug("$prefix [$order_id] $id/$bare_id");
  245. if ($item['_reference']) {
  246. if (strpos($id, "FEED") === 0) {
  247. $cat_id = ($item_id != "root") ?
  248. db_escape_string($bare_item_id) : "NULL";
  249. db_query($this->link, "UPDATE ttrss_feeds
  250. SET order_id = $order_id, cat_id = '$cat_id'
  251. WHERE id = '$bare_id' AND
  252. owner_uid = " . $_SESSION["uid"]);
  253. } else if (strpos($id, "CAT:") === 0) {
  254. $this->process_category_order($data_map, $item['_reference'], $item_id,
  255. $nest_level+1);
  256. if ($item_id != 'root') {
  257. $parent_qpart = db_escape_string($bare_id);
  258. } else {
  259. $parent_qpart = 'NULL';
  260. }
  261. db_query($this->link, "UPDATE ttrss_feed_categories
  262. SET order_id = '$order_id' WHERE id = '$bare_id' AND
  263. owner_uid = " . $_SESSION["uid"]);
  264. }
  265. }
  266. ++$order_id;
  267. }
  268. }
  269. }
  270. function savefeedorder() {
  271. $data = json_decode($_POST['payload'], true);
  272. #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
  273. #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
  274. if (!is_array($data['items']))
  275. $data['items'] = json_decode($data['items'], true);
  276. # print_r($data['items']);
  277. if (is_array($data) && is_array($data['items'])) {
  278. $cat_order_id = 0;
  279. $data_map = array();
  280. $root_item = false;
  281. foreach ($data['items'] as $item) {
  282. # if ($item['id'] != 'root') {
  283. if (is_array($item['items'])) {
  284. if (isset($item['items']['_reference'])) {
  285. $data_map[$item['id']] = array($item['items']);
  286. } else {
  287. $data_map[$item['id']] =& $item['items'];
  288. }
  289. }
  290. if ($item['id'] == 'root') {
  291. $root_item = $item['id'];
  292. }
  293. }
  294. $this->process_category_order($data_map, $root_item);
  295. /* foreach ($data['items'][0]['items'] as $item) {
  296. $id = $item['_reference'];
  297. $bare_id = substr($id, strpos($id, ':')+1);
  298. ++$cat_order_id;
  299. if ($bare_id > 0) {
  300. db_query($this->link, "UPDATE ttrss_feed_categories
  301. SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
  302. owner_uid = " . $_SESSION["uid"]);
  303. }
  304. $feed_order_id = 0;
  305. if (is_array($data_map[$id])) {
  306. foreach ($data_map[$id] as $feed) {
  307. $id = $feed['_reference'];
  308. $feed_id = substr($id, strpos($id, ':')+1);
  309. if ($bare_id != 0)
  310. $cat_query = "cat_id = '$bare_id'";
  311. else
  312. $cat_query = "cat_id = NULL";
  313. db_query($this->link, "UPDATE ttrss_feeds
  314. SET order_id = '$feed_order_id',
  315. $cat_query
  316. WHERE id = '$feed_id' AND
  317. owner_uid = " . $_SESSION["uid"]);
  318. ++$feed_order_id;
  319. }
  320. }
  321. } */
  322. }
  323. return;
  324. }
  325. function removeicon() {
  326. $feed_id = db_escape_string($_REQUEST["feed_id"]);
  327. $result = db_query($this->link, "SELECT id FROM ttrss_feeds
  328. WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
  329. if (db_num_rows($result) != 0) {
  330. unlink(ICONS_DIR . "/$feed_id.ico");
  331. }
  332. return;
  333. }
  334. function uploadicon() {
  335. $icon_file = $_FILES['icon_file']['tmp_name'];
  336. $feed_id = db_escape_string($_REQUEST["feed_id"]);
  337. if (is_file($icon_file) && $feed_id) {
  338. if (filesize($icon_file) < 20000) {
  339. $result = db_query($this->link, "SELECT id FROM ttrss_feeds
  340. WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
  341. if (db_num_rows($result) != 0) {
  342. unlink(ICONS_DIR . "/$feed_id.ico");
  343. move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
  344. $rc = 0;
  345. } else {
  346. $rc = 2;
  347. }
  348. } else {
  349. $rc = 1;
  350. }
  351. } else {
  352. $rc = 2;
  353. }
  354. print "<script type=\"text/javascript\">";
  355. print "parent.uploadIconHandler($rc);";
  356. print "</script>";
  357. return;
  358. }
  359. function editfeed() {
  360. global $purge_intervals;
  361. global $update_intervals;
  362. global $update_methods;
  363. $feed_id = db_escape_string($_REQUEST["id"]);
  364. $result = db_query($this->link,
  365. "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
  366. owner_uid = " . $_SESSION["uid"]);
  367. $title = htmlspecialchars(db_fetch_result($result,
  368. 0, "title"));
  369. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">";
  370. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
  371. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
  372. print "<div class=\"dlgSec\">".__("Feed")."</div>";
  373. print "<div class=\"dlgSecCont\">";
  374. /* Title */
  375. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
  376. placeHolder=\"".__("Feed Title")."\"
  377. style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">";
  378. /* Feed URL */
  379. $feed_url = db_fetch_result($result, 0, "feed_url");
  380. $feed_url = htmlspecialchars(db_fetch_result($result,
  381. 0, "feed_url"));
  382. print "<hr/>";
  383. print __('URL:') . " ";
  384. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
  385. placeHolder=\"".__("Feed URL")."\"
  386. regExp='^(http|https)://.*' style=\"width : 20em\"
  387. name=\"feed_url\" value=\"$feed_url\">";
  388. $last_error = db_fetch_result($result, 0, "last_error");
  389. if ($last_error) {
  390. print "&nbsp;<span title=\"".htmlspecialchars($last_error)."\"
  391. class=\"feed_error\">(error)</span>";
  392. }
  393. /* Category */
  394. if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
  395. $cat_id = db_fetch_result($result, 0, "cat_id");
  396. print "<hr/>";
  397. print __('Place in category:') . " ";
  398. print_feed_cat_select($this->link, "cat_id", $cat_id,
  399. 'dojoType="dijit.form.Select"');
  400. }
  401. print "</div>";
  402. print "<div class=\"dlgSec\">".__("Update")."</div>";
  403. print "<div class=\"dlgSecCont\">";
  404. /* Update Interval */
  405. $update_interval = db_fetch_result($result, 0, "update_interval");
  406. print_select_hash("update_interval", $update_interval, $update_intervals,
  407. 'dojoType="dijit.form.Select"');
  408. /* Update method */
  409. $update_method = db_fetch_result($result, 0, "update_method",
  410. 'dojoType="dijit.form.Select"');
  411. print " " . __('using') . " ";
  412. print_select_hash("update_method", $update_method, $update_methods,
  413. 'dojoType="dijit.form.Select"');
  414. $purge_interval = db_fetch_result($result, 0, "purge_interval");
  415. /* Purge intl */
  416. print "<hr/>";
  417. print __('Article purging:') . " ";
  418. print_select_hash("purge_interval", $purge_interval, $purge_intervals,
  419. 'dojoType="dijit.form.Select" ' .
  420. ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
  421. print "</div>";
  422. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  423. print "<div class=\"dlgSecCont\">";
  424. $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
  425. print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\"
  426. placeHolder=\"".__("Login")."\"
  427. name=\"auth_login\" value=\"$auth_login\"><hr/>";
  428. $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
  429. print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  430. placeHolder=\"".__("Password")."\"
  431. value=\"$auth_pass\">";
  432. print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\">
  433. ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')."
  434. </div>";
  435. print "</div>";
  436. print "<div class=\"dlgSec\">".__("Options")."</div>";
  437. print "<div class=\"dlgSecCont\">";
  438. $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
  439. if ($private) {
  440. $checked = "checked=\"1\"";
  441. } else {
  442. $checked = "";
  443. }
  444. print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
  445. $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
  446. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  447. if ($rtl_content) {
  448. $checked = "checked=\"1\"";
  449. } else {
  450. $checked = "";
  451. }
  452. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
  453. $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
  454. $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
  455. if ($include_in_digest) {
  456. $checked = "checked=\"1\"";
  457. } else {
  458. $checked = "";
  459. }
  460. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
  461. name=\"include_in_digest\"
  462. $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  463. $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
  464. if ($always_display_enclosures) {
  465. $checked = "checked";
  466. } else {
  467. $checked = "";
  468. }
  469. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
  470. name=\"always_display_enclosures\"
  471. $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  472. $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
  473. if ($cache_images) {
  474. $checked = "checked=\"1\"";
  475. } else {
  476. $checked = "";
  477. }
  478. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
  479. name=\"cache_images\"
  480. $checked>&nbsp;<label for=\"cache_images\">".
  481. __('Cache images locally')."</label>";
  482. $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
  483. if ($mark_unread_on_update) {
  484. $checked = "checked";
  485. } else {
  486. $checked = "";
  487. }
  488. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"
  489. name=\"mark_unread_on_update\"
  490. $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
  491. $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
  492. if ($update_on_checksum_change) {
  493. $checked = "checked";
  494. } else {
  495. $checked = "";
  496. }
  497. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"update_on_checksum_change\"
  498. name=\"update_on_checksum_change\"
  499. $checked>&nbsp;<label for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
  500. print "</div>";
  501. /* Icon */
  502. print "<div class=\"dlgSec\">".__("Icon")."</div>";
  503. print "<div class=\"dlgSecCont\">";
  504. print "<iframe name=\"icon_upload_iframe\"
  505. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  506. print "<form style='display : block' target=\"icon_upload_iframe\"
  507. enctype=\"multipart/form-data\" method=\"POST\"
  508. action=\"backend.php\">
  509. <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
  510. <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
  511. <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
  512. <input type=\"hidden\" name=\"method\" value=\"uploadicon\">
  513. <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
  514. type=\"submit\">".__('Replace')."</button>
  515. <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
  516. type=\"submit\">".__('Remove')."</button>
  517. </form>";
  518. print "</div>";
  519. $title = htmlspecialchars($title, ENT_QUOTES);
  520. print "<div class='dlgButtons'>
  521. <div style=\"float : left\">
  522. <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
  523. __('Unsubscribe')."</button>";
  524. if (PUBSUBHUBBUB_ENABLED) {
  525. $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
  526. $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\"";
  527. print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled
  528. onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates').
  529. "</button>";
  530. }
  531. print "</div>";
  532. print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">".
  533. __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>";
  534. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
  535. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
  536. </div>";
  537. return;
  538. }
  539. function editfeeds() {
  540. global $purge_intervals;
  541. global $update_intervals;
  542. global $update_methods;
  543. $feed_ids = db_escape_string($_REQUEST["ids"]);
  544. print "<div class=\"dialogNotice\">" . __("Enable the options you wish to apply using checkboxes on the right:") . "</div>";
  545. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
  546. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
  547. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">";
  548. print "<div class=\"dlgSec\">".__("Feed")."</div>";
  549. print "<div class=\"dlgSecCont\">";
  550. /* Title */
  551. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  552. disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
  553. name=\"title\" value=\"$title\">";
  554. $this->batch_edit_cbox("title");
  555. /* Feed URL */
  556. print "<br/>";
  557. print __('URL:') . " ";
  558. print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
  559. required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
  560. name=\"feed_url\" value=\"$feed_url\">";
  561. $this->batch_edit_cbox("feed_url");
  562. /* Category */
  563. if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
  564. print "<br/>";
  565. print __('Place in category:') . " ";
  566. print_feed_cat_select($this->link, "cat_id", $cat_id,
  567. 'disabled="1" dojoType="dijit.form.Select"');
  568. $this->batch_edit_cbox("cat_id");
  569. }
  570. print "</div>";
  571. print "<div class=\"dlgSec\">".__("Update")."</div>";
  572. print "<div class=\"dlgSecCont\">";
  573. /* Update Interval */
  574. print_select_hash("update_interval", $update_interval, $update_intervals,
  575. 'disabled="1" dojoType="dijit.form.Select"');
  576. $this->batch_edit_cbox("update_interval");
  577. /* Update method */
  578. print " " . __('using') . " ";
  579. print_select_hash("update_method", $update_method, $update_methods,
  580. 'disabled="1" dojoType="dijit.form.Select"');
  581. $this->batch_edit_cbox("update_method");
  582. /* Purge intl */
  583. if (FORCE_ARTICLE_PURGE == 0) {
  584. print "<br/>";
  585. print __('Article purging:') . " ";
  586. print_select_hash("purge_interval", $purge_interval, $purge_intervals,
  587. 'disabled="1" dojoType="dijit.form.Select"');
  588. $this->batch_edit_cbox("purge_interval");
  589. }
  590. print "</div>";
  591. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  592. print "<div class=\"dlgSecCont\">";
  593. print "<input dojoType=\"dijit.form.TextBox\"
  594. placeHolder=\"".__("Login")."\" disabled=\"1\"
  595. name=\"auth_login\" value=\"$auth_login\">";
  596. $this->batch_edit_cbox("auth_login");
  597. print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  598. placeHolder=\"".__("Password")."\" disabled=\"1\"
  599. value=\"$auth_pass\">";
  600. $this->batch_edit_cbox("auth_pass");
  601. print "</div>";
  602. print "<div class=\"dlgSec\">".__("Options")."</div>";
  603. print "<div class=\"dlgSecCont\">";
  604. print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
  605. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
  606. print "&nbsp;"; $this->batch_edit_cbox("private", "private_l");
  607. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
  608. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
  609. print "&nbsp;"; $this->batch_edit_cbox("rtl_content", "rtl_content_l");
  610. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
  611. name=\"include_in_digest\"
  612. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  613. print "&nbsp;"; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
  614. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
  615. name=\"always_display_enclosures\"
  616. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  617. print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
  618. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
  619. name=\"cache_images\"
  620. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
  621. for=\"cache_images\">".
  622. __('Cache images locally')."</label>";
  623. print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
  624. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
  625. name=\"mark_unread_on_update\"
  626. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
  627. print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
  628. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"update_on_checksum_change\"
  629. name=\"update_on_checksum_change\"
  630. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"update_on_checksum_change_l\" class='insensitive' for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
  631. print "&nbsp;"; $this->batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
  632. print "</div>";
  633. print "<div class='dlgButtons'>
  634. <button dojoType=\"dijit.form.Button\"
  635. onclick=\"return dijit.byId('feedEditDlg').execute()\">".
  636. __('Save')."</button>
  637. <button dojoType=\"dijit.form.Button\"
  638. onclick=\"return dijit.byId('feedEditDlg').hide()\">".
  639. __('Cancel')."</button>
  640. </div>";
  641. return;
  642. }
  643. function batchEditSave() {
  644. return $this->editsaveops(true);
  645. }
  646. function editSave() {
  647. return $this->editsaveops(false);
  648. }
  649. function editsaveops($batch) {
  650. $feed_title = db_escape_string(trim($_POST["title"]));
  651. $feed_link = db_escape_string(trim($_POST["feed_url"]));
  652. $upd_intl = (int) db_escape_string($_POST["update_interval"]);
  653. $purge_intl = (int) db_escape_string($_POST["purge_interval"]);
  654. $feed_id = (int) db_escape_string($_POST["id"]); /* editSave */
  655. $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
  656. $cat_id = (int) db_escape_string($_POST["cat_id"]);
  657. $auth_login = db_escape_string(trim($_POST["auth_login"]));
  658. $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
  659. $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
  660. $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
  661. $include_in_digest = checkbox_to_sql_bool(
  662. db_escape_string($_POST["include_in_digest"]));
  663. $cache_images = checkbox_to_sql_bool(
  664. db_escape_string($_POST["cache_images"]));
  665. $update_method = (int) db_escape_string($_POST["update_method"]);
  666. $always_display_enclosures = checkbox_to_sql_bool(
  667. db_escape_string($_POST["always_display_enclosures"]));
  668. $mark_unread_on_update = checkbox_to_sql_bool(
  669. db_escape_string($_POST["mark_unread_on_update"]));
  670. $update_on_checksum_change = checkbox_to_sql_bool(
  671. db_escape_string($_POST["update_on_checksum_change"]));
  672. if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
  673. if ($cat_id && $cat_id != 0) {
  674. $category_qpart = "cat_id = '$cat_id',";
  675. $category_qpart_nocomma = "cat_id = '$cat_id'";
  676. } else {
  677. $category_qpart = 'cat_id = NULL,';
  678. $category_qpart_nocomma = 'cat_id = NULL';
  679. }
  680. } else {
  681. $category_qpart = "";
  682. $category_qpart_nocomma = "";
  683. }
  684. $cache_images_qpart = "cache_images = $cache_images,";
  685. if (!$batch) {
  686. $result = db_query($this->link, "UPDATE ttrss_feeds SET
  687. $category_qpart
  688. title = '$feed_title', feed_url = '$feed_link',
  689. update_interval = '$upd_intl',
  690. purge_interval = '$purge_intl',
  691. auth_login = '$auth_login',
  692. auth_pass = '$auth_pass',
  693. private = $private,
  694. rtl_content = $rtl_content,
  695. $cache_images_qpart
  696. include_in_digest = $include_in_digest,
  697. always_display_enclosures = $always_display_enclosures,
  698. mark_unread_on_update = $mark_unread_on_update,
  699. update_on_checksum_change = $update_on_checksum_change,
  700. update_method = '$update_method'
  701. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  702. } else {
  703. $feed_data = array();
  704. foreach (array_keys($_POST) as $k) {
  705. if ($k != "op" && $k != "method" && $k != "ids") {
  706. $feed_data[$k] = $_POST[$k];
  707. }
  708. }
  709. db_query($this->link, "BEGIN");
  710. foreach (array_keys($feed_data) as $k) {
  711. $qpart = "";
  712. switch ($k) {
  713. case "title":
  714. $qpart = "title = '$feed_title'";
  715. break;
  716. case "feed_url":
  717. $qpart = "feed_url = '$feed_link'";
  718. break;
  719. case "update_interval":
  720. $qpart = "update_interval = '$upd_intl'";
  721. break;
  722. case "purge_interval":
  723. $qpart = "purge_interval = '$purge_intl'";
  724. break;
  725. case "auth_login":
  726. $qpart = "auth_login = '$auth_login'";
  727. break;
  728. case "auth_pass":
  729. $qpart = "auth_pass = '$auth_pass'";
  730. break;
  731. case "private":
  732. $qpart = "private = $private";
  733. break;
  734. case "include_in_digest":
  735. $qpart = "include_in_digest = $include_in_digest";
  736. break;
  737. case "always_display_enclosures":
  738. $qpart = "always_display_enclosures = $always_display_enclosures";
  739. break;
  740. case "mark_unread_on_update":
  741. $qpart = "mark_unread_on_update = $mark_unread_on_update";
  742. break;
  743. case "update_on_checksum_change":
  744. $qpart = "update_on_checksum_change = $update_on_checksum_change";
  745. break;
  746. case "cache_images":
  747. $qpart = "cache_images = $cache_images";
  748. break;
  749. case "rtl_content":
  750. $qpart = "rtl_content = $rtl_content";
  751. break;
  752. case "update_method":
  753. $qpart = "update_method = '$update_method'";
  754. break;
  755. case "cat_id":
  756. $qpart = $category_qpart_nocomma;
  757. break;
  758. }
  759. if ($qpart) {
  760. db_query($this->link,
  761. "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
  762. AND owner_uid = " . $_SESSION["uid"]);
  763. print "<br/>";
  764. }
  765. }
  766. db_query($this->link, "COMMIT");
  767. }
  768. return;
  769. }
  770. function resetPubSub() {
  771. $ids = db_escape_string($_REQUEST["ids"]);
  772. db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids)
  773. AND owner_uid = " . $_SESSION["uid"]);
  774. return;
  775. }
  776. function remove() {
  777. $ids = split(",", db_escape_string($_REQUEST["ids"]));
  778. foreach ($ids as $id) {
  779. remove_feed($this->link, $id, $_SESSION["uid"]);
  780. }
  781. return;
  782. }
  783. function clear() {
  784. $id = db_escape_string($_REQUEST["id"]);
  785. clear_feed_articles($this->link, $id);
  786. }
  787. function rescore() {
  788. $ids = split(",", db_escape_string($_REQUEST["ids"]));
  789. foreach ($ids as $id) {
  790. $filters = load_filters($this->link, $id, $_SESSION["uid"], 6);
  791. $result = db_query($this->link, "SELECT
  792. title, content, link, ref_id, author,".
  793. SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
  794. FROM
  795. ttrss_user_entries, ttrss_entries
  796. WHERE ref_id = id AND feed_id = '$id' AND
  797. owner_uid = " .$_SESSION['uid']."
  798. ");
  799. $scores = array();
  800. while ($line = db_fetch_assoc($result)) {
  801. $tags = get_article_tags($this->link, $line["ref_id"]);
  802. $article_filters = get_article_filters($filters, $line['title'],
  803. $line['content'], $line['link'], strtotime($line['updated']),
  804. $line['author'], $tags);
  805. $new_score = calculate_article_score($article_filters);
  806. if (!$scores[$new_score]) $scores[$new_score] = array();
  807. array_push($scores[$new_score], $line['ref_id']);
  808. }
  809. foreach (array_keys($scores) as $s) {
  810. if ($s > 1000) {
  811. db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
  812. marked = true WHERE
  813. ref_id IN (" . join(',', $scores[$s]) . ")");
  814. } else if ($s < -500) {
  815. db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
  816. unread = false WHERE
  817. ref_id IN (" . join(',', $scores[$s]) . ")");
  818. } else {
  819. db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
  820. ref_id IN (" . join(',', $scores[$s]) . ")");
  821. }
  822. }
  823. }
  824. print __("All done.");
  825. }
  826. function rescoreAll() {
  827. $result = db_query($this->link,
  828. "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
  829. while ($feed_line = db_fetch_assoc($result)) {
  830. $id = $feed_line["id"];
  831. $filters = load_filters($this->link, $id, $_SESSION["uid"], 6);
  832. $tmp_result = db_query($this->link, "SELECT
  833. title, content, link, ref_id, author,".
  834. SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
  835. FROM
  836. ttrss_user_entries, ttrss_entries
  837. WHERE ref_id = id AND feed_id = '$id' AND
  838. owner_uid = " .$_SESSION['uid']."
  839. ");
  840. $scores = array();
  841. while ($line = db_fetch_assoc($tmp_result)) {
  842. $tags = get_article_tags($this->link, $line["ref_id"]);
  843. $article_filters = get_article_filters($filters, $line['title'],
  844. $line['content'], $line['link'], strtotime($line['updated']),
  845. $line['author'], $tags);
  846. $new_score = calculate_article_score($article_filters);
  847. if (!$scores[$new_score]) $scores[$new_score] = array();
  848. array_push($scores[$new_score], $line['ref_id']);
  849. }
  850. foreach (array_keys($scores) as $s) {
  851. if ($s > 1000) {
  852. db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
  853. marked = true WHERE
  854. ref_id IN (" . join(',', $scores[$s]) . ")");
  855. } else {
  856. db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
  857. ref_id IN (" . join(',', $scores[$s]) . ")");
  858. }
  859. }
  860. }
  861. print __("All done.");
  862. }
  863. function add() {
  864. $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
  865. $cat_id = db_escape_string($_REQUEST["cat_id"]);
  866. $p_from = db_escape_string($_REQUEST["from"]);
  867. /* only read authentication information from POST */
  868. $auth_login = db_escape_string(trim($_POST["auth_login"]));
  869. $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
  870. if ($p_from != 'tt-rss') {
  871. header('Content-Type: text/html; charset=utf-8');
  872. print "<html>
  873. <head>
  874. <title>Tiny Tiny RSS</title>
  875. <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
  876. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  877. </head>
  878. <body>
  879. <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
  880. alt=\"Tiny Tiny RSS\"/>
  881. <h1>Subscribe to feed...</h1>";
  882. }
  883. $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
  884. switch ($rc) {
  885. case 1:
  886. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  887. break;
  888. case 2:
  889. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  890. break;
  891. case 3:
  892. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  893. break;
  894. case 0:
  895. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  896. break;
  897. case 4:
  898. print_notice(__("Multiple feed URLs found."));
  899. $feed_urls = get_feeds_from_html($feed_url);
  900. break;
  901. case 5:
  902. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  903. break;
  904. }
  905. if ($p_from != 'tt-rss') {
  906. if ($feed_urls) {
  907. print "<form action=\"backend.php\">";
  908. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  909. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  910. print "<input type=\"hidden\" name=\"method\" value=\"add\">";
  911. print "<select name=\"feed_url\">";
  912. foreach ($feed_urls as $url => $name) {
  913. $url = htmlspecialchars($url);
  914. $name = htmlspecialchars($name);
  915. print "<option value=\"$url\">$name</option>";
  916. }
  917. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
  918. "\">";
  919. print "</form>";
  920. }
  921. $tp_uri = get_self_url_prefix() . "/prefs.php";
  922. $tt_uri = get_self_url_prefix();
  923. if ($rc <= 2){
  924. $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
  925. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  926. $feed_id = db_fetch_result($result, 0, "id");
  927. } else {
  928. $feed_id = 0;
  929. }
  930. print "<p>";
  931. if ($feed_id) {
  932. print "<form method=\"GET\" style='display: inline'
  933. action=\"$tp_uri\">
  934. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  935. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  936. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  937. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  938. </form>";
  939. }
  940. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  941. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  942. </form></p>";
  943. print "</body></html>";
  944. return;
  945. }
  946. }
  947. function categorize() {
  948. $ids = split(",", db_escape_string($_REQUEST["ids"]));
  949. $cat_id = db_escape_string($_REQUEST["cat_id"]);
  950. if ($cat_id == 0) {
  951. $cat_id_qpart = 'NULL';
  952. } else {
  953. $cat_id_qpart = "'$cat_id'";
  954. }
  955. db_query($this->link, "BEGIN");
  956. foreach ($ids as $id) {
  957. db_query($this->link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
  958. WHERE id = '$id'
  959. AND owner_uid = " . $_SESSION["uid"]);
  960. }
  961. db_query($this->link, "COMMIT");
  962. }
  963. function removeCat() {
  964. $ids = split(",", db_escape_string($_REQUEST["ids"]));
  965. foreach ($ids as $id) {
  966. remove_feed_category($this->link, $id, $_SESSION["uid"]);
  967. }
  968. }
  969. function addCat() {
  970. $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
  971. add_feed_category($this->link, $feed_cat);
  972. }
  973. function index() {
  974. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  975. print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
  976. $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
  977. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  978. $num_errors = db_fetch_result($result, 0, "num_errors");
  979. if ($num_errors > 0) {
  980. $error_button = "<button dojoType=\"dijit.form.Button\"
  981. onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
  982. __("Feeds with errors") . "</button>";
  983. }
  984. if (DB_TYPE == "pgsql") {
  985. $interval_qpart = "NOW() - INTERVAL '3 months'";
  986. } else {
  987. $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
  988. }
  989. $result = db_query($this->link, "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
  990. (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
  991. ttrss_entries.id = ref_id AND
  992. ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
  993. ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
  994. $num_inactive = db_fetch_result($result, 0, "num_inactive");
  995. if ($num_inactive > 0) {
  996. $inactive_button = "<button dojoType=\"dijit.form.Button\"
  997. onclick=\"showInactiveFeeds()\">" .
  998. __("Inactive feeds") . "</button>";
  999. }
  1000. $feed_search = db_escape_string($_REQUEST["search"]);
  1001. if (array_key_exists("search", $_REQUEST)) {
  1002. $_SESSION["prefs_feed_search"] = $feed_search;
  1003. } else {
  1004. $feed_search = $_SESSION["prefs_feed_search"];
  1005. }
  1006. print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
  1007. print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar
  1008. print "<div style='float : right; padding-right : 4px;'>
  1009. <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
  1010. value=\"$feed_search\">
  1011. <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">".
  1012. __('Search')."</button>
  1013. </div>";
  1014. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1015. "<span>" . __('Select')."</span>";
  1016. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1017. print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
  1018. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  1019. print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
  1020. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  1021. print "</div></div>";
  1022. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1023. "<span>" . __('Feeds')."</span>";
  1024. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1025. print "<div onclick=\"quickAddFeed()\"
  1026. dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
  1027. print "<div onclick=\"editSelectedFeed()\"
  1028. dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
  1029. print "<div onclick=\"resetFeedOrder()\"
  1030. dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
  1031. print "<div onclick=\"batchSubscribe()\"
  1032. dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
  1033. print "</div></div>";
  1034. if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
  1035. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1036. "<span>" . __('Categories')."</span>";
  1037. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1038. print "<div onclick=\"createCategory()\"
  1039. dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
  1040. print "<div onclick=\"toggleHiddenFeedCats()\"
  1041. dojoType=\"dijit.MenuItem\">".__('(Un)hide empty categories')."</div>";
  1042. print "<div onclick=\"resetCatOrder()\"
  1043. dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
  1044. print "</div></div>";
  1045. }
  1046. print $error_button;
  1047. print $inactive_button;
  1048. print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
  1049. .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
  1050. if (defined('_ENABLE_FEED_DEBUGGING')) {
  1051. print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
  1052. <option value=\"facDefault\" selected>".__('More actions...')."</option>";
  1053. if (FORCE_ARTICLE_PURGE == 0) {
  1054. print
  1055. "<option value=\"facPurge\">".__('Manual purge')."</option>";
  1056. }
  1057. print "
  1058. <option value=\"facClear\">".__('Clear feed data')."</option>
  1059. <option value=\"facRescore\">".__('Rescore articles')."</option>";
  1060. print "</select>";
  1061. }
  1062. print "</div>"; # toolbar
  1063. //print '</div>';
  1064. print '<div dojoType="dijit.layout.ContentPane" region="center">';
  1065. print "<div id=\"feedlistLoading\">
  1066. <img src='images/indicator_tiny.gif'>".
  1067. __("Loading, please wait...")."</div>";
  1068. print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
  1069. url=\"backend.php?op=pref-feeds&method=getfeedtree\">
  1070. </div>
  1071. <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
  1072. query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
  1073. childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
  1074. </div>
  1075. <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
  1076. dndController=\"dijit.tree.dndSource\"
  1077. betweenThreshold=\"5\"
  1078. model=\"feedModel\" openOnClick=\"false\">
  1079. <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
  1080. var id = String(item.id);
  1081. var bare_id = id.substr(id.indexOf(':')+1);
  1082. if (id.match('FEED:')) {
  1083. editFeed(bare_id);
  1084. } else if (id.match('CAT:')) {
  1085. editCat(bare_id, item);
  1086. }
  1087. </script>
  1088. <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
  1089. Element.hide(\"feedlistLoading\");
  1090. </script>
  1091. </div>";
  1092. # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
  1093. # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
  1094. # </div>";
  1095. print '</div>';
  1096. print '</div>';
  1097. print "</div>"; # feeds pane
  1098. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Import and export')."\">";
  1099. print "<h3>" . __("OPML") . "</h3>";
  1100. print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
  1101. print __("Only main settings profile can be migrated using OPML.") . "</p>";
  1102. print "<iframe id=\"upload_iframe\"
  1103. name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
  1104. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  1105. print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
  1106. enctype=\"multipart/form-data\" method=\"POST\"
  1107. action=\"backend.php\">
  1108. <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
  1109. <input type=\"hidden\" name=\"op\" value=\"dlg\">
  1110. <input type=\"hidden\" name=\"method\" value=\"importOpml\">
  1111. <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
  1112. __('Import my OPML') . "</button>";
  1113. print "<hr>";
  1114. print "<p>" . __('Filename:') .
  1115. " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" />&nbsp;" .
  1116. __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
  1117. print "</p><button dojoType=\"dijit.form.Button\"
  1118. onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
  1119. __('Export OPML') . "</button></p></form>";
  1120. print "<hr>";
  1121. print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
  1122. print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>";
  1123. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
  1124. __('Display published OPML URL')."</button> ";
  1125. print "<h3>" . __("Article archive") . "</h3>";
  1126. print "<p>" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "</p>";
  1127. print "<button dojoType=\"dijit.form.Button\" onclick=\"return exportData()\">".
  1128. __('Export my data')."</button> ";
  1129. print "<hr>";
  1130. print "<iframe id=\"data_upload_iframe\"
  1131. name=\"data_upload_iframe\" onload=\"dataImportComplete(this)\"
  1132. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  1133. print "<form name=\"import_form\" style='display : block' target=\"data_upload_iframe\"
  1134. enctype=\"multipart/form-data\" method=\"POST\"
  1135. action=\"backend.php\">
  1136. <input id=\"export_file\" name=\"export_file\" type=\"file\">&nbsp;
  1137. <input type=\"hidden\" name=\"op\" value=\"dlg\">
  1138. <input type=\"hidden\" name=\"method\" value=\"dataimport\">
  1139. <button dojoType=\"dijit.form.Button\" onclick=\"return importData();\" type=\"submit\">" .
  1140. __('Import') . "</button>";
  1141. print "</div>"; # pane
  1142. if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
  1143. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
  1144. print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
  1145. print "<p>";
  1146. print "<button onclick='window.navigator.registerContentHandler(" .
  1147. "\"application/vnd.mozilla.maybe.feed\", " .
  1148. "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
  1149. __('Click here to register this site as a feed reader.') .
  1150. "</button>";
  1151. print "</p>";
  1152. print "</div>"; # pane
  1153. }
  1154. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
  1155. print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
  1156. $bm_subscribe_url = str_replace('%s', '', add_feed_url());
  1157. $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?'));
  1158. $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
  1159. print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
  1160. print "</div>"; #pane
  1161. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
  1162. print "<h3>" . __("Published articles and generated feeds") . "</h3>";
  1163. print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
  1164. $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
  1165. "/public.php?op=rss&id=-2&view-mode=all_articles");;
  1166. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
  1167. __('Display URL')."</button> ";
  1168. print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
  1169. __('Clear all generated URLs')."</button> ";
  1170. print "<h3>" . __("Articles shared by URL") . "</h3>";
  1171. print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
  1172. print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
  1173. __('Unshare all articles')."</button> ";
  1174. print "</div>"; #pane
  1175. if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
  1176. print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Twitter')."\">";
  1177. $result = db_query($this->link, "SELECT COUNT(*) AS cid FROM ttrss_users
  1178. WHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND
  1179. id = " . $_SESSION['uid']);
  1180. $is_registered = db_fetch_result($result, 0, "cid") != 0;
  1181. if (!$is_registered) {
  1182. print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.'));
  1183. } else {
  1184. print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.'));
  1185. }
  1186. print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">".
  1187. __("Register with Twitter.com")."</button>";
  1188. print " ";
  1189. print "<button dojoType=\"dijit.form.Button\"
  1190. onclick=\"return clearTwitterCredentials()\">".
  1191. __("Clear stored credentials")."</button>";
  1192. print "</div>"; # pane
  1193. }
  1194. print "</div>"; #container
  1195. }
  1196. private function feedlist_init_cat($cat_id, $hidden = false) {
  1197. $obj = array();
  1198. $cat_id = (int) $cat_id;
  1199. if ($cat_id > 0) {
  1200. $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
  1201. } else if ($cat_id == 0 || $cat_id == -2) {
  1202. $cat_unread = getCategoryUnread($this->link, $cat_id);
  1203. }
  1204. $obj['id'] = 'CAT:' . $cat_id;
  1205. $obj['items'] = array();
  1206. $obj['name'] = getCategoryTitle($this->link, $cat_id);
  1207. $obj['type'] = 'category';
  1208. $obj['unread'] = (int) $cat_unread;
  1209. $obj['hidden'] = $hidden;
  1210. $obj['bare_id'] = $cat_id;
  1211. return $obj;
  1212. }
  1213. private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
  1214. $obj = array();
  1215. $feed_id = (int) $feed_id;
  1216. if (!$title)
  1217. $title = getFeedTitle($this->link, $feed_id, false);
  1218. if ($unread === false)
  1219. $unread = getFeedUnread($this->link, $feed_id, false);
  1220. $obj['id'] = 'FEED:' . $feed_id;
  1221. $obj['name'] = $title;
  1222. $obj['unread'] = (int) $unread;
  1223. $obj['type'] = 'feed';
  1224. $obj['error'] = $error;
  1225. $obj['updated'] = $updated;
  1226. $obj['icon'] = getFeedIcon($feed_id);
  1227. $obj['bare_id'] = $feed_id;
  1228. return $obj;
  1229. }
  1230. }
  1231. ?>