define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30);
define_default('DAEMON_FEED_LIMIT', 500);
define_default('DAEMON_SLEEP_INTERVAL', 120);
- define_default('_MIN_CACHE_IMAGE_SIZE', 1024);
+ define_default('_MIN_CACHE_FILE_SIZE', 1024);
function calculate_article_hash($article, $pluginhost) {
$tmp = "";
function update_feedbrowser_cache() {
$result = db_query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers
- FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
- WHERE tf.feed_url = ttrss_feeds.feed_url
- AND (private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%'))
+ FROM ttrss_feeds WHERE feed_url NOT IN (SELECT feed_url FROM ttrss_feeds
+ WHERE private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%')
GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT 1000");
db_query("BEGIN");
$callback_url = get_self_url_prefix() .
"/public.php?op=pubsub&id=$feed";
- $s = new Subscriber($feed_hub_url, $callback_url);
+ $s = new Pubsubhubbub\Subscriber\Subscriber($feed_hub_url, $callback_url);
$rc = $s->subscribe($feed_self_url);
_debug("force catchup: $entry_force_catchup");
if ($cache_images && is_writable(CACHE_DIR . '/images'))
- cache_images($entry_content, $site_url, $debug_enabled);
+ cache_media($entry_content, $site_url, $debug_enabled);
$entry_content = db_escape_string($entry_content, false);
"/public.php?op=rss&id=-2&key=" .
get_feed_access_key(-2, false, $owner_uid);
- $p = new Publisher(PUBSUBHUBBUB_HUB);
+ $p = new pubsubhubbub\publisher\Publisher(PUBSUBHUBBUB_HUB);
/* $pubsub_result = */ $p->publish_update($rss_link);
}
}
}
+ if ($cache_images && is_writable(CACHE_DIR . '/images'))
+ cache_enclosures($enclosures, $site_url, $debug_enabled);
+
if ($debug_enabled) {
_debug("article enclosures:", $debug_enabled);
print_r($enclosures);
return $rss;
}
- function cache_images($html, $site_url, $debug) {
+ function cache_enclosures($enclosures, $site_url, $debug) {
+ foreach ($enclosures as $enc) {
+
+ if (preg_match("/(image|audio|video)/", $enc[1])) {
+
+ $src = rewrite_relative_url($site_url, $enc[0]);
+
+ $local_filename = CACHE_DIR . "/images/" . sha1($src);
+
+ if ($debug) _debug("cache_enclosures: downloading: $src to $local_filename");
+
+ if (!file_exists($local_filename)) {
+ $file_content = fetch_file_contents($src);
+
+ if ($file_content && strlen($file_content) > _MIN_CACHE_FILE_SIZE) {
+ file_put_contents($local_filename, $file_content);
+ }
+ } else {
+ touch($local_filename);
+ }
+ }
+ }
+ }
+
+ function cache_media($html, $site_url, $debug) {
libxml_use_internal_errors(true);
$charset_hack = '<head>
$doc->loadHTML($charset_hack . $html);
$xpath = new DOMXPath($doc);
- $entries = $xpath->query('(//img[@src])');
+ $entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])');
foreach ($entries as $entry) {
- if ($entry->hasAttribute('src')) {
+ if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
$src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
- $local_filename = CACHE_DIR . "/images/" . sha1($src) . ".png";
+ $local_filename = CACHE_DIR . "/images/" . sha1($src);
- if ($debug) _debug("cache_images: downloading: $src to $local_filename");
+ if ($debug) _debug("cache_media: downloading: $src to $local_filename");
if (!file_exists($local_filename)) {
$file_content = fetch_file_contents($src);
- if ($file_content && strlen($file_content) > _MIN_CACHE_IMAGE_SIZE) {
+ if ($file_content && strlen($file_content) > _MIN_CACHE_FILE_SIZE) {
file_put_contents($local_filename, $file_content);
}
} else {