@@ -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 | * |
@@ -112,24 +112,24 @@ discard block |
||
| 112 | 112 | $cachedVarsCssFile = $this->folder->newFile($this->fileName); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $icons = $this->getIconsFromCss($currentData . $css); |
|
| 115 | + $icons = $this->getIconsFromCss($currentData.$css); |
|
| 116 | 116 | |
| 117 | 117 | $data = ''; |
| 118 | 118 | $list = ''; |
| 119 | 119 | foreach ($icons as $icon => $url) { |
| 120 | 120 | $list .= "--$icon: url('$url');"; |
| 121 | - list($location,$color) = $this->parseUrl($url); |
|
| 121 | + list($location, $color) = $this->parseUrl($url); |
|
| 122 | 122 | $svg = false; |
| 123 | 123 | if ($location !== '' && \file_exists($location)) { |
| 124 | 124 | $svg = \file_get_contents($location); |
| 125 | 125 | } |
| 126 | 126 | if ($svg === false) { |
| 127 | - $this->logger->debug('Failed to get icon file ' . $location); |
|
| 127 | + $this->logger->debug('Failed to get icon file '.$location); |
|
| 128 | 128 | $data .= "--$icon: url('$url');"; |
| 129 | 129 | continue; |
| 130 | 130 | } |
| 131 | 131 | $encode = base64_encode($this->colorizeSvg($svg, $color)); |
| 132 | - $data .= '--' . $icon . ': url(data:image/svg+xml;base64,' . $encode . ');'; |
|
| 132 | + $data .= '--'.$icon.': url(data:image/svg+xml;base64,'.$encode.');'; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (\strlen($data) > 0 && \strlen($list) > 0) { |
@@ -149,20 +149,20 @@ discard block |
||
| 149 | 149 | private function parseUrl($url): array { |
| 150 | 150 | $location = ''; |
| 151 | 151 | $color = ''; |
| 152 | - $base = $this->getRoutePrefix() . '/svg/'; |
|
| 152 | + $base = $this->getRoutePrefix().'/svg/'; |
|
| 153 | 153 | $cleanUrl = \substr($url, \strlen($base)); |
| 154 | - if (\strpos($url, $base . 'core') === 0) { |
|
| 154 | + if (\strpos($url, $base.'core') === 0) { |
|
| 155 | 155 | $cleanUrl = \substr($cleanUrl, \strlen('core')); |
| 156 | 156 | if (\preg_match('/\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) { |
| 157 | - list(,$cleanUrl,$color) = $matches; |
|
| 158 | - $location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg'; |
|
| 157 | + list(,$cleanUrl, $color) = $matches; |
|
| 158 | + $location = \OC::$SERVERROOT.'/core/img/'.$cleanUrl.'.svg'; |
|
| 159 | 159 | } |
| 160 | 160 | } elseif (\strpos($url, $base) === 0) { |
| 161 | - if(\preg_match('/([A-z0-9\_\-]+)\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) { |
|
| 162 | - list(,$app,$cleanUrl, $color) = $matches; |
|
| 163 | - $location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg'; |
|
| 161 | + if (\preg_match('/([A-z0-9\_\-]+)\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) { |
|
| 162 | + list(,$app, $cleanUrl, $color) = $matches; |
|
| 163 | + $location = \OC_App::getAppPath($app).'/img/'.$cleanUrl.'.svg'; |
|
| 164 | 164 | if ($app === 'settings') { |
| 165 | - $location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg'; |
|
| 165 | + $location = \OC::$SERVERROOT.'/settings/img/'.$cleanUrl.'.svg'; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | public function colorizeSvg($svg, $color): string { |
| 182 | 182 | // add fill (fill is not present on black elements) |
| 183 | 183 | $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
| 184 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
| 184 | + $svg = preg_replace($fillRe, '<$1 fill="#'.$color.'"/>', $svg); |
|
| 185 | 185 | |
| 186 | 186 | // replace any fill or stroke colors |
| 187 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
| 188 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
| 187 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#'.$color.'"', $svg); |
|
| 188 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#'.$color.'"', $svg); |
|
| 189 | 189 | return $svg; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | private function getRoutePrefix() { |
| 193 | 193 | $frontControllerActive = (\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
| 194 | - $prefix = \OC::$WEBROOT . '/index.php'; |
|
| 194 | + $prefix = \OC::$WEBROOT.'/index.php'; |
|
| 195 | 195 | if ($frontControllerActive) { |
| 196 | 196 | $prefix = \OC::$WEBROOT; |
| 197 | 197 | } |