]> git.wh0rd.org - tt-rss.git/blame - mobile/functions.php
mobile: implement WIP pagination for flat feedlist
[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) {
7 if ($_SESSION["mobile-prefs"][$id]) return "true";
8
9 }
10
11 function mobile_get_pref($link, $id) {
12 return $_SESSION["mobile-prefs"][$id];
13 }
14
15 function mobile_set_pref($link, $id, $value) {
16 $_SESSION["mobile-prefs"][$id] = $value;
17 }
18
3518718b
AD
19 function mobile_feed_has_icon($id) {
20 $filename = "../".ICONS_DIR."/$id.ico";
42096f52 21
3518718b
AD
22 return file_exists($filename) && filesize($filename) > 0;
23 }
42096f52 24
95004daf 25 function render_flat_feed_list($link, $offset) {
b1bd222c 26 $owner_uid = $_SESSION["uid"];
95004daf
AD
27 $limit = 30;
28
29 if (!$offset) $offset = 0;
b1bd222c 30
f0a0c1ff
AD
31 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
32 $order_by = "unread DESC, title";
33 } else {
34 $order_by = "title";
35 }
36
b1bd222c
AD
37 $result = db_query($link, "SELECT id,
38 title,
39 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
40 WHERE feed_id = ttrss_feeds.id AND unread = true
41 AND ttrss_user_entries.ref_id = ttrss_entries.id
42 AND owner_uid = '$owner_uid') as unread
43 FROM ttrss_feeds
44 WHERE
45 ttrss_feeds.hidden = false AND
46 ttrss_feeds.owner_uid = '$owner_uid' AND
47 parent_feed IS NULL
95004daf 48 ORDER BY $order_by LIMIT $limit OFFSET $offset");
b1bd222c 49
95004daf 50 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
9ab798a5 51 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
b1bd222c
AD
52
53 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
95004daf
AD
54
55 $num_feeds = 0;
56
b1bd222c
AD
57 while ($line = db_fetch_assoc($result)) {
58 $id = $line["id"];
59 $unread = $line["unread"];
60
61 // $unread = rand(0, 100);
62
63 if ($unread > 0) {
64 $line["title"] = $line["title"] . " ($unread)";
65 $class = '';
66 } else {
67 $class = 'oldItem';
68 }
69
70 if (mobile_feed_has_icon($id)) {
71 $icon_url = "../".ICONS_URL."/$id.ico";
72 } else {
73 $icon_url = "../images/blank_icon.gif";
74 }
f0a0c1ff
AD
75
76 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
77 print "<li class='$class'><a href='feed.php?id=$id'>" .
78 "<img class='tinyIcon' src='$icon_url'/>".
79 $line["title"] . "</a></li>";
95004daf 80 ++$num_feeds;
f0a0c1ff 81 }
b1bd222c 82 }
b1bd222c 83
95004daf
AD
84 $next_offset = $offset + $num_feeds;
85
86 print "<li><a href=\"home.php?skip=$next_offset\"
87 target=\"_replace\">Show more feeds...</a></li>";
b1bd222c 88
95004daf 89 if (!$offset) print "</ul>";
b1bd222c
AD
90
91 }
92
3518718b
AD
93 function render_category($link, $cat_id) {
94 $owner_uid = $_SESSION["uid"];
42096f52 95
e2b7a855 96 if ($cat_id >= 0) {
85233b8e 97
e2b7a855
AD
98 if ($cat_id != 0) {
99 $cat_query = "cat_id = '$cat_id'";
3518718b 100 } else {
e2b7a855 101 $cat_query = "cat_id IS NULL";
0d3adafe 102 }
f0a0c1ff
AD
103
104 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
105 $order_by = "unread DESC, title";
106 } else {
107 $order_by = "title";
108 }
109
e2b7a855
AD
110 $result = db_query($link, "SELECT id,
111 title,
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 FROM ttrss_feeds
117 WHERE
118 ttrss_feeds.hidden = false AND
119 ttrss_feeds.owner_uid = '$owner_uid' AND
120 parent_feed IS NULL AND
121 $cat_query
f0a0c1ff 122 ORDER BY $order_by");
e2b7a855
AD
123
124 $title = getCategoryTitle($link, $cat_id);
125
9ab798a5 126 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
bf974b02 127 myBackHref='home.php'>";
e2b7a855
AD
128
129 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
130
131 while ($line = db_fetch_assoc($result)) {
132 $id = $line["id"];
133 $unread = $line["unread"];
3e94601e 134
e2b7a855
AD
135 // $unread = rand(0, 100);
136
137 if ($unread > 0) {
138 $line["title"] = $line["title"] . " ($unread)";
139 $class = '';
140 } else {
141 $class = 'oldItem';
142 }
143
144 if (mobile_feed_has_icon($id)) {
145 $icon_url = "../".ICONS_URL."/$id.ico";
146 } else {
147 $icon_url = "../images/blank_icon.gif";
148 }
f0a0c1ff
AD
149
150 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
151 print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" .
152 "<img class='tinyIcon' src='$icon_url'/>".
153 $line["title"] . "</a></li>";
154 }
0d3adafe 155 }
e2b7a855
AD
156
157 print "</ul>";
158 } else if ($cat_id == -1) {
159
17fd15be
AD
160 $title = __('Special');
161
9ab798a5
AD
162 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
163 myBackHref='home.php'>";
e2b7a855
AD
164
165 foreach (array(-4, -1,-2,-3) as $id) {
166 $title = getFeedTitle($link, $id);
167 $unread = getFeedUnread($link, $id, false);
168
169 if ($unread > 0) {
170 $title = $title . " ($unread)";
171 $class = '';
172 } else {
173 $class = 'oldItem';
eead4d26 174 }
8e3f7217 175
f0a0c1ff
AD
176 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
177 print "<li class='$class'>
178 <a href='feed.php?id=$id&cat_id=-1'>$title</a></li>";
179 }
e2b7a855 180 }
8e3f7217 181
17fd15be
AD
182 print "</ul>";
183 } else if ($cat_id == -2) {
184
185 $title = __('Labels');
186
9ab798a5
AD
187 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
188 myBackHref='home.php'>";
17fd15be
AD
189
190 $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
191 WHERE owner_uid = '$owner_uid'");
192
193 $label_data = array();
194
195 while ($line = db_fetch_assoc($result)) {
196
197 $id = -$line["id"] - 11;
198
199 $unread = getFeedUnread($link, $id);
200 $title = $line["caption"];
201
202 if ($unread > 0) {
203 $title = $title . " ($unread)";
204 $class = '';
205 } else {
206 $class = 'oldItem';
207 }
208
f0a0c1ff
AD
209 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
210 print "<li class='$class'>
211 <a href='feed.php?id=$id&cat=-2'>$title</a></li>";
212 }
17fd15be 213 }
e2b7a855
AD
214 print "</ul>";
215 }
0d3adafe
AD
216 }
217
3518718b
AD
218 function render_categories_list($link) {
219 $owner_uid = $_SESSION["uid"];
2f468537 220
2f468537 221
9ab798a5
AD
222 print '<ul id="home" title="'.__('Home').'" selected="true"
223 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
eead4d26 224
3518718b
AD
225 foreach (array(-1, -2) as $id) {
226 $title = getCategoryTitle($link, $id);
227 $unread = getFeedUnread($link, $id, true);
228 if ($unread > 0) {
229 $title = $title . " ($unread)";
230 $class = '';
eead4d26 231 } else {
3518718b 232 $class = 'oldItem';
c878bc01 233 }
2f468537 234
3518718b 235 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
2f468537
AD
236 }
237
3518718b
AD
238 $result = db_query($link, "SELECT
239 ttrss_feed_categories.id,
240 ttrss_feed_categories.title,
241 COUNT(ttrss_feeds.id) AS num_feeds
242 FROM ttrss_feed_categories, ttrss_feeds
243 WHERE ttrss_feed_categories.owner_uid = $owner_uid
244 AND ttrss_feed_categories.id = cat_id
245 AND hidden = false
246 GROUP BY ttrss_feed_categories.id,
247 ttrss_feed_categories.title
248 ORDER BY ttrss_feed_categories.title");
2f468537 249
3518718b 250 while ($line = db_fetch_assoc($result)) {
fc46ab83 251
3518718b 252 if ($line["num_feeds"] > 0) {
2f468537 253
3518718b 254 $unread = getFeedUnread($link, $line["id"], true);
2f468537 255 $id = $line["id"];
510ac75f 256
3518718b
AD
257 if ($unread > 0) {
258 $line["title"] = $line["title"] . " ($unread)";
259 $class = '';
510ac75f 260 } else {
3518718b 261 $class = 'oldItem';
510ac75f 262 }
2f468537 263
f0a0c1ff
AD
264 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
265 print "<li class='$class'><a href='cat.php?id=$id'>" .
266 $line["title"] . "</a></li>";
267 }
2f468537 268 }
2f468537
AD
269 }
270
2f468537 271
3518718b
AD
272 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
273 cat_id IS NULL and owner_uid = '$owner_uid'");
42096f52 274
3518718b 275 $num_feeds = db_fetch_result($result, 0, "nf");
42096f52 276
3518718b
AD
277 if ($num_feeds > 0) {
278 $unread = getFeedUnread($link, 0, true);
279 $title = "Uncategorized";
42096f52 280
3518718b
AD
281 if ($unread > 0) {
282 $title = "$title ($unread)";
283 $class = '';
42096f52 284 } else {
3518718b 285 $class = 'oldItem';
42096f52
AD
286 }
287
f0a0c1ff
AD
288 if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
289 print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>";
290 }
3518718b 291 }
42096f52 292
3518718b
AD
293 print "</ul>";
294 }
24ac6776 295
78d7a965 296 function render_headlines_list($link, $feed_id, $cat_id, $offset) {
24ac6776 297
3518718b 298 $feed_id = $feed_id;
78d7a965 299 $limit = 15;
3518718b 300 $filter = '';
3e092346 301 $is_cat = false;
3518718b 302 $view_mode = 'adaptive';
d9aad400 303
3518718b 304 /* do not rely on params below */
d9aad400 305
3518718b
AD
306 $search = '';
307 $search_mode = '';
308 $match_on = '';
78d7a965 309
3518718b 310 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
78d7a965 311 $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset);
541890fb 312
3518718b
AD
313 $result = $qfh_ret[0];
314 $feed_title = $qfh_ret[1];
42096f52 315
78d7a965
AD
316 if (!$offset) {
317 if ($cat_id) {
318 $cat_title = getCategoryTitle($link, $cat_id);
3e092346 319
78d7a965
AD
320 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
321 myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>";
322 } else {
323 print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\"
324 myBackLabel='".__("Home")."' myBackHref='home.php'>";
325 }
b1bd222c 326 }
24ac6776 327
78d7a965
AD
328 $num_headlines = 0;
329
3518718b
AD
330 while ($line = db_fetch_assoc($result)) {
331 $id = $line["id"];
3e94601e 332 $real_feed_id = $line["feed_id"];
f70f7e28 333
3518718b
AD
334 if (sql_bool_to_bool($line["unread"])) {
335 $class = '';
f70f7e28 336 } else {
3518718b 337 $class = 'oldItem';
f70f7e28
AD
338 }
339
3e94601e
AD
340 if (mobile_feed_has_icon($real_feed_id)) {
341 $icon_url = "../".ICONS_URL."/$real_feed_id.ico";
342 } else {
343 $icon_url = "../images/blank_icon.gif";
344 }
345
346 print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'>
347 <img class='tinyIcon' src='$icon_url'>";
3518718b
AD
348 print $line["title"];
349 print "</a></li>";
4a596be6 350
78d7a965
AD
351 ++$num_headlines;
352
42096f52
AD
353 }
354
78d7a965
AD
355// print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>";
356
357 $next_offset = $offset + $num_headlines;
358 $num_unread = getFeedUnread($link, $feed_id, $is_cat);
359
360 /* FIXME needs normal implementation */
361
362 if ($num_unread == 0 || $num_unread > $next_offset) {
363 print "<li><a href=\"feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset\"
364 target=\"_replace\">Get more articles...</a></li>";
365 }
366
367 if (!$offset) print "</ul>";
3518718b 368
42096f52
AD
369 }
370
3e092346 371 function render_article($link, $id, $feed_id, $cat_id) {
0809065e 372
3518718b
AD
373 $query = "SELECT title,link,content,feed_id,comments,int_id,
374 marked,unread,published,
375 ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
376 author
377 FROM ttrss_entries,ttrss_user_entries
378 WHERE id = '$id' AND ref_id = id AND owner_uid = " .
379 $_SESSION["uid"] ;
0809065e 380
3518718b 381 $result = db_query($link, $query);
0809065e 382
3e092346 383 if (db_num_rows($result) != 0) {
0809065e 384
3e092346 385 $line = db_fetch_assoc($result);
0809065e 386
3e092346
AD
387 $tmp_result = db_query($link, "UPDATE ttrss_user_entries
388 SET unread = false,last_read = NOW()
389 WHERE ref_id = '$id'
390 AND owner_uid = " . $_SESSION["uid"]);
0809065e 391
3e092346
AD
392 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
393 $updated_fmt = smart_date_time(strtotime($line["updated"]));
394 } else {
395 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
396 $updated_fmt = date($short_date, strtotime($line["updated"]));
397 }
398
399 $title = $line["title"];
400 $article_link = $line["link"];
401
402 $feed_title = getFeedTitle($link, $feed_id, false);
403
404 print "<div class=\"panel\" id=\"article-$id\" title=\"$title\"
405 selected=\"true\"
406 myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>";
407
bf974b02 408 print "<h2><a target='_blank' href='$link'>$title</a></h2>";
3e092346
AD
409
410 print "<fieldset>";
411
bf974b02 412/* print "<div class=\"row\">";
3e092346 413 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
bf974b02 414 print "</div>"; */
3e092346
AD
415
416 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
417 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
418
3e092346
AD
419 print "<div class=\"row\">";
420 print "<label id='updated'>Updated:</label>";
421 print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>";
422 print "</div>";
423
424 print "</fieldset>";
3bac78a0
AD
425
426 $content = sanitize_rss($link, $line["content"]);
427 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
428
f0a0c1ff
AD
429 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
430 $content = preg_replace('/<img[^>]+>/is', '', $content);
431 }
432
706fe949 433 print "<p>$content</p>";
6101b0e1
AD
434
435 print "<fieldset>";
436
437 print "<div class=\"row\">
438 <label>Starred</label>
439 <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>
440 </div>";
3e092346 441
6101b0e1
AD
442 print "<div class=\"row\">
443 <label>Published</label>
444 <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>
445 </div>";
446
447 print "</fieldset>";
448
3e092346 449 print "</div>";
f70f7e28 450
3e092346 451 }
4a596be6 452 }
0d3adafe 453?>