Completed
Pull Request — master (#4108)
by Jan-Christoph
11:41
created
apps/theming/lib/ThemingDefaults.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -32,196 +32,196 @@
 block discarded – undo
32 32
 
33 33
 class ThemingDefaults extends \OC_Defaults {
34 34
 
35
-	/** @var IConfig */
36
-	private $config;
37
-	/** @var IL10N */
38
-	private $l;
39
-	/** @var IURLGenerator */
40
-	private $urlGenerator;
41
-	/** @var IRootFolder */
42
-	private $rootFolder;
43
-	/** @var ICacheFactory */
44
-	private $cacheFactory;
45
-	/** @var string */
46
-	private $name;
47
-	/** @var string */
48
-	private $url;
49
-	/** @var string */
50
-	private $slogan;
51
-	/** @var string */
52
-	private $color;
53
-
54
-	/**
55
-	 * ThemingDefaults constructor.
56
-	 *
57
-	 * @param IConfig $config
58
-	 * @param IL10N $l
59
-	 * @param IURLGenerator $urlGenerator
60
-	 * @param \OC_Defaults $defaults
61
-	 * @param IRootFolder $rootFolder
62
-	 * @param ICacheFactory $cacheFactory
63
-	 */
64
-	public function __construct(IConfig $config,
65
-								IL10N $l,
66
-								IURLGenerator $urlGenerator,
67
-								\OC_Defaults $defaults,
68
-								IRootFolder $rootFolder,
69
-								ICacheFactory $cacheFactory
70
-	) {
71
-		parent::__construct();
72
-		$this->config = $config;
73
-		$this->l = $l;
74
-		$this->urlGenerator = $urlGenerator;
75
-		$this->rootFolder = $rootFolder;
76
-		$this->cacheFactory = $cacheFactory;
77
-
78
-		$this->name = $defaults->getName();
79
-		$this->url = $defaults->getBaseUrl();
80
-		$this->slogan = $defaults->getSlogan();
81
-		$this->color = $defaults->getColorPrimary();
82
-	}
83
-
84
-	public function getName() {
85
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
-	}
87
-
88
-	public function getHTMLName() {
89
-		return $this->config->getAppValue('theming', 'name', $this->name);
90
-	}
91
-
92
-	public function getTitle() {
93
-		return $this->getName();
94
-	}
95
-
96
-	public function getEntity() {
97
-		return $this->getName();
98
-	}
99
-
100
-	public function getBaseUrl() {
101
-		return $this->config->getAppValue('theming', 'url', $this->url);
102
-	}
103
-
104
-	public function getSlogan() {
105
-		return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
-	}
107
-
108
-	public function getShortFooter() {
109
-		$slogan = $this->getSlogan();
110
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
-			($slogan !== '' ? ' – ' . $slogan : '');
113
-
114
-		return $footer;
115
-	}
116
-
117
-	/**
118
-	 * Color that is used for the header as well as for mail headers
119
-	 *
120
-	 * @return string
121
-	 */
122
-	public function getColorPrimary() {
123
-		return $this->config->getAppValue('theming', 'color', $this->color);
124
-	}
125
-
126
-	/**
127
-	 * Themed logo url
128
-	 *
129
-	 * @return string
130
-	 */
131
-	public function getLogo() {
132
-		$logo = $this->config->getAppValue('theming', 'logoMime');
133
-		if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) {
134
-			return $this->urlGenerator->imagePath('core','logo.svg');
135
-		} else {
136
-			return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
137
-		}
138
-	}
139
-
140
-	/**
141
-	 * Themed background image url
142
-	 *
143
-	 * @return string
144
-	 */
145
-	public function getBackground() {
146
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
147
-		if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) {
148
-			return $this->urlGenerator->imagePath('core','background.jpg');
149
-		} else {
150
-			return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Check if Imagemagick is enabled and if SVG is supported
156
-	 * otherwise we can't render custom icons
157
-	 *
158
-	 * @return bool
159
-	 */
160
-	public function shouldReplaceIcons() {
161
-		$cache = $this->cacheFactory->create('theming');
162
-		if($value = $cache->get('shouldReplaceIcons')) {
163
-			return (bool)$value;
164
-		}
165
-		$value = false;
166
-		if(extension_loaded('imagick')) {
167
-			$checkImagick = new \Imagick();
168
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
169
-				$value = true;
170
-			}
171
-			$checkImagick->clear();
172
-		}
173
-		$cache->set('shouldReplaceIcons', $value);
174
-		return $value;
175
-	}
176
-
177
-	/**
178
-	 * Increases the cache buster key
179
-	 */
180
-	private function increaseCacheBuster() {
181
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
182
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
183
-	}
184
-
185
-	/**
186
-	 * Update setting in the database
187
-	 *
188
-	 * @param string $setting
189
-	 * @param string $value
190
-	 */
191
-	public function set($setting, $value) {
192
-		$this->config->setAppValue('theming', $setting, $value);
193
-		$this->increaseCacheBuster();
194
-	}
195
-
196
-	/**
197
-	 * Revert settings to the default value
198
-	 *
199
-	 * @param string $setting setting which should be reverted
200
-	 * @return string default value
201
-	 */
202
-	public function undo($setting) {
203
-		$this->config->deleteAppValue('theming', $setting);
204
-		$this->increaseCacheBuster();
205
-
206
-		switch ($setting) {
207
-			case 'name':
208
-				$returnValue = $this->getEntity();
209
-				break;
210
-			case 'url':
211
-				$returnValue = $this->getBaseUrl();
212
-				break;
213
-			case 'slogan':
214
-				$returnValue = $this->getSlogan();
215
-				break;
216
-			case 'color':
217
-				$returnValue = $this->getColorPrimary();
218
-				break;
219
-			default:
220
-				$returnValue = '';
221
-				break;
222
-		}
223
-
224
-		return $returnValue;
225
-	}
35
+    /** @var IConfig */
36
+    private $config;
37
+    /** @var IL10N */
38
+    private $l;
39
+    /** @var IURLGenerator */
40
+    private $urlGenerator;
41
+    /** @var IRootFolder */
42
+    private $rootFolder;
43
+    /** @var ICacheFactory */
44
+    private $cacheFactory;
45
+    /** @var string */
46
+    private $name;
47
+    /** @var string */
48
+    private $url;
49
+    /** @var string */
50
+    private $slogan;
51
+    /** @var string */
52
+    private $color;
53
+
54
+    /**
55
+     * ThemingDefaults constructor.
56
+     *
57
+     * @param IConfig $config
58
+     * @param IL10N $l
59
+     * @param IURLGenerator $urlGenerator
60
+     * @param \OC_Defaults $defaults
61
+     * @param IRootFolder $rootFolder
62
+     * @param ICacheFactory $cacheFactory
63
+     */
64
+    public function __construct(IConfig $config,
65
+                                IL10N $l,
66
+                                IURLGenerator $urlGenerator,
67
+                                \OC_Defaults $defaults,
68
+                                IRootFolder $rootFolder,
69
+                                ICacheFactory $cacheFactory
70
+    ) {
71
+        parent::__construct();
72
+        $this->config = $config;
73
+        $this->l = $l;
74
+        $this->urlGenerator = $urlGenerator;
75
+        $this->rootFolder = $rootFolder;
76
+        $this->cacheFactory = $cacheFactory;
77
+
78
+        $this->name = $defaults->getName();
79
+        $this->url = $defaults->getBaseUrl();
80
+        $this->slogan = $defaults->getSlogan();
81
+        $this->color = $defaults->getColorPrimary();
82
+    }
83
+
84
+    public function getName() {
85
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
+    }
87
+
88
+    public function getHTMLName() {
89
+        return $this->config->getAppValue('theming', 'name', $this->name);
90
+    }
91
+
92
+    public function getTitle() {
93
+        return $this->getName();
94
+    }
95
+
96
+    public function getEntity() {
97
+        return $this->getName();
98
+    }
99
+
100
+    public function getBaseUrl() {
101
+        return $this->config->getAppValue('theming', 'url', $this->url);
102
+    }
103
+
104
+    public function getSlogan() {
105
+        return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
+    }
107
+
108
+    public function getShortFooter() {
109
+        $slogan = $this->getSlogan();
110
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
+            ($slogan !== '' ? ' – ' . $slogan : '');
113
+
114
+        return $footer;
115
+    }
116
+
117
+    /**
118
+     * Color that is used for the header as well as for mail headers
119
+     *
120
+     * @return string
121
+     */
122
+    public function getColorPrimary() {
123
+        return $this->config->getAppValue('theming', 'color', $this->color);
124
+    }
125
+
126
+    /**
127
+     * Themed logo url
128
+     *
129
+     * @return string
130
+     */
131
+    public function getLogo() {
132
+        $logo = $this->config->getAppValue('theming', 'logoMime');
133
+        if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) {
134
+            return $this->urlGenerator->imagePath('core','logo.svg');
135
+        } else {
136
+            return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
137
+        }
138
+    }
139
+
140
+    /**
141
+     * Themed background image url
142
+     *
143
+     * @return string
144
+     */
145
+    public function getBackground() {
146
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
147
+        if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) {
148
+            return $this->urlGenerator->imagePath('core','background.jpg');
149
+        } else {
150
+            return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Check if Imagemagick is enabled and if SVG is supported
156
+     * otherwise we can't render custom icons
157
+     *
158
+     * @return bool
159
+     */
160
+    public function shouldReplaceIcons() {
161
+        $cache = $this->cacheFactory->create('theming');
162
+        if($value = $cache->get('shouldReplaceIcons')) {
163
+            return (bool)$value;
164
+        }
165
+        $value = false;
166
+        if(extension_loaded('imagick')) {
167
+            $checkImagick = new \Imagick();
168
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
169
+                $value = true;
170
+            }
171
+            $checkImagick->clear();
172
+        }
173
+        $cache->set('shouldReplaceIcons', $value);
174
+        return $value;
175
+    }
176
+
177
+    /**
178
+     * Increases the cache buster key
179
+     */
180
+    private function increaseCacheBuster() {
181
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
182
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
183
+    }
184
+
185
+    /**
186
+     * Update setting in the database
187
+     *
188
+     * @param string $setting
189
+     * @param string $value
190
+     */
191
+    public function set($setting, $value) {
192
+        $this->config->setAppValue('theming', $setting, $value);
193
+        $this->increaseCacheBuster();
194
+    }
195
+
196
+    /**
197
+     * Revert settings to the default value
198
+     *
199
+     * @param string $setting setting which should be reverted
200
+     * @return string default value
201
+     */
202
+    public function undo($setting) {
203
+        $this->config->deleteAppValue('theming', $setting);
204
+        $this->increaseCacheBuster();
205
+
206
+        switch ($setting) {
207
+            case 'name':
208
+                $returnValue = $this->getEntity();
209
+                break;
210
+            case 'url':
211
+                $returnValue = $this->getBaseUrl();
212
+                break;
213
+            case 'slogan':
214
+                $returnValue = $this->getSlogan();
215
+                break;
216
+            case 'color':
217
+                $returnValue = $this->getColorPrimary();
218
+                break;
219
+            default:
220
+                $returnValue = '';
221
+                break;
222
+        }
223
+
224
+        return $returnValue;
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
apps/theming/lib/Capabilities.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -33,37 +33,37 @@
 block discarded – undo
33 33
  */
34 34
 class Capabilities implements ICapability {
35 35
 
36
-	/** @var ThemingDefaults */
37
-	protected $theming;
36
+    /** @var ThemingDefaults */
37
+    protected $theming;
38 38
 
39 39
 
40
-	/** @var IURLGenerator */
41
-	protected $url;
40
+    /** @var IURLGenerator */
41
+    protected $url;
42 42
 
43
-	/**
44
-	 * @param ThemingDefaults $theming
45
-	 * @param IURLGenerator $url
46
-	 */
47
-	public function __construct(ThemingDefaults $theming, IURLGenerator $url) {
48
-		$this->theming = $theming;
49
-		$this->url = $url;
50
-	}
43
+    /**
44
+     * @param ThemingDefaults $theming
45
+     * @param IURLGenerator $url
46
+     */
47
+    public function __construct(ThemingDefaults $theming, IURLGenerator $url) {
48
+        $this->theming = $theming;
49
+        $this->url = $url;
50
+    }
51 51
 
52
-	/**
53
-	 * Return this classes capabilities
54
-	 *
55
-	 * @return array
56
-	 */
57
-	public function getCapabilities() {
58
-		return [
59
-			'theming' => [
60
-				'name' => $this->theming->getName(),
61
-				'url' => $this->theming->getBaseUrl(),
62
-				'slogan' => $this->theming->getSlogan(),
63
-				'color' => $this->theming->getColorPrimary(),
64
-				'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
65
-				'background' => $this->url->getAbsoluteURL($this->theming->getBackground()),
66
-			],
67
-		];
68
-	}
52
+    /**
53
+     * Return this classes capabilities
54
+     *
55
+     * @return array
56
+     */
57
+    public function getCapabilities() {
58
+        return [
59
+            'theming' => [
60
+                'name' => $this->theming->getName(),
61
+                'url' => $this->theming->getBaseUrl(),
62
+                'slogan' => $this->theming->getSlogan(),
63
+                'color' => $this->theming->getColorPrimary(),
64
+                'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
65
+                'background' => $this->url->getAbsoluteURL($this->theming->getBackground()),
66
+            ],
67
+        ];
68
+    }
69 69
 }
Please login to merge, or discard this patch.
apps/theming/lib/IconBuilder.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -28,162 +28,162 @@
 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
-		$icon = $this->renderAppIcon($app, 32);
56
-		if($icon === false) {
57
-			return false;
58
-		}
59
-		$icon->setImageFormat("png24");
60
-		$data = $icon->getImageBlob();
61
-		$icon->destroy();
62
-		return $data;
63
-	}
64
-
65
-	/**
66
-	 * @param $app string app name
67
-	 * @return string|false image blob
68
-	 */
69
-	public function getTouchIcon($app) {
70
-		$icon = $this->renderAppIcon($app, 512);
71
-		if($icon === false) {
72
-			return false;
73
-		}
74
-		$icon->setImageFormat("png24");
75
-		$data = $icon->getImageBlob();
76
-		$icon->destroy();
77
-		return $data;
78
-	}
79
-
80
-	/**
81
-	 * Render app icon on themed background color
82
-	 * fallback to logo
83
-	 *
84
-	 * @param $app string app name
85
-	 * @param $size int size of the icon in px
86
-	 * @return Imagick|false
87
-	 */
88
-	public function renderAppIcon($app, $size) {
89
-		try {
90
-			$appIcon = $this->util->getAppIcon($app);
91
-			$appIconContent = file_get_contents($appIcon);
92
-		} catch (AppPathNotFoundException $e) {
93
-			return false;
94
-		}
95
-
96
-		if($appIconContent === false) {
97
-			return false;
98
-		}
99
-
100
-		$color = $this->themingDefaults->getColorPrimary();
101
-		$mime = mime_content_type($appIcon);
102
-
103
-		// generate background image with rounded corners
104
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
105
-			'<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">' .
106
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
107
-			'</svg>';
108
-		// resize svg magic as this seems broken in Imagemagick
109
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
110
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
111
-				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
112
-			} else {
113
-				$svg = $appIconContent;
114
-			}
115
-			$tmp = new Imagick();
116
-			$tmp->readImageBlob($svg);
117
-			$x = $tmp->getImageWidth();
118
-			$y = $tmp->getImageHeight();
119
-			$res = $tmp->getImageResolution();
120
-			$tmp->destroy();
121
-
122
-			if($x>$y) {
123
-				$max = $x;
124
-			} else {
125
-				$max = $y;
126
-			}
127
-
128
-			// convert svg to resized image
129
-			$appIconFile = new Imagick();
130
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
131
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
132
-			$appIconFile->setResolution($resX, $resY);
133
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
134
-			$appIconFile->readImageBlob($svg);
135
-			$appIconFile->scaleImage(512, 512, true);
136
-		} else {
137
-			$appIconFile = new Imagick();
138
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
139
-			$appIconFile->readImageBlob(file_get_contents($appIcon));
140
-			$appIconFile->scaleImage(512, 512, true);
141
-		}
142
-
143
-		// offset for icon positioning
144
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
145
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
146
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
147
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
148
-		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
149
-		// center icon
150
-		$offset_w = 512 / 2 - $innerWidth / 2;
151
-		$offset_h = 512 / 2 - $innerHeight / 2;
152
-
153
-		$appIconFile->setImageFormat("png24");
154
-
155
-		$finalIconFile = new Imagick();
156
-		$finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
157
-		$finalIconFile->readImageBlob($background);
158
-		$finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
159
-		$finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
160
-		$finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
161
-		$finalIconFile->setImageFormat('png24');
162
-		if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
163
-			$filter = Imagick::INTERPOLATE_BICUBIC;
164
-		} else {
165
-			$filter = Imagick::FILTER_LANCZOS;
166
-		}
167
-		$finalIconFile->resizeImage($size, $size, $filter, 1, false);
168
-
169
-		$appIconFile->destroy();
170
-		return $finalIconFile;
171
-	}
172
-
173
-	public function colorSvg($app, $image) {
174
-		try {
175
-			$imageFile = $this->util->getAppImage($app, $image);
176
-		} catch (AppPathNotFoundException $e) {
177
-			return false;
178
-		}
179
-		$svg = file_get_contents($imageFile);
180
-		if ($svg !== false && $svg !== "") {
181
-			$color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
182
-			$svg = $this->util->colorizeSvg($svg, $color);
183
-			return $svg;
184
-		} else {
185
-			return false;
186
-		}
187
-	}
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
+        $icon = $this->renderAppIcon($app, 32);
56
+        if($icon === false) {
57
+            return false;
58
+        }
59
+        $icon->setImageFormat("png24");
60
+        $data = $icon->getImageBlob();
61
+        $icon->destroy();
62
+        return $data;
63
+    }
64
+
65
+    /**
66
+     * @param $app string app name
67
+     * @return string|false image blob
68
+     */
69
+    public function getTouchIcon($app) {
70
+        $icon = $this->renderAppIcon($app, 512);
71
+        if($icon === false) {
72
+            return false;
73
+        }
74
+        $icon->setImageFormat("png24");
75
+        $data = $icon->getImageBlob();
76
+        $icon->destroy();
77
+        return $data;
78
+    }
79
+
80
+    /**
81
+     * Render app icon on themed background color
82
+     * fallback to logo
83
+     *
84
+     * @param $app string app name
85
+     * @param $size int size of the icon in px
86
+     * @return Imagick|false
87
+     */
88
+    public function renderAppIcon($app, $size) {
89
+        try {
90
+            $appIcon = $this->util->getAppIcon($app);
91
+            $appIconContent = file_get_contents($appIcon);
92
+        } catch (AppPathNotFoundException $e) {
93
+            return false;
94
+        }
95
+
96
+        if($appIconContent === false) {
97
+            return false;
98
+        }
99
+
100
+        $color = $this->themingDefaults->getColorPrimary();
101
+        $mime = mime_content_type($appIcon);
102
+
103
+        // generate background image with rounded corners
104
+        $background = '<?xml version="1.0" encoding="UTF-8"?>' .
105
+            '<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">' .
106
+            '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
107
+            '</svg>';
108
+        // resize svg magic as this seems broken in Imagemagick
109
+        if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
110
+            if(substr($appIconContent, 0, 5) !== "<?xml") {
111
+                $svg = "<?xml version=\"1.0\"?>".$appIconContent;
112
+            } else {
113
+                $svg = $appIconContent;
114
+            }
115
+            $tmp = new Imagick();
116
+            $tmp->readImageBlob($svg);
117
+            $x = $tmp->getImageWidth();
118
+            $y = $tmp->getImageHeight();
119
+            $res = $tmp->getImageResolution();
120
+            $tmp->destroy();
121
+
122
+            if($x>$y) {
123
+                $max = $x;
124
+            } else {
125
+                $max = $y;
126
+            }
127
+
128
+            // convert svg to resized image
129
+            $appIconFile = new Imagick();
130
+            $resX = (int)(512 * $res['x'] / $max * 2.53);
131
+            $resY = (int)(512 * $res['y'] / $max * 2.53);
132
+            $appIconFile->setResolution($resX, $resY);
133
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
134
+            $appIconFile->readImageBlob($svg);
135
+            $appIconFile->scaleImage(512, 512, true);
136
+        } else {
137
+            $appIconFile = new Imagick();
138
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
139
+            $appIconFile->readImageBlob(file_get_contents($appIcon));
140
+            $appIconFile->scaleImage(512, 512, true);
141
+        }
142
+
143
+        // offset for icon positioning
144
+        $border_w = (int)($appIconFile->getImageWidth() * 0.05);
145
+        $border_h = (int)($appIconFile->getImageHeight() * 0.05);
146
+        $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
147
+        $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
148
+        $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
149
+        // center icon
150
+        $offset_w = 512 / 2 - $innerWidth / 2;
151
+        $offset_h = 512 / 2 - $innerHeight / 2;
152
+
153
+        $appIconFile->setImageFormat("png24");
154
+
155
+        $finalIconFile = new Imagick();
156
+        $finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
157
+        $finalIconFile->readImageBlob($background);
158
+        $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
159
+        $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
160
+        $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
161
+        $finalIconFile->setImageFormat('png24');
162
+        if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
163
+            $filter = Imagick::INTERPOLATE_BICUBIC;
164
+        } else {
165
+            $filter = Imagick::FILTER_LANCZOS;
166
+        }
167
+        $finalIconFile->resizeImage($size, $size, $filter, 1, false);
168
+
169
+        $appIconFile->destroy();
170
+        return $finalIconFile;
171
+    }
172
+
173
+    public function colorSvg($app, $image) {
174
+        try {
175
+            $imageFile = $this->util->getAppImage($app, $image);
176
+        } catch (AppPathNotFoundException $e) {
177
+            return false;
178
+        }
179
+        $svg = file_get_contents($imageFile);
180
+        if ($svg !== false && $svg !== "") {
181
+            $color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
182
+            $svg = $this->util->colorizeSvg($svg, $color);
183
+            return $svg;
184
+        } else {
185
+            return false;
186
+        }
187
+    }
188 188
 
189 189
 }
Please login to merge, or discard this patch.
apps/encryption/templates/mail.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 	<tr><td>
7 7
 			<table cellspacing="0" cellpadding="0" border="0" width="600px">
8 8
 				<tr>
9
-					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>">
9
+					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>">
10 10
 						<img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
11 11
 					</td>
12 12
 				</tr>
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 					<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
28 28
 						<?php p($theme->getName()); ?> -
29 29
 						<?php p($theme->getSlogan()); ?>
30
-						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a>
30
+						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a>
31 31
 					</td>
32 32
 				</tr>
33 33
 				<tr>
Please login to merge, or discard this patch.