@@ -40,73 +40,73 @@ |
||
| 40 | 40 | |
| 41 | 41 | class JsController extends Controller { |
| 42 | 42 | |
| 43 | - /** @var IAppData */ |
|
| 44 | - protected $appData; |
|
| 43 | + /** @var IAppData */ |
|
| 44 | + protected $appData; |
|
| 45 | 45 | |
| 46 | - /** @var ITimeFactory */ |
|
| 47 | - protected $timeFactory; |
|
| 46 | + /** @var ITimeFactory */ |
|
| 47 | + protected $timeFactory; |
|
| 48 | 48 | |
| 49 | - public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 50 | - parent::__construct($appName, $request); |
|
| 49 | + public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 50 | + parent::__construct($appName, $request); |
|
| 51 | 51 | |
| 52 | - $this->appData = $appDataFactory->get('js'); |
|
| 53 | - $this->timeFactory = $timeFactory; |
|
| 54 | - } |
|
| 52 | + $this->appData = $appDataFactory->get('js'); |
|
| 53 | + $this->timeFactory = $timeFactory; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @PublicPage |
|
| 58 | - * @NoCSRFRequired |
|
| 59 | - * |
|
| 60 | - * @param string $fileName js filename with extension |
|
| 61 | - * @param string $appName js folder name |
|
| 62 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 63 | - */ |
|
| 64 | - public function getJs(string $fileName, string $appName): Response { |
|
| 65 | - try { |
|
| 66 | - $folder = $this->appData->getFolder($appName); |
|
| 67 | - $gzip = false; |
|
| 68 | - $file = $this->getFile($folder, $fileName, $gzip); |
|
| 69 | - } catch(NotFoundException $e) { |
|
| 70 | - return new NotFoundResponse(); |
|
| 71 | - } |
|
| 56 | + /** |
|
| 57 | + * @PublicPage |
|
| 58 | + * @NoCSRFRequired |
|
| 59 | + * |
|
| 60 | + * @param string $fileName js filename with extension |
|
| 61 | + * @param string $appName js folder name |
|
| 62 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 63 | + */ |
|
| 64 | + public function getJs(string $fileName, string $appName): Response { |
|
| 65 | + try { |
|
| 66 | + $folder = $this->appData->getFolder($appName); |
|
| 67 | + $gzip = false; |
|
| 68 | + $file = $this->getFile($folder, $fileName, $gzip); |
|
| 69 | + } catch(NotFoundException $e) { |
|
| 70 | + return new NotFoundResponse(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
| 74 | - if ($gzip) { |
|
| 75 | - $response->addHeader('Content-Encoding', 'gzip'); |
|
| 76 | - } |
|
| 73 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
| 74 | + if ($gzip) { |
|
| 75 | + $response->addHeader('Content-Encoding', 'gzip'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - $ttl = 31536000; |
|
| 79 | - $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable'); |
|
| 78 | + $ttl = 31536000; |
|
| 79 | + $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable'); |
|
| 80 | 80 | |
| 81 | - $expires = new \DateTime(); |
|
| 82 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 83 | - $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
| 84 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 85 | - $response->addHeader('Pragma', 'cache'); |
|
| 86 | - return $response; |
|
| 87 | - } |
|
| 81 | + $expires = new \DateTime(); |
|
| 82 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 83 | + $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
| 84 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 85 | + $response->addHeader('Pragma', 'cache'); |
|
| 86 | + return $response; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param ISimpleFolder $folder |
|
| 91 | - * @param string $fileName |
|
| 92 | - * @param bool $gzip is set to true if we use the gzip file |
|
| 93 | - * @return ISimpleFile |
|
| 94 | - * |
|
| 95 | - * @throws NotFoundException |
|
| 96 | - */ |
|
| 97 | - private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { |
|
| 98 | - $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 89 | + /** |
|
| 90 | + * @param ISimpleFolder $folder |
|
| 91 | + * @param string $fileName |
|
| 92 | + * @param bool $gzip is set to true if we use the gzip file |
|
| 93 | + * @return ISimpleFile |
|
| 94 | + * |
|
| 95 | + * @throws NotFoundException |
|
| 96 | + */ |
|
| 97 | + private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { |
|
| 98 | + $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 99 | 99 | |
| 100 | - if (strpos($encoding, 'gzip') !== false) { |
|
| 101 | - try { |
|
| 102 | - $gzip = true; |
|
| 103 | - return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 104 | - } catch (NotFoundException $e) { |
|
| 105 | - // continue |
|
| 106 | - } |
|
| 107 | - } |
|
| 100 | + if (strpos($encoding, 'gzip') !== false) { |
|
| 101 | + try { |
|
| 102 | + $gzip = true; |
|
| 103 | + return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 104 | + } catch (NotFoundException $e) { |
|
| 105 | + // continue |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $gzip = false; |
|
| 110 | - return $folder->getFile($fileName); |
|
| 111 | - } |
|
| 109 | + $gzip = false; |
|
| 110 | + return $folder->getFile($fileName); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -34,103 +34,103 @@ |
||
| 34 | 34 | |
| 35 | 35 | class SvgController extends Controller { |
| 36 | 36 | |
| 37 | - /** @var string */ |
|
| 38 | - protected $serverRoot; |
|
| 39 | - |
|
| 40 | - /** @var ITimeFactory */ |
|
| 41 | - protected $timeFactory; |
|
| 42 | - |
|
| 43 | - public function __construct(string $appName, |
|
| 44 | - IRequest $request, |
|
| 45 | - ITimeFactory $timeFactory) { |
|
| 46 | - parent::__construct($appName, $request); |
|
| 47 | - |
|
| 48 | - $this->serverRoot = \OC::$SERVERROOT; |
|
| 49 | - $this->timeFactory = $timeFactory; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @NoAdminRequired |
|
| 54 | - * @NoCSRFRequired |
|
| 55 | - * |
|
| 56 | - * Generate svg from filename with the requested color |
|
| 57 | - * |
|
| 58 | - * @param string $folder |
|
| 59 | - * @param string $fileName |
|
| 60 | - * @param string $color |
|
| 61 | - * @return DataDisplayResponse|NotFoundException |
|
| 62 | - */ |
|
| 63 | - public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
| 64 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
| 65 | - return $this->getSvg($path, $color); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @NoAdminRequired |
|
| 70 | - * @NoCSRFRequired |
|
| 71 | - * |
|
| 72 | - * Generate svg from filename with the requested color |
|
| 73 | - * |
|
| 74 | - * @param string $app |
|
| 75 | - * @param string $fileName |
|
| 76 | - * @param string $color |
|
| 77 | - * @return DataDisplayResponse|NotFoundException |
|
| 78 | - */ |
|
| 79 | - public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
| 80 | - |
|
| 81 | - if ($app === 'settings') { |
|
| 82 | - $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
| 83 | - return $this->getSvg($path, $color); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $appPath = \OC_App::getAppWebPath($app); |
|
| 87 | - if (!$appPath) { |
|
| 88 | - return new NotFoundResponse(); |
|
| 89 | - } |
|
| 90 | - $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
| 91 | - return $this->getSvg($path, $color); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Generate svg from filename with the requested color |
|
| 97 | - * |
|
| 98 | - * @param string $path |
|
| 99 | - * @param string $color |
|
| 100 | - * @return DataDisplayResponse|NotFoundException |
|
| 101 | - */ |
|
| 102 | - private function getSvg(string $path, string $color) { |
|
| 103 | - if (!file_exists($path)) { |
|
| 104 | - return new NotFoundResponse(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $svg = file_get_contents($path); |
|
| 108 | - |
|
| 109 | - if (is_null($svg)) { |
|
| 110 | - return new NotFoundResponse(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // add fill (fill is not present on black elements) |
|
| 114 | - $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#])+)\/>/mi'; |
|
| 115 | - |
|
| 116 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
| 117 | - |
|
| 118 | - // replace any fill or stroke colors |
|
| 119 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
| 120 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
| 121 | - |
|
| 122 | - $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 123 | - |
|
| 124 | - // Set cache control |
|
| 125 | - $ttl = 31536000; |
|
| 126 | - $response->cacheFor($ttl); |
|
| 127 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
| 128 | - $expires = new \DateTime(); |
|
| 129 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 130 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 131 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 132 | - $response->addHeader('Pragma', 'cache'); |
|
| 133 | - |
|
| 134 | - return $response; |
|
| 135 | - } |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $serverRoot; |
|
| 39 | + |
|
| 40 | + /** @var ITimeFactory */ |
|
| 41 | + protected $timeFactory; |
|
| 42 | + |
|
| 43 | + public function __construct(string $appName, |
|
| 44 | + IRequest $request, |
|
| 45 | + ITimeFactory $timeFactory) { |
|
| 46 | + parent::__construct($appName, $request); |
|
| 47 | + |
|
| 48 | + $this->serverRoot = \OC::$SERVERROOT; |
|
| 49 | + $this->timeFactory = $timeFactory; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @NoAdminRequired |
|
| 54 | + * @NoCSRFRequired |
|
| 55 | + * |
|
| 56 | + * Generate svg from filename with the requested color |
|
| 57 | + * |
|
| 58 | + * @param string $folder |
|
| 59 | + * @param string $fileName |
|
| 60 | + * @param string $color |
|
| 61 | + * @return DataDisplayResponse|NotFoundException |
|
| 62 | + */ |
|
| 63 | + public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
| 64 | + $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
| 65 | + return $this->getSvg($path, $color); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @NoAdminRequired |
|
| 70 | + * @NoCSRFRequired |
|
| 71 | + * |
|
| 72 | + * Generate svg from filename with the requested color |
|
| 73 | + * |
|
| 74 | + * @param string $app |
|
| 75 | + * @param string $fileName |
|
| 76 | + * @param string $color |
|
| 77 | + * @return DataDisplayResponse|NotFoundException |
|
| 78 | + */ |
|
| 79 | + public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
| 80 | + |
|
| 81 | + if ($app === 'settings') { |
|
| 82 | + $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
| 83 | + return $this->getSvg($path, $color); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $appPath = \OC_App::getAppWebPath($app); |
|
| 87 | + if (!$appPath) { |
|
| 88 | + return new NotFoundResponse(); |
|
| 89 | + } |
|
| 90 | + $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
| 91 | + return $this->getSvg($path, $color); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Generate svg from filename with the requested color |
|
| 97 | + * |
|
| 98 | + * @param string $path |
|
| 99 | + * @param string $color |
|
| 100 | + * @return DataDisplayResponse|NotFoundException |
|
| 101 | + */ |
|
| 102 | + private function getSvg(string $path, string $color) { |
|
| 103 | + if (!file_exists($path)) { |
|
| 104 | + return new NotFoundResponse(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $svg = file_get_contents($path); |
|
| 108 | + |
|
| 109 | + if (is_null($svg)) { |
|
| 110 | + return new NotFoundResponse(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // add fill (fill is not present on black elements) |
|
| 114 | + $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#])+)\/>/mi'; |
|
| 115 | + |
|
| 116 | + $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
| 117 | + |
|
| 118 | + // replace any fill or stroke colors |
|
| 119 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
| 120 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
| 121 | + |
|
| 122 | + $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
| 123 | + |
|
| 124 | + // Set cache control |
|
| 125 | + $ttl = 31536000; |
|
| 126 | + $response->cacheFor($ttl); |
|
| 127 | + $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
| 128 | + $expires = new \DateTime(); |
|
| 129 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 130 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 131 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 132 | + $response->addHeader('Pragma', 'cache'); |
|
| 133 | + |
|
| 134 | + return $response; |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare (strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2018, John Molakvoæ ([email protected]) |
| 5 | 5 | * |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return DataDisplayResponse|NotFoundException |
| 62 | 62 | */ |
| 63 | 63 | public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
| 64 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
| 64 | + $path = $this->serverRoot."/core/img/$folder/$fileName.svg"; |
|
| 65 | 65 | return $this->getSvg($path, $color); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
| 80 | 80 | |
| 81 | 81 | if ($app === 'settings') { |
| 82 | - $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
| 82 | + $path = $this->serverRoot."/settings/img/$fileName.svg"; |
|
| 83 | 83 | return $this->getSvg($path, $color); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if (!$appPath) { |
| 88 | 88 | return new NotFoundResponse(); |
| 89 | 89 | } |
| 90 | - $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
| 90 | + $path = $this->serverRoot.$appPath."/img/$fileName.svg"; |
|
| 91 | 91 | return $this->getSvg($path, $color); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -113,21 +113,21 @@ discard block |
||
| 113 | 113 | // add fill (fill is not present on black elements) |
| 114 | 114 | $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#])+)\/>/mi'; |
| 115 | 115 | |
| 116 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
| 116 | + $svg = preg_replace($fillRe, '<$1 fill="#'.$color.'"/>', $svg); |
|
| 117 | 117 | |
| 118 | 118 | // replace any fill or stroke colors |
| 119 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
| 120 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
| 119 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#'.$color.'"', $svg); |
|
| 120 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#'.$color.'"', $svg); |
|
| 121 | 121 | |
| 122 | 122 | $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
| 123 | 123 | |
| 124 | 124 | // Set cache control |
| 125 | 125 | $ttl = 31536000; |
| 126 | 126 | $response->cacheFor($ttl); |
| 127 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
| 127 | + $response->addHeader('Content-Disposition', 'inline; filename="'.$fileName.'.svg"'); |
|
| 128 | 128 | $expires = new \DateTime(); |
| 129 | 129 | $expires->setTimestamp($this->timeFactory->getTime()); |
| 130 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 130 | + $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
| 131 | 131 | $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
| 132 | 132 | $response->addHeader('Pragma', 'cache'); |
| 133 | 133 | |
@@ -36,50 +36,50 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $application = new Application(); |
| 38 | 38 | $application->registerRoutes($this, [ |
| 39 | - 'routes' => [ |
|
| 40 | - ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
| 41 | - ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
| 42 | - ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
| 43 | - ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
| 44 | - ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
| 45 | - ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
| 46 | - ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
| 47 | - ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
| 48 | - ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
| 49 | - ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
| 50 | - ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
| 51 | - ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
| 52 | - ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
| 53 | - ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
| 54 | - ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
| 55 | - ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
| 56 | - ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
| 57 | - ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
| 58 | - ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
| 59 | - ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
| 60 | - ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
| 61 | - ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
| 62 | - ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
| 63 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
| 64 | - ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 65 | - ['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 66 | - ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 67 | - ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
| 68 | - ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
| 69 | - ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
| 70 | - ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
| 71 | - ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
| 72 | - ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
| 73 | - ], |
|
| 74 | - 'ocs' => [ |
|
| 75 | - ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
| 76 | - ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
| 77 | - ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
| 78 | - ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
| 79 | - ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
| 80 | - ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
| 81 | - ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
| 82 | - ], |
|
| 39 | + 'routes' => [ |
|
| 40 | + ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
| 41 | + ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
| 42 | + ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
| 43 | + ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
| 44 | + ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
| 45 | + ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
| 46 | + ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
| 47 | + ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
| 48 | + ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
| 49 | + ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
| 50 | + ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
| 51 | + ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
| 52 | + ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
| 53 | + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
| 54 | + ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
| 55 | + ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
| 56 | + ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
| 57 | + ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
| 58 | + ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
| 59 | + ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
| 60 | + ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
| 61 | + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
| 62 | + ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
| 63 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
| 64 | + ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 65 | + ['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 66 | + ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'], |
|
| 67 | + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
| 68 | + ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
| 69 | + ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
| 70 | + ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
| 71 | + ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
| 72 | + ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
| 73 | + ], |
|
| 74 | + 'ocs' => [ |
|
| 75 | + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
| 76 | + ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
| 77 | + ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
| 78 | + ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
| 79 | + ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
| 80 | + ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
| 81 | + ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
| 82 | + ], |
|
| 83 | 83 | ]); |
| 84 | 84 | |
| 85 | 85 | // Post installation check |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | // Core ajax actions |
| 89 | 89 | // Routing |
| 90 | 90 | $this->create('core_ajax_update', '/core/ajax/update.php') |
| 91 | - ->actionInclude('core/ajax/update.php'); |
|
| 91 | + ->actionInclude('core/ajax/update.php'); |
|
| 92 | 92 | |
| 93 | 93 | // File routes |
| 94 | 94 | $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) { |
| 95 | - $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
| 96 | - $app->dispatch('ViewController', 'index'); |
|
| 95 | + $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
| 96 | + $app->dispatch('ViewController', 'index'); |
|
| 97 | 97 | }); |
| 98 | 98 | |
| 99 | 99 | // Call routes |
@@ -102,52 +102,52 @@ discard block |
||
| 102 | 102 | * @suppress PhanUndeclaredClassMethod |
| 103 | 103 | */ |
| 104 | 104 | $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) { |
| 105 | - if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
| 106 | - $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
| 107 | - $app->dispatch('PageController', 'index'); |
|
| 108 | - } else { |
|
| 109 | - throw new \OC\HintException('App spreed is not enabled'); |
|
| 110 | - } |
|
| 105 | + if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
| 106 | + $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
| 107 | + $app->dispatch('PageController', 'index'); |
|
| 108 | + } else { |
|
| 109 | + throw new \OC\HintException('App spreed is not enabled'); |
|
| 110 | + } |
|
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | 113 | // Sharing routes |
| 114 | 114 | $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) { |
| 115 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 116 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 117 | - $app->dispatch('ShareController', 'showShare'); |
|
| 118 | - } else { |
|
| 119 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
| 120 | - } |
|
| 115 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 116 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 117 | + $app->dispatch('ShareController', 'showShare'); |
|
| 118 | + } else { |
|
| 119 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
| 120 | + } |
|
| 121 | 121 | }); |
| 122 | 122 | $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate/{redirect}')->post()->action(function($urlParams) { |
| 123 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 124 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 125 | - $app->dispatch('ShareController', 'authenticate'); |
|
| 126 | - } else { |
|
| 127 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
| 128 | - } |
|
| 123 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 124 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 125 | + $app->dispatch('ShareController', 'authenticate'); |
|
| 126 | + } else { |
|
| 127 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
| 128 | + } |
|
| 129 | 129 | }); |
| 130 | 130 | $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate/{redirect}')->get()->action(function($urlParams) { |
| 131 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 132 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 133 | - $app->dispatch('ShareController', 'showAuthenticate'); |
|
| 134 | - } else { |
|
| 135 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
| 136 | - } |
|
| 131 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 132 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 133 | + $app->dispatch('ShareController', 'showAuthenticate'); |
|
| 134 | + } else { |
|
| 135 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
| 136 | + } |
|
| 137 | 137 | }); |
| 138 | 138 | $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) { |
| 139 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 140 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 141 | - $app->dispatch('ShareController', 'downloadShare'); |
|
| 142 | - } else { |
|
| 143 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
| 144 | - } |
|
| 139 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 140 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 141 | + $app->dispatch('ShareController', 'downloadShare'); |
|
| 142 | + } else { |
|
| 143 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
| 144 | + } |
|
| 145 | 145 | }); |
| 146 | 146 | $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) { |
| 147 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 148 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 149 | - $app->dispatch('PublicPreviewController', 'directLink'); |
|
| 150 | - } else { |
|
| 151 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
| 152 | - } |
|
| 147 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
| 148 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
| 149 | + $app->dispatch('PublicPreviewController', 'directLink'); |
|
| 150 | + } else { |
|
| 151 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
| 152 | + } |
|
| 153 | 153 | }); |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | <meta charset="utf-8"> |
| 5 | 5 | <title> |
| 6 | 6 | <?php |
| 7 | - p(!empty($_['application'])?$_['application'].' - ':''); |
|
| 7 | + p(!empty($_['application']) ? $_['application'].' - ' : ''); |
|
| 8 | 8 | p($theme->getTitle()); |
| 9 | 9 | ?> |
| 10 | 10 | </title> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | <meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>"> |
| 15 | 15 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 16 | 16 | <meta name="apple-mobile-web-app-status-bar-style" content="black"> |
| 17 | - <meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>"> |
|
| 17 | + <meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>"> |
|
| 18 | 18 | <meta name="mobile-web-app-capable" content="yes"> |
| 19 | 19 | <meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>"> |
| 20 | 20 | <link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>"> |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | <?php emit_script_loading_tags($_); ?> |
| 26 | 26 | <?php print_unescaped($_['headers']); ?> |
| 27 | 27 | </head> |
| 28 | - <body id="<?php p($_['bodyid']);?>"> |
|
| 28 | + <body id="<?php p($_['bodyid']); ?>"> |
|
| 29 | 29 | <?php include 'layout.noscript.warning.php'; ?> |
| 30 | 30 | |
| 31 | 31 | <a href="#app-content" class="button primary skip-navigation skip-content"><?php p($l->t('Skip to main content')); ?></a> |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | id="nextcloud"> |
| 41 | 41 | <div class="logo logo-icon"> |
| 42 | 42 | <h1 class="hidden-visually"> |
| 43 | - <?php p($theme->getName()); ?> <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?> |
|
| 43 | + <?php p($theme->getName()); ?> <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?> |
|
| 44 | 44 | </h1> |
| 45 | 45 | </div> |
| 46 | 46 | </a> |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | <?php if ($_['themingInvertMenu']) { ?> |
| 56 | 56 | <defs><filter id="invertMenuMain-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs> |
| 57 | 57 | <?php } ?> |
| 58 | - <image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon" /> |
|
| 58 | + <image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon" /> |
|
| 59 | 59 | </svg> |
| 60 | 60 | <div class="icon-loading-small-dark" |
| 61 | 61 | style="display:none;"></div> |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | <div id="navigation" style="display: none;" aria-label="<?php p($l->t('More apps menu')); ?>"> |
| 79 | 79 | <div id="apps"> |
| 80 | 80 | <ul> |
| 81 | - <?php foreach($_['navigation'] as $entry): ?> |
|
| 81 | + <?php foreach ($_['navigation'] as $entry): ?> |
|
| 82 | 82 | <li data-id="<?php p($entry['id']); ?>"> |
| 83 | 83 | <a href="<?php print_unescaped($entry['href']); ?>" |
| 84 | - <?php if( $entry['active'] ): ?> class="active"<?php endif; ?> |
|
| 84 | + <?php if ($entry['active']): ?> class="active"<?php endif; ?> |
|
| 85 | 85 | aria-label="<?php p($entry['name']); ?>"> |
| 86 | 86 | <svg width="16" height="16" viewBox="0 0 16 16" alt=""> |
| 87 | 87 | <defs><filter id="invertMenuMore-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs> |
| 88 | - <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image> |
|
| 88 | + <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon"></image> |
|
| 89 | 89 | </svg> |
| 90 | 90 | <div class="icon-loading-small" style="display:none;"></div> |
| 91 | 91 | <span><?php p($entry['name']); ?></span> |
@@ -102,43 +102,43 @@ discard block |
||
| 102 | 102 | <div class="header-right"> |
| 103 | 103 | <form class="searchbox" action="#" method="post" role="search" novalidate> |
| 104 | 104 | <label for="searchbox" class="hidden-visually"> |
| 105 | - <?php p($l->t('Search'));?> |
|
| 105 | + <?php p($l->t('Search')); ?> |
|
| 106 | 106 | </label> |
| 107 | 107 | <input id="searchbox" type="search" name="query" |
| 108 | 108 | value="" required class="hidden icon-search-white" |
| 109 | 109 | autocomplete="off"> |
| 110 | - <button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search'));?></span></button> |
|
| 110 | + <button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search')); ?></span></button> |
|
| 111 | 111 | </form> |
| 112 | 112 | <div id="contactsmenu"> |
| 113 | 113 | <div class="icon-contacts menutoggle" tabindex="0" role="button" |
| 114 | 114 | aria-haspopup="true" aria-controls="contactsmenu-menu" aria-expanded="false"> |
| 115 | - <span class="hidden-visually"><?php p($l->t('Contacts'));?> |
|
| 115 | + <span class="hidden-visually"><?php p($l->t('Contacts')); ?> |
|
| 116 | 116 | </div> |
| 117 | 117 | <div id="contactsmenu-menu" class="menu" |
| 118 | - aria-label="<?php p($l->t('Contacts menu'));?>"></div> |
|
| 118 | + aria-label="<?php p($l->t('Contacts menu')); ?>"></div> |
|
| 119 | 119 | </div> |
| 120 | 120 | <div id="settings"> |
| 121 | 121 | <div id="expand" tabindex="0" role="button" class="menutoggle" |
| 122 | - aria-label="<?php p($l->t('Settings'));?>" |
|
| 122 | + aria-label="<?php p($l->t('Settings')); ?>" |
|
| 123 | 123 | aria-haspopup="true" aria-controls="expanddiv" aria-expanded="false"> |
| 124 | 124 | <div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>"> |
| 125 | 125 | <?php if ($_['userAvatarSet']): ?> |
| 126 | 126 | <img alt="" width="32" height="32" |
| 127 | - src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>" |
|
| 128 | - srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x" |
|
| 127 | + src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>" |
|
| 128 | + srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x" |
|
| 129 | 129 | > |
| 130 | 130 | <?php endif; ?> |
| 131 | 131 | </div> |
| 132 | 132 | <div id="expandDisplayName" class="icon-settings-white"></div> |
| 133 | 133 | </div> |
| 134 | 134 | <nav id="expanddiv" style="display:none;" |
| 135 | - aria-label="<?php p($l->t('Settings menu'));?>"> |
|
| 135 | + aria-label="<?php p($l->t('Settings menu')); ?>"> |
|
| 136 | 136 | <ul> |
| 137 | - <?php foreach($_['settingsnavigation'] as $entry):?> |
|
| 137 | + <?php foreach ($_['settingsnavigation'] as $entry):?> |
|
| 138 | 138 | <li data-id="<?php p($entry['id']); ?>"> |
| 139 | 139 | <a href="<?php print_unescaped($entry['href']); ?>" |
| 140 | - <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>> |
|
| 141 | - <img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"> |
|
| 140 | + <?php if ($entry["active"]): ?> class="active"<?php endif; ?>> |
|
| 141 | + <img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"> |
|
| 142 | 142 | <?php p($entry['name']) ?> |
| 143 | 143 | </a> |
| 144 | 144 | </li> |
@@ -46,335 +46,335 @@ |
||
| 46 | 46 | |
| 47 | 47 | class SCSSCacher { |
| 48 | 48 | |
| 49 | - /** @var ILogger */ |
|
| 50 | - protected $logger; |
|
| 51 | - |
|
| 52 | - /** @var IAppData */ |
|
| 53 | - protected $appData; |
|
| 54 | - |
|
| 55 | - /** @var IURLGenerator */ |
|
| 56 | - protected $urlGenerator; |
|
| 57 | - |
|
| 58 | - /** @var IConfig */ |
|
| 59 | - protected $config; |
|
| 60 | - |
|
| 61 | - /** @var \OC_Defaults */ |
|
| 62 | - private $defaults; |
|
| 63 | - |
|
| 64 | - /** @var string */ |
|
| 65 | - protected $serverRoot; |
|
| 66 | - |
|
| 67 | - /** @var ICache */ |
|
| 68 | - protected $depsCache; |
|
| 69 | - |
|
| 70 | - /** @var null|string */ |
|
| 71 | - private $injectedVariables; |
|
| 72 | - |
|
| 73 | - /** @var ICacheFactory */ |
|
| 74 | - private $cacheFactory; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param ILogger $logger |
|
| 78 | - * @param Factory $appDataFactory |
|
| 79 | - * @param IURLGenerator $urlGenerator |
|
| 80 | - * @param IConfig $config |
|
| 81 | - * @param \OC_Defaults $defaults |
|
| 82 | - * @param string $serverRoot |
|
| 83 | - * @param ICacheFactory $cacheFactory |
|
| 84 | - */ |
|
| 85 | - public function __construct(ILogger $logger, |
|
| 86 | - Factory $appDataFactory, |
|
| 87 | - IURLGenerator $urlGenerator, |
|
| 88 | - IConfig $config, |
|
| 89 | - \OC_Defaults $defaults, |
|
| 90 | - $serverRoot, |
|
| 91 | - ICacheFactory $cacheFactory) { |
|
| 92 | - $this->logger = $logger; |
|
| 93 | - $this->appData = $appDataFactory->get('css'); |
|
| 94 | - $this->urlGenerator = $urlGenerator; |
|
| 95 | - $this->config = $config; |
|
| 96 | - $this->defaults = $defaults; |
|
| 97 | - $this->serverRoot = $serverRoot; |
|
| 98 | - $this->cacheFactory = $cacheFactory; |
|
| 99 | - $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Process the caching process if needed |
|
| 104 | - * |
|
| 105 | - * @param string $root Root path to the nextcloud installation |
|
| 106 | - * @param string $file |
|
| 107 | - * @param string $app The app name |
|
| 108 | - * @return boolean |
|
| 109 | - * @throws NotPermittedException |
|
| 110 | - */ |
|
| 111 | - public function process(string $root, string $file, string $app): bool { |
|
| 112 | - $path = explode('/', $root . '/' . $file); |
|
| 113 | - |
|
| 114 | - $fileNameSCSS = array_pop($path); |
|
| 115 | - $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
|
| 116 | - |
|
| 117 | - $path = implode('/', $path); |
|
| 118 | - $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 119 | - |
|
| 120 | - try { |
|
| 121 | - $folder = $this->appData->getFolder($app); |
|
| 122 | - } catch(NotFoundException $e) { |
|
| 123 | - // creating css appdata folder |
|
| 124 | - $folder = $this->appData->newFolder($app); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 129 | - return true; |
|
| 130 | - } |
|
| 131 | - return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param $appName |
|
| 136 | - * @param $fileName |
|
| 137 | - * @return ISimpleFile |
|
| 138 | - */ |
|
| 139 | - public function getCachedCSS(string $appName, string $fileName): ISimpleFile { |
|
| 140 | - $folder = $this->appData->getFolder($appName); |
|
| 141 | - $cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName); |
|
| 142 | - return $folder->getFile($cachedFileName); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Check if the file is cached or not |
|
| 147 | - * @param string $fileNameCSS |
|
| 148 | - * @param ISimpleFolder $folder |
|
| 149 | - * @return boolean |
|
| 150 | - */ |
|
| 151 | - private function isCached(string $fileNameCSS, ISimpleFolder $folder) { |
|
| 152 | - try { |
|
| 153 | - $cachedFile = $folder->getFile($fileNameCSS); |
|
| 154 | - if ($cachedFile->getSize() > 0) { |
|
| 155 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 156 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 157 | - if ($deps === null) { |
|
| 158 | - $depFile = $folder->getFile($depFileName); |
|
| 159 | - $deps = $depFile->getContent(); |
|
| 160 | - //Set to memcache for next run |
|
| 161 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 162 | - } |
|
| 163 | - $deps = json_decode($deps, true); |
|
| 164 | - |
|
| 165 | - foreach ((array)$deps as $file=>$mtime) { |
|
| 166 | - if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - return true; |
|
| 171 | - } |
|
| 172 | - return false; |
|
| 173 | - } catch(NotFoundException $e) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Check if the variables file has changed |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - private function variablesChanged(): bool { |
|
| 183 | - $injectedVariables = $this->getInjectedVariables(); |
|
| 184 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 185 | - $this->resetCache(); |
|
| 186 | - $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - return false; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Cache the file with AppData |
|
| 194 | - * |
|
| 195 | - * @param string $path |
|
| 196 | - * @param string $fileNameCSS |
|
| 197 | - * @param string $fileNameSCSS |
|
| 198 | - * @param ISimpleFolder $folder |
|
| 199 | - * @param string $webDir |
|
| 200 | - * @return boolean |
|
| 201 | - * @throws NotPermittedException |
|
| 202 | - */ |
|
| 203 | - private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, ISimpleFolder $folder, string $webDir) { |
|
| 204 | - $scss = new Compiler(); |
|
| 205 | - $scss->setImportPaths([ |
|
| 206 | - $path, |
|
| 207 | - $this->serverRoot . '/core/css/', |
|
| 208 | - ]); |
|
| 209 | - // Continue after throw |
|
| 210 | - $scss->setIgnoreErrors(true); |
|
| 211 | - if($this->config->getSystemValue('debug')) { |
|
| 212 | - // Debug mode |
|
| 213 | - $scss->setFormatter(Expanded::class); |
|
| 214 | - $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 215 | - } else { |
|
| 216 | - // Compression |
|
| 217 | - $scss->setFormatter(Crunched::class); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - try { |
|
| 221 | - $cachedfile = $folder->getFile($fileNameCSS); |
|
| 222 | - } catch(NotFoundException $e) { |
|
| 223 | - $cachedfile = $folder->newFile($fileNameCSS); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 227 | - try { |
|
| 228 | - $depFile = $folder->getFile($depFileName); |
|
| 229 | - } catch (NotFoundException $e) { |
|
| 230 | - $depFile = $folder->newFile($depFileName); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // Compile |
|
| 234 | - try { |
|
| 235 | - $compiledScss = $scss->compile( |
|
| 236 | - '$webroot: \'' . \OC::$WEBROOT. '\';'. |
|
| 237 | - '@import "functions.scss";' . |
|
| 238 | - '@import "variables.scss";' . |
|
| 239 | - $this->getInjectedVariables() . |
|
| 240 | - '@import "'.$fileNameSCSS.'";'); |
|
| 241 | - } catch(ParserException $e) { |
|
| 242 | - $this->logger->error($e, ['app' => 'core']); |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // Gzip file |
|
| 247 | - try { |
|
| 248 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 249 | - } catch (NotFoundException $e) { |
|
| 250 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - try { |
|
| 254 | - $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 255 | - $cachedfile->putContent($data); |
|
| 256 | - $deps = json_encode($scss->getParsedFiles()); |
|
| 257 | - $depFile->putContent($deps); |
|
| 258 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 259 | - $gzipFile->putContent(gzencode($data, 9)); |
|
| 260 | - $this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 261 | - return true; |
|
| 262 | - } catch(NotPermittedException $e) { |
|
| 263 | - $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
| 264 | - return false; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Reset scss cache by deleting all generated css files |
|
| 270 | - * We need to regenerate all files when variables change |
|
| 271 | - */ |
|
| 272 | - public function resetCache() { |
|
| 273 | - $this->injectedVariables = null; |
|
| 274 | - $this->cacheFactory->createDistributed('SCSS-')->clear(); |
|
| 275 | - $appDirectory = $this->appData->getDirectoryListing(); |
|
| 276 | - foreach ($appDirectory as $folder) { |
|
| 277 | - foreach ($folder->getDirectoryListing() as $file) { |
|
| 278 | - try { |
|
| 279 | - $file->delete(); |
|
| 280 | - } catch(NotPermittedException $e) { |
|
| 281 | - $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return string SCSS code for variables from OC_Defaults |
|
| 289 | - */ |
|
| 290 | - private function getInjectedVariables(): string { |
|
| 291 | - if ($this->injectedVariables !== null) { |
|
| 292 | - return $this->injectedVariables; |
|
| 293 | - } |
|
| 294 | - $variables = ''; |
|
| 295 | - foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 296 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // check for valid variables / otherwise fall back to defaults |
|
| 300 | - try { |
|
| 301 | - $scss = new Compiler(); |
|
| 302 | - $scss->compile($variables); |
|
| 303 | - $this->injectedVariables = $variables; |
|
| 304 | - } catch (ParserException $e) { |
|
| 305 | - $this->logger->error($e, ['app' => 'core']); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $variables; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Add the correct uri prefix to make uri valid again |
|
| 313 | - * @param string $css |
|
| 314 | - * @param string $webDir |
|
| 315 | - * @return string |
|
| 316 | - */ |
|
| 317 | - private function rebaseUrls(string $css, string $webDir): string { |
|
| 318 | - $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
| 319 | - $subst = 'url(\''.$webDir.'/$1\')'; |
|
| 320 | - return preg_replace($re, $subst, $css); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Return the cached css file uri |
|
| 325 | - * @param string $appName the app name |
|
| 326 | - * @param string $fileName |
|
| 327 | - * @return string |
|
| 328 | - */ |
|
| 329 | - public function getCachedSCSS(string $appName, string $fileName): string { |
|
| 330 | - $tmpfileLoc = explode('/', $fileName); |
|
| 331 | - $fileName = array_pop($tmpfileLoc); |
|
| 332 | - $fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName); |
|
| 333 | - |
|
| 334 | - return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Prepend hashed base url to the css file |
|
| 339 | - * @param string $cssFile |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - private function prependBaseurlPrefix(string $cssFile): string { |
|
| 343 | - $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 344 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Prepend hashed app version hash |
|
| 349 | - * @param string $cssFile |
|
| 350 | - * @param string $appId |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - private function prependVersionPrefix(string $cssFile, string $appId): string { |
|
| 354 | - $appVersion = \OC_App::getAppVersion($appId); |
|
| 355 | - if ($appVersion !== '0') { |
|
| 356 | - return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
| 357 | - } |
|
| 358 | - $coreVersion = \OC_Util::getVersionString(); |
|
| 359 | - return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Get WebDir root |
|
| 364 | - * @param string $path the css file path |
|
| 365 | - * @param string $appName the app name |
|
| 366 | - * @param string $serverRoot the server root path |
|
| 367 | - * @param string $webRoot the nextcloud installation root path |
|
| 368 | - * @return string the webDir |
|
| 369 | - */ |
|
| 370 | - private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
|
| 371 | - // Detect if path is within server root AND if path is within an app path |
|
| 372 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 373 | - // Get the file path within the app directory |
|
| 374 | - $appDirectoryPath = explode($appName, $path)[1]; |
|
| 375 | - // Remove the webroot |
|
| 376 | - return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 377 | - } |
|
| 378 | - return $webRoot.substr($path, strlen($serverRoot)); |
|
| 379 | - } |
|
| 49 | + /** @var ILogger */ |
|
| 50 | + protected $logger; |
|
| 51 | + |
|
| 52 | + /** @var IAppData */ |
|
| 53 | + protected $appData; |
|
| 54 | + |
|
| 55 | + /** @var IURLGenerator */ |
|
| 56 | + protected $urlGenerator; |
|
| 57 | + |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + protected $config; |
|
| 60 | + |
|
| 61 | + /** @var \OC_Defaults */ |
|
| 62 | + private $defaults; |
|
| 63 | + |
|
| 64 | + /** @var string */ |
|
| 65 | + protected $serverRoot; |
|
| 66 | + |
|
| 67 | + /** @var ICache */ |
|
| 68 | + protected $depsCache; |
|
| 69 | + |
|
| 70 | + /** @var null|string */ |
|
| 71 | + private $injectedVariables; |
|
| 72 | + |
|
| 73 | + /** @var ICacheFactory */ |
|
| 74 | + private $cacheFactory; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param ILogger $logger |
|
| 78 | + * @param Factory $appDataFactory |
|
| 79 | + * @param IURLGenerator $urlGenerator |
|
| 80 | + * @param IConfig $config |
|
| 81 | + * @param \OC_Defaults $defaults |
|
| 82 | + * @param string $serverRoot |
|
| 83 | + * @param ICacheFactory $cacheFactory |
|
| 84 | + */ |
|
| 85 | + public function __construct(ILogger $logger, |
|
| 86 | + Factory $appDataFactory, |
|
| 87 | + IURLGenerator $urlGenerator, |
|
| 88 | + IConfig $config, |
|
| 89 | + \OC_Defaults $defaults, |
|
| 90 | + $serverRoot, |
|
| 91 | + ICacheFactory $cacheFactory) { |
|
| 92 | + $this->logger = $logger; |
|
| 93 | + $this->appData = $appDataFactory->get('css'); |
|
| 94 | + $this->urlGenerator = $urlGenerator; |
|
| 95 | + $this->config = $config; |
|
| 96 | + $this->defaults = $defaults; |
|
| 97 | + $this->serverRoot = $serverRoot; |
|
| 98 | + $this->cacheFactory = $cacheFactory; |
|
| 99 | + $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Process the caching process if needed |
|
| 104 | + * |
|
| 105 | + * @param string $root Root path to the nextcloud installation |
|
| 106 | + * @param string $file |
|
| 107 | + * @param string $app The app name |
|
| 108 | + * @return boolean |
|
| 109 | + * @throws NotPermittedException |
|
| 110 | + */ |
|
| 111 | + public function process(string $root, string $file, string $app): bool { |
|
| 112 | + $path = explode('/', $root . '/' . $file); |
|
| 113 | + |
|
| 114 | + $fileNameSCSS = array_pop($path); |
|
| 115 | + $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
|
| 116 | + |
|
| 117 | + $path = implode('/', $path); |
|
| 118 | + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 119 | + |
|
| 120 | + try { |
|
| 121 | + $folder = $this->appData->getFolder($app); |
|
| 122 | + } catch(NotFoundException $e) { |
|
| 123 | + // creating css appdata folder |
|
| 124 | + $folder = $this->appData->newFolder($app); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 129 | + return true; |
|
| 130 | + } |
|
| 131 | + return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param $appName |
|
| 136 | + * @param $fileName |
|
| 137 | + * @return ISimpleFile |
|
| 138 | + */ |
|
| 139 | + public function getCachedCSS(string $appName, string $fileName): ISimpleFile { |
|
| 140 | + $folder = $this->appData->getFolder($appName); |
|
| 141 | + $cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName); |
|
| 142 | + return $folder->getFile($cachedFileName); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Check if the file is cached or not |
|
| 147 | + * @param string $fileNameCSS |
|
| 148 | + * @param ISimpleFolder $folder |
|
| 149 | + * @return boolean |
|
| 150 | + */ |
|
| 151 | + private function isCached(string $fileNameCSS, ISimpleFolder $folder) { |
|
| 152 | + try { |
|
| 153 | + $cachedFile = $folder->getFile($fileNameCSS); |
|
| 154 | + if ($cachedFile->getSize() > 0) { |
|
| 155 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 156 | + $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 157 | + if ($deps === null) { |
|
| 158 | + $depFile = $folder->getFile($depFileName); |
|
| 159 | + $deps = $depFile->getContent(); |
|
| 160 | + //Set to memcache for next run |
|
| 161 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 162 | + } |
|
| 163 | + $deps = json_decode($deps, true); |
|
| 164 | + |
|
| 165 | + foreach ((array)$deps as $file=>$mtime) { |
|
| 166 | + if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + return true; |
|
| 171 | + } |
|
| 172 | + return false; |
|
| 173 | + } catch(NotFoundException $e) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Check if the variables file has changed |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + private function variablesChanged(): bool { |
|
| 183 | + $injectedVariables = $this->getInjectedVariables(); |
|
| 184 | + if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 185 | + $this->resetCache(); |
|
| 186 | + $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Cache the file with AppData |
|
| 194 | + * |
|
| 195 | + * @param string $path |
|
| 196 | + * @param string $fileNameCSS |
|
| 197 | + * @param string $fileNameSCSS |
|
| 198 | + * @param ISimpleFolder $folder |
|
| 199 | + * @param string $webDir |
|
| 200 | + * @return boolean |
|
| 201 | + * @throws NotPermittedException |
|
| 202 | + */ |
|
| 203 | + private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, ISimpleFolder $folder, string $webDir) { |
|
| 204 | + $scss = new Compiler(); |
|
| 205 | + $scss->setImportPaths([ |
|
| 206 | + $path, |
|
| 207 | + $this->serverRoot . '/core/css/', |
|
| 208 | + ]); |
|
| 209 | + // Continue after throw |
|
| 210 | + $scss->setIgnoreErrors(true); |
|
| 211 | + if($this->config->getSystemValue('debug')) { |
|
| 212 | + // Debug mode |
|
| 213 | + $scss->setFormatter(Expanded::class); |
|
| 214 | + $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 215 | + } else { |
|
| 216 | + // Compression |
|
| 217 | + $scss->setFormatter(Crunched::class); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + try { |
|
| 221 | + $cachedfile = $folder->getFile($fileNameCSS); |
|
| 222 | + } catch(NotFoundException $e) { |
|
| 223 | + $cachedfile = $folder->newFile($fileNameCSS); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 227 | + try { |
|
| 228 | + $depFile = $folder->getFile($depFileName); |
|
| 229 | + } catch (NotFoundException $e) { |
|
| 230 | + $depFile = $folder->newFile($depFileName); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // Compile |
|
| 234 | + try { |
|
| 235 | + $compiledScss = $scss->compile( |
|
| 236 | + '$webroot: \'' . \OC::$WEBROOT. '\';'. |
|
| 237 | + '@import "functions.scss";' . |
|
| 238 | + '@import "variables.scss";' . |
|
| 239 | + $this->getInjectedVariables() . |
|
| 240 | + '@import "'.$fileNameSCSS.'";'); |
|
| 241 | + } catch(ParserException $e) { |
|
| 242 | + $this->logger->error($e, ['app' => 'core']); |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // Gzip file |
|
| 247 | + try { |
|
| 248 | + $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 249 | + } catch (NotFoundException $e) { |
|
| 250 | + $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + try { |
|
| 254 | + $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 255 | + $cachedfile->putContent($data); |
|
| 256 | + $deps = json_encode($scss->getParsedFiles()); |
|
| 257 | + $depFile->putContent($deps); |
|
| 258 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 259 | + $gzipFile->putContent(gzencode($data, 9)); |
|
| 260 | + $this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 261 | + return true; |
|
| 262 | + } catch(NotPermittedException $e) { |
|
| 263 | + $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
| 264 | + return false; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Reset scss cache by deleting all generated css files |
|
| 270 | + * We need to regenerate all files when variables change |
|
| 271 | + */ |
|
| 272 | + public function resetCache() { |
|
| 273 | + $this->injectedVariables = null; |
|
| 274 | + $this->cacheFactory->createDistributed('SCSS-')->clear(); |
|
| 275 | + $appDirectory = $this->appData->getDirectoryListing(); |
|
| 276 | + foreach ($appDirectory as $folder) { |
|
| 277 | + foreach ($folder->getDirectoryListing() as $file) { |
|
| 278 | + try { |
|
| 279 | + $file->delete(); |
|
| 280 | + } catch(NotPermittedException $e) { |
|
| 281 | + $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return string SCSS code for variables from OC_Defaults |
|
| 289 | + */ |
|
| 290 | + private function getInjectedVariables(): string { |
|
| 291 | + if ($this->injectedVariables !== null) { |
|
| 292 | + return $this->injectedVariables; |
|
| 293 | + } |
|
| 294 | + $variables = ''; |
|
| 295 | + foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 296 | + $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // check for valid variables / otherwise fall back to defaults |
|
| 300 | + try { |
|
| 301 | + $scss = new Compiler(); |
|
| 302 | + $scss->compile($variables); |
|
| 303 | + $this->injectedVariables = $variables; |
|
| 304 | + } catch (ParserException $e) { |
|
| 305 | + $this->logger->error($e, ['app' => 'core']); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $variables; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Add the correct uri prefix to make uri valid again |
|
| 313 | + * @param string $css |
|
| 314 | + * @param string $webDir |
|
| 315 | + * @return string |
|
| 316 | + */ |
|
| 317 | + private function rebaseUrls(string $css, string $webDir): string { |
|
| 318 | + $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
| 319 | + $subst = 'url(\''.$webDir.'/$1\')'; |
|
| 320 | + return preg_replace($re, $subst, $css); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Return the cached css file uri |
|
| 325 | + * @param string $appName the app name |
|
| 326 | + * @param string $fileName |
|
| 327 | + * @return string |
|
| 328 | + */ |
|
| 329 | + public function getCachedSCSS(string $appName, string $fileName): string { |
|
| 330 | + $tmpfileLoc = explode('/', $fileName); |
|
| 331 | + $fileName = array_pop($tmpfileLoc); |
|
| 332 | + $fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName); |
|
| 333 | + |
|
| 334 | + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Prepend hashed base url to the css file |
|
| 339 | + * @param string $cssFile |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + private function prependBaseurlPrefix(string $cssFile): string { |
|
| 343 | + $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 344 | + return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Prepend hashed app version hash |
|
| 349 | + * @param string $cssFile |
|
| 350 | + * @param string $appId |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + private function prependVersionPrefix(string $cssFile, string $appId): string { |
|
| 354 | + $appVersion = \OC_App::getAppVersion($appId); |
|
| 355 | + if ($appVersion !== '0') { |
|
| 356 | + return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
| 357 | + } |
|
| 358 | + $coreVersion = \OC_Util::getVersionString(); |
|
| 359 | + return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Get WebDir root |
|
| 364 | + * @param string $path the css file path |
|
| 365 | + * @param string $appName the app name |
|
| 366 | + * @param string $serverRoot the server root path |
|
| 367 | + * @param string $webRoot the nextcloud installation root path |
|
| 368 | + * @return string the webDir |
|
| 369 | + */ |
|
| 370 | + private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
|
| 371 | + // Detect if path is within server root AND if path is within an app path |
|
| 372 | + if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 373 | + // Get the file path within the app directory |
|
| 374 | + $appDirectoryPath = explode($appName, $path)[1]; |
|
| 375 | + // Remove the webroot |
|
| 376 | + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 377 | + } |
|
| 378 | + return $webRoot.substr($path, strlen($serverRoot)); |
|
| 379 | + } |
|
| 380 | 380 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $this->defaults = $defaults; |
| 97 | 97 | $this->serverRoot = $serverRoot; |
| 98 | 98 | $this->cacheFactory = $cacheFactory; |
| 99 | - $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
| 99 | + $this->depsCache = $cacheFactory->createDistributed('SCSS-'.md5($this->urlGenerator->getBaseUrl())); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @throws NotPermittedException |
| 110 | 110 | */ |
| 111 | 111 | public function process(string $root, string $file, string $app): bool { |
| 112 | - $path = explode('/', $root . '/' . $file); |
|
| 112 | + $path = explode('/', $root.'/'.$file); |
|
| 113 | 113 | |
| 114 | 114 | $fileNameSCSS = array_pop($path); |
| 115 | 115 | $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | try { |
| 121 | 121 | $folder = $this->appData->getFolder($app); |
| 122 | - } catch(NotFoundException $e) { |
|
| 122 | + } catch (NotFoundException $e) { |
|
| 123 | 123 | // creating css appdata folder |
| 124 | 124 | $folder = $this->appData->newFolder($app); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 128 | + if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 129 | 129 | return true; |
| 130 | 130 | } |
| 131 | 131 | return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
@@ -152,17 +152,17 @@ discard block |
||
| 152 | 152 | try { |
| 153 | 153 | $cachedFile = $folder->getFile($fileNameCSS); |
| 154 | 154 | if ($cachedFile->getSize() > 0) { |
| 155 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 156 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 155 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 156 | + $deps = $this->depsCache->get($folder->getName().'-'.$depFileName); |
|
| 157 | 157 | if ($deps === null) { |
| 158 | 158 | $depFile = $folder->getFile($depFileName); |
| 159 | 159 | $deps = $depFile->getContent(); |
| 160 | 160 | //Set to memcache for next run |
| 161 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 161 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 162 | 162 | } |
| 163 | 163 | $deps = json_decode($deps, true); |
| 164 | 164 | |
| 165 | - foreach ((array)$deps as $file=>$mtime) { |
|
| 165 | + foreach ((array) $deps as $file=>$mtime) { |
|
| 166 | 166 | if (!file_exists($file) || filemtime($file) > $mtime) { |
| 167 | 167 | return false; |
| 168 | 168 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | return true; |
| 171 | 171 | } |
| 172 | 172 | return false; |
| 173 | - } catch(NotFoundException $e) { |
|
| 173 | + } catch (NotFoundException $e) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | private function variablesChanged(): bool { |
| 183 | 183 | $injectedVariables = $this->getInjectedVariables(); |
| 184 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 184 | + if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 185 | 185 | $this->resetCache(); |
| 186 | 186 | $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
| 187 | 187 | return true; |
@@ -204,11 +204,11 @@ discard block |
||
| 204 | 204 | $scss = new Compiler(); |
| 205 | 205 | $scss->setImportPaths([ |
| 206 | 206 | $path, |
| 207 | - $this->serverRoot . '/core/css/', |
|
| 207 | + $this->serverRoot.'/core/css/', |
|
| 208 | 208 | ]); |
| 209 | 209 | // Continue after throw |
| 210 | 210 | $scss->setIgnoreErrors(true); |
| 211 | - if($this->config->getSystemValue('debug')) { |
|
| 211 | + if ($this->config->getSystemValue('debug')) { |
|
| 212 | 212 | // Debug mode |
| 213 | 213 | $scss->setFormatter(Expanded::class); |
| 214 | 214 | $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | try { |
| 221 | 221 | $cachedfile = $folder->getFile($fileNameCSS); |
| 222 | - } catch(NotFoundException $e) { |
|
| 222 | + } catch (NotFoundException $e) { |
|
| 223 | 223 | $cachedfile = $folder->newFile($fileNameCSS); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 226 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 227 | 227 | try { |
| 228 | 228 | $depFile = $folder->getFile($depFileName); |
| 229 | 229 | } catch (NotFoundException $e) { |
@@ -233,21 +233,21 @@ discard block |
||
| 233 | 233 | // Compile |
| 234 | 234 | try { |
| 235 | 235 | $compiledScss = $scss->compile( |
| 236 | - '$webroot: \'' . \OC::$WEBROOT. '\';'. |
|
| 237 | - '@import "functions.scss";' . |
|
| 238 | - '@import "variables.scss";' . |
|
| 239 | - $this->getInjectedVariables() . |
|
| 236 | + '$webroot: \''.\OC::$WEBROOT.'\';'. |
|
| 237 | + '@import "functions.scss";'. |
|
| 238 | + '@import "variables.scss";'. |
|
| 239 | + $this->getInjectedVariables(). |
|
| 240 | 240 | '@import "'.$fileNameSCSS.'";'); |
| 241 | - } catch(ParserException $e) { |
|
| 241 | + } catch (ParserException $e) { |
|
| 242 | 242 | $this->logger->error($e, ['app' => 'core']); |
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Gzip file |
| 247 | 247 | try { |
| 248 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 248 | + $gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 249 | 249 | } catch (NotFoundException $e) { |
| 250 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 250 | + $gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | try { |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | $cachedfile->putContent($data); |
| 256 | 256 | $deps = json_encode($scss->getParsedFiles()); |
| 257 | 257 | $depFile->putContent($deps); |
| 258 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 258 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 259 | 259 | $gzipFile->putContent(gzencode($data, 9)); |
| 260 | 260 | $this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
| 261 | 261 | return true; |
| 262 | - } catch(NotPermittedException $e) { |
|
| 263 | - $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
| 262 | + } catch (NotPermittedException $e) { |
|
| 263 | + $this->logger->error('SCSSCacher: unable to cache: '.$fileNameSCSS); |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | } |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | foreach ($folder->getDirectoryListing() as $file) { |
| 278 | 278 | try { |
| 279 | 279 | $file->delete(); |
| 280 | - } catch(NotPermittedException $e) { |
|
| 281 | - $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
| 280 | + } catch (NotPermittedException $e) { |
|
| 281 | + $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: '.$file->getName()]); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | $variables = ''; |
| 295 | 295 | foreach ($this->defaults->getScssVariables() as $key => $value) { |
| 296 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 296 | + $variables .= '$'.$key.': '.$value.';'; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // check for valid variables / otherwise fall back to defaults |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | private function prependBaseurlPrefix(string $cssFile): string { |
| 343 | 343 | $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
| 344 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile; |
|
| 344 | + return substr(md5($this->urlGenerator->getBaseUrl().$frontendController), 0, 4).'-'.$cssFile; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -353,10 +353,10 @@ discard block |
||
| 353 | 353 | private function prependVersionPrefix(string $cssFile, string $appId): string { |
| 354 | 354 | $appVersion = \OC_App::getAppVersion($appId); |
| 355 | 355 | if ($appVersion !== '0') { |
| 356 | - return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
| 356 | + return substr(md5($appVersion), 0, 4).'-'.$cssFile; |
|
| 357 | 357 | } |
| 358 | 358 | $coreVersion = \OC_Util::getVersionString(); |
| 359 | - return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
| 359 | + return substr(md5($coreVersion), 0, 4).'-'.$cssFile; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | */ |
| 370 | 370 | private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
| 371 | 371 | // Detect if path is within server root AND if path is within an app path |
| 372 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 372 | + if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 373 | 373 | // Get the file path within the app directory |
| 374 | 374 | $appDirectoryPath = explode($appName, $path)[1]; |
| 375 | 375 | // Remove the webroot |
@@ -49,354 +49,354 @@ |
||
| 49 | 49 | use OCP\Util; |
| 50 | 50 | |
| 51 | 51 | class Manager implements IManager { |
| 52 | - /** @var ILogger */ |
|
| 53 | - private $log; |
|
| 54 | - /** @var IDBConnection */ |
|
| 55 | - private $dbc; |
|
| 56 | - /** @var IL10N */ |
|
| 57 | - private $l; |
|
| 58 | - /** @var IConfig */ |
|
| 59 | - private $config; |
|
| 60 | - /** @var EncryptionManager */ |
|
| 61 | - private $encryptionManager; |
|
| 62 | - /** @var IUserManager */ |
|
| 63 | - private $userManager; |
|
| 64 | - /** @var ILockingProvider */ |
|
| 65 | - private $lockingProvider; |
|
| 66 | - /** @var IRequest */ |
|
| 67 | - private $request; |
|
| 68 | - /** @var IURLGenerator */ |
|
| 69 | - private $url; |
|
| 70 | - /** @var AccountManager */ |
|
| 71 | - private $accountManager; |
|
| 72 | - /** @var IGroupManager */ |
|
| 73 | - private $groupManager; |
|
| 74 | - /** @var IFactory */ |
|
| 75 | - private $l10nFactory; |
|
| 76 | - /** @var IAppManager */ |
|
| 77 | - private $appManager; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param ILogger $log |
|
| 81 | - * @param IDBConnection $dbc |
|
| 82 | - * @param IL10N $l |
|
| 83 | - * @param IConfig $config |
|
| 84 | - * @param EncryptionManager $encryptionManager |
|
| 85 | - * @param IUserManager $userManager |
|
| 86 | - * @param ILockingProvider $lockingProvider |
|
| 87 | - * @param IRequest $request |
|
| 88 | - * @param IURLGenerator $url |
|
| 89 | - * @param AccountManager $accountManager |
|
| 90 | - * @param IGroupManager $groupManager |
|
| 91 | - * @param IFactory $l10nFactory |
|
| 92 | - * @param IAppManager $appManager |
|
| 93 | - */ |
|
| 94 | - public function __construct( |
|
| 95 | - ILogger $log, |
|
| 96 | - IDBConnection $dbc, |
|
| 97 | - IL10N $l, |
|
| 98 | - IConfig $config, |
|
| 99 | - EncryptionManager $encryptionManager, |
|
| 100 | - IUserManager $userManager, |
|
| 101 | - ILockingProvider $lockingProvider, |
|
| 102 | - IRequest $request, |
|
| 103 | - IURLGenerator $url, |
|
| 104 | - AccountManager $accountManager, |
|
| 105 | - IGroupManager $groupManager, |
|
| 106 | - IFactory $l10nFactory, |
|
| 107 | - IAppManager $appManager |
|
| 108 | - ) { |
|
| 109 | - $this->log = $log; |
|
| 110 | - $this->dbc = $dbc; |
|
| 111 | - $this->l = $l; |
|
| 112 | - $this->config = $config; |
|
| 113 | - $this->encryptionManager = $encryptionManager; |
|
| 114 | - $this->userManager = $userManager; |
|
| 115 | - $this->lockingProvider = $lockingProvider; |
|
| 116 | - $this->request = $request; |
|
| 117 | - $this->url = $url; |
|
| 118 | - $this->accountManager = $accountManager; |
|
| 119 | - $this->groupManager = $groupManager; |
|
| 120 | - $this->l10nFactory = $l10nFactory; |
|
| 121 | - $this->appManager = $appManager; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** @var array */ |
|
| 125 | - protected $sectionClasses = []; |
|
| 126 | - |
|
| 127 | - /** @var array */ |
|
| 128 | - protected $sections = []; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param string $type 'admin' or 'personal' |
|
| 132 | - * @param string $section Class must implement OCP\Settings\ISection |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - public function registerSection(string $type, string $section) { |
|
| 136 | - $this->sectionClasses[$section] = $type; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $type 'admin' or 'personal' |
|
| 141 | - * @return ISection[] |
|
| 142 | - */ |
|
| 143 | - protected function getSections(string $type): array { |
|
| 144 | - if (!isset($this->sections[$type])) { |
|
| 145 | - $this->sections[$type] = []; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - foreach ($this->sectionClasses as $class => $sectionType) { |
|
| 149 | - try { |
|
| 150 | - /** @var ISection $section */ |
|
| 151 | - $section = \OC::$server->query($class); |
|
| 152 | - } catch (QueryException $e) { |
|
| 153 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (!$section instanceof ISection) { |
|
| 158 | - $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
| 159 | - continue; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $this->sections[$sectionType][$section->getID()] = $section; |
|
| 163 | - |
|
| 164 | - unset($this->sectionClasses[$class]); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return $this->sections[$type]; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** @var array */ |
|
| 171 | - protected $settingClasses = []; |
|
| 172 | - |
|
| 173 | - /** @var array */ |
|
| 174 | - protected $settings = []; |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $type 'admin' or 'personal' |
|
| 178 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - public function registerSetting(string $type, string $setting) { |
|
| 182 | - $this->settingClasses[$setting] = $type; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @param string $type 'admin' or 'personal' |
|
| 187 | - * @param string $section |
|
| 188 | - * @return ISettings[] |
|
| 189 | - */ |
|
| 190 | - protected function getSettings(string $type, string $section): array { |
|
| 191 | - if (!isset($this->settings[$type])) { |
|
| 192 | - $this->settings[$type] = []; |
|
| 193 | - } |
|
| 194 | - if (!isset($this->settings[$type][$section])) { |
|
| 195 | - $this->settings[$type][$section] = []; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
| 199 | - try { |
|
| 200 | - /** @var ISettings $setting */ |
|
| 201 | - $setting = \OC::$server->query($class); |
|
| 202 | - } catch (QueryException $e) { |
|
| 203 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 204 | - continue; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (!$setting instanceof ISettings) { |
|
| 208 | - $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => ILogger::INFO]); |
|
| 209 | - continue; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
| 213 | - $this->settings[$settingsType][$setting->getSection()] = []; |
|
| 214 | - } |
|
| 215 | - $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
| 216 | - |
|
| 217 | - unset($this->settingClasses[$class]); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $this->settings[$type][$section]; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @inheritdoc |
|
| 225 | - */ |
|
| 226 | - public function getAdminSections(): array { |
|
| 227 | - // built-in sections |
|
| 228 | - $sections = [ |
|
| 229 | - 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 230 | - 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 231 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 232 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 233 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 234 | - 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
| 235 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 236 | - ]; |
|
| 237 | - |
|
| 238 | - $appSections = $this->getSections('admin'); |
|
| 239 | - |
|
| 240 | - foreach ($appSections as $section) { |
|
| 241 | - /** @var ISection $section */ |
|
| 242 | - if (!isset($sections[$section->getPriority()])) { |
|
| 243 | - $sections[$section->getPriority()] = []; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $sections[$section->getPriority()][] = $section; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - ksort($sections); |
|
| 250 | - |
|
| 251 | - return $sections; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param string $section |
|
| 256 | - * @return ISection[] |
|
| 257 | - */ |
|
| 258 | - private function getBuiltInAdminSettings($section): array { |
|
| 259 | - $forms = []; |
|
| 260 | - |
|
| 261 | - if ($section === 'overview') { |
|
| 262 | - /** @var ISettings $form */ |
|
| 263 | - $form = new Admin\Overview($this->config); |
|
| 264 | - $forms[$form->getPriority()] = [$form]; |
|
| 265 | - } |
|
| 266 | - if ($section === 'server') { |
|
| 267 | - /** @var ISettings $form */ |
|
| 268 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 269 | - $forms[$form->getPriority()] = [$form]; |
|
| 270 | - $form = new Admin\Mail($this->config); |
|
| 271 | - $forms[$form->getPriority()] = [$form]; |
|
| 272 | - } |
|
| 273 | - if ($section === 'encryption') { |
|
| 274 | - /** @var ISettings $form */ |
|
| 275 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 276 | - $forms[$form->getPriority()] = [$form]; |
|
| 277 | - } |
|
| 278 | - if ($section === 'sharing') { |
|
| 279 | - /** @var ISettings $form */ |
|
| 280 | - $form = new Admin\Sharing($this->config, $this->l); |
|
| 281 | - $forms[$form->getPriority()] = [$form]; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $forms; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param string $section |
|
| 289 | - * @return ISection[] |
|
| 290 | - */ |
|
| 291 | - private function getBuiltInPersonalSettings($section): array { |
|
| 292 | - $forms = []; |
|
| 293 | - |
|
| 294 | - if ($section === 'personal-info') { |
|
| 295 | - /** @var ISettings $form */ |
|
| 296 | - $form = new Personal\PersonalInfo( |
|
| 297 | - $this->config, |
|
| 298 | - $this->userManager, |
|
| 299 | - $this->groupManager, |
|
| 300 | - $this->accountManager, |
|
| 301 | - $this->appManager, |
|
| 302 | - $this->l10nFactory, |
|
| 303 | - $this->l |
|
| 304 | - ); |
|
| 305 | - $forms[$form->getPriority()] = [$form]; |
|
| 306 | - $form = new Personal\ServerDevNotice(); |
|
| 307 | - $forms[$form->getPriority()] = [$form]; |
|
| 308 | - } |
|
| 309 | - if($section === 'security') { |
|
| 310 | - /** @var ISettings $form */ |
|
| 311 | - $form = new Personal\Security($this->userManager); |
|
| 312 | - $forms[$form->getPriority()] = [$form]; |
|
| 313 | - } |
|
| 314 | - if ($section === 'additional') { |
|
| 315 | - /** @var ISettings $form */ |
|
| 316 | - $form = new Personal\Additional(); |
|
| 317 | - $forms[$form->getPriority()] = [$form]; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $forms; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @inheritdoc |
|
| 325 | - */ |
|
| 326 | - public function getAdminSettings($section): array { |
|
| 327 | - $settings = $this->getBuiltInAdminSettings($section); |
|
| 328 | - $appSettings = $this->getSettings('admin', $section); |
|
| 329 | - |
|
| 330 | - foreach ($appSettings as $setting) { |
|
| 331 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 332 | - $settings[$setting->getPriority()] = []; |
|
| 333 | - } |
|
| 334 | - $settings[$setting->getPriority()][] = $setting; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - ksort($settings); |
|
| 338 | - return $settings; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @inheritdoc |
|
| 343 | - */ |
|
| 344 | - public function getPersonalSections(): array { |
|
| 345 | - $sections = [ |
|
| 346 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 347 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 348 | - 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
| 349 | - ]; |
|
| 350 | - |
|
| 351 | - $legacyForms = \OC_App::getForms('personal'); |
|
| 352 | - if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 353 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $appSections = $this->getSections('personal'); |
|
| 357 | - |
|
| 358 | - foreach ($appSections as $section) { |
|
| 359 | - /** @var ISection $section */ |
|
| 360 | - if (!isset($sections[$section->getPriority()])) { |
|
| 361 | - $sections[$section->getPriority()] = []; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $sections[$section->getPriority()][] = $section; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - ksort($sections); |
|
| 368 | - |
|
| 369 | - return $sections; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param string[] $forms |
|
| 374 | - * @return bool |
|
| 375 | - */ |
|
| 376 | - private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
| 377 | - foreach ($forms as $form) { |
|
| 378 | - if(trim($form) !== '') { |
|
| 379 | - return true; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - return false; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @inheritdoc |
|
| 387 | - */ |
|
| 388 | - public function getPersonalSettings($section): array { |
|
| 389 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
| 390 | - $appSettings = $this->getSettings('personal', $section); |
|
| 391 | - |
|
| 392 | - foreach ($appSettings as $setting) { |
|
| 393 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 394 | - $settings[$setting->getPriority()] = []; |
|
| 395 | - } |
|
| 396 | - $settings[$setting->getPriority()][] = $setting; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - ksort($settings); |
|
| 400 | - return $settings; |
|
| 401 | - } |
|
| 52 | + /** @var ILogger */ |
|
| 53 | + private $log; |
|
| 54 | + /** @var IDBConnection */ |
|
| 55 | + private $dbc; |
|
| 56 | + /** @var IL10N */ |
|
| 57 | + private $l; |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + private $config; |
|
| 60 | + /** @var EncryptionManager */ |
|
| 61 | + private $encryptionManager; |
|
| 62 | + /** @var IUserManager */ |
|
| 63 | + private $userManager; |
|
| 64 | + /** @var ILockingProvider */ |
|
| 65 | + private $lockingProvider; |
|
| 66 | + /** @var IRequest */ |
|
| 67 | + private $request; |
|
| 68 | + /** @var IURLGenerator */ |
|
| 69 | + private $url; |
|
| 70 | + /** @var AccountManager */ |
|
| 71 | + private $accountManager; |
|
| 72 | + /** @var IGroupManager */ |
|
| 73 | + private $groupManager; |
|
| 74 | + /** @var IFactory */ |
|
| 75 | + private $l10nFactory; |
|
| 76 | + /** @var IAppManager */ |
|
| 77 | + private $appManager; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param ILogger $log |
|
| 81 | + * @param IDBConnection $dbc |
|
| 82 | + * @param IL10N $l |
|
| 83 | + * @param IConfig $config |
|
| 84 | + * @param EncryptionManager $encryptionManager |
|
| 85 | + * @param IUserManager $userManager |
|
| 86 | + * @param ILockingProvider $lockingProvider |
|
| 87 | + * @param IRequest $request |
|
| 88 | + * @param IURLGenerator $url |
|
| 89 | + * @param AccountManager $accountManager |
|
| 90 | + * @param IGroupManager $groupManager |
|
| 91 | + * @param IFactory $l10nFactory |
|
| 92 | + * @param IAppManager $appManager |
|
| 93 | + */ |
|
| 94 | + public function __construct( |
|
| 95 | + ILogger $log, |
|
| 96 | + IDBConnection $dbc, |
|
| 97 | + IL10N $l, |
|
| 98 | + IConfig $config, |
|
| 99 | + EncryptionManager $encryptionManager, |
|
| 100 | + IUserManager $userManager, |
|
| 101 | + ILockingProvider $lockingProvider, |
|
| 102 | + IRequest $request, |
|
| 103 | + IURLGenerator $url, |
|
| 104 | + AccountManager $accountManager, |
|
| 105 | + IGroupManager $groupManager, |
|
| 106 | + IFactory $l10nFactory, |
|
| 107 | + IAppManager $appManager |
|
| 108 | + ) { |
|
| 109 | + $this->log = $log; |
|
| 110 | + $this->dbc = $dbc; |
|
| 111 | + $this->l = $l; |
|
| 112 | + $this->config = $config; |
|
| 113 | + $this->encryptionManager = $encryptionManager; |
|
| 114 | + $this->userManager = $userManager; |
|
| 115 | + $this->lockingProvider = $lockingProvider; |
|
| 116 | + $this->request = $request; |
|
| 117 | + $this->url = $url; |
|
| 118 | + $this->accountManager = $accountManager; |
|
| 119 | + $this->groupManager = $groupManager; |
|
| 120 | + $this->l10nFactory = $l10nFactory; |
|
| 121 | + $this->appManager = $appManager; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** @var array */ |
|
| 125 | + protected $sectionClasses = []; |
|
| 126 | + |
|
| 127 | + /** @var array */ |
|
| 128 | + protected $sections = []; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param string $type 'admin' or 'personal' |
|
| 132 | + * @param string $section Class must implement OCP\Settings\ISection |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + public function registerSection(string $type, string $section) { |
|
| 136 | + $this->sectionClasses[$section] = $type; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $type 'admin' or 'personal' |
|
| 141 | + * @return ISection[] |
|
| 142 | + */ |
|
| 143 | + protected function getSections(string $type): array { |
|
| 144 | + if (!isset($this->sections[$type])) { |
|
| 145 | + $this->sections[$type] = []; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + foreach ($this->sectionClasses as $class => $sectionType) { |
|
| 149 | + try { |
|
| 150 | + /** @var ISection $section */ |
|
| 151 | + $section = \OC::$server->query($class); |
|
| 152 | + } catch (QueryException $e) { |
|
| 153 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (!$section instanceof ISection) { |
|
| 158 | + $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
| 159 | + continue; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $this->sections[$sectionType][$section->getID()] = $section; |
|
| 163 | + |
|
| 164 | + unset($this->sectionClasses[$class]); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return $this->sections[$type]; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** @var array */ |
|
| 171 | + protected $settingClasses = []; |
|
| 172 | + |
|
| 173 | + /** @var array */ |
|
| 174 | + protected $settings = []; |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $type 'admin' or 'personal' |
|
| 178 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + public function registerSetting(string $type, string $setting) { |
|
| 182 | + $this->settingClasses[$setting] = $type; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @param string $type 'admin' or 'personal' |
|
| 187 | + * @param string $section |
|
| 188 | + * @return ISettings[] |
|
| 189 | + */ |
|
| 190 | + protected function getSettings(string $type, string $section): array { |
|
| 191 | + if (!isset($this->settings[$type])) { |
|
| 192 | + $this->settings[$type] = []; |
|
| 193 | + } |
|
| 194 | + if (!isset($this->settings[$type][$section])) { |
|
| 195 | + $this->settings[$type][$section] = []; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
| 199 | + try { |
|
| 200 | + /** @var ISettings $setting */ |
|
| 201 | + $setting = \OC::$server->query($class); |
|
| 202 | + } catch (QueryException $e) { |
|
| 203 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 204 | + continue; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (!$setting instanceof ISettings) { |
|
| 208 | + $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => ILogger::INFO]); |
|
| 209 | + continue; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
| 213 | + $this->settings[$settingsType][$setting->getSection()] = []; |
|
| 214 | + } |
|
| 215 | + $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
| 216 | + |
|
| 217 | + unset($this->settingClasses[$class]); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $this->settings[$type][$section]; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @inheritdoc |
|
| 225 | + */ |
|
| 226 | + public function getAdminSections(): array { |
|
| 227 | + // built-in sections |
|
| 228 | + $sections = [ |
|
| 229 | + 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 230 | + 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 231 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 232 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 233 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 234 | + 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
| 235 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 236 | + ]; |
|
| 237 | + |
|
| 238 | + $appSections = $this->getSections('admin'); |
|
| 239 | + |
|
| 240 | + foreach ($appSections as $section) { |
|
| 241 | + /** @var ISection $section */ |
|
| 242 | + if (!isset($sections[$section->getPriority()])) { |
|
| 243 | + $sections[$section->getPriority()] = []; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $sections[$section->getPriority()][] = $section; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + ksort($sections); |
|
| 250 | + |
|
| 251 | + return $sections; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param string $section |
|
| 256 | + * @return ISection[] |
|
| 257 | + */ |
|
| 258 | + private function getBuiltInAdminSettings($section): array { |
|
| 259 | + $forms = []; |
|
| 260 | + |
|
| 261 | + if ($section === 'overview') { |
|
| 262 | + /** @var ISettings $form */ |
|
| 263 | + $form = new Admin\Overview($this->config); |
|
| 264 | + $forms[$form->getPriority()] = [$form]; |
|
| 265 | + } |
|
| 266 | + if ($section === 'server') { |
|
| 267 | + /** @var ISettings $form */ |
|
| 268 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 269 | + $forms[$form->getPriority()] = [$form]; |
|
| 270 | + $form = new Admin\Mail($this->config); |
|
| 271 | + $forms[$form->getPriority()] = [$form]; |
|
| 272 | + } |
|
| 273 | + if ($section === 'encryption') { |
|
| 274 | + /** @var ISettings $form */ |
|
| 275 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 276 | + $forms[$form->getPriority()] = [$form]; |
|
| 277 | + } |
|
| 278 | + if ($section === 'sharing') { |
|
| 279 | + /** @var ISettings $form */ |
|
| 280 | + $form = new Admin\Sharing($this->config, $this->l); |
|
| 281 | + $forms[$form->getPriority()] = [$form]; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $forms; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param string $section |
|
| 289 | + * @return ISection[] |
|
| 290 | + */ |
|
| 291 | + private function getBuiltInPersonalSettings($section): array { |
|
| 292 | + $forms = []; |
|
| 293 | + |
|
| 294 | + if ($section === 'personal-info') { |
|
| 295 | + /** @var ISettings $form */ |
|
| 296 | + $form = new Personal\PersonalInfo( |
|
| 297 | + $this->config, |
|
| 298 | + $this->userManager, |
|
| 299 | + $this->groupManager, |
|
| 300 | + $this->accountManager, |
|
| 301 | + $this->appManager, |
|
| 302 | + $this->l10nFactory, |
|
| 303 | + $this->l |
|
| 304 | + ); |
|
| 305 | + $forms[$form->getPriority()] = [$form]; |
|
| 306 | + $form = new Personal\ServerDevNotice(); |
|
| 307 | + $forms[$form->getPriority()] = [$form]; |
|
| 308 | + } |
|
| 309 | + if($section === 'security') { |
|
| 310 | + /** @var ISettings $form */ |
|
| 311 | + $form = new Personal\Security($this->userManager); |
|
| 312 | + $forms[$form->getPriority()] = [$form]; |
|
| 313 | + } |
|
| 314 | + if ($section === 'additional') { |
|
| 315 | + /** @var ISettings $form */ |
|
| 316 | + $form = new Personal\Additional(); |
|
| 317 | + $forms[$form->getPriority()] = [$form]; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $forms; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @inheritdoc |
|
| 325 | + */ |
|
| 326 | + public function getAdminSettings($section): array { |
|
| 327 | + $settings = $this->getBuiltInAdminSettings($section); |
|
| 328 | + $appSettings = $this->getSettings('admin', $section); |
|
| 329 | + |
|
| 330 | + foreach ($appSettings as $setting) { |
|
| 331 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 332 | + $settings[$setting->getPriority()] = []; |
|
| 333 | + } |
|
| 334 | + $settings[$setting->getPriority()][] = $setting; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + ksort($settings); |
|
| 338 | + return $settings; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @inheritdoc |
|
| 343 | + */ |
|
| 344 | + public function getPersonalSections(): array { |
|
| 345 | + $sections = [ |
|
| 346 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 347 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 348 | + 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
| 349 | + ]; |
|
| 350 | + |
|
| 351 | + $legacyForms = \OC_App::getForms('personal'); |
|
| 352 | + if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 353 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $appSections = $this->getSections('personal'); |
|
| 357 | + |
|
| 358 | + foreach ($appSections as $section) { |
|
| 359 | + /** @var ISection $section */ |
|
| 360 | + if (!isset($sections[$section->getPriority()])) { |
|
| 361 | + $sections[$section->getPriority()] = []; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $sections[$section->getPriority()][] = $section; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + ksort($sections); |
|
| 368 | + |
|
| 369 | + return $sections; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param string[] $forms |
|
| 374 | + * @return bool |
|
| 375 | + */ |
|
| 376 | + private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
| 377 | + foreach ($forms as $form) { |
|
| 378 | + if(trim($form) !== '') { |
|
| 379 | + return true; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + return false; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @inheritdoc |
|
| 387 | + */ |
|
| 388 | + public function getPersonalSettings($section): array { |
|
| 389 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
| 390 | + $appSettings = $this->getSettings('personal', $section); |
|
| 391 | + |
|
| 392 | + foreach ($appSettings as $setting) { |
|
| 393 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 394 | + $settings[$setting->getPriority()] = []; |
|
| 395 | + } |
|
| 396 | + $settings[$setting->getPriority()][] = $setting; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + ksort($settings); |
|
| 400 | + return $settings; |
|
| 401 | + } |
|
| 402 | 402 | } |