/** * @param $dataTable * @return Renderer */ protected function buildDataTableRenderer($dataTable) { $format = self::getFormatFromClass(get_class($this)); $renderer = Renderer::factory($format); $renderer->setTable($dataTable); $renderer->setRenderSubTables(Common::getRequestVar('expanded', false, 'int', $this->request)); $renderer->setHideIdSubDatableFromResponse(Common::getRequestVar('hideIdSubDatable', false, 'int', $this->request)); return $renderer; }
public function renderArray($array) { if (Piwik::isMultiDimensionalArray($array)) { $jsonRenderer = Renderer::factory('json'); $jsonRenderer->setTable($array); $result = $jsonRenderer->render(); return $this->applyJsonpIfNeeded($result); } return $this->renderDataTable($array); }
public function renderArray($array) { if (Piwik::isMultiDimensionalArray($array)) { $jsonRenderer = Renderer::factory('json'); $jsonRenderer->setTable($array); $result = $jsonRenderer->render(); return $this->applyJsonpIfNeeded($result); } $result = $this->renderDataTable($array); // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable if (!empty($array) && Piwik::isAssociativeArray($array) && !Piwik::isMultiDimensionalArray($array)) { $result = substr($result, 1, strlen($result) - 2); } return $result; }
/** * @param $dataTable * @return Renderer */ protected function buildDataTableRenderer($dataTable) { $format = self::getFormatFromClass(get_class($this)); if ($format == 'json2') { $format = 'json'; } $idSite = Common::getRequestVar('idSite', 0, 'int', $this->request); if (empty($idSite)) { $idSite = 'all'; } $renderer = Renderer::factory($format); $renderer->setTable($dataTable); $renderer->setIdSite($idSite); $renderer->setRenderSubTables(Common::getRequestVar('expanded', false, 'int', $this->request)); $renderer->setHideIdSubDatableFromResponse(Common::getRequestVar('hideIdSubDatable', false, 'int', $this->request)); return $renderer; }
public function render() { $idSite = Common::getRequestVar('idSite'); $site = new Site($idSite); $url = urldecode(Common::getRequestVar('url', '', 'string')); if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = 'http://' . $url; } if (empty($url) || !UrlHelper::isLookLikeUrl($url)) { $url = $site->getMainUrl(); } $dataTable = API::getInstance()->getRank($url); /** @var \Piwik\DataTable\Renderer\Php $renderer */ $renderer = Renderer::factory('php'); $renderer->setSerialize(false); return $this->renderTemplate('getRank', array('urlToRank' => Url::getHostFromUrl($url), 'ranks' => $renderer->render($dataTable))); }
/** * tell us when the API is broken * * @group Plugins */ public function test_API() { try { $dataTable = API::getInstance()->getRank('http://www.microsoft.com/'); } catch (Exception $e) { $this->markTestSkipped('A SEO http request failed, Skipping this test for now. Error was: ' . $e->getMessage()); } $renderer = Renderer::factory('php'); $renderer->setSerialize(false); $ranks = $renderer->render($dataTable); foreach ($ranks as $rank) { $message = $rank['id'] . ' expected non-zero rank, got [' . $rank['rank'] . ']'; if (empty($rank['rank'])) { $this->markTestSkipped("Skipped to avoid random build failure: " . $message); } $this->assertNotEmpty($rank['rank'], $message); } }
function getRank() { $idSite = Common::getRequestVar('idSite'); $site = new Site($idSite); $url = urldecode(Common::getRequestVar('url', '', 'string')); if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = 'http://' . $url; } if (empty($url) || !UrlHelper::isLookLikeUrl($url)) { $url = $site->getMainUrl(); } $dataTable = API::getInstance()->getRank($url); $view = new View('@SEO/getRank'); $view->urlToRank = RankChecker::extractDomainFromUrl($url); /** @var \Piwik\DataTable\Renderer\Php $renderer */ $renderer = Renderer::factory('php'); $renderer->setSerialize(false); $view->ranks = $renderer->render($dataTable); return $view->render(); }
/** * Apply the specified renderer to the DataTable * * @param DataTable|array $dataTable * @return string */ protected function getRenderedDataTable($dataTable) { $format = strtolower($this->outputFormat); // if asked for original dataStructure if ($format == 'original') { // by default "original" data is not serialized if ($this->caseRendererPHPSerialize($defaultSerialize = 0)) { $dataTable = serialize($dataTable); } return $dataTable; } $method = Common::getRequestVar('method', '', 'string', $this->request); $renderer = Renderer::factory($format); $renderer->setTable($dataTable); $renderer->setRenderSubTables(Common::getRequestVar('expanded', false, 'int', $this->request)); $renderer->setHideIdSubDatableFromResponse(Common::getRequestVar('hideIdSubDatable', false, 'int', $this->request)); if ($format == 'php') { $renderer->setSerialize($this->caseRendererPHPSerialize()); $renderer->setPrettyDisplay(Common::getRequestVar('prettyDisplay', false, 'int', $this->request)); } else { if ($format == 'html') { $renderer->setTableId($this->request['method']); } else { if ($format == 'csv' || $format == 'tsv') { $renderer->setConvertToUnicode(Common::getRequestVar('convertToUnicode', true, 'int', $this->request)); } } } // prepare translation of column names if ($format == 'html' || $format == 'csv' || $format == 'tsv' || ($format = 'rss')) { $renderer->setApiMethod($method); $renderer->setIdSite(Common::getRequestVar('idSite', false, 'int', $this->request)); $renderer->setTranslateColumnNames(Common::getRequestVar('translateColumnNames', false, 'int', $this->request)); } return $renderer->render(); }