]> git.wh0rd.org - tt-rss.git/blame_incremental - mobile/functions.php
mobile: implement WIP pagination for flat feedlist
[tt-rss.git] / mobile / functions.php
... / ...
CommitLineData
1<?php
2 define('TTRSS_SESSION_NAME', 'ttrss_m_sid');
3
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
19 function mobile_feed_has_icon($id) {
20 $filename = "../".ICONS_DIR."/$id.ico";
21
22 return file_exists($filename) && filesize($filename) > 0;
23 }
24
25 function render_flat_feed_list($link, $offset) {
26 $owner_uid = $_SESSION["uid"];
27 $limit = 30;
28
29 if (!$offset) $offset = 0;
30
31 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
32 $order_by = "unread DESC, title";
33 } else {
34 $order_by = "title";
35 }
36
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
48 ORDER BY $order_by LIMIT $limit OFFSET $offset");
49
50 if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true"
51 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
52
53 // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>";
54
55 $num_feeds = 0;
56
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 }
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>";
80 ++$num_feeds;
81 }
82 }
83
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>";
88
89 if (!$offset) print "</ul>";
90
91 }
92
93 function render_category($link, $cat_id) {
94 $owner_uid = $_SESSION["uid"];
95
96 if ($cat_id >= 0) {
97
98 if ($cat_id != 0) {
99 $cat_query = "cat_id = '$cat_id'";
100 } else {
101 $cat_query = "cat_id IS NULL";
102 }
103
104 if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) {
105 $order_by = "unread DESC, title";
106 } else {
107 $order_by = "title";
108 }
109
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
122 ORDER BY $order_by");
123
124 $title = getCategoryTitle($link, $cat_id);
125
126 print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."'
127 myBackHref='home.php'>";
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"];
134
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 }
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 }
155 }
156
157 print "</ul>";
158 } else if ($cat_id == -1) {
159
160 $title = __('Special');
161
162 print "<ul id='cat--1' title='$title' myBackLabel='".__("Home")."'
163 myBackHref='home.php'>";
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';
174 }
175
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 }
180 }
181
182 print "</ul>";
183 } else if ($cat_id == -2) {
184
185 $title = __('Labels');
186
187 print "<ul id='cat--2' title='$title' myBackLabel='".__("Home")."'
188 myBackHref='home.php'>";
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
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 }
213 }
214 print "</ul>";
215 }
216 }
217
218 function render_categories_list($link) {
219 $owner_uid = $_SESSION["uid"];
220
221
222 print '<ul id="home" title="'.__('Home').'" selected="true"
223 myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">';
224
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 = '';
231 } else {
232 $class = 'oldItem';
233 }
234
235 print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>";
236 }
237
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");
249
250 while ($line = db_fetch_assoc($result)) {
251
252 if ($line["num_feeds"] > 0) {
253
254 $unread = getFeedUnread($link, $line["id"], true);
255 $id = $line["id"];
256
257 if ($unread > 0) {
258 $line["title"] = $line["title"] . " ($unread)";
259 $class = '';
260 } else {
261 $class = 'oldItem';
262 }
263
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 }
268 }
269 }
270
271
272 $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE
273 cat_id IS NULL and owner_uid = '$owner_uid'");
274
275 $num_feeds = db_fetch_result($result, 0, "nf");
276
277 if ($num_feeds > 0) {
278 $unread = getFeedUnread($link, 0, true);
279 $title = "Uncategorized";
280
281 if ($unread > 0) {
282 $title = "$title ($unread)";
283 $class = '';
284 } else {
285 $class = 'oldItem';
286 }
287
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 }
291 }
292
293 print "</ul>";
294 }
295
296 function render_headlines_list($link, $feed_id, $cat_id, $offset) {
297
298 $feed_id = $feed_id;
299 $limit = 15;
300 $filter = '';
301 $is_cat = false;
302 $view_mode = 'adaptive';
303
304 /* do not rely on params below */
305
306 $search = '';
307 $search_mode = '';
308 $match_on = '';
309
310 $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
311 $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset);
312
313 $result = $qfh_ret[0];
314 $feed_title = $qfh_ret[1];
315
316 if (!$offset) {
317 if ($cat_id) {
318 $cat_title = getCategoryTitle($link, $cat_id);
319
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 }
326 }
327
328 $num_headlines = 0;
329
330 while ($line = db_fetch_assoc($result)) {
331 $id = $line["id"];
332 $real_feed_id = $line["feed_id"];
333
334 if (sql_bool_to_bool($line["unread"])) {
335 $class = '';
336 } else {
337 $class = 'oldItem';
338 }
339
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'>";
348 print $line["title"];
349 print "</a></li>";
350
351 ++$num_headlines;
352
353 }
354
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>";
368
369 }
370
371 function render_article($link, $id, $feed_id, $cat_id) {
372
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"] ;
380
381 $result = db_query($link, $query);
382
383 if (db_num_rows($result) != 0) {
384
385 $line = db_fetch_assoc($result);
386
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"]);
391
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
408 print "<h2><a target='_blank' href='$link'>$title</a></h2>";
409
410 print "<fieldset>";
411
412/* print "<div class=\"row\">";
413 print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>";
414 print "</div>"; */
415
416 $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false";
417 $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false";
418
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>";
425
426 $content = sanitize_rss($link, $line["content"]);
427 $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content);
428
429 if (!mobile_get_pref($link, "SHOW_IMAGES")) {
430 $content = preg_replace('/<img[^>]+>/is', '', $content);
431 }
432
433 print "<p>$content</p>";
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>";
441
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
449 print "</div>";
450
451 }
452 }
453?>