feeds.php 53 KB

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