|
|
|
@ -1226,33 +1226,20 @@ class RSSUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function cache_media($html, $site_url) {
|
|
|
|
|
$cache = new DiskCache("images");
|
|
|
|
|
|
|
|
|
|
if ($cache->isWritable()) {
|
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
if ($doc->loadHTML($html)) {
|
|
|
|
|
$xpath = new DOMXPath($doc);
|
|
|
|
|
|
|
|
|
|
$entries = $xpath->query('(//img[@src])|(//video/source[@src])|(//audio/source[@src])|(//video[@poster])|(//video[@src])');
|
|
|
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
|
foreach (array('src', 'poster') as $attr) {
|
|
|
|
|
if ($entry->hasAttribute($attr) && strpos($entry->getAttribute($attr), "data:") !== 0) {
|
|
|
|
|
$src = rewrite_relative_url($site_url, $entry->getAttribute($attr));
|
|
|
|
|
|
|
|
|
|
$local_filename = sha1($src);
|
|
|
|
|
static function cache_media_url($cache, $url, $site_url) {
|
|
|
|
|
$url = rewrite_relative_url($site_url, $url);
|
|
|
|
|
$local_filename = sha1($url);
|
|
|
|
|
|
|
|
|
|
Debug::log("cache_media: checking $src", Debug::$LOG_VERBOSE);
|
|
|
|
|
Debug::log("cache_media: checking $url", Debug::$LOG_VERBOSE);
|
|
|
|
|
|
|
|
|
|
if (!$cache->exists($local_filename)) {
|
|
|
|
|
Debug::log("cache_media: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
|
|
|
|
|
Debug::log("cache_media: downloading: $url to $local_filename", Debug::$LOG_VERBOSE);
|
|
|
|
|
|
|
|
|
|
global $fetch_last_error_code;
|
|
|
|
|
global $fetch_last_error;
|
|
|
|
|
|
|
|
|
|
$file_content = fetch_file_contents(array("url" => $src,
|
|
|
|
|
"http_referrer" => $src,
|
|
|
|
|
$file_content = fetch_file_contents(array("url" => $url,
|
|
|
|
|
"http_referrer" => $url,
|
|
|
|
|
"max_size" => MAX_CACHE_FILE_SIZE));
|
|
|
|
|
|
|
|
|
|
if ($file_content) {
|
|
|
|
@ -1264,6 +1251,34 @@ class RSSUtils {
|
|
|
|
|
$cache->touch($local_filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function cache_media($html, $site_url) {
|
|
|
|
|
$cache = new DiskCache("images");
|
|
|
|
|
|
|
|
|
|
if ($cache->isWritable()) {
|
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
if ($doc->loadHTML($html)) {
|
|
|
|
|
$xpath = new DOMXPath($doc);
|
|
|
|
|
|
|
|
|
|
$entries = $xpath->query('(//img[@src]|//source[@src|@srcset]|//video[@poster|@src])');
|
|
|
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
|
foreach (array('src', 'poster') as $attr) {
|
|
|
|
|
if ($entry->hasAttribute($attr) && strpos($entry->getAttribute($attr), "data:") !== 0) {
|
|
|
|
|
RSSUtils::cache_media_url($cache, $entry->getAttribute($attr), $site_url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($entry->hasAttribute("srcset")) {
|
|
|
|
|
$tokens = explode(",", $entry->getAttribute('srcset'));
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($tokens); $i++) {
|
|
|
|
|
$token = trim($tokens[$i]);
|
|
|
|
|
|
|
|
|
|
list ($url, $width) = explode(" ", $token, 2);
|
|
|
|
|
|
|
|
|
|
RSSUtils::cache_media_url($cache, $url, $site_url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|