Passed
Push — master ( f0dd71...c56a27 )
by Christoph
11:49 queued 12s
created
lib/private/Collaboration/Resources/Collection.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -38,195 +38,195 @@
 block discarded – undo
38 38
 
39 39
 class Collection implements ICollection {
40 40
 
41
-	/** @var IManager|Manager */
42
-	protected $manager;
43
-
44
-	/** @var IDBConnection */
45
-	protected $connection;
46
-
47
-	/** @var int */
48
-	protected $id;
49
-
50
-	/** @var string */
51
-	protected $name;
52
-
53
-	/** @var IUser|null */
54
-	protected $userForAccess;
55
-
56
-	/** @var bool|null */
57
-	protected $access;
58
-
59
-	/** @var IResource[] */
60
-	protected $resources;
61
-
62
-	public function __construct(
63
-		IManager $manager,
64
-		IDBConnection $connection,
65
-		int $id,
66
-		string $name,
67
-		?IUser $userForAccess = null,
68
-		?bool $access = null
69
-	) {
70
-		$this->manager = $manager;
71
-		$this->connection = $connection;
72
-		$this->id = $id;
73
-		$this->name = $name;
74
-		$this->userForAccess = $userForAccess;
75
-		$this->access = $access;
76
-		$this->resources = [];
77
-	}
78
-
79
-	/**
80
-	 * @return int
81
-	 * @since 16.0.0
82
-	 */
83
-	public function getId(): int {
84
-		return $this->id;
85
-	}
86
-
87
-	/**
88
-	 * @return string
89
-	 * @since 16.0.0
90
-	 */
91
-	public function getName(): string {
92
-		return $this->name;
93
-	}
94
-
95
-	/**
96
-	 * @param string $name
97
-	 * @since 16.0.0
98
-	 */
99
-	public function setName(string $name): void {
100
-		$query = $this->connection->getQueryBuilder();
101
-		$query->update(Manager::TABLE_COLLECTIONS)
102
-			->set('name', $query->createNamedParameter($name))
103
-			->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
104
-		$query->execute();
105
-
106
-		$this->name = $name;
107
-	}
108
-
109
-	/**
110
-	 * @return IResource[]
111
-	 * @since 16.0.0
112
-	 */
113
-	public function getResources(): array {
114
-		if (empty($this->resources)) {
115
-			$this->resources = $this->manager->getResourcesByCollectionForUser($this, $this->userForAccess);
116
-		}
117
-
118
-		return $this->resources;
119
-	}
120
-
121
-	/**
122
-	 * Adds a resource to a collection
123
-	 *
124
-	 * @param IResource $resource
125
-	 * @throws ResourceException when the resource is already part of the collection
126
-	 * @since 16.0.0
127
-	 */
128
-	public function addResource(IResource $resource): void {
129
-		array_map(function (IResource $r) use ($resource) {
130
-			if ($this->isSameResource($r, $resource)) {
131
-				throw new ResourceException('Already part of the collection');
132
-			}
133
-		}, $this->getResources());
134
-
135
-		$this->resources[] = $resource;
136
-
137
-		$query = $this->connection->getQueryBuilder();
138
-		$query->insert(Manager::TABLE_RESOURCES)
139
-			->values([
140
-				'collection_id' => $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT),
141
-				'resource_type' => $query->createNamedParameter($resource->getType()),
142
-				'resource_id' => $query->createNamedParameter($resource->getId()),
143
-			]);
144
-
145
-		try {
146
-			$query->execute();
147
-		} catch (ConstraintViolationException $e) {
148
-			throw new ResourceException('Already part of the collection');
149
-		}
150
-
151
-		$this->manager->invalidateAccessCacheForCollection($this);
152
-	}
153
-
154
-	/**
155
-	 * Removes a resource from a collection
156
-	 *
157
-	 * @param IResource $resource
158
-	 * @since 16.0.0
159
-	 */
160
-	public function removeResource(IResource $resource): void {
161
-		$this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
162
-			return !$this->isSameResource($r, $resource);
163
-		});
164
-
165
-		$query = $this->connection->getQueryBuilder();
166
-		$query->delete(Manager::TABLE_RESOURCES)
167
-			->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
168
-			->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
169
-			->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
170
-		$query->execute();
171
-
172
-		if (empty($this->resources)) {
173
-			$this->removeCollection();
174
-		} else {
175
-			$this->manager->invalidateAccessCacheForCollection($this);
176
-		}
177
-
178
-	}
179
-
180
-	/**
181
-	 * Can a user/guest access the collection
182
-	 *
183
-	 * @param IUser|null $user
184
-	 * @return bool
185
-	 * @since 16.0.0
186
-	 */
187
-	public function canAccess(?IUser $user): bool {
188
-		if ($user instanceof IUser) {
189
-			return $this->canUserAccess($user);
190
-		}
191
-		return $this->canGuestAccess();
192
-	}
193
-
194
-	protected function canUserAccess(IUser $user): bool {
195
-		if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
196
-			return $this->access;
197
-		}
198
-
199
-		$access = $this->manager->canAccessCollection($this, $user);
200
-		if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
201
-			$this->access = $access;
202
-		}
203
-		return $access;
204
-	}
205
-
206
-	protected function canGuestAccess(): bool {
207
-		if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
208
-			return $this->access;
209
-		}
210
-
211
-		$access = $this->manager->canAccessCollection($this, null);
212
-		if (!$this->userForAccess instanceof IUser) {
213
-			$this->access = $access;
214
-		}
215
-		return $access;
216
-	}
217
-
218
-	protected function isSameResource(IResource $resource1, IResource $resource2): bool {
219
-		return $resource1->getType() === $resource2->getType() &&
220
-			$resource1->getId() === $resource2->getId();
221
-	}
222
-
223
-	protected function removeCollection(): void {
224
-		$query = $this->connection->getQueryBuilder();
225
-		$query->delete(Manager::TABLE_COLLECTIONS)
226
-			->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
227
-		$query->execute();
228
-
229
-		$this->manager->invalidateAccessCacheForCollection($this);
230
-		$this->id = 0;
231
-	}
41
+    /** @var IManager|Manager */
42
+    protected $manager;
43
+
44
+    /** @var IDBConnection */
45
+    protected $connection;
46
+
47
+    /** @var int */
48
+    protected $id;
49
+
50
+    /** @var string */
51
+    protected $name;
52
+
53
+    /** @var IUser|null */
54
+    protected $userForAccess;
55
+
56
+    /** @var bool|null */
57
+    protected $access;
58
+
59
+    /** @var IResource[] */
60
+    protected $resources;
61
+
62
+    public function __construct(
63
+        IManager $manager,
64
+        IDBConnection $connection,
65
+        int $id,
66
+        string $name,
67
+        ?IUser $userForAccess = null,
68
+        ?bool $access = null
69
+    ) {
70
+        $this->manager = $manager;
71
+        $this->connection = $connection;
72
+        $this->id = $id;
73
+        $this->name = $name;
74
+        $this->userForAccess = $userForAccess;
75
+        $this->access = $access;
76
+        $this->resources = [];
77
+    }
78
+
79
+    /**
80
+     * @return int
81
+     * @since 16.0.0
82
+     */
83
+    public function getId(): int {
84
+        return $this->id;
85
+    }
86
+
87
+    /**
88
+     * @return string
89
+     * @since 16.0.0
90
+     */
91
+    public function getName(): string {
92
+        return $this->name;
93
+    }
94
+
95
+    /**
96
+     * @param string $name
97
+     * @since 16.0.0
98
+     */
99
+    public function setName(string $name): void {
100
+        $query = $this->connection->getQueryBuilder();
101
+        $query->update(Manager::TABLE_COLLECTIONS)
102
+            ->set('name', $query->createNamedParameter($name))
103
+            ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
104
+        $query->execute();
105
+
106
+        $this->name = $name;
107
+    }
108
+
109
+    /**
110
+     * @return IResource[]
111
+     * @since 16.0.0
112
+     */
113
+    public function getResources(): array {
114
+        if (empty($this->resources)) {
115
+            $this->resources = $this->manager->getResourcesByCollectionForUser($this, $this->userForAccess);
116
+        }
117
+
118
+        return $this->resources;
119
+    }
120
+
121
+    /**
122
+     * Adds a resource to a collection
123
+     *
124
+     * @param IResource $resource
125
+     * @throws ResourceException when the resource is already part of the collection
126
+     * @since 16.0.0
127
+     */
128
+    public function addResource(IResource $resource): void {
129
+        array_map(function (IResource $r) use ($resource) {
130
+            if ($this->isSameResource($r, $resource)) {
131
+                throw new ResourceException('Already part of the collection');
132
+            }
133
+        }, $this->getResources());
134
+
135
+        $this->resources[] = $resource;
136
+
137
+        $query = $this->connection->getQueryBuilder();
138
+        $query->insert(Manager::TABLE_RESOURCES)
139
+            ->values([
140
+                'collection_id' => $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT),
141
+                'resource_type' => $query->createNamedParameter($resource->getType()),
142
+                'resource_id' => $query->createNamedParameter($resource->getId()),
143
+            ]);
144
+
145
+        try {
146
+            $query->execute();
147
+        } catch (ConstraintViolationException $e) {
148
+            throw new ResourceException('Already part of the collection');
149
+        }
150
+
151
+        $this->manager->invalidateAccessCacheForCollection($this);
152
+    }
153
+
154
+    /**
155
+     * Removes a resource from a collection
156
+     *
157
+     * @param IResource $resource
158
+     * @since 16.0.0
159
+     */
160
+    public function removeResource(IResource $resource): void {
161
+        $this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
162
+            return !$this->isSameResource($r, $resource);
163
+        });
164
+
165
+        $query = $this->connection->getQueryBuilder();
166
+        $query->delete(Manager::TABLE_RESOURCES)
167
+            ->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
168
+            ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
169
+            ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
170
+        $query->execute();
171
+
172
+        if (empty($this->resources)) {
173
+            $this->removeCollection();
174
+        } else {
175
+            $this->manager->invalidateAccessCacheForCollection($this);
176
+        }
177
+
178
+    }
179
+
180
+    /**
181
+     * Can a user/guest access the collection
182
+     *
183
+     * @param IUser|null $user
184
+     * @return bool
185
+     * @since 16.0.0
186
+     */
187
+    public function canAccess(?IUser $user): bool {
188
+        if ($user instanceof IUser) {
189
+            return $this->canUserAccess($user);
190
+        }
191
+        return $this->canGuestAccess();
192
+    }
193
+
194
+    protected function canUserAccess(IUser $user): bool {
195
+        if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
196
+            return $this->access;
197
+        }
198
+
199
+        $access = $this->manager->canAccessCollection($this, $user);
200
+        if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
201
+            $this->access = $access;
202
+        }
203
+        return $access;
204
+    }
205
+
206
+    protected function canGuestAccess(): bool {
207
+        if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
208
+            return $this->access;
209
+        }
210
+
211
+        $access = $this->manager->canAccessCollection($this, null);
212
+        if (!$this->userForAccess instanceof IUser) {
213
+            $this->access = $access;
214
+        }
215
+        return $access;
216
+    }
217
+
218
+    protected function isSameResource(IResource $resource1, IResource $resource2): bool {
219
+        return $resource1->getType() === $resource2->getType() &&
220
+            $resource1->getId() === $resource2->getId();
221
+    }
222
+
223
+    protected function removeCollection(): void {
224
+        $query = $this->connection->getQueryBuilder();
225
+        $query->delete(Manager::TABLE_COLLECTIONS)
226
+            ->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
227
+        $query->execute();
228
+
229
+        $this->manager->invalidateAccessCacheForCollection($this);
230
+        $this->id = 0;
231
+    }
232 232
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @since 16.0.0
127 127
 	 */
