-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 04fb749
Showing
18 changed files
with
1,288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/composer.lock | ||
/composer.phar | ||
/phpunit.xml | ||
/.phpunit.result.cache | ||
/phpunit.phar | ||
/config/Migrations/schema-dump-default.lock | ||
/vendor/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Assets plugin for CakePHP | ||
|
||
## Installation | ||
|
||
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). | ||
|
||
The recommended way to install composer packages is: | ||
|
||
``` | ||
composer require passchn/cakephp-assets | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "passchn/cakephp-assets", | ||
"description": "Asset management plugin for CakePHP", | ||
"type": "cakephp-plugin", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=8.0", | ||
"cakephp/cakephp": "^4.3", | ||
"josegonzalez/cakephp-upload": "^6.0", | ||
"league/csv": "^9.8", | ||
"nette/finder": "^2.5", | ||
"nette/utils": "^3.2", | ||
"intervention/image": "^2.7" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.5 || ^9.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Test\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Test\\Test\\": "tests/", | ||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Migrations\AbstractMigration; | ||
|
||
class AssetsAddAssetsTable extends AbstractMigration | ||
{ | ||
/** | ||
* Up Method. | ||
* | ||
* More information on this method is available here: | ||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-up-method | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
$this->table('assets_assets', ['id' => false, 'primary_key' => ['id']]) | ||
->addColumn('id', 'uuid', [ | ||
'default' => '', | ||
'limit' => null, | ||
'null' => false, | ||
]) | ||
->addColumn('title', 'string', [ | ||
'default' => '', | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('description', 'text', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => true, | ||
]) | ||
->addColumn('category', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]) | ||
->addColumn('filename', 'string', [ | ||
'default' => '', | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('directory', 'string', [ | ||
'default' => '', | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('mimetype', 'string', [ | ||
'default' => '', | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('filesize', 'string', [ | ||
'default' => '', | ||
'limit' => 255, | ||
'null' => false, | ||
]) | ||
->addColumn('created', 'timestamp', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => true, | ||
]) | ||
->addColumn('modified', 'timestamp', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => true, | ||
]) | ||
->create(); | ||
} | ||
|
||
/** | ||
* Down Method. | ||
* | ||
* More information on this method is available here: | ||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-down-method | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
|
||
$this->table('assets_assets')->drop()->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
/** | ||
* Configuration for the Assets Plugin | ||
*/ | ||
'AssetsPlugin' => [ | ||
'AssetsTable' => [ | ||
'DisplayField' => 'title', | ||
'Behaviors' => [], | ||
] | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use Cake\Routing\Route\DashedRoute; | ||
use Cake\Routing\RouteBuilder; | ||
|
||
return static function (RouteBuilder $routes) { | ||
$routes->plugin( | ||
'Assets', | ||
['path' => '/assets'], | ||
function (RouteBuilder $routes) { | ||
$routes->setRouteClass(DashedRoute::class); | ||
|
||
$routes->fallbacks(DashedRoute::class); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Assets\Controller; | ||
|
||
use App\Controller\AppController as BaseController; | ||
use Assets\Model\Table\AssetsAssetsTable; | ||
|
||
class AppController extends BaseController | ||
{ | ||
protected AssetsAssetsTable $Assets; | ||
|
||
public function initialize(): void | ||
{ | ||
parent::initialize(); | ||
$this->Assets = $this->fetchTable('Assets.AssetsAssets'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Assets\Controller; | ||
|
||
use Assets\Controller\AppController; | ||
use function __; | ||
|
||
/** | ||
* Assets Controller | ||
* | ||
* @method \Cake\ORM\Entity[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) | ||
*/ | ||
class AssetsController extends AppController | ||
{ | ||
/** | ||
* View method | ||
* | ||
* @param string|null $id Asset id. | ||
* @return \Cake\Http\Response|null|void Renders view | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function view($id = null) | ||
{ | ||
$asset = $this->Assets->get($id, [ | ||
'contain' => [], | ||
]); | ||
|
||
$this->set(compact('asset')); | ||
} | ||
|
||
/** | ||
* @return void | ||
* | ||
* Add ?download=1 to URL to download instead of view the file. | ||
*/ | ||
public function download(string $id) | ||
{ | ||
$asset = $this->Assets->get($id); | ||
|
||
$disposition = $this->getRequest()->getQuery('download') ? 'attachment' : 'inline'; | ||
|
||
header("Content-type: " . $asset->mimetype); | ||
header("Content-Disposition: $disposition; filename=\"{$asset->public_filename}\""); | ||
header("Pragma: no-cache"); | ||
header("Expires: 0"); | ||
|
||
try { | ||
echo $asset->read(); | ||
} catch (\Exception $e) { | ||
echo __("Die Datei kann nicht geöffnet werden. "); | ||
} | ||
|
||
exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Assets\Controller\admin; | ||
|
||
use Assets\Controller\AppController; | ||
use function __; | ||
|
||
/** | ||
* Assets Controller | ||
* | ||
* @method \Cake\ORM\Entity[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) | ||
*/ | ||
class AssetsController extends AppController | ||
{ | ||
/** | ||
* Index method | ||
* | ||
* @return \Cake\Http\Response|null|void Renders view | ||
*/ | ||
public function index() | ||
{ | ||
$assets = $this->paginate($this->Assets); | ||
|
||
$this->set(compact('assets')); | ||
} | ||
|
||
/** | ||
* View method | ||
* | ||
* @param string|null $id Asset id. | ||
* @return \Cake\Http\Response|null|void Renders view | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function view($id = null) | ||
{ | ||
$asset = $this->Assets->get($id, [ | ||
'contain' => [], | ||
]); | ||
|
||
$this->set(compact('asset')); | ||
} | ||
|
||
/** | ||
* Add method | ||
* | ||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. | ||
*/ | ||
public function add() | ||
{ | ||
$asset = $this->Assets->newEmptyEntity(); | ||
if ($this->request->is('post')) { | ||
$asset = $this->Assets->patchEntity($asset, $this->request->getData()); | ||
if ($this->Assets->save($asset)) { | ||
$this->Flash->success(__('The asset has been saved.')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
$this->Flash->error(__('The asset could not be saved. Please, try again.')); | ||
} | ||
$this->set(compact('asset')); | ||
} | ||
|
||
/** | ||
* Edit method | ||
* | ||
* @param string|null $id Asset id. | ||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function edit($id = null) | ||
{ | ||
$asset = $this->Assets->get($id, [ | ||
'contain' => [], | ||
]); | ||
if ($this->request->is(['patch', 'post', 'put'])) { | ||
$asset = $this->Assets->patchEntity($asset, $this->request->getData()); | ||
if ($this->Assets->save($asset)) { | ||
$this->Flash->success(__('The asset has been saved.')); | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
$this->Flash->error(__('The asset could not be saved. Please, try again.')); | ||
} | ||
$this->set(compact('asset')); | ||
} | ||
|
||
/** | ||
* Delete method | ||
* | ||
* @param string|null $id Asset id. | ||
* @return \Cake\Http\Response|null|void Redirects to index. | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function delete($id = null) | ||
{ | ||
$this->request->allowMethod(['post', 'delete']); | ||
$asset = $this->Assets->get($id); | ||
if ($this->Assets->delete($asset)) { | ||
$this->Flash->success(__('The asset has been deleted.')); | ||
} else { | ||
$this->Flash->error(__('The asset could not be deleted. Please, try again.')); | ||
} | ||
|
||
return $this->redirect(['action' => 'index']); | ||
} | ||
|
||
/** | ||
* @return void | ||
* | ||
* Add ?download=1 to URL to download instead of view the file. | ||
*/ | ||
public function download(string $id) | ||
{ | ||
$asset = $this->Assets->get($id); | ||
|
||
$disposition = $this->getRequest()->getQuery('download') ? 'attachment' : 'inline'; | ||
|
||
header("Content-type: " . $asset->mimetype); | ||
header("Content-Disposition: $disposition; filename=\"{$asset->public_filename}\""); | ||
header("Pragma: no-cache"); | ||
header("Expires: 0"); | ||
|
||
try { | ||
echo $asset->read(); | ||
} catch (\Exception $e) { | ||
echo __("Die Datei kann nicht geöffnet werden. "); | ||
} | ||
|
||
exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Assets\Enum; | ||
|
||
class ImageSizes | ||
{ | ||
const THMB = 75; | ||
const SM = 120; | ||
const MD = 230; | ||
const LG = 520; | ||
const XL = 750; | ||
const XXL = 1250; | ||
const HD = 1920; | ||
} |
Oops, something went wrong.