Skip to content

Commit

Permalink
changed mobile user agent check
Browse files Browse the repository at this point in the history
  • Loading branch information
memurats committed May 8, 2024
1 parent c5361cc commit 87118b8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ public function __construct(
$this->request = $request;
$this->nonceManager = $nonceManager;
$this->mobileUserAgents = $config->getSystemValue('nmc_marketing.mobile_user_agents', [
'/^Mozilla\/5\.0 \(Android\) Nextcloud\-android\/(?<version>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)).*$/',
'/^Mozilla\/5\.0 \(iOS\) Nextcloud\-iOS\/(?<version>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)).*$/',
]);
'Nextcloud-android',
'MagentaCLOUD-android',
'Magenta-android',
'Nextcloud-iOS',
'MagentaCLOUD-iOS',
'Nextcloud iOS',
'MagentaCLOUD iOS',
'Magenta-iOS',
'(Android)',
'(iOS)',
]);
}

public function handle(Event $event): void {
Expand Down Expand Up @@ -64,12 +72,13 @@ public function handle(Event $event): void {
* Check whether request comes from a mobile client
*/
private function isMobileUserAgent(string $userAgent): bool {

foreach ($this->mobileUserAgents as $mobileUserAgent) {

if (preg_match($mobileUserAgent, $userAgent, $matches)) {
if (str_contains($userAgent, $mobileUserAgent)) {
return true;
}
}

return false;
}
}

0 comments on commit 87118b8

Please sign in to comment.