]> git.wh0rd.org - tt-rss.git/blame - classes/feeds.php
add ability to auto-assign articles to labels (bump schema)
[tt-rss.git] / classes / feeds.php
CommitLineData
3f363052 1<?php\r
30c337cf
AD
2require_once "colors.php";\r
3\r
369dbc19 4class Feeds extends Handler_Protected {\r
46da73c2 5\r
8484ce22
AD
6 function csrf_ignore($method) {\r
7 $csrf_ignored = array("index");\r
8\r
9 return array_search($method, $csrf_ignored) !== false;\r
10 }\r
11\r
f65ede50
AD
12 private function make_gradient($end, $class) {\r
13 $start = $class == "even" ? "#f0f0f0" : "#ffffff";\r
14\r
15 return "style='background: linear-gradient(left , $start 6%, $end 100%);\r
16 background: -o-linear-gradient(left , $start 6%, $end 100%);\r
17 background: -moz-linear-gradient(left , $start 6%, $end 100%);\r
18 background: -webkit-linear-gradient(left , $start 6%, $end 100%);\r
19 background: -ms-linear-gradient(left , $start 6%, $end 100%);\r
20 background: -webkit-gradient(linear, left top, right top,\r
21 color-stop(0.06, $start), color-stop(1, $end));'";\r
22 }\r
23\r
79178062
AD
24 private function format_headline_subtoolbar($feed_site_url, $feed_title,\r
25 $feed_id, $is_cat, $search, $match_on,\r
26 $search_mode, $view_mode, $error) {\r
27\r
28 $page_prev_link = "viewFeedGoPage(-1)";\r
29 $page_next_link = "viewFeedGoPage(1)";\r
30 $page_first_link = "viewFeedGoPage(0)";\r
31\r
32 $catchup_page_link = "catchupPage()";\r
33 $catchup_feed_link = "catchupCurrentFeed()";\r
34 $catchup_sel_link = "catchupSelection()";\r
35\r
36 $archive_sel_link = "archiveSelection()";\r
37 $delete_sel_link = "deleteSelection()";\r
38\r
39 $sel_all_link = "selectArticles('all')";\r
40 $sel_unread_link = "selectArticles('unread')";\r
41 $sel_none_link = "selectArticles('none')";\r
42 $sel_inv_link = "selectArticles('invert')";\r
43\r
44 $tog_unread_link = "selectionToggleUnread()";\r
45 $tog_marked_link = "selectionToggleMarked()";\r
46 $tog_published_link = "selectionTogglePublished()";\r
47\r
f1080825
AD
48 if ($is_cat) $cat_q = "&is_cat=$is_cat";\r
49\r
50 if ($search) {\r
51 $search_q = "&q=$search&m=$match_on&smode=$search_mode";\r
52 } else {\r
53 $search_q = "";\r
54 }\r
55\r
56 $rss_link = htmlspecialchars(get_self_url_prefix() .\r
57 "/public.php?op=rss&id=$feed_id$cat_q$search_q");\r
58\r
59 // right part\r
60\r
61 $reply .= "<span class='r'>";\r
74467907 62 $reply .= "<span id='feed_title'>";\r
f1080825
AD
63\r
64 if ($feed_site_url) {\r
65 $target = "target=\"_blank\"";\r
66 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".\r
67 truncate_string($feed_title,30)."</a>";\r
68\r
69 if ($error) {\r
70 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";\r
71 }\r
72\r
73 } else {\r
74 $reply .= $feed_title;\r
75 }\r
76\r
74467907
AD
77 $reply .= "</span>";\r
78\r
f1080825
AD
79 $reply .= "\r
80 <a href=\"#\"\r
81 title=\"".__("View as RSS feed")."\"\r
82 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">\r
83 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";\r
84\r
85 $reply .= "</span>";\r
86\r
87 // left part\r
79178062
AD
88\r
89 $reply .= __('Select:')."\r
90 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,\r
91 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,\r
92 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,\r
93 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";\r
94\r
95 $reply .= " ";\r
96\r
97 $reply .= "<select dojoType=\"dijit.form.Select\"\r
98 onchange=\"headlineActionsChange(this)\">";\r
99 $reply .= "<option value=\"false\">".__('Actions...')."</option>";\r
100\r
101 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";\r
102\r
103 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>\r
104 <option value=\"$tog_marked_link\">".__('Starred')."</option>\r
105 <option value=\"$tog_published_link\">".__('Published')."</option>";\r
106\r
107 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";\r
108\r
109 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";\r
110\r
111 if ($feed_id != "0") {\r
112 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";\r
113 } else {\r
114 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";\r
115 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";\r
116\r
117 }\r
118\r
119 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').\r
120 "</option>";\r
121\r
79178062
AD
122 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";\r
123\r
124 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";\r
125\r
126 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";\r
127\r
128 $reply .= "</select>";\r
129\r
f1080825 130 //$reply .= "</div>";\r
79178062 131\r
f1080825 132 //$reply .= "</h2";\r
79178062
AD
133\r
134 return $reply;\r
135 }\r
136\r
137 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,\r
138 $next_unread_feed, $offset, $vgr_last_feed = false,\r
09101297 139 $override_order = false, $include_children = false) {\r
79178062
AD
140\r
141 $disable_cache = false;\r
142\r
143 $reply = array();\r
144\r
145 $timing_info = getmicrotime();\r
146\r
147 $topmost_article_ids = array();\r
148\r
149 if (!$offset) $offset = 0;\r
150 if ($method == "undefined") $method = "";\r
151\r
152 $method_split = explode(":", $method);\r
153\r
c0c2abba
AD
154 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {\r
155 // Update the feed if required with some basic flood control\r
156\r
157 $result = db_query($this->link,\r
d372d2bb 158 "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated\r
c0c2abba
AD
159 FROM ttrss_feeds WHERE id = '$feed'");\r
160\r
161 if (db_num_rows($result) != 0) {\r
162 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));\r
d372d2bb
AD
163 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));\r
164\r
b24504b1 165 if (!$cache_images && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) {\r
c0c2abba
AD
166 include "rssfuncs.php";\r
167 update_rss_feed($this->link, $feed, true, true);\r
168 }\r
169 }\r
3c696512 170 }\r
79178062 171\r
79178062
AD
172 if ($method_split[0] == "MarkAllReadGR") {\r
173 catchup_feed($this->link, $method_split[1], false);\r
174 }\r
175\r
176 // FIXME: might break tag display?\r
177\r
178 if (is_numeric($feed) && $feed > 0 && !$cat_view) {\r
179 $result = db_query($this->link,\r
180 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");\r
181\r
182 if (db_num_rows($result) == 0) {\r
183 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";\r
184 }\r
185 }\r
186\r
75c648cf 187 if (is_numeric($feed) && $feed > 0) {\r
79178062
AD
188\r
189 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r
190 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);\r
191\r
192 if (db_num_rows($result) == 1) {\r
193 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));\r
194 } else {\r
195 $rtl_content = false;\r
196 }\r
197\r
198 if ($rtl_content) {\r
199 $rtl_tag = "dir=\"RTL\"";\r
200 } else {\r
201 $rtl_tag = "";\r
202 }\r
203 } else {\r
204 $rtl_tag = "";\r
205 $rtl_content = false;\r
206 }\r
207\r
208 @$search = db_escape_string($_REQUEST["query"]);\r
209\r
210 if ($search) {\r
211 $disable_cache = true;\r
212 }\r
213\r
214 @$search_mode = db_escape_string($_REQUEST["search_mode"]);\r
215 @$match_on = db_escape_string($_REQUEST["match_on"]);\r
216\r
217 if (!$match_on) {\r
218 $match_on = "both";\r
219 }\r
220\r
221 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);\r
222\r
223// error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");\r
224 if( $search_mode == '' && $method != '' ){\r
225 $search_mode = $method;\r
226 }\r
227// error_log("search_mode: " . $search_mode);\r
228 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,\r
09101297
AD
229 $search, $search_mode, $match_on, $override_order, $offset, 0,\r
230 false, 0, $include_children);\r
79178062
AD
231\r
232 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);\r
233\r
234 $result = $qfh_ret[0];\r
235 $feed_title = $qfh_ret[1];\r
236 $feed_site_url = $qfh_ret[2];\r
237 $last_error = $qfh_ret[3];\r
238\r
239 $vgroup_last_feed = $vgr_last_feed;\r
240\r
241// if (!$offset) {\r
242\r
243 if (db_num_rows($result) > 0) {\r
244 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,\r
245 $feed_title,\r
246 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,\r
247 $last_error);\r
248 }\r
249// }\r
250\r
251 $headlines_count = db_num_rows($result);\r
252\r
1baac280
AD
253 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
254 $button_plugins = array();\r
255 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {\r
8b299a16 256 $pclass = "button_" . trim($p);\r
1baac280
AD
257\r
258 if (class_exists($pclass)) {\r
259 $plugin = new $pclass($link);\r
260 array_push($button_plugins, $plugin);\r
261 }\r
262 }\r
263 }\r
264\r
79178062
AD
265 if (db_num_rows($result) > 0) {\r
266\r
267 $lnum = $offset;\r
268\r
269 $num_unread = 0;\r
270 $cur_feed_title = '';\r
271\r
272 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;\r
273\r
274 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);\r
275\r
276 while ($line = db_fetch_assoc($result)) {\r
79178062
AD
277 $class = ($lnum % 2) ? "even" : "odd";\r
278\r
279 $id = $line["id"];\r
280 $feed_id = $line["feed_id"];\r
281 $label_cache = $line["label_cache"];\r
282 $labels = false;\r
30c337cf 283 $label_row_style = "";\r
79178062
AD
284\r
285 if ($label_cache) {\r
286 $label_cache = json_decode($label_cache, true);\r
287\r
288 if ($label_cache) {\r
289 if ($label_cache["no-labels"] == 1)\r
290 $labels = array();\r
02195b9d 291 else\r
79178062 292 $labels = $label_cache;\r
02195b9d
AD
293 }\r
294 }\r
295\r
296 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);\r
30c337cf 297\r
02195b9d
AD
298 if (count($labels) > 0) {\r
299 for ($i = 0; $i < min(4, count($labels)); $i++) {\r
300 $bg = rgb2hsl(_color_unpack($labels[$i][3]));\r
30c337cf 301\r
02195b9d
AD
302 if ($bg && $bg[1] > 0) {\r
303 $bg[1] = 0.1;\r
304 $bg[2] = 1;\r
305\r
306 $bg = _color_pack(hsl2rgb($bg));\r
307 $label_row_style = $this->make_gradient($bg, $class);;\r
308\r
309 break;\r
30c337cf 310 }\r
79178062
AD
311 }\r
312 }\r
313\r
79178062
AD
314 $labels_str = "<span id=\"HLLCTR-$id\">";\r
315 $labels_str .= format_article_labels($labels, $id);\r
316 $labels_str .= "</span>";\r
317\r
318 if (count($topmost_article_ids) < 3) {\r
319 array_push($topmost_article_ids, $id);\r
320 }\r
321\r
322 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {\r
323\r
324 $update_pic = "<img id='FUPDPIC-$id' src=\"".\r
325 theme_image($this->link, 'images/updated.png')."\"\r
326 alt=\"Updated\">";\r
327 } else {\r
328 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"\r
329 alt=\"Updated\">";\r
330 }\r
331\r
332 if (sql_bool_to_bool($line["unread"]) &&\r
333 time() - strtotime($line["updated_noms"]) < $fresh_intl) {\r
334\r
335 $update_pic = "<img id='FUPDPIC-$id' src=\"".\r
336 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";\r
337 }\r
338\r
339 if ($line["unread"] == "t" || $line["unread"] == "1") {\r
340 $class .= " Unread";\r
341 ++$num_unread;\r
342 $is_unread = true;\r
343 } else {\r
344 $is_unread = false;\r
345 }\r
346\r
347 if ($line["marked"] == "t" || $line["marked"] == "1") {\r
348 $marked_pic = "<img id=\"FMPIC-$id\"\r
349 src=\"".theme_image($this->link, 'images/mark_set.png')."\"\r
350 class=\"markedPic\" alt=\"Unstar article\"\r
351 onclick='javascript:toggleMark($id)'>";\r
352 } else {\r
353 $marked_pic = "<img id=\"FMPIC-$id\"\r
354 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"\r
355 class=\"markedPic\" alt=\"Star article\"\r
356 onclick='javascript:toggleMark($id)'>";\r
357 }\r
358\r
359 if ($line["published"] == "t" || $line["published"] == "1") {\r
360 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r
361 'images/pub_set.png')."\"\r
362 class=\"markedPic\"\r
363 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";\r
364 } else {\r
365 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r
366 'images/pub_unset.png')."\"\r
367 class=\"markedPic\"\r
368 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";\r
369 }\r
370\r
371# $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .\r
372# $line["title"] . "</a>";\r
373\r
374# $content_link = "<a\r
375# href=\"" . htmlspecialchars($line["link"]) . "\"\r
376# onclick=\"view($id,$feed_id);\">" .\r
377# $line["title"] . "</a>";\r
378\r
379# $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .\r
380# $line["title"] . "</a>";\r
381\r
382 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);\r
383\r
384 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r
d3253f49
AD
385 $content_preview = truncate_string(strip_tags($line["content_preview"]),\r
386 100);\r
79178062
AD
387 }\r
388\r
389 $score = $line["score"];\r
390\r
391 $score_pic = theme_image($this->link,\r
392 "images/" . get_score_pic($score));\r
393\r
394/* $score_title = __("(Click to change)");\r
395 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"\r
396 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */\r
397\r
398 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"\r
399 title=\"$score\">";\r
400\r
401 if ($score > 500) {\r
402 $hlc_suffix = "H";\r
403 } else if ($score < -100) {\r
404 $hlc_suffix = "L";\r
405 } else {\r
406 $hlc_suffix = "";\r
407 }\r
408\r
409 $entry_author = $line["author"];\r
410\r
411 if ($entry_author) {\r
412 $entry_author = " - $entry_author";\r
413 }\r
414\r
415 $has_feed_icon = feed_has_icon($feed_id);\r
416\r
417 if ($has_feed_icon) {\r
418 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
419 } else {\r
420 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";\r
421 }\r
422\r
423 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
424\r
425 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
426 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {\r
427\r
428 $cur_feed_title = $line["feed_title"];\r
429 $vgroup_last_feed = $feed_id;\r
430\r
431 $cur_feed_title = htmlspecialchars($cur_feed_title);\r
432\r
44245618 433 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
79178062
AD
434\r
435 $reply['content'] .= "<div class='cdmFeedTitle'>".\r
436 "<div style=\"float : right\">$feed_icon_img</div>".\r
437 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
438 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
439\r
440 }\r
441 }\r
442\r
443 $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
444 onmouseout='postMouseOut($id)'";\r
445\r
30c337cf 446 $reply['content'] .= "<div class='$class' id='RROW-$id' $label_row_style $mouseover_attrs>";\r
79178062
AD
447\r
448 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";\r
449\r
450 $reply['content'] .= "<div class='hlLeft'>";\r
451\r
452 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r
453 id=\"RCHK-$id\">";\r
454\r
455 $reply['content'] .= "$marked_pic";\r
456 $reply['content'] .= "$published_pic";\r
457\r
458 $reply['content'] .= "</div>";\r
459\r
460 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'\r
461 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";\r
462 $reply['content'] .= "<a id=\"RTITLE-$id\"\r
463 href=\"" . htmlspecialchars($line["link"]) . "\"\r
464 onclick=\"\">" .\r
d3253f49 465 truncate_string($line["title"], 200);\r
79178062
AD
466\r
467 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r
468 if ($content_preview) {\r
469 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";\r
470 }\r
471 }\r
472\r
473 $reply['content'] .= "</a></span>";\r
474\r
475 $reply['content'] .= $labels_str;\r
476\r
477 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
478 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
479 if (@$line["feed_title"]) {\r
480 $reply['content'] .= "<span class=\"hlFeed\">\r
481 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
482 $line["feed_title"]."</a>)\r
483 </span>";\r
484 }\r
485 }\r
486\r
487 $reply['content'] .= "</div>";\r
488\r
489 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";\r
490 $reply['content'] .= "<div class=\"hlRight\">";\r
491\r
492 $reply['content'] .= $score_pic;\r
493\r
494 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
495\r
496 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"\r
497 style=\"cursor : pointer\"\r
498 title=\"".htmlspecialchars($line['feed_title'])."\">\r
499 $feed_icon_img<span>";\r
500 }\r
501\r
502 $reply['content'] .= "</div>";\r
503 $reply['content'] .= "</div>";\r
504\r
505 } else {\r
506\r
507 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {\r
508 if ($feed_id != $vgroup_last_feed) {\r
509\r
510 $cur_feed_title = $line["feed_title"];\r
511 $vgroup_last_feed = $feed_id;\r
512\r
513 $cur_feed_title = htmlspecialchars($cur_feed_title);\r
514\r
515 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
516\r
517 $has_feed_icon = feed_has_icon($feed_id);\r
518\r
519 if ($has_feed_icon) {\r
520 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
521 } else {\r
522 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";\r
523 }\r
524\r
525 $reply['content'] .= "<div class='cdmFeedTitle'>".\r
526 "<div style=\"float : right\">$feed_icon_img</div>".\r
527 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
528 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
529 }\r
530 }\r
531\r
532 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');\r
533\r
534 $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
535 onmouseout='postMouseOut($id)'";\r
536\r
30c337cf 537 $reply['content'] .= "<div class=\"$class\" $label_row_style\r
79178062
AD
538 id=\"RROW-$id\" $mouseover_attrs'>";\r
539\r
540 $reply['content'] .= "<div class=\"cdmHeader\">";\r
541\r
542 $reply['content'] .= "<div>";\r
543\r
544 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r
545 'RROW-$id')\" id=\"RCHK-$id\"/>";\r
546\r
547 $reply['content'] .= "$marked_pic";\r
548 $reply['content'] .= "$published_pic";\r
549\r
550 $reply['content'] .= "</div>";\r
551\r
aa8b48a0 552 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .\r
5c568973 553 htmlspecialchars(strip_tags($line['title'])) . "</div>";\r
aa8b48a0 554\r
79178062
AD
555 $reply['content'] .= "<span id=\"RTITLE-$id\"\r
556 onclick=\"return cdmClicked(event, $id);\"\r
557 class=\"titleWrap$hlc_suffix\">\r
558 <a class=\"title\"\r
559 title=\"".htmlspecialchars($line['title'])."\"\r
560 target=\"_blank\" href=\"".\r
561 htmlspecialchars($line["link"])."\">".\r
b235e09b 562 $line["title"] .\r
79178062
AD
563 " $entry_author</a>";\r
564\r
565 $reply['content'] .= $labels_str;\r
566\r
567 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
568 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
569 if (@$line["feed_title"]) {\r
570 $reply['content'] .= "<span class=\"hlFeed\">\r
571 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
572 $line["feed_title"]."</a>)\r
573 </span>";\r
574 }\r
575 }\r
576\r
577 if (!$expand_cdm)\r
578 $content_hidden = "style=\"display : none\"";\r
579 else\r
580 $excerpt_hidden = "style=\"display : none\"";\r
581\r
582 $reply['content'] .= "<span $excerpt_hidden\r
583 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";\r
584\r
585 $reply['content'] .= "</span>";\r
586\r
587 $reply['content'] .= "<div>";\r
588 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";\r
589 $reply['content'] .= "$score_pic";\r
590\r
591 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {\r
592 $reply['content'] .= "<span style=\"cursor : pointer\"\r
593 title=\"".htmlspecialchars($line["feed_title"])."\"\r
594 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";\r
595 }\r
596 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";\r
597 $reply['content'] .= "</div>";\r
598\r
599 $reply['content'] .= "</div>";\r
600\r
601 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden\r
602 onclick=\"return cdmClicked(event, $id);\"\r
603 id=\"CICD-$id\">";\r
604\r
605 $reply['content'] .= "<div class=\"cdmContentInner\">";\r
606\r
607 if ($line["orig_feed_id"]) {\r
608\r
609 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r
610 WHERE id = ".$line["orig_feed_id"]);\r
611\r
612 if (db_num_rows($tmp_result) != 0) {\r
613\r
614 $reply['content'] .= "<div clear='both'>";\r
615 $reply['content'] .= __("Originally from:");\r
616\r
617 $reply['content'] .= "&nbsp;";\r
618\r
619 $tmp_line = db_fetch_assoc($tmp_result);\r
620\r
621 $reply['content'] .= "<a target='_blank'\r
622 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .\r
623 $tmp_line['title'] . "</a>";\r
624\r
625 $reply['content'] .= "&nbsp;";\r
626\r
627 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";\r
11cb9506 628 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";\r
79178062
AD
629\r
630 $reply['content'] .= "</div>";\r
631 }\r
632 }\r
633\r
b3682750
AD
634 $feed_site_url = $line["site_url"];\r
635\r
636 $article_content = sanitize($this->link, $line["content_preview"],\r
637 false, false, $feed_site_url);\r
79178062
AD
638\r
639 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";\r
640 if ($line['note']) {\r
641 $reply['content'] .= format_article_note($id, $line['note']);\r
642 }\r
643 $reply['content'] .= "</div>";\r
644\r
645 $reply['content'] .= "<span id=\"CWRAP-$id\">";\r
09c816ca 646 $reply['content'] .= $article_content;\r
79178062
AD
647 $reply['content'] .= "</span>";\r
648\r
649/* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM\r
650 ttrss_feeds WHERE id = ".\r
651 (($line['feed_id'] == null) ? $line['orig_feed_id'] :\r
652 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);\r
653\r
654 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,\r
655 0, "always_display_enclosures")); */\r
656\r
657 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);\r
658\r
659 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,\r
660 $article_content);\r
661\r
662 $reply['content'] .= "</div>";\r
663\r
664 $reply['content'] .= "<div class=\"cdmFooter\">";\r
665\r
666 $tag_cache = $line["tag_cache"];\r
667\r
668 $tags_str = format_tags_string(\r
669 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),\r
670 $id);\r
671\r
672 $reply['content'] .= "<img src='".theme_image($this->link,\r
673 'images/tag.png')."' alt='Tags' title='Tags'>\r
674 <span id=\"ATSTR-$id\">$tags_str</span>\r
675 <a title=\"".__('Edit tags for this article')."\"\r
676 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";\r
677\r
678 $num_comments = $line["num_comments"];\r
679 $entry_comments = "";\r
680\r
681 if ($num_comments > 0) {\r
682 if ($line["comments"]) {\r
6e577ba1 683 $comments_url = htmlspecialchars($line["comments"]);\r
79178062 684 } else {\r
6e577ba1 685 $comments_url = htmlspecialchars($line["link"]);\r
79178062
AD
686 }\r
687 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";\r
688 } else {\r
689 if ($line["comments"] && $line["link"] != $line["comments"]) {\r
6e577ba1 690 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";\r
79178062
AD
691 }\r
692 }\r
693\r
694 if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";\r
695\r
696 $reply['content'] .= "<div style=\"float : right\">";\r
697\r
698 $reply['content'] .= "<img src=\"images/art-zoom.png\"\r
699 onclick=\"zoomToArticle(event, $id)\"\r
700 style=\"cursor : pointer\"\r
701 alt='Zoom'\r
702 title='".__('Open article in new tab')."'>";\r
703\r
704 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);\r
705\r
f9ac31d6 706 foreach ($button_plugins as $p) {\r
1baac280 707 $reply['content'] .= $p->render($id, $line);\r
79178062
AD
708 }\r
709\r
79178062
AD
710 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r
711 style=\"cursor : pointer\" style=\"cursor : pointer\"\r
712 onclick=\"dismissArticle($id)\"\r
638e27c8 713 title='".__('Close article')."'>";\r
79178062
AD
714\r
715 $reply['content'] .= "</div>";\r
716 $reply['content'] .= "</div>";\r
717\r
718 $reply['content'] .= "</div>";\r
719\r
720 $reply['content'] .= "</div>";\r
721\r
722 }\r
723\r
724 ++$lnum;\r
725 }\r
726\r
727 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);\r
728\r
729 } else {\r
730 $message = "";\r
731\r
732 switch ($view_mode) {\r
733 case "unread":\r
734 $message = __("No unread articles found to display.");\r
735 break;\r
736 case "updated":\r
737 $message = __("No updated articles found to display.");\r
738 break;\r
739 case "marked":\r
740 $message = __("No starred articles found to display.");\r
741 break;\r
742 default:\r
743 if ($feed < -10) {\r
744 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");\r
745 } else {\r
746 $message = __("No articles found to display.");\r
747 }\r
748 }\r
749\r
750 if (!$offset && $message) {\r
751 $reply['content'] .= "<div class='whiteBox'>$message";\r
752\r
753 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";\r
754\r
755 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r
756 WHERE owner_uid = " . $_SESSION['uid']);\r
757\r
758 $last_updated = db_fetch_result($result, 0, "last_updated");\r
759 $last_updated = make_local_datetime($this->link, $last_updated, false);\r
760\r
761 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);\r
762\r
763 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r
764 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);\r
765\r
766 $num_errors = db_fetch_result($result, 0, "num_errors");\r
767\r
768 if ($num_errors > 0) {\r
769 $reply['content'] .= "<br/>";\r
770 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".\r
771 __('Some feeds have update errors (click for details)')."</a>";\r
772 }\r
773 $reply['content'] .= "</span></p></div>";\r
774 }\r
775 }\r
776\r
777 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);\r
778\r
779 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,\r
780 $vgroup_last_feed, $reply);\r
781 }\r
782\r
3f363052
AD
783 function catchupAll() {\r
784 db_query($this->link, "UPDATE ttrss_user_entries SET\r
785 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);\r
786 ccache_zero_all($this->link, $_SESSION["uid"]);\r
46da73c2 787 }\r
3f363052
AD
788\r
789 function collapse() {\r
790 $cat_id = db_escape_string($_REQUEST["cid"]);\r
791 $mode = (int) db_escape_string($_REQUEST['mode']);\r
792 toggle_collapse_cat($this->link, $cat_id, $mode);\r
793 }\r
794\r
3f363052
AD
795 function view() {\r
796 $timing_info = getmicrotime();\r
46da73c2 797\r
3f363052 798 $reply = array();\r
46da73c2 799\r
3f363052 800 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);\r
46da73c2 801\r
3f363052 802 $omode = db_escape_string($_REQUEST["omode"]);\r
46da73c2 803\r
3f363052
AD
804 $feed = db_escape_string($_REQUEST["feed"]);\r
805 $method = db_escape_string($_REQUEST["m"]);\r
806 $view_mode = db_escape_string($_REQUEST["view_mode"]);\r
807 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");\r
09101297 808 @$cat_view = $_REQUEST["cat"] == "true";\r
3f363052
AD
809 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);\r
810 @$offset = db_escape_string($_REQUEST["skip"]);\r
811 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);\r
812 $order_by = db_escape_string($_REQUEST["order_by"]);\r
46da73c2 813\r
3f363052 814 if (is_numeric($feed)) $feed = (int) $feed;\r
46da73c2 815\r
3f363052
AD
816 /* Feed -5 is a special case: it is used to display auxiliary information\r
817 * when there's nothing to load - e.g. no stuff in fresh feed */\r
46da73c2 818\r
3f363052
AD
819 if ($feed == -5) {\r
820 print json_encode(generate_dashboard_feed($this->link));\r
821 return;\r
822 }\r
46da73c2 823\r
3f363052 824 $result = false;\r
46da73c2 825\r
3f363052
AD
826 if ($feed < -10) {\r
827 $label_feed = -11-$feed;\r
828 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r
829 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);\r
830 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {\r
831 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r
832 id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
833 } else if ($cat_view && is_numeric($feed) && $feed > 0) {\r
834 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r
835 id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
836 }\r
46da73c2 837\r
3f363052
AD
838 if ($result && db_num_rows($result) == 0) {\r
839 print json_encode(generate_error_feed($this->link, __("Feed not found.")));\r
840 return;\r
841 }\r
46da73c2 842\r
3f363052
AD
843 /* Updating a label ccache means recalculating all of the caches\r
844 * so for performance reasons we don't do that here */\r
46da73c2 845\r
3f363052
AD
846 if ($feed >= 0) {\r
847 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);\r
848 }\r
46da73c2 849\r
3f363052
AD
850 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);\r
851 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);\r
852 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);\r
854a2ace 853\r
75c648cf 854 if (!$cat_view && is_numeric($feed) && $feed > 0) {\r
3f363052
AD
855 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r
856 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);\r
857 }\r
46da73c2 858\r
3f363052 859 $reply['headlines'] = array();\r
46da73c2 860\r
3f363052
AD
861 if (!$next_unread_feed)\r
862 $reply['headlines']['id'] = $feed;\r
863 else\r
864 $reply['headlines']['id'] = $next_unread_feed;\r
46da73c2 865\r
3f363052 866 $reply['headlines']['is_cat'] = (bool) $cat_view;\r
46da73c2 867\r
3f363052 868 $override_order = false;\r
46da73c2 869\r
3f363052
AD
870 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {\r
871 $date_sort_field = "updated";\r
872 } else {\r
873 $date_sort_field = "date_entered";\r
874 }\r
46da73c2 875\r
3f363052
AD
876 switch ($order_by) {\r
877 case "date":\r
878 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
879 $override_order = "$date_sort_field";\r
880 } else {\r
881 $override_order = "$date_sort_field DESC";\r
882 }\r
883 break;\r
46da73c2 884\r
3f363052
AD
885 case "title":\r
886 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
887 $override_order = "title DESC, $date_sort_field";\r
888 } else {\r
889 $override_order = "title, $date_sort_field DESC";\r
890 }\r
891 break;\r
46da73c2 892\r
3f363052
AD
893 case "score":\r
894 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
895 $override_order = "score, $date_sort_field";\r
896 } else {\r
897 $override_order = "score DESC, $date_sort_field DESC";\r
898 }\r
899 break;\r
900 }\r
46da73c2 901\r
3f363052 902 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);\r
46da73c2 903\r
79178062 904 $ret = $this->format_headlines_list($feed, $method,\r
3f363052 905 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,\r
0ef32f48 906 $vgroup_last_feed, $override_order, true);\r
46da73c2 907\r
3f363052
AD
908 $topmost_article_ids = $ret[0];\r
909 $headlines_count = $ret[1];\r
910 $returned_feed = $ret[2];\r
911 $disable_cache = $ret[3];\r
912 $vgroup_last_feed = $ret[4];\r
46da73c2 913\r
3f363052
AD
914 $reply['headlines']['content'] =& $ret[5]['content'];\r
915 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];\r
46da73c2 916\r
3f363052 917 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);\r
46da73c2 918\r
3f363052
AD
919 $reply['headlines-info'] = array("count" => (int) $headlines_count,\r
920 "vgroup_last_feed" => $vgroup_last_feed,\r
921 "disable_cache" => (bool) $disable_cache);\r
46da73c2 922\r
3f363052 923 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);\r
46da73c2 924\r
3f363052
AD
925 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {\r
926 $articles = array();\r
46da73c2 927\r
3f363052
AD
928 foreach ($topmost_article_ids as $id) {\r
929 array_push($articles, format_article($this->link, $id, false));\r
930 }\r
46da73c2 931\r
3f363052
AD
932 $reply['articles'] = $articles;\r
933 }\r
46da73c2 934\r
3f363052 935 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);\r
46da73c2 936\r
3f363052 937 $reply['runtime-info'] = make_runtime_info($this->link);\r
46da73c2 938\r
3f363052 939 print json_encode($reply);\r
46da73c2 940\r
3f363052
AD
941 }\r
942}\r
46da73c2 943?>\r