Completed
Pull Request — master (#10075)
by
unknown
27:10
created
settings/Activity/SecurityFilter.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -28,39 +28,39 @@
 block discarded – undo
28 28
 
29 29
 class SecurityFilter implements IFilter {
30 30
 
31
-	/** @var IURLGenerator */
32
-	private $urlGenerator;
31
+    /** @var IURLGenerator */
32
+    private $urlGenerator;
33 33
 
34
-	/** @var IL10N */
35
-	private $l10n;
34
+    /** @var IL10N */
35
+    private $l10n;
36 36
 
37
-	public function __construct(IURLGenerator $urlGenerator, IL10N $l10n) {
38
-		$this->urlGenerator = $urlGenerator;
39
-		$this->l10n = $l10n;
40
-	}
37
+    public function __construct(IURLGenerator $urlGenerator, IL10N $l10n) {
38
+        $this->urlGenerator = $urlGenerator;
39
+        $this->l10n = $l10n;
40
+    }
41 41
 
42
-	public function allowedApps() {
43
-		return [];
44
-	}
42
+    public function allowedApps() {
43
+        return [];
44
+    }
45 45
 
46
-	public function filterTypes(array $types) {
47
-		return array_intersect(['security'], $types);
48
-	}
46
+    public function filterTypes(array $types) {
47
+        return array_intersect(['security'], $types);
48
+    }
49 49
 
50
-	public function getIcon() {
51
-		return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'));
52
-	}
50
+    public function getIcon() {
51
+        return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'));
52
+    }
53 53
 
54
-	public function getIdentifier() {
55
-		return 'security';
56
-	}
54
+    public function getIdentifier() {
55
+        return 'security';
56
+    }
57 57
 
58
-	public function getName() {
59
-		return $this->l10n->t('Security');
60
-	}
58
+    public function getName() {
59
+        return $this->l10n->t('Security');
60
+    }
61 61
 
62
-	public function getPriority() {
63
-		return 30;
64
-	}
62
+    public function getPriority() {
63
+        return 30;
64
+    }
65 65
 
66 66
 }
Please login to merge, or discard this patch.
settings/Activity/SecuritySetting.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,39 +27,39 @@
 block discarded – undo
27 27
 
28 28
 class SecuritySetting implements ISetting {
29 29
 
30
-	/** @var IL10N */
31
-	private $l10n;
30
+    /** @var IL10N */
31
+    private $l10n;
32 32
 
33
-	public function __construct(IL10N $l10n) {
34
-		$this->l10n = $l10n;
35
-	}
33
+    public function __construct(IL10N $l10n) {
34
+        $this->l10n = $l10n;
35
+    }
36 36
 
37
-	public function canChangeMail() {
38
-		return false;
39
-	}
37
+    public function canChangeMail() {
38
+        return false;
39
+    }
40 40
 
41
-	public function canChangeStream() {
42
-		return false;
43
-	}
41
+    public function canChangeStream() {
42
+        return false;
43
+    }
44 44
 
45
-	public function getIdentifier() {
46
-		return 'security';
47
-	}
45
+    public function getIdentifier() {
46
+        return 'security';
47
+    }
48 48
 
49
-	public function getName() {
50
-		return $this->l10n->t('Security');
51
-	}
49
+    public function getName() {
50
+        return $this->l10n->t('Security');
51
+    }
52 52
 
53
-	public function getPriority() {
54
-		return 30;
55
-	}
53
+    public function getPriority() {
54
+        return 30;
55
+    }
56 56
 
57
-	public function isDefaultEnabledMail() {
58
-		return true;
59
-	}
57
+    public function isDefaultEnabledMail() {
58
+        return true;
59
+    }
60 60
 
61
-	public function isDefaultEnabledStream() {
62
-		return true;
63
-	}
61
+    public function isDefaultEnabledStream() {
62
+        return true;
63
+    }
64 64
 
65 65
 }
Please login to merge, or discard this patch.
lib/private/ServerContainer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 
85 85
 		if (isset($this->namespaces[$namespace])) {
86 86
 			if (!isset($this->hasNoAppContainer[$namespace])) {
87
-				$applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
87
+				$applicationClassName = 'OCA\\'.$sensitiveNamespace.'\\AppInfo\\Application';
88 88
 				if (class_exists($applicationClassName)) {
89 89
 					new $applicationClassName();
90 90
 					if (isset($this->appContainers[$namespace])) {
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,101 +34,101 @@
 block discarded – undo
34 34
  * @package OC
35 35
  */
36 36
 class ServerContainer extends SimpleContainer {
37
-	/** @var DIContainer[] */
38
-	protected $appContainers;
37
+    /** @var DIContainer[] */
38
+    protected $appContainers;
39 39
 
40
-	/** @var string[] */
41
-	protected $hasNoAppContainer;
40
+    /** @var string[] */
41
+    protected $hasNoAppContainer;
42 42
 
43
-	/** @var string[] */
44
-	protected $namespaces;
43
+    /** @var string[] */
44
+    protected $namespaces;
45 45
 
46
-	/**
47
-	 * ServerContainer constructor.
48
-	 */
49
-	public function __construct() {
50
-		parent::__construct();
51
-		$this->appContainers = [];
52
-		$this->namespaces = [];
53
-		$this->hasNoAppContainer = [];
54
-	}
46
+    /**
47
+     * ServerContainer constructor.
48
+     */
49
+    public function __construct() {
50
+        parent::__construct();
51
+        $this->appContainers = [];
52
+        $this->namespaces = [];
53
+        $this->hasNoAppContainer = [];
54
+    }
55 55
 
56
-	/**
57
-	 * @param string $appName
58
-	 * @param string $appNamespace
59
-	 */
60
-	public function registerNamespace($appName, $appNamespace) {
61
-		// Cut of OCA\ and lowercase
62
-		$appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
63
-		$this->namespaces[$appNamespace] = $appName;
64
-	}
56
+    /**
57
+     * @param string $appName
58
+     * @param string $appNamespace
59
+     */
60
+    public function registerNamespace($appName, $appNamespace) {
61
+        // Cut of OCA\ and lowercase
62
+        $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
63
+        $this->namespaces[$appNamespace] = $appName;
64
+    }
65 65
 
66
-	/**
67
-	 * @param string $appName
68
-	 * @param DIContainer $container
69
-	 */
70
-	public function registerAppContainer($appName, DIContainer $container) {
71
-		$this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
72
-	}
66
+    /**
67
+     * @param string $appName
68
+     * @param DIContainer $container
69
+     */
70
+    public function registerAppContainer($appName, DIContainer $container) {
71
+        $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
72
+    }
73 73
 
74
-	/**
75
-	 * @param string $namespace
76
-	 * @param string $sensitiveNamespace
77
-	 * @return DIContainer
78
-	 * @throws QueryException
79
-	 */
80
-	protected function getAppContainer($namespace, $sensitiveNamespace) {
81
-		if (isset($this->appContainers[$namespace])) {
82
-			return $this->appContainers[$namespace];
83
-		}
74
+    /**
75
+     * @param string $namespace
76
+     * @param string $sensitiveNamespace
77
+     * @return DIContainer
78
+     * @throws QueryException
79
+     */
80
+    protected function getAppContainer($namespace, $sensitiveNamespace) {
81
+        if (isset($this->appContainers[$namespace])) {
82
+            return $this->appContainers[$namespace];
83
+        }
84 84
 
85
-		if (isset($this->namespaces[$namespace])) {
86
-			if (!isset($this->hasNoAppContainer[$namespace])) {
87
-				$applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
88
-				if (class_exists($applicationClassName)) {
89
-					new $applicationClassName();
90
-					if (isset($this->appContainers[$namespace])) {
91
-						return $this->appContainers[$namespace];
92
-					}
93
-				}
94
-				$this->hasNoAppContainer[$namespace] = true;
95
-			}
85
+        if (isset($this->namespaces[$namespace])) {
86
+            if (!isset($this->hasNoAppContainer[$namespace])) {
87
+                $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
88
+                if (class_exists($applicationClassName)) {
89
+                    new $applicationClassName();
90
+                    if (isset($this->appContainers[$namespace])) {
91
+                        return $this->appContainers[$namespace];
92
+                    }
93
+                }
94
+                $this->hasNoAppContainer[$namespace] = true;
95
+            }
96 96
 
97
-			return new DIContainer($this->namespaces[$namespace]);
98
-		}
99
-		throw new QueryException();
100
-	}
97
+            return new DIContainer($this->namespaces[$namespace]);
98
+        }
99
+        throw new QueryException();
100
+    }
101 101
 
102
-	/**
103
-	 * @param string $name name of the service to query for
104
-	 * @return mixed registered service for the given $name
105
-	 * @throws QueryException if the query could not be resolved
106
-	 */
107
-	public function query($name) {
108
-		$name = $this->sanitizeName($name);
102
+    /**
103
+     * @param string $name name of the service to query for
104
+     * @return mixed registered service for the given $name
105
+     * @throws QueryException if the query could not be resolved
106
+     */
107
+    public function query($name) {
108
+        $name = $this->sanitizeName($name);
109 109
 
110
-		// In case the service starts with OCA\ we try to find the service in
111
-		// the apps container first.
112
-		if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
113
-			$segments = explode('\\', $name);
114
-			try {
115
-				$appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
116
-				return $appContainer->queryNoFallback($name);
117
-			} catch (QueryException $e) {
118
-				// Didn't find the service or the respective app container,
119
-				// ignore it and fall back to the core container.
120
-			}
121
-		} else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) {
122
-			$segments = explode('\\', $name);
123
-			try {
124
-				$appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
125
-				return $appContainer->queryNoFallback($name);
126
-			} catch (QueryException $e) {
127
-				// Didn't find the service or the respective app container,
128
-				// ignore it and fall back to the core container.
129
-			}
130
-		}
110
+        // In case the service starts with OCA\ we try to find the service in
111
+        // the apps container first.
112
+        if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
113
+            $segments = explode('\\', $name);
114
+            try {
115
+                $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
116
+                return $appContainer->queryNoFallback($name);
117
+            } catch (QueryException $e) {
118
+                // Didn't find the service or the respective app container,
119
+                // ignore it and fall back to the core container.
120
+            }
121
+        } else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) {
122
+            $segments = explode('\\', $name);
123
+            try {
124
+                $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
125
+                return $appContainer->queryNoFallback($name);
126
+            } catch (QueryException $e) {
127
+                // Didn't find the service or the respective app container,
128
+                // ignore it and fall back to the core container.
129
+            }
130
+        }
131 131
 
132
-		return parent::query($name);
133
-	}
132
+        return parent::query($name);
133
+    }
134 134
 }
Please login to merge, or discard this patch.
apps/theming/lib/Util.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	/**
72 72
 	 * get color for on-page elements:
73 73
 	 * theme color by default, grey if theme color is to bright
74
-	 * @param $color
74
+	 * @param string $color
75 75
 	 * @return string
76 76
 	 */
77 77
 	public function elementColor($color) {
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
 	/**
116 116
 	 * @param $app string app name
117
-	 * @return string|ISimpleFile path to app icon / file of logo
117
+	 * @return string path to app icon / file of logo
118 118
 	 */
119 119
 	public function getAppIcon($app) {
120 120
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	/**
191 191
 	 * replace default color with a custom one
192 192
 	 *
193
-	 * @param $svg string content of a svg file
194
-	 * @param $color string color to match
193
+	 * @param string $svg string content of a svg file
194
+	 * @param string $color string color to match
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function colorizeSvg($svg, $color) {
Please login to merge, or discard this patch.
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -36,215 +36,215 @@
 block discarded – undo
36 36
 
37 37
 class Util {
38 38
 
39
-	/** @var IConfig */
40
-	private $config;
41
-
42
-	/** @var IAppManager */
43
-	private $appManager;
44
-
45
-	/** @var IAppData */
46
-	private $appData;
47
-
48
-	/**
49
-	 * Util constructor.
50
-	 *
51
-	 * @param IConfig $config
52
-	 * @param IAppManager $appManager
53
-	 * @param IAppData $appData
54
-	 */
55
-	public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) {
56
-		$this->config = $config;
57
-		$this->appManager = $appManager;
58
-		$this->appData = $appData;
59
-	}
60
-
61
-	/**
62
-	 * @param string $color rgb color value
63
-	 * @return bool
64
-	 */
65
-	public function invertTextColor($color) {
66
-		$l = $this->calculateLuma($color);
67
-		if($l>0.6) {
68
-			return true;
69
-		} else {
70
-			return false;
71
-		}
72
-	}
73
-
74
-	/**
75
-	 * get color for on-page elements:
76
-	 * theme color by default, grey if theme color is to bright
77
-	 * @param $color
78
-	 * @return string
79
-	 */
80
-	public function elementColor($color) {
81
-		$l = $this->calculateLuminance($color);
82
-		if($l>0.8) {
83
-			return '#555555';
84
-		}
85
-		return $color;
86
-	}
87
-
88
-	/**
89
-	 * @param string $color rgb color value
90
-	 * @return float
91
-	 */
92
-	public function calculateLuminance($color) {
93
-		list($red, $green, $blue) = $this->hexToRGB($color);
94
-		$compiler = new Compiler();
95
-		$hsl = $compiler->toHSL($red, $green, $blue);
96
-		return $hsl[3]/100;
97
-	}
98
-
99
-	/**
100
-	 * @param string $color rgb color value
101
-	 * @return float
102
-	 */
103
-	public function calculateLuma($color) {
104
-		list($red, $green, $blue) = $this->hexToRGB($color);
105
-		return (0.2126 * $red  + 0.7152 * $green + 0.0722 * $blue) / 255;
106
-	}
107
-
108
-	/**
109
-	 * @param string $color rgb color value
110
-	 * @return int[]
111
-	 */
112
-	public function hexToRGB($color) {
113
-		$hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
114
-		if (strlen($hex) === 3) {
115
-			$hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
116
-		}
117
-		if (strlen($hex) !== 6) {
118
-			return 0;
119
-		}
120
-		return [
121
-			hexdec(substr($hex, 0, 2)),
122
-			hexdec(substr($hex, 2, 2)),
123
-			hexdec(substr($hex, 4, 2))
124
-		];
125
-	}
126
-
127
-	/**
128
-	 * @param $color
129
-	 * @return string base64 encoded radio button svg
130
-	 */
131
-	public function generateRadioButton($color) {
132
-		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
133
-			'<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
134
-		return base64_encode($radioButtonIcon);
135
-	}
136
-
137
-
138
-	/**
139
-	 * @param $app string app name
140
-	 * @return string|ISimpleFile path to app icon / file of logo
141
-	 */
142
-	public function getAppIcon($app) {
143
-		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
144
-		try {
145
-			$appPath = $this->appManager->getAppPath($app);
146
-			$icon = $appPath . '/img/' . $app . '.svg';
147
-			if (file_exists($icon)) {
148
-				return $icon;
149
-			}
150
-			$icon = $appPath . '/img/app.svg';
151
-			if (file_exists($icon)) {
152
-				return $icon;
153
-			}
154
-		} catch (AppPathNotFoundException $e) {}
155
-
156
-		if ($this->config->getAppValue('theming', 'logoMime', '') !== '') {
157
-			$logoFile = null;
158
-			try {
159
-				$folder = $this->appData->getFolder('images');
160
-				if ($folder !== null) {
161
-					return $folder->getFile('logo');
162
-				}
163
-			} catch (NotFoundException $e) {}
164
-		}
165
-		return \OC::$SERVERROOT . '/core/img/logo.svg';
166
-	}
167
-
168
-	/**
169
-	 * @param $app string app name
170
-	 * @param $image string relative path to image in app folder
171
-	 * @return string|false absolute path to image
172
-	 */
173
-	public function getAppImage($app, $image) {
174
-		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
175
-		$image = str_replace(array('\0', '\\', '..'), '', $image);
176
-		if ($app === "core") {
177
-			$icon = \OC::$SERVERROOT . '/core/img/' . $image;
178
-			if (file_exists($icon)) {
179
-				return $icon;
180
-			}
181
-		}
182
-
183
-		try {
184
-			$appPath = $this->appManager->getAppPath($app);
185
-		} catch (AppPathNotFoundException $e) {
186
-			return false;
187
-		}
188
-
189
-		$icon = $appPath . '/img/' . $image;
190
-		if (file_exists($icon)) {
191
-			return $icon;
192
-		}
193
-		$icon = $appPath . '/img/' . $image . '.svg';
194
-		if (file_exists($icon)) {
195
-			return $icon;
196
-		}
197
-		$icon = $appPath . '/img/' . $image . '.png';
198
-		if (file_exists($icon)) {
199
-			return $icon;
200
-		}
201
-		$icon = $appPath . '/img/' . $image . '.gif';
202
-		if (file_exists($icon)) {
203
-			return $icon;
204
-		}
205
-		$icon = $appPath . '/img/' . $image . '.jpg';
206
-		if (file_exists($icon)) {
207
-			return $icon;
208
-		}
209
-
210
-		return false;
211
-	}
212
-
213
-	/**
214
-	 * replace default color with a custom one
215
-	 *
216
-	 * @param $svg string content of a svg file
217
-	 * @param $color string color to match
218
-	 * @return string
219
-	 */
220
-	public function colorizeSvg($svg, $color) {
221
-		$svg = preg_replace('/#0082c9/i', $color, $svg);
222
-		return $svg;
223
-	}
224
-
225
-	/**
226
-	 * Check if a custom theme is set in the server configuration
227
-	 * 
228
-	 * @return bool
229
-	 */
230
-	public function isAlreadyThemed() {
231
-		$theme = $this->config->getSystemValue('theme', '');
232
-		if ($theme !== '') {
233
-			return true;
234
-		}
235
-		return false;
236
-	}
237
-
238
-	public function isBackgroundThemed() {
239
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
240
-
241
-		$backgroundExists = true;
242
-		try {
243
-			$this->appData->getFolder('images')->getFile('background');
244
-		} catch (\Exception $e) {
245
-			$backgroundExists = false;
246
-		}
247
-		return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists;
248
-	}
39
+    /** @var IConfig */
40
+    private $config;
41
+
42
+    /** @var IAppManager */
43
+    private $appManager;
44
+
45
+    /** @var IAppData */
46
+    private $appData;
47
+
48
+    /**
49
+     * Util constructor.
50
+     *
51
+     * @param IConfig $config
52
+     * @param IAppManager $appManager
53
+     * @param IAppData $appData
54
+     */
55
+    public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) {
56
+        $this->config = $config;
57
+        $this->appManager = $appManager;
58
+        $this->appData = $appData;
59
+    }
60
+
61
+    /**
62
+     * @param string $color rgb color value
63
+     * @return bool
64
+     */
65
+    public function invertTextColor($color) {
66
+        $l = $this->calculateLuma($color);
67
+        if($l>0.6) {
68
+            return true;
69
+        } else {
70
+            return false;
71
+        }
72
+    }
73
+
74
+    /**
75
+     * get color for on-page elements:
76
+     * theme color by default, grey if theme color is to bright
77
+     * @param $color
78
+     * @return string
79
+     */
80
+    public function elementColor($color) {
81
+        $l = $this->calculateLuminance($color);
82
+        if($l>0.8) {
83
+            return '#555555';
84
+        }
85
+        return $color;
86
+    }
87
+
88
+    /**
89
+     * @param string $color rgb color value
90
+     * @return float
91
+     */
92
+    public function calculateLuminance($color) {
93
+        list($red, $green, $blue) = $this->hexToRGB($color);
94
+        $compiler = new Compiler();
95
+        $hsl = $compiler->toHSL($red, $green, $blue);
96
+        return $hsl[3]/100;
97
+    }
98
+
99
+    /**
100
+     * @param string $color rgb color value
101
+     * @return float
102
+     */
103
+    public function calculateLuma($color) {
104
+        list($red, $green, $blue) = $this->hexToRGB($color);
105
+        return (0.2126 * $red  + 0.7152 * $green + 0.0722 * $blue) / 255;
106
+    }
107
+
108
+    /**
109
+     * @param string $color rgb color value
110
+     * @return int[]
111
+     */
112
+    public function hexToRGB($color) {
113
+        $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
114
+        if (strlen($hex) === 3) {
115
+            $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
116
+        }
117
+        if (strlen($hex) !== 6) {
118
+            return 0;
119
+        }
120
+        return [
121
+            hexdec(substr($hex, 0, 2)),
122
+            hexdec(substr($hex, 2, 2)),
123
+            hexdec(substr($hex, 4, 2))
124
+        ];
125
+    }
126
+
127
+    /**
128
+     * @param $color
129
+     * @return string base64 encoded radio button svg
130
+     */
131
+    public function generateRadioButton($color) {
132
+        $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
133
+            '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
134
+        return base64_encode($radioButtonIcon);
135
+    }
136
+
137
+
138
+    /**
139
+     * @param $app string app name
140
+     * @return string|ISimpleFile path to app icon / file of logo
141
+     */
142
+    public function getAppIcon($app) {
143
+        $app = str_replace(array('\0', '/', '\\', '..'), '', $app);
144
+        try {
145
+            $appPath = $this->appManager->getAppPath($app);
146
+            $icon = $appPath . '/img/' . $app . '.svg';
147
+            if (file_exists($icon)) {
148
+                return $icon;
149
+            }
150
+            $icon = $appPath . '/img/app.svg';
151
+            if (file_exists($icon)) {
152
+                return $icon;
153
+            }
154
+        } catch (AppPathNotFoundException $e) {}
155
+
156
+        if ($this->config->getAppValue('theming', 'logoMime', '') !== '') {
157
+            $logoFile = null;
158
+            try {
159
+                $folder = $this->appData->getFolder('images');
160
+                if ($folder !== null) {
161
+                    return $folder->getFile('logo');
162
+                }
163
+            } catch (NotFoundException $e) {}
164
+        }
165
+        return \OC::$SERVERROOT . '/core/img/logo.svg';
166
+    }
167
+
168
+    /**
169
+     * @param $app string app name
170
+     * @param $image string relative path to image in app folder
171
+     * @return string|false absolute path to image
172
+     */
173
+    public function getAppImage($app, $image) {
174
+        $app = str_replace(array('\0', '/', '\\', '..'), '', $app);
175
+        $image = str_replace(array('\0', '\\', '..'), '', $image);
176
+        if ($app === "core") {
177
+            $icon = \OC::$SERVERROOT . '/core/img/' . $image;
178
+            if (file_exists($icon)) {
179
+                return $icon;
180
+            }
181
+        }
182
+
183
+        try {
184
+            $appPath = $this->appManager->getAppPath($app);
185
+        } catch (AppPathNotFoundException $e) {
186
+            return false;
187
+        }
188
+
189
+        $icon = $appPath . '/img/' . $image;
190
+        if (file_exists($icon)) {
191
+            return $icon;
192
+        }
193
+        $icon = $appPath . '/img/' . $image . '.svg';
194
+        if (file_exists($icon)) {
195
+            return $icon;
196
+        }
197
+        $icon = $appPath . '/img/' . $image . '.png';
198
+        if (file_exists($icon)) {
199
+            return $icon;
200
+        }
201
+        $icon = $appPath . '/img/' . $image . '.gif';
202
+        if (file_exists($icon)) {
203
+            return $icon;
204
+        }
205
+        $icon = $appPath . '/img/' . $image . '.jpg';
206
+        if (file_exists($icon)) {
207
+            return $icon;
208
+        }
209
+
210
+        return false;
211
+    }
212
+
213
+    /**
214
+     * replace default color with a custom one
215
+     *
216
+     * @param $svg string content of a svg file
217
+     * @param $color string color to match
218
+     * @return string
219
+     */
220
+    public function colorizeSvg($svg, $color) {
221
+        $svg = preg_replace('/#0082c9/i', $color, $svg);
222
+        return $svg;
223
+    }
224
+
225
+    /**
226
+     * Check if a custom theme is set in the server configuration
227
+     * 
228
+     * @return bool
229
+     */
230
+    public function isAlreadyThemed() {
231
+        $theme = $this->config->getSystemValue('theme', '');
232
+        if ($theme !== '') {
233
+            return true;
234
+        }
235
+        return false;
236
+    }
237
+
238
+    public function isBackgroundThemed() {
239
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
240
+
241
+        $backgroundExists = true;
242
+        try {
243
+            $this->appData->getFolder('images')->getFile('background');
244
+        } catch (\Exception $e) {
245
+            $backgroundExists = false;
246
+        }
247
+        return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists;
248
+    }
249 249
 
250 250
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function invertTextColor($color) {
66 66
 		$l = $this->calculateLuma($color);
67
-		if($l>0.6) {
67
+		if ($l > 0.6) {
68 68
 			return true;
69 69
 		} else {
70 70
 			return false;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function elementColor($color) {
81 81
 		$l = $this->calculateLuminance($color);
82
-		if($l>0.8) {
82
+		if ($l > 0.8) {
83 83
 			return '#555555';
84 84
 		}
85 85
 		return $color;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		list($red, $green, $blue) = $this->hexToRGB($color);
94 94
 		$compiler = new Compiler();
95 95
 		$hsl = $compiler->toHSL($red, $green, $blue);
96
-		return $hsl[3]/100;
96
+		return $hsl[3] / 100;
97 97
 	}
98 98
 
99 99
 	/**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function calculateLuma($color) {
104 104
 		list($red, $green, $blue) = $this->hexToRGB($color);
105
-		return (0.2126 * $red  + 0.7152 * $green + 0.0722 * $blue) / 255;
105
+		return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255;
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	public function hexToRGB($color) {
113 113
 		$hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
114 114
 		if (strlen($hex) === 3) {
115
-			$hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
115
+			$hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2};
116 116
 		}
117 117
 		if (strlen($hex) !== 6) {
118 118
 			return 0;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @return string base64 encoded radio button svg
130 130
 	 */
131 131
 	public function generateRadioButton($color) {
132
-		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
132
+		$radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'.
133 133
 			'<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
134 134
 		return base64_encode($radioButtonIcon);
135 135
 	}
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
144 144
 		try {
145 145
 			$appPath = $this->appManager->getAppPath($app);
146
-			$icon = $appPath . '/img/' . $app . '.svg';
146
+			$icon = $appPath.'/img/'.$app.'.svg';
147 147
 			if (file_exists($icon)) {
148 148
 				return $icon;
149 149
 			}
150
-			$icon = $appPath . '/img/app.svg';
150
+			$icon = $appPath.'/img/app.svg';
151 151
 			if (file_exists($icon)) {
152 152
 				return $icon;
153 153
 			}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 				}
163 163
 			} catch (NotFoundException $e) {}
164 164
 		}
165
-		return \OC::$SERVERROOT . '/core/img/logo.svg';
165
+		return \OC::$SERVERROOT.'/core/img/logo.svg';
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 		$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
175 175
 		$image = str_replace(array('\0', '\\', '..'), '', $image);
176 176
 		if ($app === "core") {
177
-			$icon = \OC::$SERVERROOT . '/core/img/' . $image;
177
+			$icon = \OC::$SERVERROOT.'/core/img/'.$image;
178 178
 			if (file_exists($icon)) {
179 179
 				return $icon;
180 180
 			}
@@ -186,23 +186,23 @@  discard block
 block discarded – undo
186 186
 			return false;
187 187
 		}
188 188
 
189
-		$icon = $appPath . '/img/' . $image;
189
+		$icon = $appPath.'/img/'.$image;
190 190
 		if (file_exists($icon)) {
191 191
 			return $icon;
192 192
 		}
193
-		$icon = $appPath . '/img/' . $image . '.svg';
193
+		$icon = $appPath.'/img/'.$image.'.svg';
194 194
 		if (file_exists($icon)) {
195 195
 			return $icon;
196 196
 		}
197
-		$icon = $appPath . '/img/' . $image . '.png';
197
+		$icon = $appPath.'/img/'.$image.'.png';
198 198
 		if (file_exists($icon)) {
199 199
 			return $icon;
200 200
 		}
201
-		$icon = $appPath . '/img/' . $image . '.gif';
201
+		$icon = $appPath.'/img/'.$image.'.gif';
202 202
 		if (file_exists($icon)) {
203 203
 			return $icon;
204 204
 		}
205
-		$icon = $appPath . '/img/' . $image . '.jpg';
205
+		$icon = $appPath.'/img/'.$image.'.jpg';
206 206
 		if (file_exists($icon)) {
207 207
 			return $icon;
208 208
 		}
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	}
237 237
 
238 238
 	public function isBackgroundThemed() {
239
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
239
+		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
240 240
 
241 241
 		$backgroundExists = true;
242 242
 		try {
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CachePermissionsMask.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,25 +24,25 @@
 block discarded – undo
24 24
 namespace OC\Files\Cache\Wrapper;
25 25
 
26 26
 class CachePermissionsMask extends CacheWrapper {
27
-	/**
28
-	 * @var int
29
-	 */
30
-	protected $mask;
27
+    /**
28
+     * @var int
29
+     */
30
+    protected $mask;
31 31
 
32
-	/**
33
-	 * @param \OCP\Files\Cache\ICache $cache
34
-	 * @param int $mask
35
-	 */
36
-	public function __construct($cache, $mask) {
37
-		parent::__construct($cache);
38
-		$this->mask = $mask;
39
-	}
32
+    /**
33
+     * @param \OCP\Files\Cache\ICache $cache
34
+     * @param int $mask
35
+     */
36
+    public function __construct($cache, $mask) {
37
+        parent::__construct($cache);
38
+        $this->mask = $mask;
39
+    }
40 40
 
41
-	protected function formatCacheEntry($entry) {
42
-		if (isset($entry['permissions'])) {
43
-			$entry['scan_permissions'] = $entry['permissions'];
44
-			$entry['permissions'] &= $this->mask;
45
-		}
46
-		return $entry;
47
-	}
41
+    protected function formatCacheEntry($entry) {
42
+        if (isset($entry['permissions'])) {
43
+            $entry['scan_permissions'] = $entry['permissions'];
44
+            $entry['permissions'] &= $this->mask;
45
+        }
46
+        return $entry;
47
+    }
48 48
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/ClientMapper.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -28,62 +28,62 @@
 block discarded – undo
28 28
 
29 29
 class ClientMapper extends Mapper {
30 30
 
31
-	/**
32
-	 * @param IDBConnection $db
33
-	 */
34
-	public function __construct(IDBConnection $db) {
35
-		parent::__construct($db, 'oauth2_clients');
36
-	}
31
+    /**
32
+     * @param IDBConnection $db
33
+     */
34
+    public function __construct(IDBConnection $db) {
35
+        parent::__construct($db, 'oauth2_clients');
36
+    }
37 37
 
38
-	/**
39
-	 * @param string $clientIdentifier
40
-	 * @return Client
41
-	 * @throws ClientNotFoundException
42
-	 */
43
-	public function getByIdentifier($clientIdentifier) {
44
-		$qb = $this->db->getQueryBuilder();
45
-		$qb
46
-			->select('*')
47
-			->from($this->tableName)
48
-			->where($qb->expr()->eq('client_identifier', $qb->createNamedParameter($clientIdentifier)));
49
-		$result = $qb->execute();
50
-		$row = $result->fetch();
51
-		$result->closeCursor();
52
-		if($row === false) {
53
-			throw new ClientNotFoundException();
54
-		}
55
-		return Client::fromRow($row);
56
-	}
38
+    /**
39
+     * @param string $clientIdentifier
40
+     * @return Client
41
+     * @throws ClientNotFoundException
42
+     */
43
+    public function getByIdentifier($clientIdentifier) {
44
+        $qb = $this->db->getQueryBuilder();
45
+        $qb
46
+            ->select('*')
47
+            ->from($this->tableName)
48
+            ->where($qb->expr()->eq('client_identifier', $qb->createNamedParameter($clientIdentifier)));
49
+        $result = $qb->execute();
50
+        $row = $result->fetch();
51
+        $result->closeCursor();
52
+        if($row === false) {
53
+            throw new ClientNotFoundException();
54
+        }
55
+        return Client::fromRow($row);
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $uid internal uid of the client
60
-	 * @return Client
61
-	 * @throws ClientNotFoundException
62
-	 */
63
-	public function getByUid($uid) {
64
-		$qb = $this->db->getQueryBuilder();
65
-		$qb
66
-			->select('*')
67
-			->from($this->tableName)
68
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($uid, IQueryBuilder::PARAM_INT)));
69
-		$result = $qb->execute();
70
-		$row = $result->fetch();
71
-		$result->closeCursor();
72
-		if($row === false) {
73
-			throw new ClientNotFoundException();
74
-		}
75
-		return Client::fromRow($row);
76
-	}
58
+    /**
59
+     * @param string $uid internal uid of the client
60
+     * @return Client
61
+     * @throws ClientNotFoundException
62
+     */
63
+    public function getByUid($uid) {
64
+        $qb = $this->db->getQueryBuilder();
65
+        $qb
66
+            ->select('*')
67
+            ->from($this->tableName)
68
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($uid, IQueryBuilder::PARAM_INT)));
69
+        $result = $qb->execute();
70
+        $row = $result->fetch();
71
+        $result->closeCursor();
72
+        if($row === false) {
73
+            throw new ClientNotFoundException();
74
+        }
75
+        return Client::fromRow($row);
76
+    }
77 77
 
78
-	/**
79
-	 * @return Client[]
80
-	 */
81
-	public function getClients() {
82
-		$qb = $this->db->getQueryBuilder();
83
-		$qb
84
-			->select('*')
85
-			->from($this->tableName);
78
+    /**
79
+     * @return Client[]
80
+     */
81
+    public function getClients() {
82
+        $qb = $this->db->getQueryBuilder();
83
+        $qb
84
+            ->select('*')
85
+            ->from($this->tableName);
86 86
 
87
-		return $this->findEntities($qb->getSQL());
88
-	}
87
+        return $this->findEntities($qb->getSQL());
88
+    }
89 89
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		$result = $qb->execute();
50 50
 		$row = $result->fetch();
51 51
 		$result->closeCursor();
52
-		if($row === false) {
52
+		if ($row === false) {
53 53
 			throw new ClientNotFoundException();
54 54
 		}
55 55
 		return Client::fromRow($row);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		$result = $qb->execute();
70 70
 		$row = $result->fetch();
71 71
 		$result->closeCursor();
72
-		if($row === false) {
72
+		if ($row === false) {
73 73
 			throw new ClientNotFoundException();
74 74
 		}
75 75
 		return Client::fromRow($row);
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/AccessTokenMapper.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -28,43 +28,43 @@
 block discarded – undo
28 28
 
29 29
 class AccessTokenMapper extends Mapper {
30 30
 
31
-	/**
32
-	 * @param IDBConnection $db
33
-	 */
34
-	public function __construct(IDBConnection $db) {
35
-		parent::__construct($db, 'oauth2_access_tokens');
36
-	}
31
+    /**
32
+     * @param IDBConnection $db
33
+     */
34
+    public function __construct(IDBConnection $db) {
35
+        parent::__construct($db, 'oauth2_access_tokens');
36
+    }
37 37
 
38
-	/**
39
-	 * @param string $code
40
-	 * @return AccessToken
41
-	 * @throws AccessTokenNotFoundException
42
-	 */
43
-	public function getByCode($code) {
44
-		$qb = $this->db->getQueryBuilder();
45
-		$qb
46
-			->select('*')
47
-			->from($this->tableName)
48
-			->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code))));
49
-		$result = $qb->execute();
50
-		$row = $result->fetch();
51
-		$result->closeCursor();
52
-		if($row === false) {
53
-			throw new AccessTokenNotFoundException();
54
-		}
55
-		return AccessToken::fromRow($row);
56
-	}
38
+    /**
39
+     * @param string $code
40
+     * @return AccessToken
41
+     * @throws AccessTokenNotFoundException
42
+     */
43
+    public function getByCode($code) {
44
+        $qb = $this->db->getQueryBuilder();
45
+        $qb
46
+            ->select('*')
47
+            ->from($this->tableName)
48
+            ->where($qb->expr()->eq('hashed_code', $qb->createNamedParameter(hash('sha512', $code))));
49
+        $result = $qb->execute();
50
+        $row = $result->fetch();
51
+        $result->closeCursor();
52
+        if($row === false) {
53
+            throw new AccessTokenNotFoundException();
54
+        }
55
+        return AccessToken::fromRow($row);
56
+    }
57 57
 
58
-	/**
59
-	 * delete all access token from a given client
60
-	 *
61
-	 * @param int $id
62
-	 */
63
-	public function deleteByClientId($id) {
64
-		$qb = $this->db->getQueryBuilder();
65
-		$qb
66
-			->delete($this->tableName)
67
-			->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
68
-		$qb->execute();
69
-	}
58
+    /**
59
+     * delete all access token from a given client
60
+     *
61
+     * @param int $id
62
+     */
63
+    public function deleteByClientId($id) {
64
+        $qb = $this->db->getQueryBuilder();
65
+        $qb
66
+            ->delete($this->tableName)
67
+            ->where($qb->expr()->eq('client_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
68
+        $qb->execute();
69
+    }
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 		$result = $qb->execute();
50 50
 		$row = $result->fetch();
51 51
 		$result->closeCursor();
52
-		if($row === false) {
52
+		if ($row === false) {
53 53
 			throw new AccessTokenNotFoundException();
54 54
 		}
55 55
 		return AccessToken::fromRow($row);
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Auth.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function requiresCSRFCheck() {
172 172
 		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
173
+		if ($this->request->getMethod() === 'GET') {
174 174
 			return false;
175 175
 		}
176 176
 
177 177
 		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
178
+		if ($this->request->isUserAgent([
179 179
 			IRequest::USER_AGENT_CLIENT_DESKTOP,
180 180
 			IRequest::USER_AGENT_CLIENT_ANDROID,
181 181
 			IRequest::USER_AGENT_CLIENT_IOS,
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 
186 186
 		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
187
+		if (!$this->userSession->isLoggedIn()) {
188 188
 			return false;
189 189
 		}
190 190
 
191 191
 		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
192
+		if ($this->request->getMethod() === 'POST') {
193 193
 			return true;
194 194
 		}
195 195
 
196 196
 		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
197
+		if ($this->userSession->isLoggedIn() &&
198 198
 			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199 199
 			return false;
200 200
 		}
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
 	private function auth(RequestInterface $request, ResponseInterface $response) {
212 212
 		$forcedLogout = false;
213 213
 
214
-		if(!$this->request->passesCSRFCheck() &&
214
+		if (!$this->request->passesCSRFCheck() &&
215 215
 			$this->requiresCSRFCheck()) {
216 216
 			// In case of a fail with POST we need to recheck the credentials
217
-			if($this->request->getMethod() === 'POST') {
217
+			if ($this->request->getMethod() === 'POST') {
218 218
 				$forcedLogout = true;
219 219
 			} else {
220 220
 				$response->setStatus(401);
@@ -222,10 +222,10 @@  discard block
 block discarded – undo
222 222
 			}
223 223
 		}
224 224
 
225
-		if($forcedLogout) {
225
+		if ($forcedLogout) {
226 226
 			$this->userSession->logout();
227 227
 		} else {
228
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
228
+			if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229 229
 				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230 230
 			}
231 231
 			if (\OC_User::handleApacheAuth() ||
@@ -238,19 +238,19 @@  discard block
 block discarded – undo
238 238
 				\OC_Util::setupFS($user);
239 239
 				$this->currentUser = $user;
240 240
 				$this->session->close();
241
-				return [true, $this->principalPrefix . $user];
241
+				return [true, $this->principalPrefix.$user];
242 242
 			}
243 243
 		}
244 244
 
245 245
 		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246 246
 			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
247
+			$response->addHeader('WWW-Authenticate', 'DummyBasic realm="'.$this->realm.'"');
248 248
 			$response->setStatus(401);
249 249
 			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250 250
 		}
251 251
 
252 252
 		$data = parent::check($request, $response);
253
-		if($data[0] === true) {
253
+		if ($data[0] === true) {
254 254
 			$startPos = strrpos($data[1], '/') + 1;
255 255
 			$user = $this->userSession->getUser()->getUID();
256 256
 			$data[1] = substr_replace($data[1], $user, $startPos);
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -49,212 +49,212 @@
 block discarded – undo
49 49
 class Auth extends AbstractBasic {
50 50
 
51 51
 
52
-	const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
52
+    const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
53 53
 
54
-	/** @var ISession */
55
-	private $session;
56
-	/** @var Session */
57
-	private $userSession;
58
-	/** @var IRequest */
59
-	private $request;
60
-	/** @var string */
61
-	private $currentUser;
62
-	/** @var Manager */
63
-	private $twoFactorManager;
64
-	/** @var Throttler */
65
-	private $throttler;
54
+    /** @var ISession */
55
+    private $session;
56
+    /** @var Session */
57
+    private $userSession;
58
+    /** @var IRequest */
59
+    private $request;
60
+    /** @var string */
61
+    private $currentUser;
62
+    /** @var Manager */
63
+    private $twoFactorManager;
64
+    /** @var Throttler */
65
+    private $throttler;
66 66
 
67
-	/**
68
-	 * @param ISession $session
69
-	 * @param Session $userSession
70
-	 * @param IRequest $request
71
-	 * @param Manager $twoFactorManager
72
-	 * @param Throttler $throttler
73
-	 * @param string $principalPrefix
74
-	 */
75
-	public function __construct(ISession $session,
76
-								Session $userSession,
77
-								IRequest $request,
78
-								Manager $twoFactorManager,
79
-								Throttler $throttler,
80
-								$principalPrefix = 'principals/users/') {
81
-		$this->session = $session;
82
-		$this->userSession = $userSession;
83
-		$this->twoFactorManager = $twoFactorManager;
84
-		$this->request = $request;
85
-		$this->throttler = $throttler;
86
-		$this->principalPrefix = $principalPrefix;
67
+    /**
68
+     * @param ISession $session
69
+     * @param Session $userSession
70
+     * @param IRequest $request
71
+     * @param Manager $twoFactorManager
72
+     * @param Throttler $throttler
73
+     * @param string $principalPrefix
74
+     */
75
+    public function __construct(ISession $session,
76
+                                Session $userSession,
77
+                                IRequest $request,
78
+                                Manager $twoFactorManager,
79
+                                Throttler $throttler,
80
+                                $principalPrefix = 'principals/users/') {
81
+        $this->session = $session;
82
+        $this->userSession = $userSession;
83
+        $this->twoFactorManager = $twoFactorManager;
84
+        $this->request = $request;
85
+        $this->throttler = $throttler;
86
+        $this->principalPrefix = $principalPrefix;
87 87
 
88
-		// setup realm
89
-		$defaults = new \OCP\Defaults();
90
-		$this->realm = $defaults->getName();
91
-	}
88
+        // setup realm
89
+        $defaults = new \OCP\Defaults();
90
+        $this->realm = $defaults->getName();
91
+    }
92 92
 
93
-	/**
94
-	 * Whether the user has initially authenticated via DAV
95
-	 *
96
-	 * This is required for WebDAV clients that resent the cookies even when the
97
-	 * account was changed.
98
-	 *
99
-	 * @see https://github.com/owncloud/core/issues/13245
100
-	 *
101
-	 * @param string $username
102
-	 * @return bool
103
-	 */
104
-	public function isDavAuthenticated($username) {
105
-		return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
106
-		$this->session->get(self::DAV_AUTHENTICATED) === $username;
107
-	}
93
+    /**
94
+     * Whether the user has initially authenticated via DAV
95
+     *
96
+     * This is required for WebDAV clients that resent the cookies even when the
97
+     * account was changed.
98
+     *
99
+     * @see https://github.com/owncloud/core/issues/13245
100
+     *
101
+     * @param string $username
102
+     * @return bool
103
+     */
104
+    public function isDavAuthenticated($username) {
105
+        return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
106
+        $this->session->get(self::DAV_AUTHENTICATED) === $username;
107
+    }
108 108
 
109
-	/**
110
-	 * Validates a username and password
111
-	 *
112
-	 * This method should return true or false depending on if login
113
-	 * succeeded.
114
-	 *
115
-	 * @param string $username
116
-	 * @param string $password
117
-	 * @return bool
118
-	 * @throws PasswordLoginForbidden
119
-	 */
120
-	protected function validateUserPass($username, $password) {
121
-		if ($this->userSession->isLoggedIn() &&
122
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())
123
-		) {
124
-			\OC_Util::setupFS($this->userSession->getUser()->getUID());
125
-			$this->session->close();
126
-			return true;
127
-		} else {
128
-			\OC_Util::setupFS(); //login hooks may need early access to the filesystem
129
-			try {
130
-				if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
131
-					\OC_Util::setupFS($this->userSession->getUser()->getUID());
132
-					$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
133
-					$this->session->close();
134
-					return true;
135
-				} else {
136
-					$this->session->close();
137
-					return false;
138
-				}
139
-			} catch (PasswordLoginForbiddenException $ex) {
140
-				$this->session->close();
141
-				throw new PasswordLoginForbidden();
142
-			}
143
-		}
144
-	}
109
+    /**
110
+     * Validates a username and password
111
+     *
112
+     * This method should return true or false depending on if login
113
+     * succeeded.
114
+     *
115
+     * @param string $username
116
+     * @param string $password
117
+     * @return bool
118
+     * @throws PasswordLoginForbidden
119
+     */
120
+    protected function validateUserPass($username, $password) {
121
+        if ($this->userSession->isLoggedIn() &&
122
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())
123
+        ) {
124
+            \OC_Util::setupFS($this->userSession->getUser()->getUID());
125
+            $this->session->close();
126
+            return true;
127
+        } else {
128
+            \OC_Util::setupFS(); //login hooks may need early access to the filesystem
129
+            try {
130
+                if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
131
+                    \OC_Util::setupFS($this->userSession->getUser()->getUID());
132
+                    $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
133
+                    $this->session->close();
134
+                    return true;
135
+                } else {
136
+                    $this->session->close();
137
+                    return false;
138
+                }
139
+            } catch (PasswordLoginForbiddenException $ex) {
140
+                $this->session->close();
141
+                throw new PasswordLoginForbidden();
142
+            }
143
+        }
144
+    }
145 145
 
146
-	/**
147
-	 * @param RequestInterface $request
148
-	 * @param ResponseInterface $response
149
-	 * @return array
150
-	 * @throws NotAuthenticated
151
-	 * @throws ServiceUnavailable
152
-	 */
153
-	function check(RequestInterface $request, ResponseInterface $response) {
154
-		try {
155
-			return $this->auth($request, $response);
156
-		} catch (NotAuthenticated $e) {
157
-			throw $e;
158
-		} catch (Exception $e) {
159
-			$class = get_class($e);
160
-			$msg = $e->getMessage();
161
-			\OC::$server->getLogger()->logException($e);
162
-			throw new ServiceUnavailable("$class: $msg");
163
-		}
164
-	}
146
+    /**
147
+     * @param RequestInterface $request
148
+     * @param ResponseInterface $response
149
+     * @return array
150
+     * @throws NotAuthenticated
151
+     * @throws ServiceUnavailable
152
+     */
153
+    function check(RequestInterface $request, ResponseInterface $response) {
154
+        try {
155
+            return $this->auth($request, $response);
156
+        } catch (NotAuthenticated $e) {
157
+            throw $e;
158
+        } catch (Exception $e) {
159
+            $class = get_class($e);
160
+            $msg = $e->getMessage();
161
+            \OC::$server->getLogger()->logException($e);
162
+            throw new ServiceUnavailable("$class: $msg");
163
+        }
164
+    }
165 165
 
166
-	/**
167
-	 * Checks whether a CSRF check is required on the request
168
-	 *
169
-	 * @return bool
170
-	 */
171
-	private function requiresCSRFCheck() {
172
-		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
174
-			return false;
175
-		}
166
+    /**
167
+     * Checks whether a CSRF check is required on the request
168
+     *
169
+     * @return bool
170
+     */
171
+    private function requiresCSRFCheck() {
172
+        // GET requires no check at all
173
+        if($this->request->getMethod() === 'GET') {
174
+            return false;
175
+        }
176 176
 
177
-		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
179
-			IRequest::USER_AGENT_CLIENT_DESKTOP,
180
-			IRequest::USER_AGENT_CLIENT_ANDROID,
181
-			IRequest::USER_AGENT_CLIENT_IOS,
182
-		])) {
183
-			return false;
184
-		}
177
+        // Official Nextcloud clients require no checks
178
+        if($this->request->isUserAgent([
179
+            IRequest::USER_AGENT_CLIENT_DESKTOP,
180
+            IRequest::USER_AGENT_CLIENT_ANDROID,
181
+            IRequest::USER_AGENT_CLIENT_IOS,
182
+        ])) {
183
+            return false;
184
+        }
185 185
 
186
-		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
188
-			return false;
189
-		}
186
+        // If not logged-in no check is required
187
+        if(!$this->userSession->isLoggedIn()) {
188
+            return false;
189
+        }
190 190
 
191
-		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
193
-			return true;
194
-		}
191
+        // POST always requires a check
192
+        if($this->request->getMethod() === 'POST') {
193
+            return true;
194
+        }
195 195
 
196
-		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
198
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
-			return false;
200
-		}
196
+        // If logged-in AND DAV authenticated no check is required
197
+        if($this->userSession->isLoggedIn() &&
198
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
+            return false;
200
+        }
201 201
 
202
-		return true;
203
-	}
202
+        return true;
203
+    }
204 204
 
205
-	/**
206
-	 * @param RequestInterface $request
207
-	 * @param ResponseInterface $response
208
-	 * @return array
209
-	 * @throws NotAuthenticated
210
-	 */
211
-	private function auth(RequestInterface $request, ResponseInterface $response) {
212
-		$forcedLogout = false;
205
+    /**
206
+     * @param RequestInterface $request
207
+     * @param ResponseInterface $response
208
+     * @return array
209
+     * @throws NotAuthenticated
210
+     */
211
+    private function auth(RequestInterface $request, ResponseInterface $response) {
212
+        $forcedLogout = false;
213 213
 
214
-		if(!$this->request->passesCSRFCheck() &&
215
-			$this->requiresCSRFCheck()) {
216
-			// In case of a fail with POST we need to recheck the credentials
217
-			if($this->request->getMethod() === 'POST') {
218
-				$forcedLogout = true;
219
-			} else {
220
-				$response->setStatus(401);
221
-				throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
222
-			}
223
-		}
214
+        if(!$this->request->passesCSRFCheck() &&
215
+            $this->requiresCSRFCheck()) {
216
+            // In case of a fail with POST we need to recheck the credentials
217
+            if($this->request->getMethod() === 'POST') {
218
+                $forcedLogout = true;
219
+            } else {
220
+                $response->setStatus(401);
221
+                throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
222
+            }
223
+        }
224 224
 
225
-		if($forcedLogout) {
226
-			$this->userSession->logout();
227
-		} else {
228
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229
-				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230
-			}
231
-			if (\OC_User::handleApacheAuth() ||
232
-				//Fix for broken webdav clients
233
-				($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
234
-				//Well behaved clients that only send the cookie are allowed
235
-				($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
236
-			) {
237
-				$user = $this->userSession->getUser()->getUID();
238
-				\OC_Util::setupFS($user);
239
-				$this->currentUser = $user;
240
-				$this->session->close();
241
-				return [true, $this->principalPrefix . $user];
242
-			}
243
-		}
225
+        if($forcedLogout) {
226
+            $this->userSession->logout();
227
+        } else {
228
+            if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229
+                throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230
+            }
231
+            if (\OC_User::handleApacheAuth() ||
232
+                //Fix for broken webdav clients
233
+                ($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
234
+                //Well behaved clients that only send the cookie are allowed
235
+                ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
236
+            ) {
237
+                $user = $this->userSession->getUser()->getUID();
238
+                \OC_Util::setupFS($user);
239
+                $this->currentUser = $user;
240
+                $this->session->close();
241
+                return [true, $this->principalPrefix . $user];
242
+            }
243
+        }
244 244
 
245
-		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246
-			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
248
-			$response->setStatus(401);
249
-			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250
-		}
245
+        if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246
+            // do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
+            $response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
248
+            $response->setStatus(401);
249
+            throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250
+        }
251 251
 
252
-		$data = parent::check($request, $response);
253
-		if($data[0] === true) {
254
-			$startPos = strrpos($data[1], '/') + 1;
255
-			$user = $this->userSession->getUser()->getUID();
256
-			$data[1] = substr_replace($data[1], $user, $startPos);
257
-		}
258
-		return $data;
259
-	}
252
+        $data = parent::check($request, $response);
253
+        if($data[0] === true) {
254
+            $startPos = strrpos($data[1], '/') + 1;
255
+            $user = $this->userSession->getUser()->getUID();
256
+            $data[1] = substr_replace($data[1], $user, $startPos);
257
+        }
258
+        return $data;
259
+    }
260 260
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/BearerAuth.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	private function setupUserFs($userId) {
56 56
 		\OC_Util::setupFS($userId);
57 57
 		$this->session->close();
58
-		return $this->principalPrefix . $userId;
58
+		return $this->principalPrefix.$userId;
59 59
 	}
60 60
 
61 61
 	/**
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	public function validateBearerToken($bearerToken) {
65 65
 		\OC_Util::setupFS();
66 66
 
67
-		if(!$this->userSession->isLoggedIn()) {
67
+		if (!$this->userSession->isLoggedIn()) {
68 68
 			$this->userSession->tryTokenLogin($this->request);
69 69
 		}
70
-		if($this->userSession->isLoggedIn()) {
70
+		if ($this->userSession->isLoggedIn()) {
71 71
 			return $this->setupUserFs($this->userSession->getUser()->getUID());
72 72
 		}
73 73
 
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,66 +29,66 @@
 block discarded – undo
29 29
 use Sabre\HTTP\ResponseInterface;
30 30
 
31 31
 class BearerAuth extends AbstractBearer {
32
-	/** @var IUserSession */
33
-	private $userSession;
34
-	/** @var ISession */
35
-	private $session;
36
-	/** @var IRequest */
37
-	private $request;
38
-	/** @var string */
39
-	private $principalPrefix;
32
+    /** @var IUserSession */
33
+    private $userSession;
34
+    /** @var ISession */
35
+    private $session;
36
+    /** @var IRequest */
37
+    private $request;
38
+    /** @var string */
39
+    private $principalPrefix;
40 40
 
41
-	/**
42
-	 * @param IUserSession $userSession
43
-	 * @param ISession $session
44
-	 * @param string $principalPrefix
45
-	 * @param IRequest $request
46
-	 */
47
-	public function __construct(IUserSession $userSession,
48
-								ISession $session,
49
-								IRequest $request,
50
-								$principalPrefix = 'principals/users/') {
51
-		$this->userSession = $userSession;
52
-		$this->session = $session;
53
-		$this->request = $request;
54
-		$this->principalPrefix = $principalPrefix;
41
+    /**
42
+     * @param IUserSession $userSession
43
+     * @param ISession $session
44
+     * @param string $principalPrefix
45
+     * @param IRequest $request
46
+     */
47
+    public function __construct(IUserSession $userSession,
48
+                                ISession $session,
49
+                                IRequest $request,
50
+                                $principalPrefix = 'principals/users/') {
51
+        $this->userSession = $userSession;
52
+        $this->session = $session;
53
+        $this->request = $request;
54
+        $this->principalPrefix = $principalPrefix;
55 55
 
56
-		// setup realm
57
-		$defaults = new \OCP\Defaults();
58
-		$this->realm = $defaults->getName();
59
-	}
56
+        // setup realm
57
+        $defaults = new \OCP\Defaults();
58
+        $this->realm = $defaults->getName();
59
+    }
60 60
 
61
-	private function setupUserFs($userId) {
62
-		\OC_Util::setupFS($userId);
63
-		$this->session->close();
64
-		return $this->principalPrefix . $userId;
65
-	}
61
+    private function setupUserFs($userId) {
62
+        \OC_Util::setupFS($userId);
63
+        $this->session->close();
64
+        return $this->principalPrefix . $userId;
65
+    }
66 66
 
67
-	/**
68
-	 * {@inheritdoc}
69
-	 */
70
-	public function validateBearerToken($bearerToken) {
71
-		\OC_Util::setupFS();
67
+    /**
68
+     * {@inheritdoc}
69
+     */
70
+    public function validateBearerToken($bearerToken) {
71
+        \OC_Util::setupFS();
72 72
 
73
-		if(!$this->userSession->isLoggedIn()) {
74
-			$this->userSession->tryTokenLogin($this->request);
75
-		}
76
-		if($this->userSession->isLoggedIn()) {
77
-			return $this->setupUserFs($this->userSession->getUser()->getUID());
78
-		}
73
+        if(!$this->userSession->isLoggedIn()) {
74
+            $this->userSession->tryTokenLogin($this->request);
75
+        }
76
+        if($this->userSession->isLoggedIn()) {
77
+            return $this->setupUserFs($this->userSession->getUser()->getUID());
78
+        }
79 79
 
80
-		return false;
81
-	}
80
+        return false;
81
+    }
82 82
 
83
-	/**
84
-	 * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
-	 * header which some DAV clients can't handle. Thus we override this function
86
-	 * and make it simply return a 401.
87
-	 *
88
-	 * @param RequestInterface $request
89
-	 * @param ResponseInterface $response
90
-	 */
91
-	public function challenge(RequestInterface $request, ResponseInterface $response) {
92
-		$response->setStatus(401);
93
-	}
83
+    /**
84
+     * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
+     * header which some DAV clients can't handle. Thus we override this function
86
+     * and make it simply return a 401.
87
+     *
88
+     * @param RequestInterface $request
89
+     * @param ResponseInterface $response
90
+     */
91
+    public function challenge(RequestInterface $request, ResponseInterface $response) {
92
+        $response->setStatus(401);
93
+    }
94 94
 }
Please login to merge, or discard this patch.