]> git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
d2df9410813feaf05a75c96a461ff13066cc3bfa
[tt-rss.git] / classes / feeds.php
1 <?php
2 require_once "colors.php";
3
4 class Feeds extends Handler_Protected {
5
6 function csrf_ignore($method) {
7 $csrf_ignored = array("index", "feedbrowser", "quickaddfeed", "search");
8
9 return array_search($method, $csrf_ignored) !== false;
10 }
11
12 private function make_gradient($end, $class) {
13 $start = $class == "even" ? "#f0f0f0" : "#ffffff";
14
15 return "style='background: linear-gradient(left , $start 6%, $end 100%);
16 background: -o-linear-gradient(left , $start 6%, $end 100%);
17 background: -moz-linear-gradient(left , $start 6%, $end 100%);
18 background: -webkit-linear-gradient(left , $start 6%, $end 100%);
19 background: -ms-linear-gradient(left , $start 6%, $end 100%);
20 background: -webkit-gradient(linear, left top, right top,
21 color-stop(0.06, $start), color-stop(1, $end));'";
22 }
23
24 private function format_headline_subtoolbar($feed_site_url, $feed_title,
25 $feed_id, $is_cat, $search,
26 $search_mode, $view_mode, $error) {
27
28 $page_prev_link = "viewFeedGoPage(-1)";
29 $page_next_link = "viewFeedGoPage(1)";
30 $page_first_link = "viewFeedGoPage(0)";
31
32 $catchup_page_link = "catchupPage()";
33 $catchup_feed_link = "catchupCurrentFeed()";
34 $catchup_sel_link = "catchupSelection()";
35
36 $archive_sel_link = "archiveSelection()";
37 $delete_sel_link = "deleteSelection()";
38
39 $sel_all_link = "selectArticles('all')";
40 $sel_unread_link = "selectArticles('unread')";
41 $sel_none_link = "selectArticles('none')";
42 $sel_inv_link = "selectArticles('invert')";
43
44 $tog_unread_link = "selectionToggleUnread()";
45 $tog_marked_link = "selectionToggleMarked()";
46 $tog_published_link = "selectionTogglePublished()";
47
48 $set_score_link = "setSelectionScore()";
49
50 if ($is_cat) $cat_q = "&is_cat=$is_cat";
51
52 if ($search) {
53 $search_q = "&q=$search&smode=$search_mode";
54 } else {
55 $search_q = "";
56 }
57
58 $rss_link = htmlspecialchars(get_self_url_prefix() .
59 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
60
61 // right part
62
63 $reply .= "<span class='r'>";
64 $reply .= "<span id='feed_title'>";
65
66 if ($feed_site_url) {
67 $target = "target=\"_blank\"";
68 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
69 truncate_string($feed_title,30)."</a>";
70
71 if ($error) {
72 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
73 }
74
75 } else {
76 $reply .= $feed_title;
77 }
78
79 $reply .= "</span>";
80
81 $reply .= "
82 <a href=\"#\"
83 title=\"".__("View as RSS feed")."\"
84 onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
85 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/pub_set.svg\"></a>";
86
87 $reply .= "</span>";
88
89 // left part
90
91 $reply .= __('Select:')."
92 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
93 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
94 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
95 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
96
97 $reply .= " ";
98
99 $reply .= "<select dojoType=\"dijit.form.Select\"
100 onchange=\"headlineActionsChange(this)\">";
101 $reply .= "<option value=\"false\">".__('More...')."</option>";
102
103 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
104
105 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
106 <option value=\"$tog_marked_link\">".__('Starred')."</option>
107 <option value=\"$tog_published_link\">".__('Published')."</option>";
108
109 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
110
111 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
112 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
113
114 if ($feed_id != "0") {
115 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
116 } else {
117 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
118 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
119
120 }
121
122 global $pluginhost;
123
124 if ($pluginhost->get_plugin("mail")) {
125 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
126 "</option>";
127 }
128
129 if ($pluginhost->get_plugin("mailto")) {
130 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
131 "</option>";
132 }
133
134 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
135
136 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
137
138 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
139
140 $reply .= "</select>";
141
142 //$reply .= "</div>";
143
144 //$reply .= "</h2";
145
146 return $reply;
147 }
148
149 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
150 $next_unread_feed, $offset, $vgr_last_feed = false,
151 $override_order = false, $include_children = false) {
152
153 if (isset($_REQUEST["DevForceUpdate"]))
154 header("Content-Type: text/plain");
155
156 $disable_cache = false;
157
158 $reply = array();
159
160 $timing_info = microtime(true);
161
162 $topmost_article_ids = array();
163
164 if (!$offset) $offset = 0;
165 if ($method == "undefined") $method = "";
166
167 $method_split = explode(":", $method);
168
169 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
170 // Update the feed if required with some basic flood control
171
172 $result = db_query($this->link,
173 "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
174 FROM ttrss_feeds WHERE id = '$feed'");
175
176 if (db_num_rows($result) != 0) {
177 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
178 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
179
180 if (!$cache_images && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) {
181 include "rssfuncs.php";
182 update_rss_feed($this->link, $feed, true, true);
183 } else {
184 db_query($this->link, "UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
185 WHERE id = '$feed'");
186 }
187 }
188 }
189
190 if ($method_split[0] == "MarkAllReadGR") {
191 catchup_feed($this->link, $method_split[1], false);
192 }
193
194 // FIXME: might break tag display?
195
196 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
197 $result = db_query($this->link,
198 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
199
200 if (db_num_rows($result) == 0) {
201 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
202 }
203 }
204
205 @$search = db_escape_string($this->link, $_REQUEST["query"]);
206
207 if ($search) {
208 $disable_cache = true;
209 }
210
211 @$search_mode = db_escape_string($this->link, $_REQUEST["search_mode"]);
212
213 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
214
215 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
216 if( $search_mode == '' && $method != '' ){
217 $search_mode = $method;
218 }
219 // error_log("search_mode: " . $search_mode);
220
221 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
222 global $pluginhost;
223
224 $handler = $pluginhost->get_feed_handler(
225 PluginHost::feed_to_pfeed_id($feed));
226
227 // function queryFeedHeadlines($link, $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) {
228
229 if ($handler) {
230 $options = array(
231 "limit" => $limit,
232 "view_mode" => $view_mode,
233 "cat_view" => $cat_view,
234 "search" => $search,
235 "search_mode" => $search_mode,
236 "override_order" => $override_order,
237 "offset" => $offset,
238 "owner_uid" => $_SESSION["uid"],
239 "filter" => false,
240 "since_id" => 0,
241 "include_children" => $include_children);
242
243 $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
244 $options);
245 }
246
247 } else {
248 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
249 $search, $search_mode, $override_order, $offset, 0,
250 false, 0, $include_children);
251 }
252
253 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
254
255 $result = $qfh_ret[0];
256 $feed_title = $qfh_ret[1];
257 $feed_site_url = $qfh_ret[2];
258 $last_error = $qfh_ret[3];
259
260 $vgroup_last_feed = $vgr_last_feed;
261
262 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
263 $feed_title,
264 $feed, $cat_view, $search, $search_mode, $view_mode,
265 $last_error);
266
267 $headlines_count = db_num_rows($result);
268
269 /* if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
270 $button_plugins = array();
271 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
272 $pclass = "button_" . trim($p);
273
274 if (class_exists($pclass)) {
275 $plugin = new $pclass($link);
276 array_push($button_plugins, $plugin);
277 }
278 }
279 } */
280
281 global $pluginhost;
282
283 if (db_num_rows($result) > 0) {
284
285 $lnum = $offset;
286
287 $num_unread = 0;
288 $cur_feed_title = '';
289
290 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
291
292 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
293
294 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
295
296 while ($line = db_fetch_assoc($result)) {
297 $class = ($lnum % 2) ? "even" : "odd";
298
299 $id = $line["id"];
300 $feed_id = $line["feed_id"];
301 $label_cache = $line["label_cache"];
302 $labels = false;
303 $label_row_style = "";
304
305 if ($label_cache) {
306 $label_cache = json_decode($label_cache, true);
307
308 if ($label_cache) {
309 if ($label_cache["no-labels"] == 1)
310 $labels = array();
311 else
312 $labels = $label_cache;
313 }
314 }
315
316 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
317
318 if (count($labels) > 0) {
319 for ($i = 0; $i < min(4, count($labels)); $i++) {
320 $bg = rgb2hsl(_color_unpack($labels[$i][3]));
321
322 if ($bg && $bg[1] > 0) {
323 $bg[1] = 0.1;
324 $bg[2] = 1;
325
326 $bg = _color_pack(hsl2rgb($bg));
327 $label_row_style = $this->make_gradient($bg, $class);;
328
329 break;
330 }
331 }
332 }
333
334 $labels_str = "<span id=\"HLLCTR-$id\">";
335 $labels_str .= format_article_labels($labels, $id);
336 $labels_str .= "</span>";
337
338 if (count($topmost_article_ids) < 3) {
339 array_push($topmost_article_ids, $id);
340 }
341
342 if ($line["unread"] == "t" || $line["unread"] == "1") {
343 $class .= " Unread";
344 ++$num_unread;
345 $is_unread = true;
346 } else {
347 $is_unread = false;
348 }
349
350 if ($line["marked"] == "t" || $line["marked"] == "1") {
351 $marked_pic = "<img id=\"FMPIC-$id\"
352 src=\"images/mark_set.svg\"
353 class=\"markedPic\" alt=\"Unstar article\"
354 onclick='javascript:toggleMark($id)'>";
355 } else {
356 $marked_pic = "<img id=\"FMPIC-$id\"
357 src=\"images/mark_unset.svg\"
358 class=\"markedPic\" alt=\"Star article\"
359 onclick='javascript:toggleMark($id)'>";
360 }
361
362 if ($line["published"] == "t" || $line["published"] == "1") {
363 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.svg\"
364 class=\"markedPic\"
365 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
366 } else {
367 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.svg\"
368 class=\"markedPic\"
369 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
370 }
371
372 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
373 # $line["title"] . "</a>";
374
375 # $content_link = "<a
376 # href=\"" . htmlspecialchars($line["link"]) . "\"
377 # onclick=\"view($id,$feed_id);\">" .
378 # $line["title"] . "</a>";
379
380 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
381 # $line["title"] . "</a>";
382
383 $updated_fmt = make_local_datetime($this->link, $line["updated"], false);
384 $date_entered_fmt = T_sprintf("Imported at %s",
385 make_local_datetime($this->link, $line["date_entered"], false));
386
387 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
388 $content_preview = truncate_string(strip_tags($line["content_preview"]),
389 100);
390 }
391
392 $score = $line["score"];
393
394 $score_pic = "images/" . get_score_pic($score);
395
396 /* $score_title = __("(Click to change)");
397 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
398 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
399
400 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
401 title=\"$score\">";
402
403 if ($score > 500) {
404 $hlc_suffix = "H";
405 } else if ($score < -100) {
406 $hlc_suffix = "L";
407 } else {
408 $hlc_suffix = "";
409 }
410
411 $entry_author = $line["author"];
412
413 if ($entry_author) {
414 $entry_author = " - $entry_author";
415 }
416
417 $has_feed_icon = feed_has_icon($feed_id);
418
419 if ($has_feed_icon) {
420 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
421 } else {
422 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.svg\" alt=\"\">";
423 }
424
425 $entry_site_url = $line["site_url"];
426
427 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
428
429 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
430 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
431
432 $cur_feed_title = $line["feed_title"];
433 $vgroup_last_feed = $feed_id;
434
435 $cur_feed_title = htmlspecialchars($cur_feed_title);
436
437 $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
438
439 $reply['content'] .= "<div class='cdmFeedTitle'>".
440 "<div style=\"float : right\">$feed_icon_img</div>".
441 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
442 $line["feed_title"]."</a> $vf_catchup_link</div>";
443
444 }
445 }
446
447 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
448 onmouseout='postMouseOut($id)'";
449
450 $reply['content'] .= "<div class='hl $class' id='RROW-$id' $label_row_style $mouseover_attrs>";
451
452 $reply['content'] .= "<div class='hlLeft'>";
453
454 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
455 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
456 id=\"RCHK-$id\">";
457
458 $reply['content'] .= "$marked_pic";
459 $reply['content'] .= "$published_pic";
460
461 $reply['content'] .= "</div>";
462
463 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
464 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
465 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title\"
466 href=\"" . htmlspecialchars($line["link"]) . "\"
467 onclick=\"\">" .
468 truncate_string($line["title"], 200);
469
470 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
471 if ($content_preview) {
472 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
473 }
474 }
475
476 $reply['content'] .= "</a></span>";
477
478 $reply['content'] .= $labels_str;
479
480 $reply['content'] .= "</div>";
481
482 $reply['content'] .= "<span class=\"hlUpdated\">";
483
484 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
485 if (@$line["feed_title"]) {
486 $reply['content'] .= "<div class=\"hlFeed\">
487 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
488 truncate_string($line["feed_title"],30)."</a>
489 </div>";
490 }
491 }
492
493 $reply['content'] .= "<span title='$date_entered_fmt'>$updated_fmt</span>
494 </span>";
495
496 $reply['content'] .= "<div class=\"hlRight\">";
497
498 $reply['content'] .= $score_pic;
499
500 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
501
502 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
503 style=\"cursor : pointer\"
504 title=\"".htmlspecialchars($line['feed_title'])."\">
505 $feed_icon_img<span>";
506 }
507
508 $reply['content'] .= "</div>";
509 $reply['content'] .= "</div>";
510
511 } else {
512
513 $line["tags"] = get_article_tags($this->link, $id, $_SESSION["uid"], $line["tag_cache"]);
514 unset($line["tag_cache"]);
515
516 $line["content"] = sanitize($this->link, $line["content_preview"],
517 sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
518
519 foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM) as $p) {
520 $line = $p->hook_render_article_cdm($line);
521 }
522
523 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
524 if ($feed_id != $vgroup_last_feed) {
525
526 $cur_feed_title = $line["feed_title"];
527 $vgroup_last_feed = $feed_id;
528
529 $cur_feed_title = htmlspecialchars($cur_feed_title);
530
531 $vf_catchup_link = "(<a class='catchup' onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
532
533 $has_feed_icon = feed_has_icon($feed_id);
534
535 if ($has_feed_icon) {
536 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
537 } else {
538 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
539 }
540
541 $reply['content'] .= "<div class='cdmFeedTitle'>".
542 "<div style=\"float : right\">$feed_icon_img</div>".
543 "<a href=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
544 $line["feed_title"]."</a> $vf_catchup_link</div>";
545 }
546 }
547
548 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
549 onmouseout='postMouseOut($id)'";
550
551 $expanded_class = $expand_cdm ? "expanded" : "expandable";
552
553 $reply['content'] .= "<div class=\"cdm $expanded_class $class\"
554 id=\"RROW-$id\" $mouseover_attrs'>";
555
556 $reply['content'] .= "<div class=\"cdmHeader\">";
557
558 $reply['content'] .= "<div style=\"vertical-align : middle\">";
559
560 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
561 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
562 id=\"RCHK-$id\">";
563
564 $reply['content'] .= "$marked_pic";
565 $reply['content'] .= "$published_pic";
566
567 $reply['content'] .= "</div>";
568
569 $reply['content'] .= "<span id=\"RTITLE-$id\"
570 onclick=\"return cdmClicked(event, $id);\"
571 class=\"titleWrap$hlc_suffix\">
572 <a class=\"title\"
573 target=\"_blank\" href=\"".
574 htmlspecialchars($line["link"])."\">".
575 $line["title"] .
576 " <span class=\"author\">$entry_author</span></a>";
577
578 $reply['content'] .= $labels_str;
579
580 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
581 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
582 title=\"".__("Collapse article")."\"/></span>";
583
584 if (!$expand_cdm)
585 $content_hidden = "style=\"display : none\"";
586 else
587 $excerpt_hidden = "style=\"display : none\"";
588
589 $reply['content'] .= "<span $excerpt_hidden
590 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
591 $reply['content'] .= "</span>";
592
593 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
594 if (@$line["feed_title"]) {
595 $reply['content'] .= "<div class=\"hlFeed\">
596 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
597 truncate_string($line["feed_title"],30)."</a>
598 </div>";
599 }
600 }
601
602 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
603 $updated_fmt</span>";
604
605 $reply['content'] .= "<div style=\"vertical-align : middle\">";
606 $reply['content'] .= "$score_pic";
607
608 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
609 $reply['content'] .= "<span style=\"cursor : pointer\"
610 title=\"".htmlspecialchars($line["feed_title"])."\"
611 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
612 }
613 $reply['content'] .= "</div>";
614
615 $reply['content'] .= "</div>";
616
617 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
618 onclick=\"return cdmClicked(event, $id);\"
619 id=\"CICD-$id\">";
620
621 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
622 if ($line['note']) {
623 $reply['content'] .= format_article_note($id, $line['note']);
624 }
625 $reply['content'] .= "</div>";
626
627
628 $reply['content'] .= "<div class=\"cdmContentInner\">";
629
630 if ($line["orig_feed_id"]) {
631
632 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
633 WHERE id = ".$line["orig_feed_id"]);
634
635 if (db_num_rows($tmp_result) != 0) {
636
637 $reply['content'] .= "<div clear='both'>";
638 $reply['content'] .= __("Originally from:");
639
640 $reply['content'] .= "&nbsp;";
641
642 $tmp_line = db_fetch_assoc($tmp_result);
643
644 $reply['content'] .= "<a target='_blank'
645 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
646 $tmp_line['title'] . "</a>";
647
648 $reply['content'] .= "&nbsp;";
649
650 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
651 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.svg'></a>";
652
653 $reply['content'] .= "</div>";
654 }
655 }
656
657 $reply['content'] .= "<span id=\"CWRAP-$id\">";
658
659 // if (!$expand_cdm) {
660 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
661 $reply['content'] .= htmlspecialchars($line["content"]);
662 $reply['content'] .= "</span.";
663
664 // } else {
665 // $reply['content'] .= $line["content"];
666 // }
667
668 $reply['content'] .= "</span>";
669
670 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
671
672 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
673
674 $reply['content'] .= "</div>";
675
676 $reply['content'] .= "<div class=\"cdmFooter\">";
677
678 $tags_str = format_tags_string($line["tags"], $id);
679
680 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
681 <span id=\"ATSTR-$id\">$tags_str</span>
682 <a title=\"".__('Edit tags for this article')."\"
683 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
684
685 $num_comments = $line["num_comments"];
686 $entry_comments = "";
687
688 if ($num_comments > 0) {
689 if ($line["comments"]) {
690 $comments_url = htmlspecialchars($line["comments"]);
691 } else {
692 $comments_url = htmlspecialchars($line["link"]);
693 }
694 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
695 } else {
696 if ($line["comments"] && $line["link"] != $line["comments"]) {
697 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
698 }
699 }
700
701 if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";
702
703 $reply['content'] .= "<div style=\"float : right\">";
704
705 foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
706 $reply['content'] .= $p->hook_article_button($line);
707 }
708
709 $reply['content'] .= "</div>";
710 $reply['content'] .= "</div>";
711
712 $reply['content'] .= "</div>";
713
714 $reply['content'] .= "</div>";
715
716 }
717
718 ++$lnum;
719 }
720
721 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
722
723 } else {
724 $message = "";
725
726 switch ($view_mode) {
727 case "unread":
728 $message = __("No unread articles found to display.");
729 break;
730 case "updated":
731 $message = __("No updated articles found to display.");
732 break;
733 case "marked":
734 $message = __("No starred articles found to display.");
735 break;
736 default:
737 if ($feed < LABEL_BASE_INDEX) {
738 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
739 } else {
740 $message = __("No articles found to display.");
741 }
742 }
743
744 if (!$offset && $message) {
745 $reply['content'] .= "<div class='whiteBox'>$message";
746
747 $reply['content'] .= "<p><span class=\"insensitive\">";
748
749 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
750 WHERE owner_uid = " . $_SESSION['uid']);
751
752 $last_updated = db_fetch_result($result, 0, "last_updated");
753 $last_updated = make_local_datetime($this->link, $last_updated, false);
754
755 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
756
757 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
758 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
759
760 $num_errors = db_fetch_result($result, 0, "num_errors");
761
762 if ($num_errors > 0) {
763 $reply['content'] .= "<br/>";
764 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
765 __('Some feeds have update errors (click for details)')."</a>";
766 }
767 $reply['content'] .= "</span></p></div>";
768 }
769 }
770
771 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
772
773 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
774 $vgroup_last_feed, $reply);
775 }
776
777 function catchupAll() {
778 db_query($this->link, "UPDATE ttrss_user_entries SET
779 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
780 ccache_zero_all($this->link, $_SESSION["uid"]);
781 }
782
783 function view() {
784 $timing_info = microtime(true);
785
786 $reply = array();
787
788 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
789
790 $omode = db_escape_string($this->link, $_REQUEST["omode"]);
791
792 $feed = db_escape_string($this->link, $_REQUEST["feed"]);
793 $method = db_escape_string($this->link, $_REQUEST["m"]);
794 $view_mode = db_escape_string($this->link, $_REQUEST["view_mode"]);
795 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
796 @$cat_view = $_REQUEST["cat"] == "true";
797 @$next_unread_feed = db_escape_string($this->link, $_REQUEST["nuf"]);
798 @$offset = db_escape_string($this->link, $_REQUEST["skip"]);
799 @$vgroup_last_feed = db_escape_string($this->link, $_REQUEST["vgrlf"]);
800 $order_by = db_escape_string($this->link, $_REQUEST["order_by"]);
801
802 if (is_numeric($feed)) $feed = (int) $feed;
803
804 /* Feed -5 is a special case: it is used to display auxiliary information
805 * when there's nothing to load - e.g. no stuff in fresh feed */
806
807 if ($feed == -5) {
808 print json_encode($this->generate_dashboard_feed($this->link));
809 return;
810 }
811
812 $result = false;
813
814 if ($feed < LABEL_BASE_INDEX) {
815 $label_feed = feed_to_label_id($feed);
816 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
817 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
818 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
819 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
820 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
821 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
822 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
823 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
824 }
825
826 if ($result && db_num_rows($result) == 0) {
827 print json_encode($this->generate_error_feed($this->link, __("Feed not found.")));
828 return;
829 }
830
831 /* Updating a label ccache means recalculating all of the caches
832 * so for performance reasons we don't do that here */
833
834 if ($feed >= 0) {
835 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
836 }
837
838 /* if (is_numeric($feed) && $feed > 0) {
839 $view_settings = db_escape_string($this->link, json_encode(array(
840 "view_mode" => $view_mode, "order_by" => $order_by)));
841
842 $table = $cat_view ? "ttrss_feed_categories" : "ttrss_feeds";
843
844 db_query($this->link, "UPDATE $table SET view_settings = '$view_settings'
845 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
846 } else {
847 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
848 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
849 } */
850
851 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
852 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
853
854 /* bump login timestamp if needed */
855 if (time() - $_SESSION["last_login_update"] > 3600) {
856 db_query($this->link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
857 $_SESSION["uid"]);
858 $_SESSION["last_login_update"] = time();
859 }
860
861 if (!$cat_view && is_numeric($feed) && $feed > 0) {
862 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
863 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
864 }
865
866 $reply['headlines'] = array();
867
868 if (!$next_unread_feed)
869 $reply['headlines']['id'] = $feed;
870 else
871 $reply['headlines']['id'] = $next_unread_feed;
872
873 $reply['headlines']['is_cat'] = (bool) $cat_view;
874
875 $override_order = false;
876
877 switch ($order_by) {
878 case "date_reverse":
879 $override_order = "date_entered, updated";
880 break;
881 case "feed_dates":
882 $override_order = "updated DESC";
883 break;
884 }
885
886 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
887
888 $ret = $this->format_headlines_list($feed, $method,
889 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
890 $vgroup_last_feed, $override_order, true);
891
892 //$topmost_article_ids = $ret[0];
893 $headlines_count = $ret[1];
894 $returned_feed = $ret[2];
895 $disable_cache = $ret[3];
896 $vgroup_last_feed = $ret[4];
897
898 $reply['headlines']['content'] =& $ret[5]['content'];
899 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
900
901 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
902
903 $reply['headlines-info'] = array("count" => (int) $headlines_count,
904 "vgroup_last_feed" => $vgroup_last_feed,
905 "disable_cache" => (bool) $disable_cache);
906
907 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
908
909 $reply['runtime-info'] = make_runtime_info($this->link);
910
911 print json_encode($reply);
912
913 }
914
915 private function generate_dashboard_feed($link) {
916 $reply = array();
917
918 $reply['headlines']['id'] = -5;
919 $reply['headlines']['is_cat'] = false;
920
921 $reply['headlines']['toolbar'] = '';
922 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
923
924 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
925
926 $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
927 WHERE owner_uid = " . $_SESSION['uid']);
928
929 $last_updated = db_fetch_result($result, 0, "last_updated");
930 $last_updated = make_local_datetime($link, $last_updated, false);
931
932 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
933
934 $result = db_query($link, "SELECT COUNT(id) AS num_errors
935 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
936
937 $num_errors = db_fetch_result($result, 0, "num_errors");
938
939 if ($num_errors > 0) {
940 $reply['headlines']['content'] .= "<br/>";
941 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
942 __('Some feeds have update errors (click for details)')."</a>";
943 }
944 $reply['headlines']['content'] .= "</span></p>";
945
946 $reply['headlines-info'] = array("count" => 0,
947 "vgroup_last_feed" => '',
948 "unread" => 0,
949 "disable_cache" => true);
950
951 return $reply;
952 }
953
954 private function generate_error_feed($link, $error) {
955 $reply = array();
956
957 $reply['headlines']['id'] = -6;
958 $reply['headlines']['is_cat'] = false;
959
960 $reply['headlines']['toolbar'] = '';
961 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
962
963 $reply['headlines-info'] = array("count" => 0,
964 "vgroup_last_feed" => '',
965 "unread" => 0,
966 "disable_cache" => true);
967
968 return $reply;
969 }
970
971 function quickAddFeed() {
972 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
973 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
974
975 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
976 print "<div class=\"dlgSecCont\">";
977
978 print "<div style='float : right'>
979 <img style='display : none'
980 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
981
982 print "<input style=\"font-size : 16px; width : 20em;\"
983 placeHolder=\"".__("Feed or site URL")."\"
984 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
985
986 print "<hr/>";
987
988 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
989 print __('Place in category:') . " ";
990 print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"');
991 }
992
993 print "</div>";
994
995 print '<div id="feedDlg_feedsContainer" style="display : none">
996
997 <div class="dlgSec">' . __('Available feeds') . '</div>
998 <div class="dlgSecCont">'.
999 '<select id="feedDlg_feedContainerSelect"
1000 dojoType="dijit.form.Select" size="3">
1001 <script type="dojo/method" event="onChange" args="value">
1002 dijit.byId("feedDlg_feedUrl").attr("value", value);
1003 </script>
1004 </select>'.
1005 '</div></div>';
1006
1007 print "<div id='feedDlg_loginContainer' style='display : none'>
1008
1009 <div class=\"dlgSec\">".__("Authentication")."</div>
1010 <div class=\"dlgSecCont\">".
1011
1012 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1013 placeHolder=\"".__("Login")."\"
1014 style=\"width : 10em;\"> ".
1015 " <input
1016 placeHolder=\"".__("Password")."\"
1017 dojoType=\"dijit.form.TextBox\" type='password'
1018 style=\"width : 10em;\" name='pass'\">
1019 </div></div>";
1020
1021
1022 print "<div style=\"clear : both\">
1023 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1024 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1025 <label for=\"feedDlg_loginCheck\">".
1026 __('This feed requires authentication.')."</div>";
1027
1028 print "</form>";
1029
1030 print "<div class=\"dlgButtons\">
1031 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1032
1033 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) {
1034 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1035 }
1036
1037 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1038 </div>";
1039
1040 //return;
1041 }
1042
1043 function feedBrowser() {
1044 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
1045
1046 $browser_search = db_escape_string($this->link, $_REQUEST["search"]);
1047
1048 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1049 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
1050
1051 print "<div dojoType=\"dijit.Toolbar\">
1052 <div style='float : right'>
1053 <img style='display : none'
1054 id='feed_browser_spinner' src='images/indicator_white.gif'>
1055 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1056 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1057 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1058 </div>";
1059
1060 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1061 <option value='1'>" . __('Popular feeds') . "</option>
1062 <option value='2'>" . __('Feed archive') . "</option>
1063 </select> ";
1064
1065 print __("limit:");
1066
1067 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1068
1069 foreach (array(25, 50, 100, 200) as $l) {
1070 $issel = ($l == $limit) ? "selected=\"1\"" : "";
1071 print "<option $issel value=\"$l\">$l</option>";
1072 }
1073
1074 print "</select> ";
1075
1076 print "</div>";
1077
1078 $owner_uid = $_SESSION["uid"];
1079
1080 require_once "feedbrowser.php";
1081
1082 print "<ul class='browseFeedList' id='browseFeedList'>";
1083 print make_feed_browser($this->link, $search, 25);
1084 print "</ul>";
1085
1086 print "<div align='center'>
1087 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1088 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1089 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1090
1091 }
1092
1093 function search() {
1094 $this->params = explode(":", db_escape_string($this->link, $_REQUEST["param"]), 2);
1095
1096 $active_feed_id = sprintf("%d", $this->params[0]);
1097 $is_cat = $this->params[1] != "false";
1098
1099 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1100
1101 print "<div class=\"dlgSecCont\">";
1102
1103 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1104 style=\"font-size : 16px; width : 20em;\"
1105 required=\"1\" name=\"query\" type=\"search\" value=''>";
1106
1107 print "<hr/>".__('Limit search to:')." ";
1108
1109 print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
1110 <option value=\"all_feeds\">".__('All feeds')."</option>";
1111
1112 $feed_title = getFeedTitle($this->link, $active_feed_id);
1113
1114 if (!$is_cat) {
1115 $feed_cat_title = getFeedCatTitle($this->link, $active_feed_id);
1116 } else {
1117 $feed_cat_title = getCategoryTitle($this->link, $active_feed_id);
1118 }
1119
1120 if ($active_feed_id && !$is_cat) {
1121 print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
1122 } else {
1123 print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
1124 }
1125
1126 if ($is_cat) {
1127 $cat_preselected = "selected=\"1\"";
1128 }
1129
1130 if (get_pref($this->link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
1131 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
1132 } else {
1133 //print "<option disabled>".__('This category')."</option>";
1134 }
1135
1136 print "</select>";
1137
1138 print "</div>";
1139
1140 print "<div class=\"dlgButtons\">";
1141
1142 if (!SPHINX_ENABLED) {
1143 print "<div style=\"float : left\">
1144 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">Search syntax</a>
1145 </div>";
1146 }
1147
1148 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1149 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
1150 </div>";
1151 }
1152
1153
1154 }
1155 ?>