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
|
<?php
/**
* Piwik - 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\Actions\DataTable\Filter;
use Piwik\Common;
use Piwik\Config;
use Piwik\DataTable\BaseFilter;
use Piwik\DataTable\Row;
use Piwik\DataTable;
use Piwik\Tracker\Action;
class Actions extends BaseFilter
{
private $actionType;
/**
* Constructor.
*
* @param DataTable $table The table to eventually filter.
* @param bool $isPageTitleType Whether we are handling page title or regular URL
*/
public function __construct($table, $actionType)
{
parent::__construct($table);
$this->actionType = $actionType;
}
/**
* @param DataTable $table
*/
public function filter($table)
{
$table->filter(function (DataTable $dataTable) {
$site = $dataTable->getMetadata('site');
$urlPrefix = $site ? $site->getMainUrl() : null;
$defaultActionName = Config::getInstance()->General['action_default_name'];
$isPageTitleType = $this->actionType == Action::TYPE_PAGE_TITLE;
// for BC, we read the old style delimiter first (see #1067)
$actionDelimiter = @Config::getInstance()->General['action_category_delimiter'];
if (empty($actionDelimiter)) {
if ($isPageTitleType) {
$actionDelimiter = Config::getInstance()->General['action_title_category_delimiter'];
} else {
$actionDelimiter = Config::getInstance()->General['action_url_category_delimiter'];
}
}
foreach ($dataTable->getRows() as $row) {
if (!$row->isSummaryRow()) {
$url = $row->getMetadata('url');
$pageTitlePath = $row->getMetadata('page_title_path');
$folderUrlStart = $row->getMetadata('folder_url_start');
$label = $row->getColumn('label');
if ($url) {
$row->setMetadata('segmentValue', urldecode($url));
} else if ($folderUrlStart) {
$row->setMetadata('segment', 'pageUrl=^' . urlencode(urlencode($folderUrlStart)));
} else if ($pageTitlePath) {
if ($row->getIdSubDataTable()) {
$row->setMetadata('segment', 'pageTitle=^' . urlencode(urlencode(trim(urldecode($pageTitlePath)))));
} else {
$row->setMetadata('segmentValue', trim(urldecode($pageTitlePath)));
}
} else if ($isPageTitleType && !in_array($label, [DataTable::LABEL_SUMMARY_ROW])) {
// for older data w/o page_title_path metadata
if ($row->getIdSubDataTable()) {
$row->setMetadata('segment', 'pageTitle=^' . urlencode(urlencode(trim(urldecode($label)))));
} else {
$row->setMetadata('segmentValue', trim(urldecode($label)));
}
} else if ($this->actionType == Action::TYPE_PAGE_URL && $urlPrefix) { // folder for older data w/ no folder URL metadata
$row->setMetadata('segment', 'pageUrl=^' . urlencode(urlencode($urlPrefix . '/' . $label)));
}
}
// remove the default action name 'index' in the end of flattened urls and prepend $actionDelimiter
if (Common::getRequestVar('flat', 0)) {
$label = $row->getColumn('label');
$stringToSearch = $actionDelimiter.$defaultActionName;
if (substr($label, -strlen($stringToSearch)) == $stringToSearch) {
$label = substr($label, 0, -strlen($defaultActionName));
$label = rtrim($label, $actionDelimiter) . $actionDelimiter;
$row->setColumn('label', $label);
}
$dataTable->setLabelsHaveChanged();
}
$row->deleteMetadata('folder_url_start');
$row->deleteMetadata('page_title_path');
}
});
// TODO can we remove this one again?
$table->queueFilter('GroupBy', array('label', function ($label) {
return urldecode($label);
}));
foreach ($table->getRowsWithoutSummaryRow() as $row) {
$subtable = $row->getSubtable();
if ($subtable) {
$this->filter($subtable);
}
}
}
}
|