PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.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 2 years ago Html.php 2 years ago Pdf.php 2 years ago Tsv.php 2 years ago
Html.php
126 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\ReportRenderer;
11
12 use Piwik\Piwik;
13 use Piwik\ReportRenderer;
14 use Piwik\View;
15 /**
16 * HTML report renderer
17 */
18 class Html extends ReportRenderer
19 {
20 const IMAGE_GRAPH_WIDTH = 700;
21 const IMAGE_GRAPH_HEIGHT = 200;
22 const HTML_CONTENT_TYPE = 'text/html';
23 const HTML_FILE_EXTENSION = 'html';
24 const UNSUBSCRIBE_LINK_PLACEHOLDER = '__unsubscribeLink__';
25 protected $renderImageInline = false;
26 private $rendering = "";
27 public function setLocale($locale)
28 {
29 //Nothing to do
30 }
31 /**
32 * Currently only used for HTML reports.
33 * When sent by mail, images are attached to the mail: renderImageInline = false
34 * When downloaded, images are included base64 encoded in the report body: renderImageInline = true
35 *
36 * @param boolean $renderImageInline
37 */
38 public function setRenderImageInline($renderImageInline)
39 {
40 $this->renderImageInline = $renderImageInline;
41 }
42 public function sendToDisk($filename)
43 {
44 $this->epilogue();
45 return ReportRenderer::writeFile($filename, self::HTML_FILE_EXTENSION, $this->rendering);
46 }
47 public function sendToBrowserDownload($filename)
48 {
49 $this->epilogue();
50 ReportRenderer::sendToBrowser($filename, self::HTML_FILE_EXTENSION, self::HTML_CONTENT_TYPE, $this->rendering);
51 }
52 public function sendToBrowserInline($filename)
53 {
54 $this->epilogue();
55 ReportRenderer::inlineToBrowser(self::HTML_CONTENT_TYPE, $this->rendering);
56 }
57 public function getRenderedReport()
58 {
59 $this->epilogue();
60 return $this->rendering;
61 }
62 private function epilogue()
63 {
64 // the unsubscribe link is specific to the email address the report is sent to, so we can't generate it here.
65 // instead we use a placeholder value, and replace it with the correct value in ScheduledReports::sendReport().
66 $view = new View\HtmlEmailFooterView(self::UNSUBSCRIBE_LINK_PLACEHOLDER);
67 $this->rendering .= $view->render();
68 }
69 public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
70 {
71 $frontPageView = new View\HtmlReportEmailHeaderView($reportTitle, $prettyDate, $description, $reportMetadata, $segment, $this->idSite, $this->report['period']);
72 $this->rendering .= $frontPageView->render();
73 }
74 public function renderReport($processedReport)
75 {
76 $reportView = new View('@CoreHome/ReportRenderer/_htmlReportBody');
77 View\HtmlReportEmailHeaderView::assignCommonParameters($reportView);
78 $reportMetadata = $processedReport['metadata'];
79 $reportData = $processedReport['reportData'];
80 $columns = $processedReport['columns'];
81 list($reportData, $columns) = self::processTableFormat($reportMetadata, $reportData, $columns);
82 $reportView->assign("reportName", $reportMetadata['name']);
83 $reportView->assign("reportId", $reportMetadata['uniqueId']);
84 $reportView->assign("reportColumns", $columns);
85 $reportView->assign("reportRows", $reportData->getRows());
86 $reportView->assign("reportRowsMetadata", $processedReport['reportMetadata']->getRows());
87 $reportView->assign("displayTable", $processedReport['displayTable']);
88 $displayGraph = $processedReport['displayGraph'];
89 $evolutionGraph = $processedReport['evolutionGraph'];
90 $reportView->assign("displayGraph", $displayGraph);
91 if ($displayGraph) {
92 $reportView->assign("graphWidth", self::IMAGE_GRAPH_WIDTH);
93 $reportView->assign("graphHeight", self::IMAGE_GRAPH_HEIGHT);
94 $reportView->assign("renderImageInline", $this->renderImageInline);
95 if ($this->renderImageInline) {
96 $staticGraph = parent::getStaticGraph($reportMetadata, self::IMAGE_GRAPH_WIDTH, self::IMAGE_GRAPH_HEIGHT, $evolutionGraph, $processedReport['segment']);
97 $reportView->assign("generatedImageGraph", base64_encode($staticGraph));
98 unset($generatedImageGraph);
99 }
100 }
101 $this->rendering .= $reportView->render();
102 }
103 public function getAttachments($report, $processedReports, $prettyDate)
104 {
105 $additionalFiles = array();
106 foreach ($processedReports as $processedReport) {
107 if ($processedReport['displayGraph']) {
108 $additionalFiles[] = $this->getAttachment($report, $processedReport, $prettyDate);
109 }
110 }
111 return $additionalFiles;
112 }
113 protected function getAttachment($report, $processedReport, $prettyDate)
114 {
115 $additionalFile = array();
116 $segment = \Piwik\Plugins\ScheduledReports\API::getSegment($report['idsegment']);
117 $segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : '';
118 $processedReportMetadata = $processedReport['metadata'];
119 $additionalFile['filename'] = sprintf('%s - %s - %d - %s %d%s.png', $processedReportMetadata['name'], $prettyDate, $report['idsite'], Piwik::translate('General_Report'), $report['idreport'], $segmentName);
120 $additionalFile['cid'] = $processedReportMetadata['uniqueId'];
121 $additionalFile['content'] = ReportRenderer::getStaticGraph($processedReportMetadata, \Piwik\ReportRenderer\Html::IMAGE_GRAPH_WIDTH, \Piwik\ReportRenderer\Html::IMAGE_GRAPH_HEIGHT, $processedReport['evolutionGraph'], $segment);
122 $additionalFile['mimeType'] = 'image/png';
123 return $additionalFile;
124 }
125 }
126