PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 2.8.18 All 259 releases
wpfunnels / vendor / intervention / image / src / Intervention / Image / ImageServiceProviderLaravel4.php

ImageServiceProviderLaravel4.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at vendor/intervention/image/src/Intervention/Image/ImageServiceProviderLaravel4.php

113 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Intervention\Image;
4
5 use Illuminate\Support\ServiceProvider;
6 use Illuminate\Http\Response as IlluminateResponse;
7
8 class ImageServiceProviderLaravel4 extends ServiceProvider
9 {
10 /**
11 * Bootstrap the application events.
12 *
13 * @return void
14 */
15 public function boot()
16 {
17 $this->package('intervention/image');
18
19 // try to create imagecache route only if imagecache is present
20 if (class_exists('Intervention\\Image\\ImageCache')) {
21
22 $app = $this->app;
23
24 // load imagecache config
25 $app['config']->package('intervention/imagecache', __DIR__.'/../../../../imagecache/src/config', 'imagecache');
26 $config = $app['config'];
27
28 // create dynamic manipulation route
29 if (is_string($config->get('imagecache::route'))) {
30
31 // add original to route templates
32 $config->set('imagecache::templates.original', null);
33
34 // setup image manipulator route
35 $app['router']->get($config->get('imagecache::route').'/{template}/{filename}', ['as' => 'imagecache', function ($template, $filename) use ($app, $config) {
36
37 // disable session cookies for image route
38 $app['config']->set('session.driver', 'array');
39
40 // find file
41 foreach ($config->get('imagecache::paths') as $path) {
42 // don't allow '..' in filenames
43 $image_path = $path.'/'.str_replace('..', '', $filename);
44 if (file_exists($image_path) && is_file($image_path)) {
45 break;
46 } else {
47 $image_path = false;
48 }
49 }
50
51 // abort if file not found
52 if ($image_path === false) {
53 $app->abort(404);
54 }
55
56 // define template callback
57 $callback = $config->get("imagecache::templates.{$template}");
58
59 if (is_callable($callback) || class_exists($callback)) {
60
61 // image manipulation based on callback
62 $content = $app['image']->cache(function ($image) use ($image_path, $callback) {
63
64 switch (true) {
65 case is_callable($callback):
66 return $callback($image->make($image_path));
67 break;
68
69 case class_exists($callback):
70 return $image->make($image_path)->filter(new $callback);
71 break;
72 }
73
74 }, $config->get('imagecache::lifetime'));
75
76 } else {
77
78 // get original image file contents
79 $content = file_get_contents($image_path);
80 }
81
82 // define mime type
83 $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
84
85 // return http response
86 return new IlluminateResponse($content, 200, [
87 'Content-Type' => $mime,
88 'Cache-Control' => 'max-age='.($config->get('imagecache::lifetime')*60).', public',
89 'Etag' => md5($content)
90 ]);
91
92 }])->where(['template' => join('|', array_keys($config->get('imagecache::templates'))), 'filename' => '[ \w\\.\\/\\-]+']);
93 }
94 }
95 }
96
97 /**
98 * Register the service provider.
99 *
100 * @return void
101 */
102 public function register()
103 {
104 $app = $this->app;
105
106 $app['image'] = $app->share(function ($app) {
107 return new ImageManager($app['config']->get('image::config'));
108 });
109
110 $app->alias('image', 'Intervention\Image\ImageManager');
111 }
112 }
113