feeds.php 57 KB

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