]>
Commit | Line | Data |
---|---|---|
71af6d36 | 1 | var SCHEMA_VERSION = 10; |
b871dd06 | 2 | |
25d99353 AD |
3 | var offline_mode = false; |
4 | var store = false; | |
5 | var localServer = false; | |
6 | var db = false; | |
79e565a9 AD |
7 | var articles_synced = 0; |
8 | var sync_in_progress = false; | |
206d4967 | 9 | var sync_timer = false; |
25d99353 | 10 | |
a491a7f1 | 11 | function view_offline(id) { |
4681834e AD |
12 | try { |
13 | ||
14 | enableHotkeys(); | |
15 | showArticleInHeadlines(id); | |
16 | ||
1b27261c AD |
17 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]); |
18 | ||
19 | var rs = db.execute("SELECT * FROM articles WHERE id = ?", [id]); | |
20 | ||
21 | if (rs.isValidRow()) { | |
22 | ||
23 | var tmp = "<div class=\"postReply\">"; | |
24 | ||
25 | tmp += "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" "+ | |
26 | "onmouseout=\"enable_resize(false)\">"; | |
27 | ||
28 | tmp += "<div class=\"postDate\">"+rs.fieldByName("updated")+"</div>"; | |
29 | ||
30 | if (rs.fieldByName("link") != "") { | |
31 | tmp += "<div clear='both'><a target=\"_blank\" "+ | |
32 | "href=\"" + rs.fieldByName("link") + "\">" + | |
33 | rs.fieldByName("title") + "</a></div>"; | |
34 | } else { | |
35 | tmp += "<div clear='both'>" + rs.fieldByName("title") + "</div>"; | |
36 | } | |
4681834e | 37 | |
3ab18266 | 38 | /* tmp += "<div style='float : right'> "+ |
1b27261c AD |
39 | "<img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>"; |
40 | tmp += rs.fieldByName("tags"); | |
3ab18266 | 41 | tmp += "</div>"; */ |
1b27261c | 42 | |
424fc145 | 43 | /* tmp += "<div clear='both'>"+ |
12aa4007 AD |
44 | "<a target=\"_blank\" "+ |
45 | "href=\"" + rs.fieldByName("comments") + "\">" + | |
424fc145 | 46 | __("comments") + "</a></div>"; */ |
1b27261c AD |
47 | |
48 | tmp += "</div>"; | |
49 | ||
50 | tmp += "<div class=\"postContent\">" | |
51 | tmp += rs.fieldByName("content"); | |
52 | tmp += "</div>"; | |
53 | ||
54 | tmp += "</div>"; | |
55 | ||
56 | render_article(tmp); | |
57 | update_local_feedlist_counters(); | |
58 | } | |
4681834e | 59 | |
03c96380 AD |
60 | rs.close(); |
61 | ||
4681834e AD |
62 | return false; |
63 | ||
64 | } catch (e) { | |
65 | exception_error("view_offline", e); | |
66 | } | |
67 | } | |
68 | ||
4169bb67 | 69 | function viewfeed_offline(feed_id, subop, is_cat, offset) { |
4681834e AD |
70 | try { |
71 | notify(''); | |
72 | ||
73 | if (!offset) offset = 0; | |
74 | ||
0e923da4 AD |
75 | if (offset > 0) { |
76 | _feed_cur_page = parseInt(offset); | |
77 | if (_infscroll_request_sent) { | |
78 | return; | |
79 | } | |
80 | } else { | |
81 | _feed_cur_page = 0; | |
82 | _infscroll_disable = 0; | |
83 | } | |
84 | ||
85 | if (getActiveFeedId() != feed_id) { | |
86 | _feed_cur_page = 0; | |
87 | active_post_id = 0; | |
88 | _infscroll_disable = 0; | |
89 | } | |
90 | ||
4681834e AD |
91 | loading_set_progress(100); |
92 | ||
93 | clean_feed_selections(); | |
94 | ||
95 | setActiveFeedId(feed_id, is_cat); | |
96 | ||
97 | if (!is_cat) { | |
acac8448 | 98 | var feedr = $("FEEDR-" + feed_id); |
4681834e AD |
99 | if (feedr && !feedr.className.match("Selected")) { |
100 | feedr.className = feedr.className + "Selected"; | |
101 | } | |
102 | } else { | |
acac8448 | 103 | var feedr = $("FCAT-" + feed_id); |
4681834e AD |
104 | if (feedr && !feedr.className.match("Selected")) { |
105 | feedr.className = feedr.className + "Selected"; | |
106 | } | |
107 | } | |
108 | ||
67625745 AD |
109 | if (subop == "MarkAllRead") { |
110 | catchup_local_feed(feed_id, is_cat); | |
111 | } | |
112 | ||
4681834e AD |
113 | Form.enable("main_toolbar_form"); |
114 | ||
acac8448 | 115 | var f = $("headlines-frame"); |
4681834e AD |
116 | try { |
117 | if (reply.offset == 0) { | |
84c7b824 | 118 | console.log("resetting headlines scrollTop"); |
4681834e AD |
119 | f.scrollTop = 0; |
120 | } | |
121 | } catch (e) { }; | |
122 | ||
123 | ||
4681834e | 124 | var tmp = ""; |
046a2e3c | 125 | var feed_title = ""; |
4681834e | 126 | |
046a2e3c AD |
127 | if (is_cat) { |
128 | feed_title = get_local_category_title(feed_id); | |
129 | } else { | |
130 | feed_title = get_local_feed_title(feed_id); | |
131 | } | |
4681834e | 132 | |
88a66534 | 133 | if (feed_title) { |
4681834e AD |
134 | |
135 | if (offset == 0) { | |
136 | tmp += "<div id=\"headlinesContainer\">"; | |
137 | ||
138 | tmp += "<div class=\"headlinesSubToolbar\">"; | |
139 | tmp += "<div id=\"subtoolbar_ftitle\">"; | |
140 | tmp += feed_title; | |
141 | tmp += "</div>"; | |
142 | ||
46b84d29 AD |
143 | var catchup_feed_link = "javascript:catchupCurrentFeed()"; |
144 | var catchup_sel_link = "javascript:catchupSelection()"; | |
145 | ||
e69fb880 AD |
146 | var sel_all_link = "javascript:selectArticles('all')"; |
147 | var sel_unread_link = "javascript:selectArticles('unread')"; | |
148 | var sel_none_link = "javascript:selectArticles('none')"; | |
149 | var sel_inv_link = "javascript:invertHeadlineSelection()"; | |
46b84d29 | 150 | |
e69fb880 AD |
151 | var tog_unread_link = "javascript:selectionToggleUnread()"; |
152 | var tog_marked_link = "javascript:selectionToggleMarked()"; | |
4681834e AD |
153 | |
154 | tmp += __('Select:')+ | |
155 | " <a href=\""+sel_all_link+"\">"+__('All')+"</a>, "+ | |
156 | "<a href=\""+sel_unread_link+"\">"+__('Unread')+"</a>, "+ | |
157 | "<a href=\""+sel_inv_link+"\">"+__('Invert')+"</a>, "+ | |
158 | "<a href=\""+sel_none_link+"\">"+__('None')+"</a>"; | |
159 | ||
160 | tmp += " "; | |
161 | ||
67cf0d4a AD |
162 | tmp += "<span onmouseover=\"enable_selection(false)\" "+ |
163 | "onmouseout=\"enable_selection(true) \"" + | |
164 | "onclick=\"toggleHeadlineActions()\" id=\"headlineActionsDrop\">" + | |
165 | __("Actions...") + " <img src=\"images/down_arrow.png\">" + | |
166 | "</span>"; | |
167 | ||
168 | tmp += "<ul id=\"headlineActionsBody\" style=\"display : none\">"; | |
169 | ||
67cf0d4a AD |
170 | tmp += "<li class=\"insensitive\">"+__('Selection toggle:')+"</li>"+ |
171 | "<li onclick=\""+tog_unread_link+"\"> "+__('Unread')+"</li>"+ | |
172 | "<li onclick=\""+tog_marked_link+"\"> "+__('Starred')+"</li>"+ | |
173 | "<li class=\"insensitive\">"+__('Mark as read:')+"</li>"+ | |
174 | "<li onclick=\""+catchup_sel_link+"\"> "+__('Selection')+"</li>"; | |
175 | ||
176 | tmp += "<li onclick=\""+catchup_feed_link+"\"> "+__('Entire feed')+ | |
177 | "</li>"; | |
178 | ||
179 | tmp += "</ul>"; | |
180 | ||
4681834e AD |
181 | tmp += "</div>"; |
182 | ||
183 | tmp += "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">"; | |
acac8448 | 184 | if ($("content-frame")) { |
779ba075 AD |
185 | tmp += "<table class=\"headlinesList\" id=\"headlinesList\" cellspacing=\"0\">"; |
186 | } | |
4681834e AD |
187 | |
188 | } | |
189 | ||
4681834e AD |
190 | var limit = 30; |
191 | ||
192 | var toolbar_form = document.forms["main_toolbar_form"]; | |
193 | ||
65216276 | 194 | //var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex].value; |
4681834e AD |
195 | var view_mode = toolbar_form.view_mode[toolbar_form.view_mode.selectedIndex].value; |
196 | ||
197 | var limit_qpart = ""; | |
198 | var strategy_qpart = ""; | |
199 | var mode_qpart = ""; | |
e491d06d | 200 | var offset_qpart = ""; |
4681834e AD |
201 | |
202 | if (limit != 0) { | |
203 | limit_qpart = "LIMIT " + limit; | |
204 | } | |
205 | ||
206 | if (view_mode == "all_articles") { | |
207 | mode_qpart = "1"; | |
208 | } else if (view_mode == "adaptive") { | |
046a2e3c AD |
209 | if (is_cat && get_local_category_unread(feed_id) || |
210 | get_local_feed_unread(feed_id) > 0) { | |
211 | mode_qpart = "unread = 1"; | |
4681834e AD |
212 | } else { |
213 | mode_qpart = "1"; | |
214 | } | |
046a2e3c | 215 | |
4681834e AD |
216 | } else if (view_mode == "marked") { |
217 | mode_qpart = "marked = 1"; | |
218 | } else if (view_mode == "unread") { | |
219 | mode_qpart = "unread = 1"; | |
220 | } else { | |
221 | mode_qpart = "1"; | |
222 | } | |
223 | ||
79645416 AD |
224 | var ext_tables_qpart = ""; |
225 | ||
046a2e3c AD |
226 | if (is_cat) { |
227 | if (feed_id >= 0) { | |
228 | strategy_qpart = "cat_id = " + feed_id; | |
229 | } else if (feed_id == -2) { | |
230 | strategy_qpart = "article_labels.id = articles.id"; | |
231 | ext_tables_qpart = ",article_labels"; | |
232 | } | |
233 | } else if (feed_id > 0) { | |
4681834e AD |
234 | strategy_qpart = "feed_id = " + feed_id; |
235 | } else if (feed_id == -1) { | |
236 | strategy_qpart = "marked = 1"; | |
237 | } else if (feed_id == -4) { | |
238 | strategy_qpart = "1"; | |
88a66534 AD |
239 | } else if (feed_id < -10) { |
240 | var label_id = -11 - feed_id; | |
79645416 AD |
241 | strategy_qpart = "article_labels.id = articles.id AND label_id = " + label_id; |
242 | ext_tables_qpart = ",article_labels"; | |
e491d06d AD |
243 | } |
244 | ||
245 | if (offset > 0) { | |
246 | offset_qpart = "OFFSET " + (offset*30); | |
247 | } else { | |
248 | offset_qpart = ""; | |
249 | } | |
4681834e | 250 | |
851ce414 | 251 | var query = "SELECT *,feeds.title AS feed_title "+ |
046a2e3c | 252 | "FROM articles,feeds,categories"+ext_tables_qpart+" "+ |
79645416 | 253 | "WHERE " + |
046a2e3c | 254 | "cat_id = categories.id AND " + |
851ce414 | 255 | "feed_id = feeds.id AND " + |
4681834e AD |
256 | strategy_qpart + |
257 | " AND " + mode_qpart + | |
258 | " ORDER BY updated DESC "+ | |
e491d06d AD |
259 | limit_qpart + " " + |
260 | offset_qpart; | |
4681834e AD |
261 | |
262 | var rs = db.execute(query); | |
263 | ||
e491d06d | 264 | var line_num = offset*30; |
4681834e | 265 | |
851ce414 AD |
266 | var real_feed_id = feed_id; |
267 | ||
4681834e AD |
268 | while (rs.isValidRow()) { |
269 | ||
270 | var id = rs.fieldByName("id"); | |
271 | var feed_id = rs.fieldByName("feed_id"); | |
272 | ||
851ce414 AD |
273 | var entry_feed_title = false; |
274 | ||
046a2e3c | 275 | if (real_feed_id < 0 || is_cat) { |
851ce414 AD |
276 | entry_feed_title = rs.fieldByName("feed_title"); |
277 | } | |
278 | ||
4681834e AD |
279 | var marked_pic; |
280 | ||
281 | var row_class = (line_num % 2) ? "even" : "odd"; | |
282 | ||
283 | if (rs.fieldByName("unread") == "1") { | |
284 | row_class += "Unread"; | |
285 | } | |
6da82466 AD |
286 | |
287 | var labels = get_local_article_labels(id); | |
288 | ||
6da82466 AD |
289 | var labels_str = "<span id=\"HLLCTR-"+id+"\">"; |
290 | labels_str += format_article_labels(labels, id); | |
291 | labels_str += "</span>"; | |
292 | ||
4681834e AD |
293 | if (rs.fieldByName("marked") == "1") { |
294 | marked_pic = "<img id=\"FMPIC-"+id+"\" "+ | |
295 | "src=\"images/mark_set.png\" class=\"markedPic\""+ | |
296 | "alt=\"Unstar article\" onclick='javascript:tMark("+id+")'>"; | |
297 | } else { | |
298 | marked_pic = "<img id=\"FMPIC-"+id+"\" "+ | |
299 | "src=\"images/mark_unset.png\" class=\"markedPic\""+ | |
300 | "alt=\"Star article\" onclick='javascript:tMark("+id+")'>"; | |
301 | } | |
302 | ||
303 | var mouseover_attrs = "onmouseover='postMouseIn($id)' "+ | |
304 | "onmouseout='postMouseOut($id)'"; | |
779ba075 AD |
305 | |
306 | var content_preview = truncate_string(strip_tags(rs.fieldByName("content")), | |
307 | 100); | |
4681834e | 308 | |
acac8448 | 309 | if ($("content-frame")) { |
4681834e | 310 | |
779ba075 AD |
311 | tmp += "<tr class='"+row_class+"' id='RROW-"+id+"' "+mouseover_attrs+">"; |
312 | ||
313 | tmp += "<td class='hlUpdPic'> </td>"; | |
4681834e | 314 | |
779ba075 AD |
315 | tmp += "<td class='hlSelectRow'>"+ |
316 | "<input type=\"checkbox\" onclick=\"tSR(this)\" id=\"RCHK-"+id+"\"></td>"; | |
317 | ||
318 | tmp += "<td class='hlMarkedPic'>"+marked_pic+"</td>"; | |
319 | ||
a491a7f1 | 320 | tmp += "<td onclick='view("+id+")' "+ |
779ba075 AD |
321 | "class='hlContent' valign='middle'>"; |
322 | ||
851ce414 | 323 | tmp += "<a target=\"_blank\" id=\"RTITLE-"+id+"\" href=\"" + |
779ba075 | 324 | rs.fieldByName("link") + "\"" + |
a491a7f1 | 325 | "onclick=\"return view("+id+");\">"+ |
779ba075 | 326 | rs.fieldByName("title"); |
4681834e | 327 | |
779ba075 AD |
328 | tmp += "<span class=\"contentPreview\"> - "+content_preview+"</span>"; |
329 | ||
330 | tmp += "</a>"; | |
851ce414 | 331 | |
6da82466 AD |
332 | tmp += labels_str; |
333 | ||
851ce414 AD |
334 | if (entry_feed_title) { |
335 | tmp += " <span class=\"hlFeed\">"+ | |
336 | "(<a href='javascript:viewfeed("+feed_id+ | |
337 | ")'>"+entry_feed_title+"</a>)</span>"; | |
338 | } | |
339 | ||
779ba075 | 340 | tmp += "</td>"; |
d07f08e8 | 341 | |
a491a7f1 | 342 | tmp += "<td class=\"hlUpdated\" onclick='view("+id+")'>"+ |
d07f08e8 AD |
343 | "<nobr>"+rs.fieldByName("updated").substring(0,16)+ |
344 | "</nobr></td>"; | |
779ba075 AD |
345 | |
346 | tmp += "</tr>"; | |
347 | } else { | |
4681834e | 348 | |
779ba075 AD |
349 | var add_class = ""; |
350 | ||
351 | if (rs.fieldByName("unread") == "1") { | |
352 | add_class = "Unread"; | |
353 | } | |
354 | ||
355 | tmp += "<div class=\"cdmArticle"+add_class+"\" id=\"RROW-"+id+"\" "+ | |
356 | mouseover_attrs+"'>"; | |
357 | ||
d07f08e8 AD |
358 | feed_icon_img = "<img class=\"tinyFeedIcon\" src=\""+ |
359 | getInitParam("icons_url")+"/"+feed_id+".ico\" alt=\"\">"; | |
360 | cdm_feed_icon = "<span style=\"cursor : pointer\" "+ | |
361 | "onclick=\"viewfeed("+feed_id+")\">"+feed_icon_img+"</span>"; | |
362 | ||
779ba075 AD |
363 | tmp += "<div class=\"cdmHeader\">"; |
364 | tmp += "<div class=\"articleUpdated\">"+ | |
d07f08e8 AD |
365 | rs.fieldByName("updated").substring(0,16)+ |
366 | " "+cdm_feed_icon+"</div>"; | |
779ba075 AD |
367 | |
368 | tmp += "<span id=\"RTITLE-"+id+"\" class=\"titleWrap\">"+ | |
369 | "<a class=\"title\" onclick=\"javascript:toggleUnread("+id+", 0)\""+ | |
370 | "target=\"_blank\" href=\""+rs.fieldByName("link")+ | |
371 | "\">"+rs.fieldByName("title")+"</a>"; | |
851ce414 | 372 | |
6da82466 AD |
373 | tmp += labels_str; |
374 | ||
851ce414 AD |
375 | if (entry_feed_title) { |
376 | tmp += " (<a href='javascript:viewfeed("+feed_id+ | |
377 | ")'>"+entry_feed_title+"</a>)"; | |
378 | } | |
379 | ||
779ba075 AD |
380 | tmp += "</span></div>"; |
381 | ||
382 | tmp += "<div class=\"cdmContent\" onclick=\"cdmClicked("+id+")\""+ | |
383 | "id=\"CICD-"+id+"\">"; | |
384 | tmp += rs.fieldByName("content"); | |
385 | tmp += "<br clear='both'>" | |
386 | tmp += "</div>"; | |
387 | ||
388 | tmp += "<div class=\"cdmFooter\"><span class='s0'>"; | |
389 | tmp += __("Select:")+ | |
390 | " <input type=\"checkbox\" "+ | |
391 | "onclick=\"toggleSelectRowById(this, 'RROW-"+id+"')\" "+ | |
392 | "class=\"feedCheckBox\" id=\"RCHK-"+id+"\">"; | |
393 | ||
394 | tmp += "</span><span class='s1'>"+marked_pic+"</span> "; | |
395 | ||
3ab18266 | 396 | /* tmp += "<span class='s1'>"+ |
779ba075 AD |
397 | "<img class='tagsPic' src='images/tag.png' alt='Tags' title='Tags'>"+ |
398 | "<span id=\"ATSTR-"+id+"\">"+rs.fieldByName("tags")+"</span>"+ | |
3ab18266 | 399 | "</span>"; */ |
779ba075 AD |
400 | |
401 | tmp += "<span class='s2'>Toggle: <a class=\"cdmToggleLink\""+ | |
402 | "href=\"javascript:toggleUnread("+id+")\">"+ | |
403 | "Unread</a></span>"; | |
404 | tmp += "</div>"; | |
405 | ||
406 | tmp += "</div>"; | |
407 | } | |
4681834e AD |
408 | |
409 | rs.next(); | |
410 | line_num++; | |
411 | } | |
03c96380 | 412 | |
0e923da4 AD |
413 | if (line_num - offset*30 < 30) { |
414 | _infscroll_disable = 1; | |
415 | } | |
416 | ||
03c96380 | 417 | rs.close(); |
4681834e AD |
418 | |
419 | if (offset == 0) { | |
420 | tmp += "</table>"; | |
76d20f5f AD |
421 | |
422 | if (line_num - offset*30 == 0) { | |
423 | tmp += "<div class='whiteBox'>" + | |
424 | __("No articles found to display.") + | |
425 | "</div>"; | |
426 | } | |
4681834e AD |
427 | tmp += "</div></div>"; |
428 | } | |
429 | ||
430 | if (offset == 0) { | |
acac8448 | 431 | var container = $("headlines-frame"); |
4681834e AD |
432 | container.innerHTML = tmp; |
433 | } else { | |
434 | var ids = getSelectedArticleIds2(); | |
435 | ||
acac8448 | 436 | var container = $("headlinesList"); |
e491d06d | 437 | container.innerHTML = container.innerHTML + tmp; |
4681834e AD |
438 | |
439 | for (var i = 0; i < ids.length; i++) { | |
440 | markHeadline(ids[i]); | |
441 | } | |
442 | } | |
443 | } | |
444 | ||
445 | remove_splash(); | |
446 | ||
0e923da4 | 447 | _infscroll_request_sent = 0; |
4681834e AD |
448 | |
449 | } catch (e) { | |
450 | exception_error("viewfeed_offline", e); | |
451 | } | |
452 | } | |
453 | ||
454 | function render_offline_feedlist() { | |
455 | try { | |
1c980681 | 456 | var cats_enabled = getInitParam("enable_feed_cats") == "1"; |
d6416405 | 457 | |
4681834e AD |
458 | var tmp = "<ul class=\"feedList\" id=\"feedList\">"; |
459 | ||
460 | var unread = get_local_feed_unread(-4); | |
461 | ||
462 | global_unread = unread; | |
463 | updateTitle(); | |
464 | ||
d6416405 | 465 | if (cats_enabled) { |
c2726c96 | 466 | tmp += printCategoryHeader(-1, is_local_cat_collapsed(-1), false); |
d6416405 AD |
467 | } |
468 | ||
4681834e AD |
469 | tmp += printFeedEntry(-4, __("All articles"), "feed", unread, |
470 | "images/tag.png"); | |
471 | ||
472 | var unread = get_local_feed_unread(-1); | |
473 | ||
474 | tmp += printFeedEntry(-1, __("Starred articles"), "feed", unread, | |
475 | "images/mark_set.png"); | |
476 | ||
d6416405 AD |
477 | if (cats_enabled) { |
478 | tmp += "</ul></li>"; | |
479 | } else { | |
480 | tmp += "<li><hr/></li>"; | |
481 | } | |
4681834e | 482 | |
c2726c96 AD |
483 | if (cats_enabled) { |
484 | tmp += printCategoryHeader(-2, is_local_cat_collapsed(-2), false); | |
485 | } | |
486 | ||
487 | var rs = db.execute("SELECT id,caption "+ | |
488 | "FROM labels "+ | |
489 | "ORDER BY caption"); | |
490 | ||
491 | while (rs.isValidRow()) { | |
492 | var id = -11 - parseInt(rs.field(0)); | |
493 | var caption = rs.field(1); | |
494 | var unread = get_local_feed_unread(id); | |
495 | ||
496 | tmp += printFeedEntry(id, caption, "feed", unread, | |
497 | "images/label.png"); | |
498 | ||
499 | rs.next(); | |
500 | } | |
501 | ||
502 | rs.close(); | |
503 | ||
504 | if (cats_enabled) { | |
505 | tmp += "</ul></li>"; | |
506 | } else { | |
507 | tmp += "<li><hr/></li>"; | |
508 | } | |
509 | ||
f4c11347 | 510 | /* var rs = db.execute("SELECT feeds.id,feeds.title,has_icon,COUNT(articles.id) "+ |
4681834e AD |
511 | "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ |
512 | "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ | |
f4c11347 AD |
513 | "ORDER BY feeds.title"); */ |
514 | ||
d6416405 AD |
515 | var order_by = "feeds.title"; |
516 | ||
517 | if (cats_enabled) order_by = "categories.title," + order_by; | |
518 | ||
519 | var rs = db.execute("SELECT "+ | |
520 | "feeds.id,feeds.title,has_icon,cat_id,collapsed "+ | |
521 | "FROM feeds,categories WHERE cat_id = categories.id "+ | |
522 | "ORDER BY "+order_by); | |
523 | ||
524 | var tmp_cat_id = -1; | |
4681834e AD |
525 | |
526 | while (rs.isValidRow()) { | |
527 | ||
528 | var id = rs.field(0); | |
529 | var title = rs.field(1); | |
530 | var has_icon = rs.field(2); | |
f4c11347 | 531 | var unread = get_local_feed_unread(id); |
d6416405 AD |
532 | var cat_id = rs.field(3); |
533 | var cat_hidden = rs.field(4); | |
534 | ||
535 | if (cat_id != tmp_cat_id && cats_enabled) { | |
536 | if (tmp_cat_id != -1) { | |
537 | tmp += "</ul></li>"; | |
538 | } | |
046a2e3c | 539 | tmp += printCategoryHeader(cat_id, cat_hidden, true); |
d6416405 AD |
540 | tmp_cat_id = cat_id; |
541 | } | |
4681834e AD |
542 | |
543 | var icon = ""; | |
544 | ||
545 | if (has_icon) { | |
046a2e3c | 546 | icon = getInitParam("icons_url") + "/" + id + ".ico"; |
4681834e AD |
547 | } |
548 | ||
4681834e AD |
549 | var feed_icon = ""; |
550 | ||
551 | var row_class = "feed"; | |
552 | ||
553 | if (unread > 0) { | |
554 | row_class += "Unread"; | |
555 | fctr_class = "feedCtrHasUnread"; | |
556 | } else { | |
557 | fctr_class = "feedCtrNoUnread"; | |
558 | } | |
559 | ||
560 | tmp += printFeedEntry(id, title, "feed", unread, icon); | |
561 | ||
562 | rs.next(); | |
563 | } | |
564 | ||
03c96380 AD |
565 | rs.close(); |
566 | ||
983a6a9c AD |
567 | if (cats_enabled) { |
568 | tmp += "</ul>"; | |
569 | } | |
570 | ||
4681834e AD |
571 | tmp += "</ul>"; |
572 | ||
573 | render_feedlist(tmp); | |
574 | } catch (e) { | |
575 | exception_error("render_offline_feedlist", e); | |
576 | } | |
577 | } | |
578 | ||
579 | function init_offline() { | |
580 | try { | |
581 | offline_mode = true; | |
9ca945a6 | 582 | store.enabled = true; |
4681834e AD |
583 | |
584 | Element.hide("dispSwitchPrompt"); | |
4681834e | 585 | |
69ea0cdd AD |
586 | Element.hide("topLinksOnline"); |
587 | Element.show("topLinksOffline"); | |
588 | ||
acac8448 | 589 | var tb_form = $("main_toolbar_form"); |
80b1c238 AD |
590 | Element.hide(tb_form.update); |
591 | ||
acac8448 | 592 | var chooser = $("quickMenuChooser"); |
3c6d3586 AD |
593 | chooser.disabled = true; |
594 | ||
3034277a AD |
595 | var rs = db.execute("SELECT key, value FROM init_params"); |
596 | ||
597 | while (rs.isValidRow()) { | |
598 | init_params[rs.field(0)] = rs.field(1); | |
599 | rs.next(); | |
600 | } | |
601 | ||
602 | rs.close(); | |
4681834e | 603 | |
b15e516e AD |
604 | var rs = db.execute("SELECT COUNT(*) FROM feeds"); |
605 | ||
606 | var num_feeds = 0; | |
607 | ||
608 | if (rs.isValidRow()) { | |
609 | num_feeds = rs.field(0); | |
610 | } | |
611 | ||
612 | rs.close(); | |
613 | ||
614 | if (num_feeds == 0) { | |
615 | remove_splash(); | |
616 | return fatalError(0, | |
617 | __("Data for offline browsing has not been downloaded yet.")); | |
618 | } | |
619 | ||
4681834e | 620 | render_offline_feedlist(); |
10003c4c | 621 | init_second_stage(); |
b15e516e AD |
622 | window.setTimeout("viewfeed(-4)", 50); |
623 | ||
4681834e AD |
624 | } catch (e) { |
625 | exception_error("init_offline", e); | |
626 | } | |
627 | } | |
628 | ||
629 | function offline_download_parse(stage, transport) { | |
630 | try { | |
631 | if (transport.responseXML) { | |
632 | ||
206d4967 AD |
633 | if (!sync_in_progress) return; |
634 | ||
badac687 AD |
635 | var sync_ok = transport.responseXML.getElementsByTagName("sync-ok"); |
636 | ||
637 | if (sync_ok.length > 0) { | |
638 | for (var i = 0; i < sync_ok.length; i++) { | |
639 | var id = sync_ok[i].getAttribute("id"); | |
492a4a6a AD |
640 | var unread = sync_ok[i].getAttribute("unread"); |
641 | var marked = sync_ok[i].getAttribute("marked"); | |
642 | ||
badac687 | 643 | if (id) { |
84c7b824 | 644 | console.log("synced offline info for id " + id); |
492a4a6a AD |
645 | |
646 | if (unread != undefined && marked != undefined) { | |
647 | db.execute("UPDATE articles SET "+ | |
648 | "unread = ?, marked = ? WHERE id = ?", [unread, marked, id]); | |
649 | ||
650 | } | |
badac687 AD |
651 | db.execute("UPDATE articles SET modified = '' WHERE id = ?", [id]); |
652 | } | |
653 | } | |
654 | } | |
655 | ||
4681834e AD |
656 | if (stage == 0) { |
657 | ||
8ca1a0ac AD |
658 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing feeds..."); |
659 | ||
4681834e AD |
660 | var feeds = transport.responseXML.getElementsByTagName("feed"); |
661 | ||
662 | if (feeds.length > 0) { | |
663 | db.execute("DELETE FROM feeds"); | |
664 | } | |
665 | ||
666 | for (var i = 0; i < feeds.length; i++) { | |
667 | var id = feeds[i].getAttribute("id"); | |
668 | var has_icon = feeds[i].getAttribute("has_icon"); | |
669 | var title = feeds[i].firstChild.nodeValue; | |
d8781c91 AD |
670 | var cat_id = feeds[i].getAttribute("cat_id"); |
671 | ||
672 | db.execute("INSERT INTO feeds (id,title,has_icon,cat_id)"+ | |
75aa83ec | 673 | "VALUES (?,?,?,?)", |
d8781c91 | 674 | [id, title, has_icon, cat_id]); |
4681834e | 675 | } |
75aa83ec | 676 | |
8ca1a0ac AD |
677 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing categories..."); |
678 | ||
75aa83ec AD |
679 | var cats = transport.responseXML.getElementsByTagName("category"); |
680 | ||
681 | if (feeds.length > 0) { | |
682 | db.execute("DELETE FROM categories"); | |
683 | } | |
684 | ||
685 | for (var i = 0; i < cats.length; i++) { | |
686 | var id = cats[i].getAttribute("id"); | |
687 | var collapsed = cats[i].getAttribute("collapsed"); | |
688 | var title = cats[i].firstChild.nodeValue; | |
689 | ||
690 | db.execute("INSERT INTO categories (id,title,collapsed)"+ | |
691 | "VALUES (?,?,?)", | |
692 | [id, title, collapsed]); | |
693 | } | |
694 | ||
8ca1a0ac AD |
695 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing labels..."); |
696 | ||
ed22888b AD |
697 | var labels = transport.responseXML.getElementsByTagName("label"); |
698 | ||
699 | if (labels.length > 0) { | |
700 | db.execute("DELETE FROM labels"); | |
701 | } | |
702 | ||
703 | for (var i = 0; i < labels.length; i++) { | |
704 | var id = labels[i].getAttribute("id"); | |
705 | var fg_color = labels[i].getAttribute("fg_color"); | |
706 | var bg_color = labels[i].getAttribute("bg_color"); | |
707 | var caption = labels[i].firstChild.nodeValue; | |
708 | ||
709 | db.execute("INSERT INTO labels (id,caption,fg_color,bg_color)"+ | |
710 | "VALUES (?,?,?,?)", | |
711 | [id, caption, fg_color, bg_color]); | |
712 | } | |
713 | ||
8ca1a0ac AD |
714 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing articles..."); |
715 | ||
716 | sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 2*1000); | |
4681834e AD |
717 | } else { |
718 | ||
719 | var articles = transport.responseXML.getElementsByTagName("article"); | |
720 | ||
3e52ab08 AD |
721 | var limit = transport.responseXML.getElementsByTagName("limit")[0]; |
722 | ||
723 | if (limit) { | |
724 | limit = limit.getAttribute("value"); | |
725 | } else { | |
726 | limit = 0; | |
727 | } | |
728 | ||
4681834e AD |
729 | var articles_found = 0; |
730 | ||
731 | for (var i = 0; i < articles.length; i++) { | |
732 | var a = eval("("+articles[i].firstChild.nodeValue+")"); | |
733 | articles_found++; | |
734 | if (a) { | |
735 | ||
4681834e | 736 | db.execute("DELETE FROM articles WHERE id = ?", [a.id]); |
c2726c96 | 737 | |
4681834e AD |
738 | db.execute("INSERT INTO articles "+ |
739 | "(id, feed_id, title, link, guid, updated, content, "+ | |
55852afa AD |
740 | "unread, marked, tags, comments) "+ |
741 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | |
4681834e | 742 | [a.id, a.feed_id, a.title, a.link, a.guid, a.updated, |
55852afa | 743 | a.content, a.unread, a.marked, a.tags, |
3034277a | 744 | a.comments]); |
4681834e | 745 | |
c2726c96 AD |
746 | if (a.labels.length > 0) { |
747 | for (var j = 0; j < a.labels.length; j++) { | |
748 | label_local_add_article(a.id, a.labels[j][0]); | |
749 | } | |
750 | } | |
751 | ||
4681834e AD |
752 | } |
753 | } | |
754 | ||
84c7b824 | 755 | console.log("downloaded articles: " + articles_found + " limit: " + limit); |
3e52ab08 | 756 | |
79e565a9 AD |
757 | articles_synced += articles_found; |
758 | ||
b4dc02e2 | 759 | var msg =__("Synchronizing articles (%d)...").replace("%d", articles_synced); |
79e565a9 AD |
760 | |
761 | $("offlineModeSyncMsg").innerHTML = msg; | |
762 | ||
badac687 AD |
763 | var has_sync_data = has_local_sync_data(); |
764 | ||
765 | if (articles_found >= limit || has_sync_data) { | |
206d4967 | 766 | sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", |
8ca1a0ac | 767 | 3*1000); |
84c7b824 | 768 | console.log("<b>update_offline_data: done " + stage + " HSD: " + |
badac687 | 769 | has_sync_data + "</b>"); |
4681834e | 770 | } else { |
206d4967 | 771 | window.setTimeout("offlineDownloadStart()", 180*1000); |
84c7b824 | 772 | console.log("update_offline_data: finished"); |
4681834e | 773 | |
79e565a9 | 774 | var pic = $("offlineModePic"); |
04870193 AD |
775 | |
776 | if (pic) { | |
777 | pic.src = "images/offline.png"; | |
79e565a9 AD |
778 | |
779 | var rs = db.execute("SELECT value FROM syncdata WHERE key = 'last_online'"); | |
780 | var last_sync = ""; | |
781 | ||
782 | if (rs.isValidRow()) { | |
783 | last_sync = rs.field(0).substring(0,16); | |
784 | } | |
785 | rs.close(); | |
786 | ||
787 | var msg = __("Last sync: %s").replace("%s", last_sync); | |
788 | ||
789 | articles_synced = 0; | |
790 | ||
791 | $("offlineModeSyncMsg").innerHTML = msg; | |
04870193 AD |
792 | } |
793 | ||
8ca1a0ac | 794 | offlineSyncShowHideElems(false); |
79e565a9 AD |
795 | |
796 | sync_in_progress = false; | |
797 | ||
711f9461 AD |
798 | db.execute("DELETE FROM articles WHERE "+ |
799 | "updated < DATETIME('NOW', 'localtime', '-31 days')"); | |
4681834e AD |
800 | |
801 | } | |
802 | } | |
803 | ||
7f4f9f4e | 804 | update_local_sync_data(); |
04870193 | 805 | |
7f4f9f4e | 806 | |
f45c85f9 | 807 | // notify(''); |
b2319311 | 808 | |
b4dc02e2 AD |
809 | } else { |
810 | sync_in_progress = false; | |
811 | ||
812 | var pic = $("offlineModePic"); | |
813 | ||
814 | if (pic) { | |
815 | pic.src = "images/offline.png"; | |
8ca1a0ac | 816 | var msg = __("Last sync: Error receiving data."); |
b4dc02e2 AD |
817 | articles_synced = 0; |
818 | $("offlineModeSyncMsg").innerHTML = msg; | |
819 | } | |
820 | ||
8ca1a0ac | 821 | offlineSyncShowHideElems(false); |
4681834e | 822 | } |
b4dc02e2 | 823 | |
4681834e AD |
824 | } catch (e) { |
825 | exception_error("offline_download_parse", e); | |
826 | } | |
827 | } | |
828 | ||
829 | function update_offline_data(stage) { | |
830 | try { | |
831 | ||
c16694c8 | 832 | if (!stage) stage = 0; |
79e565a9 | 833 | |
23e2fb84 | 834 | if (!db || offline_mode || getInitParam("offline_enabled") != "1") return; |
4681834e | 835 | |
b4e75b2a | 836 | var query = "?op=rpc&subop=download"; |
e8080ee9 | 837 | |
4681834e | 838 | var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles"); |
03c96380 | 839 | |
4681834e AD |
840 | if (rs.isValidRow() && rs.field(0)) { |
841 | var offline_dl_max_id = rs.field(0); | |
842 | var offline_dl_min_id = rs.field(1); | |
843 | ||
844 | query = query + "&cidt=" + offline_dl_max_id; | |
845 | query = query + "&cidb=" + offline_dl_min_id; | |
e8080ee9 | 846 | |
673b99ca | 847 | if (stage > 0) stage = 1; |
4681834e AD |
848 | } |
849 | ||
03c96380 AD |
850 | rs.close(); |
851 | ||
84c7b824 | 852 | console.log("update_offline_data: stage " + stage); |
e8080ee9 AD |
853 | |
854 | query = query + "&stage=" + stage; | |
855 | ||
badac687 AD |
856 | var to_sync = prepare_local_sync_data(); |
857 | ||
858 | if (to_sync != "") { | |
b4e75b2a | 859 | to_sync = "&sync=" + param_escape(to_sync); |
badac687 AD |
860 | } |
861 | ||
b4e75b2a | 862 | query = query + to_sync; |
badac687 | 863 | |
79e565a9 | 864 | var pic = $("offlineModePic"); |
04870193 AD |
865 | |
866 | if (pic) { | |
867 | pic.src = "images/offline-sync.gif"; | |
79e565a9 AD |
868 | if (articles_synced == 0) { |
869 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing..."); | |
870 | } | |
871 | } | |
872 | ||
8ca1a0ac | 873 | offlineSyncShowHideElems(true); |
9ca945a6 | 874 | offlineUpdateStore(); |
79e565a9 | 875 | |
79e565a9 | 876 | sync_in_progress = true; |
04870193 | 877 | |
84c7b824 | 878 | console.log(query); |
b4e75b2a AD |
879 | |
880 | new Ajax.Request("backend.php", { | |
881 | parameters: query, | |
4681834e AD |
882 | onComplete: function(transport) { |
883 | offline_download_parse(stage, transport); | |
4681834e AD |
884 | } }); |
885 | ||
886 | } catch (e) { | |
887 | exception_error("initiate_offline_download", e); | |
888 | } | |
889 | } | |
890 | ||
d6416405 | 891 | function set_feedlist_counter(id, ctr, is_cat) { |
4681834e AD |
892 | try { |
893 | ||
acac8448 AD |
894 | var feedctr = $("FEEDCTR-" + id); |
895 | var feedu = $("FEEDU-" + id); | |
896 | var feedr = $("FEEDR-" + id); | |
4681834e | 897 | |
d6416405 | 898 | if (is_cat) { |
acac8448 | 899 | var catctr = $("FCATCTR-" + id); |
d6416405 AD |
900 | if (catctr) { |
901 | catctr.innerHTML = "(" + ctr + ")"; | |
902 | if (ctr > 0) { | |
903 | catctr.className = "catCtrHasUnread"; | |
904 | } else { | |
905 | catctr.className = "catCtrNoUnread"; | |
906 | } | |
907 | } | |
908 | } else if (feedctr && feedu && feedr) { | |
4681834e AD |
909 | |
910 | var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML)); | |
911 | ||
912 | feedu.innerHTML = ctr; | |
913 | ||
914 | if (ctr > 0) { | |
915 | feedctr.className = "feedCtrHasUnread"; | |
916 | if (!feedr.className.match("Unread")) { | |
917 | var is_selected = feedr.className.match("Selected"); | |
918 | ||
919 | feedr.className = feedr.className.replace("Selected", ""); | |
920 | feedr.className = feedr.className.replace("Unread", ""); | |
921 | ||
922 | feedr.className = feedr.className + "Unread"; | |
923 | ||
924 | if (is_selected) { | |
925 | feedr.className = feedr.className + "Selected"; | |
926 | } | |
927 | ||
928 | } | |
929 | ||
930 | if (row_needs_hl) { | |
931 | new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5", | |
932 | queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } ); | |
933 | } | |
934 | } else { | |
935 | feedctr.className = "feedCtrNoUnread"; | |
936 | feedr.className = feedr.className.replace("Unread", ""); | |
937 | } | |
938 | } | |
939 | ||
940 | } catch (e) { | |
941 | exception_error("set_feedlist_counter", e); | |
942 | } | |
943 | } | |
944 | ||
945 | function update_local_feedlist_counters() { | |
946 | try { | |
b7dbf528 | 947 | if (!offline_mode || !db) return; |
4681834e | 948 | |
f4c11347 | 949 | /* var rs = db.execute("SELECT feeds.id,COUNT(articles.id) "+ |
4681834e AD |
950 | "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ |
951 | "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ | |
f4c11347 AD |
952 | "ORDER BY feeds.title"); */ |
953 | ||
d6416405 | 954 | var rs = db.execute("SELECT id FROM feeds "+ |
f4c11347 | 955 | "ORDER BY title"); |
4681834e AD |
956 | |
957 | while (rs.isValidRow()) { | |
958 | var id = rs.field(0); | |
f4c11347 | 959 | var ctr = get_local_feed_unread(id); |
d6416405 AD |
960 | set_feedlist_counter(id, ctr, false); |
961 | rs.next(); | |
962 | } | |
4681834e | 963 | |
d6416405 AD |
964 | rs.close(); |
965 | ||
966 | var rs = db.execute("SELECT cat_id,SUM(unread) "+ | |
967 | "FROM articles, feeds WHERE feeds.id = feed_id GROUP BY cat_id"); | |
4681834e | 968 | |
d6416405 AD |
969 | while (rs.isValidRow()) { |
970 | var id = rs.field(0); | |
971 | var ctr = rs.field(1); | |
972 | set_feedlist_counter(id, ctr, true); | |
4681834e AD |
973 | rs.next(); |
974 | } | |
975 | ||
03c96380 AD |
976 | rs.close(); |
977 | ||
c174bcdf AD |
978 | set_feedlist_counter(-2, get_local_category_unread(-2), true); |
979 | ||
4681834e AD |
980 | set_feedlist_counter(-4, get_local_feed_unread(-4)); |
981 | set_feedlist_counter(-1, get_local_feed_unread(-1)); | |
982 | ||
88a66534 AD |
983 | var rs = db.execute("SELECT id FROM labels"); |
984 | ||
985 | while (rs.isValidRow()) { | |
986 | var id = -11 - rs.field(0); | |
987 | var ctr = get_local_feed_unread(id); | |
988 | set_feedlist_counter(id, ctr, false); | |
989 | rs.next(); | |
990 | } | |
991 | ||
992 | rs.close(); | |
993 | ||
4681834e AD |
994 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); |
995 | ||
996 | global_unread = get_local_feed_unread(-4); | |
997 | updateTitle(); | |
998 | ||
999 | } catch (e) { | |
1000 | exception_error("update_local_feedlist_counters", e); | |
1001 | } | |
1002 | } | |
774b8df8 AD |
1003 | |
1004 | function get_local_feed_unread(id) { | |
1005 | try { | |
1006 | var rs; | |
1007 | ||
1008 | if (id == -4) { | |
1009 | rs = db.execute("SELECT SUM(unread) FROM articles"); | |
1010 | } else if (id == -1) { | |
1011 | rs = db.execute("SELECT SUM(unread) FROM articles WHERE marked = 1"); | |
88a66534 | 1012 | } else if (id > 0) { |
774b8df8 | 1013 | rs = db.execute("SELECT SUM(unread) FROM articles WHERE feed_id = ?", [id]); |
88a66534 AD |
1014 | } else if (id < -10) { |
1015 | var label_id = -11 - id; | |
1016 | rs = db.execute("SELECT SUM(unread) FROM articles,article_labels "+ | |
1017 | "WHERE article_labels.id = articles.id AND label_id = ?", [label_id]); | |
774b8df8 AD |
1018 | } |
1019 | ||
03c96380 AD |
1020 | var a = false; |
1021 | ||
774b8df8 | 1022 | if (rs.isValidRow()) { |
03c96380 | 1023 | a = rs.field(0); |
774b8df8 | 1024 | } else { |
03c96380 | 1025 | a = 0; |
774b8df8 AD |
1026 | } |
1027 | ||
03c96380 AD |
1028 | rs.close(); |
1029 | ||
1030 | return a; | |
1031 | ||
774b8df8 AD |
1032 | } catch (e) { |
1033 | exception_error("get_local_feed_unread", e); | |
1034 | } | |
1035 | } | |
1036 | ||
59b223d7 AD |
1037 | function enable_offline_reading() { |
1038 | try { | |
1039 | ||
23e2fb84 | 1040 | if (db && getInitParam("offline_enabled") == "1") { |
59b223d7 | 1041 | init_local_sync_data(); |
79e565a9 AD |
1042 | Element.show("offlineModePic"); |
1043 | offlineDownloadStart(); | |
59b223d7 AD |
1044 | } |
1045 | ||
1046 | } catch (e) { | |
1047 | exception_error("enable_offline_reading", e); | |
1048 | } | |
1049 | } | |
1050 | ||
25d99353 AD |
1051 | function init_gears() { |
1052 | try { | |
1053 | ||
1054 | if (window.google && google.gears) { | |
8ca1a0ac AD |
1055 | |
1056 | try { | |
1057 | localServer = google.gears.factory.create("beta.localserver"); | |
1058 | } catch (e) { | |
1059 | return; | |
1060 | } | |
1061 | ||
25d99353 | 1062 | store = localServer.createManagedStore("tt-rss"); |
206d4967 | 1063 | store.manifestUrl = "manifest.json.php"; |
9ca945a6 | 1064 | store.enabled = false; |
206d4967 | 1065 | |
25d99353 AD |
1066 | db = google.gears.factory.create('beta.database'); |
1067 | db.open('tt-rss'); | |
1068 | ||
1069 | db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); | |
1070 | ||
1071 | var rs = db.execute("SELECT schema_version FROM version"); | |
1072 | ||
1073 | var version = ""; | |
1074 | ||
1075 | if (rs.isValidRow()) { | |
1076 | version = rs.field(0); | |
1077 | } | |
1078 | ||
3034277a AD |
1079 | rs.close(); |
1080 | ||
25d99353 | 1081 | if (version != SCHEMA_VERSION) { |
3034277a | 1082 | db.execute("DROP TABLE IF EXISTS init_params"); |
b871dd06 AD |
1083 | db.execute("DROP TABLE IF EXISTS cache"); |
1084 | db.execute("DROP TABLE IF EXISTS feeds"); | |
d8781c91 | 1085 | db.execute("DROP TABLE IF EXISTS categories"); |
ed22888b AD |
1086 | db.execute("DROP TABLE IF EXISTS labels"); |
1087 | db.execute("DROP TABLE IF EXISTS article_labels"); | |
b871dd06 | 1088 | db.execute("DROP TABLE IF EXISTS articles"); |
c174bcdf AD |
1089 | db.execute("DROP INDEX IF EXISTS article_labels_label_id_idx"); |
1090 | db.execute("DROP INDEX IF EXISTS articles_unread_idx"); | |
1091 | db.execute("DROP INDEX IF EXISTS articles_feed_id_idx"); | |
badac687 AD |
1092 | db.execute("DROP INDEX IF EXISTS articles_id_idx"); |
1093 | db.execute("DROP INDEX IF EXISTS article_labels_id_idx"); | |
3034277a | 1094 | db.execute("DROP TABLE IF EXISTS version"); |
6b684299 AD |
1095 | db.execute("DROP TRIGGER IF EXISTS articles_update_unread"); |
1096 | db.execute("DROP TRIGGER IF EXISTS articles_update_marked"); | |
5b880817 | 1097 | db.execute("DROP TRIGGER IF EXISTS articles_remove_labelrefs"); |
3034277a | 1098 | db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); |
6b684299 | 1099 | db.execute("DROP TABLE IF EXISTS syncdata"); |
25d99353 AD |
1100 | db.execute("INSERT INTO version (schema_version) VALUES (?)", |
1101 | [SCHEMA_VERSION]); | |
1102 | } | |
1103 | ||
71af6d36 | 1104 | db.execute("CREATE TABLE IF NOT EXISTS init_params (key text, value text)"); |
3034277a | 1105 | |
71af6d36 AD |
1106 | db.execute("CREATE TABLE IF NOT EXISTS cache (id integer, article text, param text, added text)"); |
1107 | db.execute("CREATE TABLE IF NOT EXISTS feeds (id integer, title text, has_icon integer, cat_id integer)"); | |
1108 | db.execute("CREATE TABLE IF NOT EXISTS categories (id integer, title text, collapsed integer)"); | |
1109 | db.execute("CREATE TABLE IF NOT EXISTS labels (id integer, caption text, fg_color text, bg_color text)"); | |
ed22888b | 1110 | db.execute("CREATE TABLE IF NOT EXISTS article_labels (id integer, label_id integer)"); |
55852afa | 1111 | db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated timestamp, content text, tags text, unread integer, marked integer, added text, modified timestamp, comments text)"); |
c174bcdf AD |
1112 | |
1113 | db.execute("CREATE INDEX IF NOT EXISTS articles_unread_idx ON articles(unread)"); | |
1114 | db.execute("CREATE INDEX IF NOT EXISTS article_labels_label_id_idx ON article_labels(label_id)"); | |
1115 | db.execute("CREATE INDEX IF NOT EXISTS articles_feed_id_idx ON articles(feed_id)"); | |
badac687 AD |
1116 | db.execute("CREATE INDEX IF NOT EXISTS articles_id_idx ON articles(id)"); |
1117 | db.execute("CREATE INDEX IF NOT EXISTS article_labels_id_idx ON article_labels(id)"); | |
779ba075 | 1118 | |
71af6d36 | 1119 | db.execute("CREATE TABLE IF NOT EXISTS syncdata (key integer, value text)"); |
6b684299 | 1120 | |
779ba075 | 1121 | db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'"); |
69ea0cdd | 1122 | |
6b684299 | 1123 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_unread "+ |
55852afa AD |
1124 | "UPDATE OF unread ON articles "+ |
1125 | "BEGIN "+ | |
711f9461 | 1126 | "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ |
6b684299 AD |
1127 | "WHERE id = OLD.id AND "+ |
1128 | "OLD.unread != NEW.unread;"+ | |
1129 | "END;"); | |
1130 | ||
1131 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_marked "+ | |
1132 | "UPDATE OF marked ON articles "+ | |
1133 | "BEGIN "+ | |
1134 | "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ | |
1135 | "WHERE id = OLD.id;"+ | |
55852afa AD |
1136 | "END;"); |
1137 | ||
5b880817 AD |
1138 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_remove_labelrefs "+ |
1139 | "DELETE ON articles "+ | |
1140 | "BEGIN "+ | |
1141 | "DELETE FROM article_labels WHERE id = OLD.id; "+ | |
1142 | "END; "); | |
1143 | ||
25d99353 AD |
1144 | } |
1145 | ||
1146 | cache_expire(); | |
1147 | ||
1148 | } catch (e) { | |
1149 | exception_error("init_gears", e); | |
1150 | } | |
1151 | } | |
1152 | ||
a8caa4c7 | 1153 | function offlineArticlesStored() { |
206d4967 | 1154 | |
8ca1a0ac AD |
1155 | var rs = db.execute("SELECT COUNT(*) FROM articles"); |
1156 | var count = 0; | |
1157 | if (rs.isValidRow()) { | |
1158 | count = rs.field(0); | |
1159 | } | |
1160 | ||
1161 | rs.close(); | |
1162 | ||
a8caa4c7 AD |
1163 | return count; |
1164 | } | |
1165 | ||
1166 | function gotoOffline() { | |
1167 | ||
84c7b824 | 1168 | // console.log("[Local store] currentVersion = " + store.currentVersion); |
a8caa4c7 AD |
1169 | |
1170 | ||
1171 | if (offlineArticlesStored() == 0) { | |
8ca1a0ac AD |
1172 | notify_error("You have to synchronize some articles before going into offline mode."); |
1173 | return; | |
1174 | } | |
1175 | ||
206d4967 AD |
1176 | if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) { |
1177 | ||
9ca945a6 | 1178 | store.enabled = true; |
206d4967 AD |
1179 | store.checkForUpdate(); |
1180 | ||
80b7fe74 | 1181 | notify_progress("Preparing offline mode...", true); |
206d4967 AD |
1182 | |
1183 | var timerId = window.setInterval(function() { | |
1184 | if (store.currentVersion) { | |
1185 | window.clearInterval(timerId); | |
84c7b824 | 1186 | console.log("[Local store] sync complete: " + store.currentVersion); |
8ca1a0ac AD |
1187 | |
1188 | //window.location.href = "tt-rss.php"; | |
1189 | ||
1190 | offlineDownloadStop(); | |
8ca1a0ac AD |
1191 | init_offline(); |
1192 | ||
1193 | notify_info("Tiny Tiny RSS is in offline mode."); | |
1194 | ||
206d4967 | 1195 | } else if (store.updateStatus == 3) { |
84c7b824 | 1196 | console.log("[Local store] sync error: " + store.lastErrorMessage); |
8ca1a0ac | 1197 | notify_error(store.lastErrorMessage, true); |
206d4967 AD |
1198 | } }, 500); |
1199 | } | |
69ea0cdd AD |
1200 | } |
1201 | ||
1202 | function gotoOnline() { | |
9ca945a6 AD |
1203 | // if (confirm(__("You won't be able to access offline version of Tiny Tiny RSS until you switch it into offline mode again. Go online?"))) { |
1204 | if (confirm(__("Tiny Tiny RSS will reload. Go online?"))) { | |
1205 | //localServer.removeManagedStore("tt-rss"); | |
f4280bdd | 1206 | window.location.href = "tt-rss.php?online=1"; |
206d4967 | 1207 | } |
69ea0cdd | 1208 | } |
774b8df8 | 1209 | |
c26aa9f0 AD |
1210 | function local_collapse_cat(id) { |
1211 | try { | |
1212 | if (db) { | |
1213 | db.execute("UPDATE categories SET collapsed = NOT collapsed WHERE id = ?", | |
1214 | [id]); | |
1215 | } | |
1216 | } catch (e) { | |
1217 | exception_error("local_collapse_cat", e); | |
1218 | } | |
1219 | } | |
d6416405 AD |
1220 | |
1221 | function get_local_category_title(id) { | |
1222 | try { | |
71af6d36 | 1223 | |
d6416405 AD |
1224 | var rs = db.execute("SELECT title FROM categories WHERE id = ?", [id]); |
1225 | var tmp = ""; | |
1226 | ||
1227 | if (rs.isValidRow()) { | |
1228 | tmp = rs.field(0); | |
1229 | } | |
1230 | ||
1231 | rs.close(); | |
1232 | ||
1233 | return tmp; | |
1234 | ||
1235 | } catch (e) { | |
1236 | exception_error("get_local_category_title", e); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | function get_local_category_unread(id) { | |
1241 | try { | |
c174bcdf AD |
1242 | var rs = false; |
1243 | ||
1244 | if (id >= 0) { | |
1245 | rs = db.execute("SELECT SUM(unread) FROM articles, feeds "+ | |
1246 | "WHERE feeds.id = feed_id AND cat_id = ?", [id]); | |
1247 | } else if (id == -2) { | |
1248 | rs = db.execute("SELECT SUM(unread) FROM article_labels, articles "+ | |
1249 | "where article_labels.id = articles.id"); | |
1250 | } else { | |
1251 | return 0; | |
1252 | } | |
d6416405 AD |
1253 | |
1254 | var tmp = 0; | |
1255 | ||
1256 | if (rs.isValidRow()) { | |
1257 | tmp = rs.field(0); | |
1258 | } | |
1259 | ||
1260 | rs.close(); | |
1261 | ||
1262 | return tmp; | |
1263 | ||
1264 | } catch (e) { | |
1265 | exception_error("get_local_category_unread", e); | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | function printCategoryHeader(cat_id, hidden, can_browse) { | |
1270 | try { | |
1271 | if (hidden == undefined) hidden = false; | |
1272 | if (can_browse == undefined) can_browse = false; | |
1273 | ||
1274 | var tmp_category = get_local_category_title(cat_id); | |
1275 | var tmp = ""; | |
1276 | ||
1277 | var cat_unread = get_local_category_unread(cat_id); | |
1278 | ||
1279 | var holder_style = ""; | |
1280 | var ellipsis = ""; | |
1281 | ||
1282 | if (hidden) { | |
1283 | holder_style = "display:none;"; | |
1284 | ellipsis = "…"; | |
1285 | } | |
1286 | ||
1287 | var catctr_class = (cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
1288 | ||
1289 | var browse_cat_link = ""; | |
1290 | var inner_title_class = "catTitleNL"; | |
1291 | ||
1292 | if (can_browse) { | |
046a2e3c | 1293 | browse_cat_link = "onclick=\"javascript:viewCategory("+cat_id+")\""; |
d6416405 AD |
1294 | inner_title_class = "catTitle"; |
1295 | } | |
1296 | ||
1297 | var cat_class = "feedCat"; | |
1298 | ||
1299 | tmp += "<li class=\""+cat_class+"\" id=\"FCAT-"+cat_id+"\">"+ | |
1300 | "<img onclick=\"toggleCollapseCat("+cat_id+")\" class=\"catCollapse\""+ | |
1301 | " title=\""+__('Click to collapse category')+"\""+ | |
1302 | " src=\"images/cat-collapse.png\"><span class=\""+inner_title_class+"\" "+ | |
1303 | " id=\"FCATN-"+cat_id+"\" "+browse_cat_link+ | |
1304 | "\">"+tmp_category+"</span>"; | |
1305 | ||
1306 | tmp += "<span id=\"FCAP-"+cat_id+"\">"; | |
1307 | ||
1308 | tmp += " <span id=\"FCATCTR-"+cat_id+"\" "+ | |
1309 | "class=\""+catctr_class+"\">("+cat_unread+")</span> "+ellipsis; | |
1310 | ||
1311 | tmp += "</span>"; | |
1312 | ||
1313 | tmp += "<ul class=\"feedCatList\" id=\"FCATLIST-"+cat_id+"\" "+ | |
1314 | "style='"+holder_style+"'>"; | |
1315 | ||
1316 | return tmp; | |
1317 | } catch (e) { | |
1318 | exception_error("printCategoryHeader", e); | |
1319 | } | |
1320 | } | |
1321 | ||
c2726c96 AD |
1322 | function is_local_cat_collapsed(id) { |
1323 | try { | |
1324 | ||
1325 | var rs = db.execute("SELECT collapsed FROM categories WHERE id = ?", [id]); | |
1326 | var cat_hidden = 0; | |
1327 | ||
1328 | if (rs.isValidRow()) { | |
1329 | cat_hidden = rs.field(0); | |
1330 | } | |
1331 | ||
1332 | rs.close(); | |
1333 | ||
1334 | return cat_hidden == "1"; | |
1335 | ||
1336 | } catch (e) { | |
1337 | exception_error("is_local_cat_collapsed", e); | |
1338 | } | |
1339 | } | |
1340 | ||
6da82466 AD |
1341 | function get_local_article_labels(id) { |
1342 | try { | |
1343 | var rs = db.execute("SELECT DISTINCT label_id,caption,fg_color,bg_color "+ | |
1344 | "FROM labels, article_labels "+ | |
1345 | "WHERE labels.id = label_id AND article_labels.id = ?", [id]); | |
1346 | ||
1347 | var tmp = new Array(); | |
1348 | ||
1349 | while (rs.isValidRow()) { | |
1350 | var e = new Array(); | |
1351 | ||
1352 | e[0] = rs.field(0); | |
1353 | e[1] = rs.field(1); | |
1354 | e[2] = rs.field(2); | |
1355 | e[3] = rs.field(3); | |
1356 | ||
1357 | tmp.push(e); | |
1358 | ||
1359 | rs.next(); | |
1360 | } | |
1361 | ||
1362 | return tmp; | |
1363 | ||
1364 | } catch (e) { | |
1365 | exception_error("get_local_article_labels", e); | |
1366 | } | |
1367 | } | |
1368 | ||
c2726c96 AD |
1369 | function label_local_add_article(id, label_id) { |
1370 | try { | |
84c7b824 | 1371 | //console.log("label_local_add_article " + id + " => " + label_id); |
c2726c96 AD |
1372 | |
1373 | var rs = db.execute("SELECT COUNT(id) FROM article_labels WHERE "+ | |
1374 | "id = ? AND label_id = ?", [id, label_id]); | |
1375 | var check = rs.field(0); | |
1376 | ||
1377 | if (rs.isValidRow()) { | |
1378 | var check = rs.field(0); | |
1379 | } | |
1380 | rs.close(); | |
1381 | ||
1382 | if (check == 0) { | |
1383 | db.execute("INSERT INTO article_labels (id, label_id) VALUES "+ | |
1384 | "(?,?)", [id, label_id]); | |
1385 | } | |
1386 | ||
1387 | } catch (e) { | |
1388 | exception_error("label_local_add_article", e); | |
1389 | } | |
1390 | } | |
88a66534 AD |
1391 | |
1392 | function get_local_feed_title(id) { | |
1393 | try { | |
1394 | ||
1395 | var feed_title = "Unknown feed: " + id; | |
1396 | ||
1397 | if (id > 0) { | |
1398 | var rs = db.execute("SELECT title FROM feeds WHERE id = ?", [id]); | |
1399 | ||
1400 | if (rs.isValidRow()) { | |
1401 | feed_title = rs.field(0); | |
1402 | } | |
1403 | ||
1404 | rs.close(); | |
1405 | } else if (id == -1) { | |
1406 | feed_title = __("Starred articles"); | |
1407 | } else if (id == -4) { | |
1408 | feed_title = __("All articles"); | |
1409 | } else if (id < -10) { | |
1410 | ||
1411 | var label_id = -11 - id; | |
1412 | ||
1413 | var rs = db.execute("SELECT caption FROM labels WHERE id = ?", [label_id]); | |
1414 | ||
1415 | if (rs.isValidRow()) { | |
1416 | feed_title = rs.field(0); | |
1417 | } | |
1418 | ||
1419 | rs.close(); | |
1420 | } | |
1421 | ||
1422 | return feed_title; | |
1423 | ||
1424 | } catch (e) { | |
1425 | exception_error("get_local_feed_title", e); | |
1426 | } | |
1427 | } | |
6da82466 AD |
1428 | |
1429 | function format_article_labels(labels, id) { | |
1430 | try { | |
1431 | ||
1432 | var labels_str = ""; | |
1433 | ||
1434 | if (!labels) return ""; | |
1435 | ||
1436 | for (var i = 0; i < labels.length; i++) { | |
1437 | var l = labels[i]; | |
1438 | ||
1439 | labels_str += "<span class='hlLabelRef' "+ | |
1440 | "style='color : "+l[2]+"; background-color : "+l[3]+"'>"+l[1]+"</span>"; | |
1441 | } | |
1442 | ||
1443 | return labels_str; | |
1444 | ||
1445 | } catch (e) { | |
1446 | exception_error("format_article_labels", e); | |
1447 | } | |
1448 | } | |
1449 | ||
6b684299 AD |
1450 | function init_local_sync_data() { |
1451 | try { | |
23e2fb84 AD |
1452 | |
1453 | if (!db) return; | |
1454 | ||
6b684299 AD |
1455 | var rs = db.execute("SELECT COUNT(*) FROM syncdata WHERE key = 'last_online'"); |
1456 | var has_last_online = 0; | |
1457 | ||
1458 | if (rs.isValidRow()) { | |
1459 | has_last_online = rs.field(0); | |
1460 | } | |
1461 | ||
1462 | rs.close(); | |
1463 | ||
1464 | if (!has_last_online) { | |
1465 | db.execute("INSERT INTO syncdata (key, value) VALUES ('last_online', '')"); | |
1466 | } | |
1467 | ||
1468 | } catch (e) { | |
1469 | exception_error("init_local_sync_data", e); | |
1470 | ||
1471 | } | |
1472 | } | |
1473 | ||
badac687 AD |
1474 | function has_local_sync_data() { |
1475 | try { | |
1476 | ||
1477 | var rs = db.execute("SELECT id FROM articles "+ | |
1478 | "WHERE modified > (SELECT value FROM syncdata WHERE key = 'last_online') "+ | |
1479 | "LIMIT 1"); | |
1480 | ||
1481 | var tmp = 0; | |
1482 | ||
1483 | if (rs.isValidRow()) { | |
1484 | tmp = rs.field(0); | |
1485 | } | |
1486 | ||
1487 | rs.close(); | |
1488 | ||
1489 | return tmp != 0; | |
1490 | ||
1491 | } catch (e) { | |
1492 | exception_error("has_local_sync_data", e); | |
1493 | } | |
1494 | } | |
1495 | ||
1496 | function prepare_local_sync_data() { | |
1497 | try { | |
1498 | var rs = db.execute("SELECT value FROM syncdata WHERE key = 'last_online'"); | |
1499 | ||
1500 | var last_online = ""; | |
1501 | ||
1502 | if (rs.isValidRow()) { | |
1503 | last_online = rs.field(0); | |
1504 | } | |
1505 | ||
1506 | rs.close(); | |
1507 | ||
1508 | var rs = db.execute("SELECT id,unread,marked FROM articles "+ | |
1509 | "WHERE modified > ? LIMIT 200", [last_online]); | |
1510 | ||
1511 | var tmp = last_online + ";"; | |
1512 | ||
1513 | var entries = 0; | |
1514 | ||
1515 | while (rs.isValidRow()) { | |
1516 | var e = new Array(); | |
1517 | ||
1518 | tmp = tmp + rs.field(0) + "," + rs.field(1) + "," + rs.field(2) + ";"; | |
1519 | entries++; | |
1520 | ||
1521 | rs.next(); | |
1522 | } | |
1523 | ||
1524 | rs.close(); | |
1525 | ||
1526 | if (entries > 0) { | |
1527 | return tmp; | |
1528 | } else { | |
1529 | return ''; | |
1530 | } | |
1531 | ||
1532 | } catch (e) { | |
1533 | exception_error("prepare_local_sync_data", e); | |
1534 | } | |
1535 | } | |
1536 | ||
6b684299 AD |
1537 | function update_local_sync_data() { |
1538 | try { | |
1539 | if (db && !offline_mode) { | |
badac687 AD |
1540 | |
1541 | var rs = db.execute("SELECT id FROM articles "+ | |
1542 | "WHERE modified > (SELECT value FROM syncdata WHERE "+ | |
1543 | "key = 'last_online') LIMIT 1") | |
1544 | ||
1545 | var f_id = 0; | |
1546 | ||
1547 | if (rs.isValidRow()) { | |
1548 | f_id = rs.field(0); | |
1549 | } | |
1550 | ||
1551 | rs.close(); | |
1552 | ||
1553 | /* no pending articles to sync */ | |
1554 | ||
1555 | if (f_id == 0) { | |
1556 | db.execute("UPDATE syncdata SET value = DATETIME('NOW', 'localtime') "+ | |
1557 | "WHERE key = 'last_online'"); | |
1558 | } | |
6b684299 AD |
1559 | |
1560 | } | |
1561 | } catch (e) { | |
1562 | exception_error("update_local_sync_data", e); | |
1563 | } | |
1564 | } | |
67625745 AD |
1565 | |
1566 | function catchup_local_feed(id, is_cat) { | |
1567 | try { | |
6161d5cc AD |
1568 | if (!db) return; |
1569 | ||
67625745 AD |
1570 | if (!is_cat) { |
1571 | if (id >= 0) { | |
1572 | db.execute("UPDATE articles SET unread = 0 WHERE feed_id = ?", [id]); | |
1573 | } else if (id == -1) { | |
1574 | db.execute("UPDATE articles SET unread = 0 WHERE marked = 1"); | |
1575 | } else if (id == -4) { | |
1576 | db.execute("UPDATE articles SET unread = 0"); | |
1577 | } else if (id < -10) { | |
1578 | var label_id = -11-id; | |
1579 | ||
1580 | db.execute("UPDATE articles SET unread = 0 WHERE "+ | |
1581 | "(SELECT COUNT(*) FROM article_labels WHERE "+ | |
1582 | "article_labels.id = articles.id AND label_id = ?) > 0", [label_id]); | |
1583 | } | |
1584 | } | |
1585 | ||
1586 | update_local_feedlist_counters(); | |
1587 | ||
1588 | } catch (e) { | |
1589 | exception_error("catchup_local_feed", e); | |
1590 | } | |
1591 | } | |
79e565a9 AD |
1592 | |
1593 | function toggleOfflineModeInfo() { | |
1594 | try { | |
1595 | var e = $('offlineModeDrop'); | |
1596 | var p = $('offlineModePic'); | |
1597 | ||
1598 | if (Element.visible(e)) { | |
1599 | Element.hide(e); | |
1600 | } else { | |
1601 | Element.show(e); | |
1602 | } | |
1603 | ||
1604 | } catch (e) { | |
1605 | exception_error("toggleOfflineModeInfo", e); | |
1606 | } | |
1607 | } | |
1608 | ||
65c0779b | 1609 | function offlineDownloadStart(stage) { |
79e565a9 | 1610 | try { |
65c0779b AD |
1611 | if (!stage) stage = 0; |
1612 | ||
79e565a9 | 1613 | if (db && !sync_in_progress && getInitParam("offline_enabled") == "1") { |
65c0779b | 1614 | window.setTimeout("update_offline_data("+stage+")", 100); |
79e565a9 AD |
1615 | } |
1616 | } catch (e) { | |
1617 | exception_error("offlineDownloadStart", e); | |
1618 | } | |
1619 | } | |
1620 | ||
206d4967 AD |
1621 | function offlineDownloadStop() { |
1622 | try { | |
1623 | if (db && sync_in_progress && getInitParam("offline_enabled") == "1") { | |
8ca1a0ac AD |
1624 | |
1625 | sync_in_progress = false; | |
1626 | ||
1627 | if (sync_timer) { | |
1628 | window.clearTimeout(sync_timer); | |
1629 | sync_timer = false; | |
1630 | } | |
1631 | ||
1632 | var pic = $("offlineModePic"); | |
1633 | ||
1634 | if (pic) { | |
1635 | pic.src = "images/offline.png"; | |
1636 | var msg = __("Last sync: Cancelled."); | |
1637 | articles_synced = 0; | |
1638 | $("offlineModeSyncMsg").innerHTML = msg; | |
1639 | } | |
1640 | ||
1641 | offlineSyncShowHideElems(false); | |
1642 | ||
206d4967 AD |
1643 | } |
1644 | } catch (e) { | |
1645 | exception_error("offlineDownloadStart", e); | |
1646 | } | |
1647 | } | |
1648 | ||
79e565a9 AD |
1649 | function offlineClearData() { |
1650 | try { | |
1651 | if (db) { | |
1652 | ||
b4dc02e2 | 1653 | if (confirm(__("This will remove all offline data stored by Tiny Tiny RSS on this computer. Continue?"))) { |
79e565a9 AD |
1654 | |
1655 | notify_progress("Removing offline data..."); | |
1656 | ||
b4dc02e2 AD |
1657 | localServer.removeManagedStore("tt-rss"); |
1658 | ||
79e565a9 AD |
1659 | db.execute("DELETE FROM articles"); |
1660 | db.execute("DELETE FROM article_labels"); | |
1661 | db.execute("DELETE FROM labels"); | |
1662 | db.execute("DELETE FROM feeds"); | |
8ca1a0ac | 1663 | db.execute("DELETE FROM cache"); |
79e565a9 | 1664 | |
8ca1a0ac | 1665 | notify_info("Local data removed."); |
79e565a9 AD |
1666 | } |
1667 | } | |
1668 | } catch (e) { | |
1669 | exception_error("offlineClearData", e); | |
1670 | } | |
1671 | } | |
206d4967 AD |
1672 | |
1673 | function offlineUpdateStore() { | |
1674 | try { | |
9ca945a6 | 1675 | if (offline_mode || !store) return; |
206d4967 | 1676 | |
9ca945a6 AD |
1677 | store.checkForUpdate(); |
1678 | ||
1679 | var timerId = window.setInterval(function() { | |
1680 | if (store.currentVersion) { | |
1681 | window.clearInterval(timerId); | |
84c7b824 | 1682 | console.log("[Local store] sync complete: " + store.currentVersion); |
9ca945a6 | 1683 | } else if (store.updateStatus == 3) { |
84c7b824 | 1684 | console.log("[Local store] sync error: " + store.lastErrorMessage); |
9ca945a6 | 1685 | } }, 500); |
206d4967 AD |
1686 | |
1687 | } catch (e) { | |
1688 | exception_error("offlineUpdateStore", e); | |
1689 | } | |
1690 | } | |
8ca1a0ac AD |
1691 | |
1692 | function offlineSyncShowHideElems(syncing) { | |
1693 | try { | |
1694 | ||
1695 | var elems = $$("div.hideWhenSyncing"); | |
1696 | ||
1697 | for (var j = 0; j < elems.length; j++) { | |
1698 | if (syncing) { | |
1699 | Element.hide(elems[j]); | |
1700 | } else { | |
1701 | Element.show(elems[j]); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | var elems = $$("div.showWhenSyncing"); | |
1706 | ||
1707 | for (var j = 0; j < elems.length; j++) { | |
1708 | if (syncing) { | |
1709 | Element.show(elems[j]); | |
1710 | } else { | |
1711 | Element.hide(elems[j]); | |
1712 | } | |
1713 | } | |
1714 | ||
1715 | } catch (e) { | |
1716 | exception_error("offlineSyncShowHideElems", e); | |
1717 | } | |
1718 | } | |
9ca945a6 AD |
1719 | |
1720 | function offlineConfirmModeChange() { | |
1721 | try { | |
1722 | ||
a8caa4c7 | 1723 | if (db && getInitParam("offline_enabled") == "1" && offlineArticlesStored() > 0) { |
9ca945a6 AD |
1724 | var ok = confirm(__("Tiny Tiny RSS has trouble accessing its server. Would you like to go offline?")); |
1725 | ||
1726 | if (ok) { | |
1727 | init_offline(); | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | } catch (e) { | |
1732 | exception_error("offlineConfirmModeChange", e); | |
1733 | } | |
1734 | } | |
f2a648e1 AD |
1735 | |
1736 | function printFeedEntry(id, title, row_class, unread, icon) { | |
1737 | ||
1738 | var tmp = ""; | |
1739 | var fctr_class = ""; | |
1740 | var feed_icon = ""; | |
1741 | ||
1742 | if (unread > 0) { | |
1743 | row_class += "Unread"; | |
1744 | fctr_class = "feedCtrHasUnread"; | |
1745 | } else { | |
1746 | fctr_class = "feedCtrNoUnread"; | |
1747 | } | |
1748 | ||
1749 | if (icon) { | |
1750 | feed_icon = "<img id='FIMG-"+id+"' src='" + icon + "'>"; | |
1751 | } else { | |
1752 | feed_icon = "<img id='FIMG-"+id+"' src='images/blank_icon.gif'>"; | |
1753 | } | |
1754 | ||
1755 | var link = "<a title=\"FIXME\" id=\"FEEDL-"+id+"\""+ | |
1756 | "href=\"javascript:viewfeed('"+id+"', '', false, '', false, 0);\">"+ | |
1757 | title + "</a>"; | |
1758 | ||
1759 | tmp += "<li id='FEEDR-"+id+"' class="+row_class+">" + feed_icon + | |
1760 | "<span id=\"FEEDN-"+id+"\">" + link + "</span>"; | |
1761 | ||
1762 | tmp += " <span class='"+fctr_class+"' id=\"FEEDCTR-"+id+"\">" + | |
1763 | "(<span id=\"FEEDU-"+id+"\">"+unread+"</span>)</span>"; | |
1764 | ||
1765 | tmp += "</li>"; | |
1766 | ||
1767 | return tmp; | |
1768 | } | |
1769 | ||
1770 |