feeds.php 32 KB

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