mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-08 05:28:41 +00:00
Fixing json serialization and reporter
This commit is contained in:
parent
b9c1cc4857
commit
470e6afc1a
24
Admin/Routes/Web/Api.php
Normal file
24
Admin/Routes/Web/Api.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^.*/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,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
@ -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,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user