Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/DevicesDetection/VisitorDetails.php')
-rw-r--r--plugins/DevicesDetection/VisitorDetails.php175
1 files changed, 175 insertions, 0 deletions
diff --git a/plugins/DevicesDetection/VisitorDetails.php b/plugins/DevicesDetection/VisitorDetails.php
new file mode 100644
index 0000000000..d358c2d1ef
--- /dev/null
+++ b/plugins/DevicesDetection/VisitorDetails.php
@@ -0,0 +1,175 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\DevicesDetection;
+
+use Piwik\Plugins\Live\VisitorDetailsAbstract;
+use Piwik\View;
+
+require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php';
+
+class VisitorDetails extends VisitorDetailsAbstract
+{
+ public function extendVisitorDetails(&$visitor)
+ {
+ $visitor['deviceType'] = $this->getDeviceType();
+ $visitor['deviceTypeIcon'] = $this->getDeviceTypeIcon();
+ $visitor['deviceBrand'] = $this->getDeviceBrand();
+ $visitor['deviceModel'] = $this->getDeviceModel();
+ $visitor['operatingSystem'] = $this->getOperatingSystem();
+ $visitor['operatingSystemName'] = $this->getOperatingSystemName();
+ $visitor['operatingSystemIcon'] = $this->getOperatingSystemIcon();
+ $visitor['operatingSystemCode'] = $this->getOperatingSystemCode();
+ $visitor['operatingSystemVersion'] = $this->getOperatingSystemVersion();
+ $visitor['browserFamily'] = $this->getBrowserEngine();
+ $visitor['browserFamilyDescription'] = $this->getBrowserEngineDescription();
+ $visitor['browser'] = $this->getBrowser();
+ $visitor['browserName'] = $this->getBrowserName();
+ $visitor['browserIcon'] = $this->getBrowserIcon();
+ $visitor['browserCode'] = $this->getBrowserCode();
+ $visitor['browserVersion'] = $this->getBrowserVersion();
+ }
+
+ protected function getDeviceType()
+ {
+ return getDeviceTypeLabel($this->details['config_device_type']);
+ }
+
+ protected function getDeviceTypeIcon()
+ {
+ return getDeviceTypeLogo($this->details['config_device_type']);
+ }
+
+ protected function getDeviceBrand()
+ {
+ return getDeviceBrandLabel($this->details['config_device_brand']);
+ }
+
+ protected function getDeviceModel()
+ {
+ return $this->details['config_device_model'];
+ }
+
+ protected function getOperatingSystemCode()
+ {
+ return $this->details['config_os'];
+ }
+
+ protected function getOperatingSystem()
+ {
+ return getOsFullName($this->details['config_os'] . ";" . $this->details['config_os_version']);
+ }
+
+ protected function getOperatingSystemName()
+ {
+ return getOsFullName($this->details['config_os']);
+ }
+
+ protected function getOperatingSystemVersion()
+ {
+ return $this->details['config_os_version'];
+ }
+
+ protected function getOperatingSystemIcon()
+ {
+ return getOsLogo($this->details['config_os']);
+ }
+
+ protected function getBrowserEngineDescription()
+ {
+ return getBrowserEngineName($this->getBrowserEngine());
+ }
+
+ protected function getBrowserEngine()
+ {
+ return $this->details['config_browser_engine'];
+ }
+
+ protected function getBrowserCode()
+ {
+ return $this->details['config_browser_name'];
+ }
+
+ protected function getBrowserVersion()
+ {
+ return $this->details['config_browser_version'];
+ }
+
+ protected function getBrowser()
+ {
+ return getBrowserNameWithVersion($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']);
+ }
+
+ protected function getBrowserName()
+ {
+ return getBrowserName($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']);
+ }
+
+ protected function getBrowserIcon()
+ {
+ return getBrowserLogo($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']);
+ }
+
+
+ private $devices = array();
+
+ public function initProfile($visits, &$profile)
+ {
+ $this->devices = array();
+ }
+
+ public function handleProfileVisit($visit, &$profile)
+ {
+ $deviceType = $visit->getColumn('deviceType');
+ $deviceTypeIcon = $visit->getColumn('deviceTypeIcon');
+ $deviceBrand = $visit->getColumn('deviceBrand');
+ $deviceModel = $visit->getColumn('deviceModel');
+ $deviceName = trim($deviceBrand . " " . $deviceModel);
+
+ if (!isset($this->devices[$deviceType])) {
+ $this->devices[$deviceType] = array(
+ 'count' => 0,
+ 'icon' => $deviceTypeIcon,
+ 'devices' => array()
+ );
+ }
+
+ ++$this->devices[$deviceType]['count'];
+
+ if (!isset($this->devices[$deviceType]['devices'][$deviceName])) {
+ $this->devices[$deviceType]['devices'][$deviceName] = 0;
+ }
+
+ ++$this->devices[$deviceType]['devices'][$deviceName];
+ }
+
+ public function finalizeProfile($visits, &$profile)
+ {
+ $devices = $this->devices;
+ uksort($this->devices, function($a, $b) use ($devices) {
+ $cmp = strcmp($devices[$b]['count'], $devices[$a]['count']);
+ if (0 == $cmp) {
+ $cmp = strcmp($a, $b);
+ }
+ return $cmp;
+ });
+
+ foreach ($this->devices as $type => $devicesData) {
+ $typeDevices = [];
+ foreach ($devicesData['devices'] as $name => $count) {
+ $typeDevices[] = [
+ 'name' => $name,
+ 'count' => $count
+ ];
+ }
+ $this->devices[$type]['devices'] = $typeDevices;
+ }
+
+ $profile['devices'] = $this->devices;
+ }
+} \ No newline at end of file