3 static function calculate_article_hash($article, $pluginhost) {
6 foreach ($article as $k => $v) {
7 if ($k != "feed" && isset($v)) {
8 $x = strip_tags(is_array($v) ?
implode(",", $v) : $v);
10 //_debug("$k:" . sha1($x) . ":" . htmlspecialchars($x), true);
12 $tmp .= sha1("$k:" . sha1($x));
16 return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp);
19 // Strips utf8mb4 characters (i.e. emoji) for mysql
20 static function strip_utf8mb4($str) {
21 return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
24 static function update_feedbrowser_cache() {
28 $sth = $pdo->query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers
29 FROM ttrss_feeds WHERE feed_url NOT IN (SELECT feed_url FROM ttrss_feeds
30 WHERE private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%')
31 GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT 1000");
33 $pdo->beginTransaction();
35 $pdo->query("DELETE FROM ttrss_feedbrowser_cache");
39 while ($line = $sth->fetch()) {
41 $subscribers = $line["subscribers"];
42 $feed_url = $line["feed_url"];
43 $title = $line["title"];
44 $site_url = $line["site_url"];
46 $tmph = $pdo->prepare("SELECT subscribers FROM
47 ttrss_feedbrowser_cache WHERE feed_url = ?");
48 $tmph->execute([$feed_url]);
50 if (!$tmph->fetch()) {
52 $tmph = $pdo->prepare("INSERT INTO ttrss_feedbrowser_cache
53 (feed_url, site_url, title, subscribers)
57 $tmph->execute([$feed_url, $site_url, $title, $subscribers]);
71 static function update_daemon_common($limit = DAEMON_FEED_LIMIT
, $debug = true) {
72 $schema_version = get_schema_version();
74 if ($schema_version != SCHEMA_VERSION
) {
75 die("Schema version is wrong, please upgrade the database.\n");
80 if (!SINGLE_USER_MODE
&& DAEMON_UPDATE_LOGIN_LIMIT
> 0) {
81 if (DB_TYPE
== "pgsql") {
82 $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT
." days'";
84 $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT
." DAY)";
87 $login_thresh_qpart = "";
90 if (DB_TYPE
== "pgsql") {
91 $update_limit_qpart = "AND ((
92 ttrss_feeds.update_interval = 0
93 AND ttrss_user_prefs.value != '-1'
94 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
96 ttrss_feeds.update_interval > 0
97 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
98 ) OR (ttrss_feeds.last_updated IS NULL
99 AND ttrss_user_prefs.value != '-1')
100 OR (last_updated = '1970-01-01 00:00:00'
101 AND ttrss_user_prefs.value != '-1'))";
103 $update_limit_qpart = "AND ((
104 ttrss_feeds.update_interval = 0
105 AND ttrss_user_prefs.value != '-1'
106 AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
108 ttrss_feeds.update_interval > 0
109 AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
110 ) OR (ttrss_feeds.last_updated IS NULL
111 AND ttrss_user_prefs.value != '-1')
112 OR (last_updated = '1970-01-01 00:00:00'
113 AND ttrss_user_prefs.value != '-1'))";
116 // Test if feed is currently being updated by another process.
117 if (DB_TYPE
== "pgsql") {
118 $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')";
120 $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))";
123 $query_limit = $limit ?
sprintf("LIMIT %d", $limit) : "";
125 // Update the least recently updated feeds first
126 $query_order = "ORDER BY last_updated";
127 if (DB_TYPE
== "pgsql") $query_order .= " NULLS FIRST";
129 $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
131 ttrss_feeds, ttrss_users, ttrss_user_prefs
133 ttrss_feeds.owner_uid = ttrss_users.id
134 AND ttrss_user_prefs.profile IS NULL
135 AND ttrss_users.id = ttrss_user_prefs.owner_uid
136 AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
137 $login_thresh_qpart $update_limit_qpart
138 $updstart_thresh_qpart
139 $query_order $query_limit";
141 $res = $pdo->query($query);
143 $feeds_to_update = array();
144 while ($line = $res->fetch()) {
145 array_push($feeds_to_update, $line['feed_url']);
148 if ($debug) _debug(sprintf("Scheduled %d feeds to update...", count($feeds_to_update)));
150 // Update last_update_started before actually starting the batch
151 // in order to minimize collision risk for parallel daemon tasks
152 if (count($feeds_to_update) > 0) {
153 $feeds_qmarks = arr_qmarks($feeds_to_update);
155 $tmph = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
156 WHERE feed_url IN ($feeds_qmarks)");
157 $tmph->execute($feeds_to_update);
161 $bstarted = microtime(true);
163 $batch_owners = array();
165 // since we have the data cached, we can deal with other feeds with the same url
166 $usth = $pdo->prepare("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid
167 FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE
168 ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND
169 ttrss_users.id = ttrss_user_prefs.owner_uid AND
170 ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' AND
171 ttrss_user_prefs.profile IS NULL AND
175 ORDER BY ttrss_feeds.id $query_limit");
177 foreach ($feeds_to_update as $feed) {
178 if($debug) _debug("Base feed: $feed");
180 $usth->execute([$feed]);
181 //update_rss_feed($line["id"], true);
183 if ($tline = $usth->fetch()) {
184 if ($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]);
186 if (array_search($tline["owner_uid"], $batch_owners) === FALSE)
187 array_push($batch_owners, $tline["owner_uid"]);
189 $fstarted = microtime(true);
192 RSSUtils
::update_rss_feed($tline["id"], true, false);
193 } catch (PDOException
$e) {
194 Logger
::get()->log_error(E_USER_NOTICE
, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
196 _debug_suppress(false);
198 _debug(sprintf(" %.4f (sec)", microtime(true) - $fstarted));
205 _debug(sprintf("Processed %d feeds in %.4f (sec), %.4f (sec/feed avg)", $nf,
206 microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf));
209 foreach ($batch_owners as $owner_uid) {
210 _debug("Running housekeeping tasks for user $owner_uid...");
212 RSSUtils
::housekeeping_user($owner_uid);
215 // Send feed digests by email if needed.
216 Digest
::send_headlines_digests($debug);
221 // this is used when subscribing
222 static function set_basic_feed_info($feed) {
226 $sth = $pdo->prepare("SELECT owner_uid,feed_url,auth_pass,auth_login
227 FROM ttrss_feeds WHERE id = ?");
228 $sth->execute([$feed]);
230 if ($row = $sth->fetch()) {
232 $owner_uid = $row["owner_uid"];
233 $auth_login = $row["auth_login"];
234 $auth_pass = $row["auth_pass"];
235 $fetch_url = $row["feed_url"];
237 $pluginhost = new PluginHost();
238 $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
240 $pluginhost->load(PLUGINS
, PluginHost
::KIND_ALL
);
241 $pluginhost->load($user_plugins, PluginHost
::KIND_USER
, $owner_uid);
242 $pluginhost->load_data();
244 $basic_info = array();
245 foreach ($pluginhost->get_hooks(PluginHost
::HOOK_FEED_BASIC_INFO
) as $plugin) {
246 $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass);
250 $feed_data = fetch_file_contents($fetch_url, false,
251 $auth_login, $auth_pass, false,
255 global $fetch_curl_used;
257 if (!$fetch_curl_used) {
258 $tmp = @gzdecode
($feed_data);
260 if ($tmp) $feed_data = $tmp;
263 $feed_data = trim($feed_data);
265 $rss = new FeedParser($feed_data);
268 if (!$rss->error()) {
270 'title' => mb_substr($rss->get_title(), 0, 199),
271 'site_url' => mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245)
276 if ($basic_info && is_array($basic_info)) {
277 $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
278 $sth->execute([$feed]);
280 if ($row = $sth->fetch()) {
282 $registered_title = $row["title"];
283 $orig_site_url = $row["site_url"];
285 if ($basic_info['title'] && (!$registered_title ||
$registered_title == "[Unknown]")) {
287 $sth = $pdo->prepare("UPDATE ttrss_feeds SET
288 title = ? WHERE id = ?");
289 $sth->execute([$basic_info['title'], $feed]);
292 if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) {
293 $sth = $pdo->prepare("UPDATE ttrss_feeds SET
294 site_url = ? WHERE id = ?");
295 $sth->execute([$basic_info['site_url'], $feed]);
304 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
306 static function update_rss_feed($feed, $no_cache = false) {
308 $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') ||
clean($_REQUEST['xdebug']);
310 _debug_suppress(!$debug_enabled);
311 _debug("start", $debug_enabled);
315 $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
316 $sth->execute([$feed]);
318 if (!$row = $sth->fetch()) {
319 _debug("feed $feed NOT FOUND/SKIPPED", $debug_enabled);
320 user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING
);
324 $title = $row["title"];
326 // feed was batch-subscribed or something, we need to get basic info
327 // this is not optimal currently as it fetches stuff separately TODO: optimize
328 if ($title == "[Unknown]") {
329 _debug("setting basic feed info for $feed...");
330 RSSUtils
::set_basic_feed_info($feed);
333 $sth = $pdo->prepare("SELECT id,update_interval,auth_login,
334 feed_url,auth_pass,cache_images,
335 mark_unread_on_update, owner_uid,
336 auth_pass_encrypted, feed_language,
338 ".SUBSTRING_FOR_DATE
."(last_unconditional, 1, 19) AS last_unconditional
339 FROM ttrss_feeds WHERE id = ?");
340 $sth->execute([$feed]);
342 if ($row = $sth->fetch()) {
344 $owner_uid = $row["owner_uid"];
345 $mark_unread_on_update = $row["mark_unread_on_update"];
347 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
349 $sth->execute([$feed]);
351 $auth_login = $row["auth_login"];
352 $auth_pass = $row["auth_pass"];
353 $stored_last_modified = $row["last_modified"];
354 $last_unconditional = $row["last_unconditional"];
355 $cache_images = $row["cache_images"];
356 $fetch_url = $row["feed_url"];
358 $feed_language = mb_strtolower($row["feed_language"]);
359 if (!$feed_language) $feed_language = 'english';
365 $date_feed_processed = date('Y-m-d H:i');
367 $cache_filename = CACHE_DIR
. "/feeds/" . sha1($fetch_url) . ".xml";
369 $pluginhost = new PluginHost();
370 $pluginhost->set_debug($debug_enabled);
371 $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
373 $pluginhost->load(PLUGINS
, PluginHost
::KIND_ALL
);
374 $pluginhost->load($user_plugins, PluginHost
::KIND_USER
, $owner_uid);
375 $pluginhost->load_data();
379 $force_refetch = isset($_REQUEST["force_refetch"]);
382 foreach ($pluginhost->get_hooks(PluginHost
::HOOK_FETCH_FEED
) as $plugin) {
383 $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass);
388 file_exists($cache_filename) &&
389 is_readable($cache_filename) &&
390 !$auth_login && !$auth_pass &&
391 filemtime($cache_filename) > time() - 30) {
393 _debug("using local cache [$cache_filename].", $debug_enabled);
395 @$feed_data = file_get_contents($cache_filename);
398 $rss_hash = sha1($feed_data);
402 _debug("local cache will not be used for this feed", $debug_enabled);
405 global $fetch_last_modified;
407 // fetch feed from source
409 _debug("last unconditional update request: $last_unconditional");
411 if (ini_get("open_basedir") && function_exists("curl_init")) {
412 _debug("not using CURL due to open_basedir restrictions");
415 if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL
) {
416 _debug("maximum allowed interval for conditional requests exceeded, forcing refetch");
418 $force_refetch = true;
420 _debug("stored last modified for conditional request: $stored_last_modified", $debug_enabled);
423 _debug("fetching [$fetch_url] (force_refetch: $force_refetch)...", $debug_enabled);
425 $feed_data = fetch_file_contents([
427 "login" => $auth_login,
428 "pass" => $auth_pass,
429 "timeout" => $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT
: FEED_FETCH_TIMEOUT
,
430 "last_modified" => $force_refetch ?
"" : $stored_last_modified
433 global $fetch_curl_used;
435 if (!$fetch_curl_used) {
436 $tmp = @gzdecode
($feed_data);
438 if ($tmp) $feed_data = $tmp;
441 $feed_data = trim($feed_data);
443 _debug("fetch done.", $debug_enabled);
444 _debug("source last modified: " . $fetch_last_modified, $debug_enabled);
446 if ($feed_data && $fetch_last_modified != $stored_last_modified) {
447 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
448 $sth->execute([substr($fetch_last_modified, 0, 245), $feed]);
451 // cache vanilla feed data for re-use
452 if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR
. "/feeds")) {
453 $new_rss_hash = sha1($feed_data);
455 if ($new_rss_hash != $rss_hash) {
456 _debug("saving $cache_filename", $debug_enabled);
457 @file_put_contents
($cache_filename, $feed_data);
463 global $fetch_last_error;
464 global $fetch_last_error_code;
466 _debug("unable to fetch: $fetch_last_error [$fetch_last_error_code]", $debug_enabled);
469 if ($fetch_last_error_code != 304) {
470 $error_message = $fetch_last_error;
472 _debug("source claims data not modified, nothing to do.", $debug_enabled);
476 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
477 last_updated = NOW() WHERE id = ?");
478 $sth->execute([$error_message, $feed]);
483 foreach ($pluginhost->get_hooks(PluginHost
::HOOK_FEED_FETCHED
) as $plugin) {
484 $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
487 $rss = new FeedParser($feed_data);
490 if (!$rss->error()) {
492 // We use local pluginhost here because we need to load different per-user feed plugins
493 $pluginhost->run_hooks(PluginHost
::HOOK_FEED_PARSED
, "hook_feed_parsed", $rss);
495 _debug("language: $feed_language", $debug_enabled);
496 _debug("processing feed data...", $debug_enabled);
498 if (DB_TYPE
== "pgsql") {
499 $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
501 $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
504 $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color,
505 (favicon_last_checked IS NULL OR $favicon_interval_qpart) AS
507 FROM ttrss_feeds WHERE id = ?");
508 $sth->execute([$feed]);
510 if ($row = $sth->fetch()) {
511 $favicon_needs_check = $row["favicon_needs_check"];
512 $favicon_avg_color = $row["favicon_avg_color"];
513 $owner_uid = $row["owner_uid"];
518 $site_url = mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245);
520 _debug("site_url: $site_url", $debug_enabled);
521 _debug("feed_title: " . $rss->get_title(), $debug_enabled);
523 if ($favicon_needs_check ||
$force_refetch) {
525 /* terrible hack: if we crash on floicon shit here, we won't check
526 * the icon avgcolor again (unless the icon got updated) */
528 $favicon_file = ICONS_DIR
. "/$feed.ico";
529 $favicon_modified = @filemtime
($favicon_file);
531 _debug("checking favicon...", $debug_enabled);
533 RSSUtils
::check_feed_favicon($site_url, $feed);
534 $favicon_modified_new = @filemtime
($favicon_file);
536 if ($favicon_modified_new > $favicon_modified)
537 $favicon_avg_color = '';
539 $favicon_colorstring = "";
540 if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
541 require_once "colors.php";
543 $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE
545 $sth->execute([$feed]);
547 $favicon_color = calculate_avg_color($favicon_file);
549 $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color);
551 } else if ($favicon_avg_color == 'fail') {
552 _debug("floicon failed on this file, not trying to recalculate avg color", $debug_enabled);
555 $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW()
556 $favicon_colorstring WHERE id = ?");
557 $sth->execute([$feed]);
560 _debug("loading filters & labels...", $debug_enabled);
562 $filters = load_filters($feed, $owner_uid);
564 if ($debug_enabled) {
568 _debug("" . count($filters) . " filters loaded.", $debug_enabled);
570 $items = $rss->get_items();
572 if (!is_array($items)) {
573 _debug("no articles found.", $debug_enabled);
575 $sth = $pdo->prepare("UPDATE ttrss_feeds
576 SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?");
577 $sth->execute([$feed]);
579 return true; // no articles
582 _debug("processing articles...", $debug_enabled);
586 foreach ($items as $item) {
587 $pdo->beginTransaction();
589 if (clean($_REQUEST['xdebug']) == 3) {
593 if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
594 _debug("looks like there's too many articles to process at once, breaking out", $debug_enabled);
599 $entry_guid = strip_tags($item->get_id());
600 if (!$entry_guid) $entry_guid = strip_tags($item->get_link());
601 if (!$entry_guid) $entry_guid = RSSUtils
::make_guid_from_title($item->get_title());
608 $entry_guid = "$owner_uid,$entry_guid";
610 $entry_guid_hashed = 'SHA1:' . sha1($entry_guid);
612 _debug("guid $entry_guid / $entry_guid_hashed", $debug_enabled);
614 $entry_timestamp = strip_tags($item->get_date());
616 _debug("orig date: " . $item->get_date(), $debug_enabled);
618 if ($entry_timestamp == -1 ||
!$entry_timestamp ||
$entry_timestamp > time()) {
619 $entry_timestamp = time();
622 $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
624 _debug("date $entry_timestamp [$entry_timestamp_fmt]", $debug_enabled);
626 $entry_title = strip_tags($item->get_title());
628 $entry_link = rewrite_relative_url($site_url, $item->get_link());
630 $entry_language = mb_substr(trim($item->get_language()), 0, 2);
632 _debug("title $entry_title", $debug_enabled);
633 _debug("link $entry_link", $debug_enabled);
634 _debug("language $entry_language", $debug_enabled);
636 if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);;
638 $entry_content = $item->get_content();
639 if (!$entry_content) $entry_content = $item->get_description();
641 if (clean($_REQUEST["xdebug"]) == 2) {
643 print htmlspecialchars($entry_content);
647 $entry_comments = mb_substr(strip_tags($item->get_comments_url()), 0, 245);
648 $num_comments = (int) $item->get_comments_count();
650 $entry_author = strip_tags($item->get_author());
651 $entry_guid = mb_substr($entry_guid, 0, 245);
653 _debug("author $entry_author", $debug_enabled);
654 _debug("num_comments: $num_comments", $debug_enabled);
655 _debug("looking for tags...", $debug_enabled);
657 // parse <category> entries into tags
659 $additional_tags = array();
661 $additional_tags_src = $item->get_categories();
663 if (is_array($additional_tags_src)) {
664 foreach ($additional_tags_src as $tobj) {
665 array_push($additional_tags, $tobj);
669 $entry_tags = array_unique($additional_tags);
671 for ($i = 0; $i < count($entry_tags); $i++
) {
672 $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
674 // we don't support numeric tags, let's prefix them
675 if (is_numeric($entry_tags[$i])) $entry_tags[$i] = 't:' . $entry_tags[$i];
678 _debug("tags found: " . join(",", $entry_tags), $debug_enabled);
680 _debug("done collecting data.", $debug_enabled);
682 $sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries
683 WHERE guid = ? OR guid = ?");
684 $sth->execute([$entry_guid, $entry_guid_hashed]);
686 if ($row = $sth->fetch()) {
687 $base_entry_id = $row["id"];
688 $entry_stored_hash = $row["content_hash"];
689 $article_labels = Article
::get_article_labels($base_entry_id, $owner_uid);
691 $existing_tags = Article
::get_article_tags($base_entry_id, $owner_uid);
692 $entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
694 $base_entry_id = false;
695 $entry_stored_hash = "";
696 $article_labels = array();
699 $article = array("owner_uid" => $owner_uid, // read only
700 "guid" => $entry_guid, // read only
701 "guid_hashed" => $entry_guid_hashed, // read only
702 "title" => $entry_title,
703 "content" => $entry_content,
704 "link" => $entry_link,
705 "labels" => $article_labels, // current limitation: can add labels to article, can't remove them
706 "tags" => $entry_tags,
707 "author" => $entry_author,
708 "force_catchup" => false, // ugly hack for the time being
709 "score_modifier" => 0, // no previous value, plugin should recalculate score modifier based on content if needed
710 "language" => $entry_language,
711 "num_comments" => $num_comments, // read only
712 "feed" => array("id" => $feed,
713 "fetch_url" => $fetch_url,
714 "site_url" => $site_url,
715 "cache_images" => $cache_images)
718 $entry_plugin_data = "";
719 $entry_current_hash = RSSUtils
::calculate_article_hash($article, $pluginhost);
721 _debug("article hash: $entry_current_hash [stored=$entry_stored_hash]", $debug_enabled);
723 if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) {
724 _debug("stored article seems up to date [IID: $base_entry_id], updating timestamp only", $debug_enabled);
726 // we keep encountering the entry in feeds, so we need to
727 // update date_updated column so that we don't get horrible
728 // dupes when the entry gets purged and reinserted again e.g.
729 // in the case of SLOW SLOW OMG SLOW updating feeds
731 $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW()
733 $sth->execute([$base_entry_id]);
739 _debug("hash differs, applying plugin filters:", $debug_enabled);
741 foreach ($pluginhost->get_hooks(PluginHost
::HOOK_ARTICLE_FILTER
) as $plugin) {
742 _debug("... " . get_class($plugin), $debug_enabled);
744 $start = microtime(true);
745 $article = $plugin->hook_article_filter($article);
747 _debug("=== " . sprintf("%.4f (sec)", microtime(true) - $start), $debug_enabled);
749 $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ",";
752 if (clean($_REQUEST["xdebug"]) == 2) {
753 print "processed content: ";
754 print htmlspecialchars($article["content"]);
758 _debug("plugin data: $entry_plugin_data", $debug_enabled);
760 // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
761 if (DB_TYPE
== "mysql" && MYSQL_CHARSET
!= "UTF8MB4") {
762 foreach ($article as $k => $v) {
763 // i guess we'll have to take the risk of 4byte unicode labels & tags here
764 if (is_string($article[$k])) {
765 $article[$k] = RSSUtils
::strip_utf8mb4($v);
770 /* Collect article tags here so we could filter by them: */
772 $matched_rules = array();
774 $article_filters = RSSUtils
::get_article_filters($filters, $article["title"],
775 $article["content"], $article["link"], $article["author"],
776 $article["tags"], $matched_rules);
778 if ($debug_enabled) {
779 _debug("matched filter rules: ", $debug_enabled);
781 if (count($matched_rules) != 0) {
782 print_r($matched_rules);
785 _debug("filter actions: ", $debug_enabled);
787 if (count($article_filters) != 0) {
788 print_r($article_filters);
792 $plugin_filter_names = RSSUtils
::find_article_filters($article_filters, "plugin");
793 $plugin_filter_actions = $pluginhost->get_filter_actions();
795 if (count($plugin_filter_names) > 0) {
796 _debug("applying plugin filter actions...", $debug_enabled);
798 foreach ($plugin_filter_names as $pfn) {
799 list($pfclass,$pfaction) = explode(":", $pfn["param"]);
801 if (isset($plugin_filter_actions[$pfclass])) {
802 $plugin = $pluginhost->get_plugin($pfclass);
804 _debug("... $pfclass: $pfaction", $debug_enabled);
807 $start = microtime(true);
808 $article = $plugin->hook_article_filter_action($article, $pfaction);
810 _debug("=== " . sprintf("%.4f (sec)", microtime(true) - $start), $debug_enabled);
812 _debug("??? $pfclass: plugin object not found.");
815 _debug("??? $pfclass: filter plugin not registered.");
820 $entry_tags = $article["tags"];
821 $entry_title = strip_tags($article["title"]);
822 $entry_author = mb_substr(strip_tags($article["author"]), 0, 245);
823 $entry_link = strip_tags($article["link"]);
824 $entry_content = $article["content"]; // escaped below
825 $entry_force_catchup = $article["force_catchup"];
826 $article_labels = $article["labels"];
827 $entry_score_modifier = (int) $article["score_modifier"];
828 $entry_language = $article["language"];
830 if ($debug_enabled) {
831 _debug("article labels:", $debug_enabled);
833 if (count($article_labels) != 0) {
834 print_r($article_labels);
838 _debug("force catchup: $entry_force_catchup");
840 if ($cache_images && is_writable(CACHE_DIR
. '/images'))
841 RSSUtils
::cache_media($entry_content, $site_url, $debug_enabled);
843 $csth = $pdo->prepare("SELECT id FROM ttrss_entries
844 WHERE guid = ? OR guid = ?");
845 $csth->execute([$entry_guid, $entry_guid_hashed]);
847 if (!$row = $csth->fetch()) {
849 _debug("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", $debug_enabled);
851 // base post entry does not exist, create it
853 $usth = $pdo->prepare(
854 "INSERT INTO ttrss_entries
875 $usth->execute([$entry_title,
878 $entry_timestamp_fmt,
881 $date_feed_processed,
890 $csth->execute([$entry_guid, $entry_guid_hashed]);
895 if ($row = $csth->fetch()) {
897 _debug("base guid found, checking for user record", $debug_enabled);
899 $ref_id = $row['id'];
900 $entry_ref_id = $ref_id;
902 if (RSSUtils
::find_article_filter($article_filters, "filter")) {
907 $score = RSSUtils
::calculate_article_score($article_filters) +
$entry_score_modifier;
909 _debug("initial score: $score [including plugin modifier: $entry_score_modifier]", $debug_enabled);
911 // check for user post link to main table
913 $sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE
914 ref_id = ? AND owner_uid = ?");
915 $sth->execute([$ref_id, $owner_uid]);
917 // okay it doesn't exist - create user entry
918 if ($row = $sth->fetch()) {
919 $entry_ref_id = $row["ref_id"];
920 $entry_int_id = $row["int_id"];
922 _debug("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
925 _debug("user record not found, creating...", $debug_enabled);
927 if ($score >= -500 && !RSSUtils
::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
929 $last_read_qpart = null;
932 $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted
935 if (RSSUtils
::find_article_filter($article_filters, 'mark') ||
$score > 1000) {
941 if (RSSUtils
::find_article_filter($article_filters, 'publish')) {
947 $last_marked = ($marked == 1) ?
'NOW()' : 'NULL';
948 $last_published = ($published == 1) ?
'NOW()' : 'NULL';
950 $sth = $pdo->prepare(
951 "INSERT INTO ttrss_user_entries
952 (ref_id, owner_uid, feed_id, unread, last_read, marked,
953 published, score, tag_cache, label_cache, uuid,
954 last_marked, last_published)
955 VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")");
957 $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked,
958 $published, $score]);
960 $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
961 ref_id = ? AND owner_uid = ? AND
962 feed_id = ? LIMIT 1");
964 $sth->execute([$ref_id, $owner_uid, $feed]);
966 if ($row = $sth->fetch())
967 $entry_int_id = $row['int_id'];
970 _debug("resulting RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
972 if (DB_TYPE
== "pgsql")
973 $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
975 $tsvector_qpart = "";
977 $sth = $pdo->prepare("UPDATE ttrss_entries
981 content_hash = :content_hash,
983 date_updated = NOW(),
984 num_comments = :num_comments,
985 plugin_data = :plugin_data,
990 $params = [":title" => $entry_title,
991 ":content" => "$entry_content",
992 ":content_hash" => $entry_current_hash,
993 ":updated" => $entry_timestamp_fmt,
994 ":num_comments" => (int)$num_comments,
995 ":plugin_data" => $entry_plugin_data,
996 ":author" => "$entry_author",
997 ":lang" => $entry_language,
1000 if (DB_TYPE
== "pgsql") {
1001 $params[":ts_lang"] = $feed_language;
1002 $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000);
1005 $sth->execute($params);
1008 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1009 SET score = ? WHERE ref_id = ?");
1010 $sth->execute([$score, $ref_id]);
1012 if ($mark_unread_on_update) {
1013 _debug("article updated, marking unread as requested.", $debug_enabled);
1015 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1016 SET last_read = null, unread = true WHERE ref_id = ?");
1017 $sth->execute([$ref_id]);
1021 _debug("assigning labels [other]...", $debug_enabled);
1023 foreach ($article_labels as $label) {
1024 Labels
::add_article($entry_ref_id, $label[1], $owner_uid);
1027 _debug("assigning labels [filters]...", $debug_enabled);
1029 RSSUtils
::assign_article_to_label_filters($entry_ref_id, $article_filters,
1030 $owner_uid, $article_labels);
1032 _debug("looking for enclosures...", $debug_enabled);
1036 $enclosures = array();
1038 $encs = $item->get_enclosures();
1040 if (is_array($encs)) {
1041 foreach ($encs as $e) {
1043 rewrite_relative_url($site_url, $e->link
),
1044 $e->type
, $e->length
, $e->title
, $e->width
, $e->height
);
1046 // Yet another episode of "mysql utf8_general_ci is gimped"
1047 if (DB_TYPE
== "mysql" && MYSQL_CHARSET
!= "UTF8MB4") {
1048 for ($i = 0; $i < count($e_item); $i++
) {
1049 if (is_string($e_item[$i])) {
1050 $e_item[$i] = RSSUtils
::strip_utf8mb4($e_item[$i]);
1055 array_push($enclosures, $e_item);
1059 if ($cache_images && is_writable(CACHE_DIR
. '/images'))
1060 RSSUtils
::cache_enclosures($enclosures, $site_url, $debug_enabled);
1062 if ($debug_enabled) {
1063 _debug("article enclosures:", $debug_enabled);
1064 print_r($enclosures);
1067 $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures
1068 WHERE content_url = ? AND content_type = ? AND post_id = ?");
1070 $usth = $pdo->prepare("INSERT INTO ttrss_enclosures
1071 (content_url, content_type, title, duration, post_id, width, height) VALUES
1072 (?, ?, ?, ?, ?, ?, ?)");
1074 foreach ($enclosures as $enc) {
1076 $enc_type = $enc[1];
1077 $enc_dur = (int)$enc[2];
1078 $enc_title = $enc[3];
1079 $enc_width = intval($enc[4]);
1080 $enc_height = intval($enc[5]);
1082 $esth->execute([$enc_url, $enc_type, $entry_ref_id]);
1084 if (!$esth->fetch()) {
1085 $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
1089 // check for manual tags (we have to do it here since they're loaded from filters)
1091 foreach ($article_filters as $f) {
1092 if ($f["type"] == "tag") {
1094 $manual_tags = trim_array(explode(",", $f["param"]));
1096 foreach ($manual_tags as $tag) {
1097 if (tag_is_valid($tag)) {
1098 array_push($entry_tags, $tag);
1106 $boring_tags = trim_array(explode(",", mb_strtolower(get_pref(
1107 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
1109 $filtered_tags = array();
1110 $tags_to_cache = array();
1112 if ($entry_tags && is_array($entry_tags)) {
1113 foreach ($entry_tags as $tag) {
1114 if (array_search($tag, $boring_tags) === false) {
1115 array_push($filtered_tags, $tag);
1120 $filtered_tags = array_unique($filtered_tags);
1122 if ($debug_enabled) {
1123 _debug("filtered article tags:", $debug_enabled);
1124 print_r($filtered_tags);
1127 // Save article tags in the database
1129 if (count($filtered_tags) > 0) {
1131 $tsth = $pdo->prepare("SELECT id FROM ttrss_tags
1132 WHERE tag_name = ? AND post_int_id = ? AND
1133 owner_uid = ? LIMIT 1");
1135 $usth = $pdo->prepare("INSERT INTO ttrss_tags
1136 (owner_uid,tag_name,post_int_id)
1139 foreach ($filtered_tags as $tag) {
1141 $tag = sanitize_tag($tag);
1143 if (!tag_is_valid($tag)) continue;
1145 $tsth->execute([$tag, $entry_int_id, $owner_uid]);
1147 if (!$tsth->fetch()) {
1148 $usth->execute([$owner_uid, $tag, $entry_int_id]);
1151 array_push($tags_to_cache, $tag);
1154 /* update the cache */
1156 $tags_to_cache = array_unique($tags_to_cache);
1158 $tags_str = join(",", $tags_to_cache);
1160 $tsth = $pdo->prepare("UPDATE ttrss_user_entries
1161 SET tag_cache = ? WHERE ref_id = ?
1162 AND owner_uid = ?");
1163 $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]);
1166 _debug("article processed", $debug_enabled);
1171 _debug("purging feed...", $debug_enabled);
1173 purge_feed($feed, 0, $debug_enabled);
1175 $sth = $pdo->prepare("UPDATE ttrss_feeds
1176 SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?");
1177 $sth->execute([$feed]);
1181 $error_msg = mb_substr($rss->error(), 0, 245);
1183 _debug("fetch error: $error_msg", $debug_enabled);
1185 if (count($rss->errors()) > 1) {
1186 foreach ($rss->errors() as $error) {
1191 $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
1192 last_updated = NOW(), last_unconditional = NOW() WHERE id = ?");
1193 $sth->execute([$error_msg, $feed]);
1199 _debug("done", $debug_enabled);
1204 static function cache_enclosures($enclosures, $site_url, $debug) {
1205 foreach ($enclosures as $enc) {
1207 if (preg_match("/(image|audio|video)/", $enc[1])) {
1209 $src = rewrite_relative_url($site_url, $enc[0]);
1211 $local_filename = CACHE_DIR
. "/images/" . sha1($src);
1213 if ($debug) _debug("cache_enclosures: downloading: $src to $local_filename");
1215 if (!file_exists($local_filename)) {
1216 $file_content = fetch_file_contents($src);
1218 if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE
) {
1219 file_put_contents($local_filename, $file_content);
1221 } else if (is_writable($local_filename)) {
1222 touch($local_filename);
1228 static function cache_media($html, $site_url, $debug) {
1229 libxml_use_internal_errors(true);
1231 $charset_hack = '<head>
1232 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
1235 $doc = new DOMDocument();
1236 $doc->loadHTML($charset_hack . $html);
1237 $xpath = new DOMXPath($doc);
1239 $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])');
1241 foreach ($entries as $entry) {
1242 if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
1243 $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
1245 $local_filename = CACHE_DIR
. "/images/" . sha1($src);
1247 if ($debug) _debug("cache_media: checking $src");
1249 if (!file_exists($local_filename)) {
1250 if ($debug) _debug("cache_media: downloading: $src to $local_filename");
1252 $file_content = fetch_file_contents($src);
1254 if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE
) {
1255 file_put_contents($local_filename, $file_content);
1257 } else if (is_writable($local_filename)) {
1258 touch($local_filename);
1264 static function expire_error_log($debug) {
1265 if ($debug) _debug("Removing old error log entries...");
1269 if (DB_TYPE
== "pgsql") {
1270 $pdo->query("DELETE FROM ttrss_error_log
1271 WHERE created_at < NOW() - INTERVAL '7 days'");
1273 $pdo->query("DELETE FROM ttrss_error_log
1274 WHERE created_at < DATE_SUB(NOW(), INTERVAL 7 DAY)");
1278 static function expire_lock_files($debug) {
1279 //if ($debug) _debug("Removing old lock files...");
1283 if (is_writable(LOCK_DIRECTORY
)) {
1284 $files = glob(LOCK_DIRECTORY
. "/*.lock");
1287 foreach ($files as $file) {
1288 if (!file_is_locked(basename($file)) && time() - filemtime($file) > 86400*2) {
1296 if ($debug) _debug("Removed $num_deleted old lock files.");
1299 static function expire_cached_files($debug) {
1300 foreach (array("simplepie", "feeds", "images", "export", "upload") as $dir) {
1301 $cache_dir = CACHE_DIR
. "/$dir";
1303 // if ($debug) _debug("Expiring $cache_dir");
1307 if (is_writable($cache_dir)) {
1308 $files = glob("$cache_dir/*");
1311 foreach ($files as $file) {
1312 if (time() - filemtime($file) > 86400*CACHE_MAX_DAYS
) {
1321 if ($debug) _debug("$cache_dir: removed $num_deleted files.");
1326 * Source: http://www.php.net/manual/en/function.parse-url.php#104527
1327 * Returns the url query as associative array
1329 * @param string query
1330 * @return array params
1332 static function convertUrlQuery($query) {
1333 $queryParts = explode('&', $query);
1337 foreach ($queryParts as $param) {
1338 $item = explode('=', $param);
1339 $params[$item[0]] = $item[1];
1345 static function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false) {
1348 foreach ($filters as $filter) {
1349 $match_any_rule = $filter["match_any_rule"];
1350 $inverse = $filter["inverse"];
1351 $filter_match = false;
1353 foreach ($filter["rules"] as $rule) {
1355 $reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
1356 $rule_inverse = $rule["inverse"];
1361 switch ($rule["type"]) {
1363 $match = @preg_match
("/$reg_exp/iu", $title);
1366 // we don't need to deal with multiline regexps
1367 $content = preg_replace("/[\r\n\t]/", "", $content);
1369 $match = @preg_match
("/$reg_exp/iu", $content);
1372 // we don't need to deal with multiline regexps
1373 $content = preg_replace("/[\r\n\t]/", "", $content);
1375 $match = (@preg_match
("/$reg_exp/iu", $title) || @preg_match
("/$reg_exp/iu", $content));
1378 $match = @preg_match
("/$reg_exp/iu", $link);
1381 $match = @preg_match
("/$reg_exp/iu", $author);
1384 foreach ($tags as $tag) {
1385 if (@preg_match
("/$reg_exp/iu", $tag)) {
1393 if ($rule_inverse) $match = !$match;
1395 if ($match_any_rule) {
1397 $filter_match = true;
1401 $filter_match = $match;
1408 if ($inverse) $filter_match = !$filter_match;
1410 if ($filter_match) {
1411 if (is_array($matched_rules)) array_push($matched_rules, $rule);
1413 foreach ($filter["actions"] AS $action) {
1414 array_push($matches, $action);
1416 // if Stop action encountered, perform no further processing
1417 if (isset($action["type"]) && $action["type"] == "stop") return $matches;
1425 static function find_article_filter($filters, $filter_name) {
1426 foreach ($filters as $f) {
1427 if ($f["type"] == $filter_name) {
1434 static function find_article_filters($filters, $filter_name) {
1437 foreach ($filters as $f) {
1438 if ($f["type"] == $filter_name) {
1439 array_push($results, $f);
1445 static function calculate_article_score($filters) {
1448 foreach ($filters as $f) {
1449 if ($f["type"] == "score") {
1450 $score +
= $f["param"];
1456 static function labels_contains_caption($labels, $caption) {
1457 foreach ($labels as $label) {
1458 if ($label[1] == $caption) {
1466 static function assign_article_to_label_filters($id, $filters, $owner_uid, $article_labels) {
1467 foreach ($filters as $f) {
1468 if ($f["type"] == "label") {
1469 if (!RSSUtils
::labels_contains_caption($article_labels, $f["param"])) {
1470 Labels
::add_article($id, $f["param"], $owner_uid);
1476 static function make_guid_from_title($title) {
1477 return preg_replace("/[ \"\',.:;]/", "-",
1478 mb_strtolower(strip_tags($title), 'utf-8'));
1481 static function cleanup_counters_cache($debug) {
1484 $res = $pdo->query("DELETE FROM ttrss_counters_cache
1485 WHERE feed_id > 0 AND
1486 (SELECT COUNT(id) FROM ttrss_feeds WHERE
1488 ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0");
1490 $frows = $res->rowCount();
1492 $res = $pdo->query("DELETE FROM ttrss_cat_counters_cache
1493 WHERE feed_id > 0 AND
1494 (SELECT COUNT(id) FROM ttrss_feed_categories WHERE
1496 ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0");
1498 $crows = $res->rowCount();
1500 if ($debug) _debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries.");
1503 static function housekeeping_user($owner_uid) {
1504 $tmph = new PluginHost();
1506 load_user_plugins($owner_uid, $tmph);
1508 $tmph->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", "");
1511 static function housekeeping_common($debug) {
1512 RSSUtils
::expire_cached_files($debug);
1513 RSSUtils
::expire_lock_files($debug);
1514 RSSUtils
::expire_error_log($debug);
1516 $count = RSSUtils
::update_feedbrowser_cache();
1517 _debug("Feedbrowser updated, $count feeds processed.");
1519 Article
::purge_orphans( true);
1520 RSSUtils
::cleanup_counters_cache($debug);
1522 //$rc = cleanup_tags( 14, 50000);
1523 //_debug("Cleaned $rc cached tags.");
1525 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", "");
1528 static function check_feed_favicon($site_url, $feed) {
1529 # print "FAVICON [$site_url]: $favicon_url\n";
1531 $icon_file = ICONS_DIR
. "/$feed.ico";
1533 if (!file_exists($icon_file)) {
1534 $favicon_url = get_favicon_url($site_url);
1537 // Limiting to "image" type misses those served with text/plain
1538 $contents = fetch_file_contents($favicon_url); // , "image");
1541 // Crude image type matching.
1542 // Patterns gleaned from the file(1) source code.
1543 if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
1544 // 0 string \000\000\001\000 MS Windows icon resource
1545 //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
1547 elseif (preg_match('/^GIF8/', $contents)) {
1548 // 0 string GIF8 GIF image data
1549 //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
1551 elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
1552 // 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data
1553 //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
1555 elseif (preg_match('/^\xff\xd8/', $contents)) {
1556 // 0 beshort 0xffd8 JPEG image data
1557 //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
1559 elseif (preg_match('/^BM/', $contents)) {
1560 // 0 string BM PC bitmap (OS2, Windows BMP files)
1561 //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image");
1564 //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
1570 $fp = @fopen
($icon_file, "w");
1573 fwrite($fp, $contents);
1575 chmod($icon_file, 0644);