]> git.wh0rd.org - tt-rss.git/blob - mobile/functions.php
07a7544de8e29fe2c609bc0f1deeceada457f418
[tt-rss.git] / mobile / functions.php
1 <?php
2 define('MOBILE_FEEDLIST_ENABLE_ICONS', false);
3 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
4
5 function render_feeds_list($link) {
6
7 $tags = $_GET["tags"];
8
9 print "<div id=\"heading\">";
10
11 if ($tags) {
12 print "Tags <span id=\"headingAddon\">
13 (<a href=\"tt-rss.php\">View feeds</a>, ";
14 } else {
15 print "Feeds <span id=\"headingAddon\">
16 (<a href=\"tt-rss.php?tags=1\">View tags</a>, ";
17 }
18
19 print "<a href=\"tt-rss.php?go=sform\">Search</a>, ";
20
21 print "<a href=\"logout.php\">Logout</a>)</span>";
22 print "</div>";
23
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')) {
33 print "<li class=\"feedCat\">Special</li>";
34 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
35 }
36
37 $num_fresh = getFeedUnread($link, -3);
38
39 $class = "virt";
40
41 if ($num_fresh > 0) $class .= "Unread";
42
43 printMobileFeedEntry(-3, $class, "Fresh articles", $num_fresh,
44 "../images/fresh.png", $link);
45
46 $num_starred = getFeedUnread($link, -1);
47
48 $class = "virt";
49
50 if ($num_starred > 0) $class .= "Unread";
51
52 printMobileFeedEntry(-1, $class, "Starred articles", $num_starred,
53 "../images/mark_set.png", $link);
54
55 if (get_pref($link, 'ENABLE_FEED_CATS')) {
56 print "</ul>";
57 }
58
59 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
60
61 $result = db_query($link, "SELECT id,description FROM
62 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
63
64 if (db_num_rows($result) > 0) {
65 if (get_pref($link, 'ENABLE_FEED_CATS')) {
66 print "<li class=\"feedCat\">Labels</li>";
67 print "<li class=\"feedCatHolder\"><ul class=\"feedCatList\">";
68 } else {
69 // print "<li><hr></li>";
70 }
71 }
72
73 while ($line = db_fetch_assoc($result)) {
74
75 error_reporting (0);
76
77 $count = getFeedUnread($link, -$line["id"]-11);
78
79 $class = "label";
80
81 if ($count > 0) {
82 $class .= "Unread";
83 }
84
85 error_reporting (DEFAULT_ERROR_LEVEL);
86
87 printMobileFeedEntry(-$line["id"]-11,
88 $class, $line["description"], $count, "../images/label.png", $link);
89
90 }
91
92 if (db_num_rows($result) > 0) {
93 if (get_pref($link, 'ENABLE_FEED_CATS')) {
94 print "</ul>";
95 }
96 }
97
98 }
99
100 if (get_pref($link, 'ENABLE_FEED_CATS')) {
101 $order_by_qpart = "category,title";
102 } else {
103 $order_by_qpart = "title";
104 }
105
106 $result = db_query($link, "SELECT ttrss_feeds.*,
107 SUBSTRING(last_updated,1,19) AS last_updated_noms,
108 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
109 WHERE feed_id = ttrss_feeds.id AND
110 ttrss_user_entries.ref_id = ttrss_entries.id AND
111 owner_uid = '$owner_uid') AS total,
112 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
113 WHERE feed_id = ttrss_feeds.id AND unread = true
114 AND ttrss_user_entries.ref_id = ttrss_entries.id
115 AND owner_uid = '$owner_uid') as unread,
116 cat_id,last_error,
117 ttrss_feed_categories.title AS category,
118 ttrss_feed_categories.collapsed
119 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
120 ON (ttrss_feed_categories.id = cat_id)
121 WHERE
122 ttrss_feeds.hidden = false AND
123 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
124 ORDER BY $order_by_qpart");
125
126 $actid = $_GET["actid"];
127
128 /* real feeds */
129
130 $lnum = 0;
131
132 $category = "";
133
134 while ($line = db_fetch_assoc($result)) {
135
136 $feed = db_unescape_string($line["title"]);
137 $feed_id = $line["id"];
138
139 $subop = $_GET["subop"];
140
141 $total = $line["total"];
142 $unread = $line["unread"];
143
144 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
145
146 if ($rtl_content) {
147 $rtl_tag = "dir=\"RTL\"";
148 } else {
149 $rtl_tag = "";
150 }
151
152 $tmp_result = db_query($link,
153 "SELECT id,COUNT(unread) AS unread
154 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
155 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
156 WHERE parent_feed = '$feed_id' AND unread = true
157 GROUP BY ttrss_feeds.id");
158
159 if (db_num_rows($tmp_result) > 0) {
160 while ($l = db_fetch_assoc($tmp_result)) {
161 $unread += $l["unread"];
162 }
163 }
164
165 $cat_id = $line["cat_id"];
166
167 $tmp_category = $line["category"];
168
169 if (!$tmp_category) {
170 $tmp_category = "Uncategorized";
171 }
172
173 // $class = ($lnum % 2) ? "even" : "odd";
174
175 if ($line["last_error"]) {
176 $class = "error";
177 } else {
178 $class = "feed";
179 }
180
181 if ($unread > 0) $class .= "Unread";
182
183 if ($actid == $feed_id) {
184 $class .= "Selected";
185 }
186
187 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
188
189 if ($category) {
190 print "</ul></li>";
191 }
192
193 $category = $tmp_category;
194
195 $collapsed = $line["collapsed"];
196
197 // workaround for NULL category
198 if ($category == "Uncategorized") {
199 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
200 $collapsed = "t";
201 }
202 }
203
204 if ($collapsed == "t" || $collapsed == "1") {
205 $holder_class = "invisible";
206 $ellipsis = "...";
207 } else {
208 $holder_class = "feedCatHolder";
209 $ellipsis = "";
210 }
211
212 if ($cat_id) {
213 $cat_id_qpart = "cat_id = '$cat_id'";
214 } else {
215 $cat_id_qpart = "cat_id IS NULL";
216 }
217
218 $cat_id = sprintf("%d", $cat_id);
219 $cat_unread = getCategoryUnread($link, $cat_id);
220
221 print "<li class=\"feedCat\">
222 <a href=\"?subop=tc&id=$cat_id\">$tmp_category</a>
223 <a href=\"?go=vf&id=$cat_id&cat=true\">
224 <span class=\"$catctr_class\">($cat_unread
225 unread)$ellipsis</span></a></li>";
226
227 print "<li id=\"feedCatHolder\" class=\"$holder_class\">
228 <ul class=\"feedCatList\">";
229 }
230
231 printMobileFeedEntry($feed_id, $class, $feed, $unread,
232 "../icons/$feed_id.ico", $link, $rtl_content);
233
234 ++$lnum;
235 }
236
237 } else {
238 // tags
239
240 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
241 FROM ttrss_user_entries WHERE int_id = post_int_id
242 AND unread = true)) AS count FROM ttrss_tags
243 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
244
245 $tags = array();
246
247 while ($line = db_fetch_assoc($result)) {
248 $tags[$line["tag_name"]] += $line["count"];
249 }
250
251 foreach (array_keys($tags) as $tag) {
252
253 $unread = $tags[$tag];
254
255 $class = "tag";
256
257 if ($unread > 0) {
258 $class .= "Unread";
259 }
260
261 printMobileFeedEntry($tag, $class, $tag, $unread,
262 "../images/tag.png", $link);
263
264 }
265
266
267 }
268 }
269
270 function printMobileFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
271 $rtl_content = false) {
272
273 if (file_exists($icon_file) && filesize($icon_file) > 0) {
274 $feed_icon = "<img src=\"$icon_file\">";
275 } else {
276 $feed_icon = "<img src=\"../images/blank_icon.gif\">";
277 }
278
279 if ($rtl_content) {
280 $rtl_tag = "dir=\"rtl\"";
281 } else {
282 $rtl_tag = "dir=\"ltr\"";
283 }
284
285 $feed = "<a href=\"?go=vf&id=$feed_id\">$feed_title</a>";
286
287 print "<li class=\"$class\">";
288 # if (get_pref($link, 'ENABLE_FEED_ICONS')) {
289 # print "$feed_icon";
290 # }
291
292 print "<span $rtl_tag>$feed</span> ";
293
294 if ($unread != 0) {
295 print "<span $rtl_tag>($unread)</span>";
296 }
297
298 print "</li>";
299
300 }
301
302 function render_headlines($link) {
303
304 $feed = db_escape_string($_GET["id"]);
305 $limit = db_escape_string($_GET["limit"]);
306 $view_mode = db_escape_string($_GET["viewmode"]);
307 $cat_view = db_escape_string($_GET["cat"]);
308 $subop = $_GET["subop"];
309
310 if (!$view_mode) $view_mode = "Adaptive";
311 if (!$limit) $limit = 30;
312 if (!$feed) $feed = 0;
313
314 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
315
316 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
317 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
318
319 if (db_num_rows($result) == 1) {
320 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
321 } else {
322 $rtl_content = false;
323 }
324
325 if ($rtl_content) {
326 $rtl_tag = "dir=\"RTL\"";
327 } else {
328 $rtl_tag = "";
329 }
330 } else {
331 $rtl_content = false;
332 $rtl_tag = "";
333 }
334
335 print "<div id=\"headlines\" $rtl_tag>";
336
337 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
338 update_generic_feed($link, $feed, $cat_view, true);
339 }
340
341 if ($subop == "MarkAllRead") {
342 catchup_feed($link, $feed, $cat_view);
343 }
344
345 if ($subop == "MarkPageRead") {
346 $ids_to_mark = $_SESSION["last_page_ids.$feed"];
347
348 if ($ids_to_mark) {
349
350 foreach ($ids_to_mark as $id) {
351 db_query($link, "UPDATE ttrss_user_entries SET
352 unread = false,last_read = NOW()
353 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
354 }
355 }
356 }
357
358
359 /// START /////////////////////////////////////////////////////////////////////////////////
360
361 $search = db_escape_string($_GET["query"]);
362 $search_mode = db_escape_string($_GET["search_mode"]);
363 $match_on = db_escape_string($_GET["match_on"]);
364
365 if (!$match_on) {
366 $match_on = "both";
367 }
368
369 $real_offset = $offset * $limit;
370
371 if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
372
373 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
374 $search, $search_mode, $match_on, false, $real_offset);
375
376 if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
377
378 $result = $qfh_ret[0];
379 $feed_title = $qfh_ret[1];
380 $feed_site_url = $qfh_ret[2];
381 $last_error = $qfh_ret[3];
382
383 /// STOP //////////////////////////////////////////////////////////////////////////////////
384
385 if (!$result) {
386 print "<div align='center'>
387 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
388 return;
389 }
390
391 print "<div id=\"heading\">";
392 # if (!$cat_view && file_exists("../icons/$feed.ico") && filesize("../icons/$feed.ico") > 0) {
393 # print "<img class=\"feedIcon\" src=\"../icons/$feed.ico\">";
394 # }
395
396 print "$feed_title <span id=\"headingAddon\">(";
397 print "<a href=\"tt-rss.php\">Back</a>, ";
398 print "<a href=\"tt-rss.php?go=sform&aid=$feed&ic=$cat_view\">Search</a>, ";
399 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=ForceUpdate\">Update</a>";
400 # print "Mark as read: ";
401 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAsRead\">Page</a>, ";
402 # print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a>";
403
404 print ")</span>";
405
406 print "</div>";
407
408 if (db_num_rows($result) > 0) {
409
410 print "<ul class=\"headlines\">";
411
412 $page_art_ids = array();
413
414 $lnum = 0;
415
416 error_reporting (DEFAULT_ERROR_LEVEL);
417
418 $num_unread = 0;
419
420 while ($line = db_fetch_assoc($result)) {
421
422 $class = ($lnum % 2) ? "even" : "odd";
423
424 $id = $line["id"];
425 $feed_id = $line["feed_id"];
426
427 array_push($page_art_ids, $id);
428
429 if ($line["last_read"] == "" &&
430 ($line["unread"] != "t" && $line["unread"] != "1")) {
431
432 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
433 alt=\"Updated\">";
434 } else {
435 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
436 alt=\"Updated\">";
437 }
438
439 if ($line["unread"] == "t" || $line["unread"] == "1") {
440 $class .= "Unread";
441 ++$num_unread;
442 $is_unread = true;
443 } else {
444 $is_unread = false;
445 }
446
447 if ($line["marked"] == "t" || $line["marked"] == "1") {
448 $marked_pic = "<img class='marked' src=\"../images/mark_set.png\">";
449 } else {
450 $marked_pic = "<img class='marked' src=\"../images/mark_unset.png\">";
451 }
452
453 $content_link = "<a href=\"?go=view&id=$id&ret_feed=$feed&feed=$feed_id\">" .
454 $line["title"] . "</a>";
455
456 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
457 $updated_fmt = smart_date_time(strtotime($line["updated"]));
458 } else {
459 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
460 $updated_fmt = date($short_date, strtotime($line["updated"]));
461 }
462
463 print "<li class='$class'>";
464
465 print "<a href=\"?go=vf&id=$feed&ts=$id\">$marked_pic</a>";
466
467 print $content_link;
468
469 if ($line["feed_title"]) {
470 print " (<a href='?go=vf&id=$feed_id'>".
471 $line["feed_title"]."</a>)";
472 }
473
474 print "<span class='hlUpdated'> ($updated_fmt)</span>";
475
476 print "</li>";
477
478
479 ++$lnum;
480 }
481
482 print "</ul>";
483
484 print "<div class='footerAddon'>Mark as read: ";
485
486 $_SESSION["last_page_ids.$feed"] = $page_art_ids;
487
488 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkPageRead\">Page</a>, ";
489 print "<a href=\"tt-rss.php?go=vf&id=$feed&subop=MarkAllRead\">Feed</a></div>";
490
491 } else {
492 print "<div align='center'>No articles found.</div>";
493 }
494
495 }
496
497 function render_article($link) {
498
499 $id = db_escape_string($_GET["id"]);
500 $feed_id = db_escape_string($_GET["feed"]);
501 $ret_feed_id = db_escape_string($_GET["ret_feed"]);
502
503 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
504 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
505
506 if (db_num_rows($result) == 1) {
507 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
508 } else {
509 $rtl_content = false;
510 }
511
512 if ($rtl_content) {
513 $rtl_tag = "dir=\"RTL\"";
514 $rtl_class = "RTL";
515 } else {
516 $rtl_tag = "";
517 $rtl_class = "";
518 }
519
520 $result = db_query($link, "UPDATE ttrss_user_entries
521 SET unread = false,last_read = NOW()
522 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
523
524 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
525 SUBSTRING(updated,1,16) as updated,
526 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
527 num_comments,
528 author
529 FROM ttrss_entries,ttrss_user_entries
530 WHERE id = '$id' AND ref_id = id");
531
532 if ($result) {
533
534 $line = db_fetch_assoc($result);
535
536 $num_comments = $line["num_comments"];
537 $entry_comments = "";
538
539 if ($num_comments > 0) {
540 if ($line["comments"]) {
541 $comments_url = $line["comments"];
542 } else {
543 $comments_url = $line["link"];
544 }
545 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
546 } else {
547 if ($line["comments"] && $line["link"] != $line["comments"]) {
548 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
549 }
550 }
551
552 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
553 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
554 ORDER BY tag_name");
555
556 $tags_str = "";
557 $f_tags_str = "";
558
559 $num_tags = 0;
560
561 while ($tmp_line = db_fetch_assoc($tmp_result)) {
562 $num_tags++;
563 $tag = $tmp_line["tag_name"];
564 $tag_str = "<a href=\"?go=vf&id=$tag\">$tag</a>, ";
565 $tags_str .= $tag_str;
566 }
567
568 $tags_str = preg_replace("/, $/", "", $tags_str);
569
570 $parsed_updated = date(get_pref($link, 'SHORT_DATE_FORMAT'),
571 strtotime($line["updated"]));
572
573 print "<div id=\"heading\">";
574
575 # if (file_exists("../icons/$feed_id.ico") && filesize("../icons/$feed_id.ico") > 0) {
576 # print "<img class=\"feedIcon\" src=\"../icons/$feed_id.ico\">";
577 # }
578
579 $feed_link = "<a href=\"tt-rss.php?go=vf&id=$ret_feed_id\">Feed</a>";
580
581 print "<a href=\"" . $line["link"] . "\">" .
582 truncate_string($line["title"], 30) . "</a>";
583 print " <span id=\"headingAddon\">$parsed_updated ($feed_link)</span>";
584 print "</div>";
585
586 if ($num_tags > 0) {
587 print "<div class=\"postTags\">Tags: $tags_str</div>";
588 }
589
590 print sanitize_rss($link, $line["content"], true);;
591
592 }
593
594 print "</body></html>";
595 }
596
597 function render_search_form($link, $active_feed_id = false, $is_cat = false) {
598
599 print "<div id=\"heading\">";
600
601 print "Search <span id=\"headingAddon\">
602 (<a href=\"tt-rss.php\">Go back</a>)</span></div>";
603
604 print "<form method=\"GET\" action=\"tt-rss.php\" class=\"searchForm\">";
605
606 print "<input type=\"hidden\" name=\"go\" value=\"vf\">";
607 print "<input type=\"hidden\" name=\"id\" value=\"$active_feed_id\">";
608 print "<input type=\"hidden\" name=\"cat\" value=\"$is_cat\">";
609
610 print "<table><tr><td>".__('Search:')."</td><td>";
611 print "<input name=\"query\"></td></tr>";
612
613 print "<tr><td>".__('Where:')."</td><td>";
614
615 print "<select name=\"search_mode\">
616 <option value=\"all_feeds\">".__('All feeds')."</option>";
617
618 $feed_title = getFeedTitle($link, $active_feed_id);
619
620 if (!$is_cat) {
621 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
622 } else {
623 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
624 }
625
626 if ($active_feed_id && !$is_cat) {
627 print "<option selected value=\"this_feed\">$feed_title</option>";
628 } else {
629 print "<option disabled>".__('This feed')."</option>";
630 }
631
632 if ($is_cat) {
633 $cat_preselected = "selected";
634 }
635
636 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
637 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
638 } else {
639 //print "<option disabled>".__('This category')."</option>";
640 }
641
642 print "</select></td></tr>";
643
644 print "<tr><td>".__('Match on:')."</td><td>";
645
646 $search_fields = array(
647 "title" => __("Title"),
648 "content" => __("Content"),
649 "both" => __("Title or content"));
650
651 print_select_hash("match_on", 3, $search_fields);
652
653 print "</td></tr></table>";
654
655 print "<input type=\"submit\" value=\"".__('Search')."\">";
656
657 print "</form>";
658
659 print "</div>";
660 }
661
662 ?>