Skip to content

Commit

Permalink
Merge pull request #58 from nextmcloud/nmc/disable-mobile-consent
Browse files Browse the repository at this point in the history
changed mobile user agent check
  • Loading branch information
memurats authored May 8, 2024
2 parents 21fd574 + d6346fb commit 4af2be9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ 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)',
]);
}

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 4af2be9

Please sign in to comment.