Exemple #1
0
 /**
  * Computes the output for the given data table
  *
  * @param Piwik_DataTable  $table
  * @return string
  * @throws Exception
  */
 protected function renderTable($table)
 {
     if (!$table instanceof Piwik_DataTable_Array || $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 = Piwik_Common::getRequestVar('idSite', 1, 'int');
     $period = Piwik_Common::getRequestVar('period');
     $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName() . "?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);
         $dateInSiteTimezone = Piwik_Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
         $thisPiwikUrl = Piwik_Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
         $siteName = $site->getName();
         $title = $siteName . " on " . $date;
         $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>http://piwik.org</author>\n\t\t<description>";
         $out .= Piwik_Common::sanitizeInputValue($this->renderDataTable($subtable));
         $out .= "</description>\n\t</item>\n";
     }
     $header = $this->getRssHeader();
     $footer = $this->getRssFooter();
     return $header . $out . $footer;
 }
 /**
  * This method can be used by subclasses to iterate over data tables that might be
  * data table arrays. It calls back the template method self::doManipulate for each table.
  * This way, data table arrays can be handled in a transparent fashion.
  *
  * @param Piwik_DataTable_Array|Piwik_DataTable  $dataTable
  * @throws Exception
  * @return Piwik_DataTable_Array|Piwik_DataTable
  */
 protected function manipulate($dataTable)
 {
     if ($dataTable instanceof Piwik_DataTable_Array) {
         $newTableArray = new Piwik_DataTable_Array();
         $newTableArray->metadata = $dataTable->metadata;
         $newTableArray->setKeyName($dataTable->getKeyName());
         foreach ($dataTable->getArray() as $date => $subTable) {
             // for period=week, the label is "2011-08-15 to 2011-08-21", which is
             // an invalid date parameter => only use the first date
             // in other languages the whole string does not start with the date so
             // we need to preg match it.
             if (!preg_match('/[0-9]{4}(-[0-9]{2})?(-[0-9]{2})?/', $date, $match)) {
                 throw new Exception("Could not recognize date: {$date}");
             }
             $dateForApiRequest = $match[0];
             $subTable = $this->doManipulate($subTable, $dateForApiRequest);
             $newTableArray->addTable($subTable, $date);
         }
         return $newTableArray;
     }
     if ($dataTable instanceof Piwik_DataTable) {
         return $this->doManipulate($dataTable);
     }
     return $dataTable;
 }
Exemple #3
0
 /**
  * Computes the output for the given data table
  *
  * @param Piwik_DataTable  $table
  * @return string
  */
 protected function renderTable($table)
 {
     if ($table instanceof Piwik_DataTable_Array) {
         foreach ($table->getArray() as $date => $subtable) {
             if ($subtable->getRowsCount()) {
                 $this->buildTableStructure($subtable, '_' . $table->getKeyName(), $date);
             }
         }
     } else {
         if ($table->getRowsCount()) {
             $this->buildTableStructure($table);
         }
     }
     $out = $this->renderDataTable();
     return $out;
 }