diff --git a/www/plugins/jasonwilliams/imgcache/Plugin.php b/www/plugins/jasonwilliams/imgcache/Plugin.php index 4c44a06..c1eab93 100644 --- a/www/plugins/jasonwilliams/imgcache/Plugin.php +++ b/www/plugins/jasonwilliams/imgcache/Plugin.php @@ -5,6 +5,7 @@ */ use System\Classes\PluginBase; +use JasonWilliams\ImgCache\Classes\Image; class Plugin extends PluginBase { @@ -24,7 +25,8 @@ class Plugin extends PluginBase return [ 'filters' => [ 'imgcache' => function($imgurl) { - return $imgurl; + $image = new Image($imgurl); + return $image; } ] ]; diff --git a/www/plugins/jasonwilliams/imgcache/assets/images/notfound.png b/www/plugins/jasonwilliams/imgcache/assets/images/notfound.png new file mode 100644 index 0000000..f8b472e Binary files /dev/null and b/www/plugins/jasonwilliams/imgcache/assets/images/notfound.png differ diff --git a/www/plugins/jasonwilliams/imgcache/classes/Image.php b/www/plugins/jasonwilliams/imgcache/classes/Image.php new file mode 100644 index 0000000..bfe5d8d --- /dev/null +++ b/www/plugins/jasonwilliams/imgcache/classes/Image.php @@ -0,0 +1,52 @@ +imgurl = $url; + $this->folder = base_path(substr(config('cms.storage.media.path'), 1)).'/external/'; + $this->urlbase = config('cms.storage.media.path').'/external/'; + $this->filename = md5($url).'.jpg'; + + $fs = new Filesystem; + + if($fs->existsInsensitive($this->folder.$this->filename)) + { + $this->found = true; + $this->imgurl = $this->urlbase.$this->filename; + return; + } + + $req = new Http(); + $img = $req->get($url, [ + 'CURLOPT_CONNECTTIMEOUT' => 1 + ]); + + if ($img->code !== 200) $this->imgurl = '/plugins/jasonwilliams/imgcache/assets/images/notfound.png'; + else { + $this->found = true; + $fs->put($this->folder.$this->filename, $img); + $this->imgurl = $this->urlbase.$this->filename; + } + } + + public function __toString() + { + return $this->imgurl; + } +} diff --git a/www/themes/jason-williamsca/partials/feed/template.htm b/www/themes/jason-williamsca/partials/feed/template.htm index 0194921..01b664c 100644 --- a/www/themes/jason-williamsca/partials/feed/template.htm +++ b/www/themes/jason-williamsca/partials/feed/template.htm @@ -13,7 +13,6 @@