@@ -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'])) { |
@@ -31,231 +31,231 @@ |
||
31 | 31 | |
32 | 32 | class EventMerger implements IEventMerger { |
33 | 33 | |
34 | - /** @var IL10N */ |
|
35 | - protected $l10n; |
|
34 | + /** @var IL10N */ |
|
35 | + protected $l10n; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IL10N $l10n |
|
39 | - */ |
|
40 | - public function __construct(IL10N $l10n) { |
|
41 | - $this->l10n = $l10n; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param IL10N $l10n |
|
39 | + */ |
|
40 | + public function __construct(IL10N $l10n) { |
|
41 | + $this->l10n = $l10n; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Combines two events when possible to have grouping: |
|
46 | - * |
|
47 | - * Example1: Two events with subject '{user} created {file}' and |
|
48 | - * $mergeParameter file with different file and same user will be merged |
|
49 | - * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
50 | - * will be set, if the events have been merged. |
|
51 | - * |
|
52 | - * Example2: Two events with subject '{user} created {file}' and |
|
53 | - * $mergeParameter file with same file and same user will be merged to |
|
54 | - * '{user} created {file1}' and the childEvent on the return will be set, if |
|
55 | - * the events have been merged. |
|
56 | - * |
|
57 | - * The following requirements have to be met, in order to be merged: |
|
58 | - * - Both events need to have the same `getApp()` |
|
59 | - * - Both events must not have a message `getMessage()` |
|
60 | - * - Both events need to have the same subject `getSubject()` |
|
61 | - * - Both events need to have the same object type `getObjectType()` |
|
62 | - * - The time difference between both events must not be bigger then 3 hours |
|
63 | - * - Only up to 5 events can be merged. |
|
64 | - * - All parameters apart from such starting with $mergeParameter must be |
|
65 | - * the same for both events. |
|
66 | - * |
|
67 | - * @param string $mergeParameter |
|
68 | - * @param IEvent $event |
|
69 | - * @param IEvent|null $previousEvent |
|
70 | - * @return IEvent |
|
71 | - */ |
|
72 | - public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
73 | - // No second event => can not combine |
|
74 | - if (!$previousEvent instanceof IEvent) { |
|
75 | - return $event; |
|
76 | - } |
|
44 | + /** |
|
45 | + * Combines two events when possible to have grouping: |
|
46 | + * |
|
47 | + * Example1: Two events with subject '{user} created {file}' and |
|
48 | + * $mergeParameter file with different file and same user will be merged |
|
49 | + * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
50 | + * will be set, if the events have been merged. |
|
51 | + * |
|
52 | + * Example2: Two events with subject '{user} created {file}' and |
|
53 | + * $mergeParameter file with same file and same user will be merged to |
|
54 | + * '{user} created {file1}' and the childEvent on the return will be set, if |
|
55 | + * the events have been merged. |
|
56 | + * |
|
57 | + * The following requirements have to be met, in order to be merged: |
|
58 | + * - Both events need to have the same `getApp()` |
|
59 | + * - Both events must not have a message `getMessage()` |
|
60 | + * - Both events need to have the same subject `getSubject()` |
|
61 | + * - Both events need to have the same object type `getObjectType()` |
|
62 | + * - The time difference between both events must not be bigger then 3 hours |
|
63 | + * - Only up to 5 events can be merged. |
|
64 | + * - All parameters apart from such starting with $mergeParameter must be |
|
65 | + * the same for both events. |
|
66 | + * |
|
67 | + * @param string $mergeParameter |
|
68 | + * @param IEvent $event |
|
69 | + * @param IEvent|null $previousEvent |
|
70 | + * @return IEvent |
|
71 | + */ |
|
72 | + public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
73 | + // No second event => can not combine |
|
74 | + if (!$previousEvent instanceof IEvent) { |
|
75 | + return $event; |
|
76 | + } |
|
77 | 77 | |
78 | - // Different app => can not combine |
|
79 | - if ($event->getApp() !== $previousEvent->getApp()) { |
|
80 | - return $event; |
|
81 | - } |
|
78 | + // Different app => can not combine |
|
79 | + if ($event->getApp() !== $previousEvent->getApp()) { |
|
80 | + return $event; |
|
81 | + } |
|
82 | 82 | |
83 | - // Message is set => can not combine |
|
84 | - if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
85 | - return $event; |
|
86 | - } |
|
83 | + // Message is set => can not combine |
|
84 | + if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
85 | + return $event; |
|
86 | + } |
|
87 | 87 | |
88 | - // Different subject => can not combine |
|
89 | - if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
90 | - return $event; |
|
91 | - } |
|
88 | + // Different subject => can not combine |
|
89 | + if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
90 | + return $event; |
|
91 | + } |
|
92 | 92 | |
93 | - // Different object type => can not combine |
|
94 | - if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
95 | - return $event; |
|
96 | - } |
|
93 | + // Different object type => can not combine |
|
94 | + if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
95 | + return $event; |
|
96 | + } |
|
97 | 97 | |
98 | - // More than 3 hours difference => can not combine |
|
99 | - if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
100 | - return $event; |
|
101 | - } |
|
98 | + // More than 3 hours difference => can not combine |
|
99 | + if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
100 | + return $event; |
|
101 | + } |
|
102 | 102 | |
103 | - // Other parameters are not the same => can not combine |
|
104 | - try { |
|
105 | - [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
106 | - } catch (\UnexpectedValueException $e) { |
|
107 | - return $event; |
|
108 | - } |
|
103 | + // Other parameters are not the same => can not combine |
|
104 | + try { |
|
105 | + [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
106 | + } catch (\UnexpectedValueException $e) { |
|
107 | + return $event; |
|
108 | + } |
|
109 | 109 | |
110 | - try { |
|
111 | - $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
112 | - $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
110 | + try { |
|
111 | + $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
112 | + $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
113 | 113 | |
114 | - $event->setRichSubject($newSubject, $parameters) |
|
115 | - ->setParsedSubject($parsedSubject) |
|
116 | - ->setChildEvent($previousEvent) |
|
117 | - ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
118 | - } catch (\UnexpectedValueException $e) { |
|
119 | - return $event; |
|
120 | - } |
|
114 | + $event->setRichSubject($newSubject, $parameters) |
|
115 | + ->setParsedSubject($parsedSubject) |
|
116 | + ->setChildEvent($previousEvent) |
|
117 | + ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
118 | + } catch (\UnexpectedValueException $e) { |
|
119 | + return $event; |
|
120 | + } |
|
121 | 121 | |
122 | - return $event; |
|
123 | - } |
|
122 | + return $event; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $mergeParameter |
|
127 | - * @param IEvent $event |
|
128 | - * @param IEvent $previousEvent |
|
129 | - * @return array |
|
130 | - * @throws \UnexpectedValueException |
|
131 | - */ |
|
132 | - protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
133 | - $params1 = $event->getRichSubjectParameters(); |
|
134 | - $params2 = $previousEvent->getRichSubjectParameters(); |
|
135 | - $params = []; |
|
125 | + /** |
|
126 | + * @param string $mergeParameter |
|
127 | + * @param IEvent $event |
|
128 | + * @param IEvent $previousEvent |
|
129 | + * @return array |
|
130 | + * @throws \UnexpectedValueException |
|
131 | + */ |
|
132 | + protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
133 | + $params1 = $event->getRichSubjectParameters(); |
|
134 | + $params2 = $previousEvent->getRichSubjectParameters(); |
|
135 | + $params = []; |
|
136 | 136 | |
137 | - $combined = 0; |
|
137 | + $combined = 0; |
|
138 | 138 | |
139 | - // Check that all parameters from $event exist in $previousEvent |
|
140 | - foreach ($params1 as $key => $parameter) { |
|
141 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
142 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
143 | - $combined++; |
|
144 | - $params[$mergeParameter . $combined] = $parameter; |
|
145 | - } |
|
146 | - continue; |
|
147 | - } |
|
139 | + // Check that all parameters from $event exist in $previousEvent |
|
140 | + foreach ($params1 as $key => $parameter) { |
|
141 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
142 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
143 | + $combined++; |
|
144 | + $params[$mergeParameter . $combined] = $parameter; |
|
145 | + } |
|
146 | + continue; |
|
147 | + } |
|
148 | 148 | |
149 | - if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
150 | - // Parameter missing on $previousEvent or different => can not combine |
|
151 | - throw new \UnexpectedValueException(); |
|
152 | - } |
|
149 | + if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
150 | + // Parameter missing on $previousEvent or different => can not combine |
|
151 | + throw new \UnexpectedValueException(); |
|
152 | + } |
|
153 | 153 | |
154 | - $params[$key] = $parameter; |
|
155 | - } |
|
154 | + $params[$key] = $parameter; |
|
155 | + } |
|
156 | 156 | |
157 | - // Check that all parameters from $previousEvent exist in $event |
|
158 | - foreach ($params2 as $key => $parameter) { |
|
159 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
160 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
161 | - $combined++; |
|
162 | - $params[$mergeParameter . $combined] = $parameter; |
|
163 | - } |
|
164 | - continue; |
|
165 | - } |
|
157 | + // Check that all parameters from $previousEvent exist in $event |
|
158 | + foreach ($params2 as $key => $parameter) { |
|
159 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
160 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
161 | + $combined++; |
|
162 | + $params[$mergeParameter . $combined] = $parameter; |
|
163 | + } |
|
164 | + continue; |
|
165 | + } |
|
166 | 166 | |
167 | - if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
168 | - // Parameter missing on $event or different => can not combine |
|
169 | - throw new \UnexpectedValueException(); |
|
170 | - } |
|
167 | + if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
168 | + // Parameter missing on $event or different => can not combine |
|
169 | + throw new \UnexpectedValueException(); |
|
170 | + } |
|
171 | 171 | |
172 | - $params[$key] = $parameter; |
|
173 | - } |
|
172 | + $params[$key] = $parameter; |
|
173 | + } |
|
174 | 174 | |
175 | - return [$combined, $params]; |
|
176 | - } |
|
175 | + return [$combined, $params]; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param array[] $parameters |
|
180 | - * @param string $mergeParameter |
|
181 | - * @param array $parameter |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
185 | - foreach ($parameters as $key => $param) { |
|
186 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
187 | - if ($param === $parameter) { |
|
188 | - return true; |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - return false; |
|
193 | - } |
|
178 | + /** |
|
179 | + * @param array[] $parameters |
|
180 | + * @param string $mergeParameter |
|
181 | + * @param array $parameter |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
185 | + foreach ($parameters as $key => $param) { |
|
186 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
187 | + if ($param === $parameter) { |
|
188 | + return true; |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + return false; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @param string $subject |
|
197 | - * @param string $parameter |
|
198 | - * @param int $counter |
|
199 | - * @return mixed |
|
200 | - */ |
|
201 | - protected function getExtendedSubject($subject, $parameter, $counter) { |
|
202 | - switch ($counter) { |
|
203 | - case 1: |
|
204 | - $replacement = '{' . $parameter . '1}'; |
|
205 | - break; |
|
206 | - case 2: |
|
207 | - $replacement = $this->l10n->t( |
|
208 | - '%1$s and %2$s', |
|
209 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
210 | - ); |
|
211 | - break; |
|
212 | - case 3: |
|
213 | - $replacement = $this->l10n->t( |
|
214 | - '%1$s, %2$s and %3$s', |
|
215 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
216 | - ); |
|
217 | - break; |
|
218 | - case 4: |
|
219 | - $replacement = $this->l10n->t( |
|
220 | - '%1$s, %2$s, %3$s and %4$s', |
|
221 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
222 | - ); |
|
223 | - break; |
|
224 | - case 5: |
|
225 | - $replacement = $this->l10n->t( |
|
226 | - '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
227 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
228 | - ); |
|
229 | - break; |
|
230 | - default: |
|
231 | - throw new \UnexpectedValueException(); |
|
232 | - } |
|
195 | + /** |
|
196 | + * @param string $subject |
|
197 | + * @param string $parameter |
|
198 | + * @param int $counter |
|
199 | + * @return mixed |
|
200 | + */ |
|
201 | + protected function getExtendedSubject($subject, $parameter, $counter) { |
|
202 | + switch ($counter) { |
|
203 | + case 1: |
|
204 | + $replacement = '{' . $parameter . '1}'; |
|
205 | + break; |
|
206 | + case 2: |
|
207 | + $replacement = $this->l10n->t( |
|
208 | + '%1$s and %2$s', |
|
209 | + ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
210 | + ); |
|
211 | + break; |
|
212 | + case 3: |
|
213 | + $replacement = $this->l10n->t( |
|
214 | + '%1$s, %2$s and %3$s', |
|
215 | + ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
216 | + ); |
|
217 | + break; |
|
218 | + case 4: |
|
219 | + $replacement = $this->l10n->t( |
|
220 | + '%1$s, %2$s, %3$s and %4$s', |
|
221 | + ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
222 | + ); |
|
223 | + break; |
|
224 | + case 5: |
|
225 | + $replacement = $this->l10n->t( |
|
226 | + '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
227 | + ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
228 | + ); |
|
229 | + break; |
|
230 | + default: |
|
231 | + throw new \UnexpectedValueException(); |
|
232 | + } |
|
233 | 233 | |
234 | - return str_replace( |
|
235 | - '{' . $parameter . '}', |
|
236 | - $replacement, |
|
237 | - $subject |
|
238 | - ); |
|
239 | - } |
|
234 | + return str_replace( |
|
235 | + '{' . $parameter . '}', |
|
236 | + $replacement, |
|
237 | + $subject |
|
238 | + ); |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * @param string $subject |
|
243 | - * @param array[] $parameters |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - protected function generateParsedSubject($subject, $parameters) { |
|
247 | - $placeholders = $replacements = []; |
|
248 | - foreach ($parameters as $placeholder => $parameter) { |
|
249 | - $placeholders[] = '{' . $placeholder . '}'; |
|
250 | - if ($parameter['type'] === 'file') { |
|
251 | - $replacements[] = trim($parameter['path'], '/'); |
|
252 | - } elseif (isset($parameter['name'])) { |
|
253 | - $replacements[] = $parameter['name']; |
|
254 | - } else { |
|
255 | - $replacements[] = $parameter['id']; |
|
256 | - } |
|
257 | - } |
|
241 | + /** |
|
242 | + * @param string $subject |
|
243 | + * @param array[] $parameters |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + protected function generateParsedSubject($subject, $parameters) { |
|
247 | + $placeholders = $replacements = []; |
|
248 | + foreach ($parameters as $placeholder => $parameter) { |
|
249 | + $placeholders[] = '{' . $placeholder . '}'; |
|
250 | + if ($parameter['type'] === 'file') { |
|
251 | + $replacements[] = trim($parameter['path'], '/'); |
|
252 | + } elseif (isset($parameter['name'])) { |
|
253 | + $replacements[] = $parameter['name']; |
|
254 | + } else { |
|
255 | + $replacements[] = $parameter['id']; |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - return str_replace($placeholders, $replacements, $subject); |
|
260 | - } |
|
259 | + return str_replace($placeholders, $replacements, $subject); |
|
260 | + } |
|
261 | 261 | } |
@@ -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 | } |
@@ -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 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->doFind($resource); |
76 | 76 | } catch (ResourceNotFoundException $e) { |
77 | 77 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
78 | - $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
78 | + $this->logger->debug('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | if (!empty($this->theme)) { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->doFindTheme($resource); |
85 | 85 | } catch (ResourceNotFoundException $e) { |
86 | 86 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
87 | - $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
87 | + $this->logger->debug('Could not find resource file in theme "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | } |
159 | 159 | $this->resources[] = [$root, $webRoot, $file]; |
160 | 160 | |
161 | - if ($throw && !is_file($root . '/' . $file)) { |
|
161 | + if ($throw && !is_file($root.'/'.$file)) { |
|
162 | 162 | throw new ResourceNotFoundException($file, $webRoot); |
163 | 163 | } |
164 | 164 | } |
@@ -31,172 +31,172 @@ |
||
31 | 31 | namespace OC\Template; |
32 | 32 | |
33 | 33 | abstract class ResourceLocator { |
34 | - protected $theme; |
|
35 | - |
|
36 | - protected $mapping; |
|
37 | - protected $serverroot; |
|
38 | - protected $thirdpartyroot; |
|
39 | - protected $webroot; |
|
40 | - |
|
41 | - protected $resources = []; |
|
42 | - |
|
43 | - /** @var \OCP\ILogger */ |
|
44 | - protected $logger; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param \OCP\ILogger $logger |
|
48 | - * @param string $theme |
|
49 | - * @param array $core_map |
|
50 | - * @param array $party_map |
|
51 | - */ |
|
52 | - public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
53 | - $this->logger = $logger; |
|
54 | - $this->theme = $theme; |
|
55 | - $this->mapping = $core_map + $party_map; |
|
56 | - $this->serverroot = key($core_map); |
|
57 | - $this->thirdpartyroot = key($party_map); |
|
58 | - $this->webroot = $this->mapping[$this->serverroot]; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $resource |
|
63 | - */ |
|
64 | - abstract public function doFind($resource); |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $resource |
|
68 | - */ |
|
69 | - abstract public function doFindTheme($resource); |
|
70 | - |
|
71 | - /** |
|
72 | - * Finds the resources and adds them to the list |
|
73 | - * |
|
74 | - * @param array $resources |
|
75 | - */ |
|
76 | - public function find($resources) { |
|
77 | - foreach ($resources as $resource) { |
|
78 | - try { |
|
79 | - $this->doFind($resource); |
|
80 | - } catch (ResourceNotFoundException $e) { |
|
81 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
82 | - $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
83 | - } |
|
84 | - } |
|
85 | - if (!empty($this->theme)) { |
|
86 | - foreach ($resources as $resource) { |
|
87 | - try { |
|
88 | - $this->doFindTheme($resource); |
|
89 | - } catch (ResourceNotFoundException $e) { |
|
90 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
91 | - $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * append the $file resource if exist at $root |
|
99 | - * |
|
100 | - * @param string $root path to check |
|
101 | - * @param string $file the filename |
|
102 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
103 | - * @return bool True if the resource was found, false otherwise |
|
104 | - */ |
|
105 | - protected function appendIfExist($root, $file, $webRoot = null) { |
|
106 | - if (is_file($root.'/'.$file)) { |
|
107 | - $this->append($root, $file, $webRoot, false); |
|
108 | - return true; |
|
109 | - } |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Attempt to find the webRoot |
|
115 | - * |
|
116 | - * traverse the potential web roots upwards in the path |
|
117 | - * |
|
118 | - * example: |
|
119 | - * - root: /srv/www/apps/myapp |
|
120 | - * - available mappings: ['/srv/www'] |
|
121 | - * |
|
122 | - * First we check if a mapping for /srv/www/apps/myapp is available, |
|
123 | - * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
124 | - * valid web root |
|
125 | - * |
|
126 | - * @param string $root |
|
127 | - * @return string|null The web root or null on failure |
|
128 | - */ |
|
129 | - protected function findWebRoot($root) { |
|
130 | - $webRoot = null; |
|
131 | - $tmpRoot = $root; |
|
132 | - |
|
133 | - while ($webRoot === null) { |
|
134 | - if (isset($this->mapping[$tmpRoot])) { |
|
135 | - $webRoot = $this->mapping[$tmpRoot]; |
|
136 | - break; |
|
137 | - } |
|
138 | - |
|
139 | - if ($tmpRoot === '/') { |
|
140 | - break; |
|
141 | - } |
|
142 | - |
|
143 | - $tmpRoot = dirname($tmpRoot); |
|
144 | - } |
|
145 | - |
|
146 | - if ($webRoot === null) { |
|
147 | - $realpath = realpath($root); |
|
148 | - |
|
149 | - if ($realpath && ($realpath !== $root)) { |
|
150 | - return $this->findWebRoot($realpath); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - return $webRoot; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * append the $file resource at $root |
|
159 | - * |
|
160 | - * @param string $root path to check |
|
161 | - * @param string $file the filename |
|
162 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
163 | - * @param bool $throw Throw an exception, when the route does not exist |
|
164 | - * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
165 | - */ |
|
166 | - protected function append($root, $file, $webRoot = null, $throw = true) { |
|
167 | - if (!is_string($root)) { |
|
168 | - if ($throw) { |
|
169 | - throw new ResourceNotFoundException($file, $webRoot); |
|
170 | - } |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - if (!$webRoot) { |
|
175 | - $webRoot = $this->findWebRoot($root); |
|
176 | - |
|
177 | - if ($webRoot === null) { |
|
178 | - $webRoot = ''; |
|
179 | - $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
180 | - 'app' => 'lib', |
|
181 | - 'root' => $root, |
|
182 | - 'file' => $file, |
|
183 | - 'webRoot' => $webRoot, |
|
184 | - 'throw' => $throw ? 'true' : 'false' |
|
185 | - ]); |
|
186 | - } |
|
187 | - } |
|
188 | - $this->resources[] = [$root, $webRoot, $file]; |
|
189 | - |
|
190 | - if ($throw && !is_file($root . '/' . $file)) { |
|
191 | - throw new ResourceNotFoundException($file, $webRoot); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns the list of all resources that should be loaded |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function getResources() { |
|
200 | - return $this->resources; |
|
201 | - } |
|
34 | + protected $theme; |
|
35 | + |
|
36 | + protected $mapping; |
|
37 | + protected $serverroot; |
|
38 | + protected $thirdpartyroot; |
|
39 | + protected $webroot; |
|
40 | + |
|
41 | + protected $resources = []; |
|
42 | + |
|
43 | + /** @var \OCP\ILogger */ |
|
44 | + protected $logger; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param \OCP\ILogger $logger |
|
48 | + * @param string $theme |
|
49 | + * @param array $core_map |
|
50 | + * @param array $party_map |
|
51 | + */ |
|
52 | + public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
53 | + $this->logger = $logger; |
|
54 | + $this->theme = $theme; |
|
55 | + $this->mapping = $core_map + $party_map; |
|
56 | + $this->serverroot = key($core_map); |
|
57 | + $this->thirdpartyroot = key($party_map); |
|
58 | + $this->webroot = $this->mapping[$this->serverroot]; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $resource |
|
63 | + */ |
|
64 | + abstract public function doFind($resource); |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $resource |
|
68 | + */ |
|
69 | + abstract public function doFindTheme($resource); |
|
70 | + |
|
71 | + /** |
|
72 | + * Finds the resources and adds them to the list |
|
73 | + * |
|
74 | + * @param array $resources |
|
75 | + */ |
|
76 | + public function find($resources) { |
|
77 | + foreach ($resources as $resource) { |
|
78 | + try { |
|
79 | + $this->doFind($resource); |
|
80 | + } catch (ResourceNotFoundException $e) { |
|
81 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
82 | + $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
83 | + } |
|
84 | + } |
|
85 | + if (!empty($this->theme)) { |
|
86 | + foreach ($resources as $resource) { |
|
87 | + try { |
|
88 | + $this->doFindTheme($resource); |
|
89 | + } catch (ResourceNotFoundException $e) { |
|
90 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
91 | + $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * append the $file resource if exist at $root |
|
99 | + * |
|
100 | + * @param string $root path to check |
|
101 | + * @param string $file the filename |
|
102 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
103 | + * @return bool True if the resource was found, false otherwise |
|
104 | + */ |
|
105 | + protected function appendIfExist($root, $file, $webRoot = null) { |
|
106 | + if (is_file($root.'/'.$file)) { |
|
107 | + $this->append($root, $file, $webRoot, false); |
|
108 | + return true; |
|
109 | + } |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Attempt to find the webRoot |
|
115 | + * |
|
116 | + * traverse the potential web roots upwards in the path |
|
117 | + * |
|
118 | + * example: |
|
119 | + * - root: /srv/www/apps/myapp |
|
120 | + * - available mappings: ['/srv/www'] |
|
121 | + * |
|
122 | + * First we check if a mapping for /srv/www/apps/myapp is available, |
|
123 | + * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
124 | + * valid web root |
|
125 | + * |
|
126 | + * @param string $root |
|
127 | + * @return string|null The web root or null on failure |
|
128 | + */ |
|
129 | + protected function findWebRoot($root) { |
|
130 | + $webRoot = null; |
|
131 | + $tmpRoot = $root; |
|
132 | + |
|
133 | + while ($webRoot === null) { |
|
134 | + if (isset($this->mapping[$tmpRoot])) { |
|
135 | + $webRoot = $this->mapping[$tmpRoot]; |
|
136 | + break; |
|
137 | + } |
|
138 | + |
|
139 | + if ($tmpRoot === '/') { |
|
140 | + break; |
|
141 | + } |
|
142 | + |
|
143 | + $tmpRoot = dirname($tmpRoot); |
|
144 | + } |
|
145 | + |
|
146 | + if ($webRoot === null) { |
|
147 | + $realpath = realpath($root); |
|
148 | + |
|
149 | + if ($realpath && ($realpath !== $root)) { |
|
150 | + return $this->findWebRoot($realpath); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + return $webRoot; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * append the $file resource at $root |
|
159 | + * |
|
160 | + * @param string $root path to check |
|
161 | + * @param string $file the filename |
|
162 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
163 | + * @param bool $throw Throw an exception, when the route does not exist |
|
164 | + * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
165 | + */ |
|
166 | + protected function append($root, $file, $webRoot = null, $throw = true) { |
|
167 | + if (!is_string($root)) { |
|
168 | + if ($throw) { |
|
169 | + throw new ResourceNotFoundException($file, $webRoot); |
|
170 | + } |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + if (!$webRoot) { |
|
175 | + $webRoot = $this->findWebRoot($root); |
|
176 | + |
|
177 | + if ($webRoot === null) { |
|
178 | + $webRoot = ''; |
|
179 | + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
180 | + 'app' => 'lib', |
|
181 | + 'root' => $root, |
|
182 | + 'file' => $file, |
|
183 | + 'webRoot' => $webRoot, |
|
184 | + 'throw' => $throw ? 'true' : 'false' |
|
185 | + ]); |
|
186 | + } |
|
187 | + } |
|
188 | + $this->resources[] = [$root, $webRoot, $file]; |
|
189 | + |
|
190 | + if ($throw && !is_file($root . '/' . $file)) { |
|
191 | + throw new ResourceNotFoundException($file, $webRoot); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns the list of all resources that should be loaded |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function getResources() { |
|
200 | + return $this->resources; |
|
201 | + } |
|
202 | 202 | } |
@@ -117,7 +117,7 @@ |
||
117 | 117 | if (array_key_exists($key, $this->vars)) { |
118 | 118 | $this->vars[$key][] = $value; |
119 | 119 | } else { |
120 | - $this->vars[$key] = [ $value ]; |
|
120 | + $this->vars[$key] = [$value]; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 |
@@ -34,157 +34,157 @@ |
||
34 | 34 | use Throwable; |
35 | 35 | |
36 | 36 | class Base { |
37 | - private $template; // The template |
|
38 | - private $vars; // Vars |
|
39 | - |
|
40 | - /** @var \OCP\IL10N */ |
|
41 | - private $l10n; |
|
42 | - |
|
43 | - /** @var Defaults */ |
|
44 | - private $theme; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $template |
|
48 | - * @param string $requestToken |
|
49 | - * @param \OCP\IL10N $l10n |
|
50 | - * @param Defaults $theme |
|
51 | - */ |
|
52 | - public function __construct($template, $requestToken, $l10n, $theme) { |
|
53 | - $this->vars = []; |
|
54 | - $this->vars['requesttoken'] = $requestToken; |
|
55 | - $this->l10n = $l10n; |
|
56 | - $this->template = $template; |
|
57 | - $this->theme = $theme; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string $serverRoot |
|
62 | - * @param string|false $app_dir |
|
63 | - * @param string $theme |
|
64 | - * @param string $app |
|
65 | - * @return string[] |
|
66 | - */ |
|
67 | - protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
68 | - // Check if the app is in the app folder or in the root |
|
69 | - if (file_exists($app_dir.'/templates/')) { |
|
70 | - return [ |
|
71 | - $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
72 | - $app_dir.'/templates/', |
|
73 | - ]; |
|
74 | - } |
|
75 | - return [ |
|
76 | - $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
77 | - $serverRoot.'/'.$app.'/templates/', |
|
78 | - ]; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $serverRoot |
|
83 | - * @param string $theme |
|
84 | - * @return string[] |
|
85 | - */ |
|
86 | - protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
87 | - return [ |
|
88 | - $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
89 | - $serverRoot.'/core/templates/', |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Assign variables |
|
95 | - * @param string $key key |
|
96 | - * @param array|bool|integer|string|Throwable $value value |
|
97 | - * @return bool |
|
98 | - * |
|
99 | - * This function assigns a variable. It can be accessed via $_[$key] in |
|
100 | - * the template. |
|
101 | - * |
|
102 | - * If the key existed before, it will be overwritten |
|
103 | - */ |
|
104 | - public function assign($key, $value) { |
|
105 | - $this->vars[$key] = $value; |
|
106 | - return true; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Appends a variable |
|
111 | - * @param string $key key |
|
112 | - * @param mixed $value value |
|
113 | - * |
|
114 | - * This function assigns a variable in an array context. If the key already |
|
115 | - * exists, the value will be appended. It can be accessed via |
|
116 | - * $_[$key][$position] in the template. |
|
117 | - */ |
|
118 | - public function append($key, $value) { |
|
119 | - if (array_key_exists($key, $this->vars)) { |
|
120 | - $this->vars[$key][] = $value; |
|
121 | - } else { |
|
122 | - $this->vars[$key] = [ $value ]; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Prints the proceeded template |
|
128 | - * @return bool |
|
129 | - * |
|
130 | - * This function proceeds the template and prints its output. |
|
131 | - */ |
|
132 | - public function printPage() { |
|
133 | - $data = $this->fetchPage(); |
|
134 | - if ($data === false) { |
|
135 | - return false; |
|
136 | - } else { |
|
137 | - print $data; |
|
138 | - return true; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Process the template |
|
144 | - * |
|
145 | - * @param array|null $additionalParams |
|
146 | - * @return string This function processes the template. |
|
147 | - * |
|
148 | - * This function processes the template. |
|
149 | - */ |
|
150 | - public function fetchPage($additionalParams = null) { |
|
151 | - return $this->load($this->template, $additionalParams); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * doing the actual work |
|
156 | - * |
|
157 | - * @param string $file |
|
158 | - * @param array|null $additionalParams |
|
159 | - * @return string content |
|
160 | - * |
|
161 | - * Includes the template file, fetches its output |
|
162 | - */ |
|
163 | - protected function load($file, $additionalParams = null) { |
|
164 | - // Register the variables |
|
165 | - $_ = $this->vars; |
|
166 | - $l = $this->l10n; |
|
167 | - $theme = $this->theme; |
|
168 | - |
|
169 | - if (!is_null($additionalParams)) { |
|
170 | - $_ = array_merge($additionalParams, $this->vars); |
|
171 | - foreach ($_ as $var => $value) { |
|
172 | - ${$var} = $value; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - // Include |
|
177 | - ob_start(); |
|
178 | - try { |
|
179 | - include $file; |
|
180 | - $data = ob_get_contents(); |
|
181 | - } catch (\Exception $e) { |
|
182 | - @ob_end_clean(); |
|
183 | - throw $e; |
|
184 | - } |
|
185 | - @ob_end_clean(); |
|
186 | - |
|
187 | - // Return data |
|
188 | - return $data; |
|
189 | - } |
|
37 | + private $template; // The template |
|
38 | + private $vars; // Vars |
|
39 | + |
|
40 | + /** @var \OCP\IL10N */ |
|
41 | + private $l10n; |
|
42 | + |
|
43 | + /** @var Defaults */ |
|
44 | + private $theme; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $template |
|
48 | + * @param string $requestToken |
|
49 | + * @param \OCP\IL10N $l10n |
|
50 | + * @param Defaults $theme |
|
51 | + */ |
|
52 | + public function __construct($template, $requestToken, $l10n, $theme) { |
|
53 | + $this->vars = []; |
|
54 | + $this->vars['requesttoken'] = $requestToken; |
|
55 | + $this->l10n = $l10n; |
|
56 | + $this->template = $template; |
|
57 | + $this->theme = $theme; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string $serverRoot |
|
62 | + * @param string|false $app_dir |
|
63 | + * @param string $theme |
|
64 | + * @param string $app |
|
65 | + * @return string[] |
|
66 | + */ |
|
67 | + protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
68 | + // Check if the app is in the app folder or in the root |
|
69 | + if (file_exists($app_dir.'/templates/')) { |
|
70 | + return [ |
|
71 | + $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
72 | + $app_dir.'/templates/', |
|
73 | + ]; |
|
74 | + } |
|
75 | + return [ |
|
76 | + $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
77 | + $serverRoot.'/'.$app.'/templates/', |
|
78 | + ]; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $serverRoot |
|
83 | + * @param string $theme |
|
84 | + * @return string[] |
|
85 | + */ |
|
86 | + protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
87 | + return [ |
|
88 | + $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
89 | + $serverRoot.'/core/templates/', |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Assign variables |
|
95 | + * @param string $key key |
|
96 | + * @param array|bool|integer|string|Throwable $value value |
|
97 | + * @return bool |
|
98 | + * |
|
99 | + * This function assigns a variable. It can be accessed via $_[$key] in |
|
100 | + * the template. |
|
101 | + * |
|
102 | + * If the key existed before, it will be overwritten |
|
103 | + */ |
|
104 | + public function assign($key, $value) { |
|
105 | + $this->vars[$key] = $value; |
|
106 | + return true; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Appends a variable |
|
111 | + * @param string $key key |
|
112 | + * @param mixed $value value |
|
113 | + * |
|
114 | + * This function assigns a variable in an array context. If the key already |
|
115 | + * exists, the value will be appended. It can be accessed via |
|
116 | + * $_[$key][$position] in the template. |
|
117 | + */ |
|
118 | + public function append($key, $value) { |
|
119 | + if (array_key_exists($key, $this->vars)) { |
|
120 | + $this->vars[$key][] = $value; |
|
121 | + } else { |
|
122 | + $this->vars[$key] = [ $value ]; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Prints the proceeded template |
|
128 | + * @return bool |
|
129 | + * |
|
130 | + * This function proceeds the template and prints its output. |
|
131 | + */ |
|
132 | + public function printPage() { |
|
133 | + $data = $this->fetchPage(); |
|
134 | + if ($data === false) { |
|
135 | + return false; |
|
136 | + } else { |
|
137 | + print $data; |
|
138 | + return true; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Process the template |
|
144 | + * |
|
145 | + * @param array|null $additionalParams |
|
146 | + * @return string This function processes the template. |
|
147 | + * |
|
148 | + * This function processes the template. |
|
149 | + */ |
|
150 | + public function fetchPage($additionalParams = null) { |
|
151 | + return $this->load($this->template, $additionalParams); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * doing the actual work |
|
156 | + * |
|
157 | + * @param string $file |
|
158 | + * @param array|null $additionalParams |
|
159 | + * @return string content |
|
160 | + * |
|
161 | + * Includes the template file, fetches its output |
|
162 | + */ |
|
163 | + protected function load($file, $additionalParams = null) { |
|
164 | + // Register the variables |
|
165 | + $_ = $this->vars; |
|
166 | + $l = $this->l10n; |
|
167 | + $theme = $this->theme; |
|
168 | + |
|
169 | + if (!is_null($additionalParams)) { |
|
170 | + $_ = array_merge($additionalParams, $this->vars); |
|
171 | + foreach ($_ as $var => $value) { |
|
172 | + ${$var} = $value; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + // Include |
|
177 | + ob_start(); |
|
178 | + try { |
|
179 | + include $file; |
|
180 | + $data = ob_get_contents(); |
|
181 | + } catch (\Exception $e) { |
|
182 | + @ob_end_clean(); |
|
183 | + throw $e; |
|
184 | + } |
|
185 | + @ob_end_clean(); |
|
186 | + |
|
187 | + // Return data |
|
188 | + return $data; |
|
189 | + } |
|
190 | 190 | } |