PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / ReportRenderer / Html.php
matomo / app / core / ReportRenderer Last commit date
Csv.php 5 years ago Html.php 5 years ago Pdf.php 5 years ago Tsv.php 5 years ago
Html.php
184 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9 namespace Piwik\ReportRenderer;
10
11 use Piwik\Mail;
12 use Piwik\Piwik;
13 use Piwik\ReportRenderer;
14 use Piwik\View;
15
16 /**
17 * HTML report renderer
18 */
19 class Html extends ReportRenderer
20 {
21 const IMAGE_GRAPH_WIDTH = 700;
22 const IMAGE_GRAPH_HEIGHT = 200;
23
24 const HTML_CONTENT_TYPE = 'text/html';
25 const HTML_FILE_EXTENSION = 'html';
26 const UNSUBSCRIBE_LINK_PLACEHOLDER = '__unsubscribeLink__';
27
28 protected $renderImageInline = false;
29
30 private $rendering = "";
31
32 public function setLocale($locale)
33 {
34 //Nothing to do
35 }
36
37 /**
38 * Currently only used for HTML reports.
39 * When sent by mail, images are attached to the mail: renderImageInline = false
40 * When downloaded, images are included base64 encoded in the report body: renderImageInline = true
41 *
42 * @param boolean $renderImageInline
43 */
44 public function setRenderImageInline($renderImageInline)
45 {
46 $this->renderImageInline = $renderImageInline;
47 }
48
49 public function sendToDisk($filename)
50 {
51 $this->epilogue();
52
53 return ReportRenderer::writeFile($filename, self::HTML_FILE_EXTENSION, $this->rendering);
54 }
55
56 public function sendToBrowserDownload($filename)
57 {
58 $this->epilogue();
59
60 ReportRenderer::sendToBrowser($filename, self::HTML_FILE_EXTENSION, self::HTML_CONTENT_TYPE, $this->rendering);
61 }
62
63 public function sendToBrowserInline($filename)
64 {
65 $this->epilogue();
66
67 ReportRenderer::inlineToBrowser(self::HTML_CONTENT_TYPE, $this->rendering);
68 }
69
70 public function getRenderedReport()
71 {
72 $this->epilogue();
73
74 return $this->rendering;
75 }
76
77 private function epilogue()
78 {
79 // the unsubscribe link is specific to the email address the report is sent to, so we can't generate it here.
80 // instead we use a placeholder value, and replace it with the correct value in ScheduledReports::sendReport().
81 $view = new View\HtmlEmailFooterView(self::UNSUBSCRIBE_LINK_PLACEHOLDER);
82 $this->rendering .= $view->render();
83 }
84
85 public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
86 {
87 $frontPageView = new View\HtmlReportEmailHeaderView($reportTitle, $prettyDate, $description, $reportMetadata,
88 $segment, $this->idSite, $this->report['period']);
89 $this->rendering .= $frontPageView->render();
90 }
91
92 public function renderReport($processedReport)
93 {
94 $reportView = new View('@CoreHome/ReportRenderer/_htmlReportBody');
95 View\HtmlReportEmailHeaderView::assignCommonParameters($reportView);
96
97 $reportMetadata = $processedReport['metadata'];
98 $reportData = $processedReport['reportData'];
99 $columns = $processedReport['columns'];
100 list($reportData, $columns) = self::processTableFormat($reportMetadata, $reportData, $columns);
101
102 $reportView->assign("reportName", $reportMetadata['name']);
103 $reportView->assign("reportId", $reportMetadata['uniqueId']);
104 $reportView->assign("reportColumns", $columns);
105 $reportView->assign("reportRows", $reportData->getRows());
106 $reportView->assign("reportRowsMetadata", $processedReport['reportMetadata']->getRows());
107 $reportView->assign("displayTable", $processedReport['displayTable']);
108
109 $displayGraph = $processedReport['displayGraph'];
110 $evolutionGraph = $processedReport['evolutionGraph'];
111 $reportView->assign("displayGraph", $displayGraph);
112
113 if ($displayGraph) {
114 $reportView->assign("graphWidth", self::IMAGE_GRAPH_WIDTH);
115 $reportView->assign("graphHeight", self::IMAGE_GRAPH_HEIGHT);
116 $reportView->assign("renderImageInline", $this->renderImageInline);
117
118 if ($this->renderImageInline) {
119 $staticGraph = parent::getStaticGraph(
120 $reportMetadata,
121 self::IMAGE_GRAPH_WIDTH,
122 self::IMAGE_GRAPH_HEIGHT,
123 $evolutionGraph,
124 $processedReport['segment']
125 );
126 $reportView->assign("generatedImageGraph", base64_encode($staticGraph));
127 unset($generatedImageGraph);
128 }
129 }
130
131 $this->rendering .= $reportView->render();
132 }
133
134 public function getAttachments($report, $processedReports, $prettyDate)
135 {
136 $additionalFiles = array();
137
138 foreach ($processedReports as $processedReport) {
139 if ($processedReport['displayGraph']) {
140 $additionalFiles[] = $this->getAttachment($report, $processedReport, $prettyDate);
141 }
142 }
143
144 return $additionalFiles;
145 }
146
147 protected function getAttachment($report, $processedReport, $prettyDate)
148 {
149 $additionalFile = array();
150
151 $segment = \Piwik\Plugins\ScheduledReports\API::getSegment($report['idsegment']);
152
153 $segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : '';
154
155 $processedReportMetadata = $processedReport['metadata'];
156
157 $additionalFile['filename'] =
158 sprintf(
159 '%s - %s - %d - %s %d%s.png',
160 $processedReportMetadata['name'],
161 $prettyDate,
162 $report['idsite'],
163 Piwik::translate('General_Report'),
164 $report['idreport'],
165 $segmentName
166 );
167
168 $additionalFile['cid'] = $processedReportMetadata['uniqueId'];
169
170 $additionalFile['content'] =
171 ReportRenderer::getStaticGraph(
172 $processedReportMetadata,
173 Html::IMAGE_GRAPH_WIDTH,
174 Html::IMAGE_GRAPH_HEIGHT,
175 $processedReport['evolutionGraph'],
176 $segment
177 );
178
179 $additionalFile['mimeType'] = 'image/png';
180
181 return $additionalFile;
182 }
183 }
184