]>
Commit | Line | Data |
---|---|---|
40d13c28 | 1 | <? |
f1a80dae | 2 | |
894ebcf5 | 3 | /* if ($_GET["debug"]) { |
cce28758 AD |
4 | define('DEFAULT_ERROR_LEVEL', E_ALL); |
5 | } else { | |
6 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
894ebcf5 | 7 | } */ |
cce28758 | 8 | |
40d13c28 | 9 | require_once 'config.php'; |
b619ff15 | 10 | require_once 'db-prefs.php'; |
5bc0bd27 | 11 | require_once 'compat.php'; |
af106b0e | 12 | require_once 'errors.php'; |
8911ac8b | 13 | require_once 'version.php'; |
40d13c28 | 14 | |
7c5a308d AD |
15 | if (RSS_BACKEND_TYPE == "magpie") { |
16 | require_once 'magpierss/rss_utils.inc'; | |
17 | } else if (RSS_BACKEND_TYPE == "simplepie") { | |
18 | require_once 'simplepie/simplepie.inc'; | |
19 | } | |
387234f3 | 20 | |
a3ee2a38 AD |
21 | define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); |
22 | ||
ad507f85 AD |
23 | function purge_feed($link, $feed_id, $purge_interval, $debug = false) { |
24 | ||
25 | $rows = -1; | |
4c193675 | 26 | |
fefa6ca3 | 27 | if (DB_TYPE == "pgsql") { |
44e241cb | 28 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 29 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 30 | (SELECT date_entered FROM ttrss_entries WHERE |
44e241cb AD |
31 | id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */ |
32 | ||
6e7f8d26 AD |
33 | $pg_version = get_pgsql_version($link); |
34 | ||
35 | if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) { | |
1e59ae35 AD |
36 | |
37 | $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE | |
38 | ttrss_entries.id = ref_id AND | |
39 | marked = false AND | |
40 | feed_id = '$feed_id' AND | |
41 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); | |
42 | ||
43 | } else { | |
44 | ||
45 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
46 | USING ttrss_entries | |
47 | WHERE ttrss_entries.id = ref_id AND | |
48 | marked = false AND | |
49 | feed_id = '$feed_id' AND | |
fc774155 | 50 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
1e59ae35 | 51 | } |
ad507f85 AD |
52 | |
53 | $rows = pg_affected_rows($result); | |
54 | ||
fefa6ca3 | 55 | } else { |
1e59ae35 | 56 | |
30f1746f | 57 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 58 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 59 | (SELECT date_entered FROM ttrss_entries WHERE |
30f1746f AD |
60 | id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ |
61 | ||
62 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
63 | USING ttrss_user_entries, ttrss_entries | |
64 | WHERE ttrss_entries.id = ref_id AND | |
65 | marked = false AND | |
66 | feed_id = '$feed_id' AND | |
67 | ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); | |
68 | ||
ad507f85 AD |
69 | $rows = mysql_affected_rows($link); |
70 | ||
71 | } | |
72 | ||
73 | if ($debug) { | |
74 | print "Purged feed $feed_id ($purge_interval): deleted $rows articles\n"; | |
fefa6ca3 AD |
75 | } |
76 | } | |
77 | ||
44e241cb AD |
78 | function global_purge_old_posts($link, $do_output = false, $limit = false) { |
79 | ||
894ebcf5 | 80 | $random_qpart = sql_random_function(); |
fefa6ca3 | 81 | |
44e241cb AD |
82 | if ($limit) { |
83 | $limit_qpart = "LIMIT $limit"; | |
84 | } else { | |
85 | $limit_qpart = ""; | |
86 | } | |
87 | ||
fefa6ca3 | 88 | $result = db_query($link, |
44e241cb AD |
89 | "SELECT id,purge_interval,owner_uid FROM ttrss_feeds |
90 | ORDER BY $random_qpart $limit_qpart"); | |
fefa6ca3 AD |
91 | |
92 | while ($line = db_fetch_assoc($result)) { | |
93 | ||
94 | $feed_id = $line["id"]; | |
95 | $purge_interval = $line["purge_interval"]; | |
96 | $owner_uid = $line["owner_uid"]; | |
97 | ||
98 | if ($purge_interval == 0) { | |
99 | ||
100 | $tmp_result = db_query($link, | |
101 | "SELECT value FROM ttrss_user_prefs WHERE | |
102 | pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); | |
103 | ||
104 | if (db_num_rows($tmp_result) != 0) { | |
105 | $purge_interval = db_fetch_result($tmp_result, 0, "value"); | |
106 | } | |
107 | } | |
108 | ||
109 | if ($do_output) { | |
ad507f85 | 110 | // print "Feed $feed_id: purge interval = $purge_interval\n"; |
fefa6ca3 AD |
111 | } |
112 | ||
113 | if ($purge_interval > 0) { | |
ad507f85 | 114 | purge_feed($link, $feed_id, $purge_interval, $do_output); |
fefa6ca3 AD |
115 | } |
116 | } | |
117 | ||
71604ca4 AD |
118 | // purge orphaned posts in main content table |
119 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
120 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
121 | ||
fefa6ca3 AD |
122 | } |
123 | ||
b6eefba5 | 124 | function purge_old_posts($link) { |
5d73494a | 125 | |
f1a80dae AD |
126 | $user_id = $_SESSION["uid"]; |
127 | ||
128 | $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds | |
129 | WHERE owner_uid = '$user_id'"); | |
5d73494a AD |
130 | |
131 | while ($line = db_fetch_assoc($result)) { | |
132 | ||
133 | $feed_id = $line["id"]; | |
134 | $purge_interval = $line["purge_interval"]; | |
135 | ||
b619ff15 | 136 | if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS'); |
5d73494a | 137 | |
140aae81 | 138 | if ($purge_interval > 0) { |
fefa6ca3 | 139 | purge_feed($link, $feed_id, $purge_interval); |
5d73494a AD |
140 | } |
141 | } | |
71604ca4 AD |
142 | |
143 | // purge orphaned posts in main content table | |
144 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
145 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
c3a8d71a AD |
146 | } |
147 | ||
1f2b01ed | 148 | function update_all_feeds($link, $fetch, $user_id = false, $force_daemon = false) { |
40d13c28 | 149 | |
4769ddaf | 150 | if (WEB_DEMO_MODE) return; |
b0b4abcf | 151 | |
a2770077 AD |
152 | if (!$user_id) { |
153 | $user_id = $_SESSION["uid"]; | |
154 | purge_old_posts($link); | |
155 | } | |
156 | ||
25af8dad | 157 | // db_query($link, "BEGIN"); |
b82af8c3 | 158 | |
cbd8650d AD |
159 | if (MAX_UPDATE_TIME > 0) { |
160 | if (DB_TYPE == "mysql") { | |
161 | $q_order = "RAND()"; | |
162 | } else { | |
163 | $q_order = "RANDOM()"; | |
164 | } | |
165 | } else { | |
166 | $q_order = "last_updated DESC"; | |
167 | } | |
168 | ||
d148926e | 169 | $result = db_query($link, "SELECT feed_url,id, |
798f722b | 170 | SUBSTRING(last_updated,1,19) AS last_updated, |
5c563acd | 171 | update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id' |
cbd8650d AD |
172 | ORDER BY $q_order"); |
173 | ||
174 | $upd_start = time(); | |
40d13c28 | 175 | |
b6eefba5 | 176 | while ($line = db_fetch_assoc($result)) { |
d148926e AD |
177 | $upd_intl = $line["update_interval"]; |
178 | ||
b619ff15 | 179 | if (!$upd_intl || $upd_intl == 0) { |
a2770077 | 180 | $upd_intl = get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $user_id); |
b619ff15 | 181 | } |
d148926e | 182 | |
c1e202b7 AD |
183 | if ($upd_intl < 0) { |
184 | // Updates for this feed are disabled | |
185 | continue; | |
186 | } | |
187 | ||
93d40f50 AD |
188 | if ($fetch || (!$line["last_updated"] || |
189 | time() - strtotime($line["last_updated"]) > ($upd_intl * 60))) { | |
c5142cca | 190 | |
cbd8650d AD |
191 | // print "<!-- feed: ".$line["feed_url"]." -->"; |
192 | ||
1f2b01ed | 193 | update_rss_feed($link, $line["feed_url"], $line["id"], $force_daemon); |
cbd8650d AD |
194 | |
195 | $upd_elapsed = time() - $upd_start; | |
196 | ||
197 | if (MAX_UPDATE_TIME > 0 && $upd_elapsed > MAX_UPDATE_TIME) { | |
198 | return; | |
199 | } | |
d148926e | 200 | } |
40d13c28 AD |
201 | } |
202 | ||
25af8dad | 203 | // db_query($link, "COMMIT"); |
b82af8c3 | 204 | |
40d13c28 AD |
205 | } |
206 | ||
9e997874 | 207 | function check_feed_favicon($feed_url, $feed, $link) { |
78800912 AD |
208 | $feed_url = str_replace("http://", "", $feed_url); |
209 | $feed_url = preg_replace("/\/.*$/", "", $feed_url); | |
210 | ||
211 | $icon_url = "http://$feed_url/favicon.ico"; | |
273a2f6b | 212 | $icon_file = ICONS_DIR . "/$feed.ico"; |
78800912 AD |
213 | |
214 | if (!file_exists($icon_file)) { | |
e695fdc8 | 215 | |
78800912 AD |
216 | error_reporting(0); |
217 | $r = fopen($icon_url, "r"); | |
cce28758 | 218 | error_reporting (DEFAULT_ERROR_LEVEL); |
78800912 AD |
219 | |
220 | if ($r) { | |
7d7cbaf5 | 221 | $tmpfname = tempnam(TMP_DIRECTORY, "ttrssicon"); |
78800912 AD |
222 | |
223 | $t = fopen($tmpfname, "w"); | |
224 | ||
225 | while (!feof($r)) { | |
226 | $buf = fread($r, 16384); | |
227 | fwrite($t, $buf); | |
228 | } | |
229 | ||
230 | fclose($r); | |
231 | fclose($t); | |
232 | ||
e695fdc8 AD |
233 | error_reporting(0); |
234 | if (!rename($tmpfname, $icon_file)) { | |
235 | unlink($tmpfname); | |
236 | } | |
717f5e64 AD |
237 | |
238 | chmod($icon_file, 0644); | |
239 | ||
cce28758 | 240 | error_reporting (DEFAULT_ERROR_LEVEL); |
78800912 AD |
241 | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
ddb68b81 | 246 | function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { |
40d13c28 | 247 | |
4769ddaf | 248 | if (WEB_DEMO_MODE) return; |
b0b4abcf | 249 | |
ddb68b81 | 250 | if (DAEMON_REFRESH_ONLY && !$_GET["daemon"] && !$ignore_daemon) { |
21cfcdf2 AD |
251 | return; |
252 | } | |
253 | ||
47c6c988 | 254 | $result = db_query($link, "SELECT update_interval,auth_login,auth_pass |
a88c1f36 AD |
255 | FROM ttrss_feeds WHERE id = '$feed'"); |
256 | ||
47c6c988 AD |
257 | $auth_login = db_fetch_result($result, 0, "auth_login"); |
258 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
259 | ||
a88c1f36 AD |
260 | $update_interval = db_fetch_result($result, 0, "update_interval"); |
261 | ||
262 | if ($update_interval < 0) { return; } | |
263 | ||
ab3d0b99 AD |
264 | $feed = db_escape_string($feed); |
265 | ||
47c6c988 AD |
266 | $fetch_url = $feed_url; |
267 | ||
268 | if ($auth_login && $auth_pass) { | |
269 | $url_parts = array(); | |
270 | preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts); | |
271 | ||
272 | if ($url_parts[1] && $url_parts[2]) { | |
273 | $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2]; | |
274 | } | |
275 | ||
276 | } | |
ab3d0b99 | 277 | |
7c5a308d AD |
278 | if (RSS_BACKEND_TYPE == "magpie") { |
279 | error_reporting(0); | |
280 | $rss = fetch_rss($fetch_url); | |
281 | error_reporting (DEFAULT_ERROR_LEVEL); | |
282 | } else if (RSS_BACKEND_TYPE == "simplepie") { | |
283 | ||
284 | if (!file_exists(SIMPLEPIE_CACHE_DIR)) { | |
285 | mkdir(SIMPLEPIE_CACHE_DIR); | |
286 | } | |
76798ff3 | 287 | |
7c5a308d AD |
288 | $rss = new SimplePie(); |
289 | $rss->feed_url($fetch_url); | |
290 | $rss->cache_location(SIMPLEPIE_CACHE_DIR); | |
291 | $rss->init(); | |
292 | } | |
293 | ||
b6eefba5 | 294 | $feed = db_escape_string($feed); |
dcee8f61 | 295 | |
7c5a308d | 296 | $rss_check = $rss; |
b82af8c3 | 297 | |
7c5a308d AD |
298 | if (RSS_BACKEND_TYPE == "simplepie") { |
299 | $rss_check = $rss->data; | |
300 | } | |
301 | ||
302 | if ($rss_check) { | |
303 | ||
44e241cb | 304 | // db_query($link, "BEGIN"); |
dd8c76a9 | 305 | |
a88c1f36 | 306 | $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid |
f324892e | 307 | FROM ttrss_feeds WHERE id = '$feed'"); |
331900c6 | 308 | |
b6eefba5 AD |
309 | $registered_title = db_fetch_result($result, 0, "title"); |
310 | $orig_icon_url = db_fetch_result($result, 0, "icon_url"); | |
f324892e | 311 | $orig_site_url = db_fetch_result($result, 0, "site_url"); |
331900c6 | 312 | |
7fed1940 AD |
313 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); |
314 | ||
a2770077 AD |
315 | if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid)) { |
316 | check_feed_favicon($feed_url, $feed, $link); | |
317 | } | |
318 | ||
746b249f | 319 | if (!$registered_title || $registered_title == "[Unknown]") { |
7c5a308d AD |
320 | |
321 | if (RSS_BACKEND_TYPE == "magpie") { | |
322 | $feed_title = db_escape_string($rss->channel["title"]); | |
323 | } else { | |
324 | $feed_title = $rss->get_feed_title(); | |
325 | } | |
326 | ||
f324892e AD |
327 | db_query($link, "UPDATE ttrss_feeds SET |
328 | title = '$feed_title' WHERE id = '$feed'"); | |
329 | } | |
330 | ||
7c5a308d AD |
331 | if (RSS_BACKEND_TYPE == "magpie") { |
332 | $site_url = $rss->channel["link"]; | |
333 | // weird, weird Magpie | |
334 | if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); | |
335 | } else { | |
336 | $site_url = $rss->get_feed_link(); | |
337 | } | |
147f7691 AD |
338 | |
339 | if ($site_url && $orig_site_url != db_escape_string($site_url)) { | |
f324892e AD |
340 | db_query($link, "UPDATE ttrss_feeds SET |
341 | site_url = '$site_url' WHERE id = '$feed'"); | |
331900c6 | 342 | } |
40d13c28 | 343 | |
b7f4bda2 AD |
344 | // print "I: " . $rss->channel["image"]["url"]; |
345 | ||
7c5a308d AD |
346 | if (RSS_BACKEND_TYPE == "magpie") { |
347 | $icon_url = $rss->image["url"]; | |
348 | } else { | |
349 | $icon_url = $rss->get_image_url(); # FIXME | |
350 | } | |
b7f4bda2 | 351 | |
147f7691 | 352 | if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { |
b6eefba5 AD |
353 | $icon_url = db_escape_string($icon_url); |
354 | db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); | |
b7f4bda2 AD |
355 | } |
356 | ||
e6155a06 AD |
357 | |
358 | $filters = array(); | |
359 | ||
4b3dff6e | 360 | $result = db_query($link, "SELECT reg_exp, |
db42b934 AD |
361 | ttrss_filter_types.name AS name, |
362 | ttrss_filter_actions.name AS action | |
363 | FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE | |
364 | owner_uid = $owner_uid AND | |
365 | ttrss_filter_types.id = filter_type AND | |
366 | ttrss_filter_actions.id = action_id AND | |
ead60402 | 367 | (feed_id IS NULL OR feed_id = '$feed')"); |
e6155a06 | 368 | |
b6eefba5 | 369 | while ($line = db_fetch_assoc($result)) { |
e6155a06 | 370 | if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); |
19c9cb11 AD |
371 | |
372 | $filter["reg_exp"] = $line["reg_exp"]; | |
373 | $filter["action"] = $line["action"]; | |
374 | ||
375 | array_push($filters[$line["name"]], $filter); | |
e6155a06 AD |
376 | } |
377 | ||
7c5a308d AD |
378 | if (RSS_BACKEND_TYPE == "magpie") { |
379 | $iterator = $rss->items; | |
ddb68b81 | 380 | |
7c5a308d AD |
381 | if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; |
382 | if (!$iterator || !is_array($iterator)) $iterator = $rss; | |
383 | ||
384 | } else { | |
385 | $iterator = $rss->get_items(); | |
386 | } | |
c22789da AD |
387 | |
388 | if (!is_array($iterator)) { | |
39541e74 | 389 | /* db_query($link, "UPDATE ttrss_feeds |
75bd0669 | 390 | SET last_error = 'Parse error: can\'t find any articles.' |
39541e74 | 391 | WHERE id = '$feed'"); */ |
c22789da AD |
392 | return; // WTF? |
393 | } | |
ddb68b81 AD |
394 | |
395 | foreach ($iterator as $item) { | |
7c5a308d AD |
396 | |
397 | if (RSS_BACKEND_TYPE == "magpie") { | |
398 | ||
399 | $entry_guid = $item["id"]; | |
400 | ||
401 | if (!$entry_guid) $entry_guid = $item["guid"]; | |
402 | if (!$entry_guid) $entry_guid = $item["link"]; | |
40d13c28 | 403 | |
7c5a308d | 404 | if (!$entry_guid) continue; |
40d13c28 | 405 | |
7c5a308d AD |
406 | $entry_timestamp = ""; |
407 | ||
408 | $rss_2_date = $item['pubdate']; | |
409 | $rss_1_date = $item['dc']['date']; | |
410 | $atom_date = $item['issued']; | |
411 | if (!$atom_date) $atom_date = $item['updated']; | |
b82af8c3 | 412 | |
7c5a308d AD |
413 | if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); |
414 | if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); | |
415 | if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); | |
416 | ||
417 | if ($entry_timestamp == "") { | |
418 | $entry_timestamp = time(); | |
419 | $no_orig_date = 'true'; | |
420 | } else { | |
421 | $no_orig_date = 'false'; | |
422 | } | |
423 | ||
424 | $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
425 | ||
426 | $entry_title = $item["title"]; | |
427 | ||
428 | // strange Magpie workaround | |
429 | $entry_link = $item["link_"]; | |
430 | if (!$entry_link) $entry_link = $item["link"]; | |
431 | ||
432 | if (!$entry_title) continue; | |
433 | if (!$entry_link) continue; | |
434 | ||
435 | $entry_content = $item["content:escaped"]; | |
436 | ||
437 | if (!$entry_content) $entry_content = $item["content:encoded"]; | |
438 | if (!$entry_content) $entry_content = $item["content"]; | |
79b5d2d2 | 439 | if (!$entry_content) $entry_content = $item["atom_content"]; |
7c5a308d AD |
440 | if (!$entry_content) $entry_content = $item["summary"]; |
441 | if (!$entry_content) $entry_content = $item["description"]; | |
442 | ||
443 | // if (!$entry_content) continue; | |
444 | ||
445 | // WTF | |
446 | if (is_array($entry_content)) { | |
447 | $entry_content = $entry_content["encoded"]; | |
448 | if (!$entry_content) $entry_content = $entry_content["escaped"]; | |
449 | } | |
450 | ||
451 | // print_r($item); | |
452 | // print_r(htmlspecialchars($entry_content)); | |
453 | // print "<br>"; | |
454 | ||
455 | $entry_content_unescaped = $entry_content; | |
456 | $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); | |
457 | ||
458 | $entry_comments = $item["comments"]; | |
459 | ||
460 | $entry_author = db_escape_string($item['dc']['creator']); | |
461 | ||
462 | $entry_guid = db_escape_string($entry_guid); | |
463 | ||
464 | $result = db_query($link, "SELECT id FROM ttrss_entries | |
465 | WHERE guid = '$entry_guid'"); | |
466 | ||
467 | $entry_content = db_escape_string($entry_content); | |
468 | $entry_title = db_escape_string($entry_title); | |
469 | $entry_link = db_escape_string($entry_link); | |
470 | $entry_comments = db_escape_string($entry_comments); | |
471 | ||
472 | $num_comments = db_escape_string($item["slash"]["comments"]); | |
473 | ||
474 | if (!$num_comments) $num_comments = 0; | |
71ad3959 | 475 | |
7c5a308d | 476 | } else if (RSS_BACKEND_TYPE == "simplepie") { |
ddb68b81 | 477 | |
7c5a308d | 478 | $entry_guid = $item->get_id(); |
71ad3959 | 479 | |
7c5a308d AD |
480 | if (!$entry_guid) { |
481 | $entry_guid = $item->get_permalink(); | |
482 | } | |
483 | ||
484 | if (!$entry_guid) continue; | |
485 | ||
486 | $entry_timestamp = $item->get_date("U"); | |
487 | ||
488 | if ($entry_timestamp == "") { | |
489 | $entry_timestamp = time(); | |
490 | $no_orig_date = 'true'; | |
491 | } else { | |
492 | $no_orig_date = 'false'; | |
493 | } | |
494 | ||
495 | $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
496 | ||
497 | $entry_title = $item->get_title(); | |
498 | $entry_link = $item->get_permalink(); | |
499 | ||
500 | if (!$entry_title) continue; | |
501 | if (!$entry_link) continue; | |
71ad3959 | 502 | |
7c5a308d AD |
503 | $entry_content = $item->get_description(); |
504 | ||
505 | // print_r(htmlspecialchars($entry_content)); | |
506 | // print "<br>"; | |
507 | ||
508 | $entry_content_unescaped = $entry_content; | |
509 | $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); | |
510 | ||
511 | $entry_comments = ""; # FIXME | |
512 | ||
513 | $entry_author = $item->get_author(0); | |
1696229f | 514 | |
7c5a308d AD |
515 | $entry_author = db_escape_string($entry_author->name); |
516 | ||
517 | $entry_guid = db_escape_string($entry_guid); | |
a2015351 | 518 | |
7c5a308d AD |
519 | $result = db_query($link, "SELECT id FROM ttrss_entries |
520 | WHERE guid = '$entry_guid'"); | |
521 | ||
522 | $entry_content = db_escape_string($entry_content); | |
523 | $entry_title = db_escape_string($entry_title); | |
524 | $entry_link = db_escape_string($entry_link); | |
525 | $entry_comments = db_escape_string($entry_comments); | |
526 | ||
527 | $num_comments = 0; # FIXME | |
528 | ||
529 | if (!$num_comments) $num_comments = 0; | |
a2015351 | 530 | |
8add756a AD |
531 | } |
532 | ||
44e241cb AD |
533 | db_query($link, "BEGIN"); |
534 | ||
4c193675 AD |
535 | if (db_num_rows($result) == 0) { |
536 | ||
537 | // base post entry does not exist, create it | |
538 | ||
4c193675 AD |
539 | $result = db_query($link, |
540 | "INSERT INTO ttrss_entries | |
541 | (title, | |
542 | guid, | |
543 | link, | |
544 | updated, | |
545 | content, | |
546 | content_hash, | |
547 | no_orig_date, | |
548 | date_entered, | |
11b0dce2 | 549 | comments, |
b6104dee AD |
550 | num_comments, |
551 | author) | |
4c193675 AD |
552 | VALUES |
553 | ('$entry_title', | |
554 | '$entry_guid', | |
555 | '$entry_link', | |
556 | '$entry_timestamp_fmt', | |
557 | '$entry_content', | |
558 | '$content_hash', | |
559 | $no_orig_date, | |
560 | NOW(), | |
11b0dce2 | 561 | '$entry_comments', |
b6104dee AD |
562 | '$num_comments', |
563 | '$entry_author')"); | |
8926aab8 AD |
564 | } else { |
565 | // we keep encountering the entry in feeds, so we need to | |
566 | // update date_entered column so that we don't get horrible | |
567 | // dupes when the entry gets purged and reinserted again e.g. | |
568 | // in the case of SLOW SLOW OMG SLOW updating feeds | |
569 | ||
570 | $base_entry_id = db_fetch_result($result, 0, "id"); | |
571 | ||
572 | db_query($link, "UPDATE ttrss_entries SET date_entered = NOW() | |
573 | WHERE id = '$base_entry_id'"); | |
4c193675 AD |
574 | } |
575 | ||
576 | // now it should exist, if not - bad luck then | |
577 | ||
6385315d AD |
578 | $result = db_query($link, "SELECT |
579 | id,content_hash,no_orig_date,title, | |
8926aab8 | 580 | substring(date_entered,1,19) as date_entered, |
11b0dce2 AD |
581 | substring(updated,1,19) as updated, |
582 | num_comments | |
6385315d AD |
583 | FROM |
584 | ttrss_entries | |
585 | WHERE guid = '$entry_guid'"); | |
4c193675 AD |
586 | |
587 | if (db_num_rows($result) == 1) { | |
588 | ||
11b0dce2 AD |
589 | // this will be used below in update handler |
590 | $orig_content_hash = db_fetch_result($result, 0, "content_hash"); | |
591 | $orig_title = db_fetch_result($result, 0, "title"); | |
592 | $orig_num_comments = db_fetch_result($result, 0, "num_comments"); | |
8926aab8 AD |
593 | $orig_date_entered = strtotime(db_fetch_result($result, |
594 | 0, "date_entered")); | |
6385315d | 595 | |
11b0dce2 | 596 | $ref_id = db_fetch_result($result, 0, "id"); |
4c193675 | 597 | |
11b0dce2 | 598 | // check for user post link to main table |
4c193675 | 599 | |
11b0dce2 AD |
600 | // do we allow duplicate posts with same GUID in different feeds? |
601 | if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid)) { | |
602 | $dupcheck_qpart = "AND feed_id = '$feed'"; | |
603 | } else { | |
604 | $dupcheck_qpart = ""; | |
605 | } | |
71604ca4 | 606 | |
11b0dce2 | 607 | // error_reporting(0); |
19c9cb11 | 608 | |
11b0dce2 AD |
609 | $filter_name = get_filter_name($entry_title, $entry_content, |
610 | $entry_link, $filters); | |
19c9cb11 | 611 | |
11b0dce2 AD |
612 | if ($filter_name == "filter") { |
613 | continue; | |
614 | } | |
19c9cb11 | 615 | |
11b0dce2 | 616 | // error_reporting (DEFAULT_ERROR_LEVEL); |
3a933f22 | 617 | |
11b0dce2 AD |
618 | $result = db_query($link, |
619 | "SELECT ref_id FROM ttrss_user_entries WHERE | |
620 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' | |
621 | $dupcheck_qpart"); | |
622 | ||
623 | // okay it doesn't exist - create user entry | |
624 | if (db_num_rows($result) == 0) { | |
625 | ||
626 | if ($filter_name != 'catchup') { | |
627 | $unread = 'true'; | |
628 | $last_read_qpart = 'NULL'; | |
629 | } else { | |
630 | $unread = 'false'; | |
631 | $last_read_qpart = 'NOW()'; | |
632 | } | |
dd7d3187 AD |
633 | |
634 | if ($filter_name == 'mark') { | |
635 | $marked = 'true'; | |
636 | } else { | |
637 | $marked = 'false'; | |
638 | } | |
19c9cb11 | 639 | |
11b0dce2 AD |
640 | $result = db_query($link, |
641 | "INSERT INTO ttrss_user_entries | |
dd7d3187 | 642 | (ref_id, owner_uid, feed_id, unread, last_read, marked) |
11b0dce2 | 643 | VALUES ('$ref_id', '$owner_uid', '$feed', $unread, |
dd7d3187 | 644 | $last_read_qpart, $marked)"); |
11b0dce2 AD |
645 | } |
646 | ||
6385315d AD |
647 | $post_needs_update = false; |
648 | ||
a2770077 | 649 | if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid) && |
6385315d AD |
650 | ($content_hash != $orig_content_hash)) { |
651 | $post_needs_update = true; | |
652 | } | |
653 | ||
654 | if ($orig_title != $entry_title) { | |
655 | $post_needs_update = true; | |
656 | } | |
657 | ||
11b0dce2 AD |
658 | if ($orig_num_comments != $num_comments) { |
659 | $post_needs_update = true; | |
660 | } | |
661 | ||
6385315d AD |
662 | // this doesn't seem to be very reliable |
663 | // | |
664 | // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) { | |
665 | // $post_needs_update = true; | |
666 | // } | |
667 | ||
668 | // if post needs update, update it and mark all user entries | |
1c73bc0c | 669 | // linking to this post as updated |
6385315d AD |
670 | if ($post_needs_update) { |
671 | ||
672 | // print "<!-- post $orig_title needs update : $post_needs_update -->"; | |
673 | ||
6385315d | 674 | db_query($link, "UPDATE ttrss_entries |
11b0dce2 AD |
675 | SET title = '$entry_title', content = '$entry_content', |
676 | num_comments = '$num_comments' | |
6385315d AD |
677 | WHERE id = '$ref_id'"); |
678 | ||
679 | db_query($link, "UPDATE ttrss_user_entries | |
680 | SET last_read = null WHERE ref_id = '$ref_id' AND unread = false"); | |
681 | ||
682 | } | |
4c193675 AD |
683 | } |
684 | ||
44e241cb AD |
685 | db_query($link, "COMMIT"); |
686 | ||
eb36b4eb AD |
687 | /* taaaags */ |
688 | // <a href="http://technorati.com/tag/Xorg" rel="tag">Xorg</a>, // | |
689 | ||
05732aa0 | 690 | $entry_tags = null; |
eb36b4eb | 691 | |
372ced8b | 692 | preg_match_all("/<a.*?href=.http:\/\/.*?technorati.com\/tag\/([^\"\'>]+)/i", |
ee2c3050 AD |
693 | $entry_content_unescaped, $entry_tags); |
694 | ||
695 | // print "<br>$entry_title : $entry_content_unescaped<br>"; | |
696 | // print_r($entry_tags); | |
372ced8b | 697 | // print "<br>"; |
eb36b4eb AD |
698 | |
699 | $entry_tags = $entry_tags[1]; | |
700 | ||
701 | if (count($entry_tags) > 0) { | |
702 | ||
44e241cb AD |
703 | db_query($link, "BEGIN"); |
704 | ||
05732aa0 AD |
705 | $result = db_query($link, "SELECT id,int_id |
706 | FROM ttrss_entries,ttrss_user_entries | |
25da6909 | 707 | WHERE guid = '$entry_guid' |
05732aa0 | 708 | AND feed_id = '$feed' AND ref_id = id |
7fed1940 | 709 | AND owner_uid = '$owner_uid'"); |
eb36b4eb | 710 | |
fe99ab12 | 711 | if (db_num_rows($result) == 1) { |
eb36b4eb | 712 | |
fe99ab12 AD |
713 | $entry_id = db_fetch_result($result, 0, "id"); |
714 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
715 | ||
716 | foreach ($entry_tags as $tag) { | |
717 | $tag = db_escape_string(strtolower($tag)); | |
31483fc1 AD |
718 | |
719 | $tag = str_replace("+", " ", $tag); | |
fe99ab12 AD |
720 | $tag = str_replace("technorati tag: ", "", $tag); |
721 | ||
722 | $result = db_query($link, "SELECT id FROM ttrss_tags | |
723 | WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND | |
724 | owner_uid = '$owner_uid' LIMIT 1"); | |
725 | ||
726 | // print db_fetch_result($result, 0, "id"); | |
727 | ||
728 | if ($result && db_num_rows($result) == 0) { | |
729 | ||
730 | // print "tagging $entry_id as $tag<br>"; | |
731 | ||
732 | db_query($link, "INSERT INTO ttrss_tags | |
733 | (owner_uid,tag_name,post_int_id) | |
734 | VALUES ('$owner_uid','$tag', '$entry_int_id')"); | |
735 | } | |
736 | } | |
eb36b4eb | 737 | } |
44e241cb | 738 | db_query($link, "COMMIT"); |
05732aa0 | 739 | } |
4c193675 | 740 | } |
40d13c28 | 741 | |
ab3d0b99 AD |
742 | db_query($link, "UPDATE ttrss_feeds |
743 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
eb36b4eb | 744 | |
44e241cb | 745 | // db_query($link, "COMMIT"); |
dd8c76a9 | 746 | |
ab3d0b99 AD |
747 | } else { |
748 | $error_msg = db_escape_string(magpie_error()); | |
749 | db_query($link, | |
aa5f9f5f AD |
750 | "UPDATE ttrss_feeds SET last_error = '$error_msg', |
751 | last_updated = NOW() WHERE id = '$feed'"); | |
40d13c28 AD |
752 | } |
753 | ||
754 | } | |
755 | ||
f175937c | 756 | function print_select($id, $default, $values, $attributes = "") { |
79f3553b | 757 | print "<select name=\"$id\" id=\"$id\" $attributes>"; |
a0d53889 AD |
758 | foreach ($values as $v) { |
759 | if ($v == $default) | |
760 | $sel = " selected"; | |
761 | else | |
762 | $sel = ""; | |
763 | ||
764 | print "<option$sel>$v</option>"; | |
765 | } | |
766 | print "</select>"; | |
767 | } | |
40d13c28 | 768 | |
79f3553b AD |
769 | function print_select_hash($id, $default, $values, $attributes = "") { |
770 | print "<select name=\"$id\" id='$id' $attributes>"; | |
673d54ca AD |
771 | foreach (array_keys($values) as $v) { |
772 | if ($v == $default) | |
773 | $sel = "selected"; | |
774 | else | |
775 | $sel = ""; | |
776 | ||
777 | print "<option $sel value=\"$v\">".$values[$v]."</option>"; | |
778 | } | |
779 | ||
780 | print "</select>"; | |
781 | } | |
782 | ||
19c9cb11 | 783 | function get_filter_name($title, $content, $link, $filters) { |
e6155a06 AD |
784 | |
785 | if ($filters["title"]) { | |
19c9cb11 AD |
786 | foreach ($filters["title"] as $filter) { |
787 | $reg_exp = $filter["reg_exp"]; | |
788 | if (preg_match("/$reg_exp/i", $title)) { | |
789 | return $filter["action"]; | |
790 | } | |
e6155a06 AD |
791 | } |
792 | } | |
793 | ||
794 | if ($filters["content"]) { | |
19c9cb11 AD |
795 | foreach ($filters["content"] as $filter) { |
796 | $reg_exp = $filter["reg_exp"]; | |
797 | if (preg_match("/$reg_exp/i", $content)) { | |
798 | return $filter["action"]; | |
799 | } | |
e6155a06 AD |
800 | } |
801 | } | |
802 | ||
803 | if ($filters["both"]) { | |
804 | foreach ($filters["both"] as $filter) { | |
19c9cb11 AD |
805 | $reg_exp = $filter["reg_exp"]; |
806 | if (preg_match("/$reg_exp/i", $title) || | |
807 | preg_match("/$reg_exp/i", $content)) { | |
808 | return $filter["action"]; | |
809 | } | |
e6155a06 AD |
810 | } |
811 | } | |
812 | ||
3a933f22 | 813 | if ($filters["link"]) { |
19c9cb11 AD |
814 | $reg_exp = $filter["reg_exp"]; |
815 | foreach ($filters["link"] as $filter) { | |
816 | $reg_exp = $filter["reg_exp"]; | |
817 | if (preg_match("/$reg_exp/i", $link)) { | |
818 | return $filter["action"]; | |
819 | } | |
3a933f22 AD |
820 | } |
821 | } | |
822 | ||
e6155a06 AD |
823 | return false; |
824 | } | |
825 | ||
9323147e | 826 | function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link, |
fb1fb4ab | 827 | $rtl_content = false, $last_updated = false, $last_error = false) { |
254e0e4b AD |
828 | |
829 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
023fe037 | 830 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">"; |
254e0e4b | 831 | } else { |
023fe037 | 832 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">"; |
254e0e4b AD |
833 | } |
834 | ||
9323147e AD |
835 | if ($rtl_content) { |
836 | $rtl_tag = "dir=\"rtl\""; | |
837 | } else { | |
838 | $rtl_tag = "dir=\"ltr\""; | |
839 | } | |
840 | ||
78d5212c AD |
841 | $error_notify_msg = ""; |
842 | ||
fb1fb4ab AD |
843 | if ($last_error) { |
844 | $link_title = "Error: $last_error ($last_updated)"; | |
78d5212c | 845 | $error_notify_msg = "(Error)"; |
ad780e9c | 846 | } else if ($last_updated) { |
fb1fb4ab AD |
847 | $link_title = "Updated: $last_updated"; |
848 | } | |
849 | ||
850 | $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\" href=\"javascript:viewfeed('$feed_id', 0);\">$feed_title</a>"; | |
254e0e4b AD |
851 | |
852 | print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; | |
b619ff15 | 853 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { |
254e0e4b AD |
854 | print "$feed_icon"; |
855 | } | |
856 | ||
9323147e | 857 | print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>"; |
254e0e4b AD |
858 | |
859 | if ($unread != 0) { | |
860 | $fctr_class = ""; | |
861 | } else { | |
862 | $fctr_class = "class=\"invisible\""; | |
863 | } | |
864 | ||
9323147e | 865 | print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\"> |
254e0e4b | 866 | (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>"; |
78d5212c AD |
867 | |
868 | if (get_pref($link, "EXTENDED_FEEDLIST")) { | |
869 | print "<div class=\"feedExtInfo\"> | |
870 | <span id=\"FLUPD-$feed_id\">$last_updated $error_notify_msg</span></div>"; | |
871 | } | |
872 | ||
254e0e4b AD |
873 | print "</li>"; |
874 | ||
875 | } | |
876 | ||
406d9489 AD |
877 | function getmicrotime() { |
878 | list($usec, $sec) = explode(" ",microtime()); | |
879 | return ((float)$usec + (float)$sec); | |
880 | } | |
881 | ||
77e96719 AD |
882 | function print_radio($id, $default, $values, $attributes = "") { |
883 | foreach ($values as $v) { | |
884 | ||
885 | if ($v == $default) | |
5da169d9 | 886 | $sel = "checked"; |
77e96719 | 887 | else |
5da169d9 AD |
888 | $sel = ""; |
889 | ||
890 | if ($v == "Yes") { | |
891 | $sel .= " value=\"1\""; | |
892 | } else { | |
893 | $sel .= " value=\"0\""; | |
894 | } | |
77e96719 | 895 | |
69654950 AD |
896 | print "<input class=\"noborder\" |
897 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; | |
77e96719 AD |
898 | |
899 | } | |
900 | } | |
901 | ||
ff485f1d AD |
902 | function initialize_user_prefs($link, $uid) { |
903 | ||
904 | $uid = db_escape_string($uid); | |
905 | ||
906 | db_query($link, "BEGIN"); | |
907 | ||
908 | $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); | |
909 | ||
910 | $u_result = db_query($link, "SELECT pref_name | |
911 | FROM ttrss_user_prefs WHERE owner_uid = '$uid'"); | |
912 | ||
913 | $active_prefs = array(); | |
914 | ||
915 | while ($line = db_fetch_assoc($u_result)) { | |
916 | array_push($active_prefs, $line["pref_name"]); | |
917 | } | |
918 | ||
919 | while ($line = db_fetch_assoc($result)) { | |
920 | if (array_search($line["pref_name"], $active_prefs) === FALSE) { | |
921 | // print "adding " . $line["pref_name"] . "<br>"; | |
922 | ||
923 | db_query($link, "INSERT INTO ttrss_user_prefs | |
924 | (owner_uid,pref_name,value) VALUES | |
925 | ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); | |
926 | ||
927 | } | |
928 | } | |
929 | ||
930 | db_query($link, "COMMIT"); | |
931 | ||
932 | } | |
956c7629 AD |
933 | |
934 | function lookup_user_id($link, $user) { | |
935 | ||
936 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
937 | login = '$login'"); | |
938 | ||
939 | if (db_num_rows($result) == 1) { | |
940 | return db_fetch_result($result, 0, "id"); | |
941 | } else { | |
942 | return false; | |
943 | } | |
944 | } | |
945 | ||
c8437f35 AD |
946 | function authenticate_user($link, $login, $password) { |
947 | ||
131b01b3 | 948 | if (!SINGLE_USER_MODE) { |
c8437f35 | 949 | |
131b01b3 AD |
950 | $pwd_hash = 'SHA1:' . sha1($password); |
951 | ||
952 | $result = db_query($link, "SELECT id,login,access_level FROM ttrss_users WHERE | |
953 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
954 | ||
955 | if (db_num_rows($result) == 1) { | |
956 | $_SESSION["uid"] = db_fetch_result($result, 0, "id"); | |
957 | $_SESSION["name"] = db_fetch_result($result, 0, "login"); | |
958 | $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level"); | |
959 | ||
960 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
961 | $_SESSION["uid"]); | |
962 | ||
963 | $user_theme = get_user_theme_path($link); | |
964 | ||
965 | $_SESSION["theme"] = $user_theme; | |
966 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
967 | ||
968 | initialize_user_prefs($link, $_SESSION["uid"]); | |
969 | ||
970 | return true; | |
971 | } | |
972 | ||
973 | return false; | |
503eb349 | 974 | |
131b01b3 | 975 | } else { |
503eb349 | 976 | |
131b01b3 AD |
977 | $_SESSION["uid"] = 1; |
978 | $_SESSION["name"] = "admin"; | |
f557cd78 | 979 | |
0bbba72d AD |
980 | $user_theme = get_user_theme_path($link); |
981 | ||
982 | $_SESSION["theme"] = $user_theme; | |
983 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
984 | ||
985 | initialize_user_prefs($link, $_SESSION["uid"]); | |
986 | ||
c8437f35 AD |
987 | return true; |
988 | } | |
c8437f35 AD |
989 | } |
990 | ||
e6cb77a0 AD |
991 | function make_password($length = 8) { |
992 | ||
993 | $password = ""; | |
798f722b AD |
994 | $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; |
995 | ||
996 | $i = 0; | |
e6cb77a0 AD |
997 | |
998 | while ($i < $length) { | |
999 | $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
1000 | ||
1001 | if (!strstr($password, $char)) { | |
1002 | $password .= $char; | |
1003 | $i++; | |
1004 | } | |
1005 | } | |
1006 | return $password; | |
1007 | } | |
1008 | ||
1009 | // this is called after user is created to initialize default feeds, labels | |
1010 | // or whatever else | |
1011 | ||
1012 | // user preferences are checked on every login, not here | |
1013 | ||
1014 | function initialize_user($link, $uid) { | |
1015 | ||
1016 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1017 | values ('$uid','unread = true', 'Unread articles')"); | |
1018 | ||
1019 | db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) | |
1020 | values ('$uid','last_read is null and unread = false', 'Updated articles')"); | |
1021 | ||
1022 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) | |
74bff337 | 1023 | values ('$uid', 'Tiny Tiny RSS: New Releases', |
628fcd2c | 1024 | 'http://tt-rss.spb.ru/releases.rss')"); |
3b0feb9b AD |
1025 | |
1026 | } | |
e6cb77a0 | 1027 | |
b8aa49bc | 1028 | function logout_user() { |
5ccc1cf5 AD |
1029 | session_destroy(); |
1030 | if (isset($_COOKIE[session_name()])) { | |
1031 | setcookie(session_name(), '', time()-42000, '/'); | |
1032 | } | |
b8aa49bc AD |
1033 | } |
1034 | ||
75836f33 | 1035 | function get_script_urlpath() { |
87a79fa4 | 1036 | return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]); |
75836f33 AD |
1037 | } |
1038 | ||
1039 | function get_login_redirect() { | |
1040 | $server = $_SERVER["SERVER_NAME"]; | |
1041 | ||
1042 | if (ENABLE_LOGIN_SSL) { | |
1043 | $protocol = "https"; | |
1044 | } else { | |
1045 | $protocol = "http"; | |
1046 | } | |
1047 | ||
1048 | $url_path = get_script_urlpath(); | |
1049 | ||
1050 | $redirect_uri = "$protocol://$server$url_path/login.php"; | |
1051 | ||
1052 | return $redirect_uri; | |
1053 | } | |
1054 | ||
916f788a | 1055 | function validate_session($link) { |
a2e9b457 | 1056 | if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { |
916f788a AD |
1057 | if ($_SESSION["ip_address"]) { |
1058 | if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { | |
1059 | return false; | |
1060 | } | |
1061 | } | |
1062 | } | |
1063 | return true; | |
1064 | } | |
1065 | ||
7ae65adf AD |
1066 | function basic_nosid_redirect_check() { |
1067 | if (!SINGLE_USER_MODE) { | |
3dd46f19 | 1068 | if (!$_COOKIE[get_session_cookie_name()]) { |
7ae65adf AD |
1069 | $redirect_uri = get_login_redirect(); |
1070 | $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]); | |
1071 | header("Location: $redirect_uri?rt=$return_to"); | |
1072 | exit; | |
1073 | } | |
1074 | } | |
1075 | } | |
1076 | ||
b8aa49bc AD |
1077 | function login_sequence($link) { |
1078 | if (!SINGLE_USER_MODE) { | |
75836f33 | 1079 | |
916f788a AD |
1080 | if (!validate_session($link)) { |
1081 | logout_user(); | |
1082 | $redirect_uri = get_login_redirect(); | |
1083 | $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]); | |
1084 | header("Location: $redirect_uri?rt=$return_to"); | |
1085 | exit; | |
1086 | } | |
1087 | ||
b8aa49bc AD |
1088 | if (!USE_HTTP_AUTH) { |
1089 | if (!$_SESSION["uid"]) { | |
75836f33 | 1090 | $redirect_uri = get_login_redirect(); |
e31dca14 AD |
1091 | $return_to = preg_replace('/.*?\//', '', $_SERVER["REQUEST_URI"]); |
1092 | header("Location: $redirect_uri?rt=$return_to"); | |
b8aa49bc AD |
1093 | exit; |
1094 | } | |
1095 | } else { | |
f557cd78 AD |
1096 | if (!$_SESSION["uid"]) { |
1097 | if (!$_SERVER["PHP_AUTH_USER"]) { | |
1098 | ||
1099 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"'); | |
1100 | header('HTTP/1.0 401 Unauthorized'); | |
1101 | exit; | |
1102 | ||
1103 | } else { | |
1104 | $auth_result = authenticate_user($link, | |
1105 | $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]); | |
1106 | ||
1107 | if (!$auth_result) { | |
1108 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS"'); | |
1109 | header('HTTP/1.0 401 Unauthorized'); | |
1110 | exit; | |
1111 | } | |
1112 | } | |
1113 | } | |
b8aa49bc AD |
1114 | } |
1115 | } else { | |
0bbba72d | 1116 | return authenticate_user($link, "admin", null); |
b8aa49bc AD |
1117 | } |
1118 | } | |
3547842a AD |
1119 | |
1120 | function truncate_string($str, $max_len) { | |
12db369c AD |
1121 | if (mb_strlen($str, "utf-8") > $max_len - 3) { |
1122 | return mb_substr($str, 0, $max_len, "utf-8") . "..."; | |
3547842a AD |
1123 | } else { |
1124 | return $str; | |
1125 | } | |
1126 | } | |
54a60e1a AD |
1127 | |
1128 | function get_user_theme_path($link) { | |
798f722b AD |
1129 | $result = db_query($link, "SELECT theme_path |
1130 | FROM | |
1131 | ttrss_themes,ttrss_users | |
1132 | WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); | |
54a60e1a AD |
1133 | if (db_num_rows($result) != 0) { |
1134 | return db_fetch_result($result, 0, "theme_path"); | |
1135 | } else { | |
1136 | return null; | |
1137 | } | |
1138 | } | |
be773442 AD |
1139 | |
1140 | function smart_date_time($timestamp) { | |
1141 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1142 | return date("G:i", $timestamp); | |
f26450f1 | 1143 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1144 | return date("M d, G:i", $timestamp); |
1145 | } else { | |
b02111c2 | 1146 | return date("Y/m/d G:i", $timestamp); |
be773442 AD |
1147 | } |
1148 | } | |
1149 | ||
1150 | function smart_date($timestamp) { | |
1151 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1152 | return "Today"; | |
f26450f1 | 1153 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1154 | return date("D m", $timestamp); |
1155 | } else { | |
b02111c2 | 1156 | return date("Y/m/d", $timestamp); |
be773442 AD |
1157 | } |
1158 | } | |
a654a595 AD |
1159 | |
1160 | function sql_bool_to_string($s) { | |
1161 | if ($s == "t" || $s == "1") { | |
1162 | return "true"; | |
1163 | } else { | |
1164 | return "false"; | |
1165 | } | |
1166 | } | |
e3c99f3b AD |
1167 | |
1168 | function sql_bool_to_bool($s) { | |
1169 | if ($s == "t" || $s == "1") { | |
1170 | return true; | |
1171 | } else { | |
1172 | return false; | |
1173 | } | |
1174 | } | |
0ea4fb50 | 1175 | |
e3c99f3b | 1176 | |
0ea4fb50 AD |
1177 | function toggleEvenOdd($a) { |
1178 | if ($a == "even") | |
1179 | return "odd"; | |
1180 | else | |
1181 | return "even"; | |
1182 | } | |
6043fb7e AD |
1183 | |
1184 | function sanity_check($link) { | |
9cbca41f | 1185 | |
6043fb7e AD |
1186 | $error_code = 0; |
1187 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
1188 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
1189 | ||
1190 | if ($schema_version != SCHEMA_VERSION) { | |
1191 | $error_code = 5; | |
1192 | } | |
1193 | ||
6043fb7e | 1194 | if ($error_code != 0) { |
3560a0be | 1195 | print_error_xml(5); |
6043fb7e AD |
1196 | return false; |
1197 | } else { | |
1198 | return true; | |
9cbca41f | 1199 | } |
6043fb7e AD |
1200 | } |
1201 | ||
27981ca3 AD |
1202 | function file_is_locked($filename) { |
1203 | error_reporting(0); | |
1204 | $fp = fopen($filename, "r"); | |
1205 | error_reporting(DEFAULT_ERROR_LEVEL); | |
1206 | if ($fp) { | |
1207 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
1208 | flock($fp, LOCK_UN); | |
1209 | fclose($fp); | |
1210 | return false; | |
1211 | } | |
1212 | fclose($fp); | |
1213 | return true; | |
1214 | } | |
1215 | return false; | |
1216 | } | |
1217 | ||
fcb4c0c9 AD |
1218 | function make_lockfile($filename) { |
1219 | $fp = fopen($filename, "w"); | |
1220 | ||
1221 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
1222 | return $fp; | |
1223 | } else { | |
1224 | return false; | |
1225 | } | |
1226 | } | |
1227 | ||
894ebcf5 AD |
1228 | function sql_random_function() { |
1229 | if (DB_TYPE == "mysql") { | |
1230 | return "RAND()"; | |
1231 | } else { | |
1232 | return "RANDOM()"; | |
1233 | } | |
1234 | } | |
1235 | ||
23aa0d16 AD |
1236 | function catchup_feed($link, $feed, $cat_view) { |
1237 | if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) { | |
1238 | ||
1239 | if ($cat_view) { | |
1240 | ||
1241 | if ($feed > 0) { | |
1242 | $cat_qpart = "cat_id = '$feed'"; | |
1243 | } else { | |
1244 | $cat_qpart = "cat_id IS NULL"; | |
1245 | } | |
1246 | ||
1247 | $tmp_result = db_query($link, "SELECT id | |
1248 | FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . | |
1249 | $_SESSION["uid"]); | |
1250 | ||
1251 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1252 | ||
1253 | $tmp_feed = $tmp_line["id"]; | |
1254 | ||
1255 | db_query($link, "UPDATE ttrss_user_entries | |
1256 | SET unread = false,last_read = NOW() | |
1257 | WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]); | |
1258 | } | |
1259 | ||
1260 | } else if ($feed > 0) { | |
1261 | ||
1262 | $tmp_result = db_query($link, "SELECT id | |
1263 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
1264 | ORDER BY cat_id,title"); | |
1265 | ||
1266 | $parent_ids = array(); | |
1267 | ||
1268 | if (db_num_rows($tmp_result) > 0) { | |
1269 | while ($p = db_fetch_assoc($tmp_result)) { | |
1270 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
1271 | } | |
1272 | ||
1273 | $children_qpart = implode(" OR ", $parent_ids); | |
1274 | ||
1275 | db_query($link, "UPDATE ttrss_user_entries | |
1276 | SET unread = false,last_read = NOW() | |
1277 | WHERE (feed_id = '$feed' OR $children_qpart) | |
1278 | AND owner_uid = " . $_SESSION["uid"]); | |
1279 | ||
1280 | } else { | |
1281 | db_query($link, "UPDATE ttrss_user_entries | |
1282 | SET unread = false,last_read = NOW() | |
1283 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1284 | } | |
1285 | ||
1286 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
1287 | ||
1288 | if ($feed == -1) { | |
1289 | db_query($link, "UPDATE ttrss_user_entries | |
1290 | SET unread = false,last_read = NOW() | |
1291 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); | |
1292 | } | |
1293 | ||
1294 | } else if ($feed < -10) { // label | |
1295 | ||
1296 | // TODO make this more efficient | |
1297 | ||
1298 | $label_id = -$feed - 11; | |
1299 | ||
1300 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1301 | WHERE id = '$label_id'"); | |
1302 | ||
1303 | if ($tmp_result) { | |
1304 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1305 | ||
1306 | db_query($link, "BEGIN"); | |
1307 | ||
1308 | $tmp2_result = db_query($link, | |
1309 | "SELECT | |
1310 | int_id | |
1311 | FROM | |
1312 | ttrss_user_entries,ttrss_entries | |
1313 | WHERE | |
1314 | ref_id = id AND | |
1315 | $sql_exp AND | |
1316 | owner_uid = " . $_SESSION["uid"]); | |
1317 | ||
1318 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
1319 | db_query($link, "UPDATE | |
1320 | ttrss_user_entries | |
1321 | SET | |
1322 | unread = false, last_read = NOW() | |
1323 | WHERE | |
1324 | int_id = " . $tmp_line["int_id"]); | |
1325 | } | |
1326 | ||
1327 | db_query($link, "COMMIT"); | |
1328 | ||
1329 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
1330 | SET unread = false,last_read = NOW() | |
1331 | WHERE $sql_exp | |
1332 | AND ref_id = id | |
1333 | AND owner_uid = ".$_SESSION["uid"]); */ | |
1334 | } | |
1335 | } | |
1336 | } else { // tag | |
1337 | db_query($link, "BEGIN"); | |
1338 | ||
1339 | $tag_name = db_escape_string($feed); | |
1340 | ||
1341 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
1342 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
1343 | ||
1344 | while ($line = db_fetch_assoc($result)) { | |
1345 | db_query($link, "UPDATE ttrss_user_entries SET | |
1346 | unread = false, last_read = NOW() | |
1347 | WHERE int_id = " . $line["post_int_id"]); | |
1348 | } | |
1349 | db_query($link, "COMMIT"); | |
1350 | } | |
1351 | } | |
1352 | ||
1353 | function update_generic_feed($link, $feed, $cat_view) { | |
1354 | if ($cat_view) { | |
1355 | ||
1356 | if ($feed > 0) { | |
1357 | $cat_qpart = "cat_id = '$feed'"; | |
1358 | } else { | |
1359 | $cat_qpart = "cat_id IS NULL"; | |
1360 | } | |
1361 | ||
1362 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1363 | WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]); | |
1364 | ||
1365 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1366 | $feed_url = $tmp_line["feed_url"]; | |
1367 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1368 | } | |
1369 | ||
1370 | } else { | |
1371 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1372 | WHERE id = '$feed'"); | |
1373 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
1374 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1375 | } | |
1376 | } | |
a9cb1f83 AD |
1377 | |
1378 | function getAllCounters($link) { | |
1379 | getLabelCounters($link); | |
1380 | getFeedCounters($link); | |
1381 | getTagCounters($link); | |
1382 | getGlobalCounters($link); | |
1383 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1384 | getCategoryCounters($link); | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | function getCategoryCounters($link) { | |
1389 | $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) | |
1390 | FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id | |
1391 | AND unread = true)) AS unread FROM ttrss_feeds | |
1392 | WHERE | |
1393 | owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); | |
1394 | ||
1395 | while ($line = db_fetch_assoc($result)) { | |
1396 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
1397 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". | |
1398 | $line["unread"]."\"/>"; | |
1399 | } | |
1400 | } | |
1401 | ||
1402 | function getFeedUnread($link, $feed) { | |
1403 | $n_feed = sprintf("%d", $feed); | |
1404 | ||
1405 | if ($n_feed == -1) { | |
1406 | $match_part = "marked = true"; | |
1407 | } else if ($feed > 0) { | |
1408 | $match_part = "feed_id = '$n_feed'"; | |
1409 | } else if ($feed < -10) { | |
1410 | $label_id = -$feed - 11; | |
1411 | ||
1412 | $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE | |
1413 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
1414 | ||
1415 | $match_part = db_fetch_result($result, 0, "sql_exp"); | |
1416 | } | |
1417 | ||
1418 | if ($match_part) { | |
1419 | ||
1420 | $result = db_query($link, "SELECT count(int_id) AS unread | |
1421 | FROM ttrss_user_entries | |
1422 | WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); | |
1423 | ||
1424 | } else { | |
1425 | ||
1426 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
1427 | FROM ttrss_tags,ttrss_user_entries | |
1428 | WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND | |
1429 | ttrss_tags.owner_uid = " . $_SESSION["uid"]); | |
1430 | } | |
1431 | ||
1432 | $unread = db_fetch_result($result, 0, "unread"); | |
1433 | return $unread; | |
1434 | } | |
1435 | ||
1436 | /* FIXME this needs reworking */ | |
1437 | ||
1438 | function getGlobalUnread($link) { | |
1439 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries | |
1440 | WHERE unread = true AND | |
1441 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1442 | owner_uid = " . $_SESSION["uid"]); | |
1443 | $c_id = db_fetch_result($result, 0, "c_id"); | |
1444 | return $c_id; | |
1445 | } | |
1446 | ||
1447 | function getGlobalCounters($link, $global_unread = -1) { | |
1448 | if ($global_unread == -1) { | |
1449 | $global_unread = getGlobalUnread($link); | |
1450 | } | |
1451 | print "<counter type=\"global\" id='global-unread' counter='$global_unread'/>"; | |
1452 | } | |
1453 | ||
1454 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
1455 | ||
1456 | if ($smart_mode) { | |
1457 | if (!$_SESSION["tctr_last_value"]) { | |
1458 | $_SESSION["tctr_last_value"] = array(); | |
1459 | } | |
1460 | } | |
1461 | ||
1462 | $old_counters = $_SESSION["tctr_last_value"]; | |
1463 | ||
1464 | $tctrs_modified = false; | |
1465 | ||
1466 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
1467 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
1468 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1469 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND | |
1470 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name | |
1471 | UNION | |
1472 | select tag_name,0 as count FROM ttrss_tags | |
1473 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ | |
1474 | ||
1475 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) | |
1476 | FROM ttrss_user_entries WHERE int_id = post_int_id | |
1477 | AND unread = true)) AS count FROM ttrss_tags | |
1478 | WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); | |
1479 | ||
1480 | $tags = array(); | |
1481 | ||
1482 | while ($line = db_fetch_assoc($result)) { | |
1483 | $tags[$line["tag_name"]] += $line["count"]; | |
1484 | } | |
1485 | ||
1486 | foreach (array_keys($tags) as $tag) { | |
1487 | $unread = $tags[$tag]; | |
1488 | ||
1489 | $tag = htmlspecialchars($tag); | |
1490 | ||
1491 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
1492 | $old_counters[$tag] = $unread; | |
1493 | $tctrs_modified = true; | |
1494 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
1495 | } | |
1496 | ||
1497 | } | |
1498 | ||
1499 | if ($smart_mode && $tctrs_modified) { | |
1500 | $_SESSION["tctr_last_value"] = $old_counters; | |
1501 | } | |
1502 | ||
1503 | } | |
1504 | ||
ef393de7 | 1505 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { |
a9cb1f83 AD |
1506 | |
1507 | if ($smart_mode) { | |
1508 | if (!$_SESSION["lctr_last_value"]) { | |
1509 | $_SESSION["lctr_last_value"] = array(); | |
1510 | } | |
1511 | } | |
1512 | ||
ef393de7 AD |
1513 | $ret_arr = array(); |
1514 | ||
a9cb1f83 AD |
1515 | $old_counters = $_SESSION["lctr_last_value"]; |
1516 | $lctrs_modified = false; | |
1517 | ||
1518 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries | |
1519 | WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1520 | unread = true AND owner_uid = ".$_SESSION["uid"]); | |
1521 | ||
1522 | $count = db_fetch_result($result, 0, "count"); | |
1523 | ||
ef393de7 AD |
1524 | if (!$ret_mode) { |
1525 | print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>"; | |
1526 | } else { | |
1527 | $ret_arr["-1"]["counter"] = $count; | |
1528 | $ret_arr["-1"]["description"] = "Starred"; | |
1529 | } | |
a9cb1f83 AD |
1530 | |
1531 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM | |
1532 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
1533 | ||
1534 | while ($line = db_fetch_assoc($result)) { | |
1535 | ||
1536 | $id = -$line["id"] - 11; | |
1537 | ||
ef393de7 AD |
1538 | $label_name = $line["description"]; |
1539 | ||
a9cb1f83 AD |
1540 | error_reporting (0); |
1541 | ||
1542 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries | |
1543 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
1544 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1545 | owner_uid = ".$_SESSION["uid"]); | |
1546 | ||
1547 | $count = db_fetch_result($tmp_result, 0, "count"); | |
1548 | ||
1549 | if (!$smart_mode || $old_counters[$id] != $count) { | |
1550 | $old_counters[$id] = $count; | |
1551 | $lctrs_modified = true; | |
ef393de7 AD |
1552 | if (!$ret_mode) { |
1553 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>"; | |
1554 | } else { | |
1555 | $ret_arr[$id]["counter"] = $count; | |
1556 | $ret_arr[$id]["description"] = $label_name; | |
1557 | } | |
a9cb1f83 AD |
1558 | } |
1559 | ||
1560 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1561 | } | |
1562 | ||
1563 | if ($smart_mode && $lctrs_modified) { | |
1564 | $_SESSION["lctr_last_value"] = $old_counters; | |
1565 | } | |
ef393de7 AD |
1566 | |
1567 | return $ret_arr; | |
a9cb1f83 AD |
1568 | } |
1569 | ||
1570 | /* function getFeedCounter($link, $id) { | |
1571 | ||
1572 | $result = db_query($link, "SELECT | |
1573 | count(id) as count,last_error | |
1574 | FROM ttrss_entries,ttrss_user_entries,ttrss_feeds | |
1575 | WHERE feed_id = '$id' AND unread = true | |
1576 | AND ttrss_user_entries.feed_id = ttrss_feeds.id | |
1577 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
1578 | ||
1579 | $count = db_fetch_result($result, 0, "count"); | |
1580 | $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error")); | |
1581 | ||
1582 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>"; | |
1583 | } */ | |
1584 | ||
1585 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
1586 | ||
1587 | if ($smart_mode) { | |
1588 | if (!$_SESSION["fctr_last_value"]) { | |
1589 | $_SESSION["fctr_last_value"] = array(); | |
1590 | } | |
1591 | } | |
1592 | ||
1593 | $old_counters = $_SESSION["fctr_last_value"]; | |
1594 | ||
1595 | $result = db_query($link, "SELECT id,last_error,parent_feed, | |
fb1fb4ab | 1596 | SUBSTRING(last_updated,1,19) AS last_updated, |
a9cb1f83 AD |
1597 | (SELECT count(id) |
1598 | FROM ttrss_entries,ttrss_user_entries | |
1599 | WHERE feed_id = ttrss_feeds.id AND | |
1600 | ttrss_user_entries.ref_id = ttrss_entries.id | |
1601 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count | |
1602 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . " | |
1603 | AND parent_feed IS NULL"); | |
1604 | ||
1605 | $fctrs_modified = false; | |
1606 | ||
fb1fb4ab AD |
1607 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); |
1608 | ||
a9cb1f83 AD |
1609 | while ($line = db_fetch_assoc($result)) { |
1610 | ||
1611 | $id = $line["id"]; | |
1612 | $count = $line["count"]; | |
1613 | $last_error = htmlspecialchars($line["last_error"]); | |
fb1fb4ab AD |
1614 | |
1615 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
1616 | $last_updated = smart_date_time(strtotime($line["last_updated"])); | |
1617 | } else { | |
1618 | $last_updated = date($short_date, strtotime($line["last_updated"])); | |
1619 | } | |
1620 | ||
a9cb1f83 AD |
1621 | $has_img = is_file(ICONS_DIR . "/$id.ico"); |
1622 | ||
1623 | $tmp_result = db_query($link, | |
1624 | "SELECT id,COUNT(unread) AS unread | |
1625 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries | |
1626 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
1627 | WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id"); | |
1628 | ||
1629 | if (db_num_rows($tmp_result) > 0) { | |
1630 | while ($l = db_fetch_assoc($tmp_result)) { | |
1631 | $count += $l["unread"]; | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | if (!$smart_mode || $old_counters[$id] != $count) { | |
1636 | $old_counters[$id] = $count; | |
1637 | $fctrs_modified = true; | |
1638 | ||
1639 | if ($last_error) { | |
1640 | $error_part = "error=\"$last_error\""; | |
1641 | } else { | |
1642 | $error_part = ""; | |
1643 | } | |
1644 | ||
1645 | if ($has_img) { | |
1646 | $has_img_part = "hi=\"$has_img\""; | |
1647 | } else { | |
1648 | $has_img_part = ""; | |
1649 | } | |
1650 | ||
fb1fb4ab | 1651 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\"/>"; |
a9cb1f83 AD |
1652 | } |
1653 | } | |
1654 | ||
1655 | if ($smart_mode && $fctrs_modified) { | |
1656 | $_SESSION["fctr_last_value"] = $old_counters; | |
1657 | } | |
1658 | } | |
1659 | ||
1b758780 AD |
1660 | function get_script_dt_add() { |
1661 | if (strpos(VERSION, "99") === false) { | |
1662 | return VERSION; | |
1663 | } else { | |
1664 | return time(); | |
1665 | } | |
1666 | } | |
1667 | ||
6e7f8d26 AD |
1668 | function get_pgsql_version($link) { |
1669 | $result = db_query($link, "SELECT version() AS version"); | |
1670 | $version = split(" ", db_fetch_result($result, 0, "version")); | |
1671 | return $version[1]; | |
1672 | } | |
1673 | ||
af106b0e AD |
1674 | function print_error_xml($code, $add_msg = "") { |
1675 | global $ERRORS; | |
1676 | ||
1677 | $error_msg = $ERRORS[$code]; | |
1678 | ||
1679 | if ($add_msg) { | |
1680 | $error_msg = "$error_msg; $add_msg"; | |
1681 | } | |
1682 | ||
4c2abbc1 | 1683 | print "<rpc-reply>"; |
af106b0e | 1684 | print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>"; |
4c2abbc1 | 1685 | print "</rpc-reply>"; |
af106b0e | 1686 | } |
956c7629 AD |
1687 | |
1688 | function subscribe_to_feed($link, $feed_link, $cat_id = 0) { | |
1689 | ||
1690 | if ($cat_id == "0" || !$cat_id) { | |
1691 | $cat_qpart = "NULL"; | |
1692 | } else { | |
1693 | $cat_qpart = "'$cat_id'"; | |
1694 | } | |
1695 | ||
1696 | $result = db_query($link, | |
1697 | "SELECT id FROM ttrss_feeds | |
1698 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
1699 | ||
1700 | if (db_num_rows($result) == 0) { | |
1701 | ||
1702 | $result = db_query($link, | |
1703 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
1704 | VALUES ('".$_SESSION["uid"]."', '$feed_link', | |
1705 | '[Unknown]', $cat_qpart)"); | |
1706 | ||
1707 | $result = db_query($link, | |
1708 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
1709 | AND owner_uid = " . $_SESSION["uid"]); | |
1710 | ||
1711 | $feed_id = db_fetch_result($result, 0, "id"); | |
1712 | ||
1713 | if ($feed_id) { | |
1714 | update_rss_feed($link, $feed_link, $feed_id, true); | |
1715 | } | |
1716 | ||
1717 | return true; | |
1718 | } else { | |
1719 | return false; | |
1720 | } | |
1721 | } | |
1722 | ||
673d54ca AD |
1723 | function print_feed_select($link, $id, $default_id = "", |
1724 | $attributes = "", $include_all_feeds = true) { | |
1725 | ||
79f3553b | 1726 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca | 1727 | if ($include_all_feeds) { |
79f3553b | 1728 | print "<option value=\"0\">All feeds</option>"; |
673d54ca AD |
1729 | } |
1730 | ||
1731 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
1732 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1733 | ||
1734 | if (db_num_rows($result) > 0 && $include_all_feeds) { | |
1735 | print "<option disabled>--------</option>"; | |
1736 | } | |
1737 | ||
1738 | while ($line = db_fetch_assoc($result)) { | |
1739 | if ($line["id"] == $default_id) { | |
1740 | $is_selected = "selected"; | |
1741 | } else { | |
1742 | $is_selected = ""; | |
1743 | } | |
79f3553b | 1744 | printf("<option $is_selected value='%d'>%s</option>", |
07164479 | 1745 | $line["id"], htmlspecialchars(db_unescape_string($line["title"]))); |
673d54ca AD |
1746 | } |
1747 | ||
1748 | print "</select>"; | |
1749 | } | |
1750 | ||
1751 | function print_feed_cat_select($link, $id, $default_id = "", | |
1752 | $attributes = "", $include_all_cats = true) { | |
1753 | ||
79f3553b | 1754 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca AD |
1755 | |
1756 | if ($include_all_cats) { | |
14f69488 | 1757 | print "<option value=\"0\">Uncategorized</option>"; |
673d54ca AD |
1758 | } |
1759 | ||
1760 | $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1761 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1762 | ||
1763 | if (db_num_rows($result) > 0 && $include_all_cats) { | |
1764 | print "<option disabled>--------</option>"; | |
1765 | } | |
1766 | ||
1767 | while ($line = db_fetch_assoc($result)) { | |
1768 | if ($line["id"] == $default_id) { | |
1769 | $is_selected = "selected"; | |
1770 | } else { | |
1771 | $is_selected = ""; | |
1772 | } | |
14f69488 | 1773 | printf("<option $is_selected value='%d'>%s</option>", |
07164479 | 1774 | $line["id"], htmlspecialchars(db_unescape_string($line["title"]))); |
673d54ca AD |
1775 | } |
1776 | ||
1777 | print "</select>"; | |
1778 | } | |
1779 | ||
14f69488 AD |
1780 | function checkbox_to_sql_bool($val) { |
1781 | return ($val == "on") ? "true" : "false"; | |
1782 | } | |
86b682ce AD |
1783 | |
1784 | function getFeedCatTitle($link, $id) { | |
1785 | if ($id == -1) { | |
1786 | return "Special"; | |
1787 | } else if ($id < -10) { | |
1788 | return "Labels"; | |
1789 | } else if ($id > 0) { | |
1790 | $result = db_query($link, "SELECT ttrss_feed_categories.title | |
1791 | FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND | |
1792 | cat_id = ttrss_feed_categories.id"); | |
1793 | if (db_num_rows($result) == 1) { | |
1794 | return db_fetch_result($result, 0, "title"); | |
1795 | } else { | |
eb4311d0 | 1796 | return "Uncategorized"; |
86b682ce AD |
1797 | } |
1798 | } else { | |
1799 | return "getFeedCatTitle($id) failed"; | |
1800 | } | |
1801 | ||
1802 | } | |
1803 | ||
1804 | function getFeedTitle($link, $id) { | |
1805 | if ($id == -1) { | |
1806 | return "Starred articles"; | |
1807 | } else if ($id < -10) { | |
1808 | $label_id = -10 - $id; | |
1809 | $result = db_query($link, "SELECT description FROM ttrss_labels WHERE id = '$label_id'"); | |
1810 | if (db_num_rows($result) == 1) { | |
1811 | return db_fetch_result($result, 0, "description"); | |
1812 | } else { | |
1813 | return "Unknown label ($label_id)"; | |
1814 | } | |
1815 | ||
1816 | } else if ($id > 0) { | |
1817 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'"); | |
1818 | if (db_num_rows($result) == 1) { | |
1819 | return db_fetch_result($result, 0, "title"); | |
1820 | } else { | |
1821 | return "Unknown feed ($id)"; | |
1822 | } | |
1823 | } else { | |
1824 | return "getFeedTitle($id) failed"; | |
1825 | } | |
1826 | ||
1827 | } | |
3dd46f19 AD |
1828 | |
1829 | function get_session_cookie_name() { | |
1830 | return ((!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME); | |
1831 | } | |
3ac2b520 AD |
1832 | |
1833 | function print_init_params($link) { | |
1834 | print "<init-params>"; | |
1835 | if ($_SESSION["stored-params"]) { | |
1836 | foreach (array_keys($_SESSION["stored-params"]) as $key) { | |
1837 | $value = htmlspecialchars($_SESSION["stored-params"][$key]); | |
1838 | print "<param key=\"$key\" value=\"$value\"/>"; | |
1839 | } | |
1840 | } | |
1841 | ||
1842 | print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>"; | |
1843 | print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>"; | |
0d51e25d | 1844 | print "<param key=\"daemon_refresh_only\" value=\"" . DAEMON_REFRESH_ONLY . "\"/>"; |
3ac2b520 AD |
1845 | |
1846 | print "<param key=\"on_catchup_show_next_feed\" value=\"" . | |
1847 | get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>"; | |
1848 | ||
e8bd0da9 AD |
1849 | print "<param key=\"hide_read_feeds\" value=\"" . |
1850 | sprintf("%d", get_pref($link, "HIDE_READ_FEEDS")) . "\"/>"; | |
1851 | ||
c9268ed5 AD |
1852 | print "<param key=\"feeds_sort_by_unread\" value=\"" . |
1853 | sprintf("%d", get_pref($link, "FEEDS_SORT_BY_UNREAD")) . "\"/>"; | |
1854 | ||
3ac2b520 AD |
1855 | print "</init-params>"; |
1856 | } | |
f54f515f AD |
1857 | |
1858 | function print_runtime_info($link) { | |
1859 | print "<runtime-info>"; | |
71ad883b AD |
1860 | if (ENABLE_UPDATE_DAEMON) { |
1861 | print "<param key=\"daemon_is_running\" value=\"". | |
1862 | sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>"; | |
1863 | } | |
f54f515f AD |
1864 | print "</runtime-info>"; |
1865 | } | |
ef393de7 AD |
1866 | |
1867 | function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on) { | |
1868 | ||
1869 | if ($search) { | |
1870 | if ($match_on == "both") { | |
1871 | $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%') | |
1872 | OR upper(ttrss_entries.content) LIKE '%$search%') AND"; | |
1873 | } else if ($match_on == "title") { | |
1874 | $search_query_part = "upper(ttrss_entries.title) LIKE upper('%$search%') | |
1875 | AND"; | |
1876 | } else if ($match_on == "content") { | |
1877 | $search_query_part = "upper(ttrss_entries.content) LIKE upper('%$search%') AND"; | |
1878 | } | |
1879 | } else { | |
1880 | $search_query_part = ""; | |
1881 | } | |
1882 | ||
1883 | $view_query_part = ""; | |
1884 | ||
1885 | if ($view_mode == "adaptive") { | |
1886 | if ($search) { | |
1887 | $view_query_part = " "; | |
1888 | } else if ($feed != -1) { | |
1889 | $unread = getFeedUnread($link, $feed); | |
1890 | if ($unread > 0) { | |
1891 | $view_query_part = " unread = true AND "; | |
1892 | } | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | if ($view_mode == "marked") { | |
1897 | $view_query_part = " marked = true AND "; | |
1898 | } | |
1899 | ||
1900 | if ($view_mode == "unread") { | |
1901 | $view_query_part = " unread = true AND "; | |
1902 | } | |
1903 | ||
1904 | if ($limit > 0) { | |
1905 | $limit_query_part = "LIMIT " . $limit; | |
1906 | } | |
1907 | ||
1908 | $vfeed_query_part = ""; | |
1909 | ||
1910 | // override query strategy and enable feed display when searching globally | |
1911 | if ($search && $search_mode == "all_feeds") { | |
1912 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1913 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1914 | } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { | |
1915 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1916 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1917 | id = feed_id) as feed_title,"; | |
1918 | } else if ($feed >= 0 && $search && $search_mode == "this_cat") { | |
1919 | ||
1920 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1921 | ||
1922 | $tmp_result = db_query($link, "SELECT id | |
1923 | FROM ttrss_feeds WHERE cat_id = | |
1924 | (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'"); | |
1925 | ||
1926 | $cat_siblings = array(); | |
1927 | ||
1928 | if (db_num_rows($tmp_result) > 0) { | |
1929 | while ($p = db_fetch_assoc($tmp_result)) { | |
1930 | array_push($cat_siblings, "feed_id = " . $p["id"]); | |
1931 | } | |
1932 | ||
1933 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
1934 | $feed, implode(" OR ", $cat_siblings)); | |
1935 | ||
1936 | } else { | |
1937 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1938 | } | |
1939 | ||
1940 | } else if ($feed >= 0) { | |
1941 | ||
1942 | if ($cat_view) { | |
1943 | ||
1944 | if ($feed > 0) { | |
1945 | $query_strategy_part = "cat_id = '$feed'"; | |
1946 | } else { | |
1947 | $query_strategy_part = "cat_id IS NULL"; | |
1948 | } | |
1949 | ||
1950 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1951 | ||
1952 | } else { | |
1953 | $tmp_result = db_query($link, "SELECT id | |
1954 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
1955 | ORDER BY cat_id,title"); | |
1956 | ||
1957 | $parent_ids = array(); | |
1958 | ||
1959 | if (db_num_rows($tmp_result) > 0) { | |
1960 | while ($p = db_fetch_assoc($tmp_result)) { | |
1961 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
1962 | } | |
1963 | ||
1964 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
1965 | $feed, implode(" OR ", $parent_ids)); | |
1966 | ||
1967 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1968 | } else { | |
1969 | $query_strategy_part = "feed_id = '$feed'"; | |
1970 | } | |
1971 | } | |
1972 | } else if ($feed == -1) { // starred virtual feed | |
1973 | $query_strategy_part = "marked = true"; | |
1974 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1975 | } else if ($feed <= -10) { // labels | |
1976 | $label_id = -$feed - 11; | |
1977 | ||
1978 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1979 | WHERE id = '$label_id'"); | |
1980 | ||
1981 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1982 | ||
1983 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1984 | } else { | |
1985 | $query_strategy_part = "id > 0"; // dumb | |
1986 | } | |
1987 | ||
1988 | $order_by = "updated DESC"; | |
1989 | ||
1990 | $feed_title = ""; | |
1991 | ||
1992 | if ($search && $search_mode == "all_feeds") { | |
1993 | $feed_title = "Global search results ($search)"; | |
1994 | } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { | |
1995 | $feed_title = "Feed search results ($search, $feed)"; | |
1996 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { | |
1997 | $feed_title = $feed; | |
1998 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { | |
1999 | ||
2000 | if ($cat_view) { | |
2001 | ||
2002 | if ($feed != 0) { | |
2003 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories | |
2004 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
2005 | $feed_title = db_fetch_result($result, 0, "title"); | |
2006 | } else { | |
2007 | $feed_title = "Uncategorized"; | |
2008 | } | |
2009 | } else { | |
2010 | ||
2011 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
2012 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
2013 | ||
2014 | $feed_title = db_fetch_result($result, 0, "title"); | |
2015 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
2016 | $last_error = db_fetch_result($result, 0, "last_error"); | |
2017 | ||
2018 | } | |
2019 | ||
2020 | } else if ($feed == -1) { | |
2021 | $feed_title = "Starred articles"; | |
2022 | } else if ($feed < -10) { | |
2023 | $label_id = -$feed - 11; | |
2024 | $result = db_query($link, "SELECT description FROM ttrss_labels | |
2025 | WHERE id = '$label_id'"); | |
2026 | $feed_title = db_fetch_result($result, 0, "description"); | |
2027 | } else { | |
2028 | $feed_title = "?"; | |
2029 | } | |
2030 | ||
2031 | $feed_title = db_unescape_string($feed_title); | |
2032 | ||
2033 | if ($feed < -10) error_reporting (0); | |
2034 | ||
2035 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
2036 | ||
2037 | if ($feed >= 0) { | |
2038 | $feed_kind = "Feeds"; | |
2039 | } else { | |
2040 | $feed_kind = "Labels"; | |
2041 | } | |
2042 | ||
2043 | $content_query_part = "content as content_preview,"; | |
2044 | ||
2045 | $query = "SELECT | |
2046 | ttrss_entries.id,ttrss_entries.title, | |
2047 | SUBSTRING(updated,1,16) as updated, | |
2048 | unread,feed_id,marked,link,last_read, | |
2049 | SUBSTRING(last_read,1,19) as last_read_noms, | |
2050 | $vfeed_query_part | |
2051 | $content_query_part | |
2052 | SUBSTRING(updated,1,19) as updated_noms | |
2053 | FROM | |
2054 | ttrss_entries,ttrss_user_entries,ttrss_feeds | |
2055 | WHERE | |
2056 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
2057 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
2058 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
2059 | $search_query_part | |
2060 | $view_query_part | |
2061 | $query_strategy_part ORDER BY $order_by | |
2062 | $limit_query_part"; | |
2063 | ||
2064 | $result = db_query($link, $query); | |
2065 | ||
2066 | if ($_GET["debug"]) print $query; | |
2067 | ||
2068 | } else { | |
2069 | // browsing by tag | |
2070 | ||
2071 | $feed_kind = "Tags"; | |
2072 | ||
2073 | $result = db_query($link, "SELECT | |
2074 | ttrss_entries.id as id,title, | |
2075 | SUBSTRING(updated,1,16) as updated, | |
2076 | unread,feed_id, | |
2077 | marked,link,last_read, | |
2078 | SUBSTRING(last_read,1,19) as last_read_noms, | |
2079 | $vfeed_query_part | |
2080 | $content_query_part | |
2081 | SUBSTRING(updated,1,19) as updated_noms | |
2082 | FROM | |
2083 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
2084 | WHERE | |
2085 | ref_id = ttrss_entries.id AND | |
2086 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
2087 | post_int_id = int_id AND tag_name = '$feed' AND | |
2088 | $view_query_part | |
2089 | $search_query_part | |
2090 | $query_strategy_part ORDER BY $order_by | |
2091 | $limit_query_part"); | |
2092 | } | |
2093 | ||
c7188969 | 2094 | return array($result, $feed_title, $feed_site_url, $last_error); |
ef393de7 AD |
2095 | |
2096 | } | |
2097 | ||
40d13c28 | 2098 | ?> |