<?php
/**
- * @file src/Module/Proxy.php
- * Based upon "Privacy Image Cache" by Tobias Hößl <https://github.com/CatoTH/>
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
*/
+
namespace Friendica\Module;
use Friendica\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
// 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());
+ chmod($filename, DI::config()->get('system', 'proxy_file_chmod'));
} elseif($cachefile !== '') {
// cache file
file_put_contents($cachefile, $image->asString());
// 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());
+ chmod($filename, DI::config()->get('system', 'proxy_file_chmod'));
}
self::responseImageHttpCache($image);