feeds.php 30 KB

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