@@ -38,137 +38,137 @@ |
||
38 | 38 | */ |
39 | 39 | class SaveAccountsTableData implements IRepairStep { |
40 | 40 | |
41 | - const BATCH_SIZE = 75; |
|
42 | - |
|
43 | - /** @var IDBConnection */ |
|
44 | - protected $db; |
|
45 | - |
|
46 | - /** @var IConfig */ |
|
47 | - protected $config; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IDBConnection $db |
|
51 | - * @param IConfig $config |
|
52 | - */ |
|
53 | - public function __construct(IDBConnection $db, IConfig $config) { |
|
54 | - $this->db = $db; |
|
55 | - $this->config = $config; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getName() { |
|
62 | - return 'Copy data from accounts table when migrating from ownCloud'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param IOutput $output |
|
67 | - */ |
|
68 | - public function run(IOutput $output) { |
|
69 | - if (!$this->shouldRun()) { |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - $offset = 0; |
|
74 | - $numUsers = $this->runStep($offset); |
|
75 | - |
|
76 | - while ($numUsers === self::BATCH_SIZE) { |
|
77 | - $offset += $numUsers; |
|
78 | - $numUsers = $this->runStep($offset); |
|
79 | - } |
|
80 | - |
|
81 | - // Remove the table |
|
82 | - $this->db->dropTable('accounts'); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - protected function shouldRun() { |
|
89 | - $schema = $this->db->createSchema(); |
|
90 | - |
|
91 | - $tableName = $this->config->getSystemValue('dbtableprefix', 'oc_') . 'accounts'; |
|
92 | - if (!$schema->hasTable($tableName)) { |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - $table = $schema->getTable($tableName); |
|
97 | - return $table->hasColumn('user_id'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param int $offset |
|
102 | - * @return int Number of copied users |
|
103 | - */ |
|
104 | - protected function runStep($offset) { |
|
105 | - $query = $this->db->getQueryBuilder(); |
|
106 | - $query->select('*') |
|
107 | - ->from('accounts') |
|
108 | - ->orderBy('id') |
|
109 | - ->setMaxResults(self::BATCH_SIZE); |
|
110 | - |
|
111 | - if ($offset > 0) { |
|
112 | - $query->setFirstResult($offset); |
|
113 | - } |
|
114 | - |
|
115 | - $result = $query->execute(); |
|
116 | - |
|
117 | - $update = $this->db->getQueryBuilder(); |
|
118 | - $update->update('users') |
|
119 | - ->set('displayname', $update->createParameter('displayname')) |
|
120 | - ->where($update->expr()->eq('uid', $update->createParameter('userid'))); |
|
121 | - |
|
122 | - $updatedUsers = 0; |
|
123 | - while ($row = $result->fetch()) { |
|
124 | - try { |
|
125 | - $this->migrateUserInfo($update, $row); |
|
126 | - } catch (PreConditionNotMetException $e) { |
|
127 | - // Ignore and continue |
|
128 | - } catch (\UnexpectedValueException $e) { |
|
129 | - // Ignore and continue |
|
130 | - } |
|
131 | - $updatedUsers++; |
|
132 | - } |
|
133 | - $result->closeCursor(); |
|
134 | - |
|
135 | - return $updatedUsers; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param IQueryBuilder $update |
|
140 | - * @param array $userdata |
|
141 | - * @throws PreConditionNotMetException |
|
142 | - * @throws \UnexpectedValueException |
|
143 | - */ |
|
144 | - protected function migrateUserInfo(IQueryBuilder $update, $userdata) { |
|
145 | - $state = (int) $userdata['state']; |
|
146 | - if ($state === 3) { |
|
147 | - // Deleted user, ignore |
|
148 | - return; |
|
149 | - } |
|
150 | - |
|
151 | - if ($userdata['email'] !== null) { |
|
152 | - $this->config->setUserValue($userdata['user_id'], 'settings', 'email', $userdata['email']); |
|
153 | - } |
|
154 | - if ($userdata['quota'] !== null) { |
|
155 | - $this->config->setUserValue($userdata['user_id'], 'files', 'quota', $userdata['quota']); |
|
156 | - } |
|
157 | - if ($userdata['last_login'] !== null) { |
|
158 | - $this->config->setUserValue($userdata['user_id'], 'login', 'lastLogin', $userdata['last_login']); |
|
159 | - } |
|
160 | - if ($state === 1) { |
|
161 | - $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'true'); |
|
162 | - } else if ($state === 2) { |
|
163 | - $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'false'); |
|
164 | - } |
|
165 | - |
|
166 | - if ($userdata['display_name'] !== null) { |
|
167 | - $update->setParameter('displayname', $userdata['display_name']) |
|
168 | - ->setParameter('userid', $userdata['user_id']); |
|
169 | - $update->execute(); |
|
170 | - } |
|
171 | - |
|
172 | - } |
|
41 | + const BATCH_SIZE = 75; |
|
42 | + |
|
43 | + /** @var IDBConnection */ |
|
44 | + protected $db; |
|
45 | + |
|
46 | + /** @var IConfig */ |
|
47 | + protected $config; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IDBConnection $db |
|
51 | + * @param IConfig $config |
|
52 | + */ |
|
53 | + public function __construct(IDBConnection $db, IConfig $config) { |
|
54 | + $this->db = $db; |
|
55 | + $this->config = $config; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getName() { |
|
62 | + return 'Copy data from accounts table when migrating from ownCloud'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param IOutput $output |
|
67 | + */ |
|
68 | + public function run(IOutput $output) { |
|
69 | + if (!$this->shouldRun()) { |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + $offset = 0; |
|
74 | + $numUsers = $this->runStep($offset); |
|
75 | + |
|
76 | + while ($numUsers === self::BATCH_SIZE) { |
|
77 | + $offset += $numUsers; |
|
78 | + $numUsers = $this->runStep($offset); |
|
79 | + } |
|
80 | + |
|
81 | + // Remove the table |
|
82 | + $this->db->dropTable('accounts'); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + protected function shouldRun() { |
|
89 | + $schema = $this->db->createSchema(); |
|
90 | + |
|
91 | + $tableName = $this->config->getSystemValue('dbtableprefix', 'oc_') . 'accounts'; |
|
92 | + if (!$schema->hasTable($tableName)) { |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + $table = $schema->getTable($tableName); |
|
97 | + return $table->hasColumn('user_id'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param int $offset |
|
102 | + * @return int Number of copied users |
|
103 | + */ |
|
104 | + protected function runStep($offset) { |
|
105 | + $query = $this->db->getQueryBuilder(); |
|
106 | + $query->select('*') |
|
107 | + ->from('accounts') |
|
108 | + ->orderBy('id') |
|
109 | + ->setMaxResults(self::BATCH_SIZE); |
|
110 | + |
|
111 | + if ($offset > 0) { |
|
112 | + $query->setFirstResult($offset); |
|
113 | + } |
|
114 | + |
|
115 | + $result = $query->execute(); |
|
116 | + |
|
117 | + $update = $this->db->getQueryBuilder(); |
|
118 | + $update->update('users') |
|
119 | + ->set('displayname', $update->createParameter('displayname')) |
|
120 | + ->where($update->expr()->eq('uid', $update->createParameter('userid'))); |
|
121 | + |
|
122 | + $updatedUsers = 0; |
|
123 | + while ($row = $result->fetch()) { |
|
124 | + try { |
|
125 | + $this->migrateUserInfo($update, $row); |
|
126 | + } catch (PreConditionNotMetException $e) { |
|
127 | + // Ignore and continue |
|
128 | + } catch (\UnexpectedValueException $e) { |
|
129 | + // Ignore and continue |
|
130 | + } |
|
131 | + $updatedUsers++; |
|
132 | + } |
|
133 | + $result->closeCursor(); |
|
134 | + |
|
135 | + return $updatedUsers; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param IQueryBuilder $update |
|
140 | + * @param array $userdata |
|
141 | + * @throws PreConditionNotMetException |
|
142 | + * @throws \UnexpectedValueException |
|
143 | + */ |
|
144 | + protected function migrateUserInfo(IQueryBuilder $update, $userdata) { |
|
145 | + $state = (int) $userdata['state']; |
|
146 | + if ($state === 3) { |
|
147 | + // Deleted user, ignore |
|
148 | + return; |
|
149 | + } |
|
150 | + |
|
151 | + if ($userdata['email'] !== null) { |
|
152 | + $this->config->setUserValue($userdata['user_id'], 'settings', 'email', $userdata['email']); |
|
153 | + } |
|
154 | + if ($userdata['quota'] !== null) { |
|
155 | + $this->config->setUserValue($userdata['user_id'], 'files', 'quota', $userdata['quota']); |
|
156 | + } |
|
157 | + if ($userdata['last_login'] !== null) { |
|
158 | + $this->config->setUserValue($userdata['user_id'], 'login', 'lastLogin', $userdata['last_login']); |
|
159 | + } |
|
160 | + if ($state === 1) { |
|
161 | + $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'true'); |
|
162 | + } else if ($state === 2) { |
|
163 | + $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'false'); |
|
164 | + } |
|
165 | + |
|
166 | + if ($userdata['display_name'] !== null) { |
|
167 | + $update->setParameter('displayname', $userdata['display_name']) |
|
168 | + ->setParameter('userid', $userdata['user_id']); |
|
169 | + $update->execute(); |
|
170 | + } |
|
171 | + |
|
172 | + } |
|
173 | 173 | } |
174 | 174 |
@@ -88,7 +88,7 @@ |
||
88 | 88 | protected function shouldRun() { |
89 | 89 | $schema = $this->db->createSchema(); |
90 | 90 | |
91 | - $tableName = $this->config->getSystemValue('dbtableprefix', 'oc_') . 'accounts'; |
|
91 | + $tableName = $this->config->getSystemValue('dbtableprefix', 'oc_').'accounts'; |
|
92 | 92 | if (!$schema->hasTable($tableName)) { |
93 | 93 | return false; |
94 | 94 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $searchResult->markExactIdMatch($resultType); |
80 | 80 | } |
81 | 81 | $result['exact'][] = [ |
82 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
82 | + 'label' => $contact['FN']." ($cloudId)", |
|
83 | 83 | 'value' => [ |
84 | 84 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
85 | 85 | 'shareWith' => $cloudId, |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ]; |
89 | 89 | } else { |
90 | 90 | $result['wide'][] = [ |
91 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
91 | + 'label' => $contact['FN']." ($cloudId)", |
|
92 | 92 | 'value' => [ |
93 | 93 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
94 | 94 | 'shareWith' => $cloudId, |
@@ -33,107 +33,107 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class RemotePlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
36 | + protected $shareeEnumeration; |
|
37 | 37 | |
38 | - /** @var IManager */ |
|
39 | - private $contactsManager; |
|
40 | - /** @var ICloudIdManager */ |
|
41 | - private $cloudIdManager; |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
38 | + /** @var IManager */ |
|
39 | + private $contactsManager; |
|
40 | + /** @var ICloudIdManager */ |
|
41 | + private $cloudIdManager; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | 44 | |
45 | - public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | - $this->contactsManager = $contactsManager; |
|
47 | - $this->cloudIdManager = $cloudIdManager; |
|
48 | - $this->config = $config; |
|
45 | + public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | + $this->contactsManager = $contactsManager; |
|
47 | + $this->cloudIdManager = $cloudIdManager; |
|
48 | + $this->config = $config; |
|
49 | 49 | |
50 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | - } |
|
50 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | + } |
|
52 | 52 | |
53 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
54 | - $result = ['wide' => [], 'exact' => []]; |
|
55 | - $resultType = new SearchResultType('remotes'); |
|
53 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
54 | + $result = ['wide' => [], 'exact' => []]; |
|
55 | + $resultType = new SearchResultType('remotes'); |
|
56 | 56 | |
57 | - // Search in contacts |
|
58 | - //@todo Pagination missing |
|
59 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
60 | - foreach ($addressBookContacts as $contact) { |
|
61 | - if (isset($contact['isLocalSystemBook'])) { |
|
62 | - continue; |
|
63 | - } |
|
64 | - if (isset($contact['CLOUD'])) { |
|
65 | - $cloudIds = $contact['CLOUD']; |
|
66 | - if (!is_array($cloudIds)) { |
|
67 | - $cloudIds = [$cloudIds]; |
|
68 | - } |
|
69 | - $lowerSearch = strtolower($search); |
|
70 | - foreach ($cloudIds as $cloudId) { |
|
71 | - try { |
|
72 | - list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
73 | - } catch (\InvalidArgumentException $e) { |
|
74 | - continue; |
|
75 | - } |
|
57 | + // Search in contacts |
|
58 | + //@todo Pagination missing |
|
59 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
60 | + foreach ($addressBookContacts as $contact) { |
|
61 | + if (isset($contact['isLocalSystemBook'])) { |
|
62 | + continue; |
|
63 | + } |
|
64 | + if (isset($contact['CLOUD'])) { |
|
65 | + $cloudIds = $contact['CLOUD']; |
|
66 | + if (!is_array($cloudIds)) { |
|
67 | + $cloudIds = [$cloudIds]; |
|
68 | + } |
|
69 | + $lowerSearch = strtolower($search); |
|
70 | + foreach ($cloudIds as $cloudId) { |
|
71 | + try { |
|
72 | + list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
73 | + } catch (\InvalidArgumentException $e) { |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
78 | - if (strtolower($cloudId) === $lowerSearch) { |
|
79 | - $searchResult->markExactIdMatch($resultType); |
|
80 | - } |
|
81 | - $result['exact'][] = [ |
|
82 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
83 | - 'value' => [ |
|
84 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
85 | - 'shareWith' => $cloudId, |
|
86 | - 'server' => $serverUrl, |
|
87 | - ], |
|
88 | - ]; |
|
89 | - } else { |
|
90 | - $result['wide'][] = [ |
|
91 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
92 | - 'value' => [ |
|
93 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
94 | - 'shareWith' => $cloudId, |
|
95 | - 'server' => $serverUrl, |
|
96 | - ], |
|
97 | - ]; |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
77 | + if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
78 | + if (strtolower($cloudId) === $lowerSearch) { |
|
79 | + $searchResult->markExactIdMatch($resultType); |
|
80 | + } |
|
81 | + $result['exact'][] = [ |
|
82 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
83 | + 'value' => [ |
|
84 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
85 | + 'shareWith' => $cloudId, |
|
86 | + 'server' => $serverUrl, |
|
87 | + ], |
|
88 | + ]; |
|
89 | + } else { |
|
90 | + $result['wide'][] = [ |
|
91 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
92 | + 'value' => [ |
|
93 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
94 | + 'shareWith' => $cloudId, |
|
95 | + 'server' => $serverUrl, |
|
96 | + ], |
|
97 | + ]; |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - if (!$this->shareeEnumeration) { |
|
104 | - $result['wide'] = []; |
|
105 | - } else { |
|
106 | - $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
107 | - } |
|
103 | + if (!$this->shareeEnumeration) { |
|
104 | + $result['wide'] = []; |
|
105 | + } else { |
|
106 | + $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
107 | + } |
|
108 | 108 | |
109 | - if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
110 | - $result['exact'][] = [ |
|
111 | - 'label' => $search, |
|
112 | - 'value' => [ |
|
113 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
114 | - 'shareWith' => $search, |
|
115 | - ], |
|
116 | - ]; |
|
117 | - } |
|
109 | + if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
110 | + $result['exact'][] = [ |
|
111 | + 'label' => $search, |
|
112 | + 'value' => [ |
|
113 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
114 | + 'shareWith' => $search, |
|
115 | + ], |
|
116 | + ]; |
|
117 | + } |
|
118 | 118 | |
119 | - $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
119 | + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
120 | 120 | |
121 | - return true; |
|
122 | - } |
|
121 | + return true; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * split user and remote from federated cloud id |
|
126 | - * |
|
127 | - * @param string $address federated share address |
|
128 | - * @return array [user, remoteURL] |
|
129 | - * @throws \InvalidArgumentException |
|
130 | - */ |
|
131 | - public function splitUserRemote($address) { |
|
132 | - try { |
|
133 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
134 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
135 | - } catch (\InvalidArgumentException $e) { |
|
136 | - throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
137 | - } |
|
138 | - } |
|
124 | + /** |
|
125 | + * split user and remote from federated cloud id |
|
126 | + * |
|
127 | + * @param string $address federated share address |
|
128 | + * @return array [user, remoteURL] |
|
129 | + * @throws \InvalidArgumentException |
|
130 | + */ |
|
131 | + public function splitUserRemote($address) { |
|
132 | + try { |
|
133 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
134 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
135 | + } catch (\InvalidArgumentException $e) { |
|
136 | + throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $searchResult = $this->c->resolve(SearchResult::class); |
48 | 48 | |
49 | 49 | foreach ($shareTypes as $type) { |
50 | - if(!isset($this->pluginList[$type])) { |
|
50 | + if (!isset($this->pluginList[$type])) { |
|
51 | 51 | continue; |
52 | 52 | } |
53 | 53 | foreach ($this->pluginList[$type] as $plugin) { |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | // that the exact same email address and federated cloud id exists |
71 | 71 | $emailType = new SearchResultType('emails'); |
72 | 72 | $remoteType = new SearchResultType('remotes'); |
73 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
73 | + if ($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
74 | 74 | $searchResult->unsetResult($remoteType); |
75 | 75 | } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
76 | 76 | $searchResult->unsetResult($emailType); |
77 | 77 | } |
78 | 78 | |
79 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
79 | + return [$searchResult->asArray(), (bool) $hasMoreResults]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public function registerPlugin(array $pluginInfo) { |
83 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
84 | - if($shareType === null) { |
|
83 | + $shareType = constant(Share::class.'::'.$pluginInfo['shareType']); |
|
84 | + if ($shareType === null) { |
|
85 | 85 | throw new \InvalidArgumentException('Provided ShareType is invalid'); |
86 | 86 | } |
87 | 87 | $this->pluginList[$shareType][] = $pluginInfo['class']; |
@@ -31,68 +31,68 @@ |
||
31 | 31 | use OCP\Share; |
32 | 32 | |
33 | 33 | class Search implements ISearch { |
34 | - /** @var IContainer */ |
|
35 | - private $c; |
|
34 | + /** @var IContainer */ |
|
35 | + private $c; |
|
36 | 36 | |
37 | - protected $pluginList = []; |
|
37 | + protected $pluginList = []; |
|
38 | 38 | |
39 | - public function __construct(IContainer $c) { |
|
40 | - $this->c = $c; |
|
41 | - } |
|
39 | + public function __construct(IContainer $c) { |
|
40 | + $this->c = $c; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $search |
|
45 | - * @param array $shareTypes |
|
46 | - * @param bool $lookup |
|
47 | - * @param int|null $limit |
|
48 | - * @param int|null $offset |
|
49 | - * @return array |
|
50 | - * @throws \OCP\AppFramework\QueryException |
|
51 | - */ |
|
52 | - public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | - $hasMoreResults = false; |
|
43 | + /** |
|
44 | + * @param string $search |
|
45 | + * @param array $shareTypes |
|
46 | + * @param bool $lookup |
|
47 | + * @param int|null $limit |
|
48 | + * @param int|null $offset |
|
49 | + * @return array |
|
50 | + * @throws \OCP\AppFramework\QueryException |
|
51 | + */ |
|
52 | + public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | + $hasMoreResults = false; |
|
54 | 54 | |
55 | - /** @var ISearchResult $searchResult */ |
|
56 | - $searchResult = $this->c->resolve(SearchResult::class); |
|
55 | + /** @var ISearchResult $searchResult */ |
|
56 | + $searchResult = $this->c->resolve(SearchResult::class); |
|
57 | 57 | |
58 | - foreach ($shareTypes as $type) { |
|
59 | - if(!isset($this->pluginList[$type])) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - foreach ($this->pluginList[$type] as $plugin) { |
|
63 | - /** @var ISearchPlugin $searchPlugin */ |
|
64 | - $searchPlugin = $this->c->resolve($plugin); |
|
65 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | - } |
|
67 | - } |
|
58 | + foreach ($shareTypes as $type) { |
|
59 | + if(!isset($this->pluginList[$type])) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + foreach ($this->pluginList[$type] as $plugin) { |
|
63 | + /** @var ISearchPlugin $searchPlugin */ |
|
64 | + $searchPlugin = $this->c->resolve($plugin); |
|
65 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - // Get from lookup server, not a separate share type |
|
70 | - if ($lookup) { |
|
71 | - $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | - } |
|
69 | + // Get from lookup server, not a separate share type |
|
70 | + if ($lookup) { |
|
71 | + $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | + } |
|
74 | 74 | |
75 | - // sanitizing, could go into the plugins as well |
|
75 | + // sanitizing, could go into the plugins as well |
|
76 | 76 | |
77 | - // if we have a exact match, either for the federated cloud id or for the |
|
78 | - // email address we only return the exact match. It is highly unlikely |
|
79 | - // that the exact same email address and federated cloud id exists |
|
80 | - $emailType = new SearchResultType('emails'); |
|
81 | - $remoteType = new SearchResultType('remotes'); |
|
82 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | - $searchResult->unsetResult($remoteType); |
|
84 | - } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | - $searchResult->unsetResult($emailType); |
|
86 | - } |
|
77 | + // if we have a exact match, either for the federated cloud id or for the |
|
78 | + // email address we only return the exact match. It is highly unlikely |
|
79 | + // that the exact same email address and federated cloud id exists |
|
80 | + $emailType = new SearchResultType('emails'); |
|
81 | + $remoteType = new SearchResultType('remotes'); |
|
82 | + if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | + $searchResult->unsetResult($remoteType); |
|
84 | + } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | + $searchResult->unsetResult($emailType); |
|
86 | + } |
|
87 | 87 | |
88 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | - } |
|
88 | + return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | + } |
|
90 | 90 | |
91 | - public function registerPlugin(array $pluginInfo) { |
|
92 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | - if($shareType === null) { |
|
94 | - throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | - } |
|
96 | - $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | - } |
|
91 | + public function registerPlugin(array $pluginInfo) { |
|
92 | + $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | + if($shareType === null) { |
|
94 | + throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | + } |
|
96 | + $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | + } |
|
98 | 98 | } |
@@ -35,39 +35,39 @@ |
||
35 | 35 | */ |
36 | 36 | class MoveToTrashEvent extends Event { |
37 | 37 | |
38 | - /** @var bool */ |
|
39 | - private $moveToTrashBin; |
|
38 | + /** @var bool */ |
|
39 | + private $moveToTrashBin; |
|
40 | 40 | |
41 | - /** @var Node */ |
|
42 | - private $node; |
|
41 | + /** @var Node */ |
|
42 | + private $node; |
|
43 | 43 | |
44 | - public function __construct(Node $node) { |
|
45 | - $this->moveToTrashBin = true; |
|
46 | - $this->node = $node; |
|
47 | - } |
|
44 | + public function __construct(Node $node) { |
|
45 | + $this->moveToTrashBin = true; |
|
46 | + $this->node = $node; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * get Node which will be deleted |
|
51 | - * |
|
52 | - * @return Node |
|
53 | - */ |
|
54 | - public function getNode() { |
|
55 | - return $this->node; |
|
56 | - } |
|
49 | + /** |
|
50 | + * get Node which will be deleted |
|
51 | + * |
|
52 | + * @return Node |
|
53 | + */ |
|
54 | + public function getNode() { |
|
55 | + return $this->node; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * disable trash bin for this operation |
|
60 | - */ |
|
61 | - public function disableTrashBin() { |
|
62 | - $this->moveToTrashBin = false; |
|
63 | - } |
|
58 | + /** |
|
59 | + * disable trash bin for this operation |
|
60 | + */ |
|
61 | + public function disableTrashBin() { |
|
62 | + $this->moveToTrashBin = false; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * should the file be moved to the trash bin? |
|
67 | - * |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function shouldMoveToTrashBin() { |
|
71 | - return $this->moveToTrashBin; |
|
72 | - } |
|
65 | + /** |
|
66 | + * should the file be moved to the trash bin? |
|
67 | + * |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function shouldMoveToTrashBin() { |
|
71 | + return $this->moveToTrashBin; |
|
72 | + } |
|
73 | 73 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
127 | 127 | $template->addHeader(); |
128 | 128 | $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
129 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
129 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | 130 | $template->addFooter(); |
131 | 131 | |
132 | 132 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
197 | 197 | $template->addHeader(); |
198 | 198 | $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
199 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
199 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | 200 | if ($user->getEMailAddress()) { |
201 | 201 | $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
202 | 202 | } |
@@ -38,176 +38,176 @@ |
||
38 | 38 | |
39 | 39 | class Hooks { |
40 | 40 | |
41 | - /** @var IActivityManager */ |
|
42 | - protected $activityManager; |
|
43 | - /** @var IUserManager */ |
|
44 | - protected $userManager; |
|
45 | - /** @var IUserSession */ |
|
46 | - protected $userSession; |
|
47 | - /** @var IURLGenerator */ |
|
48 | - protected $urlGenerator; |
|
49 | - /** @var IMailer */ |
|
50 | - protected $mailer; |
|
51 | - /** @var IConfig */ |
|
52 | - protected $config; |
|
53 | - /** @var IFactory */ |
|
54 | - protected $languageFactory; |
|
55 | - /** @var IL10N */ |
|
56 | - protected $l; |
|
57 | - |
|
58 | - public function __construct(IActivityManager $activityManager, |
|
59 | - IUserManager $userManager, |
|
60 | - IUserSession $userSession, |
|
61 | - IURLGenerator $urlGenerator, |
|
62 | - IMailer $mailer, |
|
63 | - IConfig $config, |
|
64 | - IFactory $languageFactory, |
|
65 | - IL10N $l) { |
|
66 | - $this->activityManager = $activityManager; |
|
67 | - $this->userManager = $userManager; |
|
68 | - $this->userSession = $userSession; |
|
69 | - $this->urlGenerator = $urlGenerator; |
|
70 | - $this->mailer = $mailer; |
|
71 | - $this->config = $config; |
|
72 | - $this->languageFactory = $languageFactory; |
|
73 | - $this->l = $l; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $uid |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @throws \BadMethodCallException |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function onChangePassword($uid) { |
|
83 | - $user = $this->userManager->get($uid); |
|
84 | - |
|
85 | - if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
86 | - // User didn't login, so don't create activities and emails. |
|
87 | - return; |
|
88 | - } |
|
89 | - |
|
90 | - $event = $this->activityManager->generateEvent(); |
|
91 | - $event->setApp('settings') |
|
92 | - ->setType('personal_settings') |
|
93 | - ->setAffectedUser($user->getUID()); |
|
94 | - |
|
95 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
96 | - |
|
97 | - $actor = $this->userSession->getUser(); |
|
98 | - if ($actor instanceof IUser) { |
|
99 | - if ($actor->getUID() !== $user->getUID()) { |
|
100 | - $this->l = $this->languageFactory->get( |
|
101 | - 'settings', |
|
102 | - $this->config->getUserValue( |
|
103 | - $user->getUID(), 'core', 'lang', |
|
104 | - $this->config->getSystemValue('default_language', 'en') |
|
105 | - ) |
|
106 | - ); |
|
107 | - |
|
108 | - $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
109 | - $event->setAuthor($actor->getUID()) |
|
110 | - ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
111 | - } else { |
|
112 | - $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
113 | - $event->setAuthor($actor->getUID()) |
|
114 | - ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
115 | - } |
|
116 | - } else { |
|
117 | - $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
118 | - $event->setSubject(Provider::PASSWORD_RESET); |
|
119 | - } |
|
120 | - |
|
121 | - $this->activityManager->publish($event); |
|
122 | - |
|
123 | - if ($user->getEMailAddress() !== null) { |
|
124 | - $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
125 | - 'displayname' => $user->getDisplayName(), |
|
126 | - 'emailAddress' => $user->getEMailAddress(), |
|
127 | - 'instanceUrl' => $instanceUrl, |
|
128 | - ]); |
|
129 | - |
|
130 | - $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
131 | - $template->addHeader(); |
|
132 | - $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
133 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
134 | - $template->addFooter(); |
|
135 | - |
|
136 | - |
|
137 | - $message = $this->mailer->createMessage(); |
|
138 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
139 | - $message->useTemplate($template); |
|
140 | - $this->mailer->send($message); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @param IUser $user |
|
146 | - * @param string|null $oldMailAddress |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - * @throws \BadMethodCallException |
|
149 | - */ |
|
150 | - public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
151 | - |
|
152 | - if ($oldMailAddress === $user->getEMailAddress() || |
|
153 | - $user->getLastLogin() === 0) { |
|
154 | - // Email didn't really change or user didn't login, |
|
155 | - // so don't create activities and emails. |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - $event = $this->activityManager->generateEvent(); |
|
160 | - $event->setApp('settings') |
|
161 | - ->setType('personal_settings') |
|
162 | - ->setAffectedUser($user->getUID()); |
|
163 | - |
|
164 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
165 | - |
|
166 | - $actor = $this->userSession->getUser(); |
|
167 | - if ($actor instanceof IUser) { |
|
168 | - $subject = Provider::EMAIL_CHANGED_SELF; |
|
169 | - if ($actor->getUID() !== $user->getUID()) { |
|
170 | - $this->l = $this->languageFactory->get( |
|
171 | - 'settings', |
|
172 | - $this->config->getUserValue( |
|
173 | - $user->getUID(), 'core', 'lang', |
|
174 | - $this->config->getSystemValue('default_language', 'en') |
|
175 | - ) |
|
176 | - ); |
|
177 | - $subject = Provider::EMAIL_CHANGED; |
|
178 | - } |
|
179 | - $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
180 | - $event->setAuthor($actor->getUID()) |
|
181 | - ->setSubject($subject); |
|
182 | - } else { |
|
183 | - $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
184 | - $event->setSubject(Provider::EMAIL_CHANGED); |
|
185 | - } |
|
186 | - $this->activityManager->publish($event); |
|
187 | - |
|
188 | - |
|
189 | - if ($oldMailAddress !== null) { |
|
190 | - $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
191 | - 'displayname' => $user->getDisplayName(), |
|
192 | - 'newEMailAddress' => $user->getEMailAddress(), |
|
193 | - 'oldEMailAddress' => $oldMailAddress, |
|
194 | - 'instanceUrl' => $instanceUrl, |
|
195 | - ]); |
|
196 | - |
|
197 | - $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
198 | - $template->addHeader(); |
|
199 | - $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
200 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
201 | - if ($user->getEMailAddress()) { |
|
202 | - $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
203 | - } |
|
204 | - $template->addFooter(); |
|
205 | - |
|
206 | - |
|
207 | - $message = $this->mailer->createMessage(); |
|
208 | - $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
209 | - $message->useTemplate($template); |
|
210 | - $this->mailer->send($message); |
|
211 | - } |
|
212 | - } |
|
41 | + /** @var IActivityManager */ |
|
42 | + protected $activityManager; |
|
43 | + /** @var IUserManager */ |
|
44 | + protected $userManager; |
|
45 | + /** @var IUserSession */ |
|
46 | + protected $userSession; |
|
47 | + /** @var IURLGenerator */ |
|
48 | + protected $urlGenerator; |
|
49 | + /** @var IMailer */ |
|
50 | + protected $mailer; |
|
51 | + /** @var IConfig */ |
|
52 | + protected $config; |
|
53 | + /** @var IFactory */ |
|
54 | + protected $languageFactory; |
|
55 | + /** @var IL10N */ |
|
56 | + protected $l; |
|
57 | + |
|
58 | + public function __construct(IActivityManager $activityManager, |
|
59 | + IUserManager $userManager, |
|
60 | + IUserSession $userSession, |
|
61 | + IURLGenerator $urlGenerator, |
|
62 | + IMailer $mailer, |
|
63 | + IConfig $config, |
|
64 | + IFactory $languageFactory, |
|
65 | + IL10N $l) { |
|
66 | + $this->activityManager = $activityManager; |
|
67 | + $this->userManager = $userManager; |
|
68 | + $this->userSession = $userSession; |
|
69 | + $this->urlGenerator = $urlGenerator; |
|
70 | + $this->mailer = $mailer; |
|
71 | + $this->config = $config; |
|
72 | + $this->languageFactory = $languageFactory; |
|
73 | + $this->l = $l; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $uid |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @throws \BadMethodCallException |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function onChangePassword($uid) { |
|
83 | + $user = $this->userManager->get($uid); |
|
84 | + |
|
85 | + if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
86 | + // User didn't login, so don't create activities and emails. |
|
87 | + return; |
|
88 | + } |
|
89 | + |
|
90 | + $event = $this->activityManager->generateEvent(); |
|
91 | + $event->setApp('settings') |
|
92 | + ->setType('personal_settings') |
|
93 | + ->setAffectedUser($user->getUID()); |
|
94 | + |
|
95 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
96 | + |
|
97 | + $actor = $this->userSession->getUser(); |
|
98 | + if ($actor instanceof IUser) { |
|
99 | + if ($actor->getUID() !== $user->getUID()) { |
|
100 | + $this->l = $this->languageFactory->get( |
|
101 | + 'settings', |
|
102 | + $this->config->getUserValue( |
|
103 | + $user->getUID(), 'core', 'lang', |
|
104 | + $this->config->getSystemValue('default_language', 'en') |
|
105 | + ) |
|
106 | + ); |
|
107 | + |
|
108 | + $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
109 | + $event->setAuthor($actor->getUID()) |
|
110 | + ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
111 | + } else { |
|
112 | + $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
113 | + $event->setAuthor($actor->getUID()) |
|
114 | + ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
115 | + } |
|
116 | + } else { |
|
117 | + $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
118 | + $event->setSubject(Provider::PASSWORD_RESET); |
|
119 | + } |
|
120 | + |
|
121 | + $this->activityManager->publish($event); |
|
122 | + |
|
123 | + if ($user->getEMailAddress() !== null) { |
|
124 | + $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
125 | + 'displayname' => $user->getDisplayName(), |
|
126 | + 'emailAddress' => $user->getEMailAddress(), |
|
127 | + 'instanceUrl' => $instanceUrl, |
|
128 | + ]); |
|
129 | + |
|
130 | + $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
131 | + $template->addHeader(); |
|
132 | + $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
133 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
134 | + $template->addFooter(); |
|
135 | + |
|
136 | + |
|
137 | + $message = $this->mailer->createMessage(); |
|
138 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
139 | + $message->useTemplate($template); |
|
140 | + $this->mailer->send($message); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @param IUser $user |
|
146 | + * @param string|null $oldMailAddress |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + * @throws \BadMethodCallException |
|
149 | + */ |
|
150 | + public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
151 | + |
|
152 | + if ($oldMailAddress === $user->getEMailAddress() || |
|
153 | + $user->getLastLogin() === 0) { |
|
154 | + // Email didn't really change or user didn't login, |
|
155 | + // so don't create activities and emails. |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + $event = $this->activityManager->generateEvent(); |
|
160 | + $event->setApp('settings') |
|
161 | + ->setType('personal_settings') |
|
162 | + ->setAffectedUser($user->getUID()); |
|
163 | + |
|
164 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
165 | + |
|
166 | + $actor = $this->userSession->getUser(); |
|
167 | + if ($actor instanceof IUser) { |
|
168 | + $subject = Provider::EMAIL_CHANGED_SELF; |
|
169 | + if ($actor->getUID() !== $user->getUID()) { |
|
170 | + $this->l = $this->languageFactory->get( |
|
171 | + 'settings', |
|
172 | + $this->config->getUserValue( |
|
173 | + $user->getUID(), 'core', 'lang', |
|
174 | + $this->config->getSystemValue('default_language', 'en') |
|
175 | + ) |
|
176 | + ); |
|
177 | + $subject = Provider::EMAIL_CHANGED; |
|
178 | + } |
|
179 | + $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
180 | + $event->setAuthor($actor->getUID()) |
|
181 | + ->setSubject($subject); |
|
182 | + } else { |
|
183 | + $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
184 | + $event->setSubject(Provider::EMAIL_CHANGED); |
|
185 | + } |
|
186 | + $this->activityManager->publish($event); |
|
187 | + |
|
188 | + |
|
189 | + if ($oldMailAddress !== null) { |
|
190 | + $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
191 | + 'displayname' => $user->getDisplayName(), |
|
192 | + 'newEMailAddress' => $user->getEMailAddress(), |
|
193 | + 'oldEMailAddress' => $oldMailAddress, |
|
194 | + 'instanceUrl' => $instanceUrl, |
|
195 | + ]); |
|
196 | + |
|
197 | + $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
198 | + $template->addHeader(); |
|
199 | + $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
200 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
201 | + if ($user->getEMailAddress()) { |
|
202 | + $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
203 | + } |
|
204 | + $template->addFooter(); |
|
205 | + |
|
206 | + |
|
207 | + $message = $this->mailer->createMessage(); |
|
208 | + $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
209 | + $message->useTemplate($template); |
|
210 | + $this->mailer->send($message); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -37,45 +37,45 @@ |
||
37 | 37 | class CreateVersionEvent extends Event { |
38 | 38 | |
39 | 39 | |
40 | - /** @var bool */ |
|
41 | - private $createVersion; |
|
40 | + /** @var bool */ |
|
41 | + private $createVersion; |
|
42 | 42 | |
43 | - /** @var Node */ |
|
44 | - private $node; |
|
43 | + /** @var Node */ |
|
44 | + private $node; |
|
45 | 45 | |
46 | - /** |
|
47 | - * CreateVersionEvent constructor. |
|
48 | - * |
|
49 | - * @param Node $node |
|
50 | - */ |
|
51 | - public function __construct(Node $node) { |
|
52 | - $this->createVersion = true; |
|
53 | - $this->node = $node; |
|
54 | - } |
|
46 | + /** |
|
47 | + * CreateVersionEvent constructor. |
|
48 | + * |
|
49 | + * @param Node $node |
|
50 | + */ |
|
51 | + public function __construct(Node $node) { |
|
52 | + $this->createVersion = true; |
|
53 | + $this->node = $node; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * get Node of the file which should be versioned |
|
58 | - * |
|
59 | - * @return Node |
|
60 | - */ |
|
61 | - public function getNode() { |
|
62 | - return $this->node; |
|
63 | - } |
|
56 | + /** |
|
57 | + * get Node of the file which should be versioned |
|
58 | + * |
|
59 | + * @return Node |
|
60 | + */ |
|
61 | + public function getNode() { |
|
62 | + return $this->node; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * disable versions for this file |
|
67 | - */ |
|
68 | - public function disableVersions() { |
|
69 | - $this->createVersion = false; |
|
70 | - } |
|
65 | + /** |
|
66 | + * disable versions for this file |
|
67 | + */ |
|
68 | + public function disableVersions() { |
|
69 | + $this->createVersion = false; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * should a version be created for this file? |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function shouldCreateVersion() { |
|
78 | - return $this->createVersion; |
|
79 | - } |
|
72 | + /** |
|
73 | + * should a version be created for this file? |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function shouldCreateVersion() { |
|
78 | + return $this->createVersion; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | $icon->setImageFormat("png32"); |
64 | 64 | |
65 | 65 | $clone = clone $icon; |
66 | - $clone->scaleImage(16,0); |
|
66 | + $clone->scaleImage(16, 0); |
|
67 | 67 | $favicon->addImage($clone); |
68 | 68 | |
69 | 69 | $clone = clone $icon; |
70 | - $clone->scaleImage(32,0); |
|
70 | + $clone->scaleImage(32, 0); |
|
71 | 71 | $favicon->addImage($clone); |
72 | 72 | |
73 | 73 | $clone = clone $icon; |
74 | - $clone->scaleImage(64,0); |
|
74 | + $clone->scaleImage(64, 0); |
|
75 | 75 | $favicon->addImage($clone); |
76 | 76 | |
77 | 77 | $clone = clone $icon; |
78 | - $clone->scaleImage(128,0); |
|
78 | + $clone->scaleImage(128, 0); |
|
79 | 79 | $favicon->addImage($clone); |
80 | 80 | |
81 | 81 | $data = $favicon->getImagesBlob(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function renderAppIcon($app, $size) { |
119 | 119 | $appIcon = $this->util->getAppIcon($app); |
120 | - if($appIcon === false) { |
|
120 | + if ($appIcon === false) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | if ($appIcon instanceof ISimpleFile) { |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $mime = mime_content_type($appIcon); |
129 | 129 | } |
130 | 130 | |
131 | - if($appIconContent === false || $appIconContent === "") { |
|
131 | + if ($appIconContent === false || $appIconContent === "") { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $color = $this->themingDefaults->getColorPrimary(); |
136 | 136 | |
137 | 137 | // generate background image with rounded corners |
138 | - $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
139 | - '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
140 | - '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
138 | + $background = '<?xml version="1.0" encoding="UTF-8"?>'. |
|
139 | + '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">'. |
|
140 | + '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:'.$color.';" />'. |
|
141 | 141 | '</svg>'; |
142 | 142 | // resize svg magic as this seems broken in Imagemagick |
143 | - if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
144 | - if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
143 | + if ($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
144 | + if (substr($appIconContent, 0, 5) !== "<?xml") { |
|
145 | 145 | $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
146 | 146 | } else { |
147 | 147 | $svg = $appIconContent; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $res = $tmp->getImageResolution(); |
154 | 154 | $tmp->destroy(); |
155 | 155 | |
156 | - if($x>$y) { |
|
156 | + if ($x > $y) { |
|
157 | 157 | $max = $x; |
158 | 158 | } else { |
159 | 159 | $max = $y; |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | // convert svg to resized image |
163 | 163 | $appIconFile = new Imagick(); |
164 | - $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
165 | - $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
164 | + $resX = (int) (512 * $res['x'] / $max * 2.53); |
|
165 | + $resY = (int) (512 * $res['y'] / $max * 2.53); |
|
166 | 166 | $appIconFile->setResolution($resX, $resY); |
167 | 167 | $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
168 | 168 | $appIconFile->readImageBlob($svg); |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | $appIconFile->scaleImage(512, 512, true); |
186 | 186 | } |
187 | 187 | // offset for icon positioning |
188 | - $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
189 | - $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
190 | - $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
191 | - $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
188 | + $border_w = (int) ($appIconFile->getImageWidth() * 0.05); |
|
189 | + $border_h = (int) ($appIconFile->getImageHeight() * 0.05); |
|
190 | + $innerWidth = (int) ($appIconFile->getImageWidth() - $border_w * 2); |
|
191 | + $innerHeight = (int) ($appIconFile->getImageHeight() - $border_h * 2); |
|
192 | 192 | $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
193 | 193 | // center icon |
194 | 194 | $offset_w = 512 / 2 - $innerWidth / 2; |
@@ -31,211 +31,211 @@ |
||
31 | 31 | use OCP\Files\SimpleFS\ISimpleFile; |
32 | 32 | |
33 | 33 | class IconBuilder { |
34 | - /** @var ThemingDefaults */ |
|
35 | - private $themingDefaults; |
|
36 | - /** @var Util */ |
|
37 | - private $util; |
|
38 | - /** @var ImageManager */ |
|
39 | - private $imageManager; |
|
40 | - |
|
41 | - /** |
|
42 | - * IconBuilder constructor. |
|
43 | - * |
|
44 | - * @param ThemingDefaults $themingDefaults |
|
45 | - * @param Util $util |
|
46 | - * @param ImageManager $imageManager |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ThemingDefaults $themingDefaults, |
|
50 | - Util $util, |
|
51 | - ImageManager $imageManager |
|
52 | - ) { |
|
53 | - $this->themingDefaults = $themingDefaults; |
|
54 | - $this->util = $util; |
|
55 | - $this->imageManager = $imageManager; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param $app string app name |
|
60 | - * @return string|false image blob |
|
61 | - */ |
|
62 | - public function getFavicon($app) { |
|
63 | - if (!$this->imageManager->shouldReplaceIcons()) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - try { |
|
67 | - $favicon = new Imagick(); |
|
68 | - $favicon->setFormat("ico"); |
|
69 | - $icon = $this->renderAppIcon($app, 128); |
|
70 | - if ($icon === false) { |
|
71 | - return false; |
|
72 | - } |
|
73 | - $icon->setImageFormat("png32"); |
|
74 | - |
|
75 | - $clone = clone $icon; |
|
76 | - $clone->scaleImage(16,0); |
|
77 | - $favicon->addImage($clone); |
|
78 | - |
|
79 | - $clone = clone $icon; |
|
80 | - $clone->scaleImage(32,0); |
|
81 | - $favicon->addImage($clone); |
|
82 | - |
|
83 | - $clone = clone $icon; |
|
84 | - $clone->scaleImage(64,0); |
|
85 | - $favicon->addImage($clone); |
|
86 | - |
|
87 | - $clone = clone $icon; |
|
88 | - $clone->scaleImage(128,0); |
|
89 | - $favicon->addImage($clone); |
|
90 | - |
|
91 | - $data = $favicon->getImagesBlob(); |
|
92 | - $favicon->destroy(); |
|
93 | - $icon->destroy(); |
|
94 | - $clone->destroy(); |
|
95 | - return $data; |
|
96 | - } catch (\ImagickException $e) { |
|
97 | - return false; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $app string app name |
|
103 | - * @return string|false image blob |
|
104 | - */ |
|
105 | - public function getTouchIcon($app) { |
|
106 | - try { |
|
107 | - $icon = $this->renderAppIcon($app, 512); |
|
108 | - if ($icon === false) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - $icon->setImageFormat("png32"); |
|
112 | - $data = $icon->getImageBlob(); |
|
113 | - $icon->destroy(); |
|
114 | - return $data; |
|
115 | - } catch (\ImagickException $e) { |
|
116 | - return false; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Render app icon on themed background color |
|
122 | - * fallback to logo |
|
123 | - * |
|
124 | - * @param $app string app name |
|
125 | - * @param $size int size of the icon in px |
|
126 | - * @return Imagick|false |
|
127 | - */ |
|
128 | - public function renderAppIcon($app, $size) { |
|
129 | - $appIcon = $this->util->getAppIcon($app); |
|
130 | - if($appIcon === false) { |
|
131 | - return false; |
|
132 | - } |
|
133 | - if ($appIcon instanceof ISimpleFile) { |
|
134 | - $appIconContent = $appIcon->getContent(); |
|
135 | - $mime = $appIcon->getMimeType(); |
|
136 | - } else { |
|
137 | - $appIconContent = file_get_contents($appIcon); |
|
138 | - $mime = mime_content_type($appIcon); |
|
139 | - } |
|
140 | - |
|
141 | - if($appIconContent === false || $appIconContent === "") { |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - $color = $this->themingDefaults->getColorPrimary(); |
|
146 | - |
|
147 | - // generate background image with rounded corners |
|
148 | - $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
149 | - '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
150 | - '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
151 | - '</svg>'; |
|
152 | - // resize svg magic as this seems broken in Imagemagick |
|
153 | - if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
154 | - if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
155 | - $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
|
156 | - } else { |
|
157 | - $svg = $appIconContent; |
|
158 | - } |
|
159 | - $tmp = new Imagick(); |
|
160 | - $tmp->readImageBlob($svg); |
|
161 | - $x = $tmp->getImageWidth(); |
|
162 | - $y = $tmp->getImageHeight(); |
|
163 | - $res = $tmp->getImageResolution(); |
|
164 | - $tmp->destroy(); |
|
165 | - |
|
166 | - if($x>$y) { |
|
167 | - $max = $x; |
|
168 | - } else { |
|
169 | - $max = $y; |
|
170 | - } |
|
171 | - |
|
172 | - // convert svg to resized image |
|
173 | - $appIconFile = new Imagick(); |
|
174 | - $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
175 | - $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
176 | - $appIconFile->setResolution($resX, $resY); |
|
177 | - $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
178 | - $appIconFile->readImageBlob($svg); |
|
179 | - |
|
180 | - /** |
|
181 | - * invert app icons for bright primary colors |
|
182 | - * the default nextcloud logo will not be inverted to black |
|
183 | - */ |
|
184 | - if ($this->util->invertTextColor($color) |
|
185 | - && !$appIcon instanceof ISimpleFile |
|
186 | - && $app !== "core" |
|
187 | - ) { |
|
188 | - $appIconFile->negateImage(false); |
|
189 | - } |
|
190 | - $appIconFile->scaleImage(512, 512, true); |
|
191 | - } else { |
|
192 | - $appIconFile = new Imagick(); |
|
193 | - $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
194 | - $appIconFile->readImageBlob($appIconContent); |
|
195 | - $appIconFile->scaleImage(512, 512, true); |
|
196 | - } |
|
197 | - // offset for icon positioning |
|
198 | - $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
199 | - $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
200 | - $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
201 | - $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
202 | - $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
|
203 | - // center icon |
|
204 | - $offset_w = 512 / 2 - $innerWidth / 2; |
|
205 | - $offset_h = 512 / 2 - $innerHeight / 2; |
|
206 | - |
|
207 | - $finalIconFile = new Imagick(); |
|
208 | - $finalIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
209 | - $finalIconFile->readImageBlob($background); |
|
210 | - $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
|
211 | - $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5"); |
|
212 | - $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h); |
|
213 | - $finalIconFile->setImageFormat('png24'); |
|
214 | - if (defined("Imagick::INTERPOLATE_BICUBIC") === true) { |
|
215 | - $filter = Imagick::INTERPOLATE_BICUBIC; |
|
216 | - } else { |
|
217 | - $filter = Imagick::FILTER_LANCZOS; |
|
218 | - } |
|
219 | - $finalIconFile->resizeImage($size, $size, $filter, 1, false); |
|
220 | - |
|
221 | - $appIconFile->destroy(); |
|
222 | - return $finalIconFile; |
|
223 | - } |
|
224 | - |
|
225 | - public function colorSvg($app, $image) { |
|
226 | - try { |
|
227 | - $imageFile = $this->util->getAppImage($app, $image); |
|
228 | - } catch (AppPathNotFoundException $e) { |
|
229 | - return false; |
|
230 | - } |
|
231 | - $svg = file_get_contents($imageFile); |
|
232 | - if ($svg !== false && $svg !== "") { |
|
233 | - $color = $this->util->elementColor($this->themingDefaults->getColorPrimary()); |
|
234 | - $svg = $this->util->colorizeSvg($svg, $color); |
|
235 | - return $svg; |
|
236 | - } else { |
|
237 | - return false; |
|
238 | - } |
|
239 | - } |
|
34 | + /** @var ThemingDefaults */ |
|
35 | + private $themingDefaults; |
|
36 | + /** @var Util */ |
|
37 | + private $util; |
|
38 | + /** @var ImageManager */ |
|
39 | + private $imageManager; |
|
40 | + |
|
41 | + /** |
|
42 | + * IconBuilder constructor. |
|
43 | + * |
|
44 | + * @param ThemingDefaults $themingDefaults |
|
45 | + * @param Util $util |
|
46 | + * @param ImageManager $imageManager |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ThemingDefaults $themingDefaults, |
|
50 | + Util $util, |
|
51 | + ImageManager $imageManager |
|
52 | + ) { |
|
53 | + $this->themingDefaults = $themingDefaults; |
|
54 | + $this->util = $util; |
|
55 | + $this->imageManager = $imageManager; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param $app string app name |
|
60 | + * @return string|false image blob |
|
61 | + */ |
|
62 | + public function getFavicon($app) { |
|
63 | + if (!$this->imageManager->shouldReplaceIcons()) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + try { |
|
67 | + $favicon = new Imagick(); |
|
68 | + $favicon->setFormat("ico"); |
|
69 | + $icon = $this->renderAppIcon($app, 128); |
|
70 | + if ($icon === false) { |
|
71 | + return false; |
|
72 | + } |
|
73 | + $icon->setImageFormat("png32"); |
|
74 | + |
|
75 | + $clone = clone $icon; |
|
76 | + $clone->scaleImage(16,0); |
|
77 | + $favicon->addImage($clone); |
|
78 | + |
|
79 | + $clone = clone $icon; |
|
80 | + $clone->scaleImage(32,0); |
|
81 | + $favicon->addImage($clone); |
|
82 | + |
|
83 | + $clone = clone $icon; |
|
84 | + $clone->scaleImage(64,0); |
|
85 | + $favicon->addImage($clone); |
|
86 | + |
|
87 | + $clone = clone $icon; |
|
88 | + $clone->scaleImage(128,0); |
|
89 | + $favicon->addImage($clone); |
|
90 | + |
|
91 | + $data = $favicon->getImagesBlob(); |
|
92 | + $favicon->destroy(); |
|
93 | + $icon->destroy(); |
|
94 | + $clone->destroy(); |
|
95 | + return $data; |
|
96 | + } catch (\ImagickException $e) { |
|
97 | + return false; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $app string app name |
|
103 | + * @return string|false image blob |
|
104 | + */ |
|
105 | + public function getTouchIcon($app) { |
|
106 | + try { |
|
107 | + $icon = $this->renderAppIcon($app, 512); |
|
108 | + if ($icon === false) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + $icon->setImageFormat("png32"); |
|
112 | + $data = $icon->getImageBlob(); |
|
113 | + $icon->destroy(); |
|
114 | + return $data; |
|
115 | + } catch (\ImagickException $e) { |
|
116 | + return false; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Render app icon on themed background color |
|
122 | + * fallback to logo |
|
123 | + * |
|
124 | + * @param $app string app name |
|
125 | + * @param $size int size of the icon in px |
|
126 | + * @return Imagick|false |
|
127 | + */ |
|
128 | + public function renderAppIcon($app, $size) { |
|
129 | + $appIcon = $this->util->getAppIcon($app); |
|
130 | + if($appIcon === false) { |
|
131 | + return false; |
|
132 | + } |
|
133 | + if ($appIcon instanceof ISimpleFile) { |
|
134 | + $appIconContent = $appIcon->getContent(); |
|
135 | + $mime = $appIcon->getMimeType(); |
|
136 | + } else { |
|
137 | + $appIconContent = file_get_contents($appIcon); |
|
138 | + $mime = mime_content_type($appIcon); |
|
139 | + } |
|
140 | + |
|
141 | + if($appIconContent === false || $appIconContent === "") { |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + $color = $this->themingDefaults->getColorPrimary(); |
|
146 | + |
|
147 | + // generate background image with rounded corners |
|
148 | + $background = '<?xml version="1.0" encoding="UTF-8"?>' . |
|
149 | + '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:cc="http://creativecommons.org/ns#" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink">' . |
|
150 | + '<rect x="0" y="0" rx="100" ry="100" width="512" height="512" style="fill:' . $color . ';" />' . |
|
151 | + '</svg>'; |
|
152 | + // resize svg magic as this seems broken in Imagemagick |
|
153 | + if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") { |
|
154 | + if(substr($appIconContent, 0, 5) !== "<?xml") { |
|
155 | + $svg = "<?xml version=\"1.0\"?>".$appIconContent; |
|
156 | + } else { |
|
157 | + $svg = $appIconContent; |
|
158 | + } |
|
159 | + $tmp = new Imagick(); |
|
160 | + $tmp->readImageBlob($svg); |
|
161 | + $x = $tmp->getImageWidth(); |
|
162 | + $y = $tmp->getImageHeight(); |
|
163 | + $res = $tmp->getImageResolution(); |
|
164 | + $tmp->destroy(); |
|
165 | + |
|
166 | + if($x>$y) { |
|
167 | + $max = $x; |
|
168 | + } else { |
|
169 | + $max = $y; |
|
170 | + } |
|
171 | + |
|
172 | + // convert svg to resized image |
|
173 | + $appIconFile = new Imagick(); |
|
174 | + $resX = (int)(512 * $res['x'] / $max * 2.53); |
|
175 | + $resY = (int)(512 * $res['y'] / $max * 2.53); |
|
176 | + $appIconFile->setResolution($resX, $resY); |
|
177 | + $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
178 | + $appIconFile->readImageBlob($svg); |
|
179 | + |
|
180 | + /** |
|
181 | + * invert app icons for bright primary colors |
|
182 | + * the default nextcloud logo will not be inverted to black |
|
183 | + */ |
|
184 | + if ($this->util->invertTextColor($color) |
|
185 | + && !$appIcon instanceof ISimpleFile |
|
186 | + && $app !== "core" |
|
187 | + ) { |
|
188 | + $appIconFile->negateImage(false); |
|
189 | + } |
|
190 | + $appIconFile->scaleImage(512, 512, true); |
|
191 | + } else { |
|
192 | + $appIconFile = new Imagick(); |
|
193 | + $appIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
194 | + $appIconFile->readImageBlob($appIconContent); |
|
195 | + $appIconFile->scaleImage(512, 512, true); |
|
196 | + } |
|
197 | + // offset for icon positioning |
|
198 | + $border_w = (int)($appIconFile->getImageWidth() * 0.05); |
|
199 | + $border_h = (int)($appIconFile->getImageHeight() * 0.05); |
|
200 | + $innerWidth = (int)($appIconFile->getImageWidth() - $border_w * 2); |
|
201 | + $innerHeight = (int)($appIconFile->getImageHeight() - $border_h * 2); |
|
202 | + $appIconFile->adaptiveResizeImage($innerWidth, $innerHeight); |
|
203 | + // center icon |
|
204 | + $offset_w = 512 / 2 - $innerWidth / 2; |
|
205 | + $offset_h = 512 / 2 - $innerHeight / 2; |
|
206 | + |
|
207 | + $finalIconFile = new Imagick(); |
|
208 | + $finalIconFile->setBackgroundColor(new ImagickPixel('transparent')); |
|
209 | + $finalIconFile->readImageBlob($background); |
|
210 | + $finalIconFile->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
|
211 | + $finalIconFile->setImageArtifact('compose:args', "1,0,-0.5,0.5"); |
|
212 | + $finalIconFile->compositeImage($appIconFile, Imagick::COMPOSITE_ATOP, $offset_w, $offset_h); |
|
213 | + $finalIconFile->setImageFormat('png24'); |
|
214 | + if (defined("Imagick::INTERPOLATE_BICUBIC") === true) { |
|
215 | + $filter = Imagick::INTERPOLATE_BICUBIC; |
|
216 | + } else { |
|
217 | + $filter = Imagick::FILTER_LANCZOS; |
|
218 | + } |
|
219 | + $finalIconFile->resizeImage($size, $size, $filter, 1, false); |
|
220 | + |
|
221 | + $appIconFile->destroy(); |
|
222 | + return $finalIconFile; |
|
223 | + } |
|
224 | + |
|
225 | + public function colorSvg($app, $image) { |
|
226 | + try { |
|
227 | + $imageFile = $this->util->getAppImage($app, $image); |
|
228 | + } catch (AppPathNotFoundException $e) { |
|
229 | + return false; |
|
230 | + } |
|
231 | + $svg = file_get_contents($imageFile); |
|
232 | + if ($svg !== false && $svg !== "") { |
|
233 | + $color = $this->util->elementColor($this->themingDefaults->getColorPrimary()); |
|
234 | + $svg = $this->util->colorizeSvg($svg, $color); |
|
235 | + return $svg; |
|
236 | + } else { |
|
237 | + return false; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @package OCP |
30 | 30 | * @since 7.0.0 |
31 | 31 | */ |
32 | -interface ICacheFactory{ |
|
32 | +interface ICacheFactory { |
|
33 | 33 | /** |
34 | 34 | * Get a distributed memory cache instance |
35 | 35 | * |
@@ -31,58 +31,58 @@ |
||
31 | 31 | * @since 7.0.0 |
32 | 32 | */ |
33 | 33 | interface ICacheFactory{ |
34 | - /** |
|
35 | - * Get a distributed memory cache instance |
|
36 | - * |
|
37 | - * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps |
|
38 | - * |
|
39 | - * @param string $prefix |
|
40 | - * @return ICache |
|
41 | - * @since 7.0.0 |
|
42 | - * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal |
|
43 | - */ |
|
44 | - public function create(string $prefix = ''): ICache; |
|
34 | + /** |
|
35 | + * Get a distributed memory cache instance |
|
36 | + * |
|
37 | + * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps |
|
38 | + * |
|
39 | + * @param string $prefix |
|
40 | + * @return ICache |
|
41 | + * @since 7.0.0 |
|
42 | + * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal |
|
43 | + */ |
|
44 | + public function create(string $prefix = ''): ICache; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Check if any memory cache backend is available |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - * @since 7.0.0 |
|
51 | - */ |
|
52 | - public function isAvailable(): bool; |
|
46 | + /** |
|
47 | + * Check if any memory cache backend is available |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + * @since 7.0.0 |
|
51 | + */ |
|
52 | + public function isAvailable(): bool; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Check if a local memory cache backend is available |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - * @since 14.0.0 |
|
59 | - */ |
|
60 | - public function isLocalCacheAvailable(): bool; |
|
54 | + /** |
|
55 | + * Check if a local memory cache backend is available |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + * @since 14.0.0 |
|
59 | + */ |
|
60 | + public function isLocalCacheAvailable(): bool; |
|
61 | 61 | |
62 | - /** |
|
63 | - * create a cache instance for storing locks |
|
64 | - * |
|
65 | - * @param string $prefix |
|
66 | - * @return IMemcache |
|
67 | - * @since 13.0.0 |
|
68 | - */ |
|
69 | - public function createLocking(string $prefix = ''): IMemcache; |
|
62 | + /** |
|
63 | + * create a cache instance for storing locks |
|
64 | + * |
|
65 | + * @param string $prefix |
|
66 | + * @return IMemcache |
|
67 | + * @since 13.0.0 |
|
68 | + */ |
|
69 | + public function createLocking(string $prefix = ''): IMemcache; |
|
70 | 70 | |
71 | - /** |
|
72 | - * create a distributed cache instance |
|
73 | - * |
|
74 | - * @param string $prefix |
|
75 | - * @return ICache |
|
76 | - * @since 13.0.0 |
|
77 | - */ |
|
78 | - public function createDistributed(string $prefix = ''): ICache; |
|
71 | + /** |
|
72 | + * create a distributed cache instance |
|
73 | + * |
|
74 | + * @param string $prefix |
|
75 | + * @return ICache |
|
76 | + * @since 13.0.0 |
|
77 | + */ |
|
78 | + public function createDistributed(string $prefix = ''): ICache; |
|
79 | 79 | |
80 | - /** |
|
81 | - * create a local cache instance |
|
82 | - * |
|
83 | - * @param string $prefix |
|
84 | - * @return ICache |
|
85 | - * @since 13.0.0 |
|
86 | - */ |
|
87 | - public function createLocal(string $prefix = ''): ICache; |
|
80 | + /** |
|
81 | + * create a local cache instance |
|
82 | + * |
|
83 | + * @param string $prefix |
|
84 | + * @return ICache |
|
85 | + * @since 13.0.0 |
|
86 | + */ |
|
87 | + public function createLocal(string $prefix = ''): ICache; |
|
88 | 88 | } |
@@ -31,76 +31,76 @@ |
||
31 | 31 | |
32 | 32 | class SameSiteCookieMiddleware extends Middleware { |
33 | 33 | |
34 | - /** @var Request */ |
|
35 | - private $request; |
|
36 | - |
|
37 | - /** @var ControllerMethodReflector */ |
|
38 | - private $reflector; |
|
39 | - |
|
40 | - public function __construct(Request $request, |
|
41 | - ControllerMethodReflector $reflector) { |
|
42 | - $this->request = $request; |
|
43 | - $this->reflector = $reflector; |
|
44 | - } |
|
45 | - |
|
46 | - public function beforeController($controller, $methodName) { |
|
47 | - $requestUri = $this->request->getScriptName(); |
|
48 | - $processingScript = explode('/', $requestUri); |
|
49 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
50 | - |
|
51 | - if ($processingScript !== 'index.php') { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
56 | - if ($noSSC) { |
|
57 | - return; |
|
58 | - } |
|
59 | - |
|
60 | - if (!$this->request->passesLaxCookieCheck()) { |
|
61 | - throw new LaxSameSiteCookieFailedException(); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
66 | - if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
67 | - $respone = new Response(); |
|
68 | - $respone->setStatus(Http::STATUS_FOUND); |
|
69 | - $respone->addHeader('Location', $this->request->getRequestUri()); |
|
70 | - |
|
71 | - $this->setSameSiteCookie(); |
|
72 | - |
|
73 | - return $respone; |
|
74 | - } |
|
75 | - |
|
76 | - throw $exception; |
|
77 | - } |
|
78 | - |
|
79 | - protected function setSameSiteCookie() { |
|
80 | - $cookieParams = $this->request->getCookieParams(); |
|
81 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
82 | - $policies = [ |
|
83 | - 'lax', |
|
84 | - 'strict', |
|
85 | - ]; |
|
86 | - |
|
87 | - // Append __Host to the cookie if it meets the requirements |
|
88 | - $cookiePrefix = ''; |
|
89 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | - $cookiePrefix = '__Host-'; |
|
91 | - } |
|
92 | - |
|
93 | - foreach($policies as $policy) { |
|
94 | - header( |
|
95 | - sprintf( |
|
96 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | - $cookiePrefix, |
|
98 | - $policy, |
|
99 | - $cookieParams['path'], |
|
100 | - $policy |
|
101 | - ), |
|
102 | - false |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
34 | + /** @var Request */ |
|
35 | + private $request; |
|
36 | + |
|
37 | + /** @var ControllerMethodReflector */ |
|
38 | + private $reflector; |
|
39 | + |
|
40 | + public function __construct(Request $request, |
|
41 | + ControllerMethodReflector $reflector) { |
|
42 | + $this->request = $request; |
|
43 | + $this->reflector = $reflector; |
|
44 | + } |
|
45 | + |
|
46 | + public function beforeController($controller, $methodName) { |
|
47 | + $requestUri = $this->request->getScriptName(); |
|
48 | + $processingScript = explode('/', $requestUri); |
|
49 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
50 | + |
|
51 | + if ($processingScript !== 'index.php') { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
56 | + if ($noSSC) { |
|
57 | + return; |
|
58 | + } |
|
59 | + |
|
60 | + if (!$this->request->passesLaxCookieCheck()) { |
|
61 | + throw new LaxSameSiteCookieFailedException(); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
66 | + if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
67 | + $respone = new Response(); |
|
68 | + $respone->setStatus(Http::STATUS_FOUND); |
|
69 | + $respone->addHeader('Location', $this->request->getRequestUri()); |
|
70 | + |
|
71 | + $this->setSameSiteCookie(); |
|
72 | + |
|
73 | + return $respone; |
|
74 | + } |
|
75 | + |
|
76 | + throw $exception; |
|
77 | + } |
|
78 | + |
|
79 | + protected function setSameSiteCookie() { |
|
80 | + $cookieParams = $this->request->getCookieParams(); |
|
81 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
82 | + $policies = [ |
|
83 | + 'lax', |
|
84 | + 'strict', |
|
85 | + ]; |
|
86 | + |
|
87 | + // Append __Host to the cookie if it meets the requirements |
|
88 | + $cookiePrefix = ''; |
|
89 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | + $cookiePrefix = '__Host-'; |
|
91 | + } |
|
92 | + |
|
93 | + foreach($policies as $policy) { |
|
94 | + header( |
|
95 | + sprintf( |
|
96 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | + $cookiePrefix, |
|
98 | + $policy, |
|
99 | + $cookieParams['path'], |
|
100 | + $policy |
|
101 | + ), |
|
102 | + false |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function beforeController($controller, $methodName) { |
47 | 47 | $requestUri = $this->request->getScriptName(); |
48 | 48 | $processingScript = explode('/', $requestUri); |
49 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
49 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
50 | 50 | |
51 | 51 | if ($processingScript !== 'index.php') { |
52 | 52 | return; |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | |
87 | 87 | // Append __Host to the cookie if it meets the requirements |
88 | 88 | $cookiePrefix = ''; |
89 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
89 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
90 | 90 | $cookiePrefix = '__Host-'; |
91 | 91 | } |
92 | 92 | |
93 | - foreach($policies as $policy) { |
|
93 | + foreach ($policies as $policy) { |
|
94 | 94 | header( |
95 | 95 | sprintf( |
96 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
96 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
97 | 97 | $cookiePrefix, |
98 | 98 | $policy, |
99 | 99 | $cookieParams['path'], |