diff --git a/Admin/Installer.php b/Admin/Installer.php index 84208c8..4bd707f 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -84,10 +84,10 @@ final class Installer extends InstallerAbstract private static function installMedia($dbPool, $data) : void { $collection = new Collection(); - $collection->setName((string) $data['name'] ?? ''); + $collection->name = (string) $data['name'] ?? ''; $collection->setVirtualPath((string) $data['virtualPath'] ?? '/'); $collection->setPath((string) ($data['path'] ?? '/Modules/Media/Files/' . ((string) $data['name'] ?? ''))); - $collection->setCreatedBy(new NullAccount((int) $data['user'] ?? 1)); + $collection->createdBy = new NullAccount((int) $data['user'] ?? 1); CollectionMapper::create($collection); } diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 1209543..61c3bc5 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -34,6 +34,7 @@ use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; use phpOMS\System\File\Local\Directory; use phpOMS\Utils\Parser\Markdown\Markdown; +use phpOMS\System\File\FileUtils; /** * Media class. @@ -88,7 +89,7 @@ final class ApiController extends Controller $uploads = $this->uploadFiles( $request->getData('name') === null || $request->getFiles() !== null ? '' : $request->getData('name'), $request->getFiles(), - $request->getHeader()->getAccount(), + $request->header->account, __DIR__ . '/../../../Modules/Media/Files' . \urldecode((string) ($request->getData('path') ?? '')), \urldecode((string) ($request->getData('virtualpath') ?? '')), (string) ($request->getData('type') ?? ''), @@ -240,12 +241,12 @@ final class ApiController extends Controller $media = new Media(); $media->setPath(self::normalizeDbPath($status['path']) . '/' . $status['filename']); - $media->setName($status['name']); - $media->setSize($status['size']); - $media->setCreatedBy(new NullAccount($account)); - $media->setExtension($status['extension']); + $media->name = $status['name']; + $media->size = $status['size']; + $media->createdBy = new NullAccount($account); + $media->extension = $status['extension']; $media->setVirtualPath($virtualPath); - $media->setType($type); + $media->type = $type; MediaMapper::create($media); @@ -296,7 +297,7 @@ final class ApiController extends Controller /** @var Media $new */ $new = $this->updateMediaFromRequest($request); - $this->updateModel($request->getHeader()->getAccount(), $old, $new, MediaMapper::class, 'media', $request->getOrigin()); + $this->updateModel($request->header->account, $old, $new, MediaMapper::class, 'media', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully updated', $new); } @@ -315,8 +316,8 @@ final class ApiController extends Controller /** @var Media $media */ $media = MediaMapper::get($id); - $media->setName((string) ($request->getData('name') ?? $media->getName())); - $media->setDescription((string) ($request->getData('description') ?? $media->getDescription())); + $media->name = (string) ($request->getData('name') ?? $media->name); + $media->description = (string) ($request->getData('description') ?? $media->description); $media->setPath((string) ($request->getData('path') ?? $media->getPath())); $media->setVirtualPath(\urldecode((string) ($request->getData('virtualpath') ?? $media->getVirtualPath()))); @@ -327,20 +328,20 @@ final class ApiController extends Controller ) { $name = \explode('.', \basename($path)); - $media->setName($name[0]); - $media->setExtension($name[1] ?? ''); + $media->name = $name[0]; + $media->extension = $name[1] ?? ''; $media->setVirtualPath(\dirname($path)); $media->setPath('/Modules/Media/Files/' . \ltrim($path, '\\/')); - $media->setAbsolute(false); + $media->isAbsolute = false; } if ($request->getData('content') !== null) { \file_put_contents( - $media->isAbsolute() ? $media->getPath() : __DIR__ . '/../../../' . \ltrim($media->getPath(), '\\/'), + $media->isAbsolute ? $media->getPath() : __DIR__ . '/../../../' . \ltrim($media->getPath(), '\\/'), $request->getData('content') ); - $media->setSize(\strlen($request->getData('content'))); + $media->size = \strlen($request->getData('content')); } return $media; @@ -363,13 +364,13 @@ final class ApiController extends Controller { if (!empty($val = $this->validateCollectionCreate($request))) { $response->set('collection_create', new FormValidation($val)); - $response->getHeader()->setStatusCode(RequestStatusCode::R_400); + $response->header->status = RequestStatusCode::R_400; return; } $collection = $this->createCollectionFromRequest($request); - $this->createModel($request->getHeader()->getAccount(), $collection, CollectionMapper::class, 'collection', $request->getOrigin()); + $this->createModel($request->header->account, $collection, CollectionMapper::class, 'collection', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Collection', 'Collection successfully created.', $collection); } @@ -404,10 +405,10 @@ final class ApiController extends Controller private function createCollectionFromRequest(RequestAbstract $request) : Collection { $mediaCollection = new Collection(); - $mediaCollection->setName($request->getData('name') ?? ''); - $mediaCollection->setDescription($description = Markdown::parse($request->getData('description') ?? '')); - $mediaCollection->setDescriptionRaw($description); - $mediaCollection->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); + $mediaCollection->name = $request->getData('name') ?? ''; + $mediaCollection->description = ($description = Markdown::parse($request->getData('description') ?? '')); + $mediaCollection->descriptionRaw = $description; + $mediaCollection->createdBy = new NullAccount($request->header->account); $media = $request->getDataJson('media-list'); foreach ($media as $file) { @@ -459,10 +460,10 @@ final class ApiController extends Controller /* Create collection */ $mediaCollection = new Collection(); - $mediaCollection->setName($name); - $mediaCollection->setDescription(Markdown::parse($description)); - $mediaCollection->setDescriptionRaw($description); - $mediaCollection->setCreatedBy(new NullAccount($account)); + $mediaCollection->name = $name; + $mediaCollection->description = Markdown::parse($description); + $mediaCollection->descriptionRaw = $description; + $mediaCollection->createdBy = new NullAccount($account); $mediaCollection->setSources($media); $mediaCollection->setVirtualPath('/'); $mediaCollection->setPath('/Modules/Media/Files'); @@ -496,7 +497,7 @@ final class ApiController extends Controller } else { if (\stripos( FileUtils::absolute(__DIR__ . '/../../../Modules/Media/Files/' . \ltrim($path, '\\/')), - FileUtils::absolute(__DIR__ . '/../../../Modules/Media/Files/') + FileUtils::absolute(__DIR__ . '/../../../') ) !== 0 ) { $outputDir = self::createMediaPath(__DIR__ . '/../../../Modules/Media/Files'); @@ -527,7 +528,7 @@ final class ApiController extends Controller ], ]; - $created = $this->createDbEntries($status, $request->getHeader()->getAccount(), $virtualPath, $request->getData('type') ?? ''); + $created = $this->createDbEntries($status, $request->header->account, $virtualPath, $request->getData('type') ?? ''); $ids = []; foreach ($created as $file) { diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 16b6ebf..ec6c024 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -115,28 +115,28 @@ final class BackendController extends Controller if (\is_array($collection) && \is_dir(__DIR__ . '/../Files' . $path)) { $collection = new Collection(); - $collection->setName(\basename($path)); + $collection->name = \basename($path); $collection->setVirtualPath(\dirname($path)); $collection->setPath(\dirname($path)); - $collection->setAbsolute(false); + $collection->isAbsolute = false; } if ($collection instanceof Collection) { $media += $collection->getSources(); /** @var string[] $glob */ - $glob = $collection->isAbsolute() - ? $collection->getPath() . '/' . $collection->getName() . '/*' - : \glob(__DIR__ . '/../Files/' . \rtrim($collection->getPath(), '/') . '/' . $collection->getName() . '/*'); + $glob = $collection->isAbsolute + ? $collection->getPath() . '/' . $collection->name . '/*' + : \glob(__DIR__ . '/../Files/' . \rtrim($collection->getPath(), '/') . '/' . $collection->name . '/*'); $glob = $glob === false ? [] : $glob; foreach ($glob as $file) { foreach ($media as $obj) { - if (($obj->getExtension() !== 'collection' - && !empty($obj->getExtension()) - && $obj->getName() . '.' . $obj->getExtension() === \basename($file)) - || ($obj->getExtension() === 'collection' - && $obj->getName() === \basename($file)) + if (($obj->extension !== 'collection' + && !empty($obj->extension) + && $obj->name . '.' . $obj->extension === \basename($file)) + || ($obj->extension === 'collection' + && $obj->name === \basename($file)) ) { continue 2; } @@ -145,10 +145,10 @@ final class BackendController extends Controller $pathinfo = \pathinfo($file); $localMedia = new Media(); - $localMedia->setName($pathinfo['filename']); - $localMedia->setExtension(\is_dir($file) ? 'collection' : $pathinfo['extension'] ?? ''); + $localMedia->name = $pathinfo['filename']; + $localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? ''; $localMedia->setVirtualPath($path); - $localMedia->setCreatedBy(new Account()); + $localMedia->createdBy = new Account(); $media[] = $localMedia; } @@ -180,15 +180,15 @@ final class BackendController extends Controller $id = (int) $request->getData('id'); $media = MediaMapper::get($id); - if ($media->getExtension() === 'collection') { + if ($media->extension === 'collection') { $media = MediaMapper::getByVirtualPath( - $media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->getName() + $media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->name ); $collection = CollectionMapper::get((int) $request->getData('id')); $media = \array_merge($media, $collection->getSources()); - $view->addData('path', $collection->getVirtualPath() . '/' . $collection->getName()); + $view->addData('path', $collection->getVirtualPath() . '/' . $collection->name); $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); } @@ -200,11 +200,11 @@ final class BackendController extends Controller ) { $name = \explode('.', \basename($path)); - $media->setName($name[0]); - $media->setExtension($name[1] ?? ''); + $media->name = $name[0]; + $media->extension = $name[1] ?? ''; $media->setVirtualPath(\dirname($path)); $media->setPath('/Modules/Media/Files/' . \ltrim($path, '\\/')); - $media->setAbsolute(false); + $media->isAbsolute = false; } } diff --git a/Models/Collection.php b/Models/Collection.php index 034a9d4..30a7e31 100755 --- a/Models/Collection.php +++ b/Models/Collection.php @@ -38,7 +38,7 @@ class Collection extends Media implements \Iterator * @var string * @since 1.0.0 */ - protected string $extension = 'collection'; + public string $extension = 'collection'; /** * Is collection. @@ -48,17 +48,6 @@ class Collection extends Media implements \Iterator */ protected int $collection = 1; - /** - * Constructor. - * - * @since 1.0.0 - */ - public function __construct() - { - parent::__construct(); - $this->setExtension('colection'); - } - /** * Set sources. * diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index 517be0a..05b9435 100755 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -129,19 +129,19 @@ final class CollectionMapper extends MediaMapper $parent = CollectionMapper::getParentCollection($path); if (\is_array($parent) && \is_dir(__DIR__ . '/../../Media/Files' . $path)) { $parent = new Collection(); - $parent->setName(\basename($path)); + $parent->name = \basename($path); $parent->setVirtualPath(\dirname($path)); $parent->setPath(\dirname($path)); - $parent->setAbsolute(false); + $parent->isAbsolute = false; } if ($parent instanceof Collection) { $collection += $parent->getSources(); /** @var string[] $glob */ - $glob = $parent->isAbsolute() - ? $parent->getPath() . '/' . $parent->getName() . '/*' - : \glob(__DIR__ . '/../Files/' . \rtrim($parent->getPath(), '/') . '/' . $parent->getName() . '/*'); + $glob = $parent->isAbsolute + ? $parent->getPath() . '/' . $parent->name . '/*' + : \glob(__DIR__ . '/../Files/' . \rtrim($parent->getPath(), '/') . '/' . $parent->name . '/*'); $glob = $glob === false ? [] : $glob; foreach ($glob as $file) { @@ -150,11 +150,11 @@ final class CollectionMapper extends MediaMapper } foreach ($collection as $obj) { - if (($obj->getExtension() !== 'collection' - && !empty($obj->getExtension()) - && $obj->getName() . '.' . $obj->getExtension() === \basename($file)) - || ($obj->getExtension() === 'collection' - && $obj->getName() === \basename($file)) + if (($obj->extension !== 'collection' + && !empty($obj->extension) + && $obj->name . '.' . $obj->extension === \basename($file)) + || ($obj->extension === 'collection' + && $obj->name === \basename($file)) ) { continue 2; } @@ -163,10 +163,10 @@ final class CollectionMapper extends MediaMapper $pathinfo = \pathinfo($file); $localMedia = new Collection(); - $localMedia->setName($pathinfo['filename']); - $localMedia->setExtension(\is_dir($file) ? 'collection' : $pathinfo['extension'] ?? ''); + $localMedia->name = $pathinfo['filename']; + $localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? ''; $localMedia->setVirtualPath($path); - $localMedia->setCreatedBy(new Account()); + $localMedia->createdBy = new Account(); $collection[] = $localMedia; } diff --git a/Models/Media.php b/Models/Media.php index 24213a4..b20afbd 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -41,7 +41,7 @@ class Media implements \JsonSerializable * @var string * @since 1.0.0 */ - protected string $name = ''; + public string $name = ''; /** * Type. @@ -49,7 +49,7 @@ class Media implements \JsonSerializable * @var string * @since 1.0.0 */ - protected string $type = ''; + public string $type = ''; /** * Extension. @@ -57,7 +57,7 @@ class Media implements \JsonSerializable * @var string * @since 1.0.0 */ - protected string $extension = ''; + public string $extension = ''; /** * File size in bytes. @@ -65,7 +65,7 @@ class Media implements \JsonSerializable * @var int * @since 1.0.0 */ - protected int $size = 0; + public int $size = 0; /** * Author. @@ -73,7 +73,7 @@ class Media implements \JsonSerializable * @var Account * @since 1.0.0 */ - protected Account $createdBy; + public Account $createdBy; /** * Uploaded. @@ -81,7 +81,7 @@ class Media implements \JsonSerializable * @var \DateTimeImmutable * @since 1.0.0 */ - protected \DateTimeImmutable $createdAt; + public \DateTimeImmutable $createdAt; /** * Resource path. @@ -105,7 +105,7 @@ class Media implements \JsonSerializable * @var bool * @since 1.0.0 */ - protected bool $isAbsolute = false; + public bool $isAbsolute = false; /** * Is versioned. @@ -113,7 +113,7 @@ class Media implements \JsonSerializable * @var bool * @since 1.0.0 */ - protected bool $versioned = false; + public bool $isVersioned = false; /** * Media Description. @@ -121,7 +121,7 @@ class Media implements \JsonSerializable * @var string * @since 1.0.0 */ - protected string $description = ''; + public string $description = ''; /** * Media Description. @@ -129,7 +129,7 @@ class Media implements \JsonSerializable * @var string * @since 1.0.0 */ - protected string $descriptionRaw = ''; + public string $descriptionRaw = ''; /** * Media encryption nonce. @@ -153,7 +153,7 @@ class Media implements \JsonSerializable * @var bool * @since 1.0.0 */ - protected bool $hidden = false; + public bool $isHidden = false; /** * Is collection. @@ -298,56 +298,6 @@ class Media implements \JsonSerializable return $this->nonce === null ? false : \hash_equals($this->nonce, $nonce); } - /** - * @return bool - * - * @since 1.0.0 - */ - public function isAbsolute() : bool - { - return $this->isAbsolute; - } - - /** - * @return void - * - * @since 1.0.0 - */ - public function setAbsolute(bool $absolute) : void - { - $this->isAbsolute = $absolute; - } - - /** - * @return Account - * - * @since 1.0.0 - */ - public function getCreatedBy() : Account - { - return $this->createdBy; - } - - /** - * @return \DateTimeImmutable - * - * @since 1.0.0 - */ - public function getCreatedAt() : \DateTimeImmutable - { - return $this->createdAt; - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getExtension() : string - { - return $this->extension; - } - /** * @return string * @@ -368,90 +318,6 @@ class Media implements \JsonSerializable return $this->virtualPath; } - /** - * @return string - * - * @since 1.0.0 - */ - public function getName() : string - { - return $this->name; - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getType() : string - { - return $this->type; - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getDescription() : string - { - return $this->description; - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getDescriptionRaw() : string - { - return $this->descriptionRaw; - } - - /** - * @return int - * - * @since 1.0.0 - */ - public function getSize() : int - { - return $this->size; - } - - /** - * @return bool - * - * @since 1.0.0 - */ - public function isVersioned() : bool - { - return $this->versioned; - } - - /** - * @param Account $createdBy Creator - * - * @return void - * - * @since 1.0.0 - */ - public function setCreatedBy(Account $createdBy) : void - { - $this->createdBy = $createdBy; - } - - /** - * @param string $extension Extension - * - * @return void - * - * @since 1.0.0 - */ - public function setExtension(string $extension) : void - { - $this->extension = $extension; - } - /** * @param string $path $filepath * @@ -476,100 +342,6 @@ class Media implements \JsonSerializable $this->virtualPath = \str_replace('\\', '/', $path); } - /** - * @param string $name Media name (not file name) - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) : void - { - $this->name = $name; - } - - /** - * @param string $type Media type - * - * @return void - * - * @since 1.0.0 - */ - public function setType(string $type) : void - { - $this->type = $type; - } - - /** - * @param string $description Media description - * - * @return void - * - * @since 1.0.0 - */ - public function setDescription(string $description) : void - { - $this->description = $description; - } - - /** - * @param string $description Media description - * - * @return void - * - * @since 1.0.0 - */ - public function setDescriptionRaw(string $description) : void - { - $this->descriptionRaw = $description; - } - - /** - * @param int $size Filesize - * - * @return void - * - * @since 1.0.0 - */ - public function setSize(int $size) : void - { - $this->size = $size; - } - - /** - * @param bool $versioned File is version controlled - * - * @return void - * - * @since 1.0.0 - */ - public function setVersioned(bool $versioned) : void - { - $this->versioned = $versioned; - } - - /** - * @return bool - * - * @since 1.0.0 - */ - public function isHidden() : bool - { - return $this->hidden; - } - - /** - * @param bool $hidden File is hidden - * - * @return void - * - * @since 1.0.0 - */ - public function setHidden(bool $hidden) : void - { - $this->hidden = $hidden; - } - /** * {@inheritdoc} */ @@ -583,7 +355,7 @@ class Media implements \JsonSerializable 'extension' => $this->extension, 'virtualpath' => $this->virtualPath, 'size' => $this->size, - 'hidden' => $this->hidden, + 'hidden' => $this->isHidden, 'path' => $this->path, 'absolute' => $this->isAbsolute, 'createdBy' => $this->createdBy, diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index 1c0d024..f4c3941 100755 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -40,8 +40,8 @@ class MediaMapper extends DataMapperAbstract 'media_type' => ['name' => 'media_type', 'type' => 'string', 'internal' => 'type'], 'media_description' => ['name' => 'media_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true], 'media_description_raw' => ['name' => 'media_description_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], - 'media_versioned' => ['name' => 'media_versioned', 'type' => 'bool', 'internal' => 'versioned'], - 'media_hidden' => ['name' => 'media_hidden', 'type' => 'bool', 'internal' => 'hidden'], + 'media_versioned' => ['name' => 'media_versioned', 'type' => 'bool', 'internal' => 'isVersioned'], + 'media_hidden' => ['name' => 'media_hidden', 'type' => 'bool', 'internal' => 'isHidden'], 'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true], 'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true], 'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'], diff --git a/Models/UploadFile.php b/Models/UploadFile.php index dafb9b6..d98b6fb 100755 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -261,7 +261,7 @@ class UploadFile $limit = 0; do { - $sha = \sha1_file($tempName . $rnd); + $sha = \sha1($tempName . $rnd); if ($sha === false) { throw new \Exception('No file path could be found. Potential attack!'); diff --git a/Theme/Backend/Components/InlinePreview/BaseView.php b/Theme/Backend/Components/InlinePreview/BaseView.php index 27751b0..6f9fcd9 100755 --- a/Theme/Backend/Components/InlinePreview/BaseView.php +++ b/Theme/Backend/Components/InlinePreview/BaseView.php @@ -95,18 +95,6 @@ class BaseView extends View return $this->id; } - /** - * Get name - * - * @return string - * - * @since 1.0.0 - */ - public function getName() : string - { - return $this->name; - } - /** * Is required? * diff --git a/Theme/Backend/Components/InlinePreview/inline-preview.tpl.php b/Theme/Backend/Components/InlinePreview/inline-preview.tpl.php index 1d5850e..d27a4c7 100755 --- a/Theme/Backend/Components/InlinePreview/inline-preview.tpl.php +++ b/Theme/Backend/Components/InlinePreview/inline-preview.tpl.php @@ -42,7 +42,7 @@