feeds.php 59 KB

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