-
- /**
- * setup ./proxy folder for direct cache
- *
- * @return bool False if direct cache can't be used.
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- private static function setupDirectCache()
- {
- $a = DI::app();
- $basepath = $a->getBasePath();
-
- // If the cache path isn't there, try to create it
- if (!is_dir($basepath . '/proxy') && is_writable($basepath)) {
- mkdir($basepath . '/proxy');
- }
-
- // Checking if caching into a folder in the webroot is activated and working
- $direct_cache = (is_dir($basepath . '/proxy') && is_writable($basepath . '/proxy'));
- // we don't use direct cache if image url is passed in args and not in querystring
- $direct_cache = $direct_cache && ($a->argc > 1) && !isset($_REQUEST['url']);
-
- return $direct_cache;
- }
-
-
- /**
- * Try to reply with image in cachefile
- *
- * @param array $request Array from getRequestInfo
- *
- * @return string Cache file name, empty string if cache is not enabled.
- *
- * If cachefile exists, script ends here and this function will never returns
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- private static function responseFromCache(&$request)
- {
- $cachefile = get_cachefile(hash('md5', $request['url']));
- if ($cachefile != '' && file_exists($cachefile)) {
- $img = new Image(file_get_contents($cachefile), mime_content_type($cachefile));
- self::responseImageHttpCache($img);
- // stop.
- }
- return $cachefile;
- }
-
- /**
- * Try to reply with image in database
- *
- * @param array $request Array from getRequestInfo
- *
- * If the image exists in database, then script ends here and this function will never returns
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- private static function responseFromDB(&$request)
- {
- $photo = Photo::getPhoto($request['urlhash']);
-
- if ($photo !== false) {
- $img = Photo::getImageForPhoto($photo);
- self::responseImageHttpCache($img);
- // stop.
- }
- }
-