X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fproxy.php;h=8e2a38925483f2533e81c1f8a9fcd13938f5bdac;hb=44592611e1582fd97ae1988343418a0dae1ae2a0;hp=d26967dddf2f1e6e21d1749728f213236cbab419;hpb=26983bafff024adab0339b828ec21d83fc5d1007;p=friendica.git diff --git a/mod/proxy.php b/mod/proxy.php index d26967dddf..8e2a389254 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -12,6 +12,7 @@ define("PROXY_SIZE_LARGE", "large"); require_once('include/security.php'); require_once("include/Photo.php"); +if(! function_exists('proxy_init')) { function proxy_init() { global $a, $_SERVER; @@ -44,14 +45,15 @@ function proxy_init() { $thumb = false; $size = 1024; $sizetype = ""; + $basepath = $a->get_basepath(); // If the cache path isn't there, try to create it - if (!is_dir($_SERVER["DOCUMENT_ROOT"]."/proxy")) - if (is_writable($_SERVER["DOCUMENT_ROOT"])) - mkdir($_SERVER["DOCUMENT_ROOT"]."/proxy"); + if (!is_dir($basepath."/proxy")) + if (is_writable($basepath)) + mkdir($basepath."/proxy"); // Checking if caching into a folder in the webroot is activated and working - $direct_cache = (is_dir($_SERVER["DOCUMENT_ROOT"]."/proxy") AND is_writable($_SERVER["DOCUMENT_ROOT"]."/proxy")); + $direct_cache = (is_dir($basepath."/proxy") AND is_writable($basepath."/proxy")); // Look for filename in the arguments if ((isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) AND !isset($_REQUEST["url"])) { @@ -211,9 +213,9 @@ function proxy_init() { // advantage: real file access is really fast // Otherwise write in cachefile if ($valid AND $direct_cache) { - file_put_contents($_SERVER["DOCUMENT_ROOT"]."/proxy/".proxy_url($_REQUEST['url'], true), $img_str_orig); + file_put_contents($basepath."/proxy/".proxy_url($_REQUEST['url'], true), $img_str_orig); if ($sizetype <> '') - file_put_contents($_SERVER["DOCUMENT_ROOT"]."/proxy/".proxy_url($_REQUEST['url'], true).$sizetype, $img_str); + file_put_contents($basepath."/proxy/".proxy_url($_REQUEST['url'], true).$sizetype, $img_str); } elseif ($cachefile != '') file_put_contents($cachefile, $img_str_orig); @@ -231,12 +233,18 @@ function proxy_init() { killme(); } +} +if(! function_exists('proxy_url')) { function proxy_url($url, $writemode = false, $size = "") { global $_SERVER; $a = get_app(); + if (substr($url, 0, strlen('http')) !== 'http') { + return($url); + } + // Only continue if it isn't a local image and the isn't deactivated if (proxy_is_local_image($url)) { $url = str_replace(normalise_link($a->get_baseurl())."/", $a->get_baseurl()."/", $url); @@ -247,7 +255,7 @@ function proxy_url($url, $writemode = false, $size = "") { return($url); // Creating a sub directory to reduce the amount of files in the cache directory - $basepath = $_SERVER["DOCUMENT_ROOT"]."/proxy"; + $basepath = $a->get_basepath()."/proxy"; $path = substr(hash("md5", $url), 0, 2); @@ -289,11 +297,13 @@ function proxy_url($url, $writemode = false, $size = "") { else return ($proxypath.$size); } +} /** * @param $url string * @return boolean */ +if(! function_exists('proxy_is_local_image')) { function proxy_is_local_image($url) { if ($url[0] == '/') return true; @@ -304,7 +314,9 @@ function proxy_is_local_image($url) { $url = normalise_link($url); return (substr($url, 0, strlen($baseurl)) == $baseurl); } +} +if(! function_exists('proxy_parse_query')) { function proxy_parse_query($var) { /** * Use this function to parse out the query array element from @@ -323,7 +335,9 @@ function proxy_parse_query($var) { unset($val, $x, $var); return $arr; } +} +if(! function_exists('proxy_img_cb')) { function proxy_img_cb($matches) { // if the picture seems to be from another picture cache then take the original source @@ -337,10 +351,13 @@ function proxy_img_cb($matches) { return $matches[1].proxy_url(htmlspecialchars_decode($matches[2])).$matches[3]; } +} +if(! function_exists('proxy_parse_html')) { function proxy_parse_html($html) { $a = get_app(); $html = str_replace(normalise_link($a->get_baseurl())."/", $a->get_baseurl()."/", $html); return preg_replace_callback("/(]*src *= *[\"'])([^\"']+)([\"'][^>]*>)/siU", "proxy_img_cb", $html); } +}