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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_MobileMessaging_ReportRenderer
*/
/**
*
* @package Piwik_MobileMessaging_ReportRenderer
*/
class Piwik_MobileMessaging_ReportRenderer_Sms extends Piwik_ReportRenderer
{
const FLOAT_REGEXP = '/[-+]?[0-9]*[\.,]?[0-9]+/';
const SMS_CONTENT_TYPE = 'text/plain';
const SMS_FILE_EXTENSION = 'sms';
private $rendering = "";
public function setLocale($locale)
{
// nothing to do
}
public function sendToDisk($filename)
{
return Piwik_ReportRenderer::writeFile($filename, self::SMS_FILE_EXTENSION, $this->rendering);
}
public function sendToBrowserDownload($filename)
{
Piwik_ReportRenderer::sendToBrowser($filename, self::SMS_FILE_EXTENSION, self::SMS_CONTENT_TYPE, $this->rendering);
}
public function sendToBrowserInline($filename)
{
Piwik_ReportRenderer::inlineToBrowser(self::SMS_CONTENT_TYPE, $this->rendering);
}
public function getRenderedReport()
{
return $this->rendering;
}
public function renderFrontPage($websiteName, $prettyDate, $description, $reportMetadata)
{
// nothing to do
}
public function renderReport($processedReport)
{
$isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
$prettyDate = $processedReport['prettyDate'];
$reportData = $processedReport['reportData'];
$evolutionMetrics = array();
$multiSitesAPIMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced = true);
foreach ($multiSitesAPIMetrics as $metricSettings) {
$evolutionMetrics[] = $metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY];
}
// no decimal for all metrics to shorten SMS content (keeps the monetary sign for revenue metrics)
$reportData->filter(
'ColumnCallbackReplace',
array(
array_merge(array_keys($multiSitesAPIMetrics), $evolutionMetrics),
create_function(
'$value',
'
return preg_replace_callback (
"' . self::FLOAT_REGEXP . '",
create_function (
\'$matches\',
\'return round($matches[0]);\'
),
$value
);
'
)
)
);
// evolution metrics formatting :
// - remove monetary, percentage and white spaces to shorten SMS content
// (this is also needed to be able to test $value != 0 and see if there is an evolution at all in SMSReport.tpl)
// - adds a plus sign
$reportData->filter(
'ColumnCallbackReplace',
array(
$evolutionMetrics,
create_function(
'$value',
'
$matched = preg_match("' . self::FLOAT_REGEXP . '", $value, $matches);
return $matched ? sprintf("%+d",$matches[0]) : $value;
'
)
)
);
$dataRows = $reportData->getRows();
$reportMetadata = $processedReport['reportMetadata'];
$reportRowsMetadata = $reportMetadata->getRows();
$siteHasECommerce = array();
foreach ($reportRowsMetadata as $rowMetadata) {
$idSite = $rowMetadata->getColumn('idsite');
$siteHasECommerce[$idSite] = Piwik_Site::isEcommerceEnabledFor($idSite);
}
$smarty = new Piwik_Smarty();
$smarty->assign("isGoalPluginEnabled", $isGoalPluginEnabled);
$smarty->assign("reportRows", $dataRows);
$smarty->assign("reportRowsMetadata", $reportRowsMetadata);
$smarty->assign("prettyDate", $prettyDate);
$smarty->assign("siteHasECommerce", $siteHasECommerce);
$smarty->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll');
$this->rendering .= $smarty->fetch(PIWIK_USER_PATH . '/plugins/MobileMessaging/templates/SMSReport.tpl');
}
}
|