]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
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'; |
cc17c205 | 10 | |
fc2b26a6 AD |
11 | if (DB_TYPE == "pgsql") { |
12 | define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE'); | |
13 | } else { | |
14 | define('SUBSTRING_FOR_DATE', 'SUBSTRING'); | |
15 | } | |
16 | ||
9632f884 AD |
17 | /** |
18 | * Return available translations names. | |
19 | * | |
20 | * @access public | |
21 | * @return array A array of available translations. | |
22 | */ | |
f8c612d4 | 23 | function get_translations() { |
6a214f92 | 24 | $tr = array( |
a927fe7b | 25 | "auto" => "Detect automatically", |
6a214f92 | 26 | "en_US" => "English", |
a927fe7b | 27 | "de_DE" => "Deutsch", |
6a214f92 | 28 | "fr_FR" => "Français", |
e78fd196 | 29 | "hu_HU" => "Magyar (Hungarian)", |
bb5d3960 | 30 | "it_IT" => "Italiano", |
1d004f12 | 31 | "ja_JP" => "日本語 (Japanese)", |
592535d7 | 32 | "nb_NO" => "Norwegian bokmål", |
6a214f92 | 33 | "ru_RU" => "Русский", |
9a063469 | 34 | "pt_BR" => "Portuguese/Brazil", |
6a214f92 | 35 | "zh_CN" => "Simplified Chinese"); |
f8c612d4 AD |
36 | |
37 | return $tr; | |
38 | } | |
39 | ||
9632f884 | 40 | if (ENABLE_TRANSLATIONS == true) { // If translations are enabled. |
865220a4 | 41 | require_once "accept-to-gettext.php"; |
0ba3a127 | 42 | require_once "lib/gettext/gettext.inc"; |
aba609e0 | 43 | |
8d039718 AD |
44 | function startup_gettext() { |
45 | ||
46 | # Get locale from Accept-Language header | |
6a214f92 | 47 | $lang = al2gt(array_keys(get_translations()), "text/html"); |
89cb787e AD |
48 | |
49 | if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) { | |
50 | $lang = _TRANSLATION_OVERRIDE_DEFAULT; | |
51 | } | |
52 | ||
672f3f3c | 53 | if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") { |
68659d98 AD |
54 | $lang = $_COOKIE["ttrss_lang"]; |
55 | } | |
56 | ||
7c33dbd4 AD |
57 | /* In login action of mobile version */ |
58 | if ($_POST["language"] && defined('MOBILE_VERSION')) { | |
59 | $lang = $_POST["language"]; | |
60 | $_COOKIE["ttrss_lang"] = $lang; | |
61 | } | |
62 | ||
8d039718 | 63 | if ($lang) { |
86e2e1b9 AD |
64 | if (defined('LC_MESSAGES')) { |
65 | _setlocale(LC_MESSAGES, $lang); | |
66 | } else if (defined('LC_ALL')) { | |
67 | _setlocale(LC_ALL, $lang); | |
68 | } else { | |
69 | die("can't setlocale(): please set ENABLE_TRANSLATIONS to false in config.php"); | |
70 | } | |
7c33dbd4 AD |
71 | |
72 | if (defined('MOBILE_VERSION')) { | |
73 | _bindtextdomain("messages", "../locale"); | |
74 | } else { | |
75 | _bindtextdomain("messages", "locale"); | |
76 | } | |
77 | ||
8d039718 AD |
78 | _textdomain("messages"); |
79 | _bind_textdomain_codeset("messages", "UTF-8"); | |
80 | } | |
aba609e0 | 81 | } |
aba609e0 | 82 | |
cc17c205 | 83 | startup_gettext(); |
865220a4 | 84 | |
9632f884 | 85 | } else { // If translations are enabled. |
865220a4 AD |
86 | function __($msg) { |
87 | return $msg; | |
88 | } | |
89 | function startup_gettext() { | |
90 | // no-op | |
91 | return true; | |
92 | } | |
9632f884 | 93 | } // If translations are enabled. |
cc17c205 | 94 | |
b619ff15 | 95 | require_once 'db-prefs.php'; |
5bc0bd27 | 96 | require_once 'compat.php'; |
af106b0e | 97 | require_once 'errors.php'; |
8911ac8b | 98 | require_once 'version.php'; |
40d13c28 | 99 | |
d134e3a3 | 100 | require_once 'lib/phpmailer/class.phpmailer.php'; |
a8931123 | 101 | |
49f9c923 | 102 | define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); |
a3ee2a38 | 103 | define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); |
ba0f7628 | 104 | define('MAGPIE_CACHE_AGE', 60*15); // 15 minutes |
a3ee2a38 | 105 | |
5ef03f15 | 106 | require_once "lib/simplepie/simplepie.inc"; |
816cdfb7 AD |
107 | require_once "lib/magpierss/rss_fetch.inc"; |
108 | require_once 'lib/magpierss/rss_utils.inc'; | |
f45a286b | 109 | require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php'; |
49f9c923 | 110 | |
45004d43 AD |
111 | /** |
112 | * Print a timestamped debug message. | |
113 | * | |
114 | * @param string $msg The debug message. | |
115 | * @return void | |
116 | */ | |
6f9e33e4 AD |
117 | function _debug($msg) { |
118 | $ts = strftime("%H:%M:%S", time()); | |
2a6a9395 AD |
119 | if (function_exists('posix_getpid')) { |
120 | $ts = "$ts/" . posix_getpid(); | |
121 | } | |
6f9e33e4 | 122 | print "[$ts] $msg\n"; |
45004d43 | 123 | } // function _debug |
6f9e33e4 | 124 | |
9632f884 AD |
125 | /** |
126 | * Purge a feed old posts. | |
127 | * | |
128 | * @param mixed $link A database connection. | |
129 | * @param mixed $feed_id The id of the purged feed. | |
130 | * @param mixed $purge_interval Olderness of purged posts. | |
131 | * @param boolean $debug Set to True to enable the debug. False by default. | |
132 | * @access public | |
133 | * @return void | |
134 | */ | |
ad507f85 AD |
135 | function purge_feed($link, $feed_id, $purge_interval, $debug = false) { |
136 | ||
07d0efe9 | 137 | if (!$purge_interval) $purge_interval = feed_purge_interval($link, $feed_id); |
01299231 | 138 | |
ad507f85 | 139 | $rows = -1; |
4c193675 | 140 | |
07d0efe9 AD |
141 | $result = db_query($link, |
142 | "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); | |
143 | ||
144 | $owner_uid = false; | |
145 | ||
146 | if (db_num_rows($result) == 1) { | |
147 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
148 | } | |
149 | ||
ab954dff AD |
150 | if ($purge_interval == -1 || !$purge_interval) { |
151 | if ($owner_uid) { | |
152 | ccache_update($link, $feed_id, $owner_uid); | |
153 | } | |
154 | return; | |
155 | } | |
156 | ||
07d0efe9 AD |
157 | if (!$owner_uid) return; |
158 | ||
3907ef71 AD |
159 | if (FORCE_ARTICLE_PURGE == 0) { |
160 | $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES", | |
161 | $owner_uid, false); | |
162 | } else { | |
163 | $purge_unread = true; | |
164 | $purge_interval = FORCE_ARTICLE_PURGE; | |
165 | } | |
07d0efe9 AD |
166 | |
167 | if (!$purge_unread) $query_limit = " unread = false AND "; | |
168 | ||
fefa6ca3 | 169 | if (DB_TYPE == "pgsql") { |
44e241cb | 170 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 171 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 172 | (SELECT date_entered FROM ttrss_entries WHERE |
44e241cb AD |
173 | id = ref_id) < NOW() - INTERVAL '$purge_interval days'"); */ |
174 | ||
6e7f8d26 AD |
175 | $pg_version = get_pgsql_version($link); |
176 | ||
177 | if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) { | |
1e59ae35 AD |
178 | |
179 | $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE | |
180 | ttrss_entries.id = ref_id AND | |
181 | marked = false AND | |
182 | feed_id = '$feed_id' AND | |
07d0efe9 | 183 | $query_limit |
1e59ae35 AD |
184 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
185 | ||
186 | } else { | |
187 | ||
188 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
189 | USING ttrss_entries | |
190 | WHERE ttrss_entries.id = ref_id AND | |
191 | marked = false AND | |
192 | feed_id = '$feed_id' AND | |
07d0efe9 | 193 | $query_limit |
fc774155 | 194 | ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); |
1e59ae35 | 195 | } |
ad507f85 AD |
196 | |
197 | $rows = pg_affected_rows($result); | |
198 | ||
fefa6ca3 | 199 | } else { |
1e59ae35 | 200 | |
30f1746f | 201 | /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE |
fefa6ca3 | 202 | marked = false AND feed_id = '$feed_id' AND |
35d8cf43 | 203 | (SELECT date_entered FROM ttrss_entries WHERE |
30f1746f AD |
204 | id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ |
205 | ||
206 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
207 | USING ttrss_user_entries, ttrss_entries | |
208 | WHERE ttrss_entries.id = ref_id AND | |
209 | marked = false AND | |
210 | feed_id = '$feed_id' AND | |
07d0efe9 | 211 | $query_limit |
30f1746f AD |
212 | ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); |
213 | ||
ad507f85 AD |
214 | $rows = mysql_affected_rows($link); |
215 | ||
216 | } | |
217 | ||
ced46404 AD |
218 | ccache_update($link, $feed_id, $owner_uid); |
219 | ||
ad507f85 | 220 | if ($debug) { |
6f9e33e4 | 221 | _debug("Purged feed $feed_id ($purge_interval): deleted $rows articles"); |
fefa6ca3 | 222 | } |
9632f884 | 223 | } // function purge_feed |
fefa6ca3 | 224 | |
9632f884 AD |
225 | /** |
226 | * Purge old posts from old feeds. | |
227 | * | |
228 | * @param mixed $link A database connection | |
229 | * @param boolean $do_output Set to true to enable printed output, false by default. | |
230 | * @param integer $limit The maximal number of removed posts. | |
231 | * @access public | |
232 | * @return void | |
233 | */ | |
44e241cb AD |
234 | function global_purge_old_posts($link, $do_output = false, $limit = false) { |
235 | ||
894ebcf5 | 236 | $random_qpart = sql_random_function(); |
fefa6ca3 | 237 | |
44e241cb AD |
238 | if ($limit) { |
239 | $limit_qpart = "LIMIT $limit"; | |
240 | } else { | |
241 | $limit_qpart = ""; | |
242 | } | |
243 | ||
fefa6ca3 | 244 | $result = db_query($link, |
44e241cb AD |
245 | "SELECT id,purge_interval,owner_uid FROM ttrss_feeds |
246 | ORDER BY $random_qpart $limit_qpart"); | |
fefa6ca3 AD |
247 | |
248 | while ($line = db_fetch_assoc($result)) { | |
249 | ||
250 | $feed_id = $line["id"]; | |
251 | $purge_interval = $line["purge_interval"]; | |
252 | $owner_uid = $line["owner_uid"]; | |
253 | ||
254 | if ($purge_interval == 0) { | |
255 | ||
256 | $tmp_result = db_query($link, | |
257 | "SELECT value FROM ttrss_user_prefs WHERE | |
258 | pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); | |
259 | ||
260 | if (db_num_rows($tmp_result) != 0) { | |
261 | $purge_interval = db_fetch_result($tmp_result, 0, "value"); | |
262 | } | |
263 | } | |
264 | ||
265 | if ($do_output) { | |
ad507f85 | 266 | // print "Feed $feed_id: purge interval = $purge_interval\n"; |
fefa6ca3 AD |
267 | } |
268 | ||
3907ef71 | 269 | if ($purge_interval > 0 || FORCE_ARTICLE_PURGE) { |
ad507f85 | 270 | purge_feed($link, $feed_id, $purge_interval, $do_output); |
fefa6ca3 AD |
271 | } |
272 | } | |
273 | ||
71604ca4 | 274 | // purge orphaned posts in main content table |
dab52d7b | 275 | $result = db_query($link, "DELETE FROM ttrss_entries WHERE |
71604ca4 AD |
276 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); |
277 | ||
dab52d7b AD |
278 | if ($do_output) { |
279 | $rows = db_affected_rows($link, $result); | |
280 | _debug("Purged $rows orphaned posts."); | |
281 | } | |
282 | ||
9632f884 | 283 | } // function global_purge_old_posts |
fefa6ca3 | 284 | |
07d0efe9 AD |
285 | function feed_purge_interval($link, $feed_id) { |
286 | ||
287 | $result = db_query($link, "SELECT purge_interval, owner_uid FROM ttrss_feeds | |
288 | WHERE id = '$feed_id'"); | |
289 | ||
290 | if (db_num_rows($result) == 1) { | |
291 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); | |
292 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
293 | ||
294 | if ($purge_interval == 0) $purge_interval = get_pref($link, | |
863be6ca | 295 | 'PURGE_OLD_DAYS', $owner_uid); |
07d0efe9 AD |
296 | |
297 | return $purge_interval; | |
298 | ||
299 | } else { | |
300 | return -1; | |
301 | } | |
302 | } | |
303 | ||
b6eefba5 | 304 | function purge_old_posts($link) { |
5d73494a | 305 | |
f1a80dae AD |
306 | $user_id = $_SESSION["uid"]; |
307 | ||
308 | $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds | |
309 | WHERE owner_uid = '$user_id'"); | |
5d73494a AD |
310 | |
311 | while ($line = db_fetch_assoc($result)) { | |
312 | ||
313 | $feed_id = $line["id"]; | |
314 | $purge_interval = $line["purge_interval"]; | |
315 | ||
b619ff15 | 316 | if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS'); |
5d73494a | 317 | |
140aae81 | 318 | if ($purge_interval > 0) { |
fefa6ca3 | 319 | purge_feed($link, $feed_id, $purge_interval); |
5d73494a AD |
320 | } |
321 | } | |
71604ca4 | 322 | |
0e0dd486 AD |
323 | purge_orphans($link); |
324 | } | |
325 | ||
326 | function purge_orphans($link) { | |
71604ca4 AD |
327 | // purge orphaned posts in main content table |
328 | db_query($link, "DELETE FROM ttrss_entries WHERE | |
329 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
c3a8d71a AD |
330 | } |
331 | ||
c7d57b66 AD |
332 | function get_feed_update_interval($link, $feed_id) { |
333 | $result = db_query($link, "SELECT owner_uid, update_interval FROM | |
334 | ttrss_feeds WHERE id = '$feed_id'"); | |
335 | ||
336 | if (db_num_rows($result) == 1) { | |
337 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
338 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); | |
339 | ||
340 | if ($update_interval != 0) { | |
341 | return $update_interval; | |
342 | } else { | |
343 | return get_pref($link, 'DEFAULT_UPDATE_INTERVAL', $owner_uid, false); | |
344 | } | |
345 | ||
346 | } else { | |
347 | return -1; | |
348 | } | |
349 | } | |
350 | ||
4065b60b AD |
351 | function fetch_file_contents($url) { |
352 | if (USE_CURL_FOR_ICONS) { | |
353 | $tmpfile = tempnam(TMP_DIRECTORY, "ttrss-tmp"); | |
354 | ||
355 | $ch = curl_init($url); | |
356 | $fp = fopen($tmpfile, "w"); | |
357 | ||
358 | if ($fp) { | |
359 | curl_setopt($ch, CURLOPT_FILE, $fp); | |
dd966fed AD |
360 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); |
361 | curl_setopt($ch, CURLOPT_TIMEOUT, 45); | |
4065b60b AD |
362 | curl_exec($ch); |
363 | curl_close($ch); | |
364 | fclose($fp); | |
365 | } | |
366 | ||
367 | $contents = file_get_contents($tmpfile); | |
368 | unlink($tmpfile); | |
369 | ||
370 | return $contents; | |
371 | ||
372 | } else { | |
373 | return file_get_contents($url); | |
374 | } | |
375 | ||
376 | } | |
78800912 | 377 | |
9632f884 AD |
378 | /** |
379 | * Try to determine the favicon URL for a feed. | |
380 | * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) | |
381 | * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php | |
382 | * | |
383 | * @param string $url A feed or page URL | |
384 | * @access public | |
385 | * @return mixed The favicon URL, or false if none was found. | |
386 | */ | |
4065b60b | 387 | function get_favicon_url($url) { |
99331724 | 388 | |
4065b60b | 389 | if ($html = @fetch_file_contents($url)) { |
78800912 | 390 | |
4065b60b AD |
391 | if ( preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { |
392 | // Attempt to grab a favicon link from their webpage url | |
393 | $linkUrl = html_entity_decode($matches[1]); | |
c798704b | 394 | |
4065b60b AD |
395 | if (substr($linkUrl, 0, 1) == '/') { |
396 | $urlParts = parse_url($url); | |
397 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; | |
398 | } else if (substr($linkUrl, 0, 7) == 'http://') { | |
399 | $faviconURL = $linkUrl; | |
4065b60b | 400 | } else { |
c7e51de1 AD |
401 | $pos = strrpos($url, "/"); |
402 | // no "/" in url or "/" is part of "://" | |
403 | if ($pos === false || $pos == (strpos($url, "://")+2)) { | |
404 | $faviconURL = $url.'/'.$linkUrl; | |
405 | } else { | |
406 | $faviconURL = substr($url, 0, $pos+1).$linkUrl; | |
407 | } | |
e695fdc8 | 408 | } |
717f5e64 | 409 | |
c798704b | 410 | } else { |
4065b60b AD |
411 | // If unsuccessful, attempt to "guess" the favicon location |
412 | $urlParts = parse_url($url); | |
413 | $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; | |
414 | } | |
415 | } | |
c798704b | 416 | |
4065b60b AD |
417 | // Run a test to see if what we have attempted to get actually exists. |
418 | if(USE_CURL_FOR_ICONS || url_validate($faviconURL)) { | |
419 | return $faviconURL; | |
420 | } else { | |
421 | return false; | |
422 | } | |
9632f884 | 423 | } // function get_favicon_url |
4065b60b | 424 | |
9632f884 AD |
425 | /** |
426 | * Check if a link is a valid and working URL. | |
427 | * | |
428 | * @param mixed $link A URL to check | |
429 | * @access public | |
430 | * @return boolean True if the URL is valid, false otherwise. | |
431 | */ | |
4065b60b AD |
432 | function url_validate($link) { |
433 | ||
434 | $url_parts = @parse_url($link); | |
435 | ||
436 | if ( empty( $url_parts["host"] ) ) | |
437 | return false; | |
438 | ||
439 | if ( !empty( $url_parts["path"] ) ) { | |
440 | $documentpath = $url_parts["path"]; | |
441 | } else { | |
442 | $documentpath = "/"; | |
443 | } | |
444 | ||
445 | if ( !empty( $url_parts["query"] ) ) | |
446 | $documentpath .= "?" . $url_parts["query"]; | |
447 | ||
448 | $host = $url_parts["host"]; | |
449 | $port = $url_parts["port"]; | |
450 | ||
451 | if ( empty($port) ) | |
452 | $port = "80"; | |
453 | ||
454 | $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); | |
455 | ||
456 | if ( !$socket ) | |
457 | return false; | |
c798704b | 458 | |
4065b60b AD |
459 | fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); |
460 | ||
461 | $http_response = fgets( $socket, 22 ); | |
462 | ||
c7e51de1 | 463 | $responses = "/(200 OK)|(30[123])/"; |
4065b60b AD |
464 | if ( preg_match($responses, $http_response) ) { |
465 | fclose($socket); | |
466 | return true; | |
467 | } else { | |
468 | return false; | |
469 | } | |
470 | ||
9632f884 | 471 | } // function url_validate |
4065b60b AD |
472 | |
473 | function check_feed_favicon($site_url, $feed, $link) { | |
474 | $favicon_url = get_favicon_url($site_url); | |
475 | ||
476 | # print "FAVICON [$site_url]: $favicon_url\n"; | |
477 | ||
478 | error_reporting(0); | |
479 | ||
480 | $icon_file = ICONS_DIR . "/$feed.ico"; | |
481 | ||
482 | if ($favicon_url && !file_exists($icon_file)) { | |
483 | $contents = fetch_file_contents($favicon_url); | |
484 | ||
485 | $fp = fopen($icon_file, "w"); | |
78800912 | 486 | |
4065b60b AD |
487 | if ($fp) { |
488 | fwrite($fp, $contents); | |
489 | fclose($fp); | |
490 | chmod($icon_file, 0644); | |
491 | } | |
78800912 | 492 | } |
4065b60b AD |
493 | |
494 | error_reporting(DEFAULT_ERROR_LEVEL); | |
495 | ||
78800912 AD |
496 | } |
497 | ||
ddb68b81 | 498 | function update_rss_feed($link, $feed_url, $feed, $ignore_daemon = false) { |
40d13c28 | 499 | |
17c0eeba | 500 | if (!$_GET["daemon"] && !$ignore_daemon) { |
45004d43 | 501 | return false; |
21cfcdf2 AD |
502 | } |
503 | ||
4bc64807 | 504 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 505 | _debug("update_rss_feed: start"); |
219bd8fc AD |
506 | } |
507 | ||
39a52499 AD |
508 | if (!$ignore_daemon) { |
509 | ||
510 | if (DB_TYPE == "pgsql") { | |
511 | $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; | |
512 | } else { | |
513 | $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; | |
514 | } | |
515 | ||
516 | $result = db_query($link, "SELECT id,update_interval,auth_login, | |
16211ddb | 517 | auth_pass,cache_images,update_method |
39a52499 | 518 | FROM ttrss_feeds WHERE id = '$feed' AND $updstart_thresh_qpart"); |
02008cb1 | 519 | |
39a52499 AD |
520 | } else { |
521 | ||
522 | $result = db_query($link, "SELECT id,update_interval,auth_login, | |
50b2db96 | 523 | auth_pass,cache_images,update_method,hidden,last_updated |
39a52499 AD |
524 | FROM ttrss_feeds WHERE id = '$feed'"); |
525 | ||
526 | } | |
a88c1f36 | 527 | |
5370d37f AD |
528 | if (db_num_rows($result) == 0) { |
529 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
02008cb1 | 530 | _debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND/SKIPPED"); |
5370d37f | 531 | } |
45004d43 | 532 | return false; |
5370d37f AD |
533 | } |
534 | ||
ddc34b9b | 535 | $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden")); |
16211ddb | 536 | $update_method = db_fetch_result($result, 0, "update_method"); |
50b2db96 | 537 | $last_updated = db_fetch_result($result, 0, "last_updated"); |
16211ddb | 538 | |
3c50da83 AD |
539 | db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW() |
540 | WHERE id = '$feed'"); | |
541 | ||
464bd61e AD |
542 | $auth_login = db_fetch_result($result, 0, "auth_login"); |
543 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
544 | ||
34459667 AD |
545 | if (ALLOW_SELECT_UPDATE_METHOD) { |
546 | if (ENABLE_SIMPLEPIE) { | |
547 | $use_simplepie = $update_method != 1; | |
548 | } else { | |
549 | $use_simplepie = $update_method == 2; | |
550 | } | |
16211ddb | 551 | } else { |
34459667 | 552 | $use_simplepie = ENABLE_SIMPLEPIE; |
16211ddb AD |
553 | } |
554 | ||
555 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
556 | _debug("use simplepie: $use_simplepie (feed setting: $update_method)\n"); | |
557 | } | |
558 | ||
559 | if (!$use_simplepie) { | |
464bd61e AD |
560 | $auth_login = urlencode($auth_login); |
561 | $auth_pass = urlencode($auth_pass); | |
562 | } | |
47c6c988 | 563 | |
a88c1f36 | 564 | $update_interval = db_fetch_result($result, 0, "update_interval"); |
bc0f0785 | 565 | $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); |
a88c1f36 AD |
566 | |
567 | if ($update_interval < 0) { return; } | |
568 | ||
ab3d0b99 AD |
569 | $feed = db_escape_string($feed); |
570 | ||
47c6c988 AD |
571 | $fetch_url = $feed_url; |
572 | ||
573 | if ($auth_login && $auth_pass) { | |
574 | $url_parts = array(); | |
575 | preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts); | |
576 | ||
577 | if ($url_parts[1] && $url_parts[2]) { | |
578 | $fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2]; | |
579 | } | |
580 | ||
581 | } | |
ab3d0b99 | 582 | |
4bc64807 | 583 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
ca872b9d | 584 | _debug("update_rss_feed: fetching [$fetch_url]..."); |
219bd8fc AD |
585 | } |
586 | ||
9fdf7824 | 587 | if (!defined('DAEMON_EXTENDED_DEBUG') && !$_GET['xdebug']) { |
219bd8fc AD |
588 | error_reporting(0); |
589 | } | |
590 | ||
16211ddb | 591 | if (!$use_simplepie) { |
9fdf7824 AD |
592 | $rss = fetch_rss($fetch_url); |
593 | } else { | |
c7d57b66 AD |
594 | if (!is_dir(SIMPLEPIE_CACHE_DIR)) { |
595 | mkdir(SIMPLEPIE_CACHE_DIR); | |
596 | } | |
597 | ||
ca872b9d AD |
598 | $rss = new SimplePie(); |
599 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
16211ddb | 600 | # $rss->set_timeout(10); |
ca872b9d AD |
601 | $rss->set_feed_url($fetch_url); |
602 | $rss->set_output_encoding('UTF-8'); | |
c7d57b66 | 603 | |
bc0f0785 AD |
604 | if (SIMPLEPIE_CACHE_IMAGES && $cache_images) { |
605 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
606 | _debug("enabling image cache"); | |
607 | } | |
608 | ||
dab52d7b | 609 | $rss->set_image_handler('./image.php', 'i'); |
bc0f0785 | 610 | } |
dab52d7b | 611 | |
c7d57b66 AD |
612 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
613 | _debug("feed update interval (sec): " . | |
614 | get_feed_update_interval($link, $feed)*60); | |
615 | } | |
616 | ||
617 | if (is_dir(SIMPLEPIE_CACHE_DIR)) { | |
618 | $rss->set_cache_location(SIMPLEPIE_CACHE_DIR); | |
619 | $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60); | |
620 | } | |
621 | ||
9fdf7824 | 622 | $rss->init(); |
9fdf7824 AD |
623 | } |
624 | ||
625 | // print_r($rss); | |
219bd8fc | 626 | |
4bc64807 | 627 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 628 | _debug("update_rss_feed: fetch done, parsing..."); |
219bd8fc AD |
629 | } else { |
630 | error_reporting (DEFAULT_ERROR_LEVEL); | |
631 | } | |
632 | ||
b6eefba5 | 633 | $feed = db_escape_string($feed); |
dcee8f61 | 634 | |
16211ddb | 635 | if ($use_simplepie) { |
ca872b9d AD |
636 | $fetch_ok = !$rss->error(); |
637 | } else { | |
638 | $fetch_ok = !!$rss; | |
639 | } | |
640 | ||
641 | if ($fetch_ok) { | |
50b62214 | 642 | |
4bc64807 | 643 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
644 | _debug("update_rss_feed: processing feed data..."); |
645 | } | |
646 | ||
44e241cb | 647 | // db_query($link, "BEGIN"); |
dd8c76a9 | 648 | |
a88c1f36 | 649 | $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid |
f324892e | 650 | FROM ttrss_feeds WHERE id = '$feed'"); |
331900c6 | 651 | |
b6eefba5 AD |
652 | $registered_title = db_fetch_result($result, 0, "title"); |
653 | $orig_icon_url = db_fetch_result($result, 0, "icon_url"); | |
f324892e | 654 | $orig_site_url = db_fetch_result($result, 0, "site_url"); |
331900c6 | 655 | |
7fed1940 AD |
656 | $owner_uid = db_fetch_result($result, 0, "owner_uid"); |
657 | ||
16211ddb | 658 | if ($use_simplepie) { |
9fdf7824 AD |
659 | $site_url = $rss->get_link(); |
660 | } else { | |
661 | $site_url = $rss->channel["link"]; | |
662 | } | |
663 | ||
8d0ec6fd | 664 | if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) { |
4bc64807 | 665 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
666 | _debug("update_rss_feed: checking favicon..."); |
667 | } | |
9fdf7824 AD |
668 | |
669 | check_feed_favicon($site_url, $feed, $link); | |
a2770077 AD |
670 | } |
671 | ||
746b249f | 672 | if (!$registered_title || $registered_title == "[Unknown]") { |
4bc64807 | 673 | |
16211ddb | 674 | if ($use_simplepie) { |
c2f8aac4 | 675 | $feed_title = db_escape_string($rss->get_title()); |
fb486a33 AD |
676 | } else { |
677 | $feed_title = db_escape_string($rss->channel["title"]); | |
678 | } | |
4bc64807 AD |
679 | |
680 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
681 | _debug("update_rss_feed: registering title: $feed_title"); | |
682 | } | |
7c5a308d | 683 | |
f324892e AD |
684 | db_query($link, "UPDATE ttrss_feeds SET |
685 | title = '$feed_title' WHERE id = '$feed'"); | |
686 | } | |
687 | ||
49f9c923 | 688 | // weird, weird Magpie |
16211ddb | 689 | if (!$use_simplepie) { |
9fdf7824 AD |
690 | if (!$site_url) $site_url = db_escape_string($rss->channel["link_"]); |
691 | } | |
147f7691 AD |
692 | |
693 | if ($site_url && $orig_site_url != db_escape_string($site_url)) { | |
f324892e AD |
694 | db_query($link, "UPDATE ttrss_feeds SET |
695 | site_url = '$site_url' WHERE id = '$feed'"); | |
331900c6 | 696 | } |
40d13c28 | 697 | |
b7f4bda2 AD |
698 | // print "I: " . $rss->channel["image"]["url"]; |
699 | ||
16211ddb | 700 | if (!$use_simplepie) { |
9fdf7824 AD |
701 | $icon_url = $rss->image["url"]; |
702 | } else { | |
703 | $icon_url = $rss->get_image_url(); | |
704 | } | |
b7f4bda2 | 705 | |
147f7691 | 706 | if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) { |
b6eefba5 AD |
707 | $icon_url = db_escape_string($icon_url); |
708 | db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); | |
b7f4bda2 AD |
709 | } |
710 | ||
51e456d6 | 711 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
712 | _debug("update_rss_feed: loading filters..."); |
713 | } | |
e6155a06 | 714 | |
5daa24f2 | 715 | $filters = load_filters($link, $feed, $owner_uid); |
e6155a06 | 716 | |
16211ddb | 717 | if ($use_simplepie) { |
9fdf7824 AD |
718 | $iterator = $rss->get_items(); |
719 | } else { | |
720 | $iterator = $rss->items; | |
721 | if (!$iterator || !is_array($iterator)) $iterator = $rss->entries; | |
722 | if (!$iterator || !is_array($iterator)) $iterator = $rss; | |
723 | } | |
c22789da AD |
724 | |
725 | if (!is_array($iterator)) { | |
39541e74 | 726 | /* db_query($link, "UPDATE ttrss_feeds |
75bd0669 | 727 | SET last_error = 'Parse error: can\'t find any articles.' |
77f0a2a7 AD |
728 | WHERE id = '$feed'"); */ |
729 | ||
730 | // clear any errors and mark feed as updated if fetched okay | |
731 | // even if it's blank | |
732 | ||
51e456d6 | 733 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
844012bc AD |
734 | _debug("update_rss_feed: entry iterator is not an array, no articles?"); |
735 | } | |
736 | ||
77f0a2a7 AD |
737 | db_query($link, "UPDATE ttrss_feeds |
738 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
739 | ||
740 | return; // no articles | |
c22789da | 741 | } |
ddb68b81 | 742 | |
51e456d6 | 743 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
50b62214 AD |
744 | _debug("update_rss_feed: processing articles..."); |
745 | } | |
746 | ||
ddb68b81 | 747 | foreach ($iterator as $item) { |
7c5a308d | 748 | |
40ce98f4 AD |
749 | if ($_GET['xdebug']) { |
750 | print_r($item); | |
ea322415 | 751 | |
40ce98f4 | 752 | } |
71bd29f6 | 753 | |
16211ddb | 754 | if ($use_simplepie) { |
9fdf7824 AD |
755 | $entry_guid = $item->get_id(); |
756 | if (!$entry_guid) $entry_guid = $item->get_link(); | |
757 | if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title()); | |
758 | ||
759 | } else { | |
760 | ||
761 | $entry_guid = $item["id"]; | |
34e420fb | 762 | |
9fdf7824 AD |
763 | if (!$entry_guid) $entry_guid = $item["guid"]; |
764 | if (!$entry_guid) $entry_guid = $item["link"]; | |
765 | if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); | |
766 | } | |
be832a1a | 767 | |
9fdf7824 | 768 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
769 | _debug("update_rss_feed: guid $entry_guid"); |
770 | } | |
771 | ||
be832a1a AD |
772 | if (!$entry_guid) continue; |
773 | ||
774 | $entry_timestamp = ""; | |
775 | ||
16211ddb | 776 | if ($use_simplepie) { |
9fdf7824 AD |
777 | $entry_timestamp = strtotime($item->get_date()); |
778 | } else { | |
779 | $rss_2_date = $item['pubdate']; | |
780 | $rss_1_date = $item['dc']['date']; | |
781 | $atom_date = $item['issued']; | |
782 | if (!$atom_date) $atom_date = $item['updated']; | |
be832a1a | 783 | |
9fdf7824 AD |
784 | if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date); |
785 | if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date); | |
786 | if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); | |
787 | } | |
9bb36aa0 | 788 | |
2e930846 | 789 | if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { |
be832a1a AD |
790 | $entry_timestamp = time(); |
791 | $no_orig_date = 'true'; | |
792 | } else { | |
793 | $no_orig_date = 'false'; | |
794 | } | |
795 | ||
796 | $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
797 | ||
44d0e774 AD |
798 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
799 | _debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]"); | |
800 | } | |
801 | ||
16211ddb | 802 | if ($use_simplepie) { |
9fdf7824 AD |
803 | $entry_title = $item->get_title(); |
804 | } else { | |
805 | $entry_title = trim(strip_tags($item["title"])); | |
806 | } | |
be832a1a | 807 | |
16211ddb | 808 | if ($use_simplepie) { |
9fdf7824 AD |
809 | $entry_link = $item->get_link(); |
810 | } else { | |
811 | // strange Magpie workaround | |
812 | $entry_link = $item["link_"]; | |
813 | if (!$entry_link) $entry_link = $item["link"]; | |
814 | } | |
be832a1a | 815 | |
9bb36aa0 AD |
816 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
817 | _debug("update_rss_feed: title $entry_title"); | |
818 | } | |
819 | ||
820 | if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);; | |
7d3ab0dd | 821 | |
be832a1a | 822 | $entry_link = strip_tags($entry_link); |
7d3ab0dd | 823 | |
16211ddb | 824 | if ($use_simplepie) { |
4af7a36a AD |
825 | $entry_content = $item->get_content(); |
826 | if (!$entry_content) $entry_content = $item->get_description(); | |
9fdf7824 AD |
827 | } else { |
828 | $entry_content = $item["content:escaped"]; | |
829 | ||
830 | if (!$entry_content) $entry_content = $item["content:encoded"]; | |
e91ab107 | 831 | if (!$entry_content) $entry_content = $item["content"]["encoded"]; |
9fdf7824 | 832 | if (!$entry_content) $entry_content = $item["content"]; |
ea322415 AD |
833 | |
834 | // Magpie bugs are getting ridiculous | |
835 | if (trim($entry_content) == "Array") $entry_content = false; | |
836 | ||
9fdf7824 AD |
837 | if (!$entry_content) $entry_content = $item["atom_content"]; |
838 | if (!$entry_content) $entry_content = $item["summary"]; | |
e91ab107 AD |
839 | |
840 | if (!$entry_content || | |
841 | strlen($entry_content) < strlen($item["description"])) { | |
842 | $entry_content = $item["description"]; | |
843 | }; | |
9fdf7824 AD |
844 | |
845 | // WTF | |
846 | if (is_array($entry_content)) { | |
847 | $entry_content = $entry_content["encoded"]; | |
848 | if (!$entry_content) $entry_content = $entry_content["escaped"]; | |
ea322415 | 849 | } |
be832a1a AD |
850 | } |
851 | ||
ea322415 AD |
852 | if ($_GET["xdebug"]) { |
853 | print "update_rss_feed: content: "; | |
854 | print_r(htmlspecialchars($entry_content)); | |
855 | } | |
be832a1a AD |
856 | |
857 | $entry_content_unescaped = $entry_content; | |
be832a1a | 858 | |
16211ddb | 859 | if ($use_simplepie) { |
9fdf7824 | 860 | $entry_comments = strip_tags($item->data["comments"]); |
30cf38dd | 861 | if ($item->get_author()) { |
e1d600f0 | 862 | $entry_author_item = $item->get_author(); |
a0c6eafb AD |
863 | $entry_author = $entry_author_item->get_name(); |
864 | if (!$entry_author) $entry_author = $entry_author_item->get_email(); | |
d1ee9106 AD |
865 | |
866 | $entry_author = db_escape_string($entry_author); | |
30cf38dd | 867 | } |
9fdf7824 AD |
868 | } else { |
869 | $entry_comments = strip_tags($item["comments"]); | |
870 | ||
871 | $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); | |
4d6e9157 | 872 | |
9fdf7824 AD |
873 | if ($item['author']) { |
874 | ||
875 | if (is_array($item['author'])) { | |
876 | ||
877 | if (!$entry_author) { | |
878 | $entry_author = db_escape_string(strip_tags($item['author']['name'])); | |
879 | } | |
880 | ||
881 | if (!$entry_author) { | |
882 | $entry_author = db_escape_string(strip_tags($item['author']['email'])); | |
883 | } | |
4d6e9157 | 884 | } |
9fdf7824 | 885 | |
4d6e9157 | 886 | if (!$entry_author) { |
9fdf7824 | 887 | $entry_author = db_escape_string(strip_tags($item['author'])); |
4d6e9157 | 888 | } |
83f114c8 | 889 | } |
be832a1a AD |
890 | } |
891 | ||
83f114c8 AD |
892 | if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; |
893 | ||
be832a1a | 894 | $entry_guid = db_escape_string(strip_tags($entry_guid)); |
2ad9ee56 | 895 | $entry_guid = mb_substr($entry_guid, 0, 250); |
be832a1a AD |
896 | |
897 | $result = db_query($link, "SELECT id FROM ttrss_entries | |
898 | WHERE guid = '$entry_guid'"); | |
899 | ||
900 | $entry_content = db_escape_string($entry_content); | |
7e43ad58 AD |
901 | |
902 | $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); | |
903 | ||
be832a1a AD |
904 | $entry_title = db_escape_string($entry_title); |
905 | $entry_link = db_escape_string($entry_link); | |
2544f36b AD |
906 | $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); |
907 | $entry_author = mb_substr($entry_author, 0, 250); | |
be832a1a | 908 | |
16211ddb | 909 | if ($use_simplepie) { |
9fdf7824 AD |
910 | $num_comments = 0; #FIXME# |
911 | } else { | |
912 | $num_comments = db_escape_string($item["slash"]["comments"]); | |
913 | } | |
be832a1a AD |
914 | |
915 | if (!$num_comments) $num_comments = 0; | |
916 | ||
fefef828 | 917 | // parse <category> entries into tags |
be832a1a | 918 | |
16211ddb | 919 | if ($use_simplepie) { |
be832a1a | 920 | |
fefef828 | 921 | $additional_tags = array(); |
9fdf7824 | 922 | $additional_tags_src = $item->get_categories(); |
3b9e5af4 | 923 | |
a702e931 AD |
924 | if (is_array($additional_tags_src)) { |
925 | foreach ($additional_tags_src as $tobj) { | |
926 | array_push($additional_tags, $tobj->get_term()); | |
927 | } | |
fefef828 | 928 | } |
fefef828 | 929 | |
6af621c7 AD |
930 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
931 | _debug("update_rss_feed: category tags:"); | |
932 | print_r($additional_tags); | |
933 | } | |
934 | ||
9fdf7824 | 935 | } else { |
fefef828 | 936 | |
9fdf7824 | 937 | $t_ctr = $item['category#']; |
fefef828 | 938 | |
9fdf7824 AD |
939 | $additional_tags = false; |
940 | ||
941 | if ($t_ctr == 0) { | |
942 | $additional_tags = false; | |
71bd29f6 | 943 | } else if ($t_ctr > 0) { |
9fdf7824 | 944 | $additional_tags = array($item['category']); |
71bd29f6 AD |
945 | |
946 | if ($item['category@term']) { | |
947 | array_push($additional_tags, $item['category@term']); | |
948 | } | |
949 | ||
9fdf7824 AD |
950 | for ($i = 0; $i <= $t_ctr; $i++ ) { |
951 | if ($item["category#$i"]) { | |
952 | array_push($additional_tags, $item["category#$i"]); | |
953 | } | |
71bd29f6 AD |
954 | |
955 | if ($item["category#$i@term"]) { | |
956 | array_push($additional_tags, $item["category#$i@term"]); | |
957 | } | |
9fdf7824 AD |
958 | } |
959 | } | |
960 | ||
961 | // parse <dc:subject> elements | |
962 | ||
963 | $t_ctr = $item['dc']['subject#']; | |
964 | ||
71bd29f6 | 965 | if ($t_ctr > 0) { |
9fdf7824 | 966 | $additional_tags = array($item['dc']['subject']); |
71bd29f6 | 967 | |
9fdf7824 AD |
968 | for ($i = 0; $i <= $t_ctr; $i++ ) { |
969 | if ($item['dc']["subject#$i"]) { | |
970 | array_push($additional_tags, $item['dc']["subject#$i"]); | |
971 | } | |
fefef828 AD |
972 | } |
973 | } | |
974 | } | |
8add756a | 975 | |
ce53e200 AD |
976 | // enclosures |
977 | ||
978 | $enclosures = array(); | |
979 | ||
16211ddb | 980 | if ($use_simplepie) { |
ce53e200 AD |
981 | $encs = $item->get_enclosures(); |
982 | ||
3b9e5af4 AD |
983 | if (is_array($encs)) { |
984 | foreach ($encs as $e) { | |
985 | $e_item = array( | |
986 | $e->link, $e->type, $e->length); | |
987 | ||
988 | array_push($enclosures, $e_item); | |
989 | } | |
ce53e200 AD |
990 | } |
991 | ||
992 | } else { | |
e91ab107 AD |
993 | // <enclosure> |
994 | ||
ce53e200 AD |
995 | $e_ctr = $item['enclosure#']; |
996 | ||
997 | if ($e_ctr > 0) { | |
998 | $e_item = array($item['enclosure@url'], | |
999 | $item['enclosure@type'], | |
1000 | $item['enclosure@length']); | |
1001 | ||
1002 | array_push($enclosures, $e_item); | |
1003 | ||
71bd29f6 AD |
1004 | for ($i = 0; $i <= $e_ctr; $i++ ) { |
1005 | ||
1006 | if ($item["enclosure#$i@url"]) { | |
1007 | $e_item = array($item["enclosure#$i@url"], | |
1008 | $item["enclosure#$i@type"], | |
1009 | $item["enclosure#$i@length"]); | |
1010 | array_push($enclosures, $e_item); | |
1011 | } | |
ce53e200 AD |
1012 | } |
1013 | } | |
1014 | ||
e91ab107 | 1015 | // <media:content> |
b652fdae | 1016 | // can there be many of those? yes -fox |
e91ab107 AD |
1017 | |
1018 | $m_ctr = $item['media']['content#']; | |
1019 | ||
1020 | if ($m_ctr > 0) { | |
1021 | $e_item = array($item['media']['content@url'], | |
1022 | $item['media']['content@medium'], | |
1023 | $item['media']['content@length']); | |
1024 | ||
1025 | array_push($enclosures, $e_item); | |
e91ab107 | 1026 | |
b652fdae AD |
1027 | for ($i = 0; $i <= $m_ctr; $i++ ) { |
1028 | ||
1029 | if ($item["media"]["content#$i@url"]) { | |
1030 | $e_item = array($item["media"]["content#$i@url"], | |
1031 | $item["media"]["content#$i@medium"], | |
1032 | $item["media"]["content#$i@length"]); | |
1033 | array_push($enclosures, $e_item); | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | } | |
ce53e200 AD |
1038 | } |
1039 | ||
d48d160c | 1040 | # sanitize content |
183ad07b | 1041 | |
621ffb00 AD |
1042 | $entry_content = sanitize_article_content($entry_content); |
1043 | $entry_title = sanitize_article_content($entry_title); | |
d48d160c | 1044 | |
9fdf7824 | 1045 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1046 | _debug("update_rss_feed: done collecting data [TITLE:$entry_title]"); |
1047 | } | |
1048 | ||
44e241cb AD |
1049 | db_query($link, "BEGIN"); |
1050 | ||
4c193675 AD |
1051 | if (db_num_rows($result) == 0) { |
1052 | ||
9fdf7824 | 1053 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1054 | _debug("update_rss_feed: base guid not found"); |
1055 | } | |
1056 | ||
4c193675 AD |
1057 | // base post entry does not exist, create it |
1058 | ||
4c193675 AD |
1059 | $result = db_query($link, |
1060 | "INSERT INTO ttrss_entries | |
1061 | (title, | |
1062 | guid, | |
1063 | link, | |
1064 | updated, | |
1065 | content, | |
1066 | content_hash, | |
1067 | no_orig_date, | |
1068 | date_entered, | |
11b0dce2 | 1069 | comments, |
b6104dee AD |
1070 | num_comments, |
1071 | author) | |
4c193675 AD |
1072 | VALUES |
1073 | ('$entry_title', | |
1074 | '$entry_guid', | |
1075 | '$entry_link', | |
1076 | '$entry_timestamp_fmt', | |
1077 | '$entry_content', | |
1078 | '$content_hash', | |
1079 | $no_orig_date, | |
1080 | NOW(), | |
11b0dce2 | 1081 | '$entry_comments', |
b6104dee AD |
1082 | '$num_comments', |
1083 | '$entry_author')"); | |
8926aab8 AD |
1084 | } else { |
1085 | // we keep encountering the entry in feeds, so we need to | |
1086 | // update date_entered column so that we don't get horrible | |
1087 | // dupes when the entry gets purged and reinserted again e.g. | |
1088 | // in the case of SLOW SLOW OMG SLOW updating feeds | |
1089 | ||
1090 | $base_entry_id = db_fetch_result($result, 0, "id"); | |
1091 | ||
1092 | db_query($link, "UPDATE ttrss_entries SET date_entered = NOW() | |
1093 | WHERE id = '$base_entry_id'"); | |
4c193675 AD |
1094 | } |
1095 | ||
1096 | // now it should exist, if not - bad luck then | |
1097 | ||
6385315d AD |
1098 | $result = db_query($link, "SELECT |
1099 | id,content_hash,no_orig_date,title, | |
2ac6b765 AD |
1100 | ".SUBSTRING_FOR_DATE."(date_entered,1,19) as date_entered, |
1101 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated, | |
11b0dce2 | 1102 | num_comments |
6385315d AD |
1103 | FROM |
1104 | ttrss_entries | |
1105 | WHERE guid = '$entry_guid'"); | |
4c193675 | 1106 | |
ce53e200 AD |
1107 | $entry_ref_id = 0; |
1108 | $entry_int_id = 0; | |
1109 | ||
4c193675 AD |
1110 | if (db_num_rows($result) == 1) { |
1111 | ||
9fdf7824 | 1112 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 | 1113 | _debug("update_rss_feed: base guid found, checking for user record"); |
34e420fb AD |
1114 | } |
1115 | ||
11b0dce2 AD |
1116 | // this will be used below in update handler |
1117 | $orig_content_hash = db_fetch_result($result, 0, "content_hash"); | |
1118 | $orig_title = db_fetch_result($result, 0, "title"); | |
1119 | $orig_num_comments = db_fetch_result($result, 0, "num_comments"); | |
8926aab8 AD |
1120 | $orig_date_entered = strtotime(db_fetch_result($result, |
1121 | 0, "date_entered")); | |
6385315d | 1122 | |
11b0dce2 | 1123 | $ref_id = db_fetch_result($result, 0, "id"); |
ce53e200 | 1124 | $entry_ref_id = $ref_id; |
4c193675 | 1125 | |
11b0dce2 | 1126 | // check for user post link to main table |
4c193675 | 1127 | |
11b0dce2 | 1128 | // do we allow duplicate posts with same GUID in different feeds? |
8d0ec6fd | 1129 | if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { |
11b0dce2 AD |
1130 | $dupcheck_qpart = "AND feed_id = '$feed'"; |
1131 | } else { | |
1132 | $dupcheck_qpart = ""; | |
1133 | } | |
71604ca4 | 1134 | |
11b0dce2 | 1135 | // error_reporting(0); |
19c9cb11 | 1136 | |
f8382011 | 1137 | $article_filters = get_article_filters($filters, $entry_title, |
44d0e774 | 1138 | $entry_content, $entry_link, $entry_timestamp); |
19c9cb11 | 1139 | |
9fdf7824 | 1140 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
1141 | _debug("update_rss_feed: article filters: "); |
1142 | if (count($article_filters) != 0) { | |
1143 | print_r($article_filters); | |
1144 | } | |
1145 | } | |
1146 | ||
f8382011 | 1147 | if (find_article_filter($article_filters, "filter")) { |
ee4a9812 | 1148 | db_query($link, "COMMIT"); // close transaction in progress |
11b0dce2 AD |
1149 | continue; |
1150 | } | |
19c9cb11 | 1151 | |
11b0dce2 | 1152 | // error_reporting (DEFAULT_ERROR_LEVEL); |
3a933f22 | 1153 | |
ff6e357a AD |
1154 | $score = calculate_article_score($article_filters); |
1155 | ||
1156 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1157 | _debug("update_rss_feed: initial score: $score"); | |
1158 | } | |
1159 | ||
11b0dce2 | 1160 | $result = db_query($link, |
ce53e200 | 1161 | "SELECT ref_id, int_id FROM ttrss_user_entries WHERE |
11b0dce2 AD |
1162 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' |
1163 | $dupcheck_qpart"); | |
7ca91eb3 | 1164 | |
11b0dce2 AD |
1165 | // okay it doesn't exist - create user entry |
1166 | if (db_num_rows($result) == 0) { | |
1167 | ||
9fdf7824 | 1168 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
7ca91eb3 AD |
1169 | _debug("update_rss_feed: user record not found, creating..."); |
1170 | } | |
1171 | ||
24605713 | 1172 | if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) { |
11b0dce2 AD |
1173 | $unread = 'true'; |
1174 | $last_read_qpart = 'NULL'; | |
1175 | } else { | |
1176 | $unread = 'false'; | |
1177 | $last_read_qpart = 'NOW()'; | |
1178 | } | |
dd7d3187 | 1179 | |
32d59314 | 1180 | if (find_article_filter($article_filters, 'mark') || $score > 1000) { |
dd7d3187 AD |
1181 | $marked = 'true'; |
1182 | } else { | |
1183 | $marked = 'false'; | |
1184 | } | |
a36c0dfe AD |
1185 | |
1186 | if (find_article_filter($article_filters, 'publish')) { | |
1187 | $published = 'true'; | |
1188 | } else { | |
1189 | $published = 'false'; | |
1190 | } | |
1191 | ||
11b0dce2 AD |
1192 | $result = db_query($link, |
1193 | "INSERT INTO ttrss_user_entries | |
ff6e357a AD |
1194 | (ref_id, owner_uid, feed_id, unread, last_read, marked, |
1195 | published, score) | |
11b0dce2 | 1196 | VALUES ('$ref_id', '$owner_uid', '$feed', $unread, |
ff6e357a | 1197 | $last_read_qpart, $marked, $published, '$score')"); |
ce53e200 AD |
1198 | |
1199 | $result = db_query($link, | |
1200 | "SELECT int_id FROM ttrss_user_entries WHERE | |
1201 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND | |
1202 | feed_id = '$feed' LIMIT 1"); | |
1203 | ||
1204 | if (db_num_rows($result) == 1) { | |
1205 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
1206 | } | |
1207 | } else { | |
1208 | $entry_ref_id = db_fetch_result($result, 0, "ref_id"); | |
1209 | $entry_int_id = db_fetch_result($result, 0, "int_id"); | |
11b0dce2 | 1210 | } |
ce53e200 AD |
1211 | |
1212 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1213 | _debug("update_rss_feed: RID: $entry_ref_id, IID: $entry_int_id"); | |
1214 | } | |
1215 | ||
6385315d AD |
1216 | $post_needs_update = false; |
1217 | ||
8d0ec6fd | 1218 | if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && |
6385315d | 1219 | ($content_hash != $orig_content_hash)) { |
7e43ad58 | 1220 | // print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->"; |
6385315d AD |
1221 | $post_needs_update = true; |
1222 | } | |
1223 | ||
7e43ad58 | 1224 | if (db_escape_string($orig_title) != $entry_title) { |
6385315d AD |
1225 | $post_needs_update = true; |
1226 | } | |
1227 | ||
11b0dce2 AD |
1228 | if ($orig_num_comments != $num_comments) { |
1229 | $post_needs_update = true; | |
1230 | } | |
1231 | ||
6385315d AD |
1232 | // this doesn't seem to be very reliable |
1233 | // | |
1234 | // if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) { | |
1235 | // $post_needs_update = true; | |
1236 | // } | |
1237 | ||
1238 | // if post needs update, update it and mark all user entries | |
1c73bc0c | 1239 | // linking to this post as updated |
6385315d AD |
1240 | if ($post_needs_update) { |
1241 | ||
7ca91eb3 AD |
1242 | if (defined('DAEMON_EXTENDED_DEBUG')) { |
1243 | _debug("update_rss_feed: post $entry_guid needs update..."); | |
1244 | } | |
1245 | ||
6385315d AD |
1246 | // print "<!-- post $orig_title needs update : $post_needs_update -->"; |
1247 | ||
6385315d | 1248 | db_query($link, "UPDATE ttrss_entries |
11b0dce2 | 1249 | SET title = '$entry_title', content = '$entry_content', |
7e43ad58 | 1250 | content_hash = '$content_hash', |
11b0dce2 | 1251 | num_comments = '$num_comments' |
6385315d AD |
1252 | WHERE id = '$ref_id'"); |
1253 | ||
8d0ec6fd | 1254 | if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) { |
4919fb42 AD |
1255 | db_query($link, "UPDATE ttrss_user_entries |
1256 | SET last_read = null, unread = true WHERE ref_id = '$ref_id'"); | |
1257 | } else { | |
1258 | db_query($link, "UPDATE ttrss_user_entries | |
1259 | SET last_read = null WHERE ref_id = '$ref_id' AND unread = false"); | |
1260 | } | |
6385315d AD |
1261 | |
1262 | } | |
4c193675 AD |
1263 | } |
1264 | ||
44e241cb AD |
1265 | db_query($link, "COMMIT"); |
1266 | ||
ceb30ba4 AD |
1267 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1268 | _debug("update_rss_feed: assigning labels..."); | |
1269 | } | |
1270 | ||
1271 | assign_article_to_labels($link, $entry_ref_id, $article_filters, | |
1272 | $owner_uid); | |
1273 | ||
ce53e200 AD |
1274 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1275 | _debug("update_rss_feed: looking for enclosures..."); | |
1276 | } | |
1277 | ||
1278 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1279 | print_r($enclosures); | |
1280 | } | |
1281 | ||
1282 | db_query($link, "BEGIN"); | |
1283 | ||
1284 | foreach ($enclosures as $enc) { | |
1285 | $enc_url = db_escape_string($enc[0]); | |
1286 | $enc_type = db_escape_string($enc[1]); | |
1287 | $enc_dur = db_escape_string($enc[2]); | |
1288 | ||
1289 | $result = db_query($link, "SELECT id FROM ttrss_enclosures | |
1290 | WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'"); | |
1291 | ||
1292 | if (db_num_rows($result) == 0) { | |
1293 | db_query($link, "INSERT INTO ttrss_enclosures | |
1294 | (content_url, content_type, title, duration, post_id) VALUES | |
1295 | ('$enc_url', '$enc_type', '', '$enc_dur', '$entry_ref_id')"); | |
1296 | } | |
1297 | } | |
1298 | ||
1299 | db_query($link, "COMMIT"); | |
1300 | ||
9fdf7824 | 1301 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb AD |
1302 | _debug("update_rss_feed: looking for tags..."); |
1303 | } | |
1304 | ||
eb36b4eb | 1305 | /* taaaags */ |
40e1a95b | 1306 | // <a href="..." rel="tag">Xorg</a>, // |
eb36b4eb | 1307 | |
05732aa0 | 1308 | $entry_tags = null; |
eb36b4eb | 1309 | |
40e1a95b | 1310 | preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\/a>/i", |
ee2c3050 AD |
1311 | $entry_content_unescaped, $entry_tags); |
1312 | ||
fefef828 AD |
1313 | /* print "<p><br/>$entry_title : $entry_content_unescaped<br>"; |
1314 | print_r($entry_tags); | |
1315 | print "<br/></p>"; */ | |
eb36b4eb AD |
1316 | |
1317 | $entry_tags = $entry_tags[1]; | |
1318 | ||
073ca0e6 AD |
1319 | # check for manual tags |
1320 | ||
f8382011 AD |
1321 | $tag_filter = find_article_filter($article_filters, "tag"); |
1322 | ||
1323 | if ($tag_filter) { | |
073ca0e6 | 1324 | |
f8382011 | 1325 | $manual_tags = trim_array(split(",", $tag_filter[1])); |
073ca0e6 | 1326 | |
f8382011 | 1327 | foreach ($manual_tags as $tag) { |
be832a1a AD |
1328 | if (tag_is_valid($tag)) { |
1329 | array_push($entry_tags, $tag); | |
1330 | } | |
1331 | } | |
1332 | } | |
1333 | ||
11c9ea1f AD |
1334 | $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, |
1335 | 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); | |
8fc70781 | 1336 | |
fefef828 AD |
1337 | if ($additional_tags && is_array($additional_tags)) { |
1338 | foreach ($additional_tags as $tag) { | |
156a785d AD |
1339 | if (tag_is_valid($tag) && |
1340 | array_search($tag, $boring_tags) === FALSE) { | |
073ca0e6 AD |
1341 | array_push($entry_tags, $tag); |
1342 | } | |
1343 | } | |
fefef828 AD |
1344 | } |
1345 | ||
fcc95e24 | 1346 | // print "<p>TAGS: "; print_r($entry_tags); print "</p>"; |
073ca0e6 | 1347 | |
9fdf7824 AD |
1348 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
1349 | print_r($entry_tags); | |
1350 | } | |
1351 | ||
eb36b4eb AD |
1352 | if (count($entry_tags) > 0) { |
1353 | ||
44e241cb AD |
1354 | db_query($link, "BEGIN"); |
1355 | ||
fe99ab12 | 1356 | foreach ($entry_tags as $tag) { |
fefef828 | 1357 | |
14b6c54b | 1358 | $tag = sanitize_tag($tag); |
fefef828 | 1359 | $tag = db_escape_string($tag); |
31483fc1 | 1360 | |
ef063748 AD |
1361 | if (!tag_is_valid($tag)) continue; |
1362 | ||
fe99ab12 AD |
1363 | $result = db_query($link, "SELECT id FROM ttrss_tags |
1364 | WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND | |
1365 | owner_uid = '$owner_uid' LIMIT 1"); | |
1366 | ||
1367 | // print db_fetch_result($result, 0, "id"); | |
1368 | ||
1369 | if ($result && db_num_rows($result) == 0) { | |
1370 | ||
fe99ab12 AD |
1371 | db_query($link, "INSERT INTO ttrss_tags |
1372 | (owner_uid,tag_name,post_int_id) | |
1373 | VALUES ('$owner_uid','$tag', '$entry_int_id')"); | |
1374 | } | |
1375 | } | |
ce53e200 | 1376 | |
44e241cb | 1377 | db_query($link, "COMMIT"); |
05732aa0 | 1378 | } |
9fdf7824 AD |
1379 | |
1380 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1381 | _debug("update_rss_feed: article processed"); | |
1382 | } | |
4c193675 | 1383 | } |
40d13c28 | 1384 | |
50b2db96 AD |
1385 | if (!$last_updated) { |
1386 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1387 | _debug("update_rss_feed: new feed, catching it up..."); | |
1388 | } | |
c7e51de1 | 1389 | catchup_feed($link, $feed, false, $owner_uid); |
50b2db96 AD |
1390 | } |
1391 | ||
ddc34b9b AD |
1392 | if (!$hidden) { |
1393 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1394 | _debug("update_rss_feed: updating counters cache..."); | |
1395 | } | |
2627f2d0 | 1396 | |
3907ef71 AD |
1397 | // disabled, purge_feed() does that... |
1398 | //ccache_update($link, $feed, $owner_uid); | |
ddc34b9b | 1399 | } |
2627f2d0 | 1400 | |
0e70ed51 | 1401 | purge_feed($link, $feed, 0); |
3907ef71 | 1402 | |
ab3d0b99 AD |
1403 | db_query($link, "UPDATE ttrss_feeds |
1404 | SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); | |
eb36b4eb | 1405 | |
44e241cb | 1406 | // db_query($link, "COMMIT"); |
dd8c76a9 | 1407 | |
ab3d0b99 | 1408 | } else { |
ca872b9d | 1409 | |
16211ddb | 1410 | if ($use_simplepie) { |
ca872b9d | 1411 | $error_msg = mb_substr($rss->error(), 0, 250); |
9fdf7824 | 1412 | } else { |
ca872b9d | 1413 | $error_msg = mb_substr(magpie_error(), 0, 250); |
9fdf7824 | 1414 | } |
ca872b9d AD |
1415 | |
1416 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { | |
1417 | _debug("update_rss_feed: error fetching feed: $error_msg"); | |
1418 | } | |
1419 | ||
1420 | $error_msg = db_escape_string($error_msg); | |
1421 | ||
ab3d0b99 | 1422 | db_query($link, |
aa5f9f5f AD |
1423 | "UPDATE ttrss_feeds SET last_error = '$error_msg', |
1424 | last_updated = NOW() WHERE id = '$feed'"); | |
40d13c28 AD |
1425 | } |
1426 | ||
16211ddb | 1427 | if ($use_simplepie) { |
ac6ebdb3 AD |
1428 | unset($rss); |
1429 | } | |
1430 | ||
9fdf7824 | 1431 | if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { |
34e420fb | 1432 | _debug("update_rss_feed: done"); |
219bd8fc AD |
1433 | } |
1434 | ||
40d13c28 AD |
1435 | } |
1436 | ||
f175937c | 1437 | function print_select($id, $default, $values, $attributes = "") { |
79f3553b | 1438 | print "<select name=\"$id\" id=\"$id\" $attributes>"; |
a0d53889 AD |
1439 | foreach ($values as $v) { |
1440 | if ($v == $default) | |
1441 | $sel = " selected"; | |
1442 | else | |
1443 | $sel = ""; | |
1444 | ||
1445 | print "<option$sel>$v</option>"; | |
1446 | } | |
1447 | print "</select>"; | |
1448 | } | |
40d13c28 | 1449 | |
79f3553b AD |
1450 | function print_select_hash($id, $default, $values, $attributes = "") { |
1451 | print "<select name=\"$id\" id='$id' $attributes>"; | |
673d54ca AD |
1452 | foreach (array_keys($values) as $v) { |
1453 | if ($v == $default) | |
74d5c8fa | 1454 | $sel = 'selected="selected"'; |
673d54ca AD |
1455 | else |
1456 | $sel = ""; | |
1457 | ||
1458 | print "<option $sel value=\"$v\">".$values[$v]."</option>"; | |
1459 | } | |
1460 | ||
1461 | print "</select>"; | |
1462 | } | |
1463 | ||
44d0e774 | 1464 | function get_article_filters($filters, $title, $content, $link, $timestamp) { |
240054f1 | 1465 | $matches = array(); |
c2d9322b | 1466 | |
240054f1 AD |
1467 | if ($filters["title"]) { |
1468 | foreach ($filters["title"] as $filter) { | |
c2d9322b AD |
1469 | $reg_exp = $filter["reg_exp"]; |
1470 | $inverse = $filter["inverse"]; | |
1471 | if ((!$inverse && preg_match("/$reg_exp/i", $title)) || | |
1472 | ($inverse && !preg_match("/$reg_exp/i", $title))) { | |
1473 | ||
240054f1 AD |
1474 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1475 | } | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | if ($filters["content"]) { | |
1480 | foreach ($filters["content"] as $filter) { | |
c2d9322b AD |
1481 | $reg_exp = $filter["reg_exp"]; |
1482 | $inverse = $filter["inverse"]; | |
1483 | ||
1484 | if ((!$inverse && preg_match("/$reg_exp/i", $content)) || | |
1485 | ($inverse && !preg_match("/$reg_exp/i", $content))) { | |
1486 | ||
240054f1 AD |
1487 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1488 | } | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | if ($filters["both"]) { | |
1493 | foreach ($filters["both"] as $filter) { | |
1494 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1495 | $inverse = $filter["inverse"]; |
1496 | ||
1497 | if ($inverse) { | |
d404ae81 | 1498 | if (!preg_match("/$reg_exp/i", $title) && !preg_match("/$reg_exp/i", $content)) { |
c2d9322b AD |
1499 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1500 | } | |
1501 | } else { | |
1502 | if (preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) { | |
1503 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1504 | } | |
240054f1 AD |
1505 | } |
1506 | } | |
1507 | } | |
1508 | ||
1509 | if ($filters["link"]) { | |
1510 | $reg_exp = $filter["reg_exp"]; | |
1511 | foreach ($filters["link"] as $filter) { | |
1512 | $reg_exp = $filter["reg_exp"]; | |
c2d9322b AD |
1513 | $inverse = $filter["inverse"]; |
1514 | ||
1515 | if ((!$inverse && preg_match("/$reg_exp/i", $link)) || | |
1516 | ($inverse && !preg_match("/$reg_exp/i", $link))) { | |
1517 | ||
240054f1 AD |
1518 | array_push($matches, array($filter["action"], $filter["action_param"])); |
1519 | } | |
1520 | } | |
1521 | } | |
1522 | ||
44d0e774 AD |
1523 | if ($filters["date"]) { |
1524 | $reg_exp = $filter["reg_exp"]; | |
1525 | foreach ($filters["date"] as $filter) { | |
1526 | $date_modifier = $filter["filter_param"]; | |
1527 | $inverse = $filter["inverse"]; | |
1528 | $check_timestamp = strtotime($filter["reg_exp"]); | |
1529 | ||
1530 | # no-op when timestamp doesn't parse to prevent misfires | |
1531 | ||
1532 | if ($check_timestamp) { | |
1533 | $match_ok = false; | |
1534 | ||
1535 | if ($date_modifier == "before" && $timestamp < $check_timestamp || | |
1536 | $date_modifier == "after" && $timestamp > $check_timestamp) { | |
1537 | $match_ok = true; | |
1538 | } | |
1539 | ||
1540 | if ($inverse) $match_ok = !$match_ok; | |
1541 | ||
1542 | if ($match_ok) { | |
1543 | array_push($matches, array($filter["action"], $filter["action_param"])); | |
1544 | } | |
1545 | } | |
1546 | } | |
1547 | } | |
1548 | ||
240054f1 AD |
1549 | return $matches; |
1550 | } | |
1551 | ||
f8382011 AD |
1552 | function find_article_filter($filters, $filter_name) { |
1553 | foreach ($filters as $f) { | |
1554 | if ($f[0] == $filter_name) { | |
1555 | return $f; | |
1556 | }; | |
1557 | } | |
1558 | return false; | |
1559 | } | |
1560 | ||
ff6e357a AD |
1561 | function calculate_article_score($filters) { |
1562 | $score = 0; | |
1563 | ||
1564 | foreach ($filters as $f) { | |
1565 | if ($f[0] == "score") { | |
1566 | $score += $f[1]; | |
1567 | }; | |
1568 | } | |
1569 | return $score; | |
1570 | } | |
1571 | ||
ceb30ba4 AD |
1572 | function assign_article_to_labels($link, $id, $filters, $owner_uid) { |
1573 | foreach ($filters as $f) { | |
1574 | if ($f[0] == "label") { | |
1575 | label_add_article($link, $id, $f[1], $owner_uid); | |
1576 | }; | |
1577 | } | |
1578 | } | |
ff6e357a | 1579 | |
9323147e | 1580 | function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link, |
2eb9c95c AD |
1581 | $rtl_content = false, $last_updated = false, $last_error = false, |
1582 | $fg_content = false, $bg_content = false) { | |
254e0e4b AD |
1583 | |
1584 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
023fe037 | 1585 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">"; |
254e0e4b | 1586 | } else { |
023fe037 | 1587 | $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"images/blank_icon.gif\">"; |
254e0e4b AD |
1588 | } |
1589 | ||
9323147e AD |
1590 | if ($rtl_content) { |
1591 | $rtl_tag = "dir=\"rtl\""; | |
1592 | } else { | |
1593 | $rtl_tag = "dir=\"ltr\""; | |
1594 | } | |
1595 | ||
78d5212c AD |
1596 | $error_notify_msg = ""; |
1597 | ||
fb1fb4ab AD |
1598 | if ($last_error) { |
1599 | $link_title = "Error: $last_error ($last_updated)"; | |
78d5212c | 1600 | $error_notify_msg = "(Error)"; |
ad780e9c | 1601 | } else if ($last_updated) { |
fb1fb4ab AD |
1602 | $link_title = "Updated: $last_updated"; |
1603 | } | |
1604 | ||
7210613a | 1605 | $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\" |
c50e2b30 | 1606 | href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>"; |
254e0e4b | 1607 | |
2eb9c95c AD |
1608 | /* if ($feed_id < -10) { |
1609 | $bg_color = "#00ccff"; | |
1610 | $fg_color = "white"; | |
1611 | } | |
1612 | ||
1613 | if ($fg_color || $bg_color) { | |
1614 | $color_str = "<div class='labelColorIndicator' | |
1615 | style='color : $fg_color; background-color : $bg_color'>l</div>"; | |
1616 | } | |
1617 | ||
1618 | print $color_str; */ | |
1619 | ||
8836613c | 1620 | print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; |
b619ff15 | 1621 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { |
254e0e4b AD |
1622 | print "$feed_icon"; |
1623 | } | |
1624 | ||
9323147e | 1625 | print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>"; |
254e0e4b AD |
1626 | |
1627 | if ($unread != 0) { | |
d7e83df7 | 1628 | $fctr_class = "class=\"feedCtrHasUnread\""; |
254e0e4b | 1629 | } else { |
d7e83df7 | 1630 | $fctr_class = "class=\"feedCtrNoUnread\""; |
254e0e4b AD |
1631 | } |
1632 | ||
9323147e | 1633 | print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\"> |
254e0e4b | 1634 | (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>"; |
78d5212c AD |
1635 | |
1636 | if (get_pref($link, "EXTENDED_FEEDLIST")) { | |
bdb7369b | 1637 | $total = getFeedArticles($link, $feed_id); |
78d5212c | 1638 | print "<div class=\"feedExtInfo\"> |
bdb7369b | 1639 | <span id=\"FLUPD-$feed_id\">$last_updated ($total total) $error_notify_msg</span></div>"; |
78d5212c | 1640 | } |
2eb9c95c | 1641 | |
254e0e4b AD |
1642 | print "</li>"; |
1643 | ||
1644 | } | |
1645 | ||
406d9489 AD |
1646 | function getmicrotime() { |
1647 | list($usec, $sec) = explode(" ",microtime()); | |
1648 | return ((float)$usec + (float)$sec); | |
1649 | } | |
1650 | ||
f541eb78 | 1651 | function print_radio($id, $default, $true_is, $values, $attributes = "") { |
77e96719 AD |
1652 | foreach ($values as $v) { |
1653 | ||
1654 | if ($v == $default) | |
5da169d9 | 1655 | $sel = "checked"; |
77e96719 | 1656 | else |
5da169d9 AD |
1657 | $sel = ""; |
1658 | ||
f541eb78 | 1659 | if ($v == $true_is) { |
5da169d9 AD |
1660 | $sel .= " value=\"1\""; |
1661 | } else { | |
1662 | $sel .= " value=\"0\""; | |
1663 | } | |
77e96719 | 1664 | |
69654950 AD |
1665 | print "<input class=\"noborder\" |
1666 | type=\"radio\" $sel $attributes name=\"$id\"> $v "; | |
77e96719 AD |
1667 | |
1668 | } | |
1669 | } | |
1670 | ||
ff485f1d AD |
1671 | function initialize_user_prefs($link, $uid) { |
1672 | ||
1673 | $uid = db_escape_string($uid); | |
1674 | ||
1675 | db_query($link, "BEGIN"); | |
1676 | ||
1677 | $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); | |
1678 | ||
1679 | $u_result = db_query($link, "SELECT pref_name | |
1680 | FROM ttrss_user_prefs WHERE owner_uid = '$uid'"); | |
1681 | ||
1682 | $active_prefs = array(); | |
1683 | ||
1684 | while ($line = db_fetch_assoc($u_result)) { | |
1685 | array_push($active_prefs, $line["pref_name"]); | |
1686 | } | |
1687 | ||
1688 | while ($line = db_fetch_assoc($result)) { | |
1689 | if (array_search($line["pref_name"], $active_prefs) === FALSE) { | |
1690 | // print "adding " . $line["pref_name"] . "<br>"; | |
1691 | ||
1692 | db_query($link, "INSERT INTO ttrss_user_prefs | |
1693 | (owner_uid,pref_name,value) VALUES | |
1694 | ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); | |
1695 | ||
1696 | } | |
1697 | } | |
1698 | ||
1699 | db_query($link, "COMMIT"); | |
1700 | ||
1701 | } | |
956c7629 AD |
1702 | |
1703 | function lookup_user_id($link, $user) { | |
1704 | ||
1705 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
1706 | login = '$login'"); | |
1707 | ||
1708 | if (db_num_rows($result) == 1) { | |
1709 | return db_fetch_result($result, 0, "id"); | |
1710 | } else { | |
1711 | return false; | |
1712 | } | |
1713 | } | |
1714 | ||
18664970 AD |
1715 | function http_authenticate_user($link) { |
1716 | ||
4bc64807 AD |
1717 | error_log("http_authenticate_user: ".$_SERVER["PHP_AUTH_USER"]."\n", 3, '/tmp/tt-rss.log'); |
1718 | ||
18664970 AD |
1719 | if (!$_SERVER["PHP_AUTH_USER"]) { |
1720 | ||
1721 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1722 | header('HTTP/1.0 401 Unauthorized'); | |
1723 | exit; | |
1724 | ||
1725 | } else { | |
1726 | $auth_result = authenticate_user($link, | |
1727 | $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]); | |
1728 | ||
1729 | if (!$auth_result) { | |
1730 | header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); | |
1731 | header('HTTP/1.0 401 Unauthorized'); | |
1732 | exit; | |
1733 | } | |
1734 | } | |
1735 | ||
1736 | return true; | |
1737 | } | |
1738 | ||
461766f3 | 1739 | function authenticate_user($link, $login, $password, $force_auth = false) { |
c8437f35 | 1740 | |
131b01b3 | 1741 | if (!SINGLE_USER_MODE) { |
c8437f35 | 1742 | |
1a9f4d3c AD |
1743 | $pwd_hash1 = encrypt_password($password); |
1744 | $pwd_hash2 = encrypt_password($password, $login); | |
2d969845 | 1745 | $login = db_escape_string($login); |
461766f3 | 1746 | |
66917e70 | 1747 | if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH |
73f5f114 | 1748 | && $_SERVER["REMOTE_USER"] && $login != "admin") { |
66917e70 AD |
1749 | |
1750 | $login = db_escape_string($_SERVER["REMOTE_USER"]); | |
1751 | ||
73f5f114 | 1752 | $query = "SELECT id,login,access_level,pwd_hash |
461766f3 | 1753 | FROM ttrss_users WHERE |
66917e70 AD |
1754 | login = '$login'"; |
1755 | ||
461766f3 | 1756 | } else { |
1a9f4d3c | 1757 | $query = "SELECT id,login,access_level,pwd_hash |
461766f3 | 1758 | FROM ttrss_users WHERE |
1a9f4d3c AD |
1759 | login = '$login' AND (pwd_hash = '$pwd_hash1' OR |
1760 | pwd_hash = '$pwd_hash2')"; | |
461766f3 AD |
1761 | } |
1762 | ||
1763 | $result = db_query($link, $query); | |
131b01b3 AD |
1764 | |
1765 | if (db_num_rows($result) == 1) { | |
1766 | $_SESSION["uid"] = db_fetch_result($result, 0, "id"); | |
1767 | $_SESSION["name"] = db_fetch_result($result, 0, "login"); | |
1768 | $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level"); | |
1769 | ||
1770 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1771 | $_SESSION["uid"]); | |
1772 | ||
1773 | $user_theme = get_user_theme_path($link); | |
1774 | ||
1775 | $_SESSION["theme"] = $user_theme; | |
1776 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1a9f4d3c | 1777 | $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); |
131b01b3 AD |
1778 | |
1779 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1780 | ||
1781 | return true; | |
1782 | } | |
1783 | ||
1784 | return false; | |
503eb349 | 1785 | |
131b01b3 | 1786 | } else { |
503eb349 | 1787 | |
131b01b3 AD |
1788 | $_SESSION["uid"] = 1; |
1789 | $_SESSION["name"] = "admin"; | |
f557cd78 | 1790 | |
0bbba72d AD |
1791 | $user_theme = get_user_theme_path($link); |
1792 | ||
1793 | $_SESSION["theme"] = $user_theme; | |
1794 | $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; | |
1795 | ||
1796 | initialize_user_prefs($link, $_SESSION["uid"]); | |
1797 | ||
c8437f35 AD |
1798 | return true; |
1799 | } | |
c8437f35 AD |
1800 | } |
1801 | ||
e6cb77a0 AD |
1802 | function make_password($length = 8) { |
1803 | ||
1804 | $password = ""; | |
798f722b AD |
1805 | $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; |
1806 | ||
1807 | $i = 0; | |
e6cb77a0 AD |
1808 | |
1809 | while ($i < $length) { | |
1810 | $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); | |
1811 | ||
1812 | if (!strstr($password, $char)) { | |
1813 | $password .= $char; | |
1814 | $i++; | |
1815 | } | |
1816 | } | |
1817 | return $password; | |
1818 | } | |
1819 | ||
1820 | // this is called after user is created to initialize default feeds, labels | |
1821 | // or whatever else | |
1822 | ||
1823 | // user preferences are checked on every login, not here | |
1824 | ||
1825 | function initialize_user($link, $uid) { | |
1826 | ||
e2549229 | 1827 | /* db_query($link, "INSERT INTO ttrss_labels2 (owner_uid, caption) |
69d47936 AD |
1828 | VALUES ('$uid', 'All Articles')"); |
1829 | ||
1830 | db_query($link, "INSERT INTO ttrss_filters | |
1831 | (owner_uid, feed_id, filter_type, reg_exp, enabled, | |
1832 | action_id, action_param, filter_param) | |
e2549229 | 1833 | VALUES ('$uid', NULL, 1, '.', true, 7, 'All Articles', 'before')"); */ |
69d47936 | 1834 | |
e6cb77a0 | 1835 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) |
74bff337 | 1836 | values ('$uid', 'Tiny Tiny RSS: New Releases', |
b6d486a3 | 1837 | 'http://tt-rss.org/releases.rss')"); |
3b0feb9b | 1838 | |
cd2cd415 AD |
1839 | db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) |
1840 | values ('$uid', 'Tiny Tiny RSS: Forum', | |
b6d486a3 | 1841 | 'http://tt-rss.org/forum/rss.php')"); |
3b0feb9b | 1842 | } |
e6cb77a0 | 1843 | |
b8aa49bc | 1844 | function logout_user() { |
5ccc1cf5 AD |
1845 | session_destroy(); |
1846 | if (isset($_COOKIE[session_name()])) { | |
1847 | setcookie(session_name(), '', time()-42000, '/'); | |
1848 | } | |
b8aa49bc AD |
1849 | } |
1850 | ||
75836f33 | 1851 | function get_script_urlpath() { |
87a79fa4 | 1852 | return preg_replace('/\/[^\/]*$/', "", $_SERVER["REQUEST_URI"]); |
75836f33 AD |
1853 | } |
1854 | ||
916f788a | 1855 | function validate_session($link) { |
741edab2 AD |
1856 | if (SINGLE_USER_MODE) { |
1857 | return true; | |
1858 | } | |
1859 | ||
a2e9b457 | 1860 | if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { |
916f788a AD |
1861 | if ($_SESSION["ip_address"]) { |
1862 | if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { | |
af163b85 | 1863 | $_SESSION["login_error_msg"] = __("Session failed to validate (incorrect IP)"); |
916f788a AD |
1864 | return false; |
1865 | } | |
1866 | } | |
1867 | } | |
d620cfe7 | 1868 | |
e6684130 AD |
1869 | if ($_SESSION["uid"]) { |
1870 | ||
1871 | $result = db_query($link, | |
1872 | "SELECT pwd_hash FROM ttrss_users WHERE id = '".$_SESSION["uid"]."'"); | |
1873 | ||
1874 | $pwd_hash = db_fetch_result($result, 0, "pwd_hash"); | |
1875 | ||
1876 | if ($pwd_hash != $_SESSION["pwd_hash"]) { | |
1877 | return false; | |
1878 | } | |
1879 | } | |
1880 | ||
a885f0ec | 1881 | /* if ($_SESSION["cookie_lifetime"] && $_SESSION["uid"]) { |
d620cfe7 | 1882 | |
8e849206 | 1883 | //print_r($_SESSION); |
d620cfe7 AD |
1884 | |
1885 | if (time() > $_SESSION["cookie_lifetime"]) { | |
1886 | return false; | |
1887 | } | |
a885f0ec AD |
1888 | } */ |
1889 | ||
916f788a AD |
1890 | return true; |
1891 | } | |
1892 | ||
793185a9 | 1893 | function login_sequence($link, $mobile = false) { |
b8aa49bc | 1894 | if (!SINGLE_USER_MODE) { |
75836f33 | 1895 | |
461766f3 AD |
1896 | if (defined('_DEBUG_USER_SWITCH') && $_SESSION["uid"]) { |
1897 | $swu = db_escape_string($_REQUEST["swu"]); | |
1898 | if ($swu) { | |
1899 | $_SESSION["prefs_cache"] = false; | |
1900 | return authenticate_user($link, $swu, null, true); | |
1901 | } | |
1902 | } | |
1903 | ||
7f0acba7 | 1904 | $login_action = $_POST["login_action"]; |
a885f0ec | 1905 | |
01a87dff | 1906 | # try to authenticate user if called from login form |
7f0acba7 | 1907 | if ($login_action == "do_login") { |
01a87dff AD |
1908 | $login = $_POST["login"]; |
1909 | $password = $_POST["password"]; | |
d620cfe7 | 1910 | $remember_me = $_POST["remember_me"]; |
f557cd78 | 1911 | |
01a87dff AD |
1912 | if (authenticate_user($link, $login, $password)) { |
1913 | $_POST["password"] = ""; | |
d620cfe7 | 1914 | |
f8c612d4 | 1915 | $_SESSION["language"] = $_POST["language"]; |
a598370d | 1916 | $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; |
f8c612d4 | 1917 | |
d620cfe7 AD |
1918 | header("Location: " . $_SERVER["REQUEST_URI"]); |
1919 | exit; | |
1920 | ||
01a87dff | 1921 | return; |
7f0acba7 | 1922 | } else { |
af163b85 | 1923 | $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
01a87dff AD |
1924 | } |
1925 | } | |
1926 | ||
7f0acba7 | 1927 | if (!$_SESSION["uid"] || !validate_session($link)) { |
206d4967 AD |
1928 | render_login_form($link, $mobile); |
1929 | //header("Location: login.php"); | |
01a87dff | 1930 | exit; |
d3687e7a AD |
1931 | } else { |
1932 | /* bump login timestamp */ | |
1933 | db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . | |
1934 | $_SESSION["uid"]); | |
019bd5a9 | 1935 | |
d54780bc | 1936 | if ($_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) { |
019bd5a9 AD |
1937 | setcookie("ttrss_lang", $_SESSION["language"], |
1938 | time() + SESSION_COOKIE_LIFETIME); | |
1939 | } | |
4fdb0476 AD |
1940 | |
1941 | /* bump counters stamp since we're getting reloaded anyway */ | |
1942 | ||
1943 | $_SESSION["get_all_counters_stamp"] = time(); | |
b8aa49bc | 1944 | } |
d620cfe7 | 1945 | |
b8aa49bc | 1946 | } else { |
0bbba72d | 1947 | return authenticate_user($link, "admin", null); |
b8aa49bc AD |
1948 | } |
1949 | } | |
3547842a AD |
1950 | |
1951 | function truncate_string($str, $max_len) { | |
12db369c | 1952 | if (mb_strlen($str, "utf-8") > $max_len - 3) { |
66a251f9 | 1953 | return mb_substr($str, 0, $max_len, "utf-8") . "…"; |
3547842a AD |
1954 | } else { |
1955 | return $str; | |
1956 | } | |
1957 | } | |
54a60e1a AD |
1958 | |
1959 | function get_user_theme_path($link) { | |
798f722b AD |
1960 | $result = db_query($link, "SELECT theme_path |
1961 | FROM | |
1962 | ttrss_themes,ttrss_users | |
1963 | WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); | |
54a60e1a AD |
1964 | if (db_num_rows($result) != 0) { |
1965 | return db_fetch_result($result, 0, "theme_path"); | |
1966 | } else { | |
1967 | return null; | |
1968 | } | |
1969 | } | |
be773442 AD |
1970 | |
1971 | function smart_date_time($timestamp) { | |
1972 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1973 | return date("G:i", $timestamp); | |
f26450f1 | 1974 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1975 | return date("M d, G:i", $timestamp); |
1976 | } else { | |
7d7e0509 | 1977 | return date("Y/m/d, G:i", $timestamp); |
be773442 AD |
1978 | } |
1979 | } | |
1980 | ||
1981 | function smart_date($timestamp) { | |
1982 | if (date("Y.m.d", $timestamp) == date("Y.m.d")) { | |
1983 | return "Today"; | |
f26450f1 | 1984 | } else if (date("Y", $timestamp) == date("Y")) { |
be773442 AD |
1985 | return date("D m", $timestamp); |
1986 | } else { | |
b02111c2 | 1987 | return date("Y/m/d", $timestamp); |
be773442 AD |
1988 | } |
1989 | } | |
a654a595 AD |
1990 | |
1991 | function sql_bool_to_string($s) { | |
1992 | if ($s == "t" || $s == "1") { | |
1993 | return "true"; | |
1994 | } else { | |
1995 | return "false"; | |
1996 | } | |
1997 | } | |
e3c99f3b AD |
1998 | |
1999 | function sql_bool_to_bool($s) { | |
2000 | if ($s == "t" || $s == "1") { | |
2001 | return true; | |
2002 | } else { | |
2003 | return false; | |
2004 | } | |
2005 | } | |
0ea4fb50 | 2006 | |
badac687 AD |
2007 | function bool_to_sql_bool($s) { |
2008 | if ($s) { | |
2009 | return "true"; | |
2010 | } else { | |
2011 | return "false"; | |
2012 | } | |
2013 | } | |
e3c99f3b | 2014 | |
0ea4fb50 AD |
2015 | function toggleEvenOdd($a) { |
2016 | if ($a == "even") | |
2017 | return "odd"; | |
2018 | else | |
2019 | return "even"; | |
2020 | } | |
6043fb7e AD |
2021 | |
2022 | function sanity_check($link) { | |
9cbca41f | 2023 | |
aec3ce39 AD |
2024 | error_reporting(0); |
2025 | ||
6043fb7e AD |
2026 | $error_code = 0; |
2027 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
2028 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
2029 | ||
2030 | if ($schema_version != SCHEMA_VERSION) { | |
2031 | $error_code = 5; | |
2032 | } | |
2033 | ||
aec3ce39 AD |
2034 | if (DB_TYPE == "mysql") { |
2035 | $result = db_query($link, "SELECT true", false); | |
2036 | if (db_num_rows($result) != 1) { | |
2037 | $error_code = 10; | |
2038 | } | |
2039 | } | |
2040 | ||
f29ba148 AD |
2041 | if (db_escape_string("testTEST") != "testTEST") { |
2042 | $error_code = 12; | |
2043 | } | |
2044 | ||
aec3ce39 AD |
2045 | error_reporting (DEFAULT_ERROR_LEVEL); |
2046 | ||
6043fb7e | 2047 | if ($error_code != 0) { |
aec3ce39 | 2048 | print_error_xml($error_code); |
6043fb7e AD |
2049 | return false; |
2050 | } else { | |
2051 | return true; | |
4220d6b0 | 2052 | } |
6043fb7e AD |
2053 | } |
2054 | ||
27981ca3 | 2055 | function file_is_locked($filename) { |
31a6d42d AD |
2056 | if (function_exists('flock')) { |
2057 | error_reporting(0); | |
cfa43e02 | 2058 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); |
31a6d42d AD |
2059 | error_reporting(DEFAULT_ERROR_LEVEL); |
2060 | if ($fp) { | |
2061 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
2062 | flock($fp, LOCK_UN); | |
2063 | fclose($fp); | |
2064 | return false; | |
2065 | } | |
27981ca3 | 2066 | fclose($fp); |
31a6d42d | 2067 | return true; |
e89aed7b AD |
2068 | } else { |
2069 | return false; | |
27981ca3 | 2070 | } |
27981ca3 | 2071 | } |
c1fb4a5e | 2072 | return true; // consider the file always locked and skip the test |
27981ca3 AD |
2073 | } |
2074 | ||
fcb4c0c9 | 2075 | function make_lockfile($filename) { |
cfa43e02 | 2076 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
fcb4c0c9 AD |
2077 | |
2078 | if (flock($fp, LOCK_EX | LOCK_NB)) { | |
2079 | return $fp; | |
2080 | } else { | |
2081 | return false; | |
2082 | } | |
2083 | } | |
2084 | ||
bf7fcde8 | 2085 | function make_stampfile($filename) { |
cfa43e02 | 2086 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
bf7fcde8 | 2087 | |
8e00ae9b | 2088 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
bf7fcde8 | 2089 | fwrite($fp, time() . "\n"); |
8e00ae9b | 2090 | flock($fp, LOCK_UN); |
bf7fcde8 AD |
2091 | fclose($fp); |
2092 | return true; | |
2093 | } else { | |
2094 | return false; | |
2095 | } | |
2096 | } | |
2097 | ||
8e00ae9b AD |
2098 | function read_stampfile($filename) { |
2099 | ||
2100 | error_reporting(0); | |
cfa43e02 | 2101 | $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); |
8e00ae9b AD |
2102 | error_reporting (DEFAULT_ERROR_LEVEL); |
2103 | ||
e89aed7b AD |
2104 | if ($fp) { |
2105 | if (flock($fp, LOCK_EX)) { | |
2106 | $stamp = fgets($fp); | |
2107 | flock($fp, LOCK_UN); | |
2108 | fclose($fp); | |
2109 | return $stamp; | |
2110 | } else { | |
2111 | return false; | |
2112 | } | |
8e00ae9b AD |
2113 | } else { |
2114 | return false; | |
2115 | } | |
2116 | } | |
bf7fcde8 | 2117 | |
894ebcf5 AD |
2118 | function sql_random_function() { |
2119 | if (DB_TYPE == "mysql") { | |
2120 | return "RAND()"; | |
2121 | } else { | |
2122 | return "RANDOM()"; | |
2123 | } | |
2124 | } | |
2125 | ||
c7e51de1 AD |
2126 | function catchup_feed($link, $feed, $cat_view, $owner_uid) { |
2127 | ||
2128 | if (!$owner_uid) $owner_uid = $_SESSION['uid']; | |
88040f57 AD |
2129 | |
2130 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
23aa0d16 AD |
2131 | |
2132 | if ($cat_view) { | |
2133 | ||
72a2f4f5 | 2134 | if ($feed >= 0) { |
f9fca8cb AD |
2135 | |
2136 | if ($feed > 0) { | |
2137 | $cat_qpart = "cat_id = '$feed'"; | |
2138 | } else { | |
2139 | $cat_qpart = "cat_id IS NULL"; | |
2140 | } | |
23aa0d16 | 2141 | |
f9fca8cb | 2142 | $tmp_result = db_query($link, "SELECT id |
c7e51de1 | 2143 | FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = $owner_uid"); |
f9fca8cb AD |
2144 | |
2145 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
23aa0d16 | 2146 | |
f9fca8cb | 2147 | $tmp_feed = $tmp_line["id"]; |
23aa0d16 | 2148 | |
f9fca8cb AD |
2149 | db_query($link, "UPDATE ttrss_user_entries |
2150 | SET unread = false,last_read = NOW() | |
c7e51de1 | 2151 | WHERE feed_id = '$tmp_feed' AND owner_uid = $owner_uid"); |
f9fca8cb AD |
2152 | } |
2153 | } else if ($feed == -2) { | |
23aa0d16 | 2154 | |
6f69764c AD |
2155 | |
2156 | db_query($link, "UPDATE ttrss_user_entries | |
2157 | SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) | |
2158 | FROM ttrss_user_labels2 WHERE article_id = ref_id) > 0 | |
c7e51de1 | 2159 | AND unread = true AND owner_uid = $owner_uid"); |
23aa0d16 AD |
2160 | } |
2161 | ||
2162 | } else if ($feed > 0) { | |
2163 | ||
2164 | $tmp_result = db_query($link, "SELECT id | |
2165 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
2166 | ORDER BY cat_id,title"); | |
2167 | ||
2168 | $parent_ids = array(); | |
2169 | ||
2170 | if (db_num_rows($tmp_result) > 0) { | |
2171 | while ($p = db_fetch_assoc($tmp_result)) { | |
2172 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
2173 | } | |
2174 | ||
2175 | $children_qpart = implode(" OR ", $parent_ids); | |
2176 | ||
2177 | db_query($link, "UPDATE ttrss_user_entries | |
2178 | SET unread = false,last_read = NOW() | |
2179 | WHERE (feed_id = '$feed' OR $children_qpart) | |
c7e51de1 | 2180 | AND owner_uid = $owner_uid"); |
23aa0d16 AD |
2181 | |
2182 | } else { | |
2183 | db_query($link, "UPDATE ttrss_user_entries | |
2184 | SET unread = false,last_read = NOW() | |
c7e51de1 | 2185 | WHERE feed_id = '$feed' AND owner_uid = $owner_uid"); |
23aa0d16 AD |
2186 | } |
2187 | ||
2188 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
2189 | ||
2190 | if ($feed == -1) { | |
2191 | db_query($link, "UPDATE ttrss_user_entries | |
2192 | SET unread = false,last_read = NOW() | |
c7e51de1 | 2193 | WHERE marked = true AND owner_uid = $owner_uid"); |
23aa0d16 | 2194 | } |
e4f4b46f AD |
2195 | |
2196 | if ($feed == -2) { | |
2197 | db_query($link, "UPDATE ttrss_user_entries | |
2198 | SET unread = false,last_read = NOW() | |
c7e51de1 | 2199 | WHERE published = true AND owner_uid = $owner_uid"); |
e4f4b46f AD |
2200 | } |
2201 | ||
2d24f032 AD |
2202 | if ($feed == -3) { |
2203 | ||
c1d7e6c3 AD |
2204 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE"); |
2205 | ||
2d24f032 | 2206 | if (DB_TYPE == "pgsql") { |
7608b38a | 2207 | $match_part = "updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2208 | } else { |
7608b38a | 2209 | $match_part = "updated > DATE_SUB(NOW(), |
c1d7e6c3 | 2210 | INTERVAL $intl HOUR) "; |
2d24f032 AD |
2211 | } |
2212 | ||
1f3335dc AD |
2213 | $result = db_query($link, "SELECT id FROM ttrss_entries, |
2214 | ttrss_user_entries WHERE $match_part AND | |
2215 | unread = true AND | |
2216 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
c7e51de1 | 2217 | owner_uid = $owner_uid"); |
1f3335dc AD |
2218 | |
2219 | $affected_ids = array(); | |
2220 | ||
2221 | while ($line = db_fetch_assoc($result)) { | |
2222 | array_push($affected_ids, $line["id"]); | |
2223 | } | |
2224 | ||
2225 | catchupArticlesById($link, $affected_ids, 0); | |
2d24f032 AD |
2226 | } |
2227 | ||
3584cb11 AD |
2228 | if ($feed == -4) { |
2229 | db_query($link, "UPDATE ttrss_user_entries | |
2230 | SET unread = false,last_read = NOW() | |
c7e51de1 | 2231 | WHERE owner_uid = $owner_uid"); |
3584cb11 AD |
2232 | } |
2233 | ||
23aa0d16 AD |
2234 | } else if ($feed < -10) { // label |
2235 | ||
23aa0d16 AD |
2236 | $label_id = -$feed - 11; |
2237 | ||
933ba4ee | 2238 | db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2 |
338c238d AD |
2239 | SET unread = false, last_read = NOW() |
2240 | WHERE label_id = '$label_id' AND unread = true | |
c7e51de1 | 2241 | AND owner_uid = '$owner_uid' AND ref_id = article_id"); |
23aa0d16 | 2242 | |
23aa0d16 | 2243 | } |
ad0056a8 | 2244 | |
c7e51de1 | 2245 | ccache_update($link, $feed, $owner_uid, $cat_view); |
ad0056a8 | 2246 | |
23aa0d16 AD |
2247 | } else { // tag |
2248 | db_query($link, "BEGIN"); | |
2249 | ||
2250 | $tag_name = db_escape_string($feed); | |
2251 | ||
2252 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
c7e51de1 | 2253 | WHERE tag_name = '$tag_name' AND owner_uid = $owner_uid"); |
23aa0d16 AD |
2254 | |
2255 | while ($line = db_fetch_assoc($result)) { | |
2256 | db_query($link, "UPDATE ttrss_user_entries SET | |
2257 | unread = false, last_read = NOW() | |
2258 | WHERE int_id = " . $line["post_int_id"]); | |
2259 | } | |
2260 | db_query($link, "COMMIT"); | |
2261 | } | |
2262 | } | |
2263 | ||
35bf080c | 2264 | function update_generic_feed($link, $feed, $cat_view, $force_update = false) { |
23aa0d16 AD |
2265 | if ($cat_view) { |
2266 | ||
2267 | if ($feed > 0) { | |
2268 | $cat_qpart = "cat_id = '$feed'"; | |
2269 | } else { | |
2270 | $cat_qpart = "cat_id IS NULL"; | |
2271 | } | |
2272 | ||
571dad82 | 2273 | $tmp_result = db_query($link, "SELECT id,feed_url FROM ttrss_feeds |
23aa0d16 AD |
2274 | WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]); |
2275 | ||
2276 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2277 | $feed_url = $tmp_line["feed_url"]; | |
571dad82 | 2278 | $feed_id = $tmp_line["id"]; |
35bf080c | 2279 | update_rss_feed($link, $feed_url, $feed_id, $force_update); |
23aa0d16 AD |
2280 | } |
2281 | ||
2282 | } else { | |
2283 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
2284 | WHERE id = '$feed'"); | |
2285 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
35bf080c | 2286 | update_rss_feed($link, $feed_url, $feed, $force_update); |
23aa0d16 AD |
2287 | } |
2288 | } | |
a9cb1f83 | 2289 | |
4ffa126e | 2290 | function getAllCounters($link, $omode = "flc", $active_feed = false) { |
cf4d339c | 2291 | |
e33fe293 | 2292 | if (!$omode) $omode = "flc"; |
d9e4bba0 | 2293 | |
e33fe293 | 2294 | getGlobalCounters($link); |
d9e4bba0 | 2295 | |
e33fe293 AD |
2296 | if (strchr($omode, "l")) getLabelCounters($link); |
2297 | if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed); | |
2298 | if (strchr($omode, "t")) getTagCounters($link); | |
2299 | if (strchr($omode, "c")) { | |
2300 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2301 | getCategoryCounters($link); | |
cf4d339c | 2302 | } |
e33fe293 | 2303 | } |
a9cb1f83 AD |
2304 | } |
2305 | ||
2306 | function getCategoryCounters($link) { | |
bba7c4bf AD |
2307 | # two special categories are -1 and -2 (all virtuals; all labels) |
2308 | ||
b2531a28 | 2309 | /* $ctr = getCategoryUnread($link, -1); |
bba7c4bf | 2310 | |
b2531a28 | 2311 | print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>"; */ |
bba7c4bf | 2312 | |
b2531a28 | 2313 | $ctr = getCategoryUnread($link, -2); |
bba7c4bf AD |
2314 | |
2315 | print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>"; | |
2316 | ||
14073c0a AD |
2317 | $age_qpart = getMaxAgeSubquery(); |
2318 | ||
31375163 AD |
2319 | $result = db_query($link, "SELECT id AS cat_id, value AS unread |
2320 | FROM ttrss_feed_categories, ttrss_cat_counters_cache | |
2321 | WHERE ttrss_cat_counters_cache.feed_id = id AND | |
2322 | ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]); | |
a9cb1f83 AD |
2323 | |
2324 | while ($line = db_fetch_assoc($result)) { | |
2325 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
8a4c759e | 2326 | |
a9cb1f83 AD |
2327 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". |
2328 | $line["unread"]."\"/>"; | |
2329 | } | |
d232a40f AD |
2330 | |
2331 | /* Special case: NULL category doesn't actually exist in the DB */ | |
2332 | ||
2333 | print "<counter type=\"category\" id=\"0\" counter=\"". | |
2334 | ccache_find($link, 0, $_SESSION["uid"], true)."\"/>"; | |
2335 | ||
a9cb1f83 AD |
2336 | } |
2337 | ||
b6d486a3 AD |
2338 | function getCategoryUnread($link, $cat, $owner_uid = false) { |
2339 | ||
2340 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
f295c368 | 2341 | |
bba7c4bf | 2342 | if ($cat >= 0) { |
18664970 | 2343 | |
bba7c4bf AD |
2344 | if ($cat != 0) { |
2345 | $cat_query = "cat_id = '$cat'"; | |
2346 | } else { | |
2347 | $cat_query = "cat_id IS NULL"; | |
2348 | } | |
14073c0a AD |
2349 | |
2350 | $age_qpart = getMaxAgeSubquery(); | |
2351 | ||
bba7c4bf AD |
2352 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query |
2353 | AND hidden = false | |
b6d486a3 | 2354 | AND owner_uid = " . $owner_uid); |
bba7c4bf AD |
2355 | |
2356 | $cat_feeds = array(); | |
2357 | while ($line = db_fetch_assoc($result)) { | |
2358 | array_push($cat_feeds, "feed_id = " . $line["id"]); | |
2359 | } | |
2360 | ||
2361 | if (count($cat_feeds) == 0) return 0; | |
2362 | ||
2363 | $match_part = implode(" OR ", $cat_feeds); | |
2364 | ||
2365 | $result = db_query($link, "SELECT COUNT(int_id) AS unread | |
14073c0a AD |
2366 | FROM ttrss_user_entries,ttrss_entries |
2367 | WHERE unread = true AND ($match_part) AND id = ref_id | |
b6d486a3 | 2368 | AND $age_qpart AND owner_uid = " . $owner_uid); |
bba7c4bf AD |
2369 | |
2370 | $unread = 0; | |
2371 | ||
2372 | # this needs to be rewritten | |
2373 | while ($line = db_fetch_assoc($result)) { | |
2374 | $unread += $line["unread"]; | |
2375 | } | |
2376 | ||
2377 | return $unread; | |
2378 | } else if ($cat == -1) { | |
2d24f032 | 2379 | return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3); |
bba7c4bf | 2380 | } else if ($cat == -2) { |
f295c368 | 2381 | |
b2531a28 AD |
2382 | $result = db_query($link, " |
2383 | SELECT COUNT(unread) AS unread FROM | |
2384 | ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds | |
2385 | WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND | |
2386 | ttrss_labels2.owner_uid = '$owner_uid' | |
2387 | AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id | |
2388 | AND ttrss_user_entries.owner_uid = '$owner_uid'"); | |
ceb30ba4 | 2389 | |
b2531a28 | 2390 | $unread = db_fetch_result($result, 0, "unread"); |
f295c368 | 2391 | |
b2531a28 | 2392 | return $unread; |
f295c368 | 2393 | |
ceb30ba4 | 2394 | } |
f295c368 AD |
2395 | } |
2396 | ||
14073c0a AD |
2397 | function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) { |
2398 | if (DB_TYPE == "pgsql") { | |
2399 | return "ttrss_entries.date_entered > | |
2400 | NOW() - INTERVAL '$days days'"; | |
2401 | } else { | |
2402 | return "ttrss_entries.date_entered > | |
2403 | DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
2404 | } | |
2405 | } | |
2406 | ||
f295c368 | 2407 | function getFeedUnread($link, $feed, $is_cat = false) { |
2627f2d0 | 2408 | return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]); |
bdb7369b AD |
2409 | } |
2410 | ||
ceb30ba4 AD |
2411 | function getLabelUnread($link, $label_id, $owner_uid = false) { |
2412 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
2413 | ||
2414 | $result = db_query($link, " | |
0112162d | 2415 | SELECT COUNT(unread) AS unread FROM |
b0f24af1 AD |
2416 | ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds |
2417 | WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND | |
2418 | ttrss_labels2.owner_uid = '$owner_uid' AND ttrss_labels2.id = '$label_id' | |
2419 | AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id | |
933ba4ee | 2420 | AND ttrss_user_entries.owner_uid = '$owner_uid'"); |
ceb30ba4 AD |
2421 | |
2422 | if (db_num_rows($result) != 0) { | |
2423 | return db_fetch_result($result, 0, "unread"); | |
2424 | } else { | |
2425 | return 0; | |
2426 | } | |
2427 | } | |
2428 | ||
2627f2d0 AD |
2429 | function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false, |
2430 | $owner_uid = false) { | |
2431 | ||
a9cb1f83 | 2432 | $n_feed = sprintf("%d", $feed); |
f295c368 | 2433 | |
2627f2d0 AD |
2434 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
2435 | ||
bdb7369b AD |
2436 | if ($unread_only) { |
2437 | $unread_qpart = "unread = true"; | |
2438 | } else { | |
2439 | $unread_qpart = "true"; | |
2440 | } | |
2441 | ||
14073c0a AD |
2442 | $age_qpart = getMaxAgeSubquery(); |
2443 | ||
f295c368 | 2444 | if ($is_cat) { |
b6d486a3 | 2445 | return getCategoryUnread($link, $n_feed, $owner_uid); |
f295c368 | 2446 | } else if ($n_feed == -1) { |
a9cb1f83 | 2447 | $match_part = "marked = true"; |
e4f4b46f AD |
2448 | } else if ($n_feed == -2) { |
2449 | $match_part = "published = true"; | |
2d24f032 AD |
2450 | } else if ($n_feed == -3) { |
2451 | $match_part = "unread = true"; | |
2452 | ||
b71e188e | 2453 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); |
c1d7e6c3 | 2454 | |
2d24f032 | 2455 | if (DB_TYPE == "pgsql") { |
7608b38a | 2456 | $match_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 2457 | } else { |
7608b38a | 2458 | $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 | 2459 | } |
b2531a28 AD |
2460 | } else if ($n_feed == -4) { |
2461 | $match_part = "true"; | |
4919fb42 | 2462 | } else if ($n_feed > 0) { |
831ff047 | 2463 | |
e8b8485f AD |
2464 | $result = db_query($link, "SELECT id FROM ttrss_feeds |
2465 | WHERE parent_feed = '$n_feed' | |
318260cc | 2466 | AND hidden = false |
2627f2d0 | 2467 | AND owner_uid = " . $owner_uid); |
831ff047 AD |
2468 | |
2469 | if (db_num_rows($result) > 0) { | |
4919fb42 | 2470 | |
831ff047 AD |
2471 | $linked_feeds = array(); |
2472 | while ($line = db_fetch_assoc($result)) { | |
2473 | array_push($linked_feeds, "feed_id = " . $line["id"]); | |
2474 | } | |
e8b8485f AD |
2475 | |
2476 | array_push($linked_feeds, "feed_id = $n_feed"); | |
831ff047 AD |
2477 | |
2478 | $match_part = implode(" OR ", $linked_feeds); | |
2479 | ||
4919fb42 | 2480 | $result = db_query($link, "SELECT COUNT(int_id) AS unread |
14073c0a | 2481 | FROM ttrss_user_entries,ttrss_entries |
bdb7369b | 2482 | WHERE $unread_qpart AND |
14073c0a AD |
2483 | ttrss_user_entries.ref_id = ttrss_entries.id AND |
2484 | $age_qpart AND | |
2485 | ($match_part) AND | |
2627f2d0 | 2486 | owner_uid = " . $owner_uid); |
4919fb42 AD |
2487 | |
2488 | $unread = 0; | |
2489 | ||
2490 | # this needs to be rewritten | |
2491 | while ($line = db_fetch_assoc($result)) { | |
2492 | $unread += $line["unread"]; | |
2493 | } | |
2494 | ||
2495 | return $unread; | |
2496 | ||
831ff047 AD |
2497 | } else { |
2498 | $match_part = "feed_id = '$n_feed'"; | |
2499 | } | |
a9cb1f83 | 2500 | } else if ($feed < -10) { |
318260cc | 2501 | |
a9cb1f83 AD |
2502 | $label_id = -$feed - 11; |
2503 | ||
ceb30ba4 | 2504 | return getLabelUnread($link, $label_id, $owner_uid); |
a9cb1f83 | 2505 | |
a9cb1f83 AD |
2506 | } |
2507 | ||
2508 | if ($match_part) { | |
2509 | ||
2510 | $result = db_query($link, "SELECT count(int_id) AS unread | |
88040f57 AD |
2511 | FROM ttrss_user_entries,ttrss_feeds,ttrss_entries WHERE |
2512 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
2513 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
cfb02131 | 2514 | ttrss_feeds.hidden = false AND |
14073c0a | 2515 | $age_qpart AND |
2627f2d0 | 2516 | $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = " . $owner_uid); |
a9cb1f83 AD |
2517 | |
2518 | } else { | |
2519 | ||
2520 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
14073c0a | 2521 | FROM ttrss_tags,ttrss_user_entries,ttrss_entries |
828f22b7 | 2522 | WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id |
bdb7369b | 2523 | AND $unread_qpart AND $age_qpart AND |
2627f2d0 | 2524 | ttrss_tags.owner_uid = " . $owner_uid); |
a9cb1f83 AD |
2525 | } |
2526 | ||
2527 | $unread = db_fetch_result($result, 0, "unread"); | |
cfb02131 | 2528 | |
a9cb1f83 AD |
2529 | return $unread; |
2530 | } | |
2531 | ||
f3acc32e AD |
2532 | function getGlobalUnread($link, $user_id = false) { |
2533 | ||
2534 | if (!$user_id) { | |
2535 | $user_id = $_SESSION["uid"]; | |
2536 | } | |
2537 | ||
8a4c759e AD |
2538 | $result = db_query($link, "SELECT SUM(value) AS c_id FROM ttrss_counters_cache |
2539 | WHERE owner_uid = '$user_id' AND feed_id > 0"); | |
2540 | ||
2541 | $c_id = db_fetch_result($result, 0, "c_id"); | |
2542 | ||
a9cb1f83 AD |
2543 | return $c_id; |
2544 | } | |
2545 | ||
2546 | function getGlobalCounters($link, $global_unread = -1) { | |
2547 | if ($global_unread == -1) { | |
2548 | $global_unread = getGlobalUnread($link); | |
2549 | } | |
7bf7e4d3 AD |
2550 | print "<counter type=\"global\" id='global-unread' |
2551 | counter='$global_unread'/>"; | |
2552 | ||
2553 | $result = db_query($link, "SELECT COUNT(id) AS fn FROM | |
2554 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
2555 | ||
2556 | $subscribed_feeds = db_fetch_result($result, 0, "fn"); | |
2557 | ||
2558 | print "<counter type=\"global\" id='subscribed-feeds' | |
2559 | counter='$subscribed_feeds'/>"; | |
2560 | ||
a9cb1f83 AD |
2561 | } |
2562 | ||
2563 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
2564 | ||
2565 | if ($smart_mode) { | |
2566 | if (!$_SESSION["tctr_last_value"]) { | |
2567 | $_SESSION["tctr_last_value"] = array(); | |
2568 | } | |
2569 | } | |
2570 | ||
2571 | $old_counters = $_SESSION["tctr_last_value"]; | |
2572 | ||
2573 | $tctrs_modified = false; | |
2574 | ||
14073c0a AD |
2575 | $age_qpart = getMaxAgeSubquery(); |
2576 | ||
a9cb1f83 | 2577 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
2578 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
2579 | AND ref_id = id AND $age_qpart | |
a9cb1f83 | 2580 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
2581 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
2582 | ORDER BY count DESC LIMIT 55"); | |
a9cb1f83 AD |
2583 | |
2584 | $tags = array(); | |
2585 | ||
2586 | while ($line = db_fetch_assoc($result)) { | |
2587 | $tags[$line["tag_name"]] += $line["count"]; | |
2588 | } | |
2589 | ||
2590 | foreach (array_keys($tags) as $tag) { | |
2591 | $unread = $tags[$tag]; | |
2592 | ||
2593 | $tag = htmlspecialchars($tag); | |
2594 | ||
2595 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
2596 | $old_counters[$tag] = $unread; | |
2597 | $tctrs_modified = true; | |
2598 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
2599 | } | |
2600 | ||
2601 | } | |
2602 | ||
2603 | if ($smart_mode && $tctrs_modified) { | |
2604 | $_SESSION["tctr_last_value"] = $old_counters; | |
2605 | } | |
2606 | ||
2607 | } | |
2608 | ||
ef393de7 | 2609 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) { |
a9cb1f83 | 2610 | |
14073c0a AD |
2611 | $age_qpart = getMaxAgeSubquery(); |
2612 | ||
a9cb1f83 AD |
2613 | if ($smart_mode) { |
2614 | if (!$_SESSION["lctr_last_value"]) { | |
2615 | $_SESSION["lctr_last_value"] = array(); | |
2616 | } | |
2617 | } | |
2618 | ||
ef393de7 | 2619 | $ret_arr = array(); |
bdb7369b | 2620 | |
b2531a28 | 2621 | for ($i = -1; $i >= -4; $i--) { |
bdb7369b | 2622 | |
ceb30ba4 AD |
2623 | $count = getFeedUnread($link, $i); |
2624 | ||
2625 | if (!$ret_mode) { | |
2626 | ||
2627 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2628 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $i) . " total)\""; | |
2629 | } else { | |
2630 | $xmsg_part = ""; | |
2631 | } | |
bdb7369b | 2632 | |
ceb30ba4 | 2633 | print "<counter type=\"label\" id=\"$i\" counter=\"$count\" $xmsg_part/>"; |
bdb7369b | 2634 | } else { |
ceb30ba4 AD |
2635 | $ret_arr[$i]["counter"] = $count; |
2636 | $ret_arr[$i]["description"] = getFeedTitle($link, $i); | |
bdb7369b | 2637 | } |
ceb30ba4 | 2638 | |
e4f4b46f AD |
2639 | } |
2640 | ||
ceb30ba4 AD |
2641 | $old_counters = $_SESSION["lctr_last_value"]; |
2642 | $lctrs_modified = false; | |
bdb7369b | 2643 | |
2d24f032 | 2644 | |
ceb30ba4 | 2645 | $owner_uid = $_SESSION["uid"]; |
e4f4b46f | 2646 | |
467ff402 AD |
2647 | $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 |
2648 | WHERE owner_uid = '$owner_uid'"); | |
abd9b165 AD |
2649 | |
2650 | while ($line = db_fetch_assoc($result)) { | |
a9cb1f83 | 2651 | |
abd9b165 AD |
2652 | $id = -$line["id"] - 11; |
2653 | ||
ceb30ba4 | 2654 | $label_name = $line["caption"]; |
467ff402 | 2655 | $count = getFeedUnread($link, $id); |
ceb30ba4 | 2656 | |
abd9b165 AD |
2657 | if (!$smart_mode || $old_counters[$id] != $count) { |
2658 | $old_counters[$id] = $count; | |
2659 | $lctrs_modified = true; | |
2660 | if (!$ret_mode) { | |
2661 | ||
2662 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { | |
2663 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2664 | } else { | |
2665 | $xmsg_part = ""; | |
2666 | } | |
2667 | ||
2668 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\" $xmsg_part/>"; | |
bdb7369b | 2669 | } else { |
abd9b165 AD |
2670 | $ret_arr[$id]["counter"] = $count; |
2671 | $ret_arr[$id]["description"] = $label_name; | |
bdb7369b | 2672 | } |
ef393de7 | 2673 | } |
abd9b165 AD |
2674 | |
2675 | error_reporting (DEFAULT_ERROR_LEVEL); | |
5f4f7adf | 2676 | } |
a9cb1f83 AD |
2677 | |
2678 | if ($smart_mode && $lctrs_modified) { | |
2679 | $_SESSION["lctr_last_value"] = $old_counters; | |
2680 | } | |
ef393de7 AD |
2681 | |
2682 | return $ret_arr; | |
a9cb1f83 AD |
2683 | } |
2684 | ||
4ffa126e | 2685 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS, $active_feed = false) { |
a9cb1f83 | 2686 | |
14073c0a AD |
2687 | $age_qpart = getMaxAgeSubquery(); |
2688 | ||
a9cb1f83 AD |
2689 | if ($smart_mode) { |
2690 | if (!$_SESSION["fctr_last_value"]) { | |
2691 | $_SESSION["fctr_last_value"] = array(); | |
2692 | } | |
2693 | } | |
2694 | ||
2695 | $old_counters = $_SESSION["fctr_last_value"]; | |
2696 | ||
8a4c759e AD |
2697 | $query = "SELECT ttrss_feeds.id, |
2698 | ttrss_feeds.title, | |
2699 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, | |
de0a2122 AD |
2700 | last_error, value AS count |
2701 | FROM ttrss_feeds, ttrss_counters_cache | |
8a4c759e AD |
2702 | WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]." |
2703 | AND parent_feed IS NULL | |
55e01d7e | 2704 | AND ttrss_counters_cache.feed_id = id"; |
a9cb1f83 | 2705 | |
14073c0a | 2706 | $result = db_query($link, $query); |
a9cb1f83 AD |
2707 | $fctrs_modified = false; |
2708 | ||
fb1fb4ab AD |
2709 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); |
2710 | ||
a9cb1f83 AD |
2711 | while ($line = db_fetch_assoc($result)) { |
2712 | ||
2713 | $id = $line["id"]; | |
de0a2122 | 2714 | $count = $line["count"]; |
a9cb1f83 | 2715 | $last_error = htmlspecialchars($line["last_error"]); |
fb1fb4ab AD |
2716 | |
2717 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
2718 | $last_updated = smart_date_time(strtotime($line["last_updated"])); | |
2719 | } else { | |
2720 | $last_updated = date($short_date, strtotime($line["last_updated"])); | |
2721 | } | |
2722 | ||
588fb13b AD |
2723 | $last_updated = htmlspecialchars($last_updated); |
2724 | ||
7defa089 | 2725 | $has_img = feed_has_icon($id); |
a9cb1f83 | 2726 | |
de0a2122 AD |
2727 | $tmp_result = db_query($link, |
2728 | "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache | |
2729 | WHERE parent_feed = '$id' AND feed_id = id"); | |
2730 | ||
2731 | $count += db_fetch_result($tmp_result, 0, "unread"); | |
a9cb1f83 AD |
2732 | |
2733 | if (!$smart_mode || $old_counters[$id] != $count) { | |
2734 | $old_counters[$id] = $count; | |
2735 | $fctrs_modified = true; | |
2736 | ||
2737 | if ($last_error) { | |
2738 | $error_part = "error=\"$last_error\""; | |
2739 | } else { | |
2740 | $error_part = ""; | |
2741 | } | |
2742 | ||
2743 | if ($has_img) { | |
2744 | $has_img_part = "hi=\"$has_img\""; | |
2745 | } else { | |
2746 | $has_img_part = ""; | |
2747 | } | |
2748 | ||
4ffa126e AD |
2749 | if ($active_feed && $id == $active_feed) { |
2750 | $has_title_part = "title=\"" . htmlspecialchars($line["title"]) . "\""; | |
2751 | } else { | |
2752 | $has_title_part = ""; | |
2753 | } | |
2754 | ||
bdb7369b AD |
2755 | if (get_pref($link, 'EXTENDED_FEEDLIST')) { |
2756 | $xmsg_part = "xmsg=\"(" . getFeedArticles($link, $id) . " total)\""; | |
2757 | } | |
2758 | ||
2759 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part updated=\"$last_updated\" $xmsg_part $has_title_part/>"; | |
a9cb1f83 AD |
2760 | } |
2761 | } | |
2762 | ||
2763 | if ($smart_mode && $fctrs_modified) { | |
2764 | $_SESSION["fctr_last_value"] = $old_counters; | |
2765 | } | |
2766 | } | |
2767 | ||
1b758780 | 2768 | function get_script_dt_add() { |
3ac60b76 | 2769 | /* if (strpos(VERSION, ".99") === false) { |
1b758780 AD |
2770 | return VERSION; |
2771 | } else { | |
2772 | return time(); | |
3ac60b76 AD |
2773 | } */ |
2774 | return time(); | |
1b758780 AD |
2775 | } |
2776 | ||
6e7f8d26 AD |
2777 | function get_pgsql_version($link) { |
2778 | $result = db_query($link, "SELECT version() AS version"); | |
2779 | $version = split(" ", db_fetch_result($result, 0, "version")); | |
2780 | return $version[1]; | |
2781 | } | |
2782 | ||
af106b0e AD |
2783 | function print_error_xml($code, $add_msg = "") { |
2784 | global $ERRORS; | |
2785 | ||
2786 | $error_msg = $ERRORS[$code]; | |
2787 | ||
2788 | if ($add_msg) { | |
2789 | $error_msg = "$error_msg; $add_msg"; | |
2790 | } | |
2791 | ||
4c2abbc1 | 2792 | print "<rpc-reply>"; |
af106b0e | 2793 | print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>"; |
4c2abbc1 | 2794 | print "</rpc-reply>"; |
af106b0e | 2795 | } |
956c7629 | 2796 | |
f27de515 AD |
2797 | function subscribe_to_feed($link, $feed_link, $cat_id = 0, |
2798 | $auth_login = '', $auth_pass = '') { | |
bb0f29a4 | 2799 | |
b3dfe8ba | 2800 | # check for feed:http://url |
c91c2249 AD |
2801 | $feed_link = trim(preg_replace("/^feed:/", "", $feed_link)); |
2802 | ||
b3dfe8ba | 2803 | # check for feed://URL |
e2d84cdb | 2804 | if (strpos($feed_link, "//") === 0) { |
b3dfe8ba AD |
2805 | $feed_link = "http:$feed_link"; |
2806 | } | |
2807 | ||
c91c2249 | 2808 | if ($feed_link == "") return; |
bb0f29a4 | 2809 | |
956c7629 AD |
2810 | if ($cat_id == "0" || !$cat_id) { |
2811 | $cat_qpart = "NULL"; | |
2812 | } else { | |
2813 | $cat_qpart = "'$cat_id'"; | |
2814 | } | |
2815 | ||
2816 | $result = db_query($link, | |
2817 | "SELECT id FROM ttrss_feeds | |
2818 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
2819 | ||
2820 | if (db_num_rows($result) == 0) { | |
2821 | ||
2822 | $result = db_query($link, | |
f27de515 AD |
2823 | "INSERT INTO ttrss_feeds |
2824 | (owner_uid,feed_url,title,cat_id, auth_login,auth_pass) | |
956c7629 | 2825 | VALUES ('".$_SESSION["uid"]."', '$feed_link', |
f27de515 | 2826 | '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')"); |
956c7629 AD |
2827 | |
2828 | $result = db_query($link, | |
2829 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
f27de515 | 2830 | AND owner_uid = " . $_SESSION["uid"]); |
956c7629 AD |
2831 | |
2832 | $feed_id = db_fetch_result($result, 0, "id"); | |
2833 | ||
2834 | if ($feed_id) { | |
2835 | update_rss_feed($link, $feed_link, $feed_id, true); | |
2836 | } | |
2837 | ||
2838 | return true; | |
2839 | } else { | |
2840 | return false; | |
2841 | } | |
2842 | } | |
2843 | ||
673d54ca AD |
2844 | function print_feed_select($link, $id, $default_id = "", |
2845 | $attributes = "", $include_all_feeds = true) { | |
2846 | ||
79f3553b | 2847 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca | 2848 | if ($include_all_feeds) { |
89cb787e | 2849 | print "<option value=\"0\">".__('All feeds')."</option>"; |
673d54ca AD |
2850 | } |
2851 | ||
2852 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2853 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2854 | ||
2855 | if (db_num_rows($result) > 0 && $include_all_feeds) { | |
2856 | print "<option disabled>--------</option>"; | |
2857 | } | |
2858 | ||
2859 | while ($line = db_fetch_assoc($result)) { | |
2860 | if ($line["id"] == $default_id) { | |
2861 | $is_selected = "selected"; | |
2862 | } else { | |
2863 | $is_selected = ""; | |
2864 | } | |
79f3553b | 2865 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2866 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2867 | } |
2868 | ||
2869 | print "</select>"; | |
2870 | } | |
2871 | ||
2872 | function print_feed_cat_select($link, $id, $default_id = "", | |
2873 | $attributes = "", $include_all_cats = true) { | |
2874 | ||
79f3553b | 2875 | print "<select id=\"$id\" name=\"$id\" $attributes>"; |
673d54ca AD |
2876 | |
2877 | if ($include_all_cats) { | |
d1db26aa | 2878 | print "<option value=\"0\">".__('Uncategorized')."</option>"; |
673d54ca AD |
2879 | } |
2880 | ||
2881 | $result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
2882 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2883 | ||
2884 | if (db_num_rows($result) > 0 && $include_all_cats) { | |
2885 | print "<option disabled>--------</option>"; | |
2886 | } | |
2887 | ||
2888 | while ($line = db_fetch_assoc($result)) { | |
2889 | if ($line["id"] == $default_id) { | |
2890 | $is_selected = "selected"; | |
2891 | } else { | |
2892 | $is_selected = ""; | |
2893 | } | |
14f69488 | 2894 | printf("<option $is_selected value='%d'>%s</option>", |
47439031 | 2895 | $line["id"], htmlspecialchars($line["title"])); |
673d54ca AD |
2896 | } |
2897 | ||
2898 | print "</select>"; | |
2899 | } | |
2900 | ||
14f69488 AD |
2901 | function checkbox_to_sql_bool($val) { |
2902 | return ($val == "on") ? "true" : "false"; | |
2903 | } | |
86b682ce AD |
2904 | |
2905 | function getFeedCatTitle($link, $id) { | |
2906 | if ($id == -1) { | |
d1db26aa | 2907 | return __("Special"); |
86b682ce | 2908 | } else if ($id < -10) { |
d1db26aa | 2909 | return __("Labels"); |
86b682ce AD |
2910 | } else if ($id > 0) { |
2911 | $result = db_query($link, "SELECT ttrss_feed_categories.title | |
2912 | FROM ttrss_feeds, ttrss_feed_categories WHERE ttrss_feeds.id = '$id' AND | |
2913 | cat_id = ttrss_feed_categories.id"); | |
2914 | if (db_num_rows($result) == 1) { | |
2915 | return db_fetch_result($result, 0, "title"); | |
2916 | } else { | |
d1db26aa | 2917 | return __("Uncategorized"); |
86b682ce AD |
2918 | } |
2919 | } else { | |
2920 | return "getFeedCatTitle($id) failed"; | |
2921 | } | |
2922 | ||
2923 | } | |
2924 | ||
2925 | function getFeedTitle($link, $id) { | |
2926 | if ($id == -1) { | |
d1db26aa | 2927 | return __("Starred articles"); |
945c243e AD |
2928 | } else if ($id == -2) { |
2929 | return __("Published articles"); | |
2d24f032 AD |
2930 | } else if ($id == -3) { |
2931 | return __("Fresh articles"); | |
b2531a28 AD |
2932 | } else if ($id == -4) { |
2933 | return __("All articles"); | |
86b682ce | 2934 | } else if ($id < -10) { |
76626c72 | 2935 | $label_id = -$id - 11; |
ceb30ba4 | 2936 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'"); |
86b682ce | 2937 | if (db_num_rows($result) == 1) { |
ceb30ba4 | 2938 | return db_fetch_result($result, 0, "caption"); |
86b682ce AD |
2939 | } else { |
2940 | return "Unknown label ($label_id)"; | |
2941 | } | |
2942 | ||
2943 | } else if ($id > 0) { | |
2944 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$id'"); | |
2945 | if (db_num_rows($result) == 1) { | |
2946 | return db_fetch_result($result, 0, "title"); | |
2947 | } else { | |
2948 | return "Unknown feed ($id)"; | |
2949 | } | |
2950 | } else { | |
849b3825 AD |
2951 | if (preg_match("/^-?[0-9][0-9]*$/", $id)) { |
2952 | return "getFeedTitle($id) failed"; | |
2953 | } else { | |
2954 | return $id; | |
2955 | } | |
86b682ce AD |
2956 | } |
2957 | ||
2958 | } | |
3dd46f19 AD |
2959 | |
2960 | function get_session_cookie_name() { | |
2961 | return ((!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME); | |
2962 | } | |
3ac2b520 AD |
2963 | |
2964 | function print_init_params($link) { | |
2965 | print "<init-params>"; | |
2966 | if ($_SESSION["stored-params"]) { | |
2967 | foreach (array_keys($_SESSION["stored-params"]) as $key) { | |
5f57b06d AD |
2968 | if ($key) { |
2969 | $value = htmlspecialchars($_SESSION["stored-params"][$key]); | |
2970 | print "<param key=\"$key\" value=\"$value\"/>"; | |
2971 | } | |
3ac2b520 AD |
2972 | } |
2973 | } | |
2974 | ||
20361063 | 2975 | print "<param key=\"theme\" value=\"".$_SESSION["theme"]."\"/>"; |
3ac2b520 AD |
2976 | print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>"; |
2977 | print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>"; | |
17c0eeba | 2978 | print "<param key=\"daemon_refresh_only\" value=\"true\"/>"; |
3ac2b520 AD |
2979 | |
2980 | print "<param key=\"on_catchup_show_next_feed\" value=\"" . | |
2981 | get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED") . "\"/>"; | |
2982 | ||
e8bd0da9 | 2983 | print "<param key=\"hide_read_feeds\" value=\"" . |
465ff90b | 2984 | (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>"; |
e8bd0da9 | 2985 | |
1c980681 AD |
2986 | print "<param key=\"enable_feed_cats\" value=\"" . |
2987 | (int) get_pref($link, "ENABLE_FEED_CATS") . "\"/>"; | |
2988 | ||
c9268ed5 | 2989 | print "<param key=\"feeds_sort_by_unread\" value=\"" . |
465ff90b | 2990 | (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>"; |
c9268ed5 | 2991 | |
f6d6e22f | 2992 | print "<param key=\"confirm_feed_catchup\" value=\"" . |
465ff90b | 2993 | (int) get_pref($link, "CONFIRM_FEED_CATCHUP") . "\"/>"; |
f6d6e22f | 2994 | |
ac7bcd71 | 2995 | print "<param key=\"cdm_auto_catchup\" value=\"" . |
465ff90b | 2996 | (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>"; |
ac7bcd71 | 2997 | |
8e9c121b AD |
2998 | print "<param key=\"icons_url\" value=\"" . ICONS_URL . "\"/>"; |
2999 | ||
be0801a1 AD |
3000 | print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME . "\"/>"; |
3001 | ||
40496720 AD |
3002 | print "<param key=\"default_view_mode\" value=\"" . |
3003 | get_pref($link, "_DEFAULT_VIEW_MODE") . "\"/>"; | |
3004 | ||
3005 | print "<param key=\"default_view_limit\" value=\"" . | |
465ff90b | 3006 | (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>"; |
40496720 | 3007 | |
7b4d02a8 AD |
3008 | print "<param key=\"default_view_order_by\" value=\"" . |
3009 | get_pref($link, "_DEFAULT_VIEW_ORDER_BY") . "\"/>"; | |
3010 | ||
fe8d2059 AD |
3011 | print "<param key=\"prefs_active_tab\" value=\"" . |
3012 | get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>"; | |
3013 | ||
465ff90b AD |
3014 | print "<param key=\"infobox_disable_overlay\" value=\"" . |
3015 | get_pref($link, "_INFOBOX_DISABLE_OVERLAY") . "\"/>"; | |
3016 | ||
527c3bf0 AD |
3017 | print "<param key=\"icons_location\" value=\"" . |
3018 | ICONS_URL . "\"/>"; | |
3019 | ||
22f3e356 AD |
3020 | print "<param key=\"hide_read_shows_special\" value=\"" . |
3021 | (int) get_pref($link, "HIDE_READ_SHOWS_SPECIAL") . "\"/>"; | |
3022 | ||
fca93350 AD |
3023 | print "<param key=\"hide_feedlist\" value=\"" . |
3024 | (int) get_pref($link, "HIDE_FEEDLIST") . "\"/>"; | |
24c1e1c1 | 3025 | |
a598370d AD |
3026 | print "<param key=\"bw_limit\" value=\"". |
3027 | (int) $_SESSION["bw_limit"]."\"/>"; | |
3028 | ||
bd090ab4 AD |
3029 | // print "<param key=\"sync_counters\" value=\"" . |
3030 | // (int) get_pref($link, "SYNC_COUNTERS") . "\"/>"; | |
3031 | ||
3032 | print "<param key=\"sync_counters\" value=\"1\"/>"; | |
d234a2e3 | 3033 | |
5de926d8 AD |
3034 | print "<param key=\"offline_enabled\" value=\"". |
3035 | (int) get_pref($link, "ENABLE_OFFLINE_READING") . "\"/>"; | |
59b223d7 | 3036 | |
9b7ecc0a AD |
3037 | $result = db_query($link, "SELECT COUNT(*) AS cf FROM |
3038 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
3039 | ||
3040 | $num_feeds = db_fetch_result($result, 0, "cf"); | |
3041 | ||
3042 | print "<param key=\"num_feeds\" value=\"". | |
3043 | (int)$num_feeds. "\"/>"; | |
3044 | ||
3ac2b520 AD |
3045 | print "</init-params>"; |
3046 | } | |
f54f515f AD |
3047 | |
3048 | function print_runtime_info($link) { | |
3049 | print "<runtime-info>"; | |
20361063 | 3050 | |
9b7ecc0a AD |
3051 | $result = db_query($link, "SELECT COUNT(*) AS cf FROM |
3052 | ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); | |
3053 | ||
3054 | $num_feeds = db_fetch_result($result, 0, "cf"); | |
3055 | ||
3056 | print "<param key=\"num_feeds\" value=\"". | |
3057 | (int)$num_feeds. "\"/>"; | |
3058 | ||
71ad883b AD |
3059 | if (ENABLE_UPDATE_DAEMON) { |
3060 | print "<param key=\"daemon_is_running\" value=\"". | |
3061 | sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>"; | |
8e00ae9b | 3062 | |
9041f58b | 3063 | if (time() - $_SESSION["daemon_stamp_check"] > 30) { |
8e00ae9b AD |
3064 | |
3065 | $stamp = (int)read_stampfile("update_daemon.stamp"); | |
3066 | ||
fbae93d8 AD |
3067 | // print "<param key=\"daemon_stamp_delta\" value=\"$stamp_delta\"/>"; |
3068 | ||
8e00ae9b | 3069 | if ($stamp) { |
9041f58b AD |
3070 | $stamp_delta = time() - $stamp; |
3071 | ||
3072 | if ($stamp_delta > 1800) { | |
f6854e44 | 3073 | $stamp_check = 0; |
8e00ae9b | 3074 | } else { |
f6854e44 AD |
3075 | $stamp_check = 1; |
3076 | $_SESSION["daemon_stamp_check"] = time(); | |
8e00ae9b AD |
3077 | } |
3078 | ||
f6854e44 AD |
3079 | print "<param key=\"daemon_stamp_ok\" value=\"$stamp_check\"/>"; |
3080 | ||
8e00ae9b AD |
3081 | $stamp_fmt = date("Y.m.d, G:i", $stamp); |
3082 | ||
3083 | print "<param key=\"daemon_stamp\" value=\"$stamp_fmt\"/>"; | |
3084 | } | |
8e00ae9b | 3085 | } |
71ad883b | 3086 | } |
8e00ae9b | 3087 | |
d9fa39f1 AD |
3088 | if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) { |
3089 | ||
8742de78 | 3090 | if ($_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { |
d9fa39f1 AD |
3091 | $new_version_details = check_for_update($link); |
3092 | ||
3093 | print "<param key=\"new_version_available\" value=\"". | |
3094 | sprintf("%d", $new_version_details != ""). "\"/>"; | |
3095 | ||
3096 | $_SESSION["last_version_check"] = time(); | |
3097 | } | |
3098 | } | |
3099 | ||
1c9df66e | 3100 | // print "<param key=\"new_version_available\" value=\"1\"/>"; |
b4507bc2 | 3101 | |
f54f515f AD |
3102 | print "</runtime-info>"; |
3103 | } | |
ef393de7 | 3104 | |
88040f57 | 3105 | function getSearchSql($search, $match_on) { |
ef393de7 | 3106 | |
88040f57 | 3107 | $search_query_part = ""; |
e20c9d88 | 3108 | |
88040f57 AD |
3109 | $keywords = split(" ", $search); |
3110 | $query_keywords = array(); | |
e20c9d88 | 3111 | |
88040f57 | 3112 | if ($match_on == "both") { |
e20c9d88 | 3113 | |
88040f57 AD |
3114 | foreach ($keywords as $k) { |
3115 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%') | |
3116 | OR UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
3117 | } | |
e20c9d88 | 3118 | |
88040f57 | 3119 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 3120 | |
88040f57 | 3121 | } else if ($match_on == "title") { |
e20c9d88 | 3122 | |
88040f57 AD |
3123 | foreach ($keywords as $k) { |
3124 | array_push($query_keywords, "(UPPER(ttrss_entries.title) LIKE UPPER('%$k%'))"); | |
3125 | } | |
e20c9d88 | 3126 | |
88040f57 | 3127 | $search_query_part = implode("AND", $query_keywords) . " AND "; |
e20c9d88 | 3128 | |
88040f57 AD |
3129 | } else if ($match_on == "content") { |
3130 | ||
3131 | foreach ($keywords as $k) { | |
3132 | array_push($query_keywords, "(UPPER(ttrss_entries.content) LIKE UPPER('%$k%'))"); | |
3133 | } | |
3134 | } | |
3135 | ||
3136 | $search_query_part = implode("AND", $query_keywords); | |
3137 | ||
3138 | return $search_query_part; | |
3139 | } | |
3140 | ||
c36bf4d5 AD |
3141 | function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) { |
3142 | ||
3143 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
c1a0b534 | 3144 | |
88040f57 AD |
3145 | if ($search) { |
3146 | ||
3147 | $search_query_part = getSearchSql($search, $match_on); | |
3148 | $search_query_part .= " AND "; | |
e20c9d88 | 3149 | |
ef393de7 AD |
3150 | } else { |
3151 | $search_query_part = ""; | |
3152 | } | |
3153 | ||
3154 | $view_query_part = ""; | |
3155 | ||
7b4d02a8 | 3156 | if ($view_mode == "adaptive" || $view_query_part == "noscores") { |
ef393de7 AD |
3157 | if ($search) { |
3158 | $view_query_part = " "; | |
3159 | } else if ($feed != -1) { | |
f295c368 | 3160 | $unread = getFeedUnread($link, $feed, $cat_view); |
ef393de7 | 3161 | if ($unread > 0) { |
ff863e00 | 3162 | $view_query_part = " unread = true AND "; |
ef393de7 AD |
3163 | } |
3164 | } | |
3165 | } | |
3166 | ||
3167 | if ($view_mode == "marked") { | |
3168 | $view_query_part = " marked = true AND "; | |
3169 | } | |
3170 | ||
3171 | if ($view_mode == "unread") { | |
3172 | $view_query_part = " unread = true AND "; | |
3173 | } | |
8b09eac8 AD |
3174 | |
3175 | if ($view_mode == "updated") { | |
3176 | $view_query_part = " (last_read is null and unread = false) AND "; | |
3177 | } | |
3178 | ||
ef393de7 AD |
3179 | if ($limit > 0) { |
3180 | $limit_query_part = "LIMIT " . $limit; | |
3181 | } | |
3182 | ||
3183 | $vfeed_query_part = ""; | |
3184 | ||
3185 | // override query strategy and enable feed display when searching globally | |
3186 | if ($search && $search_mode == "all_feeds") { | |
3187 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3188 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3189 | } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { | |
3190 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3191 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
3192 | id = feed_id) as feed_title,"; | |
3193 | } else if ($feed >= 0 && $search && $search_mode == "this_cat") { | |
3194 | ||
3195 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
0a6c4846 AD |
3196 | |
3197 | $tmp_result = false; | |
3198 | ||
3199 | if ($cat_view) { | |
3200 | $tmp_result = db_query($link, "SELECT id | |
3201 | FROM ttrss_feeds WHERE cat_id = '$feed'"); | |
3202 | } else { | |
3203 | $tmp_result = db_query($link, "SELECT id | |
3204 | FROM ttrss_feeds WHERE cat_id = (SELECT cat_id FROM ttrss_feeds | |
3205 | WHERE id = '$feed') AND id != '$feed'"); | |
3206 | } | |
ef393de7 AD |
3207 | |
3208 | $cat_siblings = array(); | |
3209 | ||
3210 | if (db_num_rows($tmp_result) > 0) { | |
3211 | while ($p = db_fetch_assoc($tmp_result)) { | |
3212 | array_push($cat_siblings, "feed_id = " . $p["id"]); | |
3213 | } | |
3214 | ||
3215 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
3216 | $feed, implode(" OR ", $cat_siblings)); | |
3217 | ||
3218 | } else { | |
3219 | $query_strategy_part = "ttrss_entries.id > 0"; | |
3220 | } | |
3221 | ||
3222 | } else if ($feed >= 0) { | |
3223 | ||
3224 | if ($cat_view) { | |
5c365f60 | 3225 | |
ef393de7 AD |
3226 | if ($feed > 0) { |
3227 | $query_strategy_part = "cat_id = '$feed'"; | |
3228 | } else { | |
3229 | $query_strategy_part = "cat_id IS NULL"; | |
3230 | } | |
3231 | ||
3232 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
5c365f60 | 3233 | |
ef393de7 AD |
3234 | } else { |
3235 | $tmp_result = db_query($link, "SELECT id | |
3236 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
3237 | ORDER BY cat_id,title"); | |
3238 | ||
3239 | $parent_ids = array(); | |
3240 | ||
3241 | if (db_num_rows($tmp_result) > 0) { | |
3242 | while ($p = db_fetch_assoc($tmp_result)) { | |
3243 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
3244 | } | |
3245 | ||
3246 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
3247 | $feed, implode(" OR ", $parent_ids)); | |
3248 | ||
3249 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3250 | } else { | |
3251 | $query_strategy_part = "feed_id = '$feed'"; | |
3252 | } | |
3253 | } | |
3254 | } else if ($feed == -1) { // starred virtual feed | |
3255 | $query_strategy_part = "marked = true"; | |
3256 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
e6a38cde AD |
3257 | } else if ($feed == -2) { // published virtual feed OR labels category |
3258 | ||
3259 | if (!$cat_view) { | |
3260 | $query_strategy_part = "published = true"; | |
3261 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3262 | } else { | |
3263 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
3264 | ||
3265 | $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2"; | |
3266 | ||
3267 | $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND | |
3268 | ttrss_user_labels2.article_id = ref_id"; | |
3269 | ||
3270 | } | |
3271 | ||
2d24f032 AD |
3272 | } else if ($feed == -3) { // fresh virtual feed |
3273 | $query_strategy_part = "unread = true"; | |
3274 | ||
7a22dc2a | 3275 | $intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE", $owner_uid); |
c1d7e6c3 | 3276 | |
2d24f032 | 3277 | if (DB_TYPE == "pgsql") { |
7608b38a | 3278 | $query_strategy_part .= " AND updated > NOW() - INTERVAL '$intl hour' "; |
2d24f032 | 3279 | } else { |
7608b38a | 3280 | $query_strategy_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
2d24f032 AD |
3281 | } |
3282 | ||
b2531a28 AD |
3283 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
3284 | } else if ($feed == -4) { // all articles virtual feed | |
3285 | $query_strategy_part = "true"; | |
e4f4b46f | 3286 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
ef393de7 AD |
3287 | } else if ($feed <= -10) { // labels |
3288 | $label_id = -$feed - 11; | |
3de0261a | 3289 | |
ceb30ba4 AD |
3290 | $query_strategy_part = "label_id = '$label_id' AND |
3291 | ttrss_labels2.id = ttrss_user_labels2.label_id AND | |
3292 | ttrss_user_labels2.article_id = ref_id"; | |
3de0261a | 3293 | |
ef393de7 | 3294 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
ceb30ba4 AD |
3295 | $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2"; |
3296 | ||
ef393de7 AD |
3297 | } else { |
3298 | $query_strategy_part = "id > 0"; // dumb | |
3299 | } | |
d6e5706d | 3300 | |
7a22dc2a | 3301 | if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { |
d6e5706d AD |
3302 | $order_by = "updated"; |
3303 | } else { | |
3304 | $order_by = "updated DESC"; | |
3305 | } | |
e939722a | 3306 | |
7b4d02a8 AD |
3307 | if ($view_mode != "noscores") { |
3308 | $order_by = "score DESC, $order_by"; | |
3309 | } | |
48b0c4ec | 3310 | |
e939722a AD |
3311 | if ($override_order) { |
3312 | $order_by = $override_order; | |
3313 | } | |
ef393de7 AD |
3314 | |
3315 | $feed_title = ""; | |
3316 | ||
3317 | if ($search && $search_mode == "all_feeds") { | |
b36e002f | 3318 | $feed_title = __("Search results")." ($search)"; |
ef393de7 | 3319 | } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
b36e002f | 3320 | $feed_title = __("Search results")." ($search, $feed)"; |
ef393de7 AD |
3321 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { |
3322 | $feed_title = $feed; | |
3323 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { | |
3324 | ||
3325 | if ($cat_view) { | |
5c365f60 | 3326 | |
ef393de7 AD |
3327 | if ($feed != 0) { |
3328 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories | |
c36bf4d5 | 3329 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
3330 | $feed_title = db_fetch_result($result, 0, "title"); |
3331 | } else { | |
d1db26aa | 3332 | $feed_title = __("Uncategorized"); |
ef393de7 | 3333 | } |
e1eb2147 AD |
3334 | |
3335 | if ($search) { | |
b36e002f | 3336 | $feed_title = __("Searched for")." $search ($feed_title)"; |
e1eb2147 AD |
3337 | } |
3338 | ||
ef393de7 AD |
3339 | } else { |
3340 | ||
3341 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
c36bf4d5 | 3342 | WHERE id = '$feed' AND owner_uid = $owner_uid"); |
ef393de7 AD |
3343 | |
3344 | $feed_title = db_fetch_result($result, 0, "title"); | |
3345 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
3346 | $last_error = db_fetch_result($result, 0, "last_error"); | |
e1eb2147 AD |
3347 | |
3348 | if ($search) { | |
b36e002f | 3349 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
e1eb2147 | 3350 | } |
ef393de7 AD |
3351 | } |
3352 | ||
3353 | } else if ($feed == -1) { | |
d1db26aa | 3354 | $feed_title = __("Starred articles"); |
6cfa22dc | 3355 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } |
e4f4b46f | 3356 | } else if ($feed == -2) { |
3c88195b AD |
3357 | if (!$cat_view) { |
3358 | $feed_title = __("Published articles"); | |
3359 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } | |
3360 | } else { | |
3361 | $feed_title = __("Labels"); | |
3362 | } | |
2d24f032 AD |
3363 | } else if ($feed == -3) { |
3364 | $feed_title = __("Fresh articles"); | |
6cfa22dc | 3365 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } |
b2531a28 AD |
3366 | } else if ($feed == -4) { |
3367 | $feed_title = __("All articles"); | |
3368 | if ($search) { $feed_title = __("Searched for") . " $search ($feed_title)"; } | |
ef393de7 AD |
3369 | } else if ($feed < -10) { |
3370 | $label_id = -$feed - 11; | |
ceb30ba4 | 3371 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 |
ef393de7 | 3372 | WHERE id = '$label_id'"); |
ceb30ba4 | 3373 | $feed_title = db_fetch_result($result, 0, "caption"); |
88040f57 AD |
3374 | |
3375 | if ($search) { | |
b36e002f | 3376 | $feed_title = __("Searched for") . " $search ($feed_title)"; |
88040f57 | 3377 | } |
ef393de7 AD |
3378 | } else { |
3379 | $feed_title = "?"; | |
3380 | } | |
3381 | ||
62129e67 AD |
3382 | $content_query_part = "content as content_preview,"; |
3383 | ||
ef393de7 AD |
3384 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { |
3385 | ||
3386 | if ($feed >= 0) { | |
3387 | $feed_kind = "Feeds"; | |
3388 | } else { | |
3389 | $feed_kind = "Labels"; | |
3390 | } | |
3391 | ||
95a82c08 AD |
3392 | if ($limit_query_part) { |
3393 | $offset_query_part = "OFFSET $offset"; | |
3394 | } | |
3395 | ||
d00f22ac | 3396 | if ($vfeed_query_part && get_pref($link, 'VFEED_GROUP_BY_FEED', $owner_uid)) { |
6cfea5c7 | 3397 | if (!$override_order) { |
43fc671f AD |
3398 | $order_by = "ttrss_feeds.title, $order_by"; |
3399 | } | |
3400 | ||
a91c7082 AD |
3401 | // Special output for Fresh feed |
3402 | ||
3403 | /* if ($feed == -3) { | |
43fc671f AD |
3404 | $group_limit_part = "(select count(*) from |
3405 | ttrss_user_entries AS t1, ttrss_entries AS t2 where | |
3406 | t1.ref_id = t2.id and t1.owner_uid = 2 and | |
3407 | t1.feed_id = ttrss_user_entries.feed_id and | |
3408 | t2.updated > ttrss_entries.updated) <= 5 AND"; | |
a91c7082 | 3409 | } */ |
6cfea5c7 AD |
3410 | } |
3411 | ||
3ebd7ca5 | 3412 | $query = "SELECT DISTINCT |
1f64b1be | 3413 | guid, |
ef393de7 | 3414 | ttrss_entries.id,ttrss_entries.title, |
46921916 | 3415 | updated, |
c7e51de1 | 3416 | note, |
e4f4b46f | 3417 | unread,feed_id,marked,published,link,last_read, |
fc2b26a6 | 3418 | ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, |
ef393de7 AD |
3419 | $vfeed_query_part |
3420 | $content_query_part | |
fc2b26a6 | 3421 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, |
ff6e357a | 3422 | author,score |
ef393de7 | 3423 | FROM |
ceb30ba4 | 3424 | ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part |
ef393de7 | 3425 | WHERE |
43fc671f | 3426 | $group_limit_part |
546499a9 | 3427 | ttrss_feeds.hidden = false AND |
ef393de7 AD |
3428 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
3429 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
c36bf4d5 | 3430 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
3431 | $search_query_part |
3432 | $view_query_part | |
3433 | $query_strategy_part ORDER BY $order_by | |
95a82c08 | 3434 | $limit_query_part $offset_query_part"; |
4bc311fc | 3435 | |
ef393de7 | 3436 | if ($_GET["debug"]) print $query; |
4bc311fc AD |
3437 | |
3438 | $result = db_query($link, $query); | |
ef393de7 AD |
3439 | |
3440 | } else { | |
3441 | // browsing by tag | |
3442 | ||
3443 | $feed_kind = "Tags"; | |
3444 | ||
3445 | $result = db_query($link, "SELECT | |
1f64b1be | 3446 | guid, |
c7e51de1 | 3447 | note, |
ef393de7 | 3448 | ttrss_entries.id as id,title, |
46921916 | 3449 | updated, |
ef393de7 AD |
3450 | unread,feed_id, |
3451 | marked,link,last_read, | |
fc2b26a6 | 3452 | ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms, |
ef393de7 AD |
3453 | $vfeed_query_part |
3454 | $content_query_part | |
4d0b3607 AD |
3455 | ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms, |
3456 | score | |
ef393de7 AD |
3457 | FROM |
3458 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
3459 | WHERE | |
546499a9 | 3460 | ref_id = ttrss_entries.id AND |
c36bf4d5 | 3461 | ttrss_user_entries.owner_uid = '$owner_uid' AND |
ef393de7 AD |
3462 | post_int_id = int_id AND tag_name = '$feed' AND |
3463 | $view_query_part | |
3464 | $search_query_part | |
3465 | $query_strategy_part ORDER BY $order_by | |
3466 | $limit_query_part"); | |
3467 | } | |
3468 | ||
c7188969 | 3469 | return array($result, $feed_title, $feed_site_url, $last_error); |
ef393de7 AD |
3470 | |
3471 | } | |
3472 | ||
c36bf4d5 | 3473 | function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat, |
ead2715d AD |
3474 | $limit, $search, $search_mode, $match_on) { |
3475 | ||
c7e51de1 AD |
3476 | $note_style = "background-color : #fff7d5; border-width : 1px; ". |
3477 | "padding : 5px; border-style : dashed; border-color : #e7d796;". | |
3478 | "margin-top : 5px; color : #9a8c59;"; | |
3479 | ||
ead2715d | 3480 | if (!$limit) $limit = 30; |
18664970 AD |
3481 | |
3482 | $qfh_ret = queryFeedHeadlines($link, $feed, | |
ead2715d | 3483 | $limit, false, $is_cat, $search, $search_mode, $match_on, "updated DESC", 0, |
c36bf4d5 | 3484 | $owner_uid); |
18664970 AD |
3485 | |
3486 | $result = $qfh_ret[0]; | |
59e2aab4 | 3487 | $feed_title = htmlspecialchars($qfh_ret[1]); |
18664970 AD |
3488 | $feed_site_url = $qfh_ret[2]; |
3489 | $last_error = $qfh_ret[3]; | |
3490 | ||
a5472764 | 3491 | // if (!$feed_site_url) $feed_site_url = "http://localhost/"; |
4bc64807 | 3492 | |
a5472764 AD |
3493 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?> |
3494 | <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?> | |
3495 | <rss version=\"2.0\"> | |
3baeeeca AD |
3496 | <channel> |
3497 | <title>$feed_title</title> | |
4bc64807 AD |
3498 | <link>$feed_site_url</link> |
3499 | <description>Feed generated by Tiny Tiny RSS</description>"; | |
3baeeeca AD |
3500 | |
3501 | while ($line = db_fetch_assoc($result)) { | |
3502 | print "<item>"; | |
4bc64807 | 3503 | print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>"; |
3baeeeca | 3504 | print "<link>" . htmlspecialchars($line["link"]) . "</link>"; |
0c3d1c68 | 3505 | |
bc976a8c | 3506 | $tags = get_article_tags($link, $line["id"], $owner_uid); |
0c3d1c68 AD |
3507 | |
3508 | foreach ($tags as $tag) { | |
3509 | print "<category>" . htmlspecialchars($tag) . "</category>"; | |
3510 | } | |
3511 | ||
3baeeeca AD |
3512 | $rfc822_date = date('r', strtotime($line["updated"])); |
3513 | ||
3514 | print "<pubDate>$rfc822_date</pubDate>"; | |
3515 | ||
3516 | print "<title>" . | |
3517 | htmlspecialchars($line["title"]) . "</title>"; | |
3518 | ||
c7e51de1 AD |
3519 | print "<description><![CDATA["; |
3520 | print $line["content_preview"]; | |
3521 | if ($line["note"]) { | |
3522 | print "<div style='$note_style'>"; | |
3523 | print $line["note"]; | |
3524 | print "</div>"; | |
3525 | } | |
3526 | print "]]></description>"; | |
3baeeeca AD |
3527 | |
3528 | print "</item>"; | |
3529 | } | |
3530 | ||
3531 | print "</channel></rss>"; | |
18664970 AD |
3532 | |
3533 | } | |
3534 | ||
0a6c4846 AD |
3535 | function getCategoryTitle($link, $cat_id) { |
3536 | ||
bba7c4bf AD |
3537 | if ($cat_id == -1) { |
3538 | return __("Special"); | |
3539 | } else if ($cat_id == -2) { | |
3540 | return __("Labels"); | |
0a6c4846 | 3541 | } else { |
bba7c4bf AD |
3542 | |
3543 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories WHERE | |
3544 | id = '$cat_id'"); | |
3545 | ||
3546 | if (db_num_rows($result) == 1) { | |
3547 | return db_fetch_result($result, 0, "title"); | |
3548 | } else { | |
3549 | return "Uncategorized"; | |
3550 | } | |
0a6c4846 AD |
3551 | } |
3552 | } | |
3553 | ||
f45a286b AD |
3554 | function strip_tags_long($string, $allowed) { |
3555 | ||
3556 | $config = HTMLPurifier_Config::createDefault(); | |
3557 | ||
3558 | $config->set('HTML', 'Allowed', $allowed); | |
3559 | $purifier = new HTMLPurifier($config); | |
3560 | ||
3561 | return $purifier->purify($string); | |
3562 | ||
3563 | } | |
3564 | ||
f738aef1 AD |
3565 | // http://ru2.php.net/strip-tags |
3566 | ||
f45a286b | 3567 | /* function strip_tags_long($textstring, $allowed){ |
f738aef1 AD |
3568 | while($textstring != strip_tags($textstring, $allowed)) |
3569 | { | |
3570 | while (strlen($textstring) != 0) | |
3571 | { | |
3572 | if (strlen($textstring) > 1024) { | |
3573 | $otherlen = 1024; | |
3574 | } else { | |
3575 | $otherlen = strlen($textstring); | |
3576 | } | |
3577 | $temptext = strip_tags(substr($textstring,0,$otherlen), $allowed); | |
3578 | $safetext .= $temptext; | |
3579 | $textstring = substr_replace($textstring,'',0,$otherlen); | |
3580 | } | |
3581 | $textstring = $safetext; | |
3582 | } | |
3583 | return $textstring; | |
f45a286b | 3584 | } */ |
f738aef1 AD |
3585 | |
3586 | ||
1ac0baf4 | 3587 | function sanitize_rss($link, $str, $force_strip_tags = false) { |
60452879 | 3588 | $res = $str; |
183ad07b | 3589 | |
1ac0baf4 | 3590 | if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) { |
f738aef1 | 3591 | |
f45a286b AD |
3592 | // $res = strip_tags_long($res, |
3593 | // "<p><a><i><em><b><strong><code><pre><blockquote><br><img><ul><ol><li>"); | |
3594 | ||
7e1265ed | 3595 | $res = strip_tags_long($res, |
f45a286b | 3596 | "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4"); |
f738aef1 | 3597 | |
f826eee1 AD |
3598 | } |
3599 | ||
8dccabed AD |
3600 | if (get_pref($link, "STRIP_IMAGES")) { |
3601 | ||
3602 | $res = preg_replace('/<img[^>]+>/is', '', $res); | |
3603 | ||
3604 | } | |
3605 | ||
183ad07b AD |
3606 | return $res; |
3607 | } | |
b72c3ef8 | 3608 | |
45004d43 AD |
3609 | /** |
3610 | * Send by mail a digest of last articles. | |
3611 | * | |
3612 | * @param mixed $link The database connection. | |
3613 | * @param integer $limit The maximum number of articles by digest. | |
3614 | * @return boolean Return false if digests are not enabled. | |
3615 | */ | |
9cd7c995 AD |
3616 | function send_headlines_digests($link, $limit = 100) { |
3617 | ||
1ddba275 AD |
3618 | if (!DIGEST_ENABLE) return false; |
3619 | ||
9cd7c995 | 3620 | $user_limit = DIGEST_EMAIL_LIMIT; |
5430c959 | 3621 | $days = 1; |
9cd7c995 AD |
3622 | |
3623 | print "Sending digests, batch of max $user_limit users, days = $days, headline limit = $limit\n\n"; | |
3624 | ||
3625 | if (DB_TYPE == "pgsql") { | |
3626 | $interval_query = "last_digest_sent < NOW() - INTERVAL '$days days'"; | |
3627 | } else if (DB_TYPE == "mysql") { | |
3628 | $interval_query = "last_digest_sent < DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3629 | } | |
3630 | ||
3631 | $result = db_query($link, "SELECT id,email FROM ttrss_users | |
3632 | WHERE email != '' AND (last_digest_sent IS NULL OR $interval_query)"); | |
3633 | ||
3634 | while ($line = db_fetch_assoc($result)) { | |
dc85be2b | 3635 | |
9cd7c995 AD |
3636 | if (get_pref($link, 'DIGEST_ENABLE', $line['id'], false)) { |
3637 | print "Sending digest for UID:" . $line['id'] . " - " . $line["email"] . " ... "; | |
3638 | ||
dc85be2b AD |
3639 | $do_catchup = get_pref($link, 'DIGEST_CATCHUP', $line['id'], false); |
3640 | ||
9cd7c995 AD |
3641 | $tuple = prepare_headlines_digest($link, $line["id"], $days, $limit); |
3642 | $digest = $tuple[0]; | |
3643 | $headlines_count = $tuple[1]; | |
dc85be2b | 3644 | $affected_ids = $tuple[2]; |
c62a2c21 | 3645 | $digest_text = $tuple[3]; |
9cd7c995 AD |
3646 | |
3647 | if ($headlines_count > 0) { | |
a8931123 | 3648 | |
c62a2c21 | 3649 | $mail = new PHPMailer(); |
a8931123 | 3650 | |
d134e3a3 AD |
3651 | $mail->PluginDir = "lib/phpmailer/"; |
3652 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
a8931123 | 3653 | |
c62a2c21 | 3654 | $mail->CharSet = "UTF-8"; |
a8931123 | 3655 | |
c62a2c21 AD |
3656 | $mail->From = DIGEST_FROM_ADDRESS; |
3657 | $mail->FromName = DIGEST_FROM_NAME; | |
3658 | $mail->AddAddress($line["email"], $line["login"]); | |
c7ddac5c | 3659 | |
c62a2c21 | 3660 | if (DIGEST_SMTP_HOST) { |
a8931123 AD |
3661 | $mail->Host = DIGEST_SMTP_HOST; |
3662 | $mail->Mailer = "smtp"; | |
19a1da0d | 3663 | $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; |
a8931123 AD |
3664 | $mail->Username = DIGEST_SMTP_LOGIN; |
3665 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
c62a2c21 | 3666 | } |
a8931123 | 3667 | |
c62a2c21 | 3668 | $mail->IsHTML(true); |
163a295e | 3669 | $mail->Subject = DIGEST_SUBJECT; |
c62a2c21 AD |
3670 | $mail->Body = $digest; |
3671 | $mail->AltBody = $digest_text; | |
a8931123 | 3672 | |
c62a2c21 | 3673 | $rc = $mail->Send(); |
a8931123 | 3674 | |
c62a2c21 | 3675 | if (!$rc) print "ERROR: " . $mail->ErrorInfo; |
a8931123 | 3676 | |
9cd7c995 | 3677 | print "RC=$rc\n"; |
a8931123 | 3678 | |
c62a2c21 | 3679 | if ($rc && $do_catchup) { |
dc85be2b | 3680 | print "Marking affected articles as read...\n"; |
9968d46f | 3681 | catchupArticlesById($link, $affected_ids, 0, $line["id"]); |
dc85be2b AD |
3682 | } |
3683 | ||
9cd7c995 AD |
3684 | db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW() |
3685 | WHERE id = " . $line["id"]); | |
3686 | } else { | |
3687 | print "No headlines\n"; | |
3688 | } | |
3689 | } | |
3690 | } | |
3691 | ||
cedd3e89 AD |
3692 | print "All done.\n"; |
3693 | ||
9cd7c995 AD |
3694 | } |
3695 | ||
7e3634d9 | 3696 | function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) { |
c62a2c21 | 3697 | |
fe7537b5 | 3698 | require_once "lib/MiniTemplator.class.php"; |
c62a2c21 AD |
3699 | |
3700 | $tpl = new MiniTemplator; | |
3701 | $tpl_t = new MiniTemplator; | |
3702 | ||
3703 | $tpl->readTemplateFromFile("templates/digest_template_html.txt"); | |
3704 | $tpl_t->readTemplateFromFile("templates/digest_template.txt"); | |
3705 | ||
3706 | $tpl->setVariable('CUR_DATE', date('Y/m/d')); | |
3707 | $tpl->setVariable('CUR_TIME', date('G:i')); | |
3708 | ||
3709 | $tpl_t->setVariable('CUR_DATE', date('Y/m/d')); | |
3710 | $tpl_t->setVariable('CUR_TIME', date('G:i')); | |
7e3634d9 | 3711 | |
dc85be2b AD |
3712 | $affected_ids = array(); |
3713 | ||
7e3634d9 | 3714 | if (DB_TYPE == "pgsql") { |
9cd7c995 | 3715 | $interval_query = "ttrss_entries.date_entered > NOW() - INTERVAL '$days days'"; |
7e3634d9 AD |
3716 | } else if (DB_TYPE == "mysql") { |
3717 | $interval_query = "ttrss_entries.date_entered > DATE_SUB(NOW(), INTERVAL $days DAY)"; | |
3718 | } | |
3719 | ||
3720 | $result = db_query($link, "SELECT ttrss_entries.title, | |
3721 | ttrss_feeds.title AS feed_title, | |
3722 | date_entered, | |
dc85be2b | 3723 | ttrss_user_entries.ref_id, |
7e3634d9 | 3724 | link, |
c62a2c21 | 3725 | SUBSTRING(content, 1, 120) AS excerpt, |
fc2b26a6 | 3726 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
7e3634d9 AD |
3727 | FROM |
3728 | ttrss_user_entries,ttrss_entries,ttrss_feeds | |
3729 | WHERE | |
3730 | ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id | |
3dd9183c | 3731 | AND include_in_digest = true |
7e3634d9 | 3732 | AND $interval_query |
a8931123 | 3733 | AND hidden = false |
448b0abd | 3734 | AND ttrss_user_entries.owner_uid = $user_id |
c62a2c21 AD |
3735 | AND unread = true |
3736 | ORDER BY ttrss_feeds.title, date_entered DESC | |
7e3634d9 AD |
3737 | LIMIT $limit"); |
3738 | ||
3739 | $cur_feed_title = ""; | |
3740 | ||
9cd7c995 AD |
3741 | $headlines_count = db_num_rows($result); |
3742 | ||
c62a2c21 AD |
3743 | $headlines = array(); |
3744 | ||
7e3634d9 | 3745 | while ($line = db_fetch_assoc($result)) { |
c62a2c21 AD |
3746 | array_push($headlines, $line); |
3747 | } | |
3748 | ||
3749 | for ($i = 0; $i < sizeof($headlines); $i++) { | |
3750 | ||
3751 | $line = $headlines[$i]; | |
dc85be2b AD |
3752 | |
3753 | array_push($affected_ids, $line["ref_id"]); | |
3754 | ||
7e3634d9 | 3755 | $updated = smart_date_time(strtotime($line["last_updated"])); |
7e3634d9 | 3756 | |
c62a2c21 AD |
3757 | $tpl->setVariable('FEED_TITLE', $line["feed_title"]); |
3758 | $tpl->setVariable('ARTICLE_TITLE', $line["title"]); | |
3759 | $tpl->setVariable('ARTICLE_LINK', $line["link"]); | |
3760 | $tpl->setVariable('ARTICLE_UPDATED', $updated); | |
163a295e AD |
3761 | $tpl->setVariable('ARTICLE_EXCERPT', |
3762 | truncate_string(strip_tags($line["excerpt"]), 100)); | |
7e3634d9 | 3763 | |
c62a2c21 AD |
3764 | $tpl->addBlock('article'); |
3765 | ||
3766 | $tpl_t->setVariable('FEED_TITLE', $line["feed_title"]); | |
3767 | $tpl_t->setVariable('ARTICLE_TITLE', $line["title"]); | |
3768 | $tpl_t->setVariable('ARTICLE_LINK', $line["link"]); | |
3769 | $tpl_t->setVariable('ARTICLE_UPDATED', $updated); | |
3770 | // $tpl_t->setVariable('ARTICLE_EXCERPT', | |
3771 | // truncate_string(strip_tags($line["excerpt"]), 100)); | |
3772 | ||
3773 | $tpl_t->addBlock('article'); | |
3774 | ||
3775 | if ($headlines[$i]['feed_title'] != $headlines[$i+1]['feed_title']) { | |
3776 | $tpl->addBlock('feed'); | |
3777 | $tpl_t->addBlock('feed'); | |
7e3634d9 AD |
3778 | } |
3779 | ||
7e3634d9 AD |
3780 | } |
3781 | ||
c62a2c21 AD |
3782 | $tpl->addBlock('digest'); |
3783 | $tpl->generateOutputToString($tmp); | |
3784 | ||
3785 | $tpl_t->addBlock('digest'); | |
3786 | $tpl_t->generateOutputToString($tmp_t); | |
7e3634d9 | 3787 | |
c62a2c21 | 3788 | return array($tmp, $headlines_count, $affected_ids, $tmp_t); |
7e3634d9 AD |
3789 | } |
3790 | ||
73495fd1 | 3791 | function check_for_update($link) { |
b6d486a3 | 3792 | $releases_feed = "http://tt-rss.org/releases.rss"; |
b72c3ef8 AD |
3793 | |
3794 | if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) { | |
3795 | return; | |
3796 | } | |
3797 | ||
3798 | error_reporting(0); | |
f67d9754 AD |
3799 | if (ENABLE_SIMPLEPIE) { |
3800 | $rss = new SimplePie(); | |
3801 | $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT); | |
4148e809 | 3802 | // $rss->set_timeout(MAGPIE_FETCH_TIME_OUT); |
f67d9754 AD |
3803 | $rss->set_feed_url($fetch_url); |
3804 | $rss->set_output_encoding('UTF-8'); | |
3805 | $rss->init(); | |
3806 | } else { | |
3807 | $rss = fetch_rss($releases_feed); | |
3808 | } | |
b72c3ef8 AD |
3809 | error_reporting (DEFAULT_ERROR_LEVEL); |
3810 | ||
3811 | if ($rss) { | |
3812 | ||
f67d9754 AD |
3813 | if (ENABLE_SIMPLEPIE) { |
3814 | $items = $rss->get_items(); | |
3815 | } else { | |
3816 | $items = $rss->items; | |
b72c3ef8 | 3817 | |
f67d9754 AD |
3818 | if (!$items || !is_array($items)) $items = $rss->entries; |
3819 | if (!$items || !is_array($items)) $items = $rss; | |
3820 | } | |
b72c3ef8 | 3821 | |
da412ad3 | 3822 | if (!is_array($items) || count($items) == 0) { |
b72c3ef8 | 3823 | return; |
da412ad3 | 3824 | } |
b72c3ef8 | 3825 | |
a41d2c65 | 3826 | $latest_item = $items[0]; |
b72c3ef8 | 3827 | |
f67d9754 AD |
3828 | if (ENABLE_SIMPLEPIE) { |
3829 | $last_title = $latest_item->get_title(); | |
3830 | } else { | |
3831 | $last_title = $latest_item["title"]; | |
3832 | } | |
b72c3ef8 | 3833 | |
f67d9754 AD |
3834 | $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $last_title)); |
3835 | ||
3836 | if (ENABLE_SIMPLEPIE) { | |
dcf7fd08 AD |
3837 | $release_url = sanitize_rss($link, $latest_item->get_link()); |
3838 | $content = sanitize_rss($link, $latest_item->get_description()); | |
f67d9754 AD |
3839 | } else { |
3840 | $release_url = sanitize_rss($link, $latest_item["link"]); | |
3841 | $content = sanitize_rss($link, $latest_item["description"]); | |
3842 | } | |
48e1a342 | 3843 | |
a41d2c65 | 3844 | if (version_compare(VERSION, $latest_version) == -1) { |
73495fd1 AD |
3845 | return sprintf("New version of Tiny-Tiny RSS (%s) is available:", |
3846 | $latest_version)."<div class='milestoneDetails'>$content</div>"; | |
3847 | } else { | |
3848 | return false; | |
3849 | } | |
b72c3ef8 AD |
3850 | } |
3851 | } | |
472782e8 | 3852 | |
18eddb2c AD |
3853 | function markArticlesById($link, $ids, $cmode) { |
3854 | ||
3855 | $tmp_ids = array(); | |
3856 | ||
3857 | foreach ($ids as $id) { | |
3858 | array_push($tmp_ids, "ref_id = '$id'"); | |
3859 | } | |
3860 | ||
3861 | $ids_qpart = join(" OR ", $tmp_ids); | |
3862 | ||
3863 | if ($cmode == 0) { | |
3864 | db_query($link, "UPDATE ttrss_user_entries SET | |
3865 | marked = false,last_read = NOW() | |
3866 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3867 | } else if ($cmode == 1) { | |
3868 | db_query($link, "UPDATE ttrss_user_entries SET | |
3869 | marked = true | |
3870 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3871 | } else { | |
3872 | db_query($link, "UPDATE ttrss_user_entries SET | |
3873 | marked = NOT marked,last_read = NOW() | |
3874 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3875 | } | |
3876 | } | |
3877 | ||
e4f4b46f AD |
3878 | function publishArticlesById($link, $ids, $cmode) { |
3879 | ||
3880 | $tmp_ids = array(); | |
3881 | ||
3882 | foreach ($ids as $id) { | |
3883 | array_push($tmp_ids, "ref_id = '$id'"); | |
3884 | } | |
3885 | ||
3886 | $ids_qpart = join(" OR ", $tmp_ids); | |
3887 | ||
3888 | if ($cmode == 0) { | |
3889 | db_query($link, "UPDATE ttrss_user_entries SET | |
3890 | published = false,last_read = NOW() | |
3891 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3892 | } else if ($cmode == 1) { | |
3893 | db_query($link, "UPDATE ttrss_user_entries SET | |
3894 | published = true | |
3895 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3896 | } else { | |
3897 | db_query($link, "UPDATE ttrss_user_entries SET | |
3898 | published = NOT published,last_read = NOW() | |
3899 | WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]); | |
3900 | } | |
3901 | } | |
3902 | ||
9968d46f AD |
3903 | function catchupArticlesById($link, $ids, $cmode, $owner_uid = false) { |
3904 | ||
3905 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
472782e8 AD |
3906 | |
3907 | $tmp_ids = array(); | |
3908 | ||
3909 | foreach ($ids as $id) { | |
3910 | array_push($tmp_ids, "ref_id = '$id'"); | |
3911 | } | |
3912 | ||
3913 | $ids_qpart = join(" OR ", $tmp_ids); | |
3914 | ||
3915 | if ($cmode == 0) { | |
3916 | db_query($link, "UPDATE ttrss_user_entries SET | |
3917 | unread = false,last_read = NOW() | |
9968d46f | 3918 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 AD |
3919 | } else if ($cmode == 1) { |
3920 | db_query($link, "UPDATE ttrss_user_entries SET | |
3921 | unread = true | |
9968d46f | 3922 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 AD |
3923 | } else { |
3924 | db_query($link, "UPDATE ttrss_user_entries SET | |
3925 | unread = NOT unread,last_read = NOW() | |
9968d46f | 3926 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); |
472782e8 | 3927 | } |
0737b95a AD |
3928 | |
3929 | /* update ccache */ | |
3930 | ||
3931 | $result = db_query($link, "SELECT DISTINCT feed_id FROM ttrss_user_entries | |
3932 | WHERE ($ids_qpart) AND owner_uid = $owner_uid"); | |
3933 | ||
3934 | while ($line = db_fetch_assoc($result)) { | |
3935 | ccache_update($link, $line["feed_id"], $owner_uid); | |
3936 | } | |
472782e8 AD |
3937 | } |
3938 | ||
e097e8be AD |
3939 | function catchupArticleById($link, $id, $cmode) { |
3940 | ||
3941 | if ($cmode == 0) { | |
3942 | db_query($link, "UPDATE ttrss_user_entries SET | |
3943 | unread = false,last_read = NOW() | |
3944 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3945 | } else if ($cmode == 1) { | |
3946 | db_query($link, "UPDATE ttrss_user_entries SET | |
3947 | unread = true | |
3948 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3949 | } else { | |
3950 | db_query($link, "UPDATE ttrss_user_entries SET | |
3951 | unread = NOT unread,last_read = NOW() | |
3952 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
3953 | } | |
3954 | } | |
3955 | ||
1f64b1be AD |
3956 | function make_guid_from_title($title) { |
3957 | return preg_replace("/[ \"\',.:;]/", "-", | |
fefef828 | 3958 | mb_strtolower(strip_tags($title), 'utf-8')); |
1f64b1be AD |
3959 | } |
3960 | ||
11befbb2 | 3961 | function print_headline_subtoolbar($link, $feed_site_url, $feed_title, |
0ef68e6f AD |
3962 | $feed_id, $is_cat, $search, $match_on, |
3963 | $search_mode) { | |
e6c115b2 | 3964 | |
0ef68e6f | 3965 | print "<div class=\"headlinesSubToolbar\">"; |
11befbb2 | 3966 | |
e6c115b2 AD |
3967 | $page_prev_link = "javascript:viewFeedGoPage(-1)"; |
3968 | $page_next_link = "javascript:viewFeedGoPage(1)"; | |
3969 | $page_first_link = "javascript:viewFeedGoPage(0)"; | |
203de776 | 3970 | |
eb28b131 AD |
3971 | $catchup_page_link = "javascript:catchupPage()"; |
3972 | $catchup_feed_link = "javascript:catchupCurrentFeed()"; | |
a5ae125a | 3973 | $catchup_sel_link = "javascript:catchupSelection()"; |
c6008b62 | 3974 | |
11befbb2 AD |
3975 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
3976 | ||
c6008b62 AD |
3977 | $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; |
3978 | $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)"; | |
3979 | $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)"; | |
e75d70b5 | 3980 | $sel_inv_link = "javascript:invertHeadlineSelection()"; |
11befbb2 | 3981 | |
c6008b62 AD |
3982 | $tog_unread_link = "javascript:selectionToggleUnread()"; |
3983 | $tog_marked_link = "javascript:selectionToggleMarked()"; | |
e4f4b46f | 3984 | $tog_published_link = "javascript:selectionTogglePublished()"; |
11befbb2 | 3985 | |
c6008b62 | 3986 | } else { |
11befbb2 | 3987 | |
c6008b62 AD |
3988 | $sel_all_link = "javascript:cdmSelectArticles('all')"; |
3989 | $sel_unread_link = "javascript:cdmSelectArticles('unread')"; | |
3990 | $sel_none_link = "javascript:cdmSelectArticles('none')"; | |
3991 | ||
e75d70b5 AD |
3992 | $sel_inv_link = "javascript:invertHeadlineSelection()"; |
3993 | ||
c6008b62 AD |
3994 | $tog_unread_link = "javascript:selectionToggleUnread(true)"; |
3995 | $tog_marked_link = "javascript:selectionToggleMarked(true)"; | |
e4f4b46f | 3996 | $tog_published_link = "javascript:selectionTogglePublished(true)"; |
c6008b62 AD |
3997 | |
3998 | } | |
3999 | ||
0ef68e6f AD |
4000 | print "<div id=\"subtoolbar_ftitle\">"; |
4001 | ||
4002 | if ($feed_site_url) { | |
4003 | if (!$bottom) { | |
4004 | $target = "target=\"_blank\""; | |
4005 | } | |
4006 | print "<a $target href=\"$feed_site_url\">". | |
4007 | truncate_string($feed_title,30)."</a>"; | |
4008 | } else { | |
4009 | print $feed_title; | |
4010 | } | |
4011 | ||
4012 | if ($search) { | |
4013 | $search_q = "&q=$search&m=$match_on&smode=$search_mode"; | |
4014 | } | |
4015 | ||
4016 | print " | |
4017 | <a target=\"_blank\" | |
4018 | href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\"> | |
4019 | <img class=\"noborder\" | |
4020 | alt=\"".__('Generated feed')."\" src=\"images/feed-icon-12x12.png\"> | |
4021 | </a>"; | |
b8a637f3 | 4022 | |
0ef68e6f | 4023 | print "</div>"; |
ceb30ba4 | 4024 | |
d75ed3eb AD |
4025 | print __('Select:')." |
4026 | <a href=\"$sel_all_link\">".__('All')."</a>, | |
4027 | <a href=\"$sel_unread_link\">".__('Unread')."</a>, | |
4028 | <a href=\"$sel_inv_link\">".__('Invert')."</a>, | |
4029 | <a href=\"$sel_none_link\">".__('None')."</a></li>"; | |
bf3c9838 | 4030 | |
d75ed3eb | 4031 | print " "; |
bf3c9838 | 4032 | |
d75ed3eb AD |
4033 | print "<span |
4034 | onmouseover=\"enable_selection(false)\" | |
4035 | onmouseout=\"enable_selection(true)\" | |
4036 | onclick=\"toggleHeadlineActions()\" id=\"headlineActionsDrop\">". | |
4037 | __("Actions...") . " <img src=\"images/down_arrow.png\"> | |
4038 | </span>"; | |
bf3c9838 | 4039 | |
d75ed3eb | 4040 | print "<ul id=\"headlineActionsBody\" style=\"display : none\">"; |
bf3c9838 | 4041 | |
d75ed3eb AD |
4042 | print "<li class=\"insensitive\">".__('Selection toggle:')."</li> |
4043 | <li onclick=\"$tog_unread_link\"> ".__('Unread')."</li> | |
4044 | <li onclick=\"$tog_marked_link\"> ".__('Starred')."</li> | |
4045 | <li onclick=\"$tog_published_link\"> ".__('Published')."</li> | |
4046 | <!-- <li><span class=\"insensitive\">--------</span></li> --> | |
4047 | <li class=\"insensitive\">".__('Mark as read:')."</li> | |
4048 | <li onclick=\"$catchup_sel_link\"> ".__('Selection')."</li>"; | |
bf3c9838 | 4049 | |
d75ed3eb AD |
4050 | print "<li onclick=\"$catchup_feed_link\"> ".__('Entire feed'). |
4051 | "</li>"; | |
bf3c9838 | 4052 | |
d75ed3eb AD |
4053 | //print "<li><span class=\"insensitive\">--------</span></li>"; |
4054 | print "<li class=\"insensitive\">".__('Assign label:')."</li>"; | |
bf3c9838 | 4055 | |
79c88e11 | 4056 | print_labels_headlines_dropdown($link, $feed_id); |
c6008b62 | 4057 | |
d75ed3eb | 4058 | print "</ul>"; |
11befbb2 | 4059 | |
0ef68e6f | 4060 | print "</div>"; |
11befbb2 AD |
4061 | } |
4062 | ||
bba7c4bf AD |
4063 | function printCategoryHeader($link, $cat_id, $hidden = false, $can_browse = true) { |
4064 | ||
4065 | $tmp_category = getCategoryTitle($link, $cat_id); | |
cc914918 AD |
4066 | |
4067 | if ($cat_id > 0) { | |
4068 | $cat_unread = ccache_find($link, $cat_id, $_SESSION["uid"], true); | |
b2531a28 | 4069 | } else if ($cat_id == 0 || $cat_id == -2) { |
cc914918 AD |
4070 | $cat_unread = getCategoryUnread($link, $cat_id); |
4071 | } | |
bba7c4bf AD |
4072 | |
4073 | if ($hidden) { | |
4074 | $holder_style = "display:none;"; | |
66a251f9 | 4075 | $ellipsis = "…"; |
bba7c4bf AD |
4076 | } else { |
4077 | $holder_style = ""; | |
4078 | $ellipsis = ""; | |
4079 | } | |
4080 | ||
4081 | $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
4082 | ||
bba7c4bf | 4083 | if ($can_browse) { |
4c41e58f AD |
4084 | $browse_cat_link = "onclick=\"javascript:viewCategory($cat_id)\""; |
4085 | $inner_title_class = "catTitle"; | |
bba7c4bf | 4086 | } else { |
4c41e58f AD |
4087 | $browse_cat_link = ""; |
4088 | $inner_title_class = "catTitleNL"; | |
bba7c4bf AD |
4089 | } |
4090 | ||
2baedabe | 4091 | $cat_class = "feedCat"; |
364e391e AD |
4092 | |
4093 | print "<li class=\"$cat_class\" id=\"FCAT-$cat_id\"> | |
98fb6193 | 4094 | <img onclick=\"toggleCollapseCat($cat_id)\" class=\"catCollapse\" |
4c41e58f AD |
4095 | title=\"".__('Click to collapse category')."\" |
4096 | src=\"images/cat-collapse.png\"><span class=\"$inner_title_class\" | |
4097 | id=\"FCATN-$cat_id\" $browse_cat_link | |
4098 | \">$tmp_category</span>"; | |
4099 | ||
4100 | print "<span id=\"FCAP-$cat_id\">"; | |
4101 | ||
dda1396f | 4102 | print " <span id=\"FCATCTR-$cat_id\" |
bba7c4bf AD |
4103 | class=\"$catctr_class\">($cat_unread)</span> $ellipsis"; |
4104 | ||
4c41e58f | 4105 | print "</span>"; |
bba7c4bf | 4106 | |
782ddd70 | 4107 | //print "</li>"; |
bba7c4bf | 4108 | |
60ea2377 | 4109 | print "<ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>"; |
7abee14f | 4110 | |
bba7c4bf AD |
4111 | } |
4112 | ||
f407c086 AD |
4113 | function outputFeedList($link, $tags = false) { |
4114 | ||
3bd9a780 | 4115 | print "<ul class=\"feedList\" id=\"feedList\">"; |
f407c086 AD |
4116 | |
4117 | $owner_uid = $_SESSION["uid"]; | |
4118 | ||
cf4d339c | 4119 | /* virtual feeds */ |
f407c086 | 4120 | |
cf4d339c | 4121 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
3b086176 AD |
4122 | |
4123 | if ($_COOKIE["ttrss_vf_vclps"] == 1) { | |
bba7c4bf | 4124 | $cat_hidden = true; |
3b086176 | 4125 | } else { |
bba7c4bf | 4126 | $cat_hidden = false; |
3b086176 AD |
4127 | } |
4128 | ||
bba7c4bf | 4129 | printCategoryHeader($link, -1, $cat_hidden, false); |
cf4d339c | 4130 | } |
f407c086 | 4131 | |
cf4d339c | 4132 | $num_starred = getFeedUnread($link, -1); |
e4f4b46f | 4133 | $num_published = getFeedUnread($link, -2); |
2d24f032 | 4134 | $num_fresh = getFeedUnread($link, -3); |
b2531a28 AD |
4135 | $num_total = getFeedUnread($link, -4); |
4136 | ||
4137 | $class = "virt"; | |
4138 | ||
4139 | if ($num_total > 0) $class .= "Unread"; | |
4140 | ||
4141 | printFeedEntry(-4, $class, __("All articles"), $num_total, | |
4142 | "images/tag.png", $link); | |
2d24f032 AD |
4143 | |
4144 | $class = "virt"; | |
4145 | ||
4146 | if ($num_fresh > 0) $class .= "Unread"; | |
4147 | ||
4148 | printFeedEntry(-3, $class, __("Fresh articles"), $num_fresh, | |
4149 | "images/fresh.png", $link); | |
f407c086 | 4150 | |
cf4d339c | 4151 | $class = "virt"; |
f407c086 | 4152 | |
cf4d339c | 4153 | if ($num_starred > 0) $class .= "Unread"; |
f407c086 | 4154 | |
abd8a516 AD |
4155 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); |
4156 | ||
4157 | if ($is_ie) { | |
4158 | $mark_img_ext = "gif"; | |
4159 | } else { | |
4160 | $mark_img_ext = "png"; | |
4161 | } | |
4162 | ||
d1db26aa | 4163 | printFeedEntry(-1, $class, __("Starred articles"), $num_starred, |
abd8a516 | 4164 | "images/mark_set.$mark_img_ext", $link); |
f407c086 | 4165 | |
e4f4b46f AD |
4166 | $class = "virt"; |
4167 | ||
4168 | if ($num_published > 0) $class .= "Unread"; | |
4169 | ||
4170 | printFeedEntry(-2, $class, __("Published articles"), $num_published, | |
f5e0338d | 4171 | "images/pub_set.gif", $link); |
e4f4b46f | 4172 | |
cf4d339c | 4173 | if (get_pref($link, 'ENABLE_FEED_CATS')) { |
8b803aa2 | 4174 | print "</ul></li>"; |
cf4d339c | 4175 | } |
f407c086 | 4176 | |
cf4d339c | 4177 | if (!$tags) { |
f407c086 | 4178 | |
ceb30ba4 | 4179 | |
2eb9c95c | 4180 | $result = db_query($link, "SELECT * FROM |
ceb30ba4 | 4181 | ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption"); |
f407c086 AD |
4182 | |
4183 | if (db_num_rows($result) > 0) { | |
4184 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
bd64489f AD |
4185 | |
4186 | if ($_COOKIE["ttrss_vf_lclps"] == 1) { | |
bba7c4bf | 4187 | $cat_hidden = true; |
bd64489f | 4188 | } else { |
bba7c4bf | 4189 | $cat_hidden = false; |
bd64489f AD |
4190 | } |
4191 | ||
e6a38cde | 4192 | printCategoryHeader($link, -2, $cat_hidden, true); |
bd64489f | 4193 | |
f407c086 | 4194 | } else { |
3bd9a780 | 4195 | print "<li><hr></li>"; |
f407c086 AD |
4196 | } |
4197 | } | |
4198 | ||
4199 | while ($line = db_fetch_assoc($result)) { | |
4200 | ||
f407c086 AD |
4201 | $label_id = -$line['id'] - 11; |
4202 | $count = getFeedUnread($link, $label_id); | |
4203 | ||
4204 | $class = "label"; | |
4205 | ||
4206 | if ($count > 0) { | |
4207 | $class .= "Unread"; | |
4208 | } | |
f407c086 AD |
4209 | |
4210 | printFeedEntry($label_id, | |
ceb30ba4 | 4211 | $class, $line["caption"], |
2eb9c95c AD |
4212 | $count, "images/label.png", $link, |
4213 | false, false, false, | |
4214 | $line['fg_color'], $line['bg_color']); | |
f407c086 AD |
4215 | |
4216 | } | |
4217 | ||
4218 | if (db_num_rows($result) > 0) { | |
4219 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
4220 | print "</ul>"; | |
4221 | } | |
ceb30ba4 | 4222 | } |
f407c086 | 4223 | |
f407c086 AD |
4224 | |
4225 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 4226 | print "<li><hr></li>"; |
f407c086 AD |
4227 | } |
4228 | ||
4229 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
4230 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
9d393c84 | 4231 | $order_by_qpart = "order_id,category,unread DESC,title"; |
f407c086 | 4232 | } else { |
9d393c84 | 4233 | $order_by_qpart = "order_id,category,title"; |
f407c086 AD |
4234 | } |
4235 | } else { | |
4236 | if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) { | |
4237 | $order_by_qpart = "unread DESC,title"; | |
4238 | } else { | |
4239 | $order_by_qpart = "title"; | |
4240 | } | |
4241 | } | |
4242 | ||
14073c0a AD |
4243 | $age_qpart = getMaxAgeSubquery(); |
4244 | ||
99509451 | 4245 | $query = "SELECT ttrss_feeds.*, |
fc2b26a6 | 4246 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms, |
f407c086 AD |
4247 | cat_id,last_error, |
4248 | ttrss_feed_categories.title AS category, | |
d7135e2a AD |
4249 | ttrss_feed_categories.collapsed, |
4250 | value AS unread | |
4251 | FROM ttrss_feeds LEFT JOIN ttrss_feed_categories | |
4252 | ON (ttrss_feed_categories.id = cat_id) | |
4253 | LEFT JOIN ttrss_counters_cache | |
4254 | ON | |
4255 | (ttrss_feeds.id = feed_id) | |
f407c086 AD |
4256 | WHERE |
4257 | ttrss_feeds.hidden = false AND | |
4258 | ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL | |
99509451 AD |
4259 | ORDER BY $order_by_qpart"; |
4260 | ||
4261 | $result = db_query($link, $query); | |
f407c086 AD |
4262 | |
4263 | $actid = $_GET["actid"]; | |
4264 | ||
4265 | /* real feeds */ | |
4266 | ||
4267 | $lnum = 0; | |
4268 | ||
4269 | $total_unread = 0; | |
4270 | ||
4271 | $category = ""; | |
4272 | ||
4273 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4274 | ||
4275 | while ($line = db_fetch_assoc($result)) { | |
4276 | ||
70c9b173 | 4277 | $feed = htmlspecialchars(trim($line["title"])); |
0f39ae20 AD |
4278 | |
4279 | if (!$feed) $feed = "[Untitled]"; | |
4280 | ||
f407c086 | 4281 | $feed_id = $line["id"]; |
d7135e2a | 4282 | $unread = $line["unread"]; |
f407c086 AD |
4283 | |
4284 | $subop = $_GET["subop"]; | |
f407c086 AD |
4285 | |
4286 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4287 | $last_updated = smart_date_time(strtotime($line["last_updated_noms"])); | |
4288 | } else { | |
4289 | $last_updated = date($short_date, strtotime($line["last_updated_noms"])); | |
4290 | } | |
4291 | ||
4292 | $rtl_content = sql_bool_to_bool($line["rtl_content"]); | |
4293 | ||
4294 | if ($rtl_content) { | |
4295 | $rtl_tag = "dir=\"RTL\""; | |
4296 | } else { | |
4297 | $rtl_tag = ""; | |
4298 | } | |
4299 | ||
4300 | $tmp_result = db_query($link, | |
de0a2122 AD |
4301 | "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache |
4302 | WHERE parent_feed = '$feed_id' AND feed_id = id"); | |
f407c086 | 4303 | |
de0a2122 AD |
4304 | $unread += db_fetch_result($tmp_result, 0, "unread"); |
4305 | ||
f407c086 AD |
4306 | $cat_id = $line["cat_id"]; |
4307 | ||
4308 | $tmp_category = $line["category"]; | |
4309 | ||
4310 | if (!$tmp_category) { | |
d1db26aa | 4311 | $tmp_category = __("Uncategorized"); |
f407c086 AD |
4312 | } |
4313 | ||
4314 | // $class = ($lnum % 2) ? "even" : "odd"; | |
4315 | ||
4316 | if ($line["last_error"]) { | |
4317 | $class = "error"; | |
4318 | } else { | |
4319 | $class = "feed"; | |
4320 | } | |
4321 | ||
4322 | if ($unread > 0) $class .= "Unread"; | |
4323 | ||
4324 | if ($actid == $feed_id) { | |
4325 | $class .= "Selected"; | |
4326 | } | |
4327 | ||
4328 | $total_unread += $unread; | |
4329 | ||
4330 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
4331 | ||
4332 | if ($category) { | |
8b803aa2 | 4333 | print "</ul></li>"; |
f407c086 AD |
4334 | } |
4335 | ||
4336 | $category = $tmp_category; | |
4337 | ||
7abee14f | 4338 | $collapsed = sql_bool_to_bool($line["collapsed"]); |
f407c086 AD |
4339 | |
4340 | // workaround for NULL category | |
d1db26aa | 4341 | if ($category == __("Uncategorized")) { |
f407c086 AD |
4342 | if ($_COOKIE["ttrss_vf_uclps"] == 1) { |
4343 | $collapsed = "t"; | |
4344 | } | |
4345 | } | |
4346 | ||
f407c086 AD |
4347 | $cat_id = sprintf("%d", $cat_id); |
4348 | ||
7abee14f AD |
4349 | printCategoryHeader($link, $cat_id, $collapsed, true); |
4350 | ||
f407c086 AD |
4351 | } |
4352 | ||
4353 | printFeedEntry($feed_id, $class, $feed, $unread, | |
68dcbd31 | 4354 | ICONS_URL."/$feed_id.ico", $link, $rtl_content, |
f407c086 AD |
4355 | $last_updated, $line["last_error"]); |
4356 | ||
4357 | ++$lnum; | |
4358 | } | |
4359 | ||
4360 | if (db_num_rows($result) == 0) { | |
3bd9a780 | 4361 | print "<li>".__('No feeds to display.')."</li>"; |
f407c086 AD |
4362 | } |
4363 | ||
4364 | } else { | |
4365 | ||
4366 | // tags | |
4367 | ||
4368 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
4369 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
4370 | post_int_id = ttrss_user_entries.int_id AND | |
4371 | unread = true AND ref_id = ttrss_entries.id | |
4372 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
4373 | UNION | |
4374 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' | |
4375 | ORDER BY tag_name"); */ | |
4376 | ||
4377 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
d1db26aa | 4378 | print "<li class=\"feedCat\">".__('Tags')."</li>"; |
60ea2377 | 4379 | print "<ul class=\"feedCatList\">"; |
f407c086 AD |
4380 | } |
4381 | ||
14073c0a AD |
4382 | $age_qpart = getMaxAgeSubquery(); |
4383 | ||
f407c086 | 4384 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) |
14073c0a AD |
4385 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
4386 | AND ref_id = id AND $age_qpart | |
f407c086 | 4387 | AND unread = true)) AS count FROM ttrss_tags |
ef1ac7c7 AD |
4388 | WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name |
4389 | ORDER BY count DESC LIMIT 50"); | |
f407c086 AD |
4390 | |
4391 | $tags = array(); | |
4392 | ||
4393 | while ($line = db_fetch_assoc($result)) { | |
4394 | $tags[$line["tag_name"]] += $line["count"]; | |
4395 | } | |
4396 | ||
4397 | foreach (array_keys($tags) as $tag) { | |
4398 | ||
4399 | $unread = $tags[$tag]; | |
4400 | ||
4401 | $class = "tag"; | |
4402 | ||
4403 | if ($unread > 0) { | |
4404 | $class .= "Unread"; | |
4405 | } | |
4406 | ||
4407 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); | |
4408 | ||
4409 | } | |
4410 | ||
4411 | if (db_num_rows($result) == 0) { | |
4412 | print "<li>No tags to display.</li>"; | |
4413 | } | |
4414 | ||
4415 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3bd9a780 | 4416 | print "</ul>"; |
f407c086 AD |
4417 | } |
4418 | ||
4419 | } | |
4420 | ||
4421 | print "</ul>"; | |
4422 | ||
4423 | } | |
4424 | ||
bc976a8c | 4425 | function get_article_tags($link, $id, $owner_uid = 0) { |
0b126ac2 AD |
4426 | |
4427 | $a_id = db_escape_string($id); | |
4428 | ||
bc976a8c AD |
4429 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
4430 | ||
0c3d1c68 AD |
4431 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name, |
4432 | owner_uid as owner FROM | |
0b126ac2 | 4433 | ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
bc976a8c | 4434 | ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name"); |
0b126ac2 AD |
4435 | |
4436 | $tags = array(); | |
4437 | ||
4438 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
4439 | array_push($tags, $tmp_line["tag_name"]); | |
4440 | } | |
4441 | ||
4442 | return $tags; | |
4443 | } | |
4444 | ||
d62a3b63 AD |
4445 | function trim_value(&$value) { |
4446 | $value = trim($value); | |
4447 | } | |
4448 | ||
4449 | function trim_array($array) { | |
4450 | $tmp = $array; | |
4451 | array_walk($tmp, 'trim_value'); | |
4452 | return $tmp; | |
4453 | } | |
4454 | ||
be832a1a | 4455 | function tag_is_valid($tag) { |
ef063748 AD |
4456 | if ($tag == '') return false; |
4457 | if (preg_match("/^[0-9]*$/", $tag)) return false; | |
41f7498a | 4458 | if (mb_strlen($tag) > 250) return false; |
ef063748 | 4459 | |
31365729 AD |
4460 | if (function_exists('iconv')) { |
4461 | $tag = iconv("utf-8", "utf-8", $tag); | |
4462 | } | |
4463 | ||
ef063748 AD |
4464 | if (!$tag) return false; |
4465 | ||
4466 | return true; | |
be832a1a AD |
4467 | } |
4468 | ||
793185a9 AD |
4469 | function render_login_form($link, $mobile = false) { |
4470 | if (!$mobile) { | |
4471 | require_once "login_form.php"; | |
4472 | } else { | |
4473 | require_once "mobile/login_form.php"; | |
4474 | } | |
01a87dff AD |
4475 | } |
4476 | ||
dc56b3b7 AD |
4477 | // from http://developer.apple.com/internet/safari/faq.html |
4478 | function no_cache_incantation() { | |
4479 | header("Expires: Mon, 22 Dec 1980 00:00:00 GMT"); // Happy birthday to me :) | |
4480 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified | |
4481 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1 | |
4482 | header("Cache-Control: post-check=0, pre-check=0", false); | |
4483 | header("Pragma: no-cache"); // HTTP/1.0 | |
4484 | } | |
4485 | ||
42395d28 AD |
4486 | function format_warning($msg, $id = "") { |
4487 | return "<div class=\"warning\" id=\"$id\"> | |
e780d1d2 | 4488 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
0d32b41e AD |
4489 | } |
4490 | ||
4491 | function format_notice($msg) { | |
4492 | return "<div class=\"notice\"> | |
e780d1d2 | 4493 | <img src=\"images/sign_info.gif\">$msg</div>"; |
0d32b41e AD |
4494 | } |
4495 | ||
68d2f95e AD |
4496 | function format_error($msg) { |
4497 | return "<div class=\"error\"> | |
e780d1d2 | 4498 | <img src=\"images/sign_excl.gif\">$msg</div>"; |
68d2f95e AD |
4499 | } |
4500 | ||
4dccf1ed AD |
4501 | function print_notice($msg) { |
4502 | return print format_notice($msg); | |
4503 | } | |
4504 | ||
4505 | function print_warning($msg) { | |
4506 | return print format_warning($msg); | |
4507 | } | |
4508 | ||
68d2f95e AD |
4509 | function print_error($msg) { |
4510 | return print format_error($msg); | |
4511 | } | |
4512 | ||
4513 | ||
4dccf1ed AD |
4514 | function T_sprintf() { |
4515 | $args = func_get_args(); | |
4516 | return vsprintf(__(array_shift($args)), $args); | |
4517 | } | |
4518 | ||
eedfb635 AD |
4519 | function outputArticleXML($link, $id, $feed_id, $mark_as_read = true, |
4520 | $zoom_mode = false) { | |
3de0261a | 4521 | |
10eb9da8 AD |
4522 | /* we can figure out feed_id from article id anyway, why do we |
4523 | * pass feed_id here? */ | |
4524 | ||
4525 | $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries | |
4526 | WHERE ref_id = '$id'"); | |
4527 | ||
4528 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
4529 | ||
eedfb635 | 4530 | if (!$zoom_mode) { print "<article id='$id'><![CDATA["; }; |
3de0261a AD |
4531 | |
4532 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds | |
4533 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
4534 | ||
4535 | if (db_num_rows($result) == 1) { | |
4536 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4537 | } else { | |
4538 | $rtl_content = false; | |
4539 | } | |
4540 | ||
4541 | if ($rtl_content) { | |
4542 | $rtl_tag = "dir=\"RTL\""; | |
4543 | $rtl_class = "RTL"; | |
4544 | } else { | |
4545 | $rtl_tag = ""; | |
4546 | $rtl_class = ""; | |
4547 | } | |
4548 | ||
4549 | if ($mark_as_read) { | |
4550 | $result = db_query($link, "UPDATE ttrss_user_entries | |
4551 | SET unread = false,last_read = NOW() | |
4552 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
8a4c759e AD |
4553 | |
4554 | ccache_update($link, $feed_id, $_SESSION["uid"]); | |
3de0261a AD |
4555 | } |
4556 | ||
4557 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, | |
fc2b26a6 | 4558 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
3de0261a AD |
4559 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, |
4560 | num_comments, | |
c7e51de1 AD |
4561 | author, |
4562 | note | |
3de0261a AD |
4563 | FROM ttrss_entries,ttrss_user_entries |
4564 | WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]); | |
4565 | ||
4566 | if ($result) { | |
4567 | ||
4568 | $link_target = ""; | |
4569 | ||
4570 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { | |
e944346c | 4571 | $link_target = "target=\"_blank\""; |
3de0261a AD |
4572 | } |
4573 | ||
4574 | $line = db_fetch_assoc($result); | |
4575 | ||
4576 | if ($line["icon_url"]) { | |
4577 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
4578 | } else { | |
4579 | $feed_icon = " "; | |
4580 | } | |
4581 | ||
3de0261a AD |
4582 | $num_comments = $line["num_comments"]; |
4583 | $entry_comments = ""; | |
4584 | ||
4585 | if ($num_comments > 0) { | |
4586 | if ($line["comments"]) { | |
4587 | $comments_url = $line["comments"]; | |
4588 | } else { | |
4589 | $comments_url = $line["link"]; | |
4590 | } | |
4591 | $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>"; | |
4592 | } else { | |
4593 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
4594 | $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>"; | |
4595 | } | |
4596 | } | |
4597 | ||
eedfb635 AD |
4598 | if ($zoom_mode) { |
4599 | header("Content-Type: text/html"); | |
4600 | print "<html><head> | |
5bb0cc8e | 4601 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
eedfb635 AD |
4602 | <title>Tiny Tiny RSS - ".$line["title"]."</title> |
4603 | <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss.css\"> | |
4604 | </head><body>"; | |
4605 | } | |
4606 | ||
4607 | ||
3de0261a AD |
4608 | print "<div class=\"postReply\">"; |
4609 | ||
94047498 AD |
4610 | print "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" |
4611 | onmouseout=\"enable_resize(false)\">"; | |
3de0261a AD |
4612 | |
4613 | $entry_author = $line["author"]; | |
4614 | ||
4615 | if ($entry_author) { | |
60164936 | 4616 | $entry_author = __(" - ") . $entry_author; |
3de0261a AD |
4617 | } |
4618 | ||
4619 | $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4620 | strtotime($line["updated"])); | |
4621 | ||
4622 | print "<div class=\"postDate$rtl_class\">$parsed_updated</div>"; | |
4623 | ||
4624 | if ($line["link"]) { | |
4625 | print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" . | |
06202d88 | 4626 | $line["title"] . "</a><span class='author'>$entry_author</span></div>"; |
3de0261a AD |
4627 | } else { |
4628 | print "<div clear='both'>" . $line["title"] . "$entry_author</div>"; | |
4629 | } | |
4630 | ||
307d187c | 4631 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
e7544143 | 4632 | |
3de0261a AD |
4633 | if (!$entry_comments) $entry_comments = " "; # placeholder |
4634 | ||
5f014cf1 | 4635 | print "<div style='float : right'> |
c7e51de1 | 4636 | <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'> "; |
eedfb635 AD |
4637 | |
4638 | if (!$zoom_mode) { | |
307d187c | 4639 | print "<span id=\"ATSTR-$id\">$tags_str</span> |
eedfb635 | 4640 | <a title=\"".__('Edit tags for this article')."\" |
4710e3dc AD |
4641 | href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a>"; |
4642 | ||
4643 | if (defined('_ENABLE_INLINE_VIEW')) { | |
4644 | ||
4645 | print "<img src=\"images/art-inline.png\" class='tagsPic' | |
98fe7044 | 4646 | style=\"cursor : pointer\" style=\"cursor : pointer\" |
4710e3dc AD |
4647 | onclick=\"showOriginalArticleInline($id)\" |
4648 | alt='Inline' title='".__('Display original article content')."'>"; | |
4649 | ||
4650 | } | |
4651 | ||
4652 | print "<img src=\"images/art-zoom.png\" class='tagsPic' | |
98fe7044 | 4653 | style=\"cursor : pointer\" style=\"cursor : pointer\" |
eedfb635 AD |
4654 | onclick=\"zoomToArticle($id)\" |
4655 | alt='Zoom' title='".__('Show article summary in new window')."'>"; | |
c7e51de1 AD |
4656 | |
4657 | $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); | |
4658 | ||
4659 | print "<img src=\"images/art-pub-note.png\" class='tagsPic' | |
4660 | style=\"cursor : pointer\" style=\"cursor : pointer\" | |
4661 | onclick=\"publishWithNote($id, '$note_escaped')\" | |
4662 | alt='PubNote' title='".__('Publish article with a note')."'>"; | |
4663 | ||
eedfb635 AD |
4664 | } |
4665 | print "</div>"; | |
4666 | print "<div clear='both'>$entry_comments</div>"; | |
3de0261a AD |
4667 | |
4668 | print "</div>"; | |
4669 | ||
4670 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
64ab16ac | 4671 | |
3de0261a | 4672 | print "<div class=\"postContent\">"; |
64ab16ac | 4673 | |
c54526fe | 4674 | $article_content = sanitize_rss($link, $line["content"]); |
c41890b0 | 4675 | |
3de0261a | 4676 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
c54526fe AD |
4677 | $article_content = preg_replace("/href=/i", "target=\"_blank\" href=", |
4678 | $article_content); | |
3de0261a AD |
4679 | } |
4680 | ||
c54526fe | 4681 | print $article_content; |
ce53e200 | 4682 | |
c7e51de1 AD |
4683 | print "<div id=\"POSTNOTE-$id\">"; |
4684 | if ($line['note']) { | |
4685 | print format_article_note($id, $line['note']); | |
4686 | } | |
4687 | print "</div>"; | |
4688 | ||
ce53e200 | 4689 | $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE |
4752b041 | 4690 | post_id = '$id' AND content_url != ''"); |
ce53e200 AD |
4691 | |
4692 | if (db_num_rows($result) > 0) { | |
ce53e200 | 4693 | |
9c5ee7e1 | 4694 | $entries_html = array(); |
ce53e200 AD |
4695 | $entries = array(); |
4696 | ||
4697 | while ($line = db_fetch_assoc($result)) { | |
4698 | ||
4699 | $url = $line["content_url"]; | |
4752b041 AD |
4700 | $ctype = $line["content_type"]; |
4701 | ||
4702 | if (!$ctype) $ctype = __("unknown type"); | |
ce53e200 AD |
4703 | |
4704 | $filename = substr($url, strrpos($url, "/")+1); | |
4705 | ||
8dccabed AD |
4706 | $entry = ""; |
4707 | ||
95f67d2e AD |
4708 | if (substr($ctype,0,6)=="audio/" || $ctype=="application/ogg" || $ctype=="application/x-ogg") { |
4709 | $entry .= "<audio controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />"; | |
4710 | if (($ctype == __("audio/mpeg")) && | |
4711 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { | |
4712 | $entry .= "<div><object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object></div>"; | |
4713 | } | |
4714 | $entry .= "</audio>"; | |
4715 | if (($ctype == __("audio/mpeg")) && | |
4716 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { | |
4717 | $entry .= "<a id='switchToFlashLink' href='#' onclick='return switchToFlash(this)'>".__('Switch to Flash Player')."</a><br />"; | |
4718 | $entry .= "<script type='text/javascript'>html5AudioOrFlash('$ctype');</script>"; | |
4719 | } | |
4720 | } elseif (substr($ctype,0,6)=="video/") { | |
4721 | $entry .= "<video controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />"; | |
4722 | $entry .= "</video>"; | |
8dccabed AD |
4723 | } |
4724 | ||
4725 | $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" . | |
4752b041 | 4726 | $filename . " (" . $ctype . ")" . "</a>"; |
ce53e200 | 4727 | |
9c5ee7e1 AD |
4728 | array_push($entries_html, $entry); |
4729 | ||
4730 | $entry = array(); | |
4731 | ||
4732 | $entry["type"] = $ctype; | |
4733 | $entry["filename"] = $filename; | |
4734 | $entry["url"] = $url; | |
4735 | ||
ce53e200 AD |
4736 | array_push($entries, $entry); |
4737 | } | |
4738 | ||
9c5ee7e1 AD |
4739 | print "<div class=\"postEnclosures\">"; |
4740 | ||
5c421949 | 4741 | if (!preg_match("/<img/i", $article_content)) { |
9c5ee7e1 AD |
4742 | foreach ($entries as $entry) { |
4743 | if (preg_match("/image/", $entry["type"])) { | |
4744 | print "<p><img | |
4745 | alt=\"".htmlspecialchars($entry["filename"])."\" | |
4746 | src=\"" .htmlspecialchars($entry["url"]) . "\"></p>"; | |
4747 | } | |
4748 | } | |
4749 | } | |
4750 | ||
4751 | print "<div class=\"postEnclosures\">"; | |
4752 | ||
4753 | if (db_num_rows($result) == 1) { | |
4754 | print __("Attachment:") . " "; | |
4755 | } else { | |
4756 | print __("Attachments:") . " "; | |
4757 | } | |
4758 | ||
4759 | print join(", ", $entries_html); | |
ce53e200 AD |
4760 | |
4761 | print "</div>"; | |
4762 | } | |
4763 | ||
4764 | print "</div>"; | |
3de0261a AD |
4765 | |
4766 | print "</div>"; | |
4767 | ||
4768 | } | |
4769 | ||
eedfb635 AD |
4770 | if (!$zoom_mode) { |
4771 | print "]]></article>"; | |
4772 | } else { | |
4773 | print " | |
4774 | <div style=\"text-align : center\"> | |
4775 | <input type=\"submit\" onclick=\"return window.close()\" | |
4776 | value=\"".__("Close this window")."\"></div>"; | |
4777 | print "</body></html>"; | |
4778 | ||
4779 | } | |
3de0261a AD |
4780 | |
4781 | } | |
4782 | ||
4783 | function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, | |
7b4d02a8 AD |
4784 | $next_unread_feed, $offset, $vgr_last_feed = false, |
4785 | $override_order = false) { | |
3de0261a | 4786 | |
52d7e7da AD |
4787 | $disable_cache = false; |
4788 | ||
46921916 AD |
4789 | $timing_info = getmicrotime(); |
4790 | ||
961f4c73 AD |
4791 | $topmost_article_ids = array(); |
4792 | ||
ac541432 AD |
4793 | if (!$offset) { |
4794 | $offset = 0; | |
4795 | } | |
3de0261a AD |
4796 | |
4797 | if ($subop == "undefined") $subop = ""; | |
4798 | ||
a9bcfb8f AD |
4799 | $subop_split = split(":", $subop); |
4800 | ||
3de0261a AD |
4801 | if ($subop == "CatchupSelected") { |
4802 | $ids = split(",", db_escape_string($_GET["ids"])); | |
4803 | $cmode = sprintf("%d", $_GET["cmode"]); | |
4804 | ||
4805 | catchupArticlesById($link, $ids, $cmode); | |
4806 | } | |
4807 | ||
4808 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { | |
35bf080c | 4809 | update_generic_feed($link, $feed, $cat_view, true); |
3de0261a AD |
4810 | } |
4811 | ||
4812 | if ($subop == "MarkAllRead") { | |
4813 | catchup_feed($link, $feed, $cat_view); | |
4814 | ||
4815 | if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) { | |
4816 | if ($next_unread_feed) { | |
4817 | $feed = $next_unread_feed; | |
4818 | } | |
4819 | } | |
4820 | } | |
4821 | ||
a9bcfb8f AD |
4822 | if ($subop_split[0] == "MarkAllReadGR") { |
4823 | catchup_feed($link, $subop_split[1], false); | |
4824 | } | |
4825 | ||
4826 | ||
3de0261a AD |
4827 | if ($feed_id > 0) { |
4828 | $result = db_query($link, | |
4829 | "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); | |
4830 | ||
4831 | if (db_num_rows($result) == 0) { | |
4832 | print "<div align='center'>".__('Feed not found.')."</div>"; | |
4833 | return; | |
4834 | } | |
4835 | } | |
4836 | ||
4837 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
10eb9da8 | 4838 | |
3de0261a AD |
4839 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds |
4840 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
4841 | ||
4842 | if (db_num_rows($result) == 1) { | |
4843 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
4844 | } else { | |
4845 | $rtl_content = false; | |
4846 | } | |
4847 | ||
4848 | if ($rtl_content) { | |
4849 | $rtl_tag = "dir=\"RTL\""; | |
4850 | } else { | |
4851 | $rtl_tag = ""; | |
4852 | } | |
4853 | } else { | |
4854 | $rtl_tag = ""; | |
4855 | $rtl_content = false; | |
4856 | } | |
4857 | ||
4858 | $script_dt_add = get_script_dt_add(); | |
4859 | ||
4860 | /// START ///////////////////////////////////////////////////////////////////////////////// | |
4861 | ||
4862 | $search = db_escape_string($_GET["query"]); | |
52d7e7da AD |
4863 | |
4864 | if ($search) { | |
4865 | $disable_cache = true; | |
4866 | } | |
4867 | ||
3de0261a AD |
4868 | $search_mode = db_escape_string($_GET["search_mode"]); |
4869 | $match_on = db_escape_string($_GET["match_on"]); | |
4870 | ||
4871 | if (!$match_on) { | |
4872 | $match_on = "both"; | |
4873 | } | |
4874 | ||
4875 | $real_offset = $offset * $limit; | |
4876 | ||
46921916 AD |
4877 | if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info); |
4878 | ||
3de0261a | 4879 | $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, |
7b4d02a8 | 4880 | $search, $search_mode, $match_on, $override_order, $real_offset); |
3de0261a | 4881 | |
46921916 AD |
4882 | if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info); |
4883 | ||
3de0261a AD |
4884 | $result = $qfh_ret[0]; |
4885 | $feed_title = $qfh_ret[1]; | |
4886 | $feed_site_url = $qfh_ret[2]; | |
4887 | $last_error = $qfh_ret[3]; | |
f56e3080 | 4888 | |
081e527d AD |
4889 | $vgroup_last_feed = $vgr_last_feed; |
4890 | ||
f56e3080 AD |
4891 | if ($feed == -2) { |
4892 | $feed_site_url = article_publish_url($link); | |
4893 | } | |
4894 | ||
3de0261a AD |
4895 | /// STOP ////////////////////////////////////////////////////////////////////////////////// |
4896 | ||
ac541432 AD |
4897 | if (!$offset) { |
4898 | print "<div id=\"headlinesContainer\" $rtl_tag>"; | |
3de0261a | 4899 | |
ac541432 AD |
4900 | if (!$result) { |
4901 | print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>"; | |
4902 | return; | |
4903 | } | |
3de0261a | 4904 | |
0ef68e6f AD |
4905 | print_headline_subtoolbar($link, $feed_site_url, $feed_title, |
4906 | $feed, $cat_view, $search, $match_on, $search_mode); | |
3de0261a | 4907 | |
ac541432 AD |
4908 | print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">"; |
4909 | } | |
3de0261a | 4910 | |
29dfb258 AD |
4911 | $headlines_count = db_num_rows($result); |
4912 | ||
3de0261a AD |
4913 | if (db_num_rows($result) > 0) { |
4914 | ||
4915 | # print "\{$offset}"; | |
4916 | ||
ac541432 | 4917 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
4918 | print "<table class=\"headlinesList\" id=\"headlinesList\" |
4919 | cellspacing=\"0\">"; | |
4920 | } | |
4921 | ||
4ab4d364 AD |
4922 | $lnum = $limit*$offset; |
4923 | ||
3de0261a AD |
4924 | error_reporting (DEFAULT_ERROR_LEVEL); |
4925 | ||
4926 | $num_unread = 0; | |
6cfea5c7 AD |
4927 | $cur_feed_title = ''; |
4928 | ||
3de0261a AD |
4929 | while ($line = db_fetch_assoc($result)) { |
4930 | ||
4931 | $class = ($lnum % 2) ? "even" : "odd"; | |
4932 | ||
4933 | $id = $line["id"]; | |
4934 | $feed_id = $line["feed_id"]; | |
961f4c73 | 4935 | |
e2549229 | 4936 | $labels = get_article_labels($link, $id); |
e2549229 | 4937 | |
2eb9c95c AD |
4938 | $labels_str = "<span id=\"HLLCTR-$id\">"; |
4939 | $labels_str .= format_article_labels($labels, $id); | |
f9247195 | 4940 | $labels_str .= "</span>"; |
2eb9c95c | 4941 | |
961f4c73 AD |
4942 | if (count($topmost_article_ids) < 5) { |
4943 | array_push($topmost_article_ids, $id); | |
4944 | } | |
4945 | ||
3de0261a AD |
4946 | if ($line["last_read"] == "" && |
4947 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
4948 | ||
4949 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
4950 | alt=\"Updated\">"; | |
4951 | } else { | |
4952 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
4953 | alt=\"Updated\">"; | |
4954 | } | |
4955 | ||
4956 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
4957 | $class .= "Unread"; | |
4958 | ++$num_unread; | |
4959 | $is_unread = true; | |
4960 | } else { | |
4961 | $is_unread = false; | |
4962 | } | |
abd8a516 AD |
4963 | |
4964 | $is_ie = (strpos($_SESSION["client.userAgent"], "MSIE") !== false); | |
4965 | ||
4966 | if ($is_ie) { | |
4967 | $mark_img_ext = "gif"; | |
4968 | } else { | |
4969 | $mark_img_ext = "png"; | |
4970 | } | |
4971 | ||
3de0261a | 4972 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
abd8a516 | 4973 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_set.$mark_img_ext\" |
3de0261a | 4974 | class=\"markedPic\" |
f5e0338d | 4975 | alt=\"Unstar article\" onclick='javascript:tMark($id)'>"; |
3de0261a | 4976 | } else { |
abd8a516 | 4977 | $marked_pic = "<img id=\"FMPIC-$id\" src=\"images/mark_unset.$mark_img_ext\" |
3de0261a | 4978 | class=\"markedPic\" |
f5e0338d | 4979 | alt=\"Star article\" onclick='javascript:tMark($id)'>"; |
3de0261a AD |
4980 | } |
4981 | ||
e4f4b46f | 4982 | if ($line["published"] == "t" || $line["published"] == "1") { |
f5e0338d | 4983 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.gif\" |
e4f4b46f | 4984 | class=\"markedPic\" |
f5e0338d | 4985 | alt=\"Unpublish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f | 4986 | } else { |
f5e0338d | 4987 | $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.gif\" |
e4f4b46f | 4988 | class=\"markedPic\" |
f5e0338d | 4989 | alt=\"Publish article\" onclick='javascript:tPub($id)'>"; |
e4f4b46f AD |
4990 | } |
4991 | ||
e944346c | 4992 | # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . |
3de0261a AD |
4993 | # $line["title"] . "</a>"; |
4994 | ||
f0971fc1 AD |
4995 | # $content_link = "<a |
4996 | # href=\"" . htmlspecialchars($line["link"]) . "\" | |
4997 | # onclick=\"view($id,$feed_id);\">" . | |
4998 | # $line["title"] . "</a>"; | |
3de0261a AD |
4999 | |
5000 | # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . | |
5001 | # $line["title"] . "</a>"; | |
5002 | ||
5003 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
46921916 | 5004 | $updated_fmt = smart_date_time(strtotime($line["updated_noms"])); |
3de0261a AD |
5005 | } else { |
5006 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
46921916 | 5007 | $updated_fmt = date($short_date, strtotime($line["updated_noms"])); |
3de0261a AD |
5008 | } |
5009 | ||
5010 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
5011 | $content_preview = truncate_string(strip_tags($line["content_preview"]), | |
5012 | 100); | |
5013 | } | |
5014 | ||
ff6e357a AD |
5015 | $score = $line["score"]; |
5016 | ||
1e36af0c | 5017 | $score_pic = get_score_pic($score); |
546499a9 | 5018 | |
9bf3f101 AD |
5019 | /* $score_title = __("(Click to change)"); |
5020 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" | |
5021 | onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */ | |
546499a9 | 5022 | |
5daa24f2 | 5023 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" |
9bf3f101 | 5024 | title=\"$score\">"; |
ff6e357a | 5025 | |
5daa24f2 AD |
5026 | if ($score > 500) { |
5027 | $hlc_suffix = "H"; | |
5028 | } else if ($score < -100) { | |
5029 | $hlc_suffix = "L"; | |
5030 | } else { | |
5031 | $hlc_suffix = ""; | |
5032 | } | |
5033 | ||
3de0261a AD |
5034 | $entry_author = $line["author"]; |
5035 | ||
5036 | if ($entry_author) { | |
60164936 | 5037 | $entry_author = " - $entry_author"; |
3de0261a AD |
5038 | } |
5039 | ||
7defa089 | 5040 | $has_feed_icon = feed_has_icon($feed_id); |
bd51294a AD |
5041 | |
5042 | if ($has_feed_icon) { | |
5043 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
5044 | } else { | |
5045 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; | |
20be0cf8 | 5046 | $feed_icon_img = ""; |
bd51294a AD |
5047 | } |
5048 | ||
3de0261a | 5049 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { |
6cfea5c7 | 5050 | |
d00f22ac | 5051 | if (get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
bb031f91 | 5052 | if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { |
a9bcfb8f AD |
5053 | |
5054 | $cur_feed_title = $line["feed_title"]; | |
081e527d | 5055 | $vgroup_last_feed = $feed_id; |
a9bcfb8f | 5056 | |
962d8ba4 | 5057 | $cur_feed_title = htmlspecialchars($cur_feed_title); |
43fc671f | 5058 | |
af163b85 | 5059 | $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)"; |
a9bcfb8f | 5060 | |
6cfea5c7 | 5061 | print "<tr class='feedTitle'><td colspan='7'>". |
dc803347 | 5062 | "<div style=\"float : right\">$feed_icon_img</div>". |
6cfea5c7 | 5063 | "<a href=\"javascript:viewfeed($feed_id, '', false)\">". |
965fb2af | 5064 | $line["feed_title"]."</a> $vf_catchup_link</td></tr>"; |
6cfea5c7 AD |
5065 | } |
5066 | } | |
314fcd2b AD |
5067 | |
5068 | $mouseover_attrs = "onmouseover='postMouseIn($id)' | |
5069 | onmouseout='postMouseOut($id)'"; | |
5070 | ||
5071 | print "<tr class='$class' id='RROW-$id' $mouseover_attrs>"; | |
3de0261a | 5072 | |
67343d9f | 5073 | print "<td class='hlUpdPic'>$update_pic</td>"; |
3de0261a AD |
5074 | |
5075 | print "<td class='hlSelectRow'> | |
67343d9f AD |
5076 | <input type=\"checkbox\" onclick=\"tSR(this)\" |
5077 | id=\"RCHK-$id\"> | |
3de0261a AD |
5078 | </td>"; |
5079 | ||
5080 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
e4f4b46f | 5081 | print "<td class='hlMarkedPic'>$published_pic</td>"; |
3de0261a | 5082 | |
df456bb0 AD |
5083 | # if ($line["feed_title"]) { |
5084 | # print "<td class='hlContent'>$content_link</td>"; | |
5085 | # print "<td class='hlFeed'> | |
5086 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
5087 | # truncate_string($line["feed_title"],30)."</a> </td>"; | |
5088 | # } else { | |
5089 | ||
f0971fc1 | 5090 | print "<td onclick='view($id,$feed_id)' class='hlContent$hlc_suffix' valign='middle'>"; |
df456bb0 | 5091 | |
f0971fc1 AD |
5092 | print "<a id=\"RTITLE-$id\" |
5093 | href=\"" . htmlspecialchars($line["link"]) . "\" | |
a7764e51 | 5094 | onclick=\"return view($id,$feed_id);\">" . |
df456bb0 AD |
5095 | $line["title"]; |
5096 | ||
5097 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
5098 | if ($content_preview) { | |
5099 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
3de0261a | 5100 | } |
3de0261a | 5101 | } |
df456bb0 AD |
5102 | |
5103 | print "</a>"; | |
5104 | ||
e2549229 AD |
5105 | print $labels_str; |
5106 | ||
df456bb0 AD |
5107 | # <a href=\"javascript:viewfeed($feed_id, '', false)\">". |
5108 | # $line["feed_title"]."</a> | |
5109 | ||
d00f22ac | 5110 | if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
6cfea5c7 AD |
5111 | if ($line["feed_title"]) { |
5112 | print "<span class=\"hlFeed\"> | |
5113 | (<a href=\"javascript:viewfeed($feed_id, '', false)\">". | |
5114 | $line["feed_title"]."</a>) | |
5115 | </span>"; | |
5116 | } | |
df456bb0 | 5117 | } |
df456bb0 | 5118 | print "</td>"; |
bd51294a | 5119 | |
df456bb0 | 5120 | # } |
3de0261a | 5121 | |
d7e83df7 | 5122 | print "<td class=\"hlUpdated\" onclick='view($id,$feed_id)'><nobr>$updated_fmt </nobr></td>"; |
546499a9 AD |
5123 | |
5124 | print "<td class='hlMarkedPic'>$score_pic</td>"; | |
bd51294a AD |
5125 | |
5126 | if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) { | |
d7e83df7 | 5127 | print "<td onclick=\"viewfeed($feed_id)\" class=\"hlFeedIcon\">$feed_icon_img</td>"; |
bd51294a AD |
5128 | } |
5129 | ||
3de0261a AD |
5130 | print "</tr>"; |
5131 | ||
5132 | } else { | |
6cfea5c7 | 5133 | |
bb031f91 | 5134 | if (get_pref($link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) { |
081e527d AD |
5135 | if ($feed_id != $vgroup_last_feed) { |
5136 | ||
5137 | $cur_feed_title = $line["feed_title"]; | |
5138 | $vgroup_last_feed = $feed_id; | |
5139 | ||
962d8ba4 AD |
5140 | $cur_feed_title = htmlspecialchars($cur_feed_title); |
5141 | ||
af163b85 | 5142 | $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)"; |
081e527d | 5143 | |
7defa089 | 5144 | $has_feed_icon = feed_has_icon($feed_id); |
dc803347 AD |
5145 | |
5146 | if ($has_feed_icon) { | |
5147 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
5148 | } else { | |
5149 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; | |
5150 | } | |
5151 | ||
6cfea5c7 | 5152 | print "<div class='cdmFeedTitle'>". |
dc803347 | 5153 | "<div style=\"float : right\">$feed_icon_img</div>". |
6cfea5c7 | 5154 | "<a href=\"javascript:viewfeed($feed_id, '', false)\">". |
081e527d | 5155 | $line["feed_title"]."</a> $vf_catchup_link</div>"; |
6cfea5c7 AD |
5156 | } |
5157 | } | |
5158 | ||
3de0261a AD |
5159 | if ($is_unread) { |
5160 | $add_class = "Unread"; | |
5161 | } else { | |
5162 | $add_class = ""; | |
5163 | } | |
0cacc891 AD |
5164 | |
5165 | $expand_cdm = get_pref($link, 'CDM_EXPANDED'); | |
3cd4239a | 5166 | $show_excerpt = false; |
0cacc891 | 5167 | |
5daa24f2 | 5168 | if ($expand_cdm && $score >= -100) { |
0cacc891 | 5169 | $cdm_cstyle = ""; |
3cd4239a | 5170 | $show_excerpt = false; |
0cacc891 AD |
5171 | } else { |
5172 | $cdm_cstyle = "style=\"display : none\""; | |
3cd4239a | 5173 | $show_excerpt = true; |
0cacc891 AD |
5174 | } |
5175 | ||
314fcd2b AD |
5176 | $mouseover_attrs = "onmouseover='postMouseIn($id)' |
5177 | onmouseout='postMouseOut($id)'"; | |
5178 | ||
e4914b62 | 5179 | print "<div class=\"cdmArticle$add_class\" |
3cd4239a | 5180 | id=\"RROW-$id\" |
314fcd2b | 5181 | $mouseover_attrs'>"; |
3de0261a AD |
5182 | |
5183 | print "<div class=\"cdmHeader\">"; | |
5184 | ||
965fb2af AD |
5185 | if (!get_pref($link, "VFEED_GROUP_BY_FEED") || !$line["feed_title"]) { |
5186 | $cdm_feed_icon = "<span style=\"cursor : pointer\" onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>"; | |
5187 | } | |
5188 | ||
5189 | print "<div class=\"articleUpdated\">$updated_fmt $score_pic $cdm_feed_icon | |
b3296d36 | 5190 | </div>"; |
5daa24f2 | 5191 | |
9617eb94 | 5192 | print "<span id=\"RTITLE-$id\" class=\"titleWrap$hlc_suffix\"><a class=\"title\" |
3de0261a | 5193 | onclick=\"javascript:toggleUnread($id, 0)\" |
5daa24f2 AD |
5194 | target=\"_blank\" href=\"".$line["link"]."\">".$line["title"]."</a> |
5195 | "; | |
3de0261a AD |
5196 | |
5197 | print $entry_author; | |
5198 | ||
3cd4239a | 5199 | /* if (!$expand_cdm || $score < -100) { |
0cacc891 AD |
5200 | print " <a id=\"CICH-$id\" |
5201 | href=\"javascript:cdmExpandArticle($id)\"> | |
5202 | (".__('Show article').")</a>"; | |
3cd4239a | 5203 | } */ |
0cacc891 | 5204 | |
39f3c580 | 5205 | print $labels_str; |
0cacc891 | 5206 | |
d00f22ac | 5207 | if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { |
6cfea5c7 AD |
5208 | if ($line["feed_title"]) { |
5209 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
5210 | } | |
3de0261a AD |
5211 | } |
5212 | ||
5daa24f2 | 5213 | print "</span></div>"; |
3de0261a | 5214 | |
3fc2eed5 AD |
5215 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { |
5216 | $line["content_preview"] = preg_replace("/href=/i", | |
e944346c | 5217 | "target=\"_blank\" href=", $line["content_preview"]); |
3fc2eed5 AD |
5218 | } |
5219 | ||
3cd4239a AD |
5220 | if ($show_excerpt) { |
5221 | print "<div class=\"cdmExcerpt\" id=\"CEXC-$id\" | |
5222 | onclick=\"cdmExpandArticle($id)\" | |
5223 | title=\"".__('Click to expand article')."\">"; | |
5224 | print truncate_string(strip_tags($line["content_preview"]), 100); | |
5225 | print "</div>"; | |
5226 | } | |
5227 | ||
5228 | print "<div class=\"cdmContent\" | |
5229 | onclick=\"cdmClicked($id)\" | |
5230 | id=\"CICD-$id\" $cdm_cstyle>"; | |
a04c8e8d | 5231 | |
0cacc891 | 5232 | // print "<div class=\"cdmInnerContent\" id=\"CICD-$id\" $cdm_cstyle>"; |
621ffb00 | 5233 | |
b2d5d145 | 5234 | print sanitize_rss($link, $line["content_preview"]); |
c7e51de1 AD |
5235 | |
5236 | print "<div id=\"POSTNOTE-$id\">"; | |
5237 | if ($line['note']) { | |
5238 | print format_article_note($id, $line['note']); | |
5239 | } | |
5240 | print "</div>"; | |
5241 | ||
c54526fe | 5242 | $article_content = $line["content_preview"]; |
3c66b582 AD |
5243 | |
5244 | $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE | |
4752b041 | 5245 | post_id = '$id' AND content_url != ''"); |
3c66b582 AD |
5246 | |
5247 | if (db_num_rows($e_result) > 0) { | |
3c66b582 | 5248 | |
a3eeb471 | 5249 | $entries_html = array(); |
3c66b582 AD |
5250 | $entries = array(); |
5251 | ||
5252 | while ($e_line = db_fetch_assoc($e_result)) { | |
5253 | ||
5254 | $url = $e_line["content_url"]; | |
4752b041 AD |
5255 | $ctype = $e_line["content_type"]; |
5256 | if (!$ctype) $ctype = __("unknown type"); | |
3c66b582 AD |
5257 | |
5258 | $filename = substr($url, strrpos($url, "/")+1); | |
5259 | ||
8dccabed AD |
5260 | $entry = ""; |
5261 | ||
95f67d2e AD |
5262 | if (substr($ctype,0,6)=="audio/" || $ctype=="application/ogg" || $ctype=="application/x-ogg") { |
5263 | $entry .= "<audio controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />"; | |
5264 | if (($ctype == __("audio/mpeg")) && | |
5265 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { | |
5266 | $entry .= "<div><object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object></div>"; | |
5267 | } | |
5268 | $entry .= "</audio>"; | |
5269 | if (($ctype == __("audio/mpeg")) && | |
5270 | (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { | |
5271 | $entry .= "<a id='switchToFlashLink' href='#' onclick='return switchToFlash(this)'>".__('Switch to Flash Player')."</a><br />"; | |
5272 | $entry .= "<script type='text/javascript'>html5AudioOrFlash('$ctype');</script>"; | |
5273 | } | |
5274 | } elseif (substr($ctype,0,6)=="video/") { | |
5275 | $entry .= "<video controls=\"controls\"><source src=\"$url\" type=\"$ctype\" />"; | |
5276 | $entry .= "</video>"; | |
8dccabed AD |
5277 | } |
5278 | ||
5279 | $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" . | |
4752b041 | 5280 | $filename . " (" . $ctype . ")" . "</a>"; |
3c66b582 | 5281 | |
a3eeb471 AD |
5282 | array_push($entries_html, $entry); |
5283 | ||
5284 | $entry = array(); | |
5285 | ||
5286 | $entry["type"] = $ctype; | |
5287 | $entry["filename"] = $filename; | |
5288 | $entry["url"] = $url; | |
5289 | ||
3c66b582 AD |
5290 | array_push($entries, $entry); |
5291 | } | |
5292 | ||
c54526fe | 5293 | if (!preg_match("/img/i", $article_content)) { |
a3eeb471 AD |
5294 | foreach ($entries as $entry) { |
5295 | if (preg_match("/image/", $entry["type"])) { | |
5296 | print "<p><img | |
5297 | alt=\"".htmlspecialchars($entry["filename"])."\" | |
5298 | src=\"" .htmlspecialchars($entry["url"]) . "\"></p>"; | |
5299 | } | |
5300 | } | |
5301 | } | |
5302 | ||
5303 | print "<div class=\"cdmEnclosures\">"; | |
5304 | ||
5305 | if (db_num_rows($e_result) == 1) { | |
5306 | print __("Attachment:") . " "; | |
5307 | } else { | |
5308 | print __("Attachments:") . " "; | |
5309 | } | |
5310 | ||
5311 | print join(", ", $entries_html); | |
3c66b582 AD |
5312 | |
5313 | print "</div>"; | |
5314 | } | |
5315 | ||
a3eeb471 | 5316 | |
0cacc891 AD |
5317 | print "<br clear='both'>"; |
5318 | // print "</div>"; | |
a04c8e8d | 5319 | |
0cacc891 | 5320 | /* if (!$expand_cdm) { |
12f5d8fe AD |
5321 | print "<a id=\"CICH-$id\" |
5322 | href=\"javascript:cdmExpandArticle($id)\"> | |
5323 | Show article</a>"; | |
0cacc891 | 5324 | } */ |
a04c8e8d | 5325 | |
0cacc891 | 5326 | print "</div>"; |
3de0261a | 5327 | |
e2ccbfab | 5328 | print "<div class=\"cdmFooter\"><span class='s0'>"; |
3de0261a | 5329 | |
e2ccbfab | 5330 | /* print "<div class=\"markedPic\">Star it: $marked_pic</div>"; */ |
3de0261a | 5331 | |
e2ccbfab AD |
5332 | print __("Select:"). |
5333 | " <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
3de0261a AD |
5334 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">"; |
5335 | ||
c7e51de1 AD |
5336 | print "</span><span class='s1'>$marked_pic "; |
5337 | print "$published_pic "; | |
5338 | print "<img src=\"images/art-zoom.png\" class='tagsPic' | |
eedfb635 AD |
5339 | onclick=\"zoomToArticle($id)\" |
5340 | style=\"cursor : pointer\" | |
5341 | alt='Zoom' | |
c7e51de1 AD |
5342 | title='".__('Show article summary in new window')."'> "; |
5343 | ||
5344 | $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); | |
5345 | ||
5346 | print "<img src=\"images/art-pub-note.png\" class='tagsPic' | |
5347 | style=\"cursor : pointer\" style=\"cursor : pointer\" | |
5348 | onclick=\"publishWithNote($id, '$note_escaped')\" | |
5349 | alt='PubNote' title='".__('Publish article with a note')."'>"; | |
5350 | ||
5351 | print "</span>"; | |
e2ccbfab | 5352 | |
307d187c | 5353 | $tags_str = format_tags_string(get_article_tags($link, $id), $id); |
e2ccbfab AD |
5354 | |
5355 | // print "<img src='images/tag.png' class='markedPic'>"; | |
5356 | ||
5f014cf1 | 5357 | print "<span class='s1'> |
307d187c AD |
5358 | <img class='tagsPic' src='images/tag.png' alt='Tags' title='Tags'> |
5359 | <span id=\"ATSTR-$id\">$tags_str</span> | |
5360 | <a title=\"".__('Edit tags for this article')."\" | |
5361 | href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>"; | |
3de0261a | 5362 | |
e2ccbfab | 5363 | print "</span>"; |
3de0261a | 5364 | |
c7e51de1 | 5365 | print "<span class='s2'><a class=\"cdmToggleLink\" |
e2ccbfab | 5366 | href=\"javascript:toggleUnread($id)\"> |
c7e51de1 | 5367 | ".__('toggle unread')."</a></span>"; |
3de0261a | 5368 | |
e2ccbfab | 5369 | print "</div>"; |
3de0261a AD |
5370 | print "</div>"; |
5371 | ||
5372 | } | |
5373 | ||
5374 | ++$lnum; | |
5375 | } | |
5376 | ||
ac541432 | 5377 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) { |
3de0261a AD |
5378 | print "</table>"; |
5379 | } | |
5380 | ||
3de0261a | 5381 | } else { |
93c841c4 AD |
5382 | $message = ""; |
5383 | ||
5384 | switch ($view_mode) { | |
5385 | case "unread": | |
5386 | $message = __("No unread articles found to display."); | |
5387 | break; | |
8b09eac8 AD |
5388 | case "updated": |
5389 | $message = __("No updated articles found to display."); | |
5390 | break; | |
93c841c4 AD |
5391 | case "marked": |
5392 | $message = __("No starred articles found to display."); | |
5393 | break; | |
5394 | default: | |
215af892 AD |
5395 | if ($feed < -10) { |
5396 | $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter."); | |
5397 | } else { | |
5398 | $message = __("No articles found to display."); | |
5399 | } | |
93c841c4 AD |
5400 | } |
5401 | ||
5402 | if (!$offset) print "<div class='whiteBox'>$message</div>"; | |
3de0261a AD |
5403 | } |
5404 | ||
ac541432 AD |
5405 | if (!$offset) { |
5406 | print "</div>"; | |
5407 | print "</div>"; | |
5408 | } | |
3de0261a | 5409 | |
081e527d | 5410 | return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed); |
3de0261a | 5411 | } |
0979b696 AD |
5412 | |
5413 | // from here: http://www.roscripts.com/Create_tag_cloud-71.html | |
5414 | ||
5415 | function printTagCloud($link) { | |
35a03bdd | 5416 | |
0979b696 AD |
5417 | $query = "SELECT tag_name, COUNT(post_int_id) AS count |
5418 | FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." | |
b31af972 | 5419 | GROUP BY tag_name ORDER BY count DESC LIMIT 50"; |
0979b696 AD |
5420 | |
5421 | $result = db_query($link, $query); | |
5422 | ||
5423 | $tags = array(); | |
5424 | ||
5425 | while ($line = db_fetch_assoc($result)) { | |
5426 | $tags[$line["tag_name"]] = $line["count"]; | |
5427 | } | |
5428 | ||
5429 | ksort($tags); | |
5430 | ||
5431 | $max_size = 32; // max font size in pixels | |
4548a580 | 5432 | $min_size = 11; // min font size in pixels |
0979b696 AD |
5433 | |
5434 | // largest and smallest array values | |
5435 | $max_qty = max(array_values($tags)); | |
5436 | $min_qty = min(array_values($tags)); | |
5437 | ||
5438 | // find the range of values | |
5439 | $spread = $max_qty - $min_qty; | |
5440 | if ($spread == 0) { // we don't want to divide by zero | |
5441 | $spread = 1; | |
5442 | } | |
5443 | ||
5444 | // set the font-size increment | |
5445 | $step = ($max_size - $min_size) / ($spread); | |
5446 | ||
5447 | // loop through the tag array | |
5448 | foreach ($tags as $key => $value) { | |
5449 | // calculate font-size | |
5450 | // find the $value in excess of $min_qty | |
5451 | // multiply by the font-size increment ($size) | |
5452 | // and add the $min_size set above | |
5453 | $size = round($min_size + (($value - $min_qty) * $step)); | |
546ffab4 AD |
5454 | |
5455 | $key_escaped = str_replace("'", "\\'", $key); | |
5456 | ||
5457 | echo "<a href=\"javascript:viewfeed('$key_escaped') \" style=\"font-size: " . | |
0979b696 AD |
5458 | $size . "px\" title=\"$value articles tagged with " . |
5459 | $key . '">' . $key . '</a> '; | |
5460 | } | |
5461 | } | |
46921916 AD |
5462 | |
5463 | function print_checkpoint($n, $s) { | |
5464 | $ts = getmicrotime(); | |
5465 | echo sprintf("<!-- CP[$n] %.4f seconds -->", $ts - $s); | |
5466 | return $ts; | |
5467 | } | |
14b6c54b AD |
5468 | |
5469 | function sanitize_tag($tag) { | |
5470 | $tag = trim($tag); | |
5471 | ||
5472 | $tag = mb_strtolower($tag, 'utf-8'); | |
5473 | ||
0c3d1c68 AD |
5474 | $tag = preg_replace('/[\"\+\>\<]/', "", $tag); |
5475 | ||
5476 | // $tag = str_replace('"', "", $tag); | |
5477 | // $tag = str_replace("+", " ", $tag); | |
14b6c54b AD |
5478 | $tag = str_replace("technorati tag: ", "", $tag); |
5479 | ||
5480 | return $tag; | |
5481 | } | |
e4f4b46f AD |
5482 | |
5483 | function generate_publish_key() { | |
5484 | return sha1(uniqid(rand(), true)); | |
5485 | } | |
5486 | ||
f56e3080 AD |
5487 | function article_publish_url($link) { |
5488 | ||
e2749781 AD |
5489 | $url_path = ""; |
5490 | ||
5491 | ||
5492 | if ($_SERVER['HTTPS'] != "on") { | |
5493 | $url_path = "http://"; | |
5494 | } else { | |
5495 | $url_path = "https://"; | |
5496 | } | |
f56e3080 | 5497 | |
e2749781 AD |
5498 | $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); |
5499 | $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); | |
f56e3080 AD |
5500 | |
5501 | return $url_path; | |
5502 | } | |
5503 | ||
45004d43 AD |
5504 | /** |
5505 | * Purge a feed contents, marked articles excepted. | |
5506 | * | |
5507 | * @param mixed $link The database connection. | |
5508 | * @param integer $id The id of the feed to purge. | |
5509 | * @return void | |
5510 | */ | |
d1f0c584 AD |
5511 | function clear_feed_articles($link, $id) { |
5512 | $result = db_query($link, "DELETE FROM ttrss_user_entries | |
a8ae1b9a | 5513 | WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
d1f0c584 AD |
5514 | |
5515 | $result = db_query($link, "DELETE FROM ttrss_entries WHERE | |
5516 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
ced46404 AD |
5517 | |
5518 | ccache_update($link, $id, $_SESSION['uid']); | |
45004d43 AD |
5519 | } // function clear_feed_articles |
5520 | ||
5521 | /** | |
5522 | * Compute the Mozilla Firefox feed adding URL from server HOST and REQUEST_URI. | |
5523 | * | |
5524 | * @return string The Mozilla Firefox feed adding URL. | |
5525 | */ | |
5526 | function add_feed_url() { | |
d70c5ae4 | 5527 | $url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); |
755a43ee AD |
5528 | $url_path .= "?op=pref-feeds&quiet=1&subop=add&feed_url=%s"; |
5529 | return $url_path; | |
45004d43 AD |
5530 | } // function add_feed_url |
5531 | ||
5532 | /** | |
5533 | * Encrypt a password in SHA1. | |
5534 | * | |
5535 | * @param string $pass The password to encrypt. | |
5536 | * @param string $login A optionnal login. | |
5537 | * @return string The encrypted password. | |
5538 | */ | |
1a9f4d3c AD |
5539 | function encrypt_password($pass, $login = '') { |
5540 | if ($login) { | |
5541 | return "SHA1X:" . sha1("$login:$pass"); | |
5542 | } else { | |
5543 | return "SHA1:" . sha1($pass); | |
5544 | } | |
45004d43 AD |
5545 | } // function encrypt_password |
5546 | ||
5547 | /** | |
5548 | * Update a feed batch. | |
5549 | * Used by daemons to update n feeds by run. | |
5550 | * Only update feed needing a update, and not being processed | |
5551 | * by another process. | |
5552 | * | |
5553 | * @param mixed $link Database link | |
5554 | * @param integer $limit Maximum number of feeds in update batch. Default to DAEMON_FEED_LIMIT. | |
5555 | * @param boolean $from_http Set to true if you call this function from http to disable cli specific code. | |
5556 | * @param boolean $debug Set to false to disable debug output. Default to true. | |
5557 | * @return void | |
5558 | */ | |
5559 | function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) { | |
5560 | // Process all other feeds using last_updated and interval parameters | |
5561 | ||
5562 | // Test if the user has loggued in recently. If not, it does not update its feeds. | |
5563 | if (DAEMON_UPDATE_LOGIN_LIMIT > 0) { | |
5564 | if (DB_TYPE == "pgsql") { | |
5565 | $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; | |
5566 | } else { | |
5567 | $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; | |
5568 | } | |
5569 | } else { | |
5570 | $login_thresh_qpart = ""; | |
5571 | } | |
5572 | ||
5573 | // Test if the feed need a update (update interval exceded). | |
5574 | if (DB_TYPE == "pgsql") { | |
5575 | $update_limit_qpart = "AND (( | |
5576 | ttrss_feeds.update_interval = 0 | |
5577 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) | |
5578 | ) OR ( | |
5579 | ttrss_feeds.update_interval > 0 | |
5580 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) | |
da4caf5d | 5581 | ) OR ttrss_feeds.last_updated IS NULL)"; |
45004d43 AD |
5582 | } else { |
5583 | $update_limit_qpart = "AND (( | |
5584 | ttrss_feeds.update_interval = 0 | |
5585 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) | |
5586 | ) OR ( | |
5587 | ttrss_feeds.update_interval > 0 | |
5588 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) | |
da4caf5d | 5589 | ) OR ttrss_feeds.last_updated IS NULL)"; |
45004d43 AD |
5590 | } |
5591 | ||
5592 | // Test if feed is currently being updated by another process. | |
5593 | if (DB_TYPE == "pgsql") { | |
5594 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; | |
5595 | } else { | |
5596 | $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; | |
5597 | } | |
5598 | ||
5599 | // Test if there is a limit to number of updated feeds | |
5600 | $query_limit = ""; | |
5601 | if($limit) $query_limit = sprintf("LIMIT %d", $limit); | |
5602 | ||
51b8c957 AD |
5603 | $random_qpart = sql_random_function(); |
5604 | ||
45004d43 AD |
5605 | // We search for feed needing update. |
5606 | $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid, | |
fc2b26a6 | 5607 | ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, |
45004d43 AD |
5608 | ttrss_feeds.update_interval |
5609 | FROM | |
5610 | ttrss_feeds, ttrss_users, ttrss_user_prefs | |
5611 | WHERE | |
5612 | ttrss_feeds.owner_uid = ttrss_users.id | |
5613 | AND ttrss_users.id = ttrss_user_prefs.owner_uid | |
5614 | AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' | |
5615 | $login_thresh_qpart $update_limit_qpart | |
51b8c957 AD |
5616 | $updstart_thresh_qpart |
5617 | ORDER BY $random_qpart $query_limit"); | |
45004d43 AD |
5618 | |
5619 | $user_prefs_cache = array(); | |
5620 | ||
5621 | if($debug) _debug(sprintf("Scheduled %d feeds to update...\n", db_num_rows($result))); | |
5622 | ||
5623 | // Here is a little cache magic in order to minimize risk of double feed updates. | |
5624 | $feeds_to_update = array(); | |
5625 | while ($line = db_fetch_assoc($result)) { | |
5626 | $feeds_to_update[$line['id']] = $line; | |
5627 | } | |
5628 | ||
5629 | // We update the feed last update started date before anything else. | |
5630 | // There is no lag due to feed contents downloads | |
5631 | // It prevent an other process to update the same feed. | |
5632 | $feed_ids = array_keys($feeds_to_update); | |
5633 | if($feed_ids) { | |
5634 | db_query($link, sprintf("UPDATE ttrss_feeds SET last_update_started = NOW() | |
5635 | WHERE id IN (%s)", implode(',', $feed_ids))); | |
5636 | } | |
5637 | ||
5638 | // For each feed, we call the feed update function. | |
5639 | while ($line = array_pop($feeds_to_update)) { | |
5640 | ||
5641 | if($debug) _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]); | |
5642 | ||
5643 | // We setup a alarm to alert if the feed take more than 300s to update. | |
5644 | // => HANG alarm. | |
9a91a51e | 5645 | if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(300); |
45004d43 AD |
5646 | update_rss_feed($link, $line["feed_url"], $line["id"], true); |
5647 | // Cancel the alarm (the update went well) | |
9a91a51e | 5648 | if(!$from_http && function_exists('pcntl_alarm')) pcntl_alarm(0); |
45004d43 AD |
5649 | |
5650 | sleep(1); // prevent flood (FIXME make this an option?) | |
5651 | } | |
5652 | ||
0e0dd486 AD |
5653 | // Send feed digests by email if needed. |
5654 | if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link); | |
5655 | ||
5656 | purge_orphans($link); | |
45004d43 AD |
5657 | |
5658 | } // function update_daemon_common | |
1a9f4d3c | 5659 | |
621ffb00 AD |
5660 | function sanitize_article_content($text) { |
5661 | # we don't support CDATA sections in articles, they break our own escaping | |
5662 | $text = preg_replace("/\[\[CDATA/", "", $text); | |
5663 | $text = preg_replace("/\]\]\>/", "", $text); | |
5664 | return $text; | |
5665 | } | |
fee840fb AD |
5666 | |
5667 | function load_filters($link, $feed, $owner_uid, $action_id = false) { | |
5668 | $filters = array(); | |
5669 | ||
5670 | if ($action_id) $ftype_query_part = "action_id = '$action_id' AND"; | |
5671 | ||
5672 | $result = db_query($link, "SELECT reg_exp, | |
5673 | ttrss_filter_types.name AS name, | |
5674 | ttrss_filter_actions.name AS action, | |
5675 | inverse, | |
44d0e774 AD |
5676 | action_param, |
5677 | filter_param | |
fee840fb AD |
5678 | FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE |
5679 | enabled = true AND | |
5680 | $ftype_query_part | |
5681 | owner_uid = $owner_uid AND | |
5682 | ttrss_filter_types.id = filter_type AND | |
5683 | ttrss_filter_actions.id = action_id AND | |
5684 | (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp"); | |
5685 | ||
5686 | while ($line = db_fetch_assoc($result)) { | |
5687 | if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); | |
5688 | $filter["reg_exp"] = $line["reg_exp"]; | |
5689 | $filter["action"] = $line["action"]; | |
5690 | $filter["action_param"] = $line["action_param"]; | |
44d0e774 | 5691 | $filter["filter_param"] = $line["filter_param"]; |
fee840fb AD |
5692 | $filter["inverse"] = sql_bool_to_bool($line["inverse"]); |
5693 | ||
5694 | array_push($filters[$line["name"]], $filter); | |
5695 | } | |
5696 | ||
5697 | return $filters; | |
5698 | } | |
1e36af0c AD |
5699 | |
5700 | function get_score_pic($score) { | |
1cce3aca | 5701 | if ($score > 100) { |
1e36af0c | 5702 | return "score_high.png"; |
1cce3aca AD |
5703 | } else if ($score > 0) { |
5704 | return "score_half_high.png"; | |
5705 | } else if ($score < -100) { | |
1e36af0c | 5706 | return "score_low.png"; |
1cce3aca AD |
5707 | } else if ($score < 0) { |
5708 | return "score_half_low.png"; | |
1e36af0c AD |
5709 | } else { |
5710 | return "score_neutral.png"; | |
5711 | } | |
5712 | } | |
ec92c9d1 | 5713 | |
0745839a | 5714 | function rounded_table_start($classname, $header = " ") { |
ec92c9d1 | 5715 | print "<table width='100%' class='$classname' cellspacing='0' cellpadding='0'>"; |
74d5c8fa | 5716 | print "<tr><td class='c1'> </td><td class='top'>$header</td><td class='c2'> </td></tr>"; |
ec92c9d1 AD |
5717 | print "<tr><td class='left'> </td><td class='content'>"; |
5718 | } | |
5719 | ||
0745839a | 5720 | function rounded_table_end($footer = " ") { |
ec92c9d1 | 5721 | print "</td><td class='right'> </td></tr>"; |
74d5c8fa | 5722 | print "<tr><td class='c4'> </td><td class='bottom'>$footer</td><td class='c3'> </td></tr>"; |
ec92c9d1 AD |
5723 | print "</table>"; |
5724 | } | |
5725 | ||
7defa089 AD |
5726 | function feed_has_icon($id) { |
5727 | return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; | |
5728 | } | |
f29ba148 AD |
5729 | |
5730 | function init_connection($link) { | |
5731 | if (DB_TYPE == "pgsql") { | |
6fc720fd | 5732 | pg_query($link, "set client_encoding = 'UTF-8'"); |
f29ba148 | 5733 | pg_set_client_encoding("UNICODE"); |
045d0ab8 | 5734 | pg_query($link, "set datestyle = 'ISO, european'"); |
f29ba148 AD |
5735 | } else { |
5736 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { | |
5737 | db_query($link, "SET NAMES " . MYSQL_CHARSET); | |
5738 | // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET); | |
5739 | } | |
5740 | } | |
5741 | } | |
5e96ca9d AD |
5742 | |
5743 | function update_feedbrowser_cache($link) { | |
5744 | ||
931dcbc1 | 5745 | $result = db_query($link, "SELECT feed_url,title, COUNT(id) AS subscribers |
5e96ca9d AD |
5746 | FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf |
5747 | WHERE tf.feed_url = ttrss_feeds.feed_url | |
5748 | AND (private IS true OR feed_url LIKE '%:%@%/%')) | |
d460f7aa | 5749 | GROUP BY feed_url, title ORDER BY subscribers DESC LIMIT 1000"); |
5e96ca9d AD |
5750 | |
5751 | db_query($link, "BEGIN"); | |
5752 | ||
5753 | db_query($link, "DELETE FROM ttrss_feedbrowser_cache"); | |
5754 | ||
5755 | $count = 0; | |
5756 | ||
5757 | while ($line = db_fetch_assoc($result)) { | |
5758 | $subscribers = db_escape_string($line["subscribers"]); | |
5759 | $feed_url = db_escape_string($line["feed_url"]); | |
931dcbc1 AD |
5760 | $title = db_escape_string($line["title"]); |
5761 | ||
5762 | $tmp_result = db_query($link, "SELECT subscribers FROM | |
5763 | ttrss_feedbrowser_cache WHERE feed_url = '$feed_url'"); | |
5764 | ||
5765 | if (db_num_rows($tmp_result) == 0) { | |
5766 | ||
5767 | db_query($link, "INSERT INTO ttrss_feedbrowser_cache | |
5768 | (feed_url, title, subscribers) VALUES ('$feed_url', | |
5769 | '$title', '$subscribers')"); | |
5770 | ||
5771 | ++$count; | |
5772 | ||
5773 | } | |
5e96ca9d | 5774 | |
5e96ca9d AD |
5775 | } |
5776 | ||
5777 | db_query($link, "COMMIT"); | |
5778 | ||
5779 | return $count; | |
5780 | ||
5781 | } | |
2627f2d0 | 5782 | |
8a4c759e | 5783 | function ccache_zero($link, $feed_id, $owner_uid) { |
2627f2d0 AD |
5784 | db_query($link, "UPDATE ttrss_counters_cache SET |
5785 | value = 0, updated = NOW() WHERE | |
5786 | feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); | |
8a4c759e | 5787 | } |
2627f2d0 | 5788 | |
ad0056a8 AD |
5789 | function ccache_zero_all($link, $owner_uid) { |
5790 | db_query($link, "UPDATE ttrss_counters_cache SET | |
5791 | value = 0 WHERE owner_uid = '$owner_uid'"); | |
5792 | ||
5793 | db_query($link, "UPDATE ttrss_cat_counters_cache SET | |
5794 | value = 0 WHERE owner_uid = '$owner_uid'"); | |
5795 | } | |
5796 | ||
c7e51de1 AD |
5797 | function ccache_remove($link, $feed_id, $owner_uid, $is_cat = false) { |
5798 | ||
5799 | if (!$is_cat) { | |
5800 | $table = "ttrss_counters_cache"; | |
5801 | } else { | |
5802 | $table = "ttrss_cat_counters_cache"; | |
5803 | } | |
5804 | ||
5805 | db_query($link, "DELETE FROM $table WHERE | |
5806 | feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); | |
5807 | ||
5808 | } | |
5809 | ||
5f4f7adf AD |
5810 | function ccache_update_all($link, $owner_uid) { |
5811 | ||
5812 | if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid)) { | |
5813 | ||
5814 | $result = db_query($link, "SELECT feed_id FROM ttrss_cat_counters_cache | |
5815 | WHERE feed_id > 0 AND owner_uid = '$owner_uid'"); | |
5816 | ||
5817 | while ($line = db_fetch_assoc($result)) { | |
5818 | ccache_update($link, $line["feed_id"], $owner_uid, true); | |
5819 | } | |
5820 | ||
c5ffeb61 AD |
5821 | /* We have to manually include category 0 */ |
5822 | ||
5823 | ccache_update($link, 0, $owner_uid, true); | |
5824 | ||
8a4c759e | 5825 | } else { |
5f4f7adf AD |
5826 | $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache |
5827 | WHERE feed_id > 0 AND owner_uid = '$owner_uid'"); | |
8a4c759e | 5828 | |
5f4f7adf AD |
5829 | while ($line = db_fetch_assoc($result)) { |
5830 | print ccache_update($link, $line["feed_id"], $owner_uid); | |
5831 | ||
5832 | } | |
5833 | ||
5834 | } | |
5835 | } | |
2627f2d0 | 5836 | |
6b49a3dd AD |
5837 | function ccache_find($link, $feed_id, $owner_uid, $is_cat = false, |
5838 | $no_update = false) { | |
8a4c759e | 5839 | |
5c432ba4 AD |
5840 | if (!is_numeric($feed_id)) return; |
5841 | ||
8a4c759e AD |
5842 | if (!$is_cat) { |
5843 | $table = "ttrss_counters_cache"; | |
32d2181b AD |
5844 | if ($feed_id > 0) { |
5845 | $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds | |
5846 | WHERE id = '$feed_id'"); | |
5847 | $owner_uid = db_fetch_result($tmp_result, 0, "owner_uid"); | |
5848 | } | |
8a4c759e AD |
5849 | } else { |
5850 | $table = "ttrss_cat_counters_cache"; | |
5851 | } | |
5852 | ||
5853 | if (DB_TYPE == "pgsql") { | |
5854 | $date_qpart = "updated > NOW() - INTERVAL '15 minutes'"; | |
5855 | } else if (DB_TYPE == "mysql") { | |
5856 | $date_qpart = "updated > DATE_SUB(NOW(), INTERVAL 15 MINUTE)"; | |
5857 | } | |
5858 | ||
5859 | $result = db_query($link, "SELECT value FROM $table | |
5860 | WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' | |
37fb651d | 5861 | LIMIT 1"); |
2627f2d0 AD |
5862 | |
5863 | if (db_num_rows($result) == 1) { | |
5864 | return db_fetch_result($result, 0, "value"); | |
5865 | } else { | |
6b49a3dd AD |
5866 | if ($no_update) { |
5867 | return -1; | |
5868 | } else { | |
5869 | return ccache_update($link, $feed_id, $owner_uid, $is_cat); | |
5870 | } | |
2627f2d0 AD |
5871 | } |
5872 | ||
5873 | } | |
5874 | ||
6c2a9b9e | 5875 | function ccache_update($link, $feed_id, $owner_uid, $is_cat = false, |
6b49a3dd AD |
5876 | $update_pcat = true) { |
5877 | ||
5c432ba4 AD |
5878 | if (!is_numeric($feed_id)) return; |
5879 | ||
32d2181b | 5880 | if (!$is_cat && $feed_id > 0) { |
2e93b64c AD |
5881 | $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds |
5882 | WHERE id = '$feed_id'"); | |
5883 | $owner_uid = db_fetch_result($tmp_result, 0, "owner_uid"); | |
5884 | } | |
5885 | ||
43ead405 AD |
5886 | $prev_unread = ccache_find($link, $feed_id, $owner_uid, $is_cat, true); |
5887 | ||
5888 | /* When updating a label, all we need to do is recalculate feed counters | |
5889 | * because labels are not cached */ | |
c98e43db AD |
5890 | |
5891 | if ($feed_id < 0) { | |
43ead405 AD |
5892 | ccache_update_all($link, $owner_uid); |
5893 | return; | |
c98e43db AD |
5894 | } |
5895 | ||
8a4c759e AD |
5896 | if (!$is_cat) { |
5897 | $table = "ttrss_counters_cache"; | |
5898 | } else { | |
5899 | $table = "ttrss_cat_counters_cache"; | |
5900 | } | |
5901 | ||
b6d486a3 | 5902 | if ($is_cat && $feed_id >= 0) { |
37fb651d AD |
5903 | if ($feed_id != 0) { |
5904 | $cat_qpart = "cat_id = '$feed_id'"; | |
5905 | } else { | |
5906 | $cat_qpart = "cat_id IS NULL"; | |
5907 | } | |
5908 | ||
6b49a3dd AD |
5909 | /* Recalculate counters for child feeds */ |
5910 | ||
5911 | $result = db_query($link, "SELECT id FROM ttrss_feeds | |
5912 | WHERE owner_uid = '$owner_uid' AND $cat_qpart"); | |
5913 | ||
5914 | while ($line = db_fetch_assoc($result)) { | |
5915 | ccache_update($link, $line["id"], $owner_uid, false, false); | |
5916 | } | |
5917 | ||
37fb651d AD |
5918 | $result = db_query($link, "SELECT SUM(value) AS sv |
5919 | FROM ttrss_counters_cache, ttrss_feeds | |
5920 | WHERE id = feed_id AND $cat_qpart AND | |
5921 | ttrss_feeds.owner_uid = '$owner_uid'"); | |
5922 | ||
51e196de | 5923 | $unread = (int) db_fetch_result($result, 0, "sv"); |
37fb651d | 5924 | |
f55b0b12 AD |
5925 | } else { |
5926 | $unread = (int) getFeedArticles($link, $feed_id, $is_cat, true, $owner_uid); | |
37fb651d | 5927 | } |
2627f2d0 | 5928 | |
c7e51de1 AD |
5929 | db_query($link, "BEGIN"); |
5930 | ||
8a4c759e | 5931 | $result = db_query($link, "SELECT feed_id FROM $table |
2627f2d0 AD |
5932 | WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1"); |
5933 | ||
5934 | if (db_num_rows($result) == 1) { | |
8a4c759e | 5935 | db_query($link, "UPDATE $table SET |
2627f2d0 AD |
5936 | value = '$unread', updated = NOW() WHERE |
5937 | feed_id = '$feed_id' AND owner_uid = '$owner_uid'"); | |
5938 | ||
5939 | } else { | |
8a4c759e | 5940 | db_query($link, "INSERT INTO $table |
2627f2d0 AD |
5941 | (feed_id, value, owner_uid, updated) |
5942 | VALUES | |
5943 | ($feed_id, $unread, $owner_uid, NOW())"); | |
2627f2d0 AD |
5944 | } |
5945 | ||
c7e51de1 AD |
5946 | db_query($link, "COMMIT"); |
5947 | ||
6b49a3dd | 5948 | if ($feed_id > 0 && $prev_unread != $unread) { |
8a4c759e | 5949 | |
37fb651d | 5950 | if (!$is_cat) { |
8a4c759e | 5951 | |
6b49a3dd | 5952 | /* Update parent category */ |
8a4c759e | 5953 | |
6b49a3dd | 5954 | if ($update_pcat) { |
37fb651d | 5955 | |
6b49a3dd AD |
5956 | $result = db_query($link, "SELECT cat_id FROM ttrss_feeds |
5957 | WHERE owner_uid = '$owner_uid' AND id = '$feed_id'"); | |
8a4c759e | 5958 | |
6b49a3dd | 5959 | $cat_id = (int) db_fetch_result($result, 0, "cat_id"); |
37fb651d | 5960 | |
6b49a3dd | 5961 | ccache_update($link, $cat_id, $owner_uid, true); |
6c2a9b9e | 5962 | |
6c2a9b9e | 5963 | } |
8a4c759e | 5964 | } |
5f4f7adf AD |
5965 | } else if ($feed_id < 0) { |
5966 | ccache_update_all($link, $owner_uid); | |
8a4c759e AD |
5967 | } |
5968 | ||
5969 | return $unread; | |
2627f2d0 | 5970 | } |
ceb30ba4 AD |
5971 | |
5972 | function label_find_id($link, $label, $owner_uid) { | |
5973 | $result = db_query($link, | |
5974 | "SELECT id FROM ttrss_labels2 WHERE caption = '$label' | |
5975 | AND owner_uid = '$owner_uid' LIMIT 1"); | |
5976 | ||
5977 | if (db_num_rows($result) == 1) { | |
5978 | return db_fetch_result($result, 0, "id"); | |
5979 | } else { | |
5980 | return 0; | |
5981 | } | |
5982 | } | |
5983 | ||
814bff66 AD |
5984 | function get_article_labels($link, $id) { |
5985 | $result = db_query($link, | |
2eb9c95c | 5986 | "SELECT DISTINCT label_id,caption,fg_color,bg_color |
814bff66 AD |
5987 | FROM ttrss_labels2, ttrss_user_labels2 |
5988 | WHERE id = label_id | |
5989 | AND article_id = '$id' | |
e2549229 AD |
5990 | AND owner_uid = ".$_SESSION["uid"] . " |
5991 | ORDER BY caption"); | |
814bff66 AD |
5992 | |
5993 | $rv = array(); | |
5994 | ||
5995 | while ($line = db_fetch_assoc($result)) { | |
2eb9c95c AD |
5996 | $rk = array($line["label_id"], $line["caption"], $line["fg_color"], |
5997 | $line["bg_color"]); | |
814bff66 AD |
5998 | array_push($rv, $rk); |
5999 | } | |
6000 | ||
6001 | return $rv; | |
6002 | } | |
6003 | ||
6004 | ||
b8a637f3 AD |
6005 | function label_find_caption($link, $label, $owner_uid) { |
6006 | $result = db_query($link, | |
6007 | "SELECT caption FROM ttrss_labels2 WHERE id = '$label' | |
6008 | AND owner_uid = '$owner_uid' LIMIT 1"); | |
6009 | ||
6010 | if (db_num_rows($result) == 1) { | |
6011 | return db_fetch_result($result, 0, "caption"); | |
6012 | } else { | |
6013 | return ""; | |
6014 | } | |
6015 | } | |
6016 | ||
933ba4ee AD |
6017 | function label_remove_article($link, $id, $label, $owner_uid) { |
6018 | ||
6019 | $label_id = label_find_id($link, $label, $owner_uid); | |
6020 | ||
6021 | if (!$label_id) return; | |
6022 | ||
6023 | $result = db_query($link, | |
6024 | "DELETE FROM ttrss_user_labels2 | |
6025 | WHERE | |
6026 | label_id = '$label_id' AND | |
6027 | article_id = '$id'"); | |
6028 | } | |
6029 | ||
ceb30ba4 AD |
6030 | function label_add_article($link, $id, $label, $owner_uid) { |
6031 | ||
6032 | $label_id = label_find_id($link, $label, $owner_uid); | |
6033 | ||
6034 | if (!$label_id) return; | |
6035 | ||
6036 | $result = db_query($link, | |
6037 | "SELECT | |
6038 | article_id FROM ttrss_labels2, ttrss_user_labels2 | |
6039 | WHERE | |
6040 | label_id = id AND | |
6041 | label_id = '$label_id' AND | |
6042 | article_id = '$id' AND owner_uid = '$owner_uid' | |
6043 | LIMIT 1"); | |
6044 | ||
6045 | if (db_num_rows($result) == 0) { | |
6046 | db_query($link, "INSERT INTO ttrss_user_labels2 | |
6047 | (label_id, article_id) VALUES ('$label_id', '$id')"); | |
6048 | } | |
6049 | } | |
1380f8ee AD |
6050 | |
6051 | function label_remove($link, $id, $owner_uid) { | |
6052 | ||
6053 | db_query($link, "BEGIN"); | |
6054 | ||
6055 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 | |
6056 | WHERE id = '$id'"); | |
6057 | ||
6058 | $caption = db_fetch_result($result, 0, "caption"); | |
6059 | ||
6060 | $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id' | |
6061 | AND owner_uid = " . $_SESSION["uid"]); | |
6062 | ||
6063 | if (db_affected_rows($link, $result) != 0 && $caption) { | |
6064 | ||
6065 | /* Disable filters that reference label being removed */ | |
6066 | ||
6067 | db_query($link, "UPDATE ttrss_filters SET | |
6068 | enabled = false WHERE action_param = '$caption' | |
6069 | AND action_id = 7 | |
6070 | AND owner_uid = " . $_SESSION["uid"]); | |
6071 | } | |
6072 | ||
6073 | db_query($link, "COMMIT"); | |
6074 | } | |
79c88e11 | 6075 | |
6b2ee18d AD |
6076 | function label_create($link, $caption) { |
6077 | ||
6078 | db_query($link, "BEGIN"); | |
6079 | ||
6080 | $result = false; | |
6081 | ||
6082 | $result = db_query($link, "SELECT id FROM ttrss_labels2 | |
6083 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
6084 | ||
6085 | if (db_num_rows($result) == 0) { | |
6086 | $result = db_query($link, | |
6087 | "INSERT INTO ttrss_labels2 (caption,owner_uid) | |
6088 | VALUES ('$caption', '".$_SESSION["uid"]."')"); | |
6089 | ||
6090 | $result = db_affected_rows($link, $result) != 0; | |
6091 | } | |
6092 | ||
6093 | db_query($link, "COMMIT"); | |
6094 | ||
6095 | return $result; | |
6096 | } | |
6097 | ||
79c88e11 AD |
6098 | function print_labels_headlines_dropdown($link, $feed_id) { |
6099 | print "<li onclick=\"javascript:addLabel()\"> | |
6100 | ".__("Create label...")."</li>"; | |
6101 | ||
6102 | $result = db_query($link, "SELECT id, caption FROM ttrss_labels2 WHERE | |
6103 | owner_uid = '".$_SESSION["uid"]."' ORDER BY caption"); | |
6104 | ||
6105 | while ($line = db_fetch_assoc($result)) { | |
6106 | ||
6107 | $label_id = $line["id"]; | |
6108 | $label_caption = $line["caption"]; | |
6109 | ||
6110 | if ($feed_id < -10 && $feed_id == -11-$label_id) { | |
6111 | print "<li id=\"LHDL-$id\" | |
6112 | onclick=\"javascript:selectionRemoveLabel($label_id)\"> | |
6113 | $label_caption ".__('(remove)')."</li>"; | |
6114 | } else { | |
6115 | print "<li id=\"LHDL-$id\" | |
6116 | onclick=\"javascript:selectionAssignLabel($label_id)\"> | |
6117 | $label_caption</li>"; | |
6118 | } | |
6119 | } | |
6120 | } | |
307d187c AD |
6121 | |
6122 | function format_tags_string($tags, $id) { | |
6123 | ||
6124 | $tags_str = ""; | |
6125 | $tags_nolinks_str = ""; | |
6126 | ||
6127 | $num_tags = 0; | |
6128 | ||
6129 | if ($_SESSION["theme"] == "3pane") { | |
6130 | $tag_limit = 3; | |
6131 | } else { | |
6132 | $tag_limit = 6; | |
6133 | } | |
6134 | ||
6135 | $formatted_tags = array(); | |
6136 | ||
6137 | foreach ($tags as $tag) { | |
6138 | $num_tags++; | |
6139 | $tag_escaped = str_replace("'", "\\'", $tag); | |
6140 | ||
6141 | $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>"; | |
6142 | ||
6143 | array_push($formatted_tags, $tag_str); | |
6144 | ||
6145 | if ($num_tags == $tag_limit) { | |
6146 | break; | |
6147 | } | |
6148 | } | |
6149 | ||
6150 | $tags_str = implode(", ", $formatted_tags); | |
6151 | ||
6152 | if ($num_tags < count($tags)) { | |
6153 | $tags_str .= ", …"; | |
6154 | } | |
6155 | ||
6156 | if ($num_tags == 0) { | |
6157 | $tags_str = __("no tags"); | |
6158 | } | |
6159 | ||
6160 | return $tags_str; | |
6161 | ||
6162 | } | |
2eb9c95c AD |
6163 | |
6164 | function format_article_labels($labels, $id) { | |
6165 | ||
6166 | $labels_str = ""; | |
6167 | ||
6168 | foreach ($labels as $l) { | |
6169 | $labels_str .= sprintf("<span class='hlLabelRef' | |
6170 | style='color : %s; background-color : %s'>%s</span>", | |
6171 | $l[2], $l[3], $l[1]); | |
6172 | } | |
6173 | ||
6174 | return $labels_str; | |
6175 | ||
6176 | } | |
c7e51de1 AD |
6177 | |
6178 | function format_article_note($id, $note) { | |
6179 | ||
6180 | $note_escaped = htmlspecialchars($note, ENT_QUOTES); | |
6181 | ||
6182 | $str = "<div class='articleNote'>"; | |
6183 | $str .= "<div class='articleNoteOps'>"; | |
6184 | $str .= "<a href=\"javascript:publishWithNote($id, '$note_escaped')\">". | |
6185 | __('edit note')."</a>"; | |
6186 | $str .= "</div>"; | |
6187 | $str .= $note; | |
6188 | $str .= "</div>"; | |
6189 | ||
6190 | return $str; | |
6191 | } | |
40d13c28 | 6192 | ?> |