128 128
 	public function addResource(IResource $resource): void {
129
-		array_map(function (IResource $r) use ($resource) {
129
+		array_map(function(IResource $r) use ($resource) {
130 130
 			if ($this->isSameResource($r, $resource)) {
131 131
 				throw new ResourceException('Already part of the collection');
132 132
 			}
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @since 16.0.0
159 159
 	 */
160 160
 	public function removeResource(IResource $resource): void {
161
-		$this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
161
+		$this->resources = array_filter($this->getResources(), function(IResource $r) use ($resource) {
162 162
 			return !$this->isSameResource($r, $resource);
163 163
 		});
164 164
 
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/UserPlugin.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -40,167 +40,167 @@
 block discarded – undo
40 40
 use OCP\Share\IShare;
41 41
 
42 42
 class UserPlugin implements ISearchPlugin {
43
-	/* @var bool */
44
-	protected $shareWithGroupOnly;
45
-	protected $shareeEnumeration;
46
-	protected $shareeEnumerationInGroupOnly;
47
-
48
-	/** @var IConfig */
49
-	private $config;
50
-	/** @var IGroupManager */
51
-	private $groupManager;
52
-	/** @var IUserSession */
53
-	private $userSession;
54
-	/** @var IUserManager */
55
-	private $userManager;
56
-
57
-	public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
58
-		$this->config = $config;
59
-
60
-		$this->groupManager = $groupManager;
61
-		$this->userSession = $userSession;
62
-		$this->userManager = $userManager;
63
-
64
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
65
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
66
-		$this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
67
-	}
68
-
69
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
70
-		$result = ['wide' => [], 'exact' => []];
71
-		$users = [];
72
-		$autoCompleteUsers = [];
73
-		$hasMoreResults = false;
74
-
75
-		$userGroups = [];
76
-		if ($this->shareWithGroupOnly) {
77
-			// Search in all the groups this user is part of
78
-			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
79
-			foreach ($userGroups as $userGroup) {
80
-				$usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset);
81
-				foreach ($usersInGroup as $user) {
82
-					$users[$user->getUID()] = $user;
83
-				}
84
-			}
85
-		} else {
86
-			// Search in all users
87
-			$usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
88
-			$currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
89
-			foreach ($usersTmp as $user) {
90
-				if ($user->isEnabled()) { // Don't keep deactivated users
91
-					$users[$user->getUID()] = $user;
92
-
93
-					$addToWideResults = false;
94
-					if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
95
-						$addToWideResults = true;
96
-					}
97
-
98
-					if ($this->shareeEnumerationInGroupOnly) {
99
-						$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
100
-						if (!empty($commonGroups)) {
101
-							$addToWideResults = true;
102
-						}
103
-					}
104
-
105
-					if ($addToWideResults) {
106
-						$autoCompleteUsers[] = [
107
-							'label' => $user->getDisplayName(),
108
-							'value' => [
109
-								'shareType' => IShare::TYPE_USER,
110
-								'shareWith' => (string)$user->getUID(),
111
-							],
112
-						];
113
-					}
114
-				}
115
-			}
116
-		}
117
-
118
-		$this->takeOutCurrentUser($users);
119
-
120
-		if (!$this->shareeEnumeration || count($users) < $limit) {
121
-			$hasMoreResults = true;
122
-		}
123
-
124
-		$foundUserById = false;
125
-		$lowerSearch = strtolower($search);
126
-		foreach ($users as $uid => $user) {
127
-			$userDisplayName = $user->getDisplayName();
128
-			$userEmail = $user->getEMailAddress();
129
-			$uid = (string) $uid;
130
-			if (
131
-				strtolower($uid) === $lowerSearch ||
132
-				strtolower($userDisplayName) === $lowerSearch ||
133
-				strtolower($userEmail) === $lowerSearch
134
-			) {
135
-				if (strtolower($uid) === $lowerSearch) {
136
-					$foundUserById = true;
137
-				}
138
-				$result['exact'][] = [
139
-					'label' => $userDisplayName,
140
-					'value' => [
141
-						'shareType' => Share::SHARE_TYPE_USER,
142
-						'shareWith' => $uid,
143
-					],
144
-				];
145
-			} else {
146
-				$result['wide'][] = [
147
-					'label' => $userDisplayName,
148
-					'value' => [
149
-						'shareType' => Share::SHARE_TYPE_USER,
150
-						'shareWith' => $uid,
151
-					],
152
-				];
153
-			}
154
-		}
155
-
156
-		if ($offset === 0 && !$foundUserById) {
157
-			// On page one we try if the search result has a direct hit on the
158
-			// user id and if so, we add that to the exact match list
159
-			$user = $this->userManager->get($search);
160
-			if ($user instanceof IUser) {
161
-				$addUser = true;
162
-
163
-				if ($this->shareWithGroupOnly) {
164
-					// Only add, if we have a common group
165
-					$userGroupIds = array_map(function (IGroup $group) {
166
-						return $group->getGID();
167
-					}, $userGroups);
168
-					$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
169
-					$addUser = !empty($commonGroups);
170
-				}
171
-
172
-				if ($addUser) {
173
-					$result['exact'][] = [
174
-						'label' => $user->getDisplayName(),
175
-						'value' => [
176
-							'shareType' => Share::SHARE_TYPE_USER,
177
-							'shareWith' => $user->getUID(),
178
-						],
179
-					];
180
-				}
181
-			}
182
-		}
183
-
184
-		// overwrite wide matches if they are limited
185
-		if (!$this->shareeEnumeration || $this->shareeEnumerationInGroupOnly) {
186
-			$result['wide'] = $autoCompleteUsers;
187
-		}
188
-
189
-		$type = new SearchResultType('users');
190
-		$searchResult->addResultSet($type, $result['wide'], $result['exact']);
191
-		if (count($result['exact'])) {
192
-			$searchResult->markExactIdMatch($type);
193
-		}
194
-
195
-		return $hasMoreResults;
196
-	}
197
-
198
-	public function takeOutCurrentUser(array &$users) {
199
-		$currentUser = $this->userSession->getUser();
200
-		if(!is_null($currentUser)) {
201
-			if (isset($users[$currentUser->getUID()])) {
202
-				unset($users[$currentUser->getUID()]);
203
-			}
204
-		}
205
-	}
43
+    /* @var bool */
44
+    protected $shareWithGroupOnly;
45
+    protected $shareeEnumeration;
46
+    protected $shareeEnumerationInGroupOnly;
47
+
48
+    /** @var IConfig */
49
+    private $config;
50
+    /** @var IGroupManager */
51
+    private $groupManager;
52
+    /** @var IUserSession */
53
+    private $userSession;
54
+    /** @var IUserManager */
55
+    private $userManager;
56
+
57
+    public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) {
58
+        $this->config = $config;
59
+
60
+        $this->groupManager = $groupManager;
61
+        $this->userSession = $userSession;
62
+        $this->userManager = $userManager;
63
+
64
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
65
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
66
+        $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
67
+    }
68
+
69
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
70
+        $result = ['wide' => [], 'exact' => []];
71
+        $users = [];
72
+        $autoCompleteUsers = [];
73
+        $hasMoreResults = false;
74
+
75
+        $userGroups = [];
76
+        if ($this->shareWithGroupOnly) {
77
+            // Search in all the groups this user is part of
78
+            $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
79
+            foreach ($userGroups as $userGroup) {
80
+                $usersInGroup = $userGroup->searchDisplayName($search, $limit, $offset);
81
+                foreach ($usersInGroup as $user) {
82
+                    $users[$user->getUID()] = $user;
83
+                }
84
+            }
85
+        } else {
86
+            // Search in all users
87
+            $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset);
88
+            $currentUserGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
89
+            foreach ($usersTmp as $user) {
90
+                if ($user->isEnabled()) { // Don't keep deactivated users
91
+                    $users[$user->getUID()] = $user;
92
+
93
+                    $addToWideResults = false;
94
+                    if ($this->shareeEnumeration && !$this->shareeEnumerationInGroupOnly) {
95
+                        $addToWideResults = true;
96
+                    }
97
+
98
+                    if ($this->shareeEnumerationInGroupOnly) {
99
+                        $commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
100
+                        if (!empty($commonGroups)) {
101
+                            $addToWideResults = true;
102
+                        }
103
+                    }
104
+
105
+                    if ($addToWideResults) {
106
+                        $autoCompleteUsers[] = [
107
+                            'label' => $user->getDisplayName(),
108
+                            'value' => [
109
+                                'shareType' => IShare::TYPE_USER,
110
+                                'shareWith' => (string)$user->getUID(),
111
+                            ],
112
+                        ];
113
+                    }
114
+                }
115
+            }
116
+        }
117
+
118
+        $this->takeOutCurrentUser($users);
119
+
120
+        if (!$this->shareeEnumeration || count($users) < $limit) {
121
+            $hasMoreResults = true;
122
+        }
123
+
124
+        $foundUserById = false;
125
+        $lowerSearch = strtolower($search);
126
+        foreach ($users as $uid => $user) {
127
+            $userDisplayName = $user->getDisplayName();
128
+            $userEmail = $user->getEMailAddress();
129
+            $uid = (string) $uid;
130
+            if (
131
+                strtolower($uid) === $lowerSearch ||
132
+                strtolower($userDisplayName) === $lowerSearch ||
133
+                strtolower($userEmail) === $lowerSearch
134
+            ) {
135
+                if (strtolower($uid) === $lowerSearch) {
136
+                    $foundUserById = true;
137
+                }
138
+                $result['exact'][] = [
139
+                    'label' => $userDisplayName,
140
+                    'value' => [
141
+                        'shareType' => Share::SHARE_TYPE_USER,
142
+                        'shareWith' => $uid,
143
+                    ],
144
+                ];
145
+            } else {
146
+                $result['wide'][] = [
147
+                    'label' => $userDisplayName,
148
+                    'value' => [
149
+                        'shareType' => Share::SHARE_TYPE_USER,
150
+                        'shareWith' => $uid,
151
+                    ],
152
+                ];
153
+            }
154
+        }
155
+
156
+        if ($offset === 0 && !$foundUserById) {
157
+            // On page one we try if the search result has a direct hit on the
158
+            // user id and if so, we add that to the exact match list
159
+            $user = $this->userManager->get($search);
160
+            if ($user instanceof IUser) {
161
+                $addUser = true;
162
+
163
+                if ($this->shareWithGroupOnly) {
164
+                    // Only add, if we have a common group
165
+                    $userGroupIds = array_map(function (IGroup $group) {
166
+                        return $group->getGID();
167
+                    }, $userGroups);
168
+                    $commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
169
+                    $addUser = !empty($commonGroups);
170
+                }
171
+
172
+                if ($addUser) {
173
+                    $result['exact'][] = [
174
+                        'label' => $user->getDisplayName(),
175
+                        'value' => [
176
+                            'shareType' => Share::SHARE_TYPE_USER,
177
+                            'shareWith' => $user->getUID(),
178
+                        ],
179
+                    ];
180
+                }
181
+            }
182
+        }
183
+
184
+        // overwrite wide matches if they are limited
185
+        if (!$this->shareeEnumeration || $this->shareeEnumerationInGroupOnly) {
186
+            $result['wide'] = $autoCompleteUsers;
187
+        }
188
+
189
+        $type = new SearchResultType('users');
190
+        $searchResult->addResultSet($type, $result['wide'], $result['exact']);
191
+        if (count($result['exact'])) {
192
+            $searchResult->markExactIdMatch($type);
193
+        }
194
+
195
+        return $hasMoreResults;
196
+    }
197
+
198
+    public function takeOutCurrentUser(array &$users) {
199
+        $currentUser = $this->userSession->getUser();
200
+        if(!is_null($currentUser)) {
201
+            if (isset($users[$currentUser->getUID()])) {
202
+                unset($users[$currentUser->getUID()]);
203
+            }
204
+        }
205
+    }
206 206
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 							'label' => $user->getDisplayName(),
108 108
 							'value' => [
109 109
 								'shareType' => IShare::TYPE_USER,
110
-								'shareWith' => (string)$user->getUID(),
110
+								'shareWith' => (string) $user->getUID(),
111 111
 							],
