From 87764a50cf08f33008a0f83d91b4d807643db67c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 23 Nov 2012 13:22:34 +0400 Subject: implement ttrss_feeds.cache_content --- include/functions.php | 20 +++++++++--- include/rssfuncs.php | 84 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 75 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/functions.php b/include/functions.php index 821e314f6..55333ccd6 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ data["comments"]); @@ -782,6 +765,20 @@ _debug("update_rss_feed: base guid not found"); } + if ($cache_content) { + if ($debug_enabled) { + _debug("update_rss_feed: caching content..."); + } + + $entry_cached_content = cache_content($link, $entry_link, $auth_login, $auth_pass); + + if ($cache_images && is_writable(CACHE_DIR . '/images')) + $entry_cached_content = cache_images($entry_cached_content, $site_url, $debug_enabled); + + $entry_cached_content = db_escape_string($entry_cached_content, false); + + } + // base post entry does not exist, create it $result = db_query($link, @@ -792,6 +789,7 @@ updated, content, content_hash, + cached_content, no_orig_date, date_updated, date_entered, @@ -804,6 +802,7 @@ '$entry_link', '$entry_timestamp_fmt', '$entry_content', + '$entry_cached_content', '$content_hash', $no_orig_date, NOW(), @@ -996,6 +995,19 @@ if ($content_hash != $orig_content_hash) { $post_needs_update = true; $update_insignificant = false; + + if ($cache_content) { + if ($debug_enabled) { + _debug("update_rss_feed: caching content because original checksum changed..."); + } + + $entry_cached_content = cache_content($link, $entry_link, $auth_login, $auth_pass); + + if ($cache_images && is_writable(CACHE_DIR . '/images')) + $entry_cached_content = cache_images($entry_cached_content, $site_url, $debug_enabled); + + $entry_cached_content = db_escape_string($entry_cached_content, false); + } } if (db_escape_string($orig_title) != $entry_title) { @@ -1016,6 +1028,7 @@ db_query($link, "UPDATE ttrss_entries SET title = '$entry_title', content = '$entry_content', content_hash = '$content_hash', + cached_content = '$entry_cached_content', updated = '$entry_timestamp_fmt', num_comments = '$num_comments' WHERE id = '$ref_id'"); @@ -1484,4 +1497,25 @@ } } } + + function cache_content($link, $url, $login, $pass) { + + $content = fetch_file_contents($url, $login, $pass); + + if ($content) { + $doc = new DOMDocument(); + @$doc->loadHTML($content); + $xpath = new DOMXPath($doc); + + $node = $doc->getElementsByTagName('body')->item(0); + + if ($node) { + $content = $doc->saveXML($node, LIBXML_NOEMPTYTAG); + + return $content; + } + } + + return ""; + } ?> -- cgit v1.2.3