@@ -25,61 +25,61 @@ |
||
25 | 25 | namespace OCA\Files_Sharing\Activity\Settings; |
26 | 26 | |
27 | 27 | class Shared extends ShareActivitySettings { |
28 | - /** |
|
29 | - * @return string Lowercase a-z and underscore only identifier |
|
30 | - * @since 11.0.0 |
|
31 | - */ |
|
32 | - public function getIdentifier() { |
|
33 | - return 'shared'; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return string Lowercase a-z and underscore only identifier |
|
30 | + * @since 11.0.0 |
|
31 | + */ |
|
32 | + public function getIdentifier() { |
|
33 | + return 'shared'; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string A translated string |
|
38 | - * @since 11.0.0 |
|
39 | - */ |
|
40 | - public function getName() { |
|
41 | - return $this->l->t('A file or folder has been <strong>shared</strong>'); |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return string A translated string |
|
38 | + * @since 11.0.0 |
|
39 | + */ |
|
40 | + public function getName() { |
|
41 | + return $this->l->t('A file or folder has been <strong>shared</strong>'); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return int whether the filter should be rather on the top or bottom of |
|
46 | - * the admin section. The filters are arranged in ascending order of the |
|
47 | - * priority values. It is required to return a value between 0 and 100. |
|
48 | - * @since 11.0.0 |
|
49 | - */ |
|
50 | - public function getPriority() { |
|
51 | - return 10; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return int whether the filter should be rather on the top or bottom of |
|
46 | + * the admin section. The filters are arranged in ascending order of the |
|
47 | + * priority values. It is required to return a value between 0 and 100. |
|
48 | + * @since 11.0.0 |
|
49 | + */ |
|
50 | + public function getPriority() { |
|
51 | + return 10; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return bool True when the option can be changed for the stream |
|
56 | - * @since 11.0.0 |
|
57 | - */ |
|
58 | - public function canChangeStream() { |
|
59 | - return true; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return bool True when the option can be changed for the stream |
|
56 | + * @since 11.0.0 |
|
57 | + */ |
|
58 | + public function canChangeStream() { |
|
59 | + return true; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return bool True when the option can be changed for the stream |
|
64 | - * @since 11.0.0 |
|
65 | - */ |
|
66 | - public function isDefaultEnabledStream() { |
|
67 | - return true; |
|
68 | - } |
|
62 | + /** |
|
63 | + * @return bool True when the option can be changed for the stream |
|
64 | + * @since 11.0.0 |
|
65 | + */ |
|
66 | + public function isDefaultEnabledStream() { |
|
67 | + return true; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return bool True when the option can be changed for the mail |
|
72 | - * @since 11.0.0 |
|
73 | - */ |
|
74 | - public function canChangeMail() { |
|
75 | - return true; |
|
76 | - } |
|
70 | + /** |
|
71 | + * @return bool True when the option can be changed for the mail |
|
72 | + * @since 11.0.0 |
|
73 | + */ |
|
74 | + public function canChangeMail() { |
|
75 | + return true; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return bool True when the option can be changed for the stream |
|
80 | - * @since 11.0.0 |
|
81 | - */ |
|
82 | - public function isDefaultEnabledMail() { |
|
83 | - return false; |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return bool True when the option can be changed for the stream |
|
80 | + * @since 11.0.0 |
|
81 | + */ |
|
82 | + public function isDefaultEnabledMail() { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | } |
@@ -25,61 +25,61 @@ |
||
25 | 25 | namespace OCA\Files_Sharing\Activity\Settings; |
26 | 26 | |
27 | 27 | class RemoteShare extends ShareActivitySettings { |
28 | - /** |
|
29 | - * @return string Lowercase a-z and underscore only identifier |
|
30 | - * @since 11.0.0 |
|
31 | - */ |
|
32 | - public function getIdentifier() { |
|
33 | - return 'remote_share'; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return string Lowercase a-z and underscore only identifier |
|
30 | + * @since 11.0.0 |
|
31 | + */ |
|
32 | + public function getIdentifier() { |
|
33 | + return 'remote_share'; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string A translated string |
|
38 | - * @since 11.0.0 |
|
39 | - */ |
|
40 | - public function getName() { |
|
41 | - return $this->l->t('A file or folder was shared from <strong>another server</strong>'); |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return string A translated string |
|
38 | + * @since 11.0.0 |
|
39 | + */ |
|
40 | + public function getName() { |
|
41 | + return $this->l->t('A file or folder was shared from <strong>another server</strong>'); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return int whether the filter should be rather on the top or bottom of |
|
46 | - * the admin section. The filters are arranged in ascending order of the |
|
47 | - * priority values. It is required to return a value between 0 and 100. |
|
48 | - * @since 11.0.0 |
|
49 | - */ |
|
50 | - public function getPriority() { |
|
51 | - return 11; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return int whether the filter should be rather on the top or bottom of |
|
46 | + * the admin section. The filters are arranged in ascending order of the |
|
47 | + * priority values. It is required to return a value between 0 and 100. |
|
48 | + * @since 11.0.0 |
|
49 | + */ |
|
50 | + public function getPriority() { |
|
51 | + return 11; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return bool True when the option can be changed for the stream |
|
56 | - * @since 11.0.0 |
|
57 | - */ |
|
58 | - public function canChangeStream() { |
|
59 | - return true; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return bool True when the option can be changed for the stream |
|
56 | + * @since 11.0.0 |
|
57 | + */ |
|
58 | + public function canChangeStream() { |
|
59 | + return true; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return bool True when the option can be changed for the stream |
|
64 | - * @since 11.0.0 |
|
65 | - */ |
|
66 | - public function isDefaultEnabledStream() { |
|
67 | - return true; |
|
68 | - } |
|
62 | + /** |
|
63 | + * @return bool True when the option can be changed for the stream |
|
64 | + * @since 11.0.0 |
|
65 | + */ |
|
66 | + public function isDefaultEnabledStream() { |
|
67 | + return true; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return bool True when the option can be changed for the mail |
|
72 | - * @since 11.0.0 |
|
73 | - */ |
|
74 | - public function canChangeMail() { |
|
75 | - return true; |
|
76 | - } |
|
70 | + /** |
|
71 | + * @return bool True when the option can be changed for the mail |
|
72 | + * @since 11.0.0 |
|
73 | + */ |
|
74 | + public function canChangeMail() { |
|
75 | + return true; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return bool True when the option can be changed for the stream |
|
80 | - * @since 11.0.0 |
|
81 | - */ |
|
82 | - public function isDefaultEnabledMail() { |
|
83 | - return false; |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return bool True when the option can be changed for the stream |
|
80 | + * @since 11.0.0 |
|
81 | + */ |
|
82 | + public function isDefaultEnabledMail() { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | } |
@@ -27,21 +27,21 @@ |
||
27 | 27 | use OCP\IL10N; |
28 | 28 | |
29 | 29 | abstract class ShareActivitySettings extends ActivitySettings { |
30 | - /** @var IL10N */ |
|
31 | - protected $l; |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IL10N $l |
|
35 | - */ |
|
36 | - public function __construct(IL10N $l) { |
|
37 | - $this->l = $l; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IL10N $l |
|
35 | + */ |
|
36 | + public function __construct(IL10N $l) { |
|
37 | + $this->l = $l; |
|
38 | + } |
|
39 | 39 | |
40 | - public function getGroupIdentifier() { |
|
41 | - return 'files'; |
|
42 | - } |
|
40 | + public function getGroupIdentifier() { |
|
41 | + return 'files'; |
|
42 | + } |
|
43 | 43 | |
44 | - public function getGroupName() { |
|
45 | - return $this->l->t('Files'); |
|
46 | - } |
|
44 | + public function getGroupName() { |
|
45 | + return $this->l->t('Files'); |
|
46 | + } |
|
47 | 47 | } |
@@ -35,97 +35,97 @@ |
||
35 | 35 | |
36 | 36 | class ChunkingPlugin extends ServerPlugin { |
37 | 37 | |
38 | - /** @var Server */ |
|
39 | - private $server; |
|
40 | - /** @var FutureFile */ |
|
41 | - private $sourceNode; |
|
38 | + /** @var Server */ |
|
39 | + private $server; |
|
40 | + /** @var FutureFile */ |
|
41 | + private $sourceNode; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function initialize(Server $server) { |
|
47 | - $server->on('beforeMove', [$this, 'beforeMove']); |
|
48 | - $this->server = $server; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function initialize(Server $server) { |
|
47 | + $server->on('beforeMove', [$this, 'beforeMove']); |
|
48 | + $this->server = $server; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $sourcePath source path |
|
53 | - * @param string $destination destination path |
|
54 | - * @return bool|void |
|
55 | - * @throws BadRequest |
|
56 | - * @throws NotFound |
|
57 | - */ |
|
58 | - public function beforeMove($sourcePath, $destination) { |
|
59 | - $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
60 | - if (!$this->sourceNode instanceof FutureFile) { |
|
61 | - // skip handling as the source is not a chunked FutureFile |
|
62 | - return; |
|
63 | - } |
|
51 | + /** |
|
52 | + * @param string $sourcePath source path |
|
53 | + * @param string $destination destination path |
|
54 | + * @return bool|void |
|
55 | + * @throws BadRequest |
|
56 | + * @throws NotFound |
|
57 | + */ |
|
58 | + public function beforeMove($sourcePath, $destination) { |
|
59 | + $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
60 | + if (!$this->sourceNode instanceof FutureFile) { |
|
61 | + // skip handling as the source is not a chunked FutureFile |
|
62 | + return; |
|
63 | + } |
|
64 | 64 | |
65 | - try { |
|
66 | - /** @var INode $destinationNode */ |
|
67 | - $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
68 | - if ($destinationNode instanceof Directory) { |
|
69 | - throw new BadRequest("The given destination $destination is a directory."); |
|
70 | - } |
|
71 | - } catch (NotFound $e) { |
|
72 | - // If the destination does not exist yet it's not a directory either ;) |
|
73 | - } |
|
65 | + try { |
|
66 | + /** @var INode $destinationNode */ |
|
67 | + $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
68 | + if ($destinationNode instanceof Directory) { |
|
69 | + throw new BadRequest("The given destination $destination is a directory."); |
|
70 | + } |
|
71 | + } catch (NotFound $e) { |
|
72 | + // If the destination does not exist yet it's not a directory either ;) |
|
73 | + } |
|
74 | 74 | |
75 | - $this->verifySize(); |
|
76 | - return $this->performMove($sourcePath, $destination); |
|
77 | - } |
|
75 | + $this->verifySize(); |
|
76 | + return $this->performMove($sourcePath, $destination); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Move handler for future file. |
|
81 | - * |
|
82 | - * This overrides the default move behavior to prevent Sabre |
|
83 | - * to delete the target file before moving. Because deleting would |
|
84 | - * lose the file id and metadata. |
|
85 | - * |
|
86 | - * @param string $path source path |
|
87 | - * @param string $destination destination path |
|
88 | - * @return bool|void false to stop handling, void to skip this handler |
|
89 | - */ |
|
90 | - public function performMove($path, $destination) { |
|
91 | - $fileExists = $this->server->tree->nodeExists($destination); |
|
92 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
93 | - try { |
|
94 | - $this->server->tree->move($path, $destination); |
|
95 | - } catch (Forbidden $e) { |
|
96 | - $sourceNode = $this->server->tree->getNodeForPath($path); |
|
97 | - if ($sourceNode instanceof FutureFile) { |
|
98 | - $sourceNode->delete(); |
|
99 | - } |
|
100 | - throw $e; |
|
101 | - } |
|
79 | + /** |
|
80 | + * Move handler for future file. |
|
81 | + * |
|
82 | + * This overrides the default move behavior to prevent Sabre |
|
83 | + * to delete the target file before moving. Because deleting would |
|
84 | + * lose the file id and metadata. |
|
85 | + * |
|
86 | + * @param string $path source path |
|
87 | + * @param string $destination destination path |
|
88 | + * @return bool|void false to stop handling, void to skip this handler |
|
89 | + */ |
|
90 | + public function performMove($path, $destination) { |
|
91 | + $fileExists = $this->server->tree->nodeExists($destination); |
|
92 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
93 | + try { |
|
94 | + $this->server->tree->move($path, $destination); |
|
95 | + } catch (Forbidden $e) { |
|
96 | + $sourceNode = $this->server->tree->getNodeForPath($path); |
|
97 | + if ($sourceNode instanceof FutureFile) { |
|
98 | + $sourceNode->delete(); |
|
99 | + } |
|
100 | + throw $e; |
|
101 | + } |
|
102 | 102 | |
103 | - // trigger all default events (copied from CorePlugin::move) |
|
104 | - $this->server->emit('afterMove', [$path, $destination]); |
|
105 | - $this->server->emit('afterUnbind', [$path]); |
|
106 | - $this->server->emit('afterBind', [$destination]); |
|
103 | + // trigger all default events (copied from CorePlugin::move) |
|
104 | + $this->server->emit('afterMove', [$path, $destination]); |
|
105 | + $this->server->emit('afterUnbind', [$path]); |
|
106 | + $this->server->emit('afterBind', [$destination]); |
|
107 | 107 | |
108 | - $response = $this->server->httpResponse; |
|
109 | - $response->setHeader('Content-Length', '0'); |
|
110 | - $response->setStatus($fileExists ? 204 : 201); |
|
108 | + $response = $this->server->httpResponse; |
|
109 | + $response->setHeader('Content-Length', '0'); |
|
110 | + $response->setStatus($fileExists ? 204 : 201); |
|
111 | 111 | |
112 | - return false; |
|
113 | - } |
|
112 | + return false; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @throws BadRequest |
|
117 | - */ |
|
118 | - private function verifySize() { |
|
119 | - $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
120 | - if ($expectedSize === null) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $actualSize = $this->sourceNode->getSize(); |
|
115 | + /** |
|
116 | + * @throws BadRequest |
|
117 | + */ |
|
118 | + private function verifySize() { |
|
119 | + $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
120 | + if ($expectedSize === null) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $actualSize = $this->sourceNode->getSize(); |
|
124 | 124 | |
125 | - // casted to string because cast to float cause equality for non equal numbers |
|
126 | - // and integer has the problem of limited size on 32 bit systems |
|
127 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
128 | - throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
129 | - } |
|
130 | - } |
|
125 | + // casted to string because cast to float cause equality for non equal numbers |
|
126 | + // and integer has the problem of limited size on 32 bit systems |
|
127 | + if ((string)$expectedSize !== (string)$actualSize) { |
|
128 | + throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |
@@ -31,45 +31,45 @@ |
||
31 | 31 | */ |
32 | 32 | trait UserTrait { |
33 | 33 | |
34 | - /** @var IUserSession */ |
|
35 | - protected $userSession; |
|
34 | + /** @var IUserSession */ |
|
35 | + protected $userSession; |
|
36 | 36 | |
37 | - /** |
|
38 | - * User override |
|
39 | - * |
|
40 | - * @var IUser|null |
|
41 | - */ |
|
42 | - private $user = null; |
|
37 | + /** |
|
38 | + * User override |
|
39 | + * |
|
40 | + * @var IUser|null |
|
41 | + */ |
|
42 | + private $user = null; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return IUser|null |
|
46 | - */ |
|
47 | - protected function getUser() { |
|
48 | - if ($this->user) { |
|
49 | - return $this->user; |
|
50 | - } |
|
51 | - return $this->userSession->getUser(); |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return IUser|null |
|
46 | + */ |
|
47 | + protected function getUser() { |
|
48 | + if ($this->user) { |
|
49 | + return $this->user; |
|
50 | + } |
|
51 | + return $this->userSession->getUser(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Override the user from the session |
|
56 | - * Unset with ->resetUser() when finished! |
|
57 | - * |
|
58 | - * @param IUser $user |
|
59 | - * @return self |
|
60 | - */ |
|
61 | - public function setUser(IUser $user) { |
|
62 | - $this->user = $user; |
|
63 | - return $this; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Override the user from the session |
|
56 | + * Unset with ->resetUser() when finished! |
|
57 | + * |
|
58 | + * @param IUser $user |
|
59 | + * @return self |
|
60 | + */ |
|
61 | + public function setUser(IUser $user) { |
|
62 | + $this->user = $user; |
|
63 | + return $this; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Reset the user override |
|
68 | - * |
|
69 | - * @return self |
|
70 | - */ |
|
71 | - public function resetUser() { |
|
72 | - $this->user = null; |
|
73 | - return $this; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Reset the user override |
|
68 | + * |
|
69 | + * @return self |
|
70 | + */ |
|
71 | + public function resetUser() { |
|
72 | + $this->user = null; |
|
73 | + return $this; |
|
74 | + } |
|
75 | 75 | } |
@@ -26,34 +26,34 @@ |
||
26 | 26 | use OCA\Encryption\Hooks\Contracts\IHook; |
27 | 27 | |
28 | 28 | class HookManager { |
29 | - /** @var IHook[] */ |
|
30 | - private $hookInstances = []; |
|
29 | + /** @var IHook[] */ |
|
30 | + private $hookInstances = []; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param array|IHook $instances |
|
34 | - * - This accepts either a single instance of IHook or an array of instances of IHook |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public function registerHook($instances) { |
|
38 | - if (is_array($instances)) { |
|
39 | - foreach ($instances as $instance) { |
|
40 | - if (!$instance instanceof IHook) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - $this->hookInstances[] = $instance; |
|
44 | - } |
|
45 | - } elseif ($instances instanceof IHook) { |
|
46 | - $this->hookInstances[] = $instances; |
|
47 | - } |
|
48 | - return true; |
|
49 | - } |
|
32 | + /** |
|
33 | + * @param array|IHook $instances |
|
34 | + * - This accepts either a single instance of IHook or an array of instances of IHook |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public function registerHook($instances) { |
|
38 | + if (is_array($instances)) { |
|
39 | + foreach ($instances as $instance) { |
|
40 | + if (!$instance instanceof IHook) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + $this->hookInstances[] = $instance; |
|
44 | + } |
|
45 | + } elseif ($instances instanceof IHook) { |
|
46 | + $this->hookInstances[] = $instances; |
|
47 | + } |
|
48 | + return true; |
|
49 | + } |
|
50 | 50 | |
51 | - public function fireHooks() { |
|
52 | - foreach ($this->hookInstances as $instance) { |
|
53 | - /** |
|
54 | - * Fire off the add hooks method of each instance stored in cache |
|
55 | - */ |
|
56 | - $instance->addHooks(); |
|
57 | - } |
|
58 | - } |
|
51 | + public function fireHooks() { |
|
52 | + foreach ($this->hookInstances as $instance) { |
|
53 | + /** |
|
54 | + * Fire off the add hooks method of each instance stored in cache |
|
55 | + */ |
|
56 | + $instance->addHooks(); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | } |
@@ -36,85 +36,85 @@ |
||
36 | 36 | * Provide an interface to all search providers |
37 | 37 | */ |
38 | 38 | class Search implements ISearch { |
39 | - /** @var Provider[] */ |
|
40 | - private $providers = []; |
|
41 | - private $registeredProviders = []; |
|
39 | + /** @var Provider[] */ |
|
40 | + private $providers = []; |
|
41 | + private $registeredProviders = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Search all providers for $query |
|
45 | - * @param string $query |
|
46 | - * @param string[] $inApps optionally limit results to the given apps |
|
47 | - * @param int $page pages start at page 1 |
|
48 | - * @param int $size, 0 = all |
|
49 | - * @return array An array of OC\Search\Result's |
|
50 | - */ |
|
51 | - public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) { |
|
52 | - $this->initProviders(); |
|
53 | - $results = []; |
|
54 | - foreach ($this->providers as $provider) { |
|
55 | - if (! $provider->providesResultsFor($inApps)) { |
|
56 | - continue; |
|
57 | - } |
|
58 | - if ($provider instanceof PagedProvider) { |
|
59 | - $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
60 | - } elseif ($provider instanceof Provider) { |
|
61 | - $providerResults = $provider->search($query); |
|
62 | - if ($size > 0) { |
|
63 | - $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
64 | - $results = array_merge($results, $slicedResults); |
|
65 | - } else { |
|
66 | - $results = array_merge($results, $providerResults); |
|
67 | - } |
|
68 | - } else { |
|
69 | - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]); |
|
70 | - } |
|
71 | - } |
|
72 | - return $results; |
|
73 | - } |
|
43 | + /** |
|
44 | + * Search all providers for $query |
|
45 | + * @param string $query |
|
46 | + * @param string[] $inApps optionally limit results to the given apps |
|
47 | + * @param int $page pages start at page 1 |
|
48 | + * @param int $size, 0 = all |
|
49 | + * @return array An array of OC\Search\Result's |
|
50 | + */ |
|
51 | + public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) { |
|
52 | + $this->initProviders(); |
|
53 | + $results = []; |
|
54 | + foreach ($this->providers as $provider) { |
|
55 | + if (! $provider->providesResultsFor($inApps)) { |
|
56 | + continue; |
|
57 | + } |
|
58 | + if ($provider instanceof PagedProvider) { |
|
59 | + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
60 | + } elseif ($provider instanceof Provider) { |
|
61 | + $providerResults = $provider->search($query); |
|
62 | + if ($size > 0) { |
|
63 | + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
64 | + $results = array_merge($results, $slicedResults); |
|
65 | + } else { |
|
66 | + $results = array_merge($results, $providerResults); |
|
67 | + } |
|
68 | + } else { |
|
69 | + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]); |
|
70 | + } |
|
71 | + } |
|
72 | + return $results; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Remove all registered search providers |
|
77 | - */ |
|
78 | - public function clearProviders() { |
|
79 | - $this->providers = []; |
|
80 | - $this->registeredProviders = []; |
|
81 | - } |
|
75 | + /** |
|
76 | + * Remove all registered search providers |
|
77 | + */ |
|
78 | + public function clearProviders() { |
|
79 | + $this->providers = []; |
|
80 | + $this->registeredProviders = []; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Remove one existing search provider |
|
85 | - * @param string $provider class name of a OC\Search\Provider |
|
86 | - */ |
|
87 | - public function removeProvider($provider) { |
|
88 | - $this->registeredProviders = array_filter( |
|
89 | - $this->registeredProviders, |
|
90 | - function ($element) use ($provider) { |
|
91 | - return ($element['class'] != $provider); |
|
92 | - } |
|
93 | - ); |
|
94 | - // force regeneration of providers on next search |
|
95 | - $this->providers = []; |
|
96 | - } |
|
83 | + /** |
|
84 | + * Remove one existing search provider |
|
85 | + * @param string $provider class name of a OC\Search\Provider |
|
86 | + */ |
|
87 | + public function removeProvider($provider) { |
|
88 | + $this->registeredProviders = array_filter( |
|
89 | + $this->registeredProviders, |
|
90 | + function ($element) use ($provider) { |
|
91 | + return ($element['class'] != $provider); |
|
92 | + } |
|
93 | + ); |
|
94 | + // force regeneration of providers on next search |
|
95 | + $this->providers = []; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Register a new search provider to search with |
|
100 | - * @param string $class class name of a OC\Search\Provider |
|
101 | - * @param array $options optional |
|
102 | - */ |
|
103 | - public function registerProvider($class, array $options = []) { |
|
104 | - $this->registeredProviders[] = ['class' => $class, 'options' => $options]; |
|
105 | - } |
|
98 | + /** |
|
99 | + * Register a new search provider to search with |
|
100 | + * @param string $class class name of a OC\Search\Provider |
|
101 | + * @param array $options optional |
|
102 | + */ |
|
103 | + public function registerProvider($class, array $options = []) { |
|
104 | + $this->registeredProviders[] = ['class' => $class, 'options' => $options]; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Create instances of all the registered search providers |
|
109 | - */ |
|
110 | - private function initProviders() { |
|
111 | - if (! empty($this->providers)) { |
|
112 | - return; |
|
113 | - } |
|
114 | - foreach ($this->registeredProviders as $provider) { |
|
115 | - $class = $provider['class']; |
|
116 | - $options = $provider['options']; |
|
117 | - $this->providers[] = new $class($options); |
|
118 | - } |
|
119 | - } |
|
107 | + /** |
|
108 | + * Create instances of all the registered search providers |
|
109 | + */ |
|
110 | + private function initProviders() { |
|
111 | + if (! empty($this->providers)) { |
|
112 | + return; |
|
113 | + } |
|
114 | + foreach ($this->registeredProviders as $provider) { |
|
115 | + $class = $provider['class']; |
|
116 | + $options = $provider['options']; |
|
117 | + $this->providers[] = new $class($options); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | /** @var \OCP\Defaults $theme */ |
5 | 5 | // @codeCoverageIgnoreStart |
6 | 6 | if (!isset($_)) {//standalone page is not supported anymore - redirect to / |
7 | - require_once '../../lib/base.php'; |
|
7 | + require_once '../../lib/base.php'; |
|
8 | 8 | |
9 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
10 | - header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
11 | - exit; |
|
9 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
10 | + header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
11 | + exit; |
|
12 | 12 | } |
13 | 13 | // @codeCoverageIgnoreEnd |
14 | 14 | ?> |
@@ -33,76 +33,76 @@ |
||
33 | 33 | |
34 | 34 | class AppSearch implements IProvider { |
35 | 35 | |
36 | - /** @var INavigationManager */ |
|
37 | - protected $navigationManager; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - |
|
42 | - public function __construct(INavigationManager $navigationManager, |
|
43 | - IL10N $l) { |
|
44 | - $this->navigationManager = $navigationManager; |
|
45 | - $this->l = $l; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @inheritDoc |
|
50 | - */ |
|
51 | - public function getId(): string { |
|
52 | - return 'settings_apps'; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @inheritDoc |
|
57 | - */ |
|
58 | - public function getName(): string { |
|
59 | - return $this->l->t('Apps'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @inheritDoc |
|
64 | - */ |
|
65 | - public function getOrder(string $route, array $routeParameters): int { |
|
66 | - return -50; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @inheritDoc |
|
71 | - */ |
|
72 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
73 | - $entries = $this->navigationManager->getAll('all'); |
|
74 | - |
|
75 | - $result = []; |
|
76 | - foreach ($entries as $entry) { |
|
77 | - if ( |
|
78 | - stripos($entry['name'], $query->getTerm()) === false && |
|
79 | - stripos($entry['id'], $query->getTerm()) === false |
|
80 | - ) { |
|
81 | - continue; |
|
82 | - } |
|
83 | - |
|
84 | - if (strpos($query->getRoute(), $entry['id'] . '.') === 0) { |
|
85 | - // Skip the current app, unlikely this is intended |
|
86 | - continue; |
|
87 | - } |
|
88 | - |
|
89 | - if ($entry['href'] === '') { |
|
90 | - // Nothing we can open, so ignore |
|
91 | - continue; |
|
92 | - } |
|
93 | - |
|
94 | - $result[] = new SearchResultEntry( |
|
95 | - '', |
|
96 | - $entry['name'], |
|
97 | - '', |
|
98 | - $entry['href'], |
|
99 | - 'icon-confirm' |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - return SearchResult::complete( |
|
104 | - $this->l->t('Apps'), |
|
105 | - $result |
|
106 | - ); |
|
107 | - } |
|
36 | + /** @var INavigationManager */ |
|
37 | + protected $navigationManager; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + |
|
42 | + public function __construct(INavigationManager $navigationManager, |
|
43 | + IL10N $l) { |
|
44 | + $this->navigationManager = $navigationManager; |
|
45 | + $this->l = $l; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @inheritDoc |
|
50 | + */ |
|
51 | + public function getId(): string { |
|
52 | + return 'settings_apps'; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @inheritDoc |
|
57 | + */ |
|
58 | + public function getName(): string { |
|
59 | + return $this->l->t('Apps'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @inheritDoc |
|
64 | + */ |
|
65 | + public function getOrder(string $route, array $routeParameters): int { |
|
66 | + return -50; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @inheritDoc |
|
71 | + */ |
|
72 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
73 | + $entries = $this->navigationManager->getAll('all'); |
|
74 | + |
|
75 | + $result = []; |
|
76 | + foreach ($entries as $entry) { |
|
77 | + if ( |
|
78 | + stripos($entry['name'], $query->getTerm()) === false && |
|
79 | + stripos($entry['id'], $query->getTerm()) === false |
|
80 | + ) { |
|
81 | + continue; |
|
82 | + } |
|
83 | + |
|
84 | + if (strpos($query->getRoute(), $entry['id'] . '.') === 0) { |
|
85 | + // Skip the current app, unlikely this is intended |
|
86 | + continue; |
|
87 | + } |
|
88 | + |
|
89 | + if ($entry['href'] === '') { |
|
90 | + // Nothing we can open, so ignore |
|
91 | + continue; |
|
92 | + } |
|
93 | + |
|
94 | + $result[] = new SearchResultEntry( |
|
95 | + '', |
|
96 | + $entry['name'], |
|
97 | + '', |
|
98 | + $entry['href'], |
|
99 | + 'icon-confirm' |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + return SearchResult::complete( |
|
104 | + $this->l->t('Apps'), |
|
105 | + $result |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | } |