renderTable($this->table);
}
/**
* Computes the output for the given data table
*
* @param DataTable $table
* @return string
* @throws Exception
*/
protected function renderTable($table)
{
if (!($table instanceof DataTable\Map)
|| $table->getKeyName() != 'date'
) {
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.");
}
$idSite = Common::getRequestVar('idSite', 1, 'int');
$period = Common::getRequestVar('period');
$piwikUrl = SettingsPiwik::getPiwikUrl()
. "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
$out = "";
$moreRecentFirst = array_reverse($table->getDataTables(), true);
foreach ($moreRecentFirst as $date => $subtable) {
/** @var DataTable $subtable */
$timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
$site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
$pudDate = date('r', $timestamp);
$dateInSiteTimezone = Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
$thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date=$dateInSiteTimezone");
$siteName = $site->getName();
$title = $siteName . " on " . $date;
$out .= "\t-
$pudDate
$thisPiwikUrl
$thisPiwikUrl
$title
http://piwik.org
";
$out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
$out .= "\n\t
\n";
}
$header = $this->getRssHeader();
$footer = $this->getRssFooter();
return $header . $out . $footer;
}
/**
* Returns the RSS file footer
*
* @return string
*/
protected function getRssFooter()
{
return "\t\n";
}
/**
* Returns the RSS file header
*
* @return string
*/
protected function getRssHeader()
{
$generationDate = date('r');
$header = "
piwik statistics - RSS
http://piwik.org
Piwik RSS feed
$generationDate
piwik
en
$generationDate";
return $header;
}
/**
* @param DataTable $table
*
* @return string
*/
protected function renderDataTable($table)
{
if ($table->getRowsCount() == 0) {
return "Empty table
\n";
}
$i = 1;
$tableStructure = array();
/*
* table = array
* ROW1 = col1 | col2 | col3 | metadata | idSubTable
* ROW2 = col1 | col2 (no value but appears) | col3 | metadata | idSubTable
* subtable here
*/
$allColumns = array();
foreach ($table->getRows() as $row) {
foreach ($row->getColumns() as $column => $value) {
// for example, goals data is array: not supported in export RSS
// in the future we shall reuse ViewDataTable for html exports in RSS anyway
if (is_array($value)) {
continue;
}
$allColumns[$column] = true;
$tableStructure[$i][$column] = $value;
}
$i++;
}
$html = "\n";
$html .= "";
$html .= "\n";
foreach ($allColumns as $name => $toDisplay) {
if ($toDisplay !== false) {
if ($this->translateColumnNames) {
$name = $this->translateColumnName($name);
}
$html .= "\n\t$name | ";
}
}
$html .= "\n
";
foreach ($tableStructure as $row) {
$html .= "\n\n";
foreach ($allColumns as $columnName => $toDisplay) {
if ($toDisplay !== false) {
$value = "-";
if (isset($row[$columnName])) {
$value = urldecode($row[$columnName]);
}
$html .= "\n\t$value | ";
}
}
$html .= "
";
}
$html .= "\n\n
";
return $html;
}
}