/** * Callback for Routing.beforeDispatch event. * * @param \Cake\Event\Event $event The event instance. * * @return \Cake\Network\Response Response instance. */ public function beforeDispatch(Event $event) { $request = $event->data['request']; $response = $event->data['response']; $path = urldecode($request->url); if (Configure::read('Glide.secureUrls')) { SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query); } $server = ServerFactory::create(Configure::read('Glide.serverConfig')); $cache = Configure::read('Glide.cache'); if ($cache) { $timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path)); $response->modified($timestamp); if (!$response->checkNotModified($request)) { $response = $server->getImageResponse($path, $request->query); } $response->cache($timestamp, $cache); } else { $response = $server->getImageResponse($path, $request->query); } $headers = Hash::filter((array) Configure::read('Glide.headers')); foreach ($headers as $key => $value) { $response->header($key, $value); } return $response; }
/** * Create UrlBuilder instance. * @param string $baseUrl URL prefixed to generated URL. * @param string $signKey Secret key used to secure URLs. * @return UrlBuilder The UrlBuilder instance. */ public static function create($baseUrl, $signKey = null) { $httpSignature = null; if ($signKey) { $httpSignature = SignatureFactory::create($signKey); } return new UrlBuilder($baseUrl, $httpSignature); }
/** * Returns signature. * * @return \League\Glide\Signatures\Signature * @throws InvalidConfigException */ public function getHttpSignature() { if ($this->httpSignature === null) { if ($this->signKey === null) { throw new InvalidConfigException(); } $this->httpSignature = SignatureFactory::create($this->signKey); } return $this->httpSignature; }
/** * Display image. * * @param Request $request * @param string $filename * * @return mixed */ public function show(Request $request, $filename) { if (config('clyde.secure_urls')) { try { SignatureFactory::create(config('clyde.sign_key'))->validateRequest($request->path(), $request->all()); } catch (SignatureException $e) { return response()->json('Sorry, URL signature is invalid.'); } } return Server::outputImage($filename, $request->all()); }
public function preparePage() { $sPath = implode('/', $this->aPath); $sImageroot = PATH_BASEDIR . HelperConfig::$core['directory_glide_master']; if (is_file($sImageroot . substr($sPath, strlen(HelperConfig::$core['directory_images']) + 1)) && getimagesize($sImageroot . substr($sPath, strlen(HelperConfig::$core['directory_images']) + 1))) { $glideserver = \League\Glide\ServerFactory::create(['source' => $sImageroot, 'cache' => PATH_GLIDECACHE, 'max_image_size' => HelperConfig::$core['glide_max_imagesize']]); $glideserver->setBaseUrl('/' . HelperConfig::$core['directory_images'] . '/'); // Generate a URL try { // Validate HTTP signature \League\Glide\Signatures\SignatureFactory::create(HelperConfig::$secrets['glide_signkey'])->validateRequest($sPath, $_GET); $glideserver->outputImage($sPath, $_GET); die; } catch (\League\Glide\Signatures\SignatureException $e) { $this->P = 404; } } else { $this->P = 404; } return $this->P; }
/** * Register the service provider. * * @return void */ public function register() { $this->app->bindIf('glide.source', function ($app) { $source = config('glide.source'); if (is_callable($source)) { return $source(); } return $source; }, true); $this->app->bindIf('glide.cache', function ($app) { $cache = config('glide.cache'); if (is_callable($cache)) { return $cache(); } return $cache; }, true); $this->app->bindIf('glide.manipulators', function ($app) { $manipulators = config('glide.manipulators'); if (is_callable($manipulators)) { return $manipulators(); } return $manipulators; }, true); $this->app->bindIf('glide.image_manager', function ($app) { $driver = config('glide.driver', 'gd'); return new ImageManager(['driver' => $driver]); }, true); $this->app->bindIf('glide.api', function ($app) { $imageManager = $app['glide.image_manager']; $manipulators = $app['glide.manipulators']; return new Api($imageManager, $manipulators); }, true); $this->app->bindIf('glide.server', function ($app) { $source = $app['glide.source']; $cache = $app['glide.cache']; $api = $app['glide.api']; $server = new Server($source, $cache, $api); $request = $app['request']; $server->setResponseFactory(new LumenResponseFactory($request)); return $server; }, true); $this->app->bindIf('glide.signature', function ($app) { $app->configure('app'); $key = config('app.key'); return SignatureFactory::create($key); }); $this->app->bindIf('glide.image_controller', function ($app) { $server = $app['glide.server']; $signature = $app['glide.signature']; $secure = config('glide.secure', true); $prefix = config('glide.uri'); return new ImageController($server, $signature, $secure, $prefix); }); $this->app->bindIf('glide.url_builder', function ($app) { $baseUrl = $app['request']->root() . '/' . config('glide.uri') . '/'; $secure = config('glide.secure', true); $signature = null; if ($secure) { $signature = $app['glide.signature']; } return new UrlBuilder($baseUrl, $signature); }); $this->app->alias('glide.image_manager', ImageManager::class); $this->app->alias('glide.api', Api::class); $this->app->alias('glide.server', Server::class); $this->app->alias('glide.signature', Signature::class); $this->app->alias('glide.image_controller', ImageController::class); $this->app->alias('glide.url_builder', UrlBuilder::class); }