Completed
Pull Request — master (#4888)
by Julius
32:02 queued 15:08
created
apps/theming/lib/IconBuilder.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -28,170 +28,170 @@
 block discarded – undo
28 28
 use OCP\App\AppPathNotFoundException;
29 29
 
30 30
 class IconBuilder {
31
-	/** @var ThemingDefaults */
32
-	private $themingDefaults;
33
-	/** @var Util */
34
-	private $util;
35
-
36
-	/**
37
-	 * IconBuilder constructor.
38
-	 *
39
-	 * @param ThemingDefaults $themingDefaults
40
-	 * @param Util $util
41
-	 */
42
-	public function __construct(
43
-		ThemingDefaults $themingDefaults,
44
-		Util $util
45
-	) {
46
-		$this->themingDefaults = $themingDefaults;
47
-		$this->util = $util;
48
-	}
49
-
50
-	/**
51
-	 * @param $app string app name
52
-	 * @return string|false image blob
53
-	 */
54
-	public function getFavicon($app) {
55
-		try {
56
-			$icon = $this->renderAppIcon($app, 32);
57
-			if ($icon === false) {
58
-				return false;
59
-			}
60
-			$icon->setImageFormat("png24");
61
-			$data = $icon->getImageBlob();
62
-			$icon->destroy();
63
-			return $data;
64
-		} catch (\ImagickException $e) {
65
-			return false;
66
-		}
67
-	}
68
-
69
-	/**
70
-	 * @param $app string app name
71
-	 * @return string|false image blob
72
-	 */
73
-	public function getTouchIcon($app) {
74
-		try {
75
-			$icon = $this->renderAppIcon($app, 512);
76
-			if ($icon === false) {
77
-				return false;
78
-			}
79
-			$icon->setImageFormat("png24");
80
-			$data = $icon->getImageBlob();
81
-			$icon->destroy();
82
-			return $data;
83
-		} catch (\ImagickException $e) {
84
-			return false;
85
-		}
86
-	}
87
-
88
-	/**
89
-	 * Render app icon on themed background color
90
-	 * fallback to logo
91
-	 *
92
-	 * @param $app string app name
93
-	 * @param $size int size of the icon in px
94
-	 * @return Imagick|false
95
-	 */
96
-	public function renderAppIcon($app, $size) {
97
-		try {
98
-			$appIcon = $this->util->getAppIcon($app);
99
-			$appIconContent = file_get_contents($appIcon);
100
-		} catch (AppPathNotFoundException $e) {
101
-			return false;
102
-		}
103
-
104
-		if($appIconContent === false) {
105
-			return false;
106
-		}
107
-
108
-		$color = $this->themingDefaults->getColorPrimary();
109
-		$mime = mime_content_type($appIcon);
110
-
111
-		// generate background image with rounded corners
112
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
113
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
114
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
115
-			'</svg>';
116
-		// resize svg magic as this seems broken in Imagemagick
117
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
118
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
119
-				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
120
-			} else {
121
-				$svg = $appIconContent;
122
-			}
123
-			$tmp = new Imagick();
124
-			$tmp->readImageBlob($svg);
125
-			$x = $tmp->getImageWidth();
126
-			$y = $tmp->getImageHeight();
127
-			$res = $tmp->getImageResolution();
128
-			$tmp->destroy();
129
-
130
-			if($x>$y) {
131
-				$max = $x;
132
-			} else {
133
-				$max = $y;
134
-			}
135
-
136
-			// convert svg to resized image
137
-			$appIconFile = new Imagick();
138
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
139
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
140
-			$appIconFile->setResolution($resX, $resY);
141
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
142
-			$appIconFile->readImageBlob($svg);
143
-			$appIconFile->scaleImage(512, 512, true);
144
-		} else {
145
-			$appIconFile = new Imagick();
146
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
147
-			$appIconFile->readImageBlob(file_get_contents($appIcon));
148
-			$appIconFile->scaleImage(512, 512, true);
149
-		}
150
-
151
-		// offset for icon positioning
152
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
153
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
154
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
155
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
156
-		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
157
-		// center icon
158
-		$offset_w = 512 / 2 - $innerWidth / 2;
159
-		$offset_h = 512 / 2 - $innerHeight / 2;
160
-
161
-		$appIconFile->setImageFormat("png24");
162
-
163
-		$finalIconFile = new Imagick();
164
-		$finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
165
-		$finalIconFile->readImageBlob($background);
166
-		$finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
167
-		$finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
168
-		$finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
169
-		$finalIconFile->setImageFormat('png24');
170
-		if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
171
-			$filter = Imagick::INTERPOLATE_BICUBIC;
172
-		} else {
173
-			$filter = Imagick::FILTER_LANCZOS;
174
-		}
175
-		$finalIconFile->resizeImage($size, $size, $filter, 1, false);
176
-
177
-		$appIconFile->destroy();
178
-		return $finalIconFile;
179
-	}
180
-
181
-	public function colorSvg($app, $image) {
182
-		try {
183
-			$imageFile = $this->util->getAppImage($app, $image);
184
-		} catch (AppPathNotFoundException $e) {
185
-			return false;
186
-		}
187
-		$svg = file_get_contents($imageFile);
188
-		if ($svg !== false && $svg !== "") {
189
-			$color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
190
-			$svg = $this->util->colorizeSvg($svg, $color);
191
-			return $svg;
192
-		} else {
193
-			return false;
194
-		}
195
-	}
31
+    /** @var ThemingDefaults */
32
+    private $themingDefaults;
33
+    /** @var Util */
34
+    private $util;
35
+
36
+    /**
37
+     * IconBuilder constructor.
38
+     *
39
+     * @param ThemingDefaults $themingDefaults
40
+     * @param Util $util
41
+     */
42
+    public function __construct(
43
+        ThemingDefaults $themingDefaults,
44
+        Util $util
45
+    ) {
46
+        $this->themingDefaults = $themingDefaults;
47
+        $this->util = $util;
48
+    }
49
+
50
+    /**
51
+     * @param $app string app name
52
+     * @return string|false image blob
53
+     */
54
+    public function getFavicon($app) {
55
+        try {
56
+            $icon = $this->renderAppIcon($app, 32);
57
+            if ($icon === false) {
58
+                return false;
59
+            }
60
+            $icon->setImageFormat("png24");
61
+            $data = $icon->getImageBlob();
62
+            $icon->destroy();
63
+            return $data;
64
+        } catch (\ImagickException $e) {
65
+            return false;
66
+        }
67
+    }
68
+
69
+    /**
70
+     * @param $app string app name
71
+     * @return string|false image blob
72
+     */
73
+    public function getTouchIcon($app) {
74
+        try {
75
+            $icon = $this->renderAppIcon($app, 512);
76
+            if ($icon === false) {
77
+                return false;
78
+            }
79
+            $icon->setImageFormat("png24");
80
+            $data = $icon->getImageBlob();
81
+            $icon->destroy();
82
+            return $data;
83
+        } catch (\ImagickException $e) {
84
+            return false;
85
+        }
86
+    }
87
+
88
+    /**
89
+     * Render app icon on themed background color
90
+     * fallback to logo
91
+     *
92
+     * @param $app string app name
93
+     * @param $size int size of the icon in px
94
+     * @return Imagick|false
95
+     */
96
+    public function renderAppIcon($app, $size) {
97
+        try {
98
+            $appIcon = $this->util->getAppIcon($app);
99
+            $appIconContent = file_get_contents($appIcon);
100
+        } catch (AppPathNotFoundException $e) {
101
+            return false;
102
+        }
103
+
104
+        if($appIconContent === false) {
105
+            return false;
106
+        }
107
+
108
+        $color = $this->themingDefaults->getColorPrimary();
109
+        $mime = mime_content_type($appIcon);
110
+
111
+        // generate background image with rounded corners
112
+        $background = '<?xml version="1.0" encoding="UTF-8"?>' .
113
+            '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
114
+            '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
115
+            '</svg>';
116
+        // resize svg magic as this seems broken in Imagemagick
117
+        if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
118
+            if(substr($appIconContent, 0, 5) !== "<?xml") {
119
+                $svg = "<?xml version=\"1.0\"?>".$appIconContent;
120
+            } else {
121
+                $svg = $appIconContent;
122
+            }
123
+            $tmp = new Imagick();
124
+            $tmp->readImageBlob($svg);
125
+            $x = $tmp->getImageWidth();
126
+            $y = $tmp->getImageHeight();
127
+            $res = $tmp->getImageResolution();
128
+            $tmp->destroy();
129
+
130
+            if($x>$y) {
131
+                $max = $x;
132
+            } else {
133
+                $max = $y;
134
+            }
135
+
136
+            // convert svg to resized image
137
+            $appIconFile = new Imagick();
138
+            $resX = (int)(512 * $res['x'] / $max * 2.53);
139
+            $resY = (int)(512 * $res['y'] / $max * 2.53);
140
+            $appIconFile->setResolution($resX, $resY);
141
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
142
+            $appIconFile->readImageBlob($svg);
143
+            $appIconFile->scaleImage(512, 512, true);
144
+        } else {
145
+            $appIconFile = new Imagick();
146
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
147
+            $appIconFile->readImageBlob(file_get_contents($appIcon));
148
+            $appIconFile->scaleImage(512, 512, true);
149
+        }
150
+
151
+        // offset for icon positioning
152
+        $border_w = (int)($appIconFile->getImageWidth() * 0.05);
153
+        $border_h = (int)($appIconFile->getImageHeight() * 0.05);
154
+        $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
155
+        $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
156
+        $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
157
+        // center icon
158
+        $offset_w = 512 / 2 - $innerWidth / 2;
159
+        $offset_h = 512 / 2 - $innerHeight / 2;
160
+
161
+        $appIconFile->setImageFormat("png24");
162
+
163
+        $finalIconFile = new Imagick();
164
+        $finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
165
+        $finalIconFile->readImageBlob($background);
166
+        $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
167
+        $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
168
+        $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
169
+        $finalIconFile->setImageFormat('png24');
170
+        if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
171
+            $filter = Imagick::INTERPOLATE_BICUBIC;
172
+        } else {
173
+            $filter = Imagick::FILTER_LANCZOS;
174
+        }
175
+        $finalIconFile->resizeImage($size, $size, $filter, 1, false);
176
+
177
+        $appIconFile->destroy();
178
+        return $finalIconFile;
179
+    }
180
+
181
+    public function colorSvg($app, $image) {
182
+        try {
183
+            $imageFile = $this->util->getAppImage($app, $image);
184
+        } catch (AppPathNotFoundException $e) {
185
+            return false;
186
+        }
187
+        $svg = file_get_contents($imageFile);
188
+        if ($svg !== false && $svg !== "") {
189
+            $color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
190
+            $svg = $this->util->colorizeSvg($svg, $color);
191
+            return $svg;
192
+        } else {
193
+            return false;
194
+        }
195
+    }
196 196
 
