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