/
var
/
www
/
vhosts
/
ihelp.ro
/
httpdocs
/
src
/
Model
/
Table
/
/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
mkdir
upload
Name
Size
Mode
Actions
AppTable.php
2056
0644
edit
dl
rm
AwbsTable.php
7076
0644
edit
dl
rm
BankAccountsTable.php
2622
0644
edit
dl
rm
BannersTable.php
3464
0644
edit
dl
rm
CartProductsTable.php
1752
0644
edit
dl
rm
CartsTable.php
2120
0644
edit
dl
rm
CategoriesTable.php
2599
0644
edit
dl
rm
CauseNewsTable.php
1877
0644
edit
dl
rm
CausesTable.php
3936
0644
edit
dl
rm
CausesTagsTable.php
1450
0644
edit
dl
rm
CitiesTable.php
1909
0644
edit
dl
rm
CountiesTable.php
1186
0644
edit
dl
rm
DocumentsTable.php
2761
0644
edit
dl
rm
DonationsTable.php
2965
0644
edit
dl
rm
GalleryImagesTable.php
11671
0644
edit
dl
rm
LoginTokensTable.php
1486
0644
edit
dl
rm
OrderProductsTable.php
1749
0644
edit
dl
rm
OrdersTable.php
4810
0644
edit
dl
rm
ProductFavoritesTable.php
2255
0644
edit
dl
rm
ProductsTable.php
6987
0644
edit
dl
rm
ProductsTagsTable.php
1466
0644
edit
dl
rm
ProfilesTable.php
3594
0644
edit
dl
rm
ProposedCausesTable.php
1793
0644
edit
dl
rm
SettingsTable.php
1783
0644
edit
dl
rm
SponsorsActivitiesTable.php
3562
0644
edit
dl
rm
SponsorsTable.php
1494
0644
edit
dl
rm
TagsTable.php
906
0644
edit
dl
rm
UserAddressesTable.php
4183
0644
edit
dl
rm
UserSocialsTable.php
783
0644
edit
dl
rm
UsersTable.php
6672
0644
edit
dl
rm
Edit:
/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/GalleryImagesTable.php
(11671B)
<?php declare(strict_types=1); namespace App\Model\Table; use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; use Imagine\Gd\Imagine; use Imagine\Image\Box; use Imagine\Image\Point; use Imagine\Image\ImageInterface; /** * GalleryImages Model */ class GalleryImagesTable extends AppTable { /** * Initialize method */ public function initialize(array $config): void { parent::initialize($config); $this->setTable('gallery_images'); $this->setDisplayField('name'); $this->setPrimaryKey('id'); $this->addBehavior('Timestamp'); $this->addBehavior('Tree'); $this->addBehavior('Josegonzalez/Upload.Upload', [ 'image_path' => [ 'path' => 'webroot{DS}img{DS}uploads{DS}images{DS}{field-value:model}{DS}{field-value:foreign_uuid}{DS}', 'fields' => [ 'dir' => 'upload_dir', ], 'nameCallback' => function ($table, $entity, $data, $field, $settings) { $ext = pathinfo($data->getClientFilename(), PATHINFO_EXTENSION); return uniqid() . '_' . rand(1, 9999) . '_' . date('Ymd_Hms') . '.' . $ext; }, 'transformer' => function ($table, $entity, $data, $field, $settings, $filename) { /** * test start 2 * * */ $extension = pathinfo($filename, PATHINFO_EXTENSION); // Store the thumbnail in a temporary file $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; $backgroundWidth = 800; $backgroundHeight = 600; $imagine = new \Imagine\Gd\Imagine(); $size = new \Imagine\Image\Box($backgroundWidth, $backgroundHeight); $mode = \Imagine\Image\ImageInterface::THUMBNAIL_FLAG_NOCLONE; $x = 0; $y = 0; $palette = new \Imagine\Image\Palette\RGB(); $background = $imagine->create(new \Imagine\Image\Box($backgroundWidth, $backgroundHeight), $palette->color('#ededed', 100)); $photo = $imagine->open($data->getStream()->getMetadata('uri'))->thumbnail($size, $mode); $srcImgWidth = $photo->getSize()->getWidth(); $srcImgHeight = $photo->getSize()->getHeight(); // daca width <800 if ($backgroundWidth > $srcImgWidth) { $x = $backgroundWidth / 2 - $srcImgWidth / 2; } else if ($backgroundHeight > $srcImgHeight) { $y = $backgroundHeight / 2 - $srcImgHeight / 2; } $background->paste($photo, new \Imagine\Image\Point($x, $y))->save($tmp); // test end 2 /** * test start 1 * * */ // $extension = pathinfo($filename, PATHINFO_EXTENSION); // // Store the thumbnail in a temporary file // $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; // $finalW = 800; // $finalH = 600; // $finalWHRatio = $finalW / $finalH; // $mode = \Imagine\Image\ImageInterface::FILTER_LANCZOS; // $imagine = new \Imagine\Gd\Imagine(); // $image = $imagine->open($data->getStream()->getMetadata('uri')); // $srcImgWidth = $image->getSize()->getWidth(); // $srcImgHeight = $image->getSize()->getHeight(); // $srcWHRatio = $srcImgWidth / $srcImgHeight; // $resizedH = ''; // $resizedW = ''; // if ($srcWHRatio > $finalWHRatio) { // $resizedW = $srcWHRatio * $finalH; // $resizedH = $finalH; // $x_crop = $resizedW / 2 - ($finalW / 2); // $y_crop = 0; // $imagine // ->open($data->getStream()->getMetadata('uri')) // ->resize(new \Imagine\Image\Box($resizedW, $resizedH), $mode) // ->crop(new Point($x_crop, $y_crop), new Box($resizedW, $$resizedH)) // ->save($tmp); // } else { // $resizedW = $finalH; // $resizedH = $finalW / $srcWHRatio; // $x_crop = 0; // $y_crop = $resizedH / 2 - $finalH / 2; // $imagine // ->open($data->getStream()->getMetadata('uri')) // ->resize(new \Imagine\Image\Box($resizedW, $resizedH), $mode) // ->crop(new Point($x_crop, $y_crop), new Box($resizedW, $resizedH)) // ->save($tmp); // } //test end 1 /** * start default * * */ // $extension = pathinfo($filename, PATHINFO_EXTENSION); // // Store the thumbnail in a temporary file // $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension; // // Use the Imagine library to DO THE THING // $size = new \Imagine\Image\Box(800, 600); // $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET; // $imagine = new \Imagine\Gd\Imagine(); // // Save that modified file to our temp file // $imagine->open($data->getStream()->getMetadata('uri')) // ->thumbnail($size, $mode) // ->crop(new Point(0, 0), $size) // ->save($tmp); // end default // Now return the original *and* the thumbnail return [ $data->getStream()->getMetadata('uri') => $filename, $tmp => 'resize-' . $filename, ]; }, 'keepFilesOnDelete' => false, ], ]); $this->belongsTo('ParentGalleryImages', [ 'className' => 'GalleryImages', 'foreignKey' => 'parent_id', ]); $this->hasMany('ChildGalleryImages', [ 'className' => 'GalleryImages', 'foreignKey' => 'parent_id', ]); $this->belongsTo('Causes', [ 'foreignKey' => 'foreign_key' ]); $this->belongsTo('Products', [ 'foreignKey' => 'foreign_key' ]); } /** * Default validation rules. */ public function validationDefault(Validator $validator): Validator { $validator ->integer('id') ->allowEmptyString('id', null, 'create'); $validator ->integer('foreign_key') ->requirePresence('foreign_key', 'create') ->notEmptyString('foreign_key'); $validator ->scalar('model') ->maxLength('model', 64) ->requirePresence('model', 'create') ->notEmptyString('model'); $validator ->scalar('name') ->maxLength('name', 255) ->allowEmptyString('name'); $validator ->scalar('description') ->allowEmptyString('description'); $validator ->scalar('copyright') ->maxLength('copyright', 255) ->allowEmptyString('copyright'); $validator->setProvider('upload', \Josegonzalez\Upload\Validation\DefaultValidation::class); $validator ->requirePresence('image_path', 'create', __d('admin', 'Acest câmp este obligatoriu')) ->allowEmptyFile('image_path'); $validator ->add('image_path', 'isFileUpload', [ 'rule' => ['isFileUpload'], 'message' => __d('admin', 'Selectați imaginea'), 'provider' => 'upload', 'last' => true, ]) ->add('image_path', 'fileExtensions', [ 'rule' => ['mimeType', ['image/jpeg', 'image/png', 'image/jpeg']], 'message' => __d('admin', 'Fișierele trebuie să fie .png .jpg'), 'last' => true, ]) ->add('image_path', 'fileBelowMaxSize', [ 'rule' => ['isBelowMaxSize', 1024 * 1024 * 1], 'message' => __d('admin', 'Fișierul trebuie să aibă sub 1 MB'), 'provider' => 'upload' ]) ->add('image_path', 'fileAboveMinWidth', [ 'rule' => ['isAboveMinWidth', 800], 'message' => __d('admin', 'Această imagine trebuie să aibă o lățime de cel puțin 800 de pixeli'), 'provider' => 'upload' ]) ->add('image_path', 'fileAboveMinHeight', [ 'rule' => ['isAboveMinHeight', 600], 'message' => __d('admin', 'Această imagine trebuie să aibă cel puțin 600 de pixeli înălțime'), 'provider' => 'upload' ]); return $validator; } /** * Default validation rules. */ public function validationFeaturedImage(Validator $validator): Validator { $validator->setProvider('upload', \Josegonzalez\Upload\Validation\DefaultValidation::class); $validator ->requirePresence('image_path', 'create', __d('admin', 'Acest câmp este obligatoriu')) ->allowEmptyFile('image_path'); $validator ->add('image_path', 'isFileUpload', [ 'rule' => ['isFileUpload'], 'message' => __d('admin', 'Selectați imaginea'), 'provider' => 'upload', 'last' => true, ]) ->add('image_path', 'fileExtensions', [ 'rule' => ['mimeType', ['image/jpeg', 'image/png', 'image/jpeg']], 'message' => __d('admin', 'Fișierele trebuie să fie .png .jpg'), 'last' => true, ]) ->add('image_path', 'fileBelowMaxSize', [ 'rule' => ['isBelowMaxSize', 1024 * 1024 * 1], 'message' => __d('admin', 'Fișierul trebuie să aibă sub 1 MB'), 'provider' => 'upload' ]) ->add('image_path', 'fileAboveMinWidth', [ 'rule' => ['isAboveMinWidth', 800], 'message' => __d('admin', 'Această imagine trebuie să aibă o lățime de cel puțin 800 de pixeli'), 'provider' => 'upload' ]) ->add('image_path', 'fileAboveMinHeight', [ 'rule' => ['isAboveMinHeight', 600], 'message' => __d('admin', 'Această imagine trebuie să aibă cel puțin 600 de pixeli înălțime'), 'provider' => 'upload' ]); return $validator; } /** * Returns a rules checker object that will be used for validating */ public function buildRules(RulesChecker $rules): RulesChecker { $rules->add($rules->existsIn(['parent_id'], 'ParentGalleryImages'), ['errorField' => 'parent_id']); return $rules; } }
Save
cmd:
run