Passed
Push — master ( d23e96...1bc100 )
by Roeland
11:25 queued 10s
created
lib/public/Collaboration/Collaborators/ISearchResult.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -30,44 +30,44 @@
 block discarded – undo
30 30
  * @since 13.0.0
31 31
  */
32 32
 interface ISearchResult {
33
-	/**
34
-	 * @param SearchResultType $type
35
-	 * @param array $matches
36
-	 * @param array|null $exactMatches
37
-	 * @since 13.0.0
38
-	 */
39
-	public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null);
33
+    /**
34
+     * @param SearchResultType $type
35
+     * @param array $matches
36
+     * @param array|null $exactMatches
37
+     * @since 13.0.0
38
+     */
39
+    public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null);
40 40
 
41
-	/**
42
-	 * @param SearchResultType $type
43
-	 * @param string $collaboratorId
44
-	 * @return bool
45
-	 * @since 13.0.0
46
-	 */
47
-	public function hasResult(SearchResultType $type, $collaboratorId);
41
+    /**
42
+     * @param SearchResultType $type
43
+     * @param string $collaboratorId
44
+     * @return bool
45
+     * @since 13.0.0
46
+     */
47
+    public function hasResult(SearchResultType $type, $collaboratorId);
48 48
 
49
-	/**
50
-	 * @param SearchResultType $type
51
-	 * @since 13.0.0
52
-	 */
53
-	public function unsetResult(SearchResultType $type);
49
+    /**
50
+     * @param SearchResultType $type
51
+     * @since 13.0.0
52
+     */
53
+    public function unsetResult(SearchResultType $type);
54 54
 
55
-	/**
56
-	 * @param SearchResultType $type
57
-	 * @since 13.0.0
58
-	 */
59
-	public function markExactIdMatch(SearchResultType $type);
55
+    /**
56
+     * @param SearchResultType $type
57
+     * @since 13.0.0
58
+     */
59
+    public function markExactIdMatch(SearchResultType $type);
60 60
 
61
-	/**
62
-	 * @param SearchResultType $type
63
-	 * @return bool
64
-	 * @since 13.0.0
65
-	 */
66
-	public function hasExactIdMatch(SearchResultType $type);
61
+    /**
62
+     * @param SearchResultType $type
63
+     * @return bool
64
+     * @since 13.0.0
65
+     */
66
+    public function hasExactIdMatch(SearchResultType $type);
67 67
 
68
-	/**
69
-	 * @return array
70
-	 * @since 13.0.0
71
-	 */
72
-	public function asArray();
68
+    /**
69
+     * @return array
70
+     * @since 13.0.0
71
+     */
72
+    public function asArray();
73 73
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/Search.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		$searchResult = $this->c->resolve(SearchResult::class);
48 48
 
