@@ -36,209 +36,209 @@ |
||
36 | 36 | |
37 | 37 | class Util { |
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
41 | - |
|
42 | - /** @var IAppManager */ |
|
43 | - private $appManager; |
|
44 | - |
|
45 | - /** @var IAppData */ |
|
46 | - private $appData; |
|
47 | - |
|
48 | - /** |
|
49 | - * Util constructor. |
|
50 | - * |
|
51 | - * @param IConfig $config |
|
52 | - * @param IAppManager $appManager |
|
53 | - * @param IAppData $appData |
|
54 | - */ |
|
55 | - public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
56 | - $this->config = $config; |
|
57 | - $this->appManager = $appManager; |
|
58 | - $this->appData = $appData; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $color rgb color value |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function invertTextColor($color) { |
|
66 | - $l = $this->calculateLuma($color); |
|
67 | - if($l>0.6) { |
|
68 | - return true; |
|
69 | - } else { |
|
70 | - return false; |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * get color for on-page elements: |
|
76 | - * theme color by default, grey if theme color is to bright |
|
77 | - * @param $color |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function elementColor($color) { |
|
81 | - $l = $this->calculateLuminance($color); |
|
82 | - if($l>0.8) { |
|
83 | - return '#555555'; |
|
84 | - } |
|
85 | - return $color; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $color rgb color value |
|
90 | - * @return float |
|
91 | - */ |
|
92 | - public function calculateLuminance($color) { |
|
93 | - $rgb = $this->hexToRGB($color); |
|
94 | - $red = $rgb[0]; |
|
95 | - $green = $rgb[1]; |
|
96 | - $blue = $rgb[2]; |
|
97 | - $compiler = new Compiler(); |
|
98 | - $hsl = $compiler->toHSL($red, $green, $blue); |
|
99 | - return $hsl[3]/100; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $color rgb color value |
|
104 | - * @return float |
|
105 | - */ |
|
106 | - public function calculateLuma($color) { |
|
107 | - $rgb = $this->hexToRGB($color); |
|
108 | - $red = $rgb[0]; |
|
109 | - $green = $rgb[1]; |
|
110 | - $blue = $rgb[2]; |
|
111 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $color rgb color value |
|
116 | - * @return int[] |
|
117 | - */ |
|
118 | - public function hexToRGB($color) { |
|
119 | - $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
120 | - if (strlen($hex) === 3) { |
|
121 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
122 | - } |
|
123 | - if (strlen($hex) !== 6) { |
|
124 | - return 0; |
|
125 | - } |
|
126 | - return [ |
|
127 | - hexdec(substr($hex, 0, 2)), |
|
128 | - hexdec(substr($hex, 2, 2)), |
|
129 | - hexdec(substr($hex, 4, 2)) |
|
130 | - ]; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param $color |
|
135 | - * @return string base64 encoded radio button svg |
|
136 | - */ |
|
137 | - public function generateRadioButton($color) { |
|
138 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
139 | - '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
140 | - return base64_encode($radioButtonIcon); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param $app string app name |
|
146 | - * @return string|ISimpleFile path to app icon / file of logo |
|
147 | - */ |
|
148 | - public function getAppIcon($app) { |
|
149 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
150 | - try { |
|
151 | - $appPath = $this->appManager->getAppPath($app); |
|
152 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
153 | - if (file_exists($icon)) { |
|
154 | - return $icon; |
|
155 | - } |
|
156 | - $icon = $appPath . '/img/app.svg'; |
|
157 | - if (file_exists($icon)) { |
|
158 | - return $icon; |
|
159 | - } |
|
160 | - } catch (AppPathNotFoundException $e) {} |
|
161 | - |
|
162 | - if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
163 | - $logoFile = null; |
|
164 | - try { |
|
165 | - $folder = $this->appData->getFolder('images'); |
|
166 | - if ($folder !== null) { |
|
167 | - return $folder->getFile('logo'); |
|
168 | - } |
|
169 | - } catch (NotFoundException $e) {} |
|
170 | - } |
|
171 | - return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param $app string app name |
|
176 | - * @param $image string relative path to image in app folder |
|
177 | - * @return string|false absolute path to image |
|
178 | - */ |
|
179 | - public function getAppImage($app, $image) { |
|
180 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
181 | - $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
182 | - if ($app === "core") { |
|
183 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
184 | - if (file_exists($icon)) { |
|
185 | - return $icon; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - try { |
|
190 | - $appPath = $this->appManager->getAppPath($app); |
|
191 | - } catch (AppPathNotFoundException $e) { |
|
192 | - return false; |
|
193 | - } |
|
194 | - |
|
195 | - $icon = $appPath . '/img/' . $image; |
|
196 | - if (file_exists($icon)) { |
|
197 | - return $icon; |
|
198 | - } |
|
199 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
200 | - if (file_exists($icon)) { |
|
201 | - return $icon; |
|
202 | - } |
|
203 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
204 | - if (file_exists($icon)) { |
|
205 | - return $icon; |
|
206 | - } |
|
207 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
208 | - if (file_exists($icon)) { |
|
209 | - return $icon; |
|
210 | - } |
|
211 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
212 | - if (file_exists($icon)) { |
|
213 | - return $icon; |
|
214 | - } |
|
215 | - |
|
216 | - return false; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * replace default color with a custom one |
|
221 | - * |
|
222 | - * @param $svg string content of a svg file |
|
223 | - * @param $color string color to match |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function colorizeSvg($svg, $color) { |
|
227 | - $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
228 | - return $svg; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Check if a custom theme is set in the server configuration |
|
233 | - * |
|
234 | - * @return bool |
|
235 | - */ |
|
236 | - public function isAlreadyThemed() { |
|
237 | - $theme = $this->config->getSystemValue('theme', ''); |
|
238 | - if ($theme !== '') { |
|
239 | - return true; |
|
240 | - } |
|
241 | - return false; |
|
242 | - } |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | + |
|
42 | + /** @var IAppManager */ |
|
43 | + private $appManager; |
|
44 | + |
|
45 | + /** @var IAppData */ |
|
46 | + private $appData; |
|
47 | + |
|
48 | + /** |
|
49 | + * Util constructor. |
|
50 | + * |
|
51 | + * @param IConfig $config |
|
52 | + * @param IAppManager $appManager |
|
53 | + * @param IAppData $appData |
|
54 | + */ |
|
55 | + public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
56 | + $this->config = $config; |
|
57 | + $this->appManager = $appManager; |
|
58 | + $this->appData = $appData; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $color rgb color value |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function invertTextColor($color) { |
|
66 | + $l = $this->calculateLuma($color); |
|
67 | + if($l>0.6) { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * get color for on-page elements: |
|
76 | + * theme color by default, grey if theme color is to bright |
|
77 | + * @param $color |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function elementColor($color) { |
|
81 | + $l = $this->calculateLuminance($color); |
|
82 | + if($l>0.8) { |
|
83 | + return '#555555'; |
|
84 | + } |
|
85 | + return $color; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $color rgb color value |
|
90 | + * @return float |
|
91 | + */ |
|
92 | + public function calculateLuminance($color) { |
|
93 | + $rgb = $this->hexToRGB($color); |
|
94 | + $red = $rgb[0]; |
|
95 | + $green = $rgb[1]; |
|
96 | + $blue = $rgb[2]; |
|
97 | + $compiler = new Compiler(); |
|
98 | + $hsl = $compiler->toHSL($red, $green, $blue); |
|
99 | + return $hsl[3]/100; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $color rgb color value |
|
104 | + * @return float |
|
105 | + */ |
|
106 | + public function calculateLuma($color) { |
|
107 | + $rgb = $this->hexToRGB($color); |
|
108 | + $red = $rgb[0]; |
|
109 | + $green = $rgb[1]; |
|
110 | + $blue = $rgb[2]; |
|
111 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $color rgb color value |
|
116 | + * @return int[] |
|
117 | + */ |
|
118 | + public function hexToRGB($color) { |
|
119 | + $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
120 | + if (strlen($hex) === 3) { |
|
121 | + $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
122 | + } |
|
123 | + if (strlen($hex) !== 6) { |
|
124 | + return 0; |
|
125 | + } |
|
126 | + return [ |
|
127 | + hexdec(substr($hex, 0, 2)), |
|
128 | + hexdec(substr($hex, 2, 2)), |
|
129 | + hexdec(substr($hex, 4, 2)) |
|
130 | + ]; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param $color |
|
135 | + * @return string base64 encoded radio button svg |
|
136 | + */ |
|
137 | + public function generateRadioButton($color) { |
|
138 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
139 | + '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
140 | + return base64_encode($radioButtonIcon); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param $app string app name |
|
146 | + * @return string|ISimpleFile path to app icon / file of logo |
|
147 | + */ |
|
148 | + public function getAppIcon($app) { |
|
149 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
150 | + try { |
|
151 | + $appPath = $this->appManager->getAppPath($app); |
|
152 | + $icon = $appPath . '/img/' . $app . '.svg'; |
|
153 | + if (file_exists($icon)) { |
|
154 | + return $icon; |
|
155 | + } |
|
156 | + $icon = $appPath . '/img/app.svg'; |
|
157 | + if (file_exists($icon)) { |
|
158 | + return $icon; |
|
159 | + } |
|
160 | + } catch (AppPathNotFoundException $e) {} |
|
161 | + |
|
162 | + if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
163 | + $logoFile = null; |
|
164 | + try { |
|
165 | + $folder = $this->appData->getFolder('images'); |
|
166 | + if ($folder !== null) { |
|
167 | + return $folder->getFile('logo'); |
|
168 | + } |
|
169 | + } catch (NotFoundException $e) {} |
|
170 | + } |
|
171 | + return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param $app string app name |
|
176 | + * @param $image string relative path to image in app folder |
|
177 | + * @return string|false absolute path to image |
|
178 | + */ |
|
179 | + public function getAppImage($app, $image) { |
|
180 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
181 | + $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
182 | + if ($app === "core") { |
|
183 | + $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
184 | + if (file_exists($icon)) { |
|
185 | + return $icon; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + try { |
|
190 | + $appPath = $this->appManager->getAppPath($app); |
|
191 | + } catch (AppPathNotFoundException $e) { |
|
192 | + return false; |
|
193 | + } |
|
194 | + |
|
195 | + $icon = $appPath . '/img/' . $image; |
|
196 | + if (file_exists($icon)) { |
|
197 | + return $icon; |
|
198 | + } |
|
199 | + $icon = $appPath . '/img/' . $image . '.svg'; |
|
200 | + if (file_exists($icon)) { |
|
201 | + return $icon; |
|
202 | + } |
|
203 | + $icon = $appPath . '/img/' . $image . '.png'; |
|
204 | + if (file_exists($icon)) { |
|
205 | + return $icon; |
|
206 | + } |
|
207 | + $icon = $appPath . '/img/' . $image . '.gif'; |
|
208 | + if (file_exists($icon)) { |
|
209 | + return $icon; |
|
210 | + } |
|
211 | + $icon = $appPath . '/img/' . $image . '.jpg'; |
|
212 | + if (file_exists($icon)) { |
|
213 | + return $icon; |
|
214 | + } |
|
215 | + |
|
216 | + return false; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * replace default color with a custom one |
|
221 | + * |
|
222 | + * @param $svg string content of a svg file |
|
223 | + * @param $color string color to match |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function colorizeSvg($svg, $color) { |
|
227 | + $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
228 | + return $svg; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Check if a custom theme is set in the server configuration |
|
233 | + * |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | + public function isAlreadyThemed() { |
|
237 | + $theme = $this->config->getSystemValue('theme', ''); |
|
238 | + if ($theme !== '') { |
|
239 | + return true; |
|
240 | + } |
|
241 | + return false; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function invertTextColor($color) { |
66 | 66 | $l = $this->calculateLuma($color); |
67 | - if($l>0.6) { |
|
67 | + if ($l > 0.6) { |
|
68 | 68 | return true; |
69 | 69 | } else { |
70 | 70 | return false; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function elementColor($color) { |
81 | 81 | $l = $this->calculateLuminance($color); |
82 | - if($l>0.8) { |
|
82 | + if ($l > 0.8) { |
|
83 | 83 | return '#555555'; |
84 | 84 | } |
85 | 85 | return $color; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $blue = $rgb[2]; |
97 | 97 | $compiler = new Compiler(); |
98 | 98 | $hsl = $compiler->toHSL($red, $green, $blue); |
99 | - return $hsl[3]/100; |
|
99 | + return $hsl[3] / 100; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $red = $rgb[0]; |
109 | 109 | $green = $rgb[1]; |
110 | 110 | $blue = $rgb[2]; |
111 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
111 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | public function hexToRGB($color) { |
119 | 119 | $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
120 | 120 | if (strlen($hex) === 3) { |
121 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
121 | + $hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; |
|
122 | 122 | } |
123 | 123 | if (strlen($hex) !== 6) { |
124 | 124 | return 0; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return string base64 encoded radio button svg |
136 | 136 | */ |
137 | 137 | public function generateRadioButton($color) { |
138 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
138 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'. |
|
139 | 139 | '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
140 | 140 | return base64_encode($radioButtonIcon); |
141 | 141 | } |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
150 | 150 | try { |
151 | 151 | $appPath = $this->appManager->getAppPath($app); |
152 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
152 | + $icon = $appPath.'/img/'.$app.'.svg'; |
|
153 | 153 | if (file_exists($icon)) { |
154 | 154 | return $icon; |
155 | 155 | } |
156 | - $icon = $appPath . '/img/app.svg'; |
|
156 | + $icon = $appPath.'/img/app.svg'; |
|
157 | 157 | if (file_exists($icon)) { |
158 | 158 | return $icon; |
159 | 159 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | } catch (NotFoundException $e) {} |
170 | 170 | } |
171 | - return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
171 | + return \OC::$SERVERROOT.'/core/img/logo.svg'; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
181 | 181 | $image = str_replace(array('\0', '\\', '..'), '', $image); |
182 | 182 | if ($app === "core") { |
183 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
183 | + $icon = \OC::$SERVERROOT.'/core/img/'.$image; |
|
184 | 184 | if (file_exists($icon)) { |
185 | 185 | return $icon; |
186 | 186 | } |
@@ -192,23 +192,23 @@ discard block |
||
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
195 | - $icon = $appPath . '/img/' . $image; |
|
195 | + $icon = $appPath.'/img/'.$image; |
|
196 | 196 | if (file_exists($icon)) { |
197 | 197 | return $icon; |
198 | 198 | } |
199 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
199 | + $icon = $appPath.'/img/'.$image.'.svg'; |
|
200 | 200 | if (file_exists($icon)) { |
201 | 201 | return $icon; |
202 | 202 | } |
203 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
203 | + $icon = $appPath.'/img/'.$image.'.png'; |
|
204 | 204 | if (file_exists($icon)) { |
205 | 205 | return $icon; |
206 | 206 | } |
207 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
207 | + $icon = $appPath.'/img/'.$image.'.gif'; |
|
208 | 208 | if (file_exists($icon)) { |
209 | 209 | return $icon; |
210 | 210 | } |
211 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
211 | + $icon = $appPath.'/img/'.$image.'.jpg'; |
|
212 | 212 | if (file_exists($icon)) { |
213 | 213 | return $icon; |
214 | 214 | } |