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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\ReportRenderer;
use Piwik\Piwik;
use Piwik\ReportRenderer;
use Piwik\View;
/**
* HTML report renderer
*/
class Html extends ReportRenderer
{
public const IMAGE_GRAPH_WIDTH = 700;
public const IMAGE_GRAPH_HEIGHT = 200;
public const HTML_CONTENT_TYPE = 'text/html';
public const HTML_FILE_EXTENSION = 'html';
public const UNSUBSCRIBE_LINK_PLACEHOLDER = '__unsubscribeLink__';
protected $renderImageInline = false;
private $rendering = "";
public function setLocale($locale)
{
//Nothing to do
}
/**
* Currently only used for HTML reports.
* When sent by mail, images are attached to the mail: renderImageInline = false
* When downloaded, images are included base64 encoded in the report body: renderImageInline = true
*
* @param boolean $renderImageInline
*/
public function setRenderImageInline($renderImageInline)
{
$this->renderImageInline = $renderImageInline;
}
public function sendToDisk($filename)
{
$this->epilogue();
return ReportRenderer::writeFile($filename, self::HTML_FILE_EXTENSION, $this->rendering);
}
public function sendToBrowserDownload($filename)
{
$this->epilogue();
ReportRenderer::sendToBrowser($filename, self::HTML_FILE_EXTENSION, self::HTML_CONTENT_TYPE, $this->rendering);
}
public function sendToBrowserInline($filename)
{
$this->epilogue();
ReportRenderer::inlineToBrowser(self::HTML_CONTENT_TYPE, $this->rendering);
}
public function getRenderedReport()
{
$this->epilogue();
return $this->rendering;
}
private function epilogue()
{
// the unsubscribe link is specific to the email address the report is sent to, so we can't generate it here.
// instead we use a placeholder value, and replace it with the correct value in ScheduledReports::sendReport().
$view = new View\HtmlEmailFooterView(self::UNSUBSCRIBE_LINK_PLACEHOLDER);
$this->rendering .= $view->render();
}
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
{
$frontPageView = new View\HtmlReportEmailHeaderView(
$reportTitle,
$prettyDate,
$description,
$reportMetadata,
$segment,
$this->idSite,
$this->report['period']
);
$this->rendering .= $frontPageView->render();
}
public function renderReport($processedReport)
{
$reportView = new View('@CoreHome/ReportRenderer/_htmlReportBody');
View\HtmlReportEmailHeaderView::assignCommonParameters($reportView);
$reportMetadata = $processedReport['metadata'];
$reportData = $processedReport['reportData'];
$columns = $processedReport['columns'];
list($reportData, $columns) = self::processTableFormat($reportMetadata, $reportData, $columns);
$reportView->assign("reportName", $reportMetadata['name']);
$reportView->assign("reportId", $reportMetadata['uniqueId']);
$reportView->assign("reportColumns", $columns);
$reportView->assign("reportRows", $reportData->getRows());
$reportView->assign("reportRowsMetadata", $processedReport['reportMetadata']->getRows());
$reportView->assign("displayTable", $processedReport['displayTable']);
$displayGraph = $processedReport['displayGraph'];
$evolutionGraph = $processedReport['evolutionGraph'];
$reportView->assign("displayGraph", $displayGraph);
if ($displayGraph) {
$reportView->assign("graphWidth", self::IMAGE_GRAPH_WIDTH);
$reportView->assign("graphHeight", self::IMAGE_GRAPH_HEIGHT);
$reportView->assign("renderImageInline", $this->renderImageInline);
if ($this->renderImageInline) {
$staticGraph = parent::getStaticGraph(
$reportMetadata,
self::IMAGE_GRAPH_WIDTH,
self::IMAGE_GRAPH_HEIGHT,
$evolutionGraph,
$processedReport['segment']
);
$reportView->assign("generatedImageGraph", base64_encode($staticGraph));
}
}
$this->rendering .= $reportView->render();
}
public function getAttachments($report, $processedReports, $prettyDate)
{
$additionalFiles = array();
foreach ($processedReports as $processedReport) {
if ($processedReport['displayGraph']) {
$additionalFiles[] = $this->getAttachment($report, $processedReport, $prettyDate);
}
}
return $additionalFiles;
}
protected function getAttachment($report, $processedReport, $prettyDate)
{
$additionalFile = array();
$segment = \Piwik\Plugins\ScheduledReports\API::getSegment($report['idsegment']);
$segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : '';
$processedReportMetadata = $processedReport['metadata'];
$additionalFile['filename'] =
sprintf(
'%s - %s - %d - %s %d%s.png',
$processedReportMetadata['name'],
$prettyDate,
$report['idsite'],
Piwik::translate('General_Report'),
$report['idreport'],
$segmentName
);
$additionalFile['cid'] = $processedReportMetadata['uniqueId'];
$additionalFile['content'] =
ReportRenderer::getStaticGraph(
$processedReportMetadata,
Html::IMAGE_GRAPH_WIDTH,
Html::IMAGE_GRAPH_HEIGHT,
$processedReport['evolutionGraph'],
$segment
);
$additionalFile['mimeType'] = 'image/png';
return $additionalFile;
}
}
|