@@ -32,109 +32,109 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class UpdateConfig extends Command { |
| 35 | - public const SUPPORTED_KEYS = [ |
|
| 36 | - 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color' |
|
| 37 | - ]; |
|
| 38 | - |
|
| 39 | - public const SUPPORTED_IMAGE_KEYS = [ |
|
| 40 | - 'background', 'logo', 'favicon', 'logoheader' |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - private $themingDefaults; |
|
| 44 | - private $imageManager; |
|
| 45 | - private $config; |
|
| 46 | - |
|
| 47 | - public function __construct(ThemingDefaults $themingDefaults, ImageManager $imageManager, IConfig $config) { |
|
| 48 | - parent::__construct(); |
|
| 49 | - |
|
| 50 | - $this->themingDefaults = $themingDefaults; |
|
| 51 | - $this->imageManager = $imageManager; |
|
| 52 | - $this->config = $config; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - protected function configure() { |
|
| 56 | - $this |
|
| 57 | - ->setName('theming:config') |
|
| 58 | - ->setDescription('Set theming app config values') |
|
| 59 | - ->addArgument( |
|
| 60 | - 'key', |
|
| 61 | - InputArgument::OPTIONAL, |
|
| 62 | - 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 63 | - 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 64 | - ) |
|
| 65 | - ->addArgument( |
|
| 66 | - 'value', |
|
| 67 | - InputArgument::OPTIONAL, |
|
| 68 | - 'Value to set (leave empty to obtain the current value)' |
|
| 69 | - ) |
|
| 70 | - ->addOption( |
|
| 71 | - 'reset', |
|
| 72 | - 'r', |
|
| 73 | - InputOption::VALUE_NONE, |
|
| 74 | - 'Reset the given config key to default' |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 80 | - $key = $input->getArgument('key'); |
|
| 81 | - $value = $input->getArgument('value'); |
|
| 82 | - |
|
| 83 | - if ($key === null) { |
|
| 84 | - $output->writeln('Current theming config:'); |
|
| 85 | - foreach (self::SUPPORTED_KEYS as $key) { |
|
| 86 | - $value = $this->config->getAppValue('theming', $key, ''); |
|
| 87 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 88 | - } |
|
| 89 | - foreach (self::SUPPORTED_IMAGE_KEYS as $key) { |
|
| 90 | - $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 91 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 92 | - } |
|
| 93 | - return 0; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 97 | - $output->writeln('<error>Invalid config key provided</error>'); |
|
| 98 | - return 1; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ($input->getOption('reset')) { |
|
| 102 | - $defaultValue = $this->themingDefaults->undo($key); |
|
| 103 | - $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 104 | - return 0; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($value === null) { |
|
| 108 | - $value = $this->config->getAppValue('theming', $key, ''); |
|
| 109 | - if ($value !== '') { |
|
| 110 | - $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 111 | - } else { |
|
| 112 | - $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 113 | - } |
|
| 114 | - return 0; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if (in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 118 | - if (strpos($value, '/') !== 0) { |
|
| 119 | - $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 120 | - return 1; |
|
| 121 | - } |
|
| 122 | - if (!file_exists($value)) { |
|
| 123 | - $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 124 | - return 1; |
|
| 125 | - } |
|
| 126 | - $value = $this->imageManager->updateImage($key, $value); |
|
| 127 | - $key = $key . 'Mime'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 131 | - $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 132 | - return 1; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $this->themingDefaults->set($key, $value); |
|
| 136 | - $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 137 | - |
|
| 138 | - return 0; |
|
| 139 | - } |
|
| 35 | + public const SUPPORTED_KEYS = [ |
|
| 36 | + 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color' |
|
| 37 | + ]; |
|
| 38 | + |
|
| 39 | + public const SUPPORTED_IMAGE_KEYS = [ |
|
| 40 | + 'background', 'logo', 'favicon', 'logoheader' |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + private $themingDefaults; |
|
| 44 | + private $imageManager; |
|
| 45 | + private $config; |
|
| 46 | + |
|
| 47 | + public function __construct(ThemingDefaults $themingDefaults, ImageManager $imageManager, IConfig $config) { |
|
| 48 | + parent::__construct(); |
|
| 49 | + |
|
| 50 | + $this->themingDefaults = $themingDefaults; |
|
| 51 | + $this->imageManager = $imageManager; |
|
| 52 | + $this->config = $config; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + protected function configure() { |
|
| 56 | + $this |
|
| 57 | + ->setName('theming:config') |
|
| 58 | + ->setDescription('Set theming app config values') |
|
| 59 | + ->addArgument( |
|
| 60 | + 'key', |
|
| 61 | + InputArgument::OPTIONAL, |
|
| 62 | + 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 63 | + 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 64 | + ) |
|
| 65 | + ->addArgument( |
|
| 66 | + 'value', |
|
| 67 | + InputArgument::OPTIONAL, |
|
| 68 | + 'Value to set (leave empty to obtain the current value)' |
|
| 69 | + ) |
|
| 70 | + ->addOption( |
|
| 71 | + 'reset', |
|
| 72 | + 'r', |
|
| 73 | + InputOption::VALUE_NONE, |
|
| 74 | + 'Reset the given config key to default' |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 80 | + $key = $input->getArgument('key'); |
|
| 81 | + $value = $input->getArgument('value'); |
|
| 82 | + |
|
| 83 | + if ($key === null) { |
|
| 84 | + $output->writeln('Current theming config:'); |
|
| 85 | + foreach (self::SUPPORTED_KEYS as $key) { |
|
| 86 | + $value = $this->config->getAppValue('theming', $key, ''); |
|
| 87 | + $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 88 | + } |
|
| 89 | + foreach (self::SUPPORTED_IMAGE_KEYS as $key) { |
|
| 90 | + $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 91 | + $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 92 | + } |
|
| 93 | + return 0; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 97 | + $output->writeln('<error>Invalid config key provided</error>'); |
|
| 98 | + return 1; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ($input->getOption('reset')) { |
|
| 102 | + $defaultValue = $this->themingDefaults->undo($key); |
|
| 103 | + $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 104 | + return 0; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($value === null) { |
|
| 108 | + $value = $this->config->getAppValue('theming', $key, ''); |
|
| 109 | + if ($value !== '') { |
|
| 110 | + $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 111 | + } else { |
|
| 112 | + $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 113 | + } |
|
| 114 | + return 0; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if (in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 118 | + if (strpos($value, '/') !== 0) { |
|
| 119 | + $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 120 | + return 1; |
|
| 121 | + } |
|
| 122 | + if (!file_exists($value)) { |
|
| 123 | + $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 124 | + return 1; |
|
| 125 | + } |
|
| 126 | + $value = $this->imageManager->updateImage($key, $value); |
|
| 127 | + $key = $key . 'Mime'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 131 | + $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 132 | + return 1; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $this->themingDefaults->set($key, $value); |
|
| 136 | + $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 137 | + |
|
| 138 | + return 0; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | ->addArgument( |
| 60 | 60 | 'key', |
| 61 | 61 | InputArgument::OPTIONAL, |
| 62 | - 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 63 | - 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 62 | + 'Key to update the theming app configuration (leave empty to get a list of all configured values)'.PHP_EOL. |
|
| 63 | + 'One of: '.implode(', ', self::SUPPORTED_KEYS) |
|
| 64 | 64 | ) |
| 65 | 65 | ->addArgument( |
| 66 | 66 | 'value', |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | $output->writeln('Current theming config:'); |
| 85 | 85 | foreach (self::SUPPORTED_KEYS as $key) { |
| 86 | 86 | $value = $this->config->getAppValue('theming', $key, ''); |
| 87 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 87 | + $output->writeln('- '.$key.': '.$value.''); |
|
| 88 | 88 | } |
| 89 | 89 | foreach (self::SUPPORTED_IMAGE_KEYS as $key) { |
| 90 | - $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 91 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 90 | + $value = $this->config->getAppValue('theming', $key.'Mime', ''); |
|
| 91 | + $output->writeln('- '.$key.': '.$value.''); |
|
| 92 | 92 | } |
| 93 | 93 | return 0; |
| 94 | 94 | } |
@@ -100,40 +100,40 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | if ($input->getOption('reset')) { |
| 102 | 102 | $defaultValue = $this->themingDefaults->undo($key); |
| 103 | - $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 103 | + $output->writeln('<info>Reset '.$key.' to '.$defaultValue.'</info>'); |
|
| 104 | 104 | return 0; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | if ($value === null) { |
| 108 | 108 | $value = $this->config->getAppValue('theming', $key, ''); |
| 109 | 109 | if ($value !== '') { |
| 110 | - $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 110 | + $output->writeln('<info>'.$key.' is currently set to '.$value.'</info>'); |
|
| 111 | 111 | } else { |
| 112 | - $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 112 | + $output->writeln('<info>'.$key.' is currently not set</info>'); |
|
| 113 | 113 | } |
| 114 | 114 | return 0; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if (in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
| 118 | 118 | if (strpos($value, '/') !== 0) { |
| 119 | - $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 119 | + $output->writeln('<error>The image file needs to be provided as an absolute path: '.$value.'.</error>'); |
|
| 120 | 120 | return 1; |
| 121 | 121 | } |
| 122 | 122 | if (!file_exists($value)) { |
| 123 | - $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 123 | + $output->writeln('<error>File could not be found: '.$value.'.</error>'); |
|
| 124 | 124 | return 1; |
| 125 | 125 | } |
| 126 | 126 | $value = $this->imageManager->updateImage($key, $value); |
| 127 | - $key = $key . 'Mime'; |
|
| 127 | + $key = $key.'Mime'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
| 131 | - $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 131 | + $output->writeln('<error>The given color is invalid: '.$value.'</error>'); |
|
| 132 | 132 | return 1; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $this->themingDefaults->set($key, $value); |
| 136 | - $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 136 | + $output->writeln('<info>Updated '.$key.' to '.$value.'</info>'); |
|
| 137 | 137 | |
| 138 | 138 | return 0; |
| 139 | 139 | } |
@@ -51,405 +51,405 @@ |
||
| 51 | 51 | |
| 52 | 52 | class ThemingDefaults extends \OC_Defaults { |
| 53 | 53 | |
| 54 | - /** @var IConfig */ |
|
| 55 | - private $config; |
|
| 56 | - /** @var IL10N */ |
|
| 57 | - private $l; |
|
| 58 | - /** @var ImageManager */ |
|
| 59 | - private $imageManager; |
|
| 60 | - /** @var IURLGenerator */ |
|
| 61 | - private $urlGenerator; |
|
| 62 | - /** @var ICacheFactory */ |
|
| 63 | - private $cacheFactory; |
|
| 64 | - /** @var Util */ |
|
| 65 | - private $util; |
|
| 66 | - /** @var IAppManager */ |
|
| 67 | - private $appManager; |
|
| 68 | - /** @var INavigationManager */ |
|
| 69 | - private $navigationManager; |
|
| 70 | - |
|
| 71 | - /** @var string */ |
|
| 72 | - private $name; |
|
| 73 | - /** @var string */ |
|
| 74 | - private $title; |
|
| 75 | - /** @var string */ |
|
| 76 | - private $entity; |
|
| 77 | - /** @var string */ |
|
| 78 | - private $productName; |
|
| 79 | - /** @var string */ |
|
| 80 | - private $url; |
|
| 81 | - /** @var string */ |
|
| 82 | - private $color; |
|
| 83 | - |
|
| 84 | - /** @var string */ |
|
| 85 | - private $iTunesAppId; |
|
| 86 | - /** @var string */ |
|
| 87 | - private $iOSClientUrl; |
|
| 88 | - /** @var string */ |
|
| 89 | - private $AndroidClientUrl; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * ThemingDefaults constructor. |
|
| 93 | - * |
|
| 94 | - * @param IConfig $config |
|
| 95 | - * @param IL10N $l |
|
| 96 | - * @param ImageManager $imageManager |
|
| 97 | - * @param IURLGenerator $urlGenerator |
|
| 98 | - * @param ICacheFactory $cacheFactory |
|
| 99 | - * @param Util $util |
|
| 100 | - * @param IAppManager $appManager |
|
| 101 | - */ |
|
| 102 | - public function __construct(IConfig $config, |
|
| 103 | - IL10N $l, |
|
| 104 | - IURLGenerator $urlGenerator, |
|
| 105 | - ICacheFactory $cacheFactory, |
|
| 106 | - Util $util, |
|
| 107 | - ImageManager $imageManager, |
|
| 108 | - IAppManager $appManager, |
|
| 109 | - INavigationManager $navigationManager |
|
| 110 | - ) { |
|
| 111 | - parent::__construct(); |
|
| 112 | - $this->config = $config; |
|
| 113 | - $this->l = $l; |
|
| 114 | - $this->imageManager = $imageManager; |
|
| 115 | - $this->urlGenerator = $urlGenerator; |
|
| 116 | - $this->cacheFactory = $cacheFactory; |
|
| 117 | - $this->util = $util; |
|
| 118 | - $this->appManager = $appManager; |
|
| 119 | - $this->navigationManager = $navigationManager; |
|
| 120 | - |
|
| 121 | - $this->name = parent::getName(); |
|
| 122 | - $this->title = parent::getTitle(); |
|
| 123 | - $this->entity = parent::getEntity(); |
|
| 124 | - $this->productName = parent::getProductName(); |
|
| 125 | - $this->url = parent::getBaseUrl(); |
|
| 126 | - $this->color = parent::getColorPrimary(); |
|
| 127 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 128 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 129 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function getName() { |
|
| 133 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getHTMLName() { |
|
| 137 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function getTitle() { |
|
| 141 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function getEntity() { |
|
| 145 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getProductName() { |
|
| 149 | - return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName)); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function getBaseUrl() { |
|
| 153 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function getSlogan(?string $lang = null) { |
|
| 157 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function getImprintUrl() { |
|
| 161 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function getPrivacyUrl() { |
|
| 165 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public function getShortFooter() { |
|
| 169 | - $slogan = $this->getSlogan(); |
|
| 170 | - $baseUrl = $this->getBaseUrl(); |
|
| 171 | - if ($baseUrl !== '') { |
|
| 172 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
| 173 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
| 174 | - } else { |
|
| 175 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
| 176 | - } |
|
| 177 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 178 | - |
|
| 179 | - $links = [ |
|
| 180 | - [ |
|
| 181 | - 'text' => $this->l->t('Legal notice'), |
|
| 182 | - 'url' => (string)$this->getImprintUrl() |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'text' => $this->l->t('Privacy policy'), |
|
| 186 | - 'url' => (string)$this->getPrivacyUrl() |
|
| 187 | - ], |
|
| 188 | - ]; |
|
| 189 | - |
|
| 190 | - $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
| 191 | - $guestNavigation = array_map(function ($nav) { |
|
| 192 | - return [ |
|
| 193 | - 'text' => $nav['name'], |
|
| 194 | - 'url' => $nav['href'] |
|
| 195 | - ]; |
|
| 196 | - }, $navigation); |
|
| 197 | - $links = array_merge($links, $guestNavigation); |
|
| 198 | - |
|
| 199 | - $legalLinks = ''; |
|
| 200 | - $divider = ''; |
|
| 201 | - foreach ($links as $link) { |
|
| 202 | - if ($link['url'] !== '' |
|
| 203 | - && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
| 204 | - ) { |
|
| 205 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
| 206 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
| 207 | - $divider = ' · '; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - if ($legalLinks !== '') { |
|
| 211 | - $footer .= '<br/>' . $legalLinks; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $footer; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Color that is used for the header as well as for mail headers |
|
| 219 | - * |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - public function getColorPrimary() { |
|
| 223 | - $color = $this->config->getAppValue('theming', 'color', $this->color); |
|
| 224 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
| 225 | - $color = '#0082c9'; |
|
| 226 | - } |
|
| 227 | - return $color; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Themed logo url |
|
| 232 | - * |
|
| 233 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public function getLogo($useSvg = true): string { |
|
| 237 | - $logo = $this->config->getAppValue('theming', 'logoMime', ''); |
|
| 238 | - |
|
| 239 | - // short cut to avoid setting up the filesystem just to check if the logo is there |
|
| 240 | - // |
|
| 241 | - // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. |
|
| 242 | - // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which |
|
| 243 | - // needs to be called then) |
|
| 244 | - if ($useSvg === true && $logo !== false) { |
|
| 245 | - $logoExists = true; |
|
| 246 | - } else { |
|
| 247 | - try { |
|
| 248 | - $this->imageManager->getImage('logo', $useSvg); |
|
| 249 | - $logoExists = true; |
|
| 250 | - } catch (\Exception $e) { |
|
| 251 | - $logoExists = false; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 256 | - |
|
| 257 | - if (!$logo || !$logoExists) { |
|
| 258 | - if ($useSvg) { |
|
| 259 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
| 260 | - } else { |
|
| 261 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
| 262 | - } |
|
| 263 | - return $logo . '?v=' . $cacheBusterCounter; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Themed background image url |
|
| 271 | - * |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 274 | - public function getBackground(): string { |
|
| 275 | - return $this->imageManager->getImageUrl('background'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return string |
|
| 280 | - */ |
|
| 281 | - public function getiTunesAppId() { |
|
| 282 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function getiOSClientUrl() { |
|
| 289 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @return string |
|
| 294 | - */ |
|
| 295 | - public function getAndroidClientUrl() { |
|
| 296 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @return array scss variables to overwrite |
|
| 302 | - */ |
|
| 303 | - public function getScssVariables() { |
|
| 304 | - $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 305 | - $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); |
|
| 306 | - if ($value = $cache->get('getScssVariables')) { |
|
| 307 | - return $value; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $variables = [ |
|
| 311 | - 'theming-cachebuster' => "'" . $cacheBuster . "'", |
|
| 312 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
| 313 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
| 314 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
| 315 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
| 316 | - ]; |
|
| 317 | - |
|
| 318 | - $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
| 319 | - $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
| 320 | - $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
| 321 | - $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
| 322 | - $variables['image-login-plain'] = 'false'; |
|
| 323 | - |
|
| 324 | - if ($this->config->getAppValue('theming', 'color', '') !== '') { |
|
| 325 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
| 326 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 327 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { |
|
| 331 | - $variables['image-login-plain'] = 'true'; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $variables['has-legal-links'] = 'false'; |
|
| 335 | - if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
| 336 | - $variables['has-legal-links'] = 'true'; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - $cache->set('getScssVariables', $variables); |
|
| 340 | - return $variables; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Check if the image should be replaced by the theming app |
|
| 345 | - * and return the new image location then |
|
| 346 | - * |
|
| 347 | - * @param string $app name of the app |
|
| 348 | - * @param string $image filename of the image |
|
| 349 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 350 | - */ |
|
| 351 | - public function replaceImagePath($app, $image) { |
|
| 352 | - if ($app === '' || $app === 'files_sharing') { |
|
| 353 | - $app = 'core'; |
|
| 354 | - } |
|
| 355 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 356 | - |
|
| 357 | - try { |
|
| 358 | - $customFavicon = $this->imageManager->getImage('favicon'); |
|
| 359 | - } catch (NotFoundException $e) { |
|
| 360 | - $customFavicon = null; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $route = false; |
|
| 364 | - if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 365 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
| 366 | - } |
|
| 367 | - if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 368 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
| 369 | - } |
|
| 370 | - if ($image === 'manifest.json') { |
|
| 371 | - try { |
|
| 372 | - $appPath = $this->appManager->getAppPath($app); |
|
| 373 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - } catch (AppPathNotFoundException $e) { |
|
| 377 | - } |
|
| 378 | - $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest'); |
|
| 379 | - } |
|
| 380 | - if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
| 381 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ($route) { |
|
| 385 | - return $route . '?v=' . $cacheBusterValue; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - return false; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Increases the cache buster key |
|
| 393 | - */ |
|
| 394 | - private function increaseCacheBuster() { |
|
| 395 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 396 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey + 1); |
|
| 397 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
| 398 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Update setting in the database |
|
| 403 | - * |
|
| 404 | - * @param string $setting |
|
| 405 | - * @param string $value |
|
| 406 | - */ |
|
| 407 | - public function set($setting, $value) { |
|
| 408 | - $this->config->setAppValue('theming', $setting, $value); |
|
| 409 | - $this->increaseCacheBuster(); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Revert settings to the default value |
|
| 414 | - * |
|
| 415 | - * @param string $setting setting which should be reverted |
|
| 416 | - * @return string default value |
|
| 417 | - */ |
|
| 418 | - public function undo($setting) { |
|
| 419 | - $this->config->deleteAppValue('theming', $setting); |
|
| 420 | - $this->increaseCacheBuster(); |
|
| 421 | - |
|
| 422 | - $returnValue = ''; |
|
| 423 | - switch ($setting) { |
|
| 424 | - case 'name': |
|
| 425 | - $returnValue = $this->getEntity(); |
|
| 426 | - break; |
|
| 427 | - case 'url': |
|
| 428 | - $returnValue = $this->getBaseUrl(); |
|
| 429 | - break; |
|
| 430 | - case 'slogan': |
|
| 431 | - $returnValue = $this->getSlogan(); |
|
| 432 | - break; |
|
| 433 | - case 'color': |
|
| 434 | - $returnValue = $this->getColorPrimary(); |
|
| 435 | - break; |
|
| 436 | - case 'logo': |
|
| 437 | - case 'logoheader': |
|
| 438 | - case 'background': |
|
| 439 | - case 'favicon': |
|
| 440 | - $this->imageManager->delete($setting); |
|
| 441 | - break; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return $returnValue; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Color of text in the header and primary buttons |
|
| 449 | - * |
|
| 450 | - * @return string |
|
| 451 | - */ |
|
| 452 | - public function getTextColorPrimary() { |
|
| 453 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 454 | - } |
|
| 54 | + /** @var IConfig */ |
|
| 55 | + private $config; |
|
| 56 | + /** @var IL10N */ |
|
| 57 | + private $l; |
|
| 58 | + /** @var ImageManager */ |
|
| 59 | + private $imageManager; |
|
| 60 | + /** @var IURLGenerator */ |
|
| 61 | + private $urlGenerator; |
|
| 62 | + /** @var ICacheFactory */ |
|
| 63 | + private $cacheFactory; |
|
| 64 | + /** @var Util */ |
|
| 65 | + private $util; |
|
| 66 | + /** @var IAppManager */ |
|
| 67 | + private $appManager; |
|
| 68 | + /** @var INavigationManager */ |
|
| 69 | + private $navigationManager; |
|
| 70 | + |
|
| 71 | + /** @var string */ |
|
| 72 | + private $name; |
|
| 73 | + /** @var string */ |
|
| 74 | + private $title; |
|
| 75 | + /** @var string */ |
|
| 76 | + private $entity; |
|
| 77 | + /** @var string */ |
|
| 78 | + private $productName; |
|
| 79 | + /** @var string */ |
|
| 80 | + private $url; |
|
| 81 | + /** @var string */ |
|
| 82 | + private $color; |
|
| 83 | + |
|
| 84 | + /** @var string */ |
|
| 85 | + private $iTunesAppId; |
|
| 86 | + /** @var string */ |
|
| 87 | + private $iOSClientUrl; |
|
| 88 | + /** @var string */ |
|
| 89 | + private $AndroidClientUrl; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * ThemingDefaults constructor. |
|
| 93 | + * |
|
| 94 | + * @param IConfig $config |
|
| 95 | + * @param IL10N $l |
|
| 96 | + * @param ImageManager $imageManager |
|
| 97 | + * @param IURLGenerator $urlGenerator |
|
| 98 | + * @param ICacheFactory $cacheFactory |
|
| 99 | + * @param Util $util |
|
| 100 | + * @param IAppManager $appManager |
|
| 101 | + */ |
|
| 102 | + public function __construct(IConfig $config, |
|
| 103 | + IL10N $l, |
|
| 104 | + IURLGenerator $urlGenerator, |
|
| 105 | + ICacheFactory $cacheFactory, |
|
| 106 | + Util $util, |
|
| 107 | + ImageManager $imageManager, |
|
| 108 | + IAppManager $appManager, |
|
| 109 | + INavigationManager $navigationManager |
|
| 110 | + ) { |
|
| 111 | + parent::__construct(); |
|
| 112 | + $this->config = $config; |
|
| 113 | + $this->l = $l; |
|
| 114 | + $this->imageManager = $imageManager; |
|
| 115 | + $this->urlGenerator = $urlGenerator; |
|
| 116 | + $this->cacheFactory = $cacheFactory; |
|
| 117 | + $this->util = $util; |
|
| 118 | + $this->appManager = $appManager; |
|
| 119 | + $this->navigationManager = $navigationManager; |
|
| 120 | + |
|
| 121 | + $this->name = parent::getName(); |
|
| 122 | + $this->title = parent::getTitle(); |
|
| 123 | + $this->entity = parent::getEntity(); |
|
| 124 | + $this->productName = parent::getProductName(); |
|
| 125 | + $this->url = parent::getBaseUrl(); |
|
| 126 | + $this->color = parent::getColorPrimary(); |
|
| 127 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 128 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 129 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function getName() { |
|
| 133 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getHTMLName() { |
|
| 137 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function getTitle() { |
|
| 141 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function getEntity() { |
|
| 145 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getProductName() { |
|
| 149 | + return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName)); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function getBaseUrl() { |
|
| 153 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function getSlogan(?string $lang = null) { |
|
| 157 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function getImprintUrl() { |
|
| 161 | + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function getPrivacyUrl() { |
|
| 165 | + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + public function getShortFooter() { |
|
| 169 | + $slogan = $this->getSlogan(); |
|
| 170 | + $baseUrl = $this->getBaseUrl(); |
|
| 171 | + if ($baseUrl !== '') { |
|
| 172 | + $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
| 173 | + ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
| 174 | + } else { |
|
| 175 | + $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
| 176 | + } |
|
| 177 | + $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 178 | + |
|
| 179 | + $links = [ |
|
| 180 | + [ |
|
| 181 | + 'text' => $this->l->t('Legal notice'), |
|
| 182 | + 'url' => (string)$this->getImprintUrl() |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'text' => $this->l->t('Privacy policy'), |
|
| 186 | + 'url' => (string)$this->getPrivacyUrl() |
|
| 187 | + ], |
|
| 188 | + ]; |
|
| 189 | + |
|
| 190 | + $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
| 191 | + $guestNavigation = array_map(function ($nav) { |
|
| 192 | + return [ |
|
| 193 | + 'text' => $nav['name'], |
|
| 194 | + 'url' => $nav['href'] |
|
| 195 | + ]; |
|
| 196 | + }, $navigation); |
|
| 197 | + $links = array_merge($links, $guestNavigation); |
|
| 198 | + |
|
| 199 | + $legalLinks = ''; |
|
| 200 | + $divider = ''; |
|
| 201 | + foreach ($links as $link) { |
|
| 202 | + if ($link['url'] !== '' |
|
| 203 | + && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
| 204 | + ) { |
|
| 205 | + $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
| 206 | + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
| 207 | + $divider = ' · '; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + if ($legalLinks !== '') { |
|
| 211 | + $footer .= '<br/>' . $legalLinks; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $footer; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Color that is used for the header as well as for mail headers |
|
| 219 | + * |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + public function getColorPrimary() { |
|
| 223 | + $color = $this->config->getAppValue('theming', 'color', $this->color); |
|
| 224 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
| 225 | + $color = '#0082c9'; |
|
| 226 | + } |
|
| 227 | + return $color; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Themed logo url |
|
| 232 | + * |
|
| 233 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public function getLogo($useSvg = true): string { |
|
| 237 | + $logo = $this->config->getAppValue('theming', 'logoMime', ''); |
|
| 238 | + |
|
| 239 | + // short cut to avoid setting up the filesystem just to check if the logo is there |
|
| 240 | + // |
|
| 241 | + // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. |
|
| 242 | + // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which |
|
| 243 | + // needs to be called then) |
|
| 244 | + if ($useSvg === true && $logo !== false) { |
|
| 245 | + $logoExists = true; |
|
| 246 | + } else { |
|
| 247 | + try { |
|
| 248 | + $this->imageManager->getImage('logo', $useSvg); |
|
| 249 | + $logoExists = true; |
|
| 250 | + } catch (\Exception $e) { |
|
| 251 | + $logoExists = false; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 256 | + |
|
| 257 | + if (!$logo || !$logoExists) { |
|
| 258 | + if ($useSvg) { |
|
| 259 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
| 260 | + } else { |
|
| 261 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
| 262 | + } |
|
| 263 | + return $logo . '?v=' . $cacheBusterCounter; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Themed background image url |
|
| 271 | + * |
|
| 272 | + * @return string |
|
| 273 | + */ |
|
| 274 | + public function getBackground(): string { |
|
| 275 | + return $this->imageManager->getImageUrl('background'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return string |
|
| 280 | + */ |
|
| 281 | + public function getiTunesAppId() { |
|
| 282 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function getiOSClientUrl() { |
|
| 289 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @return string |
|
| 294 | + */ |
|
| 295 | + public function getAndroidClientUrl() { |
|
| 296 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @return array scss variables to overwrite |
|
| 302 | + */ |
|
| 303 | + public function getScssVariables() { |
|
| 304 | + $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 305 | + $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); |
|
| 306 | + if ($value = $cache->get('getScssVariables')) { |
|
| 307 | + return $value; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $variables = [ |
|
| 311 | + 'theming-cachebuster' => "'" . $cacheBuster . "'", |
|
| 312 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
| 313 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
| 314 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
| 315 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
| 316 | + ]; |
|
| 317 | + |
|
| 318 | + $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
| 319 | + $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
| 320 | + $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
| 321 | + $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
| 322 | + $variables['image-login-plain'] = 'false'; |
|
| 323 | + |
|
| 324 | + if ($this->config->getAppValue('theming', 'color', '') !== '') { |
|
| 325 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
| 326 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 327 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { |
|
| 331 | + $variables['image-login-plain'] = 'true'; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $variables['has-legal-links'] = 'false'; |
|
| 335 | + if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
| 336 | + $variables['has-legal-links'] = 'true'; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + $cache->set('getScssVariables', $variables); |
|
| 340 | + return $variables; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Check if the image should be replaced by the theming app |
|
| 345 | + * and return the new image location then |
|
| 346 | + * |
|
| 347 | + * @param string $app name of the app |
|
| 348 | + * @param string $image filename of the image |
|
| 349 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 350 | + */ |
|
| 351 | + public function replaceImagePath($app, $image) { |
|
| 352 | + if ($app === '' || $app === 'files_sharing') { |
|
| 353 | + $app = 'core'; |
|
| 354 | + } |
|
| 355 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 356 | + |
|
| 357 | + try { |
|
| 358 | + $customFavicon = $this->imageManager->getImage('favicon'); |
|
| 359 | + } catch (NotFoundException $e) { |
|
| 360 | + $customFavicon = null; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $route = false; |
|
| 364 | + if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 365 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
| 366 | + } |
|
| 367 | + if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
| 368 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
| 369 | + } |
|
| 370 | + if ($image === 'manifest.json') { |
|
| 371 | + try { |
|
| 372 | + $appPath = $this->appManager->getAppPath($app); |
|
| 373 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + } catch (AppPathNotFoundException $e) { |
|
| 377 | + } |
|
| 378 | + $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest'); |
|
| 379 | + } |
|
| 380 | + if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
| 381 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ($route) { |
|
| 385 | + return $route . '?v=' . $cacheBusterValue; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + return false; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Increases the cache buster key |
|
| 393 | + */ |
|
| 394 | + private function increaseCacheBuster() { |
|
| 395 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 396 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey + 1); |
|
| 397 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
| 398 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Update setting in the database |
|
| 403 | + * |
|
| 404 | + * @param string $setting |
|
| 405 | + * @param string $value |
|
| 406 | + */ |
|
| 407 | + public function set($setting, $value) { |
|
| 408 | + $this->config->setAppValue('theming', $setting, $value); |
|
| 409 | + $this->increaseCacheBuster(); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Revert settings to the default value |
|
| 414 | + * |
|
| 415 | + * @param string $setting setting which should be reverted |
|
| 416 | + * @return string default value |
|
| 417 | + */ |
|
| 418 | + public function undo($setting) { |
|
| 419 | + $this->config->deleteAppValue('theming', $setting); |
|
| 420 | + $this->increaseCacheBuster(); |
|
| 421 | + |
|
| 422 | + $returnValue = ''; |
|
| 423 | + switch ($setting) { |
|
| 424 | + case 'name': |
|
| 425 | + $returnValue = $this->getEntity(); |
|
| 426 | + break; |
|
| 427 | + case 'url': |
|
| 428 | + $returnValue = $this->getBaseUrl(); |
|
| 429 | + break; |
|
| 430 | + case 'slogan': |
|
| 431 | + $returnValue = $this->getSlogan(); |
|
| 432 | + break; |
|
| 433 | + case 'color': |
|
| 434 | + $returnValue = $this->getColorPrimary(); |
|
| 435 | + break; |
|
| 436 | + case 'logo': |
|
| 437 | + case 'logoheader': |
|
| 438 | + case 'background': |
|
| 439 | + case 'favicon': |
|
| 440 | + $this->imageManager->delete($setting); |
|
| 441 | + break; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return $returnValue; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Color of text in the header and primary buttons |
|
| 449 | + * |
|
| 450 | + * @return string |
|
| 451 | + */ |
|
| 452 | + public function getTextColorPrimary() { |
|
| 453 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 454 | + } |
|
| 455 | 455 | } |