@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | // Admin? Or SubAdmin? |
124 | 124 | $uid = $user->getUID(); |
125 | 125 | $subAdminManager = $this->groupManager->getSubAdmin(); |
126 | - if($this->groupManager->isAdmin($uid)){ |
|
126 | + if ($this->groupManager->isAdmin($uid)) { |
|
127 | 127 | $users = $this->userManager->search($search, $limit, $offset); |
128 | 128 | } else if ($subAdminManager->isSubAdmin($user)) { |
129 | 129 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $subAdminOfGroups[$key] = $group->getGID(); |
132 | 132 | } |
133 | 133 | |
134 | - if($offset === null) { |
|
134 | + if ($offset === null) { |
|
135 | 135 | $offset = 0; |
136 | 136 | } |
137 | 137 | |
@@ -165,22 +165,22 @@ discard block |
||
165 | 165 | $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
166 | 166 | $subAdminManager = $this->groupManager->getSubAdmin(); |
167 | 167 | |
168 | - if($this->userManager->userExists($userid)) { |
|
168 | + if ($this->userManager->userExists($userid)) { |
|
169 | 169 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
170 | 170 | throw new OCSException('User already exists', 102); |
171 | 171 | } |
172 | 172 | |
173 | - if(is_array($groups)) { |
|
173 | + if (is_array($groups)) { |
|
174 | 174 | foreach ($groups as $group) { |
175 | - if(!$this->groupManager->groupExists($group)) { |
|
175 | + if (!$this->groupManager->groupExists($group)) { |
|
176 | 176 | throw new OCSException('group '.$group.' does not exist', 104); |
177 | 177 | } |
178 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
179 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
178 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
179 | + throw new OCSException('insufficient privileges for group '.$group, 105); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } else { |
183 | - if(!$isAdmin) { |
|
183 | + if (!$isAdmin) { |
|
184 | 184 | throw new OCSException('no group specified (required for subadmins)', 106); |
185 | 185 | } |
186 | 186 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | public function getCurrentUser() { |
230 | 230 | $user = $this->userSession->getUser(); |
231 | 231 | if ($user) { |
232 | - $data = $this->getUserData($user->getUID()); |
|
232 | + $data = $this->getUserData($user->getUID()); |
|
233 | 233 | // rename "displayname" to "display-name" only for this call to keep |
234 | 234 | // the API stable. |
235 | 235 | $data['display-name'] = $data['displayname']; |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | |
256 | 256 | // Check if the target user exists |
257 | 257 | $targetUserObject = $this->userManager->get($userId); |
258 | - if($targetUserObject === null) { |
|
258 | + if ($targetUserObject === null) { |
|
259 | 259 | throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
260 | 260 | } |
261 | 261 | |
262 | 262 | // Admin? Or SubAdmin? |
263 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
263 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
264 | 264 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
265 | 265 | $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
266 | 266 | } else { |
267 | 267 | // Check they are looking up themselves |
268 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
268 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
269 | 269 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
270 | 270 | } |
271 | 271 | } |
@@ -311,12 +311,12 @@ discard block |
||
311 | 311 | $currentLoggedInUser = $this->userSession->getUser(); |
312 | 312 | |
313 | 313 | $targetUser = $this->userManager->get($userId); |
314 | - if($targetUser === null) { |
|
314 | + if ($targetUser === null) { |
|
315 | 315 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
316 | 316 | } |
317 | 317 | |
318 | 318 | $permittedFields = []; |
319 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
319 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
320 | 320 | // Editing self (display, email) |
321 | 321 | if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
322 | 322 | $permittedFields[] = 'display'; |
@@ -343,13 +343,13 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | // If admin they can edit their own quota |
346 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
346 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
347 | 347 | $permittedFields[] = 'quota'; |
348 | 348 | } |
349 | 349 | } else { |
350 | 350 | // Check if admin / subadmin |
351 | 351 | $subAdminManager = $this->groupManager->getSubAdmin(); |
352 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
352 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
353 | 353 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
354 | 354 | // They have permissions over the user |
355 | 355 | $permittedFields[] = 'display'; |
@@ -369,18 +369,18 @@ discard block |
||
369 | 369 | } |
370 | 370 | } |
371 | 371 | // Check if permitted to edit this field |
372 | - if(!in_array($key, $permittedFields)) { |
|
372 | + if (!in_array($key, $permittedFields)) { |
|
373 | 373 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
374 | 374 | } |
375 | 375 | // Process the edit |
376 | - switch($key) { |
|
376 | + switch ($key) { |
|
377 | 377 | case 'display': |
378 | 378 | case AccountManager::PROPERTY_DISPLAYNAME: |
379 | 379 | $targetUser->setDisplayName($value); |
380 | 380 | break; |
381 | 381 | case 'quota': |
382 | 382 | $quota = $value; |
383 | - if($quota !== 'none' && $quota !== 'default') { |
|
383 | + if ($quota !== 'none' && $quota !== 'default') { |
|
384 | 384 | if (is_numeric($quota)) { |
385 | 385 | $quota = (float) $quota; |
386 | 386 | } else { |
@@ -389,9 +389,9 @@ discard block |
||
389 | 389 | if ($quota === false) { |
390 | 390 | throw new OCSException('Invalid quota value '.$value, 103); |
391 | 391 | } |
392 | - if($quota === 0) { |
|
392 | + if ($quota === 0) { |
|
393 | 393 | $quota = 'default'; |
394 | - }else if($quota === -1) { |
|
394 | + } else if ($quota === -1) { |
|
395 | 395 | $quota = 'none'; |
396 | 396 | } else { |
397 | 397 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
415 | 415 | break; |
416 | 416 | case AccountManager::PROPERTY_EMAIL: |
417 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
417 | + if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
418 | 418 | $targetUser->setEMailAddress($value); |
419 | 419 | } else { |
420 | 420 | throw new OCSException('', 102); |
@@ -450,18 +450,18 @@ discard block |
||
450 | 450 | |
451 | 451 | $targetUser = $this->userManager->get($userId); |
452 | 452 | |
453 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
453 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
454 | 454 | throw new OCSException('', 101); |
455 | 455 | } |
456 | 456 | |
457 | 457 | // If not permitted |
458 | 458 | $subAdminManager = $this->groupManager->getSubAdmin(); |
459 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
459 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
460 | 460 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
461 | 461 | } |
462 | 462 | |
463 | 463 | // Go ahead with the delete |
464 | - if($targetUser->delete()) { |
|
464 | + if ($targetUser->delete()) { |
|
465 | 465 | return new DataResponse(); |
466 | 466 | } else { |
467 | 467 | throw new OCSException('', 101); |
@@ -505,13 +505,13 @@ discard block |
||
505 | 505 | $currentLoggedInUser = $this->userSession->getUser(); |
506 | 506 | |
507 | 507 | $targetUser = $this->userManager->get($userId); |
508 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
508 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
509 | 509 | throw new OCSException('', 101); |
510 | 510 | } |
511 | 511 | |
512 | 512 | // If not permitted |
513 | 513 | $subAdminManager = $this->groupManager->getSubAdmin(); |
514 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
514 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
515 | 515 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
516 | 516 | } |
517 | 517 | |
@@ -532,11 +532,11 @@ discard block |
||
532 | 532 | $loggedInUser = $this->userSession->getUser(); |
533 | 533 | |
534 | 534 | $targetUser = $this->userManager->get($userId); |
535 | - if($targetUser === null) { |
|
535 | + if ($targetUser === null) { |
|
536 | 536 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
537 | 537 | } |
538 | 538 | |
539 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
539 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
540 | 540 | // Self lookup or admin lookup |
541 | 541 | return new DataResponse([ |
542 | 542 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | $subAdminManager = $this->groupManager->getSubAdmin(); |
546 | 546 | |
547 | 547 | // Looking up someone else |
548 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
548 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
549 | 549 | // Return the group that the method caller is subadmin of for the user in question |
550 | 550 | /** @var IGroup[] $getSubAdminsGroups */ |
551 | 551 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
@@ -575,16 +575,16 @@ discard block |
||
575 | 575 | * @throws OCSException |
576 | 576 | */ |
577 | 577 | public function addToGroup($userId, $groupid = '') { |
578 | - if($groupid === '') { |
|
578 | + if ($groupid === '') { |
|
579 | 579 | throw new OCSException('', 101); |
580 | 580 | } |
581 | 581 | |
582 | 582 | $group = $this->groupManager->get($groupid); |
583 | 583 | $targetUser = $this->userManager->get($userId); |
584 | - if($group === null) { |
|
584 | + if ($group === null) { |
|
585 | 585 | throw new OCSException('', 102); |
586 | 586 | } |
587 | - if($targetUser === null) { |
|
587 | + if ($targetUser === null) { |
|
588 | 588 | throw new OCSException('', 103); |
589 | 589 | } |
590 | 590 | |
@@ -612,17 +612,17 @@ discard block |
||
612 | 612 | public function removeFromGroup($userId, $groupid) { |
613 | 613 | $loggedInUser = $this->userSession->getUser(); |
614 | 614 | |
615 | - if($groupid === null) { |
|
615 | + if ($groupid === null) { |
|
616 | 616 | throw new OCSException('', 101); |
617 | 617 | } |
618 | 618 | |
619 | 619 | $group = $this->groupManager->get($groupid); |
620 | - if($group === null) { |
|
620 | + if ($group === null) { |
|
621 | 621 | throw new OCSException('', 102); |
622 | 622 | } |
623 | 623 | |
624 | 624 | $targetUser = $this->userManager->get($userId); |
625 | - if($targetUser === null) { |
|
625 | + if ($targetUser === null) { |
|
626 | 626 | throw new OCSException('', 103); |
627 | 627 | } |
628 | 628 | |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
647 | 647 | /** @var IGroup[] $subAdminGroups */ |
648 | 648 | $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
649 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
649 | + $subAdminGroups = array_map(function(IGroup $subAdminGroup) { |
|
650 | 650 | return $subAdminGroup->getGID(); |
651 | 651 | }, $subAdminGroups); |
652 | 652 | $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
@@ -678,15 +678,15 @@ discard block |
||
678 | 678 | $user = $this->userManager->get($userId); |
679 | 679 | |
680 | 680 | // Check if the user exists |
681 | - if($user === null) { |
|
681 | + if ($user === null) { |
|
682 | 682 | throw new OCSException('User does not exist', 101); |
683 | 683 | } |
684 | 684 | // Check if group exists |
685 | - if($group === null) { |
|
686 | - throw new OCSException('Group does not exist', 102); |
|
685 | + if ($group === null) { |
|
686 | + throw new OCSException('Group does not exist', 102); |
|
687 | 687 | } |
688 | 688 | // Check if trying to make subadmin of admin group |
689 | - if($group->getGID() === 'admin') { |
|
689 | + if ($group->getGID() === 'admin') { |
|
690 | 690 | throw new OCSException('Cannot create subadmins for admin group', 103); |
691 | 691 | } |
692 | 692 | |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | return new DataResponse(); |
698 | 698 | } |
699 | 699 | // Go |
700 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
700 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
701 | 701 | return new DataResponse(); |
702 | 702 | } else { |
703 | 703 | throw new OCSException('Unknown error occurred', 103); |
@@ -720,20 +720,20 @@ discard block |
||
720 | 720 | $subAdminManager = $this->groupManager->getSubAdmin(); |
721 | 721 | |
722 | 722 | // Check if the user exists |
723 | - if($user === null) { |
|
723 | + if ($user === null) { |
|
724 | 724 | throw new OCSException('User does not exist', 101); |
725 | 725 | } |
726 | 726 | // Check if the group exists |
727 | - if($group === null) { |
|
727 | + if ($group === null) { |
|
728 | 728 | throw new OCSException('Group does not exist', 101); |
729 | 729 | } |
730 | 730 | // Check if they are a subadmin of this said group |
731 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
731 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
732 | 732 | throw new OCSException('User is not a subadmin of this group', 102); |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Go |
736 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
736 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
737 | 737 | return new DataResponse(); |
738 | 738 | } else { |
739 | 739 | throw new OCSException('Unknown error occurred', 103); |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | public function getUserSubAdminGroups($userId) { |
751 | 751 | $user = $this->userManager->get($userId); |
752 | 752 | // Check if the user exists |
753 | - if($user === null) { |
|
753 | + if ($user === null) { |
|
754 | 754 | throw new OCSException('User does not exist', 101); |
755 | 755 | } |
756 | 756 | |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | $groups[$key] = $group->getGID(); |
761 | 761 | } |
762 | 762 | |
763 | - if(!$groups) { |
|
763 | + if (!$groups) { |
|
764 | 764 | throw new OCSException('Unknown error occurred', 102); |
765 | 765 | } else { |
766 | 766 | return new DataResponse($groups); |
@@ -804,13 +804,13 @@ discard block |
||
804 | 804 | $currentLoggedInUser = $this->userSession->getUser(); |
805 | 805 | |
806 | 806 | $targetUser = $this->userManager->get($userId); |
807 | - if($targetUser === null) { |
|
807 | + if ($targetUser === null) { |
|
808 | 808 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
809 | 809 | } |
810 | 810 | |
811 | 811 | // Check if admin / subadmin |
812 | 812 | $subAdminManager = $this->groupManager->getSubAdmin(); |
813 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
813 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
814 | 814 | && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
815 | 815 | // No rights |
816 | 816 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
@@ -832,8 +832,8 @@ discard block |
||
832 | 832 | $this->newUserMailHelper->setL10N($l10n); |
833 | 833 | $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
834 | 834 | $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
835 | - } catch(\Exception $e) { |
|
836 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
835 | + } catch (\Exception $e) { |
|
836 | + $this->logger->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
837 | 837 | throw new OCSException('Sending email failed', 102); |
838 | 838 | } |
839 | 839 |
@@ -50,799 +50,799 @@ |
||
50 | 50 | |
51 | 51 | class UsersController extends OCSController { |
52 | 52 | |
53 | - /** @var IUserManager */ |
|
54 | - private $userManager; |
|
55 | - /** @var IConfig */ |
|
56 | - private $config; |
|
57 | - /** @var IAppManager */ |
|
58 | - private $appManager; |
|
59 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
60 | - private $groupManager; |
|
61 | - /** @var IUserSession */ |
|
62 | - private $userSession; |
|
63 | - /** @var AccountManager */ |
|
64 | - private $accountManager; |
|
65 | - /** @var ILogger */ |
|
66 | - private $logger; |
|
67 | - /** @var IFactory */ |
|
68 | - private $l10nFactory; |
|
69 | - /** @var NewUserMailHelper */ |
|
70 | - private $newUserMailHelper; |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $appName |
|
74 | - * @param IRequest $request |
|
75 | - * @param IUserManager $userManager |
|
76 | - * @param IConfig $config |
|
77 | - * @param IAppManager $appManager |
|
78 | - * @param IGroupManager $groupManager |
|
79 | - * @param IUserSession $userSession |
|
80 | - * @param AccountManager $accountManager |
|
81 | - * @param ILogger $logger |
|
82 | - * @param IFactory $l10nFactory |
|
83 | - * @param NewUserMailHelper $newUserMailHelper |
|
84 | - */ |
|
85 | - public function __construct($appName, |
|
86 | - IRequest $request, |
|
87 | - IUserManager $userManager, |
|
88 | - IConfig $config, |
|
89 | - IAppManager $appManager, |
|
90 | - IGroupManager $groupManager, |
|
91 | - IUserSession $userSession, |
|
92 | - AccountManager $accountManager, |
|
93 | - ILogger $logger, |
|
94 | - IFactory $l10nFactory, |
|
95 | - NewUserMailHelper $newUserMailHelper) { |
|
96 | - parent::__construct($appName, $request); |
|
97 | - |
|
98 | - $this->userManager = $userManager; |
|
99 | - $this->config = $config; |
|
100 | - $this->appManager = $appManager; |
|
101 | - $this->groupManager = $groupManager; |
|
102 | - $this->userSession = $userSession; |
|
103 | - $this->accountManager = $accountManager; |
|
104 | - $this->logger = $logger; |
|
105 | - $this->l10nFactory = $l10nFactory; |
|
106 | - $this->newUserMailHelper = $newUserMailHelper; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @NoAdminRequired |
|
111 | - * |
|
112 | - * returns a list of users |
|
113 | - * |
|
114 | - * @param string $search |
|
115 | - * @param int $limit |
|
116 | - * @param int $offset |
|
117 | - * @return DataResponse |
|
118 | - */ |
|
119 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
120 | - $user = $this->userSession->getUser(); |
|
121 | - $users = []; |
|
122 | - |
|
123 | - // Admin? Or SubAdmin? |
|
124 | - $uid = $user->getUID(); |
|
125 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
126 | - if($this->groupManager->isAdmin($uid)){ |
|
127 | - $users = $this->userManager->search($search, $limit, $offset); |
|
128 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
129 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
130 | - foreach ($subAdminOfGroups as $key => $group) { |
|
131 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
132 | - } |
|
133 | - |
|
134 | - if($offset === null) { |
|
135 | - $offset = 0; |
|
136 | - } |
|
137 | - |
|
138 | - $users = []; |
|
139 | - foreach ($subAdminOfGroups as $group) { |
|
140 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
141 | - } |
|
142 | - |
|
143 | - $users = array_slice($users, $offset, $limit); |
|
144 | - } |
|
145 | - |
|
146 | - $users = array_keys($users); |
|
147 | - |
|
148 | - return new DataResponse([ |
|
149 | - 'users' => $users |
|
150 | - ]); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @PasswordConfirmationRequired |
|
155 | - * @NoAdminRequired |
|
156 | - * |
|
157 | - * @param string $userid |
|
158 | - * @param string $password |
|
159 | - * @param array $groups |
|
160 | - * @return DataResponse |
|
161 | - * @throws OCSException |
|
162 | - */ |
|
163 | - public function addUser($userid, $password, $groups = null) { |
|
164 | - $user = $this->userSession->getUser(); |
|
165 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
166 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
167 | - |
|
168 | - if($this->userManager->userExists($userid)) { |
|
169 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
170 | - throw new OCSException('User already exists', 102); |
|
171 | - } |
|
172 | - |
|
173 | - if(is_array($groups)) { |
|
174 | - foreach ($groups as $group) { |
|
175 | - if(!$this->groupManager->groupExists($group)) { |
|
176 | - throw new OCSException('group '.$group.' does not exist', 104); |
|
177 | - } |
|
178 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
179 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
180 | - } |
|
181 | - } |
|
182 | - } else { |
|
183 | - if(!$isAdmin) { |
|
184 | - throw new OCSException('no group specified (required for subadmins)', 106); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - try { |
|
189 | - $newUser = $this->userManager->createUser($userid, $password); |
|
190 | - $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
191 | - |
|
192 | - if (is_array($groups)) { |
|
193 | - foreach ($groups as $group) { |
|
194 | - $this->groupManager->get($group)->addUser($newUser); |
|
195 | - $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
196 | - } |
|
197 | - } |
|
198 | - return new DataResponse(); |
|
199 | - } catch (\Exception $e) { |
|
200 | - $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
201 | - throw new OCSException('Bad request', 101); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * @NoAdminRequired |
|
207 | - * @NoSubAdminRequired |
|
208 | - * |
|
209 | - * gets user info |
|
210 | - * |
|
211 | - * @param string $userId |
|
212 | - * @return DataResponse |
|
213 | - * @throws OCSException |
|
214 | - */ |
|
215 | - public function getUser($userId) { |
|
216 | - $data = $this->getUserData($userId); |
|
217 | - return new DataResponse($data); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @NoAdminRequired |
|
222 | - * @NoSubAdminRequired |
|
223 | - * |
|
224 | - * gets user info from the currently logged in user |
|
225 | - * |
|
226 | - * @return DataResponse |
|
227 | - * @throws OCSException |
|
228 | - */ |
|
229 | - public function getCurrentUser() { |
|
230 | - $user = $this->userSession->getUser(); |
|
231 | - if ($user) { |
|
232 | - $data = $this->getUserData($user->getUID()); |
|
233 | - // rename "displayname" to "display-name" only for this call to keep |
|
234 | - // the API stable. |
|
235 | - $data['display-name'] = $data['displayname']; |
|
236 | - unset($data['displayname']); |
|
237 | - return new DataResponse($data); |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * creates a array with all user data |
|
246 | - * |
|
247 | - * @param $userId |
|
248 | - * @return array |
|
249 | - * @throws OCSException |
|
250 | - */ |
|
251 | - protected function getUserData($userId) { |
|
252 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
253 | - |
|
254 | - $data = []; |
|
255 | - |
|
256 | - // Check if the target user exists |
|
257 | - $targetUserObject = $this->userManager->get($userId); |
|
258 | - if($targetUserObject === null) { |
|
259 | - throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
260 | - } |
|
261 | - |
|
262 | - // Admin? Or SubAdmin? |
|
263 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
264 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
265 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
266 | - } else { |
|
267 | - // Check they are looking up themselves |
|
268 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
269 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - $userAccount = $this->accountManager->getUser($targetUserObject); |
|
274 | - $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
275 | - $gids = []; |
|
276 | - foreach ($groups as $group) { |
|
277 | - $gids[] = $group->getDisplayName(); |
|
278 | - } |
|
279 | - |
|
280 | - // Find the data |
|
281 | - $data['id'] = $targetUserObject->getUID(); |
|
282 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
283 | - $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
284 | - $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
285 | - $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
286 | - $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
287 | - $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
288 | - $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
289 | - $data['groups'] = $gids; |
|
290 | - $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
291 | - $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
292 | - |
|
293 | - return $data; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * @NoAdminRequired |
|
298 | - * @NoSubAdminRequired |
|
299 | - * @PasswordConfirmationRequired |
|
300 | - * |
|
301 | - * edit users |
|
302 | - * |
|
303 | - * @param string $userId |
|
304 | - * @param string $key |
|
305 | - * @param string $value |
|
306 | - * @return DataResponse |
|
307 | - * @throws OCSException |
|
308 | - * @throws OCSForbiddenException |
|
309 | - */ |
|
310 | - public function editUser($userId, $key, $value) { |
|
311 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
312 | - |
|
313 | - $targetUser = $this->userManager->get($userId); |
|
314 | - if($targetUser === null) { |
|
315 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
316 | - } |
|
317 | - |
|
318 | - $permittedFields = []; |
|
319 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
320 | - // Editing self (display, email) |
|
321 | - if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
322 | - $permittedFields[] = 'display'; |
|
323 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
324 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
325 | - } |
|
326 | - |
|
327 | - $permittedFields[] = 'password'; |
|
328 | - if ($this->config->getSystemValue('force_language', false) === false || |
|
329 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
330 | - $permittedFields[] = 'language'; |
|
331 | - } |
|
332 | - |
|
333 | - if ($this->config->getSystemValue('force_locale', false) === false || |
|
334 | - $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
335 | - $permittedFields[] = 'locale'; |
|
336 | - } |
|
337 | - |
|
338 | - if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
339 | - $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
340 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
341 | - if ($shareProvider->isLookupServerUploadEnabled()) { |
|
342 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
343 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
344 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
345 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - // If admin they can edit their own quota |
|
350 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
351 | - $permittedFields[] = 'quota'; |
|
352 | - } |
|
353 | - } else { |
|
354 | - // Check if admin / subadmin |
|
355 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
356 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
357 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
358 | - // They have permissions over the user |
|
359 | - $permittedFields[] = 'display'; |
|
360 | - $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
361 | - $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
362 | - $permittedFields[] = 'password'; |
|
363 | - $permittedFields[] = 'language'; |
|
364 | - $permittedFields[] = 'locale'; |
|
365 | - $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
366 | - $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
367 | - $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
368 | - $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
369 | - $permittedFields[] = 'quota'; |
|
370 | - } else { |
|
371 | - // No rights |
|
372 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
373 | - } |
|
374 | - } |
|
375 | - // Check if permitted to edit this field |
|
376 | - if(!in_array($key, $permittedFields)) { |
|
377 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
378 | - } |
|
379 | - // Process the edit |
|
380 | - switch($key) { |
|
381 | - case 'display': |
|
382 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
383 | - $targetUser->setDisplayName($value); |
|
384 | - break; |
|
385 | - case 'quota': |
|
386 | - $quota = $value; |
|
387 | - if($quota !== 'none' && $quota !== 'default') { |
|
388 | - if (is_numeric($quota)) { |
|
389 | - $quota = (float) $quota; |
|
390 | - } else { |
|
391 | - $quota = \OCP\Util::computerFileSize($quota); |
|
392 | - } |
|
393 | - if ($quota === false) { |
|
394 | - throw new OCSException('Invalid quota value '.$value, 103); |
|
395 | - } |
|
396 | - if($quota === 0) { |
|
397 | - $quota = 'default'; |
|
398 | - }else if($quota === -1) { |
|
399 | - $quota = 'none'; |
|
400 | - } else { |
|
401 | - $quota = \OCP\Util::humanFileSize($quota); |
|
402 | - } |
|
403 | - } |
|
404 | - $targetUser->setQuota($quota); |
|
405 | - break; |
|
406 | - case 'password': |
|
407 | - $targetUser->setPassword($value); |
|
408 | - break; |
|
409 | - case 'language': |
|
410 | - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
411 | - if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
412 | - throw new OCSException('Invalid language', 102); |
|
413 | - } |
|
414 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
415 | - break; |
|
416 | - case 'locale': |
|
417 | - if (!$this->l10nFactory->localeExists($value)) { |
|
418 | - throw new OCSException('Invalid locale', 102); |
|
419 | - } |
|
420 | - $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
421 | - break; |
|
422 | - case AccountManager::PROPERTY_EMAIL: |
|
423 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
424 | - $targetUser->setEMailAddress($value); |
|
425 | - } else { |
|
426 | - throw new OCSException('', 102); |
|
427 | - } |
|
428 | - break; |
|
429 | - case AccountManager::PROPERTY_PHONE: |
|
430 | - case AccountManager::PROPERTY_ADDRESS: |
|
431 | - case AccountManager::PROPERTY_WEBSITE: |
|
432 | - case AccountManager::PROPERTY_TWITTER: |
|
433 | - $userAccount = $this->accountManager->getUser($targetUser); |
|
434 | - if ($userAccount[$key]['value'] !== $value) { |
|
435 | - $userAccount[$key]['value'] = $value; |
|
436 | - $this->accountManager->updateUser($targetUser, $userAccount); |
|
437 | - } |
|
438 | - break; |
|
439 | - default: |
|
440 | - throw new OCSException('', 103); |
|
441 | - } |
|
442 | - return new DataResponse(); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @PasswordConfirmationRequired |
|
447 | - * @NoAdminRequired |
|
448 | - * |
|
449 | - * @param string $userId |
|
450 | - * @return DataResponse |
|
451 | - * @throws OCSException |
|
452 | - * @throws OCSForbiddenException |
|
453 | - */ |
|
454 | - public function deleteUser($userId) { |
|
455 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
456 | - |
|
457 | - $targetUser = $this->userManager->get($userId); |
|
458 | - |
|
459 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
460 | - throw new OCSException('', 101); |
|
461 | - } |
|
462 | - |
|
463 | - // If not permitted |
|
464 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
465 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
466 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
467 | - } |
|
468 | - |
|
469 | - // Go ahead with the delete |
|
470 | - if($targetUser->delete()) { |
|
471 | - return new DataResponse(); |
|
472 | - } else { |
|
473 | - throw new OCSException('', 101); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * @PasswordConfirmationRequired |
|
479 | - * @NoAdminRequired |
|
480 | - * |
|
481 | - * @param string $userId |
|
482 | - * @return DataResponse |
|
483 | - * @throws OCSException |
|
484 | - * @throws OCSForbiddenException |
|
485 | - */ |
|
486 | - public function disableUser($userId) { |
|
487 | - return $this->setEnabled($userId, false); |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * @PasswordConfirmationRequired |
|
492 | - * @NoAdminRequired |
|
493 | - * |
|
494 | - * @param string $userId |
|
495 | - * @return DataResponse |
|
496 | - * @throws OCSException |
|
497 | - * @throws OCSForbiddenException |
|
498 | - */ |
|
499 | - public function enableUser($userId) { |
|
500 | - return $this->setEnabled($userId, true); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * @param string $userId |
|
505 | - * @param bool $value |
|
506 | - * @return DataResponse |
|
507 | - * @throws OCSException |
|
508 | - * @throws OCSForbiddenException |
|
509 | - */ |
|
510 | - private function setEnabled($userId, $value) { |
|
511 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
512 | - |
|
513 | - $targetUser = $this->userManager->get($userId); |
|
514 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
515 | - throw new OCSException('', 101); |
|
516 | - } |
|
517 | - |
|
518 | - // If not permitted |
|
519 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
520 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
521 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
522 | - } |
|
523 | - |
|
524 | - // enable/disable the user now |
|
525 | - $targetUser->setEnabled($value); |
|
526 | - return new DataResponse(); |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * @NoAdminRequired |
|
531 | - * @NoSubAdminRequired |
|
532 | - * |
|
533 | - * @param string $userId |
|
534 | - * @return DataResponse |
|
535 | - * @throws OCSException |
|
536 | - */ |
|
537 | - public function getUsersGroups($userId) { |
|
538 | - $loggedInUser = $this->userSession->getUser(); |
|
539 | - |
|
540 | - $targetUser = $this->userManager->get($userId); |
|
541 | - if($targetUser === null) { |
|
542 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
543 | - } |
|
544 | - |
|
545 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
546 | - // Self lookup or admin lookup |
|
547 | - return new DataResponse([ |
|
548 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
549 | - ]); |
|
550 | - } else { |
|
551 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
552 | - |
|
553 | - // Looking up someone else |
|
554 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
555 | - // Return the group that the method caller is subadmin of for the user in question |
|
556 | - /** @var IGroup[] $getSubAdminsGroups */ |
|
557 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
558 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
559 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
560 | - } |
|
561 | - $groups = array_intersect( |
|
562 | - $getSubAdminsGroups, |
|
563 | - $this->groupManager->getUserGroupIds($targetUser) |
|
564 | - ); |
|
565 | - return new DataResponse(['groups' => $groups]); |
|
566 | - } else { |
|
567 | - // Not permitted |
|
568 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * @PasswordConfirmationRequired |
|
576 | - * @NoAdminRequired |
|
577 | - * |
|
578 | - * @param string $userId |
|
579 | - * @param string $groupid |
|
580 | - * @return DataResponse |
|
581 | - * @throws OCSException |
|
582 | - */ |
|
583 | - public function addToGroup($userId, $groupid = '') { |
|
584 | - if($groupid === '') { |
|
585 | - throw new OCSException('', 101); |
|
586 | - } |
|
587 | - |
|
588 | - $group = $this->groupManager->get($groupid); |
|
589 | - $targetUser = $this->userManager->get($userId); |
|
590 | - if($group === null) { |
|
591 | - throw new OCSException('', 102); |
|
592 | - } |
|
593 | - if($targetUser === null) { |
|
594 | - throw new OCSException('', 103); |
|
595 | - } |
|
596 | - |
|
597 | - // If they're not an admin, check they are a subadmin of the group in question |
|
598 | - $loggedInUser = $this->userSession->getUser(); |
|
599 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
600 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
601 | - throw new OCSException('', 104); |
|
602 | - } |
|
603 | - |
|
604 | - // Add user to group |
|
605 | - $group->addUser($targetUser); |
|
606 | - return new DataResponse(); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * @PasswordConfirmationRequired |
|
611 | - * @NoAdminRequired |
|
612 | - * |
|
613 | - * @param string $userId |
|
614 | - * @param string $groupid |
|
615 | - * @return DataResponse |
|
616 | - * @throws OCSException |
|
617 | - */ |
|
618 | - public function removeFromGroup($userId, $groupid) { |
|
619 | - $loggedInUser = $this->userSession->getUser(); |
|
620 | - |
|
621 | - if($groupid === null) { |
|
622 | - throw new OCSException('', 101); |
|
623 | - } |
|
624 | - |
|
625 | - $group = $this->groupManager->get($groupid); |
|
626 | - if($group === null) { |
|
627 | - throw new OCSException('', 102); |
|
628 | - } |
|
629 | - |
|
630 | - $targetUser = $this->userManager->get($userId); |
|
631 | - if($targetUser === null) { |
|
632 | - throw new OCSException('', 103); |
|
633 | - } |
|
634 | - |
|
635 | - // If they're not an admin, check they are a subadmin of the group in question |
|
636 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
637 | - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
638 | - throw new OCSException('', 104); |
|
639 | - } |
|
640 | - |
|
641 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
642 | - if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
643 | - if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
644 | - if ($group->getGID() === 'admin') { |
|
645 | - throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
646 | - } |
|
647 | - } else { |
|
648 | - // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
649 | - throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
650 | - } |
|
651 | - |
|
652 | - } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
653 | - /** @var IGroup[] $subAdminGroups */ |
|
654 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
655 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
656 | - return $subAdminGroup->getGID(); |
|
657 | - }, $subAdminGroups); |
|
658 | - $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
659 | - $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
660 | - |
|
661 | - if (count($userSubAdminGroups) <= 1) { |
|
662 | - // Subadmin must not be able to remove a user from all their subadmin groups. |
|
663 | - throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - // Remove user from group |
|
668 | - $group->removeUser($targetUser); |
|
669 | - return new DataResponse(); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Creates a subadmin |
|
674 | - * |
|
675 | - * @PasswordConfirmationRequired |
|
676 | - * |
|
677 | - * @param string $userId |
|
678 | - * @param string $groupid |
|
679 | - * @return DataResponse |
|
680 | - * @throws OCSException |
|
681 | - */ |
|
682 | - public function addSubAdmin($userId, $groupid) { |
|
683 | - $group = $this->groupManager->get($groupid); |
|
684 | - $user = $this->userManager->get($userId); |
|
685 | - |
|
686 | - // Check if the user exists |
|
687 | - if($user === null) { |
|
688 | - throw new OCSException('User does not exist', 101); |
|
689 | - } |
|
690 | - // Check if group exists |
|
691 | - if($group === null) { |
|
692 | - throw new OCSException('Group does not exist', 102); |
|
693 | - } |
|
694 | - // Check if trying to make subadmin of admin group |
|
695 | - if($group->getGID() === 'admin') { |
|
696 | - throw new OCSException('Cannot create subadmins for admin group', 103); |
|
697 | - } |
|
698 | - |
|
699 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
700 | - |
|
701 | - // We cannot be subadmin twice |
|
702 | - if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
703 | - return new DataResponse(); |
|
704 | - } |
|
705 | - // Go |
|
706 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
707 | - return new DataResponse(); |
|
708 | - } else { |
|
709 | - throw new OCSException('Unknown error occurred', 103); |
|
710 | - } |
|
711 | - } |
|
712 | - |
|
713 | - /** |
|
714 | - * Removes a subadmin from a group |
|
715 | - * |
|
716 | - * @PasswordConfirmationRequired |
|
717 | - * |
|
718 | - * @param string $userId |
|
719 | - * @param string $groupid |
|
720 | - * @return DataResponse |
|
721 | - * @throws OCSException |
|
722 | - */ |
|
723 | - public function removeSubAdmin($userId, $groupid) { |
|
724 | - $group = $this->groupManager->get($groupid); |
|
725 | - $user = $this->userManager->get($userId); |
|
726 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
727 | - |
|
728 | - // Check if the user exists |
|
729 | - if($user === null) { |
|
730 | - throw new OCSException('User does not exist', 101); |
|
731 | - } |
|
732 | - // Check if the group exists |
|
733 | - if($group === null) { |
|
734 | - throw new OCSException('Group does not exist', 101); |
|
735 | - } |
|
736 | - // Check if they are a subadmin of this said group |
|
737 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
738 | - throw new OCSException('User is not a subadmin of this group', 102); |
|
739 | - } |
|
740 | - |
|
741 | - // Go |
|
742 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
743 | - return new DataResponse(); |
|
744 | - } else { |
|
745 | - throw new OCSException('Unknown error occurred', 103); |
|
746 | - } |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Get the groups a user is a subadmin of |
|
751 | - * |
|
752 | - * @param string $userId |
|
753 | - * @return DataResponse |
|
754 | - * @throws OCSException |
|
755 | - */ |
|
756 | - public function getUserSubAdminGroups($userId) { |
|
757 | - $user = $this->userManager->get($userId); |
|
758 | - // Check if the user exists |
|
759 | - if($user === null) { |
|
760 | - throw new OCSException('User does not exist', 101); |
|
761 | - } |
|
762 | - |
|
763 | - // Get the subadmin groups |
|
764 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
765 | - foreach ($groups as $key => $group) { |
|
766 | - $groups[$key] = $group->getGID(); |
|
767 | - } |
|
768 | - |
|
769 | - if(!$groups) { |
|
770 | - throw new OCSException('Unknown error occurred', 102); |
|
771 | - } else { |
|
772 | - return new DataResponse($groups); |
|
773 | - } |
|
774 | - } |
|
775 | - |
|
776 | - /** |
|
777 | - * @param string $userId |
|
778 | - * @return array |
|
779 | - * @throws \OCP\Files\NotFoundException |
|
780 | - */ |
|
781 | - protected function fillStorageInfo($userId) { |
|
782 | - try { |
|
783 | - \OC_Util::tearDownFS(); |
|
784 | - \OC_Util::setupFS($userId); |
|
785 | - $storage = OC_Helper::getStorageInfo('/'); |
|
786 | - $data = [ |
|
787 | - 'free' => $storage['free'], |
|
788 | - 'used' => $storage['used'], |
|
789 | - 'total' => $storage['total'], |
|
790 | - 'relative' => $storage['relative'], |
|
791 | - 'quota' => $storage['quota'], |
|
792 | - ]; |
|
793 | - } catch (NotFoundException $ex) { |
|
794 | - $data = []; |
|
795 | - } |
|
796 | - return $data; |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * @NoAdminRequired |
|
801 | - * @PasswordConfirmationRequired |
|
802 | - * |
|
803 | - * resend welcome message |
|
804 | - * |
|
805 | - * @param string $userId |
|
806 | - * @return DataResponse |
|
807 | - * @throws OCSException |
|
808 | - */ |
|
809 | - public function resendWelcomeMessage($userId) { |
|
810 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
811 | - |
|
812 | - $targetUser = $this->userManager->get($userId); |
|
813 | - if($targetUser === null) { |
|
814 | - throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
815 | - } |
|
816 | - |
|
817 | - // Check if admin / subadmin |
|
818 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
819 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
820 | - && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
821 | - // No rights |
|
822 | - throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
823 | - } |
|
824 | - |
|
825 | - $email = $targetUser->getEMailAddress(); |
|
826 | - if ($email === '' || $email === null) { |
|
827 | - throw new OCSException('Email address not available', 101); |
|
828 | - } |
|
829 | - $username = $targetUser->getUID(); |
|
830 | - $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
831 | - if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
832 | - $lang = 'en'; |
|
833 | - } |
|
834 | - |
|
835 | - $l10n = $this->l10nFactory->get('settings', $lang); |
|
836 | - |
|
837 | - try { |
|
838 | - $this->newUserMailHelper->setL10N($l10n); |
|
839 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
840 | - $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
841 | - } catch(\Exception $e) { |
|
842 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
843 | - throw new OCSException('Sending email failed', 102); |
|
844 | - } |
|
845 | - |
|
846 | - return new DataResponse(); |
|
847 | - } |
|
53 | + /** @var IUserManager */ |
|
54 | + private $userManager; |
|
55 | + /** @var IConfig */ |
|
56 | + private $config; |
|
57 | + /** @var IAppManager */ |
|
58 | + private $appManager; |
|
59 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
60 | + private $groupManager; |
|
61 | + /** @var IUserSession */ |
|
62 | + private $userSession; |
|
63 | + /** @var AccountManager */ |
|
64 | + private $accountManager; |
|
65 | + /** @var ILogger */ |
|
66 | + private $logger; |
|
67 | + /** @var IFactory */ |
|
68 | + private $l10nFactory; |
|
69 | + /** @var NewUserMailHelper */ |
|
70 | + private $newUserMailHelper; |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $appName |
|
74 | + * @param IRequest $request |
|
75 | + * @param IUserManager $userManager |
|
76 | + * @param IConfig $config |
|
77 | + * @param IAppManager $appManager |
|
78 | + * @param IGroupManager $groupManager |
|
79 | + * @param IUserSession $userSession |
|
80 | + * @param AccountManager $accountManager |
|
81 | + * @param ILogger $logger |
|
82 | + * @param IFactory $l10nFactory |
|
83 | + * @param NewUserMailHelper $newUserMailHelper |
|
84 | + */ |
|
85 | + public function __construct($appName, |
|
86 | + IRequest $request, |
|
87 | + IUserManager $userManager, |
|
88 | + IConfig $config, |
|
89 | + IAppManager $appManager, |
|
90 | + IGroupManager $groupManager, |
|
91 | + IUserSession $userSession, |
|
92 | + AccountManager $accountManager, |
|
93 | + ILogger $logger, |
|
94 | + IFactory $l10nFactory, |
|
95 | + NewUserMailHelper $newUserMailHelper) { |
|
96 | + parent::__construct($appName, $request); |
|
97 | + |
|
98 | + $this->userManager = $userManager; |
|
99 | + $this->config = $config; |
|
100 | + $this->appManager = $appManager; |
|
101 | + $this->groupManager = $groupManager; |
|
102 | + $this->userSession = $userSession; |
|
103 | + $this->accountManager = $accountManager; |
|
104 | + $this->logger = $logger; |
|
105 | + $this->l10nFactory = $l10nFactory; |
|
106 | + $this->newUserMailHelper = $newUserMailHelper; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @NoAdminRequired |
|
111 | + * |
|
112 | + * returns a list of users |
|
113 | + * |
|
114 | + * @param string $search |
|
115 | + * @param int $limit |
|
116 | + * @param int $offset |
|
117 | + * @return DataResponse |
|
118 | + */ |
|
119 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
120 | + $user = $this->userSession->getUser(); |
|
121 | + $users = []; |
|
122 | + |
|
123 | + // Admin? Or SubAdmin? |
|
124 | + $uid = $user->getUID(); |
|
125 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
126 | + if($this->groupManager->isAdmin($uid)){ |
|
127 | + $users = $this->userManager->search($search, $limit, $offset); |
|
128 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
129 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
130 | + foreach ($subAdminOfGroups as $key => $group) { |
|
131 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
132 | + } |
|
133 | + |
|
134 | + if($offset === null) { |
|
135 | + $offset = 0; |
|
136 | + } |
|
137 | + |
|
138 | + $users = []; |
|
139 | + foreach ($subAdminOfGroups as $group) { |
|
140 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
141 | + } |
|
142 | + |
|
143 | + $users = array_slice($users, $offset, $limit); |
|
144 | + } |
|
145 | + |
|
146 | + $users = array_keys($users); |
|
147 | + |
|
148 | + return new DataResponse([ |
|
149 | + 'users' => $users |
|
150 | + ]); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @PasswordConfirmationRequired |
|
155 | + * @NoAdminRequired |
|
156 | + * |
|
157 | + * @param string $userid |
|
158 | + * @param string $password |
|
159 | + * @param array $groups |
|
160 | + * @return DataResponse |
|
161 | + * @throws OCSException |
|
162 | + */ |
|
163 | + public function addUser($userid, $password, $groups = null) { |
|
164 | + $user = $this->userSession->getUser(); |
|
165 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
166 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
167 | + |
|
168 | + if($this->userManager->userExists($userid)) { |
|
169 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
170 | + throw new OCSException('User already exists', 102); |
|
171 | + } |
|
172 | + |
|
173 | + if(is_array($groups)) { |
|
174 | + foreach ($groups as $group) { |
|
175 | + if(!$this->groupManager->groupExists($group)) { |
|
176 | + throw new OCSException('group '.$group.' does not exist', 104); |
|
177 | + } |
|
178 | + if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
179 | + throw new OCSException('insufficient privileges for group '. $group, 105); |
|
180 | + } |
|
181 | + } |
|
182 | + } else { |
|
183 | + if(!$isAdmin) { |
|
184 | + throw new OCSException('no group specified (required for subadmins)', 106); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + try { |
|
189 | + $newUser = $this->userManager->createUser($userid, $password); |
|
190 | + $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); |
|
191 | + |
|
192 | + if (is_array($groups)) { |
|
193 | + foreach ($groups as $group) { |
|
194 | + $this->groupManager->get($group)->addUser($newUser); |
|
195 | + $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); |
|
196 | + } |
|
197 | + } |
|
198 | + return new DataResponse(); |
|
199 | + } catch (\Exception $e) { |
|
200 | + $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
201 | + throw new OCSException('Bad request', 101); |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * @NoAdminRequired |
|
207 | + * @NoSubAdminRequired |
|
208 | + * |
|
209 | + * gets user info |
|
210 | + * |
|
211 | + * @param string $userId |
|
212 | + * @return DataResponse |
|
213 | + * @throws OCSException |
|
214 | + */ |
|
215 | + public function getUser($userId) { |
|
216 | + $data = $this->getUserData($userId); |
|
217 | + return new DataResponse($data); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @NoAdminRequired |
|
222 | + * @NoSubAdminRequired |
|
223 | + * |
|
224 | + * gets user info from the currently logged in user |
|
225 | + * |
|
226 | + * @return DataResponse |
|
227 | + * @throws OCSException |
|
228 | + */ |
|
229 | + public function getCurrentUser() { |
|
230 | + $user = $this->userSession->getUser(); |
|
231 | + if ($user) { |
|
232 | + $data = $this->getUserData($user->getUID()); |
|
233 | + // rename "displayname" to "display-name" only for this call to keep |
|
234 | + // the API stable. |
|
235 | + $data['display-name'] = $data['displayname']; |
|
236 | + unset($data['displayname']); |
|
237 | + return new DataResponse($data); |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * creates a array with all user data |
|
246 | + * |
|
247 | + * @param $userId |
|
248 | + * @return array |
|
249 | + * @throws OCSException |
|
250 | + */ |
|
251 | + protected function getUserData($userId) { |
|
252 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
253 | + |
|
254 | + $data = []; |
|
255 | + |
|
256 | + // Check if the target user exists |
|
257 | + $targetUserObject = $this->userManager->get($userId); |
|
258 | + if($targetUserObject === null) { |
|
259 | + throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
260 | + } |
|
261 | + |
|
262 | + // Admin? Or SubAdmin? |
|
263 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
264 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
265 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
266 | + } else { |
|
267 | + // Check they are looking up themselves |
|
268 | + if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
269 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + $userAccount = $this->accountManager->getUser($targetUserObject); |
|
274 | + $groups = $this->groupManager->getUserGroups($targetUserObject); |
|
275 | + $gids = []; |
|
276 | + foreach ($groups as $group) { |
|
277 | + $gids[] = $group->getDisplayName(); |
|
278 | + } |
|
279 | + |
|
280 | + // Find the data |
|
281 | + $data['id'] = $targetUserObject->getUID(); |
|
282 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
283 | + $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); |
|
284 | + $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); |
|
285 | + $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value']; |
|
286 | + $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value']; |
|
287 | + $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value']; |
|
288 | + $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value']; |
|
289 | + $data['groups'] = $gids; |
|
290 | + $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); |
|
291 | + $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); |
|
292 | + |
|
293 | + return $data; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * @NoAdminRequired |
|
298 | + * @NoSubAdminRequired |
|
299 | + * @PasswordConfirmationRequired |
|
300 | + * |
|
301 | + * edit users |
|
302 | + * |
|
303 | + * @param string $userId |
|
304 | + * @param string $key |
|
305 | + * @param string $value |
|
306 | + * @return DataResponse |
|
307 | + * @throws OCSException |
|
308 | + * @throws OCSForbiddenException |
|
309 | + */ |
|
310 | + public function editUser($userId, $key, $value) { |
|
311 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
312 | + |
|
313 | + $targetUser = $this->userManager->get($userId); |
|
314 | + if($targetUser === null) { |
|
315 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
316 | + } |
|
317 | + |
|
318 | + $permittedFields = []; |
|
319 | + if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
320 | + // Editing self (display, email) |
|
321 | + if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
|
322 | + $permittedFields[] = 'display'; |
|
323 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
324 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
325 | + } |
|
326 | + |
|
327 | + $permittedFields[] = 'password'; |
|
328 | + if ($this->config->getSystemValue('force_language', false) === false || |
|
329 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
330 | + $permittedFields[] = 'language'; |
|
331 | + } |
|
332 | + |
|
333 | + if ($this->config->getSystemValue('force_locale', false) === false || |
|
334 | + $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
335 | + $permittedFields[] = 'locale'; |
|
336 | + } |
|
337 | + |
|
338 | + if ($this->appManager->isEnabledForUser('federatedfilesharing')) { |
|
339 | + $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
340 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
341 | + if ($shareProvider->isLookupServerUploadEnabled()) { |
|
342 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
343 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
344 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
345 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + // If admin they can edit their own quota |
|
350 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
351 | + $permittedFields[] = 'quota'; |
|
352 | + } |
|
353 | + } else { |
|
354 | + // Check if admin / subadmin |
|
355 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
356 | + if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
357 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
358 | + // They have permissions over the user |
|
359 | + $permittedFields[] = 'display'; |
|
360 | + $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
|
361 | + $permittedFields[] = AccountManager::PROPERTY_EMAIL; |
|
362 | + $permittedFields[] = 'password'; |
|
363 | + $permittedFields[] = 'language'; |
|
364 | + $permittedFields[] = 'locale'; |
|
365 | + $permittedFields[] = AccountManager::PROPERTY_PHONE; |
|
366 | + $permittedFields[] = AccountManager::PROPERTY_ADDRESS; |
|
367 | + $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
|
368 | + $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
|
369 | + $permittedFields[] = 'quota'; |
|
370 | + } else { |
|
371 | + // No rights |
|
372 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
373 | + } |
|
374 | + } |
|
375 | + // Check if permitted to edit this field |
|
376 | + if(!in_array($key, $permittedFields)) { |
|
377 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
378 | + } |
|
379 | + // Process the edit |
|
380 | + switch($key) { |
|
381 | + case 'display': |
|
382 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
383 | + $targetUser->setDisplayName($value); |
|
384 | + break; |
|
385 | + case 'quota': |
|
386 | + $quota = $value; |
|
387 | + if($quota !== 'none' && $quota !== 'default') { |
|
388 | + if (is_numeric($quota)) { |
|
389 | + $quota = (float) $quota; |
|
390 | + } else { |
|
391 | + $quota = \OCP\Util::computerFileSize($quota); |
|
392 | + } |
|
393 | + if ($quota === false) { |
|
394 | + throw new OCSException('Invalid quota value '.$value, 103); |
|
395 | + } |
|
396 | + if($quota === 0) { |
|
397 | + $quota = 'default'; |
|
398 | + }else if($quota === -1) { |
|
399 | + $quota = 'none'; |
|
400 | + } else { |
|
401 | + $quota = \OCP\Util::humanFileSize($quota); |
|
402 | + } |
|
403 | + } |
|
404 | + $targetUser->setQuota($quota); |
|
405 | + break; |
|
406 | + case 'password': |
|
407 | + $targetUser->setPassword($value); |
|
408 | + break; |
|
409 | + case 'language': |
|
410 | + $languagesCodes = $this->l10nFactory->findAvailableLanguages(); |
|
411 | + if (!in_array($value, $languagesCodes, true) && $value !== 'en') { |
|
412 | + throw new OCSException('Invalid language', 102); |
|
413 | + } |
|
414 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
|
415 | + break; |
|
416 | + case 'locale': |
|
417 | + if (!$this->l10nFactory->localeExists($value)) { |
|
418 | + throw new OCSException('Invalid locale', 102); |
|
419 | + } |
|
420 | + $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value); |
|
421 | + break; |
|
422 | + case AccountManager::PROPERTY_EMAIL: |
|
423 | + if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
424 | + $targetUser->setEMailAddress($value); |
|
425 | + } else { |
|
426 | + throw new OCSException('', 102); |
|
427 | + } |
|
428 | + break; |
|
429 | + case AccountManager::PROPERTY_PHONE: |
|
430 | + case AccountManager::PROPERTY_ADDRESS: |
|
431 | + case AccountManager::PROPERTY_WEBSITE: |
|
432 | + case AccountManager::PROPERTY_TWITTER: |
|
433 | + $userAccount = $this->accountManager->getUser($targetUser); |
|
434 | + if ($userAccount[$key]['value'] !== $value) { |
|
435 | + $userAccount[$key]['value'] = $value; |
|
436 | + $this->accountManager->updateUser($targetUser, $userAccount); |
|
437 | + } |
|
438 | + break; |
|
439 | + default: |
|
440 | + throw new OCSException('', 103); |
|
441 | + } |
|
442 | + return new DataResponse(); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @PasswordConfirmationRequired |
|
447 | + * @NoAdminRequired |
|
448 | + * |
|
449 | + * @param string $userId |
|
450 | + * @return DataResponse |
|
451 | + * @throws OCSException |
|
452 | + * @throws OCSForbiddenException |
|
453 | + */ |
|
454 | + public function deleteUser($userId) { |
|
455 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
456 | + |
|
457 | + $targetUser = $this->userManager->get($userId); |
|
458 | + |
|
459 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
460 | + throw new OCSException('', 101); |
|
461 | + } |
|
462 | + |
|
463 | + // If not permitted |
|
464 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
465 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
466 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
467 | + } |
|
468 | + |
|
469 | + // Go ahead with the delete |
|
470 | + if($targetUser->delete()) { |
|
471 | + return new DataResponse(); |
|
472 | + } else { |
|
473 | + throw new OCSException('', 101); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * @PasswordConfirmationRequired |
|
479 | + * @NoAdminRequired |
|
480 | + * |
|
481 | + * @param string $userId |
|
482 | + * @return DataResponse |
|
483 | + * @throws OCSException |
|
484 | + * @throws OCSForbiddenException |
|
485 | + */ |
|
486 | + public function disableUser($userId) { |
|
487 | + return $this->setEnabled($userId, false); |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * @PasswordConfirmationRequired |
|
492 | + * @NoAdminRequired |
|
493 | + * |
|
494 | + * @param string $userId |
|
495 | + * @return DataResponse |
|
496 | + * @throws OCSException |
|
497 | + * @throws OCSForbiddenException |
|
498 | + */ |
|
499 | + public function enableUser($userId) { |
|
500 | + return $this->setEnabled($userId, true); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * @param string $userId |
|
505 | + * @param bool $value |
|
506 | + * @return DataResponse |
|
507 | + * @throws OCSException |
|
508 | + * @throws OCSForbiddenException |
|
509 | + */ |
|
510 | + private function setEnabled($userId, $value) { |
|
511 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
512 | + |
|
513 | + $targetUser = $this->userManager->get($userId); |
|
514 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
515 | + throw new OCSException('', 101); |
|
516 | + } |
|
517 | + |
|
518 | + // If not permitted |
|
519 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
520 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
521 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
522 | + } |
|
523 | + |
|
524 | + // enable/disable the user now |
|
525 | + $targetUser->setEnabled($value); |
|
526 | + return new DataResponse(); |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * @NoAdminRequired |
|
531 | + * @NoSubAdminRequired |
|
532 | + * |
|
533 | + * @param string $userId |
|
534 | + * @return DataResponse |
|
535 | + * @throws OCSException |
|
536 | + */ |
|
537 | + public function getUsersGroups($userId) { |
|
538 | + $loggedInUser = $this->userSession->getUser(); |
|
539 | + |
|
540 | + $targetUser = $this->userManager->get($userId); |
|
541 | + if($targetUser === null) { |
|
542 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
543 | + } |
|
544 | + |
|
545 | + if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
546 | + // Self lookup or admin lookup |
|
547 | + return new DataResponse([ |
|
548 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
549 | + ]); |
|
550 | + } else { |
|
551 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
552 | + |
|
553 | + // Looking up someone else |
|
554 | + if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
555 | + // Return the group that the method caller is subadmin of for the user in question |
|
556 | + /** @var IGroup[] $getSubAdminsGroups */ |
|
557 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
558 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
559 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
560 | + } |
|
561 | + $groups = array_intersect( |
|
562 | + $getSubAdminsGroups, |
|
563 | + $this->groupManager->getUserGroupIds($targetUser) |
|
564 | + ); |
|
565 | + return new DataResponse(['groups' => $groups]); |
|
566 | + } else { |
|
567 | + // Not permitted |
|
568 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * @PasswordConfirmationRequired |
|
576 | + * @NoAdminRequired |
|
577 | + * |
|
578 | + * @param string $userId |
|
579 | + * @param string $groupid |
|
580 | + * @return DataResponse |
|
581 | + * @throws OCSException |
|
582 | + */ |
|
583 | + public function addToGroup($userId, $groupid = '') { |
|
584 | + if($groupid === '') { |
|
585 | + throw new OCSException('', 101); |
|
586 | + } |
|
587 | + |
|
588 | + $group = $this->groupManager->get($groupid); |
|
589 | + $targetUser = $this->userManager->get($userId); |
|
590 | + if($group === null) { |
|
591 | + throw new OCSException('', 102); |
|
592 | + } |
|
593 | + if($targetUser === null) { |
|
594 | + throw new OCSException('', 103); |
|
595 | + } |
|
596 | + |
|
597 | + // If they're not an admin, check they are a subadmin of the group in question |
|
598 | + $loggedInUser = $this->userSession->getUser(); |
|
599 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
600 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
601 | + throw new OCSException('', 104); |
|
602 | + } |
|
603 | + |
|
604 | + // Add user to group |
|
605 | + $group->addUser($targetUser); |
|
606 | + return new DataResponse(); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * @PasswordConfirmationRequired |
|
611 | + * @NoAdminRequired |
|
612 | + * |
|
613 | + * @param string $userId |
|
614 | + * @param string $groupid |
|
615 | + * @return DataResponse |
|
616 | + * @throws OCSException |
|
617 | + */ |
|
618 | + public function removeFromGroup($userId, $groupid) { |
|
619 | + $loggedInUser = $this->userSession->getUser(); |
|
620 | + |
|
621 | + if($groupid === null) { |
|
622 | + throw new OCSException('', 101); |
|
623 | + } |
|
624 | + |
|
625 | + $group = $this->groupManager->get($groupid); |
|
626 | + if($group === null) { |
|
627 | + throw new OCSException('', 102); |
|
628 | + } |
|
629 | + |
|
630 | + $targetUser = $this->userManager->get($userId); |
|
631 | + if($targetUser === null) { |
|
632 | + throw new OCSException('', 103); |
|
633 | + } |
|
634 | + |
|
635 | + // If they're not an admin, check they are a subadmin of the group in question |
|
636 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
637 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { |
|
638 | + throw new OCSException('', 104); |
|
639 | + } |
|
640 | + |
|
641 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
642 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
643 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
644 | + if ($group->getGID() === 'admin') { |
|
645 | + throw new OCSException('Cannot remove yourself from the admin group', 105); |
|
646 | + } |
|
647 | + } else { |
|
648 | + // Not an admin, so the user must be a subadmin of this group, but that is not allowed. |
|
649 | + throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); |
|
650 | + } |
|
651 | + |
|
652 | + } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
653 | + /** @var IGroup[] $subAdminGroups */ |
|
654 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
655 | + $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
656 | + return $subAdminGroup->getGID(); |
|
657 | + }, $subAdminGroups); |
|
658 | + $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
|
659 | + $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups); |
|
660 | + |
|
661 | + if (count($userSubAdminGroups) <= 1) { |
|
662 | + // Subadmin must not be able to remove a user from all their subadmin groups. |
|
663 | + throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105); |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + // Remove user from group |
|
668 | + $group->removeUser($targetUser); |
|
669 | + return new DataResponse(); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Creates a subadmin |
|
674 | + * |
|
675 | + * @PasswordConfirmationRequired |
|
676 | + * |
|
677 | + * @param string $userId |
|
678 | + * @param string $groupid |
|
679 | + * @return DataResponse |
|
680 | + * @throws OCSException |
|
681 | + */ |
|
682 | + public function addSubAdmin($userId, $groupid) { |
|
683 | + $group = $this->groupManager->get($groupid); |
|
684 | + $user = $this->userManager->get($userId); |
|
685 | + |
|
686 | + // Check if the user exists |
|
687 | + if($user === null) { |
|
688 | + throw new OCSException('User does not exist', 101); |
|
689 | + } |
|
690 | + // Check if group exists |
|
691 | + if($group === null) { |
|
692 | + throw new OCSException('Group does not exist', 102); |
|
693 | + } |
|
694 | + // Check if trying to make subadmin of admin group |
|
695 | + if($group->getGID() === 'admin') { |
|
696 | + throw new OCSException('Cannot create subadmins for admin group', 103); |
|
697 | + } |
|
698 | + |
|
699 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
700 | + |
|
701 | + // We cannot be subadmin twice |
|
702 | + if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
703 | + return new DataResponse(); |
|
704 | + } |
|
705 | + // Go |
|
706 | + if($subAdminManager->createSubAdmin($user, $group)) { |
|
707 | + return new DataResponse(); |
|
708 | + } else { |
|
709 | + throw new OCSException('Unknown error occurred', 103); |
|
710 | + } |
|
711 | + } |
|
712 | + |
|
713 | + /** |
|
714 | + * Removes a subadmin from a group |
|
715 | + * |
|
716 | + * @PasswordConfirmationRequired |
|
717 | + * |
|
718 | + * @param string $userId |
|
719 | + * @param string $groupid |
|
720 | + * @return DataResponse |
|
721 | + * @throws OCSException |
|
722 | + */ |
|
723 | + public function removeSubAdmin($userId, $groupid) { |
|
724 | + $group = $this->groupManager->get($groupid); |
|
725 | + $user = $this->userManager->get($userId); |
|
726 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
727 | + |
|
728 | + // Check if the user exists |
|
729 | + if($user === null) { |
|
730 | + throw new OCSException('User does not exist', 101); |
|
731 | + } |
|
732 | + // Check if the group exists |
|
733 | + if($group === null) { |
|
734 | + throw new OCSException('Group does not exist', 101); |
|
735 | + } |
|
736 | + // Check if they are a subadmin of this said group |
|
737 | + if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
738 | + throw new OCSException('User is not a subadmin of this group', 102); |
|
739 | + } |
|
740 | + |
|
741 | + // Go |
|
742 | + if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
743 | + return new DataResponse(); |
|
744 | + } else { |
|
745 | + throw new OCSException('Unknown error occurred', 103); |
|
746 | + } |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Get the groups a user is a subadmin of |
|
751 | + * |
|
752 | + * @param string $userId |
|
753 | + * @return DataResponse |
|
754 | + * @throws OCSException |
|
755 | + */ |
|
756 | + public function getUserSubAdminGroups($userId) { |
|
757 | + $user = $this->userManager->get($userId); |
|
758 | + // Check if the user exists |
|
759 | + if($user === null) { |
|
760 | + throw new OCSException('User does not exist', 101); |
|
761 | + } |
|
762 | + |
|
763 | + // Get the subadmin groups |
|
764 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
765 | + foreach ($groups as $key => $group) { |
|
766 | + $groups[$key] = $group->getGID(); |
|
767 | + } |
|
768 | + |
|
769 | + if(!$groups) { |
|
770 | + throw new OCSException('Unknown error occurred', 102); |
|
771 | + } else { |
|
772 | + return new DataResponse($groups); |
|
773 | + } |
|
774 | + } |
|
775 | + |
|
776 | + /** |
|
777 | + * @param string $userId |
|
778 | + * @return array |
|
779 | + * @throws \OCP\Files\NotFoundException |
|
780 | + */ |
|
781 | + protected function fillStorageInfo($userId) { |
|
782 | + try { |
|
783 | + \OC_Util::tearDownFS(); |
|
784 | + \OC_Util::setupFS($userId); |
|
785 | + $storage = OC_Helper::getStorageInfo('/'); |
|
786 | + $data = [ |
|
787 | + 'free' => $storage['free'], |
|
788 | + 'used' => $storage['used'], |
|
789 | + 'total' => $storage['total'], |
|
790 | + 'relative' => $storage['relative'], |
|
791 | + 'quota' => $storage['quota'], |
|
792 | + ]; |
|
793 | + } catch (NotFoundException $ex) { |
|
794 | + $data = []; |
|
795 | + } |
|
796 | + return $data; |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * @NoAdminRequired |
|
801 | + * @PasswordConfirmationRequired |
|
802 | + * |
|
803 | + * resend welcome message |
|
804 | + * |
|
805 | + * @param string $userId |
|
806 | + * @return DataResponse |
|
807 | + * @throws OCSException |
|
808 | + */ |
|
809 | + public function resendWelcomeMessage($userId) { |
|
810 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
811 | + |
|
812 | + $targetUser = $this->userManager->get($userId); |
|
813 | + if($targetUser === null) { |
|
814 | + throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
|
815 | + } |
|
816 | + |
|
817 | + // Check if admin / subadmin |
|
818 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
819 | + if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
820 | + && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
821 | + // No rights |
|
822 | + throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
|
823 | + } |
|
824 | + |
|
825 | + $email = $targetUser->getEMailAddress(); |
|
826 | + if ($email === '' || $email === null) { |
|
827 | + throw new OCSException('Email address not available', 101); |
|
828 | + } |
|
829 | + $username = $targetUser->getUID(); |
|
830 | + $lang = $this->config->getUserValue($username, 'core', 'lang', 'en'); |
|
831 | + if (!$this->l10nFactory->languageExists('settings', $lang)) { |
|
832 | + $lang = 'en'; |
|
833 | + } |
|
834 | + |
|
835 | + $l10n = $this->l10nFactory->get('settings', $lang); |
|
836 | + |
|
837 | + try { |
|
838 | + $this->newUserMailHelper->setL10N($l10n); |
|
839 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
|
840 | + $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
|
841 | + } catch(\Exception $e) { |
|
842 | + $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
843 | + throw new OCSException('Sending email failed', 102); |
|
844 | + } |
|
845 | + |
|
846 | + return new DataResponse(); |
|
847 | + } |
|
848 | 848 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public function getForm() { |
95 | 95 | $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
96 | 96 | $lookupServerUploadEnabled = false; |
97 | - if($federatedFileSharingEnabled) { |
|
97 | + if ($federatedFileSharingEnabled) { |
|
98 | 98 | $federatedFileSharing = new Application(); |
99 | 99 | $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
100 | 100 | $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | private function getLanguages(IUser $user) { |
196 | 196 | $forceLanguage = $this->config->getSystemValue('force_language', false); |
197 | - if($forceLanguage !== false) { |
|
197 | + if ($forceLanguage !== false) { |
|
198 | 198 | return []; |
199 | 199 | } |
200 | 200 | |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | $commonLanguages = []; |
207 | 207 | $languages = []; |
208 | 208 | |
209 | - foreach($languageCodes as $lang) { |
|
209 | + foreach ($languageCodes as $lang) { |
|
210 | 210 | $l = \OC::$server->getL10N('settings', $lang); |
211 | 211 | // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
212 | 212 | $potentialName = (string) $l->t('__language_name__'); |
213 | - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
213 | + if ($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
214 | 214 | $ln = array('code' => $lang, 'name' => $potentialName); |
215 | 215 | } elseif ($lang === 'en') { |
216 | 216 | $ln = ['code' => $lang, 'name' => 'English (US)']; |
217 | - }else{//fallback to language code |
|
218 | - $ln=array('code'=>$lang, 'name'=>$lang); |
|
217 | + } else {//fallback to language code |
|
218 | + $ln = array('code'=>$lang, 'name'=>$lang); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // put appropriate languages into appropriate arrays, to print them sorted |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | if ($lang === $userLang) { |
224 | 224 | $userLang = $ln; |
225 | 225 | } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
226 | - $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
226 | + $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)] = $ln; |
|
227 | 227 | } else { |
228 | - $languages[]=$ln; |
|
228 | + $languages[] = $ln; |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | ksort($commonLanguages); |
241 | 241 | |
242 | 242 | // sort now by displayed language not the iso-code |
243 | - usort( $languages, function ($a, $b) { |
|
243 | + usort($languages, function($a, $b) { |
|
244 | 244 | if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
245 | 245 | // If a doesn't have a name, but b does, list b before a |
246 | 246 | return 1; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | private function getLocales(IUser $user) { |
264 | 264 | $forceLanguage = $this->config->getSystemValue('force_locale', false); |
265 | - if($forceLanguage !== false) { |
|
265 | + if ($forceLanguage !== false) { |
|
266 | 266 | return []; |
267 | 267 | } |
268 | 268 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | default: |
314 | 314 | $message = $this->l->t('Verify'); |
315 | 315 | } |
316 | - $messageParameters[$property . 'Message'] = $message; |
|
316 | + $messageParameters[$property.'Message'] = $message; |
|
317 | 317 | } |
318 | 318 | return $messageParameters; |
319 | 319 | } |
@@ -40,282 +40,282 @@ |
||
40 | 40 | use OCP\Settings\ISettings; |
41 | 41 | |
42 | 42 | class PersonalInfo implements ISettings { |
43 | - /** @var IConfig */ |
|
44 | - private $config; |
|
45 | - /** @var IUserManager */ |
|
46 | - private $userManager; |
|
47 | - /** @var AccountManager */ |
|
48 | - private $accountManager; |
|
49 | - /** @var IGroupManager */ |
|
50 | - private $groupManager; |
|
51 | - /** @var IAppManager */ |
|
52 | - private $appManager; |
|
53 | - /** @var IFactory */ |
|
54 | - private $l10nFactory; |
|
55 | - |
|
56 | - const COMMON_LANGUAGE_CODES = [ |
|
57 | - 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
58 | - 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
59 | - ]; |
|
60 | - |
|
61 | - /** @var IL10N */ |
|
62 | - private $l; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IConfig $config |
|
66 | - * @param IUserManager $userManager |
|
67 | - * @param IGroupManager $groupManager |
|
68 | - * @param AccountManager $accountManager |
|
69 | - * @param IFactory $l10nFactory |
|
70 | - * @param IL10N $l |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - IConfig $config, |
|
74 | - IUserManager $userManager, |
|
75 | - IGroupManager $groupManager, |
|
76 | - AccountManager $accountManager, |
|
77 | - IAppManager $appManager, |
|
78 | - IFactory $l10nFactory, |
|
79 | - IL10N $l |
|
80 | - ) { |
|
81 | - $this->config = $config; |
|
82 | - $this->userManager = $userManager; |
|
83 | - $this->accountManager = $accountManager; |
|
84 | - $this->groupManager = $groupManager; |
|
85 | - $this->appManager = $appManager; |
|
86 | - $this->l10nFactory = $l10nFactory; |
|
87 | - $this->l = $l; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
92 | - * @since 9.1 |
|
93 | - */ |
|
94 | - public function getForm() { |
|
95 | - $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
96 | - $lookupServerUploadEnabled = false; |
|
97 | - if($federatedFileSharingEnabled) { |
|
98 | - $federatedFileSharing = new Application(); |
|
99 | - $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
100 | - $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
101 | - } |
|
102 | - |
|
103 | - $uid = \OC_User::getUser(); |
|
104 | - $user = $this->userManager->get($uid); |
|
105 | - $userData = $this->accountManager->getUser($user); |
|
106 | - |
|
107 | - $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
108 | - if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
109 | - $totalSpace = $this->l->t('Unlimited'); |
|
110 | - } else { |
|
111 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
112 | - } |
|
113 | - |
|
114 | - $languageParameters = $this->getLanguages($user); |
|
115 | - $localeParameters = $this->getLocales($user); |
|
116 | - $messageParameters = $this->getMessageParameters($userData); |
|
117 | - |
|
118 | - $parameters = [ |
|
119 | - 'total_space' => $totalSpace, |
|
120 | - 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
121 | - 'usage_relative' => $storageInfo['relative'], |
|
122 | - 'quota' => $storageInfo['quota'], |
|
123 | - 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
124 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
125 | - 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
126 | - 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
127 | - 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
128 | - 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
129 | - 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
130 | - 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
131 | - 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
132 | - 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
133 | - 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
134 | - 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
135 | - 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
136 | - 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
137 | - 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
138 | - 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
139 | - 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
140 | - 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
141 | - 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
142 | - 'groups' => $this->getGroups($user), |
|
143 | - 'passwordChangeSupported' => $user->canChangePassword(), |
|
144 | - ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | - |
|
146 | - |
|
147 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string the section ID, e.g. 'sharing' |
|
152 | - * @since 9.1 |
|
153 | - */ |
|
154 | - public function getSection() { |
|
155 | - return 'personal-info'; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return int whether the form should be rather on the top or bottom of |
|
160 | - * the admin section. The forms are arranged in ascending order of the |
|
161 | - * priority values. It is required to return a value between 0 and 100. |
|
162 | - * |
|
163 | - * E.g.: 70 |
|
164 | - * @since 9.1 |
|
165 | - */ |
|
166 | - public function getPriority() { |
|
167 | - return 10; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * returns a sorted list of the user's group GIDs |
|
172 | - * |
|
173 | - * @param IUser $user |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - private function getGroups(IUser $user) { |
|
177 | - $groups = array_map( |
|
178 | - function(IGroup $group) { |
|
179 | - return $group->getGID(); |
|
180 | - }, |
|
181 | - $this->groupManager->getUserGroups($user) |
|
182 | - ); |
|
183 | - sort($groups); |
|
184 | - |
|
185 | - return $groups; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * returns the user language, common language and other languages in an |
|
190 | - * associative array |
|
191 | - * |
|
192 | - * @param IUser $user |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - private function getLanguages(IUser $user) { |
|
196 | - $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | - if($forceLanguage !== false) { |
|
198 | - return []; |
|
199 | - } |
|
200 | - |
|
201 | - $uid = $user->getUID(); |
|
202 | - |
|
203 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | - $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
205 | - |
|
206 | - $commonLanguages = []; |
|
207 | - $languages = []; |
|
208 | - |
|
209 | - foreach($languageCodes as $lang) { |
|
210 | - $l = \OC::$server->getL10N('settings', $lang); |
|
211 | - // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
212 | - $potentialName = (string) $l->t('__language_name__'); |
|
213 | - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
214 | - $ln = array('code' => $lang, 'name' => $potentialName); |
|
215 | - } elseif ($lang === 'en') { |
|
216 | - $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
217 | - }else{//fallback to language code |
|
218 | - $ln=array('code'=>$lang, 'name'=>$lang); |
|
219 | - } |
|
220 | - |
|
221 | - // put appropriate languages into appropriate arrays, to print them sorted |
|
222 | - // used language -> common languages -> divider -> other languages |
|
223 | - if ($lang === $userLang) { |
|
224 | - $userLang = $ln; |
|
225 | - } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
226 | - $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
227 | - } else { |
|
228 | - $languages[]=$ln; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - // if user language is not available but set somehow: show the actual code as name |
|
233 | - if (!is_array($userLang)) { |
|
234 | - $userLang = [ |
|
235 | - 'code' => $userLang, |
|
236 | - 'name' => $userLang, |
|
237 | - ]; |
|
238 | - } |
|
239 | - |
|
240 | - ksort($commonLanguages); |
|
241 | - |
|
242 | - // sort now by displayed language not the iso-code |
|
243 | - usort( $languages, function ($a, $b) { |
|
244 | - if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
245 | - // If a doesn't have a name, but b does, list b before a |
|
246 | - return 1; |
|
247 | - } |
|
248 | - if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
249 | - // If a does have a name, but b doesn't, list a before b |
|
250 | - return -1; |
|
251 | - } |
|
252 | - // Otherwise compare the names |
|
253 | - return strcmp($a['name'], $b['name']); |
|
254 | - }); |
|
255 | - |
|
256 | - return [ |
|
257 | - 'activelanguage' => $userLang, |
|
258 | - 'commonlanguages' => $commonLanguages, |
|
259 | - 'languages' => $languages |
|
260 | - ]; |
|
261 | - } |
|
262 | - |
|
263 | - private function getLocales(IUser $user) { |
|
264 | - $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
265 | - if($forceLanguage !== false) { |
|
266 | - return []; |
|
267 | - } |
|
268 | - |
|
269 | - $uid = $user->getUID(); |
|
270 | - |
|
271 | - $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', 'en_US'); |
|
272 | - |
|
273 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
274 | - |
|
275 | - $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
276 | - |
|
277 | - $userLocale = array_filter($localeCodes, function($value) use ($userLocaleString) { |
|
278 | - return $userLocaleString === $value['code']; |
|
279 | - }); |
|
280 | - |
|
281 | - if (!empty($userLocale)) |
|
282 | - { |
|
283 | - $userLocale = reset($userLocale); |
|
284 | - } |
|
285 | - |
|
286 | - $localesForLanguage = array_filter($localeCodes, function($localeCode) use ($userLang) { |
|
287 | - return 0 === strpos($localeCode['code'], $userLang); |
|
288 | - }); |
|
289 | - |
|
290 | - return [ |
|
291 | - 'activelocaleLang' => $userLocaleString, |
|
292 | - 'activelocale' => $userLocale, |
|
293 | - 'locales' => $localeCodes, |
|
294 | - 'localesforlanguage' => $localesForLanguage, |
|
295 | - ]; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @param array $userData |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - private function getMessageParameters(array $userData) { |
|
303 | - $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
304 | - $messageParameters = []; |
|
305 | - foreach ($needVerifyMessage as $property) { |
|
306 | - switch ($userData[$property]['verified']) { |
|
307 | - case AccountManager::VERIFIED: |
|
308 | - $message = $this->l->t('Verifying'); |
|
309 | - break; |
|
310 | - case AccountManager::VERIFICATION_IN_PROGRESS: |
|
311 | - $message = $this->l->t('Verifying …'); |
|
312 | - break; |
|
313 | - default: |
|
314 | - $message = $this->l->t('Verify'); |
|
315 | - } |
|
316 | - $messageParameters[$property . 'Message'] = $message; |
|
317 | - } |
|
318 | - return $messageParameters; |
|
319 | - } |
|
43 | + /** @var IConfig */ |
|
44 | + private $config; |
|
45 | + /** @var IUserManager */ |
|
46 | + private $userManager; |
|
47 | + /** @var AccountManager */ |
|
48 | + private $accountManager; |
|
49 | + /** @var IGroupManager */ |
|
50 | + private $groupManager; |
|
51 | + /** @var IAppManager */ |
|
52 | + private $appManager; |
|
53 | + /** @var IFactory */ |
|
54 | + private $l10nFactory; |
|
55 | + |
|
56 | + const COMMON_LANGUAGE_CODES = [ |
|
57 | + 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
58 | + 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
59 | + ]; |
|
60 | + |
|
61 | + /** @var IL10N */ |
|
62 | + private $l; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IConfig $config |
|
66 | + * @param IUserManager $userManager |
|
67 | + * @param IGroupManager $groupManager |
|
68 | + * @param AccountManager $accountManager |
|
69 | + * @param IFactory $l10nFactory |
|
70 | + * @param IL10N $l |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + IConfig $config, |
|
74 | + IUserManager $userManager, |
|
75 | + IGroupManager $groupManager, |
|
76 | + AccountManager $accountManager, |
|
77 | + IAppManager $appManager, |
|
78 | + IFactory $l10nFactory, |
|
79 | + IL10N $l |
|
80 | + ) { |
|
81 | + $this->config = $config; |
|
82 | + $this->userManager = $userManager; |
|
83 | + $this->accountManager = $accountManager; |
|
84 | + $this->groupManager = $groupManager; |
|
85 | + $this->appManager = $appManager; |
|
86 | + $this->l10nFactory = $l10nFactory; |
|
87 | + $this->l = $l; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
92 | + * @since 9.1 |
|
93 | + */ |
|
94 | + public function getForm() { |
|
95 | + $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
96 | + $lookupServerUploadEnabled = false; |
|
97 | + if($federatedFileSharingEnabled) { |
|
98 | + $federatedFileSharing = new Application(); |
|
99 | + $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
|
100 | + $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
101 | + } |
|
102 | + |
|
103 | + $uid = \OC_User::getUser(); |
|
104 | + $user = $this->userManager->get($uid); |
|
105 | + $userData = $this->accountManager->getUser($user); |
|
106 | + |
|
107 | + $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
108 | + if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
109 | + $totalSpace = $this->l->t('Unlimited'); |
|
110 | + } else { |
|
111 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
112 | + } |
|
113 | + |
|
114 | + $languageParameters = $this->getLanguages($user); |
|
115 | + $localeParameters = $this->getLocales($user); |
|
116 | + $messageParameters = $this->getMessageParameters($userData); |
|
117 | + |
|
118 | + $parameters = [ |
|
119 | + 'total_space' => $totalSpace, |
|
120 | + 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
121 | + 'usage_relative' => $storageInfo['relative'], |
|
122 | + 'quota' => $storageInfo['quota'], |
|
123 | + 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
124 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
125 | + 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
126 | + 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
127 | + 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
128 | + 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
|
129 | + 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
130 | + 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
131 | + 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
132 | + 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
133 | + 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
134 | + 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
135 | + 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
136 | + 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
137 | + 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
138 | + 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
139 | + 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
140 | + 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
141 | + 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
142 | + 'groups' => $this->getGroups($user), |
|
143 | + 'passwordChangeSupported' => $user->canChangePassword(), |
|
144 | + ] + $messageParameters + $languageParameters + $localeParameters; |
|
145 | + |
|
146 | + |
|
147 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string the section ID, e.g. 'sharing' |
|
152 | + * @since 9.1 |
|
153 | + */ |
|
154 | + public function getSection() { |
|
155 | + return 'personal-info'; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return int whether the form should be rather on the top or bottom of |
|
160 | + * the admin section. The forms are arranged in ascending order of the |
|
161 | + * priority values. It is required to return a value between 0 and 100. |
|
162 | + * |
|
163 | + * E.g.: 70 |
|
164 | + * @since 9.1 |
|
165 | + */ |
|
166 | + public function getPriority() { |
|
167 | + return 10; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * returns a sorted list of the user's group GIDs |
|
172 | + * |
|
173 | + * @param IUser $user |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + private function getGroups(IUser $user) { |
|
177 | + $groups = array_map( |
|
178 | + function(IGroup $group) { |
|
179 | + return $group->getGID(); |
|
180 | + }, |
|
181 | + $this->groupManager->getUserGroups($user) |
|
182 | + ); |
|
183 | + sort($groups); |
|
184 | + |
|
185 | + return $groups; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * returns the user language, common language and other languages in an |
|
190 | + * associative array |
|
191 | + * |
|
192 | + * @param IUser $user |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + private function getLanguages(IUser $user) { |
|
196 | + $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
197 | + if($forceLanguage !== false) { |
|
198 | + return []; |
|
199 | + } |
|
200 | + |
|
201 | + $uid = $user->getUID(); |
|
202 | + |
|
203 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
204 | + $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
205 | + |
|
206 | + $commonLanguages = []; |
|
207 | + $languages = []; |
|
208 | + |
|
209 | + foreach($languageCodes as $lang) { |
|
210 | + $l = \OC::$server->getL10N('settings', $lang); |
|
211 | + // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
212 | + $potentialName = (string) $l->t('__language_name__'); |
|
213 | + if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
214 | + $ln = array('code' => $lang, 'name' => $potentialName); |
|
215 | + } elseif ($lang === 'en') { |
|
216 | + $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
217 | + }else{//fallback to language code |
|
218 | + $ln=array('code'=>$lang, 'name'=>$lang); |
|
219 | + } |
|
220 | + |
|
221 | + // put appropriate languages into appropriate arrays, to print them sorted |
|
222 | + // used language -> common languages -> divider -> other languages |
|
223 | + if ($lang === $userLang) { |
|
224 | + $userLang = $ln; |
|
225 | + } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
226 | + $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
227 | + } else { |
|
228 | + $languages[]=$ln; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + // if user language is not available but set somehow: show the actual code as name |
|
233 | + if (!is_array($userLang)) { |
|
234 | + $userLang = [ |
|
235 | + 'code' => $userLang, |
|
236 | + 'name' => $userLang, |
|
237 | + ]; |
|
238 | + } |
|
239 | + |
|
240 | + ksort($commonLanguages); |
|
241 | + |
|
242 | + // sort now by displayed language not the iso-code |
|
243 | + usort( $languages, function ($a, $b) { |
|
244 | + if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
245 | + // If a doesn't have a name, but b does, list b before a |
|
246 | + return 1; |
|
247 | + } |
|
248 | + if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
249 | + // If a does have a name, but b doesn't, list a before b |
|
250 | + return -1; |
|
251 | + } |
|
252 | + // Otherwise compare the names |
|
253 | + return strcmp($a['name'], $b['name']); |
|
254 | + }); |
|
255 | + |
|
256 | + return [ |
|
257 | + 'activelanguage' => $userLang, |
|
258 | + 'commonlanguages' => $commonLanguages, |
|
259 | + 'languages' => $languages |
|
260 | + ]; |
|
261 | + } |
|
262 | + |
|
263 | + private function getLocales(IUser $user) { |
|
264 | + $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
265 | + if($forceLanguage !== false) { |
|
266 | + return []; |
|
267 | + } |
|
268 | + |
|
269 | + $uid = $user->getUID(); |
|
270 | + |
|
271 | + $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', 'en_US'); |
|
272 | + |
|
273 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
274 | + |
|
275 | + $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
276 | + |
|
277 | + $userLocale = array_filter($localeCodes, function($value) use ($userLocaleString) { |
|
278 | + return $userLocaleString === $value['code']; |
|
279 | + }); |
|
280 | + |
|
281 | + if (!empty($userLocale)) |
|
282 | + { |
|
283 | + $userLocale = reset($userLocale); |
|
284 | + } |
|
285 | + |
|
286 | + $localesForLanguage = array_filter($localeCodes, function($localeCode) use ($userLang) { |
|
287 | + return 0 === strpos($localeCode['code'], $userLang); |
|
288 | + }); |
|
289 | + |
|
290 | + return [ |
|
291 | + 'activelocaleLang' => $userLocaleString, |
|
292 | + 'activelocale' => $userLocale, |
|
293 | + 'locales' => $localeCodes, |
|
294 | + 'localesforlanguage' => $localesForLanguage, |
|
295 | + ]; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @param array $userData |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + private function getMessageParameters(array $userData) { |
|
303 | + $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER]; |
|
304 | + $messageParameters = []; |
|
305 | + foreach ($needVerifyMessage as $property) { |
|
306 | + switch ($userData[$property]['verified']) { |
|
307 | + case AccountManager::VERIFIED: |
|
308 | + $message = $this->l->t('Verifying'); |
|
309 | + break; |
|
310 | + case AccountManager::VERIFICATION_IN_PROGRESS: |
|
311 | + $message = $this->l->t('Verifying …'); |
|
312 | + break; |
|
313 | + default: |
|
314 | + $message = $this->l->t('Verify'); |
|
315 | + } |
|
316 | + $messageParameters[$property . 'Message'] = $message; |
|
317 | + } |
|
318 | + return $messageParameters; |
|
319 | + } |
|
320 | 320 | |
321 | 321 | } |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | ?> |
40 | 40 | |
41 | 41 | <div id="quota" class="section"> |
42 | - <div style="width:<?php p($_['usage_relative']);?>%" |
|
43 | - <?php if($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
42 | + <div style="width:<?php p($_['usage_relative']); ?>%" |
|
43 | + <?php if ($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
44 | 44 | <p id="quotatext"> |
45 | 45 | <?php if ($_['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED): ?> |
46 | 46 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong>', |
47 | - [$_['usage'], $_['total_space']]));?> |
|
47 | + [$_['usage'], $_['total_space']])); ?> |
|
48 | 48 | <?php else: ?> |
49 | 49 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong> (<strong>%s %%</strong>)', |
50 | - [$_['usage'], $_['total_space'], $_['usage_relative']]));?> |
|
50 | + [$_['usage'], $_['total_space'], $_['usage_relative']])); ?> |
|
51 | 51 | <?php endif ?> |
52 | 52 | </p> |
53 | 53 | </div> |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | </div> |
82 | 82 | </div> |
83 | 83 | <span class="icon-checkmark hidden"/> |
84 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
84 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
85 | 85 | <input type="hidden" id="avatarscope" value="<?php p($_['avatarScope']) ?>"> |
86 | 86 | <?php } ?> |
87 | 87 | </form> |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | <span class="icon-password"/> |
96 | 96 | </h2> |
97 | 97 | <input type="text" id="displayname" name="displayname" |
98 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
98 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
99 | 99 | value="<?php p($_['displayName']) ?>" |
100 | 100 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
101 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
102 | - <span><?php if(isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
101 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
102 | + <span><?php if (isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
103 | 103 | <?php } ?> |
104 | 104 | <span class="icon-checkmark hidden"/> |
105 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
105 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
106 | 106 | <input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>"> |
107 | 107 | <?php } ?> |
108 | 108 | </form> |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | <label for="email"><?php p($l->t('Email')); ?></label> |
114 | 114 | <span class="icon-password"/> |
115 | 115 | </h2> |
116 | - <div class="verify <?php if ($_['email'] === '' || $_['emailScope'] !== 'public') p('hidden'); ?>"> |
|
116 | + <div class="verify <?php if ($_['email'] === '' || $_['emailScope'] !== 'public') p('hidden'); ?>"> |
|
117 | 117 | <img id="verify-email" title="<?php p($_['emailMessage']); ?>" data-status="<?php p($_['emailVerification']) ?>" src=" |
118 | 118 | <?php |
119 | - switch($_['emailVerification']) { |
|
119 | + switch ($_['emailVerification']) { |
|
120 | 120 | case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
121 | 121 | p(image_path('core', 'actions/verifying.svg')); |
122 | 122 | break; |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | ?>"> |
130 | 130 | </div> |
131 | 131 | <input type="email" name="email" id="email" value="<?php p($_['email']); ?>" |
132 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
132 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
133 | 133 | placeholder="<?php p($l->t('Your email address')); ?>" |
134 | 134 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
135 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
136 | - <span><?php if(isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
135 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
136 | + <span><?php if (isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
137 | 137 | <?php } ?> |
138 | - <?php if($_['displayNameChangeSupported']) { ?> |
|
138 | + <?php if ($_['displayNameChangeSupported']) { ?> |
|
139 | 139 | <br /> |
140 | 140 | <em><?php p($l->t('For password reset and notifications')); ?></em> |
141 | 141 | <?php } ?> |
142 | 142 | <span class="icon-checkmark hidden"/> |
143 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
143 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
144 | 144 | <input type="hidden" id="emailscope" value="<?php p($_['emailScope']) ?>"> |
145 | 145 | <?php } ?> |
146 | 146 | </form> |
147 | 147 | </div> |
148 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
148 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
149 | 149 | <div class="personal-settings-setting-box"> |
150 | 150 | <form id="phoneform" class="section"> |
151 | 151 | <h2> |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | <label for="website"><?php p($l->t('Website')); ?></label> |
181 | 181 | <span class="icon-password"/> |
182 | 182 | </h2> |
183 | - <div class="verify <?php if ($_['website'] === '' || $_['websiteScope'] !== 'public') p('hidden'); ?>"> |
|
183 | + <div class="verify <?php if ($_['website'] === '' || $_['websiteScope'] !== 'public') p('hidden'); ?>"> |
|
184 | 184 | <img id="verify-website" title="<?php p($_['websiteMessage']); ?>" data-status="<?php p($_['websiteVerification']) ?>" src=" |
185 | 185 | <?php |
186 | - switch($_['websiteVerification']) { |
|
186 | + switch ($_['websiteVerification']) { |
|
187 | 187 | case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
188 | 188 | p(image_path('core', 'actions/verifying.svg')); |
189 | 189 | break; |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | p(image_path('core', 'actions/verify.svg')); |
195 | 195 | } |
196 | 196 | ?>" |
197 | - <?php if($_['websiteVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['websiteVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
|
197 | + <?php if ($_['websiteVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['websiteVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
|
198 | 198 | > |
199 | 199 | <div class="verification-dialog popovermenu bubble menu"> |
200 | 200 | <div class="verification-dialog-content"> |
201 | 201 | <p class="explainVerification"></p> |
202 | 202 | <p class="verificationCode"></p> |
203 | - <p><?php p($l->t('It can take up to 24 hours before the account is displayed as verified.'));?></p> |
|
203 | + <p><?php p($l->t('It can take up to 24 hours before the account is displayed as verified.')); ?></p> |
|
204 | 204 | </div> |
205 | 205 | </div> |
206 | 206 | </div> |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | <label for="twitter"><?php p($l->t('Twitter')); ?></label> |
218 | 218 | <span class="icon-password"/> |
219 | 219 | </h2> |
220 | - <div class="verify <?php if ($_['twitter'] === '' || $_['twitterScope'] !== 'public') p('hidden'); ?>"> |
|
220 | + <div class="verify <?php if ($_['twitter'] === '' || $_['twitterScope'] !== 'public') p('hidden'); ?>"> |
|
221 | 221 | <img id="verify-twitter" title="<?php p($_['twitterMessage']); ?>" data-status="<?php p($_['twitterVerification']) ?>" src=" |
222 | 222 | <?php |
223 | - switch($_['twitterVerification']) { |
|
223 | + switch ($_['twitterVerification']) { |
|
224 | 224 | case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
225 | 225 | p(image_path('core', 'actions/verifying.svg')); |
226 | 226 | break; |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | p(image_path('core', 'actions/verify.svg')); |
232 | 232 | } |
233 | 233 | ?>" |
234 | - <?php if($_['twitterVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['twitterVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
|
234 | + <?php if ($_['twitterVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['twitterVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
|
235 | 235 | > |
236 | 236 | <div class="verification-dialog popovermenu bubble menu"> |
237 | 237 | <div class="verification-dialog-content"> |
238 | 238 | <p class="explainVerification"></p> |
239 | 239 | <p class="verificationCode"></p> |
240 | - <p><?php p($l->t('It can take up to 24 hours before the account is displayed as verified.'));?></p> |
|
240 | + <p><?php p($l->t('It can take up to 24 hours before the account is displayed as verified.')); ?></p> |
|
241 | 241 | </div> |
242 | 242 | </div> |
243 | 243 | </div> |
@@ -262,19 +262,19 @@ discard block |
||
262 | 262 | </div> |
263 | 263 | |
264 | 264 | <?php |
265 | -if($_['passwordChangeSupported']) { |
|
265 | +if ($_['passwordChangeSupported']) { |
|
266 | 266 | script('jquery-showpassword'); |
267 | 267 | ?> |
268 | 268 | <form id="passwordform" class="section"> |
269 | - <h2 class="inlineblock"><?php p($l->t('Password'));?></h2> |
|
269 | + <h2 class="inlineblock"><?php p($l->t('Password')); ?></h2> |
|
270 | 270 | <div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div> |
271 | 271 | <br> |
272 | 272 | <label for="pass1" class="hidden-visually"><?php p($l->t('Current password')); ?>: </label> |
273 | 273 | <input type="password" id="pass1" name="oldpassword" |
274 | - placeholder="<?php p($l->t('Current password'));?>" |
|
274 | + placeholder="<?php p($l->t('Current password')); ?>" |
|
275 | 275 | autocomplete="off" autocapitalize="none" autocorrect="off" /> |
276 | 276 | <div class="personal-show-container"> |
277 | - <label for="pass2" class="hidden-visually"><?php p($l->t('New password'));?>: </label> |
|
277 | + <label for="pass2" class="hidden-visually"><?php p($l->t('New password')); ?>: </label> |
|
278 | 278 | <input type="password" id="pass2" name="newpassword" |
279 | 279 | placeholder="<?php p($l->t('New password')); ?>" |
280 | 280 | data-typetoggle="#personal-show" |
@@ -291,27 +291,27 @@ discard block |
||
291 | 291 | <?php if (isset($_['activelanguage'])) { ?> |
292 | 292 | <form id="language" class="section"> |
293 | 293 | <h2> |
294 | - <label for="languageinput"><?php p($l->t('Language'));?></label> |
|
294 | + <label for="languageinput"><?php p($l->t('Language')); ?></label> |
|
295 | 295 | </h2> |
296 | - <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language'));?>"> |
|
297 | - <option value="<?php p($_['activelanguage']['code']);?>"> |
|
298 | - <?php p($_['activelanguage']['name']);?> |
|
296 | + <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language')); ?>"> |
|
297 | + <option value="<?php p($_['activelanguage']['code']); ?>"> |
|
298 | + <?php p($_['activelanguage']['name']); ?> |
|
299 | 299 | </option> |
300 | - <?php foreach($_['commonlanguages'] as $language):?> |
|
301 | - <option value="<?php p($language['code']);?>"> |
|
302 | - <?php p($language['name']);?> |
|
300 | + <?php foreach ($_['commonlanguages'] as $language):?> |
|
301 | + <option value="<?php p($language['code']); ?>"> |
|
302 | + <?php p($language['name']); ?> |
|
303 | 303 | </option> |
304 | - <?php endforeach;?> |
|
304 | + <?php endforeach; ?> |
|
305 | 305 | <optgroup label="––––––––––"></optgroup> |
306 | - <?php foreach($_['languages'] as $language):?> |
|
307 | - <option value="<?php p($language['code']);?>"> |
|
308 | - <?php p($language['name']);?> |
|
306 | + <?php foreach ($_['languages'] as $language):?> |
|
307 | + <option value="<?php p($language['code']); ?>"> |
|
308 | + <?php p($language['name']); ?> |
|
309 | 309 | </option> |
310 | - <?php endforeach;?> |
|
310 | + <?php endforeach; ?> |
|
311 | 311 | </select> |
312 | 312 | <a href="https://www.transifex.com/nextcloud/nextcloud/" |
313 | 313 | target="_blank" rel="noreferrer"> |
314 | - <em><?php p($l->t('Help translate'));?></em> |
|
314 | + <em><?php p($l->t('Help translate')); ?></em> |
|
315 | 315 | </a> |
316 | 316 | </form> |
317 | 317 | <?php } ?> |
@@ -319,27 +319,27 @@ discard block |
||
319 | 319 | <?php if (isset($_['activelocale'])) { ?> |
320 | 320 | <form id="locale" class="section"> |
321 | 321 | <h2> |
322 | - <label for="localeinput"><?php p($l->t('Locale'));?></label> |
|
322 | + <label for="localeinput"><?php p($l->t('Locale')); ?></label> |
|
323 | 323 | </h2> |
324 | - <select id="localeinput" name="lang" data-placeholder="<?php p($l->t('Locale'));?>"> |
|
325 | - <option value="<?php p($_['activelocale']['code']);?>"> |
|
326 | - <?php p($_['activelocale']['name']);?> |
|
324 | + <select id="localeinput" name="lang" data-placeholder="<?php p($l->t('Locale')); ?>"> |
|
325 | + <option value="<?php p($_['activelocale']['code']); ?>"> |
|
326 | + <?php p($_['activelocale']['name']); ?> |
|
327 | 327 | </option> |
328 | 328 | <optgroup label="––––––––––"></optgroup> |
329 | - <?php foreach($_['localesforlanguage'] as $locale):?> |
|
330 | - <option value="<?php p($locale['code']);?>"> |
|
331 | - <?php p($locale['name']);?> |
|
329 | + <?php foreach ($_['localesforlanguage'] as $locale):?> |
|
330 | + <option value="<?php p($locale['code']); ?>"> |
|
331 | + <?php p($locale['name']); ?> |
|
332 | 332 | </option> |
333 | - <?php endforeach;?> |
|
333 | + <?php endforeach; ?> |
|
334 | 334 | <optgroup label="––––––––––"></optgroup> |
335 | - <option value="<?php p($_['activelocale']['code']);?>"> |
|
336 | - <?php p($_['activelocale']['name']);?> |
|
335 | + <option value="<?php p($_['activelocale']['code']); ?>"> |
|
336 | + <?php p($_['activelocale']['name']); ?> |
|
337 | 337 | </option> |
338 | - <?php foreach($_['locales'] as $locale):?> |
|
339 | - <option value="<?php p($locale['code']);?>"> |
|
340 | - <?php p($locale['name']);?> |
|
338 | + <?php foreach ($_['locales'] as $locale):?> |
|
339 | + <option value="<?php p($locale['code']); ?>"> |
|
340 | + <?php p($locale['name']); ?> |
|
341 | 341 | </option> |
342 | - <?php endforeach;?> |
|
342 | + <?php endforeach; ?> |
|
343 | 343 | </select> |
344 | 344 | </form> |
345 | 345 | <?php } ?> |
@@ -40,445 +40,445 @@ |
||
40 | 40 | */ |
41 | 41 | class Factory implements IFactory { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - protected $requestLanguage = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * cached instances |
|
48 | - * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | - */ |
|
50 | - protected $instances = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array Structure: App => string[] |
|
54 | - */ |
|
55 | - protected $availableLanguages = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array Structure: string => callable |
|
59 | - */ |
|
60 | - protected $pluralFunctions = []; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IRequest */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - protected $serverRoot; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param IRequest $request |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param string $serverRoot |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - IRequest $request, |
|
82 | - IUserSession $userSession, |
|
83 | - $serverRoot) { |
|
84 | - $this->config = $config; |
|
85 | - $this->request = $request; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->serverRoot = $serverRoot; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get a language instance |
|
92 | - * |
|
93 | - * @param string $app |
|
94 | - * @param string|null $lang |
|
95 | - * @param string|null $locale |
|
96 | - * @return \OCP\IL10N |
|
97 | - */ |
|
98 | - public function get($app, $lang = null, $locale = null) { |
|
99 | - $app = \OC_App::cleanAppId($app); |
|
100 | - if ($lang !== null) { |
|
101 | - $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
102 | - } |
|
103 | - |
|
104 | - $forceLang = $this->config->getSystemValue('force_language', false); |
|
105 | - if (is_string($forceLang)) { |
|
106 | - $lang = $forceLang; |
|
107 | - } |
|
108 | - |
|
109 | - $forceLocale = $this->config->getSystemValue('force_locale', false); |
|
110 | - if (is_string($forceLocale)) { |
|
111 | - $locale = $forceLocale; |
|
112 | - } |
|
113 | - |
|
114 | - if ($lang === null || !$this->languageExists($app, $lang)) { |
|
115 | - $lang = $this->findLanguage($app); |
|
116 | - } |
|
117 | - |
|
118 | - if ($locale === null || !$this->localeExists($locale)) { |
|
119 | - $locale = $this->findLocale($app, $lang); |
|
120 | - } |
|
121 | - |
|
122 | - if (!isset($this->instances[$lang][$app])) { |
|
123 | - $this->instances[$lang][$app] = new L10N( |
|
124 | - $this, $app, $lang, $locale, |
|
125 | - $this->getL10nFilesForApp($app, $lang) |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - return $this->instances[$lang][$app]; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Find the best language |
|
134 | - * |
|
135 | - * @param string|null $app App id or null for core |
|
136 | - * @return string language If nothing works it returns 'en' |
|
137 | - */ |
|
138 | - public function findLanguage($app = null) { |
|
139 | - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
140 | - return $this->requestLanguage; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * At this point Nextcloud might not yet be installed and thus the lookup |
|
145 | - * in the preferences table might fail. For this reason we need to check |
|
146 | - * whether the instance has already been installed |
|
147 | - * |
|
148 | - * @link https://github.com/owncloud/core/issues/21955 |
|
149 | - */ |
|
150 | - if($this->config->getSystemValue('installed', false)) { |
|
151 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
152 | - if(!is_null($userId)) { |
|
153 | - $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
154 | - } else { |
|
155 | - $userLang = null; |
|
156 | - } |
|
157 | - } else { |
|
158 | - $userId = null; |
|
159 | - $userLang = null; |
|
160 | - } |
|
161 | - |
|
162 | - if ($userLang) { |
|
163 | - $this->requestLanguage = $userLang; |
|
164 | - if ($this->languageExists($app, $userLang)) { |
|
165 | - return $userLang; |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - try { |
|
170 | - // Try to get the language from the Request |
|
171 | - $lang = $this->getLanguageFromRequest($app); |
|
172 | - if ($userId !== null && $app === null && !$userLang) { |
|
173 | - $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
174 | - } |
|
175 | - return $lang; |
|
176 | - } catch (LanguageNotFoundException $e) { |
|
177 | - // Finding language from request failed fall back to default language |
|
178 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
179 | - if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
180 | - return $defaultLanguage; |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - // We could not find any language so fall back to english |
|
185 | - return 'en'; |
|
186 | - } |
|
187 | - |
|
188 | - public function findLocale($lang = null) |
|
189 | - { |
|
190 | - if ($this->config->getSystemValue('installed', false)) { |
|
191 | - $userId = null !== $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; |
|
192 | - $userLocale = null; |
|
193 | - if (null !== $userId) { |
|
194 | - $userLocale = $this->config->getUserValue($userId, 'core', 'locale', null); |
|
195 | - } |
|
196 | - } else { |
|
197 | - $userId = null; |
|
198 | - $userLocale = null; |
|
199 | - } |
|
200 | - |
|
201 | - if ($userLocale && $this->localeExists($userLocale)) { |
|
202 | - return $userLocale; |
|
203 | - } |
|
204 | - |
|
205 | - // Default : use system default locale |
|
206 | - $defaultLocale = $this->config->getSystemValue('default_locale', false); |
|
207 | - if ($defaultLocale !== false && $this->localeExists($defaultLocale)) { |
|
208 | - return $defaultLocale; |
|
209 | - } |
|
210 | - |
|
211 | - // If no user locale set, use lang as locale |
|
212 | - if (null !== $lang && $this->localeExists($lang)) { |
|
213 | - return $lang; |
|
214 | - } |
|
215 | - |
|
216 | - // At last, return USA |
|
217 | - return 'en_US'; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Find all available languages for an app |
|
222 | - * |
|
223 | - * @param string|null $app App id or null for core |
|
224 | - * @return array an array of available languages |
|
225 | - */ |
|
226 | - public function findAvailableLanguages($app = null) { |
|
227 | - $key = $app; |
|
228 | - if ($key === null) { |
|
229 | - $key = 'null'; |
|
230 | - } |
|
231 | - |
|
232 | - // also works with null as key |
|
233 | - if (!empty($this->availableLanguages[$key])) { |
|
234 | - return $this->availableLanguages[$key]; |
|
235 | - } |
|
236 | - |
|
237 | - $available = ['en']; //english is always available |
|
238 | - $dir = $this->findL10nDir($app); |
|
239 | - if (is_dir($dir)) { |
|
240 | - $files = scandir($dir); |
|
241 | - if ($files !== false) { |
|
242 | - foreach ($files as $file) { |
|
243 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
244 | - $available[] = substr($file, 0, -5); |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - // merge with translations from theme |
|
251 | - $theme = $this->config->getSystemValue('theme'); |
|
252 | - if (!empty($theme)) { |
|
253 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
254 | - |
|
255 | - if (is_dir($themeDir)) { |
|
256 | - $files = scandir($themeDir); |
|
257 | - if ($files !== false) { |
|
258 | - foreach ($files as $file) { |
|
259 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
260 | - $available[] = substr($file, 0, -5); |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - $this->availableLanguages[$key] = $available; |
|
268 | - return $available; |
|
269 | - } |
|
270 | - |
|
271 | - public function findAvailableLocales() |
|
272 | - { |
|
273 | - $localeData = file_get_contents(__DIR__ . '/locales.json'); |
|
274 | - return json_decode($localeData, true); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @param string|null $app App id or null for core |
|
279 | - * @param string $lang |
|
280 | - * @return bool |
|
281 | - */ |
|
282 | - public function languageExists($app, $lang) { |
|
283 | - if ($lang === 'en') {//english is always available |
|
284 | - return true; |
|
285 | - } |
|
286 | - |
|
287 | - $languages = $this->findAvailableLanguages($app); |
|
288 | - return array_search($lang, $languages) !== false; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param string $locale |
|
293 | - * @return bool |
|
294 | - */ |
|
295 | - public function localeExists($locale) { |
|
296 | - if ($locale === 'en') { //english is always available |
|
297 | - return true; |
|
298 | - } |
|
299 | - |
|
300 | - $locales = $this->findAvailableLocales(); |
|
301 | - |
|
302 | - $userLocale = array_filter($locales, function($value) use ($locale) { |
|
303 | - return $locale === $value['code']; |
|
304 | - }); |
|
305 | - |
|
306 | - return !empty($userLocale); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * @param string|null $app |
|
311 | - * @return string |
|
312 | - * @throws LanguageNotFoundException |
|
313 | - */ |
|
314 | - private function getLanguageFromRequest($app) { |
|
315 | - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
316 | - if ($header) { |
|
317 | - $available = $this->findAvailableLanguages($app); |
|
318 | - |
|
319 | - // E.g. make sure that 'de' is before 'de_DE'. |
|
320 | - sort($available); |
|
321 | - |
|
322 | - $preferences = preg_split('/,\s*/', strtolower($header)); |
|
323 | - foreach ($preferences as $preference) { |
|
324 | - list($preferred_language) = explode(';', $preference); |
|
325 | - $preferred_language = str_replace('-', '_', $preferred_language); |
|
326 | - |
|
327 | - foreach ($available as $available_language) { |
|
328 | - if ($preferred_language === strtolower($available_language)) { |
|
329 | - return $available_language; |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - // Fallback from de_De to de |
|
334 | - foreach ($available as $available_language) { |
|
335 | - if (substr($preferred_language, 0, 2) === $available_language) { |
|
336 | - return $available_language; |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - throw new LanguageNotFoundException(); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Checks if $sub is a subdirectory of $parent |
|
347 | - * |
|
348 | - * @param string $sub |
|
349 | - * @param string $parent |
|
350 | - * @return bool |
|
351 | - */ |
|
352 | - private function isSubDirectory($sub, $parent) { |
|
353 | - // Check whether $sub contains no ".." |
|
354 | - if(strpos($sub, '..') !== false) { |
|
355 | - return false; |
|
356 | - } |
|
357 | - |
|
358 | - // Check whether $sub is a subdirectory of $parent |
|
359 | - if (strpos($sub, $parent) === 0) { |
|
360 | - return true; |
|
361 | - } |
|
362 | - |
|
363 | - return false; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a list of language files that should be loaded |
|
368 | - * |
|
369 | - * @param string $app |
|
370 | - * @param string $lang |
|
371 | - * @return string[] |
|
372 | - */ |
|
373 | - // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
374 | - // FIXME This is also the reason, why it is not in the public interface |
|
375 | - public function getL10nFilesForApp($app, $lang) { |
|
376 | - $languageFiles = []; |
|
377 | - |
|
378 | - $i18nDir = $this->findL10nDir($app); |
|
379 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
380 | - |
|
381 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
382 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
383 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
384 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
385 | - ) |
|
386 | - && file_exists($transFile)) { |
|
387 | - // load the translations file |
|
388 | - $languageFiles[] = $transFile; |
|
389 | - } |
|
390 | - |
|
391 | - // merge with translations from theme |
|
392 | - $theme = $this->config->getSystemValue('theme'); |
|
393 | - if (!empty($theme)) { |
|
394 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
395 | - if (file_exists($transFile)) { |
|
396 | - $languageFiles[] = $transFile; |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - return $languageFiles; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * find the l10n directory |
|
405 | - * |
|
406 | - * @param string $app App id or empty string for core |
|
407 | - * @return string directory |
|
408 | - */ |
|
409 | - protected function findL10nDir($app = null) { |
|
410 | - if (in_array($app, ['core', 'lib', 'settings'])) { |
|
411 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
412 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
413 | - } |
|
414 | - } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
415 | - // Check if the app is in the app folder |
|
416 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
417 | - } |
|
418 | - return $this->serverRoot . '/core/l10n/'; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Creates a function from the plural string |
|
424 | - * |
|
425 | - * Parts of the code is copied from Habari: |
|
426 | - * https://github.com/habari/system/blob/master/classes/locale.php |
|
427 | - * @param string $string |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function createPluralFunction($string) { |
|
431 | - if (isset($this->pluralFunctions[$string])) { |
|
432 | - return $this->pluralFunctions[$string]; |
|
433 | - } |
|
434 | - |
|
435 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
436 | - // sanitize |
|
437 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
438 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
439 | - |
|
440 | - $body = str_replace( |
|
441 | - array( 'plural', 'n', '$n$plurals', ), |
|
442 | - array( '$plural', '$n', '$nplurals', ), |
|
443 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
444 | - ); |
|
445 | - |
|
446 | - // add parents |
|
447 | - // important since PHP's ternary evaluates from left to right |
|
448 | - $body .= ';'; |
|
449 | - $res = ''; |
|
450 | - $p = 0; |
|
451 | - for($i = 0; $i < strlen($body); $i++) { |
|
452 | - $ch = $body[$i]; |
|
453 | - switch ( $ch ) { |
|
454 | - case '?': |
|
455 | - $res .= ' ? ('; |
|
456 | - $p++; |
|
457 | - break; |
|
458 | - case ':': |
|
459 | - $res .= ') : ('; |
|
460 | - break; |
|
461 | - case ';': |
|
462 | - $res .= str_repeat( ')', $p ) . ';'; |
|
463 | - $p = 0; |
|
464 | - break; |
|
465 | - default: |
|
466 | - $res .= $ch; |
|
467 | - } |
|
468 | - } |
|
469 | - |
|
470 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
471 | - $function = create_function('$n', $body); |
|
472 | - $this->pluralFunctions[$string] = $function; |
|
473 | - return $function; |
|
474 | - } else { |
|
475 | - // default: one plural form for all cases but n==1 (english) |
|
476 | - $function = create_function( |
|
477 | - '$n', |
|
478 | - '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
479 | - ); |
|
480 | - $this->pluralFunctions[$string] = $function; |
|
481 | - return $function; |
|
482 | - } |
|
483 | - } |
|
43 | + /** @var string */ |
|
44 | + protected $requestLanguage = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * cached instances |
|
48 | + * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | + */ |
|
50 | + protected $instances = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array Structure: App => string[] |
|
54 | + */ |
|
55 | + protected $availableLanguages = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array Structure: string => callable |
|
59 | + */ |
|
60 | + protected $pluralFunctions = []; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IRequest */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + protected $serverRoot; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param IRequest $request |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param string $serverRoot |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + IRequest $request, |
|
82 | + IUserSession $userSession, |
|
83 | + $serverRoot) { |
|
84 | + $this->config = $config; |
|
85 | + $this->request = $request; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->serverRoot = $serverRoot; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get a language instance |
|
92 | + * |
|
93 | + * @param string $app |
|
94 | + * @param string|null $lang |
|
95 | + * @param string|null $locale |
|
96 | + * @return \OCP\IL10N |
|
97 | + */ |
|
98 | + public function get($app, $lang = null, $locale = null) { |
|
99 | + $app = \OC_App::cleanAppId($app); |
|
100 | + if ($lang !== null) { |
|
101 | + $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
102 | + } |
|
103 | + |
|
104 | + $forceLang = $this->config->getSystemValue('force_language', false); |
|
105 | + if (is_string($forceLang)) { |
|
106 | + $lang = $forceLang; |
|
107 | + } |
|
108 | + |
|
109 | + $forceLocale = $this->config->getSystemValue('force_locale', false); |
|
110 | + if (is_string($forceLocale)) { |
|
111 | + $locale = $forceLocale; |
|
112 | + } |
|
113 | + |
|
114 | + if ($lang === null || !$this->languageExists($app, $lang)) { |
|
115 | + $lang = $this->findLanguage($app); |
|
116 | + } |
|
117 | + |
|
118 | + if ($locale === null || !$this->localeExists($locale)) { |
|
119 | + $locale = $this->findLocale($app, $lang); |
|
120 | + } |
|
121 | + |
|
122 | + if (!isset($this->instances[$lang][$app])) { |
|
123 | + $this->instances[$lang][$app] = new L10N( |
|
124 | + $this, $app, $lang, $locale, |
|
125 | + $this->getL10nFilesForApp($app, $lang) |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + return $this->instances[$lang][$app]; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Find the best language |
|
134 | + * |
|
135 | + * @param string|null $app App id or null for core |
|
136 | + * @return string language If nothing works it returns 'en' |
|
137 | + */ |
|
138 | + public function findLanguage($app = null) { |
|
139 | + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
140 | + return $this->requestLanguage; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * At this point Nextcloud might not yet be installed and thus the lookup |
|
145 | + * in the preferences table might fail. For this reason we need to check |
|
146 | + * whether the instance has already been installed |
|
147 | + * |
|
148 | + * @link https://github.com/owncloud/core/issues/21955 |
|
149 | + */ |
|
150 | + if($this->config->getSystemValue('installed', false)) { |
|
151 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
152 | + if(!is_null($userId)) { |
|
153 | + $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
154 | + } else { |
|
155 | + $userLang = null; |
|
156 | + } |
|
157 | + } else { |
|
158 | + $userId = null; |
|
159 | + $userLang = null; |
|
160 | + } |
|
161 | + |
|
162 | + if ($userLang) { |
|
163 | + $this->requestLanguage = $userLang; |
|
164 | + if ($this->languageExists($app, $userLang)) { |
|
165 | + return $userLang; |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + try { |
|
170 | + // Try to get the language from the Request |
|
171 | + $lang = $this->getLanguageFromRequest($app); |
|
172 | + if ($userId !== null && $app === null && !$userLang) { |
|
173 | + $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
174 | + } |
|
175 | + return $lang; |
|
176 | + } catch (LanguageNotFoundException $e) { |
|
177 | + // Finding language from request failed fall back to default language |
|
178 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
179 | + if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
180 | + return $defaultLanguage; |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + // We could not find any language so fall back to english |
|
185 | + return 'en'; |
|
186 | + } |
|
187 | + |
|
188 | + public function findLocale($lang = null) |
|
189 | + { |
|
190 | + if ($this->config->getSystemValue('installed', false)) { |
|
191 | + $userId = null !== $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; |
|
192 | + $userLocale = null; |
|
193 | + if (null !== $userId) { |
|
194 | + $userLocale = $this->config->getUserValue($userId, 'core', 'locale', null); |
|
195 | + } |
|
196 | + } else { |
|
197 | + $userId = null; |
|
198 | + $userLocale = null; |
|
199 | + } |
|
200 | + |
|
201 | + if ($userLocale && $this->localeExists($userLocale)) { |
|
202 | + return $userLocale; |
|
203 | + } |
|
204 | + |
|
205 | + // Default : use system default locale |
|
206 | + $defaultLocale = $this->config->getSystemValue('default_locale', false); |
|
207 | + if ($defaultLocale !== false && $this->localeExists($defaultLocale)) { |
|
208 | + return $defaultLocale; |
|
209 | + } |
|
210 | + |
|
211 | + // If no user locale set, use lang as locale |
|
212 | + if (null !== $lang && $this->localeExists($lang)) { |
|
213 | + return $lang; |
|
214 | + } |
|
215 | + |
|
216 | + // At last, return USA |
|
217 | + return 'en_US'; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Find all available languages for an app |
|
222 | + * |
|
223 | + * @param string|null $app App id or null for core |
|
224 | + * @return array an array of available languages |
|
225 | + */ |
|
226 | + public function findAvailableLanguages($app = null) { |
|
227 | + $key = $app; |
|
228 | + if ($key === null) { |
|
229 | + $key = 'null'; |
|
230 | + } |
|
231 | + |
|
232 | + // also works with null as key |
|
233 | + if (!empty($this->availableLanguages[$key])) { |
|
234 | + return $this->availableLanguages[$key]; |
|
235 | + } |
|
236 | + |
|
237 | + $available = ['en']; //english is always available |
|
238 | + $dir = $this->findL10nDir($app); |
|
239 | + if (is_dir($dir)) { |
|
240 | + $files = scandir($dir); |
|
241 | + if ($files !== false) { |
|
242 | + foreach ($files as $file) { |
|
243 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
244 | + $available[] = substr($file, 0, -5); |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + // merge with translations from theme |
|
251 | + $theme = $this->config->getSystemValue('theme'); |
|
252 | + if (!empty($theme)) { |
|
253 | + $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
254 | + |
|
255 | + if (is_dir($themeDir)) { |
|
256 | + $files = scandir($themeDir); |
|
257 | + if ($files !== false) { |
|
258 | + foreach ($files as $file) { |
|
259 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
260 | + $available[] = substr($file, 0, -5); |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + $this->availableLanguages[$key] = $available; |
|
268 | + return $available; |
|
269 | + } |
|
270 | + |
|
271 | + public function findAvailableLocales() |
|
272 | + { |
|
273 | + $localeData = file_get_contents(__DIR__ . '/locales.json'); |
|
274 | + return json_decode($localeData, true); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @param string|null $app App id or null for core |
|
279 | + * @param string $lang |
|
280 | + * @return bool |
|
281 | + */ |
|
282 | + public function languageExists($app, $lang) { |
|
283 | + if ($lang === 'en') {//english is always available |
|
284 | + return true; |
|
285 | + } |
|
286 | + |
|
287 | + $languages = $this->findAvailableLanguages($app); |
|
288 | + return array_search($lang, $languages) !== false; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param string $locale |
|
293 | + * @return bool |
|
294 | + */ |
|
295 | + public function localeExists($locale) { |
|
296 | + if ($locale === 'en') { //english is always available |
|
297 | + return true; |
|
298 | + } |
|
299 | + |
|
300 | + $locales = $this->findAvailableLocales(); |
|
301 | + |
|
302 | + $userLocale = array_filter($locales, function($value) use ($locale) { |
|
303 | + return $locale === $value['code']; |
|
304 | + }); |
|
305 | + |
|
306 | + return !empty($userLocale); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * @param string|null $app |
|
311 | + * @return string |
|
312 | + * @throws LanguageNotFoundException |
|
313 | + */ |
|
314 | + private function getLanguageFromRequest($app) { |
|
315 | + $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
316 | + if ($header) { |
|
317 | + $available = $this->findAvailableLanguages($app); |
|
318 | + |
|
319 | + // E.g. make sure that 'de' is before 'de_DE'. |
|
320 | + sort($available); |
|
321 | + |
|
322 | + $preferences = preg_split('/,\s*/', strtolower($header)); |
|
323 | + foreach ($preferences as $preference) { |
|
324 | + list($preferred_language) = explode(';', $preference); |
|
325 | + $preferred_language = str_replace('-', '_', $preferred_language); |
|
326 | + |
|
327 | + foreach ($available as $available_language) { |
|
328 | + if ($preferred_language === strtolower($available_language)) { |
|
329 | + return $available_language; |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + // Fallback from de_De to de |
|
334 | + foreach ($available as $available_language) { |
|
335 | + if (substr($preferred_language, 0, 2) === $available_language) { |
|
336 | + return $available_language; |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + throw new LanguageNotFoundException(); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Checks if $sub is a subdirectory of $parent |
|
347 | + * |
|
348 | + * @param string $sub |
|
349 | + * @param string $parent |
|
350 | + * @return bool |
|
351 | + */ |
|
352 | + private function isSubDirectory($sub, $parent) { |
|
353 | + // Check whether $sub contains no ".." |
|
354 | + if(strpos($sub, '..') !== false) { |
|
355 | + return false; |
|
356 | + } |
|
357 | + |
|
358 | + // Check whether $sub is a subdirectory of $parent |
|
359 | + if (strpos($sub, $parent) === 0) { |
|
360 | + return true; |
|
361 | + } |
|
362 | + |
|
363 | + return false; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a list of language files that should be loaded |
|
368 | + * |
|
369 | + * @param string $app |
|
370 | + * @param string $lang |
|
371 | + * @return string[] |
|
372 | + */ |
|
373 | + // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
374 | + // FIXME This is also the reason, why it is not in the public interface |
|
375 | + public function getL10nFilesForApp($app, $lang) { |
|
376 | + $languageFiles = []; |
|
377 | + |
|
378 | + $i18nDir = $this->findL10nDir($app); |
|
379 | + $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
380 | + |
|
381 | + if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
382 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
383 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
384 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
385 | + ) |
|
386 | + && file_exists($transFile)) { |
|
387 | + // load the translations file |
|
388 | + $languageFiles[] = $transFile; |
|
389 | + } |
|
390 | + |
|
391 | + // merge with translations from theme |
|
392 | + $theme = $this->config->getSystemValue('theme'); |
|
393 | + if (!empty($theme)) { |
|
394 | + $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
395 | + if (file_exists($transFile)) { |
|
396 | + $languageFiles[] = $transFile; |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + return $languageFiles; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * find the l10n directory |
|
405 | + * |
|
406 | + * @param string $app App id or empty string for core |
|
407 | + * @return string directory |
|
408 | + */ |
|
409 | + protected function findL10nDir($app = null) { |
|
410 | + if (in_array($app, ['core', 'lib', 'settings'])) { |
|
411 | + if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
412 | + return $this->serverRoot . '/' . $app . '/l10n/'; |
|
413 | + } |
|
414 | + } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
415 | + // Check if the app is in the app folder |
|
416 | + return \OC_App::getAppPath($app) . '/l10n/'; |
|
417 | + } |
|
418 | + return $this->serverRoot . '/core/l10n/'; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Creates a function from the plural string |
|
424 | + * |
|
425 | + * Parts of the code is copied from Habari: |
|
426 | + * https://github.com/habari/system/blob/master/classes/locale.php |
|
427 | + * @param string $string |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function createPluralFunction($string) { |
|
431 | + if (isset($this->pluralFunctions[$string])) { |
|
432 | + return $this->pluralFunctions[$string]; |
|
433 | + } |
|
434 | + |
|
435 | + if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
436 | + // sanitize |
|
437 | + $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
438 | + $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
439 | + |
|
440 | + $body = str_replace( |
|
441 | + array( 'plural', 'n', '$n$plurals', ), |
|
442 | + array( '$plural', '$n', '$nplurals', ), |
|
443 | + 'nplurals='. $nplurals . '; plural=' . $plural |
|
444 | + ); |
|
445 | + |
|
446 | + // add parents |
|
447 | + // important since PHP's ternary evaluates from left to right |
|
448 | + $body .= ';'; |
|
449 | + $res = ''; |
|
450 | + $p = 0; |
|
451 | + for($i = 0; $i < strlen($body); $i++) { |
|
452 | + $ch = $body[$i]; |
|
453 | + switch ( $ch ) { |
|
454 | + case '?': |
|
455 | + $res .= ' ? ('; |
|
456 | + $p++; |
|
457 | + break; |
|
458 | + case ':': |
|
459 | + $res .= ') : ('; |
|
460 | + break; |
|
461 | + case ';': |
|
462 | + $res .= str_repeat( ')', $p ) . ';'; |
|
463 | + $p = 0; |
|
464 | + break; |
|
465 | + default: |
|
466 | + $res .= $ch; |
|
467 | + } |
|
468 | + } |
|
469 | + |
|
470 | + $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
471 | + $function = create_function('$n', $body); |
|
472 | + $this->pluralFunctions[$string] = $function; |
|
473 | + return $function; |
|
474 | + } else { |
|
475 | + // default: one plural form for all cases but n==1 (english) |
|
476 | + $function = create_function( |
|
477 | + '$n', |
|
478 | + '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
479 | + ); |
|
480 | + $this->pluralFunctions[$string] = $function; |
|
481 | + return $function; |
|
482 | + } |
|
483 | + } |
|
484 | 484 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @link https://github.com/owncloud/core/issues/21955 |
149 | 149 | */ |
150 | - if($this->config->getSystemValue('installed', false)) { |
|
151 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
152 | - if(!is_null($userId)) { |
|
150 | + if ($this->config->getSystemValue('installed', false)) { |
|
151 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
152 | + if (!is_null($userId)) { |
|
153 | 153 | $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
154 | 154 | } else { |
155 | 155 | $userLang = null; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | public function findLocale($lang = null) |
189 | 189 | { |
190 | 190 | if ($this->config->getSystemValue('installed', false)) { |
191 | - $userId = null !== $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; |
|
191 | + $userId = null !== $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; |
|
192 | 192 | $userLocale = null; |
193 | 193 | if (null !== $userId) { |
194 | 194 | $userLocale = $this->config->getUserValue($userId, 'core', 'locale', null); |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | // merge with translations from theme |
251 | 251 | $theme = $this->config->getSystemValue('theme'); |
252 | 252 | if (!empty($theme)) { |
253 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
253 | + $themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot)); |
|
254 | 254 | |
255 | 255 | if (is_dir($themeDir)) { |
256 | 256 | $files = scandir($themeDir); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | |
271 | 271 | public function findAvailableLocales() |
272 | 272 | { |
273 | - $localeData = file_get_contents(__DIR__ . '/locales.json'); |
|
273 | + $localeData = file_get_contents(__DIR__.'/locales.json'); |
|
274 | 274 | return json_decode($localeData, true); |
275 | 275 | } |
276 | 276 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | */ |
352 | 352 | private function isSubDirectory($sub, $parent) { |
353 | 353 | // Check whether $sub contains no ".." |
354 | - if(strpos($sub, '..') !== false) { |
|
354 | + if (strpos($sub, '..') !== false) { |
|
355 | 355 | return false; |
356 | 356 | } |
357 | 357 | |
@@ -376,12 +376,12 @@ discard block |
||
376 | 376 | $languageFiles = []; |
377 | 377 | |
378 | 378 | $i18nDir = $this->findL10nDir($app); |
379 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
379 | + $transFile = strip_tags($i18nDir).strip_tags($lang).'.json'; |
|
380 | 380 | |
381 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
382 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
383 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
384 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
381 | + if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/') |
|
382 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/') |
|
383 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/') |
|
384 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/') |
|
385 | 385 | ) |
386 | 386 | && file_exists($transFile)) { |
387 | 387 | // load the translations file |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | // merge with translations from theme |
392 | 392 | $theme = $this->config->getSystemValue('theme'); |
393 | 393 | if (!empty($theme)) { |
394 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
394 | + $transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot)); |
|
395 | 395 | if (file_exists($transFile)) { |
396 | 396 | $languageFiles[] = $transFile; |
397 | 397 | } |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | */ |
409 | 409 | protected function findL10nDir($app = null) { |
410 | 410 | if (in_array($app, ['core', 'lib', 'settings'])) { |
411 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
412 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
411 | + if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) { |
|
412 | + return $this->serverRoot.'/'.$app.'/l10n/'; |
|
413 | 413 | } |
414 | 414 | } else if ($app && \OC_App::getAppPath($app) !== false) { |
415 | 415 | // Check if the app is in the app folder |
416 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
416 | + return \OC_App::getAppPath($app).'/l10n/'; |
|
417 | 417 | } |
418 | - return $this->serverRoot . '/core/l10n/'; |
|
418 | + return $this->serverRoot.'/core/l10n/'; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | return $this->pluralFunctions[$string]; |
433 | 433 | } |
434 | 434 | |
435 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
435 | + if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
436 | 436 | // sanitize |
437 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
438 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
437 | + $nplurals = preg_replace('/[^0-9]/', '', $matches[1]); |
|
438 | + $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); |
|
439 | 439 | |
440 | 440 | $body = str_replace( |
441 | - array( 'plural', 'n', '$n$plurals', ), |
|
442 | - array( '$plural', '$n', '$nplurals', ), |
|
443 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
441 | + array('plural', 'n', '$n$plurals',), |
|
442 | + array('$plural', '$n', '$nplurals',), |
|
443 | + 'nplurals='.$nplurals.'; plural='.$plural |
|
444 | 444 | ); |
445 | 445 | |
446 | 446 | // add parents |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | $body .= ';'; |
449 | 449 | $res = ''; |
450 | 450 | $p = 0; |
451 | - for($i = 0; $i < strlen($body); $i++) { |
|
451 | + for ($i = 0; $i < strlen($body); $i++) { |
|
452 | 452 | $ch = $body[$i]; |
453 | - switch ( $ch ) { |
|
453 | + switch ($ch) { |
|
454 | 454 | case '?': |
455 | 455 | $res .= ' ? ('; |
456 | 456 | $p++; |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $res .= ') : ('; |
460 | 460 | break; |
461 | 461 | case ';': |
462 | - $res .= str_repeat( ')', $p ) . ';'; |
|
462 | + $res .= str_repeat(')', $p).';'; |
|
463 | 463 | $p = 0; |
464 | 464 | break; |
465 | 465 | default: |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
470 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
470 | + $body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
471 | 471 | $function = create_function('$n', $body); |
472 | 472 | $this->pluralFunctions[$string] = $function; |
473 | 473 | return $function; |
@@ -53,44 +53,44 @@ discard block |
||
53 | 53 | * @param string $renderAs |
54 | 54 | * @param string $appId application id |
55 | 55 | */ |
56 | - public function __construct( $renderAs, $appId = '' ) { |
|
56 | + public function __construct($renderAs, $appId = '') { |
|
57 | 57 | |
58 | 58 | // yes - should be injected .... |
59 | 59 | $this->config = \OC::$server->getConfig(); |
60 | 60 | |
61 | 61 | |
62 | 62 | // Decide which page we show |
63 | - if($renderAs == 'user') { |
|
64 | - parent::__construct( 'core', 'layout.user' ); |
|
65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
63 | + if ($renderAs == 'user') { |
|
64 | + parent::__construct('core', 'layout.user'); |
|
65 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
66 | 66 | $this->assign('bodyid', 'body-settings'); |
67 | - }else{ |
|
67 | + } else { |
|
68 | 68 | $this->assign('bodyid', 'body-user'); |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Code integrity notification |
72 | 72 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
73 | + if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | 74 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
75 | 75 | } |
76 | 76 | |
77 | 77 | // Add navigation entry |
78 | - $this->assign( 'application', ''); |
|
79 | - $this->assign( 'appid', $appId ); |
|
78 | + $this->assign('application', ''); |
|
79 | + $this->assign('appid', $appId); |
|
80 | 80 | $navigation = \OC_App::getNavigation(); |
81 | - $this->assign( 'navigation', $navigation); |
|
81 | + $this->assign('navigation', $navigation); |
|
82 | 82 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
83 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
84 | - foreach($navigation as $entry) { |
|
83 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
84 | + foreach ($navigation as $entry) { |
|
85 | 85 | if ($entry['active']) { |
86 | - $this->assign( 'application', $entry['name'] ); |
|
86 | + $this->assign('application', $entry['name']); |
|
87 | 87 | break; |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach($settingsNavigation as $entry) { |
|
91 | + foreach ($settingsNavigation as $entry) { |
|
92 | 92 | if ($entry['active']) { |
93 | - $this->assign( 'application', $entry['name'] ); |
|
93 | + $this->assign('application', $entry['name']); |
|
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
120 | 120 | $this->assign('locale', \OC::$server->getL10NFactory()->findLocale()); |
121 | 121 | |
122 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
122 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
123 | 123 | if (empty(self::$versionHash)) { |
124 | 124 | $v = \OC_App::getAppVersions(); |
125 | 125 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
151 | 151 | } |
152 | 152 | } |
153 | - foreach($jsFiles as $info) { |
|
153 | + foreach ($jsFiles as $info) { |
|
154 | 154 | $web = $info[1]; |
155 | 155 | $file = $info[2]; |
156 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
156 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | try { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | // Do not initialise scss appdata until we have a fully installed instance |
166 | 166 | // Do not load scss for update, errors, installation or login page |
167 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
167 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
168 | 168 | && !\OCP\Util::needUpgrade() |
169 | 169 | && $pathInfo !== '' |
170 | 170 | && !preg_match('/^\/login/', $pathInfo)) { |
@@ -179,27 +179,27 @@ discard block |
||
179 | 179 | $this->assign('cssfiles', array()); |
180 | 180 | $this->assign('printcssfiles', []); |
181 | 181 | $this->assign('versionHash', self::$versionHash); |
182 | - foreach($cssFiles as $info) { |
|
182 | + foreach ($cssFiles as $info) { |
|
183 | 183 | $web = $info[1]; |
184 | 184 | $file = $info[2]; |
185 | 185 | |
186 | 186 | if (substr($file, -strlen('print.css')) === 'print.css') { |
187 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
187 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
188 | 188 | } else { |
189 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
189 | + $this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | 194 | protected function getVersionHashSuffix() { |
195 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
195 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
196 | 196 | // allows chrome workspace mapping in debug mode |
197 | 197 | return ""; |
198 | 198 | } |
199 | 199 | if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
200 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | + return '?v='.self::$versionHash.'-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
201 | 201 | } |
202 | - return '?v=' . self::$versionHash; |
|
202 | + return '?v='.self::$versionHash; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // Read the selected theme from the config file |
211 | 211 | $theme = \OC_Util::getTheme(); |
212 | 212 | |
213 | - if($compileScss) { |
|
213 | + if ($compileScss) { |
|
214 | 214 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
215 | 215 | } else { |
216 | 216 | $SCSSCacher = null; |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | $locator = new \OC\Template\CSSResourceLocator( |
220 | 220 | \OC::$server->getLogger(), |
221 | 221 | $theme, |
222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
223 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
222 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
223 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
224 | 224 | $SCSSCacher |
225 | 225 | ); |
226 | 226 | $locator->find($styles); |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | $locator = new \OC\Template\JSResourceLocator( |
239 | 239 | \OC::$server->getLogger(), |
240 | 240 | $theme, |
241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
242 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
241 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
242 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
243 | 243 | new JSCombiner( |
244 | 244 | \OC::$server->getAppDataDir('js'), |
245 | 245 | \OC::$server->getURLGenerator(), |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public static function convertToRelativePath($filePath) { |
261 | 261 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
262 | - if(count($relativePath) !== 2) { |
|
262 | + if (count($relativePath) !== 2) { |
|
263 | 263 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
264 | 264 | } |
265 | 265 |
@@ -42,228 +42,228 @@ |
||
42 | 42 | |
43 | 43 | class TemplateLayout extends \OC_Template { |
44 | 44 | |
45 | - private static $versionHash = ''; |
|
45 | + private static $versionHash = ''; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var \OCP\IConfig |
|
49 | - */ |
|
50 | - private $config; |
|
47 | + /** |
|
48 | + * @var \OCP\IConfig |
|
49 | + */ |
|
50 | + private $config; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $renderAs |
|
54 | - * @param string $appId application id |
|
55 | - */ |
|
56 | - public function __construct( $renderAs, $appId = '' ) { |
|
52 | + /** |
|
53 | + * @param string $renderAs |
|
54 | + * @param string $appId application id |
|
55 | + */ |
|
56 | + public function __construct( $renderAs, $appId = '' ) { |
|
57 | 57 | |
58 | - // yes - should be injected .... |
|
59 | - $this->config = \OC::$server->getConfig(); |
|
58 | + // yes - should be injected .... |
|
59 | + $this->config = \OC::$server->getConfig(); |
|
60 | 60 | |
61 | 61 | |
62 | - // Decide which page we show |
|
63 | - if($renderAs == 'user') { |
|
64 | - parent::__construct( 'core', 'layout.user' ); |
|
65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
66 | - $this->assign('bodyid', 'body-settings'); |
|
67 | - }else{ |
|
68 | - $this->assign('bodyid', 'body-user'); |
|
69 | - } |
|
62 | + // Decide which page we show |
|
63 | + if($renderAs == 'user') { |
|
64 | + parent::__construct( 'core', 'layout.user' ); |
|
65 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
66 | + $this->assign('bodyid', 'body-settings'); |
|
67 | + }else{ |
|
68 | + $this->assign('bodyid', 'body-user'); |
|
69 | + } |
|
70 | 70 | |
71 | - // Code integrity notification |
|
72 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
75 | - } |
|
71 | + // Code integrity notification |
|
72 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
73 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
75 | + } |
|
76 | 76 | |
77 | - // Add navigation entry |
|
78 | - $this->assign( 'application', ''); |
|
79 | - $this->assign( 'appid', $appId ); |
|
80 | - $navigation = \OC_App::getNavigation(); |
|
81 | - $this->assign( 'navigation', $navigation); |
|
82 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
83 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
84 | - foreach($navigation as $entry) { |
|
85 | - if ($entry['active']) { |
|
86 | - $this->assign( 'application', $entry['name'] ); |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
77 | + // Add navigation entry |
|
78 | + $this->assign( 'application', ''); |
|
79 | + $this->assign( 'appid', $appId ); |
|
80 | + $navigation = \OC_App::getNavigation(); |
|
81 | + $this->assign( 'navigation', $navigation); |
|
82 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
83 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
84 | + foreach($navigation as $entry) { |
|
85 | + if ($entry['active']) { |
|
86 | + $this->assign( 'application', $entry['name'] ); |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - foreach($settingsNavigation as $entry) { |
|
92 | - if ($entry['active']) { |
|
93 | - $this->assign( 'application', $entry['name'] ); |
|
94 | - break; |
|
95 | - } |
|
96 | - } |
|
97 | - $userDisplayName = \OC_User::getDisplayName(); |
|
98 | - $this->assign('user_displayname', $userDisplayName); |
|
99 | - $this->assign('user_uid', \OC_User::getUser()); |
|
91 | + foreach($settingsNavigation as $entry) { |
|
92 | + if ($entry['active']) { |
|
93 | + $this->assign( 'application', $entry['name'] ); |
|
94 | + break; |
|
95 | + } |
|
96 | + } |
|
97 | + $userDisplayName = \OC_User::getDisplayName(); |
|
98 | + $this->assign('user_displayname', $userDisplayName); |
|
99 | + $this->assign('user_uid', \OC_User::getUser()); |
|
100 | 100 | |
101 | - if (\OC_User::getUser() === false) { |
|
102 | - $this->assign('userAvatarSet', false); |
|
103 | - } else { |
|
104 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
105 | - $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
106 | - } |
|
101 | + if (\OC_User::getUser() === false) { |
|
102 | + $this->assign('userAvatarSet', false); |
|
103 | + } else { |
|
104 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
105 | + $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
106 | + } |
|
107 | 107 | |
108 | - } else if ($renderAs == 'error') { |
|
109 | - parent::__construct('core', 'layout.guest', '', false); |
|
110 | - $this->assign('bodyid', 'body-login'); |
|
111 | - } else if ($renderAs == 'guest') { |
|
112 | - parent::__construct('core', 'layout.guest'); |
|
113 | - $this->assign('bodyid', 'body-login'); |
|
114 | - } else { |
|
115 | - parent::__construct('core', 'layout.base'); |
|
108 | + } else if ($renderAs == 'error') { |
|
109 | + parent::__construct('core', 'layout.guest', '', false); |
|
110 | + $this->assign('bodyid', 'body-login'); |
|
111 | + } else if ($renderAs == 'guest') { |
|
112 | + parent::__construct('core', 'layout.guest'); |
|
113 | + $this->assign('bodyid', 'body-login'); |
|
114 | + } else { |
|
115 | + parent::__construct('core', 'layout.base'); |
|
116 | 116 | |
117 | - } |
|
118 | - // Send the language and the locale to our layouts |
|
119 | - $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
120 | - $this->assign('locale', \OC::$server->getL10NFactory()->findLocale()); |
|
117 | + } |
|
118 | + // Send the language and the locale to our layouts |
|
119 | + $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
120 | + $this->assign('locale', \OC::$server->getL10NFactory()->findLocale()); |
|
121 | 121 | |
122 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
123 | - if (empty(self::$versionHash)) { |
|
124 | - $v = \OC_App::getAppVersions(); |
|
125 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
126 | - self::$versionHash = md5(implode(',', $v)); |
|
127 | - } |
|
128 | - } else { |
|
129 | - self::$versionHash = md5('not installed'); |
|
130 | - } |
|
122 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
123 | + if (empty(self::$versionHash)) { |
|
124 | + $v = \OC_App::getAppVersions(); |
|
125 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
126 | + self::$versionHash = md5(implode(',', $v)); |
|
127 | + } |
|
128 | + } else { |
|
129 | + self::$versionHash = md5('not installed'); |
|
130 | + } |
|
131 | 131 | |
132 | - // Add the js files |
|
133 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
134 | - $this->assign('jsfiles', array()); |
|
135 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
136 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
137 | - $jsConfigHelper = new JSConfigHelper( |
|
138 | - \OC::$server->getL10N('core'), |
|
139 | - \OC::$server->query(Defaults::class), |
|
140 | - \OC::$server->getAppManager(), |
|
141 | - \OC::$server->getSession(), |
|
142 | - \OC::$server->getUserSession()->getUser(), |
|
143 | - \OC::$server->getConfig(), |
|
144 | - \OC::$server->getGroupManager(), |
|
145 | - \OC::$server->getIniWrapper(), |
|
146 | - \OC::$server->getURLGenerator() |
|
147 | - ); |
|
148 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
149 | - } else { |
|
150 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
151 | - } |
|
152 | - } |
|
153 | - foreach($jsFiles as $info) { |
|
154 | - $web = $info[1]; |
|
155 | - $file = $info[2]; |
|
156 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
157 | - } |
|
132 | + // Add the js files |
|
133 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
134 | + $this->assign('jsfiles', array()); |
|
135 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
136 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
137 | + $jsConfigHelper = new JSConfigHelper( |
|
138 | + \OC::$server->getL10N('core'), |
|
139 | + \OC::$server->query(Defaults::class), |
|
140 | + \OC::$server->getAppManager(), |
|
141 | + \OC::$server->getSession(), |
|
142 | + \OC::$server->getUserSession()->getUser(), |
|
143 | + \OC::$server->getConfig(), |
|
144 | + \OC::$server->getGroupManager(), |
|
145 | + \OC::$server->getIniWrapper(), |
|
146 | + \OC::$server->getURLGenerator() |
|
147 | + ); |
|
148 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
149 | + } else { |
|
150 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
151 | + } |
|
152 | + } |
|
153 | + foreach($jsFiles as $info) { |
|
154 | + $web = $info[1]; |
|
155 | + $file = $info[2]; |
|
156 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
157 | + } |
|
158 | 158 | |
159 | - try { |
|
160 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
161 | - } catch (\Exception $e) { |
|
162 | - $pathInfo = ''; |
|
163 | - } |
|
159 | + try { |
|
160 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
161 | + } catch (\Exception $e) { |
|
162 | + $pathInfo = ''; |
|
163 | + } |
|
164 | 164 | |
165 | - // Do not initialise scss appdata until we have a fully installed instance |
|
166 | - // Do not load scss for update, errors, installation or login page |
|
167 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
168 | - && !\OCP\Util::needUpgrade() |
|
169 | - && $pathInfo !== '' |
|
170 | - && !preg_match('/^\/login/', $pathInfo)) { |
|
171 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
172 | - } else { |
|
173 | - // If we ignore the scss compiler, |
|
174 | - // we need to load the guest css fallback |
|
175 | - \OC_Util::addStyle('guest'); |
|
176 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
177 | - } |
|
165 | + // Do not initialise scss appdata until we have a fully installed instance |
|
166 | + // Do not load scss for update, errors, installation or login page |
|
167 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
168 | + && !\OCP\Util::needUpgrade() |
|
169 | + && $pathInfo !== '' |
|
170 | + && !preg_match('/^\/login/', $pathInfo)) { |
|
171 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
172 | + } else { |
|
173 | + // If we ignore the scss compiler, |
|
174 | + // we need to load the guest css fallback |
|
175 | + \OC_Util::addStyle('guest'); |
|
176 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
177 | + } |
|
178 | 178 | |
179 | - $this->assign('cssfiles', array()); |
|
180 | - $this->assign('printcssfiles', []); |
|
181 | - $this->assign('versionHash', self::$versionHash); |
|
182 | - foreach($cssFiles as $info) { |
|
183 | - $web = $info[1]; |
|
184 | - $file = $info[2]; |
|
179 | + $this->assign('cssfiles', array()); |
|
180 | + $this->assign('printcssfiles', []); |
|
181 | + $this->assign('versionHash', self::$versionHash); |
|
182 | + foreach($cssFiles as $info) { |
|
183 | + $web = $info[1]; |
|
184 | + $file = $info[2]; |
|
185 | 185 | |
186 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
187 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
188 | - } else { |
|
189 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
186 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
187 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
188 | + } else { |
|
189 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | - protected function getVersionHashSuffix() { |
|
195 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
196 | - // allows chrome workspace mapping in debug mode |
|
197 | - return ""; |
|
198 | - } |
|
199 | - if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
200 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
201 | - } |
|
202 | - return '?v=' . self::$versionHash; |
|
203 | - } |
|
194 | + protected function getVersionHashSuffix() { |
|
195 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
196 | + // allows chrome workspace mapping in debug mode |
|
197 | + return ""; |
|
198 | + } |
|
199 | + if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
200 | + return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
201 | + } |
|
202 | + return '?v=' . self::$versionHash; |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * @param array $styles |
|
207 | - * @return array |
|
208 | - */ |
|
209 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
210 | - // Read the selected theme from the config file |
|
211 | - $theme = \OC_Util::getTheme(); |
|
205 | + /** |
|
206 | + * @param array $styles |
|
207 | + * @return array |
|
208 | + */ |
|
209 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
210 | + // Read the selected theme from the config file |
|
211 | + $theme = \OC_Util::getTheme(); |
|
212 | 212 | |
213 | - if($compileScss) { |
|
214 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
215 | - } else { |
|
216 | - $SCSSCacher = null; |
|
217 | - } |
|
213 | + if($compileScss) { |
|
214 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
215 | + } else { |
|
216 | + $SCSSCacher = null; |
|
217 | + } |
|
218 | 218 | |
219 | - $locator = new \OC\Template\CSSResourceLocator( |
|
220 | - \OC::$server->getLogger(), |
|
221 | - $theme, |
|
222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
223 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
224 | - $SCSSCacher |
|
225 | - ); |
|
226 | - $locator->find($styles); |
|
227 | - return $locator->getResources(); |
|
228 | - } |
|
219 | + $locator = new \OC\Template\CSSResourceLocator( |
|
220 | + \OC::$server->getLogger(), |
|
221 | + $theme, |
|
222 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
223 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
224 | + $SCSSCacher |
|
225 | + ); |
|
226 | + $locator->find($styles); |
|
227 | + return $locator->getResources(); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @param array $scripts |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - static public function findJavascriptFiles($scripts) { |
|
235 | - // Read the selected theme from the config file |
|
236 | - $theme = \OC_Util::getTheme(); |
|
230 | + /** |
|
231 | + * @param array $scripts |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + static public function findJavascriptFiles($scripts) { |
|
235 | + // Read the selected theme from the config file |
|
236 | + $theme = \OC_Util::getTheme(); |
|
237 | 237 | |
238 | - $locator = new \OC\Template\JSResourceLocator( |
|
239 | - \OC::$server->getLogger(), |
|
240 | - $theme, |
|
241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
242 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
243 | - new JSCombiner( |
|
244 | - \OC::$server->getAppDataDir('js'), |
|
245 | - \OC::$server->getURLGenerator(), |
|
246 | - \OC::$server->getMemCacheFactory()->create('JS'), |
|
247 | - \OC::$server->getSystemConfig(), |
|
248 | - \OC::$server->getLogger() |
|
249 | - ) |
|
250 | - ); |
|
251 | - $locator->find($scripts); |
|
252 | - return $locator->getResources(); |
|
253 | - } |
|
238 | + $locator = new \OC\Template\JSResourceLocator( |
|
239 | + \OC::$server->getLogger(), |
|
240 | + $theme, |
|
241 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
242 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
243 | + new JSCombiner( |
|
244 | + \OC::$server->getAppDataDir('js'), |
|
245 | + \OC::$server->getURLGenerator(), |
|
246 | + \OC::$server->getMemCacheFactory()->create('JS'), |
|
247 | + \OC::$server->getSystemConfig(), |
|
248 | + \OC::$server->getLogger() |
|
249 | + ) |
|
250 | + ); |
|
251 | + $locator->find($scripts); |
|
252 | + return $locator->getResources(); |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
257 | - * @param string $filePath Absolute path |
|
258 | - * @return string Relative path |
|
259 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
260 | - */ |
|
261 | - public static function convertToRelativePath($filePath) { |
|
262 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
263 | - if(count($relativePath) !== 2) { |
|
264 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
265 | - } |
|
255 | + /** |
|
256 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
257 | + * @param string $filePath Absolute path |
|
258 | + * @return string Relative path |
|
259 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
260 | + */ |
|
261 | + public static function convertToRelativePath($filePath) { |
|
262 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
263 | + if(count($relativePath) !== 2) { |
|
264 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
265 | + } |
|
266 | 266 | |
267 | - return $relativePath[1]; |
|
268 | - } |
|
267 | + return $relativePath[1]; |
|
268 | + } |
|
269 | 269 | } |
@@ -25,68 +25,68 @@ |
||
25 | 25 | * @since 8.2.0 |
26 | 26 | */ |
27 | 27 | interface IFactory { |
28 | - /** |
|
29 | - * Get a language instance |
|
30 | - * |
|
31 | - * @param string $app |
|
32 | - * @param string|null $lang |
|
33 | - * @return \OCP\IL10N |
|
34 | - * @since 8.2.0 |
|
35 | - */ |
|
36 | - public function get($app, $lang = null); |
|
28 | + /** |
|
29 | + * Get a language instance |
|
30 | + * |
|
31 | + * @param string $app |
|
32 | + * @param string|null $lang |
|
33 | + * @return \OCP\IL10N |
|
34 | + * @since 8.2.0 |
|
35 | + */ |
|
36 | + public function get($app, $lang = null); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Find the best language |
|
40 | - * |
|
41 | - * @param string|null $app App id or null for core |
|
42 | - * @return string language If nothing works it returns 'en' |
|
43 | - * @since 9.0.0 |
|
44 | - */ |
|
45 | - public function findLanguage($app = null); |
|
38 | + /** |
|
39 | + * Find the best language |
|
40 | + * |
|
41 | + * @param string|null $app App id or null for core |
|
42 | + * @return string language If nothing works it returns 'en' |
|
43 | + * @since 9.0.0 |
|
44 | + */ |
|
45 | + public function findLanguage($app = null); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string|null $lang user language as default locale |
|
49 | - * @return string locale If nothing works it returns 'en_US' |
|
50 | - * @since 13.0.0 |
|
51 | - */ |
|
52 | - public function findLocale($lang = null); |
|
47 | + /** |
|
48 | + * @param string|null $lang user language as default locale |
|
49 | + * @return string locale If nothing works it returns 'en_US' |
|
50 | + * @since 13.0.0 |
|
51 | + */ |
|
52 | + public function findLocale($lang = null); |
|
53 | 53 | |
54 | - /** |
|
55 | - * Find all available languages for an app |
|
56 | - * |
|
57 | - * @param string|null $app App id or null for core |
|
58 | - * @return string[] an array of available languages |
|
59 | - * @since 9.0.0 |
|
60 | - */ |
|
61 | - public function findAvailableLanguages($app = null); |
|
54 | + /** |
|
55 | + * Find all available languages for an app |
|
56 | + * |
|
57 | + * @param string|null $app App id or null for core |
|
58 | + * @return string[] an array of available languages |
|
59 | + * @since 9.0.0 |
|
60 | + */ |
|
61 | + public function findAvailableLanguages($app = null); |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return array an array of available |
|
65 | - * @since 13.0.0 |
|
66 | - */ |
|
67 | - public function findAvailableLocales(); |
|
63 | + /** |
|
64 | + * @return array an array of available |
|
65 | + * @since 13.0.0 |
|
66 | + */ |
|
67 | + public function findAvailableLocales(); |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string|null $app App id or null for core |
|
71 | - * @param string $lang |
|
72 | - * @return bool |
|
73 | - * @since 9.0.0 |
|
74 | - */ |
|
75 | - public function languageExists($app, $lang); |
|
69 | + /** |
|
70 | + * @param string|null $app App id or null for core |
|
71 | + * @param string $lang |
|
72 | + * @return bool |
|
73 | + * @since 9.0.0 |
|
74 | + */ |
|
75 | + public function languageExists($app, $lang); |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $locale |
|
79 | - * @return bool |
|
80 | - * @since 13.0.0 |
|
81 | - */ |
|
82 | - public function localeExists($locale); |
|
77 | + /** |
|
78 | + * @param string $locale |
|
79 | + * @return bool |
|
80 | + * @since 13.0.0 |
|
81 | + */ |
|
82 | + public function localeExists($locale); |
|
83 | 83 | |
84 | - /** |
|
85 | - * Creates a function from the plural string |
|
86 | - * |
|
87 | - * @param string $string |
|
88 | - * @return string Unique function name |
|
89 | - * @since 9.0.0 |
|
90 | - */ |
|
91 | - public function createPluralFunction($string); |
|
84 | + /** |
|
85 | + * Creates a function from the plural string |
|
86 | + * |
|
87 | + * @param string $string |
|
88 | + * @return string Unique function name |
|
89 | + * @since 9.0.0 |
|
90 | + */ |
|
91 | + public function createPluralFunction($string); |
|
92 | 92 | } |
@@ -29,206 +29,206 @@ |
||
29 | 29 | |
30 | 30 | class L10N implements IL10N { |
31 | 31 | |
32 | - /** @var IFactory */ |
|
33 | - protected $factory; |
|
34 | - |
|
35 | - /** @var string App of this object */ |
|
36 | - protected $app; |
|
37 | - |
|
38 | - /** @var string Language of this object */ |
|
39 | - protected $lang; |
|
40 | - |
|
41 | - /** @var string Locale of this object */ |
|
42 | - protected $locale; |
|
43 | - |
|
44 | - /** @var string Plural forms (string) */ |
|
45 | - private $pluralFormString = 'nplurals=2; plural=(n != 1);'; |
|
46 | - |
|
47 | - /** @var string Plural forms (function) */ |
|
48 | - private $pluralFormFunction = null; |
|
49 | - |
|
50 | - /** @var string[] */ |
|
51 | - private $translations = []; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param IFactory $factory |
|
55 | - * @param string $app |
|
56 | - * @param string $lang |
|
57 | - * @param string $locale |
|
58 | - * @param array $files |
|
59 | - */ |
|
60 | - public function __construct(IFactory $factory, $app, $lang, $locale, array $files) { |
|
61 | - $this->factory = $factory; |
|
62 | - $this->app = $app; |
|
63 | - $this->lang = $lang; |
|
64 | - $this->locale = $locale; |
|
65 | - |
|
66 | - $this->translations = []; |
|
67 | - foreach ($files as $languageFile) { |
|
68 | - $this->load($languageFile); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * The code (en, de, ...) of the language that is used for this instance |
|
74 | - * |
|
75 | - * @return string language |
|
76 | - */ |
|
77 | - public function getLanguageCode() { |
|
78 | - return $this->lang; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * The code (en_US, fr_CA, ...) of the locale that is used for this instance |
|
83 | - * |
|
84 | - * @return string locale |
|
85 | - */ |
|
86 | - public function getLocaleCode() { |
|
87 | - return $this->locale; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Translating |
|
92 | - * @param string $text The text we need a translation for |
|
93 | - * @param array $parameters default:array() Parameters for sprintf |
|
94 | - * @return string Translation or the same text |
|
95 | - * |
|
96 | - * Returns the translation. If no translation is found, $text will be |
|
97 | - * returned. |
|
98 | - */ |
|
99 | - public function t($text, $parameters = array()) { |
|
100 | - return (string) new L10NString($this, $text, $parameters); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Translating |
|
105 | - * @param string $text_singular the string to translate for exactly one object |
|
106 | - * @param string $text_plural the string to translate for n objects |
|
107 | - * @param integer $count Number of objects |
|
108 | - * @param array $parameters default:array() Parameters for sprintf |
|
109 | - * @return string Translation or the same text |
|
110 | - * |
|
111 | - * Returns the translation. If no translation is found, $text will be |
|
112 | - * returned. %n will be replaced with the number of objects. |
|
113 | - * |
|
114 | - * The correct plural is determined by the plural_forms-function |
|
115 | - * provided by the po file. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function n($text_singular, $text_plural, $count, $parameters = array()) { |
|
119 | - $identifier = "_${text_singular}_::_${text_plural}_"; |
|
120 | - if (isset($this->translations[$identifier])) { |
|
121 | - return (string) new L10NString($this, $identifier, $parameters, $count); |
|
122 | - } else { |
|
123 | - if ($count === 1) { |
|
124 | - return (string) new L10NString($this, $text_singular, $parameters, $count); |
|
125 | - } else { |
|
126 | - return (string) new L10NString($this, $text_plural, $parameters, $count); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Localization |
|
133 | - * @param string $type Type of localization |
|
134 | - * @param \DateTime|int|string $data parameters for this localization |
|
135 | - * @param array $options |
|
136 | - * @return string|int|false |
|
137 | - * |
|
138 | - * Returns the localized data. |
|
139 | - * |
|
140 | - * Implemented types: |
|
141 | - * - date |
|
142 | - * - Creates a date |
|
143 | - * - params: timestamp (int/string) |
|
144 | - * - datetime |
|
145 | - * - Creates date and time |
|
146 | - * - params: timestamp (int/string) |
|
147 | - * - time |
|
148 | - * - Creates a time |
|
149 | - * - params: timestamp (int/string) |
|
150 | - * - firstday: Returns the first day of the week (0 sunday - 6 saturday) |
|
151 | - * - jsdate: Returns the short JS date format |
|
152 | - */ |
|
153 | - public function l($type, $data = null, $options = array()) { |
|
154 | - if (null === $this->locale) { |
|
155 | - // Use the language of the instance |
|
156 | - $this->locale = $this->getLanguageCode(); |
|
157 | - } |
|
158 | - if ($this->locale === 'sr@latin') { |
|
159 | - $this->locale = 'sr_latn'; |
|
160 | - } |
|
161 | - |
|
162 | - if ($type === 'firstday') { |
|
163 | - return (int) Calendar::getFirstWeekday($this->locale); |
|
164 | - } |
|
165 | - if ($type === 'jsdate') { |
|
166 | - return (string) Calendar::getDateFormat('short', $this->locale); |
|
167 | - } |
|
168 | - |
|
169 | - $value = new \DateTime(); |
|
170 | - if ($data instanceof \DateTime) { |
|
171 | - $value = $data; |
|
172 | - } else if (is_string($data) && !is_numeric($data)) { |
|
173 | - $data = strtotime($data); |
|
174 | - $value->setTimestamp($data); |
|
175 | - } else if ($data !== null) { |
|
176 | - $value->setTimestamp($data); |
|
177 | - } |
|
178 | - |
|
179 | - $options = array_merge(array('width' => 'long'), $options); |
|
180 | - $width = $options['width']; |
|
181 | - switch ($type) { |
|
182 | - case 'date': |
|
183 | - return (string) Calendar::formatDate($value, $width, $this->locale); |
|
184 | - case 'datetime': |
|
185 | - return (string) Calendar::formatDatetime($value, $width, $this->locale); |
|
186 | - case 'time': |
|
187 | - return (string) Calendar::formatTime($value, $width, $this->locale); |
|
188 | - default: |
|
189 | - return false; |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Returns an associative array with all translations |
|
195 | - * |
|
196 | - * Called by \OC_L10N_String |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function getTranslations() { |
|
200 | - return $this->translations; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Returnsed function accepts the argument $n |
|
205 | - * |
|
206 | - * Called by \OC_L10N_String |
|
207 | - * @return string the plural form function |
|
208 | - */ |
|
209 | - public function getPluralFormFunction() { |
|
210 | - if (is_null($this->pluralFormFunction)) { |
|
211 | - $this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString); |
|
212 | - } |
|
213 | - return $this->pluralFormFunction; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param $translationFile |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - protected function load($translationFile) { |
|
221 | - $json = json_decode(file_get_contents($translationFile), true); |
|
222 | - if (!is_array($json)) { |
|
223 | - $jsonError = json_last_error(); |
|
224 | - \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); |
|
225 | - return false; |
|
226 | - } |
|
227 | - |
|
228 | - if (!empty($json['pluralForm'])) { |
|
229 | - $this->pluralFormString = $json['pluralForm']; |
|
230 | - } |
|
231 | - $this->translations = array_merge($this->translations, $json['translations']); |
|
232 | - return true; |
|
233 | - } |
|
32 | + /** @var IFactory */ |
|
33 | + protected $factory; |
|
34 | + |
|
35 | + /** @var string App of this object */ |
|
36 | + protected $app; |
|
37 | + |
|
38 | + /** @var string Language of this object */ |
|
39 | + protected $lang; |
|
40 | + |
|
41 | + /** @var string Locale of this object */ |
|
42 | + protected $locale; |
|
43 | + |
|
44 | + /** @var string Plural forms (string) */ |
|
45 | + private $pluralFormString = 'nplurals=2; plural=(n != 1);'; |
|
46 | + |
|
47 | + /** @var string Plural forms (function) */ |
|
48 | + private $pluralFormFunction = null; |
|
49 | + |
|
50 | + /** @var string[] */ |
|
51 | + private $translations = []; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param IFactory $factory |
|
55 | + * @param string $app |
|
56 | + * @param string $lang |
|
57 | + * @param string $locale |
|
58 | + * @param array $files |
|
59 | + */ |
|
60 | + public function __construct(IFactory $factory, $app, $lang, $locale, array $files) { |
|
61 | + $this->factory = $factory; |
|
62 | + $this->app = $app; |
|
63 | + $this->lang = $lang; |
|
64 | + $this->locale = $locale; |
|
65 | + |
|
66 | + $this->translations = []; |
|
67 | + foreach ($files as $languageFile) { |
|
68 | + $this->load($languageFile); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * The code (en, de, ...) of the language that is used for this instance |
|
74 | + * |
|
75 | + * @return string language |
|
76 | + */ |
|
77 | + public function getLanguageCode() { |
|
78 | + return $this->lang; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * The code (en_US, fr_CA, ...) of the locale that is used for this instance |
|
83 | + * |
|
84 | + * @return string locale |
|
85 | + */ |
|
86 | + public function getLocaleCode() { |
|
87 | + return $this->locale; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Translating |
|
92 | + * @param string $text The text we need a translation for |
|
93 | + * @param array $parameters default:array() Parameters for sprintf |
|
94 | + * @return string Translation or the same text |
|
95 | + * |
|
96 | + * Returns the translation. If no translation is found, $text will be |
|
97 | + * returned. |
|
98 | + */ |
|
99 | + public function t($text, $parameters = array()) { |
|
100 | + return (string) new L10NString($this, $text, $parameters); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Translating |
|
105 | + * @param string $text_singular the string to translate for exactly one object |
|
106 | + * @param string $text_plural the string to translate for n objects |
|
107 | + * @param integer $count Number of objects |
|
108 | + * @param array $parameters default:array() Parameters for sprintf |
|
109 | + * @return string Translation or the same text |
|
110 | + * |
|
111 | + * Returns the translation. If no translation is found, $text will be |
|
112 | + * returned. %n will be replaced with the number of objects. |
|
113 | + * |
|
114 | + * The correct plural is determined by the plural_forms-function |
|
115 | + * provided by the po file. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function n($text_singular, $text_plural, $count, $parameters = array()) { |
|
119 | + $identifier = "_${text_singular}_::_${text_plural}_"; |
|
120 | + if (isset($this->translations[$identifier])) { |
|
121 | + return (string) new L10NString($this, $identifier, $parameters, $count); |
|
122 | + } else { |
|
123 | + if ($count === 1) { |
|
124 | + return (string) new L10NString($this, $text_singular, $parameters, $count); |
|
125 | + } else { |
|
126 | + return (string) new L10NString($this, $text_plural, $parameters, $count); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Localization |
|
133 | + * @param string $type Type of localization |
|
134 | + * @param \DateTime|int|string $data parameters for this localization |
|
135 | + * @param array $options |
|
136 | + * @return string|int|false |
|
137 | + * |
|
138 | + * Returns the localized data. |
|
139 | + * |
|
140 | + * Implemented types: |
|
141 | + * - date |
|
142 | + * - Creates a date |
|
143 | + * - params: timestamp (int/string) |
|
144 | + * - datetime |
|
145 | + * - Creates date and time |
|
146 | + * - params: timestamp (int/string) |
|
147 | + * - time |
|
148 | + * - Creates a time |
|
149 | + * - params: timestamp (int/string) |
|
150 | + * - firstday: Returns the first day of the week (0 sunday - 6 saturday) |
|
151 | + * - jsdate: Returns the short JS date format |
|
152 | + */ |
|
153 | + public function l($type, $data = null, $options = array()) { |
|
154 | + if (null === $this->locale) { |
|
155 | + // Use the language of the instance |
|
156 | + $this->locale = $this->getLanguageCode(); |
|
157 | + } |
|
158 | + if ($this->locale === 'sr@latin') { |
|
159 | + $this->locale = 'sr_latn'; |
|
160 | + } |
|
161 | + |
|
162 | + if ($type === 'firstday') { |
|
163 | + return (int) Calendar::getFirstWeekday($this->locale); |
|
164 | + } |
|
165 | + if ($type === 'jsdate') { |
|
166 | + return (string) Calendar::getDateFormat('short', $this->locale); |
|
167 | + } |
|
168 | + |
|
169 | + $value = new \DateTime(); |
|
170 | + if ($data instanceof \DateTime) { |
|
171 | + $value = $data; |
|
172 | + } else if (is_string($data) && !is_numeric($data)) { |
|
173 | + $data = strtotime($data); |
|
174 | + $value->setTimestamp($data); |
|
175 | + } else if ($data !== null) { |
|
176 | + $value->setTimestamp($data); |
|
177 | + } |
|
178 | + |
|
179 | + $options = array_merge(array('width' => 'long'), $options); |
|
180 | + $width = $options['width']; |
|
181 | + switch ($type) { |
|
182 | + case 'date': |
|
183 | + return (string) Calendar::formatDate($value, $width, $this->locale); |
|
184 | + case 'datetime': |
|
185 | + return (string) Calendar::formatDatetime($value, $width, $this->locale); |
|
186 | + case 'time': |
|
187 | + return (string) Calendar::formatTime($value, $width, $this->locale); |
|
188 | + default: |
|
189 | + return false; |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Returns an associative array with all translations |
|
195 | + * |
|
196 | + * Called by \OC_L10N_String |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function getTranslations() { |
|
200 | + return $this->translations; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Returnsed function accepts the argument $n |
|
205 | + * |
|
206 | + * Called by \OC_L10N_String |
|
207 | + * @return string the plural form function |
|
208 | + */ |
|
209 | + public function getPluralFormFunction() { |
|
210 | + if (is_null($this->pluralFormFunction)) { |
|
211 | + $this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString); |
|
212 | + } |
|
213 | + return $this->pluralFormFunction; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param $translationFile |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + protected function load($translationFile) { |
|
221 | + $json = json_decode(file_get_contents($translationFile), true); |
|
222 | + if (!is_array($json)) { |
|
223 | + $jsonError = json_last_error(); |
|
224 | + \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); |
|
225 | + return false; |
|
226 | + } |
|
227 | + |
|
228 | + if (!empty($json['pluralForm'])) { |
|
229 | + $this->pluralFormString = $json['pluralForm']; |
|
230 | + } |
|
231 | + $this->translations = array_merge($this->translations, $json['translations']); |
|
232 | + return true; |
|
233 | + } |
|
234 | 234 | } |
@@ -44,77 +44,77 @@ |
||
44 | 44 | * @since 6.0.0 |
45 | 45 | */ |
46 | 46 | interface IL10N { |
47 | - /** |
|
48 | - * Translating |
|
49 | - * @param string $text The text we need a translation for |
|
50 | - * @param array $parameters default:array() Parameters for sprintf |
|
51 | - * @return string Translation or the same text |
|
52 | - * |
|
53 | - * Returns the translation. If no translation is found, $text will be |
|
54 | - * returned. |
|
55 | - * @since 6.0.0 |
|
56 | - */ |
|
57 | - public function t($text, $parameters = array()); |
|
47 | + /** |
|
48 | + * Translating |
|
49 | + * @param string $text The text we need a translation for |
|
50 | + * @param array $parameters default:array() Parameters for sprintf |
|
51 | + * @return string Translation or the same text |
|
52 | + * |
|
53 | + * Returns the translation. If no translation is found, $text will be |
|
54 | + * returned. |
|
55 | + * @since 6.0.0 |
|
56 | + */ |
|
57 | + public function t($text, $parameters = array()); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Translating |
|
61 | - * @param string $text_singular the string to translate for exactly one object |
|
62 | - * @param string $text_plural the string to translate for n objects |
|
63 | - * @param integer $count Number of objects |
|
64 | - * @param array $parameters default:array() Parameters for sprintf |
|
65 | - * @return string Translation or the same text |
|
66 | - * |
|
67 | - * Returns the translation. If no translation is found, $text will be |
|
68 | - * returned. %n will be replaced with the number of objects. |
|
69 | - * |
|
70 | - * The correct plural is determined by the plural_forms-function |
|
71 | - * provided by the po file. |
|
72 | - * @since 6.0.0 |
|
73 | - * |
|
74 | - */ |
|
75 | - public function n($text_singular, $text_plural, $count, $parameters = array()); |
|
59 | + /** |
|
60 | + * Translating |
|
61 | + * @param string $text_singular the string to translate for exactly one object |
|
62 | + * @param string $text_plural the string to translate for n objects |
|
63 | + * @param integer $count Number of objects |
|
64 | + * @param array $parameters default:array() Parameters for sprintf |
|
65 | + * @return string Translation or the same text |
|
66 | + * |
|
67 | + * Returns the translation. If no translation is found, $text will be |
|
68 | + * returned. %n will be replaced with the number of objects. |
|
69 | + * |
|
70 | + * The correct plural is determined by the plural_forms-function |
|
71 | + * provided by the po file. |
|
72 | + * @since 6.0.0 |
|
73 | + * |
|
74 | + */ |
|
75 | + public function n($text_singular, $text_plural, $count, $parameters = array()); |
|
76 | 76 | |
77 | - /** |
|
78 | - * Localization |
|
79 | - * @param string $type Type of localization |
|
80 | - * @param \DateTime|int|string $data parameters for this localization |
|
81 | - * @param array $options currently supports following options: |
|
82 | - * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
83 | - * @return string|int|false |
|
84 | - * |
|
85 | - * Returns the localized data. |
|
86 | - * |
|
87 | - * Implemented types: |
|
88 | - * - date |
|
89 | - * - Creates a date |
|
90 | - * - l10n-field: date |
|
91 | - * - params: timestamp (int/string) |
|
92 | - * - datetime |
|
93 | - * - Creates date and time |
|
94 | - * - l10n-field: datetime |
|
95 | - * - params: timestamp (int/string) |
|
96 | - * - time |
|
97 | - * - Creates a time |
|
98 | - * - l10n-field: time |
|
99 | - * - params: timestamp (int/string) |
|
100 | - * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
101 | - */ |
|
102 | - public function l($type, $data, $options = array()); |
|
77 | + /** |
|
78 | + * Localization |
|
79 | + * @param string $type Type of localization |
|
80 | + * @param \DateTime|int|string $data parameters for this localization |
|
81 | + * @param array $options currently supports following options: |
|
82 | + * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
83 | + * @return string|int|false |
|
84 | + * |
|
85 | + * Returns the localized data. |
|
86 | + * |
|
87 | + * Implemented types: |
|
88 | + * - date |
|
89 | + * - Creates a date |
|
90 | + * - l10n-field: date |
|
91 | + * - params: timestamp (int/string) |
|
92 | + * - datetime |
|
93 | + * - Creates date and time |
|
94 | + * - l10n-field: datetime |
|
95 | + * - params: timestamp (int/string) |
|
96 | + * - time |
|
97 | + * - Creates a time |
|
98 | + * - l10n-field: time |
|
99 | + * - params: timestamp (int/string) |
|
100 | + * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
101 | + */ |
|
102 | + public function l($type, $data, $options = array()); |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * The code (en, de, ...) of the language that is used for this IL10N object |
|
107 | - * |
|
108 | - * @return string language |
|
109 | - * @since 7.0.0 |
|
110 | - */ |
|
111 | - public function getLanguageCode(); |
|
105 | + /** |
|
106 | + * The code (en, de, ...) of the language that is used for this IL10N object |
|
107 | + * |
|
108 | + * @return string language |
|
109 | + * @since 7.0.0 |
|
110 | + */ |
|
111 | + public function getLanguageCode(); |
|
112 | 112 | |
113 | - /** |
|
114 | - * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
115 | - * |
|
116 | - * @return string locale |
|
117 | - * @since 13.0.0 |
|
118 | - */ |
|
119 | - public function getLocaleCode(); |
|
113 | + /** |
|
114 | + * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
115 | + * |
|
116 | + * @return string locale |
|
117 | + * @since 13.0.0 |
|
118 | + */ |
|
119 | + public function getLocaleCode(); |
|
120 | 120 | } |