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