112 112
 						];
113 113
 					}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 
163 163
 				if ($this->shareWithGroupOnly) {
164 164
 					// Only add, if we have a common group
165
-					$userGroupIds = array_map(function (IGroup $group) {
165
+					$userGroupIds = array_map(function(IGroup $group) {
166 166
 						return $group->getGID();
167 167
 					}, $userGroups);
168 168
 					$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
 	public function takeOutCurrentUser(array &$users) {
199 199
 		$currentUser = $this->userSession->getUser();
200
-		if(!is_null($currentUser)) {
200
+		if (!is_null($currentUser)) {
201 201
 			if (isset($users[$currentUser->getUID()])) {
202 202
 				unset($users[$currentUser->getUID()]);
203 203
 			}
Please login to merge, or discard this patch.
lib/public/Files.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -48,73 +48,73 @@
 block discarded – undo
48 48
  * @deprecated 14.0.0
49 49
  */
50 50
 class Files {
51
-	/**
52
-	 * Recusive deletion of folders
53
-	 * @return bool
54
-	 * @since 5.0.0
55
-	 * @deprecated 14.0.0
56
-	 */
57
-	static public function rmdirr($dir) {
58
-		return \OC_Helper::rmdirr( $dir );
59
-	}
51
+    /**
52
+     * Recusive deletion of folders
53
+     * @return bool
54
+     * @since 5.0.0
55
+     * @deprecated 14.0.0
56
+     */
57
+    static public function rmdirr($dir) {
58
+        return \OC_Helper::rmdirr( $dir );
59
+    }
60 60
 
61
-	/**
62
-	 * Get the mimetype form a local file
63
-	 * @param string $path
64
-	 * @return string
65
-	 * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
66
-	 * @since 5.0.0
67
-	 * @deprecated 14.0.0
68
-	 */
69
-	static public function getMimeType($path) {
70
-		return \OC::$server->getMimeTypeDetector()->detect($path);
71
-	}
61
+    /**
62
+     * Get the mimetype form a local file
63
+     * @param string $path
64
+     * @return string
65
+     * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
66
+     * @since 5.0.0
67
+     * @deprecated 14.0.0
68
+     */
69
+    static public function getMimeType($path) {
70
+        return \OC::$server->getMimeTypeDetector()->detect($path);
71
+    }
72 72
 
73
-	/**
74
-	 * Search for files by mimetype
75
-	 * @param string $mimetype
76
-	 * @return array
77
-	 * @since 6.0.0
78
-	 * @deprecated 14.0.0
79
-	 */
80
-	static public function searchByMime($mimetype) {
81
-		return \OC\Files\Filesystem::searchByMime($mimetype);
82
-	}
73
+    /**
74
+     * Search for files by mimetype
75
+     * @param string $mimetype
76
+     * @return array
77
+     * @since 6.0.0
78
+     * @deprecated 14.0.0
79
+     */
80
+    static public function searchByMime($mimetype) {
81
+        return \OC\Files\Filesystem::searchByMime($mimetype);
82
+    }
83 83
 
84
-	/**
85
-	 * Copy the contents of one stream to another
86
-	 * @param resource $source
87
-	 * @param resource $target
88
-	 * @return int the number of bytes copied
89
-	 * @since 5.0.0
90
-	 * @deprecated 14.0.0
91
-	 */
92
-	public static function streamCopy($source, $target) {
93
-		list($count, ) = \OC_Helper::streamCopy( $source, $target );
94
-		return $count;
95
-	}
84
+    /**
85
+     * Copy the contents of one stream to another
86
+     * @param resource $source
87
+     * @param resource $target
88
+     * @return int the number of bytes copied
89
+     * @since 5.0.0
90
+     * @deprecated 14.0.0
91
+     */
92
+    public static function streamCopy($source, $target) {
93
+        list($count, ) = \OC_Helper::streamCopy( $source, $target );
94
+        return $count;
95
+    }
96 96
 
97
-	/**
98
-	 * Adds a suffix to the name in case the file exists
99
-	 * @param string $path
100
-	 * @param string $filename
101
-	 * @return string
102
-	 * @since 5.0.0
103
-	 * @deprecated 14.0.0 use getNonExistingName of the OCP\Files\Folder object
104
-	 */
105
-	public static function buildNotExistingFileName($path, $filename) {
106
-		return \OC_Helper::buildNotExistingFileName($path, $filename);
107
-	}
97
+    /**
98
+     * Adds a suffix to the name in case the file exists
99
+     * @param string $path
100
+     * @param string $filename
101
+     * @return string
102
+     * @since 5.0.0
103
+     * @deprecated 14.0.0 use getNonExistingName of the OCP\Files\Folder object
104
+     */
105
+    public static function buildNotExistingFileName($path, $filename) {
106
+        return \OC_Helper::buildNotExistingFileName($path, $filename);
107
+    }
108 108
 
109
-	/**
110
-	 * Gets the Storage for an app - creates the needed folder if they are not
111
-	 * existent
112
-	 * @param string $app
113
-	 * @return \OC\Files\View
114
-	 * @since 5.0.0
115
-	 * @deprecated 14.0.0 use IAppData instead
116
-	 */
117
-	public static function getStorage($app) {
118
-		return \OC_App::getStorage( $app );
119
-	}
109
+    /**
110
+     * Gets the Storage for an app - creates the needed folder if they are not
111
+     * existent
112
+     * @param string $app
113
+     * @return \OC\Files\View
114
+     * @since 5.0.0
115
+     * @deprecated 14.0.0 use IAppData instead
116
+     */
117
+    public static function getStorage($app) {
118
+        return \OC_App::getStorage( $app );
119
+    }
120 120
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @deprecated 14.0.0
56 56
 	 */
57 57
 	static public function rmdirr($dir) {
58
-		return \OC_Helper::rmdirr( $dir );
58
+		return \OC_Helper::rmdirr($dir);
59 59
 	}
60 60
 
61 61
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @deprecated 14.0.0
91 91
 	 */
92 92
 	public static function streamCopy($source, $target) {
93
-		list($count, ) = \OC_Helper::streamCopy( $source, $target );
93
+		list($count,) = \OC_Helper::streamCopy($source, $target);
94 94
 		return $count;
95 95
 	}
96 96
 
@@ -115,6 +115,6 @@  discard block
 block discarded – undo
115 115
 	 * @deprecated 14.0.0 use IAppData instead
116 116
 	 */
117 117
 	public static function getStorage($app) {
118
-		return \OC_App::getStorage( $app );
118
+		return \OC_App::getStorage($app);
119 119
 	}
120 120
 }
Please login to merge, or discard this patch.
lib/public/Accounts/PropertyDoesNotExistException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  */
33 33
 class PropertyDoesNotExistException extends \Exception {
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 * @param string $msg the error message
38
-	 * @since 15.0.0
39
-	 */
40
-	public function __construct($property) {
41
-		parent::__construct('Property ' . $property . ' does not exist.');
42
-	}
35
+    /**
36
+     * Constructor
37
+     * @param string $msg the error message
38
+     * @since 15.0.0
39
+     */
40
+    public function __construct($property) {
41
+        parent::__construct('Property ' . $property . ' does not exist.');
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	 * @since 15.0.0
39 39
 	 */
40 40
 	public function __construct($property) {
41
-		parent::__construct('Property ' . $property . ' does not exist.');
41
+		parent::__construct('Property '.$property.' does not exist.');
42 42
 	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/public/Util.php 2 patches
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -57,473 +57,473 @@
 block discarded – undo
57 57
  * @since 4.0.0
58 58
  */
59 59
 class Util {
60
-	/**
61
-	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62
-	 */
63
-	const DEBUG=0;
64
-	/**
65
-	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
66
-	 */
67
-	const INFO=1;
68
-	/**
69
-	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
70
-	 */
71
-	const WARN=2;
72
-	/**
73
-	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74
-	 */
75
-	const ERROR=3;
76
-	/**
77
-	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78
-	 */
79
-	const FATAL=4;
80
-
81
-	/** \OCP\Share\IManager */
82
-	private static $shareManager;
83
-
84
-	/**
85
-	 * get the current installed version of Nextcloud
86
-	 * @return array
87
-	 * @since 4.0.0
88
-	 */
89
-	public static function getVersion() {
90
-		return \OC_Util::getVersion();
91
-	}
92
-
93
-	/**
94
-	 * @since 17.0.0
95
-	 */
96
-	public static function hasExtendedSupport(): bool {
97
-		try {
98
-			/** @var \OCP\Support\Subscription\IRegistry */
99
-			$subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
100
-			return $subscriptionRegistry->delegateHasExtendedSupport();
101
-		} catch (AppFramework\QueryException $e) {}
102
-		return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
103
-	}
104
-
105
-	/**
106
-	 * Set current update channel
107
-	 * @param string $channel
108
-	 * @since 8.1.0
109
-	 */
110
-	public static function setChannel($channel) {
111
-		\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
112
-	}
113
-
114
-	/**
115
-	 * Get current update channel
116
-	 * @return string
117
-	 * @since 8.1.0
118
-	 */
119
-	public static function getChannel() {
120
-		return \OC_Util::getChannel();
121
-	}
122
-
123
-	/**
124
-	 * write a message in the log
125
-	 * @param string $app
126
-	 * @param string $message
127
-	 * @param int $level
128
-	 * @since 4.0.0
129
-	 * @deprecated 13.0.0 use log of \OCP\ILogger
130
-	 */
131
-	public static function writeLog($app, $message, $level) {
132
-		$context = ['app' => $app];
133
-		\OC::$server->getLogger()->log($level, $message, $context);
134
-	}
135
-
136
-	/**
137
-	 * check if sharing is disabled for the current user
138
-	 *
139
-	 * @return boolean
140
-	 * @since 7.0.0
141
-	 * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
142
-	 */
143
-	public static function isSharingDisabledForUser() {
144
-		if (self::$shareManager === null) {
145
-			self::$shareManager = \OC::$server->getShareManager();
146
-		}
147
-
148
-		$user = \OC::$server->getUserSession()->getUser();
149
-		if ($user !== null) {
150
-			$user = $user->getUID();
151
-		}
152
-
153
-		return self::$shareManager->sharingDisabledForUser($user);
154
-	}
155
-
156
-	/**
157
-	 * get l10n object
158
-	 * @param string $application
159
-	 * @param string|null $language
160
-	 * @return \OCP\IL10N
161
-	 * @since 6.0.0 - parameter $language was added in 8.0.0
162
-	 */
163
-	public static function getL10N($application, $language = null) {
164
-		return \OC::$server->getL10N($application, $language);
165
-	}
166
-
167
-	/**
168
-	 * add a css file
169
-	 * @param string $application
170
-	 * @param string $file
171
-	 * @since 4.0.0
172
-	 */
173
-	public static function addStyle($application, $file = null) {
174
-		\OC_Util::addStyle( $application, $file );
175
-	}
176
-
177
-	/**
178
-	 * add a javascript file
179
-	 * @param string $application
180
-	 * @param string $file
181
-	 * @since 4.0.0
182
-	 */
183
-	public static function addScript($application, $file = null) {
184
-		\OC_Util::addScript( $application, $file );
185
-	}
186
-
187
-	/**
188
-	 * Add a translation JS file
189
-	 * @param string $application application id
190
-	 * @param string $languageCode language code, defaults to the current locale
191
-	 * @since 8.0.0
192
-	 */
193
-	public static function addTranslations($application, $languageCode = null) {
194
-		\OC_Util::addTranslations($application, $languageCode);
195
-	}
196
-
197
-	/**
198
-	 * Add a custom element to the header
199
-	 * If $text is null then the element will be written as empty element.
200
-	 * So use "" to get a closing tag.
201
-	 * @param string $tag tag name of the element
202
-	 * @param array $attributes array of attributes for the element
203
-	 * @param string $text the text content for the element
204
-	 * @since 4.0.0
205
-	 */
206
-	public static function addHeader($tag, $attributes, $text=null) {
207
-		\OC_Util::addHeader($tag, $attributes, $text);
208
-	}
209
-
210
-	/**
211
-	 * Creates an absolute url to the given app and file.
212
-	 * @param string $app app
213
-	 * @param string $file file
214
-	 * @param array $args array with param=>value, will be appended to the returned url
215
-	 * 	The value of $args will be urlencoded
216
-	 * @return string the url
217
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
218
-	 */
219
-	public static function linkToAbsolute($app, $file, $args = []) {
220
-		$urlGenerator = \OC::$server->getURLGenerator();
221
-		return $urlGenerator->getAbsoluteURL(
222
-			$urlGenerator->linkTo($app, $file, $args)
223
-		);
224
-	}
225
-
226
-	/**
227
-	 * Creates an absolute url for remote use.
228
-	 * @param string $service id
229
-	 * @return string the url
230
-	 * @since 4.0.0
231
-	 */
232
-	public static function linkToRemote($service) {
233
-		$urlGenerator = \OC::$server->getURLGenerator();
234
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
235
-		return $urlGenerator->getAbsoluteURL(
236
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
237
-		);
238
-	}
239
-
240
-	/**
241
-	 * Creates an absolute url for public use
242
-	 * @param string $service id
243
-	 * @return string the url
244
-	 * @since 4.5.0
245
-	 * @deprecated 15.0.0 - use OCP\IURLGenerator
246
-	 */
247
-	public static function linkToPublic($service) {
248
-		$urlGenerator = \OC::$server->getURLGenerator();
249
-		if ($service === 'files') {
250
-			return $urlGenerator->getAbsoluteURL('/s');
251
-		}
252
-		return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
253
-	}
254
-
255
-	/**
256
-	 * Returns the server host name without an eventual port number
257
-	 * @return string the server hostname
258
-	 * @since 5.0.0
259
-	 */
260
-	public static function getServerHostName() {
261
-		$host_name = \OC::$server->getRequest()->getServerHost();
262
-		// strip away port number (if existing)
263
-		$colon_pos = strpos($host_name, ':');
264
-		if ($colon_pos != false) {
265
-			$host_name = substr($host_name, 0, $colon_pos);
266
-		}
267
-		return $host_name;
268
-	}
269
-
270
-	/**
271
-	 * Returns the default email address
272
-	 * @param string $user_part the user part of the address
273
-	 * @return string the default email address
274
-	 *
275
-	 * Assembles a default email address (using the server hostname
276
-	 * and the given user part, and returns it
277
-	 * Example: when given lostpassword-noreply as $user_part param,
278
-	 *     and is currently accessed via http(s)://example.com/,
279
-	 *     it would return '[email protected]'
280
-	 *
281
-	 * If the configuration value 'mail_from_address' is set in
282
-	 * config.php, this value will override the $user_part that
283
-	 * is passed to this function
284
-	 * @since 5.0.0
285
-	 */
286
-	public static function getDefaultEmailAddress($user_part) {
287
-		$config = \OC::$server->getConfig();
288
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
289
-		$host_name = self::getServerHostName();
290
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
291
-		$defaultEmailAddress = $user_part.'@'.$host_name;
292
-
293
-		$mailer = \OC::$server->getMailer();
294
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
295
-			return $defaultEmailAddress;
296
-		}
297
-
298
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
299
-		return $user_part.'@localhost.localdomain';
300
-	}
301
-
302
-	/**
303
-	 * Make a human file size (2048 to 2 kB)
304
-	 * @param int $bytes file size in bytes
305
-	 * @return string a human readable file size
306
-	 * @since 4.0.0
307
-	 */
308
-	public static function humanFileSize($bytes) {
309
-		return \OC_Helper::humanFileSize($bytes);
310
-	}
311
-
312
-	/**
313
-	 * Make a computer file size (2 kB to 2048)
314
-	 * @param string $str file size in a fancy format
315
-	 * @return float a file size in bytes
316
-	 *
317
-	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
318
-	 * @since 4.0.0
319
-	 */
320
-	public static function computerFileSize($str) {
321
-		return \OC_Helper::computerFileSize($str);
322
-	}
323
-
324
-	/**
325
-	 * connects a function to a hook
326
-	 *
327
-	 * @param string $signalClass class name of emitter
328
-	 * @param string $signalName name of signal
329
-	 * @param string|object $slotClass class name of slot
330
-	 * @param string $slotName name of slot
331
-	 * @return bool
332
-	 *
333
-	 * This function makes it very easy to connect to use hooks.
334
-	 *
335
-	 * TODO: write example
336
-	 * @since 4.0.0
337
-	 */
338
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
339
-		return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
340
-	}
341
-
342
-	/**
343
-	 * Emits a signal. To get data from the slot use references!
344
-	 * @param string $signalclass class name of emitter
345
-	 * @param string $signalname name of signal
346
-	 * @param array $params default: array() array with additional data
347
-	 * @return bool true if slots exists or false if not
348
-	 *
349
-	 * TODO: write example
350
-	 * @since 4.0.0
351
-	 */
352
-	static public function emitHook($signalclass, $signalname, $params = []) {
353
-		return \OC_Hook::emit($signalclass, $signalname, $params);
354
-	}
355
-
356
-	/**
357
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
358
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
359
-	 * would not be cached these unit-tests would fail.
360
-	 * @var string
361
-	 */
362
-	private static $token = '';
363
-
364
-	/**
365
-	 * Register an get/post call. This is important to prevent CSRF attacks
366
-	 * @since 4.5.0
367
-	 */
368
-	public static function callRegister() {
369
-		if(self::$token === '') {
370
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
371
-		}
372
-		return self::$token;
373
-	}
374
-
375
-	/**
376
-	 * Used to sanitize HTML
377
-	 *
378
-	 * This function is used to sanitize HTML and should be applied on any
379
-	 * string or array of strings before displaying it on a web page.
380
-	 *
381
-	 * @param string|array $value
382
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
383
-	 * @since 4.5.0
384
-	 */
385
-	public static function sanitizeHTML($value) {
386
-		return \OC_Util::sanitizeHTML($value);
387
-	}
388
-
389
-	/**
390
-	 * Public function to encode url parameters
391
-	 *
392
-	 * This function is used to encode path to file before output.
393
-	 * Encoding is done according to RFC 3986 with one exception:
394
-	 * Character '/' is preserved as is.
395
-	 *
396
-	 * @param string $component part of URI to encode
397
-	 * @return string
398
-	 * @since 6.0.0
399
-	 */
400
-	public static function encodePath($component) {
401
-		return \OC_Util::encodePath($component);
402
-	}
403
-
404
-	/**
405
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
406
-	 *
407
-	 * @param array $input The array to work on
408
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
409
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
410
-	 * @return array
411
-	 * @since 4.5.0
412
-	 */
413
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
414
-		return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
415
-	}
416
-
417
-	/**
418
-	 * performs a search in a nested array
419
-	 *
420
-	 * @param array $haystack the array to be searched
421
-	 * @param string $needle the search string
422
-	 * @param mixed $index optional, only search this key name
423
-	 * @return mixed the key of the matching field, otherwise false
424
-	 * @since 4.5.0
425
-	 * @deprecated 15.0.0
426
-	 */
427
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
428
-		return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
429
-	}
430
-
431
-	/**
432
-	 * calculates the maximum upload size respecting system settings, free space and user quota
433
-	 *
434
-	 * @param string $dir the current folder where the user currently operates
435
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
436
-	 * @return int number of bytes representing
437
-	 * @since 5.0.0
438
-	 */
439
-	public static function maxUploadFilesize($dir, $free = null) {
440
-		return \OC_Helper::maxUploadFilesize($dir, $free);
441
-	}
442
-
443
-	/**
444
-	 * Calculate free space left within user quota
445
-	 * @param string $dir the current folder where the user currently operates
446
-	 * @return int number of bytes representing
447
-	 * @since 7.0.0
448
-	 */
449
-	public static function freeSpace($dir) {
450
-		return \OC_Helper::freeSpace($dir);
451
-	}
452
-
453
-	/**
454
-	 * Calculate PHP upload limit
455
-	 *
456
-	 * @return int number of bytes representing
457
-	 * @since 7.0.0
458
-	 */
459
-	public static function uploadLimit() {
460
-		return \OC_Helper::uploadLimit();
461
-	}
462
-
463
-	/**
464
-	 * Returns whether the given file name is valid
465
-	 * @param string $file file name to check
466
-	 * @return bool true if the file name is valid, false otherwise
467
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
468
-	 * @since 7.0.0
469
-	 * @suppress PhanDeprecatedFunction
470
-	 */
471
-	public static function isValidFileName($file) {
472
-		return \OC_Util::isValidFileName($file);
473
-	}
474
-
475
-	/**
476
-	 * Compare two strings to provide a natural sort
477
-	 * @param string $a first string to compare
478
-	 * @param string $b second string to compare
479
-	 * @return int -1 if $b comes before $a, 1 if $a comes before $b
480
-	 * or 0 if the strings are identical
481
-	 * @since 7.0.0
482
-	 */
483
-	public static function naturalSortCompare($a, $b) {
484
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
485
-	}
486
-
487
-	/**
488
-	 * check if a password is required for each public link
489
-	 * @return boolean
490
-	 * @since 7.0.0
491
-	 */
492
-	public static function isPublicLinkPasswordRequired() {
493
-		return \OC_Util::isPublicLinkPasswordRequired();
494
-	}
495
-
496
-	/**
497
-	 * check if share API enforces a default expire date
498
-	 * @return boolean
499
-	 * @since 8.0.0
500
-	 */
501
-	public static function isDefaultExpireDateEnforced() {
502
-		return \OC_Util::isDefaultExpireDateEnforced();
503
-	}
504
-
505
-	protected static $needUpgradeCache = null;
506
-
507
-	/**
508
-	 * Checks whether the current version needs upgrade.
509
-	 *
510
-	 * @return bool true if upgrade is needed, false otherwise
511
-	 * @since 7.0.0
512
-	 */
513
-	public static function needUpgrade() {
514
-		if (!isset(self::$needUpgradeCache)) {
515
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
516
-		}
517
-		return self::$needUpgradeCache;
518
-	}
519
-
520
-	/**
521
-	 * is this Internet explorer ?
522
-	 *
523
-	 * @return boolean
524
-	 * @since 14.0.0
525
-	 */
526
-	public static function isIe() {
527
-		return \OC_Util::isIe();
528
-	}
60
+    /**
61
+     * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62
+     */
63
+    const DEBUG=0;
64
+    /**
65
+     * @deprecated 14.0.0 use \OCP\ILogger::INFO
66
+     */
67
+    const INFO=1;
68
+    /**
69
+     * @deprecated 14.0.0 use \OCP\ILogger::WARN
70
+     */
71
+    const WARN=2;
72
+    /**
73
+     * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74
+     */
75
+    const ERROR=3;
76
+    /**
77
+     * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78
+     */
79
+    const FATAL=4;
80
+
81
+    /** \OCP\Share\IManager */
82
+    private static $shareManager;
83
+
84
+    /**
85
+     * get the current installed version of Nextcloud
86
+     * @return array
87
+     * @since 4.0.0
88
+     */
89
+    public static function getVersion() {
90
+        return \OC_Util::getVersion();
91
+    }
92
+
93
+    /**
94
+     * @since 17.0.0
95
+     */
96
+    public static function hasExtendedSupport(): bool {
97
+        try {
98
+            /** @var \OCP\Support\Subscription\IRegistry */
99
+            $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
100
+            return $subscriptionRegistry->delegateHasExtendedSupport();
101
+        } catch (AppFramework\QueryException $e) {}
102
+        return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false);
103
+    }
104
+
105
+    /**
106
+     * Set current update channel
107
+     * @param string $channel
108
+     * @since 8.1.0
109
+     */
110
+    public static function setChannel($channel) {
111
+        \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
112
+    }
113
+
114
+    /**
115
+     * Get current update channel
116
+     * @return string
117
+     * @since 8.1.0
118
+     */
119
+    public static function getChannel() {
120
+        return \OC_Util::getChannel();
121
+    }
122
+
123
+    /**
124
+     * write a message in the log
125
+     * @param string $app
126
+     * @param string $message
127
+     * @param int $level
128
+     * @since 4.0.0
129
+     * @deprecated 13.0.0 use log of \OCP\ILogger
130
+     */
131
+    public static function writeLog($app, $message, $level) {
132
+        $context = ['app' => $app];
133
+        \OC::$server->getLogger()->log($level, $message, $context);
134
+    }
135
+
136
+    /**
137
+     * check if sharing is disabled for the current user
138
+     *
139
+     * @return boolean
140
+     * @since 7.0.0
141
+     * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
142
+     */
143
+    public static function isSharingDisabledForUser() {
144
+        if (self::$shareManager === null) {
145
+            self::$shareManager = \OC::$server->getShareManager();
146
+        }
147
+
148
+        $user = \OC::$server->getUserSession()->getUser();
149
+        if ($user !== null) {
150
+            $user = $user->getUID();
151
+        }
152
+
153
+        return self::$shareManager->sharingDisabledForUser($user);
154
+    }
155
+
156
+    /**
157
+     * get l10n object
158
+     * @param string $application
159
+     * @param string|null $language
160
+     * @return \OCP\IL10N
161
+     * @since 6.0.0 - parameter $language was added in 8.0.0
162
+     */
163
+    public static function getL10N($application, $language = null) {
164
+        return \OC::$server->getL10N($application, $language);
165
+    }
166
+
167
+    /**
168
+     * add a css file
169
+     * @param string $application
170
+     * @param string $file
171
+     * @since 4.0.0
172
+     */
173
+    public static function addStyle($application, $file = null) {
174
+        \OC_Util::addStyle( $application, $file );
175
+    }
176
+
177
+    /**
178
+     * add a javascript file
179
+     * @param string $application
180
+     * @param string $file
181
+     * @since 4.0.0
182
+     */
183
+    public static function addScript($application, $file = null) {
184
+        \OC_Util::addScript( $application, $file );
185
+    }
186
+
187
+    /**
188
+     * Add a translation JS file
189
+     * @param string $application application id
190
+     * @param string $languageCode language code, defaults to the current locale
191
+     * @since 8.0.0
192
+     */
193
+    public static function addTranslations($application, $languageCode = null) {
194
+        \OC_Util::addTranslations($application, $languageCode);
195
+    }
196
+
197
+    /**
198
+     * Add a custom element to the header
199
+     * If $text is null then the element will be written as empty element.
200
+     * So use "" to get a closing tag.
201
+     * @param string $tag tag name of the element
202
+     * @param array $attributes array of attributes for the element
203
+     * @param string $text the text content for the element
204
+     * @since 4.0.0
205
+     */
206
+    public static function addHeader($tag, $attributes, $text=null) {
207
+        \OC_Util::addHeader($tag, $attributes, $text);
208
+    }
209
+
210
+    /**
211
+     * Creates an absolute url to the given app and file.
212
+     * @param string $app app
213
+     * @param string $file file
214
+     * @param array $args array with param=>value, will be appended to the returned url
215
+     * 	The value of $args will be urlencoded
216
+     * @return string the url
217
+     * @since 4.0.0 - parameter $args was added in 4.5.0
218
+     */
219
+    public static function linkToAbsolute($app, $file, $args = []) {
220
+        $urlGenerator = \OC::$server->getURLGenerator();
221
+        return $urlGenerator->getAbsoluteURL(
222
+            $urlGenerator->linkTo($app, $file, $args)
223
+        );
224
+    }
225
+
226
+    /**
227
+     * Creates an absolute url for remote use.
228
+     * @param string $service id
229
+     * @return string the url
230
+     * @since 4.0.0
231
+     */
232
+    public static function linkToRemote($service) {
233
+        $urlGenerator = \OC::$server->getURLGenerator();
234
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
235
+        return $urlGenerator->getAbsoluteURL(
236
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
237
+        );
238
+    }
239
+
240
+    /**
241
+     * Creates an absolute url for public use
242
+     * @param string $service id
243
+     * @return string the url
244
+     * @since 4.5.0
245
+     * @deprecated 15.0.0 - use OCP\IURLGenerator
246
+     */
247
+    public static function linkToPublic($service) {
248
+        $urlGenerator = \OC::$server->getURLGenerator();
249
+        if ($service === 'files') {
250
+            return $urlGenerator->getAbsoluteURL('/s');
251
+        }
252
+        return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service);
253
+    }
254
+
255
+    /**
256
+     * Returns the server host name without an eventual port number
257
+     * @return string the server hostname
258
+     * @since 5.0.0
259
+     */
260
+    public static function getServerHostName() {
261
+        $host_name = \OC::$server->getRequest()->getServerHost();
262
+        // strip away port number (if existing)
263
+        $colon_pos = strpos($host_name, ':');
264
+        if ($colon_pos != false) {
265
+            $host_name = substr($host_name, 0, $colon_pos);
266
+        }
267
+        return $host_name;
268
+    }
269
+
270
+    /**
271
+     * Returns the default email address
272
+     * @param string $user_part the user part of the address
273
+     * @return string the default email address
274
+     *
275
+     * Assembles a default email address (using the server hostname
276
+     * and the given user part, and returns it
277
+     * Example: when given lostpassword-noreply as $user_part param,
278
+     *     and is currently accessed via http(s)://example.com/,
279
+     *     it would return '[email protected]'
280
+     *
281
+     * If the configuration value 'mail_from_address' is set in
282
+     * config.php, this value will override the $user_part that
283
+     * is passed to this function
284
+     * @since 5.0.0
285
+     */
286
+    public static function getDefaultEmailAddress($user_part) {
287
+        $config = \OC::$server->getConfig();
288
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
289
+        $host_name = self::getServerHostName();
290
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
291
+        $defaultEmailAddress = $user_part.'@'.$host_name;
292
+
293
+        $mailer = \OC::$server->getMailer();
294
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
295
+            return $defaultEmailAddress;
296
+        }
297
+
298
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
299
+        return $user_part.'@localhost.localdomain';
300
+    }
301
+
302
+    /**
303
+     * Make a human file size (2048 to 2 kB)
304
+     * @param int $bytes file size in bytes
305
+     * @return string a human readable file size
306
+     * @since 4.0.0
307
+     */
308
+    public static function humanFileSize($bytes) {
309
+        return \OC_Helper::humanFileSize($bytes);
310
+    }
311
+
312
+    /**
313
+     * Make a computer file size (2 kB to 2048)
314
+     * @param string $str file size in a fancy format
315
+     * @return float a file size in bytes
316
+     *
317
+     * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
318
+     * @since 4.0.0
319
+     */
320
+    public static function computerFileSize($str) {
321
+        return \OC_Helper::computerFileSize($str);
322
+    }
323
+
324
+    /**
325
+     * connects a function to a hook
326
+     *
327
+     * @param string $signalClass class name of emitter
328
+     * @param string $signalName name of signal
329
+     * @param string|object $slotClass class name of slot
330
+     * @param string $slotName name of slot
331
+     * @return bool
332
+     *
333
+     * This function makes it very easy to connect to use hooks.
334
+     *
335
+     * TODO: write example
336
+     * @since 4.0.0
337
+     */
338
+    static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
339
+        return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
340
+    }
341
+
342
+    /**
343
+     * Emits a signal. To get data from the slot use references!
344
+     * @param string $signalclass class name of emitter
345
+     * @param string $signalname name of signal
346
+     * @param array $params default: array() array with additional data
347
+     * @return bool true if slots exists or false if not
348
+     *
349
+     * TODO: write example
350
+     * @since 4.0.0
351
+     */
352
+    static public function emitHook($signalclass, $signalname, $params = []) {
353
+        return \OC_Hook::emit($signalclass, $signalname, $params);
354
+    }
355
+
356
+    /**
357
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
358
+     * multiple OC_Template elements which invoke `callRegister`. If the value
359
+     * would not be cached these unit-tests would fail.
360
+     * @var string
361
+     */
362
+    private static $token = '';
363
+
364
+    /**
365
+     * Register an get/post call. This is important to prevent CSRF attacks
366
+     * @since 4.5.0
367
+     */
368
+    public static function callRegister() {
369
+        if(self::$token === '') {
370
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
371
+        }
372
+        return self::$token;
373
+    }
374
+
375
+    /**
376
+     * Used to sanitize HTML
377
+     *
378
+     * This function is used to sanitize HTML and should be applied on any
379
+     * string or array of strings before displaying it on a web page.
380
+     *
381
+     * @param string|array $value
382
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
383
+     * @since 4.5.0
384
+     */
385
+    public static function sanitizeHTML($value) {
386
+        return \OC_Util::sanitizeHTML($value);
387
+    }
388
+
389
+    /**
390
+     * Public function to encode url parameters
391
+     *
392
+     * This function is used to encode path to file before output.
393
+     * Encoding is done according to RFC 3986 with one exception:
394
+     * Character '/' is preserved as is.
395
+     *
396
+     * @param string $component part of URI to encode
397
+     * @return string
398
+     * @since 6.0.0
399
+     */
400
+    public static function encodePath($component) {
401
+        return \OC_Util::encodePath($component);
402
+    }
403
+
404
+    /**
405
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
406
+     *
407
+     * @param array $input The array to work on
408
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
409
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
410
+     * @return array
411
+     * @since 4.5.0
412
+     */
413
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
414
+        return \OC_Helper::mb_array_change_key_case($input, $case, $encoding);
415
+    }
416
+
417
+    /**
418
+     * performs a search in a nested array
419
+     *
420
+     * @param array $haystack the array to be searched
421
+     * @param string $needle the search string
422
+     * @param mixed $index optional, only search this key name
423
+     * @return mixed the key of the matching field, otherwise false
424
+     * @since 4.5.0
425
+     * @deprecated 15.0.0
426
+     */
427
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
428
+        return \OC_Helper::recursiveArraySearch($haystack, $needle, $index);
429
+    }
430
+
431
+    /**
432
+     * calculates the maximum upload size respecting system settings, free space and user quota
433
+     *
434
+     * @param string $dir the current folder where the user currently operates
435
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
436
+     * @return int number of bytes representing
437
+     * @since 5.0.0
438
+     */
439
+    public static function maxUploadFilesize($dir, $free = null) {
440
+        return \OC_Helper::maxUploadFilesize($dir, $free);
441
+    }
442
+
443
+    /**
444
+     * Calculate free space left within user quota
445
+     * @param string $dir the current folder where the user currently operates
446
+     * @return int number of bytes representing
447
+     * @since 7.0.0
448
+     */
449
+    public static function freeSpace($dir) {
450
+        return \OC_Helper::freeSpace($dir);
451
+    }
452
+
453
+    /**
454
+     * Calculate PHP upload limit
455
+     *
456
+     * @return int number of bytes representing
457
+     * @since 7.0.0
458
+     */
459
+    public static function uploadLimit() {
460
+        return \OC_Helper::uploadLimit();
461
+    }
462
+
463
+    /**
464
+     * Returns whether the given file name is valid
465
+     * @param string $file file name to check
466
+     * @return bool true if the file name is valid, false otherwise
467
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
468
+     * @since 7.0.0
469
+     * @suppress PhanDeprecatedFunction
470
+     */
471
+    public static function isValidFileName($file) {
472
+        return \OC_Util::isValidFileName($file);
473
+    }
474
+
475
+    /**
476
+     * Compare two strings to provide a natural sort
477
+     * @param string $a first string to compare
478
+     * @param string $b second string to compare
479
+     * @return int -1 if $b comes before $a, 1 if $a comes before $b
480
+     * or 0 if the strings are identical
481
+     * @since 7.0.0
482
+     */
483
+    public static function naturalSortCompare($a, $b) {
484
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
485
+    }
486
+
487
+    /**
488
+     * check if a password is required for each public link
489
+     * @return boolean
490
+     * @since 7.0.0
491
+     */
492
+    public static function isPublicLinkPasswordRequired() {
493
+        return \OC_Util::isPublicLinkPasswordRequired();
494
+    }
495
+
496
+    /**
497
+     * check if share API enforces a default expire date
498
+     * @return boolean
499
+     * @since 8.0.0
500
+     */
501
+    public static function isDefaultExpireDateEnforced() {
502
+        return \OC_Util::isDefaultExpireDateEnforced();
503
+    }
504
+
505
+    protected static $needUpgradeCache = null;
506
+
507
+    /**
508
+     * Checks whether the current version needs upgrade.
509
+     *
510
+     * @return bool true if upgrade is needed, false otherwise
511
+     * @since 7.0.0
512
+     */
513
+    public static function needUpgrade() {
514
+        if (!isset(self::$needUpgradeCache)) {
515
+            self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
516
+        }
517
+        return self::$needUpgradeCache;
518
+    }
519
+
520
+    /**
521
+     * is this Internet explorer ?
522
+     *
523
+     * @return boolean
524
+     * @since 14.0.0
525
+     */
526
+    public static function isIe() {
527
+        return \OC_Util::isIe();
528
+    }
529 529
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * @deprecated 14.0.0 use \OCP\ILogger::DEBUG
62 62
 	 */
