renderTable($this->table); } protected function renderTable($table) { if(!($table instanceof Piwik_DataTable_Array) || $table->getKeyName() != 'date') { throw new Exception("RSS Feed only used on Piwik_DataTable_Array with keyName = 'date'"); } $idSite = Piwik_Common::getRequestVar('idSite', 1); $period = Piwik_Common::getRequestVar('period'); $currentUrl = Piwik_Url::getCurrentUrlWithoutFileName(); $piwikUrl = $currentUrl . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period; $out = ""; $moreRecentFirst = array_reverse($table->getArray(), true); foreach($moreRecentFirst as $date => $subtable ) { $timestamp = $table->metadata[$date]['timestamp']; $site = $table->metadata[$date]['site']; $pudDate = date('r', $timestamp); $dateUrl = date('Y-m-d', $timestamp); $thisPiwikUrl = htmlentities($piwikUrl . "&date=$dateUrl"); $siteName = $site->getName(); $title = $siteName . " on ". $date; $out .= "\t $pudDate $thisPiwikUrl $thisPiwikUrl $title http://piwik.org "; $out .= htmlspecialchars( $this->renderDataTable($subtable) ); $out .= "\n\t\n"; } $header = $this->getRssHeader(); $footer = $this->getRssFooter(); return $this->output( $header . $out . $footer); } protected function output($str) { @header("Content-Type: text/xml;charset=utf-8"); return $str; } protected function getRssFooter() { return "\t\n"; } protected function getRssHeader() { $generationDate = date('r'); $header = " piwik statistics - RSS http://piwik.org Piwik RSS feed $generationDate piwik en $generationDate"; return $header; } 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) { $html .= "\n\t"; } } $html .= "\n"; $colspan = count($allColumns); 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"; } } $html .= ""; } $html .= "\n\n
$name
$value
"; return $html; } }