diff options
Diffstat (limited to 'apps/theming/lib/Util.php')
-rw-r--r-- | apps/theming/lib/Util.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 71ed0958e42..8aa5f50ede2 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -23,8 +23,19 @@ namespace OCA\Theming; +use OCP\IConfig; +use OCP\Files\IRootFolder; + class Util { + private $config; + private $rootFolder; + + public function __construct(IConfig $config, IRootFolder $rootFolder) { + $this->config = $config; + $this->rootFolder = $rootFolder; + } + /** * @param string $color rgb color value * @return bool @@ -81,4 +92,77 @@ class Util { return base64_encode($radioButtonIcon); } + + /** + * @param $app app name + * @return string path to app icon / logo + */ + public function getAppIcon($app) { + $appPath = \OC_App::getAppPath($app); + + $icon = $appPath . '/img/' . $app . '.svg'; + if(file_exists($icon)) { + return $icon; + } + $icon = $appPath . '/img/app.svg'; + if(file_exists($icon)) { + return $icon; + } + + if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) { + return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo'; + } + return \OC::$SERVERROOT . '/core/img/logo.svg'; + } + + /** + * @param $app app name + * @param $image relative path to image in app folder + * @return string absolute path to image + */ + public function getAppImage($app, $image) { + $appPath = \OC_App::getAppPath($app); + + if($app==="core") { + $icon = \OC::$SERVERROOT . '/core/img/' . $image; + if(file_exists($icon)) { + return $icon; + } + } + + $icon = $appPath . '/img/' . $image; + if(file_exists($icon)) { + return $icon; + } + $icon = $appPath . '/img/' . $image . '.svg'; + if(file_exists($icon)) { + return $icon; + } + $icon = $appPath . '/img/' . $image . '.png'; + if(file_exists($icon)) { + return $icon; + } + $icon = $appPath . '/img/' . $image . '.gif'; + if(file_exists($icon)) { + return $icon; + } + $icon = $appPath . '/img/' . $image . '.jpg'; + if(file_exists($icon)) { + return $icon; + } + return false; + } + + /** + * replace default color with a custom one + * + * @param $svg content of a svg file + * @param $color color to match + * @return string + */ + public function colorizeSvg($svg, $color) { + $svg = preg_replace('/#0082c9/i', $color, $svg); + return $svg; + } + } |