@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
127 | 127 | $template->addHeader(); |
128 | 128 | $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
129 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
129 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | 130 | $template->addFooter(); |
131 | 131 | |
132 | 132 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
197 | 197 | $template->addHeader(); |
198 | 198 | $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
199 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
199 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | 200 | if ($user->getEMailAddress()) { |
201 | 201 | $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
202 | 202 | } |
@@ -34,179 +34,179 @@ |
||
34 | 34 | |
35 | 35 | class Hooks { |
36 | 36 | |
37 | - /** @var IActivityManager */ |
|
38 | - protected $activityManager; |
|
39 | - /** @var IUserManager */ |
|
40 | - protected $userManager; |
|
41 | - /** @var IUserSession */ |
|
42 | - protected $userSession; |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $urlGenerator; |
|
45 | - /** @var IMailer */ |
|
46 | - protected $mailer; |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - /** @var IFactory */ |
|
50 | - protected $languageFactory; |
|
51 | - /** @var IL10N */ |
|
52 | - protected $l; |
|
53 | - |
|
54 | - public function __construct(IActivityManager $activityManager, |
|
55 | - IUserManager $userManager, |
|
56 | - IUserSession $userSession, |
|
57 | - IURLGenerator $urlGenerator, |
|
58 | - IMailer $mailer, |
|
59 | - IConfig $config, |
|
60 | - IFactory $languageFactory, |
|
61 | - IL10N $l) { |
|
62 | - $this->activityManager = $activityManager; |
|
63 | - $this->userManager = $userManager; |
|
64 | - $this->userSession = $userSession; |
|
65 | - $this->urlGenerator = $urlGenerator; |
|
66 | - $this->mailer = $mailer; |
|
67 | - $this->config = $config; |
|
68 | - $this->languageFactory = $languageFactory; |
|
69 | - $this->l = $l; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $uid |
|
74 | - * @throws \InvalidArgumentException |
|
75 | - * @throws \BadMethodCallException |
|
76 | - * @throws \Exception |
|
77 | - */ |
|
78 | - public function onChangePassword($uid) { |
|
79 | - $user = $this->userManager->get($uid); |
|
80 | - |
|
81 | - if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
82 | - // User didn't login, so don't create activities and emails. |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - $event = $this->activityManager->generateEvent(); |
|
87 | - $event->setApp('settings') |
|
88 | - ->setType('personal_settings') |
|
89 | - ->setAffectedUser($user->getUID()); |
|
90 | - |
|
91 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
92 | - |
|
93 | - $actor = $this->userSession->getUser(); |
|
94 | - if ($actor instanceof IUser) { |
|
95 | - if ($actor->getUID() !== $user->getUID()) { |
|
96 | - $this->l = $this->languageFactory->get( |
|
97 | - 'settings', |
|
98 | - $this->config->getUserValue( |
|
99 | - $user->getUID(), 'core', 'lang', |
|
100 | - $this->config->getSystemValue('default_language', 'en') |
|
101 | - ) |
|
102 | - ); |
|
103 | - |
|
104 | - $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
105 | - $event->setAuthor($actor->getUID()) |
|
106 | - ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
107 | - } else { |
|
108 | - $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
109 | - $event->setAuthor($actor->getUID()) |
|
110 | - ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
111 | - } |
|
112 | - } else { |
|
113 | - $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
114 | - $event->setSubject(Provider::PASSWORD_RESET); |
|
115 | - } |
|
116 | - |
|
117 | - $this->activityManager->publish($event); |
|
118 | - |
|
119 | - if ($user->getEMailAddress() !== null) { |
|
120 | - $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
121 | - 'displayname' => $user->getDisplayName(), |
|
122 | - 'emailAddress' => $user->getEMailAddress(), |
|
123 | - 'instanceUrl' => $instanceUrl, |
|
124 | - ]); |
|
125 | - |
|
126 | - $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
127 | - $template->addHeader(); |
|
128 | - $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
129 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | - $template->addFooter(); |
|
131 | - |
|
132 | - |
|
133 | - $message = $this->mailer->createMessage(); |
|
134 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
135 | - $message->useTemplate($template); |
|
136 | - $this->mailer->send($message); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param IUser $user |
|
142 | - * @param string|null $oldMailAddress |
|
143 | - * @throws \InvalidArgumentException |
|
144 | - * @throws \BadMethodCallException |
|
145 | - */ |
|
146 | - public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
147 | - |
|
148 | - if ($oldMailAddress === $user->getEMailAddress() || |
|
149 | - $user->getLastLogin() === 0) { |
|
150 | - // Email didn't really change or user didn't login, |
|
151 | - // so don't create activities and emails. |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $event = $this->activityManager->generateEvent(); |
|
156 | - $event->setApp('settings') |
|
157 | - ->setType('personal_settings') |
|
158 | - ->setAffectedUser($user->getUID()); |
|
159 | - |
|
160 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
161 | - |
|
162 | - $actor = $this->userSession->getUser(); |
|
163 | - if ($actor instanceof IUser) { |
|
164 | - if ($actor->getUID() !== $user->getUID()) { |
|
165 | - $this->l = $this->languageFactory->get( |
|
166 | - 'settings', |
|
167 | - $this->config->getUserValue( |
|
168 | - $user->getUID(), 'core', 'lang', |
|
169 | - $this->config->getSystemValue('default_language', 'en') |
|
170 | - ) |
|
171 | - ); |
|
172 | - |
|
173 | - $text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
174 | - $event->setAuthor($actor->getUID()) |
|
175 | - ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); |
|
176 | - } else { |
|
177 | - $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
178 | - $event->setAuthor($actor->getUID()) |
|
179 | - ->setSubject(Provider::EMAIL_CHANGED_SELF); |
|
180 | - } |
|
181 | - } else { |
|
182 | - $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
183 | - $event->setSubject(Provider::EMAIL_CHANGED); |
|
184 | - } |
|
185 | - $this->activityManager->publish($event); |
|
186 | - |
|
187 | - |
|
188 | - if ($oldMailAddress !== null) { |
|
189 | - $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
190 | - 'displayname' => $user->getDisplayName(), |
|
191 | - 'newEMailAddress' => $user->getEMailAddress(), |
|
192 | - 'oldEMailAddress' => $oldMailAddress, |
|
193 | - 'instanceUrl' => $instanceUrl, |
|
194 | - ]); |
|
195 | - |
|
196 | - $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
197 | - $template->addHeader(); |
|
198 | - $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
199 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | - if ($user->getEMailAddress()) { |
|
201 | - $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
202 | - } |
|
203 | - $template->addFooter(); |
|
204 | - |
|
205 | - |
|
206 | - $message = $this->mailer->createMessage(); |
|
207 | - $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
208 | - $message->useTemplate($template); |
|
209 | - $this->mailer->send($message); |
|
210 | - } |
|
211 | - } |
|
37 | + /** @var IActivityManager */ |
|
38 | + protected $activityManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + protected $userManager; |
|
41 | + /** @var IUserSession */ |
|
42 | + protected $userSession; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $urlGenerator; |
|
45 | + /** @var IMailer */ |
|
46 | + protected $mailer; |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + /** @var IFactory */ |
|
50 | + protected $languageFactory; |
|
51 | + /** @var IL10N */ |
|
52 | + protected $l; |
|
53 | + |
|
54 | + public function __construct(IActivityManager $activityManager, |
|
55 | + IUserManager $userManager, |
|
56 | + IUserSession $userSession, |
|
57 | + IURLGenerator $urlGenerator, |
|
58 | + IMailer $mailer, |
|
59 | + IConfig $config, |
|
60 | + IFactory $languageFactory, |
|
61 | + IL10N $l) { |
|
62 | + $this->activityManager = $activityManager; |
|
63 | + $this->userManager = $userManager; |
|
64 | + $this->userSession = $userSession; |
|
65 | + $this->urlGenerator = $urlGenerator; |
|
66 | + $this->mailer = $mailer; |
|
67 | + $this->config = $config; |
|
68 | + $this->languageFactory = $languageFactory; |
|
69 | + $this->l = $l; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $uid |
|
74 | + * @throws \InvalidArgumentException |
|
75 | + * @throws \BadMethodCallException |
|
76 | + * @throws \Exception |
|
77 | + */ |
|
78 | + public function onChangePassword($uid) { |
|
79 | + $user = $this->userManager->get($uid); |
|
80 | + |
|
81 | + if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
82 | + // User didn't login, so don't create activities and emails. |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + $event = $this->activityManager->generateEvent(); |
|
87 | + $event->setApp('settings') |
|
88 | + ->setType('personal_settings') |
|
89 | + ->setAffectedUser($user->getUID()); |
|
90 | + |
|
91 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
92 | + |
|
93 | + $actor = $this->userSession->getUser(); |
|
94 | + if ($actor instanceof IUser) { |
|
95 | + if ($actor->getUID() !== $user->getUID()) { |
|
96 | + $this->l = $this->languageFactory->get( |
|
97 | + 'settings', |
|
98 | + $this->config->getUserValue( |
|
99 | + $user->getUID(), 'core', 'lang', |
|
100 | + $this->config->getSystemValue('default_language', 'en') |
|
101 | + ) |
|
102 | + ); |
|
103 | + |
|
104 | + $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
105 | + $event->setAuthor($actor->getUID()) |
|
106 | + ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
107 | + } else { |
|
108 | + $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
109 | + $event->setAuthor($actor->getUID()) |
|
110 | + ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
111 | + } |
|
112 | + } else { |
|
113 | + $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
114 | + $event->setSubject(Provider::PASSWORD_RESET); |
|
115 | + } |
|
116 | + |
|
117 | + $this->activityManager->publish($event); |
|
118 | + |
|
119 | + if ($user->getEMailAddress() !== null) { |
|
120 | + $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
121 | + 'displayname' => $user->getDisplayName(), |
|
122 | + 'emailAddress' => $user->getEMailAddress(), |
|
123 | + 'instanceUrl' => $instanceUrl, |
|
124 | + ]); |
|
125 | + |
|
126 | + $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
127 | + $template->addHeader(); |
|
128 | + $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
129 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | + $template->addFooter(); |
|
131 | + |
|
132 | + |
|
133 | + $message = $this->mailer->createMessage(); |
|
134 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
135 | + $message->useTemplate($template); |
|
136 | + $this->mailer->send($message); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param IUser $user |
|
142 | + * @param string|null $oldMailAddress |
|
143 | + * @throws \InvalidArgumentException |
|
144 | + * @throws \BadMethodCallException |
|
145 | + */ |
|
146 | + public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
147 | + |
|
148 | + if ($oldMailAddress === $user->getEMailAddress() || |
|
149 | + $user->getLastLogin() === 0) { |
|
150 | + // Email didn't really change or user didn't login, |
|
151 | + // so don't create activities and emails. |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $event = $this->activityManager->generateEvent(); |
|
156 | + $event->setApp('settings') |
|
157 | + ->setType('personal_settings') |
|
158 | + ->setAffectedUser($user->getUID()); |
|
159 | + |
|
160 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
161 | + |
|
162 | + $actor = $this->userSession->getUser(); |
|
163 | + if ($actor instanceof IUser) { |
|
164 | + if ($actor->getUID() !== $user->getUID()) { |
|
165 | + $this->l = $this->languageFactory->get( |
|
166 | + 'settings', |
|
167 | + $this->config->getUserValue( |
|
168 | + $user->getUID(), 'core', 'lang', |
|
169 | + $this->config->getSystemValue('default_language', 'en') |
|
170 | + ) |
|
171 | + ); |
|
172 | + |
|
173 | + $text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
174 | + $event->setAuthor($actor->getUID()) |
|
175 | + ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); |
|
176 | + } else { |
|
177 | + $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
178 | + $event->setAuthor($actor->getUID()) |
|
179 | + ->setSubject(Provider::EMAIL_CHANGED_SELF); |
|
180 | + } |
|
181 | + } else { |
|
182 | + $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
183 | + $event->setSubject(Provider::EMAIL_CHANGED); |
|
184 | + } |
|
185 | + $this->activityManager->publish($event); |
|
186 | + |
|
187 | + |
|
188 | + if ($oldMailAddress !== null) { |
|
189 | + $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
190 | + 'displayname' => $user->getDisplayName(), |
|
191 | + 'newEMailAddress' => $user->getEMailAddress(), |
|
192 | + 'oldEMailAddress' => $oldMailAddress, |
|
193 | + 'instanceUrl' => $instanceUrl, |
|
194 | + ]); |
|
195 | + |
|
196 | + $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
197 | + $template->addHeader(); |
|
198 | + $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
199 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | + if ($user->getEMailAddress()) { |
|
201 | + $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
202 | + } |
|
203 | + $template->addFooter(); |
|
204 | + |
|
205 | + |
|
206 | + $message = $this->mailer->createMessage(); |
|
207 | + $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
208 | + $message->useTemplate($template); |
|
209 | + $this->mailer->send($message); |
|
210 | + } |
|
211 | + } |
|
212 | 212 | } |
@@ -37,45 +37,45 @@ |
||
37 | 37 | class CreateVersionEvent extends Event { |
38 | 38 | |
39 | 39 | |
40 | - /** @var bool */ |
|
41 | - private $createVersion; |
|
40 | + /** @var bool */ |
|
41 | + private $createVersion; |
|
42 | 42 | |
43 | - /** @var Node */ |
|
44 | - private $node; |
|
43 | + /** @var Node */ |
|
44 | + private $node; |
|
45 | 45 | |
46 | - /** |
|
47 | - * CreateVersionEvent constructor. |
|
48 | - * |
|
49 | - * @param Node $node |
|
50 | - */ |
|
51 | - public function __construct(Node $node) { |
|
52 | - $this->createVersion = true; |
|
53 | - $this->node = $node; |
|
54 | - } |
|
46 | + /** |
|
47 | + * CreateVersionEvent constructor. |
|
48 | + * |
|
49 | + * @param Node $node |
|
50 | + */ |
|
51 | + public function __construct(Node $node) { |
|
52 | + $this->createVersion = true; |
|
53 | + $this->node = $node; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * get Node of the file which should be versioned |
|
58 | - * |
|
59 | - * @return Node |
|
60 | - */ |
|
61 | - public function getNode() { |
|
62 | - return $this->node; |
|
63 | - } |
|
56 | + /** |
|
57 | + * get Node of the file which should be versioned |
|
58 | + * |
|
59 | + * @return Node |
|
60 | + */ |
|
61 | + public function getNode() { |
|
62 | + return $this->node; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * disable versions for this file |
|
67 | - */ |
|
68 | - public function disableVersions() { |
|
69 | - $this->createVersion = false; |
|
70 | - } |
|
65 | + /** |
|
66 | + * disable versions for this file |
|
67 | + */ |
|
68 | + public function disableVersions() { |
|
69 | + $this->createVersion = false; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * should a version be created for this file? |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function shouldCreateVersion() { |
|
78 | - return $this->createVersion; |
|
79 | - } |
|
72 | + /** |
|
73 | + * should a version be created for this file? |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function shouldCreateVersion() { |
|
78 | + return $this->createVersion; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | $icon->setImageFormat("png32"); |
64 | 64 | |
65 | 65 | $clone = clone $icon; |
66 | - $clone->scaleImage(16,0); |
|
66 | + $clone->scaleImage(16, 0); |
|
67 | 67 | $favicon->addImage($clone); |
68 | 68 | |
69 | 69 | $clone = clone $icon; |
70 | - $clone->scaleImage(32,0); |
|
70 | + $clone->scaleImage(32, 0); |
|
71 | 71 | $favicon->addImage($clone); |
72 | 72 | |
73 | 73 | $clone = clone $icon; |
74 | - $clone->scaleImage(64,0); |
|
74 | + $clone->scaleImage(64, 0); |
|
75 | 75 | $favicon->addImage($clone); |
76 | 76 | |
77 | 77 | $clone = clone $icon; |
78 | - $clone->scaleImage(128,0); |
|
78 | + $clone->scaleImage(128, 0); |
|
79 | 79 | $favicon->addImage($clone); |
80 | 80 | |
81 | 81 | $data = $favicon->getImagesBlob(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function renderAppIcon($app, $size) { |
119 | 119 | $appIcon = $this->util->getAppIcon($app); |
120 | - if($appIcon === false) { |
|
120 | + if ($appIcon === false) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | if ($appIcon instanceof ISimpleFile) { |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $mime = mime_content_type($appIcon); |
129 | 129 | } |
130 | 130 | |
131 | - if($appIconContent === false || $appIconContent === "") { |
|
131 | + if ($appIconContent === false || $appIconContent === "") { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $color = $this->themingDefaults->getColorPrimary(); |
136 | 136 | |
137 | 137 | // generate background image with rounded corners |
138 | - $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
139 | - '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
140 | - '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
138 | + $background = '<?xml version="1.0" encoding="UTF-8"?>'. |
|
139 | + '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">'. |
|
140 | + '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:'.$color.';" />'. |
|
141 | 141 | '</svg>'; |
142 | 142 | // resize svg magic as this seems broken in Imagemagick |
143 | - if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
144 | - if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
143 | + if ($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
144 | + if (substr($appIconContent, 0, 5) !== "<?xml") { |
|
145 | 145 | $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
146 | 146 | } else { |
147 | 147 | $svg = $appIconContent; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $res = $tmp->getImageResolution(); |
154 | 154 | $tmp->destroy(); |
155 | 155 | |
156 | - if($x>$y) { |
|
156 | + if ($x > $y) { |
|
157 | 157 | $max = $x; |
158 | 158 | } else { |
159 | 159 | $max = $y; |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | // convert svg to resized image |
163 | 163 | $appIconFile = new Imagick(); |
164 | - $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
165 | - $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
164 | + $resX = (int) (512 * $res['x'] / $max * 2.53); |
|
165 | + $resY = (int) (512 * $res['y'] / $max * 2.53); |
|
166 | 166 | $appIconFile->setResolution($resX, $resY); |
167 | 167 | $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
168 | 168 | $appIconFile->readImageBlob($svg); |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | $appIconFile->scaleImage(512, 512, true); |
186 | 186 | } |
187 | 187 | // offset for icon positioning |
188 | - $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
189 | - $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
190 | - $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
191 | - $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
188 | + $border_w = (int) ($appIconFile->getImageWidth() * 0.05); |
|
189 | + $border_h = (int) ($appIconFile->getImageHeight() * 0.05); |
|
190 | + $innerWidth = (int) ($appIconFile->getImageWidth() - $border_w * 2); |
|
191 | + $innerHeight = (int) ($appIconFile->getImageHeight() - $border_h * 2); |
|
192 | 192 | $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
193 | 193 | // center icon |
194 | 194 | $offset_w = 512 / 2 - $innerWidth / 2; |
@@ -31,211 +31,211 @@ |
||
31 | 31 | use OCP\Files\SimpleFS\ISimpleFile; |
32 | 32 | |
33 | 33 | class IconBuilder { |
34 | - /** @var ThemingDefaults */ |
|
35 | - private $themingDefaults; |
|
36 | - /** @var Util */ |
|
37 | - private $util; |
|
38 | - /** @var ImageManager */ |
|
39 | - private $imageManager; |
|
40 | - |
|
41 | - /** |
|
42 | - * IconBuilder constructor. |
|
43 | - * |
|
44 | - * @param ThemingDefaults $themingDefaults |
|
45 | - * @param Util $util |
|
46 | - * @param ImageManager $imageManager |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ThemingDefaults $themingDefaults, |
|
50 | - Util $util, |
|
51 | - ImageManager $imageManager |
|
52 | - ) { |
|
53 | - $this->themingDefaults = $themingDefaults; |
|
54 | - $this->util = $util; |
|
55 | - $this->imageManager = $imageManager; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param $app string app name |
|
60 | - * @return string|false image blob |
|
61 | - */ |
|
62 | - public function getFavicon($app) { |
|
63 | - if (!$this->imageManager->shouldReplaceIcons()) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - try { |
|
67 | - $favicon = new Imagick(); |
|
68 | - $favicon->setFormat("ico"); |
|
69 | - $icon = $this->renderAppIcon($app, 128); |
|
70 | - if ($icon === false) { |
|
71 | - return false; |
|
72 | - } |
|
73 | - $icon->setImageFormat("png32"); |
|
74 | - |
|
75 | - $clone = clone $icon; |
|
76 | - $clone->scaleImage(16,0); |
|
77 | - $favicon->addImage($clone); |
|
78 | - |
|
79 | - $clone = clone $icon; |
|
80 | - $clone->scaleImage(32,0); |
|
81 | - $favicon->addImage($clone); |
|
82 | - |
|
83 | - $clone = clone $icon; |
|
84 | - $clone->scaleImage(64,0); |
|
85 | - $favicon->addImage($clone); |
|
86 | - |
|
87 | - $clone = clone $icon; |
|
88 | - $clone->scaleImage(128,0); |
|
89 | - $favicon->addImage($clone); |
|
90 | - |
|
91 | - $data = $favicon->getImagesBlob(); |
|
92 | - $favicon->destroy(); |
|
93 | - $icon->destroy(); |
|
94 | - $clone->destroy(); |
|
95 | - return $data; |
|
96 | - } catch (\ImagickException $e) { |
|
97 | - return false; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $app string app name |
|
103 | - * @return string|false image blob |
|
104 | - */ |
|
105 | - public function getTouchIcon($app) { |
|
106 | - try { |
|
107 | - $icon = $this->renderAppIcon($app, 512); |
|
108 | - if ($icon === false) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - $icon->setImageFormat("png32"); |
|
112 | - $data = $icon->getImageBlob(); |
|
113 | - $icon->destroy(); |
|
114 | - return $data; |
|
115 | - } catch (\ImagickException $e) { |
|
116 | - return false; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Render app icon on themed background color |
|
122 | - * fallback to logo |
|
123 | - * |
|
124 | - * @param $app string app name |
|
125 | - * @param $size int size of the icon in px |
|
126 | - * @return Imagick|false |
|
127 | - */ |
|
128 | - public function renderAppIcon($app, $size) { |
|
129 | - $appIcon = $this->util->getAppIcon($app); |
|
130 | - if($appIcon === false) { |
|
131 | - return false; |
|
132 | - } |
|
133 | - if ($appIcon instanceof ISimpleFile) { |
|
134 | - $appIconContent = $appIcon->getContent(); |
|
135 | - $mime = $appIcon->getMimeType(); |
|
136 | - } else { |
|
137 | - $appIconContent = file_get_contents($appIcon); |
|
138 | - $mime = mime_content_type($appIcon); |
|
139 | - } |
|
140 | - |
|
141 | - if($appIconContent === false || $appIconContent === "") { |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - $color = $this->themingDefaults->getColorPrimary(); |
|
146 | - |
|
147 | - // generate background image with rounded corners |
|
148 | - $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
149 | - '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
150 | - '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
151 | - '</svg>'; |
|
152 | - // resize svg magic as this seems broken in Imagemagick |
|
153 | - if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
154 | - if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
155 | - $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
|
156 | - } else { |
|
157 | - $svg = $appIconContent; |
|
158 | - } |
|
159 | - $tmp = new Imagick(); |
|
160 | - $tmp->readImageBlob($svg); |
|
161 | - $x = $tmp->getImageWidth(); |
|
162 | - $y = $tmp->getImageHeight(); |
|
163 | - $res = $tmp->getImageResolution(); |
|
164 | - $tmp->destroy(); |
|
165 | - |
|
166 | - if($x>$y) { |
|
167 | - $max = $x; |
|
168 | - } else { |
|
169 | - $max = $y; |
|
170 | - } |
|
171 | - |
|
172 | - // convert svg to resized image |
|
173 | - $appIconFile = new Imagick(); |
|
174 | - $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
175 | - $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
176 | - $appIconFile->setResolution($resX, $resY); |
|
177 | - $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
178 | - $appIconFile->readImageBlob($svg); |
|
179 | - |
|
180 | - /** |
|
181 | - * invert app icons for bright primary colors |
|
182 | - * the default nextcloud logo will not be inverted to black |
|
183 | - */ |
|
184 | - if ($this->util->invertTextColor($color) |
|
185 | - && !$appIcon instanceof ISimpleFile |
|
186 | - && $app !== "core" |
|
187 | - ) { |
|
188 | - $appIconFile->negateImage(false); |
|
189 | - } |
|
190 | - $appIconFile->scaleImage(512, 512, true); |
|
191 | - } else { |
|
192 | - $appIconFile = new Imagick(); |
|
193 | - $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
194 | - $appIconFile->readImageBlob($appIconContent); |
|
195 | - $appIconFile->scaleImage(512, 512, true); |
|
196 | - } |
|
197 | - // offset for icon positioning |
|
198 | - $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
199 | - $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
200 | - $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
201 | - $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
202 | - $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
|
203 | - // center icon |
|
204 | - $offset_w = 512 / 2 - $innerWidth / 2; |
|
205 | - $offset_h = 512 / 2 - $innerHeight / 2; |
|
206 | - |
|
207 | - $finalIconFile = new Imagick(); |
|
208 | - $finalIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
209 | - $finalIconFile->readImageBlob($background); |
|
210 | - $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
|
211 | - $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5"); |
|
212 | - $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h); |
|
213 | - $finalIconFile->setImageFormat('png24'); |
|
214 | - if (defined("Imagick::INTERPOLATE_BICUBIC") === true) { |
|
215 | - $filter = Imagick::INTERPOLATE_BICUBIC; |
|
216 | - } else { |
|
217 | - $filter = Imagick::FILTER_LANCZOS; |
|
218 | - } |
|
219 | - $finalIconFile->resizeImage($size, $size, $filter, 1, false); |
|
220 | - |
|
221 | - $appIconFile->destroy(); |
|
222 | - return $finalIconFile; |
|
223 | - } |
|
224 | - |
|
225 | - public function colorSvg($app, $image) { |
|
226 | - try { |
|
227 | - $imageFile = $this->util->getAppImage($app, $image); |
|
228 | - } catch (AppPathNotFoundException $e) { |
|
229 | - return false; |
|
230 | - } |
|
231 | - $svg = file_get_contents($imageFile); |
|
232 | - if ($svg !== false && $svg !== "") { |
|
233 | - $color = $this->util->elementColor($this->themingDefaults->getColorPrimary()); |
|
234 | - $svg = $this->util->colorizeSvg($svg, $color); |
|
235 | - return $svg; |
|
236 | - } else { |
|
237 | - return false; |
|
238 | - } |
|
239 | - } |
|
34 | + /** @var ThemingDefaults */ |
|
35 | + private $themingDefaults; |
|
36 | + /** @var Util */ |
|
37 | + private $util; |
|
38 | + /** @var ImageManager */ |
|
39 | + private $imageManager; |
|
40 | + |
|
41 | + /** |
|
42 | + * IconBuilder constructor. |
|
43 | + * |
|
44 | + * @param ThemingDefaults $themingDefaults |
|
45 | + * @param Util $util |
|
46 | + * @param ImageManager $imageManager |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ThemingDefaults $themingDefaults, |
|
50 | + Util $util, |
|
51 | + ImageManager $imageManager |
|
52 | + ) { |
|
53 | + $this->themingDefaults = $themingDefaults; |
|
54 | + $this->util = $util; |
|
55 | + $this->imageManager = $imageManager; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param $app string app name |
|
60 | + * @return string|false image blob |
|
61 | + */ |
|
62 | + public function getFavicon($app) { |
|
63 | + if (!$this->imageManager->shouldReplaceIcons()) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + try { |
|
67 | + $favicon = new Imagick(); |
|
68 | + $favicon->setFormat("ico"); |
|
69 | + $icon = $this->renderAppIcon($app, 128); |
|
70 | + if ($icon === false) { |
|
71 | + return false; |
|
72 | + } |
|
73 | + $icon->setImageFormat("png32"); |
|
74 | + |
|
75 | + $clone = clone $icon; |
|
76 | + $clone->scaleImage(16,0); |
|
77 | + $favicon->addImage($clone); |
|
78 | + |
|
79 | + $clone = clone $icon; |
|
80 | + $clone->scaleImage(32,0); |
|
81 | + $favicon->addImage($clone); |
|
82 | + |
|
83 | + $clone = clone $icon; |
|
84 | + $clone->scaleImage(64,0); |
|
85 | + $favicon->addImage($clone); |
|
86 | + |
|
87 | + $clone = clone $icon; |
|
88 | + $clone->scaleImage(128,0); |
|
89 | + $favicon->addImage($clone); |
|
90 | + |
|
91 | + $data = $favicon->getImagesBlob(); |
|
92 | + $favicon->destroy(); |
|
93 | + $icon->destroy(); |
|
94 | + $clone->destroy(); |
|
95 | + return $data; |
|
96 | + } catch (\ImagickException $e) { |
|
97 | + return false; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $app string app name |
|
103 | + * @return string|false image blob |
|
104 | + */ |
|
105 | + public function getTouchIcon($app) { |
|
106 | + try { |
|
107 | + $icon = $this->renderAppIcon($app, 512); |
|
108 | + if ($icon === false) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + $icon->setImageFormat("png32"); |
|
112 | + $data = $icon->getImageBlob(); |
|
113 | + $icon->destroy(); |
|
114 | + return $data; |
|
115 | + } catch (\ImagickException $e) { |
|
116 | + return false; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Render app icon on themed background color |
|
122 | + * fallback to logo |
|
123 | + * |
|
124 | + * @param $app string app name |
|
125 | + * @param $size int size of the icon in px |
|
126 | + * @return Imagick|false |
|
127 | + */ |
|
128 | + public function renderAppIcon($app, $size) { |
|
129 | + $appIcon = $this->util->getAppIcon($app); |
|
130 | + if($appIcon === false) { |
|
131 | + return false; |
|
132 | + } |
|
133 | + if ($appIcon instanceof ISimpleFile) { |
|
134 | + $appIconContent = $appIcon->getContent(); |
|
135 | + $mime = $appIcon->getMimeType(); |
|
136 | + } else { |
|
137 | + $appIconContent = file_get_contents($appIcon); |
|
138 | + $mime = mime_content_type($appIcon); |
|
139 | + } |
|
140 | + |
|
141 | + if($appIconContent === false || $appIconContent === "") { |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + $color = $this->themingDefaults->getColorPrimary(); |
|
146 | + |
|
147 | + // generate background image with rounded corners |
|
148 | + $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
149 | + '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
150 | + '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
151 | + '</svg>'; |
|
152 | + // resize svg magic as this seems broken in Imagemagick |
|
153 | + if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
154 | + if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
155 | + $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
|
156 | + } else { |
|
157 | + $svg = $appIconContent; |
|
158 | + } |
|
159 | + $tmp = new Imagick(); |
|
160 | + $tmp->readImageBlob($svg); |
|
161 | + $x = $tmp->getImageWidth(); |
|
162 | + $y = $tmp->getImageHeight(); |
|
163 | + $res = $tmp->getImageResolution(); |
|
164 | + $tmp->destroy(); |
|
165 | + |
|
166 | + if($x>$y) { |
|
167 | + $max = $x; |
|
168 | + } else { |
|
169 | + $max = $y; |
|
170 | + } |
|
171 | + |
|
172 | + // convert svg to resized image |
|
173 | + $appIconFile = new Imagick(); |
|
174 | + $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
175 | + $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
176 | + $appIconFile->setResolution($resX, $resY); |
|
177 | + $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
178 | + $appIconFile->readImageBlob($svg); |
|
179 | + |
|
180 | + /** |
|
181 | + * invert app icons for bright primary colors |
|
182 | + * the default nextcloud logo will not be inverted to black |
|
183 | + */ |
|
184 | + if ($this->util->invertTextColor($color) |
|
185 | + && !$appIcon instanceof ISimpleFile |
|
186 | + && $app !== "core" |
|
187 | + ) { |
|
188 | + $appIconFile->negateImage(false); |
|
189 | + } |
|
190 | + $appIconFile->scaleImage(512, 512, true); |
|
191 | + } else { |
|
192 | + $appIconFile = new Imagick(); |
|
193 | + $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
194 | + $appIconFile->readImageBlob($appIconContent); |
|
195 | + $appIconFile->scaleImage(512, 512, true); |
|
196 | + } |
|
197 | + // offset for icon positioning |
|
198 | + $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
199 | + $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
200 | + $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
201 | + $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
202 | + $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
|
203 | + // center icon |
|
204 | + $offset_w = 512 / 2 - $innerWidth / 2; |
|
205 | + $offset_h = 512 / 2 - $innerHeight / 2; |
|
206 | + |
|
207 | + $finalIconFile = new Imagick(); |
|
208 | + $finalIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
209 | + $finalIconFile->readImageBlob($background); |
|
210 | + $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
|
211 | + $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5"); |
|
212 | + $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h); |
|
213 | + $finalIconFile->setImageFormat('png24'); |
|
214 | + if (defined("Imagick::INTERPOLATE_BICUBIC") === true) { |
|
215 | + $filter = Imagick::INTERPOLATE_BICUBIC; |
|
216 | + } else { |
|
217 | + $filter = Imagick::FILTER_LANCZOS; |
|
218 | + } |
|
219 | + $finalIconFile->resizeImage($size, $size, $filter, 1, false); |
|
220 | + |
|
221 | + $appIconFile->destroy(); |
|
222 | + return $finalIconFile; |
|
223 | + } |
|
224 | + |
|
225 | + public function colorSvg($app, $image) { |
|
226 | + try { |
|
227 | + $imageFile = $this->util->getAppImage($app, $image); |
|
228 | + } catch (AppPathNotFoundException $e) { |
|
229 | + return false; |
|
230 | + } |
|
231 | + $svg = file_get_contents($imageFile); |
|
232 | + if ($svg !== false && $svg !== "") { |
|
233 | + $color = $this->util->elementColor($this->themingDefaults->getColorPrimary()); |
|
234 | + $svg = $this->util->colorizeSvg($svg, $color); |
|
235 | + return $svg; |
|
236 | + } else { |
|
237 | + return false; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @package OCP |
30 | 30 | * @since 7.0.0 |
31 | 31 | */ |
32 | -interface ICacheFactory{ |
|
32 | +interface ICacheFactory { |
|
33 | 33 | /** |
34 | 34 | * Get a distributed memory cache instance |
35 | 35 | * |
@@ -31,58 +31,58 @@ |
||
31 | 31 | * @since 7.0.0 |
32 | 32 | */ |
33 | 33 | interface ICacheFactory{ |
34 | - /** |
|
35 | - * Get a distributed memory cache instance |
|
36 | - * |
|
37 | - * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps |
|
38 | - * |
|
39 | - * @param string $prefix |
|
40 | - * @return ICache |
|
41 | - * @since 7.0.0 |
|
42 | - * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal |
|
43 | - */ |
|
44 | - public function create(string $prefix = ''): ICache; |
|
34 | + /** |
|
35 | + * Get a distributed memory cache instance |
|
36 | + * |
|
37 | + * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps |
|
38 | + * |
|
39 | + * @param string $prefix |
|
40 | + * @return ICache |
|
41 | + * @since 7.0.0 |
|
42 | + * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal |
|
43 | + */ |
|
44 | + public function create(string $prefix = ''): ICache; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Check if any memory cache backend is available |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - * @since 7.0.0 |
|
51 | - */ |
|
52 | - public function isAvailable(): bool; |
|
46 | + /** |
|
47 | + * Check if any memory cache backend is available |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + * @since 7.0.0 |
|
51 | + */ |
|
52 | + public function isAvailable(): bool; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Check if a local memory cache backend is available |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - * @since 14.0.0 |
|
59 | - */ |
|
60 | - public function isLocalCacheAvailable(): bool; |
|
54 | + /** |
|
55 | + * Check if a local memory cache backend is available |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + * @since 14.0.0 |
|
59 | + */ |
|
60 | + public function isLocalCacheAvailable(): bool; |
|
61 | 61 | |
62 | - /** |
|
63 | - * create a cache instance for storing locks |
|
64 | - * |
|
65 | - * @param string $prefix |
|
66 | - * @return IMemcache |
|
67 | - * @since 13.0.0 |
|
68 | - */ |
|
69 | - public function createLocking(string $prefix = ''): IMemcache; |
|
62 | + /** |
|
63 | + * create a cache instance for storing locks |
|
64 | + * |
|
65 | + * @param string $prefix |
|
66 | + * @return IMemcache |
|
67 | + * @since 13.0.0 |
|
68 | + */ |
|
69 | + public function createLocking(string $prefix = ''): IMemcache; |
|
70 | 70 | |
71 | - /** |
|
72 | - * create a distributed cache instance |
|
73 | - * |
|
74 | - * @param string $prefix |
|
75 | - * @return ICache |
|
76 | - * @since 13.0.0 |
|
77 | - */ |
|
78 | - public function createDistributed(string $prefix = ''): ICache; |
|
71 | + /** |
|
72 | + * create a distributed cache instance |
|
73 | + * |
|
74 | + * @param string $prefix |
|
75 | + * @return ICache |
|
76 | + * @since 13.0.0 |
|
77 | + */ |
|
78 | + public function createDistributed(string $prefix = ''): ICache; |
|
79 | 79 | |
80 | - /** |
|
81 | - * create a local cache instance |
|
82 | - * |
|
83 | - * @param string $prefix |
|
84 | - * @return ICache |
|
85 | - * @since 13.0.0 |
|
86 | - */ |
|
87 | - public function createLocal(string $prefix = ''): ICache; |
|
80 | + /** |
|
81 | + * create a local cache instance |
|
82 | + * |
|
83 | + * @param string $prefix |
|
84 | + * @return ICache |
|
85 | + * @since 13.0.0 |
|
86 | + */ |
|
87 | + public function createLocal(string $prefix = ''): ICache; |
|
88 | 88 | } |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | $entry['active'] = false; |
91 | - if(!isset($entry['icon'])) { |
|
91 | + if (!isset($entry['icon'])) { |
|
92 | 92 | $entry['icon'] = ''; |
93 | 93 | } |
94 | - if(!isset($entry['classes'])) { |
|
94 | + if (!isset($entry['classes'])) { |
|
95 | 95 | $entry['classes'] = ''; |
96 | 96 | } |
97 | - if(!isset($entry['type'])) { |
|
97 | + if (!isset($entry['type'])) { |
|
98 | 98 | $entry['type'] = 'link'; |
99 | 99 | } |
100 | 100 | $this->entries[] = $entry; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | ]); |
192 | 192 | |
193 | 193 | $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
194 | - if($logoutUrl !== '') { |
|
194 | + if ($logoutUrl !== '') { |
|
195 | 195 | // Logout |
196 | 196 | $this->add([ |
197 | 197 | 'type' => 'settings', |
@@ -44,290 +44,290 @@ |
||
44 | 44 | */ |
45 | 45 | |
46 | 46 | class NavigationManager implements INavigationManager { |
47 | - protected $entries = []; |
|
48 | - protected $closureEntries = []; |
|
49 | - protected $activeEntry; |
|
50 | - /** @var bool */ |
|
51 | - protected $init = false; |
|
52 | - /** @var IAppManager|AppManager */ |
|
53 | - protected $appManager; |
|
54 | - /** @var IURLGenerator */ |
|
55 | - private $urlGenerator; |
|
56 | - /** @var IFactory */ |
|
57 | - private $l10nFac; |
|
58 | - /** @var IUserSession */ |
|
59 | - private $userSession; |
|
60 | - /** @var IGroupManager|Manager */ |
|
61 | - private $groupManager; |
|
62 | - /** @var IConfig */ |
|
63 | - private $config; |
|
47 | + protected $entries = []; |
|
48 | + protected $closureEntries = []; |
|
49 | + protected $activeEntry; |
|
50 | + /** @var bool */ |
|
51 | + protected $init = false; |
|
52 | + /** @var IAppManager|AppManager */ |
|
53 | + protected $appManager; |
|
54 | + /** @var IURLGenerator */ |
|
55 | + private $urlGenerator; |
|
56 | + /** @var IFactory */ |
|
57 | + private $l10nFac; |
|
58 | + /** @var IUserSession */ |
|
59 | + private $userSession; |
|
60 | + /** @var IGroupManager|Manager */ |
|
61 | + private $groupManager; |
|
62 | + /** @var IConfig */ |
|
63 | + private $config; |
|
64 | 64 | |
65 | - public function __construct(IAppManager $appManager, |
|
66 | - IURLGenerator $urlGenerator, |
|
67 | - IFactory $l10nFac, |
|
68 | - IUserSession $userSession, |
|
69 | - IGroupManager $groupManager, |
|
70 | - IConfig $config) { |
|
71 | - $this->appManager = $appManager; |
|
72 | - $this->urlGenerator = $urlGenerator; |
|
73 | - $this->l10nFac = $l10nFac; |
|
74 | - $this->userSession = $userSession; |
|
75 | - $this->groupManager = $groupManager; |
|
76 | - $this->config = $config; |
|
77 | - } |
|
65 | + public function __construct(IAppManager $appManager, |
|
66 | + IURLGenerator $urlGenerator, |
|
67 | + IFactory $l10nFac, |
|
68 | + IUserSession $userSession, |
|
69 | + IGroupManager $groupManager, |
|
70 | + IConfig $config) { |
|
71 | + $this->appManager = $appManager; |
|
72 | + $this->urlGenerator = $urlGenerator; |
|
73 | + $this->l10nFac = $l10nFac; |
|
74 | + $this->userSession = $userSession; |
|
75 | + $this->groupManager = $groupManager; |
|
76 | + $this->config = $config; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Creates a new navigation entry |
|
81 | - * |
|
82 | - * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
83 | - * The use of a closure is preferred, because it will avoid |
|
84 | - * loading the routing of your app, unless required. |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function add($entry) { |
|
88 | - if ($entry instanceof \Closure) { |
|
89 | - $this->closureEntries[] = $entry; |
|
90 | - return; |
|
91 | - } |
|
79 | + /** |
|
80 | + * Creates a new navigation entry |
|
81 | + * |
|
82 | + * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
83 | + * The use of a closure is preferred, because it will avoid |
|
84 | + * loading the routing of your app, unless required. |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function add($entry) { |
|
88 | + if ($entry instanceof \Closure) { |
|
89 | + $this->closureEntries[] = $entry; |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | - $entry['active'] = false; |
|
94 | - if(!isset($entry['icon'])) { |
|
95 | - $entry['icon'] = ''; |
|
96 | - } |
|
97 | - if(!isset($entry['classes'])) { |
|
98 | - $entry['classes'] = ''; |
|
99 | - } |
|
100 | - if(!isset($entry['type'])) { |
|
101 | - $entry['type'] = 'link'; |
|
102 | - } |
|
103 | - $this->entries[] = $entry; |
|
104 | - } |
|
93 | + $entry['active'] = false; |
|
94 | + if(!isset($entry['icon'])) { |
|
95 | + $entry['icon'] = ''; |
|
96 | + } |
|
97 | + if(!isset($entry['classes'])) { |
|
98 | + $entry['classes'] = ''; |
|
99 | + } |
|
100 | + if(!isset($entry['type'])) { |
|
101 | + $entry['type'] = 'link'; |
|
102 | + } |
|
103 | + $this->entries[] = $entry; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Get a list of navigation entries |
|
108 | - * |
|
109 | - * @param string $type type of the navigation entries |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getAll(string $type = 'link'): array { |
|
113 | - $this->init(); |
|
114 | - foreach ($this->closureEntries as $c) { |
|
115 | - $this->add($c()); |
|
116 | - } |
|
117 | - $this->closureEntries = array(); |
|
106 | + /** |
|
107 | + * Get a list of navigation entries |
|
108 | + * |
|
109 | + * @param string $type type of the navigation entries |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getAll(string $type = 'link'): array { |
|
113 | + $this->init(); |
|
114 | + foreach ($this->closureEntries as $c) { |
|
115 | + $this->add($c()); |
|
116 | + } |
|
117 | + $this->closureEntries = array(); |
|
118 | 118 | |
119 | - $result = $this->entries; |
|
120 | - if ($type !== 'all') { |
|
121 | - $result = array_filter($this->entries, function($entry) use ($type) { |
|
122 | - return $entry['type'] === $type; |
|
123 | - }); |
|
124 | - } |
|
119 | + $result = $this->entries; |
|
120 | + if ($type !== 'all') { |
|
121 | + $result = array_filter($this->entries, function($entry) use ($type) { |
|
122 | + return $entry['type'] === $type; |
|
123 | + }); |
|
124 | + } |
|
125 | 125 | |
126 | - return $this->proceedNavigation($result); |
|
127 | - } |
|
126 | + return $this->proceedNavigation($result); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Sort navigation entries by order, name and set active flag |
|
131 | - * |
|
132 | - * @param array $list |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - private function proceedNavigation(array $list): array { |
|
136 | - usort($list, function($a, $b) { |
|
137 | - if (isset($a['order']) && isset($b['order'])) { |
|
138 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
139 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
140 | - return isset($a['order']) ? -1 : 1; |
|
141 | - } else { |
|
142 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
143 | - } |
|
144 | - }); |
|
129 | + /** |
|
130 | + * Sort navigation entries by order, name and set active flag |
|
131 | + * |
|
132 | + * @param array $list |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + private function proceedNavigation(array $list): array { |
|
136 | + usort($list, function($a, $b) { |
|
137 | + if (isset($a['order']) && isset($b['order'])) { |
|
138 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
139 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
140 | + return isset($a['order']) ? -1 : 1; |
|
141 | + } else { |
|
142 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
143 | + } |
|
144 | + }); |
|
145 | 145 | |
146 | - $activeApp = $this->getActiveEntry(); |
|
147 | - if ($activeApp !== null) { |
|
148 | - foreach ($list as $index => &$navEntry) { |
|
149 | - if ($navEntry['id'] == $activeApp) { |
|
150 | - $navEntry['active'] = true; |
|
151 | - } else { |
|
152 | - $navEntry['active'] = false; |
|
153 | - } |
|
154 | - } |
|
155 | - unset($navEntry); |
|
156 | - } |
|
146 | + $activeApp = $this->getActiveEntry(); |
|
147 | + if ($activeApp !== null) { |
|
148 | + foreach ($list as $index => &$navEntry) { |
|
149 | + if ($navEntry['id'] == $activeApp) { |
|
150 | + $navEntry['active'] = true; |
|
151 | + } else { |
|
152 | + $navEntry['active'] = false; |
|
153 | + } |
|
154 | + } |
|
155 | + unset($navEntry); |
|
156 | + } |
|
157 | 157 | |
158 | - return $list; |
|
159 | - } |
|
158 | + return $list; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * removes all the entries |
|
164 | - */ |
|
165 | - public function clear($loadDefaultLinks = true) { |
|
166 | - $this->entries = []; |
|
167 | - $this->closureEntries = []; |
|
168 | - $this->init = !$loadDefaultLinks; |
|
169 | - } |
|
162 | + /** |
|
163 | + * removes all the entries |
|
164 | + */ |
|
165 | + public function clear($loadDefaultLinks = true) { |
|
166 | + $this->entries = []; |
|
167 | + $this->closureEntries = []; |
|
168 | + $this->init = !$loadDefaultLinks; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Sets the current navigation entry of the currently running app |
|
173 | - * @param string $id of the app entry to activate (from added $entry) |
|
174 | - */ |
|
175 | - public function setActiveEntry($id) { |
|
176 | - $this->activeEntry = $id; |
|
177 | - } |
|
171 | + /** |
|
172 | + * Sets the current navigation entry of the currently running app |
|
173 | + * @param string $id of the app entry to activate (from added $entry) |
|
174 | + */ |
|
175 | + public function setActiveEntry($id) { |
|
176 | + $this->activeEntry = $id; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * gets the active Menu entry |
|
181 | - * @return string id or empty string |
|
182 | - * |
|
183 | - * This function returns the id of the active navigation entry (set by |
|
184 | - * setActiveEntry |
|
185 | - */ |
|
186 | - public function getActiveEntry() { |
|
187 | - return $this->activeEntry; |
|
188 | - } |
|
179 | + /** |
|
180 | + * gets the active Menu entry |
|
181 | + * @return string id or empty string |
|
182 | + * |
|
183 | + * This function returns the id of the active navigation entry (set by |
|
184 | + * setActiveEntry |
|
185 | + */ |
|
186 | + public function getActiveEntry() { |
|
187 | + return $this->activeEntry; |
|
188 | + } |
|
189 | 189 | |
190 | - private function init() { |
|
191 | - if ($this->init) { |
|
192 | - return; |
|
193 | - } |
|
194 | - $this->init = true; |
|
190 | + private function init() { |
|
191 | + if ($this->init) { |
|
192 | + return; |
|
193 | + } |
|
194 | + $this->init = true; |
|
195 | 195 | |
196 | - $l = $this->l10nFac->get('lib'); |
|
197 | - if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
198 | - $this->add([ |
|
199 | - 'type' => 'settings', |
|
200 | - 'id' => 'help', |
|
201 | - 'order' => 5, |
|
202 | - 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
203 | - 'name' => $l->t('Help'), |
|
204 | - 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
205 | - ]); |
|
206 | - } |
|
196 | + $l = $this->l10nFac->get('lib'); |
|
197 | + if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
198 | + $this->add([ |
|
199 | + 'type' => 'settings', |
|
200 | + 'id' => 'help', |
|
201 | + 'order' => 5, |
|
202 | + 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
203 | + 'name' => $l->t('Help'), |
|
204 | + 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
205 | + ]); |
|
206 | + } |
|
207 | 207 | |
208 | - if ($this->userSession->isLoggedIn()) { |
|
209 | - if ($this->isAdmin()) { |
|
210 | - // App management |
|
211 | - $this->add([ |
|
212 | - 'type' => 'settings', |
|
213 | - 'id' => 'core_apps', |
|
214 | - 'order' => 3, |
|
215 | - 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
216 | - 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
217 | - 'name' => $l->t('Apps'), |
|
218 | - ]); |
|
219 | - } |
|
208 | + if ($this->userSession->isLoggedIn()) { |
|
209 | + if ($this->isAdmin()) { |
|
210 | + // App management |
|
211 | + $this->add([ |
|
212 | + 'type' => 'settings', |
|
213 | + 'id' => 'core_apps', |
|
214 | + 'order' => 3, |
|
215 | + 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
216 | + 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
217 | + 'name' => $l->t('Apps'), |
|
218 | + ]); |
|
219 | + } |
|
220 | 220 | |
221 | - // Personal and (if applicable) admin settings |
|
222 | - $this->add([ |
|
223 | - 'type' => 'settings', |
|
224 | - 'id' => 'settings', |
|
225 | - 'order' => 1, |
|
226 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
227 | - 'name' => $l->t('Settings'), |
|
228 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
229 | - ]); |
|
221 | + // Personal and (if applicable) admin settings |
|
222 | + $this->add([ |
|
223 | + 'type' => 'settings', |
|
224 | + 'id' => 'settings', |
|
225 | + 'order' => 1, |
|
226 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
227 | + 'name' => $l->t('Settings'), |
|
228 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
229 | + ]); |
|
230 | 230 | |
231 | - $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
232 | - if($logoutUrl !== '') { |
|
233 | - // Logout |
|
234 | - $this->add([ |
|
235 | - 'type' => 'settings', |
|
236 | - 'id' => 'logout', |
|
237 | - 'order' => 99999, |
|
238 | - 'href' => $logoutUrl, |
|
239 | - 'name' => $l->t('Log out'), |
|
240 | - 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
241 | - ]); |
|
242 | - } |
|
231 | + $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
232 | + if($logoutUrl !== '') { |
|
233 | + // Logout |
|
234 | + $this->add([ |
|
235 | + 'type' => 'settings', |
|
236 | + 'id' => 'logout', |
|
237 | + 'order' => 99999, |
|
238 | + 'href' => $logoutUrl, |
|
239 | + 'name' => $l->t('Log out'), |
|
240 | + 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
241 | + ]); |
|
242 | + } |
|
243 | 243 | |
244 | - if ($this->isSubadmin()) { |
|
245 | - // User management |
|
246 | - $this->add([ |
|
247 | - 'type' => 'settings', |
|
248 | - 'id' => 'core_users', |
|
249 | - 'order' => 4, |
|
250 | - 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
251 | - 'name' => $l->t('Users'), |
|
252 | - 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
253 | - ]); |
|
254 | - } |
|
255 | - } |
|
244 | + if ($this->isSubadmin()) { |
|
245 | + // User management |
|
246 | + $this->add([ |
|
247 | + 'type' => 'settings', |
|
248 | + 'id' => 'core_users', |
|
249 | + 'order' => 4, |
|
250 | + 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
251 | + 'name' => $l->t('Users'), |
|
252 | + 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
253 | + ]); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - if ($this->appManager === 'null') { |
|
258 | - return; |
|
259 | - } |
|
257 | + if ($this->appManager === 'null') { |
|
258 | + return; |
|
259 | + } |
|
260 | 260 | |
261 | - if ($this->userSession->isLoggedIn()) { |
|
262 | - $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
263 | - } else { |
|
264 | - $apps = $this->appManager->getInstalledApps(); |
|
265 | - } |
|
261 | + if ($this->userSession->isLoggedIn()) { |
|
262 | + $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
263 | + } else { |
|
264 | + $apps = $this->appManager->getInstalledApps(); |
|
265 | + } |
|
266 | 266 | |
267 | - foreach ($apps as $app) { |
|
268 | - if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
269 | - continue; |
|
270 | - } |
|
267 | + foreach ($apps as $app) { |
|
268 | + if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
269 | + continue; |
|
270 | + } |
|
271 | 271 | |
272 | - // load plugins and collections from info.xml |
|
273 | - $info = $this->appManager->getAppInfo($app); |
|
274 | - if (empty($info['navigations'])) { |
|
275 | - continue; |
|
276 | - } |
|
277 | - foreach ($info['navigations'] as $nav) { |
|
278 | - if (!isset($nav['name'])) { |
|
279 | - continue; |
|
280 | - } |
|
281 | - if (!isset($nav['route'])) { |
|
282 | - continue; |
|
283 | - } |
|
284 | - $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
285 | - if ($role === 'admin' && !$this->isAdmin()) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - $l = $this->l10nFac->get($app); |
|
289 | - $id = isset($nav['id']) ? $nav['id'] : $app; |
|
290 | - $order = isset($nav['order']) ? $nav['order'] : 100; |
|
291 | - $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
292 | - $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
293 | - $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
294 | - foreach ([$icon, "$app.svg"] as $i) { |
|
295 | - try { |
|
296 | - $icon = $this->urlGenerator->imagePath($app, $i); |
|
297 | - break; |
|
298 | - } catch (\RuntimeException $ex) { |
|
299 | - // no icon? - ignore it then |
|
300 | - } |
|
301 | - } |
|
302 | - if ($icon === null) { |
|
303 | - $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
304 | - } |
|
272 | + // load plugins and collections from info.xml |
|
273 | + $info = $this->appManager->getAppInfo($app); |
|
274 | + if (empty($info['navigations'])) { |
|
275 | + continue; |
|
276 | + } |
|
277 | + foreach ($info['navigations'] as $nav) { |
|
278 | + if (!isset($nav['name'])) { |
|
279 | + continue; |
|
280 | + } |
|
281 | + if (!isset($nav['route'])) { |
|
282 | + continue; |
|
283 | + } |
|
284 | + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
285 | + if ($role === 'admin' && !$this->isAdmin()) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + $l = $this->l10nFac->get($app); |
|
289 | + $id = isset($nav['id']) ? $nav['id'] : $app; |
|
290 | + $order = isset($nav['order']) ? $nav['order'] : 100; |
|
291 | + $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
292 | + $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
293 | + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
294 | + foreach ([$icon, "$app.svg"] as $i) { |
|
295 | + try { |
|
296 | + $icon = $this->urlGenerator->imagePath($app, $i); |
|
297 | + break; |
|
298 | + } catch (\RuntimeException $ex) { |
|
299 | + // no icon? - ignore it then |
|
300 | + } |
|
301 | + } |
|
302 | + if ($icon === null) { |
|
303 | + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
304 | + } |
|
305 | 305 | |
306 | - $this->add([ |
|
307 | - 'id' => $id, |
|
308 | - 'order' => $order, |
|
309 | - 'href' => $route, |
|
310 | - 'icon' => $icon, |
|
311 | - 'type' => $type, |
|
312 | - 'name' => $l->t($nav['name']), |
|
313 | - ]); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
306 | + $this->add([ |
|
307 | + 'id' => $id, |
|
308 | + 'order' => $order, |
|
309 | + 'href' => $route, |
|
310 | + 'icon' => $icon, |
|
311 | + 'type' => $type, |
|
312 | + 'name' => $l->t($nav['name']), |
|
313 | + ]); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - private function isAdmin() { |
|
319 | - $user = $this->userSession->getUser(); |
|
320 | - if ($user !== null) { |
|
321 | - return $this->groupManager->isAdmin($user->getUID()); |
|
322 | - } |
|
323 | - return false; |
|
324 | - } |
|
318 | + private function isAdmin() { |
|
319 | + $user = $this->userSession->getUser(); |
|
320 | + if ($user !== null) { |
|
321 | + return $this->groupManager->isAdmin($user->getUID()); |
|
322 | + } |
|
323 | + return false; |
|
324 | + } |
|
325 | 325 | |
326 | - private function isSubadmin() { |
|
327 | - $user = $this->userSession->getUser(); |
|
328 | - if ($user !== null) { |
|
329 | - return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
330 | - } |
|
331 | - return false; |
|
332 | - } |
|
326 | + private function isSubadmin() { |
|
327 | + $user = $this->userSession->getUser(); |
|
328 | + if ($user !== null) { |
|
329 | + return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
330 | + } |
|
331 | + return false; |
|
332 | + } |
|
333 | 333 | } |
@@ -31,76 +31,76 @@ |
||
31 | 31 | |
32 | 32 | class SameSiteCookieMiddleware extends Middleware { |
33 | 33 | |
34 | - /** @var Request */ |
|
35 | - private $request; |
|
36 | - |
|
37 | - /** @var ControllerMethodReflector */ |
|
38 | - private $reflector; |
|
39 | - |
|
40 | - public function __construct(Request $request, |
|
41 | - ControllerMethodReflector $reflector) { |
|
42 | - $this->request = $request; |
|
43 | - $this->reflector = $reflector; |
|
44 | - } |
|
45 | - |
|
46 | - public function beforeController($controller, $methodName) { |
|
47 | - $requestUri = $this->request->getScriptName(); |
|
48 | - $processingScript = explode('/', $requestUri); |
|
49 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
50 | - |
|
51 | - if ($processingScript !== 'index.php') { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
56 | - if ($noSSC) { |
|
57 | - return; |
|
58 | - } |
|
59 | - |
|
60 | - if (!$this->request->passesLaxCookieCheck()) { |
|
61 | - throw new LaxSameSiteCookieFailedException(); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
66 | - if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
67 | - $respone = new Response(); |
|
68 | - $respone->setStatus(Http::STATUS_FOUND); |
|
69 | - $respone->addHeader('Location', $this->request->getRequestUri()); |
|
70 | - |
|
71 | - $this->setSameSiteCookie(); |
|
72 | - |
|
73 | - return $respone; |
|
74 | - } |
|
75 | - |
|
76 | - throw $exception; |
|
77 | - } |
|
78 | - |
|
79 | - protected function setSameSiteCookie() { |
|
80 | - $cookieParams = $this->request->getCookieParams(); |
|
81 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
82 | - $policies = [ |
|
83 | - 'lax', |
|
84 | - 'strict', |
|
85 | - ]; |
|
86 | - |
|
87 | - // Append __Host to the cookie if it meets the requirements |
|
88 | - $cookiePrefix = ''; |
|
89 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | - $cookiePrefix = '__Host-'; |
|
91 | - } |
|
92 | - |
|
93 | - foreach($policies as $policy) { |
|
94 | - header( |
|
95 | - sprintf( |
|
96 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | - $cookiePrefix, |
|
98 | - $policy, |
|
99 | - $cookieParams['path'], |
|
100 | - $policy |
|
101 | - ), |
|
102 | - false |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
34 | + /** @var Request */ |
|
35 | + private $request; |
|
36 | + |
|
37 | + /** @var ControllerMethodReflector */ |
|
38 | + private $reflector; |
|
39 | + |
|
40 | + public function __construct(Request $request, |
|
41 | + ControllerMethodReflector $reflector) { |
|
42 | + $this->request = $request; |
|
43 | + $this->reflector = $reflector; |
|
44 | + } |
|
45 | + |
|
46 | + public function beforeController($controller, $methodName) { |
|
47 | + $requestUri = $this->request->getScriptName(); |
|
48 | + $processingScript = explode('/', $requestUri); |
|
49 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
50 | + |
|
51 | + if ($processingScript !== 'index.php') { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
56 | + if ($noSSC) { |
|
57 | + return; |
|
58 | + } |
|
59 | + |
|
60 | + if (!$this->request->passesLaxCookieCheck()) { |
|
61 | + throw new LaxSameSiteCookieFailedException(); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
66 | + if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
67 | + $respone = new Response(); |
|
68 | + $respone->setStatus(Http::STATUS_FOUND); |
|
69 | + $respone->addHeader('Location', $this->request->getRequestUri()); |
|
70 | + |
|
71 | + $this->setSameSiteCookie(); |
|
72 | + |
|
73 | + return $respone; |
|
74 | + } |
|
75 | + |
|
76 | + throw $exception; |
|
77 | + } |
|
78 | + |
|
79 | + protected function setSameSiteCookie() { |
|
80 | + $cookieParams = $this->request->getCookieParams(); |
|
81 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
82 | + $policies = [ |
|
83 | + 'lax', |
|
84 | + 'strict', |
|
85 | + ]; |
|
86 | + |
|
87 | + // Append __Host to the cookie if it meets the requirements |
|
88 | + $cookiePrefix = ''; |
|
89 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | + $cookiePrefix = '__Host-'; |
|
91 | + } |
|
92 | + |
|
93 | + foreach($policies as $policy) { |
|
94 | + header( |
|
95 | + sprintf( |
|
96 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | + $cookiePrefix, |
|
98 | + $policy, |
|
99 | + $cookieParams['path'], |
|
100 | + $policy |
|
101 | + ), |
|
102 | + false |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function beforeController($controller, $methodName) { |
47 | 47 | $requestUri = $this->request->getScriptName(); |
48 | 48 | $processingScript = explode('/', $requestUri); |
49 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
49 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
50 | 50 | |
51 | 51 | if ($processingScript !== 'index.php') { |
52 | 52 | return; |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | |
87 | 87 | // Append __Host to the cookie if it meets the requirements |
88 | 88 | $cookiePrefix = ''; |
89 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
89 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | 90 | $cookiePrefix = '__Host-'; |
91 | 91 | } |
92 | 92 | |
93 | - foreach($policies as $policy) { |
|
93 | + foreach ($policies as $policy) { |
|
94 | 94 | header( |
95 | 95 | sprintf( |
96 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
96 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | 97 | $cookiePrefix, |
98 | 98 | $policy, |
99 | 99 | $cookieParams['path'], |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class LaxSameSiteCookieFailedException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Lax Same Site Cookie is invalid in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Lax Same Site Cookie is invalid in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | use OCP\IURLGenerator; |
30 | 30 | |
31 | 31 | class ContactsManager { |
32 | - /** @var CardDavBackend */ |
|
33 | - private $backend; |
|
32 | + /** @var CardDavBackend */ |
|
33 | + private $backend; |
|
34 | 34 | |
35 | - /** @var IL10N */ |
|
36 | - private $l10n; |
|
35 | + /** @var IL10N */ |
|
36 | + private $l10n; |
|
37 | 37 | |
38 | - /** |
|
39 | - * ContactsManager constructor. |
|
40 | - * |
|
41 | - * @param CardDavBackend $backend |
|
42 | - * @param IL10N $l10n |
|
43 | - */ |
|
44 | - public function __construct(CardDavBackend $backend, IL10N $l10n) { |
|
45 | - $this->backend = $backend; |
|
46 | - $this->l10n = $l10n; |
|
47 | - } |
|
38 | + /** |
|
39 | + * ContactsManager constructor. |
|
40 | + * |
|
41 | + * @param CardDavBackend $backend |
|
42 | + * @param IL10N $l10n |
|
43 | + */ |
|
44 | + public function __construct(CardDavBackend $backend, IL10N $l10n) { |
|
45 | + $this->backend = $backend; |
|
46 | + $this->l10n = $l10n; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IManager $cm |
|
51 | - * @param string $userId |
|
52 | - * @param IURLGenerator $urlGenerator |
|
53 | - */ |
|
54 | - public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { |
|
55 | - $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); |
|
56 | - $this->register($cm, $addressBooks, $urlGenerator); |
|
57 | - $this->setupSystemContactsProvider($cm, $urlGenerator); |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param IManager $cm |
|
51 | + * @param string $userId |
|
52 | + * @param IURLGenerator $urlGenerator |
|
53 | + */ |
|
54 | + public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { |
|
55 | + $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); |
|
56 | + $this->register($cm, $addressBooks, $urlGenerator); |
|
57 | + $this->setupSystemContactsProvider($cm, $urlGenerator); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param IManager $cm |
|
62 | - * @param IURLGenerator $urlGenerator |
|
63 | - */ |
|
64 | - public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { |
|
65 | - $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); |
|
66 | - $this->register($cm, $addressBooks, $urlGenerator); |
|
67 | - } |
|
60 | + /** |
|
61 | + * @param IManager $cm |
|
62 | + * @param IURLGenerator $urlGenerator |
|
63 | + */ |
|
64 | + public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { |
|
65 | + $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); |
|
66 | + $this->register($cm, $addressBooks, $urlGenerator); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param IManager $cm |
|
71 | - * @param $addressBooks |
|
72 | - * @param IURLGenerator $urlGenerator |
|
73 | - */ |
|
74 | - private function register(IManager $cm, $addressBooks, $urlGenerator) { |
|
75 | - foreach ($addressBooks as $addressBookInfo) { |
|
76 | - $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n); |
|
77 | - $cm->registerAddressBook( |
|
78 | - new AddressBookImpl( |
|
79 | - $addressBook, |
|
80 | - $addressBookInfo, |
|
81 | - $this->backend, |
|
82 | - $urlGenerator |
|
83 | - ) |
|
84 | - ); |
|
85 | - } |
|
86 | - } |
|
69 | + /** |
|
70 | + * @param IManager $cm |
|
71 | + * @param $addressBooks |
|
72 | + * @param IURLGenerator $urlGenerator |
|
73 | + */ |
|
74 | + private function register(IManager $cm, $addressBooks, $urlGenerator) { |
|
75 | + foreach ($addressBooks as $addressBookInfo) { |
|
76 | + $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n); |
|
77 | + $cm->registerAddressBook( |
|
78 | + new AddressBookImpl( |
|
79 | + $addressBook, |
|
80 | + $addressBookInfo, |
|
81 | + $this->backend, |
|
82 | + $urlGenerator |
|
83 | + ) |
|
84 | + ); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | */ |
12 | 12 | class Version1002Date20170926101419 extends BigIntMigration { |
13 | 13 | |
14 | - /** |
|
15 | - * @return array Returns an array with the following structure |
|
16 | - * ['table1' => ['column1', 'column2'], ...] |
|
17 | - * @since 13.0.0 |
|
18 | - */ |
|
19 | - protected function getColumnsByTable() { |
|
20 | - return [ |
|
21 | - 'twofactor_backupcodes' => ['id'], |
|
22 | - ]; |
|
23 | - } |
|
14 | + /** |
|
15 | + * @return array Returns an array with the following structure |
|
16 | + * ['table1' => ['column1', 'column2'], ...] |
|
17 | + * @since 13.0.0 |
|
18 | + */ |
|
19 | + protected function getColumnsByTable() { |
|
20 | + return [ |
|
21 | + 'twofactor_backupcodes' => ['id'], |
|
22 | + ]; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | } |