From 645ba73fd148bfecc708e73eeca31e77b90e9113 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 13 Aug 2016 14:13:07 +0200 Subject: [PATCH 01/12] Test fixes --- Controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller.js b/Controller.js index 591a249..8542c49 100644 --- a/Controller.js +++ b/Controller.js @@ -40,7 +40,7 @@ uploader.setSuccess(e.id, function (type, response) { e.querySelector('input[type=file]+input[type=hidden]').value = JSON.stringify(response.uploads); - self.app.eventManager.trigger(requestId, requestGroup); + self.app.eventManager.trigger(requestGroup, requestId); }); uploader.setUri(Url + '{/lang}/api/media'); From db391d326573376f400bcd89ff3e7cc06895bf19 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 2 Oct 2016 12:07:05 +0200 Subject: [PATCH 02/12] Core adjustments for pending issues --- Models/Collection.php | 1 - Models/CollectionMapper.php | 4 ++-- Models/UploadFile.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Models/Collection.php b/Models/Collection.php index 8652621..aa2a546 100644 --- a/Models/Collection.php +++ b/Models/Collection.php @@ -15,7 +15,6 @@ */ namespace Modules\Media\Models; - /** * Media class. * diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index 61f0d0c..4a273c3 100644 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -15,6 +15,7 @@ */ namespace Modules\Media\Models; +use Modules\Media\Models\MediaMapper; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Column; @@ -22,8 +23,7 @@ class CollectionMapper extends MediaMapper { protected static $hasMany = [ 'sources' => [ - 'mapper' => \Modules\Media\Models\MediaMapper::class, /* mapper of the related object */ - 'relationmapper' => null, /* if the relation itself is a more complex object that has it's own mapper */ + 'mapper' => MediaMapper::class, /* mapper of the related object */ 'table' => 'media_relation', /* table of the related object, null if no relation table is used (many->1) */ 'dst' => 'media_relation_dst', 'src' => 'media_relation_src', diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 27b79fb..270e7d6 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -15,7 +15,7 @@ */ namespace Modules\Media\Models; -use phpOMS\System\File\Directory; +use phpOMS\System\File\Local\Directory; /** From cc967bb57d9d49de2d04b48d6c6bceb478ad3f3b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 9 Oct 2016 20:07:30 +0200 Subject: [PATCH 03/12] Fix install --- Admin/Install/Navigation.php | 2 +- Admin/Installer.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 30d2f96..394cdfb 100644 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\Pool; */ class Navigation { - public static function install(Pool $dbPool) + public static function install(string $path, Pool $dbPool) { $navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true); diff --git a/Admin/Installer.php b/Admin/Installer.php index 43e7014..11eaaf8 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -37,9 +37,9 @@ class Installer extends InstallerAbstract /** * {@inheritdoc} */ - public static function install(Pool $dbPool, InfoManager $info) + public static function install(string $path, Pool $dbPool, InfoManager $info) { - parent::install($dbPool, $info); + parent::install($path, $dbPool, $info); switch ($dbPool->get('core')->getType()) { case DatabaseType::MYSQL: From e80b75c68b24af9229b3268dde91f379b733c544 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 29 Oct 2016 20:44:52 +0200 Subject: [PATCH 04/12] Adjust database pool name --- Admin/Activate.php | 4 ++-- Admin/Deactivate.php | 4 ++-- Admin/Install/Navigation.php | 4 ++-- Admin/Installer.php | 4 ++-- Admin/Uninstall.php | 4 ++-- Admin/Update.php | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Admin/Activate.php b/Admin/Activate.php index 5a0132f..eb10180 100644 --- a/Admin/Activate.php +++ b/Admin/Activate.php @@ -16,7 +16,7 @@ namespace Modules\Media\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\ActivateAbstract; use phpOMS\Module\InfoManager; @@ -37,7 +37,7 @@ class Activate extends ActivateAbstract /** * {@inheritdoc} */ - public static function activate(Pool $dbPool, InfoManager $info) + public static function activate(DatabasePool $dbPool, InfoManager $info) { parent::activate($dbPool, $info); } diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php index 38796a8..ea28897 100644 --- a/Admin/Deactivate.php +++ b/Admin/Deactivate.php @@ -16,7 +16,7 @@ namespace Modules\Media\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\DeactivateAbstract; use phpOMS\Module\InfoManager; @@ -37,7 +37,7 @@ class Deactivate extends DeactivateAbstract /** * {@inheritdoc} */ - public static function deactivate(Pool $dbPool, InfoManager $info) + public static function deactivate(DatabasePool $dbPool, InfoManager $info) { parent::deactivate($dbPool, $info); } diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 394cdfb..87d05aa 100644 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -14,7 +14,7 @@ * @link http://orange-management.com */ namespace Modules\Media\Admin\Install; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; /** * Navigation class. @@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\Pool; */ class Navigation { - public static function install(string $path, Pool $dbPool) + public static function install(string $path, DatabasePool $dbPool) { $navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true); diff --git a/Admin/Installer.php b/Admin/Installer.php index 11eaaf8..75c4c0c 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -16,7 +16,7 @@ namespace Modules\Media\Admin; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\InfoManager; use phpOMS\Module\InstallerAbstract; @@ -37,7 +37,7 @@ class Installer extends InstallerAbstract /** * {@inheritdoc} */ - public static function install(string $path, Pool $dbPool, InfoManager $info) + public static function install(string $path, DatabasePool $dbPool, InfoManager $info) { parent::install($path, $dbPool, $info); diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php index 3278426..fd8ed1f 100644 --- a/Admin/Uninstall.php +++ b/Admin/Uninstall.php @@ -16,7 +16,7 @@ namespace Modules\Media\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\Schema\Builder; use phpOMS\Module\UninstallAbstract; @@ -37,7 +37,7 @@ class Uninstall extends UninstallAbstract /** * {@inheritdoc} */ - public static function uninstall(Pool $dbPool, InfoManager $info) + public static function uninstall(DatabasePool $dbPool, InfoManager $info) { parent::uninstall($dbPool, $info); diff --git a/Admin/Update.php b/Admin/Update.php index 99c4e9b..4df8032 100644 --- a/Admin/Update.php +++ b/Admin/Update.php @@ -16,7 +16,7 @@ namespace Modules\Media\Admin; -use phpOMS\DataStorage\Database\Pool; +use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\UpdateAbstract; use phpOMS\System\File\Directory; @@ -37,7 +37,7 @@ class Update extends UpdateAbstract /** * {@inheritdoc} */ - public static function update(Pool $dbPool, array $info) + public static function update(DatabasePool $dbPool, array $info) { Directory::deletePath(__DIR__ . '/Update'); mkdir('Update'); From 734877e4eca3eb3d368c10c288f6967562da5b32 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 6 Nov 2016 22:22:07 +0100 Subject: [PATCH 05/12] Fixing doc blocks --- Models/MediaMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index 658ee5a..298d23a 100644 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -26,7 +26,7 @@ class MediaMapper extends DataMapperAbstract /** * Columns. * - * @var array + * @var array * @since 1.0.0 */ protected static $columns = [ From 4ff01c1c6f325bd7d6835421a58c9d91a60ac7f2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 9 Nov 2016 21:14:16 +0100 Subject: [PATCH 06/12] Fixing draw and drafting create --- Controller.php | 13 +++++++++---- Models/UploadFile.php | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Controller.php b/Controller.php index da9a93f..d28cddf 100644 --- a/Controller.php +++ b/Controller.php @@ -213,18 +213,23 @@ class Controller extends ModuleAbstract implements WebInterface if (!empty($files)) { $upload = new UploadFile(); - $rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT); - $path = '/' . trim($basePath, '/\\.') . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; + $path = self::createMediaPath($basePath); $upload->setOutputDir($path); $upload->setFileName(false); $status = $upload->upload($files); - $mediaCreated = $this->createDbEntries($status, $account); + $mediaCreated = self::createDbEntries($status, $account); } return $mediaCreated; } + public static function createMediaPath(string $basePath = '/Modules/Media/Files') : string + { + $rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT); + return '/' . trim($basePath, '/\\.') . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; + } + /** * @param array $status Files * @param int $account Uploader @@ -234,7 +239,7 @@ class Controller extends ModuleAbstract implements WebInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function createDbEntries(array $status, int $account) : array + public static function createDbEntries(array $status, int $account) : array { $mediaCreated = []; diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 270e7d6..fa9c6e1 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -138,9 +138,9 @@ class UploadFile if (!$this->fileName || empty($this->fileName) || file_exists($path . '/' . $this->fileName)) { $rnd = ''; + // todo: implement limit since this could get exploited do { $sha = sha1_file($f['tmp_name'] . $rnd); - $sha .= '.' . $extension; if ($sha === false) { $result[$key]['status'] = UploadStatus::FAILED_HASHING; @@ -148,6 +148,8 @@ class UploadFile return $result; } + $sha .= '.' . $extension; + $this->fileName = $sha; $rnd = mt_rand(); } while (file_exists($path . '/' . $this->fileName)); From 85b5b62c70bb97f38bbd333f2836ee537b139d46 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 23 Nov 2016 23:49:21 +0100 Subject: [PATCH 07/12] [Media] Optimization for external use --- Controller.php | 37 +++++++++++++++++++++++-------------- Models/Media.php | 5 +++++ Models/UploadFile.php | 16 ++++++++++++---- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Controller.php b/Controller.php index d28cddf..ac7d178 100644 --- a/Controller.php +++ b/Controller.php @@ -207,7 +207,7 @@ class Controller extends ModuleAbstract implements WebInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public function uploadFiles(array $files, int $account, string $basePath = '/Modules/Media/Files') : array + public function uploadFiles(array $files, int $account, string $basePath = 'Modules/Media/Files') : array { $mediaCreated = []; @@ -224,10 +224,10 @@ class Controller extends ModuleAbstract implements WebInterface return $mediaCreated; } - public static function createMediaPath(string $basePath = '/Modules/Media/Files') : string + public static function createMediaPath(string $basePath = 'Modules/Media/Files') : string { $rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT); - return '/' . trim($basePath, '/\\.') . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; + return $basePath . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; } /** @@ -244,20 +244,29 @@ class Controller extends ModuleAbstract implements WebInterface $mediaCreated = []; foreach ($status as $uFile) { - if ($uFile['status'] === UploadStatus::OK) { - $media = new Media(); - $media->setPath(trim($uFile['path'], '/') . '/' . $uFile['filename']); - $media->setName($uFile['filename']); - $media->setSize($uFile['size']); - $media->setCreatedBy($account); - $media->setCreatedAt(new \DateTime('NOW')); - $media->setExtension($uFile['extension']); - - $mediaCreated[] = MediaMapper::create($media); - } + $mediaCreated[] = self::createDbEntry($uFile, $account); } return $mediaCreated; } + public static function createDbEntry(array $status, int $account) + { + $media = null; + + if ($status['status'] === UploadStatus::OK) { + $media = new Media(); + $media->setPath(trim($status['path'], '/') . '/' . $status['filename']); + $media->setName($status['name']); + $media->setSize($status['size']); + $media->setCreatedBy($account); + $media->setCreatedAt(new \DateTime('NOW')); + $media->setExtension($status['extension']); + + MediaMapper::create($media); + } + + return $media; + } + } diff --git a/Models/Media.php b/Models/Media.php index 9eb419c..1666da0 100644 --- a/Models/Media.php +++ b/Models/Media.php @@ -330,4 +330,9 @@ class Media { $this->versioned = $versioned; } + + public function toArray() + { + return []; + } } diff --git a/Models/UploadFile.php b/Models/UploadFile.php index fa9c6e1..0585cd4 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -31,6 +31,7 @@ use phpOMS\System\File\Local\Directory; */ class UploadFile { + const PATH_GENERATION_LIMIT = 1000; /** * Upload max size. @@ -54,7 +55,7 @@ class UploadFile * @var string * @since 1.0.0 */ - private $outputDir = '/Modules/Media/Files'; + private $outputDir = 'Modules/Media/Files'; /** * Output file name. @@ -79,6 +80,8 @@ class UploadFile * * @return array * + * @throws \Exception + * * @since 1.0.0 * @author Dennis Eichhorn */ @@ -138,7 +141,7 @@ class UploadFile if (!$this->fileName || empty($this->fileName) || file_exists($path . '/' . $this->fileName)) { $rnd = ''; - // todo: implement limit since this could get exploited + $limit = 0; do { $sha = sha1_file($f['tmp_name'] . $rnd); @@ -152,11 +155,16 @@ class UploadFile $this->fileName = $sha; $rnd = mt_rand(); - } while (file_exists($path . '/' . $this->fileName)); + $limit++; + } while (file_exists($path . '/' . $this->fileName) && $limit < self::PATH_GENERATION_LIMIT); + + if($limit >= self::PATH_GENERATION_LIMIT) { + throw new \Exception('No file path could be found. Potential attack!'); + } } if (!is_dir($path)) { - Directory::createPath($path, '0655', true); + Directory::create($path, '0655', true); } if (!is_uploaded_file($f['tmp_name'])) { From 093f7fb831ca01446862324c74332b1b78822749 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 7 Dec 2016 19:00:00 +0100 Subject: [PATCH 08/12] Implementing interlaced image upload --- Models/UploadFile.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 0585cd4..a6a30f5 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -33,6 +33,14 @@ class UploadFile { const PATH_GENERATION_LIMIT = 1000; + /** + * Image interlaced. + * + * @var int + * @since 1.0.0 + */ + private $interlaced = true; + /** * Upload max size. * @@ -179,6 +187,14 @@ class UploadFile return $result; } + if($this->interlaced && in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) { + $img = fopen($f['tmp_name'], $path . '/' . $this->fileName); + flock($img, LOCK_EX); + imageinterlace($img, (int) $this->interlaced); + flock($img, LOCK_UN); + fclose($img); + } + $result[$key]['path'] = $this->outputDir; } @@ -241,6 +257,11 @@ class UploadFile return $this->maxSize; } + public function setInterlaced(bool $interlaced) /* : void */ + { + $this->interlaced = $interlaced; + } + /** * @param int $maxSize * From e228cb9f23ab48479e546dc1a176cc9ba729cc07 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 7 Dec 2016 20:23:04 +0100 Subject: [PATCH 09/12] Prepare const visibility --- Controller.php | 6 +++--- Models/UploadFile.php | 2 +- Models/UploadStatus.php | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Controller.php b/Controller.php index ac7d178..42758b7 100644 --- a/Controller.php +++ b/Controller.php @@ -48,7 +48,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_PATH = __DIR__; + /* public */ const MODULE_PATH = __DIR__; /** * Module version. @@ -56,7 +56,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_VERSION = '1.0.0'; + /* public */ const MODULE_VERSION = '1.0.0'; /** * Module name. @@ -64,7 +64,7 @@ class Controller extends ModuleAbstract implements WebInterface * @var string * @since 1.0.0 */ - const MODULE_NAME = 'Media'; + /* public */ const MODULE_NAME = 'Media'; /** * Providing. diff --git a/Models/UploadFile.php b/Models/UploadFile.php index a6a30f5..05db62c 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -31,7 +31,7 @@ use phpOMS\System\File\Local\Directory; */ class UploadFile { - const PATH_GENERATION_LIMIT = 1000; + /* public */ const PATH_GENERATION_LIMIT = 1000; /** * Image interlaced. diff --git a/Models/UploadStatus.php b/Models/UploadStatus.php index 8e7c10b..f3a09fd 100644 --- a/Models/UploadStatus.php +++ b/Models/UploadStatus.php @@ -30,14 +30,14 @@ use phpOMS\Datatypes\Enum; */ abstract class UploadStatus extends Enum { - const OK = 0; - const WRONG_PARAMETERS = -1; - const NOTHING_UPLOADED = -2; - const UPLOAD_SIZE = -3; - const UNKNOWN_ERROR = -4; - const CONFIG_SIZE = -5; - const WRONG_EXTENSION = -6; - const NOT_UPLOADED = -7; - const NOT_MOVABLE = -8; - const FAILED_HASHING = -9; + /* public */ const OK = 0; + /* public */ const WRONG_PARAMETERS = -1; + /* public */ const NOTHING_UPLOADED = -2; + /* public */ const UPLOAD_SIZE = -3; + /* public */ const UNKNOWN_ERROR = -4; + /* public */ const CONFIG_SIZE = -5; + /* public */ const WRONG_EXTENSION = -6; + /* public */ const NOT_UPLOADED = -7; + /* public */ const NOT_MOVABLE = -8; + /* public */ const FAILED_HASHING = -9; } From b9c1cc4857e00c0febf92161eab6103befe0013a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 7 Dec 2016 20:56:15 +0100 Subject: [PATCH 10/12] Increase php version requirement --- Admin/Activate.php | 2 +- Admin/Deactivate.php | 2 +- Admin/Install/Navigation.php | 2 +- Admin/Installer.php | 2 +- Admin/Uninstall.php | 2 +- Admin/Update.php | 2 +- Controller.php | 2 +- Models/Collection.php | 2 +- Models/CollectionMapper.php | 2 +- Models/FileStorageInterface.php | 2 +- Models/FileUploaderTrait.php | 2 +- Models/FtpFileStorage.php | 2 +- Models/LocalFileStorage.php | 2 +- Models/Media.php | 2 +- Models/MediaMapper.php | 2 +- Models/NullCollection.php | 2 +- Models/NullMedia.php | 2 +- Models/UploadFile.php | 2 +- Models/UploadStatus.php | 2 +- Theme/Backend/Lang/Navigation.en.lang.php | 2 +- Theme/Backend/Lang/api.en.lang.php | 2 +- Theme/Backend/Lang/en.lang.php | 2 +- Theme/Backend/media-create.tpl.php | 2 +- Theme/Backend/media-list.tpl.php | 2 +- Theme/Backend/media-single.tpl.php | 2 +- Theme/backend/Lang/Navigation.en.lang.php | 2 +- Theme/backend/Lang/api.en.lang.php | 2 +- Theme/backend/Lang/en.lang.php | 2 +- Theme/backend/media-create.tpl.php | 2 +- Theme/backend/media-list.tpl.php | 2 +- Theme/backend/media-single.tpl.php | 2 +- Views/MediaCreateView.php | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Admin/Activate.php b/Admin/Activate.php index eb10180..8ea223c 100644 --- a/Admin/Activate.php +++ b/Admin/Activate.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php index ea28897..2e17ea5 100644 --- a/Admin/Deactivate.php +++ b/Admin/Deactivate.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 87d05aa..8528511 100644 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Admin/Installer.php b/Admin/Installer.php index 75c4c0c..88cd8c8 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php index fd8ed1f..39dd419 100644 --- a/Admin/Uninstall.php +++ b/Admin/Uninstall.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Admin/Update.php b/Admin/Update.php index 4df8032..15a1a0c 100644 --- a/Admin/Update.php +++ b/Admin/Update.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Controller.php b/Controller.php index 42758b7..441f7a6 100644 --- a/Controller.php +++ b/Controller.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/Collection.php b/Models/Collection.php index aa2a546..e8e0034 100644 --- a/Models/Collection.php +++ b/Models/Collection.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index 4a273c3..8f5742f 100644 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/FileStorageInterface.php b/Models/FileStorageInterface.php index 6584837..501d9a0 100644 --- a/Models/FileStorageInterface.php +++ b/Models/FileStorageInterface.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/FileUploaderTrait.php b/Models/FileUploaderTrait.php index 03616e8..619a1f5 100644 --- a/Models/FileUploaderTrait.php +++ b/Models/FileUploaderTrait.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/FtpFileStorage.php b/Models/FtpFileStorage.php index 8c68a3e..30b4c97 100644 --- a/Models/FtpFileStorage.php +++ b/Models/FtpFileStorage.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/LocalFileStorage.php b/Models/LocalFileStorage.php index ec9c329..be4b83e 100644 --- a/Models/LocalFileStorage.php +++ b/Models/LocalFileStorage.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/Media.php b/Models/Media.php index 1666da0..768bd88 100644 --- a/Models/Media.php +++ b/Models/Media.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index 298d23a..71e6e7e 100644 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/NullCollection.php b/Models/NullCollection.php index 0e76639..8e769f7 100644 --- a/Models/NullCollection.php +++ b/Models/NullCollection.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/NullMedia.php b/Models/NullMedia.php index f75b531..00b7a2d 100644 --- a/Models/NullMedia.php +++ b/Models/NullMedia.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 05db62c..8b1cfdf 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Models/UploadStatus.php b/Models/UploadStatus.php index f3a09fd..16052f8 100644 --- a/Models/UploadStatus.php +++ b/Models/UploadStatus.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php index 309fcc7..ba3b048 100644 --- a/Theme/Backend/Lang/Navigation.en.lang.php +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/Lang/api.en.lang.php b/Theme/Backend/Lang/api.en.lang.php index d53f90f..f8e29de 100644 --- a/Theme/Backend/Lang/api.en.lang.php +++ b/Theme/Backend/Lang/api.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 4aa8cae..b773ca7 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/media-create.tpl.php b/Theme/Backend/media-create.tpl.php index d1be1b6..f99c0ab 100644 --- a/Theme/Backend/media-create.tpl.php +++ b/Theme/Backend/media-create.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/media-list.tpl.php b/Theme/Backend/media-list.tpl.php index 5a5774f..85158a7 100644 --- a/Theme/Backend/media-list.tpl.php +++ b/Theme/Backend/media-list.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index 1fe240e..39b12cd 100644 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/Navigation.en.lang.php b/Theme/backend/Lang/Navigation.en.lang.php index 309fcc7..ba3b048 100644 --- a/Theme/backend/Lang/Navigation.en.lang.php +++ b/Theme/backend/Lang/Navigation.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/api.en.lang.php b/Theme/backend/Lang/api.en.lang.php index d53f90f..f8e29de 100644 --- a/Theme/backend/Lang/api.en.lang.php +++ b/Theme/backend/Lang/api.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/en.lang.php b/Theme/backend/Lang/en.lang.php index 4aa8cae..b773ca7 100644 --- a/Theme/backend/Lang/en.lang.php +++ b/Theme/backend/Lang/en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/media-create.tpl.php b/Theme/backend/media-create.tpl.php index d1be1b6..f99c0ab 100644 --- a/Theme/backend/media-create.tpl.php +++ b/Theme/backend/media-create.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/media-list.tpl.php b/Theme/backend/media-list.tpl.php index 5a5774f..85158a7 100644 --- a/Theme/backend/media-list.tpl.php +++ b/Theme/backend/media-list.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/media-single.tpl.php b/Theme/backend/media-single.tpl.php index 1fe240e..39b12cd 100644 --- a/Theme/backend/media-single.tpl.php +++ b/Theme/backend/media-single.tpl.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Views/MediaCreateView.php b/Views/MediaCreateView.php index b945a52..b30ae3c 100644 --- a/Views/MediaCreateView.php +++ b/Views/MediaCreateView.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD From 470e6afc1acfbc649e9dd5bf78214d0382230c78 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 22 Jan 2017 21:08:46 +0100 Subject: [PATCH 11/12] Fixing json serialization and reporter --- Admin/Routes/Web/Api.php | 24 +++++++++++++++++++++++ Admin/Routes/Web/Backend.php | 18 ----------------- Controller.php | 16 +++++++++++++--- Models/UploadFile.php | 33 ++++++++++++++++++++++++++------ Theme/Backend/media-list.tpl.php | 2 +- Theme/backend/media-list.tpl.php | 2 +- 6 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 Admin/Routes/Web/Api.php diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..d9cc200 --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,24 @@ + [ + [ + 'dest' => '\Modules\Media\Controller:apiCollectionCreate', + 'verb' => RouteVerb::SET, + ], + ], + '^.*/api/media$' => [ + [ + 'dest' => '\Modules\Media\Controller:apiMediaUpload', + 'verb' => RouteVerb::SET, + ], + ], + '^.*/api/media/create.*$' => [ + [ + 'dest' => '\Modules\Media\Controller:apiMediaCreate', + 'verb' => RouteVerb::SET, + ], + ], +]; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 5c381b1..8931213 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -25,22 +25,4 @@ return [ 'verb' => RouteVerb::GET, ], ], - '^.*/api/media/collection.*$' => [ - [ - 'dest' => '\Modules\Media\Controller:apiCollectionCreate', - 'verb' => RouteVerb::SET, - ], - ], - '^.*/api/media$' => [ - [ - 'dest' => '\Modules\Media\Controller:apiMediaUpload', - 'verb' => RouteVerb::SET, - ], - ], - '^.*/api/media/create.*$' => [ - [ - 'dest' => '\Modules\Media\Controller:apiMediaCreate', - 'verb' => RouteVerb::SET, - ], - ], ]; diff --git a/Controller.php b/Controller.php index 441f7a6..26121bd 100644 --- a/Controller.php +++ b/Controller.php @@ -117,6 +117,9 @@ class Controller extends ModuleAbstract implements WebInterface $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000401001, $request, $response)); + $media = MediaMapper::getNewest(25); + $view->addData('media', $media); + return $view; } @@ -176,8 +179,13 @@ class Controller extends ModuleAbstract implements WebInterface { $uploads = $this->uploadFiles($request->getFiles(), $request->getAccount(), $request->getData('path') ?? '/Modules/Media/Files'); + $ids = []; + foreach($uploads as $file) { + $ids[] = $file->getId(); + } + $response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); - $response->set($request->__toString(), [['uploads' => $uploads, 'type' => 'UI']]); + $response->set($request->__toString(), [['uploads' => $ids, 'type' => 'UI']]); } /** @@ -244,7 +252,9 @@ class Controller extends ModuleAbstract implements WebInterface $mediaCreated = []; foreach ($status as $uFile) { - $mediaCreated[] = self::createDbEntry($uFile, $account); + if(!is_null($created = self::createDbEntry($uFile, $account))) { + $mediaCreated[] = $created; + } } return $mediaCreated; @@ -253,7 +263,7 @@ class Controller extends ModuleAbstract implements WebInterface public static function createDbEntry(array $status, int $account) { $media = null; - + if ($status['status'] === UploadStatus::OK) { $media = new Media(); $media->setPath(trim($status['path'], '/') . '/' . $status['filename']); diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 8b1cfdf..5a4fce7 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -141,6 +141,7 @@ class UploadFile } $split = explode('.', $f['name']); + $result[$key]['name'] = $split[0]; $extension = count($split) > 1 ? $split[count($split) - 1] : ''; $result[$key]['extension'] = $extension; @@ -181,18 +182,14 @@ class UploadFile return $result; } - if (!move_uploaded_file($f['tmp_name'], $path . '/' . $this->fileName)) { + if (!move_uploaded_file($f['tmp_name'], $dest = $path . '/' . $this->fileName)) { $result[$key]['status'] = UploadStatus::NOT_MOVABLE; return $result; } if($this->interlaced && in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) { - $img = fopen($f['tmp_name'], $path . '/' . $this->fileName); - flock($img, LOCK_EX); - imageinterlace($img, (int) $this->interlaced); - flock($img, LOCK_UN); - fclose($img); + $this->interlace($extension, $dest); } $result[$key]['path'] = $this->outputDir; @@ -201,6 +198,30 @@ class UploadFile return $result; } + private function interlace(string $extension, string $path) /* : void */ + { + + if($extension === 'png') { + $img = imagecreatefrompng($path); + } elseif($extension === 'jpg' || $extension === 'jpeg') { + $img = imagecreatefromjpeg($path); + } else { + $img = imagecreatefromgif($path); + } + + imageinterlace($img, (int) $this->interlaced); + + if($extension === 'png') { + imagepng($img, $path); + } elseif($extension === 'jpg' || $extension === 'jpeg') { + imagejpeg($img, $path); + } else { + imagegif($img, $path); + } + + imagedestroy($img); + } + /** * Find unique output path for batch of files * diff --git a/Theme/Backend/media-list.tpl.php b/Theme/Backend/media-list.tpl.php index 85158a7..a892adf 100644 --- a/Theme/Backend/media-list.tpl.php +++ b/Theme/Backend/media-list.tpl.php @@ -17,7 +17,7 @@ * @var \phpOMS\Views\View $this */ -$media = \Modules\Media\Models\MediaMapper::getNewest(25); +$media = $this->getData('media'); $footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response); $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig'); $footerView->setPages(count($media) / 25); diff --git a/Theme/backend/media-list.tpl.php b/Theme/backend/media-list.tpl.php index 85158a7..a892adf 100644 --- a/Theme/backend/media-list.tpl.php +++ b/Theme/backend/media-list.tpl.php @@ -17,7 +17,7 @@ * @var \phpOMS\Views\View $this */ -$media = \Modules\Media\Models\MediaMapper::getNewest(25); +$media = $this->getData('media'); $footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response); $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig'); $footerView->setPages(count($media) / 25); From 3a02ef07b775fcec2ffdc2e5ca2562e0d84aa83c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 25 Jan 2017 17:38:54 +0100 Subject: [PATCH 12/12] Strict type fixes --- Models/UploadFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 5a4fce7..fb24da6 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -173,7 +173,7 @@ class UploadFile } if (!is_dir($path)) { - Directory::create($path, '0655', true); + Directory::create($path, 0655, true); } if (!is_uploaded_file($f['tmp_name'])) {