@@ -30,13 +30,13 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearchPlugin { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param int $limit |
|
36 | - * @param int $offset |
|
37 | - * @param ISearchResult $searchResult |
|
38 | - * @return bool whether the plugin has more results |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param int $limit |
|
36 | + * @param int $offset |
|
37 | + * @param ISearchResult $searchResult |
|
38 | + * @return bool whether the plugin has more results |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
42 | 42 | } |
@@ -30,21 +30,21 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearch { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param array $shareTypes |
|
36 | - * @param bool $lookup |
|
37 | - * @param int $limit |
|
38 | - * @param int $offset |
|
39 | - * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param array $shareTypes |
|
36 | + * @param bool $lookup |
|
37 | + * @param int $limit |
|
38 | + * @param int $offset |
|
39 | + * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | - * 'class' with the class name of the plugin |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function registerPlugin(array $pluginInfo); |
|
44 | + /** |
|
45 | + * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | + * 'class' with the class name of the plugin |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function registerPlugin(array $pluginInfo); |
|
50 | 50 | } |
@@ -30,44 +30,44 @@ |
||
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 | } |
@@ -30,203 +30,203 @@ |
||
30 | 30 | use OCP\ICache; |
31 | 31 | |
32 | 32 | class InfoParser { |
33 | - /** @var \OCP\ICache|null */ |
|
34 | - private $cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param ICache|null $cache |
|
38 | - */ |
|
39 | - public function __construct(ICache $cache = null) { |
|
40 | - $this->cache = $cache; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $file the xml file to be loaded |
|
45 | - * @return null|array where null is an indicator for an error |
|
46 | - */ |
|
47 | - public function parse($file) { |
|
48 | - if (!file_exists($file)) { |
|
49 | - return null; |
|
50 | - } |
|
51 | - |
|
52 | - if(!is_null($this->cache)) { |
|
53 | - $fileCacheKey = $file . filemtime($file); |
|
54 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | - return json_decode($cachedValue, true); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - libxml_use_internal_errors(true); |
|
60 | - $loadEntities = libxml_disable_entity_loader(false); |
|
61 | - $xml = simplexml_load_file($file); |
|
62 | - |
|
63 | - libxml_disable_entity_loader($loadEntities); |
|
64 | - if ($xml === false) { |
|
65 | - libxml_clear_errors(); |
|
66 | - return null; |
|
67 | - } |
|
68 | - $array = $this->xmlToArray($xml); |
|
69 | - |
|
70 | - if (is_null($array)) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - |
|
74 | - if (!array_key_exists('info', $array)) { |
|
75 | - $array['info'] = []; |
|
76 | - } |
|
77 | - if (!array_key_exists('remote', $array)) { |
|
78 | - $array['remote'] = []; |
|
79 | - } |
|
80 | - if (!array_key_exists('public', $array)) { |
|
81 | - $array['public'] = []; |
|
82 | - } |
|
83 | - if (!array_key_exists('types', $array)) { |
|
84 | - $array['types'] = []; |
|
85 | - } |
|
86 | - if (!array_key_exists('repair-steps', $array)) { |
|
87 | - $array['repair-steps'] = []; |
|
88 | - } |
|
89 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | - $array['repair-steps']['install'] = []; |
|
91 | - } |
|
92 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | - $array['repair-steps']['pre-migration'] = []; |
|
94 | - } |
|
95 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | - $array['repair-steps']['post-migration'] = []; |
|
97 | - } |
|
98 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | - $array['repair-steps']['live-migration'] = []; |
|
100 | - } |
|
101 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | - $array['repair-steps']['uninstall'] = []; |
|
103 | - } |
|
104 | - if (!array_key_exists('background-jobs', $array)) { |
|
105 | - $array['background-jobs'] = []; |
|
106 | - } |
|
107 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | - $array['two-factor-providers'] = []; |
|
109 | - } |
|
110 | - if (!array_key_exists('commands', $array)) { |
|
111 | - $array['commands'] = []; |
|
112 | - } |
|
113 | - if (!array_key_exists('activity', $array)) { |
|
114 | - $array['activity'] = []; |
|
115 | - } |
|
116 | - if (!array_key_exists('filters', $array['activity'])) { |
|
117 | - $array['activity']['filters'] = []; |
|
118 | - } |
|
119 | - if (!array_key_exists('settings', $array['activity'])) { |
|
120 | - $array['activity']['settings'] = []; |
|
121 | - } |
|
122 | - if (!array_key_exists('providers', $array['activity'])) { |
|
123 | - $array['activity']['providers'] = []; |
|
124 | - } |
|
125 | - |
|
126 | - if (array_key_exists('types', $array)) { |
|
127 | - if (is_array($array['types'])) { |
|
128 | - foreach ($array['types'] as $type => $v) { |
|
129 | - unset($array['types'][$type]); |
|
130 | - if (is_string($type)) { |
|
131 | - $array['types'][] = $type; |
|
132 | - } |
|
133 | - } |
|
134 | - } else { |
|
135 | - $array['types'] = []; |
|
136 | - } |
|
137 | - } |
|
138 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | - } |
|
141 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | - } |
|
144 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | - } |
|
147 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | - } |
|
150 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | - } |
|
153 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | - } |
|
156 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | - $array['commands'] = $array['commands']['command']; |
|
158 | - } |
|
159 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | - } |
|
162 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | - } |
|
165 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | - } |
|
168 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | - ) { |
|
172 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | - } |
|
174 | - |
|
175 | - if(!is_null($this->cache)) { |
|
176 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | - } |
|
178 | - return $array; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param \SimpleXMLElement $xml |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - public function xmlToArray($xml) { |
|
186 | - if (!$xml->children()) { |
|
187 | - return (string)$xml; |
|
188 | - } |
|
189 | - |
|
190 | - $array = []; |
|
191 | - foreach ($xml->children() as $element => $node) { |
|
192 | - $totalElement = count($xml->{$element}); |
|
193 | - |
|
194 | - if (!isset($array[$element])) { |
|
195 | - $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | - } |
|
197 | - /** @var \SimpleXMLElement $node */ |
|
198 | - // Has attributes |
|
199 | - if ($attributes = $node->attributes()) { |
|
200 | - $data = [ |
|
201 | - '@attributes' => [], |
|
202 | - ]; |
|
203 | - if (!count($node->children())){ |
|
204 | - $value = (string)$node; |
|
205 | - if (!empty($value)) { |
|
206 | - $data['@value'] = (string)$node; |
|
207 | - } |
|
208 | - } else { |
|
209 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | - } |
|
211 | - foreach ($attributes as $attr => $value) { |
|
212 | - $data['@attributes'][$attr] = (string)$value; |
|
213 | - } |
|
214 | - |
|
215 | - if ($totalElement > 1) { |
|
216 | - $array[$element][] = $data; |
|
217 | - } else { |
|
218 | - $array[$element] = $data; |
|
219 | - } |
|
220 | - // Just a value |
|
221 | - } else { |
|
222 | - if ($totalElement > 1) { |
|
223 | - $array[$element][] = $this->xmlToArray($node); |
|
224 | - } else { |
|
225 | - $array[$element] = $this->xmlToArray($node); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - return $array; |
|
231 | - } |
|
33 | + /** @var \OCP\ICache|null */ |
|
34 | + private $cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param ICache|null $cache |
|
38 | + */ |
|
39 | + public function __construct(ICache $cache = null) { |
|
40 | + $this->cache = $cache; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $file the xml file to be loaded |
|
45 | + * @return null|array where null is an indicator for an error |
|
46 | + */ |
|
47 | + public function parse($file) { |
|
48 | + if (!file_exists($file)) { |
|
49 | + return null; |
|
50 | + } |
|
51 | + |
|
52 | + if(!is_null($this->cache)) { |
|
53 | + $fileCacheKey = $file . filemtime($file); |
|
54 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | + return json_decode($cachedValue, true); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + libxml_use_internal_errors(true); |
|
60 | + $loadEntities = libxml_disable_entity_loader(false); |
|
61 | + $xml = simplexml_load_file($file); |
|
62 | + |
|
63 | + libxml_disable_entity_loader($loadEntities); |
|
64 | + if ($xml === false) { |
|
65 | + libxml_clear_errors(); |
|
66 | + return null; |
|
67 | + } |
|
68 | + $array = $this->xmlToArray($xml); |
|
69 | + |
|
70 | + if (is_null($array)) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + |
|
74 | + if (!array_key_exists('info', $array)) { |
|
75 | + $array['info'] = []; |
|
76 | + } |
|
77 | + if (!array_key_exists('remote', $array)) { |
|
78 | + $array['remote'] = []; |
|
79 | + } |
|
80 | + if (!array_key_exists('public', $array)) { |
|
81 | + $array['public'] = []; |
|
82 | + } |
|
83 | + if (!array_key_exists('types', $array)) { |
|
84 | + $array['types'] = []; |
|
85 | + } |
|
86 | + if (!array_key_exists('repair-steps', $array)) { |
|
87 | + $array['repair-steps'] = []; |
|
88 | + } |
|
89 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | + $array['repair-steps']['install'] = []; |
|
91 | + } |
|
92 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | + $array['repair-steps']['pre-migration'] = []; |
|
94 | + } |
|
95 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | + $array['repair-steps']['post-migration'] = []; |
|
97 | + } |
|
98 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | + $array['repair-steps']['live-migration'] = []; |
|
100 | + } |
|
101 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | + $array['repair-steps']['uninstall'] = []; |
|
103 | + } |
|
104 | + if (!array_key_exists('background-jobs', $array)) { |
|
105 | + $array['background-jobs'] = []; |
|
106 | + } |
|
107 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | + $array['two-factor-providers'] = []; |
|
109 | + } |
|
110 | + if (!array_key_exists('commands', $array)) { |
|
111 | + $array['commands'] = []; |
|
112 | + } |
|
113 | + if (!array_key_exists('activity', $array)) { |
|
114 | + $array['activity'] = []; |
|
115 | + } |
|
116 | + if (!array_key_exists('filters', $array['activity'])) { |
|
117 | + $array['activity']['filters'] = []; |
|
118 | + } |
|
119 | + if (!array_key_exists('settings', $array['activity'])) { |
|
120 | + $array['activity']['settings'] = []; |
|
121 | + } |
|
122 | + if (!array_key_exists('providers', $array['activity'])) { |
|
123 | + $array['activity']['providers'] = []; |
|
124 | + } |
|
125 | + |
|
126 | + if (array_key_exists('types', $array)) { |
|
127 | + if (is_array($array['types'])) { |
|
128 | + foreach ($array['types'] as $type => $v) { |
|
129 | + unset($array['types'][$type]); |
|
130 | + if (is_string($type)) { |
|
131 | + $array['types'][] = $type; |
|
132 | + } |
|
133 | + } |
|
134 | + } else { |
|
135 | + $array['types'] = []; |
|
136 | + } |
|
137 | + } |
|
138 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | + } |
|
141 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | + } |
|
144 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | + } |
|
147 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | + } |
|
150 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | + } |
|
153 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | + } |
|
156 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | + $array['commands'] = $array['commands']['command']; |
|
158 | + } |
|
159 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | + } |
|
162 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | + } |
|
165 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | + } |
|
168 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | + ) { |
|
172 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | + } |
|
174 | + |
|
175 | + if(!is_null($this->cache)) { |
|
176 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | + } |
|
178 | + return $array; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param \SimpleXMLElement $xml |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + public function xmlToArray($xml) { |
|
186 | + if (!$xml->children()) { |
|
187 | + return (string)$xml; |
|
188 | + } |
|
189 | + |
|
190 | + $array = []; |
|
191 | + foreach ($xml->children() as $element => $node) { |
|
192 | + $totalElement = count($xml->{$element}); |
|
193 | + |
|
194 | + if (!isset($array[$element])) { |
|
195 | + $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | + } |
|
197 | + /** @var \SimpleXMLElement $node */ |
|
198 | + // Has attributes |
|
199 | + if ($attributes = $node->attributes()) { |
|
200 | + $data = [ |
|
201 | + '@attributes' => [], |
|
202 | + ]; |
|
203 | + if (!count($node->children())){ |
|
204 | + $value = (string)$node; |
|
205 | + if (!empty($value)) { |
|
206 | + $data['@value'] = (string)$node; |
|
207 | + } |
|
208 | + } else { |
|
209 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | + } |
|
211 | + foreach ($attributes as $attr => $value) { |
|
212 | + $data['@attributes'][$attr] = (string)$value; |
|
213 | + } |
|
214 | + |
|
215 | + if ($totalElement > 1) { |
|
216 | + $array[$element][] = $data; |
|
217 | + } else { |
|
218 | + $array[$element] = $data; |
|
219 | + } |
|
220 | + // Just a value |
|
221 | + } else { |
|
222 | + if ($totalElement > 1) { |
|
223 | + $array[$element][] = $this->xmlToArray($node); |
|
224 | + } else { |
|
225 | + $array[$element] = $this->xmlToArray($node); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + return $array; |
|
231 | + } |
|
232 | 232 | } |
@@ -33,92 +33,92 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class GroupPlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
37 | - protected $shareWithGroupOnly; |
|
36 | + protected $shareeEnumeration; |
|
37 | + protected $shareWithGroupOnly; |
|
38 | 38 | |
39 | - /** @var IGroupManager */ |
|
40 | - private $groupManager; |
|
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IUserSession */ |
|
44 | - private $userSession; |
|
39 | + /** @var IGroupManager */ |
|
40 | + private $groupManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IUserSession */ |
|
44 | + private $userSession; |
|
45 | 45 | |
46 | - public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | - $this->groupManager = $groupManager; |
|
48 | - $this->config = $config; |
|
49 | - $this->userSession = $userSession; |
|
46 | + public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | + $this->groupManager = $groupManager; |
|
48 | + $this->config = $config; |
|
49 | + $this->userSession = $userSession; |
|
50 | 50 | |
51 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | - } |
|
51 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | + } |
|
54 | 54 | |
55 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | - $hasMoreResults = false; |
|
57 | - $result = ['wide' => [], 'exact' => []]; |
|
55 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | + $hasMoreResults = false; |
|
57 | + $result = ['wide' => [], 'exact' => []]; |
|
58 | 58 | |
59 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
59 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | + $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
61 | 61 | |
62 | - if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | - $hasMoreResults = true; |
|
64 | - } |
|
62 | + if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | + $hasMoreResults = true; |
|
64 | + } |
|
65 | 65 | |
66 | - $userGroups = []; |
|
67 | - if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | - // Intersect all the groups that match with the groups this user is a member of |
|
69 | - $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | - $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | - } |
|
66 | + $userGroups = []; |
|
67 | + if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | + // Intersect all the groups that match with the groups this user is a member of |
|
69 | + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | + $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | + $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | + } |
|
73 | 73 | |
74 | - $lowerSearch = strtolower($search); |
|
75 | - foreach ($groups as $group) { |
|
76 | - // FIXME: use a more efficient approach |
|
77 | - $gid = $group->getGID(); |
|
78 | - if (!in_array($gid, $groupIds)) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | - $result['exact'][] = [ |
|
83 | - 'label' => $group->getDisplayName(), |
|
84 | - 'value' => [ |
|
85 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | - 'shareWith' => $gid, |
|
87 | - ], |
|
88 | - ]; |
|
89 | - } else { |
|
90 | - $result['wide'][] = [ |
|
91 | - 'label' => $group->getDisplayName(), |
|
92 | - 'value' => [ |
|
93 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | - 'shareWith' => $gid, |
|
95 | - ], |
|
96 | - ]; |
|
97 | - } |
|
98 | - } |
|
74 | + $lowerSearch = strtolower($search); |
|
75 | + foreach ($groups as $group) { |
|
76 | + // FIXME: use a more efficient approach |
|
77 | + $gid = $group->getGID(); |
|
78 | + if (!in_array($gid, $groupIds)) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | + $result['exact'][] = [ |
|
83 | + 'label' => $group->getDisplayName(), |
|
84 | + 'value' => [ |
|
85 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | + 'shareWith' => $gid, |
|
87 | + ], |
|
88 | + ]; |
|
89 | + } else { |
|
90 | + $result['wide'][] = [ |
|
91 | + 'label' => $group->getDisplayName(), |
|
92 | + 'value' => [ |
|
93 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | + 'shareWith' => $gid, |
|
95 | + ], |
|
96 | + ]; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - if ($offset === 0 && empty($result['exact'])) { |
|
101 | - // On page one we try if the search result has a direct hit on the |
|
102 | - // user id and if so, we add that to the exact match list |
|
103 | - $group = $this->groupManager->get($search); |
|
104 | - if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | - array_push($result['exact'], [ |
|
106 | - 'label' => $group->getDisplayName(), |
|
107 | - 'value' => [ |
|
108 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | - 'shareWith' => $group->getGID(), |
|
110 | - ], |
|
111 | - ]); |
|
112 | - } |
|
113 | - } |
|
100 | + if ($offset === 0 && empty($result['exact'])) { |
|
101 | + // On page one we try if the search result has a direct hit on the |
|
102 | + // user id and if so, we add that to the exact match list |
|
103 | + $group = $this->groupManager->get($search); |
|
104 | + if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | + array_push($result['exact'], [ |
|
106 | + 'label' => $group->getDisplayName(), |
|
107 | + 'value' => [ |
|
108 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | + 'shareWith' => $group->getGID(), |
|
110 | + ], |
|
111 | + ]); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - if (!$this->shareeEnumeration) { |
|
116 | - $result['wide'] = []; |
|
117 | - } |
|
115 | + if (!$this->shareeEnumeration) { |
|
116 | + $result['wide'] = []; |
|
117 | + } |
|
118 | 118 | |
119 | - $type = new SearchResultType('groups'); |
|
120 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
119 | + $type = new SearchResultType('groups'); |
|
120 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
121 | 121 | |
122 | - return $hasMoreResults; |
|
123 | - } |
|
122 | + return $hasMoreResults; |
|
123 | + } |
|
124 | 124 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | class SearchResultType { |
33 | - /** @var string */ |
|
34 | - protected $label; |
|
33 | + /** @var string */ |
|
34 | + protected $label; |
|
35 | 35 | |
36 | - /** |
|
37 | - * SearchResultType constructor. |
|
38 | - * |
|
39 | - * @param string $label |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function __construct($label) { |
|
43 | - $this->label = $this->getValidatedType($label); |
|
44 | - } |
|
36 | + /** |
|
37 | + * SearchResultType constructor. |
|
38 | + * |
|
39 | + * @param string $label |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function __construct($label) { |
|
43 | + $this->label = $this->getValidatedType($label); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @since 13.0.0 |
|
49 | - */ |
|
50 | - public function getLabel() { |
|
51 | - return $this->label; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @since 13.0.0 |
|
49 | + */ |
|
50 | + public function getLabel() { |
|
51 | + return $this->label; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param $type |
|
56 | - * @return string |
|
57 | - * @throws \InvalidArgumentException |
|
58 | - * @since 13.0.0 |
|
59 | - */ |
|
60 | - protected function getValidatedType($type) { |
|
61 | - $type = trim(strval($type)); |
|
54 | + /** |
|
55 | + * @param $type |
|
56 | + * @return string |
|
57 | + * @throws \InvalidArgumentException |
|
58 | + * @since 13.0.0 |
|
59 | + */ |
|
60 | + protected function getValidatedType($type) { |
|
61 | + $type = trim(strval($type)); |
|
62 | 62 | |
63 | - if($type === '') { |
|
64 | - throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | - } |
|
63 | + if($type === '') { |
|
64 | + throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | + } |
|
66 | 66 | |
67 | - if($type === 'exact') { |
|
68 | - throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | - } |
|
67 | + if($type === 'exact') { |
|
68 | + throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | + } |
|
70 | 70 | |
71 | - return $type; |
|
72 | - } |
|
71 | + return $type; |
|
72 | + } |
|
73 | 73 | } |
@@ -29,58 +29,58 @@ |
||
29 | 29 | |
30 | 30 | class SearchResult implements ISearchResult { |
31 | 31 | |
32 | - protected $result = [ |
|
33 | - 'exact' => [], |
|
34 | - ]; |
|
32 | + protected $result = [ |
|
33 | + 'exact' => [], |
|
34 | + ]; |
|
35 | 35 | |
36 | - protected $exactIdMatches = []; |
|
36 | + protected $exactIdMatches = []; |
|
37 | 37 | |
38 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | - $type = $type->getLabel(); |
|
40 | - if(!isset($this->result[$type])) { |
|
41 | - $this->result[$type] = []; |
|
42 | - $this->result['exact'][$type] = []; |
|
43 | - } |
|
38 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | + $type = $type->getLabel(); |
|
40 | + if(!isset($this->result[$type])) { |
|
41 | + $this->result[$type] = []; |
|
42 | + $this->result['exact'][$type] = []; |
|
43 | + } |
|
44 | 44 | |
45 | - $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | - if(is_array($exactMatches)) { |
|
47 | - $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | - } |
|
49 | - } |
|
45 | + $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | + if(is_array($exactMatches)) { |
|
47 | + $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - public function markExactIdMatch(SearchResultType $type) { |
|
52 | - $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | - } |
|
51 | + public function markExactIdMatch(SearchResultType $type) { |
|
52 | + $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | + } |
|
54 | 54 | |
55 | - public function hasExactIdMatch(SearchResultType$type) { |
|
56 | - return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | - } |
|
55 | + public function hasExactIdMatch(SearchResultType$type) { |
|
56 | + return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | + } |
|
58 | 58 | |
59 | - public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | - $type = $type->getLabel(); |
|
61 | - if(!isset($this->result[$type])) { |
|
62 | - return false; |
|
63 | - } |
|
59 | + public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | + $type = $type->getLabel(); |
|
61 | + if(!isset($this->result[$type])) { |
|
62 | + return false; |
|
63 | + } |
|
64 | 64 | |
65 | - $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | - foreach($resultArrays as $resultArray) { |
|
67 | - if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - } |
|
65 | + $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | + foreach($resultArrays as $resultArray) { |
|
67 | + if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return false; |
|
73 | - } |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - public function asArray() { |
|
76 | - return $this->result; |
|
77 | - } |
|
75 | + public function asArray() { |
|
76 | + return $this->result; |
|
77 | + } |
|
78 | 78 | |
79 | - public function unsetResult(SearchResultType $type) { |
|
80 | - $type = $type->getLabel(); |
|
81 | - $this->result[$type] = []; |
|
82 | - if(isset($this->result['exact'][$type])) { |
|
83 | - $this->result['exact'][$type] = []; |
|
84 | - } |
|
85 | - } |
|
79 | + public function unsetResult(SearchResultType $type) { |
|
80 | + $type = $type->getLabel(); |
|
81 | + $this->result[$type] = []; |
|
82 | + if(isset($this->result['exact'][$type])) { |
|
83 | + $this->result['exact'][$type] = []; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -35,115 +35,115 @@ |
||
35 | 35 | use OCP\Share; |
36 | 36 | |
37 | 37 | class UserPlugin implements ISearchPlugin { |
38 | - /* @var bool */ |
|
39 | - protected $shareWithGroupOnly; |
|
40 | - protected $shareeEnumeration; |
|
41 | - |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - /** @var IGroupManager */ |
|
45 | - private $groupManager; |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
50 | - |
|
51 | - public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | - $this->config = $config; |
|
53 | - |
|
54 | - $this->groupManager = $groupManager; |
|
55 | - $this->userSession = $userSession; |
|
56 | - $this->userManager = $userManager; |
|
57 | - |
|
58 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | - } |
|
61 | - |
|
62 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | - $result = ['wide' => [], 'exact' => []]; |
|
64 | - $users = []; |
|
65 | - $hasMoreResults = false; |
|
66 | - |
|
67 | - $userGroups = []; |
|
68 | - if ($this->shareWithGroupOnly) { |
|
69 | - // Search in all the groups this user is part of |
|
70 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | - foreach ($userGroups as $userGroup) { |
|
72 | - $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | - foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | - $users[$uid] = $userDisplayName; |
|
75 | - } |
|
76 | - } |
|
77 | - } else { |
|
78 | - // Search in all users |
|
79 | - $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | - |
|
81 | - foreach ($usersTmp as $user) { |
|
82 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
87 | - $hasMoreResults = true; |
|
88 | - } |
|
89 | - |
|
90 | - $foundUserById = false; |
|
91 | - $lowerSearch = strtolower($search); |
|
92 | - foreach ($users as $uid => $userDisplayName) { |
|
93 | - if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
94 | - if (strtolower($uid) === $lowerSearch) { |
|
95 | - $foundUserById = true; |
|
96 | - } |
|
97 | - $result['exact'][] = [ |
|
98 | - 'label' => $userDisplayName, |
|
99 | - 'value' => [ |
|
100 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
101 | - 'shareWith' => $uid, |
|
102 | - ], |
|
103 | - ]; |
|
104 | - } else { |
|
105 | - $result['wide'][] = [ |
|
106 | - 'label' => $userDisplayName, |
|
107 | - 'value' => [ |
|
108 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
109 | - 'shareWith' => $uid, |
|
110 | - ], |
|
111 | - ]; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - if ($offset === 0 && !$foundUserById) { |
|
116 | - // On page one we try if the search result has a direct hit on the |
|
117 | - // user id and if so, we add that to the exact match list |
|
118 | - $user = $this->userManager->get($search); |
|
119 | - if ($user instanceof IUser) { |
|
120 | - $addUser = true; |
|
121 | - |
|
122 | - if ($this->shareWithGroupOnly) { |
|
123 | - // Only add, if we have a common group |
|
124 | - $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
125 | - $addUser = !empty($commonGroups); |
|
126 | - } |
|
127 | - |
|
128 | - if ($addUser) { |
|
129 | - array_push($result['exact'], [ |
|
130 | - 'label' => $user->getDisplayName(), |
|
131 | - 'value' => [ |
|
132 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
133 | - 'shareWith' => $user->getUID(), |
|
134 | - ], |
|
135 | - ]); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - if (!$this->shareeEnumeration) { |
|
141 | - $result['wide'] = []; |
|
142 | - } |
|
143 | - |
|
144 | - $type = new SearchResultType('users'); |
|
145 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
146 | - |
|
147 | - return $hasMoreResults; |
|
148 | - } |
|
38 | + /* @var bool */ |
|
39 | + protected $shareWithGroupOnly; |
|
40 | + protected $shareeEnumeration; |
|
41 | + |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + /** @var IGroupManager */ |
|
45 | + private $groupManager; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | + |
|
51 | + public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | + $this->config = $config; |
|
53 | + |
|
54 | + $this->groupManager = $groupManager; |
|
55 | + $this->userSession = $userSession; |
|
56 | + $this->userManager = $userManager; |
|
57 | + |
|
58 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | + } |
|
61 | + |
|
62 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | + $result = ['wide' => [], 'exact' => []]; |
|
64 | + $users = []; |
|
65 | + $hasMoreResults = false; |
|
66 | + |
|
67 | + $userGroups = []; |
|
68 | + if ($this->shareWithGroupOnly) { |
|
69 | + // Search in all the groups this user is part of |
|
70 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | + foreach ($userGroups as $userGroup) { |
|
72 | + $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | + foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | + $users[$uid] = $userDisplayName; |
|
75 | + } |
|
76 | + } |
|
77 | + } else { |
|
78 | + // Search in all users |
|
79 | + $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | + |
|
81 | + foreach ($usersTmp as $user) { |
|
82 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
87 | + $hasMoreResults = true; |
|
88 | + } |
|
89 | + |
|
90 | + $foundUserById = false; |
|
91 | + $lowerSearch = strtolower($search); |
|
92 | + foreach ($users as $uid => $userDisplayName) { |
|
93 | + if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
94 | + if (strtolower($uid) === $lowerSearch) { |
|
95 | + $foundUserById = true; |
|
96 | + } |
|
97 | + $result['exact'][] = [ |
|
98 | + 'label' => $userDisplayName, |
|
99 | + 'value' => [ |
|
100 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
101 | + 'shareWith' => $uid, |
|
102 | + ], |
|
103 | + ]; |
|
104 | + } else { |
|
105 | + $result['wide'][] = [ |
|
106 | + 'label' => $userDisplayName, |
|
107 | + 'value' => [ |
|
108 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
109 | + 'shareWith' => $uid, |
|
110 | + ], |
|
111 | + ]; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + if ($offset === 0 && !$foundUserById) { |
|
116 | + // On page one we try if the search result has a direct hit on the |
|
117 | + // user id and if so, we add that to the exact match list |
|
118 | + $user = $this->userManager->get($search); |
|
119 | + if ($user instanceof IUser) { |
|
120 | + $addUser = true; |
|
121 | + |
|
122 | + if ($this->shareWithGroupOnly) { |
|
123 | + // Only add, if we have a common group |
|
124 | + $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
125 | + $addUser = !empty($commonGroups); |
|
126 | + } |
|
127 | + |
|
128 | + if ($addUser) { |
|
129 | + array_push($result['exact'], [ |
|
130 | + 'label' => $user->getDisplayName(), |
|
131 | + 'value' => [ |
|
132 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
133 | + 'shareWith' => $user->getUID(), |
|
134 | + ], |
|
135 | + ]); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + if (!$this->shareeEnumeration) { |
|
141 | + $result['wide'] = []; |
|
142 | + } |
|
143 | + |
|
144 | + $type = new SearchResultType('users'); |
|
145 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
146 | + |
|
147 | + return $hasMoreResults; |
|
148 | + } |
|
149 | 149 | } |
@@ -33,132 +33,132 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class MailPlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
37 | - |
|
38 | - /** @var IManager */ |
|
39 | - private $contactsManager; |
|
40 | - /** @var ICloudIdManager */ |
|
41 | - private $cloudIdManager; |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - |
|
45 | - public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | - $this->contactsManager = $contactsManager; |
|
47 | - $this->cloudIdManager = $cloudIdManager; |
|
48 | - $this->config = $config; |
|
49 | - |
|
50 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param $search |
|
55 | - * @param $limit |
|
56 | - * @param $offset |
|
57 | - * @param ISearchResult $searchResult |
|
58 | - * @return bool |
|
59 | - * @since 13.0.0 |
|
60 | - */ |
|
61 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
62 | - $result = ['wide' => [], 'exact' => []]; |
|
63 | - $userType = new SearchResultType('users'); |
|
64 | - $emailType = new SearchResultType('emails'); |
|
65 | - |
|
66 | - // Search in contacts |
|
67 | - //@todo Pagination missing |
|
68 | - $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
69 | - $lowerSearch = strtolower($search); |
|
70 | - foreach ($addressBookContacts as $contact) { |
|
71 | - if (isset($contact['EMAIL'])) { |
|
72 | - $emailAddresses = $contact['EMAIL']; |
|
73 | - if (!is_array($emailAddresses)) { |
|
74 | - $emailAddresses = [$emailAddresses]; |
|
75 | - } |
|
76 | - foreach ($emailAddresses as $emailAddress) { |
|
77 | - $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
78 | - |
|
79 | - if (isset($contact['isLocalSystemBook'])) { |
|
80 | - if ($exactEmailMatch) { |
|
81 | - try { |
|
82 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - continue; |
|
85 | - } |
|
86 | - |
|
87 | - if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
88 | - $singleResult = [[ |
|
89 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
90 | - 'value' => [ |
|
91 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
92 | - 'shareWith' => $cloud->getUser(), |
|
93 | - ], |
|
94 | - ]]; |
|
95 | - $searchResult->addResultSet($userType, [], $singleResult); |
|
96 | - $searchResult->markExactIdMatch($emailType); |
|
97 | - } |
|
98 | - return false; |
|
99 | - } |
|
100 | - |
|
101 | - if ($this->shareeEnumeration) { |
|
102 | - try { |
|
103 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
104 | - } catch (\InvalidArgumentException $e) { |
|
105 | - continue; |
|
106 | - } |
|
107 | - |
|
108 | - if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
109 | - $singleResult = [[ |
|
110 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
111 | - 'value' => [ |
|
112 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
113 | - 'shareWith' => $cloud->getUser(), |
|
114 | - ]], |
|
115 | - ]; |
|
116 | - $searchResult->addResultSet($userType, $singleResult, []); |
|
117 | - } |
|
118 | - } |
|
119 | - continue; |
|
120 | - } |
|
121 | - |
|
122 | - if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) { |
|
123 | - if ($exactEmailMatch) { |
|
124 | - $searchResult->markExactIdMatch($emailType); |
|
125 | - } |
|
126 | - $result['exact'][] = [ |
|
127 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
128 | - 'value' => [ |
|
129 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
130 | - 'shareWith' => $emailAddress, |
|
131 | - ], |
|
132 | - ]; |
|
133 | - } else { |
|
134 | - $result['wide'][] = [ |
|
135 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
136 | - 'value' => [ |
|
137 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
138 | - 'shareWith' => $emailAddress, |
|
139 | - ], |
|
140 | - ]; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - if (!$this->shareeEnumeration) { |
|
147 | - $result['wide'] = []; |
|
148 | - } |
|
149 | - |
|
150 | - if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
151 | - $result['exact'][] = [ |
|
152 | - 'label' => $search, |
|
153 | - 'value' => [ |
|
154 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
155 | - 'shareWith' => $search, |
|
156 | - ], |
|
157 | - ]; |
|
158 | - } |
|
159 | - |
|
160 | - $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
161 | - |
|
162 | - return true; |
|
163 | - } |
|
36 | + protected $shareeEnumeration; |
|
37 | + |
|
38 | + /** @var IManager */ |
|
39 | + private $contactsManager; |
|
40 | + /** @var ICloudIdManager */ |
|
41 | + private $cloudIdManager; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + |
|
45 | + public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | + $this->contactsManager = $contactsManager; |
|
47 | + $this->cloudIdManager = $cloudIdManager; |
|
48 | + $this->config = $config; |
|
49 | + |
|
50 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param $search |
|
55 | + * @param $limit |
|
56 | + * @param $offset |
|
57 | + * @param ISearchResult $searchResult |
|
58 | + * @return bool |
|
59 | + * @since 13.0.0 |
|
60 | + */ |
|
61 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
62 | + $result = ['wide' => [], 'exact' => []]; |
|
63 | + $userType = new SearchResultType('users'); |
|
64 | + $emailType = new SearchResultType('emails'); |
|
65 | + |
|
66 | + // Search in contacts |
|
67 | + //@todo Pagination missing |
|
68 | + $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
69 | + $lowerSearch = strtolower($search); |
|
70 | + foreach ($addressBookContacts as $contact) { |
|
71 | + if (isset($contact['EMAIL'])) { |
|
72 | + $emailAddresses = $contact['EMAIL']; |
|
73 | + if (!is_array($emailAddresses)) { |
|
74 | + $emailAddresses = [$emailAddresses]; |
|
75 | + } |
|
76 | + foreach ($emailAddresses as $emailAddress) { |
|
77 | + $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
78 | + |
|
79 | + if (isset($contact['isLocalSystemBook'])) { |
|
80 | + if ($exactEmailMatch) { |
|
81 | + try { |
|
82 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + continue; |
|
85 | + } |
|
86 | + |
|
87 | + if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
88 | + $singleResult = [[ |
|
89 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
90 | + 'value' => [ |
|
91 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
92 | + 'shareWith' => $cloud->getUser(), |
|
93 | + ], |
|
94 | + ]]; |
|
95 | + $searchResult->addResultSet($userType, [], $singleResult); |
|
96 | + $searchResult->markExactIdMatch($emailType); |
|
97 | + } |
|
98 | + return false; |
|
99 | + } |
|
100 | + |
|
101 | + if ($this->shareeEnumeration) { |
|
102 | + try { |
|
103 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
104 | + } catch (\InvalidArgumentException $e) { |
|
105 | + continue; |
|
106 | + } |
|
107 | + |
|
108 | + if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
109 | + $singleResult = [[ |
|
110 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
111 | + 'value' => [ |
|
112 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
113 | + 'shareWith' => $cloud->getUser(), |
|
114 | + ]], |
|
115 | + ]; |
|
116 | + $searchResult->addResultSet($userType, $singleResult, []); |
|
117 | + } |
|
118 | + } |
|
119 | + continue; |
|
120 | + } |
|
121 | + |
|
122 | + if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) { |
|
123 | + if ($exactEmailMatch) { |
|
124 | + $searchResult->markExactIdMatch($emailType); |
|
125 | + } |
|
126 | + $result['exact'][] = [ |
|
127 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
128 | + 'value' => [ |
|
129 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
130 | + 'shareWith' => $emailAddress, |
|
131 | + ], |
|
132 | + ]; |
|
133 | + } else { |
|
134 | + $result['wide'][] = [ |
|
135 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
136 | + 'value' => [ |
|
137 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
138 | + 'shareWith' => $emailAddress, |
|
139 | + ], |
|
140 | + ]; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + if (!$this->shareeEnumeration) { |
|
147 | + $result['wide'] = []; |
|
148 | + } |
|
149 | + |
|
150 | + if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
151 | + $result['exact'][] = [ |
|
152 | + 'label' => $search, |
|
153 | + 'value' => [ |
|
154 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
155 | + 'shareWith' => $search, |
|
156 | + ], |
|
157 | + ]; |
|
158 | + } |
|
159 | + |
|
160 | + $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
161 | + |
|
162 | + return true; |
|
163 | + } |
|
164 | 164 | } |