feeds.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. <?php
  2. class Pref_Feeds extends Handler_Protected {
  3. public static $feed_languages = array("English", "Danish", "Dutch", "Finnish", "French", "German", "Hungarian", "Italian", "Norwegian",
  4. "Portuguese", "Russian", "Spanish", "Swedish", "Turkish", "Simple");
  5. function csrf_ignore($method) {
  6. $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
  7. "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds",
  8. "batchsubscribe");
  9. return array_search($method, $csrf_ignored) !== false;
  10. }
  11. function batch_edit_cbox($elem, $label = false) {
  12. print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
  13. onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">";
  14. }
  15. function renamecat() {
  16. $title = $_REQUEST['title'];
  17. $id = $_REQUEST['id'];
  18. if ($title) {
  19. $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET
  20. title = ? WHERE id = ? AND owner_uid = ?");
  21. $sth->execute([$title, $id, $_SESSION['uid']]);
  22. }
  23. }
  24. private function get_category_items($cat_id) {
  25. if ($_REQUEST['mode'] != 2)
  26. $search = $_SESSION["prefs_feed_search"];
  27. else
  28. $search = "";
  29. // first one is set by API
  30. $show_empty_cats = $_REQUEST['force_show_empty'] ||
  31. ($_REQUEST['mode'] != 2 && !$search);
  32. $items = array();
  33. $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories
  34. WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title");
  35. $sth->execute([$_SESSION['uid'], $cat_id]);
  36. while ($line = $sth->fetch()) {
  37. $cat = array();
  38. $cat['id'] = 'CAT:' . $line['id'];
  39. $cat['bare_id'] = (int)$line['id'];
  40. $cat['name'] = $line['title'];
  41. $cat['items'] = array();
  42. $cat['checkbox'] = false;
  43. $cat['type'] = 'category';
  44. $cat['unread'] = 0;
  45. $cat['child_unread'] = 0;
  46. $cat['auxcounter'] = 0;
  47. $cat['parent_id'] = $cat_id;
  48. $cat['items'] = $this->get_category_items($line['id']);
  49. $num_children = $this->calculate_children_count($cat);
  50. $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children);
  51. if ($num_children > 0 || $show_empty_cats)
  52. array_push($items, $cat);
  53. }
  54. $fsth = $this->pdo->prepare("SELECT id, title, last_error,
  55. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  56. FROM ttrss_feeds
  57. WHERE cat_id = :cat AND
  58. owner_uid = :uid AND
  59. (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
  60. ORDER BY order_id, title");
  61. $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]);
  62. while ($feed_line = $fsth->fetch()) {
  63. $feed = array();
  64. $feed['id'] = 'FEED:' . $feed_line['id'];
  65. $feed['bare_id'] = (int)$feed_line['id'];
  66. $feed['auxcounter'] = 0;
  67. $feed['name'] = $feed_line['title'];
  68. $feed['checkbox'] = false;
  69. $feed['unread'] = 0;
  70. $feed['error'] = $feed_line['last_error'];
  71. $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
  72. $feed['param'] = make_local_datetime(
  73. $feed_line['last_updated'], true);
  74. array_push($items, $feed);
  75. }
  76. return $items;
  77. }
  78. function getfeedtree() {
  79. print json_encode($this->makefeedtree());
  80. }
  81. function makefeedtree() {
  82. if ($_REQUEST['mode'] != 2)
  83. $search = $_SESSION["prefs_feed_search"];
  84. else
  85. $search = "";
  86. $root = array();
  87. $root['id'] = 'root';
  88. $root['name'] = __('Feeds');
  89. $root['items'] = array();
  90. $root['type'] = 'category';
  91. $enable_cats = get_pref('ENABLE_FEED_CATS');
  92. if ($_REQUEST['mode'] == 2) {
  93. if ($enable_cats) {
  94. $cat = $this->feedlist_init_cat(-1);
  95. } else {
  96. $cat['items'] = array();
  97. }
  98. foreach (array(-4, -3, -1, -2, 0, -6) as $i) {
  99. array_push($cat['items'], $this->feedlist_init_feed($i));
  100. }
  101. /* Plugin feeds for -1 */
  102. $feeds = PluginHost::getInstance()->get_feeds(-1);
  103. if ($feeds) {
  104. foreach ($feeds as $feed) {
  105. $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
  106. $item = array();
  107. $item['id'] = 'FEED:' . $feed_id;
  108. $item['bare_id'] = (int)$feed_id;
  109. $item['auxcounter'] = 0;
  110. $item['name'] = $feed['title'];
  111. $item['checkbox'] = false;
  112. $item['error'] = '';
  113. $item['icon'] = $feed['icon'];
  114. $item['param'] = '';
  115. $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']);
  116. $item['type'] = 'feed';
  117. array_push($cat['items'], $item);
  118. }
  119. }
  120. if ($enable_cats) {
  121. array_push($root['items'], $cat);
  122. } else {
  123. $root['items'] = array_merge($root['items'], $cat['items']);
  124. }
  125. $sth = $this->pdo->prepare("SELECT * FROM
  126. ttrss_labels2 WHERE owner_uid = ? ORDER by caption");
  127. $sth->execute([$_SESSION['uid']]);
  128. if (get_pref('ENABLE_FEED_CATS')) {
  129. $cat = $this->feedlist_init_cat(-2);
  130. } else {
  131. $cat['items'] = array();
  132. }
  133. $num_labels = 0;
  134. while ($line = $sth->fetch()) {
  135. ++$num_labels;
  136. $label_id = Labels::label_to_feed_id($line['id']);
  137. $feed = $this->feedlist_init_feed($label_id, false, 0);
  138. $feed['fg_color'] = $line['fg_color'];
  139. $feed['bg_color'] = $line['bg_color'];
  140. array_push($cat['items'], $feed);
  141. }
  142. if ($num_labels) {
  143. if ($enable_cats) {
  144. array_push($root['items'], $cat);
  145. } else {
  146. $root['items'] = array_merge($root['items'], $cat['items']);
  147. }
  148. }
  149. }
  150. if ($enable_cats) {
  151. $show_empty_cats = $_REQUEST['force_show_empty'] ||
  152. ($_REQUEST['mode'] != 2 && !$search);
  153. $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories
  154. WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title");
  155. $sth->execute([$_SESSION['uid']]);
  156. while ($line = $sth->fetch()) {
  157. $cat = array();
  158. $cat['id'] = 'CAT:' . $line['id'];
  159. $cat['bare_id'] = (int)$line['id'];
  160. $cat['auxcounter'] = 0;
  161. $cat['name'] = $line['title'];
  162. $cat['items'] = array();
  163. $cat['checkbox'] = false;
  164. $cat['type'] = 'category';
  165. $cat['unread'] = 0;
  166. $cat['child_unread'] = 0;
  167. $cat['items'] = $this->get_category_items($line['id']);
  168. $num_children = $this->calculate_children_count($cat);
  169. $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children);
  170. if ($num_children > 0 || $show_empty_cats)
  171. array_push($root['items'], $cat);
  172. $root['param'] += count($cat['items']);
  173. }
  174. /* Uncategorized is a special case */
  175. $cat = array();
  176. $cat['id'] = 'CAT:0';
  177. $cat['bare_id'] = 0;
  178. $cat['auxcounter'] = 0;
  179. $cat['name'] = __("Uncategorized");
  180. $cat['items'] = array();
  181. $cat['type'] = 'category';
  182. $cat['checkbox'] = false;
  183. $cat['unread'] = 0;
  184. $cat['child_unread'] = 0;
  185. $fsth = $this->pdo->prepare("SELECT id, title,last_error,
  186. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  187. FROM ttrss_feeds
  188. WHERE cat_id IS NULL AND
  189. owner_uid = :uid AND
  190. (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
  191. ORDER BY order_id, title");
  192. $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]);
  193. while ($feed_line = $fsth->fetch()) {
  194. $feed = array();
  195. $feed['id'] = 'FEED:' . $feed_line['id'];
  196. $feed['bare_id'] = (int)$feed_line['id'];
  197. $feed['auxcounter'] = 0;
  198. $feed['name'] = $feed_line['title'];
  199. $feed['checkbox'] = false;
  200. $feed['error'] = $feed_line['last_error'];
  201. $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
  202. $feed['param'] = make_local_datetime(
  203. $feed_line['last_updated'], true);
  204. $feed['unread'] = 0;
  205. $feed['type'] = 'feed';
  206. array_push($cat['items'], $feed);
  207. }
  208. $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
  209. if (count($cat['items']) > 0 || $show_empty_cats)
  210. array_push($root['items'], $cat);
  211. $num_children = $this->calculate_children_count($root);
  212. $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children);
  213. } else {
  214. $fsth = $this->pdo->prepare("SELECT id, title, last_error,
  215. ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  216. FROM ttrss_feeds
  217. WHERE owner_uid = :uid AND
  218. (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search))
  219. ORDER BY order_id, title");
  220. $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]);
  221. while ($feed_line = $fsth->fetch()) {
  222. $feed = array();
  223. $feed['id'] = 'FEED:' . $feed_line['id'];
  224. $feed['bare_id'] = (int)$feed_line['id'];
  225. $feed['auxcounter'] = 0;
  226. $feed['name'] = $feed_line['title'];
  227. $feed['checkbox'] = false;
  228. $feed['error'] = $feed_line['last_error'];
  229. $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
  230. $feed['param'] = make_local_datetime(
  231. $feed_line['last_updated'], true);
  232. $feed['unread'] = 0;
  233. $feed['type'] = 'feed';
  234. array_push($root['items'], $feed);
  235. }
  236. $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
  237. }
  238. $fl = array();
  239. $fl['identifier'] = 'id';
  240. $fl['label'] = 'name';
  241. if ($_REQUEST['mode'] != 2) {
  242. $fl['items'] = array($root);
  243. } else {
  244. $fl['items'] = $root['items'];
  245. }
  246. return $fl;
  247. }
  248. function catsortreset() {
  249. $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories
  250. SET order_id = 0 WHERE owner_uid = ?");
  251. $sth->execute([$_SESSION['uid']]);
  252. }
  253. function feedsortreset() {
  254. $sth = $this->pdo->prepare("UPDATE ttrss_feeds
  255. SET order_id = 0 WHERE owner_uid = ?");
  256. $sth->execute([$_SESSION['uid']]);
  257. }
  258. private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
  259. $debug = isset($_REQUEST["debug"]);
  260. $prefix = "";
  261. for ($i = 0; $i < $nest_level; $i++)
  262. $prefix .= " ";
  263. if ($debug) _debug("$prefix C: $item_id P: $parent_id");
  264. $bare_item_id = substr($item_id, strpos($item_id, ':')+1);
  265. if ($item_id != 'root') {
  266. if ($parent_id && $parent_id != 'root') {
  267. $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
  268. $parent_qpart = $parent_bare_id;
  269. } else {
  270. $parent_qpart = null;
  271. }
  272. $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories
  273. SET parent_cat = ? WHERE id = ? AND
  274. owner_uid = ?");
  275. $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]);
  276. }
  277. $order_id = 1;
  278. $cat = $data_map[$item_id];
  279. if ($cat && is_array($cat)) {
  280. foreach ($cat as $item) {
  281. $id = $item['_reference'];
  282. $bare_id = substr($id, strpos($id, ':')+1);
  283. if ($debug) _debug("$prefix [$order_id] $id/$bare_id");
  284. if ($item['_reference']) {
  285. if (strpos($id, "FEED") === 0) {
  286. $cat_id = ($item_id != "root") ? $bare_item_id : null;
  287. $sth = $this->pdo->prepare("UPDATE ttrss_feeds
  288. SET order_id = ?, cat_id = ?
  289. WHERE id = ? AND owner_uid = ?");
  290. $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]);
  291. } else if (strpos($id, "CAT:") === 0) {
  292. $this->process_category_order($data_map, $item['_reference'], $item_id,
  293. $nest_level+1);
  294. $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories
  295. SET order_id = ? WHERE id = ? AND
  296. owner_uid = ?");
  297. $sth->execute([$order_id, $bare_id, $_SESSION['uid']]);
  298. }
  299. }
  300. ++$order_id;
  301. }
  302. }
  303. }
  304. function savefeedorder() {
  305. $data = json_decode($_POST['payload'], true);
  306. #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
  307. #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
  308. if (!is_array($data['items']))
  309. $data['items'] = json_decode($data['items'], true);
  310. # print_r($data['items']);
  311. if (is_array($data) && is_array($data['items'])) {
  312. # $cat_order_id = 0;
  313. $data_map = array();
  314. $root_item = false;
  315. foreach ($data['items'] as $item) {
  316. # if ($item['id'] != 'root') {
  317. if (is_array($item['items'])) {
  318. if (isset($item['items']['_reference'])) {
  319. $data_map[$item['id']] = array($item['items']);
  320. } else {
  321. $data_map[$item['id']] = $item['items'];
  322. }
  323. }
  324. if ($item['id'] == 'root') {
  325. $root_item = $item['id'];
  326. }
  327. }
  328. $this->process_category_order($data_map, $root_item);
  329. }
  330. }
  331. function removeicon() {
  332. $feed_id = $_REQUEST["feed_id"];
  333. $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
  334. WHERE id = ? AND owner_uid = ?");
  335. $sth->execute([$feed_id, $_SESSION['uid']]);
  336. if ($row = $sth->fetch()) {
  337. @unlink(ICONS_DIR . "/$feed_id.ico");
  338. $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL
  339. where id = ?");
  340. $sth->execute([$feed_id]);
  341. }
  342. }
  343. function uploadicon() {
  344. header("Content-type: text/html");
  345. if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
  346. $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon');
  347. $result = move_uploaded_file($_FILES['icon_file']['tmp_name'],
  348. $tmp_file);
  349. if (!$result) {
  350. return;
  351. }
  352. } else {
  353. return;
  354. }
  355. $icon_file = $tmp_file;
  356. $feed_id = $_REQUEST["feed_id"];
  357. if (is_file($icon_file) && $feed_id) {
  358. if (filesize($icon_file) < 65535) {
  359. $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
  360. WHERE id = ? AND owner_uid = ?");
  361. $sth->execute([$feed_id, $_SESSION['uid']]);
  362. if ($row = $sth->fetch()) {
  363. @unlink(ICONS_DIR . "/$feed_id.ico");
  364. if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) {
  365. $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET
  366. favicon_avg_color = ''
  367. WHERE id = ?");
  368. $sth->execute([$feed_id]);
  369. $rc = 0;
  370. }
  371. } else {
  372. $rc = 2;
  373. }
  374. } else {
  375. $rc = 1;
  376. }
  377. } else {
  378. $rc = 2;
  379. }
  380. @unlink($icon_file);
  381. print "<script type=\"text/javascript\">";
  382. print "parent.uploadIconHandler($rc);";
  383. print "</script>";
  384. return;
  385. }
  386. function editfeed() {
  387. global $purge_intervals;
  388. global $update_intervals;
  389. $feed_id = $_REQUEST["id"];
  390. $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND
  391. owner_uid = ?");
  392. $sth->execute([$feed_id, $_SESSION['uid']]);
  393. if ($row = $sth->fetch()) {
  394. print '<div dojoType="dijit.layout.TabContainer" style="height : 450px">
  395. <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">';
  396. $auth_pass_encrypted = $row["auth_pass_encrypted"];
  397. $title = htmlspecialchars($row["title"]);
  398. print_hidden("id", "$feed_id");
  399. print_hidden("op", "pref-feeds");
  400. print_hidden("method", "editSave");
  401. print "<div class=\"dlgSec\">".__("Feed")."</div>";
  402. print "<div class=\"dlgSecCont\">";
  403. /* Title */
  404. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
  405. placeHolder=\"".__("Feed Title")."\"
  406. style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">";
  407. /* Feed URL */
  408. $feed_url = htmlspecialchars($row["feed_url"]);
  409. print "<hr/>";
  410. print __('URL:') . " ";
  411. print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
  412. placeHolder=\"".__("Feed URL")."\"
  413. regExp='^(http|https)://.*' style=\"width : 20em\"
  414. name=\"feed_url\" value=\"$feed_url\">";
  415. $last_error = $row["last_error"];
  416. if ($last_error) {
  417. print "&nbsp;<img src=\"images/error.png\" alt=\"(error)\"
  418. style=\"vertical-align : middle\"
  419. title=\"".htmlspecialchars($last_error)."\">";
  420. }
  421. /* Category */
  422. if (get_pref('ENABLE_FEED_CATS')) {
  423. $cat_id = $row["cat_id"];
  424. print "<hr/>";
  425. print __('Place in category:') . " ";
  426. print_feed_cat_select("cat_id", $cat_id,
  427. 'dojoType="dijit.form.Select"');
  428. }
  429. /* FTS Stemming Language */
  430. if (DB_TYPE == "pgsql") {
  431. $feed_language = $row["feed_language"];
  432. print "<hr/>";
  433. print __('Language:') . " ";
  434. print_select("feed_language", $feed_language, $this::$feed_languages,
  435. 'dojoType="dijit.form.Select"');
  436. }
  437. print "</div>";
  438. print "<div class=\"dlgSec\">".__("Update")."</div>";
  439. print "<div class=\"dlgSecCont\">";
  440. /* Update Interval */
  441. $update_interval = $row["update_interval"];
  442. print_select_hash("update_interval", $update_interval, $update_intervals,
  443. 'dojoType="dijit.form.Select"');
  444. /* Purge intl */
  445. $purge_interval = $row["purge_interval"];
  446. print "<hr/>";
  447. print __('Article purging:') . " ";
  448. print_select_hash("purge_interval", $purge_interval, $purge_intervals,
  449. 'dojoType="dijit.form.Select" ' .
  450. ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
  451. print "</div>";
  452. $auth_login = htmlspecialchars($row["auth_login"]);
  453. $auth_pass = $row["auth_pass"];
  454. if ($auth_pass_encrypted && function_exists("mcrypt_decrypt")) {
  455. require_once "crypt.php";
  456. $auth_pass = decrypt_string($auth_pass);
  457. }
  458. $auth_pass = htmlspecialchars($auth_pass);
  459. $auth_enabled = $auth_login !== '' || $auth_pass !== '';
  460. $auth_style = $auth_enabled ? '' : 'display: none';
  461. print "<div id='feedEditDlg_loginContainer' style='$auth_style'>";
  462. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  463. print "<div class=\"dlgSecCont\">";
  464. print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\"
  465. placeHolder=\"".__("Login")."\"
  466. autocomplete=\"new-password\"
  467. name=\"auth_login\" value=\"$auth_login\"><hr/>";
  468. print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  469. autocomplete=\"new-password\"
  470. placeHolder=\"".__("Password")."\"
  471. value=\"$auth_pass\">";
  472. print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\">
  473. ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')."
  474. </div>";
  475. print "</div></div>";
  476. $auth_checked = $auth_enabled ? 'checked' : '';
  477. print "<div style=\"clear : both\">
  478. <input type=\"checkbox\" $auth_checked name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedEditDlg_loginCheck\"
  479. onclick='checkboxToggleElement(this, \"feedEditDlg_loginContainer\")'>
  480. <label for=\"feedEditDlg_loginCheck\">".
  481. __('This feed requires authentication.')."</div>";
  482. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">';
  483. //print "<div class=\"dlgSec\">".__("Options")."</div>";
  484. print "<div class=\"dlgSecSimple\">";
  485. $private = $row["private"];
  486. if ($private) {
  487. $checked = "checked=\"1\"";
  488. } else {
  489. $checked = "";
  490. }
  491. print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
  492. $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
  493. $include_in_digest = $row["include_in_digest"];
  494. if ($include_in_digest) {
  495. $checked = "checked=\"1\"";
  496. } else {
  497. $checked = "";
  498. }
  499. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
  500. name=\"include_in_digest\"
  501. $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  502. $always_display_enclosures = $row["always_display_enclosures"];
  503. if ($always_display_enclosures) {
  504. $checked = "checked";
  505. } else {
  506. $checked = "";
  507. }
  508. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
  509. name=\"always_display_enclosures\"
  510. $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  511. $hide_images = $row["hide_images"];
  512. if ($hide_images) {
  513. $checked = "checked=\"1\"";
  514. } else {
  515. $checked = "";
  516. }
  517. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\"
  518. name=\"hide_images\"
  519. $checked>&nbsp;<label for=\"hide_images\">".
  520. __('Do not embed images')."</label>";
  521. $cache_images = $row["cache_images"];
  522. if ($cache_images) {
  523. $checked = "checked=\"1\"";
  524. } else {
  525. $checked = "";
  526. }
  527. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
  528. name=\"cache_images\"
  529. $checked>&nbsp;<label for=\"cache_images\">".
  530. __('Cache media')."</label>";
  531. $mark_unread_on_update = $row["mark_unread_on_update"];
  532. if ($mark_unread_on_update) {
  533. $checked = "checked";
  534. } else {
  535. $checked = "";
  536. }
  537. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"
  538. name=\"mark_unread_on_update\"
  539. $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
  540. print "</div>";
  541. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">';
  542. /* Icon */
  543. print "<div class=\"dlgSecSimple\">";
  544. print "<img class=\"feedIcon\" src=\"".Feeds::getFeedIcon($feed_id)."\">";
  545. print "<iframe name=\"icon_upload_iframe\"
  546. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  547. print "<form style='display : block' target=\"icon_upload_iframe\"
  548. enctype=\"multipart/form-data\" method=\"POST\"
  549. action=\"backend.php\">
  550. <label class=\"dijitButton\">".__("Choose file...")."
  551. <input style=\"display: none\" id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
  552. </label>
  553. <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
  554. <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
  555. <input type=\"hidden\" name=\"method\" value=\"uploadicon\">
  556. <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
  557. type=\"submit\">".__('Replace')."</button>
  558. <button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
  559. type=\"submit\">".__('Remove')."</button>
  560. </form>";
  561. print "</div>";
  562. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">';
  563. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
  564. "hook_prefs_edit_feed", $feed_id);
  565. print "</div></div>";
  566. $title = htmlspecialchars($title, ENT_QUOTES);
  567. print "<div class='dlgButtons'>
  568. <div style=\"float : left\">
  569. <button class=\"danger\" dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
  570. __('Unsubscribe')."</button>";
  571. print "</div>";
  572. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
  573. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
  574. </div>";
  575. }
  576. }
  577. function editfeeds() {
  578. global $purge_intervals;
  579. global $update_intervals;
  580. $feed_ids = $_REQUEST["ids"];
  581. print_notice("Enable the options you wish to apply using checkboxes on the right:");
  582. print "<p>";
  583. print_hidden("ids", "$feed_ids");
  584. print_hidden("op", "pref-feeds");
  585. print_hidden("method", "batchEditSave");
  586. print "<div class=\"dlgSec\">".__("Feed")."</div>";
  587. print "<div class=\"dlgSecCont\">";
  588. /* Category */
  589. if (get_pref('ENABLE_FEED_CATS')) {
  590. print __('Place in category:') . " ";
  591. print_feed_cat_select("cat_id", false,
  592. 'disabled="1" dojoType="dijit.form.Select"');
  593. $this->batch_edit_cbox("cat_id");
  594. }
  595. /* FTS Stemming Language */
  596. if (DB_TYPE == "pgsql") {
  597. print "<hr/>";
  598. print __('Language:') . " ";
  599. print_select("feed_language", "", $this::$feed_languages,
  600. 'disabled="1" dojoType="dijit.form.Select"');
  601. $this->batch_edit_cbox("feed_language");
  602. }
  603. print "</div>";
  604. print "<div class=\"dlgSec\">".__("Update")."</div>";
  605. print "<div class=\"dlgSecCont\">";
  606. /* Update Interval */
  607. print_select_hash("update_interval", "", $update_intervals,
  608. 'disabled="1" dojoType="dijit.form.Select"');
  609. $this->batch_edit_cbox("update_interval");
  610. /* Purge intl */
  611. if (FORCE_ARTICLE_PURGE == 0) {
  612. print "<br/>";
  613. print __('Article purging:') . " ";
  614. print_select_hash("purge_interval", "", $purge_intervals,
  615. 'disabled="1" dojoType="dijit.form.Select"');
  616. $this->batch_edit_cbox("purge_interval");
  617. }
  618. print "</div>";
  619. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  620. print "<div class=\"dlgSecCont\">";
  621. print "<input dojoType=\"dijit.form.TextBox\"
  622. placeHolder=\"".__("Login")."\" disabled=\"1\"
  623. autocomplete=\"new-password\"
  624. name=\"auth_login\" value=\"\">";
  625. $this->batch_edit_cbox("auth_login");
  626. print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  627. autocomplete=\"new-password\"
  628. placeHolder=\"".__("Password")."\" disabled=\"1\"
  629. value=\"\">";
  630. $this->batch_edit_cbox("auth_pass");
  631. print "</div>";
  632. print "<div class=\"dlgSec\">".__("Options")."</div>";
  633. print "<div class=\"dlgSecCont\">";
  634. print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
  635. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
  636. print "&nbsp;"; $this->batch_edit_cbox("private", "private_l");
  637. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
  638. name=\"include_in_digest\"
  639. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  640. print "&nbsp;"; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
  641. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
  642. name=\"always_display_enclosures\"
  643. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  644. print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
  645. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\"
  646. name=\"hide_images\"
  647. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"hide_images_l\"
  648. for=\"hide_images\">".
  649. __('Do not embed images')."</label>";
  650. print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
  651. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
  652. name=\"cache_images\"
  653. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
  654. for=\"cache_images\">".
  655. __('Cache media')."</label>";
  656. print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
  657. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
  658. name=\"mark_unread_on_update\"
  659. 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>";
  660. print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
  661. print "</div>";
  662. print "<div class='dlgButtons'>
  663. <button dojoType=\"dijit.form.Button\"
  664. onclick=\"return dijit.byId('feedEditDlg').execute()\">".
  665. __('Save')."</button>
  666. <button dojoType=\"dijit.form.Button\"
  667. onclick=\"return dijit.byId('feedEditDlg').hide()\">".
  668. __('Cancel')."</button>
  669. </div>";
  670. return;
  671. }
  672. function batchEditSave() {
  673. return $this->editsaveops(true);
  674. }
  675. function editSave() {
  676. return $this->editsaveops(false);
  677. }
  678. function editsaveops($batch) {
  679. $feed_title = trim($_POST["title"]);
  680. $feed_url = trim($_POST["feed_url"]);
  681. $upd_intl = (int) $_POST["update_interval"];
  682. $purge_intl = (int) $_POST["purge_interval"];
  683. $feed_id = (int) $_POST["id"]; /* editSave */
  684. $feed_ids = explode(",", $_POST["ids"]); /* batchEditSave */
  685. $cat_id = (int) $_POST["cat_id"];
  686. $auth_login = trim($_POST["auth_login"]);
  687. $auth_pass = trim($_POST["auth_pass"]);
  688. $private = checkbox_to_sql_bool($_POST["private"]);
  689. $include_in_digest = checkbox_to_sql_bool(
  690. $_POST["include_in_digest"]);
  691. $cache_images = checkbox_to_sql_bool(
  692. $_POST["cache_images"]);
  693. $hide_images = checkbox_to_sql_bool(
  694. $_POST["hide_images"]);
  695. $always_display_enclosures = checkbox_to_sql_bool(
  696. $_POST["always_display_enclosures"]);
  697. $mark_unread_on_update = checkbox_to_sql_bool(
  698. $_POST["mark_unread_on_update"]);
  699. $feed_language = trim($_POST["feed_language"]);
  700. if (!$batch) {
  701. if ($_POST["need_auth"] !== 'on') {
  702. $auth_login = '';
  703. $auth_pass = '';
  704. }
  705. $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?");
  706. $sth->execute([$feed_id]);
  707. $row = $sth->fetch();
  708. $orig_feed_url = $row["feed_url"];
  709. $reset_basic_info = $orig_feed_url != $feed_url;
  710. $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET
  711. cat_id = :cat_id,
  712. title = :title,
  713. feed_url = :feed_url,
  714. update_interval = :upd_intl,
  715. purge_interval = :purge_intl,
  716. auth_login = :auth_login,
  717. auth_pass = :auth_pass,
  718. auth_pass_encrypted = false,
  719. private = :private,
  720. cache_images = :cache_images,
  721. hide_images = :hide_images,
  722. include_in_digest = :include_in_digest,
  723. always_display_enclosures = :always_display_enclosures,
  724. mark_unread_on_update = :mark_unread_on_update,
  725. feed_language = :feed_language
  726. WHERE id = :id AND owner_uid = :uid");
  727. $sth->execute([":title" => $feed_title,
  728. ":cat_id" => $cat_id ? $cat_id : null,
  729. ":feed_url" => $feed_url,
  730. ":upd_intl" => $upd_intl,
  731. ":purge_intl" => $purge_intl,
  732. ":auth_login" => $auth_login,
  733. ":auth_pass" => $auth_pass,
  734. ":private" => (int)$private,
  735. ":cache_images" => (int)$cache_images,
  736. ":hide_images" => (int)$hide_images,
  737. ":include_in_digest" => (int)$include_in_digest,
  738. ":always_display_enclosures" => (int)$always_display_enclosures,
  739. ":mark_unread_on_update" => (int)$mark_unread_on_update,
  740. ":feed_language" => $feed_language,
  741. ":id" => $feed_id,
  742. ":uid" => $_SESSION['uid']]);
  743. if ($reset_basic_info) {
  744. RSSUtils::set_basic_feed_info($feed_id);
  745. }
  746. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
  747. "hook_prefs_save_feed", $feed_id);
  748. } else {
  749. $feed_data = array();
  750. foreach (array_keys($_POST) as $k) {
  751. if ($k != "op" && $k != "method" && $k != "ids") {
  752. $feed_data[$k] = $_POST[$k];
  753. }
  754. }
  755. $this->pdo->beginTransaction();
  756. $feed_ids_qmarks = arr_qmarks($feed_ids);
  757. foreach (array_keys($feed_data) as $k) {
  758. $qpart = "";
  759. switch ($k) {
  760. case "title":
  761. $qpart = "title = " . $this->pdo->quote($feed_title);
  762. break;
  763. case "feed_url":
  764. $qpart = "feed_url = " . $this->pdo->quote($feed_url);
  765. break;
  766. case "update_interval":
  767. $qpart = "update_interval = " . $this->pdo->quote($upd_intl);
  768. break;
  769. case "purge_interval":
  770. $qpart = "purge_interval =" . $this->pdo->quote($purge_intl);
  771. break;
  772. case "auth_login":
  773. $qpart = "auth_login = " . $this->pdo->quote($auth_login);
  774. break;
  775. case "auth_pass":
  776. $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false";
  777. break;
  778. case "private":
  779. $qpart = "private = " . $this->pdo->quote($private);
  780. break;
  781. case "include_in_digest":
  782. $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest);
  783. break;
  784. case "always_display_enclosures":
  785. $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures);
  786. break;
  787. case "mark_unread_on_update":
  788. $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update);
  789. break;
  790. case "cache_images":
  791. $qpart = "cache_images = " . $this->pdo->quote($cache_images);
  792. break;
  793. case "hide_images":
  794. $qpart = "hide_images = " . $this->pdo->quote($hide_images);
  795. break;
  796. case "cat_id":
  797. if (get_pref('ENABLE_FEED_CATS')) {
  798. if ($cat_id) {
  799. $qpart = "cat_id = " . $this->pdo->quote($cat_id);
  800. } else {
  801. $qpart = 'cat_id = NULL';
  802. }
  803. } else {
  804. $qpart = "";
  805. }
  806. break;
  807. case "feed_language":
  808. $qpart = "feed_language = " . $this->pdo->quote($feed_language);
  809. break;
  810. }
  811. if ($qpart) {
  812. $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks)
  813. AND owner_uid = ?");
  814. $sth->execute(array_merge($feed_ids, [$_SESSION['uid']]));
  815. }
  816. }
  817. $this->pdo->commit();
  818. }
  819. return;
  820. }
  821. function remove() {
  822. $ids = explode(",", $_REQUEST["ids"]);
  823. foreach ($ids as $id) {
  824. Pref_Feeds::remove_feed($id, $_SESSION["uid"]);
  825. }
  826. return;
  827. }
  828. function removeCat() {
  829. $ids = explode(",", $_REQUEST["ids"]);
  830. foreach ($ids as $id) {
  831. $this->remove_feed_category($id, $_SESSION["uid"]);
  832. }
  833. }
  834. function addCat() {
  835. $feed_cat = trim($_REQUEST["cat"]);
  836. add_feed_category($feed_cat);
  837. }
  838. function index() {
  839. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  840. print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
  841. $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors
  842. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
  843. $sth->execute([$_SESSION['uid']]);
  844. if ($row = $sth->fetch()) {
  845. $num_errors = $row["num_errors"];
  846. } else {
  847. $num_errors = 0;
  848. }
  849. if ($num_errors > 0) {
  850. $error_button = "<button dojoType=\"dijit.form.Button\"
  851. onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
  852. __("Feeds with errors") . "</button>";
  853. }
  854. $inactive_button = "<button dojoType=\"dijit.form.Button\"
  855. id=\"pref_feeds_inactive_btn\"
  856. style=\"display : none\"
  857. onclick=\"showInactiveFeeds()\">" .
  858. __("Inactive feeds") . "</button>";
  859. $feed_search = $_REQUEST["search"];
  860. if (array_key_exists("search", $_REQUEST)) {
  861. $_SESSION["prefs_feed_search"] = $feed_search;
  862. } else {
  863. $feed_search = $_SESSION["prefs_feed_search"];
  864. }
  865. print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
  866. print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar
  867. print "<div style='float : right; padding-right : 4px;'>
  868. <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
  869. value=\"$feed_search\">
  870. <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">".
  871. __('Search')."</button>
  872. </div>";
  873. print "<div dojoType=\"dijit.form.DropDownButton\">".
  874. "<span>" . __('Select')."</span>";
  875. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  876. print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
  877. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  878. print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
  879. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  880. print "</div></div>";
  881. print "<div dojoType=\"dijit.form.DropDownButton\">".
  882. "<span>" . __('Feeds')."</span>";
  883. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  884. print "<div onclick=\"quickAddFeed()\"
  885. dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
  886. print "<div onclick=\"editSelectedFeed()\"
  887. dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
  888. print "<div onclick=\"resetFeedOrder()\"
  889. dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
  890. print "<div onclick=\"batchSubscribe()\"
  891. dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
  892. print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">"
  893. .__('Unsubscribe')."</div> ";
  894. print "</div></div>";
  895. if (get_pref('ENABLE_FEED_CATS')) {
  896. print "<div dojoType=\"dijit.form.DropDownButton\">".
  897. "<span>" . __('Categories')."</span>";
  898. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  899. print "<div onclick=\"createCategory()\"
  900. dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
  901. print "<div onclick=\"resetCatOrder()\"
  902. dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
  903. print "<div onclick=\"removeSelectedCategories()\"
  904. dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>";
  905. print "</div></div>";
  906. }
  907. print $error_button;
  908. print $inactive_button;
  909. print "</div>"; # toolbar
  910. //print '</div>';
  911. print '<div dojoType="dijit.layout.ContentPane" region="center">';
  912. print "<div id=\"feedlistLoading\">
  913. <img src='images/indicator_tiny.gif'>".
  914. __("Loading, please wait...")."</div>";
  915. print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
  916. url=\"backend.php?op=pref-feeds&method=getfeedtree\">
  917. </div>
  918. <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
  919. query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
  920. childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
  921. </div>
  922. <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
  923. dndController=\"dijit.tree.dndSource\"
  924. betweenThreshold=\"5\"
  925. autoExpand='true'
  926. model=\"feedModel\" openOnClick=\"false\">
  927. <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
  928. var id = String(item.id);
  929. var bare_id = id.substr(id.indexOf(':')+1);
  930. if (id.match('FEED:')) {
  931. editFeed(bare_id);
  932. } else if (id.match('CAT:')) {
  933. editCat(bare_id, item);
  934. }
  935. </script>
  936. <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
  937. Element.hide(\"feedlistLoading\");
  938. checkInactiveFeeds();
  939. </script>
  940. </div>";
  941. # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
  942. # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
  943. # </div>";
  944. print '</div>';
  945. print '</div>';
  946. print "</div>"; # feeds pane
  947. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
  948. print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") .
  949. __("Only main settings profile can be migrated using OPML.") . "</p>";
  950. print "<iframe id=\"upload_iframe\"
  951. name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
  952. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  953. print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
  954. enctype=\"multipart/form-data\" method=\"POST\"
  955. action=\"backend.php\">
  956. <label class=\"dijitButton\">".__("Choose file...")."
  957. <input style=\"display : none\" id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
  958. </label>
  959. <input type=\"hidden\" name=\"op\" value=\"dlg\">
  960. <input type=\"hidden\" name=\"method\" value=\"importOpml\">
  961. <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
  962. __('Import my OPML') . "</button>";
  963. print "<hr>";
  964. $opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml";
  965. print "<p>" . __('Filename:') .
  966. " <input class=\"input input-text\" type=\"text\" id=\"filename\" value=\"$opml_export_filename\" />&nbsp;" .
  967. __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
  968. print "</p><button dojoType=\"dijit.form.Button\"
  969. onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
  970. __('Export OPML') . "</button></p></form>";
  971. print "<hr>";
  972. print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>";
  973. print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
  974. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
  975. __('Display published OPML URL')."</button> ";
  976. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  977. "hook_prefs_tab_section", "prefFeedsOPML");
  978. print "</div>"; # pane
  979. if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
  980. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
  981. print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.'));
  982. print "<p>";
  983. print "<button onclick='window.navigator.registerContentHandler(" .
  984. "\"application/vnd.mozilla.maybe.feed\", " .
  985. "\"" . $this->subscribe_to_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
  986. __('Click here to register this site as a feed reader.') .
  987. "</button>";
  988. print "</p>";
  989. print "</div>"; # pane
  990. }
  991. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
  992. print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>";
  993. $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
  994. "/public.php?op=rss&id=-2&view-mode=all_articles");;
  995. print "<p>";
  996. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
  997. __('Display URL')."</button> ";
  998. print "<button class=\"warning\" dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
  999. __('Clear all generated URLs')."</button> ";
  1000. print "</p>";
  1001. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  1002. "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
  1003. print "</div>"; #pane
  1004. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  1005. "hook_prefs_tab", "prefFeeds");
  1006. print "</div>"; #container
  1007. }
  1008. private function feedlist_init_cat($cat_id) {
  1009. $obj = array();
  1010. $cat_id = (int) $cat_id;
  1011. if ($cat_id > 0) {
  1012. $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true);
  1013. } else if ($cat_id == 0 || $cat_id == -2) {
  1014. $cat_unread = Feeds::getCategoryUnread($cat_id);
  1015. }
  1016. $obj['id'] = 'CAT:' . $cat_id;
  1017. $obj['items'] = array();
  1018. $obj['name'] = Feeds::getCategoryTitle($cat_id);
  1019. $obj['type'] = 'category';
  1020. $obj['unread'] = (int) $cat_unread;
  1021. $obj['bare_id'] = $cat_id;
  1022. return $obj;
  1023. }
  1024. private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
  1025. $obj = array();
  1026. $feed_id = (int) $feed_id;
  1027. if (!$title)
  1028. $title = Feeds::getFeedTitle($feed_id, false);
  1029. if ($unread === false)
  1030. $unread = getFeedUnread($feed_id, false);
  1031. $obj['id'] = 'FEED:' . $feed_id;
  1032. $obj['name'] = $title;
  1033. $obj['unread'] = (int) $unread;
  1034. $obj['type'] = 'feed';
  1035. $obj['error'] = $error;
  1036. $obj['updated'] = $updated;
  1037. $obj['icon'] = Feeds::getFeedIcon($feed_id);
  1038. $obj['bare_id'] = $feed_id;
  1039. $obj['auxcounter'] = 0;
  1040. return $obj;
  1041. }
  1042. function inactiveFeeds() {
  1043. if (DB_TYPE == "pgsql") {
  1044. $interval_qpart = "NOW() - INTERVAL '3 months'";
  1045. } else {
  1046. $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
  1047. }
  1048. $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url,
  1049. ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
  1050. FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
  1051. (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
  1052. ttrss_entries.id = ref_id AND
  1053. ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
  1054. AND ttrss_feeds.owner_uid = ? AND
  1055. ttrss_user_entries.feed_id = ttrss_feeds.id AND
  1056. ttrss_entries.id = ref_id
  1057. GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
  1058. ORDER BY last_article");
  1059. $sth->execute([$_SESSION['uid']]);
  1060. print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>";
  1061. print "<div dojoType=\"dijit.Toolbar\">";
  1062. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1063. "<span>" . __('Select')."</span>";
  1064. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1065. print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\"
  1066. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  1067. print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\"
  1068. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  1069. print "</div></div>";
  1070. print "</div>"; #toolbar
  1071. print "<div class=\"inactiveFeedHolder\">";
  1072. print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
  1073. $lnum = 1;
  1074. while ($line = $sth->fetch()) {
  1075. $feed_id = $line["id"];
  1076. $this_row_id = "id=\"FUPDD-$feed_id\"";
  1077. # class needed for selectTableRows()
  1078. print "<tr class=\"placeholder\" $this_row_id>";
  1079. # id needed for selectTableRows()
  1080. print "<td width='5%' align='center'><input
  1081. onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
  1082. type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>";
  1083. print "<td>";
  1084. print "<a class=\"visibleLink\" href=\"#\" ".
  1085. "title=\"".__("Click to edit feed")."\" ".
  1086. "onclick=\"editFeed(".$line["id"].")\">".
  1087. htmlspecialchars($line["title"])."</a>";
  1088. print "</td><td class=\"insensitive\" align='right'>";
  1089. print make_local_datetime($line['last_article'], false);
  1090. print "</td>";
  1091. print "</tr>";
  1092. ++$lnum;
  1093. }
  1094. print "</table>";
  1095. print "</div>";
  1096. print "<div class='dlgButtons'>";
  1097. print "<div style='float : left'>";
  1098. print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
  1099. .__('Unsubscribe from selected feeds')."</button> ";
  1100. print "</div>";
  1101. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
  1102. __('Close this window')."</button>";
  1103. print "</div>";
  1104. }
  1105. function feedsWithErrors() {
  1106. $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url
  1107. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
  1108. $sth->execute([$_SESSION['uid']]);
  1109. print "<div dojoType=\"dijit.Toolbar\">";
  1110. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1111. "<span>" . __('Select')."</span>";
  1112. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1113. print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\"
  1114. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  1115. print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\"
  1116. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  1117. print "</div></div>";
  1118. print "</div>"; #toolbar
  1119. print "<div class=\"inactiveFeedHolder\">";
  1120. print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
  1121. $lnum = 1;
  1122. while ($line = $sth->fetch()) {
  1123. $feed_id = $line["id"];
  1124. $this_row_id = "id=\"FERDD-$feed_id\"";
  1125. # class needed for selectTableRows()
  1126. print "<tr class=\"placeholder\" $this_row_id>";
  1127. # id needed for selectTableRows()
  1128. print "<td width='5%' align='center'><input
  1129. onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
  1130. type=\"checkbox\" id=\"FERDC-$feed_id\"></td>";
  1131. print "<td>";
  1132. print "<a class=\"visibleLink\" href=\"#\" ".
  1133. "title=\"".__("Click to edit feed")."\" ".
  1134. "onclick=\"editFeed(".$line["id"].")\">".
  1135. htmlspecialchars($line["title"])."</a>: ";
  1136. print "<span class=\"insensitive\">";
  1137. print htmlspecialchars($line["last_error"]);
  1138. print "</span>";
  1139. print "</td>";
  1140. print "</tr>";
  1141. ++$lnum;
  1142. }
  1143. print "</table>";
  1144. print "</div>";
  1145. print "<div class='dlgButtons'>";
  1146. print "<div style='float : left'>";
  1147. print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
  1148. .__('Unsubscribe from selected feeds')."</button> ";
  1149. print "</div>";
  1150. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
  1151. __('Close this window')."</button>";
  1152. print "</div>";
  1153. }
  1154. private function remove_feed_category($id, $owner_uid) {
  1155. $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories
  1156. WHERE id = ? AND owner_uid = ?");
  1157. $sth->execute([$id, $owner_uid]);
  1158. CCache::remove($id, $owner_uid, true);
  1159. }
  1160. static function remove_feed($id, $owner_uid) {
  1161. $pdo = Db::pdo();
  1162. if ($id > 0) {
  1163. $pdo->beginTransaction();
  1164. /* save starred articles in Archived feed */
  1165. /* prepare feed if necessary */
  1166. $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?
  1167. AND owner_uid = ?");
  1168. $sth->execute([$id, $owner_uid]);
  1169. if ($row = $sth->fetch()) {
  1170. $feed_url = $row["feed_url"];
  1171. $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds
  1172. WHERE feed_url = ? AND owner_uid = ?");
  1173. $sth->execute([$feed_url, $owner_uid]);
  1174. if ($row = $sth->fetch()) {
  1175. $archive_id = $row["id"];
  1176. } else {
  1177. $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
  1178. $row = $res->fetch();
  1179. $new_feed_id = (int)$row['id'] + 1;
  1180. $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds
  1181. (id, owner_uid, title, feed_url, site_url)
  1182. SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds
  1183. WHERE id = ?");
  1184. $sth->execute([$new_feed_id, $id]);
  1185. $archive_id = $new_feed_id;
  1186. }
  1187. $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL,
  1188. orig_feed_id = ? WHERE feed_id = ? AND
  1189. marked = true AND owner_uid = ?");
  1190. $sth->execute([$archive_id, $id, $owner_uid]);
  1191. /* Remove access key for the feed */
  1192. $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE
  1193. feed_id = ? AND owner_uid = ?");
  1194. $sth->execute([$id, $owner_uid]);
  1195. /* remove the feed */
  1196. $sth = $pdo->prepare("DELETE FROM ttrss_feeds
  1197. WHERE id = ? AND owner_uid = ?");
  1198. $sth->execute([$id, $owner_uid]);
  1199. }
  1200. $pdo->commit();
  1201. if (file_exists(ICONS_DIR . "/$id.ico")) {
  1202. unlink(ICONS_DIR . "/$id.ico");
  1203. }
  1204. CCache::remove($id, $owner_uid);
  1205. } else {
  1206. Labels::remove(Labels::feed_to_label_id($id), $owner_uid);
  1207. //CCache::remove($id, $owner_uid); don't think labels are cached
  1208. }
  1209. }
  1210. function batchSubscribe() {
  1211. print_hidden("op", "pref-feeds");
  1212. print_hidden("method", "batchaddfeeds");
  1213. print "<table width='100%'><tr><td>
  1214. ".__("Add one valid RSS feed per line (no feed detection is done)")."
  1215. </td><td align='right'>";
  1216. if (get_pref('ENABLE_FEED_CATS')) {
  1217. print __('Place in category:') . " ";
  1218. print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
  1219. }
  1220. print "</td></tr><tr><td colspan='2'>";
  1221. print "<textarea
  1222. style='font-size : 12px; width : 98%; height: 200px;'
  1223. placeHolder=\"".__("Feeds to subscribe, One per line")."\"
  1224. dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
  1225. print "</td></tr><tr><td colspan='2'>";
  1226. print "<div id='feedDlg_loginContainer' style='display : none'>
  1227. " .
  1228. " <input dojoType=\"dijit.form.TextBox\" name='login'\"
  1229. placeHolder=\"".__("Login")."\"
  1230. style=\"width : 10em;\"> ".
  1231. " <input
  1232. placeHolder=\"".__("Password")."\"
  1233. dojoType=\"dijit.form.TextBox\" type='password'
  1234. autocomplete=\"new-password\"
  1235. style=\"width : 10em;\" name='pass'\">".
  1236. "</div>";
  1237. print "</td></tr><tr><td colspan='2'>";
  1238. print "<div style=\"clear : both\">
  1239. <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
  1240. onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
  1241. <label for=\"feedDlg_loginCheck\">".
  1242. __('Feeds require authentication.')."</div>";
  1243. print "</form>";
  1244. print "</td></tr></table>";
  1245. print "<div class=\"dlgButtons\">
  1246. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
  1247. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
  1248. </div>";
  1249. }
  1250. function batchAddFeeds() {
  1251. $cat_id = $_REQUEST['cat'];
  1252. $feeds = explode("\n", $_REQUEST['feeds']);
  1253. $login = $_REQUEST['login'];
  1254. $pass = trim($_REQUEST['pass']);
  1255. foreach ($feeds as $feed) {
  1256. $feed = trim($feed);
  1257. if (validate_feed_url($feed)) {
  1258. $this->pdo->beginTransaction();
  1259. $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
  1260. WHERE feed_url = ? AND owner_uid = ?");
  1261. $sth->execute([$feed, $_SESSION['uid']]);
  1262. if (!$sth->fetch()) {
  1263. $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds
  1264. (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
  1265. VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)");
  1266. $sth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]);
  1267. }
  1268. $this->pdo->commit();
  1269. }
  1270. }
  1271. }
  1272. function regenOPMLKey() {
  1273. $this->update_feed_access_key('OPML:Publish',
  1274. false, $_SESSION["uid"]);
  1275. $new_link = Opml::opml_publish_url();
  1276. print json_encode(array("link" => $new_link));
  1277. }
  1278. function regenFeedKey() {
  1279. $feed_id = $_REQUEST['id'];
  1280. $is_cat = $_REQUEST['is_cat'] == "true";
  1281. $new_key = $this->update_feed_access_key($feed_id, $is_cat);
  1282. print json_encode(array("link" => $new_key));
  1283. }
  1284. private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) {
  1285. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  1286. // clear old value and generate new one
  1287. $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys
  1288. WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?");
  1289. $sth->execute([$feed_id, $is_cat, $owner_uid]);
  1290. return get_feed_access_key($feed_id, $is_cat, $owner_uid);
  1291. }
  1292. // Silent
  1293. function clearKeys() {
  1294. $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE
  1295. owner_uid = ?");
  1296. $sth->execute([$_SESSION['uid']]);
  1297. }
  1298. private function calculate_children_count($cat) {
  1299. $c = 0;
  1300. foreach ($cat['items'] as $child) {
  1301. if ($child['type'] == 'category') {
  1302. $c += $this->calculate_children_count($child);
  1303. } else {
  1304. $c += 1;
  1305. }
  1306. }
  1307. return $c;
  1308. }
  1309. function getinactivefeeds() {
  1310. if (DB_TYPE == "pgsql") {
  1311. $interval_qpart = "NOW() - INTERVAL '3 months'";
  1312. } else {
  1313. $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
  1314. }
  1315. $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE
  1316. (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
  1317. ttrss_entries.id = ref_id AND
  1318. ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
  1319. ttrss_feeds.owner_uid = ?");
  1320. $sth->execute([$_SESSION['uid']]);
  1321. if ($row = $sth->fetch()) {
  1322. print (int)$row["num_inactive"];
  1323. }
  1324. }
  1325. static function subscribe_to_feed_url() {
  1326. $url_path = get_self_url_prefix() .
  1327. "/public.php?op=subscribe&feed_url=%s";
  1328. return $url_path;
  1329. }
  1330. }