]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Proxy.php
Merge pull request #10093 from urbalazs/copyright-2021
[friendica.git] / src / Module / Proxy.php
index e1231f0b13ab1d5cffabb5074706a50e480533a4..e43852baba0e8906890cb3be41f5261ca755b05b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -104,7 +104,7 @@ class Proxy extends BaseModule
 
                // It shouldn't happen but it does - spaces in URL
                $request['url'] = str_replace(' ', '+', $request['url']);
-               $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), true, ['timeout' => 10]);
+               $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['timeout' => 10]);
                $img_str = $fetchResult->getBody();
 
                // If there is an error then return a blank image
@@ -127,11 +127,16 @@ class Proxy extends BaseModule
                }
 
                $basepath = $a->getBasePath();
+               $filepermission = DI::config()->get('system', 'proxy_file_chmod');
 
                // Store original image
                if ($direct_cache) {
                        // direct cache , store under ./proxy/
-                       file_put_contents($basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true), $image->asString());
+                       $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true);
+                       file_put_contents($filename, $image->asString());
+                       if (!empty($filepermission)) {
+                               chmod($filename, $filepermission);
+                       }
                } elseif($cachefile !== '') {
                        // cache file
                        file_put_contents($cachefile, $image->asString());
@@ -149,7 +154,11 @@ class Proxy extends BaseModule
 
                // Store scaled image
                if ($direct_cache && $request['sizetype'] != '') {
-                       file_put_contents($basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) . $request['sizetype'], $image->asString());
+                       $filename = $basepath . '/proxy/' . ProxyUtils::proxifyUrl($request['url'], true) . $request['sizetype'];
+                       file_put_contents($filename, $image->asString());
+                       if (!empty($filepermission)) {
+                               chmod($filename, $filepermission);
+                       }
                }
 
                self::responseImageHttpCache($image);