feeds.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. <?php
  2. class Feeds extends Handler_Protected {
  3. function csrf_ignore($method) {
  4. $csrf_ignored = array("index");
  5. return array_search($method, $csrf_ignored) !== false;
  6. }
  7. private function format_headline_subtoolbar($feed_site_url, $feed_title,
  8. $feed_id, $is_cat, $search, $match_on,
  9. $search_mode, $view_mode, $error) {
  10. $page_prev_link = "viewFeedGoPage(-1)";
  11. $page_next_link = "viewFeedGoPage(1)";
  12. $page_first_link = "viewFeedGoPage(0)";
  13. $catchup_page_link = "catchupPage()";
  14. $catchup_feed_link = "catchupCurrentFeed()";
  15. $catchup_sel_link = "catchupSelection()";
  16. $archive_sel_link = "archiveSelection()";
  17. $delete_sel_link = "deleteSelection()";
  18. $sel_all_link = "selectArticles('all')";
  19. $sel_unread_link = "selectArticles('unread')";
  20. $sel_none_link = "selectArticles('none')";
  21. $sel_inv_link = "selectArticles('invert')";
  22. $tog_unread_link = "selectionToggleUnread()";
  23. $tog_marked_link = "selectionToggleMarked()";
  24. $tog_published_link = "selectionTogglePublished()";
  25. if ($is_cat) $cat_q = "&is_cat=$is_cat";
  26. if ($search) {
  27. $search_q = "&q=$search&m=$match_on&smode=$search_mode";
  28. } else {
  29. $search_q = "";
  30. }
  31. $rss_link = htmlspecialchars(get_self_url_prefix() .
  32. "/public.php?op=rss&id=$feed_id$cat_q$search_q");
  33. // right part
  34. $reply .= "<span class='r'>";
  35. if ($feed_site_url) {
  36. $target = "target=\"_blank\"";
  37. $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
  38. truncate_string($feed_title,30)."</a>";
  39. if ($error) {
  40. $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
  41. }
  42. } else {
  43. $reply .= $feed_title;
  44. }
  45. $reply .= "
  46. <a href=\"#\"
  47. title=\"".__("View as RSS feed")."\"
  48. onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
  49. <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
  50. $reply .= "</span>";
  51. // left part
  52. $reply .= __('Select:')."
  53. <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
  54. <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
  55. <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
  56. <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
  57. $reply .= " ";
  58. $reply .= "<select dojoType=\"dijit.form.Select\"
  59. onchange=\"headlineActionsChange(this)\">";
  60. $reply .= "<option value=\"false\">".__('Actions...')."</option>";
  61. $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
  62. $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
  63. <option value=\"$tog_marked_link\">".__('Starred')."</option>
  64. <option value=\"$tog_published_link\">".__('Published')."</option>";
  65. $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
  66. $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
  67. if ($feed_id != "0") {
  68. $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
  69. } else {
  70. $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
  71. $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
  72. }
  73. $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
  74. "</option>";
  75. $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
  76. $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
  77. $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
  78. $reply .= "</select>";
  79. //$reply .= "</div>";
  80. //$reply .= "</h2";
  81. return $reply;
  82. }
  83. private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
  84. $next_unread_feed, $offset, $vgr_last_feed = false,
  85. $override_order = false, $include_children = false) {
  86. global $plugins;
  87. $disable_cache = false;
  88. $reply = array();
  89. $timing_info = getmicrotime();
  90. $topmost_article_ids = array();
  91. if (!$offset) $offset = 0;
  92. if ($method == "undefined") $method = "";
  93. $method_split = explode(":", $method);
  94. if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
  95. include "rssfuncs.php";
  96. update_rss_feed($this->link, $feed, true);
  97. }
  98. if ($method_split[0] == "MarkAllReadGR") {
  99. catchup_feed($this->link, $method_split[1], false);
  100. }
  101. // FIXME: might break tag display?
  102. if (is_numeric($feed) && $feed > 0 && !$cat_view) {
  103. $result = db_query($this->link,
  104. "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
  105. if (db_num_rows($result) == 0) {
  106. $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
  107. }
  108. }
  109. if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
  110. $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds
  111. WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
  112. if (db_num_rows($result) == 1) {
  113. $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
  114. } else {
  115. $rtl_content = false;
  116. }
  117. if ($rtl_content) {
  118. $rtl_tag = "dir=\"RTL\"";
  119. } else {
  120. $rtl_tag = "";
  121. }
  122. } else {
  123. $rtl_tag = "";
  124. $rtl_content = false;
  125. }
  126. @$search = db_escape_string($_REQUEST["query"]);
  127. if ($search) {
  128. $disable_cache = true;
  129. }
  130. @$search_mode = db_escape_string($_REQUEST["search_mode"]);
  131. @$match_on = db_escape_string($_REQUEST["match_on"]);
  132. if (!$match_on) {
  133. $match_on = "both";
  134. }
  135. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
  136. // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
  137. if( $search_mode == '' && $method != '' ){
  138. $search_mode = $method;
  139. }
  140. // error_log("search_mode: " . $search_mode);
  141. $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
  142. $search, $search_mode, $match_on, $override_order, $offset, 0,
  143. false, 0, $include_children);
  144. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
  145. $result = $qfh_ret[0];
  146. $feed_title = $qfh_ret[1];
  147. $feed_site_url = $qfh_ret[2];
  148. $last_error = $qfh_ret[3];
  149. $vgroup_last_feed = $vgr_last_feed;
  150. // if (!$offset) {
  151. if (db_num_rows($result) > 0) {
  152. $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
  153. $feed_title,
  154. $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
  155. $last_error);
  156. }
  157. // }
  158. $headlines_count = db_num_rows($result);
  159. $plugins->hook('headlines_before', $reply);
  160. if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
  161. $button_plugins = array();
  162. foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
  163. $pclass = trim("button_${p}");
  164. if (class_exists($pclass)) {
  165. $plugin = new $pclass($link);
  166. array_push($button_plugins, $plugin);
  167. }
  168. }
  169. }
  170. if (db_num_rows($result) > 0) {
  171. $lnum = $offset;
  172. $num_unread = 0;
  173. $cur_feed_title = '';
  174. $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
  175. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
  176. while ($line = db_fetch_assoc($result)) {
  177. if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
  178. $plugins->hook('cdm_article_before', $line);
  179. } else {
  180. $plugins->hook('headlines_row', $line);
  181. }
  182. $class = ($lnum % 2) ? "even" : "odd";
  183. $id = $line["id"];
  184. $feed_id = $line["feed_id"];
  185. $label_cache = $line["label_cache"];
  186. $labels = false;
  187. if ($label_cache) {
  188. $label_cache = json_decode($label_cache, true);
  189. if ($label_cache) {
  190. if ($label_cache["no-labels"] == 1)
  191. $labels = array();
  192. else
  193. $labels = $label_cache;
  194. }
  195. }
  196. if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
  197. $labels_str = "<span id=\"HLLCTR-$id\">";
  198. $labels_str .= format_article_labels($labels, $id);
  199. $labels_str .= "</span>";
  200. if (count($topmost_article_ids) < 3) {
  201. array_push($topmost_article_ids, $id);
  202. }
  203. if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
  204. $update_pic = "<img id='FUPDPIC-$id' src=\"".
  205. theme_image($this->link, 'images/updated.png')."\"
  206. alt=\"Updated\">";
  207. } else {
  208. $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
  209. alt=\"Updated\">";
  210. }
  211. if (sql_bool_to_bool($line["unread"]) &&
  212. time() - strtotime($line["updated_noms"]) < $fresh_intl) {
  213. $update_pic = "<img id='FUPDPIC-$id' src=\"".
  214. theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
  215. }
  216. if ($line["unread"] == "t" || $line["unread"] == "1") {
  217. $class .= " Unread";
  218. ++$num_unread;
  219. $is_unread = true;
  220. } else {
  221. $is_unread = false;
  222. }
  223. if ($line["marked"] == "t" || $line["marked"] == "1") {
  224. $marked_pic = "<img id=\"FMPIC-$id\"
  225. src=\"".theme_image($this->link, 'images/mark_set.png')."\"
  226. class=\"markedPic\" alt=\"Unstar article\"
  227. onclick='javascript:toggleMark($id)'>";
  228. } else {
  229. $marked_pic = "<img id=\"FMPIC-$id\"
  230. src=\"".theme_image($this->link, 'images/mark_unset.png')."\"
  231. class=\"markedPic\" alt=\"Star article\"
  232. onclick='javascript:toggleMark($id)'>";
  233. }
  234. if ($line["published"] == "t" || $line["published"] == "1") {
  235. $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
  236. 'images/pub_set.png')."\"
  237. class=\"markedPic\"
  238. alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
  239. } else {
  240. $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
  241. 'images/pub_unset.png')."\"
  242. class=\"markedPic\"
  243. alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
  244. }
  245. # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
  246. # $line["title"] . "</a>";
  247. # $content_link = "<a
  248. # href=\"" . htmlspecialchars($line["link"]) . "\"
  249. # onclick=\"view($id,$feed_id);\">" .
  250. # $line["title"] . "</a>";
  251. # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
  252. # $line["title"] . "</a>";
  253. $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
  254. if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
  255. $content_preview = truncate_string(strip_tags($line["content_preview"]),
  256. 100);
  257. }
  258. $score = $line["score"];
  259. $score_pic = theme_image($this->link,
  260. "images/" . get_score_pic($score));
  261. /* $score_title = __("(Click to change)");
  262. $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
  263. onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
  264. $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
  265. title=\"$score\">";
  266. if ($score > 500) {
  267. $hlc_suffix = "H";
  268. } else if ($score < -100) {
  269. $hlc_suffix = "L";
  270. } else {
  271. $hlc_suffix = "";
  272. }
  273. $entry_author = $line["author"];
  274. if ($entry_author) {
  275. $entry_author = " - $entry_author";
  276. }
  277. $has_feed_icon = feed_has_icon($feed_id);
  278. if ($has_feed_icon) {
  279. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
  280. } else {
  281. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
  282. }
  283. if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
  284. if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
  285. if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
  286. $cur_feed_title = $line["feed_title"];
  287. $vgroup_last_feed = $feed_id;
  288. $cur_feed_title = htmlspecialchars($cur_feed_title);
  289. $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
  290. $reply['content'] .= "<div class='cdmFeedTitle'>".
  291. "<div style=\"float : right\">$feed_icon_img</div>".
  292. "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
  293. $line["feed_title"]."</a> $vf_catchup_link</div>";
  294. }
  295. }
  296. $mouseover_attrs = "onmouseover='postMouseIn($id)'
  297. onmouseout='postMouseOut($id)'";
  298. $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
  299. $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
  300. $reply['content'] .= "<div class='hlLeft'>";
  301. $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
  302. id=\"RCHK-$id\">";
  303. $reply['content'] .= "$marked_pic";
  304. $reply['content'] .= "$published_pic";
  305. $reply['content'] .= "</div>";
  306. $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
  307. class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
  308. $reply['content'] .= "<a id=\"RTITLE-$id\"
  309. href=\"" . htmlspecialchars($line["link"]) . "\"
  310. onclick=\"\">" .
  311. truncate_string($line["title"], 200);
  312. if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
  313. if ($content_preview) {
  314. $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
  315. }
  316. }
  317. $reply['content'] .= "</a></span>";
  318. $reply['content'] .= $labels_str;
  319. if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
  320. defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
  321. if (@$line["feed_title"]) {
  322. $reply['content'] .= "<span class=\"hlFeed\">
  323. (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
  324. $line["feed_title"]."</a>)
  325. </span>";
  326. }
  327. }
  328. $reply['content'] .= "</div>";
  329. $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
  330. $reply['content'] .= "<div class=\"hlRight\">";
  331. $reply['content'] .= $score_pic;
  332. if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
  333. $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
  334. style=\"cursor : pointer\"
  335. title=\"".htmlspecialchars($line['feed_title'])."\">
  336. $feed_icon_img<span>";
  337. }
  338. $reply['content'] .= "</div>";
  339. $reply['content'] .= "</div>";
  340. } else {
  341. if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
  342. if ($feed_id != $vgroup_last_feed) {
  343. $cur_feed_title = $line["feed_title"];
  344. $vgroup_last_feed = $feed_id;
  345. $cur_feed_title = htmlspecialchars($cur_feed_title);
  346. $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
  347. $has_feed_icon = feed_has_icon($feed_id);
  348. if ($has_feed_icon) {
  349. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
  350. } else {
  351. //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
  352. }
  353. $reply['content'] .= "<div class='cdmFeedTitle'>".
  354. "<div style=\"float : right\">$feed_icon_img</div>".
  355. "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
  356. $line["feed_title"]."</a> $vf_catchup_link</div>";
  357. }
  358. }
  359. $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
  360. $mouseover_attrs = "onmouseover='postMouseIn($id)'
  361. onmouseout='postMouseOut($id)'";
  362. $reply['content'] .= "<div class=\"$class\"
  363. id=\"RROW-$id\" $mouseover_attrs'>";
  364. $reply['content'] .= "<div class=\"cdmHeader\">";
  365. $reply['content'] .= "<div>";
  366. $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
  367. 'RROW-$id')\" id=\"RCHK-$id\"/>";
  368. $reply['content'] .= "$marked_pic";
  369. $reply['content'] .= "$published_pic";
  370. $reply['content'] .= "</div>";
  371. $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
  372. strip_tags($line['title']) . "</div>";
  373. $reply['content'] .= "<span id=\"RTITLE-$id\"
  374. onclick=\"return cdmClicked(event, $id);\"
  375. class=\"titleWrap$hlc_suffix\">
  376. <a class=\"title\"
  377. title=\"".htmlspecialchars($line['title'])."\"
  378. target=\"_blank\" href=\"".
  379. htmlspecialchars($line["link"])."\">".
  380. truncate_string($line["title"], 100) .
  381. " $entry_author</a>";
  382. $reply['content'] .= $labels_str;
  383. if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
  384. defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
  385. if (@$line["feed_title"]) {
  386. $reply['content'] .= "<span class=\"hlFeed\">
  387. (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
  388. $line["feed_title"]."</a>)
  389. </span>";
  390. }
  391. }
  392. if (!$expand_cdm)
  393. $content_hidden = "style=\"display : none\"";
  394. else
  395. $excerpt_hidden = "style=\"display : none\"";
  396. $reply['content'] .= "<span $excerpt_hidden
  397. id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
  398. $reply['content'] .= "</span>";
  399. $reply['content'] .= "<div>";
  400. $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
  401. $reply['content'] .= "$score_pic";
  402. if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
  403. $reply['content'] .= "<span style=\"cursor : pointer\"
  404. title=\"".htmlspecialchars($line["feed_title"])."\"
  405. onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
  406. }
  407. $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
  408. $reply['content'] .= "</div>";
  409. $reply['content'] .= "</div>";
  410. $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
  411. onclick=\"return cdmClicked(event, $id);\"
  412. id=\"CICD-$id\">";
  413. $reply['content'] .= "<div class=\"cdmContentInner\">";
  414. if ($line["orig_feed_id"]) {
  415. $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
  416. WHERE id = ".$line["orig_feed_id"]);
  417. if (db_num_rows($tmp_result) != 0) {
  418. $reply['content'] .= "<div clear='both'>";
  419. $reply['content'] .= __("Originally from:");
  420. $reply['content'] .= "&nbsp;";
  421. $tmp_line = db_fetch_assoc($tmp_result);
  422. $reply['content'] .= "<a target='_blank'
  423. href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
  424. $tmp_line['title'] . "</a>";
  425. $reply['content'] .= "&nbsp;";
  426. $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
  427. $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
  428. $reply['content'] .= "</div>";
  429. }
  430. }
  431. $feed_site_url = $line["site_url"];
  432. $article_content = sanitize($this->link, $line["content_preview"],
  433. false, false, $feed_site_url);
  434. $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
  435. if ($line['note']) {
  436. $reply['content'] .= format_article_note($id, $line['note']);
  437. }
  438. $reply['content'] .= "</div>";
  439. $reply['content'] .= "<span id=\"CWRAP-$id\">";
  440. $reply['content'] .= $expand_cdm ? $article_content : '';
  441. $reply['content'] .= "</span>";
  442. /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
  443. ttrss_feeds WHERE id = ".
  444. (($line['feed_id'] == null) ? $line['orig_feed_id'] :
  445. $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
  446. $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
  447. 0, "always_display_enclosures")); */
  448. $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
  449. $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,
  450. $article_content);
  451. $reply['content'] .= "</div>";
  452. $reply['content'] .= "<div class=\"cdmFooter\">";
  453. $tag_cache = $line["tag_cache"];
  454. $tags_str = format_tags_string(
  455. get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),
  456. $id);
  457. $reply['content'] .= "<img src='".theme_image($this->link,
  458. 'images/tag.png')."' alt='Tags' title='Tags'>
  459. <span id=\"ATSTR-$id\">$tags_str</span>
  460. <a title=\"".__('Edit tags for this article')."\"
  461. href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
  462. $num_comments = $line["num_comments"];
  463. $entry_comments = "";
  464. if ($num_comments > 0) {
  465. if ($line["comments"]) {
  466. $comments_url = $line["comments"];
  467. } else {
  468. $comments_url = $line["link"];
  469. }
  470. $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
  471. } else {
  472. if ($line["comments"] && $line["link"] != $line["comments"]) {
  473. $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
  474. }
  475. }
  476. if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";
  477. $reply['content'] .= "<div style=\"float : right\">";
  478. $reply['content'] .= "<img src=\"images/art-zoom.png\"
  479. onclick=\"zoomToArticle(event, $id)\"
  480. style=\"cursor : pointer\"
  481. alt='Zoom'
  482. title='".__('Open article in new tab')."'>";
  483. //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
  484. foreach ($button_plugins as $p) {
  485. $reply['content'] .= $p->render($id, $line);
  486. }
  487. $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
  488. style=\"cursor : pointer\" style=\"cursor : pointer\"
  489. onclick=\"dismissArticle($id)\"
  490. title='".__('Close article')."'>";
  491. $reply['content'] .= "</div>";
  492. $reply['content'] .= "</div>";
  493. $reply['content'] .= "</div>";
  494. $reply['content'] .= "</div>";
  495. $plugins->hook('cdm_article_after', $reply['content']);
  496. }
  497. ++$lnum;
  498. }
  499. $plugins->hook('headlines_after', $reply);
  500. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
  501. } else {
  502. $message = "";
  503. switch ($view_mode) {
  504. case "unread":
  505. $message = __("No unread articles found to display.");
  506. break;
  507. case "updated":
  508. $message = __("No updated articles found to display.");
  509. break;
  510. case "marked":
  511. $message = __("No starred articles found to display.");
  512. break;
  513. default:
  514. if ($feed < -10) {
  515. $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
  516. } else {
  517. $message = __("No articles found to display.");
  518. }
  519. }
  520. if (!$offset && $message) {
  521. $reply['content'] .= "<div class='whiteBox'>$message";
  522. $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
  523. $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
  524. WHERE owner_uid = " . $_SESSION['uid']);
  525. $last_updated = db_fetch_result($result, 0, "last_updated");
  526. $last_updated = make_local_datetime($this->link, $last_updated, false);
  527. $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
  528. $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
  529. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  530. $num_errors = db_fetch_result($result, 0, "num_errors");
  531. if ($num_errors > 0) {
  532. $reply['content'] .= "<br/>";
  533. $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
  534. __('Some feeds have update errors (click for details)')."</a>";
  535. }
  536. $reply['content'] .= "</span></p></div>";
  537. }
  538. }
  539. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
  540. return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
  541. $vgroup_last_feed, $reply);
  542. }
  543. function catchupAll() {
  544. db_query($this->link, "UPDATE ttrss_user_entries SET
  545. last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
  546. ccache_zero_all($this->link, $_SESSION["uid"]);
  547. }
  548. function collapse() {
  549. $cat_id = db_escape_string($_REQUEST["cid"]);
  550. $mode = (int) db_escape_string($_REQUEST['mode']);
  551. toggle_collapse_cat($this->link, $cat_id, $mode);
  552. }
  553. function view() {
  554. $timing_info = getmicrotime();
  555. $reply = array();
  556. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
  557. $omode = db_escape_string($_REQUEST["omode"]);
  558. $feed = db_escape_string($_REQUEST["feed"]);
  559. $method = db_escape_string($_REQUEST["m"]);
  560. $view_mode = db_escape_string($_REQUEST["view_mode"]);
  561. $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
  562. @$cat_view = $_REQUEST["cat"] == "true";
  563. @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
  564. @$offset = db_escape_string($_REQUEST["skip"]);
  565. @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
  566. $order_by = db_escape_string($_REQUEST["order_by"]);
  567. $include_children = $_REQUEST["include_children"] == "true";
  568. if (is_numeric($feed)) $feed = (int) $feed;
  569. /* Feed -5 is a special case: it is used to display auxiliary information
  570. * when there's nothing to load - e.g. no stuff in fresh feed */
  571. if ($feed == -5) {
  572. print json_encode(generate_dashboard_feed($this->link));
  573. return;
  574. }
  575. $result = false;
  576. if ($feed < -10) {
  577. $label_feed = -11-$feed;
  578. $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
  579. id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
  580. } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
  581. $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
  582. id = '$feed' AND owner_uid = " . $_SESSION['uid']);
  583. } else if ($cat_view && is_numeric($feed) && $feed > 0) {
  584. $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
  585. id = '$feed' AND owner_uid = " . $_SESSION['uid']);
  586. }
  587. if ($result && db_num_rows($result) == 0) {
  588. print json_encode(generate_error_feed($this->link, __("Feed not found.")));
  589. return;
  590. }
  591. /* Updating a label ccache means recalculating all of the caches
  592. * so for performance reasons we don't do that here */
  593. if ($feed >= 0) {
  594. ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
  595. }
  596. set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
  597. set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
  598. set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
  599. set_pref($this->link, "_DEFAULT_INCLUDE_CHILDREN", $include_children);
  600. if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
  601. db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
  602. WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
  603. }
  604. $reply['headlines'] = array();
  605. if (!$next_unread_feed)
  606. $reply['headlines']['id'] = $feed;
  607. else
  608. $reply['headlines']['id'] = $next_unread_feed;
  609. $reply['headlines']['is_cat'] = (bool) $cat_view;
  610. $override_order = false;
  611. if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
  612. $date_sort_field = "updated";
  613. } else {
  614. $date_sort_field = "date_entered";
  615. }
  616. switch ($order_by) {
  617. case "date":
  618. if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
  619. $override_order = "$date_sort_field";
  620. } else {
  621. $override_order = "$date_sort_field DESC";
  622. }
  623. break;
  624. case "title":
  625. if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
  626. $override_order = "title DESC, $date_sort_field";
  627. } else {
  628. $override_order = "title, $date_sort_field DESC";
  629. }
  630. break;
  631. case "score":
  632. if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
  633. $override_order = "score, $date_sort_field";
  634. } else {
  635. $override_order = "score DESC, $date_sort_field DESC";
  636. }
  637. break;
  638. }
  639. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
  640. $ret = $this->format_headlines_list($feed, $method,
  641. $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
  642. $vgroup_last_feed, $override_order, $include_children);
  643. $topmost_article_ids = $ret[0];
  644. $headlines_count = $ret[1];
  645. $returned_feed = $ret[2];
  646. $disable_cache = $ret[3];
  647. $vgroup_last_feed = $ret[4];
  648. $reply['headlines']['content'] =& $ret[5]['content'];
  649. $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
  650. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
  651. $reply['headlines-info'] = array("count" => (int) $headlines_count,
  652. "vgroup_last_feed" => $vgroup_last_feed,
  653. "disable_cache" => (bool) $disable_cache);
  654. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
  655. if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
  656. $articles = array();
  657. foreach ($topmost_article_ids as $id) {
  658. array_push($articles, format_article($this->link, $id, false));
  659. }
  660. $reply['articles'] = $articles;
  661. }
  662. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
  663. $reply['runtime-info'] = make_runtime_info($this->link);
  664. print json_encode($reply);
  665. }
  666. }
  667. ?>