summaryrefslogtreecommitdiff
path: root/classes/rssutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/rssutils.php')
-rwxr-xr-xclasses/rssutils.php557
1 files changed, 264 insertions, 293 deletions
diff --git a/classes/rssutils.php b/classes/rssutils.php
index 11a94162c..e6bf08ab1 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -21,7 +21,7 @@ class RSSUtils {
}
// Strips utf8mb4 characters (i.e. emoji) for mysql
- static function strip_utf8mb4($str) {
+ static function strip_utf8mb4(string $str) {
return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
}
@@ -52,10 +52,10 @@ class RSSUtils {
}
}
- static function update_daemon_common($limit = null, $options = []) {
+ static function update_daemon_common(int $limit = 0, array $options = []) {
if (!$limit) $limit = Config::get(Config::DAEMON_FEED_LIMIT);
- if (get_schema_version() != SCHEMA_VERSION) {
+ if (Config::get_schema_version() != Config::SCHEMA_VERSION) {
die("Schema version is wrong, please upgrade the database.\n");
}
@@ -78,27 +78,27 @@ class RSSUtils {
if (Config::get(Config::DB_TYPE) == "pgsql") {
$update_limit_qpart = "AND ((
update_interval = 0
- AND p.value != '-1'
+ AND (p.value IS NULL OR p.value != '-1')
AND last_updated < NOW() - CAST((COALESCE(p.value, '$default_interval') || ' minutes') AS INTERVAL)
) OR (
update_interval > 0
AND last_updated < NOW() - CAST((update_interval || ' minutes') AS INTERVAL)
) OR (
update_interval >= 0
- AND p.value != '-1'
+ AND (p.value IS NULL OR p.value != '-1')
AND (last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
))";
} else {
$update_limit_qpart = "AND ((
update_interval = 0
- AND p.value != '-1'
+ AND (p.value IS NULL OR p.value != '-1')
AND last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(COALESCE(p.value, '$default_interval'), SIGNED INTEGER) MINUTE)
) OR (
update_interval > 0
AND last_updated < DATE_SUB(NOW(), INTERVAL update_interval MINUTE)
) OR (
update_interval >= 0
- AND p.value != '-1'
+ AND (p.value IS NULL OR p.value != '-1')
AND (last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
))";
}
@@ -229,11 +229,9 @@ class RSSUtils {
} else {
try {
if (!self::update_rss_feed($tline["id"], true)) {
- global $fetch_last_error;
-
Logger::log(E_USER_NOTICE,
sprintf("Update request for feed %d (%s, owner UID: %d) failed: %s.",
- $tline["id"], clean($tline["title"]), $tline["owner_uid"], clean($fetch_last_error)));
+ $tline["id"], clean($tline["title"]), $tline["owner_uid"], clean(UrlHelper::$fetch_last_error)));
}
Debug::log(sprintf("<= %.4f (sec) (not using a separate process)", microtime(true) - $fstarted));
@@ -271,8 +269,8 @@ class RSSUtils {
return $nf;
}
- // this is used when subscribing
- static function set_basic_feed_info($feed) {
+ /** this is used when subscribing; TODO: update to ORM */
+ static function update_basic_info(int $feed) {
$pdo = Db::pdo();
@@ -346,215 +344,197 @@ class RSSUtils {
}
}
- static function update_rss_feed($feed, $no_cache = false) {
+ static function update_rss_feed(int $feed, bool $no_cache = false) : bool {
- Debug::log("start", Debug::$LOG_VERBOSE);
+ Debug::log("start", Debug::LOG_VERBOSE);
$pdo = Db::pdo();
- $sth = $pdo->prepare("SELECT title, site_url FROM ttrss_feeds WHERE id = ?");
- $sth->execute([$feed]);
-
- if (!$row = $sth->fetch()) {
- Debug::log("feed $feed not found, skipping.");
- user_error("Attempt to update unknown/invalid feed $feed", E_USER_WARNING);
- return false;
- }
-
- $title = $row["title"];
- $site_url = $row["site_url"];
-
- // feed was batch-subscribed or something, we need to get basic info
- // this is not optimal currently as it fetches stuff separately TODO: optimize
- if ($title == "[Unknown]" || !$title || !$site_url) {
- Debug::log("setting basic feed info for $feed [$title, $site_url]...");
- self::set_basic_feed_info($feed);
+ if (Config::get(Config::DB_TYPE) == "pgsql") {
+ $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
+ } else {
+ $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
}
- $sth = $pdo->prepare("SELECT id,update_interval,auth_login,
- feed_url,auth_pass,cache_images,
- mark_unread_on_update, owner_uid,
- auth_pass_encrypted, feed_language,
- last_modified,
- ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional
- FROM ttrss_feeds WHERE id = ?");
- $sth->execute([$feed]);
+ $feed_obj = ORM::for_table('ttrss_feeds')
+ ->select_expr("ttrss_feeds.*,
+ ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional,
+ (favicon_is_custom IS NOT TRUE AND
+ (favicon_last_checked IS NULL OR $favicon_interval_qpart)) AS favicon_needs_check")
+ ->find_one($feed);
- if ($row = $sth->fetch()) {
+ if ($feed_obj) {
+ $feed_obj->last_update_started = Db::NOW();
+ $feed_obj->save();
- $owner_uid = $row["owner_uid"];
- $mark_unread_on_update = $row["mark_unread_on_update"];
+ $feed_language = mb_strtolower($feed_obj->feed_language);
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
- WHERE id = ?");
- $sth->execute([$feed]);
-
- $auth_login = $row["auth_login"];
- $auth_pass = $row["auth_pass"];
- $stored_last_modified = $row["last_modified"];
- $last_unconditional = $row["last_unconditional"];
- $cache_images = $row["cache_images"];
- $fetch_url = $row["feed_url"];
-
- $feed_language = mb_strtolower($row["feed_language"]);
-
- if (!$feed_language)
- $feed_language = mb_strtolower(get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $owner_uid));
-
- if (!$feed_language)
- $feed_language = 'simple';
+ if (!$feed_language) $feed_language = mb_strtolower(get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $feed_obj->owner_uid));
+ if (!$feed_language) $feed_language = 'simple';
} else {
+ Debug::log("error: feeds table record not found for feed: $feed");
return false;
}
+ // feed was batch-subscribed or something, we need to get basic info
+ // this is not optimal currently as it fetches stuff separately TODO: optimize
+ if ($feed_obj->title == "[Unknown]" || empty($feed_obj->title) || empty($feed_obj->site_url)) {
+ Debug::log("setting basic feed info for $feed...");
+ self::update_basic_info($feed);
+ }
+
$date_feed_processed = date('Y-m-d H:i');
- $cache_filename = Config::get(Config::CACHE_DIR) . "/feeds/" . sha1($fetch_url) . ".xml";
+ $cache_filename = Config::get(Config::CACHE_DIR) . "/feeds/" . sha1($feed_obj->feed_url) . ".xml";
$pluginhost = new PluginHost();
- $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid);
+ $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $feed_obj->owner_uid);
$pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
- $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
- //$pluginhost->load_data();
+ $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $feed_obj->owner_uid);
$rss_hash = false;
$force_refetch = isset($_REQUEST["force_refetch"]);
$feed_data = "";
- Debug::log("running HOOK_FETCH_FEED handlers...", Debug::$LOG_VERBOSE);
+ Debug::log("running HOOK_FETCH_FEED handlers...", Debug::LOG_VERBOSE);
$start_ts = microtime(true);
$last_article_timestamp = 0;
+
+ $hff_owner_uid = $feed_obj->owner_uid;
+ $hff_feed_url = $feed_obj->feed_url;
+
$pluginhost->chain_hooks_callback(PluginHost::HOOK_FETCH_FEED,
function ($result, $plugin) use (&$feed_data, $start_ts) {
$feed_data = $result;
- Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::LOG_VERBOSE);
},
- $feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass);
+ $feed_data, $hff_feed_url, $hff_owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass);
if ($feed_data) {
- Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
+ Debug::log("feed data has been modified by a plugin.", Debug::LOG_VERBOSE);
} else {
- Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
+ Debug::log("feed data has not been modified by a plugin.", Debug::LOG_VERBOSE);
}
// try cache
if (!$feed_data &&
- file_exists($cache_filename) &&
is_readable($cache_filename) &&
- !$auth_login && !$auth_pass &&
+ !$feed_obj->auth_login && !$feed_obj->auth_pass &&
filemtime($cache_filename) > time() - 30) {
- Debug::log("using local cache [$cache_filename].", Debug::$LOG_VERBOSE);
+ Debug::log("using local cache: {$cache_filename}.", Debug::LOG_VERBOSE);
- @$feed_data = file_get_contents($cache_filename);
+ $feed_data = file_get_contents($cache_filename);
if ($feed_data) {
$rss_hash = sha1($feed_data);
}
} else {
- Debug::log("local cache will not be used for this feed", Debug::$LOG_VERBOSE);
+ Debug::log("local cache will not be used for this feed", Debug::LOG_VERBOSE);
}
- global $fetch_last_modified;
-
// fetch feed from source
if (!$feed_data) {
- Debug::log("last unconditional update request: $last_unconditional", Debug::$LOG_VERBOSE);
+ Debug::log("last unconditional update request: {$feed_obj->last_unconditional}", Debug::LOG_VERBOSE);
if (ini_get("open_basedir") && function_exists("curl_init")) {
- Debug::log("not using CURL due to open_basedir restrictions", Debug::$LOG_VERBOSE);
+ Debug::log("not using CURL due to open_basedir restrictions", Debug::LOG_VERBOSE);
}
- if (time() - strtotime($last_unconditional) > Config::get(Config::MAX_CONDITIONAL_INTERVAL)) {
- Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::$LOG_VERBOSE);
+ if (time() - strtotime($feed_obj->last_unconditional) > Config::get(Config::MAX_CONDITIONAL_INTERVAL)) {
+ Debug::log("maximum allowed interval for conditional requests exceeded, forcing refetch", Debug::LOG_VERBOSE);
$force_refetch = true;
} else {
- Debug::log("stored last modified for conditional request: $stored_last_modified", Debug::$LOG_VERBOSE);
+ Debug::log("stored last modified for conditional request: {$feed_obj->last_modified}", Debug::LOG_VERBOSE);
}
- Debug::log("fetching [$fetch_url] (force_refetch: $force_refetch)...", Debug::$LOG_VERBOSE);
+ Debug::log("fetching {$feed_obj->feed_url} (force_refetch: $force_refetch)...", Debug::LOG_VERBOSE);
$feed_data = UrlHelper::fetch([
- "url" => $fetch_url,
- "login" => $auth_login,
- "pass" => $auth_pass,
+ "url" => $feed_obj->feed_url,
+ "login" => $feed_obj->auth_login,
+ "pass" => $feed_obj->auth_pass,
"timeout" => $no_cache ? Config::get(Config::FEED_FETCH_NO_CACHE_TIMEOUT) : Config::get(Config::FEED_FETCH_TIMEOUT),
- "last_modified" => $force_refetch ? "" : $stored_last_modified
+ "last_modified" => $force_refetch ? "" : $feed_obj->last_modified
]);
$feed_data = trim($feed_data);
- global $fetch_effective_url;
- global $fetch_effective_ip_addr;
+ Debug::log("fetch done.", Debug::LOG_VERBOSE);
+ Debug::log(sprintf("effective URL (after redirects): %s (IP: %s) ", UrlHelper::$fetch_effective_url, UrlHelper::$fetch_effective_ip_addr), Debug::LOG_VERBOSE);
+ Debug::log("server last modified: " . UrlHelper::$fetch_last_modified, Debug::LOG_VERBOSE);
- Debug::log("fetch done.", Debug::$LOG_VERBOSE);
- Debug::log("effective URL (after redirects): " . clean($fetch_effective_url) . " (IP: $fetch_effective_ip_addr)", Debug::$LOG_VERBOSE);
- Debug::log("source last modified: " . $fetch_last_modified, Debug::$LOG_VERBOSE);
-
- if ($feed_data && $fetch_last_modified != $stored_last_modified) {
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_modified = ? WHERE id = ?");
- $sth->execute([substr($fetch_last_modified, 0, 245), $feed]);
+ if ($feed_data && UrlHelper::$fetch_last_modified != $feed_obj->last_modified) {
+ $feed_obj->last_modified = substr(UrlHelper::$fetch_last_modified, 0, 245);
+ $feed_obj->save();
}
// cache vanilla feed data for re-use
- if ($feed_data && !$auth_pass && !$auth_login && is_writable(Config::get(Config::CACHE_DIR) . "/feeds")) {
+ if ($feed_data && !$feed_obj->auth_pass && !$feed_obj->auth_login && is_writable(Config::get(Config::CACHE_DIR) . "/feeds")) {
$new_rss_hash = sha1($feed_data);
if ($new_rss_hash != $rss_hash) {
- Debug::log("saving $cache_filename", Debug::$LOG_VERBOSE);
- @file_put_contents($cache_filename, $feed_data);
+ Debug::log("saving to local cache: $cache_filename", Debug::LOG_VERBOSE);
+ file_put_contents($cache_filename, $feed_data);
}
}
}
if (!$feed_data) {
- global $fetch_last_error;
- global $fetch_last_error_code;
-
- Debug::log("unable to fetch: $fetch_last_error [$fetch_last_error_code]", Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("unable to fetch: %s [%s]", UrlHelper::$fetch_last_error, UrlHelper::$fetch_last_error_code), Debug::LOG_VERBOSE);
// If-Modified-Since
- if ($fetch_last_error_code == 304) {
- Debug::log("source claims data not modified, nothing to do.", Debug::$LOG_VERBOSE);
+ if (UrlHelper::$fetch_last_error_code == 304) {
+ Debug::log("source claims data not modified, nothing to do.", Debug::LOG_VERBOSE);
$error_message = "";
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
- last_successful_update = NOW(),
- last_updated = NOW() WHERE id = ?");
+ $feed_obj->set([
+ 'last_error' => '',
+ 'last_successful_update' => Db::NOW(),
+ 'last_updated' => Db::NOW(),
+ ]);
+
+ $feed_obj->save();
} else {
- $error_message = $fetch_last_error;
+ $error_message = UrlHelper::$fetch_last_error;
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_error = ?,
- last_updated = NOW() WHERE id = ?");
- }
+ $feed_obj->set([
+ 'last_error' => $error_message,
+ 'last_updated' => Db::NOW(),
+ ]);
- $sth->execute([$error_message, $feed]);
+ $feed_obj->save();
+ }
return $error_message == "";
}
- Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::$LOG_VERBOSE);
+ Debug::log("running HOOK_FEED_FETCHED handlers...", Debug::LOG_VERBOSE);
$feed_data_checksum = md5($feed_data);
+ // because chain_hooks_callback() accepts variables by value
+ $pff_owner_uid = $feed_obj->owner_uid;
+ $pff_feed_url = $feed_obj->feed_url;
+
$start_ts = microtime(true);
$pluginhost->chain_hooks_callback(PluginHost::HOOK_FEED_FETCHED,
function ($result, $plugin) use (&$feed_data, $start_ts) {
$feed_data = $result;
- Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::LOG_VERBOSE);
},
- $feed_data, $fetch_url, $owner_uid, $feed);
+ $feed_data, $pff_feed_url, $pff_owner_uid, $feed);
if (md5($feed_data) != $feed_data_checksum) {
- Debug::log("feed data has been modified by a plugin.", Debug::$LOG_VERBOSE);
+ Debug::log("feed data has been modified by a plugin.", Debug::LOG_VERBOSE);
} else {
- Debug::log("feed data has not been modified by a plugin.", Debug::$LOG_VERBOSE);
+ Debug::log("feed data has not been modified by a plugin.", Debug::LOG_VERBOSE);
}
$rss = new FeedParser($feed_data);
@@ -562,46 +542,29 @@ class RSSUtils {
if (!$rss->error()) {
- Debug::log("running HOOK_FEED_PARSED handlers...", Debug::$LOG_VERBOSE);
+ Debug::log("running HOOK_FEED_PARSED handlers...", Debug::LOG_VERBOSE);
// We use local pluginhost here because we need to load different per-user feed plugins
$start_ts = microtime(true);
$pluginhost->chain_hooks_callback(PluginHost::HOOK_FEED_PARSED,
function($result, $plugin) use ($start_ts) {
- Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)), Debug::LOG_VERBOSE);
},
$rss, $feed);
- Debug::log("language: $feed_language", Debug::$LOG_VERBOSE);
- Debug::log("processing feed data...", Debug::$LOG_VERBOSE);
-
- if (Config::get(Config::DB_TYPE) == "pgsql") {
- $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
- } else {
- $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
- }
-
- $sth = $pdo->prepare("SELECT owner_uid,favicon_avg_color,
- (favicon_last_checked IS NULL OR $favicon_interval_qpart) AS
- favicon_needs_check
- FROM ttrss_feeds WHERE id = ?");
- $sth->execute([$feed]);
+ Debug::log("language: $feed_language", Debug::LOG_VERBOSE);
+ Debug::log("processing feed data...", Debug::LOG_VERBOSE);
- if ($row = $sth->fetch()) {
- $favicon_needs_check = $row["favicon_needs_check"];
- $favicon_avg_color = $row["favicon_avg_color"];
- $owner_uid = $row["owner_uid"];
- } else {
- return false;
- }
+ $site_url = mb_substr(rewrite_relative_url($feed_obj->feed_url, clean($rss->get_link())), 0, 245);
- $site_url = mb_substr(rewrite_relative_url($fetch_url, clean($rss->get_link())), 0, 245);
+ Debug::log("site_url: $site_url", Debug::LOG_VERBOSE);
+ Debug::log("feed_title: {$rss->get_title()}", Debug::LOG_VERBOSE);
- Debug::log("site_url: $site_url", Debug::$LOG_VERBOSE);
- Debug::log("feed_title: " . clean($rss->get_title()), Debug::$LOG_VERBOSE);
+ Debug::log("favicon: needs check: {$feed_obj->favicon_needs_check} is custom: {$feed_obj->favicon_is_custom} avg color: {$feed_obj->favicon_avg_color}",
+ Debug::LOG_VERBOSE);
- if ($favicon_needs_check || $force_refetch) {
+ if ($feed_obj->favicon_needs_check || $force_refetch) {
/* terrible hack: if we crash on floicon shit here, we won't check
* the icon avgcolor again (unless the icon got updated) */
@@ -609,70 +572,74 @@ class RSSUtils {
$favicon_file = Config::get(Config::ICONS_DIR) . "/$feed.ico";
$favicon_modified = file_exists($favicon_file) ? filemtime($favicon_file) : -1;
- Debug::log("checking favicon for feed $feed...", Debug::$LOG_VERBOSE);
-
- self::check_feed_favicon($site_url, $feed);
- $favicon_modified_new = file_exists($favicon_file) ? filemtime($favicon_file) : -1;
+ if (!$feed_obj->favicon_is_custom) {
+ Debug::log("favicon: trying to update favicon...", Debug::LOG_VERBOSE);
+ self::update_favicon($site_url, $feed);
- if ($favicon_modified_new > $favicon_modified)
- $favicon_avg_color = '';
+ if ((file_exists($favicon_file) ? filemtime($favicon_file) : -1) > $favicon_modified)
+ $feed_obj->favicon_avg_color = null;
+ }
- $favicon_colorstring = "";
- if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
+ if (is_readable($favicon_file) && function_exists("imagecreatefromstring") && empty($feed_obj->favicon_avg_color)) {
require_once "colors.php";
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE
- id = ?");
- $sth->execute([$feed]);
+ Debug::log("favicon: trying to calculate average color...", Debug::LOG_VERBOSE);
- $favicon_color = \Colors\calculate_avg_color($favicon_file);
+ $feed_obj->favicon_avg_color = 'fail';
+ $feed_obj->save();
- $favicon_colorstring = ",favicon_avg_color = " . $pdo->quote($favicon_color);
+ $feed_obj->favicon_avg_color = \Colors\calculate_avg_color($favicon_file);
+ $feed_obj->save();
- } else if ($favicon_avg_color == 'fail') {
- Debug::log("floicon failed on this file, not trying to recalculate avg color", Debug::$LOG_VERBOSE);
- }
+ Debug::log("favicon: avg color: {$feed_obj->favicon_avg_color}", Debug::LOG_VERBOSE);
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET favicon_last_checked = NOW()
- $favicon_colorstring WHERE id = ?");
- $sth->execute([$feed]);
+ } else if ($feed_obj->favicon_avg_color == 'fail') {
+ Debug::log("floicon failed $favicon_file, not trying to recalculate avg color", Debug::LOG_VERBOSE);
+ }
}
- Debug::log("loading filters & labels...", Debug::$LOG_VERBOSE);
+ Debug::log("loading filters & labels...", Debug::LOG_VERBOSE);
- $filters = self::load_filters($feed, $owner_uid);
+ $filters = self::load_filters($feed, $feed_obj->owner_uid);
- if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
+ if (Debug::get_loglevel() >= Debug::LOG_EXTENDED) {
print_r($filters);
}
- Debug::log("" . count($filters) . " filters loaded.", Debug::$LOG_VERBOSE);
+ Debug::log("" . count($filters) . " filters loaded.", Debug::LOG_VERBOSE);
$items = $rss->get_items();
if (!is_array($items)) {
- Debug::log("no articles found.", Debug::$LOG_VERBOSE);
+ Debug::log("no articles found.", Debug::LOG_VERBOSE);
- $sth = $pdo->prepare("UPDATE ttrss_feeds
- SET last_updated = NOW(), last_unconditional = NOW(), last_error = '' WHERE id = ?");
- $sth->execute([$feed]);
+ $feed_obj->set([
+ 'last_updated' => Db::NOW(),
+ 'last_unconditional' => Db::NOW(),
+ 'last_error' => '',
+ ]);
+
+ $feed_obj->save();
return true; // no articles
}
- Debug::log("processing articles...", Debug::$LOG_VERBOSE);
+ Debug::log("processing articles...", Debug::LOG_VERBOSE);
$tstart = time();
foreach ($items as $item) {
$pdo->beginTransaction();
+ Debug::log("=================================================================================================================================",
+ Debug::LOG_VERBOSE);
+
if (Debug::get_loglevel() >= 3) {
print_r($item);
}
if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
- Debug::log("looks like there's too many articles to process at once, breaking out", Debug::$LOG_VERBOSE);
+ Debug::log("looks like there's too many articles to process at once, breaking out.", Debug::LOG_VERBOSE);
$pdo->commit();
break;
}
@@ -686,15 +653,16 @@ class RSSUtils {
continue;
}
- $entry_guid_hashed_compat = 'SHA1:' . sha1("$owner_uid,$entry_guid");
- $entry_guid_hashed = json_encode(["ver" => 2, "uid" => $owner_uid, "hash" => 'SHA1:' . sha1($entry_guid)]);
- $entry_guid = "$owner_uid,$entry_guid";
+ $entry_guid_hashed_compat = 'SHA1:' . sha1("{$feed_obj->owner_uid},$entry_guid");
+ $entry_guid_hashed = json_encode(["ver" => 2, "uid" => $feed_obj->owner_uid, "hash" => 'SHA1:' . sha1($entry_guid)]);
+ $entry_guid = "$feed_obj->owner_uid,$entry_guid";
- Debug::log("guid $entry_guid (hash: $entry_guid_hashed compat: $entry_guid_hashed_compat)", Debug::$LOG_VERBOSE);
+ Debug::log("guid $entry_guid (hash: $entry_guid_hashed compat: $entry_guid_hashed_compat)", Debug::LOG_VERBOSE);
$entry_timestamp = (int)$item->get_date();
- Debug::log("orig date: " . $item->get_date(), Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("orig date: %s (%s)", $item->get_date(), date("Y-m-d H:i:s", $item->get_date())),
+ Debug::LOG_VERBOSE);
$entry_title = strip_tags($item->get_title());
@@ -702,9 +670,9 @@ class RSSUtils {
$entry_language = mb_substr(trim($item->get_language()), 0, 2);
- Debug::log("title $entry_title", Debug::$LOG_VERBOSE);
- Debug::log("link $entry_link", Debug::$LOG_VERBOSE);
- Debug::log("language $entry_language", Debug::$LOG_VERBOSE);
+ Debug::log("title $entry_title", Debug::LOG_VERBOSE);
+ Debug::log("link $entry_link", Debug::LOG_VERBOSE);
+ Debug::log("language $entry_language", Debug::LOG_VERBOSE);
if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);;
@@ -723,13 +691,13 @@ class RSSUtils {
$entry_author = strip_tags($item->get_author());
$entry_guid = mb_substr($entry_guid, 0, 245);
- Debug::log("author $entry_author", Debug::$LOG_VERBOSE);
- Debug::log("looking for tags...", Debug::$LOG_VERBOSE);
+ Debug::log("author $entry_author", Debug::LOG_VERBOSE);
+ Debug::log("looking for tags...", Debug::LOG_VERBOSE);
$entry_tags = $item->get_categories();
- Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE);
+ Debug::log("tags found: " . join(", ", $entry_tags), Debug::LOG_VERBOSE);
- Debug::log("done collecting data.", Debug::$LOG_VERBOSE);
+ Debug::log("done collecting data.", Debug::LOG_VERBOSE);
$sth = $pdo->prepare("SELECT id, content_hash, lang FROM ttrss_entries
WHERE guid IN (?, ?, ?)");
@@ -738,9 +706,9 @@ class RSSUtils {
if ($row = $sth->fetch()) {
$base_entry_id = $row["id"];
$entry_stored_hash = $row["content_hash"];
- $article_labels = Article::_get_labels($base_entry_id, $owner_uid);
+ $article_labels = Article::_get_labels($base_entry_id, $feed_obj->owner_uid);
- $existing_tags = Article::_get_tags($base_entry_id, $owner_uid);
+ $existing_tags = Article::_get_tags($base_entry_id, $feed_obj->owner_uid);
$entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
} else {
$base_entry_id = false;
@@ -748,13 +716,13 @@ class RSSUtils {
$article_labels = array();
}
- Debug::log("looking for enclosures...", Debug::$LOG_VERBOSE);
+ Debug::log("looking for enclosures...", Debug::LOG_VERBOSE);
// enclosures
$enclosures = array();
- $encs = $item->_get_enclosures();
+ $encs = $item->get_enclosures();
if (is_array($encs)) {
foreach ($encs as $e) {
@@ -782,7 +750,7 @@ class RSSUtils {
}
}
- $article = array("owner_uid" => $owner_uid, // read only
+ $article = array("owner_uid" => $feed_obj->owner_uid, // read only
"guid" => $entry_guid, // read only
"guid_hashed" => $entry_guid_hashed, // read only
"title" => $entry_title,
@@ -798,33 +766,35 @@ class RSSUtils {
"num_comments" => $num_comments,
"enclosures" => $enclosures,
"feed" => array("id" => $feed,
- "fetch_url" => $fetch_url,
+ "fetch_url" => $feed_obj->feed_url,
"site_url" => $site_url,
- "cache_images" => $cache_images)
+ "cache_images" => $feed_obj->cache_images)
);
$entry_plugin_data = "";
$entry_current_hash = self::calculate_article_hash($article, $pluginhost);
- Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::$LOG_VERBOSE);
+ Debug::log("article hash: $entry_current_hash [stored=$entry_stored_hash]", Debug::LOG_VERBOSE);
if ($entry_current_hash == $entry_stored_hash && !isset($_REQUEST["force_rehash"])) {
- Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only", Debug::$LOG_VERBOSE);
+ Debug::log("stored article seems up to date [IID: $base_entry_id], updating timestamp only.", Debug::LOG_VERBOSE);
// we keep encountering the entry in feeds, so we need to
// update date_updated column so that we don't get horrible
// dupes when the entry gets purged and reinserted again e.g.
// in the case of SLOW SLOW OMG SLOW updating feeds
- $sth = $pdo->prepare("UPDATE ttrss_entries SET date_updated = NOW()
- WHERE id = ?");
- $sth->execute([$base_entry_id]);
+ $entry_obj = ORM::for_table('ttrss_entries')
+ ->find_one($base_entry_id)
+ ->set('date_updated', Db::NOW())
+ ->save();
$pdo->commit();
+
continue;
}
- Debug::log("hash differs, applying plugin filters:", Debug::$LOG_VERBOSE);
+ Debug::log("hash differs, running HOOK_ARTICLE_FILTER handlers...", Debug::LOG_VERBOSE);
$start_ts = microtime(true);
@@ -835,7 +805,7 @@ class RSSUtils {
$entry_plugin_data .= mb_strtolower(get_class($plugin)) . ",";
Debug::log(sprintf("=== %.4f (sec) %s", microtime(true) - $start_ts, get_class($plugin)),
- Debug::$LOG_VERBOSE);
+ Debug::LOG_VERBOSE);
},
$article);
@@ -845,7 +815,7 @@ class RSSUtils {
print "\n";
}
- Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE);
+ Debug::log("plugin data: {$entry_plugin_data}", Debug::LOG_VERBOSE);
// Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
if (Config::get(Config::DB_TYPE) == "mysql" && Config::get(Config::MYSQL_CHARSET) != "UTF8MB4") {
@@ -868,33 +838,35 @@ class RSSUtils {
// $article_filters should be renamed to something like $filter_actions; actual filter objects are in $matched_filters
$pluginhost->run_hooks(PluginHost::HOOK_FILTER_TRIGGERED,
- $feed, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters);
+ $feed, $feed_obj->owner_uid, $article, $matched_filters, $matched_rules, $article_filters);
$matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters);
if (count($matched_filter_ids) > 0) {
- $filter_ids_qmarks = arr_qmarks($matched_filter_ids);
+ $filter_objs = ORM::for_table('ttrss_filters2')
+ ->where('owner_uid', $feed_obj->owner_uid)
+ ->where_in('id', $matched_filter_ids);
- $fsth = $pdo->prepare("UPDATE ttrss_filters2 SET last_triggered = NOW() WHERE
- id IN ($filter_ids_qmarks) AND owner_uid = ?");
-
- $fsth->execute(array_merge($matched_filter_ids, [$owner_uid]));
+ foreach ($filter_objs as $filter_obj) {
+ $filter_obj->set('last_triggered', Db::NOW());
+ $filter_obj->save();
+ }
}
- if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
- Debug::log("matched filters: ", Debug::$LOG_VERBOSE);
+ if (Debug::get_loglevel() >= Debug::LOG_EXTENDED) {
+ Debug::log("matched filters: ", Debug::LOG_VERBOSE);
if (count($matched_filters) != 0) {
print_r($matched_filters);
}
- Debug::log("matched filter rules: ", Debug::$LOG_VERBOSE);
+ Debug::log("matched filter rules: ", Debug::LOG_VERBOSE);
if (count($matched_rules) != 0) {
print_r($matched_rules);
}
- Debug::log("filter actions: ", Debug::$LOG_VERBOSE);
+ Debug::log("filter actions: ", Debug::LOG_VERBOSE);
if (count($article_filters) != 0) {
print_r($article_filters);
@@ -905,7 +877,7 @@ class RSSUtils {
$plugin_filter_actions = $pluginhost->get_filter_actions();
if (count($plugin_filter_names) > 0) {
- Debug::log("applying plugin filter actions...", Debug::$LOG_VERBOSE);
+ Debug::log("applying plugin filter actions...", Debug::LOG_VERBOSE);
foreach ($plugin_filter_names as $pfn) {
list($pfclass,$pfaction) = explode(":", $pfn["param"]);
@@ -913,18 +885,18 @@ class RSSUtils {
if (isset($plugin_filter_actions[$pfclass])) {
$plugin = $pluginhost->get_plugin($pfclass);
- Debug::log("... $pfclass: $pfaction", Debug::$LOG_VERBOSE);
+ Debug::log("... $pfclass: $pfaction", Debug::LOG_VERBOSE);
if ($plugin) {
$start = microtime(true);
$article = $plugin->hook_article_filter_action($article, $pfaction);
- Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::$LOG_VERBOSE);
+ Debug::log(sprintf("=== %.4f (sec)", microtime(true) - $start), Debug::LOG_VERBOSE);
} else {
- Debug::log("??? $pfclass: plugin object not found.", Debug::$LOG_VERBOSE);
+ Debug::log("??? $pfclass: plugin object not found.", Debug::LOG_VERBOSE);
}
} else {
- Debug::log("??? $pfclass: filter plugin not registered.", Debug::$LOG_VERBOSE);
+ Debug::log("??? $pfclass: filter plugin not registered.", Debug::LOG_VERBOSE);
}
}
}
@@ -948,20 +920,20 @@ class RSSUtils {
$entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
- Debug::log("date $entry_timestamp [$entry_timestamp_fmt]", Debug::$LOG_VERBOSE);
- Debug::log("num_comments: $num_comments", Debug::$LOG_VERBOSE);
+ Debug::log("date: $entry_timestamp ($entry_timestamp_fmt)", Debug::LOG_VERBOSE);
+ Debug::log("num_comments: $num_comments", Debug::LOG_VERBOSE);
- if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
- Debug::log("article labels:", Debug::$LOG_VERBOSE);
+ if (Debug::get_loglevel() >= Debug::LOG_EXTENDED) {
+ Debug::log("article labels:", Debug::LOG_VERBOSE);
if (count($article_labels) != 0) {
print_r($article_labels);
}
}
- Debug::log("force catchup: $entry_force_catchup", Debug::$LOG_VERBOSE);
+ Debug::log("force catchup: $entry_force_catchup", Debug::LOG_VERBOSE);
- if ($cache_images)
+ if ($feed_obj->cache_images)
self::cache_media($entry_content, $site_url);
$csth = $pdo->prepare("SELECT id FROM ttrss_entries
@@ -970,7 +942,7 @@ class RSSUtils {
if (!$row = $csth->fetch()) {
- Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::$LOG_VERBOSE);
+ Debug::log("base guid [$entry_guid or $entry_guid_hashed] not found, creating...", Debug::LOG_VERBOSE);
// base post entry does not exist, create it
@@ -1018,36 +990,36 @@ class RSSUtils {
if ($row = $csth->fetch()) {
- Debug::log("base guid found, checking for user record", Debug::$LOG_VERBOSE);
+ Debug::log("base guid found, checking for user record", Debug::LOG_VERBOSE);
$ref_id = $row['id'];
$entry_ref_id = $ref_id;
if (self::find_article_filter($article_filters, "filter")) {
- Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE);
+ Debug::log("article is filtered out, nothing to do.", Debug::LOG_VERBOSE);
$pdo->commit();
continue;
}
$score = self::calculate_article_score($article_filters) + $entry_score_modifier;
- Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::$LOG_VERBOSE);
+ Debug::log("initial score: $score [including plugin modifier: $entry_score_modifier]", Debug::LOG_VERBOSE);
// check for user post link to main table
$sth = $pdo->prepare("SELECT ref_id, int_id FROM ttrss_user_entries WHERE
ref_id = ? AND owner_uid = ?");
- $sth->execute([$ref_id, $owner_uid]);
+ $sth->execute([$ref_id, $feed_obj->owner_uid]);
// okay it doesn't exist - create user entry
if ($row = $sth->fetch()) {
$entry_ref_id = $row["ref_id"];
$entry_int_id = $row["int_id"];
- Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
+ Debug::log("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", Debug::LOG_VERBOSE);
} else {
- Debug::log("user record not found, creating...", Debug::$LOG_VERBOSE);
+ Debug::log("user record not found, creating...", Debug::LOG_VERBOSE);
if ($score >= -500 && !self::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
$unread = 1;
@@ -1079,20 +1051,20 @@ class RSSUtils {
last_marked, last_published)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")");
- $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked,
+ $sth->execute([$ref_id, $feed_obj->owner_uid, $feed, $unread, $last_read_qpart, $marked,
$published, $score]);
$sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
ref_id = ? AND owner_uid = ? AND
feed_id = ? LIMIT 1");
- $sth->execute([$ref_id, $owner_uid, $feed]);
+ $sth->execute([$ref_id, $feed_obj->owner_uid, $feed]);
if ($row = $sth->fetch())
$entry_int_id = $row['int_id'];
}
- Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE);
+ Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::LOG_VERBOSE);
if (Config::get(Config::DB_TYPE) == "pgsql")
$tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
@@ -1134,36 +1106,36 @@ class RSSUtils {
SET score = ? WHERE ref_id = ?");
$sth->execute([$score, $ref_id]);
- if ($mark_unread_on_update &&
+ if ($feed_obj->mark_unread_on_update &&
!$entry_force_catchup &&
!self::find_article_filter($article_filters, 'catchup')) {
- Debug::log("article updated, marking unread as requested.", Debug::$LOG_VERBOSE);
+ Debug::log("article updated, marking unread as requested.", Debug::LOG_VERBOSE);
$sth = $pdo->prepare("UPDATE ttrss_user_entries
SET last_read = null, unread = true WHERE ref_id = ?");
$sth->execute([$ref_id]);
} else {
- Debug::log("article updated, but we're forbidden to mark it unread.", Debug::$LOG_VERBOSE);
+ Debug::log("article updated, but we're forbidden to mark it unread.", Debug::LOG_VERBOSE);
}
}
- Debug::log("assigning labels [other]...", Debug::$LOG_VERBOSE);
+ Debug::log("assigning labels [other]...", Debug::LOG_VERBOSE);
foreach ($article_labels as $label) {
- Labels::add_article($entry_ref_id, $label[1], $owner_uid);
+ Labels::add_article($entry_ref_id, $label[1], $feed_obj->owner_uid);
}
- Debug::log("assigning labels [filters]...", Debug::$LOG_VERBOSE);
+ Debug::log("assigning labels [filters]...", Debug::LOG_VERBOSE);
self::assign_article_to_label_filters($entry_ref_id, $article_filters,
- $owner_uid, $article_labels);
+ $feed_obj->owner_uid, $article_labels);
- if ($cache_images)
+ if ($feed_obj->cache_images)
self::cache_enclosures($enclosures, $site_url);
- if (Debug::get_loglevel() >= Debug::$LOG_EXTENDED) {
- Debug::log("article enclosures:", Debug::$LOG_VERBOSE);
+ if (Debug::get_loglevel() >= Debug::LOG_EXTENDED) {
+ Debug::log("article enclosures:", Debug::LOG_VERBOSE);
print_r($enclosures);
}
@@ -1206,13 +1178,13 @@ class RSSUtils {
$boring_tags = array_map('trim',
explode(",", mb_strtolower(
- get_pref(Prefs::BLACKLISTED_TAGS, $owner_uid))));
+ get_pref(Prefs::BLACKLISTED_TAGS, $feed_obj->owner_uid))));
$entry_tags = FeedItem_Common::normalize_categories(
array_unique(
array_diff($entry_tags, $boring_tags)));
- Debug::log("filtered tags: " . implode(", ", $entry_tags), Debug::$LOG_VERBOSE);
+ Debug::log("filtered tags: " . implode(", ", $entry_tags), Debug::LOG_VERBOSE);
// Save article tags in the database
@@ -1227,10 +1199,10 @@ class RSSUtils {
VALUES (?, ?, ?)");
foreach ($entry_tags as $tag) {
- $tsth->execute([$tag, $entry_int_id, $owner_uid]);
+ $tsth->execute([$tag, $entry_int_id, $feed_obj->owner_uid]);
if (!$tsth->fetch()) {
- $usth->execute([$owner_uid, $tag, $entry_int_id]);
+ $usth->execute([$feed_obj->owner_uid, $tag, $entry_int_id]);
}
}
@@ -1243,52 +1215,58 @@ class RSSUtils {
$tsth->execute([
join(",", $entry_tags),
$entry_ref_id,
- $owner_uid
+ $feed_obj->owner_uid
]);
}
- Debug::log("article processed", Debug::$LOG_VERBOSE);
+ Debug::log("article processed.", Debug::LOG_VERBOSE);
$pdo->commit();
}
- Debug::log("purging feed...", Debug::$LOG_VERBOSE);
+ Debug::log("=================================================================================================================================",
+ Debug::LOG_VERBOSE);
+
+ Debug::log("purging feed...", Debug::LOG_VERBOSE);
Feeds::_purge($feed, 0);
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET
- last_updated = NOW(),
- last_unconditional = NOW(),
- last_successful_update = NOW(),
- last_error = '' WHERE id = ?");
- $sth->execute([$feed]);
+ $feed_obj->set([
+ 'last_updated' => Db::NOW(),
+ 'last_unconditional' => Db::NOW(),
+ 'last_successful_update' => Db::NOW(),
+ 'last_error' => '',
+ ]);
+
+ $feed_obj->save();
} else {
$error_msg = mb_substr($rss->error(), 0, 245);
- Debug::log("fetch error: $error_msg", Debug::$LOG_VERBOSE);
+ Debug::log("fetch error: $error_msg", Debug::LOG_VERBOSE);
if (count($rss->errors()) > 1) {
foreach ($rss->errors() as $error) {
- Debug::log("+ $error", Debug::$LOG_VERBOSE);
+ Debug::log("+ $error", Debug::LOG_VERBOSE);
}
}
- $sth = $pdo->prepare("UPDATE ttrss_feeds SET
- last_error = ?,
- last_updated = NOW(),
- last_unconditional = NOW() WHERE id = ?");
- $sth->execute([$error_msg, $feed]);
+ $feed_obj->set([
+ 'last_updated' => Db::NOW(),
+ 'last_unconditional' => Db::NOW(),
+ 'last_error' => $error_msg,
+ ]);
+
+ $feed_obj->save();
unset($rss);
- Debug::log("update failed.", Debug::$LOG_VERBOSE);
+ Debug::log("update failed.", Debug::LOG_VERBOSE);
return false;
}
- Debug::log("update done.", Debug::$LOG_VERBOSE);
-
+ Debug::log("update done.", Debug::LOG_VERBOSE);
return true;
}
@@ -1304,13 +1282,9 @@ class RSSUtils {
$local_filename = sha1($src);
- Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
+ Debug::log("cache_enclosures: downloading: $src to $local_filename", Debug::LOG_VERBOSE);
if (!$cache->exists($local_filename)) {
-
- global $fetch_last_error_code;
- global $fetch_last_error;
-
$file_content = UrlHelper::fetch(array("url" => $src,
"http_referrer" => $src,
"max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)));
@@ -1318,7 +1292,7 @@ class RSSUtils {
if ($file_content) {
$cache->put($local_filename, $file_content);
} else {
- Debug::log("cache_enclosures: failed with $fetch_last_error_code: $fetch_last_error");
+ Debug::log("cache_enclosures: failed with ".UrlHelper::$fetch_last_error_code.": ".UrlHelper::$fetch_last_error);
}
} else if (is_writable($local_filename)) {
$cache->touch($local_filename);
@@ -1333,13 +1307,10 @@ class RSSUtils {
$url = rewrite_relative_url($site_url, $url);
$local_filename = sha1($url);
- Debug::log("cache_media: checking $url", Debug::$LOG_VERBOSE);
+ Debug::log("cache_media: checking $url", Debug::LOG_VERBOSE);
if (!$cache->exists($local_filename)) {
- Debug::log("cache_media: downloading: $url to $local_filename", Debug::$LOG_VERBOSE);
-
- global $fetch_last_error_code;
- global $fetch_last_error;
+ Debug::log("cache_media: downloading: $url to $local_filename", Debug::LOG_VERBOSE);
$file_content = UrlHelper::fetch(array("url" => $url,
"http_referrer" => $url,
@@ -1348,7 +1319,7 @@ class RSSUtils {
if ($file_content) {
$cache->put($local_filename, $file_content);
} else {
- Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error");
+ Debug::log("cache_media: failed with ".UrlHelper::$fetch_last_error_code.": ".UrlHelper::$fetch_last_error);
}
} else if ($cache->is_writable($local_filename)) {
$cache->touch($local_filename);
@@ -1407,7 +1378,7 @@ class RSSUtils {
}
static function expire_lock_files() {
- Debug::log("Removing old lock files...", Debug::$LOG_VERBOSE);
+ Debug::log("Removing old lock files...", Debug::LOG_VERBOSE);
$num_deleted = 0;
@@ -1657,12 +1628,12 @@ class RSSUtils {
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING);
}
- static function check_feed_favicon($site_url, $feed) {
+ static function update_favicon(string $site_url, int $feed) {
$icon_file = Config::get(Config::ICONS_DIR) . "/$feed.ico";
$favicon_url = self::get_favicon_url($site_url);
if (!$favicon_url) {
- Debug::log("couldn't find favicon URL in $site_url", Debug::$LOG_VERBOSE);
+ Debug::log("favicon: couldn't find favicon URL in $site_url", Debug::LOG_VERBOSE);
return false;
}
@@ -1673,7 +1644,7 @@ class RSSUtils {
//'type' => 'image',
]);
if (!$contents) {
- Debug::log("fetching favicon $favicon_url failed", Debug::$LOG_VERBOSE);
+ Debug::log("favicon: fetching $favicon_url failed", Debug::LOG_VERBOSE);
return false;
}
@@ -1681,35 +1652,35 @@ class RSSUtils {
// Patterns gleaned from the file(1) source code.
if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
// 0 string \000\000\001\000 MS Windows icon resource
- //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
+ //error_log("update_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
}
elseif (preg_match('/^GIF8/', $contents)) {
// 0 string GIF8 GIF image data
- //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
+ //error_log("update_favicon: favicon_url=$favicon_url isa GIF image");
}
elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
// 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data
- //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
+ //error_log("update_favicon: favicon_url=$favicon_url isa PNG image");
}
elseif (preg_match('/^\xff\xd8/', $contents)) {
// 0 beshort 0xffd8 JPEG image data
- //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
+ //error_log("update_favicon: favicon_url=$favicon_url isa JPG image");
}
elseif (preg_match('/^BM/', $contents)) {
// 0 string BM PC bitmap (OS2, Windows BMP files)
- //error_log("check_feed_favicon, favicon_url=$favicon_url isa BMP image");
+ //error_log("update_favicon, favicon_url=$favicon_url isa BMP image");
}
else {
- //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
- Debug::log("favicon $favicon_url type is unknown (not updating)", Debug::$LOG_VERBOSE);
+ //error_log("update_favicon: favicon_url=$favicon_url isa UNKNOWN type");
+ Debug::log("favicon $favicon_url type is unknown (not updating)", Debug::LOG_VERBOSE);
return false;
}
- Debug::log("setting contents of $icon_file", Debug::$LOG_VERBOSE);
+ Debug::log("favicon: saving to $icon_file", Debug::LOG_VERBOSE);
$fp = @fopen($icon_file, "w");
if (!$fp) {
- Debug::log("failed to open $icon_file for writing", Debug::$LOG_VERBOSE);
+ Debug::log("favicon: failed to open $icon_file for writing", Debug::LOG_VERBOSE);
return false;
}
@@ -1726,13 +1697,13 @@ class RSSUtils {
"\x1f" . "\x8b" . "\x08", 0) === 0;
}
- static function load_filters($feed_id, $owner_uid) {
+ static function load_filters(int $feed_id, int $owner_uid) {
$filters = array();
$feed_id = (int) $feed_id;
- $cat_id = (int)Feeds::_cat_of_feed($feed_id);
+ $cat_id = Feeds::_cat_of($feed_id);
- if ($cat_id == 0)
+ if (!$cat_id)
$null_cat_qpart = "cat_id IS NULL OR";
else
$null_cat_qpart = "";
@@ -1845,7 +1816,7 @@ class RSSUtils {
* @access public
* @return mixed The favicon URL, or false if none was found.
*/
- static function get_favicon_url($url) {
+ static function get_favicon_url(string $url) {
$favicon_url = false;