]> git.wh0rd.org - tt-rss.git/blame - mobile/functions.php
api: add show_content to getHeadlines to allow CDM-styled operation
[tt-rss.git] / mobile / functions.php
CommitLineData
e9e95dae 1<?php
581e6bb5 2 define('MOBILE_FEEDLIST_ENABLE_ICONS', false);
3dd46f19 3 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
0d3adafe 4
eead4d26 5 function render_feeds_list($link) {
42096f52 6
eead4d26 7 $tags = $_GET["tags"];
42096f52 8
eead4d26 9 print "<div id=\"heading\">";
42096f52 10
eead4d26 11 if ($tags) {
e0142e27
AD
12 print __("Tags")."<span id=\"headingAddon\">
13 (<a href=\"tt-rss.php\">".__("View feeds")."</a>, ";
eead4d26 14 } else {
e0142e27
AD
15 print __("Feeds")." <span id=\"headingAddon\">
16 (<a href=\"tt-rss.php?tags=1\">".__("View tags")."</a>, ";
42096f52 17 }
0809065e 18
e0142e27 19 print "<a href=\"tt-rss.php?go=sform\">".__("Search")."</a>, ";
0809065e 20
e0142e27 21 print "<a href=\"logout.php\">".__("Logout")."</a>)</span>";
42096f52
AD
22 print "</div>";
23
0d3adafe
AD
24 print "<ul class=\"feedList\">";
25
26 $owner_uid = $_SESSION["uid"];
27
28 if (!$tags) {
29
30 /* virtual feeds */
31
32 if (get_pref($link, 'ENABLE_FEED_CATS')) {
e0142e27 33 print "<li class=\"feedCat\">".__("Special")."</li>";
ab1486d5 34 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
0d3adafe
AD
35 }
36
a043ad29
AD
37 $num_total = getFeedUnread($link, -4);
38
39 $class = "virt";
40
41 if ($num_total > 0) $class .= "Unread";
42
43 printMobileFeedEntry(-4, $class, __("All articles"), $num_total,
44 "../images/fresh.png", $link);
45
a10d293c
AD
46 $num_fresh = getFeedUnread($link, -3);
47
48 $class = "virt";
49
50 if ($num_fresh > 0) $class .= "Unread";
51
85233b8e 52 printMobileFeedEntry(-3, $class, __("Fresh articles"), $num_fresh,
a10d293c
AD
53 "../images/fresh.png", $link);
54
318260cc 55 $num_starred = getFeedUnread($link, -1);
0d3adafe
AD
56
57 $class = "virt";
58
59 if ($num_starred > 0) $class .= "Unread";
60
85233b8e 61 printMobileFeedEntry(-1, $class, __("Starred articles"), $num_starred,
0d3adafe
AD
62 "../images/mark_set.png", $link);
63
85233b8e
AD
64 $class = "virt";
65
66 $num_published = getFeedUnread($link, -2);
67
68 if ($num_published > 0) $class .= "Unread";
69
70 printMobileFeedEntry(-2, $class, __("Published articles"), $num_published,
71 "../images/pub_set.png", $link);
72
0d3adafe
AD
73 if (get_pref($link, 'ENABLE_FEED_CATS')) {
74 print "</ul>";
75 }
76
0d3adafe 77
ceb30ba4
AD
78 $result = db_query($link, "SELECT id,caption FROM
79 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
80
0d3adafe
AD
81 if (db_num_rows($result) > 0) {
82 if (get_pref($link, 'ENABLE_FEED_CATS')) {
e0142e27 83 print "<li class=\"feedCat\">".__("Labels")."</li>";
ab1486d5 84 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
0d3adafe 85 } else {
ab1486d5 86// print "<li><hr></li>";
0d3adafe
AD
87 }
88 }
89
90 while ($line = db_fetch_assoc($result)) {
91
318260cc 92 $count = getFeedUnread($link, -$line["id"]-11);
0d3adafe
AD
93
94 $class = "label";
95
96 if ($count > 0) {
97 $class .= "Unread";
98 }
ceb30ba4 99
8e3f7217 100 printMobileFeedEntry(-$line["id"]-11,
ceb30ba4 101 $class, $line["caption"], $count, "../images/label.png", $link);
0d3adafe
AD
102
103 }
104
105 if (db_num_rows($result) > 0) {
106 if (get_pref($link, 'ENABLE_FEED_CATS')) {
107 print "</ul>";
108 }
109 }
110
0d3adafe 111
0d3adafe
AD
112 if (get_pref($link, 'ENABLE_FEED_CATS')) {
113 $order_by_qpart = "category,title";
114 } else {
115 $order_by_qpart = "title";
116 }
117
118 $result = db_query($link, "SELECT ttrss_feeds.*,
fc2b26a6 119 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
0d3adafe
AD
120 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
121 WHERE feed_id = ttrss_feeds.id AND
122 ttrss_user_entries.ref_id = ttrss_entries.id AND
123 owner_uid = '$owner_uid') AS total,
124 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
125 WHERE feed_id = ttrss_feeds.id AND unread = true
126 AND ttrss_user_entries.ref_id = ttrss_entries.id
127 AND owner_uid = '$owner_uid') as unread,
128 cat_id,last_error,
129 ttrss_feed_categories.title AS category,
130 ttrss_feed_categories.collapsed
131 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
132 ON (ttrss_feed_categories.id = cat_id)
133 WHERE
0da49bad 134 ttrss_feeds.hidden = false AND
0d3adafe
AD
135 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
136 ORDER BY $order_by_qpart");
137
138 $actid = $_GET["actid"];
139
140 /* real feeds */
141
142 $lnum = 0;
143
0d3adafe 144 $category = "";
e0142e27 145
0d3adafe 146 while ($line = db_fetch_assoc($result)) {
e0142e27
AD
147 if (get_pref($link, 'HIDE_READ_FEEDS') && (int)$line['unread']==0) {
148 continue;
149 }
150
0d3adafe
AD
151 $feed = db_unescape_string($line["title"]);
152 $feed_id = $line["id"];
153
154 $subop = $_GET["subop"];
155
156 $total = $line["total"];
157 $unread = $line["unread"];
158
159 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
160
161 if ($rtl_content) {
162 $rtl_tag = "dir=\"RTL\"";
163 } else {
164 $rtl_tag = "";
165 }
166
167 $tmp_result = db_query($link,
168 "SELECT id,COUNT(unread) AS unread
169 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
170 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
171 WHERE parent_feed = '$feed_id' AND unread = true
172 GROUP BY ttrss_feeds.id");
173
174 if (db_num_rows($tmp_result) > 0) {
175 while ($l = db_fetch_assoc($tmp_result)) {
176 $unread += $l["unread"];
177 }
178 }
179
180 $cat_id = $line["cat_id"];
181
182 $tmp_category = $line["category"];
183
184 if (!$tmp_category) {
185 $tmp_category = "Uncategorized";
186 }
187
188 // $class = ($lnum % 2) ? "even" : "odd";
189
190 if ($line["last_error"]) {
191 $class = "error";
192 } else {
193 $class = "feed";
194 }
195
196 if ($unread > 0) $class .= "Unread";
197
198 if ($actid == $feed_id) {
199 $class .= "Selected";
200 }
0d3adafe
AD
201
202 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
203
204 if ($category) {
205 print "</ul></li>";
206 }
207
208 $category = $tmp_category;
209
210 $collapsed = $line["collapsed"];
211
212 // workaround for NULL category
213 if ($category == "Uncategorized") {
214 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
215 $collapsed = "t";
216 }
217 }
218
219 if ($collapsed == "t" || $collapsed == "1") {
220 $holder_class = "invisible";
221 $ellipsis = "...";
222 } else {
ab1486d5 223 $holder_class = "feedCatHolder";
0d3adafe
AD
224 $ellipsis = "";
225 }
226
227 if ($cat_id) {
228 $cat_id_qpart = "cat_id = '$cat_id'";
229 } else {
230 $cat_id_qpart = "cat_id IS NULL";
231 }
232
0d3adafe 233 $cat_id = sprintf("%d", $cat_id);
26eb0119
AD
234 $cat_unread = getCategoryUnread($link, $cat_id);
235
0d3adafe 236 print "<li class=\"feedCat\">
42096f52 237 <a href=\"?subop=tc&id=$cat_id\">$tmp_category</a>
ab1486d5 238 <a href=\"?go=vf&id=$cat_id&cat=true\">
7aa958c8
AD
239 <span class=\"$catctr_class\">($cat_unread)$ellipsis</span>
240 </a></li>";
0d3adafe 241
ab1486d5
AD
242 print "<li id=\"feedCatHolder\" class=\"$holder_class\">
243 <ul class=\"feedCatList\">";
0d3adafe
AD
244 }
245
8e3f7217
AD
246 printMobileFeedEntry($feed_id, $class, $feed, $unread,
247 "../icons/$feed_id.ico", $link, $rtl_content);
0d3adafe
AD
248
249 ++$lnum;
250 }
251
8e3f7217 252 } else {
eead4d26
AD
253 // tags
254
255 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
256 FROM ttrss_user_entries WHERE int_id = post_int_id
257 AND unread = true)) AS count FROM ttrss_tags
847c2a78 258 WHERE owner_uid = '".$_SESSION['uid']."' GROUP BY tag_name ORDER BY tag_name");
eead4d26
AD
259
260 $tags = array();
261
262 while ($line = db_fetch_assoc($result)) {
263 $tags[$line["tag_name"]] += $line["count"];
264 }
265
266 foreach (array_keys($tags) as $tag) {
267
268 $unread = $tags[$tag];
269
270 $class = "tag";
271
272 if ($unread > 0) {
273 $class .= "Unread";
274 }
275
276 printMobileFeedEntry($tag, $class, $tag, $unread,
277 "../images/tag.png", $link);
278
279 }
280
281
8e3f7217 282 }
0d3adafe 283 }
8e3f7217
AD
284
285 function printMobileFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
286 $rtl_content = false) {
287
288 if (file_exists($icon_file) && filesize($icon_file) > 0) {
289 $feed_icon = "<img src=\"$icon_file\">";
290 } else {
291 $feed_icon = "<img src=\"../images/blank_icon.gif\">";
292 }
293
294 if ($rtl_content) {
295 $rtl_tag = "dir=\"rtl\"";
296 } else {
297 $rtl_tag = "dir=\"ltr\"";
298 }
299
300 $feed = "<a href=\"?go=vf&id=$feed_id\">$feed_title</a>";
301
302 print "<li class=\"$class\">";
581e6bb5
AD
303# if (get_pref($link, 'ENABLE_FEED_ICONS')) {
304# print "$feed_icon";
305# }
8e3f7217
AD
306
307 print "<span $rtl_tag>$feed</span> ";
308
309 if ($unread != 0) {
ab1486d5 310 print "<span $rtl_tag>($unread)</span>";
8e3f7217 311 }
8e3f7217
AD
312
313 print "</li>";
314
0d3adafe
AD
315 }
316
ab1486d5
AD
317 function render_headlines($link) {
318
2f468537
AD
319 $feed = db_escape_string($_GET["id"]);
320 $limit = db_escape_string($_GET["limit"]);
321 $view_mode = db_escape_string($_GET["viewmode"]);
ab1486d5 322 $cat_view = db_escape_string($_GET["cat"]);
bbf3ba8d 323 $subop = $_GET["subop"];
fc46ab83 324 $catchup_op = $_GET["catchup_op"];
2f468537 325
4bfe3b43
AD
326 if (!$view_mode) {
327 if ($_SESSION["mobile:viewmode"]) {
328 $view_mode = $_SESSION["mobile:viewmode"];
329 } else {
330 $view_mode = "adaptive";
331 }
332 }
333
334 $_SESSION["mobile:viewmode"] = $view_mode;
335
2f468537 336 if (!$limit) $limit = 30;
0809065e 337 if (!$feed) $feed = 0;
2f468537 338
eead4d26 339 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
2f468537 340
eead4d26
AD
341 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
342 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
2f468537 343
eead4d26
AD
344 if (db_num_rows($result) == 1) {
345 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
346 } else {
347 $rtl_content = false;
348 }
349
350 if ($rtl_content) {
351 $rtl_tag = "dir=\"RTL\"";
352 } else {
353 $rtl_tag = "";
354 }
2f468537 355 } else {
eead4d26 356 $rtl_content = false;
2f468537
AD
357 $rtl_tag = "";
358 }
359
360 print "<div id=\"headlines\" $rtl_tag>";
361
362 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
35bf080c 363 update_generic_feed($link, $feed, $cat_view, true);
2f468537
AD
364 }
365
fc46ab83 366 if ($subop == "MarkAllRead" || $catchup_op == "feed") {
2f468537
AD
367 catchup_feed($link, $feed, $cat_view);
368 }
369
fc46ab83
AD
370 if ($catchup_op == "selection") {
371 $ids_to_mark = array_keys($_GET["sel_ids"]);
372 if ($ids_to_mark) {
373 foreach ($ids_to_mark as $id) {
374 db_query($link, "UPDATE ttrss_user_entries SET
375 unread = false,last_read = NOW()
376 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
377 }
378 }
379 }
380
381 if ($subop == "MarkPageRead" || $catchup_op == "page") {
c878bc01
AD
382 $ids_to_mark = $_SESSION["last_page_ids.$feed"];
383
384 if ($ids_to_mark) {
385
386 foreach ($ids_to_mark as $id) {
387 db_query($link, "UPDATE ttrss_user_entries SET
388 unread = false,last_read = NOW()
389 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
390 }
391 }
392 }
2f468537 393
2f468537 394
0809065e 395 /// START /////////////////////////////////////////////////////////////////////////////////
2f468537 396
0809065e
AD
397 $search = db_escape_string($_GET["query"]);
398 $search_mode = db_escape_string($_GET["search_mode"]);
399 $match_on = db_escape_string($_GET["match_on"]);
2f468537 400
0809065e
AD
401 if (!$match_on) {
402 $match_on = "both";
2f468537
AD
403 }
404
0809065e 405 $real_offset = $offset * $limit;
2f468537 406
0809065e 407 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
2f468537 408
0809065e
AD
409 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
410 $search, $search_mode, $match_on, false, $real_offset);
2f468537 411
0809065e 412 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
2f468537 413
0809065e
AD
414 $result = $qfh_ret[0];
415 $feed_title = $qfh_ret[1];
416 $feed_site_url = $qfh_ret[2];
417 $last_error = $qfh_ret[3];
2f468537 418
0809065e 419 /// STOP //////////////////////////////////////////////////////////////////////////////////
2f468537
AD
420
421 if (!$result) {
e0142e27
AD
422 print "<div align='center'>".
423 __("Could not display feed (query failed). Please check label match syntax or local configuration.").
424 "</div>";
2f468537
AD
425 return;
426 }
42096f52 427
42096f52 428 print "<div id=\"heading\">";
581e6bb5
AD
429 # if (!$cat_view && file_exists("../icons/$feed.ico") && filesize("../icons/$feed.ico") > 0) {
430 # print "<img class=\"feedIcon\" src=\"../icons/$feed.ico\">";
431 # }
42096f52 432
062c1de5 433 print "$feed_title <span id=\"headingAddon\">(";
e0142e27
AD
434 print "<a href=\"tt-rss.php\">".__("Back")."</a>, ";
435 print "<a href=\"tt-rss.php?go=sform&aid=$feed&ic=$cat_view\">".__("Search")."</a>, ";
436 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=ForceUpdate\">".__("Update")."</a>";
4bfe3b43 437
c878bc01
AD
438# print "Mark as read: ";
439# print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAsRead\">Page</a>, ";
440# print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a>";
0809065e 441
062c1de5 442 print ")</span>";
4bfe3b43
AD
443
444 print "&nbsp;" . __('View:');
445
446 print "<form style=\"display : inline\" method=\"GET\" action=\"tt-rss.php\">";
447
448 /* print "<select name=\"viewmode\">
449 <option selected value=\"adaptive\"> " . __('Adaptive') . "</option>
450 <option value=\"all_articles\">" . __('All Articles') . "</option>
451 <option value=\"marked\">" . __('Starred') . "</option>
452 <option value=\"unread\">" . __('Unread') . "</option>
453 </select>"; */
454
455 $sel_values = array(
456 "adaptive" => __("Adaptive"),
457 "all_articles" => __("All Articles"),
458 "unread" => __("Unread"),
459 "marked" => __("Starred"));
460
461 print_select_hash("viewmode", $view_mode, $sel_values);
462
463 print "<input type=\"hidden\" name=\"id\" value=\"$feed\">
6d858dab 464 <input type=\"hidden\" name=\"cat\" value=\"$cat_view\">
4bfe3b43
AD
465 <input type=\"hidden\" name=\"go\" value=\"vf\">
466 <input type=\"submit\" value=\"".__('Refresh')."\">";
467 print "</form>";
468
42096f52 469 print "</div>";
2f468537
AD
470
471 if (db_num_rows($result) > 0) {
472
fc46ab83
AD
473 print "<form method=\"GET\" action=\"tt-rss.php\">";
474 print "<input type=\"hidden\" name=\"go\" value=\"vf\">";
475 print "<input type=\"hidden\" name=\"id\" value=\"$feed\">";
d9aad400 476 print "<input type=\"hidden\" name=\"cat\" value=\"$cat_view\">";
fc46ab83 477
8f3151a0 478 print "<ul class=\"headlines\" id=\"headlines\">";
2f468537 479
c878bc01
AD
480 $page_art_ids = array();
481
2f468537
AD
482 $lnum = 0;
483
484 error_reporting (DEFAULT_ERROR_LEVEL);
485
486 $num_unread = 0;
487
488 while ($line = db_fetch_assoc($result)) {
489
490 $class = ($lnum % 2) ? "even" : "odd";
491
492 $id = $line["id"];
493 $feed_id = $line["feed_id"];
c878bc01
AD
494
495 array_push($page_art_ids, $id);
2f468537
AD
496
497 if ($line["last_read"] == "" &&
498 ($line["unread"] != "t" && $line["unread"] != "1")) {
499
500 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
e0142e27 501 alt=\"".__("Updated")."\">";
2f468537
AD
502 } else {
503 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
e0142e27 504 alt=\"".__("Updated")."\">";
2f468537
AD
505 }
506
507 if ($line["unread"] == "t" || $line["unread"] == "1") {
508 $class .= "Unread";
509 ++$num_unread;
510 $is_unread = true;
511 } else {
512 $is_unread = false;
513 }
514
515 if ($line["marked"] == "t" || $line["marked"] == "1") {
9123c2ef 516 $marked_pic = "<img alt=\"S\" class='marked' src=\"../images/mark_set.png\">";
2f468537 517 } else {
9123c2ef 518 $marked_pic = "<img alt=\"s\" class='marked' src=\"../images/mark_unset.png\">";
2f468537 519 }
510ac75f
AD
520
521 if ($line["published"] == "t" || $line["published"] == "1") {
9123c2ef 522 $published_pic = "<img alt=\"P\" class='marked' src=\"../images/pub_set.gif\">";
510ac75f 523 } else {
9123c2ef 524 $published_pic = "<img alt=\"p\" class='marked' src=\"../images/pub_unset.gif\">";
510ac75f
AD
525 }
526
d9aad400 527 $content_link = "<a href=\"?go=view&id=$id&cat=$cat_view&ret_feed=$feed&feed=$feed_id\">" .
2f468537
AD
528 $line["title"] . "</a>";
529
530 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
531 $updated_fmt = smart_date_time(strtotime($line["updated"]));
532 } else {
533 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
534 $updated_fmt = date($short_date, strtotime($line["updated"]));
535 }
536
fc46ab83
AD
537 print "<li class='$class' id=\"HROW-$id\">";
538
8f3151a0
AD
539 print "<input type=\"checkbox\" name=\"sel_ids[$id]\"
540 id=\"HSCB-$id\" onchange=\"toggleSelectRow(this, $id)\">";
2f468537 541
d9aad400
AD
542 print "<a href=\"?go=vf&id=$feed&ts=$id&cat=$cat_view\">$marked_pic</a>";
543 print "<a href=\"?go=vf&id=$feed&tp=$id&cat=$cat_view\">$published_pic</a>";
24ac6776 544
ab1486d5
AD
545 print $content_link;
546
2f468537
AD
547 if ($line["feed_title"]) {
548 print " (<a href='?go=vf&id=$feed_id'>".
549 $line["feed_title"]."</a>)";
550 }
551
581e6bb5 552 print "<span class='hlUpdated'> ($updated_fmt)</span>";
ab1486d5
AD
553
554 print "</li>";
2f468537 555
2f468537
AD
556
557 ++$lnum;
558 }
559
ab1486d5 560 print "</ul>";
2f468537 561
fc46ab83 562 print "<div class='footerAddon'>";
c878bc01
AD
563
564 $_SESSION["last_page_ids.$feed"] = $page_art_ids;
565
fc46ab83
AD
566/* print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkPageRead\">Page</a>, ";
567 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a></div>"; */
568
8f3151a0 569 print "Select:
e0142e27
AD
570 <a href=\"javascript:selectHeadlines(1)\">".__("All")."</a>,
571 <a href=\"javascript:selectHeadlines(2)\">".__("Unread")."</a>,
572 <a href=\"javascript:selectHeadlines(3)\">".__("None")."</a>,
573 <a href=\"javascript:selectHeadlines(4)\">".__("Invert")."</a>";
8f3151a0
AD
574
575 print " ";
576
fc46ab83 577 print "<select name=\"catchup_op\">
e0142e27
AD
578 <option value=\"selection\">".__("Selection")."</option>
579 <option value=\"page\">".__("Page")."</option>
580 <option value=\"feed\">".__("Entire feed")."</option>
fc46ab83 581 </select>
6d858dab 582 <input type=\"hidden\" name=\"cat\" value=\"$cat_view\">
e0142e27 583 <input type=\"submit\" value=\"".__("Mark as read")."\">";
fc46ab83
AD
584
585 print "</form>";
c878bc01 586
2f468537
AD
587 } else {
588 print "<div align='center'>No articles found.</div>";
589 }
590
591 }
592
42096f52
AD
593 function render_article($link) {
594
595 $id = db_escape_string($_GET["id"]);
596 $feed_id = db_escape_string($_GET["feed"]);
31d1b6cf 597 $ret_feed_id = db_escape_string($_GET["ret_feed"]);
d9aad400 598 $cat_view = db_escape_string($_GET["cat"]);
42096f52
AD
599
600 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
601 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
602
603 if (db_num_rows($result) == 1) {
604 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
605 } else {
606 $rtl_content = false;
607 }
608
609 if ($rtl_content) {
610 $rtl_tag = "dir=\"RTL\"";
611 $rtl_class = "RTL";
612 } else {
613 $rtl_tag = "";
614 $rtl_class = "";
615 }
616
617 $result = db_query($link, "UPDATE ttrss_user_entries
618 SET unread = false,last_read = NOW()
619 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
620
621 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
f70f7e28 622 marked,published,
fc2b26a6 623 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
42096f52
AD
624 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
625 num_comments,
626 author
627 FROM ttrss_entries,ttrss_user_entries
628 WHERE id = '$id' AND ref_id = id");
629
42096f52
AD
630 if ($result) {
631
632 $line = db_fetch_assoc($result);
633
42096f52
AD
634 $num_comments = $line["num_comments"];
635 $entry_comments = "";
636
637 if ($num_comments > 0) {
638 if ($line["comments"]) {
639 $comments_url = $line["comments"];
640 } else {
641 $comments_url = $line["link"];
642 }
643 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
644 } else {
645 if ($line["comments"] && $line["link"] != $line["comments"]) {
646 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
647 }
648 }
649
eead4d26
AD
650 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
651 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
652 ORDER BY tag_name");
653
654 $tags_str = "";
655 $f_tags_str = "";
656
657 $num_tags = 0;
658
659 while ($tmp_line = db_fetch_assoc($tmp_result)) {
660 $num_tags++;
661 $tag = $tmp_line["tag_name"];
662 $tag_str = "<a href=\"?go=vf&id=$tag\">$tag</a>, ";
663 $tags_str .= $tag_str;
664 }
665
666 $tags_str = preg_replace("/, $/", "", $tags_str);
667
24ac6776 668 $parsed_updated = date(get_pref($link, 'SHORT_DATE_FORMAT'),
42096f52 669 strtotime($line["updated"]));
42096f52 670
ab1486d5 671 print "<div id=\"heading\">";
24ac6776 672
581e6bb5
AD
673 # if (file_exists("../icons/$feed_id.ico") && filesize("../icons/$feed_id.ico") > 0) {
674 # print "<img class=\"feedIcon\" src=\"../icons/$feed_id.ico\">";
675 # }
24ac6776 676
d9aad400
AD
677 if (!$cat_view) {
678 $feed_title = getFeedTitle($link, $ret_feed_id);
679 } else {
680 $feed_title = getCategoryTitle($link, $ret_feed_id);
681 $feed_title_native = getFeedTitle($link, $feed_id);
682 }
683
684 if ($feed_title_native) {
685 $feed_link = "<a href=\"tt-rss.php?go=vf&id=$feed_id\">$feed_title_native</a>";
686 $feed_link .= " in <a href=\"tt-rss.php?go=vf&id=$ret_feed_id&cat=$cat_view\">
687 $feed_title</a>";
688 } else {
689 $feed_link = "<a href=\"tt-rss.php?go=vf&id=$ret_feed_id\">$feed_title</a>";
690 }
691
541890fb
AD
692 $feedlist = "<a href=\"tt-rss.php\">".__('Back to feedlist')."</a>";
693
3d7d6cdd
AD
694 print "<a href=\"" . $line["link"] . "\">" .
695 truncate_string($line["title"], 30) . "</a>";
541890fb 696 print " <span id=\"headingAddon\">$parsed_updated ($feed_link, $feedlist)</span>";
ab1486d5 697 print "</div>";
42096f52 698
eead4d26 699 if ($num_tags > 0) {
e0142e27 700 print "<div class=\"postTags\">".__("Tags:")." $tags_str</div>";
eead4d26 701 }
24ac6776 702
f70f7e28
AD
703 if ($line["marked"] == "t" || $line["marked"] == "1") {
704 $marked_pic = "<img class='marked' src=\"../images/mark_set.png\">";
705 } else {
706 $marked_pic = "<img class='marked' src=\"../images/mark_unset.png\">";
707 }
708
709 if ($line["published"] == "t" || $line["published"] == "1") {
710 $published_pic = "<img class='marked' src=\"../images/pub_set.gif\">";
711 } else {
712 $published_pic = "<img class='marked' src=\"../images/pub_unset.gif\">";
713 }
714
4a596be6 715
f70f7e28 716 print "<div class=\"postStarOps\">";
4a596be6
AD
717 print "<a title=\"".__('Toggle starred')."\"href=\"?go=view&id=$id&ret_feed=$ret_feed_id&feed=$feed_id&sop=ts\">$marked_pic</a>";
718 print "<a title=\"".__('Toggle published')."\" href=\"?go=view&id=$id&ret_feed=$ret_feed_id&feed=$feed_id&sop=tp\">$published_pic</a>";
719 // Mark unread
720 print "<a title=\"".__('Mark as unread')."\" href=\"?go=vf&id=$ret_feed_id&feed=$feed_id&sop=mu&aid=$id";
721 if ($cat_view) { print "&cat=$cat_view"; }
722 print "\"><img class='marked' src=\"../images/art-set-unread.png\"></a>";
f70f7e28
AD
723 print "</div>";
724
1ac0baf4 725 print sanitize_rss($link, $line["content"], true);;
eead4d26 726
42096f52
AD
727 }
728
729 print "</body></html>";
42096f52
AD
730 }
731
0809065e
AD
732 function render_search_form($link, $active_feed_id = false, $is_cat = false) {
733
734 print "<div id=\"heading\">";
735
e0142e27
AD
736 print __("Search")." <span id=\"headingAddon\">
737 (<a href=\"tt-rss.php\">".__("Go back")."</a>)</span></div>";
0809065e
AD
738
739 print "<form method=\"GET\" action=\"tt-rss.php\" class=\"searchForm\">";
740
741 print "<input type=\"hidden\" name=\"go\" value=\"vf\">";
742 print "<input type=\"hidden\" name=\"id\" value=\"$active_feed_id\">";
743 print "<input type=\"hidden\" name=\"cat\" value=\"$is_cat\">";
744
745 print "<table><tr><td>".__('Search:')."</td><td>";
746 print "<input name=\"query\"></td></tr>";
747
748 print "<tr><td>".__('Where:')."</td><td>";
749
750 print "<select name=\"search_mode\">
751 <option value=\"all_feeds\">".__('All feeds')."</option>";
752
753 $feed_title = getFeedTitle($link, $active_feed_id);
754
755 if (!$is_cat) {
756 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
757 } else {
758 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
759 }
760
761 if ($active_feed_id && !$is_cat) {
762 print "<option selected value=\"this_feed\">$feed_title</option>";
763 } else {
764 print "<option disabled>".__('This feed')."</option>";
765 }
766
767 if ($is_cat) {
768 $cat_preselected = "selected";
769 }
770
771 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
772 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
773 } else {
774 //print "<option disabled>".__('This category')."</option>";
775 }
776
777 print "</select></td></tr>";
778
779 print "<tr><td>".__('Match on:')."</td><td>";
780
781 $search_fields = array(
782 "title" => __("Title"),
783 "content" => __("Content"),
784 "both" => __("Title or content"));
785
786 print_select_hash("match_on", 3, $search_fields);
787
788 print "</td></tr></table>";
789
790 print "<input type=\"submit\" value=\"".__('Search')."\">";
791
792 print "</form>";
793
794 print "</div>";
795 }
796
f70f7e28
AD
797 function toggleMarked($link, $ts_id) {
798 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = NOT marked
799 WHERE ref_id = '$ts_id' AND owner_uid = " . $_SESSION["uid"]);
800 }
801
802 function togglePublished($link, $tp_id) {
803 $result = db_query($link, "UPDATE ttrss_user_entries SET published = NOT published
804 WHERE ref_id = '$tp_id' AND owner_uid = " . $_SESSION["uid"]);
805 }
4a596be6
AD
806
807 function markUnread($link, $mu_id) {
808 $result = db_query($link, "UPDATE ttrss_user_entries SET unread = true
809 WHERE ref_id = '$mu_id' AND owner_uid = " . $_SESSION["uid"]);
810 }
811
0d3adafe 812?>