111 lines
3.4 KiB
PHP
111 lines
3.4 KiB
PHP
<?php namespace Aweos\Resizer;
|
|
|
|
use Aweos\Resizer\Classes\CacheManager;
|
|
use Aweos\Resizer\Classes\FileObserver;
|
|
use Aweos\Resizer\Classes\ImageResizer;
|
|
use Aweos\Resizer\Classes\ResizeJob;
|
|
use Aweos\Resizer\Console\ResizeMake;
|
|
use Aweos\Resizer\Console\ResizePurge;
|
|
use Aweos\Resizer\Lib\MediaPath;
|
|
use Event;
|
|
use Queue;
|
|
use System\Classes\MediaLibrary;
|
|
use System\Classes\PluginBase;
|
|
use System\Models\File;
|
|
|
|
/**
|
|
* resizer Plugin Information File
|
|
*/
|
|
class Plugin extends PluginBase
|
|
{
|
|
/**
|
|
* Returns information about this plugin.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function pluginDetails()
|
|
{
|
|
return [
|
|
'name' => 'resizer',
|
|
'description' => 'No description provided yet...',
|
|
'author' => 'aweos',
|
|
'icon' => 'icon-leaf'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Register method, called when the plugin is first registered.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->registerConsoleCommand('resizer.resizemake', ResizeMake::class);
|
|
$this->registerConsoleCommand('resizer.resizepurge', ResizePurge::class);
|
|
}
|
|
|
|
/**
|
|
* Boot method, called right before the request route.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function boot()
|
|
{
|
|
app()->bind(ImageResizer::class, function() {
|
|
$disk = (new File())->getDisk();
|
|
$dir = (new File(['is_public' => true]))->getStorageDirectory().'c/';
|
|
$media = MediaLibrary::instance();
|
|
|
|
return new ImageResizer($disk, $dir, $media);
|
|
});
|
|
|
|
Event::listen('media.file.upload', function($widget, $filePath, $uploadedFile) {
|
|
if ((new MediaPath($filePath))->shouldProcess()) {
|
|
Queue::push(ResizeJob::class, [$filePath]);
|
|
}
|
|
});
|
|
Event::listen('media.file.delete', function($widget, $filePath) {
|
|
app(FileObserver::class)->delete(new MediaPath($filePath));
|
|
app(CacheManager::class)->delete(new MediaPath($filePath));
|
|
});
|
|
|
|
Event::listen('media.file.move', function($widget, $old, $new) {
|
|
app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new));
|
|
app(CacheManager::class)->delete(new MediaPath($old));
|
|
});
|
|
Event::listen('media.file.rename', function($widget, $old, $new) {
|
|
app(FileObserver::class)->rename(new MediaPath($old), new MediaPath($new));
|
|
app(CacheManager::class)->delete(new MediaPath($old));
|
|
});
|
|
}
|
|
|
|
public function registerSettings() {
|
|
return [
|
|
'resizer' => [
|
|
'label' => 'Resizer Settings',
|
|
'description' => 'Change how images are resized and compressed',
|
|
'category' => 'Base',
|
|
'icon' => 'icon-cog',
|
|
'class' => '\Aweos\Resizer\Models\Setting',
|
|
'order' => 500,
|
|
'keywords' => 'setting',
|
|
'permissions' => ['aweos.resizer.*']
|
|
]
|
|
];
|
|
}
|
|
|
|
public function registerMarkupTags() {
|
|
return [
|
|
'filters' => [
|
|
'resize' => fn ($media, $size = 'original', $sizes = null, $options = []) => app(CacheManager::class)->get(
|
|
new MediaPath($media),
|
|
$size,
|
|
$sizes,
|
|
$options,
|
|
)
|
|
]
|
|
];
|
|
}
|
|
|
|
}
|