]>
Commit | Line | Data |
---|---|---|
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"]; |
af88c48a | 27 | $limit = 0; |
95004daf AD |
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 | ||
af88c48a AD |
37 | if ($limit > 0) { |
38 | $limit_qpart = "LIMIT $limit OFFSET $offset"; | |
39 | } else { | |
40 | $limit_qpart = ""; | |
41 | } | |
42 | ||
b1bd222c AD |
43 | $result = db_query($link, "SELECT id, |
44 | title, | |
45 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
46 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
47 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
af88c48a | 48 | AND owner_uid = '$owner_uid') AS unread |
b1bd222c AD |
49 | FROM ttrss_feeds |
50 | WHERE | |
51 | ttrss_feeds.hidden = false AND | |
52 | ttrss_feeds.owner_uid = '$owner_uid' AND | |
53 | parent_feed IS NULL | |
af88c48a | 54 | ORDER BY $order_by $limit_qpart"); |
b1bd222c | 55 | |
95004daf | 56 | if (!$offset) print '<ul id="home" title="'.__('Home').'" selected="true" |
9ab798a5 | 57 | myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">'; |
b1bd222c | 58 | |
af88c48a | 59 | |
b1bd222c | 60 | // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>"; |
95004daf AD |
61 | |
62 | $num_feeds = 0; | |
63 | ||
b1bd222c AD |
64 | while ($line = db_fetch_assoc($result)) { |
65 | $id = $line["id"]; | |
66 | $unread = $line["unread"]; | |
67 | ||
68 | // $unread = rand(0, 100); | |
69 | ||
70 | if ($unread > 0) { | |
71 | $line["title"] = $line["title"] . " ($unread)"; | |
72 | $class = ''; | |
73 | } else { | |
74 | $class = 'oldItem'; | |
75 | } | |
76 | ||
77 | if (mobile_feed_has_icon($id)) { | |
78 | $icon_url = "../".ICONS_URL."/$id.ico"; | |
79 | } else { | |
80 | $icon_url = "../images/blank_icon.gif"; | |
81 | } | |
f0a0c1ff AD |
82 | |
83 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { | |
84 | print "<li class='$class'><a href='feed.php?id=$id'>" . | |
85 | "<img class='tinyIcon' src='$icon_url'/>". | |
86 | $line["title"] . "</a></li>"; | |
87 | } | |
af88c48a AD |
88 | |
89 | ++$num_feeds; | |
b1bd222c | 90 | } |
b1bd222c | 91 | |
af88c48a | 92 | /* $next_offset = $offset + $num_feeds; |
95004daf AD |
93 | |
94 | print "<li><a href=\"home.php?skip=$next_offset\" | |
af88c48a | 95 | target=\"_replace\">Show more feeds...</a></li>"; */ |
b1bd222c | 96 | |
95004daf | 97 | if (!$offset) print "</ul>"; |
b1bd222c AD |
98 | |
99 | } | |
100 | ||
3518718b AD |
101 | function render_category($link, $cat_id) { |
102 | $owner_uid = $_SESSION["uid"]; | |
42096f52 | 103 | |
e2b7a855 | 104 | if ($cat_id >= 0) { |
85233b8e | 105 | |
e2b7a855 AD |
106 | if ($cat_id != 0) { |
107 | $cat_query = "cat_id = '$cat_id'"; | |
3518718b | 108 | } else { |
e2b7a855 | 109 | $cat_query = "cat_id IS NULL"; |
0d3adafe | 110 | } |
f0a0c1ff AD |
111 | |
112 | if (mobile_get_pref($link, "SORT_FEEDS_UNREAD")) { | |
113 | $order_by = "unread DESC, title"; | |
114 | } else { | |
115 | $order_by = "title"; | |
116 | } | |
117 | ||
e2b7a855 AD |
118 | $result = db_query($link, "SELECT id, |
119 | title, | |
120 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
121 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
122 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
123 | AND owner_uid = '$owner_uid') as unread | |
124 | FROM ttrss_feeds | |
125 | WHERE | |
126 | ttrss_feeds.hidden = false AND | |
127 | ttrss_feeds.owner_uid = '$owner_uid' AND | |
128 | parent_feed IS NULL AND | |
129 | $cat_query | |
f0a0c1ff | 130 | ORDER BY $order_by"); |
e2b7a855 AD |
131 | |
132 | $title = getCategoryTitle($link, $cat_id); | |
133 | ||
9ab798a5 | 134 | print "<ul id='cat-$cat_id' title='$title' myBackLabel='".__("Home")."' |
bf974b02 | 135 | myBackHref='home.php'>"; |
e2b7a855 AD |
136 | |
137 | // print "<li><a href='#cat-actions'>".__('Actions...')."</a></li>"; | |
138 | ||
139 | while ($line = db_fetch_assoc($result)) { | |
140 | $id = $line["id"]; | |
141 | $unread = $line["unread"]; | |
3e94601e | 142 | |
e2b7a855 AD |
143 | // $unread = rand(0, 100); |
144 | ||
145 | if ($unread > 0) { | |
146 | $line["title"] = $line["title"] . " ($unread)"; | |
147 | $class = ''; | |
148 | } else { | |
149 | $class = 'oldItem'; | |
150 | } | |
151 | ||
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")) { | |
159 | print "<li class='$class'><a href='feed.php?id=$id&cat=$cat_id'>" . | |
160 | "<img class='tinyIcon' src='$icon_url'/>". | |
161 | $line["title"] . "</a></li>"; | |
162 | } | |
0d3adafe | 163 | } |
e2b7a855 AD |
164 | |
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"]; | |
3585a3c5 | 230 | |
9ab798a5 AD |
231 | print '<ul id="home" title="'.__('Home').'" selected="true" |
232 | myBackLabel="'.__('Logout').'" myBackHref="logout.php" myBackTarget="_self">'; | |
eead4d26 | 233 | |
3585a3c5 AD |
234 | |
235 | // print "<li><a href='#searchForm'>Search...</a></li>"; | |
236 | ||
3518718b AD |
237 | foreach (array(-1, -2) as $id) { |
238 | $title = getCategoryTitle($link, $id); | |
239 | $unread = getFeedUnread($link, $id, true); | |
240 | if ($unread > 0) { | |
241 | $title = $title . " ($unread)"; | |
242 | $class = ''; | |
eead4d26 | 243 | } else { |
3518718b | 244 | $class = 'oldItem'; |
c878bc01 | 245 | } |
2f468537 | 246 | |
3518718b | 247 | print "<li class='$class'><a href='cat.php?id=$id'>$title</a></li>"; |
2f468537 AD |
248 | } |
249 | ||
3518718b AD |
250 | $result = db_query($link, "SELECT |
251 | ttrss_feed_categories.id, | |
252 | ttrss_feed_categories.title, | |
253 | COUNT(ttrss_feeds.id) AS num_feeds | |
254 | FROM ttrss_feed_categories, ttrss_feeds | |
255 | WHERE ttrss_feed_categories.owner_uid = $owner_uid | |
256 | AND ttrss_feed_categories.id = cat_id | |
257 | AND hidden = false | |
258 | GROUP BY ttrss_feed_categories.id, | |
259 | ttrss_feed_categories.title | |
260 | ORDER BY ttrss_feed_categories.title"); | |
2f468537 | 261 | |
3518718b | 262 | while ($line = db_fetch_assoc($result)) { |
fc46ab83 | 263 | |
3518718b | 264 | if ($line["num_feeds"] > 0) { |
2f468537 | 265 | |
3518718b | 266 | $unread = getFeedUnread($link, $line["id"], true); |
2f468537 | 267 | $id = $line["id"]; |
510ac75f | 268 | |
3518718b AD |
269 | if ($unread > 0) { |
270 | $line["title"] = $line["title"] . " ($unread)"; | |
271 | $class = ''; | |
510ac75f | 272 | } else { |
3518718b | 273 | $class = 'oldItem'; |
510ac75f | 274 | } |
2f468537 | 275 | |
f0a0c1ff AD |
276 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
277 | print "<li class='$class'><a href='cat.php?id=$id'>" . | |
278 | $line["title"] . "</a></li>"; | |
279 | } | |
2f468537 | 280 | } |
2f468537 AD |
281 | } |
282 | ||
2f468537 | 283 | |
3518718b AD |
284 | $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE |
285 | cat_id IS NULL and owner_uid = '$owner_uid'"); | |
42096f52 | 286 | |
3518718b | 287 | $num_feeds = db_fetch_result($result, 0, "nf"); |
42096f52 | 288 | |
3518718b AD |
289 | if ($num_feeds > 0) { |
290 | $unread = getFeedUnread($link, 0, true); | |
291 | $title = "Uncategorized"; | |
42096f52 | 292 | |
3518718b AD |
293 | if ($unread > 0) { |
294 | $title = "$title ($unread)"; | |
295 | $class = ''; | |
42096f52 | 296 | } else { |
3518718b | 297 | $class = 'oldItem'; |
42096f52 AD |
298 | } |
299 | ||
f0a0c1ff AD |
300 | if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) { |
301 | print "<li class='$class'><a href='cat.php?id=0'>$title</a></li>"; | |
302 | } | |
3518718b | 303 | } |
42096f52 | 304 | |
3518718b AD |
305 | print "</ul>"; |
306 | } | |
24ac6776 | 307 | |
3585a3c5 | 308 | function render_headlines_list($link, $feed_id, $cat_id, $offset, $search) { |
24ac6776 | 309 | |
3518718b | 310 | $feed_id = $feed_id; |
78d7a965 | 311 | $limit = 15; |
3518718b | 312 | $filter = ''; |
3e092346 | 313 | $is_cat = false; |
3518718b | 314 | $view_mode = 'adaptive'; |
d9aad400 | 315 | |
3585a3c5 AD |
316 | if ($search) { |
317 | $search_mode = 'this_feed'; | |
318 | $match_on = 'both'; | |
319 | } else { | |
320 | $search_mode = ''; | |
321 | $match_on = ''; | |
322 | } | |
78d7a965 | 323 | |
3518718b | 324 | $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, |
78d7a965 | 325 | $view_mode, $is_cat, $search, $search_mode, $match_on, false, $offset); |
541890fb | 326 | |
3518718b AD |
327 | $result = $qfh_ret[0]; |
328 | $feed_title = $qfh_ret[1]; | |
42096f52 | 329 | |
78d7a965 | 330 | if (!$offset) { |
3585a3c5 AD |
331 | |
332 | print "<form id=\"searchForm\" class=\"dialog\" method=\"POST\" | |
333 | action=\"feed.php\"> | |
334 | ||
335 | <input type=\"hidden\" name=\"id\" value=\"$feed_id\"> | |
336 | <input type=\"hidden\" name=\"cat\" value=\"$cat_id\"> | |
337 | ||
338 | <fieldset> | |
339 | <h1>Search</h1> | |
340 | <a class=\"button leftButton\" type=\"cancel\">Cancel</a> | |
341 | <a class=\"button blueButton\" type=\"submit\">Search</a> | |
342 | ||
343 | <label>Search:</label> | |
344 | <input id=\"search\" type=\"text\" name=\"search\"/> | |
345 | </fieldset> | |
346 | </form>"; | |
347 | ||
78d7a965 AD |
348 | if ($cat_id) { |
349 | $cat_title = getCategoryTitle($link, $cat_id); | |
3e092346 | 350 | |
78d7a965 AD |
351 | print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\" |
352 | myBackLabel='$cat_title' myBackHref='cat.php?id=$cat_id'>"; | |
353 | } else { | |
354 | print "<ul id=\"feed-$feed_id\" title=\"$feed_title\" selected=\"true\" | |
355 | myBackLabel='".__("Home")."' myBackHref='home.php'>"; | |
356 | } | |
3585a3c5 AD |
357 | |
358 | print "<li><a href='#searchForm'>Search...</a></li>"; | |
b1bd222c | 359 | } |
24ac6776 | 360 | |
78d7a965 AD |
361 | $num_headlines = 0; |
362 | ||
3518718b AD |
363 | while ($line = db_fetch_assoc($result)) { |
364 | $id = $line["id"]; | |
3e94601e | 365 | $real_feed_id = $line["feed_id"]; |
f70f7e28 | 366 | |
3518718b AD |
367 | if (sql_bool_to_bool($line["unread"])) { |
368 | $class = ''; | |
f70f7e28 | 369 | } else { |
3518718b | 370 | $class = 'oldItem'; |
f70f7e28 AD |
371 | } |
372 | ||
3e94601e AD |
373 | if (mobile_feed_has_icon($real_feed_id)) { |
374 | $icon_url = "../".ICONS_URL."/$real_feed_id.ico"; | |
375 | } else { | |
376 | $icon_url = "../images/blank_icon.gif"; | |
377 | } | |
378 | ||
379 | print "<li class='$class'><a href='article.php?id=$id&feed=$feed_id&cat=$cat_id'> | |
380 | <img class='tinyIcon' src='$icon_url'>"; | |
3518718b AD |
381 | print $line["title"]; |
382 | print "</a></li>"; | |
4a596be6 | 383 | |
78d7a965 AD |
384 | ++$num_headlines; |
385 | ||
42096f52 AD |
386 | } |
387 | ||
3585a3c5 AD |
388 | if ($num_headlines == 0 && $search) { |
389 | $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset"; | |
390 | ||
391 | print "<li><a href=\"$articles_url\">" . __("Nothing found (click to reload feed).") . "</a></li>"; | |
392 | ||
393 | } | |
394 | ||
78d7a965 AD |
395 | // print "<a target='_replace' href='feed.php?id=$feed_id&cat=$cat_id&skip=0'>Next $limit articles...</a>"; |
396 | ||
397 | $next_offset = $offset + $num_headlines; | |
398 | $num_unread = getFeedUnread($link, $feed_id, $is_cat); | |
399 | ||
400 | /* FIXME needs normal implementation */ | |
401 | ||
3585a3c5 AD |
402 | if ($num_headlines > 0 && ($num_unread == 0 || $num_unread > $next_offset)) { |
403 | ||
404 | $articles_url = "feed.php?id=$feed_id&cat=$cat_id&skip=$next_offset". | |
405 | "&search=$search"; | |
406 | ||
407 | print "<li><a href=\"$articles_url\" | |
78d7a965 AD |
408 | target=\"_replace\">Get more articles...</a></li>"; |
409 | } | |
410 | ||
411 | if (!$offset) print "</ul>"; | |
3518718b | 412 | |
42096f52 AD |
413 | } |
414 | ||
3e092346 | 415 | function render_article($link, $id, $feed_id, $cat_id) { |
0809065e | 416 | |
3518718b AD |
417 | $query = "SELECT title,link,content,feed_id,comments,int_id, |
418 | marked,unread,published, | |
419 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, | |
420 | author | |
421 | FROM ttrss_entries,ttrss_user_entries | |
422 | WHERE id = '$id' AND ref_id = id AND owner_uid = " . | |
423 | $_SESSION["uid"] ; | |
0809065e | 424 | |
3518718b | 425 | $result = db_query($link, $query); |
0809065e | 426 | |
3e092346 | 427 | if (db_num_rows($result) != 0) { |
0809065e | 428 | |
3e092346 | 429 | $line = db_fetch_assoc($result); |
0809065e | 430 | |
3e092346 AD |
431 | $tmp_result = db_query($link, "UPDATE ttrss_user_entries |
432 | SET unread = false,last_read = NOW() | |
433 | WHERE ref_id = '$id' | |
434 | AND owner_uid = " . $_SESSION["uid"]); | |
0809065e | 435 | |
3e092346 AD |
436 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { |
437 | $updated_fmt = smart_date_time(strtotime($line["updated"])); | |
438 | } else { | |
439 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
440 | $updated_fmt = date($short_date, strtotime($line["updated"])); | |
441 | } | |
442 | ||
443 | $title = $line["title"]; | |
444 | $article_link = $line["link"]; | |
445 | ||
446 | $feed_title = getFeedTitle($link, $feed_id, false); | |
447 | ||
448 | print "<div class=\"panel\" id=\"article-$id\" title=\"$title\" | |
449 | selected=\"true\" | |
450 | myBackLabel='$feed_title' myBackHref='feed.php?id=$feed_id&cat=$cat_id'>"; | |
451 | ||
17cd1097 | 452 | print "<h2><a target='_blank' href='$article_link'>$title</a></h2>"; |
3e092346 AD |
453 | |
454 | print "<fieldset>"; | |
455 | ||
bf974b02 | 456 | /* print "<div class=\"row\">"; |
3e092346 | 457 | print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>"; |
bf974b02 | 458 | print "</div>"; */ |
3e092346 AD |
459 | |
460 | $is_starred = (sql_bool_to_bool($line["marked"])) ? "true" : "false"; | |
461 | $is_published = (sql_bool_to_bool($line["published"])) ? "true" : "false"; | |
462 | ||
3e092346 AD |
463 | print "<div class=\"row\">"; |
464 | print "<label id='updated'>Updated:</label>"; | |
465 | print "<input enabled='false' name='updated' disabled value='$updated_fmt'/>"; | |
466 | print "</div>"; | |
467 | ||
468 | print "</fieldset>"; | |
3bac78a0 AD |
469 | |
470 | $content = sanitize_rss($link, $line["content"]); | |
471 | $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content); | |
472 | ||
f0a0c1ff AD |
473 | if (!mobile_get_pref($link, "SHOW_IMAGES")) { |
474 | $content = preg_replace('/<img[^>]+>/is', '', $content); | |
475 | } | |
476 | ||
706fe949 | 477 | print "<p>$content</p>"; |
6101b0e1 AD |
478 | |
479 | print "<fieldset>"; | |
480 | ||
481 | print "<div class=\"row\"> | |
482 | <label>Starred</label> | |
483 | <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> | |
484 | </div>"; | |
3e092346 | 485 | |
6101b0e1 AD |
486 | print "<div class=\"row\"> |
487 | <label>Published</label> | |
488 | <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> | |
489 | </div>"; | |
490 | ||
491 | print "</fieldset>"; | |
492 | ||
3e092346 | 493 | print "</div>"; |
f70f7e28 | 494 | |
3e092346 | 495 | } |
4a596be6 | 496 | } |
0d3adafe | 497 | ?> |