mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00

- resize uploaded image to thumbnail, medium, large, feed, and id3 formats - set image url formats where adapted in views - set format sizes and extensions in Images config file for customization - add validation for image uploads: `min_dims` and `is_image_squared` - update codeigniter4 and myth-auth php packages to latest develop versions - update npm packages to latest versions - update public/.htaccess closes #6
106 lines
2.7 KiB
PHP
106 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright 2020 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Validation;
|
|
|
|
use CodeIgniter\Validation\FileRules as ValidationFileRules;
|
|
|
|
class FileRules extends ValidationFileRules
|
|
{
|
|
/**
|
|
* Checks an uploaded file to verify that the dimensions are within
|
|
* a specified allowable dimension.
|
|
*
|
|
* @param string|null $blank
|
|
* @param string $params
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function min_dims(string $blank = null, string $params): bool
|
|
{
|
|
// Grab the file name off the top of the $params
|
|
// after we split it.
|
|
$params = explode(',', $params);
|
|
$name = array_shift($params);
|
|
|
|
if (!($files = $this->request->getFileMultiple($name))) {
|
|
$files = [$this->request->getFile($name)];
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
if (is_null($file)) {
|
|
return false;
|
|
}
|
|
|
|
if ($file->getError() === UPLOAD_ERR_NO_FILE) {
|
|
return true;
|
|
}
|
|
|
|
// Get Parameter sizes
|
|
$minWidth = $params[0] ?? 0;
|
|
$minHeight = $params[1] ?? 0;
|
|
|
|
// Get uploaded image size
|
|
$info = getimagesize($file->getTempName());
|
|
$fileWidth = $info[0];
|
|
$fileHeight = $info[1];
|
|
|
|
if ($fileWidth < $minWidth || $fileHeight < $minHeight) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
/**
|
|
* Checks an uploaded file to verify that the image ratio is of 1:1
|
|
*
|
|
* @param string|null $blank
|
|
* @param string $params
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_image_squared(string $blank = null, string $params): bool
|
|
{
|
|
// Grab the file name off the top of the $params
|
|
// after we split it.
|
|
$params = explode(',', $params);
|
|
$name = array_shift($params);
|
|
|
|
if (!($files = $this->request->getFileMultiple($name))) {
|
|
$files = [$this->request->getFile($name)];
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
if (is_null($file)) {
|
|
return false;
|
|
}
|
|
|
|
if ($file->getError() === UPLOAD_ERR_NO_FILE) {
|
|
return true;
|
|
}
|
|
|
|
// Get uploaded image size
|
|
$info = getimagesize($file->getTempName());
|
|
$fileWidth = $info[0];
|
|
$fileHeight = $info[1];
|
|
|
|
if ($fileWidth != $fileHeight) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
}
|