63
-	const DEBUG=0;
63
+	const DEBUG = 0;
64 64
 	/**
65 65
 	 * @deprecated 14.0.0 use \OCP\ILogger::INFO
66 66
 	 */
67
-	const INFO=1;
67
+	const INFO = 1;
68 68
 	/**
69 69
 	 * @deprecated 14.0.0 use \OCP\ILogger::WARN
70 70
 	 */
71
-	const WARN=2;
71
+	const WARN = 2;
72 72
 	/**
73 73
 	 * @deprecated 14.0.0 use \OCP\ILogger::ERROR
74 74
 	 */
75
-	const ERROR=3;
75
+	const ERROR = 3;
76 76
 	/**
77 77
 	 * @deprecated 14.0.0 use \OCP\ILogger::FATAL
78 78
 	 */
79
-	const FATAL=4;
79
+	const FATAL = 4;
80 80
 
81 81
 	/** \OCP\Share\IManager */
82 82
 	private static $shareManager;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 * @since 4.0.0
172 172
 	 */
173 173
 	public static function addStyle($application, $file = null) {
174
-		\OC_Util::addStyle( $application, $file );
174
+		\OC_Util::addStyle($application, $file);
175 175
 	}
176 176
 
177 177
 	/**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @since 4.0.0
182 182
 	 */
