PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
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 / DataTable / Renderer / Rss.php
matomo / app / core / DataTable / Renderer Last commit date
Console.php 2 months ago Csv.php 1 month ago Html.php 2 months ago Json.php 2 weeks ago Rss.php 2 weeks ago Tsv.php 2 months ago Xml.php 2 weeks ago
Rss.php
145 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\DataTable\Renderer;
10
11 use Exception;
12 use Piwik\Archive;
13 use Piwik\Common;
14 use Piwik\DataTable\Renderer;
15 use Piwik\DataTable;
16 use Piwik\Date;
17 use Piwik\SettingsPiwik;
18 /**
19 * RSS Feed.
20 * The RSS renderer can be used only on Set that are arrays of DataTable.
21 * A RSS feed contains one dataTable per element in the Set.
22 *
23 */
24 class Rss extends Renderer
25 {
26 /**
27 * Computes the dataTable output and returns the string/binary
28 */
29 public function render() : string
30 {
31 return $this->renderTable($this->table);
32 }
33 /**
34 * Computes the output for the given data table
35 *
36 * @param DataTable\Map $table Must be keyed by 'date'.
37 */
38 protected function renderTable($table) : string
39 {
40 if (!$table instanceof DataTable\Map || $table->getKeyName() != 'date') {
41 throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
42 }
43 $idSite = Common::getRequestVar('idSite', 1, 'int');
44 $period = Common::getRequestVar('period');
45 $piwikUrl = SettingsPiwik::getPiwikUrl() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
46 $out = "";
47 $moreRecentFirst = array_reverse($table->getDataTables(), \true);
48 foreach ($moreRecentFirst as $date => $subtable) {
49 /** @var DataTable $subtable */
50 $timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
51 $site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
52 $pudDate = date('r', $timestamp);
53 $dateInSiteTimezone = Date::factory($timestamp);
54 if ($site) {
55 $dateInSiteTimezone = $dateInSiteTimezone->setTimezone($site->getTimezone());
56 }
57 $dateInSiteTimezone = $dateInSiteTimezone->toString('Y-m-d');
58 $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
59 $siteName = $site ? $site->getName() : '';
60 $title = self::formatValueXml($siteName . " on " . $date);
61 $out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>https://matomo.org</author>\n\t\t<description>";
62 $out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
63 $out .= "</description>\n\t</item>\n";
64 }
65 $header = $this->getRssHeader();
66 $footer = $this->getRssFooter();
67 return $header . $out . $footer;
68 }
69 /**
70 * Returns the RSS file footer
71 */
72 protected function getRssFooter() : string
73 {
74 return "\t</channel>\n</rss>";
75 }
76 /**
77 * Returns the RSS file header
78 */
79 protected function getRssHeader() : string
80 {
81 $generationDate = date('r', Date::getNowTimestamp());
82 $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\">\n <channel>\n <title>matomo statistics - RSS</title>\n <link>https://matomo.org</link>\n <description>Matomo RSS feed</description>\n <pubDate>{$generationDate}</pubDate>\n <generator>matomo</generator>\n <language>en</language>\n <lastBuildDate>{$generationDate}</lastBuildDate>\n";
83 return $header;
84 }
85 /**
86 * @param DataTable $table
87 *
88 * @return string
89 */
90 protected function renderDataTable($table)
91 {
92 if ($table->getRowsCount() == 0) {
93 return "<strong><em>Empty table</em></strong><br />\n";
94 }
95 $i = 1;
96 $tableStructure = array();
97 /*
98 * table = array
99 * ROW1 = col1 | col2 | col3 | metadata | idSubTable
100 * ROW2 = col1 | col2 (no value but appears) | col3 | metadata | idSubTable
101 * subtable here
102 */
103 $allColumns = array();
104 foreach ($table->getRows() as $row) {
105 foreach ($row->getColumns() as $column => $value) {
106 // for example, goals data is array: not supported in export RSS
107 // in the future we shall reuse ViewDataTable for html exports in RSS anyway
108 if (is_array($value) || is_object($value)) {
109 continue;
110 }
111 $allColumns[$column] = \true;
112 $tableStructure[$i][$column] = $value;
113 }
114 $i++;
115 }
116 $html = "\n";
117 $html .= "<table border=1 width=70%>";
118 $html .= "\n<tr>";
119 foreach ($allColumns as $name => $toDisplay) {
120 if ($toDisplay !== \false) {
121 if ($this->translateColumnNames) {
122 $name = $this->translateColumnName($name);
123 }
124 $html .= "\n\t<td><strong>" . self::formatValueXml($name) . "</strong></td>";
125 }
126 }
127 $html .= "\n</tr>";
128 foreach ($tableStructure as $row) {
129 $html .= "\n\n<tr>";
130 foreach ($allColumns as $columnName => $toDisplay) {
131 if ($toDisplay !== \false) {
132 $value = "-";
133 if (isset($row[$columnName])) {
134 $value = self::formatValueXml(urldecode($row[$columnName]));
135 }
136 $html .= "\n\t<td>{$value}</td>";
137 }
138 }
139 $html .= "</tr>";
140 }
141 $html .= "\n\n</table>";
142 return $html;
143 }
144 }
145