feeds.php 57 KB

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