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