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