183 183
 	public static function addScript($application, $file = null) {
184
-		\OC_Util::addScript( $application, $file );
184
+		\OC_Util::addScript($application, $file);
185 185
 	}
186 186
 
187 187
 	/**
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param string $text the text content for the element
204 204
 	 * @since 4.0.0
205 205
 	 */
206
-	public static function addHeader($tag, $attributes, $text=null) {
206
+	public static function addHeader($tag, $attributes, $text = null) {
207 207
 		\OC_Util::addHeader($tag, $attributes, $text);
208 208
 	}
209 209
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 	 */
232 232
 	public static function linkToRemote($service) {
233 233
 		$urlGenerator = \OC::$server->getURLGenerator();
234
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
234
+		$remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service;
235 235
 		return $urlGenerator->getAbsoluteURL(
236
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
236
+			$remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '')
237 237
 		);
238 238
 	}
239 239
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @since 4.5.0
367 367
 	 */
368 368
 	public static function callRegister() {
369
-		if(self::$token === '') {
369
+		if (self::$token === '') {
370 370
 			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
371 371
 		}
372 372
 		return self::$token;
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 	 */
513 513
 	public static function needUpgrade() {
514 514
 		if (!isset(self::$needUpgradeCache)) {
515
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
515
+			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
516 516
 		}
517 517
 		return self::$needUpgradeCache;
518 518
 	}
Please login to merge, or discard this patch.
lib/public/AppFramework/ApiController.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -39,60 +39,60 @@
 block discarded – undo
39 39
  */
40 40
 abstract class ApiController extends Controller {
41 41
 
42
-	private $corsMethods;
43
-	private $corsAllowedHeaders;
44
-	private $corsMaxAge;
42
+    private $corsMethods;
43
+    private $corsAllowedHeaders;
44
+    private $corsMaxAge;
45 45
 
46
-	/**
47
-	 * constructor of the controller
48
-	 * @param string $appName the name of the app
49
-	 * @param IRequest $request an instance of the request
50
-	 * @param string $corsMethods comma separated string of HTTP verbs which
51
-	 * should be allowed for websites or webapps when calling your API, defaults to
52
-	 * 'PUT, POST, GET, DELETE, PATCH'
53
-	 * @param string $corsAllowedHeaders comma separated string of HTTP headers
54
-	 * which should be allowed for websites or webapps when calling your API,
55
-	 * defaults to 'Authorization, Content-Type, Accept'
56
-	 * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS
57
-	 * request should be cached, defaults to 1728000 seconds
58
-	 * @since 7.0.0
59
-	 */
60
-	public function __construct($appName,
61
-								IRequest $request,
62
-								$corsMethods='PUT, POST, GET, DELETE, PATCH',
63
-								$corsAllowedHeaders='Authorization, Content-Type, Accept',
64
-								$corsMaxAge=1728000) {
65
-		parent::__construct($appName, $request);
66
-		$this->corsMethods = $corsMethods;
67
-		$this->corsAllowedHeaders = $corsAllowedHeaders;
68
-		$this->corsMaxAge = $corsMaxAge;
69
-	}
46
+    /**
47
+     * constructor of the controller
48
+     * @param string $appName the name of the app
49
+     * @param IRequest $request an instance of the request
50
+     * @param string $corsMethods comma separated string of HTTP verbs which
51
+     * should be allowed for websites or webapps when calling your API, defaults to
52
+     * 'PUT, POST, GET, DELETE, PATCH'
53
+     * @param string $corsAllowedHeaders comma separated string of HTTP headers
54
+     * which should be allowed for websites or webapps when calling your API,
55
+     * defaults to 'Authorization, Content-Type, Accept'
56
+     * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS
57
+     * request should be cached, defaults to 1728000 seconds
58
+     * @since 7.0.0
59
+     */
60
+    public function __construct($appName,
61
+                                IRequest $request,
62
+                                $corsMethods='PUT, POST, GET, DELETE, PATCH',
63
+                                $corsAllowedHeaders='Authorization, Content-Type, Accept',
64
+                                $corsMaxAge=1728000) {
65
+        parent::__construct($appName, $request);
66
+        $this->corsMethods = $corsMethods;
67
+        $this->corsAllowedHeaders = $corsAllowedHeaders;
68
+        $this->corsMaxAge = $corsMaxAge;
69
+    }
70 70
 
71 71
 
72
-	/**
73
-	 * This method implements a preflighted cors response for you that you can
74
-	 * link to for the options request
75
-	 *
76
-	 * @NoAdminRequired
77
-	 * @NoCSRFRequired
78
-	 * @PublicPage
79
-	 * @since 7.0.0
80
-	 */
81
-	public function preflightedCors() {
82
-		if(isset($this->request->server['HTTP_ORIGIN'])) {
83
-			$origin = $this->request->server['HTTP_ORIGIN'];
84
-		} else {
85
-			$origin = '*';
86
-		}
72
+    /**
73
+     * This method implements a preflighted cors response for you that you can
74
+     * link to for the options request
75
+     *
76
+     * @NoAdminRequired
77
+     * @NoCSRFRequired
78
+     * @PublicPage
79
+     * @since 7.0.0
80
+     */
81
+    public function preflightedCors() {
82
+        if(isset($this->request->server['HTTP_ORIGIN'])) {
83
+            $origin = $this->request->server['HTTP_ORIGIN'];
84
+        } else {
85
+            $origin = '*';
86
+        }
87 87
 
88
-		$response = new Response();
89
-		$response->addHeader('Access-Control-Allow-Origin', $origin);
90
-		$response->addHeader('Access-Control-Allow-Methods', $this->corsMethods);
91
-		$response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge);
92
-		$response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders);
93
-		$response->addHeader('Access-Control-Allow-Credentials', 'false');
94
-		return $response;
95
-	}
88
+        $response = new Response();
89
+        $response->addHeader('Access-Control-Allow-Origin', $origin);
90
+        $response->addHeader('Access-Control-Allow-Methods', $this->corsMethods);
91
+        $response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge);
92
+        $response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders);
93
+        $response->addHeader('Access-Control-Allow-Credentials', 'false');
94
+        return $response;
95
+    }
96 96
 
