]>
git.wh0rd.org - tt-rss.git/blob - mobile/mobile-functions.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
.
3 dirname(__FILE__
) . PATH_SEPARATOR
.
4 dirname(dirname(__FILE__
)) . PATH_SEPARATOR
.
5 dirname(dirname(__FILE__
)) . "/include" );
7 require_once "functions.php";
8 require_once "sessions.php";
9 require_once "version.php";
10 require_once "db-prefs.php";
12 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
14 /* TODO replace with interface to db-prefs */
16 function mobile_pref_toggled($link, $id) {
17 if (get_pref($link, "_MOBILE_$id"))
23 function mobile_get_pref($link, $id) {
24 //return $_SESSION["mobile-prefs"][$id];
25 return get_pref($link, "_MOBILE_$id");
28 function mobile_set_pref($link, $id, $value) {
29 //$_SESSION["mobile-prefs"][$id] = $value;
30 return set_pref($link, "_MOBILE_$id", $value);
33 function mobile_feed_has_icon($id) {
34 $filename = "../".ICONS_DIR
."/$id.ico";
36 return file_exists($filename) && filesize($filename) > 0;
39 function render_flat_feed_list($link, $offset) {
40 $owner_uid = $_SESSION["uid"];
43 if (!$offset) $offset = 0;
45 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
46 $order_by = "unread DESC, title";
52 $limit_qpart = "LIMIT $limit OFFSET $offset";
57 $result = db_query($link, "SELECT id,
59 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
60 WHERE feed_id = ttrss_feeds.id AND unread = true
61 AND ttrss_user_entries.ref_id = ttrss_entries.id
62 AND owner_uid = '$owner_uid') AS unread
65 ttrss_feeds.owner_uid = '$owner_uid'
66 ORDER BY $order_by $limit_qpart");
68 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
69 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
72 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
76 while ($line = db_fetch_assoc($result)) {
78 $unread = $line["unread"];
80 // $unread = rand(0, 100);
83 $line["title"] = $line["title"] . " ($unread)";
89 if (mobile_feed_has_icon($id)) {
90 $icon_url = "../".ICONS_URL
."/$id.ico";
92 $icon_url = "../images/blank_icon.gif";
95 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
96 print "<li class='$class'><a href='feed.php?id=$id'>" .
97 "<img class='tinyIcon' src='$icon_url'/>".
98 $line["title"] . "</a></li>";
104 /* $next_offset = $offset + $num_feeds;
106 print "<li><a href=\"home.php?skip=$next_offset\"
107 target=\"_replace\">Show more feeds...</a></li>"; */
109 if (!$offset) print "</ul>";
113 function render_category($link, $cat_id, $offset) {
114 $owner_uid = $_SESSION["uid"];
119 $cat_query = "cat_id = '$cat_id'";
121 $cat_query = "cat_id IS NULL";
124 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
125 $order_by = "unread DESC, title";
130 $result = db_query($link, "SELECT id,
132 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
133 WHERE feed_id = ttrss_feeds.id AND unread = true
134 AND ttrss_user_entries.ref_id = ttrss_entries.id
135 AND owner_uid = '$owner_uid') as unread
138 ttrss_feeds.owner_uid = '$owner_uid' AND
140 ORDER BY $order_by");
142 $title = getCategoryTitle($link, $cat_id);
144 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
145 myBackHref='home.php'>";
147 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
149 while ($line = db_fetch_assoc($result)) {
151 $unread = $line["unread"];
153 // $unread = rand(0, 100);
156 $line["title"] = $line["title"] . " ($unread)";
162 if (mobile_feed_has_icon($id)) {
163 $icon_url = "../".ICONS_URL
."/$id.ico";
165 $icon_url = "../images/blank_icon.gif";
168 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
169 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
170 "<img class='tinyIcon' src='$icon_url'/>".
171 $line["title"] . "</a></li>";
176 } else if ($cat_id == -1) {
178 $title = __('Special');
180 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
181 myBackHref='home.php'>";
183 foreach (array(-4, -3, -1, -2, 0) as $id) {
184 $title = getFeedTitle($link, $id);
185 $unread = getFeedUnread($link, $id, false);
186 $icon = getFeedIcon($id);
189 $title = $title . " ($unread)";
195 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
196 print "<li class='$class'>
197 <a href='feed.php?id=$id&cat=-1'>
198 <img class='tinyIcon' src='../$icon'/>$title</a></li>";
203 } else if ($cat_id == -2) {
205 $title = __('Labels');
207 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
208 myBackHref='home.php'>";
210 $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
211 WHERE owner_uid = '$owner_uid'");
213 $label_data = array();
215 while ($line = db_fetch_assoc($result)) {
217 $id = -$line["id"] - 11;
219 $unread = getFeedUnread($link, $id);
220 $title = $line["caption"];
223 $title = $title . " ($unread)";
229 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
230 print "<li class='$class'>
231 <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
238 function render_categories_list($link) {
239 $owner_uid = $_SESSION["uid"];
241 $cat_browse = mobile_get_pref($link, "BROWSE_CATS");
243 print '<ul id="home" title="'.__('Home').'" selected="true"
244 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
246 // print "<li><a href='#searchForm'>Search...</a></li>";
248 foreach (array(-1, -2) as $id) {
249 $title = getCategoryTitle($link, $id);
250 $unread = getFeedUnread($link, $id, true);
252 $title = $title . " ($unread)";
259 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
261 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>$title</a></li>";
264 $result = db_query($link, "SELECT
265 ttrss_feed_categories.id,
266 ttrss_feed_categories.title,
267 COUNT(ttrss_feeds.id) AS num_feeds
268 FROM ttrss_feed_categories, ttrss_feeds
269 WHERE ttrss_feed_categories.owner_uid = $owner_uid
270 AND ttrss_feed_categories.id = cat_id
271 GROUP BY ttrss_feed_categories.id,
272 ttrss_feed_categories.title
273 ORDER BY ttrss_feed_categories.title");
275 while ($line = db_fetch_assoc($result)) {
277 if ($line["num_feeds"] > 0) {
279 $unread = getFeedUnread($link, $line["id"], true);
283 $line["title"] = $line["title"] . " ($unread)";
289 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
292 print "<li class='$class'><a href='cat.php?id=$id'>" .
293 $line["title"] . "</a></li>";
295 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>".
296 $line["title"] . "</a></li>";
302 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
303 cat_id IS NULL and owner_uid = '$owner_uid'");
305 $num_feeds = db_fetch_result($result, 0, "nf");
307 if ($num_feeds > 0) {
308 $unread = getFeedUnread($link, 0, true);
309 $title = "Uncategorized";
312 $title = "$title ($unread)";
318 if ($unread > 0 ||
!mobile_get_pref($link, "HIDE_READ")) {
320 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
322 print "<li class='$class'><a href='feed.php?id=0&is_cat=true'>$title</a></li>";
330 function render_headlines_list($link, $feed_id, $cat_id, $offset, $search,
337 if (!mobile_get_pref($link, "HIDE_READ"))
338 $view_mode = "all_articles";
340 $view_mode = 'adaptive';
343 $search_mode = 'this_feed';
350 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
351 $view_mode, $is_cat, $search, $search_mode, $match_on,
352 "score DESC, date_entered DESC", $offset);
354 $result = $qfh_ret[0];
355 $feed_title = $qfh_ret[1];
359 print "<form id=\"searchForm-$feed_id-$cat_id\" class=\"dialog\" method=\"POST\"
362 <input type=\"hidden\" name=\"id\" value=\"$feed_id\">
363 <input type=\"hidden\" name=\"cat\" value=\"$cat_id\">
367 <a class=\"button leftButton\" type=\"cancel\">Cancel</a>
368 <a class=\"button blueButton\" type=\"submit\">Search</a>
370 <label>Search:</label>
371 <input id=\"search\" type=\"text\" name=\"search\"/>
376 $cat_title = getCategoryTitle($link, $cat_id);
378 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
379 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
381 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
382 myBackLabel='".__("Home")."' myBackHref='home.php'>";
385 print "<li><a href='#searchForm-$feed_id-$cat_id'>Search...</a></li>";
390 while ($line = db_fetch_assoc($result)) {
392 $real_feed_id = $line["feed_id"];
394 if (sql_bool_to_bool($line["unread"])) {
400 if (mobile_feed_has_icon($real_feed_id)) {
401 $icon_url = "../".ICONS_URL
."/$real_feed_id.ico";
403 $icon_url = "../images/blank_icon.gif";
406 print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id&is_cat=$is_cat'>
407 <img class='tinyIcon' src='$icon_url'>";
408 print $line["title"];
415 if ($num_headlines == 0 && $search) {
416 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset";
418 print "<li><a href=\"$articles_url\">" . __("Nothing found (click to reload feed).") . "</a></li>";
422 // print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>";
424 $next_offset = $offset +
$num_headlines;
425 $num_unread = getFeedUnread($link, $feed_id, $is_cat);
427 /* FIXME needs normal implementation */
429 if ($num_headlines > 0 && ($num_unread == 0 ||
$num_unread > $next_offset)) {
432 $articles_url = "feed.php?id=$feed_id&skip=$next_offset".
433 "&search=$search&is_cat=true";
435 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset".
439 print "<li><a href=\"$articles_url\"
440 target=\"_replace\">Get more articles...</a></li>";
443 if (!$offset) print "</ul>";
447 function render_article($link, $id, $feed_id, $cat_id, $is_cat) {
449 $query = "SELECT title,link,content,feed_id,comments,int_id,
450 marked,unread,published,
451 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
453 FROM ttrss_entries,ttrss_user_entries
454 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
457 $result = db_query($link, $query);
459 if (db_num_rows($result) != 0) {
461 $line = db_fetch_assoc($result);
463 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
464 SET unread = false,last_read = NOW()
466 AND owner_uid = " . $_SESSION["uid"]);
468 $updated_fmt = make_local_datetime($link, $line['updated'], false);
470 $title = $line["title"];
471 $article_link = $line["link"];
474 $feed_title = getFeedTitle($link, $feed_id);
476 $feed_title = getCategoryTitle($link, $feed_id);
478 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
480 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id&is_cat=$is_cat'>";
482 if ($line['feed_id'] != $feed_id) {
483 $real_feed_title = getFeedTitle($link, $line['feed_id']);
484 $real_feed_id = $line['feed_id'];
485 $feed_link = "(<a href=\"feed.php?id=$real_feed_id\">$real_feed_title</a>)";
487 // print "<fieldset>";
489 print "<div style='float : right'>($updated_fmt)</div>";
491 print "<h2><a target='_blank' href='$article_link'>$title</a> $feed_link</h2>";
495 /* print "<div class=\"row\">";
496 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
499 $is_starred = (sql_bool_to_bool($line["marked"])) ?
"true" : "false";
500 $is_published = (sql_bool_to_bool($line["published"])) ?
"true" : "false";
502 //print "<div class=\"row\">";
503 //print "<label id='updated'>Updated:</label>";
504 //print "<input type='text' enabled='false' name='updated' disabled value='$updated_fmt'/>";
507 // print "</fieldset>";
509 $content = sanitize($link, $line["content"]);
510 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
512 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
513 $content = preg_replace('/<img[^>]+>/is', '', $content);
516 print "<p>$content</p>";
518 print "<div class='nav'>
519 <label>Navigation</label>
520 <div class='button left' onclick='goPrev($id, $feed_id, this)'>Prev</div>
521 <div class='button right' onclick='goNext($id, $feed_id, this)'>Next</div>
526 print "<div class=\"row\">
527 <label>Starred</label>
528 <div class=\"toggle\" onclick=\"toggleMarked($id, this)\" toggled=\"$is_starred\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>
531 print "<div class=\"row\">
532 <label>Published</label>
533 <div class=\"toggle\" onclick=\"togglePublished($id, this)\" toggled=\"$is_published\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>
536 print "<div class=\"row\">
537 <label>Unread</label>
538 <div class=\"toggle\" onclick=\"toggleUnread($id, this)\" toggled=\"$is_unread\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>