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
|
<?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\VisitsSummary;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Plugins\CoreVisualizations\Visualizations\Sparklines;
use Piwik\SettingsPiwik;
use Piwik\Site;
use Piwik\Translation\Translator;
use Piwik\View;
/**
*
*/
class Controller extends \Piwik\Plugin\Controller
{
/**
* @var Translator
*/
private $translator;
public function __construct(Translator $translator)
{
$this->translator = $translator;
parent::__construct();
}
/**
* @deprecated used to be a widgetized URL. There to not break widget URLs
*/
public function getSparklines()
{
$_GET['forceView'] = '1';
$_GET['viewDataTable'] = Sparklines::ID;
return FrontController::getInstance()->fetchDispatch('VisitsSummary', 'get');
}
/**
* @deprecated used to be a widgetized URL. There to not break widget URLs
*/
public function index()
{
$_GET['containerId'] = 'VisitOverviewWithGraph';
return FrontController::getInstance()->fetchDispatch('CoreHome', 'renderWidgetContainer');
}
public function getEvolutionGraph()
{
$this->checkSitePermission();
$columns = Common::getRequestVar('columns', false);
if (false !== $columns) {
$columns = Piwik::getArrayFromApiParameter($columns);
}
$documentation = $this->translator->translate('VisitsSummary_VisitsSummaryDocumentation') . '<br />'
. $this->translator->translate('General_BrokenDownReportDocumentation') . '<br /><br />'
. '<b>' . $this->translator->translate('General_ColumnNbVisits') . ':</b> '
. $this->translator->translate('General_ColumnNbVisitsDocumentation') . '<br />'
. '<b>' . $this->translator->translate('General_ColumnNbUniqVisitors') . ':</b> '
. $this->translator->translate('General_ColumnNbUniqVisitorsDocumentation') . '<br />'
. '<b>' . $this->translator->translate('General_ColumnNbActions') . ':</b> '
. $this->translator->translate('General_ColumnNbActionsDocumentation') . '<br />'
. '<b>' . $this->translator->translate('General_ColumnNbUsers') . ':</b> '
. $this->translator->translate('General_ColumnNbUsersDocumentation') . ' (<a rel="noreferrer noopener" target="_blank" href="https://matomo.org/docs/user-id/">User ID</a>)<br />'
. '<b>' . $this->translator->translate('General_ColumnActionsPerVisit') . ':</b> '
. $this->translator->translate('General_ColumnActionsPerVisitDocumentation');
$selectableColumns = array(
// columns from VisitsSummary.get
'nb_visits',
'nb_uniq_visitors',
'nb_users',
'avg_time_on_site',
'bounce_rate',
'nb_actions_per_visit',
'max_actions',
'nb_visits_converted',
// columns from Actions.get
'nb_pageviews',
'nb_uniq_pageviews',
'nb_downloads',
'nb_uniq_downloads',
'nb_outlinks',
'nb_uniq_outlinks',
'avg_time_generation'
);
$currentPeriod = Common::getRequestVar('period', false);
if (!SettingsPiwik::isUniqueVisitorsEnabled($currentPeriod)) {
$selectableColumns = array_diff($selectableColumns, ['nb_uniq_visitors', 'nb_users']);
}
$displaySiteSearch = Site::isSiteSearchEnabledFor($this->idSite);
if ($displaySiteSearch) {
$selectableColumns[] = 'nb_searches';
$selectableColumns[] = 'nb_keywords';
}
// $callingAction may be specified to distinguish between
// "VisitsSummary_WidgetLastVisits" and "VisitsSummary_WidgetOverviewGraph"
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
$selectableColumns, $documentation);
if (empty($view->config->columns_to_display)) {
$view->config->columns_to_display = array('nb_visits');
}
return $this->renderView($view);
}
public static function getVisitsSummary()
{
$result = Request::processRequest("VisitsSummary.get", array(
// we disable filters for example "search for pattern", in the case this method is called
// by a method that already calls the API with some generic filters applied
'disable_generic_filters' => 1,
'columns' => false
));
return empty($result) ? new DataTable() : $result;
}
}
|