@@ -36,203 +36,203 @@ |
||
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 | - list($red, $green, $blue) = $this->hexToRGB($color); |
|
94 | - $compiler = new Compiler(); |
|
95 | - $hsl = $compiler->toHSL($red, $green, $blue); |
|
96 | - return $hsl[3]/100; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $color rgb color value |
|
101 | - * @return float |
|
102 | - */ |
|
103 | - public function calculateLuma($color) { |
|
104 | - list($red, $green, $blue) = $this->hexToRGB($color); |
|
105 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $color rgb color value |
|
110 | - * @return int[] |
|
111 | - */ |
|
112 | - public function hexToRGB($color) { |
|
113 | - $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
114 | - if (strlen($hex) === 3) { |
|
115 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
116 | - } |
|
117 | - if (strlen($hex) !== 6) { |
|
118 | - return 0; |
|
119 | - } |
|
120 | - return [ |
|
121 | - hexdec(substr($hex, 0, 2)), |
|
122 | - hexdec(substr($hex, 2, 2)), |
|
123 | - hexdec(substr($hex, 4, 2)) |
|
124 | - ]; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $color |
|
129 | - * @return string base64 encoded radio button svg |
|
130 | - */ |
|
131 | - public function generateRadioButton($color) { |
|
132 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
133 | - '<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>'; |
|
134 | - return base64_encode($radioButtonIcon); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param $app string app name |
|
140 | - * @return string|ISimpleFile path to app icon / file of logo |
|
141 | - */ |
|
142 | - public function getAppIcon($app) { |
|
143 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
144 | - try { |
|
145 | - $appPath = $this->appManager->getAppPath($app); |
|
146 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
147 | - if (file_exists($icon)) { |
|
148 | - return $icon; |
|
149 | - } |
|
150 | - $icon = $appPath . '/img/app.svg'; |
|
151 | - if (file_exists($icon)) { |
|
152 | - return $icon; |
|
153 | - } |
|
154 | - } catch (AppPathNotFoundException $e) {} |
|
155 | - |
|
156 | - if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
157 | - $logoFile = null; |
|
158 | - try { |
|
159 | - $folder = $this->appData->getFolder('images'); |
|
160 | - if ($folder !== null) { |
|
161 | - return $folder->getFile('logo'); |
|
162 | - } |
|
163 | - } catch (NotFoundException $e) {} |
|
164 | - } |
|
165 | - return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @param $app string app name |
|
170 | - * @param $image string relative path to image in app folder |
|
171 | - * @return string|false absolute path to image |
|
172 | - */ |
|
173 | - public function getAppImage($app, $image) { |
|
174 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
175 | - $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
176 | - if ($app === "core") { |
|
177 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
178 | - if (file_exists($icon)) { |
|
179 | - return $icon; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - try { |
|
184 | - $appPath = $this->appManager->getAppPath($app); |
|
185 | - } catch (AppPathNotFoundException $e) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - $icon = $appPath . '/img/' . $image; |
|
190 | - if (file_exists($icon)) { |
|
191 | - return $icon; |
|
192 | - } |
|
193 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
194 | - if (file_exists($icon)) { |
|
195 | - return $icon; |
|
196 | - } |
|
197 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
198 | - if (file_exists($icon)) { |
|
199 | - return $icon; |
|
200 | - } |
|
201 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
202 | - if (file_exists($icon)) { |
|
203 | - return $icon; |
|
204 | - } |
|
205 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
206 | - if (file_exists($icon)) { |
|
207 | - return $icon; |
|
208 | - } |
|
209 | - |
|
210 | - return false; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * replace default color with a custom one |
|
215 | - * |
|
216 | - * @param $svg string content of a svg file |
|
217 | - * @param $color string color to match |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function colorizeSvg($svg, $color) { |
|
221 | - $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
222 | - return $svg; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Check if a custom theme is set in the server configuration |
|
227 | - * |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - public function isAlreadyThemed() { |
|
231 | - $theme = $this->config->getSystemValue('theme', ''); |
|
232 | - if ($theme !== '') { |
|
233 | - return true; |
|
234 | - } |
|
235 | - return false; |
|
236 | - } |
|
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 | + list($red, $green, $blue) = $this->hexToRGB($color); |
|
94 | + $compiler = new Compiler(); |
|
95 | + $hsl = $compiler->toHSL($red, $green, $blue); |
|
96 | + return $hsl[3]/100; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $color rgb color value |
|
101 | + * @return float |
|
102 | + */ |
|
103 | + public function calculateLuma($color) { |
|
104 | + list($red, $green, $blue) = $this->hexToRGB($color); |
|
105 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $color rgb color value |
|
110 | + * @return int[] |
|
111 | + */ |
|
112 | + public function hexToRGB($color) { |
|
113 | + $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
114 | + if (strlen($hex) === 3) { |
|
115 | + $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
116 | + } |
|
117 | + if (strlen($hex) !== 6) { |
|
118 | + return 0; |
|
119 | + } |
|
120 | + return [ |
|
121 | + hexdec(substr($hex, 0, 2)), |
|
122 | + hexdec(substr($hex, 2, 2)), |
|
123 | + hexdec(substr($hex, 4, 2)) |
|
124 | + ]; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $color |
|
129 | + * @return string base64 encoded radio button svg |
|
130 | + */ |
|
131 | + public function generateRadioButton($color) { |
|
132 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
133 | + '<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>'; |
|
134 | + return base64_encode($radioButtonIcon); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param $app string app name |
|
140 | + * @return string|ISimpleFile path to app icon / file of logo |
|
141 | + */ |
|
142 | + public function getAppIcon($app) { |
|
143 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
144 | + try { |
|
145 | + $appPath = $this->appManager->getAppPath($app); |
|
146 | + $icon = $appPath . '/img/' . $app . '.svg'; |
|
147 | + if (file_exists($icon)) { |
|
148 | + return $icon; |
|
149 | + } |
|
150 | + $icon = $appPath . '/img/app.svg'; |
|
151 | + if (file_exists($icon)) { |
|
152 | + return $icon; |
|
153 | + } |
|
154 | + } catch (AppPathNotFoundException $e) {} |
|
155 | + |
|
156 | + if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
157 | + $logoFile = null; |
|
158 | + try { |
|
159 | + $folder = $this->appData->getFolder('images'); |
|
160 | + if ($folder !== null) { |
|
161 | + return $folder->getFile('logo'); |
|
162 | + } |
|
163 | + } catch (NotFoundException $e) {} |
|
164 | + } |
|
165 | + return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @param $app string app name |
|
170 | + * @param $image string relative path to image in app folder |
|
171 | + * @return string|false absolute path to image |
|
172 | + */ |
|
173 | + public function getAppImage($app, $image) { |
|
174 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
175 | + $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
176 | + if ($app === "core") { |
|
177 | + $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
178 | + if (file_exists($icon)) { |
|
179 | + return $icon; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + try { |
|
184 | + $appPath = $this->appManager->getAppPath($app); |
|
185 | + } catch (AppPathNotFoundException $e) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + $icon = $appPath . '/img/' . $image; |
|
190 | + if (file_exists($icon)) { |
|
191 | + return $icon; |
|
192 | + } |
|
193 | + $icon = $appPath . '/img/' . $image . '.svg'; |
|
194 | + if (file_exists($icon)) { |
|
195 | + return $icon; |
|
196 | + } |
|
197 | + $icon = $appPath . '/img/' . $image . '.png'; |
|
198 | + if (file_exists($icon)) { |
|
199 | + return $icon; |
|
200 | + } |
|
201 | + $icon = $appPath . '/img/' . $image . '.gif'; |
|
202 | + if (file_exists($icon)) { |
|
203 | + return $icon; |
|
204 | + } |
|
205 | + $icon = $appPath . '/img/' . $image . '.jpg'; |
|
206 | + if (file_exists($icon)) { |
|
207 | + return $icon; |
|
208 | + } |
|
209 | + |
|
210 | + return false; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * replace default color with a custom one |
|
215 | + * |
|
216 | + * @param $svg string content of a svg file |
|
217 | + * @param $color string color to match |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function colorizeSvg($svg, $color) { |
|
221 | + $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
222 | + return $svg; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Check if a custom theme is set in the server configuration |
|
227 | + * |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + public function isAlreadyThemed() { |
|
231 | + $theme = $this->config->getSystemValue('theme', ''); |
|
232 | + if ($theme !== '') { |
|
233 | + return true; |
|
234 | + } |
|
235 | + return false; |
|
236 | + } |
|
237 | 237 | |
238 | 238 | } |
@@ -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; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | list($red, $green, $blue) = $this->hexToRGB($color); |
94 | 94 | $compiler = new Compiler(); |
95 | 95 | $hsl = $compiler->toHSL($red, $green, $blue); |
96 | - return $hsl[3]/100; |
|
96 | + return $hsl[3] / 100; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function calculateLuma($color) { |
104 | 104 | list($red, $green, $blue) = $this->hexToRGB($color); |
105 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
105 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function hexToRGB($color) { |
113 | 113 | $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
114 | 114 | if (strlen($hex) === 3) { |
115 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
115 | + $hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; |
|
116 | 116 | } |
117 | 117 | if (strlen($hex) !== 6) { |
118 | 118 | return 0; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return string base64 encoded radio button svg |
130 | 130 | */ |
131 | 131 | public function generateRadioButton($color) { |
132 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
132 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'. |
|
133 | 133 | '<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>'; |
134 | 134 | return base64_encode($radioButtonIcon); |
135 | 135 | } |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
144 | 144 | try { |
145 | 145 | $appPath = $this->appManager->getAppPath($app); |
146 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
146 | + $icon = $appPath.'/img/'.$app.'.svg'; |
|
147 | 147 | if (file_exists($icon)) { |
148 | 148 | return $icon; |
149 | 149 | } |
150 | - $icon = $appPath . '/img/app.svg'; |
|
150 | + $icon = $appPath.'/img/app.svg'; |
|
151 | 151 | if (file_exists($icon)) { |
152 | 152 | return $icon; |
153 | 153 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | } catch (NotFoundException $e) {} |
164 | 164 | } |
165 | - return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
165 | + return \OC::$SERVERROOT.'/core/img/logo.svg'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
175 | 175 | $image = str_replace(array('\0', '\\', '..'), '', $image); |
176 | 176 | if ($app === "core") { |
177 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
177 | + $icon = \OC::$SERVERROOT.'/core/img/'.$image; |
|
178 | 178 | if (file_exists($icon)) { |
179 | 179 | return $icon; |
180 | 180 | } |
@@ -186,23 +186,23 @@ discard block |
||
186 | 186 | return false; |
187 | 187 | } |
188 | 188 | |
189 | - $icon = $appPath . '/img/' . $image; |
|
189 | + $icon = $appPath.'/img/'.$image; |
|
190 | 190 | if (file_exists($icon)) { |
191 | 191 | return $icon; |
192 | 192 | } |
193 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
193 | + $icon = $appPath.'/img/'.$image.'.svg'; |
|
194 | 194 | if (file_exists($icon)) { |
195 | 195 | return $icon; |
196 | 196 | } |
197 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
197 | + $icon = $appPath.'/img/'.$image.'.png'; |
|
198 | 198 | if (file_exists($icon)) { |
199 | 199 | return $icon; |
200 | 200 | } |
201 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
201 | + $icon = $appPath.'/img/'.$image.'.gif'; |
|
202 | 202 | if (file_exists($icon)) { |
203 | 203 | return $icon; |
204 | 204 | } |
205 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
205 | + $icon = $appPath.'/img/'.$image.'.jpg'; |
|
206 | 206 | if (file_exists($icon)) { |
207 | 207 | return $icon; |
208 | 208 | } |