197 197
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 			return false;
102 102
 		}
103 103
 
104
-		if($appIconContent === false) {
104
+		if ($appIconContent === false) {
105 105
 			return false;
106 106
 		}
107 107
 
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 		$mime = mime_content_type($appIcon);
110 110
 
111 111
 		// generate background image with rounded corners
112
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
113
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
114
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
112
+		$background = '<?xml version="1.0" encoding="UTF-8"?>'.
113
+			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">'.
114
+			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:'.$color.';" />'.
115 115
 			'</svg>';
116 116
 		// resize svg magic as this seems broken in Imagemagick
117
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
118
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
117
+		if ($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
118
+			if (substr($appIconContent, 0, 5) !== "<?xml") {
119 119
 				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
120 120
 			} else {
121 121
 				$svg = $appIconContent;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 			$res = $tmp->getImageResolution();
128 128
 			$tmp->destroy();
129 129
 
130
-			if($x>$y) {
130
+			if ($x > $y) {
131 131
 				$max = $x;
132 132
 			} else {
133 133
 				$max = $y;
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 
136 136
 			// convert svg to resized image
137 137
 			$appIconFile = new Imagick();
138
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
139
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
138
+			$resX = (int) (512 * $res['x'] / $max * 2.53);
139
+			$resY = (int) (512 * $res['y'] / $max * 2.53);
140 140
 			$appIconFile->setResolution($resX, $resY);
141 141
 			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
142 142
 			$appIconFile->readImageBlob($svg);
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
 		}
150 150
 
151 151
 		// offset for icon positioning
152
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
153
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
154
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
155
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
152
+		$border_w = (int) ($appIconFile->getImageWidth() * 0.05);
153
+		$border_h = (int) ($appIconFile->getImageHeight() * 0.05);
154
+		$innerWidth = (int) ($appIconFile->getImageWidth() - $border_w * 2);
155
+		$innerHeight = (int) ($appIconFile->getImageHeight() - $border_h * 2);
156 156
 		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
157 157
 		// center icon
158 158
 		$offset_w = 512 / 2 - $innerWidth / 2;
Please login to merge, or discard this patch.
apps/theming/lib/Controller/IconController.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -38,154 +38,154 @@
 block discarded – undo
38 38
 use OCP\IConfig;
39 39
 
40 40
 class IconController extends Controller {
41
-	/** @var ThemingDefaults */
42
-	private $themingDefaults;
43
-	/** @var Util */
44
-	private $util;
45
-	/** @var ITimeFactory */
46
-	private $timeFactory;
47
-	/** @var IConfig */
48
-	private $config;
49
-	/** @var IconBuilder */
50
-	private $iconBuilder;
51
-	/** @var ImageManager */
52
-	private $imageManager;
41
+    /** @var ThemingDefaults */
42
+    private $themingDefaults;
43
+    /** @var Util */
44
+    private $util;
45
+    /** @var ITimeFactory */
46
+    private $timeFactory;
47
+    /** @var IConfig */
48
+    private $config;
49
+    /** @var IconBuilder */
50
+    private $iconBuilder;
51
+    /** @var ImageManager */
52
+    private $imageManager;
53 53
 
54
-	/**
55
-	 * IconController constructor.
56
-	 *
57
-	 * @param string $appName
58
-	 * @param IRequest $request
59
-	 * @param ThemingDefaults $themingDefaults
60
-	 * @param Util $util
61
-	 * @param ITimeFactory $timeFactory
62
-	 * @param IConfig $config
63
-	 * @param IconBuilder $iconBuilder
64
-	 * @param ImageManager $imageManager
65
-	 */
66
-	public function __construct(
67
-		$appName,
68
-		IRequest $request,
69
-		ThemingDefaults $themingDefaults,
70
-		Util $util,
71
-		ITimeFactory $timeFactory,
72
-		IConfig $config,
73
-		IconBuilder $iconBuilder,
74
-		ImageManager $imageManager
75
-	) {
76
-		parent::__construct($appName, $request);
54
+    /**
55
+     * IconController constructor.
56
+     *
57
+     * @param string $appName
58
+     * @param IRequest $request
59
+     * @param ThemingDefaults $themingDefaults
60
+     * @param Util $util
61
+     * @param ITimeFactory $timeFactory
62
+     * @param IConfig $config
63
+     * @param IconBuilder $iconBuilder
64
+     * @param ImageManager $imageManager
65
+     */
66
+    public function __construct(
67
+        $appName,
68
+        IRequest $request,
69
+        ThemingDefaults $themingDefaults,
70
+        Util $util,
71
+        ITimeFactory $timeFactory,
72
+        IConfig $config,
73
+        IconBuilder $iconBuilder,
74
+        ImageManager $imageManager
75
+    ) {
76
+        parent::__construct($appName, $request);
77 77
 
78
-		$this->themingDefaults = $themingDefaults;
79
-		$this->util = $util;
80
-		$this->timeFactory = $timeFactory;
81
-		$this->config = $config;
82
-		$this->iconBuilder = $iconBuilder;
83
-		$this->imageManager = $imageManager;
84
-	}
78
+        $this->themingDefaults = $themingDefaults;
79
+        $this->util = $util;
80
+        $this->timeFactory = $timeFactory;
81
+        $this->config = $config;
82
+        $this->iconBuilder = $iconBuilder;
83
+        $this->imageManager = $imageManager;
84
+    }
85 85
 
86
-	/**
87
-	 * @PublicPage
88
-	 * @NoCSRFRequired
89
-	 *
90
-	 * @param $app string app name
91
-	 * @param $image string image file name (svg required)
92
-	 * @return FileDisplayResponse|NotFoundResponse
93
-	 */
94
-	public function getThemedIcon($app, $image) {
95
-		try {
96
-			$iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image));
97
-		} catch (NotFoundException $exception) {
98
-			$icon = $this->iconBuilder->colorSvg($app, $image);
99
-			if ($icon === false || $icon === "") {
100
-				return new NotFoundResponse();
101
-			}
102
-			$iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
103
-		}
104
-		if ($iconFile !== false) {
105
-			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
106
-			$response->cacheFor(86400);
107
-			$expires = new \DateTime();
108
-			$expires->setTimestamp($this->timeFactory->getTime());
109
-			$expires->add(new \DateInterval('PT24H'));
110
-			$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
111
-			$response->addHeader('Pragma', 'cache');
112
-			return $response;
113
-		} else {
114
-			return new NotFoundResponse();
115
-		}
116
-	}
86
+    /**
87
+     * @PublicPage
88
+     * @NoCSRFRequired
89
+     *
90
+     * @param $app string app name
91
+     * @param $image string image file name (svg required)
92
+     * @return FileDisplayResponse|NotFoundResponse
93
+     */
94
+    public function getThemedIcon($app, $image) {
95
+        try {
96
+            $iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image));
97
+        } catch (NotFoundException $exception) {
98
+            $icon = $this->iconBuilder->colorSvg($app, $image);
99
+            if ($icon === false || $icon === "") {
100
+                return new NotFoundResponse();
101
+            }
102
+            $iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
103
+        }
104
+        if ($iconFile !== false) {
105
+            $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
106
+            $response->cacheFor(86400);
107
+            $expires = new \DateTime();
108
+            $expires->setTimestamp($this->timeFactory->getTime());
109
+            $expires->add(new \DateInterval('PT24H'));
110
+            $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
111
+            $response->addHeader('Pragma', 'cache');
112
+            return $response;
113
+        } else {
114
+            return new NotFoundResponse();
115
+        }
116
+    }
117 117
 
118
-	/**
119
-	 * Return a 32x32 favicon as png
120
-	 *
121
-	 * @PublicPage
122
-	 * @NoCSRFRequired
123
-	 *
124
-	 * @param $app string app name
125
-	 * @return FileDisplayResponse|DataDisplayResponse
126
-	 */
127
-	public function getFavicon($app = "core") {
128
-		$response = null;
129
-		if ($this->themingDefaults->shouldReplaceIcons()) {
130
-			try {
131
-				$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
132
-			} catch (NotFoundException $exception) {
133
-				$icon = $this->iconBuilder->getFavicon($app);
134
-				$iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
135
-			}
136
-			if ($iconFile !== false) {
137
-				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
138
-			}
139
-		}
140
-		if($response === null) {
141
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
142
-			/** @var FileAccessHelper */
143
-			$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
144
-			$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
145
-		}
146
-		$response->cacheFor(86400);
147
-		$expires = new \DateTime();
148
-		$expires->setTimestamp($this->timeFactory->getTime());
149
-		$expires->add(new \DateInterval('PT24H'));
150
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
151
-		$response->addHeader('Pragma', 'cache');
152
-		return $response;
153
-	}
118
+    /**
119
+     * Return a 32x32 favicon as png
120
+     *
121
+     * @PublicPage
122
+     * @NoCSRFRequired
123
+     *
124
+     * @param $app string app name
125
+     * @return FileDisplayResponse|DataDisplayResponse
126
+     */
127
+    public function getFavicon($app = "core") {
128
+        $response = null;
129
+        if ($this->themingDefaults->shouldReplaceIcons()) {
130
+            try {
131
+                $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
132
+            } catch (NotFoundException $exception) {
133
+                $icon = $this->iconBuilder->getFavicon($app);
134
+                $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
135
+            }
136
+            if ($iconFile !== false) {
137
+                $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
138
+            }
139
+        }
140
+        if($response === null) {
141
+            $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
142
+            /** @var FileAccessHelper */
143
+            $fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
144
+            $response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
145
+        }
146
+        $response->cacheFor(86400);
147
+        $expires = new \DateTime();
148
+        $expires->setTimestamp($this->timeFactory->getTime());
149
+        $expires->add(new \DateInterval('PT24H'));
150
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
151
+        $response->addHeader('Pragma', 'cache');
152
+        return $response;
153
+    }
154 154
 
155
-	/**
156
-	 * Return a 512x512 icon for touch devices
157
-	 *
158
-	 * @PublicPage
159
-	 * @NoCSRFRequired
160
-	 *
161
-	 * @param $app string app name
162
-	 * @return FileDisplayResponse|NotFoundResponse
163
-	 */
164
-	public function getTouchIcon($app = "core") {
165
-		$response = null;
166
-		if ($this->themingDefaults->shouldReplaceIcons()) {
167
-			try {
168
-				$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
169
-			} catch (NotFoundException $exception) {
170
-				$icon = $this->iconBuilder->getTouchIcon($app);
171
-				$iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
172
-			}
173
-			if ($iconFile !== false) {
174
-				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
175
-			}
176
-		}
177
-		if($response === null) {
178
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
179
-			/** @var FileAccessHelper */
180
-			$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
181
-			$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
182
-		}
183
-		$response->cacheFor(86400);
184
-		$expires = new \DateTime();
185
-		$expires->setTimestamp($this->timeFactory->getTime());
186
-		$expires->add(new \DateInterval('PT24H'));
187
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
188
-		$response->addHeader('Pragma', 'cache');
189
-		return $response;
190
-	}
155
+    /**
156
+     * Return a 512x512 icon for touch devices
157
+     *
158
+     * @PublicPage
159
+     * @NoCSRFRequired
160
+     *
161
+     * @param $app string app name
162
+     * @return FileDisplayResponse|NotFoundResponse
163
+     */
164
+    public function getTouchIcon($app = "core") {
165
+        $response = null;
166
+        if ($this->themingDefaults->shouldReplaceIcons()) {
167
+            try {
168
+                $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
169
+            } catch (NotFoundException $exception) {
170
+                $icon = $this->iconBuilder->getTouchIcon($app);
171
+                $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
172
+            }
173
+            if ($iconFile !== false) {
174
+                $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
175
+            }
176
+        }
177
+        if($response === null) {
178
+            $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
179
+            /** @var FileAccessHelper */
180
+            $fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
181
+            $response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
182
+        }
183
+        $response->cacheFor(86400);
184
+        $expires = new \DateTime();
185
+        $expires->setTimestamp($this->timeFactory->getTime());
186
+        $expires->add(new \DateInterval('PT24H'));
187
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
188
+        $response->addHeader('Pragma', 'cache');
189
+        return $response;
190
+    }
191 191
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 	 */
94 94
 	public function getThemedIcon($app, $image) {
95 95
 		try {
96
-			$iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image));
96
+			$iconFile = $this->imageManager->getCachedImage("icon-".$app.'-'.str_replace("/", "_", $image));
97 97
 		} catch (NotFoundException $exception) {
98 98
 			$icon = $this->iconBuilder->colorSvg($app, $image);
99 99
 			if ($icon === false || $icon === "") {
100 100
 				return new NotFoundResponse();
101 101
 			}
102
-			$iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
102
+			$iconFile = $this->imageManager->setCachedImage("icon-".$app.'-'.str_replace("/", "_", $image), $icon);
103 103
 		}
