diff options
Diffstat (limited to 'controller')
-rw-r--r-- | controller/config.php | 81 | ||||
-rw-r--r-- | controller/configapicontroller.php | 76 | ||||
-rw-r--r-- | controller/configcontroller.php | 50 | ||||
-rw-r--r-- | controller/configpubliccontroller.php (renamed from controller/publicconfigcontroller.php) | 10 | ||||
-rw-r--r-- | controller/files.php | 2 | ||||
-rw-r--r-- | controller/publicpreviewcontroller.php | 2 |
6 files changed, 172 insertions, 49 deletions
diff --git a/controller/config.php b/controller/config.php new file mode 100644 index 00000000..4adaec18 --- /dev/null +++ b/controller/config.php @@ -0,0 +1,81 @@ +<?php +/** + * ownCloud - gallery + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Olivier Paroz <owncloud@interfasys.ch> + * + * @copyright Olivier Paroz 2015 + */ + +namespace OCA\Gallery\Controller; + +use OCP\ILogger; + +use OCP\AppFramework\Http; + +use OCA\Gallery\Service\ConfigService; +use OCA\Gallery\Service\PreviewService; + +/** + * Trait Config + * + * @package OCA\Gallery\Controller + */ +trait Config { + + /** + * @var ConfigService + */ + private $configService; + /** + * @var PreviewService + */ + private $previewService; + /** + * @var ILogger + */ + private $logger; + + /** + * @NoAdminRequired + * + * Returns an app configuration array + * + * @param bool $extraMediaTypes + * + * @return array <string,null|array> + */ + private function getConfig($extraMediaTypes = false) { + $features = $this->configService->getFeaturesList(); + + //$this->logger->debug("Features: {features}", ['features' => $features]); + + $nativeSvgSupport = $this->isNativeSvgActivated($features); + $mediaTypes = + $this->previewService->getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport); + + return ['features' => $features, 'mediatypes' => $mediaTypes]; + } + + /** + * Determines if the native SVG feature has been activated + * + * @param array $features + * + * @return bool + */ + private function isNativeSvgActivated($features) { + $nativeSvgSupport = false; + if (!empty($features) + && array_key_exists('native_svg', $features) + && $features['native_svg'] === 'yes' + ) { + $nativeSvgSupport = true; + } + + return $nativeSvgSupport; + } +} diff --git a/controller/configapicontroller.php b/controller/configapicontroller.php new file mode 100644 index 00000000..f81ce75e --- /dev/null +++ b/controller/configapicontroller.php @@ -0,0 +1,76 @@ +<?php +/** + * ownCloud - gallery + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Olivier Paroz <owncloud@interfasys.ch> + * + * @copyright Olivier Paroz 2015 + */ + +namespace OCA\Gallery\Controller; + +use OCP\IRequest; +use OCP\ILogger; + +use OCP\AppFramework\ApiController; +use OCP\AppFramework\Http; + +use OCA\Gallery\Service\ConfigService; +use OCA\Gallery\Service\PreviewService; + +/** + * Class ConfigApiController + * + * @package OCA\Gallery\Controller + */ +class ConfigApiController extends ApiController { + + use Config; + use JsonHttpError; + + /** + * Constructor + * + * @param string $appName + * @param IRequest $request + * @param ConfigService $configService + * @param PreviewService $previewService + * @param ILogger $logger + */ + public function __construct( + $appName, + IRequest $request, + ConfigService $configService, + PreviewService $previewService, + ILogger $logger + ) { + parent::__construct($appName, $request); + + $this->configService = $configService; + $this->previewService = $previewService; + $this->logger = $logger; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @CORS + * + * Returns an app configuration array + * + * @param bool $extramediatypes + * + * @return array <string,null|array> + */ + public function get($extramediatypes = false) { + try { + return $this->getConfig($extramediatypes); + } catch (\Exception $exception) { + return $this->error($exception); + } + } + +} diff --git a/controller/configcontroller.php b/controller/configcontroller.php index 774f1b7e..00040395 100644 --- a/controller/configcontroller.php +++ b/controller/configcontroller.php @@ -28,22 +28,10 @@ use OCA\Gallery\Service\PreviewService; */ class ConfigController extends Controller { + use Config; use JsonHttpError; /** - * @var ConfigService - */ - private $configService; - /** - * @var PreviewService - */ - private $previewService; - /** - * @var ILogger - */ - private $logger; - - /** * Constructor * * @param string $appName @@ -71,38 +59,16 @@ class ConfigController extends Controller { * * Returns an app configuration array * - * @param bool $slideshow + * @param bool $extramediatypes * - * @return array<string,null|array> + * @return array <string,null|array> */ - public function getConfig($slideshow = false) { - $features = $this->configService->getFeaturesList(); - - //$this->logger->debug("Features: {features}", ['features' => $features]); - - $nativeSvgSupport = $this->isNativeSvgActivated($features); - $mediaTypes = $this->previewService->getSupportedMediaTypes($slideshow, $nativeSvgSupport); - - return ['features' => $features, 'mediatypes' => $mediaTypes]; - } - - /** - * Determines if the native SVG feature has been activated - * - * @param array $features - * - * @return bool - */ - private function isNativeSvgActivated($features) { - $nativeSvgSupport = false; - if (!empty($features) - && array_key_exists('native_svg', $features) - && $features['native_svg'] === 'yes' - ) { - $nativeSvgSupport = true; + public function get($extramediatypes = false) { + try { + return $this->getConfig($extramediatypes); + } catch (\Exception $exception) { + return $this->error($exception); } - - return $nativeSvgSupport; } } diff --git a/controller/publicconfigcontroller.php b/controller/configpubliccontroller.php index ce2d70d9..aa7bff43 100644 --- a/controller/publicconfigcontroller.php +++ b/controller/configpubliccontroller.php @@ -13,14 +13,14 @@ namespace OCA\Gallery\Controller; /** - * Class PublicConfigController + * Class ConfigPublicController * * Note: Type casting only works if the "@param" parameters are also included in this class as * their not yet inherited * * @package OCA\Gallery\Controller */ -class PublicConfigController extends ConfigController { +class ConfigPublicController extends ConfigController { /** * @PublicPage @@ -29,10 +29,10 @@ class PublicConfigController extends ConfigController { * * @inheritDoc * - * @param bool $slideshow + * @param bool $extramediatypes */ - public function getConfig($slideshow = false) { - return parent::getConfig($slideshow); + public function get($extramediatypes = false) { + return parent::get($extramediatypes); } } diff --git a/controller/files.php b/controller/files.php index 4ed75a5c..30615c0e 100644 --- a/controller/files.php +++ b/controller/files.php @@ -68,7 +68,7 @@ trait Files { * * @return array <string,array<string,string|int>>|Http\JSONResponse */ - public function getFiles($location, $features, $etag, $mediatypes) { + private function getFiles($location, $features, $etag, $mediatypes) { $files = []; /** @var Folder $folderNode */ list($folderPathFromRoot, $folderNode, $locationHasChanged) = diff --git a/controller/publicpreviewcontroller.php b/controller/publicpreviewcontroller.php index 18275e9f..d7e83d56 100644 --- a/controller/publicpreviewcontroller.php +++ b/controller/publicpreviewcontroller.php @@ -35,7 +35,7 @@ class PublicPreviewController extends PreviewController { * * @param string $ids the ID of the files of which we need thumbnail previews of * @param bool $square - * @param bool $scale + * @param float $scale */ public function getThumbnails($ids, $square, $scale) { return parent::getThumbnails($ids, $square, $scale); |