Skip to content

Commit

Permalink
use code compatible with PHP 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Jun 21, 2022
1 parent aa9d124 commit 9c2ff78
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions MatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public function __construct($idSite, $apiUrl = '')
$this->userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : false;
$this->clientHints = [];
$this->setClientHints(
$_SERVER['HTTP_SEC_CH_UA_MODEL'] ?? '',
$_SERVER['HTTP_SEC_CH_UA_PLATFORM'] ?? '',
$_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] ?? '',
$_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] ?? '',
$_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] ?? ''
!empty($_SERVER['HTTP_SEC_CH_UA_MODEL']) ? $_SERVER['HTTP_SEC_CH_UA_MODEL'] : '',
!empty($_SERVER['HTTP_SEC_CH_UA_PLATFORM']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM'] : '',
!empty($_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] : '',
!empty($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] : '',
!empty($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] : ''
);
if (!empty($apiUrl)) {
self::$URL = $apiUrl;
Expand Down Expand Up @@ -494,6 +494,8 @@ public function setUserAgent($userAgent)
* Sets the client hints, used to detect OS and browser.
* If this function is not called, the client hints sent with the current request will be used.
*
* Supported as of Matomo 4.12.0
*
* @param string $model Value of the header 'HTTP_SEC_CH_UA_MODEL'
* @param string $platform Value of the header 'HTTP_SEC_CH_UA_PLATFORM'
* @param string $platformVersion Value of the header 'HTTP_SEC_CH_UA_PLATFORM_VERSION'
Expand All @@ -510,9 +512,9 @@ public function setClientHints($model = '', $platform = '', $platformVersion = '
$reg = '/^"([^"]+)"; ?v="([^"]+)"(?:, )?/';
$list = [];

while (\preg_match($reg, $value, $matches)) {
while (\preg_match($reg, $fullVersionList, $matches)) {
$list[] = ['brand' => $matches[1], 'version' => $matches[2]];
$value = \substr($value, \strlen($matches[0]));
$fullVersionList = \substr($fullVersionList, \strlen($matches[0]));
}

$fullVersionList = $list;
Expand Down Expand Up @@ -1751,7 +1753,6 @@ protected function sendRequest($url, $method = 'GET', $data = null, $force = fal
$this->storedTrackingActions[]
= $url
. (!empty($this->userAgent) ? ('&ua=' . urlencode($this->userAgent)) : '')
. (!empty($this->clientHints) ? ('&uadata=' . urlencode(json_encode($this->clientHints))) : '')
. (!empty($this->acceptLanguage) ? ('&lang=' . urlencode($this->acceptLanguage)) : '');

// Clear custom variables & dimensions so they don't get copied over to other users in the bulk request
Expand Down Expand Up @@ -1953,6 +1954,9 @@ protected function getRequest($idSite)
$customFields . $customDimensions .
(!$this->sendImageResponse ? '&send_image=0' : '') .

// client hints
(!empty($this->clientHints) ? ('&uadata=' . urlencode(json_encode($this->clientHints))) : '') .

// DEBUG
$this->DEBUG_APPEND_URL;

Expand Down

0 comments on commit 9c2ff78

Please sign in to comment.