feeds.php 57 KB

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