104 104
 		if ($iconFile !== false) {
105 105
 			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
 		$response = null;
129 129
 		if ($this->themingDefaults->shouldReplaceIcons()) {
130 130
 			try {
131
-				$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
131
+				$iconFile = $this->imageManager->getCachedImage('favIcon-'.$app);
132 132
 			} catch (NotFoundException $exception) {
133 133
 				$icon = $this->iconBuilder->getFavicon($app);
134
-				$iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
134
+				$iconFile = $this->imageManager->setCachedImage('favIcon-'.$app, $icon);
135 135
 			}
136 136
 			if ($iconFile !== false) {
137 137
 				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
138 138
 			}
139 139
 		}
140
-		if($response === null) {
141
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
140
+		if ($response === null) {
141
+			$fallbackLogo = \OC::$SERVERROOT.'/core/img/favicon.png';
142 142
 			/** @var FileAccessHelper */
143 143
 			$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
144 144
 			$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
@@ -165,17 +165,17 @@  discard block
 block discarded – undo
165 165
 		$response = null;
166 166
 		if ($this->themingDefaults->shouldReplaceIcons()) {
167 167
 			try {
168
-				$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
168
+				$iconFile = $this->imageManager->getCachedImage('touchIcon-'.$app);
169 169
 			} catch (NotFoundException $exception) {
170 170
 				$icon = $this->iconBuilder->getTouchIcon($app);
171
-				$iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
171
+				$iconFile = $this->imageManager->setCachedImage('touchIcon-'.$app, $icon);
172 172
 			}
173 173
 			if ($iconFile !== false) {
174 174
 				$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
175 175
 			}
176 176
 		}
177
-		if($response === null) {
178
-			$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
177
+		if ($response === null) {
178
+			$fallbackLogo = \OC::$SERVERROOT.'/core/img/favicon-touch.png';
179 179
 			/** @var FileAccessHelper */
180 180
 			$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
181 181
 			$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
Please login to merge, or discard this patch.