Signed-off-by: Julius Härtl <jus@bitgrid.net>tags/v14.0.0beta1
@@ -39,8 +39,8 @@ return ['routes' => [ | |||
'verb' => 'POST' | |||
], | |||
[ | |||
'name' => 'Theming#updateLogo', | |||
'url' => '/ajax/updateLogo', | |||
'name' => 'Theming#uploadImage', | |||
'url' => '/ajax/uploadImage', | |||
'verb' => 'POST' | |||
], | |||
[ | |||
@@ -49,13 +49,8 @@ return ['routes' => [ | |||
'verb' => 'GET', | |||
], | |||
[ | |||
'name' => 'Theming#getLogo', | |||
'url' => '/logo', | |||
'verb' => 'GET', | |||
], | |||
[ | |||
'name' => 'Theming#getLoginBackground', | |||
'url' => '/loginbackground', | |||
'name' => 'Theming#getImage', | |||
'url' => '/image/{key}', | |||
'verb' => 'GET', | |||
], | |||
[ |
@@ -33,21 +33,16 @@ use OCP\AppFramework\Http; | |||
use OCP\AppFramework\Http\NotFoundResponse; | |||
use OCP\AppFramework\Http\FileDisplayResponse; | |||
use OCP\AppFramework\Http\DataDisplayResponse; | |||
use OCP\AppFramework\Http\Response; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\Files\NotFoundException; | |||
use OCP\IRequest; | |||
use OCA\Theming\Util; | |||
use OCP\IConfig; | |||
class IconController extends Controller { | |||
/** @var ThemingDefaults */ | |||
private $themingDefaults; | |||
/** @var Util */ | |||
private $util; | |||
/** @var ITimeFactory */ | |||
private $timeFactory; | |||
/** @var IConfig */ | |||
private $config; | |||
/** @var IconBuilder */ | |||
private $iconBuilder; | |||
/** @var ImageManager */ | |||
@@ -61,19 +56,16 @@ class IconController extends Controller { | |||
* @param string $appName | |||
* @param IRequest $request | |||
* @param ThemingDefaults $themingDefaults | |||
* @param Util $util | |||
* @param ITimeFactory $timeFactory | |||
* @param IConfig $config | |||
* @param IconBuilder $iconBuilder | |||
* @param ImageManager $imageManager | |||
* @param FileAccessHelper $fileAccessHelper | |||
*/ | |||
public function __construct( | |||
$appName, | |||
IRequest $request, | |||
ThemingDefaults $themingDefaults, | |||
Util $util, | |||
ITimeFactory $timeFactory, | |||
IConfig $config, | |||
IconBuilder $iconBuilder, | |||
ImageManager $imageManager, | |||
FileAccessHelper $fileAccessHelper | |||
@@ -81,9 +73,7 @@ class IconController extends Controller { | |||
parent::__construct($appName, $request); | |||
$this->themingDefaults = $themingDefaults; | |||
$this->util = $util; | |||
$this->timeFactory = $timeFactory; | |||
$this->config = $config; | |||
$this->iconBuilder = $iconBuilder; | |||
$this->imageManager = $imageManager; | |||
$this->fileAccessHelper = $fileAccessHelper; | |||
@@ -96,16 +86,17 @@ class IconController extends Controller { | |||
* @param $app string app name | |||
* @param $image string image file name (svg required) | |||
* @return FileDisplayResponse|NotFoundResponse | |||
* @throws \Exception | |||
*/ | |||
public function getThemedIcon($app, $image) { | |||
public function getThemedIcon(string $app, string $image): Response { | |||
try { | |||
$iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image)); | |||
$iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image)); | |||
} catch (NotFoundException $exception) { | |||
$icon = $this->iconBuilder->colorSvg($app, $image); | |||
if ($icon === false || $icon === "") { | |||
if ($icon === false || $icon === '') { | |||
return new NotFoundResponse(); | |||
} | |||
$iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon); | |||
$iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); | |||
} | |||
if ($iconFile !== false) { | |||
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); | |||
@@ -116,9 +107,9 @@ class IconController extends Controller { | |||
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); | |||
$response->addHeader('Pragma', 'cache'); | |||
return $response; | |||
} else { | |||
return new NotFoundResponse(); | |||
} | |||
return new NotFoundResponse(); | |||
} | |||
/** | |||
@@ -129,10 +120,17 @@ class IconController extends Controller { | |||
* | |||
* @param $app string app name | |||
* @return FileDisplayResponse|DataDisplayResponse | |||
* @throws \Exception | |||
*/ | |||
public function getFavicon($app = "core") { | |||
public function getFavicon(string $app = 'core'): Response { | |||
$response = null; | |||
if ($this->themingDefaults->shouldReplaceIcons()) { | |||
$iconFile = null; | |||
try { | |||
$iconFile = $this->imageManager->getImage('favicon'); | |||
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); | |||
} catch (NotFoundException $e) { | |||
} | |||
if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { | |||
try { | |||
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); | |||
} catch (NotFoundException $exception) { | |||
@@ -164,9 +162,15 @@ class IconController extends Controller { | |||
* | |||
* @param $app string app name | |||
* @return FileDisplayResponse|NotFoundResponse | |||
* @throws \Exception | |||
*/ | |||
public function getTouchIcon($app = "core") { | |||
public function getTouchIcon(string $app = 'core'): Response { | |||
$response = null; | |||
try { | |||
$iconFile = $this->imageManager->getImage('favicon'); | |||
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); | |||
} catch (NotFoundException $e) { | |||
} | |||
if ($this->themingDefaults->shouldReplaceIcons()) { | |||
try { | |||
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); |
@@ -33,6 +33,7 @@ | |||
namespace OCA\Theming\Controller; | |||
use OC\Template\SCSSCacher; | |||
use OCA\Theming\ImageManager; | |||
use OCA\Theming\ThemingDefaults; | |||
use OCP\AppFramework\Controller; | |||
use OCP\AppFramework\Http; | |||
@@ -81,6 +82,8 @@ class ThemingController extends Controller { | |||
private $urlGenerator; | |||
/** @var IAppManager */ | |||
private $appManager; | |||
/** @var ImageManager */ | |||
private $imageManager; | |||
/** | |||
* ThemingController constructor. | |||
@@ -110,7 +113,8 @@ class ThemingController extends Controller { | |||
IAppData $appData, | |||
SCSSCacher $scssCacher, | |||
IURLGenerator $urlGenerator, | |||
IAppManager $appManager | |||
IAppManager $appManager, | |||
ImageManager $imageManager | |||
) { | |||
parent::__construct($appName, $request); | |||
@@ -124,13 +128,15 @@ class ThemingController extends Controller { | |||
$this->scssCacher = $scssCacher; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->appManager = $appManager; | |||
$this->imageManager = $imageManager; | |||
} | |||
/** | |||
* @param string $setting | |||
* @param string $value | |||
* @return DataResponse | |||
* @internal param string $color | |||
* @throws NotFoundException | |||
* @throws NotPermittedException | |||
*/ | |||
public function updateStylesheet($setting, $value) { | |||
$value = trim($value); | |||
@@ -195,27 +201,15 @@ class ThemingController extends Controller { | |||
} | |||
/** | |||
* Update the logos and background image | |||
* | |||
* @return DataResponse | |||
* @throws NotPermittedException | |||
*/ | |||
public function updateLogo() { | |||
$backgroundColor = $this->request->getParam('backgroundColor', false); | |||
if($backgroundColor) { | |||
$this->themingDefaults->set('backgroundMime', 'backgroundColor'); | |||
return new DataResponse( | |||
[ | |||
'data' => | |||
[ | |||
'name' => 'backgroundColor', | |||
'message' => $this->l10n->t('Saved') | |||
], | |||
'status' => 'success' | |||
] | |||
); | |||
} | |||
$newLogo = $this->request->getUploadedFile('uploadlogo'); | |||
$newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); | |||
public function uploadImage(): DataResponse { | |||
// logo / background | |||
// new: favicon logo-header | |||
// | |||
$key = $this->request->getParam('key'); | |||
$image = $this->request->getUploadedFile('image'); | |||
$error = null; | |||
$phpFileUploadErrors = [ | |||
UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), | |||
@@ -227,14 +221,11 @@ class ThemingController extends Controller { | |||
UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), | |||
UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), | |||
]; | |||
if (empty($newLogo) && empty($newBackgroundLogo)) { | |||
if (empty($image)) { | |||
$error = $this->l10n->t('No file uploaded'); | |||
} | |||
if (!empty($newLogo) && array_key_exists('error', $newLogo) && $newLogo['error'] !== UPLOAD_ERR_OK) { | |||
$error = $phpFileUploadErrors[$newLogo['error']]; | |||
} | |||
if (!empty($newBackgroundLogo) && array_key_exists('error', $newBackgroundLogo) && $newBackgroundLogo['error'] !== UPLOAD_ERR_OK) { | |||
$error = $phpFileUploadErrors[$newBackgroundLogo['error']]; | |||
if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { | |||
$error = $phpFileUploadErrors[$image['error']]; | |||
} | |||
if ($error !== null) { | |||
@@ -256,61 +247,53 @@ class ThemingController extends Controller { | |||
$folder = $this->appData->newFolder('images'); | |||
} | |||
if (!empty($newLogo)) { | |||
$target = $folder->newFile('logo'); | |||
$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; | |||
if (!in_array($newLogo['type'], $supportedFormats)) { | |||
return new DataResponse( | |||
[ | |||
'data' => [ | |||
'message' => $this->l10n->t('Unsupported image type'), | |||
], | |||
'status' => 'failure', | |||
$target = $folder->newFile($key); | |||
$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; | |||
if (!in_array($image['type'], $supportedFormats)) { | |||
return new DataResponse( | |||
[ | |||
'data' => [ | |||
'message' => $this->l10n->t('Unsupported image type'), | |||
], | |||
Http::STATUS_UNPROCESSABLE_ENTITY | |||
); | |||
} | |||
$target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); | |||
$this->themingDefaults->set('logoMime', $newLogo['type']); | |||
$name = $newLogo['name']; | |||
'status' => 'failure', | |||
], | |||
Http::STATUS_UNPROCESSABLE_ENTITY | |||
); | |||
} | |||
if (!empty($newBackgroundLogo)) { | |||
$target = $folder->newFile('background'); | |||
$image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); | |||
if ($image === false) { | |||
return new DataResponse( | |||
[ | |||
'data' => [ | |||
'message' => $this->l10n->t('Unsupported image type'), | |||
], | |||
'status' => 'failure', | |||
], | |||
Http::STATUS_UNPROCESSABLE_ENTITY | |||
); | |||
} | |||
$resizeKeys = ['background']; | |||
if (in_array($key, $resizeKeys, true)) { | |||
// Optimize the image since some people may upload images that will be | |||
// either to big or are not progressive rendering. | |||
$newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); | |||
$tmpFile = $this->tempManager->getTemporaryFile(); | |||
$newWidth = imagesx($image) < 4096 ? imagesx($image) : 4096; | |||
$newHeight = imagesy($image) / (imagesx($image) / $newWidth); | |||
$image = imagescale($image, $newWidth, $newHeight); | |||
$newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; | |||
$newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); | |||
$outputImage = imagescale($newImage, $newWidth, $newHeight); | |||
imageinterlace($image, 1); | |||
imagejpeg($image, $tmpFile, 75); | |||
imagedestroy($image); | |||
imageinterlace($outputImage, 1); | |||
imagejpeg($outputImage, $tmpFile, 75); | |||
imagedestroy($outputImage); | |||
$target->putContent(file_get_contents($tmpFile, 'r')); | |||
$this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']); | |||
$name = $newBackgroundLogo['name']; | |||
} else { | |||
$target->putContent(file_get_contents($image['tmp_name'], 'r')); | |||
} | |||
$name = $image['name']; | |||
$this->themingDefaults->set($key.'Mime', $image['type']); | |||
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); | |||
return new DataResponse( | |||
[ | |||
'data' => | |||
[ | |||
'name' => $name, | |||
'message' => $this->l10n->t('Saved') | |||
'url' => $this->imageManager->getImageUrl($key), | |||
'message' => $this->l10n->t('Saved'), | |||
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) | |||
], | |||
'status' => 'success' | |||
] | |||
@@ -322,23 +305,17 @@ class ThemingController extends Controller { | |||
* | |||
* @param string $setting setting which should be reverted | |||
* @return DataResponse | |||
* @throws NotPermittedException | |||
*/ | |||
public function undo($setting) { | |||
public function undo(string $setting): DataResponse { | |||
$value = $this->themingDefaults->undo($setting); | |||
// reprocess server scss for preview | |||
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); | |||
if($setting === 'logoMime') { | |||
if (strpos($setting, 'Mime') !== -1) { | |||
$imageKey = str_replace('Mime', '', $setting); | |||
try { | |||
$file = $this->appData->getFolder('images')->getFile('logo'); | |||
$file->delete(); | |||
} catch (NotFoundException $e) { | |||
} catch (NotPermittedException $e) { | |||
} | |||
} | |||
if($setting === 'backgroundMime') { | |||
try { | |||
$file = $this->appData->getFolder('images')->getFile('background'); | |||
$file = $this->appData->getFolder('images')->getFile($imageKey); | |||
$file->delete(); | |||
} catch (NotFoundException $e) { | |||
} catch (NotPermittedException $e) { | |||
@@ -362,37 +339,14 @@ class ThemingController extends Controller { | |||
* @PublicPage | |||
* @NoCSRFRequired | |||
* | |||
* @param string $key | |||
* @return FileDisplayResponse|NotFoundResponse | |||
* @throws \Exception | |||
*/ | |||
public function getLogo() { | |||
try { | |||
/** @var File $file */ | |||
$file = $this->appData->getFolder('images')->getFile('logo'); | |||
} catch (NotFoundException $e) { | |||
return new NotFoundResponse(); | |||
} | |||
$response = new FileDisplayResponse($file); | |||
$response->cacheFor(3600); | |||
$expires = new \DateTime(); | |||
$expires->setTimestamp($this->timeFactory->getTime()); | |||
$expires->add(new \DateInterval('PT24H')); | |||
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); | |||
$response->addHeader('Pragma', 'cache'); | |||
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); | |||
return $response; | |||
} | |||
/** | |||
* @PublicPage | |||
* @NoCSRFRequired | |||
* | |||
* @return FileDisplayResponse|NotFoundResponse | |||
*/ | |||
public function getLoginBackground() { | |||
public function getImage(string $key) { | |||
try { | |||
/** @var File $file */ | |||
$file = $this->appData->getFolder('images')->getFile('background'); | |||
$file = $this->appData->getFolder('images')->getFile($key); | |||
} catch (NotFoundException $e) { | |||
return new NotFoundResponse(); | |||
} | |||
@@ -404,7 +358,7 @@ class ThemingController extends Controller { | |||
$expires->add(new \DateInterval('PT24H')); | |||
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); | |||
$response->addHeader('Pragma', 'cache'); | |||
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); | |||
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); | |||
return $response; | |||
} | |||
@@ -413,6 +367,9 @@ class ThemingController extends Controller { | |||
* @PublicPage | |||
* | |||
* @return FileDisplayResponse|NotFoundResponse | |||
* @throws NotPermittedException | |||
* @throws \Exception | |||
* @throws \OCP\App\AppPathNotFoundException | |||
*/ | |||
public function getStylesheet() { | |||
$appPath = $this->appManager->getAppPath('theming'); |
@@ -24,11 +24,16 @@ | |||
namespace OCA\Theming; | |||
use OCP\Files\SimpleFS\ISimpleFile; | |||
use OCP\IConfig; | |||
use OCP\Files\IAppData; | |||
use OCP\Files\NotFoundException; | |||
use OCP\Files\NotPermittedException; | |||
use OCP\IURLGenerator; | |||
/** | |||
* @property IURLGenerator urlGenerator | |||
*/ | |||
class ImageManager { | |||
/** @var IConfig */ | |||
@@ -36,27 +41,79 @@ class ImageManager { | |||
/** @var IAppData */ | |||
private $appData; | |||
/** @var array */ | |||
private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon']; | |||
/** | |||
* ImageManager constructor. | |||
* | |||
* @param IConfig $config | |||
* @param IAppData $appData | |||
* @param IURLGenerator $urlGenerator | |||
*/ | |||
public function __construct(IConfig $config, | |||
IAppData $appData | |||
IAppData $appData, | |||
IURLGenerator $urlGenerator | |||
) { | |||
$this->config = $config; | |||
$this->appData = $appData; | |||
$this->urlGenerator = $urlGenerator; | |||
} | |||
public function getImageUrl(string $key): string { | |||
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |||
try { | |||
$this->getImage($key); | |||
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; | |||
} catch (NotFoundException $e) { | |||
} | |||
switch ($key) { | |||
case 'logo': | |||
case 'logoheader': | |||
case 'favicon': | |||
return $this->urlGenerator->imagePath('core', 'logo.png') . '?v=' . $cacheBusterCounter; | |||
case 'background': | |||
return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; | |||
} | |||
} | |||
public function getImageUrlAbsolute(string $key): string { | |||
return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key)); | |||
} | |||
/** | |||
* @param $key | |||
* @return ISimpleFile | |||
* @throws NotFoundException | |||
*/ | |||
public function getImage(string $key): ISimpleFile { | |||
$logo = $this->config->getAppValue('theming', $key . 'Mime', false); | |||
if ($logo === false) { | |||
throw new NotFoundException(); | |||
} | |||
$folder = $this->appData->getFolder('images'); | |||
return $folder->getFile($key); | |||
} | |||
public function getCustomImages(): array { | |||
$images = []; | |||
foreach ($this->supportedImageKeys as $key) { | |||
$images[$key] = [ | |||
'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''), | |||
'url' => $this->getImageUrl($key), | |||
]; | |||
} | |||
return $images; | |||
} | |||
/** | |||
* Get folder for current theming files | |||
* | |||
* @return \OCP\Files\SimpleFS\ISimpleFolder | |||
* @return ISimpleFolder | |||
* @throws NotPermittedException | |||
* @throws \RuntimeException | |||
*/ | |||
public function getCacheFolder() { | |||
public function getCacheFolder(): ISimpleFolder { | |||
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); | |||
try { | |||
$folder = $this->appData->getFolder($cacheBusterValue); | |||
@@ -73,8 +130,9 @@ class ImageManager { | |||
* @param string $filename | |||
* @throws NotFoundException | |||
* @return \OCP\Files\SimpleFS\ISimpleFile | |||
* @throws NotPermittedException | |||
*/ | |||
public function getCachedImage($filename) { | |||
public function getCachedImage($filename): ISimpleFile { | |||
$currentFolder = $this->getCacheFolder(); | |||
return $currentFolder->getFile($filename); | |||
} | |||
@@ -85,8 +143,10 @@ class ImageManager { | |||
* @param string $filename | |||
* @param string $data | |||
* @return \OCP\Files\SimpleFS\ISimpleFile | |||
* @throws NotFoundException | |||
* @throws NotPermittedException | |||
*/ | |||
public function setCachedImage($filename, $data) { | |||
public function setCachedImage($filename, $data): ISimpleFile { | |||
$currentFolder = $this->getCacheFolder(); | |||
if ($currentFolder->fileExists($filename)) { | |||
$file = $currentFolder->getFile($filename); |
@@ -29,6 +29,7 @@ | |||
namespace OCA\Theming\Settings; | |||
use OCA\Theming\ImageManager; | |||
use OCA\Theming\ThemingDefaults; | |||
use OCP\AppFramework\Http\TemplateResponse; | |||
use OCP\IConfig; | |||
@@ -45,23 +46,25 @@ class Admin implements ISettings { | |||
private $themingDefaults; | |||
/** @var IURLGenerator */ | |||
private $urlGenerator; | |||
/** @var ImageManager */ | |||
private $imageManager; | |||
public function __construct(IConfig $config, | |||
IL10N $l, | |||
ThemingDefaults $themingDefaults, | |||
IURLGenerator $urlGenerator) { | |||
IURLGenerator $urlGenerator, | |||
ImageManager $imageManager) { | |||
$this->config = $config; | |||
$this->l = $l; | |||
$this->themingDefaults = $themingDefaults; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->imageManager = $imageManager; | |||
} | |||
/** | |||
* @return TemplateResponse | |||
*/ | |||
public function getForm() { | |||
$path = $this->urlGenerator->linkToRoute('theming.Theming.updateLogo'); | |||
public function getForm(): TemplateResponse { | |||
$themable = true; | |||
$errorMessage = ''; | |||
$theme = $this->config->getSystemValue('theme', ''); | |||
@@ -77,13 +80,10 @@ class Admin implements ISettings { | |||
'url' => $this->themingDefaults->getBaseUrl(), | |||
'slogan' => $this->themingDefaults->getSlogan(), | |||
'color' => $this->themingDefaults->getColorPrimary(), | |||
'logo' => $this->themingDefaults->getLogo(), | |||
'logoMime' => $this->config->getAppValue('theming', 'logoMime', ''), | |||
'background' => $this->themingDefaults->getBackground(), | |||
'backgroundMime' => $this->config->getAppValue('theming', 'backgroundMime', ''), | |||
'uploadLogoRoute' => $path, | |||
'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), | |||
'canThemeIcons' => $this->themingDefaults->shouldReplaceIcons(), | |||
'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons') | |||
'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), | |||
'images' => $this->imageManager->getCustomImages(), | |||
]; | |||
return new TemplateResponse('theming', 'settings-admin', $parameters, ''); | |||
@@ -92,7 +92,7 @@ class Admin implements ISettings { | |||
/** | |||
* @return string the section ID, e.g. 'sharing' | |||
*/ | |||
public function getSection() { | |||
public function getSection(): string { | |||
return 'theming'; | |||
} | |||
@@ -103,7 +103,7 @@ class Admin implements ISettings { | |||
* | |||
* E.g.: 70 | |||
*/ | |||
public function getPriority() { | |||
public function getPriority(): int { | |||
return 5; | |||
} | |||
@@ -36,7 +36,6 @@ namespace OCA\Theming; | |||
use OCP\App\AppPathNotFoundException; | |||
use OCP\App\IAppManager; | |||
use OCP\Files\IAppData; | |||
use OCP\ICacheFactory; | |||
use OCP\IConfig; | |||
use OCP\IL10N; | |||
@@ -48,10 +47,10 @@ class ThemingDefaults extends \OC_Defaults { | |||
private $config; | |||
/** @var IL10N */ | |||
private $l; | |||
/** @var ImageManager */ | |||
private $imageManager; | |||
/** @var IURLGenerator */ | |||
private $urlGenerator; | |||
/** @var IAppData */ | |||
private $appData; | |||
/** @var ICacheFactory */ | |||
private $cacheFactory; | |||
/** @var Util */ | |||
@@ -83,9 +82,8 @@ class ThemingDefaults extends \OC_Defaults { | |||
* | |||
* @param IConfig $config | |||
* @param IL10N $l | |||
* @param ImageManager $imageManager | |||
* @param IURLGenerator $urlGenerator | |||
* @param \OC_Defaults $defaults | |||
* @param IAppData $appData | |||
* @param ICacheFactory $cacheFactory | |||
* @param Util $util | |||
* @param IAppManager $appManager | |||
@@ -93,16 +91,16 @@ class ThemingDefaults extends \OC_Defaults { | |||
public function __construct(IConfig $config, | |||
IL10N $l, | |||
IURLGenerator $urlGenerator, | |||
IAppData $appData, | |||
ICacheFactory $cacheFactory, | |||
Util $util, | |||
ImageManager $imageManager, | |||
IAppManager $appManager | |||
) { | |||
parent::__construct(); | |||
$this->config = $config; | |||
$this->l = $l; | |||
$this->imageManager = $imageManager; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->appData = $appData; | |||
$this->cacheFactory = $cacheFactory; | |||
$this->util = $util; | |||
$this->appManager = $appManager; | |||
@@ -166,12 +164,12 @@ class ThemingDefaults extends \OC_Defaults { | |||
* @param bool $useSvg Whether to point to the SVG image or a fallback | |||
* @return string | |||
*/ | |||
public function getLogo($useSvg = true) { | |||
public function getLogo($useSvg = true): string { | |||
$logo = $this->config->getAppValue('theming', 'logoMime', false); | |||
$logoExists = true; | |||
try { | |||
$this->appData->getFolder('images')->getFile('logo'); | |||
$this->imageManager->getImage('logo'); | |||
} catch (\Exception $e) { | |||
$logoExists = false; | |||
} | |||
@@ -187,7 +185,7 @@ class ThemingDefaults extends \OC_Defaults { | |||
return $logo . '?v=' . $cacheBusterCounter; | |||
} | |||
return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; | |||
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter; | |||
} | |||
/** | |||
@@ -195,14 +193,8 @@ class ThemingDefaults extends \OC_Defaults { | |||
* | |||
* @return string | |||
*/ | |||
public function getBackground() { | |||
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |||
if($this->util->isBackgroundThemed()) { | |||
return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; | |||
} | |||
return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; | |||
public function getBackground(): string { | |||
$this->imageManager->getImageUrl('background'); | |||
} | |||
/** | |||
@@ -238,12 +230,16 @@ class ThemingDefaults extends \OC_Defaults { | |||
$variables = [ | |||
'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", | |||
'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", | |||
'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" | |||
'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", | |||
'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", | |||
'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", | |||
'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" | |||
]; | |||
$variables['image-logo'] = "'".$this->getLogo()."'"; | |||
$variables['image-login-background'] = "'".$this->getBackground()."'"; | |||
$variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'"; | |||
$variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; | |||
$variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; | |||
$variables['image-login-background'] = "'".$this->imageManager->getImageUrl('background')."'"; | |||
$variables['image-login-plain'] = 'false'; | |||
if ($this->config->getAppValue('theming', 'color', null) !== null) { |
@@ -114,6 +114,7 @@ use OC\SystemTag\ManagerFactory as SystemTagManagerFactory; | |||
use OC\Tagging\TagMapper; | |||
use OC\Template\JSCombiner; | |||
use OC\Template\SCSSCacher; | |||
use OCA\Theming\ImageManager; | |||
use OCA\Theming\ThemingDefaults; | |||
use OCP\App\IAppManager; | |||
@@ -943,10 +944,10 @@ class Server extends ServerContainer implements IServerContainer { | |||
$c->getConfig(), | |||
$c->getL10N('theming'), | |||
$c->getURLGenerator(), | |||
$c->getAppDataDir('theming'), | |||
$c->getMemCacheFactory(), | |||
new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), | |||
$this->getAppManager() | |||
new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), | |||
new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), | |||
$c->getAppManager() | |||
); | |||
} | |||
return new \OC_Defaults(); |