feeds.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960
  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 = 0;
  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. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  477. print "<div class=\"dlgSecCont\">";
  478. $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login"));
  479. print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\"
  480. placeHolder=\"".__("Login")."\"
  481. autocomplete=\"new-password\"
  482. name=\"auth_login\" value=\"$auth_login\"><hr/>";
  483. $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass");
  484. if ($auth_pass_encrypted && function_exists("mcrypt_decrypt")) {
  485. require_once "crypt.php";
  486. $auth_pass = decrypt_string($auth_pass);
  487. }
  488. $auth_pass = htmlspecialchars($auth_pass);
  489. print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  490. autocomplete=\"new-password\"
  491. placeHolder=\"".__("Password")."\"
  492. value=\"$auth_pass\">";
  493. print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\">
  494. ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')."
  495. </div>";
  496. print "</div>";
  497. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">';
  498. //print "<div class=\"dlgSec\">".__("Options")."</div>";
  499. print "<div class=\"dlgSecSimple\">";
  500. $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private"));
  501. if ($private) {
  502. $checked = "checked=\"1\"";
  503. } else {
  504. $checked = "";
  505. }
  506. print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
  507. $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
  508. $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest"));
  509. if ($include_in_digest) {
  510. $checked = "checked=\"1\"";
  511. } else {
  512. $checked = "";
  513. }
  514. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
  515. name=\"include_in_digest\"
  516. $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  517. $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures"));
  518. if ($always_display_enclosures) {
  519. $checked = "checked";
  520. } else {
  521. $checked = "";
  522. }
  523. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
  524. name=\"always_display_enclosures\"
  525. $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  526. $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images"));
  527. if ($hide_images) {
  528. $checked = "checked=\"1\"";
  529. } else {
  530. $checked = "";
  531. }
  532. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\"
  533. name=\"hide_images\"
  534. $checked>&nbsp;<label for=\"hide_images\">".
  535. __('Do not embed images')."</label>";
  536. $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images"));
  537. if ($cache_images) {
  538. $checked = "checked=\"1\"";
  539. } else {
  540. $checked = "";
  541. }
  542. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
  543. name=\"cache_images\"
  544. $checked>&nbsp;<label for=\"cache_images\">".
  545. __('Cache media')."</label>";
  546. $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update"));
  547. if ($mark_unread_on_update) {
  548. $checked = "checked";
  549. } else {
  550. $checked = "";
  551. }
  552. print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\"
  553. name=\"mark_unread_on_update\"
  554. $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
  555. print "</div>";
  556. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">';
  557. /* Icon */
  558. print "<div class=\"dlgSecSimple\">";
  559. print "<iframe name=\"icon_upload_iframe\"
  560. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  561. print "<form style='display : block' target=\"icon_upload_iframe\"
  562. enctype=\"multipart/form-data\" method=\"POST\"
  563. action=\"backend.php\">
  564. <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
  565. <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
  566. <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
  567. <input type=\"hidden\" name=\"method\" value=\"uploadicon\"><p>
  568. <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
  569. type=\"submit\">".__('Replace')."</button>
  570. <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
  571. type=\"submit\">".__('Remove')."</button>
  572. </form>";
  573. print "</div>";
  574. print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">';
  575. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
  576. "hook_prefs_edit_feed", $feed_id);
  577. print "</div></div>";
  578. $title = htmlspecialchars($title, ENT_QUOTES);
  579. print "<div class='dlgButtons'>
  580. <div style=\"float : left\">
  581. <button class=\"danger\" dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
  582. __('Unsubscribe')."</button>";
  583. print "</div>";
  584. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
  585. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
  586. </div>";
  587. return;
  588. }
  589. function editfeeds() {
  590. global $purge_intervals;
  591. global $update_intervals;
  592. $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]);
  593. print_notice("Enable the options you wish to apply using checkboxes on the right:");
  594. print "<p>";
  595. print_hidden("ids", "$feed_ids");
  596. print_hidden("op", "pref-feeds");
  597. print_hidden("method", "batchEditSave");
  598. print "<div class=\"dlgSec\">".__("Feed")."</div>";
  599. print "<div class=\"dlgSecCont\">";
  600. /* Category */
  601. if (get_pref('ENABLE_FEED_CATS')) {
  602. print __('Place in category:') . " ";
  603. print_feed_cat_select("cat_id", false,
  604. 'disabled="1" dojoType="dijit.form.Select"');
  605. $this->batch_edit_cbox("cat_id");
  606. }
  607. /* FTS Stemming Language */
  608. if (DB_TYPE == "pgsql") {
  609. print "<hr/>";
  610. print __('Language:') . " ";
  611. print_select("feed_language", "", $this::$feed_languages,
  612. 'disabled="1" dojoType="dijit.form.Select"');
  613. $this->batch_edit_cbox("feed_language");
  614. }
  615. print "</div>";
  616. print "<div class=\"dlgSec\">".__("Update")."</div>";
  617. print "<div class=\"dlgSecCont\">";
  618. /* Update Interval */
  619. print_select_hash("update_interval", "", $update_intervals,
  620. 'disabled="1" dojoType="dijit.form.Select"');
  621. $this->batch_edit_cbox("update_interval");
  622. /* Purge intl */
  623. if (FORCE_ARTICLE_PURGE == 0) {
  624. print "<br/>";
  625. print __('Article purging:') . " ";
  626. print_select_hash("purge_interval", "", $purge_intervals,
  627. 'disabled="1" dojoType="dijit.form.Select"');
  628. $this->batch_edit_cbox("purge_interval");
  629. }
  630. print "</div>";
  631. print "<div class=\"dlgSec\">".__("Authentication")."</div>";
  632. print "<div class=\"dlgSecCont\">";
  633. print "<input dojoType=\"dijit.form.TextBox\"
  634. placeHolder=\"".__("Login")."\" disabled=\"1\"
  635. autocomplete=\"new-password\"
  636. name=\"auth_login\" value=\"\">";
  637. $this->batch_edit_cbox("auth_login");
  638. print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
  639. autocomplete=\"new-password\"
  640. placeHolder=\"".__("Password")."\" disabled=\"1\"
  641. value=\"\">";
  642. $this->batch_edit_cbox("auth_pass");
  643. print "</div>";
  644. print "<div class=\"dlgSec\">".__("Options")."</div>";
  645. print "<div class=\"dlgSecCont\">";
  646. print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
  647. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
  648. print "&nbsp;"; $this->batch_edit_cbox("private", "private_l");
  649. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
  650. name=\"include_in_digest\"
  651. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
  652. print "&nbsp;"; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
  653. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
  654. name=\"always_display_enclosures\"
  655. dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
  656. print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
  657. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\"
  658. name=\"hide_images\"
  659. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"hide_images_l\"
  660. for=\"hide_images\">".
  661. __('Do not embed images')."</label>";
  662. print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
  663. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
  664. name=\"cache_images\"
  665. dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
  666. for=\"cache_images\">".
  667. __('Cache media')."</label>";
  668. print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
  669. print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
  670. name=\"mark_unread_on_update\"
  671. 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>";
  672. print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
  673. print "</div>";
  674. print "<div class='dlgButtons'>
  675. <button dojoType=\"dijit.form.Button\"
  676. onclick=\"return dijit.byId('feedEditDlg').execute()\">".
  677. __('Save')."</button>
  678. <button dojoType=\"dijit.form.Button\"
  679. onclick=\"return dijit.byId('feedEditDlg').hide()\">".
  680. __('Cancel')."</button>
  681. </div>";
  682. return;
  683. }
  684. function batchEditSave() {
  685. return $this->editsaveops(true);
  686. }
  687. function editSave() {
  688. return $this->editsaveops(false);
  689. }
  690. function editsaveops($batch) {
  691. $feed_title = $this->dbh->escape_string(trim($_POST["title"]));
  692. $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"]));
  693. $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]);
  694. $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]);
  695. $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */
  696. $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */
  697. $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]);
  698. $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
  699. $auth_pass = trim($_POST["auth_pass"]);
  700. $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"]));
  701. $include_in_digest = checkbox_to_sql_bool(
  702. $this->dbh->escape_string($_POST["include_in_digest"]));
  703. $cache_images = checkbox_to_sql_bool(
  704. $this->dbh->escape_string($_POST["cache_images"]));
  705. $hide_images = checkbox_to_sql_bool(
  706. $this->dbh->escape_string($_POST["hide_images"]));
  707. $always_display_enclosures = checkbox_to_sql_bool(
  708. $this->dbh->escape_string($_POST["always_display_enclosures"]));
  709. $mark_unread_on_update = checkbox_to_sql_bool(
  710. $this->dbh->escape_string($_POST["mark_unread_on_update"]));
  711. $feed_language = $this->dbh->escape_string(trim($_POST["feed_language"]));
  712. $auth_pass_encrypted = 'false';
  713. $auth_pass = $this->dbh->escape_string($auth_pass);
  714. if (get_pref('ENABLE_FEED_CATS')) {
  715. if ($cat_id && $cat_id != 0) {
  716. $category_qpart = "cat_id = '$cat_id',";
  717. $category_qpart_nocomma = "cat_id = '$cat_id'";
  718. } else {
  719. $category_qpart = 'cat_id = NULL,';
  720. $category_qpart_nocomma = 'cat_id = NULL';
  721. }
  722. } else {
  723. $category_qpart = "";
  724. $category_qpart_nocomma = "";
  725. }
  726. if (!$batch) {
  727. $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = " . $feed_id);
  728. $orig_feed_url = db_fetch_result($result, 0, "feed_url");
  729. $reset_basic_info = $orig_feed_url != $feed_link;
  730. $this->dbh->query("UPDATE ttrss_feeds SET
  731. $category_qpart
  732. title = '$feed_title', feed_url = '$feed_link',
  733. update_interval = '$upd_intl',
  734. purge_interval = '$purge_intl',
  735. auth_login = '$auth_login',
  736. auth_pass = '$auth_pass',
  737. auth_pass_encrypted = $auth_pass_encrypted,
  738. private = $private,
  739. cache_images = $cache_images,
  740. hide_images = $hide_images,
  741. include_in_digest = $include_in_digest,
  742. always_display_enclosures = $always_display_enclosures,
  743. mark_unread_on_update = $mark_unread_on_update,
  744. feed_language = '$feed_language'
  745. WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
  746. if ($reset_basic_info) {
  747. RSSUtils::set_basic_feed_info($feed_id);
  748. }
  749. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
  750. "hook_prefs_save_feed", $feed_id);
  751. } else {
  752. $feed_data = array();
  753. foreach (array_keys($_POST) as $k) {
  754. if ($k != "op" && $k != "method" && $k != "ids") {
  755. $feed_data[$k] = $_POST[$k];
  756. }
  757. }
  758. $this->dbh->query("BEGIN");
  759. foreach (array_keys($feed_data) as $k) {
  760. $qpart = "";
  761. switch ($k) {
  762. case "title":
  763. $qpart = "title = '$feed_title'";
  764. break;
  765. case "feed_url":
  766. $qpart = "feed_url = '$feed_link'";
  767. break;
  768. case "update_interval":
  769. $qpart = "update_interval = '$upd_intl'";
  770. break;
  771. case "purge_interval":
  772. $qpart = "purge_interval = '$purge_intl'";
  773. break;
  774. case "auth_login":
  775. $qpart = "auth_login = '$auth_login'";
  776. break;
  777. case "auth_pass":
  778. $qpart = "auth_pass = '$auth_pass' AND
  779. auth_pass_encrypted = $auth_pass_encrypted";
  780. break;
  781. case "private":
  782. $qpart = "private = $private";
  783. break;
  784. case "include_in_digest":
  785. $qpart = "include_in_digest = $include_in_digest";
  786. break;
  787. case "always_display_enclosures":
  788. $qpart = "always_display_enclosures = $always_display_enclosures";
  789. break;
  790. case "mark_unread_on_update":
  791. $qpart = "mark_unread_on_update = $mark_unread_on_update";
  792. break;
  793. case "cache_images":
  794. $qpart = "cache_images = $cache_images";
  795. break;
  796. case "hide_images":
  797. $qpart = "hide_images = $hide_images";
  798. break;
  799. case "cat_id":
  800. $qpart = $category_qpart_nocomma;
  801. break;
  802. case "feed_language":
  803. $qpart = "feed_language = '$feed_language'";
  804. break;
  805. }
  806. if ($qpart) {
  807. $this->dbh->query(
  808. "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
  809. AND owner_uid = " . $_SESSION["uid"]);
  810. print "<br/>";
  811. }
  812. }
  813. $this->dbh->query("COMMIT");
  814. }
  815. return;
  816. }
  817. function remove() {
  818. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  819. foreach ($ids as $id) {
  820. Pref_Feeds::remove_feed($id, $_SESSION["uid"]);
  821. }
  822. return;
  823. }
  824. function clear() {
  825. $id = $this->dbh->escape_string($_REQUEST["id"]);
  826. $this->clear_feed_articles($id);
  827. }
  828. function rescore() {
  829. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  830. foreach ($ids as $id) {
  831. $filters = load_filters($id, $_SESSION["uid"], 6);
  832. $result = $this->dbh->query("SELECT
  833. title, content, link, ref_id, author,".
  834. SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
  835. FROM
  836. ttrss_user_entries, ttrss_entries
  837. WHERE ref_id = id AND feed_id = '$id' AND
  838. owner_uid = " .$_SESSION['uid']."
  839. ");
  840. $scores = array();
  841. while ($line = $this->dbh->fetch_assoc($result)) {
  842. $tags = Article::get_article_tags($line["ref_id"]);
  843. $article_filters = RSSUtils::get_article_filters($filters, $line['title'],
  844. $line['content'], $line['link'], strtotime($line['updated']),
  845. $line['author'], $tags);
  846. $new_score = RSSUtils::calculate_article_score($article_filters);
  847. if (!$scores[$new_score]) $scores[$new_score] = array();
  848. array_push($scores[$new_score], $line['ref_id']);
  849. }
  850. foreach (array_keys($scores) as $s) {
  851. if ($s > 1000) {
  852. $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
  853. marked = true WHERE
  854. ref_id IN (" . join(',', $scores[$s]) . ")");
  855. } else if ($s < -500) {
  856. $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
  857. unread = false WHERE
  858. ref_id IN (" . join(',', $scores[$s]) . ")");
  859. } else {
  860. $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
  861. ref_id IN (" . join(',', $scores[$s]) . ")");
  862. }
  863. }
  864. }
  865. print __("All done.");
  866. }
  867. function rescoreAll() {
  868. $result = $this->dbh->query(
  869. "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
  870. while ($feed_line = $this->dbh->fetch_assoc($result)) {
  871. $id = $feed_line["id"];
  872. $filters = load_filters($id, $_SESSION["uid"], 6);
  873. $tmp_result = $this->dbh->query("SELECT
  874. title, content, link, ref_id, author,".
  875. SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
  876. FROM
  877. ttrss_user_entries, ttrss_entries
  878. WHERE ref_id = id AND feed_id = '$id' AND
  879. owner_uid = " .$_SESSION['uid']."
  880. ");
  881. $scores = array();
  882. while ($line = $this->dbh->fetch_assoc($tmp_result)) {
  883. $tags = Article::get_article_tags($line["ref_id"]);
  884. $article_filters = RSSUtils::get_article_filters($filters, $line['title'],
  885. $line['content'], $line['link'], strtotime($line['updated']),
  886. $line['author'], $tags);
  887. $new_score = RSSUtils::calculate_article_score($article_filters);
  888. if (!$scores[$new_score]) $scores[$new_score] = array();
  889. array_push($scores[$new_score], $line['ref_id']);
  890. }
  891. foreach (array_keys($scores) as $s) {
  892. if ($s > 1000) {
  893. $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
  894. marked = true WHERE
  895. ref_id IN (" . join(',', $scores[$s]) . ")");
  896. } else {
  897. $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
  898. ref_id IN (" . join(',', $scores[$s]) . ")");
  899. }
  900. }
  901. }
  902. print __("All done.");
  903. }
  904. function categorize() {
  905. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  906. $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
  907. if ($cat_id == 0) {
  908. $cat_id_qpart = 'NULL';
  909. } else {
  910. $cat_id_qpart = "'$cat_id'";
  911. }
  912. $this->dbh->query("BEGIN");
  913. foreach ($ids as $id) {
  914. $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
  915. WHERE id = '$id'
  916. AND owner_uid = " . $_SESSION["uid"]);
  917. }
  918. $this->dbh->query("COMMIT");
  919. }
  920. function removeCat() {
  921. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  922. foreach ($ids as $id) {
  923. $this->remove_feed_category($id, $_SESSION["uid"]);
  924. }
  925. }
  926. function addCat() {
  927. $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"]));
  928. add_feed_category($feed_cat);
  929. }
  930. function index() {
  931. print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
  932. print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
  933. $result = $this->dbh->query("SELECT COUNT(id) AS num_errors
  934. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  935. $num_errors = $this->dbh->fetch_result($result, 0, "num_errors");
  936. if ($num_errors > 0) {
  937. $error_button = "<button dojoType=\"dijit.form.Button\"
  938. onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" .
  939. __("Feeds with errors") . "</button>";
  940. }
  941. $inactive_button = "<button dojoType=\"dijit.form.Button\"
  942. id=\"pref_feeds_inactive_btn\"
  943. style=\"display : none\"
  944. onclick=\"showInactiveFeeds()\">" .
  945. __("Inactive feeds") . "</button>";
  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. autoExpand='true'
  1025. model=\"feedModel\" openOnClick=\"false\">
  1026. <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
  1027. var id = String(item.id);
  1028. var bare_id = id.substr(id.indexOf(':')+1);
  1029. if (id.match('FEED:')) {
  1030. editFeed(bare_id);
  1031. } else if (id.match('CAT:')) {
  1032. editCat(bare_id, item);
  1033. }
  1034. </script>
  1035. <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
  1036. Element.hide(\"feedlistLoading\");
  1037. checkInactiveFeeds();
  1038. </script>
  1039. </div>";
  1040. # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
  1041. # ".__('<b>Hint:</b> you can drag feeds and categories around.')."
  1042. # </div>";
  1043. print '</div>';
  1044. print '</div>';
  1045. print "</div>"; # feeds pane
  1046. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
  1047. print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") .
  1048. __("Only main settings profile can be migrated using OPML.") . "</p>";
  1049. print "<iframe id=\"upload_iframe\"
  1050. name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
  1051. style=\"width: 400px; height: 100px; display: none;\"></iframe>";
  1052. print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
  1053. enctype=\"multipart/form-data\" method=\"POST\"
  1054. action=\"backend.php\">
  1055. <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
  1056. <input type=\"hidden\" name=\"op\" value=\"dlg\">
  1057. <input type=\"hidden\" name=\"method\" value=\"importOpml\">
  1058. <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
  1059. __('Import my OPML') . "</button>";
  1060. print "<hr>";
  1061. $opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml";
  1062. print "<p>" . __('Filename:') .
  1063. " <input type=\"text\" id=\"filename\" value=\"$opml_export_filename\" />&nbsp;" .
  1064. __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
  1065. print "</p><button dojoType=\"dijit.form.Button\"
  1066. onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
  1067. __('Export OPML') . "</button></p></form>";
  1068. print "<hr>";
  1069. print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>";
  1070. print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
  1071. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
  1072. __('Display published OPML URL')."</button> ";
  1073. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  1074. "hook_prefs_tab_section", "prefFeedsOPML");
  1075. print "</div>"; # pane
  1076. if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
  1077. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
  1078. print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.'));
  1079. print "<p>";
  1080. print "<button onclick='window.navigator.registerContentHandler(" .
  1081. "\"application/vnd.mozilla.maybe.feed\", " .
  1082. "\"" . $this->subscribe_to_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
  1083. __('Click here to register this site as a feed reader.') .
  1084. "</button>";
  1085. print "</p>";
  1086. print "</div>"; # pane
  1087. }
  1088. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
  1089. print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>";
  1090. $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
  1091. "/public.php?op=rss&id=-2&view-mode=all_articles");;
  1092. print "<p>";
  1093. print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
  1094. __('Display URL')."</button> ";
  1095. print "<button class=\"warning\" dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
  1096. __('Clear all generated URLs')."</button> ";
  1097. print "</p>";
  1098. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
  1099. "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
  1100. print "</div>"; #pane
  1101. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  1102. "hook_prefs_tab", "prefFeeds");
  1103. print "</div>"; #container
  1104. }
  1105. private function feedlist_init_cat($cat_id) {
  1106. $obj = array();
  1107. $cat_id = (int) $cat_id;
  1108. if ($cat_id > 0) {
  1109. $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true);
  1110. } else if ($cat_id == 0 || $cat_id == -2) {
  1111. $cat_unread = Feeds::getCategoryUnread($cat_id);
  1112. }
  1113. $obj['id'] = 'CAT:' . $cat_id;
  1114. $obj['items'] = array();
  1115. $obj['name'] = Feeds::getCategoryTitle($cat_id);
  1116. $obj['type'] = 'category';
  1117. $obj['unread'] = (int) $cat_unread;
  1118. $obj['bare_id'] = $cat_id;
  1119. return $obj;
  1120. }
  1121. private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
  1122. $obj = array();
  1123. $feed_id = (int) $feed_id;
  1124. if (!$title)
  1125. $title = Feeds::getFeedTitle($feed_id, false);
  1126. if ($unread === false)
  1127. $unread = getFeedUnread($feed_id, false);
  1128. $obj['id'] = 'FEED:' . $feed_id;
  1129. $obj['name'] = $title;
  1130. $obj['unread'] = (int) $unread;
  1131. $obj['type'] = 'feed';
  1132. $obj['error'] = $error;
  1133. $obj['updated'] = $updated;
  1134. $obj['icon'] = Feeds::getFeedIcon($feed_id);
  1135. $obj['bare_id'] = $feed_id;
  1136. $obj['auxcounter'] = 0;
  1137. return $obj;
  1138. }
  1139. function inactiveFeeds() {
  1140. if (DB_TYPE == "pgsql") {
  1141. $interval_qpart = "NOW() - INTERVAL '3 months'";
  1142. } else {
  1143. $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
  1144. }
  1145. $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url,
  1146. ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
  1147. FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
  1148. (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
  1149. ttrss_entries.id = ref_id AND
  1150. ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
  1151. AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND
  1152. ttrss_user_entries.feed_id = ttrss_feeds.id AND
  1153. ttrss_entries.id = ref_id
  1154. GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
  1155. ORDER BY last_article");
  1156. print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>";
  1157. print "<div dojoType=\"dijit.Toolbar\">";
  1158. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1159. "<span>" . __('Select')."</span>";
  1160. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1161. print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\"
  1162. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  1163. print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\"
  1164. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  1165. print "</div></div>";
  1166. print "</div>"; #toolbar
  1167. print "<div class=\"inactiveFeedHolder\">";
  1168. print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
  1169. $lnum = 1;
  1170. while ($line = $this->dbh->fetch_assoc($result)) {
  1171. $feed_id = $line["id"];
  1172. $this_row_id = "id=\"FUPDD-$feed_id\"";
  1173. # class needed for selectTableRows()
  1174. print "<tr class=\"placeholder\" $this_row_id>";
  1175. # id needed for selectTableRows()
  1176. print "<td width='5%' align='center'><input
  1177. onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
  1178. type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>";
  1179. print "<td>";
  1180. print "<a class=\"visibleLink\" href=\"#\" ".
  1181. "title=\"".__("Click to edit feed")."\" ".
  1182. "onclick=\"editFeed(".$line["id"].")\">".
  1183. htmlspecialchars($line["title"])."</a>";
  1184. print "</td><td class=\"insensitive\" align='right'>";
  1185. print make_local_datetime($line['last_article'], false);
  1186. print "</td>";
  1187. print "</tr>";
  1188. ++$lnum;
  1189. }
  1190. print "</table>";
  1191. print "</div>";
  1192. print "<div class='dlgButtons'>";
  1193. print "<div style='float : left'>";
  1194. print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
  1195. .__('Unsubscribe from selected feeds')."</button> ";
  1196. print "</div>";
  1197. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
  1198. __('Close this window')."</button>";
  1199. print "</div>";
  1200. }
  1201. function feedsWithErrors() {
  1202. $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url
  1203. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  1204. print "<div dojoType=\"dijit.Toolbar\">";
  1205. print "<div dojoType=\"dijit.form.DropDownButton\">".
  1206. "<span>" . __('Select')."</span>";
  1207. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  1208. print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\"
  1209. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  1210. print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\"
  1211. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  1212. print "</div></div>";
  1213. print "</div>"; #toolbar
  1214. print "<div class=\"inactiveFeedHolder\">";
  1215. print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
  1216. $lnum = 1;
  1217. while ($line = $this->dbh->fetch_assoc($result)) {
  1218. $feed_id = $line["id"];
  1219. $this_row_id = "id=\"FERDD-$feed_id\"";
  1220. # class needed for selectTableRows()
  1221. print "<tr class=\"placeholder\" $this_row_id>";
  1222. # id needed for selectTableRows()
  1223. print "<td width='5%' align='center'><input
  1224. onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
  1225. type=\"checkbox\" id=\"FERDC-$feed_id\"></td>";
  1226. print "<td>";
  1227. print "<a class=\"visibleLink\" href=\"#\" ".
  1228. "title=\"".__("Click to edit feed")."\" ".
  1229. "onclick=\"editFeed(".$line["id"].")\">".
  1230. htmlspecialchars($line["title"])."</a>: ";
  1231. print "<span class=\"insensitive\">";
  1232. print htmlspecialchars($line["last_error"]);
  1233. print "</span>";
  1234. print "</td>";
  1235. print "</tr>";
  1236. ++$lnum;
  1237. }
  1238. print "</table>";
  1239. print "</div>";
  1240. print "<div class='dlgButtons'>";
  1241. print "<div style='float : left'>";
  1242. print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
  1243. .__('Unsubscribe from selected feeds')."</button> ";
  1244. print "</div>";
  1245. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
  1246. __('Close this window')."</button>";
  1247. print "</div>";
  1248. }
  1249. /**
  1250. * Purge a feed contents, marked articles excepted.
  1251. *
  1252. * @param mixed $link The database connection.
  1253. * @param integer $id The id of the feed to purge.
  1254. * @return void
  1255. */
  1256. private function clear_feed_articles($id) {
  1257. if ($id != 0) {
  1258. $result = $this->dbh->query("DELETE FROM ttrss_user_entries
  1259. WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
  1260. } else {
  1261. $result = $this->dbh->query("DELETE FROM ttrss_user_entries
  1262. WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
  1263. }
  1264. $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE
  1265. (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
  1266. CCache::update($id, $_SESSION['uid']);
  1267. } // function clear_feed_articles
  1268. private function remove_feed_category($id, $owner_uid) {
  1269. $this->dbh->query("DELETE FROM ttrss_feed_categories
  1270. WHERE id = '$id' AND owner_uid = $owner_uid");
  1271. CCache::remove($id, $owner_uid, true);
  1272. }
  1273. static function remove_feed($id, $owner_uid) {
  1274. if ($id > 0) {
  1275. /* save starred articles in Archived feed */
  1276. db_query("BEGIN");
  1277. /* prepare feed if necessary */
  1278. $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id
  1279. AND owner_uid = $owner_uid");
  1280. $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
  1281. $result = db_query("SELECT id FROM ttrss_archived_feeds
  1282. WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
  1283. if (db_num_rows($result) == 0) {
  1284. $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
  1285. $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
  1286. db_query("INSERT INTO ttrss_archived_feeds
  1287. (id, owner_uid, title, feed_url, site_url)
  1288. SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
  1289. WHERE id = '$id'");
  1290. $archive_id = $new_feed_id;
  1291. } else {
  1292. $archive_id = db_fetch_result($result, 0, "id");
  1293. }
  1294. db_query("UPDATE ttrss_user_entries SET feed_id = NULL,
  1295. orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND
  1296. marked = true AND owner_uid = $owner_uid");
  1297. /* Remove access key for the feed */
  1298. db_query("DELETE FROM ttrss_access_keys WHERE
  1299. feed_id = '$id' AND owner_uid = $owner_uid");
  1300. /* remove the feed */
  1301. db_query("DELETE FROM ttrss_feeds
  1302. WHERE id = '$id' AND owner_uid = $owner_uid");
  1303. db_query("COMMIT");
  1304. if (file_exists(ICONS_DIR . "/$id.ico")) {
  1305. unlink(ICONS_DIR . "/$id.ico");
  1306. }
  1307. CCache::remove($id, $owner_uid);
  1308. } else {
  1309. Labels::remove(Labels::feed_to_label_id($id), $owner_uid);
  1310. //CCache::remove($id, $owner_uid); don't think labels are cached
  1311. }
  1312. }
  1313. function batchSubscribe() {
  1314. print_hidden("op", "pref-feeds");
  1315. print_hidden("method", "batchaddfeeds");
  1316. print "<table width='100%'><tr><td>
  1317. ".__("Add one valid RSS feed per line (no feed detection is done)")."
  1318. </td><td align='right'>";
  1319. if (get_pref('ENABLE_FEED_CATS')) {
  1320. print __('Place in category:') . " ";
  1321. print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
  1322. }
  1323. print "</td></tr><tr><td colspan='2'>";
  1324. print "<textarea
  1325. style='font-size : 12px; width : 98%; height: 200px;'
  1326. placeHolder=\"".__("Feeds to subscribe, One per line")."\"
  1327. dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
  1328. print "</td></tr><tr><td colspan='2'>";
  1329. print "<div id='feedDlg_loginContainer' style='display : none'>
  1330. " .
  1331. " <input dojoType=\"dijit.form.TextBox\" name='login'\"
  1332. placeHolder=\"".__("Login")."\"
  1333. style=\"width : 10em;\"> ".
  1334. " <input
  1335. placeHolder=\"".__("Password")."\"
  1336. dojoType=\"dijit.form.TextBox\" type='password'
  1337. autocomplete=\"new-password\"
  1338. style=\"width : 10em;\" name='pass'\">".
  1339. "</div>";
  1340. print "</td></tr><tr><td colspan='2'>";
  1341. print "<div style=\"clear : both\">
  1342. <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
  1343. onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
  1344. <label for=\"feedDlg_loginCheck\">".
  1345. __('Feeds require authentication.')."</div>";
  1346. print "</form>";
  1347. print "</td></tr></table>";
  1348. print "<div class=\"dlgButtons\">
  1349. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
  1350. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
  1351. </div>";
  1352. }
  1353. function batchAddFeeds() {
  1354. $cat_id = $this->dbh->escape_string($_REQUEST['cat']);
  1355. $feeds = explode("\n", $_REQUEST['feeds']);
  1356. $login = $this->dbh->escape_string($_REQUEST['login']);
  1357. $pass = trim($_REQUEST['pass']);
  1358. foreach ($feeds as $feed) {
  1359. $feed = $this->dbh->escape_string(trim($feed));
  1360. if (validate_feed_url($feed)) {
  1361. $this->dbh->query("BEGIN");
  1362. if ($cat_id == "0" || !$cat_id) {
  1363. $cat_qpart = "NULL";
  1364. } else {
  1365. $cat_qpart = "'$cat_id'";
  1366. }
  1367. $result = $this->dbh->query(
  1368. "SELECT id FROM ttrss_feeds
  1369. WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
  1370. $auth_pass_encrypted = 'false';
  1371. $pass = $this->dbh->escape_string($pass);
  1372. if ($this->dbh->num_rows($result) == 0) {
  1373. $result = $this->dbh->query(
  1374. "INSERT INTO ttrss_feeds
  1375. (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
  1376. VALUES ('".$_SESSION["uid"]."', '$feed',
  1377. '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)");
  1378. }
  1379. $this->dbh->query("COMMIT");
  1380. }
  1381. }
  1382. }
  1383. function regenOPMLKey() {
  1384. $this->update_feed_access_key('OPML:Publish',
  1385. false, $_SESSION["uid"]);
  1386. $new_link = Opml::opml_publish_url();
  1387. print json_encode(array("link" => $new_link));
  1388. }
  1389. function regenFeedKey() {
  1390. $feed_id = $this->dbh->escape_string($_REQUEST['id']);
  1391. $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true";
  1392. $new_key = $this->update_feed_access_key($feed_id, $is_cat);
  1393. print json_encode(array("link" => $new_key));
  1394. }
  1395. private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) {
  1396. if (!$owner_uid) $owner_uid = $_SESSION["uid"];
  1397. $sql_is_cat = bool_to_sql_bool($is_cat);
  1398. $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys
  1399. WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
  1400. AND owner_uid = " . $owner_uid);
  1401. if ($this->dbh->num_rows($result) == 1) {
  1402. $key = $this->dbh->escape_string(uniqid_short());
  1403. $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key'
  1404. WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
  1405. AND owner_uid = " . $owner_uid);
  1406. return $key;
  1407. } else {
  1408. return get_feed_access_key($feed_id, $is_cat, $owner_uid);
  1409. }
  1410. }
  1411. // Silent
  1412. function clearKeys() {
  1413. $this->dbh->query("DELETE FROM ttrss_access_keys WHERE
  1414. owner_uid = " . $_SESSION["uid"]);
  1415. }
  1416. private function calculate_children_count($cat) {
  1417. $c = 0;
  1418. foreach ($cat['items'] as $child) {
  1419. if ($child['type'] == 'category') {
  1420. $c += $this->calculate_children_count($child);
  1421. } else {
  1422. $c += 1;
  1423. }
  1424. }
  1425. return $c;
  1426. }
  1427. function getinactivefeeds() {
  1428. if (DB_TYPE == "pgsql") {
  1429. $interval_qpart = "NOW() - INTERVAL '3 months'";
  1430. } else {
  1431. $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
  1432. }
  1433. $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
  1434. (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
  1435. ttrss_entries.id = ref_id AND
  1436. ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
  1437. ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
  1438. print (int) $this->dbh->fetch_result($result, 0, "num_inactive");
  1439. }
  1440. static function subscribe_to_feed_url() {
  1441. $url_path = get_self_url_prefix() .
  1442. "/public.php?op=subscribe&feed_url=%s";
  1443. return $url_path;
  1444. }
  1445. }