97 97
 
98 98
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function __construct($appName,
61 61
 								IRequest $request,
62
-								$corsMethods='PUT, POST, GET, DELETE, PATCH',
63
-								$corsAllowedHeaders='Authorization, Content-Type, Accept',
64
-								$corsMaxAge=1728000) {
62
+								$corsMethods = 'PUT, POST, GET, DELETE, PATCH',
63
+								$corsAllowedHeaders = 'Authorization, Content-Type, Accept',
64
+								$corsMaxAge = 1728000) {
65 65
 		parent::__construct($appName, $request);
66 66
 		$this->corsMethods = $corsMethods;
67 67
 		$this->corsAllowedHeaders = $corsAllowedHeaders;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @since 7.0.0
80 80
 	 */
81 81
 	public function preflightedCors() {
82
-		if(isset($this->request->server['HTTP_ORIGIN'])) {
82
+		if (isset($this->request->server['HTTP_ORIGIN'])) {
83 83
 			$origin = $this->request->server['HTTP_ORIGIN'];
84 84
 		} else {
85 85
 			$origin = '*';
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		$response = new Response();
89 89
 		$response->addHeader('Access-Control-Allow-Origin', $origin);
90 90
 		$response->addHeader('Access-Control-Allow-Methods', $this->corsMethods);
91
-		$response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge);
91
+		$response->addHeader('Access-Control-Max-Age', (string) $this->corsMaxAge);
92 92
 		$response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders);
93 93
 		$response->addHeader('Access-Control-Allow-Credentials', 'false');
94 94
 		return $response;
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DataResponse.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -39,50 +39,50 @@
 block discarded – undo
39 39
  */
40 40
 class DataResponse extends Response {
41 41
 
42
-	/**
43
-	 * response data
44
-	 * @var array|object
45
-	 */
46
-	protected $data;
42
+    /**
43
+     * response data
44
+     * @var array|object
45
+     */
46
+    protected $data;
47 47
 
48 48
 
49
-	/**
50
-	 * @param array|object $data the object or array that should be transformed
51
-	 * @param int $statusCode the Http status code, defaults to 200
52
-	 * @param array $headers additional key value based headers
53
-	 * @since 8.0.0
54
-	 */
55
-	public function __construct($data=[], $statusCode=Http::STATUS_OK,
56
-								array $headers=[]) {
57
-		parent::__construct();
49
+    /**
50
+     * @param array|object $data the object or array that should be transformed
51
+     * @param int $statusCode the Http status code, defaults to 200
52
+     * @param array $headers additional key value based headers
53
+     * @since 8.0.0
54
+     */
55
+    public function __construct($data=[], $statusCode=Http::STATUS_OK,
56
+                                array $headers=[]) {
57
+        parent::__construct();
58 58
 
59
-		$this->data = $data;
60
-		$this->setStatus($statusCode);
61
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
62
-	}
59
+        $this->data = $data;
60
+        $this->setStatus($statusCode);
61
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
62
+    }
63 63
 
64 64
 
65
-	/**
66
-	 * Sets values in the data json array
67
-	 * @param array|object $data an array or object which will be transformed
68
-	 * @return DataResponse Reference to this object
69
-	 * @since 8.0.0
70
-	 */
71
-	public function setData($data) {
72
-		$this->data = $data;
65
+    /**
66
+     * Sets values in the data json array
67
+     * @param array|object $data an array or object which will be transformed
68
+     * @return DataResponse Reference to this object
69
+     * @since 8.0.0
70
+     */
71
+    public function setData($data) {
72
+        $this->data = $data;
73 73
 
74
-		return $this;
75
-	}
74
+        return $this;
75
+    }
76 76
 
77 77
 
78
-	/**
79
-	 * Used to get the set parameters
80
-	 * @return array the data
81
-	 * @since 8.0.0
82
-	 */
83
-	public function getData() {
84
-		return $this->data;
85
-	}
78
+    /**
79
+     * Used to get the set parameters
80
+     * @return array the data
81
+     * @since 8.0.0
82
+     */
83
+    public function getData() {
84
+        return $this->data;
85
+    }
86 86
 
87 87
 
88 88
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@
 block discarded – undo
52 52
 	 * @param array $headers additional key value based headers
53 53
 	 * @since 8.0.0
54 54
 	 */
55
-	public function __construct($data=[], $statusCode=Http::STATUS_OK,
56
-								array $headers=[]) {
55
+	public function __construct($data = [], $statusCode = Http::STATUS_OK,
56
+								array $headers = []) {
57 57
 		parent::__construct();
58 58
 
59 59
 		$this->data = $data;
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/StreamResponse.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -35,35 +35,35 @@
 block discarded – undo
35 35
  * @since 8.1.0
36 36
  */
37 37
 class StreamResponse extends Response implements ICallbackResponse {
38
-	/** @var string */
39
-	private $filePath;
38
+    /** @var string */
39
+    private $filePath;
40 40
 
41
-	/**
42
-	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
43
-	 * @since 8.1.0
44
-	 */
45
-	public function __construct($filePath) {
46
-		parent::__construct();
41
+    /**
42
+     * @param string|resource $filePath the path to the file or a file handle which should be streamed
43
+     * @since 8.1.0
44
+     */
45
+    public function __construct($filePath) {
46
+        parent::__construct();
47 47
 
48
-		$this->filePath = $filePath;
49
-	}
48
+        $this->filePath = $filePath;
49
+    }
50 50
 
51 51
 
52
-	/**
53
-	 * Streams the file using readfile
54
-	 *
55
-	 * @param IOutput $output a small wrapper that handles output
56
-	 * @since 8.1.0
57
-	 */
58
-	public function callback(IOutput $output) {
59
-		// handle caching
60
-		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
61
-			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
62
-				$output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
63
-			} elseif ($output->setReadfile($this->filePath) === false) {
64
-				$output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
65
-			}
66
-		}
67
-	}
52
+    /**
53
+     * Streams the file using readfile
54
+     *
55
+     * @param IOutput $output a small wrapper that handles output
56
+     * @since 8.1.0
57
+     */
58
+    public function callback(IOutput $output) {
59
+        // handle caching
60
+        if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
61
+            if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
62
+                $output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
63
+            } elseif ($output->setReadfile($this->filePath) === false) {
64
+                $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
65
+            }
66
+        }
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DataDisplayResponse.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -34,59 +34,59 @@
 block discarded – undo
34 34
  */
35 35
 class DataDisplayResponse extends Response {
36 36
 
37
-	/**
38
-	 * response data
39
-	 * @var string
40
-	 */
41
-	protected $data;
37
+    /**
38
+     * response data
39
+     * @var string
40
+     */
41
+    protected $data;
42 42
 
43 43
 
44
-	/**
45
-	 * @param string $data the data to display
46
-	 * @param int $statusCode the Http status code, defaults to 200
47
-	 * @param array $headers additional key value based headers
48
-	 * @since 8.1.0
49
-	 */
50
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
51
-								$headers=[]) {
52
-		parent::__construct();
44
+    /**
45
+     * @param string $data the data to display
46
+     * @param int $statusCode the Http status code, defaults to 200
47
+     * @param array $headers additional key value based headers
48
+     * @since 8.1.0
49
+     */
50
+    public function __construct($data='', $statusCode=Http::STATUS_OK,
51
+                                $headers=[]) {
52
+        parent::__construct();
53 53
 
54
-		$this->data = $data;
55
-		$this->setStatus($statusCode);
56
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
57
-		$this->addHeader('Content-Disposition', 'inline; filename=""');
58
-	}
54
+        $this->data = $data;
55
+        $this->setStatus($statusCode);
56
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
57
+        $this->addHeader('Content-Disposition', 'inline; filename=""');
58
+    }
59 59
 
60
-	/**
61
-	 * Outputs data. No processing is done.
62
-	 * @return string
63
-	 * @since 8.1.0
64
-	 */
65
-	public function render() {
66
-		return $this->data;
67
-	}
60
+    /**
61
+     * Outputs data. No processing is done.
62
+     * @return string
63
+     * @since 8.1.0
64
+     */
65
+    public function render() {
66
+        return $this->data;
67
+    }
68 68
 
69 69
 
70
-	/**
71
-	 * Sets values in the data
72
-	 * @param string $data the data to display
73
-	 * @return DataDisplayResponse Reference to this object
74
-	 * @since 8.1.0
75
-	 */
76
-	public function setData($data) {
77
-		$this->data = $data;
70
+    /**
71
+     * Sets values in the data
72
+     * @param string $data the data to display
73
+     * @return DataDisplayResponse Reference to this object
74
+     * @since 8.1.0
75
+     */
76
+    public function setData($data) {
77
+        $this->data = $data;
78 78
 
79
-		return $this;
80
-	}
79
+        return $this;
80
+    }
81 81
 
82 82
 
83
-	/**
84
-	 * Used to get the set parameters
85
-	 * @return string the data
86
-	 * @since 8.1.0
87
-	 */
88
-	public function getData() {
89
-		return $this->data;
90
-	}
83
+    /**
84
+     * Used to get the set parameters
85
+     * @return string the data
86
+     * @since 8.1.0
87
+     */
88
+    public function getData() {
89
+        return $this->data;
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@
 block discarded – undo
47 47
 	 * @param array $headers additional key value based headers
48 48
 	 * @since 8.1.0
49 49
 	 */
50
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
51
-								$headers=[]) {
50
+	public function __construct($data = '', $statusCode = Http::STATUS_OK,
51
+								$headers = []) {
52 52
 		parent::__construct();
53 53
 
54 54
 		$this->data = $data;
Please login to merge, or discard this patch.