feeds.php 57 KB

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