<?php
}
- function cached_image() {
+ function cached_url() {
@$hash = basename($_GET['hash']);
+ // we don't need an extension to find the file, hash is a complete URL
+ $hash = preg_replace("/\.[^\.]*$/", "", $hash);
+
if ($hash) {
$filename = CACHE_DIR . '/images/' . $hash;
// check cache only for video and images for the time being
if ($entry->nodeName == 'img' || ($entry->parentNode && $entry->parentNode->nodeName == "video")) {
+ $cached_filename = CACHE_DIR . '/images/' . sha1($src);
$extension = $entry->tagName == 'source' ? '.mp4' : '.png';
- $cached_filename = CACHE_DIR . '/images/' . sha1($src) . $extension;
if (file_exists($cached_filename)) {
- $src = get_self_url_prefix() . '/public.php?op=cached_image&hash=' . sha1($src) . $extension;
+ $src = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($src) . $extension;
if ($entry->hasAttribute('srcset')) {
$entry->removeAttribute('srcset');
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 = "";
_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);
return $rss;
}
- function cache_images($html, $site_url, $debug) {
+ function cache_media($html, $site_url, $debug) {
libxml_use_internal_errors(true);
$charset_hack = '<head>
if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
$src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
- $extension = $entry->tagName == 'source' ? '.mp4' : '.png';
- $local_filename = CACHE_DIR . "/images/" . sha1($src) . $extension;
+ $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 {
if (preg_match("/image/", $enc["content_type"]) || preg_match("/\.(jpe?g|png|gif|bmp)$/i", $enc["filename"])) {
$proxy_all = $this->host->get($this, "proxy_all");
- $enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], 0, $proxy_all);
+ $enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], $proxy_all);
}
return $enc;
public function imgproxy() {
$url = rewrite_relative_url(SELF_URL_PATH, $_REQUEST["url"]);
- $kind = (int) $_REQUEST["kind"]; // 1 = video
// called without user context, let's just redirect to original URL
if (!$_SESSION["uid"]) {
return;
}
- $extension = $kind == 1 ? '.mp4' : '.png';
- $local_filename = CACHE_DIR . "/images/" . sha1($url) . $extension;
+ $local_filename = CACHE_DIR . "/images/" . sha1($url);
if ($_REQUEST["debug"] == "1") { print $url . "\n" . $local_filename; die; }
}
}
- function rewrite_url_if_needed($url, $kind, $all_remote = false) {
+ function rewrite_url_if_needed($url, $all_remote = false) {
$scheme = parse_url($url, PHP_URL_SCHEME);
if ($all_remote) {
if (($scheme != 'https' && $scheme != "") || $is_remote) {
if (strpos($url, "data:") !== 0) {
- $url = get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&kind=$kind&url=" .
+ $url = get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" .
urlencode($url);
}
}
$imgs = $xpath->query("//img[@src]");
foreach ($imgs as $img) {
- $new_src = $this->rewrite_url_if_needed($img->getAttribute("src"), 0, $proxy_all);
+ $new_src = $this->rewrite_url_if_needed($img->getAttribute("src"), $proxy_all);
if ($new_src != $img->getAttribute("src")) {
$img->setAttribute("src", $new_src);
foreach ($vids as $vid) {
if ($vid->hasAttribute("poster")) {
- $new_src = $this->rewrite_url_if_needed($vid->getAttribute("poster"), 0, $proxy_all);
+ $new_src = $this->rewrite_url_if_needed($vid->getAttribute("poster"), $proxy_all);
if ($new_src != $vid->getAttribute("poster")) {
$vid->setAttribute("poster", $new_src);
$vsrcs = $xpath->query("source", $vid);
foreach ($vsrcs as $vsrc) {
- $new_src = $this->rewrite_url_if_needed($vsrc->getAttribute("src"), 1, $proxy_all);
+ $new_src = $this->rewrite_url_if_needed($vsrc->getAttribute("src"), $proxy_all);
if ($new_src != $vsrc->getAttribute("src")) {
$vid->setAttribute("src", $new_src);