feeds.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. <?php
  2. require_once "colors.php";
  3. class Feeds extends Handler_Protected {
  4. function csrf_ignore($method) {
  5. $csrf_ignored = array("index", "feedbrowser", "quickaddfeed", "search");
  6. return array_search($method, $csrf_ignored) !== false;
  7. }
  8. private function format_headline_subtoolbar($feed_site_url, $feed_title,
  9. $feed_id, $is_cat, $search,
  10. $search_mode, $view_mode, $error, $feed_last_updated) {
  11. $page_prev_link = "viewFeedGoPage(-1)";
  12. $page_next_link = "viewFeedGoPage(1)";
  13. $page_first_link = "viewFeedGoPage(0)";
  14. $catchup_page_link = "catchupPage()";
  15. $catchup_feed_link = "catchupCurrentFeed()";
  16. $catchup_sel_link = "catchupSelection()";
  17. $archive_sel_link = "archiveSelection()";
  18. $delete_sel_link = "deleteSelection()";
  19. $sel_all_link = "selectArticles('all')";
  20. $sel_unread_link = "selectArticles('unread')";
  21. $sel_none_link = "selectArticles('none')";
  22. $sel_inv_link = "selectArticles('invert')";
  23. $tog_unread_link = "selectionToggleUnread()";
  24. $tog_marked_link = "selectionToggleMarked()";
  25. $tog_published_link = "selectionTogglePublished()";
  26. $set_score_link = "setSelectionScore()";
  27. if ($is_cat) $cat_q = "&is_cat=$is_cat";
  28. if ($search) {
  29. $search_q = "&q=$search&smode=$search_mode";
  30. } else {
  31. $search_q = "";
  32. }
  33. $rss_link = htmlspecialchars(get_self_url_prefix() .
  34. "/public.php?op=rss&id=$feed_id$cat_q$search_q");
  35. // right part
  36. $reply .= "<span class='r'>";
  37. $reply .= "<span id='selected_prompt'></span>";
  38. $reply .= "<span id='feed_title'>";
  39. if ($feed_site_url) {
  40. $last_updated = T_sprintf("Last updated: %s",
  41. $feed_last_updated);
  42. $target = "target=\"_blank\"";
  43. $reply .= "<a title=\"$last_updated\" $target href=\"$feed_site_url\">".
  44. truncate_string($feed_title,30)."</a>";
  45. if ($error) {
  46. $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
  47. }
  48. } else {
  49. $reply .= $feed_title;
  50. }
  51. $reply .= "</span>";
  52. $reply .= "
  53. <a href=\"#\"
  54. title=\"".__("View as RSS feed")."\"
  55. onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
  56. <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/pub_set.svg\"></a>";
  57. $reply .= "</span>";
  58. // left part
  59. $reply .= __('Select:')."
  60. <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
  61. <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
  62. <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
  63. <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
  64. $reply .= " ";
  65. $reply .= "<select dojoType=\"dijit.form.Select\"
  66. onchange=\"headlineActionsChange(this)\">";
  67. $reply .= "<option value=\"false\">".__('More...')."</option>";
  68. $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
  69. $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
  70. <option value=\"$tog_marked_link\">".__('Starred')."</option>
  71. <option value=\"$tog_published_link\">".__('Published')."</option>";
  72. $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
  73. $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
  74. $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
  75. if ($feed_id != "0") {
  76. $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
  77. } else {
  78. $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
  79. $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
  80. }
  81. if (PluginHost::getInstance()->get_plugin("mail")) {
  82. $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
  83. "</option>";
  84. }
  85. if (PluginHost::getInstance()->get_plugin("mailto")) {
  86. $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
  87. "</option>";
  88. }
  89. $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
  90. //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
  91. $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
  92. $reply .= "</select>";
  93. //$reply .= "</div>";
  94. //$reply .= "</h2";
  95. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) {
  96. echo $p->hook_headline_toolbar_button($feed_id, $is_cat);
  97. }
  98. return $reply;
  99. }
  100. private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
  101. $next_unread_feed, $offset, $vgr_last_feed = false,
  102. $override_order = false, $include_children = false) {
  103. if (isset($_REQUEST["DevForceUpdate"]))
  104. header("Content-Type: text/plain");
  105. $disable_cache = false;
  106. $reply = array();
  107. $rgba_cache = array();
  108. $timing_info = microtime(true);
  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 = $this->dbh->query(
  116. "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
  117. FROM ttrss_feeds WHERE id = '$feed'");
  118. if ($this->dbh->num_rows($result) != 0) {
  119. $last_updated = strtotime($this->dbh->fetch_result($result, 0, "last_updated"));
  120. $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images"));
  121. if (!$cache_images && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) {
  122. include "rssfuncs.php";
  123. update_rss_feed($feed, true, true);
  124. } else {
  125. $this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
  126. WHERE id = '$feed'");
  127. }
  128. }
  129. }
  130. if ($method_split[0] == "MarkAllReadGR") {
  131. catchup_feed($method_split[1], false);
  132. }
  133. // FIXME: might break tag display?
  134. if (is_numeric($feed) && $feed > 0 && !$cat_view) {
  135. $result = $this->dbh->query(
  136. "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
  137. if ($this->dbh->num_rows($result) == 0) {
  138. $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
  139. }
  140. }
  141. @$search = $this->dbh->escape_string($_REQUEST["query"]);
  142. if ($search) {
  143. $disable_cache = true;
  144. }
  145. @$search_mode = $this->dbh->escape_string($_REQUEST["search_mode"]);
  146. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
  147. // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
  148. if($search_mode == '' && $method != '' ){
  149. $search_mode = $method;
  150. }
  151. // error_log("search_mode: " . $search_mode);
  152. if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
  153. $handler = PluginHost::getInstance()->get_feed_handler(
  154. PluginHost::feed_to_pfeed_id($feed));
  155. // function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) {
  156. if ($handler) {
  157. $options = array(
  158. "limit" => $limit,
  159. "view_mode" => $view_mode,
  160. "cat_view" => $cat_view,
  161. "search" => $search,
  162. "search_mode" => $search_mode,
  163. "override_order" => $override_order,
  164. "offset" => $offset,
  165. "owner_uid" => $_SESSION["uid"],
  166. "filter" => false,
  167. "since_id" => 0,
  168. "include_children" => $include_children);
  169. $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
  170. $options);
  171. }
  172. } else {
  173. $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view,
  174. $search, $search_mode, $override_order, $offset, 0,
  175. false, 0, $include_children);
  176. }
  177. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
  178. $result = $qfh_ret[0];
  179. $feed_title = $qfh_ret[1];
  180. $feed_site_url = $qfh_ret[2];
  181. $last_error = $qfh_ret[3];
  182. $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
  183. make_local_datetime($qfh_ret[4], false) : __("Never");
  184. $vgroup_last_feed = $vgr_last_feed;
  185. $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
  186. $feed_title,
  187. $feed, $cat_view, $search, $search_mode, $view_mode,
  188. $last_error, $last_updated);
  189. $headlines_count = $this->dbh->num_rows($result);
  190. /* if (get_pref('COMBINED_DISPLAY_MODE')) {
  191. $button_plugins = array();
  192. foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
  193. $pclass = "button_" . trim($p);
  194. if (class_exists($pclass)) {
  195. $plugin = new $pclass();
  196. array_push($button_plugins, $plugin);
  197. }
  198. }
  199. } */
  200. if ($this->dbh->num_rows($result) > 0) {
  201. $lnum = $offset;
  202. $num_unread = 0;
  203. $cur_feed_title = '';
  204. $fresh_intl = get_pref("FRESH_ARTICLE_MAX_AGE") * 60 * 60;
  205. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
  206. $expand_cdm = get_pref('CDM_EXPANDED');
  207. while ($line = $this->dbh->fetch_assoc($result)) {
  208. $id = $line["id"];
  209. $feed_id = $line["feed_id"];
  210. $label_cache = $line["label_cache"];
  211. $labels = false;
  212. if ($label_cache) {
  213. $label_cache = json_decode($label_cache, true);
  214. if ($label_cache) {
  215. if ($label_cache["no-labels"] == 1)
  216. $labels = array();
  217. else
  218. $labels = $label_cache;
  219. }
  220. }
  221. if (!is_array($labels)) $labels = get_article_labels($id);
  222. $labels_str = "<span id=\"HLLCTR-$id\">";
  223. $labels_str .= format_article_labels($labels, $id);
  224. $labels_str .= "</span>";
  225. if (count($topmost_article_ids) < 3) {
  226. array_push($topmost_article_ids, $id);
  227. }
  228. $class = "";
  229. if (sql_bool_to_bool($line["unread"])) {
  230. $class .= " Unread";
  231. ++$num_unread;
  232. }
  233. if (sql_bool_to_bool($line["marked"])) {
  234. $marked_pic = "<img
  235. src=\"images/mark_set.svg\"
  236. class=\"markedPic\" alt=\"Unstar article\"
  237. onclick='toggleMark($id)'>";
  238. $class .= " marked";
  239. } else {
  240. $marked_pic = "<img
  241. src=\"images/mark_unset.svg\"
  242. class=\"markedPic\" alt=\"Star article\"
  243. onclick='toggleMark($id)'>";
  244. }
  245. if (sql_bool_to_bool($line["published"])) {
  246. $published_pic = "<img src=\"images/pub_set.svg\"
  247. class=\"pubPic\"
  248. alt=\"Unpublish article\" onclick='togglePub($id)'>";
  249. $class .= " published";
  250. } else {
  251. $published_pic = "<img src=\"images/pub_unset.svg\"
  252. class=\"pubPic\"
  253. alt=\"Publish article\" onclick='togglePub($id)'>";
  254. }
  255. # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
  256. # $line["title"] . "</a>";
  257. # $content_link = "<a
  258. # href=\"" . htmlspecialchars($line["link"]) . "\"
  259. # onclick=\"view($id,$feed_id);\">" .
  260. # $line["title"] . "</a>";
  261. # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
  262. # $line["title"] . "</a>";
  263. $updated_fmt = make_local_datetime($line["updated"], false);
  264. $date_entered_fmt = T_sprintf("Imported at %s",
  265. make_local_datetime($line["date_entered"], false));
  266. if (get_pref('SHOW_CONTENT_PREVIEW')) {
  267. $content_preview = truncate_string(strip_tags($line["content_preview"]),
  268. 250);
  269. }
  270. $score = $line["score"];
  271. $score_pic = "images/" . get_score_pic($score);
  272. /* $score_title = __("(Click to change)");
  273. $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
  274. onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
  275. $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
  276. title=\"$score\">";
  277. if ($score > 500) {
  278. $hlc_suffix = "H";
  279. } else if ($score < -100) {
  280. $hlc_suffix = "L";
  281. } else {
  282. $hlc_suffix = "";
  283. }
  284. $entry_author = $line["author"];
  285. if ($entry_author) {
  286. $entry_author = " &mdash; $entry_author";
  287. }
  288. $has_feed_icon = feed_has_icon($feed_id);
  289. if ($has_feed_icon) {
  290. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
  291. } else {
  292. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.svg\" alt=\"\">";
  293. }
  294. $entry_site_url = $line["site_url"];
  295. //setting feed headline background color, needs to change text color based on dark/light
  296. $fav_color = $line['favicon_avg_color'];
  297. require_once "colors.php";
  298. if ($fav_color && $fav_color != 'fail') {
  299. if (!isset($rgba_cache[$feed_id])) {
  300. $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
  301. }
  302. }
  303. if (!get_pref('COMBINED_DISPLAY_MODE')) {
  304. if (get_pref('VFEED_GROUP_BY_FEED')) {
  305. if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
  306. $cur_feed_title = $line["feed_title"];
  307. $vgroup_last_feed = $feed_id;
  308. $cur_feed_title = htmlspecialchars($cur_feed_title);
  309. $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
  310. $reply['content'] .= "<div class='cdmFeedTitle'>".
  311. "<div style=\"float : right\">$feed_icon_img</div>".
  312. "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
  313. $line["feed_title"]."</a> $vf_catchup_link</div>";
  314. }
  315. }
  316. $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
  317. onmouseout='postMouseOut($id)'";
  318. $reply['content'] .= "<div class='hl $class' id='RROW-$id' $mouseover_attrs>";
  319. $reply['content'] .= "<div class='hlLeft'>";
  320. $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
  321. type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
  322. class='rchk'>";
  323. $reply['content'] .= "$marked_pic";
  324. $reply['content'] .= "$published_pic";
  325. $reply['content'] .= "</div>";
  326. $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
  327. class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
  328. $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title\"
  329. href=\"" . htmlspecialchars($line["link"]) . "\"
  330. onclick=\"\">" .
  331. truncate_string($line["title"], 200);
  332. if (get_pref('SHOW_CONTENT_PREVIEW')) {
  333. if ($content_preview) {
  334. $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
  335. }
  336. }
  337. $reply['content'] .= "</a></span>";
  338. $reply['content'] .= $labels_str;
  339. $reply['content'] .= "</div>";
  340. $reply['content'] .= "<span class=\"hlUpdated\">";
  341. if (!get_pref('VFEED_GROUP_BY_FEED')) {
  342. if (@$line["feed_title"]) {
  343. $rgba = @$rgba_cache[$feed_id];
  344. $reply['content'] .= "<a class=\"hlFeed\" style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed($feed_id)\">".
  345. truncate_string($line["feed_title"],30)."</a>";
  346. }
  347. }
  348. $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
  349. </span>";
  350. $reply['content'] .= "<div class=\"hlRight\">";
  351. $reply['content'] .= $score_pic;
  352. if ($line["feed_title"] && !get_pref('VFEED_GROUP_BY_FEED')) {
  353. $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
  354. style=\"cursor : pointer\"
  355. title=\"".htmlspecialchars($line['feed_title'])."\">
  356. $feed_icon_img<span>";
  357. }
  358. $reply['content'] .= "</div>";
  359. $reply['content'] .= "</div>";
  360. } else {
  361. if ($line["tag_cache"])
  362. $tags = explode(",", $line["tag_cache"]);
  363. else
  364. $tags = false;
  365. $line["content"] = sanitize($line["content_preview"],
  366. sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
  367. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
  368. $line = $p->hook_render_article_cdm($line);
  369. }
  370. if (get_pref('VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
  371. if ($feed_id != $vgroup_last_feed) {
  372. $cur_feed_title = $line["feed_title"];
  373. $vgroup_last_feed = $feed_id;
  374. $cur_feed_title = htmlspecialchars($cur_feed_title);
  375. $vf_catchup_link = "(<a class='catchup' onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
  376. $has_feed_icon = feed_has_icon($feed_id);
  377. if ($has_feed_icon) {
  378. $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
  379. } else {
  380. //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
  381. }
  382. $reply['content'] .= "<div class='cdmFeedTitle'>".
  383. "<div style=\"float : right\">$feed_icon_img</div>".
  384. "<a href=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
  385. $line["feed_title"]."</a> $vf_catchup_link</div>";
  386. }
  387. }
  388. $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
  389. onmouseout='postMouseOut($id)'";
  390. $expanded_class = $expand_cdm ? "expanded" : "expandable";
  391. $reply['content'] .= "<div class=\"cdm $expanded_class $class\"
  392. id=\"RROW-$id\" $mouseover_attrs>";
  393. $reply['content'] .= "<div class=\"cdmHeader\" style=\"$row_background\">";
  394. $reply['content'] .= "<div style=\"vertical-align : middle\">";
  395. $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
  396. type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
  397. class='rchk'>";
  398. $reply['content'] .= "$marked_pic";
  399. $reply['content'] .= "$published_pic";
  400. $reply['content'] .= "</div>";
  401. $reply['content'] .= "<span id=\"RTITLE-$id\"
  402. onclick=\"return cdmClicked(event, $id);\"
  403. class=\"titleWrap$hlc_suffix\">
  404. <a class=\"title\"
  405. target=\"_blank\" href=\"".
  406. htmlspecialchars($line["link"])."\">".
  407. $line["title"] .
  408. "</a> <span class=\"author\">$entry_author</span>";
  409. $reply['content'] .= $labels_str;
  410. $reply['content'] .= "<span class='collapseBtn' style='display : none'>
  411. <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
  412. title=\"".__("Collapse article")."\"/></span>";
  413. if (!$expand_cdm)
  414. $content_hidden = "style=\"display : none\"";
  415. else
  416. $excerpt_hidden = "style=\"display : none\"";
  417. $reply['content'] .= "<span $excerpt_hidden
  418. id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
  419. $reply['content'] .= "</span>";
  420. if (!get_pref('VFEED_GROUP_BY_FEED')) {
  421. if (@$line["feed_title"]) {
  422. $rgba = @$rgba_cache[$feed_id];
  423. $reply['content'] .= "<div class=\"hlFeed\">
  424. <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
  425. onclick=\"viewfeed($feed_id)\">".
  426. truncate_string($line["feed_title"],30)."</a>
  427. </div>";
  428. }
  429. }
  430. $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
  431. $updated_fmt</span>";
  432. $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
  433. $reply['content'] .= "$score_pic";
  434. if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
  435. $reply['content'] .= "<span style=\"cursor : pointer\"
  436. title=\"".htmlspecialchars($line["feed_title"])."\"
  437. onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
  438. }
  439. $reply['content'] .= "</div>";
  440. $reply['content'] .= "</div>";
  441. $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
  442. onclick=\"return cdmClicked(event, $id);\"
  443. id=\"CICD-$id\">";
  444. $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
  445. if ($line['note']) {
  446. $reply['content'] .= format_article_note($id, $line['note']);
  447. }
  448. $reply['content'] .= "</div>";
  449. $reply['content'] .= "<div class=\"cdmContentInner\">";
  450. if ($line["orig_feed_id"]) {
  451. $tmp_result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds
  452. WHERE id = ".$line["orig_feed_id"]);
  453. if ($this->dbh->num_rows($tmp_result) != 0) {
  454. $reply['content'] .= "<div clear='both'>";
  455. $reply['content'] .= __("Originally from:");
  456. $reply['content'] .= "&nbsp;";
  457. $tmp_line = $this->dbh->fetch_assoc($tmp_result);
  458. $reply['content'] .= "<a target='_blank'
  459. href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
  460. $tmp_line['title'] . "</a>";
  461. $reply['content'] .= "&nbsp;";
  462. $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
  463. $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.svg'></a>";
  464. $reply['content'] .= "</div>";
  465. }
  466. }
  467. $reply['content'] .= "<span id=\"CWRAP-$id\">";
  468. // if (!$expand_cdm) {
  469. $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
  470. $reply['content'] .= htmlspecialchars($line["content"]);
  471. $reply['content'] .= "</span.";
  472. // } else {
  473. // $reply['content'] .= $line["content"];
  474. // }
  475. $reply['content'] .= "</span>";
  476. $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
  477. $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
  478. $reply['content'] .= "</div>";
  479. $reply['content'] .= "<div class=\"cdmFooter\">";
  480. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
  481. $reply['content'] .= $p->hook_article_left_button($line);
  482. }
  483. $tags_str = format_tags_string($tags, $id);
  484. $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
  485. <span id=\"ATSTR-$id\">$tags_str</span>
  486. <a title=\"".__('Edit tags for this article')."\"
  487. href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
  488. $num_comments = $line["num_comments"];
  489. $entry_comments = "";
  490. if ($num_comments > 0) {
  491. if ($line["comments"]) {
  492. $comments_url = htmlspecialchars($line["comments"]);
  493. } else {
  494. $comments_url = htmlspecialchars($line["link"]);
  495. }
  496. $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
  497. } else {
  498. if ($line["comments"] && $line["link"] != $line["comments"]) {
  499. $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
  500. }
  501. }
  502. if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";
  503. $reply['content'] .= "<div style=\"float : right\">";
  504. // $reply['content'] .= "$marked_pic";
  505. // $reply['content'] .= "$published_pic";
  506. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
  507. $reply['content'] .= $p->hook_article_button($line);
  508. }
  509. $reply['content'] .= "</div>";
  510. $reply['content'] .= "</div>";
  511. $reply['content'] .= "</div><hr/>";
  512. $reply['content'] .= "</div>";
  513. }
  514. ++$lnum;
  515. }
  516. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
  517. } else {
  518. $message = "";
  519. switch ($view_mode) {
  520. case "unread":
  521. $message = __("No unread articles found to display.");
  522. break;
  523. case "updated":
  524. $message = __("No updated articles found to display.");
  525. break;
  526. case "marked":
  527. $message = __("No starred articles found to display.");
  528. break;
  529. default:
  530. if ($feed < LABEL_BASE_INDEX) {
  531. $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter.");
  532. } else {
  533. $message = __("No articles found to display.");
  534. }
  535. }
  536. if (!$offset && $message) {
  537. $reply['content'] .= "<div class='whiteBox'>$message";
  538. $reply['content'] .= "<p><span class=\"insensitive\">";
  539. $result = $this->dbh->query("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
  540. WHERE owner_uid = " . $_SESSION['uid']);
  541. $last_updated = $this->dbh->fetch_result($result, 0, "last_updated");
  542. $last_updated = make_local_datetime($last_updated, false);
  543. $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
  544. $result = $this->dbh->query("SELECT COUNT(id) AS num_errors
  545. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  546. $num_errors = $this->dbh->fetch_result($result, 0, "num_errors");
  547. if ($num_errors > 0) {
  548. $reply['content'] .= "<br/>";
  549. $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
  550. __('Some feeds have update errors (click for details)')."</a>";
  551. }
  552. $reply['content'] .= "</span></p></div>";
  553. }
  554. }
  555. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
  556. return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
  557. $vgroup_last_feed, $reply);
  558. }
  559. function catchupAll() {
  560. $this->dbh->query("UPDATE ttrss_user_entries SET
  561. last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
  562. ccache_zero_all($_SESSION["uid"]);
  563. }
  564. function view() {
  565. $timing_info = microtime(true);
  566. $reply = array();
  567. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
  568. $omode = $this->dbh->escape_string($_REQUEST["omode"]);
  569. $feed = $this->dbh->escape_string($_REQUEST["feed"]);
  570. $method = $this->dbh->escape_string($_REQUEST["m"]);
  571. $view_mode = $this->dbh->escape_string($_REQUEST["view_mode"]);
  572. $limit = 30;
  573. @$cat_view = $_REQUEST["cat"] == "true";
  574. @$next_unread_feed = $this->dbh->escape_string($_REQUEST["nuf"]);
  575. @$offset = $this->dbh->escape_string($_REQUEST["skip"]);
  576. @$vgroup_last_feed = $this->dbh->escape_string($_REQUEST["vgrlf"]);
  577. $order_by = $this->dbh->escape_string($_REQUEST["order_by"]);
  578. if (is_numeric($feed)) $feed = (int) $feed;
  579. /* Feed -5 is a special case: it is used to display auxiliary information
  580. * when there's nothing to load - e.g. no stuff in fresh feed */
  581. if ($feed == -5) {
  582. print json_encode($this->generate_dashboard_feed());
  583. return;
  584. }
  585. $result = false;
  586. if ($feed < LABEL_BASE_INDEX) {
  587. $label_feed = feed_to_label_id($feed);
  588. $result = $this->dbh->query("SELECT id FROM ttrss_labels2 WHERE
  589. id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
  590. } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
  591. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  592. id = '$feed' AND owner_uid = " . $_SESSION['uid']);
  593. } else if ($cat_view && is_numeric($feed) && $feed > 0) {
  594. $result = $this->dbh->query("SELECT id FROM ttrss_feed_categories WHERE
  595. id = '$feed' AND owner_uid = " . $_SESSION['uid']);
  596. }
  597. if ($result && $this->dbh->num_rows($result) == 0) {
  598. print json_encode($this->generate_error_feed(__("Feed not found.")));
  599. return;
  600. }
  601. /* Updating a label ccache means recalculating all of the caches
  602. * so for performance reasons we don't do that here */
  603. if ($feed >= 0) {
  604. ccache_update($feed, $_SESSION["uid"], $cat_view);
  605. }
  606. set_pref("_DEFAULT_VIEW_MODE", $view_mode);
  607. set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
  608. /* bump login timestamp if needed */
  609. if (time() - $_SESSION["last_login_update"] > 3600) {
  610. $this->dbh->query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
  611. $_SESSION["uid"]);
  612. $_SESSION["last_login_update"] = time();
  613. }
  614. if (!$cat_view && is_numeric($feed) && $feed > 0) {
  615. $this->dbh->query("UPDATE ttrss_feeds SET last_viewed = NOW()
  616. WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
  617. }
  618. $reply['headlines'] = array();
  619. if (!$next_unread_feed)
  620. $reply['headlines']['id'] = $feed;
  621. else
  622. $reply['headlines']['id'] = $next_unread_feed;
  623. $reply['headlines']['is_cat'] = (bool) $cat_view;
  624. $override_order = false;
  625. switch ($order_by) {
  626. case "title":
  627. $override_order = "ttrss_entries.title";
  628. break;
  629. case "date_reverse":
  630. $override_order = "date_entered, updated";
  631. break;
  632. case "feed_dates":
  633. $override_order = "updated DESC";
  634. break;
  635. }
  636. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
  637. $ret = $this->format_headlines_list($feed, $method,
  638. $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
  639. $vgroup_last_feed, $override_order, true);
  640. //$topmost_article_ids = $ret[0];
  641. $headlines_count = $ret[1];
  642. $returned_feed = $ret[2];
  643. $disable_cache = $ret[3];
  644. $vgroup_last_feed = $ret[4];
  645. $reply['headlines']['content'] =& $ret[5]['content'];
  646. $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
  647. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
  648. $reply['headlines-info'] = array("count" => (int) $headlines_count,
  649. "vgroup_last_feed" => $vgroup_last_feed,
  650. "disable_cache" => (bool) $disable_cache);
  651. if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
  652. $reply['runtime-info'] = make_runtime_info();
  653. print json_encode($reply);
  654. }
  655. private function generate_dashboard_feed() {
  656. $reply = array();
  657. $reply['headlines']['id'] = -5;
  658. $reply['headlines']['is_cat'] = false;
  659. $reply['headlines']['toolbar'] = '';
  660. $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
  661. $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
  662. $result = $this->dbh->query("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
  663. WHERE owner_uid = " . $_SESSION['uid']);
  664. $last_updated = $this->dbh->fetch_result($result, 0, "last_updated");
  665. $last_updated = make_local_datetime($last_updated, false);
  666. $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
  667. $result = $this->dbh->query("SELECT COUNT(id) AS num_errors
  668. FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
  669. $num_errors = $this->dbh->fetch_result($result, 0, "num_errors");
  670. if ($num_errors > 0) {
  671. $reply['headlines']['content'] .= "<br/>";
  672. $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
  673. __('Some feeds have update errors (click for details)')."</a>";
  674. }
  675. $reply['headlines']['content'] .= "</span></p>";
  676. $reply['headlines-info'] = array("count" => 0,
  677. "vgroup_last_feed" => '',
  678. "unread" => 0,
  679. "disable_cache" => true);
  680. return $reply;
  681. }
  682. private function generate_error_feed($error) {
  683. $reply = array();
  684. $reply['headlines']['id'] = -6;
  685. $reply['headlines']['is_cat'] = false;
  686. $reply['headlines']['toolbar'] = '';
  687. $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
  688. $reply['headlines-info'] = array("count" => 0,
  689. "vgroup_last_feed" => '',
  690. "unread" => 0,
  691. "disable_cache" => true);
  692. return $reply;
  693. }
  694. function quickAddFeed() {
  695. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
  696. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
  697. print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
  698. print "<div class=\"dlgSecCont\">";
  699. print "<div style='float : right'>
  700. <img style='display : none'
  701. id='feed_add_spinner' src='images/indicator_white.gif'></div>";
  702. print "<input style=\"font-size : 16px; width : 20em;\"
  703. placeHolder=\"".__("Feed or site URL")."\"
  704. dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
  705. print "<hr/>";
  706. if (get_pref('ENABLE_FEED_CATS')) {
  707. print __('Place in category:') . " ";
  708. print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
  709. }
  710. print "</div>";
  711. print '<div id="feedDlg_feedsContainer" style="display : none">
  712. <div class="dlgSec">' . __('Available feeds') . '</div>
  713. <div class="dlgSecCont">'.
  714. '<select id="feedDlg_feedContainerSelect"
  715. dojoType="dijit.form.Select" size="3">
  716. <script type="dojo/method" event="onChange" args="value">
  717. dijit.byId("feedDlg_feedUrl").attr("value", value);
  718. </script>
  719. </select>'.
  720. '</div></div>';
  721. print "<div id='feedDlg_loginContainer' style='display : none'>
  722. <div class=\"dlgSec\">".__("Authentication")."</div>
  723. <div class=\"dlgSecCont\">".
  724. " <input dojoType=\"dijit.form.TextBox\" name='login'\"
  725. placeHolder=\"".__("Login")."\"
  726. style=\"width : 10em;\"> ".
  727. " <input
  728. placeHolder=\"".__("Password")."\"
  729. dojoType=\"dijit.form.TextBox\" type='password'
  730. style=\"width : 10em;\" name='pass'\">
  731. </div></div>";
  732. print "<div style=\"clear : both\">
  733. <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
  734. onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
  735. <label for=\"feedDlg_loginCheck\">".
  736. __('This feed requires authentication.')."</div>";
  737. print "</form>";
  738. print "<div class=\"dlgButtons\">
  739. <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
  740. if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) {
  741. print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
  742. }
  743. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
  744. </div>";
  745. //return;
  746. }
  747. function feedBrowser() {
  748. if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
  749. $browser_search = $this->dbh->escape_string($_REQUEST["search"]);
  750. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
  751. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
  752. print "<div dojoType=\"dijit.Toolbar\">
  753. <div style='float : right'>
  754. <img style='display : none'
  755. id='feed_browser_spinner' src='images/indicator_white.gif'>
  756. <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
  757. onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
  758. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
  759. </div>";
  760. print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
  761. <option value='1'>" . __('Popular feeds') . "</option>
  762. <option value='2'>" . __('Feed archive') . "</option>
  763. </select> ";
  764. print __("limit:");
  765. print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
  766. foreach (array(25, 50, 100, 200) as $l) {
  767. $issel = ($l == $limit) ? "selected=\"1\"" : "";
  768. print "<option $issel value=\"$l\">$l</option>";
  769. }
  770. print "</select> ";
  771. print "</div>";
  772. $owner_uid = $_SESSION["uid"];
  773. require_once "feedbrowser.php";
  774. print "<ul class='browseFeedList' id='browseFeedList'>";
  775. print make_feed_browser($search, 25);
  776. print "</ul>";
  777. print "<div align='center'>
  778. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
  779. <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
  780. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
  781. }
  782. function search() {
  783. $this->params = explode(":", $this->dbh->escape_string($_REQUEST["param"]), 2);
  784. $active_feed_id = sprintf("%d", $this->params[0]);
  785. $is_cat = $this->params[1] != "false";
  786. print "<div class=\"dlgSec\">".__('Look for')."</div>";
  787. print "<div class=\"dlgSecCont\">";
  788. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  789. style=\"font-size : 16px; width : 20em;\"
  790. required=\"1\" name=\"query\" type=\"search\" value=''>";
  791. print "<hr/>".__('Limit search to:')." ";
  792. print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
  793. <option value=\"all_feeds\">".__('All feeds')."</option>";
  794. $feed_title = getFeedTitle($active_feed_id);
  795. if (!$is_cat) {
  796. $feed_cat_title = getFeedCatTitle($active_feed_id);
  797. } else {
  798. $feed_cat_title = getCategoryTitle($active_feed_id);
  799. }
  800. if ($active_feed_id && !$is_cat) {
  801. print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
  802. } else {
  803. print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
  804. }
  805. if ($is_cat) {
  806. $cat_preselected = "selected=\"1\"";
  807. }
  808. if (get_pref('ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
  809. print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
  810. } else {
  811. //print "<option disabled>".__('This category')."</option>";
  812. }
  813. print "</select>";
  814. print "</div>";
  815. print "<div class=\"dlgButtons\">";
  816. if (!SPHINX_ENABLED) {
  817. print "<div style=\"float : left\">
  818. <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">Search syntax</a>
  819. </div>";
  820. }
  821. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
  822. <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
  823. </div>";
  824. }
  825. }
  826. ?>