49 49
 		foreach ($shareTypes as $type) {
50
-			if(!isset($this->pluginList[$type])) {
50
+			if (!isset($this->pluginList[$type])) {
51 51
 				continue;
52 52
 			}
53 53
 			foreach ($this->pluginList[$type] as $plugin) {
@@ -70,18 +70,18 @@  discard block
 block discarded – undo
70 70
 		// that the exact same email address and federated cloud id exists
71 71
 		$emailType = new SearchResultType('emails');
72 72
 		$remoteType = new SearchResultType('remotes');
73
-		if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) {
73
+		if ($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) {
74 74
 			$searchResult->unsetResult($remoteType);
75 75
 		} elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) {
76 76
 			$searchResult->unsetResult($emailType);
77 77
 		}
78 78
 
79
-		return [$searchResult->asArray(), (bool)$hasMoreResults];
79
+		return [$searchResult->asArray(), (bool) $hasMoreResults];
80 80
 	}
81 81
 
82 82
 	public function registerPlugin(array $pluginInfo) {
83
-		$shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
84
-		if($shareType === null) {
83
+		$shareType = constant(Share::class.'::'.$pluginInfo['shareType']);
84
+		if ($shareType === null) {
85 85
 			throw new \InvalidArgumentException('Provided ShareType is invalid');
86 86
 		}
87 87
 		$this->pluginList[$shareType][] = $pluginInfo['class'];
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -31,68 +31,68 @@
 block discarded – undo
31 31
 use OCP\Share;
32 32
 
33 33
 class Search implements ISearch {
34
-	/** @var IContainer */
35
-	private $c;
34
+    /** @var IContainer */
35
+    private $c;
36 36
 
37
-	protected $pluginList = [];
37
+    protected $pluginList = [];
38 38
 
39
-	public function __construct(IContainer $c) {
40
-		$this->c = $c;
41
-	}
39
+    public function __construct(IContainer $c) {
40
+        $this->c = $c;
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $search
45
-	 * @param array $shareTypes
46
-	 * @param bool $lookup
47
-	 * @param int|null $limit
48
-	 * @param int|null $offset
49
-	 * @return array
50
-	 * @throws \OCP\AppFramework\QueryException
51
-	 */
52
-	public function search($search, array $shareTypes, $lookup, $limit, $offset) {
53
-		$hasMoreResults = false;
43
+    /**
44
+     * @param string $search
45
+     * @param array $shareTypes
46
+     * @param bool $lookup
47
+     * @param int|null $limit
48
+     * @param int|null $offset
49
+     * @return array
50
+     * @throws \OCP\AppFramework\QueryException
51
+     */
52
+    public function search($search, array $shareTypes, $lookup, $limit, $offset) {
53
+        $hasMoreResults = false;
54 54
 
55
-		/** @var ISearchResult $searchResult */
56
-		$searchResult = $this->c->resolve(SearchResult::class);
55
+        /** @var ISearchResult $searchResult */
56
+        $searchResult = $this->c->resolve(SearchResult::class);
57 57
 
58
-		foreach ($shareTypes as $type) {
59
-			if(!isset($this->pluginList[$type])) {
60
-				continue;
61
-			}
62
-			foreach ($this->pluginList[$type] as $plugin) {
63
-				/** @var ISearchPlugin $searchPlugin */
64
-				$searchPlugin = $this->c->resolve($plugin);
65
-				$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
66
-			}
67
-		}
58
+        foreach ($shareTypes as $type) {
59
+            if(!isset($this->pluginList[$type])) {
60
+                continue;
61
+            }
62
+            foreach ($this->pluginList[$type] as $plugin) {
63
+                /** @var ISearchPlugin $searchPlugin */
64
+                $searchPlugin = $this->c->resolve($plugin);
65
+                $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
66
+            }
67
+        }
68 68
 
69
-		// Get from lookup server, not a separate share type
70
-		if ($lookup) {
71
-			$searchPlugin = $this->c->resolve(LookupPlugin::class);
72
-			$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
73
-		}
69
+        // Get from lookup server, not a separate share type
70
+        if ($lookup) {
71
+            $searchPlugin = $this->c->resolve(LookupPlugin::class);
72
+            $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
73
+        }
74 74
 
75
-		// sanitizing, could go into the plugins as well
75
+        // sanitizing, could go into the plugins as well
76 76
 
77
-		// if we have a exact match, either for the federated cloud id or for the
78
-		// email address we only return the exact match. It is highly unlikely
79
-		// that the exact same email address and federated cloud id exists
80
-		$emailType = new SearchResultType('emails');
81
-		$remoteType = new SearchResultType('remotes');
82
-		if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) {
83
-			$searchResult->unsetResult($remoteType);
84
-		} elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) {
85
-			$searchResult->unsetResult($emailType);
86
-		}
77
+        // if we have a exact match, either for the federated cloud id or for the
78
+        // email address we only return the exact match. It is highly unlikely
79
+        // that the exact same email address and federated cloud id exists
80
+        $emailType = new SearchResultType('emails');
81
+        $remoteType = new SearchResultType('remotes');
82
+        if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) {
83
+            $searchResult->unsetResult($remoteType);
84
+        } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) {
85
+            $searchResult->unsetResult($emailType);
86
+        }
87 87
 
88
-		return [$searchResult->asArray(), (bool)$hasMoreResults];
89
-	}
88
+        return [$searchResult->asArray(), (bool)$hasMoreResults];
89
+    }
90 90
 
91
-	public function registerPlugin(array $pluginInfo) {
92
-		$shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
93
-		if($shareType === null) {
94
-			throw new \InvalidArgumentException('Provided ShareType is invalid');
95
-		}
96
-		$this->pluginList[$shareType][] = $pluginInfo['class'];
97
-	}
91
+    public function registerPlugin(array $pluginInfo) {
92
+        $shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
93
+        if($shareType === null) {
94
+            throw new \InvalidArgumentException('Provided ShareType is invalid');
95
+        }
96
+        $this->pluginList[$shareType][] = $pluginInfo['class'];
97
+    }
98 98
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Events/MoveToTrashEvent.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -35,39 +35,39 @@
 block discarded – undo
35 35
  */
36 36
 class MoveToTrashEvent extends Event {
37 37
 
38
-	/** @var bool */
39
-	private $moveToTrashBin;
38
+    /** @var bool */
39
+    private $moveToTrashBin;
40 40
 
41
-	/** @var Node */
42
-	private $node;
41
+    /** @var Node */
42
+    private $node;
43 43
 
44
-	public function __construct(Node $node) {
45
-		$this->moveToTrashBin = true;
46
-		$this->node = $node;
47
-	}
44
+    public function __construct(Node $node) {
45
+        $this->moveToTrashBin = true;
46
+        $this->node = $node;
47
+    }
48 48
 
49
-	/**
50
-	 * get Node which will be deleted
51
-	 *
52
-	 * @return Node
53
-	 */
54
-	public function getNode() {
55
-		return $this->node;
56
-	}
49
+    /**
50
+     * get Node which will be deleted
51
+     *
52
+     * @return Node
53
+     */
54
+    public function getNode() {
55
+        return $this->node;
56
+    }
57 57
 
58
-	/**
59
-	 * disable trash bin for this operation
60
-	 */
61
-	public function disableTrashBin() {
62
-		$this->moveToTrashBin = false;
63
-	}
58
+    /**
59
+     * disable trash bin for this operation
60
+     */
61
+    public function disableTrashBin() {
62
+        $this->moveToTrashBin = false;
63
+    }
64 64
 
65
-	/**
66
-	 * should the file be moved to the trash bin?
67
-	 *
68
-	 * @return bool
69
-	 */
70
-	public function shouldMoveToTrashBin() {
71
-		return $this->moveToTrashBin;
72
-	}
65
+    /**
66
+     * should the file be moved to the trash bin?
67
+     *
68
+     * @return bool
69
+     */
70
+    public function shouldMoveToTrashBin() {
71
+        return $this->moveToTrashBin;
72
+    }
73 73
 }
Please login to merge, or discard this patch.
apps/files_versions/lib/Events/CreateVersionEvent.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -37,45 +37,45 @@
 block discarded – undo
37 37
 class CreateVersionEvent extends Event {
38 38
 
39 39
 
40
-	/** @var bool */
41
-	private $createVersion;
40
+    /** @var bool */
41
+    private $createVersion;
42 42
 
43
-	/** @var Node */
44
-	private $node;
43
+    /** @var Node */
44
+    private $node;
45 45
 
46
-	/**
47
-	 * CreateVersionEvent constructor.
48
-	 *
49
-	 * @param Node $node
50
-	 */
51
-	public function __construct(Node $node) {
52
-		$this->createVersion = true;
53
-		$this->node = $node;
54
-	}
46
+    /**
47
+     * CreateVersionEvent constructor.
48
+     *
49
+     * @param Node $node
50
+     */
51
+    public function __construct(Node $node) {
52
+        $this->createVersion = true;
53
+        $this->node = $node;
54
+    }
55 55
 
56
-	/**
57
-	 * get Node of the file which should be versioned
58
-	 *
59
-	 * @return Node
60
-	 */
61
-	public function getNode() {
62
-		return $this->node;
63
-	}
56
+    /**
57
+     * get Node of the file which should be versioned
58
+     *
59
+     * @return Node
60
+     */
61
+    public function getNode() {
62
+        return $this->node;
63
+    }
64 64
 
65
-	/**
66
-	 * disable versions for this file
67
-	 */
68
-	public function disableVersions() {
69
-		$this->createVersion = false;
70
-	}
65
+    /**
66
+     * disable versions for this file
67
+     */
68
+    public function disableVersions() {
69
+        $this->createVersion = false;
70
+    }
71 71
 
72
-	/**
73
-	 * should a version be created for this file?
74
-	 *
75
-	 * @return bool
76
-	 */
77
-	public function shouldCreateVersion() {
78
-		return $this->createVersion;
79
-	}
72
+    /**
73
+     * should a version be created for this file?
74
+     *
75
+     * @return bool
76
+     */
77
+    public function shouldCreateVersion() {
78
+        return $this->createVersion;
79
+    }
80 80
 
81 81
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ContactsStore.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		if ($excludedGroups) {
118 118
 			$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
119 119
 			$decodedExcludeGroups = json_decode($excludedGroups, true);
120
-			$excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
120
+			$excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : [];
121 121
 
122 122
 			if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
123 123
 				// a group of the current user is excluded -> filter all local users
@@ -133,22 +133,22 @@  discard block
 block discarded – undo
133 133
 			}
134 134
 
135 135
 			// Prevent enumerating local users
136
-			if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
136
+			if ($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
137 137
 				$filterUser = true;
138 138
 
139 139
 				$mailAddresses = $entry->getEMailAddresses();
140
-				foreach($mailAddresses as $mailAddress) {
141
-					if($mailAddress === $filter) {
140
+				foreach ($mailAddresses as $mailAddress) {
141
+					if ($mailAddress === $filter) {
142 142
 						$filterUser = false;
143 143
 						break;
144 144
 					}
145 145
 				}
146 146
 
147
-				if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
147
+				if ($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
148 148
 					$filterUser = false;
149 149
 				}
150 150
 
151
-				if($filterUser) {
151
+				if ($filterUser) {
152 152
 					return false;
153 153
 				}
154 154
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @return IEntry|null
173 173
 	 */
174 174
 	public function findOne(IUser $user, $shareType, $shareWith) {
175
-		switch($shareType) {
175
+		switch ($shareType) {
176 176
 			case 0:
177 177
 			case 6:
178 178
 				$filter = ['UID'];
Please login to merge, or discard this patch.
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -37,227 +37,227 @@
 block discarded – undo
37 37
 
38 38
 class ContactsStore implements IContactsStore {
39 39
 
40
-	/** @var IManager */
41
-	private $contactsManager;
42
-
43
-	/** @var IConfig */
44
-	private $config;
45
-
46
-	/** @var IUserManager */
47
-	private $userManager;
48
-
49
-	/** @var IGroupManager */
50
-	private $groupManager;
51
-
52
-	/**
53
-	 * @param IManager $contactsManager
54
-	 * @param IConfig $config
55
-	 * @param IUserManager $userManager
56
-	 * @param IGroupManager $groupManager
57
-	 */
58
-	public function __construct(IManager $contactsManager,
59
-								IConfig $config,
60
-								IUserManager $userManager,
61
-								IGroupManager $groupManager) {
62
-		$this->contactsManager = $contactsManager;
63
-		$this->config = $config;
64
-		$this->userManager = $userManager;
65
-		$this->groupManager = $groupManager;
66
-	}
67
-
68
-	/**
69
-	 * @param IUser $user
70
-	 * @param string|null $filter
71
-	 * @return IEntry[]
72
-	 */
73
-	public function getContacts(IUser $user, $filter) {
74
-		$allContacts = $this->contactsManager->search($filter ?: '', [
75
-			'FN',
76
-			'EMAIL'
77
-		]);
78
-
79
-		$entries = array_map(function(array $contact) {
80
-			return $this->contactArrayToEntry($contact);
81
-		}, $allContacts);
82
-		return $this->filterContacts(
83
-			$user,
84
-			$entries,
85
-			$filter
86
-		);
87
-	}
88
-
89
-	/**
90
-	 * Filters the contacts. Applies 3 filters:
91
-	 *  1. filter the current user
92
-	 *  2. if the `shareapi_allow_share_dialog_user_enumeration` config option is
93
-	 * enabled it will filter all local users
94
-	 *  3. if the `shareapi_exclude_groups` config option is enabled and the
95
-	 * current user is in an excluded group it will filter all local users.
96
-	 *  4. if the `shareapi_only_share_with_group_members` config option is
97
-	 * enabled it will filter all users which doens't have a common group
98
-	 * with the current user.
99
-	 *
100
-	 * @param IUser $self
101
-	 * @param Entry[] $entries
102
-	 * @param string $filter
103
-	 * @return Entry[] the filtered contacts
104
-	 */
105
-	private function filterContacts(IUser $self,
106
-									array $entries,
107
-									$filter) {
108
-		$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
109
-		$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes';
110
-
111
-		// whether to filter out local users
112
-		$skipLocal = false;
113
-		// whether to filter out all users which doesn't have the same group as the current user
114
-		$ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
115
-
116
-		$selfGroups = $this->groupManager->getUserGroupIds($self);
117
-
118
-		if ($excludedGroups) {
119
-			$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
120
-			$decodedExcludeGroups = json_decode($excludedGroups, true);
121
-			$excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
122
-
123
-			if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
124
-				// a group of the current user is excluded -> filter all local users
125
-				$skipLocal = true;
126
-			}
127
-		}
128
-
129
-		$selfUID = $self->getUID();
130
-
131
-		return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) {
132
-			if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) {
133
-				return false;
134
-			}
135
-
136
-			// Prevent enumerating local users
137
-			if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
138
-				$filterUser = true;
139
-
140
-				$mailAddresses = $entry->getEMailAddresses();
141
-				foreach($mailAddresses as $mailAddress) {
142
-					if($mailAddress === $filter) {
143
-						$filterUser = false;
144
-						break;
145
-					}
146
-				}
147
-
148
-				if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
149
-					$filterUser = false;
150
-				}
151
-
152
-				if($filterUser) {
153
-					return false;
154
-				}
155
-			}
156
-
157
-			if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) {
158
-				$uid = $this->userManager->get($entry->getProperty('UID'));
159
-
160
-				if ($uid === NULL) {
161
-					return false;
162
-				}
163
-
164
-				$contactGroups = $this->groupManager->getUserGroupIds($uid);
165
-				if (count(array_intersect($contactGroups, $selfGroups)) === 0) {
166
-					// no groups in common, so shouldn't see the contact
167
-					return false;
168
-				}
169
-			}
170
-
171
-			return $entry->getProperty('UID') !== $selfUID;
172
-		}));
173
-	}
174
-
175
-	/**
176
-	 * @param IUser $user
177
-	 * @param integer $shareType
178
-	 * @param string $shareWith
179
-	 * @return IEntry|null
180
-	 */
181
-	public function findOne(IUser $user, $shareType, $shareWith) {
182
-		switch($shareType) {
183
-			case 0:
184
-			case 6:
185
-				$filter = ['UID'];
186
-				break;
187
-			case 4:
188
-				$filter = ['EMAIL'];
189
-				break;
190
-			default:
191
-				return null;
192
-		}
193
-
194
-		$userId = $user->getUID();
195
-		$allContacts = $this->contactsManager->search($shareWith, $filter);
196
-		$contacts = array_filter($allContacts, function($contact) use ($userId) {
197
-			return $contact['UID'] !== $userId;
198
-		});
199
-		$match = null;
200
-
201
-		foreach ($contacts as $contact) {
202
-			if ($shareType === 4 && isset($contact['EMAIL'])) {
203
-				if (in_array($shareWith, $contact['EMAIL'])) {
204
-					$match = $contact;
205
-					break;
206
-				}
207
-			}
208
-			if ($shareType === 0 || $shareType === 6) {
209
-				$isLocal = $contact['isLocalSystemBook'] ?? false;
210
-				if ($contact['UID'] === $shareWith && $isLocal === true) {
211
-					$match = $contact;
212
-					break;
213
-				}
214
-			}
215
-		}
216
-
217
-		if ($match) {
218
-			$match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith);
219
-			if (count($match) === 1) {
220
-				$match = $match[0];
221
-			} else {
222
-				$match = null;
223
-			}
224
-
225
-		}
226
-
227
-		return $match;
228
-	}
229
-
230
-	/**
231
-	 * @param array $contact
232
-	 * @return Entry
233
-	 */
234
-	private function contactArrayToEntry(array $contact) {
235
-		$entry = new Entry();
236
-
237
-		if (isset($contact['id'])) {
238
-			$entry->setId($contact['id']);
239
-		}
240
-
241
-		if (isset($contact['FN'])) {
242
-			$entry->setFullName($contact['FN']);
243
-		}
244
-
245
-		$avatarPrefix = "VALUE=uri:";
246
-		if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
247
-			$entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
248
-		}
249
-
250
-		if (isset($contact['EMAIL'])) {
251
-			foreach ($contact['EMAIL'] as $email) {
252
-				$entry->addEMailAddress($email);
253
-			}
254
-		}
255
-
256
-		// Attach all other properties to the entry too because some
257
-		// providers might make use of it.
258
-		$entry->setProperties($contact);
259
-
260
-		return $entry;
261
-	}
40
+    /** @var IManager */
41
+    private $contactsManager;
42
+
43
+    /** @var IConfig */
44
+    private $config;
45
+
46
+    /** @var IUserManager */
47
+    private $userManager;
48
+
49
+    /** @var IGroupManager */
50
+    private $groupManager;
51
+
52
+    /**
53
+     * @param IManager $contactsManager
54
+     * @param IConfig $config
55
+     * @param IUserManager $userManager
56
+     * @param IGroupManager $groupManager
57
+     */
58
+    public function __construct(IManager $contactsManager,
59
+                                IConfig $config,
60
+                                IUserManager $userManager,
61
+                                IGroupManager $groupManager) {
62
+        $this->contactsManager = $contactsManager;
63
+        $this->config = $config;
64
+        $this->userManager = $userManager;
65
+        $this->groupManager = $groupManager;
66
+    }
67
+
68
+    /**
69
+     * @param IUser $user
70
+     * @param string|null $filter
71
+     * @return IEntry[]
72
+     */
73
+    public function getContacts(IUser $user, $filter) {
74
+        $allContacts = $this->contactsManager->search($filter ?: '', [
75
+            'FN',
76
+            'EMAIL'
77
+        ]);
78
+
79
+        $entries = array_map(function(array $contact) {
80
+            return $this->contactArrayToEntry($contact);
81
+        }, $allContacts);
82
+        return $this->filterContacts(
83
+            $user,
84
+            $entries,
85
+            $filter
86
+        );
87
+    }
88
+
89
+    /**
90
+     * Filters the contacts. Applies 3 filters:
91
+     *  1. filter the current user
92
+     *  2. if the `shareapi_allow_share_dialog_user_enumeration` config option is
93
+     * enabled it will filter all local users
94
+     *  3. if the `shareapi_exclude_groups` config option is enabled and the
95
+     * current user is in an excluded group it will filter all local users.
96
+     *  4. if the `shareapi_only_share_with_group_members` config option is
97
+     * enabled it will filter all users which doens't have a common group
98
+     * with the current user.
99
+     *
100
+     * @param IUser $self
101
+     * @param Entry[] $entries
102
+     * @param string $filter
103
+     * @return Entry[] the filtered contacts
104
+     */
105
+    private function filterContacts(IUser $self,
106
+                                    array $entries,
107
+                                    $filter) {
108
+        $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
109
+        $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes';
110
+
111
+        // whether to filter out local users
112
+        $skipLocal = false;
113
+        // whether to filter out all users which doesn't have the same group as the current user
114
+        $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
115
+
116
+        $selfGroups = $this->groupManager->getUserGroupIds($self);
117
+
118
+        if ($excludedGroups) {
119
+            $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
120
+            $decodedExcludeGroups = json_decode($excludedGroups, true);
121
+            $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
122
+
123
+            if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
124
+                // a group of the current user is excluded -> filter all local users
125
+                $skipLocal = true;
126
+            }
127
+        }
128
+
129
+        $selfUID = $self->getUID();
130
+
131
+        return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) {
132
+            if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) {
133
+                return false;
134
+            }
135
+
136
+            // Prevent enumerating local users
137
+            if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) {
138
+                $filterUser = true;
139
+
140
+                $mailAddresses = $entry->getEMailAddresses();
141
+                foreach($mailAddresses as $mailAddress) {
142
+                    if($mailAddress === $filter) {
143
+                        $filterUser = false;
144
+                        break;
145
+                    }
146
+                }
147
+
148
+                if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
149
+                    $filterUser = false;
150
+                }
151
+
152
+                if($filterUser) {
153
+                    return false;
154
+                }
155
+            }
156
+
157
+            if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) {
158
+                $uid = $this->userManager->get($entry->getProperty('UID'));
159
+
160
+                if ($uid === NULL) {
161
+                    return false;
162
+                }
163
+
164
+                $contactGroups = $this->groupManager->getUserGroupIds($uid);
165
+                if (count(array_intersect($contactGroups, $selfGroups)) === 0) {
166
+                    // no groups in common, so shouldn't see the contact
167
+                    return false;
168
+                }
169
+            }
170
+
171
+            return $entry->getProperty('UID') !== $selfUID;
172
+        }));
173
+    }
174
+
175
+    /**
176
+     * @param IUser $user
177
+     * @param integer $shareType
178
+     * @param string $shareWith
179
+     * @return IEntry|null
180
+     */
181
+    public function findOne(IUser $user, $shareType, $shareWith) {
182
+        switch($shareType) {
183
+            case 0:
184
+            case 6:
185
+                $filter = ['UID'];
186
+                break;
187
+            case 4:
188
+                $filter = ['EMAIL'];
189
+                break;
190
+            default:
191
+                return null;
192
+        }
193
+
194
+        $userId = $user->getUID();
195
+        $allContacts = $this->contactsManager->search($shareWith, $filter);
196
+        $contacts = array_filter($allContacts, function($contact) use ($userId) {
197
+            return $contact['UID'] !== $userId;
198
+        });
199
+        $match = null;
200
+
201
+        foreach ($contacts as $contact) {
202
+            if ($shareType === 4 && isset($contact['EMAIL'])) {
203
+                if (in_array($shareWith, $contact['EMAIL'])) {
204
+                    $match = $contact;
205
+                    break;
206
+                }
207
+            }
208
+            if ($shareType === 0 || $shareType === 6) {
209
+                $isLocal = $contact['isLocalSystemBook'] ?? false;
210
+                if ($contact['UID'] === $shareWith && $isLocal === true) {
211
+                    $match = $contact;
212
+                    break;
213
+                }
214
+            }
215
+        }
216
+
217
+        if ($match) {
218
+            $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith);
219
+            if (count($match) === 1) {
220
+                $match = $match[0];
221
+            } else {
222
+                $match = null;
223
+            }
224
+
225
+        }
226
+
227
+        return $match;
228
+    }
229
+
230
+    /**
231
+     * @param array $contact
232
+     * @return Entry
233
+     */
234
+    private function contactArrayToEntry(array $contact) {
235
+        $entry = new Entry();
236
+
237
+        if (isset($contact['id'])) {
238
+            $entry->setId($contact['id']);
239
+        }
240
+
241
+        if (isset($contact['FN'])) {
242
+            $entry->setFullName($contact['FN']);
243
+        }
244
+
245
+        $avatarPrefix = "VALUE=uri:";
246
+        if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
247
+            $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
248
+        }
249
+
250
+        if (isset($contact['EMAIL'])) {
251
+            foreach ($contact['EMAIL'] as $email) {
252
+                $entry->addEMailAddress($email);
253
+            }
254
+        }
255
+
256
+        // Attach all other properties to the entry too because some
257
+        // providers might make use of it.
258
+        $entry->setProperties($contact);
259
+
260
+        return $entry;
261
+    }
262 262
 
