feeds.php 58 KB

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