feeds.php 59 KB

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