]> git.wh0rd.org - tt-rss.git/blame - mobile/functions.php
reduce the number of always included libraries
[tt-rss.git] / mobile / functions.php
CommitLineData
e9e95dae 1<?php
3dd46f19 2 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
0d3adafe 3
f0a0c1ff
AD
4 /* TODO replace with interface to db-prefs */
5
6 function mobile_pref_toggled($link, $id) {
4308d33f 7 if (get_pref($link, "_MOBILE_$id"))
e9105eb5
AD
8 return "true";
9 else
10 return "";
f0a0c1ff
AD
11 }
12
13 function mobile_get_pref($link, $id) {
e9105eb5
AD
14 //return $_SESSION["mobile-prefs"][$id];
15 return get_pref($link, "_MOBILE_$id");
f0a0c1ff
AD
16 }
17
18 function mobile_set_pref($link, $id, $value) {
e9105eb5
AD
19 //$_SESSION["mobile-prefs"][$id] = $value;
20 return set_pref($link, "_MOBILE_$id", $value);
f0a0c1ff
AD
21 }
22
3518718b
AD
23 function mobile_feed_has_icon($id) {
24 $filename = "../".ICONS_DIR."/$id.ico";
42096f52 25
3518718b
AD
26 return file_exists($filename) && filesize($filename) > 0;
27 }
42096f52 28
95004daf 29 function render_flat_feed_list($link, $offset) {
b1bd222c 30 $owner_uid = $_SESSION["uid"];
af88c48a 31 $limit = 0;
95004daf
AD
32
33 if (!$offset) $offset = 0;
b1bd222c 34
f0a0c1ff
AD
35 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
36 $order_by = "unread DESC, title";
37 } else {
38 $order_by = "title";
39 }
40
af88c48a
AD
41 if ($limit > 0) {
42 $limit_qpart = "LIMIT $limit OFFSET $offset";
43 } else {
44 $limit_qpart = "";
45 }
46
b1bd222c
AD
47 $result = db_query($link, "SELECT id,
48 title,
49 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
50 WHERE feed_id = ttrss_feeds.id AND unread = true
51 AND ttrss_user_entries.ref_id = ttrss_entries.id
af88c48a 52 AND owner_uid = '$owner_uid') AS unread
b1bd222c 53 FROM ttrss_feeds
4308d33f 54 WHERE
6e63a7c3 55 ttrss_feeds.owner_uid = '$owner_uid'
4308d33f
AD
56 ORDER BY $order_by $limit_qpart");
57
95004daf 58 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
9ab798a5 59 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
b1bd222c 60
af88c48a 61
b1bd222c 62 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
95004daf
AD
63
64 $num_feeds = 0;
65
b1bd222c
AD
66 while ($line = db_fetch_assoc($result)) {
67 $id = $line["id"];
68 $unread = $line["unread"];
69
70 // $unread = rand(0, 100);
4308d33f 71
b1bd222c
AD
72 if ($unread > 0) {
73 $line["title"] = $line["title"] . " ($unread)";
74 $class = '';
75 } else {
76 $class = 'oldItem';
77 }
4308d33f 78
b1bd222c
AD
79 if (mobile_feed_has_icon($id)) {
80 $icon_url = "../".ICONS_URL."/$id.ico";
81 } else {
82 $icon_url = "../images/blank_icon.gif";
83 }
f0a0c1ff
AD
84
85 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
4308d33f
AD
86 print "<li class='$class'><a href='feed.php?id=$id'>" .
87 "<img class='tinyIcon' src='$icon_url'/>".
f0a0c1ff
AD
88 $line["title"] . "</a></li>";
89 }
af88c48a
AD
90
91 ++$num_feeds;
b1bd222c 92 }
b1bd222c 93
af88c48a 94/* $next_offset = $offset + $num_feeds;
95004daf 95
4308d33f 96 print "<li><a href=\"home.php?skip=$next_offset\"
af88c48a 97 target=\"_replace\">Show more feeds...</a></li>"; */
b1bd222c 98
95004daf 99 if (!$offset) print "</ul>";
b1bd222c
AD
100
101 }
102
cfad9259 103 function render_category($link, $cat_id, $offset) {
3518718b 104 $owner_uid = $_SESSION["uid"];
4308d33f 105
e2b7a855 106 if ($cat_id >= 0) {
85233b8e 107
e2b7a855
AD
108 if ($cat_id != 0) {
109 $cat_query = "cat_id = '$cat_id'";
3518718b 110 } else {
e2b7a855 111 $cat_query = "cat_id IS NULL";
0d3adafe 112 }
f0a0c1ff
AD
113
114 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
115 $order_by = "unread DESC, title";
116 } else {
117 $order_by = "title";
118 }
119
e2b7a855
AD
120 $result = db_query($link, "SELECT id,
121 title,
122 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
123 WHERE feed_id = ttrss_feeds.id AND unread = true
124 AND ttrss_user_entries.ref_id = ttrss_entries.id
125 AND owner_uid = '$owner_uid') as unread
126 FROM ttrss_feeds
4308d33f
AD
127 WHERE
128 ttrss_feeds.owner_uid = '$owner_uid' AND
e2b7a855 129 $cat_query
4308d33f
AD
130 ORDER BY $order_by");
131
e2b7a855 132 $title = getCategoryTitle($link, $cat_id);
4308d33f 133
9ab798a5 134 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
bf974b02 135 myBackHref='home.php'>";
4308d33f 136
e2b7a855 137 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
4308d33f 138
e2b7a855
AD
139 while ($line = db_fetch_assoc($result)) {
140 $id = $line["id"];
141 $unread = $line["unread"];
3e94601e 142
e2b7a855 143 // $unread = rand(0, 100);
4308d33f 144
e2b7a855
AD
145 if ($unread > 0) {
146 $line["title"] = $line["title"] . " ($unread)";
147 $class = '';
148 } else {
149 $class = 'oldItem';
150 }
4308d33f 151
e2b7a855
AD
152 if (mobile_feed_has_icon($id)) {
153 $icon_url = "../".ICONS_URL."/$id.ico";
154 } else {
155 $icon_url = "../images/blank_icon.gif";
156 }
f0a0c1ff
AD
157
158 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
4308d33f
AD
159 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
160 "<img class='tinyIcon' src='$icon_url'/>".
f0a0c1ff
AD
161 $line["title"] . "</a></li>";
162 }
0d3adafe 163 }
4308d33f 164
e2b7a855
AD
165 print "</ul>";
166 } else if ($cat_id == -1) {
167
17fd15be
AD
168 $title = __('Special');
169
9ab798a5
AD
170 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
171 myBackHref='home.php'>";
e2b7a855 172
87e3d2dd 173 foreach (array(-4, -3, -1, -2, 0) as $id) {
e2b7a855
AD
174 $title = getFeedTitle($link, $id);
175 $unread = getFeedUnread($link, $id, false);
af88c48a 176 $icon = getFeedIcon($id);
e2b7a855
AD
177
178 if ($unread > 0) {
179 $title = $title . " ($unread)";
180 $class = '';
181 } else {
182 $class = 'oldItem';
eead4d26 183 }
8e3f7217 184
f0a0c1ff
AD
185 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
186 print "<li class='$class'>
af88c48a
AD
187 <a href='feed.php?id=$id&cat=-1'>
188 <img class='tinyIcon' src='../$icon'/>$title</a></li>";
f0a0c1ff 189 }
e2b7a855 190 }
8e3f7217 191
17fd15be
AD
192 print "</ul>";
193 } else if ($cat_id == -2) {
194
195 $title = __('Labels');
196
9ab798a5
AD
197 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
198 myBackHref='home.php'>";
17fd15be
AD
199
200 $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
201 WHERE owner_uid = '$owner_uid'");
202
203 $label_data = array();
204
205 while ($line = db_fetch_assoc($result)) {
206
207 $id = -$line["id"] - 11;
208
209 $unread = getFeedUnread($link, $id);
210 $title = $line["caption"];
211
212 if ($unread > 0) {
213 $title = $title . " ($unread)";
214 $class = '';
215 } else {
216 $class = 'oldItem';
217 }
218
f0a0c1ff
AD
219 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
220 print "<li class='$class'>
221 <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
222 }
17fd15be 223 }
e2b7a855
AD
224 print "</ul>";
225 }
0d3adafe
AD
226 }
227
3518718b
AD
228 function render_categories_list($link) {
229 $owner_uid = $_SESSION["uid"];
cfad9259
AD
230
231 $cat_browse = mobile_get_pref($link, "BROWSE_CATS");
232
9ab798a5
AD
233 print '<ul id="home" title="'.__('Home').'" selected="true"
234 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
4308d33f 235
3585a3c5
AD
236// print "<li><a href='#searchForm'>Search...</a></li>";
237
3518718b
AD
238 foreach (array(-1, -2) as $id) {
239 $title = getCategoryTitle($link, $id);
240 $unread = getFeedUnread($link, $id, true);
4308d33f 241 if ($unread > 0) {
3518718b
AD
242 $title = $title . " ($unread)";
243 $class = '';
eead4d26 244 } else {
3518718b 245 $class = 'oldItem';
c878bc01 246 }
2f468537 247
cfad9259
AD
248 if ($cat_browse)
249 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
250 else
251 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>$title</a></li>";
2f468537
AD
252 }
253
4308d33f
AD
254 $result = db_query($link, "SELECT
255 ttrss_feed_categories.id,
256 ttrss_feed_categories.title,
257 COUNT(ttrss_feeds.id) AS num_feeds
3518718b 258 FROM ttrss_feed_categories, ttrss_feeds
4308d33f
AD
259 WHERE ttrss_feed_categories.owner_uid = $owner_uid
260 AND ttrss_feed_categories.id = cat_id
261 GROUP BY ttrss_feed_categories.id,
3518718b
AD
262 ttrss_feed_categories.title
263 ORDER BY ttrss_feed_categories.title");
2f468537 264
3518718b 265 while ($line = db_fetch_assoc($result)) {
fc46ab83 266
3518718b 267 if ($line["num_feeds"] > 0) {
2f468537 268
3518718b 269 $unread = getFeedUnread($link, $line["id"], true);
2f468537 270 $id = $line["id"];
510ac75f 271
3518718b
AD
272 if ($unread > 0) {
273 $line["title"] = $line["title"] . " ($unread)";
274 $class = '';
510ac75f 275 } else {
3518718b 276 $class = 'oldItem';
510ac75f 277 }
2f468537 278
f0a0c1ff 279 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
cfad9259 280
4308d33f
AD
281 if ($cat_browse)
282 print "<li class='$class'><a href='cat.php?id=$id'>" .
cfad9259
AD
283 $line["title"] . "</a></li>";
284 else
285 print "<li class='$class'><a href='feed.php?id=$id&is_cat=true'>".
286 $line["title"] . "</a></li>";
f0a0c1ff 287 }
2f468537 288 }
2f468537
AD
289 }
290
2f468537 291
3518718b
AD
292 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
293 cat_id IS NULL and owner_uid = '$owner_uid'");
42096f52 294
3518718b 295 $num_feeds = db_fetch_result($result, 0, "nf");
42096f52 296
3518718b
AD
297 if ($num_feeds > 0) {
298 $unread = getFeedUnread($link, 0, true);
299 $title = "Uncategorized";
42096f52 300
3518718b
AD
301 if ($unread > 0) {
302 $title = "$title ($unread)";
303 $class = '';
42096f52 304 } else {
3518718b 305 $class = 'oldItem';
42096f52
AD
306 }
307
f0a0c1ff 308 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
4308d33f
AD
309 if ($cat_browse)
310 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
311 else
312 print "<li class='$class'><a href='feed.php?id=0&is_cat=true'>$title</a></li>";
313
f0a0c1ff 314 }
3518718b 315 }
42096f52 316
3518718b
AD
317 print "</ul>";
318 }
24ac6776 319
4308d33f 320 function render_headlines_list($link, $feed_id, $cat_id, $offset, $search,
cfad9259 321 $is_cat = false) {
24ac6776 322
3518718b 323 $feed_id = $feed_id;
78d7a965 324 $limit = 15;
3518718b 325 $filter = '';
2e2d0802
AD
326
327 if (!mobile_get_pref($link, "HIDE_READ"))
328 $view_mode = "all_articles";
329 else
330 $view_mode = 'adaptive';
d9aad400 331
3585a3c5
AD
332 if ($search) {
333 $search_mode = 'this_feed';
334 $match_on = 'both';
335 } else {
336 $search_mode = '';
337 $match_on = '';
338 }
78d7a965 339
4308d33f 340 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
2e2d0802 341 $view_mode, $is_cat, $search, $search_mode, $match_on,
b9fca867 342 "score DESC, date_entered DESC", $offset);
541890fb 343
3518718b
AD
344 $result = $qfh_ret[0];
345 $feed_title = $qfh_ret[1];
42096f52 346
78d7a965 347 if (!$offset) {
3585a3c5 348
4308d33f 349 print "<form id=\"searchForm-$feed_id-$cat_id\" class=\"dialog\" method=\"POST\"
3585a3c5
AD
350 action=\"feed.php\">
351
352 <input type=\"hidden\" name=\"id\" value=\"$feed_id\">
353 <input type=\"hidden\" name=\"cat\" value=\"$cat_id\">
354
355 <fieldset>
cb216e9d 356 <h1>Search</h1>
3585a3c5
AD
357 <a class=\"button leftButton\" type=\"cancel\">Cancel</a>
358 <a class=\"button blueButton\" type=\"submit\">Search</a>
359
360 <label>Search:</label>
361 <input id=\"search\" type=\"text\" name=\"search\"/>
362 </fieldset>
4308d33f 363 </form>";
3585a3c5 364
78d7a965
AD
365 if ($cat_id) {
366 $cat_title = getCategoryTitle($link, $cat_id);
3e092346 367
78d7a965
AD
368 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
369 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
370 } else {
371 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
372 myBackLabel='".__("Home")."' myBackHref='home.php'>";
373 }
3585a3c5 374
cb216e9d 375 print "<li><a href='#searchForm-$feed_id-$cat_id'>Search...</a></li>";
b1bd222c 376 }
24ac6776 377
78d7a965
AD
378 $num_headlines = 0;
379
3518718b
AD
380 while ($line = db_fetch_assoc($result)) {
381 $id = $line["id"];
3e94601e 382 $real_feed_id = $line["feed_id"];
f70f7e28 383
3518718b
AD
384 if (sql_bool_to_bool($line["unread"])) {
385 $class = '';
f70f7e28 386 } else {
3518718b 387 $class = 'oldItem';
f70f7e28
AD
388 }
389
3e94601e
AD
390 if (mobile_feed_has_icon($real_feed_id)) {
391 $icon_url = "../".ICONS_URL."/$real_feed_id.ico";
392 } else {
393 $icon_url = "../images/blank_icon.gif";
394 }
395
9de6ced1 396 print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id&is_cat=$is_cat'>
3e94601e 397 <img class='tinyIcon' src='$icon_url'>";
3518718b
AD
398 print $line["title"];
399 print "</a></li>";
4a596be6 400
78d7a965
AD
401 ++$num_headlines;
402
42096f52
AD
403 }
404
3585a3c5
AD
405 if ($num_headlines == 0 && $search) {
406 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset";
407
408 print "<li><a href=\"$articles_url\">" . __("Nothing found (click to reload feed).") . "</a></li>";
409
410 }
411
78d7a965
AD
412// print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>";
413
414 $next_offset = $offset + $num_headlines;
415 $num_unread = getFeedUnread($link, $feed_id, $is_cat);
416
417 /* FIXME needs normal implementation */
418
3585a3c5
AD
419 if ($num_headlines > 0 && ($num_unread == 0 || $num_unread > $next_offset)) {
420
c3ad0b75
AD
421 if ($is_cat) {
422 $articles_url = "feed.php?id=$feed_id&skip=$next_offset".
423 "&search=$search&is_cat=true";
424 } else {
425 $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset".
426 "&search=$search";
427 }
3585a3c5 428
4308d33f 429 print "<li><a href=\"$articles_url\"
78d7a965
AD
430 target=\"_replace\">Get more articles...</a></li>";
431 }
432
433 if (!$offset) print "</ul>";
3518718b 434
42096f52
AD
435 }
436
9de6ced1 437 function render_article($link, $id, $feed_id, $cat_id, $is_cat) {
0809065e 438
3518718b
AD
439 $query = "SELECT title,link,content,feed_id,comments,int_id,
440 marked,unread,published,
441 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
442 author
443 FROM ttrss_entries,ttrss_user_entries
4308d33f 444 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
3518718b 445 $_SESSION["uid"] ;
0809065e 446
3518718b 447 $result = db_query($link, $query);
0809065e 448
3e092346 449 if (db_num_rows($result) != 0) {
0809065e 450
3e092346 451 $line = db_fetch_assoc($result);
0809065e 452
4308d33f
AD
453 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
454 SET unread = false,last_read = NOW()
3e092346
AD
455 WHERE ref_id = '$id'
456 AND owner_uid = " . $_SESSION["uid"]);
0809065e 457
324944f3
AD
458 $updated_fmt = make_local_datetime($link, $line['updated'], false);
459
3e092346
AD
460 $title = $line["title"];
461 $article_link = $line["link"];
4308d33f 462
9de6ced1
AD
463 if (!$is_cat)
464 $feed_title = getFeedTitle($link, $feed_id);
465 else
466 $feed_title = getCategoryTitle($link, $feed_id);
4308d33f
AD
467
468 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
3e092346 469 selected=\"true\"
9de6ced1 470 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id&is_cat=$is_cat'>";
4308d33f 471
c4904f2b
AD
472 if ($line['feed_id'] != $feed_id) {
473 $real_feed_title = getFeedTitle($link, $line['feed_id']);
474 $real_feed_id = $line['feed_id'];
475 $feed_link = "(<a href=\"feed.php?id=$real_feed_id\">$real_feed_title</a>)";
476 }
477// print "<fieldset>";
478
479 print "<div style='float : right'>($updated_fmt)</div>";
480
481 print "<h2><a target='_blank' href='$article_link'>$title</a> $feed_link</h2>";
4308d33f 482
c4904f2b 483 print "<hr>";
4308d33f 484
bf974b02 485/* print "<div class=\"row\">";
3e092346 486 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
bf974b02 487 print "</div>"; */
4308d33f 488
3e092346
AD
489 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
490 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
4308d33f 491
c4904f2b
AD
492 //print "<div class=\"row\">";
493 //print "<label id='updated'>Updated:</label>";
9abc6715 494 //print "<input type='text' enabled='false' name='updated' disabled value='$updated_fmt'/>";
c4904f2b 495 //print "</div>";
4308d33f 496
c4904f2b 497// print "</fieldset>";
3bac78a0
AD
498
499 $content = sanitize_rss($link, $line["content"]);
500 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
501
f0a0c1ff
AD
502 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
503 $content = preg_replace('/<img[^>]+>/is', '', $content);
504 }
505
706fe949 506 print "<p>$content</p>";
6101b0e1 507
a6d56d81
AD
508 print "<div class='nav'>
509 <label>Navigation</label>
510 <div class='button left' onclick='goPrev($id, $feed_id, this)'>Prev</div>
511 <div class='button right' onclick='goNext($id, $feed_id, this)'>Next</div>
512 </div>";
513
6101b0e1
AD
514 print "<fieldset>";
515
516 print "<div class=\"row\">
517 <label>Starred</label>
518 <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>
519 </div>";
4308d33f 520
6101b0e1
AD
521 print "<div class=\"row\">
522 <label>Published</label>
523 <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>
524 </div>";
525
b9fca867
AD
526 print "<div class=\"row\">
527 <label>Unread</label>
528 <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>
529 </div>";
530
531
6101b0e1
AD
532 print "</fieldset>";
533
3e092346 534 print "</div>";
f70f7e28 535
3e092346 536 }
4a596be6 537 }
0d3adafe 538?>