@@ -67,7 +67,7 @@ |
||
67 | 67 | * compared with \OC\Group\Backend::CREATE_GROUP etc. |
68 | 68 | */ |
69 | 69 | public function implementsActions($actions) { |
70 | - return (bool)($this->getSupportedActions() & $actions); |
|
70 | + return (bool) ($this->getSupportedActions() & $actions); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -29,107 +29,107 @@ |
||
29 | 29 | * Abstract base class for user management |
30 | 30 | */ |
31 | 31 | abstract class Backend implements \OCP\GroupInterface { |
32 | - /** |
|
33 | - * error code for functions not provided by the group backend |
|
34 | - */ |
|
35 | - public const NOT_IMPLEMENTED = -501; |
|
32 | + /** |
|
33 | + * error code for functions not provided by the group backend |
|
34 | + */ |
|
35 | + public const NOT_IMPLEMENTED = -501; |
|
36 | 36 | |
37 | - protected $possibleActions = [ |
|
38 | - self::CREATE_GROUP => 'createGroup', |
|
39 | - self::DELETE_GROUP => 'deleteGroup', |
|
40 | - self::ADD_TO_GROUP => 'addToGroup', |
|
41 | - self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
42 | - self::COUNT_USERS => 'countUsersInGroup', |
|
43 | - self::GROUP_DETAILS => 'getGroupDetails', |
|
44 | - self::IS_ADMIN => 'isAdmin', |
|
45 | - ]; |
|
37 | + protected $possibleActions = [ |
|
38 | + self::CREATE_GROUP => 'createGroup', |
|
39 | + self::DELETE_GROUP => 'deleteGroup', |
|
40 | + self::ADD_TO_GROUP => 'addToGroup', |
|
41 | + self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
42 | + self::COUNT_USERS => 'countUsersInGroup', |
|
43 | + self::GROUP_DETAILS => 'getGroupDetails', |
|
44 | + self::IS_ADMIN => 'isAdmin', |
|
45 | + ]; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get all supported actions |
|
49 | - * @return int bitwise-or'ed actions |
|
50 | - * |
|
51 | - * Returns the supported actions as int to be |
|
52 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
53 | - */ |
|
54 | - public function getSupportedActions() { |
|
55 | - $actions = 0; |
|
56 | - foreach ($this->possibleActions as $action => $methodName) { |
|
57 | - if (method_exists($this, $methodName)) { |
|
58 | - $actions |= $action; |
|
59 | - } |
|
60 | - } |
|
47 | + /** |
|
48 | + * Get all supported actions |
|
49 | + * @return int bitwise-or'ed actions |
|
50 | + * |
|
51 | + * Returns the supported actions as int to be |
|
52 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
53 | + */ |
|
54 | + public function getSupportedActions() { |
|
55 | + $actions = 0; |
|
56 | + foreach ($this->possibleActions as $action => $methodName) { |
|
57 | + if (method_exists($this, $methodName)) { |
|
58 | + $actions |= $action; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - return $actions; |
|
63 | - } |
|
62 | + return $actions; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Check if backend implements actions |
|
67 | - * @param int $actions bitwise-or'ed actions |
|
68 | - * @return bool |
|
69 | - * |
|
70 | - * Returns the supported actions as int to be |
|
71 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
72 | - */ |
|
73 | - public function implementsActions($actions) { |
|
74 | - return (bool)($this->getSupportedActions() & $actions); |
|
75 | - } |
|
65 | + /** |
|
66 | + * Check if backend implements actions |
|
67 | + * @param int $actions bitwise-or'ed actions |
|
68 | + * @return bool |
|
69 | + * |
|
70 | + * Returns the supported actions as int to be |
|
71 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
72 | + */ |
|
73 | + public function implementsActions($actions) { |
|
74 | + return (bool)($this->getSupportedActions() & $actions); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * is user in group? |
|
79 | - * @param string $uid uid of the user |
|
80 | - * @param string $gid gid of the group |
|
81 | - * @return bool |
|
82 | - * |
|
83 | - * Checks whether the user is member of a group or not. |
|
84 | - */ |
|
85 | - public function inGroup($uid, $gid) { |
|
86 | - return in_array($gid, $this->getUserGroups($uid)); |
|
87 | - } |
|
77 | + /** |
|
78 | + * is user in group? |
|
79 | + * @param string $uid uid of the user |
|
80 | + * @param string $gid gid of the group |
|
81 | + * @return bool |
|
82 | + * |
|
83 | + * Checks whether the user is member of a group or not. |
|
84 | + */ |
|
85 | + public function inGroup($uid, $gid) { |
|
86 | + return in_array($gid, $this->getUserGroups($uid)); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Get all groups a user belongs to |
|
91 | - * @param string $uid Name of the user |
|
92 | - * @return array an array of group names |
|
93 | - * |
|
94 | - * This function fetches all groups a user belongs to. It does not check |
|
95 | - * if the user exists at all. |
|
96 | - */ |
|
97 | - public function getUserGroups($uid) { |
|
98 | - return []; |
|
99 | - } |
|
89 | + /** |
|
90 | + * Get all groups a user belongs to |
|
91 | + * @param string $uid Name of the user |
|
92 | + * @return array an array of group names |
|
93 | + * |
|
94 | + * This function fetches all groups a user belongs to. It does not check |
|
95 | + * if the user exists at all. |
|
96 | + */ |
|
97 | + public function getUserGroups($uid) { |
|
98 | + return []; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * get a list of all groups |
|
103 | - * @param string $search |
|
104 | - * @param int $limit |
|
105 | - * @param int $offset |
|
106 | - * @return array an array of group names |
|
107 | - * |
|
108 | - * Returns a list with all groups |
|
109 | - */ |
|
101 | + /** |
|
102 | + * get a list of all groups |
|
103 | + * @param string $search |
|
104 | + * @param int $limit |
|
105 | + * @param int $offset |
|
106 | + * @return array an array of group names |
|
107 | + * |
|
108 | + * Returns a list with all groups |
|
109 | + */ |
|
110 | 110 | |
111 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
112 | - return []; |
|
113 | - } |
|
111 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
112 | + return []; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * check if a group exists |
|
117 | - * @param string $gid |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function groupExists($gid) { |
|
121 | - return in_array($gid, $this->getGroups($gid, 1)); |
|
122 | - } |
|
115 | + /** |
|
116 | + * check if a group exists |
|
117 | + * @param string $gid |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function groupExists($gid) { |
|
121 | + return in_array($gid, $this->getGroups($gid, 1)); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * get a list of all users in a group |
|
126 | - * @param string $gid |
|
127 | - * @param string $search |
|
128 | - * @param int $limit |
|
129 | - * @param int $offset |
|
130 | - * @return array an array of user ids |
|
131 | - */ |
|
132 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
133 | - return []; |
|
134 | - } |
|
124 | + /** |
|
125 | + * get a list of all users in a group |
|
126 | + * @param string $gid |
|
127 | + * @param string $search |
|
128 | + * @param int $limit |
|
129 | + * @param int $offset |
|
130 | + * @return array an array of user ids |
|
131 | + */ |
|
132 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
133 | + return []; |
|
134 | + } |
|
135 | 135 | } |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | |
134 | 134 | // Check that all parameters from $event exist in $previousEvent |
135 | 135 | foreach ($params1 as $key => $parameter) { |
136 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
136 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
137 | 137 | if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
138 | 138 | $combined++; |
139 | - $params[$mergeParameter . $combined] = $parameter; |
|
139 | + $params[$mergeParameter.$combined] = $parameter; |
|
140 | 140 | } |
141 | 141 | continue; |
142 | 142 | } |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | |
152 | 152 | // Check that all parameters from $previousEvent exist in $event |
153 | 153 | foreach ($params2 as $key => $parameter) { |
154 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
154 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
155 | 155 | if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
156 | 156 | $combined++; |
157 | - $params[$mergeParameter . $combined] = $parameter; |
|
157 | + $params[$mergeParameter.$combined] = $parameter; |
|
158 | 158 | } |
159 | 159 | continue; |
160 | 160 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
180 | 180 | foreach ($parameters as $key => $param) { |
181 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
181 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
182 | 182 | if ($param === $parameter) { |
183 | 183 | return true; |
184 | 184 | } |
@@ -196,30 +196,30 @@ discard block |
||
196 | 196 | protected function getExtendedSubject($subject, $parameter, $counter) { |
197 | 197 | switch ($counter) { |
198 | 198 | case 1: |
199 | - $replacement = '{' . $parameter . '1}'; |
|
199 | + $replacement = '{'.$parameter.'1}'; |
|
200 | 200 | break; |
201 | 201 | case 2: |
202 | 202 | $replacement = $this->l10n->t( |
203 | 203 | '%1$s and %2$s', |
204 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
204 | + ['{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
205 | 205 | ); |
206 | 206 | break; |
207 | 207 | case 3: |
208 | 208 | $replacement = $this->l10n->t( |
209 | 209 | '%1$s, %2$s and %3$s', |
210 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
210 | + ['{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
211 | 211 | ); |
212 | 212 | break; |
213 | 213 | case 4: |
214 | 214 | $replacement = $this->l10n->t( |
215 | 215 | '%1$s, %2$s, %3$s and %4$s', |
216 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
216 | + ['{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
217 | 217 | ); |
218 | 218 | break; |
219 | 219 | case 5: |
220 | 220 | $replacement = $this->l10n->t( |
221 | 221 | '%1$s, %2$s, %3$s, %4$s and %5$s', |
222 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
222 | + ['{'.$parameter.'5}', '{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
223 | 223 | ); |
224 | 224 | break; |
225 | 225 | default: |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | return str_replace( |
230 | - '{' . $parameter . '}', |
|
230 | + '{'.$parameter.'}', |
|
231 | 231 | $replacement, |
232 | 232 | $subject |
233 | 233 | ); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | protected function generateParsedSubject($subject, $parameters) { |
242 | 242 | $placeholders = $replacements = []; |
243 | 243 | foreach ($parameters as $placeholder => $parameter) { |
244 | - $placeholders[] = '{' . $placeholder . '}'; |
|
244 | + $placeholders[] = '{'.$placeholder.'}'; |
|
245 | 245 | if ($parameter['type'] === 'file') { |
246 | 246 | $replacements[] = trim($parameter['path'], '/'); |
247 | 247 | } elseif (isset($parameter['name'])) { |
@@ -30,231 +30,231 @@ |
||
30 | 30 | |
31 | 31 | class EventMerger implements IEventMerger { |
32 | 32 | |
33 | - /** @var IL10N */ |
|
34 | - protected $l10n; |
|
33 | + /** @var IL10N */ |
|
34 | + protected $l10n; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param IL10N $l10n |
|
38 | - */ |
|
39 | - public function __construct(IL10N $l10n) { |
|
40 | - $this->l10n = $l10n; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param IL10N $l10n |
|
38 | + */ |
|
39 | + public function __construct(IL10N $l10n) { |
|
40 | + $this->l10n = $l10n; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Combines two events when possible to have grouping: |
|
45 | - * |
|
46 | - * Example1: Two events with subject '{user} created {file}' and |
|
47 | - * $mergeParameter file with different file and same user will be merged |
|
48 | - * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
49 | - * will be set, if the events have been merged. |
|
50 | - * |
|
51 | - * Example2: Two events with subject '{user} created {file}' and |
|
52 | - * $mergeParameter file with same file and same user will be merged to |
|
53 | - * '{user} created {file1}' and the childEvent on the return will be set, if |
|
54 | - * the events have been merged. |
|
55 | - * |
|
56 | - * The following requirements have to be met, in order to be merged: |
|
57 | - * - Both events need to have the same `getApp()` |
|
58 | - * - Both events must not have a message `getMessage()` |
|
59 | - * - Both events need to have the same subject `getSubject()` |
|
60 | - * - Both events need to have the same object type `getObjectType()` |
|
61 | - * - The time difference between both events must not be bigger then 3 hours |
|
62 | - * - Only up to 5 events can be merged. |
|
63 | - * - All parameters apart from such starting with $mergeParameter must be |
|
64 | - * the same for both events. |
|
65 | - * |
|
66 | - * @param string $mergeParameter |
|
67 | - * @param IEvent $event |
|
68 | - * @param IEvent|null $previousEvent |
|
69 | - * @return IEvent |
|
70 | - */ |
|
71 | - public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
72 | - // No second event => can not combine |
|
73 | - if (!$previousEvent instanceof IEvent) { |
|
74 | - return $event; |
|
75 | - } |
|
43 | + /** |
|
44 | + * Combines two events when possible to have grouping: |
|
45 | + * |
|
46 | + * Example1: Two events with subject '{user} created {file}' and |
|
47 | + * $mergeParameter file with different file and same user will be merged |
|
48 | + * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
49 | + * will be set, if the events have been merged. |
|
50 | + * |
|
51 | + * Example2: Two events with subject '{user} created {file}' and |
|
52 | + * $mergeParameter file with same file and same user will be merged to |
|
53 | + * '{user} created {file1}' and the childEvent on the return will be set, if |
|
54 | + * the events have been merged. |
|
55 | + * |
|
56 | + * The following requirements have to be met, in order to be merged: |
|
57 | + * - Both events need to have the same `getApp()` |
|
58 | + * - Both events must not have a message `getMessage()` |
|
59 | + * - Both events need to have the same subject `getSubject()` |
|
60 | + * - Both events need to have the same object type `getObjectType()` |
|
61 | + * - The time difference between both events must not be bigger then 3 hours |
|
62 | + * - Only up to 5 events can be merged. |
|
63 | + * - All parameters apart from such starting with $mergeParameter must be |
|
64 | + * the same for both events. |
|
65 | + * |
|
66 | + * @param string $mergeParameter |
|
67 | + * @param IEvent $event |
|
68 | + * @param IEvent|null $previousEvent |
|
69 | + * @return IEvent |
|
70 | + */ |
|
71 | + public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
72 | + // No second event => can not combine |
|
73 | + if (!$previousEvent instanceof IEvent) { |
|
74 | + return $event; |
|
75 | + } |
|
76 | 76 | |
77 | - // Different app => can not combine |
|
78 | - if ($event->getApp() !== $previousEvent->getApp()) { |
|
79 | - return $event; |
|
80 | - } |
|
77 | + // Different app => can not combine |
|
78 | + if ($event->getApp() !== $previousEvent->getApp()) { |
|
79 | + return $event; |
|
80 | + } |
|
81 | 81 | |
82 | - // Message is set => can not combine |
|
83 | - if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
84 | - return $event; |
|
85 | - } |
|
82 | + // Message is set => can not combine |
|
83 | + if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
84 | + return $event; |
|
85 | + } |
|
86 | 86 | |
87 | - // Different subject => can not combine |
|
88 | - if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
89 | - return $event; |
|
90 | - } |
|
87 | + // Different subject => can not combine |
|
88 | + if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
89 | + return $event; |
|
90 | + } |
|
91 | 91 | |
92 | - // Different object type => can not combine |
|
93 | - if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
94 | - return $event; |
|
95 | - } |
|
92 | + // Different object type => can not combine |
|
93 | + if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
94 | + return $event; |
|
95 | + } |
|
96 | 96 | |
97 | - // More than 3 hours difference => can not combine |
|
98 | - if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
99 | - return $event; |
|
100 | - } |
|
97 | + // More than 3 hours difference => can not combine |
|
98 | + if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
99 | + return $event; |
|
100 | + } |
|
101 | 101 | |
102 | - // Other parameters are not the same => can not combine |
|
103 | - try { |
|
104 | - list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
105 | - } catch (\UnexpectedValueException $e) { |
|
106 | - return $event; |
|
107 | - } |
|
102 | + // Other parameters are not the same => can not combine |
|
103 | + try { |
|
104 | + list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
105 | + } catch (\UnexpectedValueException $e) { |
|
106 | + return $event; |
|
107 | + } |
|
108 | 108 | |
109 | - try { |
|
110 | - $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
111 | - $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
109 | + try { |
|
110 | + $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
111 | + $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
112 | 112 | |
113 | - $event->setRichSubject($newSubject, $parameters) |
|
114 | - ->setParsedSubject($parsedSubject) |
|
115 | - ->setChildEvent($previousEvent) |
|
116 | - ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
117 | - } catch (\UnexpectedValueException $e) { |
|
118 | - return $event; |
|
119 | - } |
|
113 | + $event->setRichSubject($newSubject, $parameters) |
|
114 | + ->setParsedSubject($parsedSubject) |
|
115 | + ->setChildEvent($previousEvent) |
|
116 | + ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
117 | + } catch (\UnexpectedValueException $e) { |
|
118 | + return $event; |
|
119 | + } |
|
120 | 120 | |
121 | - return $event; |
|
122 | - } |
|
121 | + return $event; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @param string $mergeParameter |
|
126 | - * @param IEvent $event |
|
127 | - * @param IEvent $previousEvent |
|
128 | - * @return array |
|
129 | - * @throws \UnexpectedValueException |
|
130 | - */ |
|
131 | - protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
132 | - $params1 = $event->getRichSubjectParameters(); |
|
133 | - $params2 = $previousEvent->getRichSubjectParameters(); |
|
134 | - $params = []; |
|
124 | + /** |
|
125 | + * @param string $mergeParameter |
|
126 | + * @param IEvent $event |
|
127 | + * @param IEvent $previousEvent |
|
128 | + * @return array |
|
129 | + * @throws \UnexpectedValueException |
|
130 | + */ |
|
131 | + protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
132 | + $params1 = $event->getRichSubjectParameters(); |
|
133 | + $params2 = $previousEvent->getRichSubjectParameters(); |
|
134 | + $params = []; |
|
135 | 135 | |
136 | - $combined = 0; |
|
136 | + $combined = 0; |
|
137 | 137 | |
138 | - // Check that all parameters from $event exist in $previousEvent |
|
139 | - foreach ($params1 as $key => $parameter) { |
|
140 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
141 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
142 | - $combined++; |
|
143 | - $params[$mergeParameter . $combined] = $parameter; |
|
144 | - } |
|
145 | - continue; |
|
146 | - } |
|
138 | + // Check that all parameters from $event exist in $previousEvent |
|
139 | + foreach ($params1 as $key => $parameter) { |
|
140 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
141 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
142 | + $combined++; |
|
143 | + $params[$mergeParameter . $combined] = $parameter; |
|
144 | + } |
|
145 | + continue; |
|
146 | + } |
|
147 | 147 | |
148 | - if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
149 | - // Parameter missing on $previousEvent or different => can not combine |
|
150 | - throw new \UnexpectedValueException(); |
|
151 | - } |
|
148 | + if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
149 | + // Parameter missing on $previousEvent or different => can not combine |
|
150 | + throw new \UnexpectedValueException(); |
|
151 | + } |
|
152 | 152 | |
153 | - $params[$key] = $parameter; |
|
154 | - } |
|
153 | + $params[$key] = $parameter; |
|
154 | + } |
|
155 | 155 | |
156 | - // Check that all parameters from $previousEvent exist in $event |
|
157 | - foreach ($params2 as $key => $parameter) { |
|
158 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
159 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
160 | - $combined++; |
|
161 | - $params[$mergeParameter . $combined] = $parameter; |
|
162 | - } |
|
163 | - continue; |
|
164 | - } |
|
156 | + // Check that all parameters from $previousEvent exist in $event |
|
157 | + foreach ($params2 as $key => $parameter) { |
|
158 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
159 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
160 | + $combined++; |
|
161 | + $params[$mergeParameter . $combined] = $parameter; |
|
162 | + } |
|
163 | + continue; |
|
164 | + } |
|
165 | 165 | |
166 | - if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
167 | - // Parameter missing on $event or different => can not combine |
|
168 | - throw new \UnexpectedValueException(); |
|
169 | - } |
|
166 | + if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
167 | + // Parameter missing on $event or different => can not combine |
|
168 | + throw new \UnexpectedValueException(); |
|
169 | + } |
|
170 | 170 | |
171 | - $params[$key] = $parameter; |
|
172 | - } |
|
171 | + $params[$key] = $parameter; |
|
172 | + } |
|
173 | 173 | |
174 | - return [$combined, $params]; |
|
175 | - } |
|
174 | + return [$combined, $params]; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @param array[] $parameters |
|
179 | - * @param string $mergeParameter |
|
180 | - * @param array $parameter |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
184 | - foreach ($parameters as $key => $param) { |
|
185 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
186 | - if ($param === $parameter) { |
|
187 | - return true; |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - return false; |
|
192 | - } |
|
177 | + /** |
|
178 | + * @param array[] $parameters |
|
179 | + * @param string $mergeParameter |
|
180 | + * @param array $parameter |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
184 | + foreach ($parameters as $key => $param) { |
|
185 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
186 | + if ($param === $parameter) { |
|
187 | + return true; |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + return false; |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @param string $subject |
|
196 | - * @param string $parameter |
|
197 | - * @param int $counter |
|
198 | - * @return mixed |
|
199 | - */ |
|
200 | - protected function getExtendedSubject($subject, $parameter, $counter) { |
|
201 | - switch ($counter) { |
|
202 | - case 1: |
|
203 | - $replacement = '{' . $parameter . '1}'; |
|
204 | - break; |
|
205 | - case 2: |
|
206 | - $replacement = $this->l10n->t( |
|
207 | - '%1$s and %2$s', |
|
208 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
209 | - ); |
|
210 | - break; |
|
211 | - case 3: |
|
212 | - $replacement = $this->l10n->t( |
|
213 | - '%1$s, %2$s and %3$s', |
|
214 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
215 | - ); |
|
216 | - break; |
|
217 | - case 4: |
|
218 | - $replacement = $this->l10n->t( |
|
219 | - '%1$s, %2$s, %3$s and %4$s', |
|
220 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
221 | - ); |
|
222 | - break; |
|
223 | - case 5: |
|
224 | - $replacement = $this->l10n->t( |
|
225 | - '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
226 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
227 | - ); |
|
228 | - break; |
|
229 | - default: |
|
230 | - throw new \UnexpectedValueException(); |
|
231 | - } |
|
194 | + /** |
|
195 | + * @param string $subject |
|
196 | + * @param string $parameter |
|
197 | + * @param int $counter |
|
198 | + * @return mixed |
|
199 | + */ |
|
200 | + protected function getExtendedSubject($subject, $parameter, $counter) { |
|
201 | + switch ($counter) { |
|
202 | + case 1: |
|
203 | + $replacement = '{' . $parameter . '1}'; |
|
204 | + break; |
|
205 | + case 2: |
|
206 | + $replacement = $this->l10n->t( |
|
207 | + '%1$s and %2$s', |
|
208 | + ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
209 | + ); |
|
210 | + break; |
|
211 | + case 3: |
|
212 | + $replacement = $this->l10n->t( |
|
213 | + '%1$s, %2$s and %3$s', |
|
214 | + ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
215 | + ); |
|
216 | + break; |
|
217 | + case 4: |
|
218 | + $replacement = $this->l10n->t( |
|
219 | + '%1$s, %2$s, %3$s and %4$s', |
|
220 | + ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
221 | + ); |
|
222 | + break; |
|
223 | + case 5: |
|
224 | + $replacement = $this->l10n->t( |
|
225 | + '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
226 | + ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
227 | + ); |
|
228 | + break; |
|
229 | + default: |
|
230 | + throw new \UnexpectedValueException(); |
|
231 | + } |
|
232 | 232 | |
233 | - return str_replace( |
|
234 | - '{' . $parameter . '}', |
|
235 | - $replacement, |
|
236 | - $subject |
|
237 | - ); |
|
238 | - } |
|
233 | + return str_replace( |
|
234 | + '{' . $parameter . '}', |
|
235 | + $replacement, |
|
236 | + $subject |
|
237 | + ); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * @param string $subject |
|
242 | - * @param array[] $parameters |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function generateParsedSubject($subject, $parameters) { |
|
246 | - $placeholders = $replacements = []; |
|
247 | - foreach ($parameters as $placeholder => $parameter) { |
|
248 | - $placeholders[] = '{' . $placeholder . '}'; |
|
249 | - if ($parameter['type'] === 'file') { |
|
250 | - $replacements[] = trim($parameter['path'], '/'); |
|
251 | - } elseif (isset($parameter['name'])) { |
|
252 | - $replacements[] = $parameter['name']; |
|
253 | - } else { |
|
254 | - $replacements[] = $parameter['id']; |
|
255 | - } |
|
256 | - } |
|
240 | + /** |
|
241 | + * @param string $subject |
|
242 | + * @param array[] $parameters |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function generateParsedSubject($subject, $parameters) { |
|
246 | + $placeholders = $replacements = []; |
|
247 | + foreach ($parameters as $placeholder => $parameter) { |
|
248 | + $placeholders[] = '{' . $placeholder . '}'; |
|
249 | + if ($parameter['type'] === 'file') { |
|
250 | + $replacements[] = trim($parameter['path'], '/'); |
|
251 | + } elseif (isset($parameter['name'])) { |
|
252 | + $replacements[] = $parameter['name']; |
|
253 | + } else { |
|
254 | + $replacements[] = $parameter['id']; |
|
255 | + } |
|
256 | + } |
|
257 | 257 | |
258 | - return str_replace($placeholders, $replacements, $subject); |
|
259 | - } |
|
258 | + return str_replace($placeholders, $replacements, $subject); |
|
259 | + } |
|
260 | 260 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | * @return IEntry[] |
90 | 90 | */ |
91 | 91 | private function sortEntries(array $entries) { |
92 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
92 | + usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
93 | 93 | return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
94 | 94 | }); |
95 | 95 | return $entries; |
@@ -34,90 +34,90 @@ |
||
34 | 34 | |
35 | 35 | class Manager { |
36 | 36 | |
37 | - /** @var ContactsStore */ |
|
38 | - private $store; |
|
37 | + /** @var ContactsStore */ |
|
38 | + private $store; |
|
39 | 39 | |
40 | - /** @var ActionProviderStore */ |
|
41 | - private $actionProviderStore; |
|
40 | + /** @var ActionProviderStore */ |
|
41 | + private $actionProviderStore; |
|
42 | 42 | |
43 | - /** @var IAppManager */ |
|
44 | - private $appManager; |
|
43 | + /** @var IAppManager */ |
|
44 | + private $appManager; |
|
45 | 45 | |
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param ContactsStore $store |
|
51 | - * @param ActionProviderStore $actionProviderStore |
|
52 | - * @param IAppManager $appManager |
|
53 | - */ |
|
54 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
55 | - $this->store = $store; |
|
56 | - $this->actionProviderStore = $actionProviderStore; |
|
57 | - $this->appManager = $appManager; |
|
58 | - $this->config = $config; |
|
59 | - } |
|
49 | + /** |
|
50 | + * @param ContactsStore $store |
|
51 | + * @param ActionProviderStore $actionProviderStore |
|
52 | + * @param IAppManager $appManager |
|
53 | + */ |
|
54 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
55 | + $this->store = $store; |
|
56 | + $this->actionProviderStore = $actionProviderStore; |
|
57 | + $this->appManager = $appManager; |
|
58 | + $this->config = $config; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param IUser $user |
|
63 | - * @param string $filter |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getEntries(IUser $user, $filter) { |
|
67 | - $maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)); |
|
68 | - $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
69 | - $topEntries = []; |
|
70 | - if (strlen($filter) >= $minSearchStringLength) { |
|
71 | - $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
61 | + /** |
|
62 | + * @param IUser $user |
|
63 | + * @param string $filter |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getEntries(IUser $user, $filter) { |
|
67 | + $maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)); |
|
68 | + $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
69 | + $topEntries = []; |
|
70 | + if (strlen($filter) >= $minSearchStringLength) { |
|
71 | + $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
72 | 72 | |
73 | - $sortedEntries = $this->sortEntries($entries); |
|
74 | - $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
75 | - $this->processEntries($topEntries, $user); |
|
76 | - } |
|
73 | + $sortedEntries = $this->sortEntries($entries); |
|
74 | + $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
75 | + $this->processEntries($topEntries, $user); |
|
76 | + } |
|
77 | 77 | |
78 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
79 | - return [ |
|
80 | - 'contacts' => $topEntries, |
|
81 | - 'contactsAppEnabled' => $contactsEnabled, |
|
82 | - ]; |
|
83 | - } |
|
78 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
79 | + return [ |
|
80 | + 'contacts' => $topEntries, |
|
81 | + 'contactsAppEnabled' => $contactsEnabled, |
|
82 | + ]; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param IUser $user |
|
87 | - * @param integer $shareType |
|
88 | - * @param string $shareWith |
|
89 | - * @return IEntry |
|
90 | - */ |
|
91 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
92 | - $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
93 | - if ($entry) { |
|
94 | - $this->processEntries([$entry], $user); |
|
95 | - } |
|
85 | + /** |
|
86 | + * @param IUser $user |
|
87 | + * @param integer $shareType |
|
88 | + * @param string $shareWith |
|
89 | + * @return IEntry |
|
90 | + */ |
|
91 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
92 | + $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
93 | + if ($entry) { |
|
94 | + $this->processEntries([$entry], $user); |
|
95 | + } |
|
96 | 96 | |
97 | - return $entry; |
|
98 | - } |
|
97 | + return $entry; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param IEntry[] $entries |
|
102 | - * @return IEntry[] |
|
103 | - */ |
|
104 | - private function sortEntries(array $entries) { |
|
105 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
106 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
107 | - }); |
|
108 | - return $entries; |
|
109 | - } |
|
100 | + /** |
|
101 | + * @param IEntry[] $entries |
|
102 | + * @return IEntry[] |
|
103 | + */ |
|
104 | + private function sortEntries(array $entries) { |
|
105 | + usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
106 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
107 | + }); |
|
108 | + return $entries; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @param IEntry[] $entries |
|
113 | - * @param IUser $user |
|
114 | - */ |
|
115 | - private function processEntries(array $entries, IUser $user) { |
|
116 | - $providers = $this->actionProviderStore->getProviders($user); |
|
117 | - foreach ($entries as $entry) { |
|
118 | - foreach ($providers as $provider) { |
|
119 | - $provider->process($entry); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
111 | + /** |
|
112 | + * @param IEntry[] $entries |
|
113 | + * @param IUser $user |
|
114 | + */ |
|
115 | + private function processEntries(array $entries, IUser $user) { |
|
116 | + $providers = $this->actionProviderStore->getProviders($user); |
|
117 | + foreach ($entries as $entry) { |
|
118 | + foreach ($providers as $provider) { |
|
119 | + $provider->process($entry); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -29,140 +29,140 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function (IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function (IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * sort the actions by priority and name |
116 | 116 | */ |
117 | 117 | private function sortActions() { |
118 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | 119 | $prio1 = $action1->getPriority(); |
120 | 120 | $prio2 = $action2->getPriority(); |
121 | 121 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function jsonSerialize() { |
154 | 154 | $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
155 | - $otherActions = array_map(function (IAction $action) { |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | 156 | return $action->jsonSerialize(); |
157 | 157 | }, array_slice($this->actions, 1)); |
158 | 158 |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return string[] |
96 | 96 | */ |
97 | 97 | private function getAppProviderClasses(IUser $user) { |
98 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
99 | 99 | $info = $this->appManager->getAppInfo($appId); |
100 | 100 | |
101 | 101 | if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return $all; |
104 | 104 | } |
105 | 105 | |
106 | - $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | + $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
107 | 107 | return array_merge($all, [$provider]); |
108 | 108 | }, []); |
109 | 109 |
@@ -34,79 +34,79 @@ |
||
34 | 34 | |
35 | 35 | class ActionProviderStore { |
36 | 36 | |
37 | - /** @var IServerContainer */ |
|
38 | - private $serverContainer; |
|
37 | + /** @var IServerContainer */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** @var AppManager */ |
|
41 | - private $appManager; |
|
40 | + /** @var AppManager */ |
|
41 | + private $appManager; |
|
42 | 42 | |
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param IServerContainer $serverContainer |
|
48 | - * @param AppManager $appManager |
|
49 | - * @param ILogger $logger |
|
50 | - */ |
|
51 | - public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
52 | - $this->serverContainer = $serverContainer; |
|
53 | - $this->appManager = $appManager; |
|
54 | - $this->logger = $logger; |
|
55 | - } |
|
46 | + /** |
|
47 | + * @param IServerContainer $serverContainer |
|
48 | + * @param AppManager $appManager |
|
49 | + * @param ILogger $logger |
|
50 | + */ |
|
51 | + public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
52 | + $this->serverContainer = $serverContainer; |
|
53 | + $this->appManager = $appManager; |
|
54 | + $this->logger = $logger; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param IUser $user |
|
59 | - * @return IProvider[] |
|
60 | - * @throws Exception |
|
61 | - */ |
|
62 | - public function getProviders(IUser $user) { |
|
63 | - $appClasses = $this->getAppProviderClasses($user); |
|
64 | - $providerClasses = $this->getServerProviderClasses(); |
|
65 | - $allClasses = array_merge($providerClasses, $appClasses); |
|
66 | - $providers = []; |
|
57 | + /** |
|
58 | + * @param IUser $user |
|
59 | + * @return IProvider[] |
|
60 | + * @throws Exception |
|
61 | + */ |
|
62 | + public function getProviders(IUser $user) { |
|
63 | + $appClasses = $this->getAppProviderClasses($user); |
|
64 | + $providerClasses = $this->getServerProviderClasses(); |
|
65 | + $allClasses = array_merge($providerClasses, $appClasses); |
|
66 | + $providers = []; |
|
67 | 67 | |
68 | - foreach ($allClasses as $class) { |
|
69 | - try { |
|
70 | - $providers[] = $this->serverContainer->query($class); |
|
71 | - } catch (QueryException $ex) { |
|
72 | - $this->logger->logException($ex, [ |
|
73 | - 'message' => "Could not load contacts menu action provider $class", |
|
74 | - 'app' => 'core', |
|
75 | - ]); |
|
76 | - throw new Exception("Could not load contacts menu action provider"); |
|
77 | - } |
|
78 | - } |
|
68 | + foreach ($allClasses as $class) { |
|
69 | + try { |
|
70 | + $providers[] = $this->serverContainer->query($class); |
|
71 | + } catch (QueryException $ex) { |
|
72 | + $this->logger->logException($ex, [ |
|
73 | + 'message' => "Could not load contacts menu action provider $class", |
|
74 | + 'app' => 'core', |
|
75 | + ]); |
|
76 | + throw new Exception("Could not load contacts menu action provider"); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - return $providers; |
|
81 | - } |
|
80 | + return $providers; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return string[] |
|
85 | - */ |
|
86 | - private function getServerProviderClasses() { |
|
87 | - return [ |
|
88 | - EMailProvider::class, |
|
89 | - ]; |
|
90 | - } |
|
83 | + /** |
|
84 | + * @return string[] |
|
85 | + */ |
|
86 | + private function getServerProviderClasses() { |
|
87 | + return [ |
|
88 | + EMailProvider::class, |
|
89 | + ]; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param IUser $user |
|
94 | - * @return string[] |
|
95 | - */ |
|
96 | - private function getAppProviderClasses(IUser $user) { |
|
97 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | - $info = $this->appManager->getAppInfo($appId); |
|
92 | + /** |
|
93 | + * @param IUser $user |
|
94 | + * @return string[] |
|
95 | + */ |
|
96 | + private function getAppProviderClasses(IUser $user) { |
|
97 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | + $info = $this->appManager->getAppInfo($appId); |
|
99 | 99 | |
100 | - if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
101 | - // Nothing to add |
|
102 | - return $all; |
|
103 | - } |
|
100 | + if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
101 | + // Nothing to add |
|
102 | + return $all; |
|
103 | + } |
|
104 | 104 | |
105 | - $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | - return array_merge($all, [$provider]); |
|
107 | - }, []); |
|
105 | + $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | + return array_merge($all, [$provider]); |
|
107 | + }, []); |
|
108 | 108 | |
109 | - return array_merge($all, $providers); |
|
110 | - }, []); |
|
111 | - } |
|
109 | + return array_merge($all, $providers); |
|
110 | + }, []); |
|
111 | + } |
|
112 | 112 | } |
@@ -24,12 +24,12 @@ |
||
24 | 24 | namespace OC\BackgroundJob\Legacy; |
25 | 25 | |
26 | 26 | class QueuedJob extends \OC\BackgroundJob\QueuedJob { |
27 | - public function run($argument) { |
|
28 | - $class = $argument['klass']; |
|
29 | - $method = $argument['method']; |
|
30 | - $parameters = $argument['parameters']; |
|
31 | - if (is_callable([$class, $method])) { |
|
32 | - call_user_func([$class, $method], $parameters); |
|
33 | - } |
|
34 | - } |
|
27 | + public function run($argument) { |
|
28 | + $class = $argument['klass']; |
|
29 | + $method = $argument['method']; |
|
30 | + $parameters = $argument['parameters']; |
|
31 | + if (is_callable([$class, $method])) { |
|
32 | + call_user_func([$class, $method], $parameters); |
|
33 | + } |
|
34 | + } |
|
35 | 35 | } |
@@ -26,37 +26,37 @@ |
||
26 | 26 | namespace OC\Template; |
27 | 27 | |
28 | 28 | class TemplateFileLocator { |
29 | - protected $dirs; |
|
30 | - private $path; |
|
29 | + protected $dirs; |
|
30 | + private $path; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param string[] $dirs |
|
34 | - */ |
|
35 | - public function __construct($dirs) { |
|
36 | - $this->dirs = $dirs; |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string[] $dirs |
|
34 | + */ |
|
35 | + public function __construct($dirs) { |
|
36 | + $this->dirs = $dirs; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $template |
|
41 | - * @return string |
|
42 | - * @throws \Exception |
|
43 | - */ |
|
44 | - public function find($template) { |
|
45 | - if ($template === '') { |
|
46 | - throw new \InvalidArgumentException('Empty template name'); |
|
47 | - } |
|
39 | + /** |
|
40 | + * @param string $template |
|
41 | + * @return string |
|
42 | + * @throws \Exception |
|
43 | + */ |
|
44 | + public function find($template) { |
|
45 | + if ($template === '') { |
|
46 | + throw new \InvalidArgumentException('Empty template name'); |
|
47 | + } |
|
48 | 48 | |
49 | - foreach ($this->dirs as $dir) { |
|
50 | - $file = $dir.$template.'.php'; |
|
51 | - if (is_file($file)) { |
|
52 | - $this->path = $dir; |
|
53 | - return $file; |
|
54 | - } |
|
55 | - } |
|
56 | - throw new \Exception('template file not found: template:'.$template); |
|
57 | - } |
|
49 | + foreach ($this->dirs as $dir) { |
|
50 | + $file = $dir.$template.'.php'; |
|
51 | + if (is_file($file)) { |
|
52 | + $this->path = $dir; |
|
53 | + return $file; |
|
54 | + } |
|
55 | + } |
|
56 | + throw new \Exception('template file not found: template:'.$template); |
|
57 | + } |
|
58 | 58 | |
59 | - public function getPath() { |
|
60 | - return $this->path; |
|
61 | - } |
|
59 | + public function getPath() { |
|
60 | + return $this->path; |
|
61 | + } |
|
62 | 62 | } |
@@ -77,20 +77,20 @@ |
||
77 | 77 | |
78 | 78 | // missing translations files fill be ignored |
79 | 79 | if (strpos($script, 'l10n/') === 0) { |
80 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
80 | + $this->appendIfExist($app_path, $script.'.js', $app_url); |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | 84 | if ($app_path === false && $app_url === false) { |
85 | 85 | $this->logger->error('Could not find resource {resource} to load', [ |
86 | - 'resource' => $app . '/' . $script . '.js', |
|
86 | + 'resource' => $app.'/'.$script.'.js', |
|
87 | 87 | 'app' => 'jsresourceloader', |
88 | 88 | ]); |
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | 92 | if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
93 | - $this->append($app_path, $script . '.js', $app_url); |
|
93 | + $this->append($app_path, $script.'.js', $app_url); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 |
@@ -30,103 +30,103 @@ |
||
30 | 30 | |
31 | 31 | class JSResourceLocator extends ResourceLocator { |
32 | 32 | |
33 | - /** @var JSCombiner */ |
|
34 | - protected $jsCombiner; |
|
35 | - |
|
36 | - public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
37 | - parent::__construct($logger, $theme, $core_map, $party_map); |
|
38 | - |
|
39 | - $this->jsCombiner = $JSCombiner; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $script |
|
44 | - */ |
|
45 | - public function doFind($script) { |
|
46 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
47 | - if (strpos($script, '3rdparty') === 0 |
|
48 | - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
49 | - return; |
|
50 | - } |
|
51 | - |
|
52 | - if (strpos($script, '/l10n/') !== false) { |
|
53 | - // For language files we try to load them all, so themes can overwrite |
|
54 | - // single l10n strings without having to translate all of them. |
|
55 | - $found = 0; |
|
56 | - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
57 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
58 | - $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
59 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
60 | - $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js'); |
|
61 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
62 | - |
|
63 | - if ($found) { |
|
64 | - return; |
|
65 | - } |
|
66 | - } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
67 | - || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
68 | - || $this->appendIfExist($this->serverroot, $script.'.js') |
|
69 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
70 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
71 | - || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
72 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
73 | - ) { |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - $app = substr($script, 0, strpos($script, '/')); |
|
78 | - $script = substr($script, strpos($script, '/') + 1); |
|
79 | - $app_path = \OC_App::getAppPath($app); |
|
80 | - $app_url = \OC_App::getAppWebPath($app); |
|
81 | - |
|
82 | - if ($app_path !== false) { |
|
83 | - // Account for the possibility of having symlinks in app path. Only |
|
84 | - // do this if $app_path is set, because an empty argument to realpath |
|
85 | - // gets turned into cwd. |
|
86 | - $app_path = realpath($app_path); |
|
87 | - } |
|
88 | - |
|
89 | - // missing translations files fill be ignored |
|
90 | - if (strpos($script, 'l10n/') === 0) { |
|
91 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
92 | - return; |
|
93 | - } |
|
94 | - |
|
95 | - if ($app_path === false && $app_url === false) { |
|
96 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
97 | - 'resource' => $app . '/' . $script . '.js', |
|
98 | - 'app' => 'jsresourceloader', |
|
99 | - ]); |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
104 | - $this->append($app_path, $script . '.js', $app_url); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $script |
|
110 | - */ |
|
111 | - public function doFindTheme($script) { |
|
112 | - } |
|
113 | - |
|
114 | - protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
115 | - if (is_file($root.'/'.$file)) { |
|
116 | - if ($this->jsCombiner->process($root, $file, $app)) { |
|
117 | - $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
118 | - } else { |
|
119 | - // Add all the files from the json |
|
120 | - $files = $this->jsCombiner->getContent($root, $file); |
|
121 | - $app_url = \OC_App::getAppWebPath($app); |
|
122 | - |
|
123 | - foreach ($files as $jsFile) { |
|
124 | - $this->append($root, $jsFile, $app_url); |
|
125 | - } |
|
126 | - } |
|
127 | - return true; |
|
128 | - } |
|
129 | - |
|
130 | - return false; |
|
131 | - } |
|
33 | + /** @var JSCombiner */ |
|
34 | + protected $jsCombiner; |
|
35 | + |
|
36 | + public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { |
|
37 | + parent::__construct($logger, $theme, $core_map, $party_map); |
|
38 | + |
|
39 | + $this->jsCombiner = $JSCombiner; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $script |
|
44 | + */ |
|
45 | + public function doFind($script) { |
|
46 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
47 | + if (strpos($script, '3rdparty') === 0 |
|
48 | + && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
49 | + return; |
|
50 | + } |
|
51 | + |
|
52 | + if (strpos($script, '/l10n/') !== false) { |
|
53 | + // For language files we try to load them all, so themes can overwrite |
|
54 | + // single l10n strings without having to translate all of them. |
|
55 | + $found = 0; |
|
56 | + $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
57 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
58 | + $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
59 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
60 | + $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js'); |
|
61 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
62 | + |
|
63 | + if ($found) { |
|
64 | + return; |
|
65 | + } |
|
66 | + } elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
67 | + || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
68 | + || $this->appendIfExist($this->serverroot, $script.'.js') |
|
69 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
70 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
71 | + || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
72 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
73 | + ) { |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + $app = substr($script, 0, strpos($script, '/')); |
|
78 | + $script = substr($script, strpos($script, '/') + 1); |
|
79 | + $app_path = \OC_App::getAppPath($app); |
|
80 | + $app_url = \OC_App::getAppWebPath($app); |
|
81 | + |
|
82 | + if ($app_path !== false) { |
|
83 | + // Account for the possibility of having symlinks in app path. Only |
|
84 | + // do this if $app_path is set, because an empty argument to realpath |
|
85 | + // gets turned into cwd. |
|
86 | + $app_path = realpath($app_path); |
|
87 | + } |
|
88 | + |
|
89 | + // missing translations files fill be ignored |
|
90 | + if (strpos($script, 'l10n/') === 0) { |
|
91 | + $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
92 | + return; |
|
93 | + } |
|
94 | + |
|
95 | + if ($app_path === false && $app_url === false) { |
|
96 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
97 | + 'resource' => $app . '/' . $script . '.js', |
|
98 | + 'app' => 'jsresourceloader', |
|
99 | + ]); |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
104 | + $this->append($app_path, $script . '.js', $app_url); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $script |
|
110 | + */ |
|
111 | + public function doFindTheme($script) { |
|
112 | + } |
|
113 | + |
|
114 | + protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
115 | + if (is_file($root.'/'.$file)) { |
|
116 | + if ($this->jsCombiner->process($root, $file, $app)) { |
|
117 | + $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
118 | + } else { |
|
119 | + // Add all the files from the json |
|
120 | + $files = $this->jsCombiner->getContent($root, $file); |
|
121 | + $app_url = \OC_App::getAppWebPath($app); |
|
122 | + |
|
123 | + foreach ($files as $jsFile) { |
|
124 | + $this->append($root, $jsFile, $app_url); |
|
125 | + } |
|
126 | + } |
|
127 | + return true; |
|
128 | + } |
|
129 | + |
|
130 | + return false; |
|
131 | + } |
|
132 | 132 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | |
66 | 66 | if ($app_path === false && $app_url === false) { |
67 | 67 | $this->logger->error('Could not find resource {resource} to load', [ |
68 | - 'resource' => $app . '/' . $style . '.css', |
|
68 | + 'resource' => $app.'/'.$style.'.css', |
|
69 | 69 | 'app' => 'cssresourceloader', |
70 | 70 | ]); |
71 | 71 | return; |
@@ -36,116 +36,116 @@ |
||
36 | 36 | |
37 | 37 | class CSSResourceLocator extends ResourceLocator { |
38 | 38 | |
39 | - /** @var SCSSCacher */ |
|
40 | - protected $scssCacher; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param ILogger $logger |
|
44 | - * @param string $theme |
|
45 | - * @param array $core_map |
|
46 | - * @param array $party_map |
|
47 | - * @param SCSSCacher $scssCacher |
|
48 | - */ |
|
49 | - public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) { |
|
50 | - $this->scssCacher = $scssCacher; |
|
51 | - |
|
52 | - parent::__construct($logger, $theme, $core_map, $party_map); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $style |
|
57 | - */ |
|
58 | - public function doFind($style) { |
|
59 | - $app = substr($style, 0, strpos($style, '/')); |
|
60 | - if (strpos($style, '3rdparty') === 0 |
|
61 | - && $this->appendIfExist($this->thirdpartyroot, $style.'.css') |
|
62 | - || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app) |
|
63 | - || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss') |
|
64 | - || $this->appendIfExist($this->serverroot, $style.'.css') |
|
65 | - || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
66 | - ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - $style = substr($style, strpos($style, '/') + 1); |
|
70 | - $app_path = \OC_App::getAppPath($app); |
|
71 | - $app_url = \OC_App::getAppWebPath($app); |
|
72 | - |
|
73 | - if ($app_path === false && $app_url === false) { |
|
74 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
75 | - 'resource' => $app . '/' . $style . '.css', |
|
76 | - 'app' => 'cssresourceloader', |
|
77 | - ]); |
|
78 | - return; |
|
79 | - } |
|
80 | - |
|
81 | - // Account for the possibility of having symlinks in app path. Doing |
|
82 | - // this here instead of above as an empty argument to realpath gets |
|
83 | - // turned into cwd. |
|
84 | - $app_path = realpath($app_path); |
|
85 | - |
|
86 | - if (!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) { |
|
87 | - $this->append($app_path, $style.'.css', $app_url); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param string $style |
|
93 | - */ |
|
94 | - public function doFindTheme($style) { |
|
95 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
96 | - $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
97 | - || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
98 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * cache and append the scss $file if exist at $root |
|
103 | - * |
|
104 | - * @param string $root path to check |
|
105 | - * @param string $file the filename |
|
106 | - * @return bool True if the resource was found and cached, false otherwise |
|
107 | - */ |
|
108 | - protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { |
|
109 | - if (is_file($root.'/'.$file)) { |
|
110 | - if ($this->scssCacher !== null) { |
|
111 | - if ($this->scssCacher->process($root, $file, $app)) { |
|
112 | - $this->append($this->serverroot, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true); |
|
113 | - return true; |
|
114 | - } else { |
|
115 | - $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); |
|
116 | - return false; |
|
117 | - } |
|
118 | - } else { |
|
119 | - return true; |
|
120 | - } |
|
121 | - } |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { |
|
126 | - if (!$scss) { |
|
127 | - parent::append($root, $file, $webRoot, $throw); |
|
128 | - } else { |
|
129 | - if (!$webRoot) { |
|
130 | - $webRoot = $this->findWebRoot($root); |
|
131 | - |
|
132 | - if ($webRoot === null) { |
|
133 | - $webRoot = ''; |
|
134 | - $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
135 | - 'app' => 'lib', |
|
136 | - 'root' => $root, |
|
137 | - 'file' => $file, |
|
138 | - 'webRoot' => $webRoot, |
|
139 | - 'throw' => $throw ? 'true' : 'false' |
|
140 | - ]); |
|
141 | - |
|
142 | - if ($throw && $root === '/') { |
|
143 | - throw new ResourceNotFoundException($file, $webRoot); |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - $this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file]; |
|
149 | - } |
|
150 | - } |
|
39 | + /** @var SCSSCacher */ |
|
40 | + protected $scssCacher; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param ILogger $logger |
|
44 | + * @param string $theme |
|
45 | + * @param array $core_map |
|
46 | + * @param array $party_map |
|
47 | + * @param SCSSCacher $scssCacher |
|
48 | + */ |
|
49 | + public function __construct(ILogger $logger, $theme, $core_map, $party_map, $scssCacher) { |
|
50 | + $this->scssCacher = $scssCacher; |
|
51 | + |
|
52 | + parent::__construct($logger, $theme, $core_map, $party_map); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $style |
|
57 | + */ |
|
58 | + public function doFind($style) { |
|
59 | + $app = substr($style, 0, strpos($style, '/')); |
|
60 | + if (strpos($style, '3rdparty') === 0 |
|
61 | + && $this->appendIfExist($this->thirdpartyroot, $style.'.css') |
|
62 | + || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $app) |
|
63 | + || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss') |
|
64 | + || $this->appendIfExist($this->serverroot, $style.'.css') |
|
65 | + || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
66 | + ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + $style = substr($style, strpos($style, '/') + 1); |
|
70 | + $app_path = \OC_App::getAppPath($app); |
|
71 | + $app_url = \OC_App::getAppWebPath($app); |
|
72 | + |
|
73 | + if ($app_path === false && $app_url === false) { |
|
74 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
75 | + 'resource' => $app . '/' . $style . '.css', |
|
76 | + 'app' => 'cssresourceloader', |
|
77 | + ]); |
|
78 | + return; |
|
79 | + } |
|
80 | + |
|
81 | + // Account for the possibility of having symlinks in app path. Doing |
|
82 | + // this here instead of above as an empty argument to realpath gets |
|
83 | + // turned into cwd. |
|
84 | + $app_path = realpath($app_path); |
|
85 | + |
|
86 | + if (!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) { |
|
87 | + $this->append($app_path, $style.'.css', $app_url); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param string $style |
|
93 | + */ |
|
94 | + public function doFindTheme($style) { |
|
95 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
96 | + $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
97 | + || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
98 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * cache and append the scss $file if exist at $root |
|
103 | + * |
|
104 | + * @param string $root path to check |
|
105 | + * @param string $file the filename |
|
106 | + * @return bool True if the resource was found and cached, false otherwise |
|
107 | + */ |
|
108 | + protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { |
|
109 | + if (is_file($root.'/'.$file)) { |
|
110 | + if ($this->scssCacher !== null) { |
|
111 | + if ($this->scssCacher->process($root, $file, $app)) { |
|
112 | + $this->append($this->serverroot, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true); |
|
113 | + return true; |
|
114 | + } else { |
|
115 | + $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); |
|
116 | + return false; |
|
117 | + } |
|
118 | + } else { |
|
119 | + return true; |
|
120 | + } |
|
121 | + } |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { |
|
126 | + if (!$scss) { |
|
127 | + parent::append($root, $file, $webRoot, $throw); |
|
128 | + } else { |
|
129 | + if (!$webRoot) { |
|
130 | + $webRoot = $this->findWebRoot($root); |
|
131 | + |
|
132 | + if ($webRoot === null) { |
|
133 | + $webRoot = ''; |
|
134 | + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
135 | + 'app' => 'lib', |
|
136 | + 'root' => $root, |
|
137 | + 'file' => $file, |
|
138 | + 'webRoot' => $webRoot, |
|
139 | + 'throw' => $throw ? 'true' : 'false' |
|
140 | + ]); |
|
141 | + |
|
142 | + if ($throw && $root === '/') { |
|
143 | + throw new ResourceNotFoundException($file, $webRoot); |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + $this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file]; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | } |