diff options
Diffstat (limited to 'apps/theming/lib')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 35 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 46 |
2 files changed, 78 insertions, 3 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index b409d309f4d..06c2c430b7f 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -423,4 +423,39 @@ class ThemingController extends Controller { $response->cacheFor(3600); return $response; } + + /** + * @NoCSRFRequired + * @PublicPage + * + * @return Http\JSONResponse + */ + public function getManifest($app) { + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); + $responseJS = [ + 'name' => $this->themingDefaults->getName(), + 'start_url' => $this->urlGenerator->getBaseUrl(), + 'icons' => + [ + [ + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', + ['app' => $app]) . '?v=' . $cacheBusterValue, + 'type'=> 'image/png', + 'sizes'=> '128x128' + ], + [ + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', + ['app' => $app]) . '?v=' . $cacheBusterValue, + 'type' => 'image/svg+xml', + 'sizes' => '16x16' + ] + ], + 'display' => 'standalone' + ]; + $response = new Http\JSONResponse($responseJS); + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); + $response->addHeader('Pragma', 'cache'); + $response->cacheFor(3600); + return $response; + } } diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 8200957edc0..5dd22fb6326 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -23,6 +23,8 @@ namespace OCA\Theming; +use OCP\App\AppPathNotFoundException; +use OCP\App\IAppManager; use OCP\Files\IAppData; use OCP\ICacheFactory; use OCP\IConfig; @@ -41,6 +43,10 @@ class ThemingDefaults extends \OC_Defaults { private $appData; /** @var ICacheFactory */ private $cacheFactory; + /** @var Util */ + private $util; + /** @var IAppManager */ + private $appManager; /** @var string */ private $name; /** @var string */ @@ -49,8 +55,7 @@ class ThemingDefaults extends \OC_Defaults { private $slogan; /** @var string */ private $color; - /** @var Util */ - private $util; + /** @var string */ private $iTunesAppId; /** @var string */ @@ -68,13 +73,15 @@ class ThemingDefaults extends \OC_Defaults { * @param IAppData $appData * @param ICacheFactory $cacheFactory * @param Util $util + * @param IAppManager $appManager */ public function __construct(IConfig $config, IL10N $l, IURLGenerator $urlGenerator, IAppData $appData, ICacheFactory $cacheFactory, - Util $util + Util $util, + IAppManager $appManager ) { parent::__construct(); $this->config = $config; @@ -83,6 +90,7 @@ class ThemingDefaults extends \OC_Defaults { $this->appData = $appData; $this->cacheFactory = $cacheFactory; $this->util = $util; + $this->appManager = $appManager; $this->name = parent::getName(); $this->url = parent::getBaseUrl(); @@ -249,6 +257,38 @@ class ThemingDefaults extends \OC_Defaults { } /** + * Check if the image should be replaced by the theming app + * and return the new image location then + * + * @param string $app name of the app + * @param string $image filename of the image + * @return bool|string false if image should not replaced, otherwise the location of the image + */ + public function replaceImagePath($app, $image) { + if($app==='') { + $app = 'core'; + } + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); + + if ($image === 'favicon.ico' && $this->shouldReplaceIcons()) { + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; + } + if ($image === 'favicon-touch.png' && $this->shouldReplaceIcons()) { + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; + } + if ($image === 'manifest.json') { + try { + $appPath = $this->appManager->getAppPath($app); + if (file_exists($appPath . '/img/manifest.json')) { + return false; + } + } catch (AppPathNotFoundException $e) {} + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; + } + return false; + } + + /** * Check if Imagemagick is enabled and if SVG is supported * otherwise we can't render custom icons * |