263 263
 }
Please login to merge, or discard this patch.
apps/theming/lib/IconBuilder.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
 			$icon->setImageFormat("png32");
64 64
 
65 65
 			$clone = clone $icon;
66
-			$clone->scaleImage(16,0);
66
+			$clone->scaleImage(16, 0);
67 67
 			$favicon->addImage($clone);
68 68
 
69 69
 			$clone = clone $icon;
70
-			$clone->scaleImage(32,0);
70
+			$clone->scaleImage(32, 0);
71 71
 			$favicon->addImage($clone);
72 72
 
73 73
 			$clone = clone $icon;
74
-			$clone->scaleImage(64,0);
74
+			$clone->scaleImage(64, 0);
75 75
 			$favicon->addImage($clone);
76 76
 
77 77
 			$clone = clone $icon;
78
-			$clone->scaleImage(128,0);
78
+			$clone->scaleImage(128, 0);
79 79
 			$favicon->addImage($clone);
80 80
 
81 81
 			$data = $favicon->getImagesBlob();
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function renderAppIcon($app, $size) {
119 119
 		$appIcon = $this->util->getAppIcon($app);
120
-		if($appIcon === false) {
120
+		if ($appIcon === false) {
121 121
 			return false;
122 122
 		}
123 123
 		if ($appIcon instanceof ISimpleFile) {
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
 			$mime = mime_content_type($appIcon);
129 129
 		}
130 130
 
131
-		if($appIconContent === false || $appIconContent === "") {
131
+		if ($appIconContent === false || $appIconContent === "") {
132 132
 			return false;
133 133
 		}
134 134
 
135 135
 		$color = $this->themingDefaults->getColorPrimary();
136 136
 
137 137
 		// generate background image with rounded corners
138
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
139
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
140
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
138
+		$background = '<?xml version="1.0" encoding="UTF-8"?>'.
139
+			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">'.
140
+			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:'.$color.';" />'.
141 141
 			'</svg>';
142 142
 		// resize svg magic as this seems broken in Imagemagick
143
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
144
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
143
+		if ($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
144
+			if (substr($appIconContent, 0, 5) !== "<?xml") {
145 145
 				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
146 146
 			} else {
147 147
 				$svg = $appIconContent;
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			$res = $tmp->getImageResolution();
154 154
 			$tmp->destroy();
155 155
 
156
-			if($x>$y) {
156
+			if ($x > $y) {
157 157
 				$max = $x;
158 158
 			} else {
159 159
 				$max = $y;
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 
162 162
 			// convert svg to resized image
163 163
 			$appIconFile = new Imagick();
164
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
165
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
164
+			$resX = (int) (512 * $res['x'] / $max * 2.53);
165
+			$resY = (int) (512 * $res['y'] / $max * 2.53);
166 166
 			$appIconFile->setResolution($resX, $resY);
167 167
 			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
168 168
 			$appIconFile->readImageBlob($svg);
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 			$appIconFile->scaleImage(512, 512, true);
186 186
 		}
187 187
 		// offset for icon positioning
188
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
189
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
190
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
191
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
188
+		$border_w = (int) ($appIconFile->getImageWidth() * 0.05);
189
+		$border_h = (int) ($appIconFile->getImageHeight() * 0.05);
190
+		$innerWidth = (int) ($appIconFile->getImageWidth() - $border_w * 2);
191
+		$innerHeight = (int) ($appIconFile->getImageHeight() - $border_h * 2);
192 192
 		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
193 193
 		// center icon
194 194
 		$offset_w = 512 / 2 - $innerWidth / 2;
Please login to merge, or discard this patch.
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -31,211 +31,211 @@
 block discarded – undo
31 31
 use OCP\Files\SimpleFS\ISimpleFile;
32 32
 
33 33
 class IconBuilder {
34
-	/** @var ThemingDefaults */
35
-	private $themingDefaults;
36
-	/** @var Util */
37
-	private $util;
38
-	/** @var ImageManager */
39
-	private $imageManager;
40
-
41
-	/**
42
-	 * IconBuilder constructor.
43
-	 *
44
-	 * @param ThemingDefaults $themingDefaults
45
-	 * @param Util $util
46
-	 * @param ImageManager $imageManager
47
-	 */
48
-	public function __construct(
49
-		ThemingDefaults $themingDefaults,
50
-		Util $util,
51
-		ImageManager $imageManager
52
-	) {
53
-		$this->themingDefaults = $themingDefaults;
54
-		$this->util = $util;
55
-		$this->imageManager = $imageManager;
56
-	}
57
-
58
-	/**
59
-	 * @param $app string app name
60
-	 * @return string|false image blob
61
-	 */
62
-	public function getFavicon($app) {
63
-		if (!$this->imageManager->shouldReplaceIcons()) {
64
-			return false;
65
-		}
66
-		try {
67
-			$favicon = new Imagick();
68
-			$favicon->setFormat("ico");
69
-			$icon = $this->renderAppIcon($app, 128);
70
-			if ($icon === false) {
71
-				return false;
72
-			}
73
-			$icon->setImageFormat("png32");
74
-
75
-			$clone = clone $icon;
76
-			$clone->scaleImage(16,0);
77
-			$favicon->addImage($clone);
78
-
79
-			$clone = clone $icon;
80
-			$clone->scaleImage(32,0);
81
-			$favicon->addImage($clone);
82
-
83
-			$clone = clone $icon;
84
-			$clone->scaleImage(64,0);
85
-			$favicon->addImage($clone);
86
-
87
-			$clone = clone $icon;
88
-			$clone->scaleImage(128,0);
89
-			$favicon->addImage($clone);
90
-
91
-			$data = $favicon->getImagesBlob();
92
-			$favicon->destroy();
93
-			$icon->destroy();
94
-			$clone->destroy();
95
-			return $data;
96
-		} catch (\ImagickException $e) {
97
-			return false;
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * @param $app string app name
103
-	 * @return string|false image blob
104
-	 */
105
-	public function getTouchIcon($app) {
106
-		try {
107
-			$icon = $this->renderAppIcon($app, 512);
108
-			if ($icon === false) {
109
-				return false;
110
-			}
111
-			$icon->setImageFormat("png32");
112
-			$data = $icon->getImageBlob();
113
-			$icon->destroy();
114
-			return $data;
115
-		} catch (\ImagickException $e) {
116
-			return false;
117
-		}
118
-	}
119
-
120
-	/**
121
-	 * Render app icon on themed background color
122
-	 * fallback to logo
123
-	 *
124
-	 * @param $app string app name
125
-	 * @param $size int size of the icon in px
126
-	 * @return Imagick|false
127
-	 */
128
-	public function renderAppIcon($app, $size) {
129
-		$appIcon = $this->util->getAppIcon($app);
130
-		if($appIcon === false) {
131
-			return false;
132
-		}
133
-		if ($appIcon instanceof ISimpleFile) {
134
-			$appIconContent = $appIcon->getContent();
135
-			$mime = $appIcon->getMimeType();
136
-		} else {
137
-			$appIconContent = file_get_contents($appIcon);
138
-			$mime = mime_content_type($appIcon);
139
-		}
140
-
141
-		if($appIconContent === false || $appIconContent === "") {
142
-			return false;
143
-		}
144
-
145
-		$color = $this->themingDefaults->getColorPrimary();
146
-
147
-		// generate background image with rounded corners
148
-		$background = '<?xml version="1.0" encoding="UTF-8"?>' .
149
-			'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
150
-			'<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
151
-			'</svg>';
152
-		// resize svg magic as this seems broken in Imagemagick
153
-		if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
154
-			if(substr($appIconContent, 0, 5) !== "<?xml") {
155
-				$svg = "<?xml version=\"1.0\"?>".$appIconContent;
156
-			} else {
157
-				$svg = $appIconContent;
158
-			}
159
-			$tmp = new Imagick();
160
-			$tmp->readImageBlob($svg);
161
-			$x = $tmp->getImageWidth();
162
-			$y = $tmp->getImageHeight();
163
-			$res = $tmp->getImageResolution();
164
-			$tmp->destroy();
165
-
166
-			if($x>$y) {
167
-				$max = $x;
168
-			} else {
169
-				$max = $y;
170
-			}
171
-
172
-			// convert svg to resized image
173
-			$appIconFile = new Imagick();
174
-			$resX = (int)(512 * $res['x'] / $max * 2.53);
175
-			$resY = (int)(512 * $res['y'] / $max * 2.53);
176
-			$appIconFile->setResolution($resX, $resY);
177
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
178
-			$appIconFile->readImageBlob($svg);
179
-
180
-			/**
181
-			 * invert app icons for bright primary colors
182
-			 * the default nextcloud logo will not be inverted to black
183
-			 */
184
-			if ($this->util->invertTextColor($color)
185
-				&& !$appIcon instanceof ISimpleFile
186
-				&& $app !== "core"
187
-			) {
188
-				$appIconFile->negateImage(false);
189
-			}
190
-			$appIconFile->scaleImage(512, 512, true);
191
-		} else {
192
-			$appIconFile = new Imagick();
193
-			$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
194
-			$appIconFile->readImageBlob($appIconContent);
195
-			$appIconFile->scaleImage(512, 512, true);
196
-		}
197
-		// offset for icon positioning
198
-		$border_w = (int)($appIconFile->getImageWidth() * 0.05);
199
-		$border_h = (int)($appIconFile->getImageHeight() * 0.05);
200
-		$innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
201
-		$innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
202
-		$appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
203
-		// center icon
204
-		$offset_w = 512 / 2 - $innerWidth / 2;
205
-		$offset_h = 512 / 2 - $innerHeight / 2;
206
-
207
-		$finalIconFile = new Imagick();
208
-		$finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
209
-		$finalIconFile->readImageBlob($background);
210
-		$finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
211
-		$finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
212
-		$finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
213
-		$finalIconFile->setImageFormat('png24');
214
-		if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
215
-			$filter = Imagick::INTERPOLATE_BICUBIC;
216
-		} else {
217
-			$filter = Imagick::FILTER_LANCZOS;
218
-		}
219
-		$finalIconFile->resizeImage($size, $size, $filter, 1, false);
220
-
221
-		$appIconFile->destroy();
222
-		return $finalIconFile;
223
-	}
224
-
225
-	public function colorSvg($app, $image) {
226
-		try {
227
-			$imageFile = $this->util->getAppImage($app, $image);
228
-		} catch (AppPathNotFoundException $e) {
229
-			return false;
230
-		}
231
-		$svg = file_get_contents($imageFile);
232
-		if ($svg !== false && $svg !== "") {
233
-			$color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
234
-			$svg = $this->util->colorizeSvg($svg, $color);
235
-			return $svg;
236
-		} else {
237
-			return false;
238
-		}
239
-	}
34
+    /** @var ThemingDefaults */
35
+    private $themingDefaults;
36
+    /** @var Util */
37
+    private $util;
38
+    /** @var ImageManager */
39
+    private $imageManager;
40
+
41
+    /**
42
+     * IconBuilder constructor.
43
+     *
44
+     * @param ThemingDefaults $themingDefaults
45
+     * @param Util $util
46
+     * @param ImageManager $imageManager
47
+     */
48
+    public function __construct(
49
+        ThemingDefaults $themingDefaults,
50
+        Util $util,
51
+        ImageManager $imageManager
52
+    ) {
53
+        $this->themingDefaults = $themingDefaults;
54
+        $this->util = $util;
55
+        $this->imageManager = $imageManager;
56
+    }
57
+
58
+    /**
59
+     * @param $app string app name
60
+     * @return string|false image blob
61
+     */
62
+    public function getFavicon($app) {
63
+        if (!$this->imageManager->shouldReplaceIcons()) {
64
+            return false;
65
+        }
66
+        try {
67
+            $favicon = new Imagick();
68
+            $favicon->setFormat("ico");
69
+            $icon = $this->renderAppIcon($app, 128);
70
+            if ($icon === false) {
71
+                return false;
72
+            }
73
+            $icon->setImageFormat("png32");
74
+
75
+            $clone = clone $icon;
76
+            $clone->scaleImage(16,0);
77
+            $favicon->addImage($clone);
78
+
79
+            $clone = clone $icon;
80
+            $clone->scaleImage(32,0);
81
+            $favicon->addImage($clone);
82
+
83
+            $clone = clone $icon;
84
+            $clone->scaleImage(64,0);
85
+            $favicon->addImage($clone);
86
+
87
+            $clone = clone $icon;
88
+            $clone->scaleImage(128,0);
89
+            $favicon->addImage($clone);
90
+
91
+            $data = $favicon->getImagesBlob();
92
+            $favicon->destroy();
93
+            $icon->destroy();
94
+            $clone->destroy();
95
+            return $data;
96
+        } catch (\ImagickException $e) {
97
+            return false;
98
+        }
99
+    }
100
+
101
+    /**
102
+     * @param $app string app name
103
+     * @return string|false image blob
104
+     */
105
+    public function getTouchIcon($app) {
106
+        try {
107
+            $icon = $this->renderAppIcon($app, 512);
108
+            if ($icon === false) {
109
+                return false;
110
+            }
111
+            $icon->setImageFormat("png32");
112
+            $data = $icon->getImageBlob();
113
+            $icon->destroy();
114
+            return $data;
115
+        } catch (\ImagickException $e) {
116
+            return false;
117
+        }
118
+    }
119
+
120
+    /**
121
+     * Render app icon on themed background color
122
+     * fallback to logo
123
+     *
124
+     * @param $app string app name
125
+     * @param $size int size of the icon in px
126
+     * @return Imagick|false
127
+     */
128
+    public function renderAppIcon($app, $size) {
129
+        $appIcon = $this->util->getAppIcon($app);
130
+        if($appIcon === false) {
131
+            return false;
132
+        }
133
+        if ($appIcon instanceof ISimpleFile) {
134
+            $appIconContent = $appIcon->getContent();
135
+            $mime = $appIcon->getMimeType();
136
+        } else {
137
+            $appIconContent = file_get_contents($appIcon);
138
+            $mime = mime_content_type($appIcon);
139
+        }
140
+
141
+        if($appIconContent === false || $appIconContent === "") {
142
+            return false;
143
+        }
144
+
145
+        $color = $this->themingDefaults->getColorPrimary();
146
+
147
+        // generate background image with rounded corners
148
+        $background = '<?xml version="1.0" encoding="UTF-8"?>' .
149
+            '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' .
150
+            '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' .
151
+            '</svg>';
152
+        // resize svg magic as this seems broken in Imagemagick
153
+        if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
154
+            if(substr($appIconContent, 0, 5) !== "<?xml") {
155
+                $svg = "<?xml version=\"1.0\"?>".$appIconContent;
156
+            } else {
157
+                $svg = $appIconContent;
158
+            }
159
+            $tmp = new Imagick();
160
+            $tmp->readImageBlob($svg);
161
+            $x = $tmp->getImageWidth();
162
+            $y = $tmp->getImageHeight();
163
+            $res = $tmp->getImageResolution();
164
+            $tmp->destroy();
165
+
166
+            if($x>$y) {
167
+                $max = $x;
168
+            } else {
169
+                $max = $y;
170
+            }
171
+
172
+            // convert svg to resized image
173
+            $appIconFile = new Imagick();
174
+            $resX = (int)(512 * $res['x'] / $max * 2.53);
175
+            $resY = (int)(512 * $res['y'] / $max * 2.53);
176
+            $appIconFile->setResolution($resX, $resY);
177
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
178
+            $appIconFile->readImageBlob($svg);
179
+
180
+            /**
181
+             * invert app icons for bright primary colors
182
+             * the default nextcloud logo will not be inverted to black
183
+             */
184
+            if ($this->util->invertTextColor($color)
185
+                && !$appIcon instanceof ISimpleFile
186
+                && $app !== "core"
187
+            ) {
188
+                $appIconFile->negateImage(false);
189
+            }
190
+            $appIconFile->scaleImage(512, 512, true);
191
+        } else {
192
+            $appIconFile = new Imagick();
193
+            $appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
194
+            $appIconFile->readImageBlob($appIconContent);
195
+            $appIconFile->scaleImage(512, 512, true);
196
+        }
197
+        // offset for icon positioning
198
+        $border_w = (int)($appIconFile->getImageWidth() * 0.05);
199
+        $border_h = (int)($appIconFile->getImageHeight() * 0.05);
200
+        $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2);
201
+        $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2);
202
+        $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight);
203
+        // center icon
204
+        $offset_w = 512 / 2 - $innerWidth / 2;
205
+        $offset_h = 512 / 2 - $innerHeight / 2;
206
+
207
+        $finalIconFile = new Imagick();
208
+        $finalIconFile->setBackgroundColor(new ImagickPixel('transparent'));
209
+        $finalIconFile->readImageBlob($background);
210
+        $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
211
+        $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5");
212
+        $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h);
213
+        $finalIconFile->setImageFormat('png24');
214
+        if (defined("Imagick::INTERPOLATE_BICUBIC") === true) {
215
+            $filter = Imagick::INTERPOLATE_BICUBIC;
216
+        } else {
217
+            $filter = Imagick::FILTER_LANCZOS;
218
+        }
219
+        $finalIconFile->resizeImage($size, $size, $filter, 1, false);
220
+
221
+        $appIconFile->destroy();
222
+        return $finalIconFile;
223
+    }
224
+
225
+    public function colorSvg($app, $image) {
226
+        try {
227
+            $imageFile = $this->util->getAppImage($app, $image);
228
+        } catch (AppPathNotFoundException $e) {
229
+            return false;
230
+        }
231
+        $svg = file_get_contents($imageFile);
232
+        if ($svg !== false && $svg !== "") {
233
+            $color = $this->util->elementColor($this->themingDefaults->getColorPrimary());
234
+            $svg = $this->util->colorizeSvg($svg, $color);
235
+            return $svg;
236
+        } else {
237
+            return false;
238
+        }
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
lib/public/ICacheFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
  * @package OCP
30 30
  * @since 7.0.0
31 31
  */
32
-interface ICacheFactory{
32
+interface ICacheFactory {
33 33
 	/**
34 34
 	 * Get a distributed memory cache instance
35 35
 	 *
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,58 +31,58 @@
 block discarded – undo
31 31
  * @since 7.0.0
32 32
  */
33 33
 interface ICacheFactory{
34
-	/**
35
-	 * Get a distributed memory cache instance
36
-	 *
37
-	 * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps
38
-	 *
39
-	 * @param string $prefix
40
-	 * @return ICache
41
-	 * @since 7.0.0
42
-	 * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal
43
-	 */
44
-	public function create(string $prefix = ''): ICache;
34
+    /**
35
+     * Get a distributed memory cache instance
36
+     *
37
+     * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps
38
+     *
39
+     * @param string $prefix
40
+     * @return ICache
41
+     * @since 7.0.0
42
+     * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal
43
+     */
44
+    public function create(string $prefix = ''): ICache;
45 45
 
46
-	/**
47
-	 * Check if any memory cache backend is available
48
-	 *
49
-	 * @return bool
50
-	 * @since 7.0.0
51
-	 */
52
-	public function isAvailable(): bool;
46
+    /**
47
+     * Check if any memory cache backend is available
48
+     *
49
+     * @return bool
50
+     * @since 7.0.0
51
+     */
52
+    public function isAvailable(): bool;
53 53
 
54
-	/**
55
-	 * Check if a local memory cache backend is available
56
-	 *
57
-	 * @return bool
58
-	 * @since 14.0.0
59
-	 */
60
-	public function isLocalCacheAvailable(): bool;
54
+    /**
55
+     * Check if a local memory cache backend is available
56
+     *
57
+     * @return bool
58
+     * @since 14.0.0
59
+     */
60
+    public function isLocalCacheAvailable(): bool;
61 61
 
62
-	/**
63
-	 * create a cache instance for storing locks
64
-	 *
65
-	 * @param string $prefix
66
-	 * @return IMemcache
67
-	 * @since 13.0.0
68
-	 */
69
-	public function createLocking(string $prefix = ''): IMemcache;
62
+    /**
63
+     * create a cache instance for storing locks
64
+     *
65
+     * @param string $prefix
66
+     * @return IMemcache
67
+     * @since 13.0.0
68
+     */
69
+    public function createLocking(string $prefix = ''): IMemcache;
70 70
 
71
-	/**
72
-	 * create a distributed cache instance
73
-	 *
74
-	 * @param string $prefix
75
-	 * @return ICache
76
-	 * @since 13.0.0
77
-	 */
78
-	public function createDistributed(string $prefix = ''): ICache;
71
+    /**
72
+     * create a distributed cache instance
73
+     *
74
+     * @param string $prefix
75
+     * @return ICache
76
+     * @since 13.0.0
77
+     */
78
+    public function createDistributed(string $prefix = ''): ICache;
79 79
 
80
-	/**
81
-	 * create a local cache instance
82
-	 *
83
-	 * @param string $prefix
84
-	 * @return ICache
85
-	 * @since 13.0.0
86
-	 */
87
-	public function createLocal(string $prefix = ''): ICache;
80
+    /**
81
+     * create a local cache instance
82
+     *
83
+     * @param string $prefix
84
+     * @return ICache
85
+     * @since 13.0.0
86
+     */
87
+    public function createLocal(string $prefix = ''): ICache;
88 88
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -31,76 +31,76 @@
 block discarded – undo
31 31
 
32 32
 class SameSiteCookieMiddleware extends Middleware {
33 33
 
34
-	/** @var Request */
35
-	private $request;
36
-
37
-	/** @var ControllerMethodReflector */
38
-	private $reflector;
39
-
40
-	public function __construct(Request $request,
41
-								ControllerMethodReflector $reflector) {
42
-		$this->request = $request;
43
-		$this->reflector = $reflector;
44
-	}
45
-
46
-	public function beforeController($controller, $methodName) {
47
-		$requestUri = $this->request->getScriptName();
48
-		$processingScript = explode('/', $requestUri);
49
-		$processingScript = $processingScript[count($processingScript)-1];
50
-
51
-		if ($processingScript !== 'index.php') {
52
-			return;
53
-		}
54
-
55
-		$noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired');
56
-		if ($noSSC) {
57
-			return;
58
-		}
59
-
60
-		if (!$this->request->passesLaxCookieCheck()) {
61
-			throw new LaxSameSiteCookieFailedException();
62
-		}
63
-	}
64
-
65
-	public function afterException($controller, $methodName, \Exception $exception) {
66
-		if ($exception instanceof LaxSameSiteCookieFailedException) {
67
-			$respone = new Response();
68
-			$respone->setStatus(Http::STATUS_FOUND);
69
-			$respone->addHeader('Location', $this->request->getRequestUri());
70
-
71
-			$this->setSameSiteCookie();
72
-
73
-			return $respone;
74
-		}
75
-
76
-		throw $exception;
77
-	}
78
-
79
-	protected function setSameSiteCookie() {
80
-		$cookieParams = $this->request->getCookieParams();
81
-		$secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : '';
82
-		$policies = [
83
-			'lax',
84
-			'strict',
85
-		];
86
-
87
-		// Append __Host to the cookie if it meets the requirements
88
-		$cookiePrefix = '';
89
-		if($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
90
-			$cookiePrefix = '__Host-';
91
-		}
92
-
93
-		foreach($policies as $policy) {
94
-			header(
95
-				sprintf(
96
-					'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
97
-					$cookiePrefix,
98
-					$policy,
99
-					$cookieParams['path'],
100
-					$policy
101
-				),
102
-				false
103
-			);
104
-		}
105
-	}
34
+    /** @var Request */
35
+    private $request;
36
+
37
+    /** @var ControllerMethodReflector */
38
+    private $reflector;
39
+
40
+    public function __construct(Request $request,
41
+                                ControllerMethodReflector $reflector) {
42
+        $this->request = $request;
43
+        $this->reflector = $reflector;
44
+    }
45
+
46
+    public function beforeController($controller, $methodName) {
47
+        $requestUri = $this->request->getScriptName();
48
+        $processingScript = explode('/', $requestUri);
49
+        $processingScript = $processingScript[count($processingScript)-1];
50
+
51
+        if ($processingScript !== 'index.php') {
52
+            return;
53
+        }
54
+
55
+        $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired');
56
+        if ($noSSC) {
57
+            return;
58
+        }
59
+
60
+        if (!$this->request->passesLaxCookieCheck()) {
61
+            throw new LaxSameSiteCookieFailedException();
62
+        }
63
+    }
64
+
65
+    public function afterException($controller, $methodName, \Exception $exception) {
66
+        if ($exception instanceof LaxSameSiteCookieFailedException) {
67
+            $respone = new Response();
68
+            $respone->setStatus(Http::STATUS_FOUND);
69
+            $respone->addHeader('Location', $this->request->getRequestUri());
70
+
71
+            $this->setSameSiteCookie();
72
+
73
+            return $respone;
74
+        }
75
+
76
+        throw $exception;
77
+    }
78
+
79
+    protected function setSameSiteCookie() {
80
+        $cookieParams = $this->request->getCookieParams();
81
+        $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : '';
82
+        $policies = [
83
+            'lax',
84
+            'strict',
85
+        ];
86
+
87
+        // Append __Host to the cookie if it meets the requirements
88
+        $cookiePrefix = '';
89
+        if($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
90
+            $cookiePrefix = '__Host-';
91
+        }
92
+
93
+        foreach($policies as $policy) {
94
+            header(
95
+                sprintf(
96
+                    'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
97
+                    $cookiePrefix,
98
+                    $policy,
99
+                    $cookieParams['path'],
100
+                    $policy
101
+                ),
102
+                false
103
+            );
104
+        }
105
+    }
106 106
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	public function beforeController($controller, $methodName) {
47 47
 		$requestUri = $this->request->getScriptName();
48 48
 		$processingScript = explode('/', $requestUri);
49
-		$processingScript = $processingScript[count($processingScript)-1];
49
+		$processingScript = $processingScript[count($processingScript) - 1];
50 50
 
51 51
 		if ($processingScript !== 'index.php') {
52 52
 			return;
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 
87 87
 		// Append __Host to the cookie if it meets the requirements
88 88
 		$cookiePrefix = '';
89
-		if($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
89
+		if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
90 90
 			$cookiePrefix = '__Host-';
91 91
 		}
92 92
 
93
-		foreach($policies as $policy) {
93
+		foreach ($policies as $policy) {
94 94
 			header(
95 95
 				sprintf(
96
-					'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
96
+					'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
97 97
 					$cookiePrefix,
98 98
 					$policy,
99 99
 					$cookieParams['path'],
Please login to merge, or discard this patch.
Middleware/Security/Exceptions/LaxSameSiteCookieFailedException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
  * @package OC\AppFramework\Middleware\Security\Exceptions
33 33
  */
34 34
 class LaxSameSiteCookieFailedException extends SecurityException {
35
-	public function __construct() {
36
-		parent::__construct('Lax Same Site Cookie is invalid in request.', Http::STATUS_PRECONDITION_FAILED);
37
-	}
35
+    public function __construct() {
36
+        parent::__construct('Lax Same Site Cookie is invalid in request.', Http::STATUS_PRECONDITION_FAILED);
37
+    }
38 38
 }
Please login to merge, or discard this patch.