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

VisitorDetails.php « DevicesDetection « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50c1e8c239c792fb4af661d7594d073c33dd80d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */

namespace Piwik\Plugins\DevicesDetection;

use Piwik\Piwik;
use Piwik\Plugins\Live\VisitorDetailsAbstract;

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 getModelName($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']);
    }

    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');
        if ($deviceBrand == Piwik::translate('General_Unknown')) {
            $deviceName = $deviceModel;
        } else {
            $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;
        });

        $devices = [];

        foreach ($this->devices as $type => $devicesData) {
            $typeDevices = [];
            foreach ($devicesData['devices'] as $name => $count) {
                $typeDevices[] = [
                    'name'  => $name,
                    'count' => $count
                ];
            }
            $devices[] = [
                'type'    => $type,
                'count'   => $devicesData['count'],
                'icon'    => $devicesData['icon'],
                'devices' => $typeDevices,
            ];
        }

        $profile['devices'] = $devices;
    }
}