diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 4f56ceb..a9ec43a 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -44,11 +44,9 @@ use phpOMS\Localization\BaseStringL11n; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Html\Head; -use phpOMS\Model\Message\FormValidation; use phpOMS\Security\Guard; use phpOMS\System\File\FileUtils; use phpOMS\System\File\Local\Directory; @@ -531,6 +529,8 @@ final class ApiController extends Controller * * @return string * + * @throws \Exception + * * @since 1.0.0 */ public static function normalizeDbPath(string $path) : string @@ -957,6 +957,8 @@ final class ApiController extends Controller * * @api * + * @throws \Exception + * * @since 1.0.0 */ public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void @@ -1072,8 +1074,8 @@ final class ApiController extends Controller $media->id ) ) { - $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []); $response->header->status = RequestStatusCode::R_403; + $this->createInvalidReturnResponse($request, $response, $media); return; } @@ -1087,8 +1089,8 @@ final class ApiController extends Controller } } else { if (empty($data) || !isset($data['guard'])) { - $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []); $response->header->status = RequestStatusCode::R_403; + $this->createInvalidReturnResponse($request, $response, $media); } } @@ -1111,16 +1113,16 @@ final class ApiController extends Controller $media = $this->prepareEncryptedMedia($media, $request); if ($media->id === 0) { - $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Media', 'Media could not be exported. Please try again.', []); $response->header->status = RequestStatusCode::R_500; + $this->createInvalidReturnResponse($request, $response, $media); return; } } - if (!\is_file($media->getAbsolutePath())) { - $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Media', 'Media could not be exported. Please try again.', []); + if ($media->extension !== 'collection' && !\is_file($media->getAbsolutePath())) { $response->header->status = RequestStatusCode::R_500; + $this->createInvalidReturnResponse($request, $response, $media); return; } @@ -1227,11 +1229,15 @@ final class ApiController extends Controller case 'php': case 'js': case 'css': + case 'csv': case 'rs': case 'py': case 'r': $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/text_raw'); break; + case 'json': + $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/json_raw'); + break; case 'txt': case 'cfg': case 'log': @@ -1255,6 +1261,9 @@ final class ApiController extends Controller case 'mpeg': $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/video_raw'); break; + case 'collection': + $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/collection_raw'); + break; default: $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/default'); } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index b13849c..971fcbc 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -66,7 +66,7 @@ final class BackendController extends Controller $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); - $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); + $path = \str_replace('+', ' ', $request->getDataString('path') ?? '/'); $hasPermission = $this->app->accountManager->get($request->header->account) ->hasPermission( diff --git a/Models/Media.php b/Models/Media.php index 09db6be..0b0837d 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -380,7 +380,7 @@ class Media implements \JsonSerializable */ public function setPath(string $path) : void { - $this->path = \str_replace('\\', '/', $path); + $this->path = \strtr($path, '\\', '/'); } /** @@ -392,7 +392,7 @@ class Media implements \JsonSerializable */ public function setVirtualPath(string $path) : void { - $this->virtualPath = \str_replace('\\', '/', $path); + $this->virtualPath = \strtr($path, '\\', '/'); } /** diff --git a/Theme/Backend/Components/Media/audio_raw.tpl.php b/Theme/Backend/Components/Media/audio_raw.tpl.php index 6e6c27f..5870bfd 100755 --- a/Theme/Backend/Components/Media/audio_raw.tpl.php +++ b/Theme/Backend/Components/Media/audio_raw.tpl.php @@ -15,6 +15,7 @@ declare(strict_types=1); use phpOMS\Uri\UriFactory; ?> + diff --git a/Theme/Backend/Components/Media/collection_raw.tpl.php b/Theme/Backend/Components/Media/collection_raw.tpl.php new file mode 100644 index 0000000..6163b5a --- /dev/null +++ b/Theme/Backend/Components/Media/collection_raw.tpl.php @@ -0,0 +1,11 @@ + + + + + + + diff --git a/Theme/Backend/Components/Media/image_raw.tpl.php b/Theme/Backend/Components/Media/image_raw.tpl.php index ec5c88f..cc8eef9 100755 --- a/Theme/Backend/Components/Media/image_raw.tpl.php +++ b/Theme/Backend/Components/Media/image_raw.tpl.php @@ -15,6 +15,7 @@ declare(strict_types=1); use phpOMS\Uri\UriFactory; ?> + = $this->printHtml( $this->getFileContent(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()) -); ?> \ No newline at end of file +); ?> \ No newline at end of file diff --git a/Theme/Backend/Components/Media/video_raw.tpl.php b/Theme/Backend/Components/Media/video_raw.tpl.php index 65290ba..571670b 100755 --- a/Theme/Backend/Components/Media/video_raw.tpl.php +++ b/Theme/Backend/Components/Media/video_raw.tpl.php @@ -15,6 +15,7 @@ declare(strict_types=1); use phpOMS\Uri\UriFactory; ?> + diff --git a/Theme/Backend/Components/Upload/upload-list.tpl.php b/Theme/Backend/Components/Upload/upload-list.tpl.php index 017deed..9909802 100755 --- a/Theme/Backend/Components/Upload/upload-list.tpl.php +++ b/Theme/Backend/Components/Upload/upload-list.tpl.php @@ -69,7 +69,14 @@ use phpOMS\Uri\UriFactory; = $this->getHtml('ID', '0', '0'); ?> = $this->getHtml('Name', 'Media', 'Backend'); ?> - + "}]}]' + data-limit="0" + data-active="true" + data-form="= $this->form; ?>" + > diff --git a/Views/MediaView.php b/Views/MediaView.php index a7b5620..55082e9 100755 --- a/Views/MediaView.php +++ b/Views/MediaView.php @@ -45,7 +45,7 @@ class MediaView extends View { if (\is_file($media->getPath() . $sub) && ($path = \realpath($media->getPath() . $sub)) !== false - && ($path = \str_replace('\\', '/', $path)) !== false + && ($path = \strtr($path, '\\', '/')) !== false && StringUtils::startsWith($path, $media->getPath()) ) { return $media->getPath() . $sub; @@ -68,7 +68,7 @@ class MediaView extends View { if (\is_dir($media->getPath() . $sub) && ($path = \realpath($media->getPath() . $sub)) !== false - && ($path = \str_replace('\\', '/', $path)) !== false + && ($path = \strtr($path, '\\', '/')) !== false && StringUtils::startsWith($path, $media->getPath()) ) { return $media->getPath() . $sub; diff --git a/tests/Autoloader.php b/tests/Autoloader.php index 80a0a1e..d2d0080 100755 --- a/tests/Autoloader.php +++ b/tests/Autoloader.php @@ -71,14 +71,12 @@ final class Autoloader * * @return void * - * @throws AutoloadException Throws this exception if the class to autoload doesn't exist. This could also be related to a wrong namespace/file path correlation. - * * @since 1.0.0 */ public static function defaultAutoloader(string $class) : void { $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); foreach (self::$paths as $path) { $file = $path . $class . '.php';
= $this->printHtml( $this->getFileContent(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()) -); ?> \ No newline at end of file +); ?>