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
|
<?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\Live;
use Piwik\Cache;
use Piwik\CacheId;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Container\StaticContainer;
/**
*
*/
class Live extends \Piwik\Plugin
{
/**
* @see \Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Live.renderAction' => 'renderAction',
'Live.renderActionTooltip' => 'renderActionTooltip',
'Live.renderVisitorDetails' => 'renderVisitorDetails',
'Live.renderVisitorIcons' => 'renderVisitorIcons',
'Template.jsGlobalVariables' => 'addJsGlobalVariables',
'API.getPagesComparisonsDisabledFor' => 'getPagesComparisonsDisabledFor',
);
}
public function getPagesComparisonsDisabledFor(&$pages)
{
$pages[] = 'General_Visitors.Live_VisitorLog';
$pages[] = 'General_Visitors.General_RealTime';
}
public function addJsGlobalVariables(&$out)
{
$actionsToDisplayCollapsed = (int)StaticContainer::get('Live.pageViewActionsToDisplayCollapsed');
$out .= "
piwik.visitorLogActionsToDisplayCollapsed = $actionsToDisplayCollapsed;
";
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/Live/stylesheets/live.less";
$stylesheets[] = "plugins/Live/stylesheets/visitor_profile.less";
}
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "node_modules/visibilityjs/lib/visibility.core.js";
$jsFiles[] = "plugins/Live/javascripts/live.js";
$jsFiles[] = "plugins/Live/javascripts/SegmentedVisitorLog.js";
$jsFiles[] = "plugins/Live/javascripts/visitorActions.js";
$jsFiles[] = "plugins/Live/javascripts/visitorProfile.js";
$jsFiles[] = "plugins/Live/javascripts/visitorLog.js";
$jsFiles[] = "plugins/Live/javascripts/rowaction.js";
$jsFiles[] = "plugins/Live/angularjs/live-widget-refresh/live-widget-refresh.directive.js";
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = "Live_VisitorProfile";
$translationKeys[] = "Live_ClickToViewAllActions";
$translationKeys[] = "Live_NoMoreVisits";
$translationKeys[] = "Live_ShowMap";
$translationKeys[] = "Live_HideMap";
$translationKeys[] = "Live_PageRefreshed";
$translationKeys[] = "Live_RowActionTooltipTitle";
$translationKeys[] = "Live_RowActionTooltipDefault";
$translationKeys[] = "Live_RowActionTooltipWithDimension";
$translationKeys[] = "Live_SegmentedVisitorLogTitle";
$translationKeys[] = "General_Segment";
$translationKeys[] = "General_And";
$translationKeys[] = 'Live_ClickToSeeAllContents';
}
public function renderAction(&$renderedAction, $action, $previousAction, $visitorDetails)
{
$visitorDetailsInstances = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsInstances as $instance) {
$renderedAction .= $instance->renderAction($action, $previousAction, $visitorDetails);
}
}
public function renderActionTooltip(&$tooltip, $action, $visitInfo)
{
$detailEntries = [];
$visitorDetailsInstances = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsInstances as $instance) {
$detailEntries = array_merge($detailEntries, $instance->renderActionTooltip($action, $visitInfo));
}
usort($detailEntries, function($a, $b) {
return version_compare($a[0], $b[0]);
});
foreach ($detailEntries AS $detailEntry) {
$tooltip .= $detailEntry[1];
}
}
public function renderVisitorDetails(&$renderedDetails, $visitorDetails)
{
$detailEntries = [];
$visitorDetailsInstances = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsInstances as $instance) {
$detailEntries = array_merge($detailEntries, $instance->renderVisitorDetails($visitorDetails));
}
usort($detailEntries, function($a, $b) {
return version_compare($a[0], $b[0]);
});
foreach ($detailEntries AS $detailEntry) {
$renderedDetails .= $detailEntry[1];
}
}
public function renderVisitorIcons(&$renderedDetails, $visitorDetails)
{
$visitorDetailsInstances = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsInstances as $instance) {
$renderedDetails .= $instance->renderIcons($visitorDetails);
}
}
/**
* Returns the segment for the most recent visitor id
*
* This method uses the transient cache to ensure it returns always the same id within one request
* as `Request::processRequest('Live.getMostRecentVisitorId')` might return different ids on each call
*
* @return mixed|string
*/
public static function getSegmentWithVisitorId()
{
$cache = Cache::getTransientCache();
$cacheId = 'segmentWithVisitorId';
if ($cache->contains($cacheId)) {
return $cache->fetch($cacheId);
}
$segment = Request::getRawSegmentFromRequest();
if (!empty($segment)) {
$segment = urldecode($segment) . ';';
}
$idVisitor = Common::getRequestVar('visitorId', false);
if ($idVisitor === false) {
$idVisitor = Request::processRequest('Live.getMostRecentVisitorId');
}
$result = urlencode($segment . 'visitorId==' . $idVisitor);
$cache->save($cacheId, $result);
return $result;
}
}
|