本文整理汇总了PHP中Piwik_Url::getQueryStringFromParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Url::getQueryStringFromParameters方法的具体用法?PHP Piwik_Url::getQueryStringFromParameters怎么用?PHP Piwik_Url::getQueryStringFromParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Url
的用法示例。
在下文中一共展示了Piwik_Url::getQueryStringFromParameters方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addMainPageMetricsToReport
/**
* Add the main metrics (pageviews, exits, bounces) to the full report.
* Data is loaded from Actions.getPageUrls using the label filter.
*/
private function addMainPageMetricsToReport(&$report, $pageUrl, $idSite, $period, $date, $segment)
{
$label = Piwik_Actions::getActionExplodedNames($pageUrl, Piwik_Tracker_Action::TYPE_ACTION_URL);
if (count($label) == 1) {
$label = $label[0];
} else {
$label = array_map('urlencode', $label);
$label = implode('>', $label);
}
$parameters = array('method' => 'Actions.getPageUrls', 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'label' => $label, 'format' => 'original', 'serialize' => '0', 'expanded' => '0');
if (!empty($segment)) {
$parameters['segment'] = $segment;
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
/** @var $dataTable Piwik_DataTable */
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("Actions.getPageUrls returned an error: " . $e->getMessage() . "\n");
}
if ($dataTable->getRowsCount() == 0) {
throw new Exception("The label '{$label}' could not be found in Actions.getPageUrls\n");
}
$row = $dataTable->getFirstRow();
if ($row !== false) {
$report['pageMetrics'] = array('pageviews' => intval($row->getColumn('nb_hits')), 'exits' => intval($row->getColumn('exit_nb_visits')), 'bounces' => intval($row->getColumn('entry_bounce_count')));
} else {
$report['pageMetrics'] = array('pageviews' => 0, 'exits' => 0, 'bounces' => 0);
}
}
示例2: redirectToIndex
/**
* Helper method used to redirect the current http request to another module/action
* If specified, will also redirect to a given website, period and /or date
*
* @param string $moduleToRedirect Module, eg. "MultiSites"
* @param string $actionToRedirect Action, eg. "index"
* @param string $websiteId Website ID, eg. 1
* @param string $defaultPeriod Default period, eg. "day"
* @param string $defaultDate Default date, eg. "today"
* @param array $parameters Parameters to append to url
*/
function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array())
{
if (is_null($websiteId)) {
$websiteId = $this->getDefaultWebsiteId();
}
if (is_null($defaultDate)) {
$defaultDate = $this->getDefaultDate();
}
if (is_null($defaultPeriod)) {
$defaultPeriod = $this->getDefaultPeriod();
}
$parametersString = '';
if (!empty($parameters)) {
$parametersString = '&' . Piwik_Url::getQueryStringFromParameters($parameters);
}
if ($websiteId) {
$url = "Location: index.php?module=" . $moduleToRedirect . "&action=" . $actionToRedirect . "&idSite=" . $websiteId . "&period=" . $defaultPeriod . "&date=" . $defaultDate . $parametersString;
header($url);
exit;
}
if (Piwik::isUserIsSuperUser()) {
Piwik_ExitWithMessage("Error: no website was found in this Piwik installation. \n\t\t\t<br />Check the table '" . Piwik_Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true);
}
$currentLogin = Piwik::getCurrentUserLogin();
if (!empty($currentLogin) && $currentLogin != 'anonymous') {
$errorMessage = sprintf(Piwik_Translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>");
$errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Zend_Registry::get('auth')->getName() . "&action=logout'>› " . Piwik_Translate('General_Logout') . "</a></b><br />";
Piwik_ExitWithMessage($errorMessage, false, true);
}
Piwik_FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false);
exit;
}
示例3: loadRowEvolutionData
/** @return Piwik_DataTable_Array */
private function loadRowEvolutionData($idSite, $period, $date, $apiModule, $apiAction, $label, $segment)
{
if ($period == 'range') {
// load days in the range
$period = 'day';
}
$parameters = array('method' => $apiModule . '.' . $apiAction, 'label' => $label, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'segment' => $segment);
// add "processed metrics" like actions per visit or bounce rate
if ($apiModule != 'Actions') {
$parameters['filter_add_columns_when_show_all_columns'] = '1';
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("API returned an error: " . $e->getMessage() . "\n");
}
if (!$dataTable instanceof Piwik_DataTable_Array) {
throw new Exception("API didn't return a DataTable array. Maybe you used " . "a single date (i.e. not YYYY-MM-DD,YYYY-MM-DD)");
}
return $dataTable;
}
示例4: loadEvolutionReport
protected function loadEvolutionReport($column = false)
{
list($apiModule, $apiAction) = explode('.', $this->apiMethod);
$parameters = array('method' => 'API.getRowEvolution', 'label' => $this->label, 'apiModule' => $apiModule, 'apiAction' => $apiAction, 'idSite' => $this->idSite, 'period' => $this->period, 'date' => $this->date, 'format' => 'original', 'serialize' => '0');
if (!empty($this->segment)) {
$parameters['segment'] = $this->segment;
}
if ($column !== false) {
$parameters['column'] = $column;
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
$report = $request->process();
$this->extractEvolutionReport($report);
}
示例5: loadRowEvolutionDataFromAPI
/**
* @param $idSite
* @param $period
* @param $date
* @param $apiModule
* @param $apiAction
* @param $label
* @param $segment
* @param $idGoal
* @throws Exception
* @return Piwik_DataTable_Array|Piwik_DataTable
*/
private function loadRowEvolutionDataFromAPI($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $idGoal = false)
{
$parameters = array('method' => $apiModule . '.' . $apiAction, 'label' => $label, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'segment' => $segment, 'idGoal' => $idGoal);
// add "processed metrics" like actions per visit or bounce rate
// note: some reports should not be filtered with AddColumnProcessedMetrics
// specifically, reports without the Piwik_Archive::INDEX_NB_VISITS metric such as Goals.getVisitsUntilConversion & Goal.getDaysToConversion
// this is because the AddColumnProcessedMetrics filter removes all datable rows lacking this metric
if ($apiModule != 'Actions' && ($apiModule != 'Goals' || $apiAction != 'getVisitsUntilConversion' && $apiAction != 'getDaysToConversion') && $label) {
$parameters['filter_add_columns_when_show_all_columns'] = '1';
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("API returned an error: " . $e->getMessage() . "\n");
}
return $dataTable;
}
示例6: initChartObjectData
protected function initChartObjectData()
{
// if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
// we don't expect plugin developers to return a well defined Piwik_DataTable_Array
if ($this->dataTable instanceof Piwik_DataTable) {
return parent::initChartObjectData();
}
$this->dataTable->applyQueuedFilters();
if (!$this->dataTable instanceof Piwik_DataTable_Array) {
throw new Exception("Expecting a DataTable_Array with custom format to draw an evolution chart");
}
// the X label is extracted from the 'period' object in the table's metadata
$xLabels = $uniqueIdsDataTable = array();
foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) {
//eg. "Aug 2009"
$xLabels[] = $metadataDataTable['period']->getLocalizedShortString();
// we keep track of all unique data table that we need to set a Y value for
$uniqueIdsDataTable[] = $idDataTable;
}
$idSite = Piwik_Common::getRequestVar('idSite', null, 'int');
$requestedColumnNames = $this->getColumnsToDisplay();
$units = $this->getUnitsForColumnsToDisplay();
$yAxisLabelToUnit = array();
$yAxisLabelToValue = array();
foreach ($this->dataTable->getArray() as $idDataTable => $dataTable) {
foreach ($dataTable->getRows() as $row) {
$rowLabel = $row->getColumn('label');
// put together configuration for row picker.
// do this for every data table in the array because rows do not
// have to present for each date.
if ($this->rowPicker !== false) {
$rowVisible = $this->handleRowForRowPicker($rowLabel);
if (!$rowVisible) {
continue;
}
}
// build data for request columns
foreach ($requestedColumnNames as $requestedColumnName) {
$yAxisLabel = $this->getSeriesLabel($rowLabel, $requestedColumnName);
if (($columnValue = $row->getColumn($requestedColumnName)) !== false) {
$yAxisLabelToValue[$yAxisLabel][$idDataTable] = $columnValue;
$yAxisLabelToUnit[$yAxisLabel] = $units[$requestedColumnName];
}
}
}
}
// make sure all column values are set to at least zero (no gap in the graph)
$yAxisLabelToValueCleaned = array();
foreach ($uniqueIdsDataTable as $uniqueIdDataTable) {
foreach ($yAxisLabelToValue as $yAxisLabel => $idDataTableToColumnValue) {
if (isset($idDataTableToColumnValue[$uniqueIdDataTable])) {
$columnValue = $idDataTableToColumnValue[$uniqueIdDataTable];
} else {
$columnValue = 0;
}
$yAxisLabelToValueCleaned[$yAxisLabel][] = $columnValue;
}
}
$this->view->setAxisXLabels($xLabels);
$this->view->setAxisYValues($yAxisLabelToValueCleaned);
$this->view->setAxisYUnits($yAxisLabelToUnit);
$countGraphElements = $this->dataTable->getRowsCount();
$firstDatatable = reset($this->dataTable->metadata);
$period = $firstDatatable['period'];
switch ($period->getLabel()) {
case 'day':
$steps = 7;
break;
case 'week':
$steps = 10;
break;
case 'month':
$steps = 6;
break;
case 'year':
$steps = 2;
break;
default:
$steps = 10;
break;
}
// For Custom Date Range, when the number of elements plotted can be small, make sure the X legend is useful
if ($countGraphElements <= 20) {
$steps = 2;
}
$this->view->setXSteps($steps);
if ($this->isLinkEnabled()) {
$axisXOnClick = array();
$queryStringAsHash = $this->getQueryStringAsHash();
foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) {
$period = $metadataDataTable['period'];
$dateInUrl = $period->getDateStart();
$parameters = array('idSite' => $idSite, 'period' => $period->getLabel(), 'date' => $dateInUrl->toString());
$hash = '';
if (!empty($queryStringAsHash)) {
$hash = '#' . Piwik_Url::getQueryStringFromParameters($queryStringAsHash + $parameters);
}
$link = 'index.php?' . Piwik_Url::getQueryStringFromParameters(array('module' => 'CoreHome', 'action' => 'index') + $parameters) . $hash;
$axisXOnClick[] = $link;
}
//.........这里部分代码省略.........
示例7: getProcessedReport
public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true)
{
$timer = new Piwik_Timer();
if ($apiParameters === false) {
$apiParameters = array();
}
if (!empty($idGoal) && empty($apiParameters['idGoal'])) {
$apiParameters['idGoal'] = $idGoal;
}
// Is this report found in the Metadata available reports?
$reportMetadata = $this->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date);
if (empty($reportMetadata)) {
throw new Exception("Requested report {$apiModule}.{$apiAction} for Website id={$idSite} not found in the list of available reports. \n");
}
$reportMetadata = reset($reportMetadata);
// Generate Api call URL passing custom parameters
$parameters = array_merge($apiParameters, array('method' => $apiModule . '.' . $apiAction, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'language' => $language));
if (!empty($segment)) {
$parameters['segment'] = $segment;
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
/** @var Piwik_DataTable */
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("API returned an error: " . $e->getMessage() . "\n");
}
list($newReport, $columns, $rowsMetadata) = $this->handleTableReport($idSite, $dataTable, $reportMetadata, isset($reportMetadata['dimension']));
foreach ($columns as $columnId => &$name) {
$name = ucfirst($name);
}
$website = new Piwik_Site($idSite);
// $segment = new Piwik_Segment($segment, $idSite);
if (Piwik_Archive::isMultiplePeriod($date, $period)) {
$period = new Piwik_Period_Range($period, $date);
} else {
if ($period == 'range') {
$period = new Piwik_Period_Range($period, $date);
} else {
$period = Piwik_Period::factory($period, Piwik_Date::factory($date));
}
}
$period = $period->getLocalizedLongString();
$return = array('website' => $website->getName(), 'prettyDate' => $period, 'metadata' => $reportMetadata, 'columns' => $columns, 'reportData' => $newReport, 'reportMetadata' => $rowsMetadata);
if ($showTimer) {
$return['timerMillis'] = $timer->getTimeMs(0);
}
return $return;
}
示例8: getReportMetadata
/**
* @param Piwik_Event_Notification $notification notification object
* @return mixed
*/
public function getReportMetadata($notification)
{
$info = $notification->getNotificationInfo();
$reports =& $notification->getNotificationObject();
$idSites = $info['idSites'];
// If only one website is selected, we add the Graph URL
if (count($idSites) != 1) {
return;
}
$idSite = reset($idSites);
// in case API.getReportMetadata was not called with date/period we use sane defaults
if (empty($info['period'])) {
$info['period'] = 'day';
}
if (empty($info['date'])) {
$info['date'] = 'today';
}
// need two sets of period & date, one for single period graphs, one for multiple periods graphs
if (Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) {
$periodForMultiplePeriodGraph = $info['period'];
$dateForMultiplePeriodGraph = $info['date'];
$periodForSinglePeriodGraph = 'range';
$dateForSinglePeriodGraph = $info['date'];
} else {
$periodForSinglePeriodGraph = $info['period'];
$dateForSinglePeriodGraph = $info['date'];
$piwikSite = new Piwik_Site($idSite);
if ($periodForSinglePeriodGraph == 'range') {
$periodForMultiplePeriodGraph = Piwik_Config::getInstance()->General['graphs_default_period_to_plot_when_period_range'];
$dateForMultiplePeriodGraph = $dateForSinglePeriodGraph;
} else {
$periodForMultiplePeriodGraph = $periodForSinglePeriodGraph;
$dateForMultiplePeriodGraph = Piwik_Controller::getDateRangeRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite);
}
}
$token_auth = Piwik_Common::getRequestVar('token_auth', false);
$urlPrefix = "index.php?";
foreach ($reports as &$report) {
$reportModule = $report['module'];
$reportAction = $report['action'];
$reportUniqueId = $reportModule . '_' . $reportAction;
$parameters = array();
$parameters['module'] = 'API';
$parameters['method'] = 'ImageGraph.get';
$parameters['idSite'] = $idSite;
$parameters['apiModule'] = $reportModule;
$parameters['apiAction'] = $reportAction;
if (!empty($token_auth)) {
$parameters['token_auth'] = $token_auth;
}
// Forward custom Report parameters to the graph URL
if (!empty($report['parameters'])) {
$parameters = array_merge($parameters, $report['parameters']);
}
if (empty($report['dimension'])) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
} else {
$parameters['period'] = $periodForSinglePeriodGraph;
$parameters['date'] = $dateForSinglePeriodGraph;
}
// add the idSubtable if it exists
$idSubtable = Piwik_Common::getRequestVar('idSubtable', false);
if ($idSubtable !== false) {
$parameters['idSubtable'] = $idSubtable;
}
$report['imageGraphUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters);
// thanks to API.getRowEvolution, reports with dimensions can now be plotted using an evolution graph
// however, most reports with a fixed set of dimension values are excluded
// this is done so Piwik Mobile and Scheduled Reports do not display them
if (empty($report['constantRowsCount']) || in_array($reportUniqueId, self::$CONSTANT_ROW_COUNT_REPORT_EXCEPTIONS)) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
$report['imageGraphEvolutionUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters);
}
}
}
示例9: getExampleUrl
/**
* Returns a string containing links to examples on how to call a given method on a given API
* It will export links to XML, CSV, HTML, JSON, PHP, etc.
* It will not export links for methods such as deleteSite or deleteUser
*
* @param string $class the class
* @param string $methodName the method
* @param array $parametersToSet parameters to set
* @return string|false when not possible
*/
public function getExampleUrl($class, $methodName, $parametersToSet = array())
{
$knowExampleDefaultParametersValues = array('access' => 'view', 'userLogin' => 'test', 'passwordMd5ied' => 'passwordExample', 'email' => 'test@example.org', 'languageCode' => 'fr', 'url' => 'http://forum.piwik.org/', 'apiModule' => 'UserCountry', 'apiAction' => 'getCountry', 'lastMinutes' => '30', 'abandonedCarts' => '0');
foreach ($parametersToSet as $name => $value) {
$knowExampleDefaultParametersValues[$name] = $value;
}
// no links for these method names
$doNotPrintExampleForTheseMethods = array('deleteSite', 'addSite', 'updateSite', 'addSiteAliasUrls', 'deleteUser', 'addUser', 'updateUser', 'setUserAccess', 'addGoal', 'updateGoal', 'deleteGoal');
if (in_array($methodName, $doNotPrintExampleForTheseMethods)) {
return false;
}
// we try to give an URL example to call the API
$aParameters = Piwik_API_Proxy::getInstance()->getParametersList($class, $methodName);
// Kindly force some known generic parameters to appear in the final list
// the parameter 'format' can be set to all API methods (used in tests)
// the parameter 'hideIdSubDatable' is used for integration tests only
// the parameter 'serialize' sets php outputs human readable, used in integration tests and debug
// the parameter 'language' sets the language for the response (eg. country names)
// the parameter 'flat' reduces a hierarchical table to a single level by concatenating labels
// the parameter 'include_aggregate_rows' can be set to include inner nodes in flat reports
// the parameter 'translateColumnNames' can be set to translate metric names in csv/tsv exports
$aParameters['format'] = false;
$aParameters['hideIdSubDatable'] = false;
$aParameters['serialize'] = false;
$aParameters['language'] = false;
$aParameters['translateColumnNames'] = false;
$aParameters['label'] = false;
$aParameters['flat'] = false;
$aParameters['include_aggregate_rows'] = false;
$aParameters['filter_truncate'] = false;
$aParameters['hideColumns'] = false;
$aParameters['showColumns'] = false;
$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
$aParameters = array_merge(array('module' => 'API', 'method' => $moduleName . '.' . $methodName), $aParameters);
foreach ($aParameters as $nameVariable => &$defaultValue) {
if (isset($knowExampleDefaultParametersValues[$nameVariable])) {
$defaultValue = $knowExampleDefaultParametersValues[$nameVariable];
} elseif ($defaultValue instanceof Piwik_API_Proxy_NoDefaultValue) {
return false;
}
}
return '?' . Piwik_Url::getQueryStringFromParameters($aParameters);
}
示例10: getReportMetadata
public function getReportMetadata($notification)
{
$info = $notification->getNotificationInfo();
$reports =& $notification->getNotificationObject();
$idSites = $info['idSites'];
// If only one website is selected, we add the Graph URL
if (count($idSites) != 1) {
return;
}
$idSite = reset($idSites);
// in case API.getReportMetadata was not called with date/period we use sane defaults
if (empty($info['period'])) {
$info['period'] = 'day';
}
if (empty($info['date'])) {
$info['date'] = 'today';
}
// need two sets of period & date, one for single period graphs, one for multiple periods graphs
if (Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) {
$periodForMultiplePeriodGraph = $info['period'];
$dateForMultiplePeriodGraph = $info['date'];
$periodForSinglePeriodGraph = 'range';
$dateForSinglePeriodGraph = $info['date'];
} else {
$periodForSinglePeriodGraph = $info['period'];
$dateForSinglePeriodGraph = $info['date'];
$piwikSite = new Piwik_Site($idSite);
if ($periodForSinglePeriodGraph == 'range') {
$periodForMultiplePeriodGraph = Zend_Registry::get('config')->General->graphs_default_period_to_plot_when_period_range;
$dateForMultiplePeriodGraph = $dateForSinglePeriodGraph;
} else {
$periodForMultiplePeriodGraph = $periodForSinglePeriodGraph;
$dateForMultiplePeriodGraph = Piwik_Controller::getDateRangeRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite);
}
}
$token_auth = Piwik_Common::getRequestVar('token_auth', false);
$urlPrefix = "index.php?";
foreach ($reports as &$report) {
$parameters = array();
$parameters['module'] = 'API';
$parameters['method'] = 'ImageGraph.get';
$parameters['idSite'] = $idSite;
$parameters['apiModule'] = $report['module'];
$parameters['apiAction'] = $report['action'];
if (!empty($token_auth)) {
$parameters['token_auth'] = $token_auth;
}
// Forward custom Report parameters to the graph URL
if (!empty($report['parameters'])) {
$parameters = array_merge($parameters, $report['parameters']);
}
if (empty($report['dimension'])) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
} else {
$parameters['period'] = $periodForSinglePeriodGraph;
$parameters['date'] = $dateForSinglePeriodGraph;
}
$report['imageGraphUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters);
}
}
示例11: Piwik_GetWidgetsList
$widgets = Piwik_GetWidgetsList();
foreach($widgets as $category => $widgetsInCategory)
{
echo '<h2>'.$category . '</h2>';
foreach($widgetsInCategory as $widget)
{
echo '<h3>'.$widget['name'].'</h3>';
$widgetUrl = Piwik_Common::getArrayFromQueryString($url);
$widgetUrl['moduleToWidgetize'] = $widget['parameters']['module'];
$widgetUrl['actionToWidgetize'] = $widget['parameters']['action'];
$parameters = $widget['parameters'];
unset($parameters['module']);
unset($parameters['action']);
foreach($parameters as $name => $value)
{
if(is_array($value))
{
$value = current($value);
}
$widgetUrl[$name] = $value;
}
$widgetUrl = Piwik_Url::getQueryStringFromParameters($widgetUrl);
echo '<div id="widgetIframe"><iframe width="500" height="350"
src="'.$widgetUrl.'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>';
}
}
?>
</body></html>
示例12: initChartObjectData
protected function initChartObjectData()
{
// if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
// we don't expect plugin developers to return a well defined Piwik_DataTable_Array
if ($this->dataTable instanceof Piwik_DataTable) {
return parent::initChartObjectData();
}
$this->dataTable->applyQueuedFilters();
if (!$this->dataTable instanceof Piwik_DataTable_Array) {
throw new Exception("Expecting a DataTable_Array with custom format to draw an evolution chart");
}
// the X label is extracted from the 'period' object in the table's metadata
$xLabels = $uniqueIdsDataTable = array();
foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) {
//eg. "Aug 2009"
$xLabels[] = html_entity_decode($metadataDataTable['period']->getLocalizedShortString(), ENT_COMPAT, 'UTF-8');
// we keep track of all unique data table that we need to set a Y value for
$uniqueIdsDataTable[] = $idDataTable;
}
$requestedColumnNames = $this->getColumnsToDisplay();
$yAxisLabelToValue = array();
foreach ($this->dataTable->getArray() as $idDataTable => $dataTable) {
foreach ($dataTable->getRows() as $row) {
$rowLabel = $row->getColumn('label');
foreach ($requestedColumnNames as $requestedColumnName) {
$metricLabel = $this->getColumnTranslation($requestedColumnName);
if ($rowLabel !== false) {
// eg. "Yahoo! (Visits)"
$yAxisLabel = "{$rowLabel} ({$metricLabel})";
} else {
// eg. "Visits"
$yAxisLabel = $metricLabel;
}
if (($columnValue = $row->getColumn($requestedColumnName)) !== false) {
$yAxisLabelToValue[$yAxisLabel][$idDataTable] = $columnValue;
}
}
}
}
// make sure all column values are set to at least zero (no gap in the graph)
$yAxisLabelToValueCleaned = array();
$yAxisLabels = array();
foreach ($uniqueIdsDataTable as $uniqueIdDataTable) {
foreach ($yAxisLabelToValue as $yAxisLabel => $idDataTableToColumnValue) {
$yAxisLabels[$yAxisLabel] = $yAxisLabel;
if (isset($idDataTableToColumnValue[$uniqueIdDataTable])) {
$columnValue = $idDataTableToColumnValue[$uniqueIdDataTable];
} else {
$columnValue = 0;
}
$yAxisLabelToValueCleaned[$yAxisLabel][] = $columnValue;
}
}
$unit = $this->yAxisUnit;
if (empty($unit)) {
$unit = $this->guessUnitFromRequestedColumnNames($requestedColumnNames);
}
$this->view->setAxisXLabels($xLabels);
$this->view->setAxisYValues($yAxisLabelToValueCleaned);
$this->view->setAxisYLabels($yAxisLabels);
$this->view->setAxisYUnit($unit);
$firstDatatable = reset($this->dataTable->metadata);
$period = $firstDatatable['period'];
switch ($period->getLabel()) {
case 'day':
$steps = 7;
break;
case 'week':
$steps = 10;
break;
case 'month':
$steps = 6;
break;
case 'year':
$steps = 2;
break;
default:
$steps = 10;
break;
}
$this->view->setXSteps($steps);
if ($this->isLinkEnabled()) {
$axisXOnClick = array();
foreach ($this->dataTable->metadata as $idDataTable => $metadataDataTable) {
$period = $metadataDataTable['period'];
$dateInUrl = $period->getDateStart();
$link = Piwik_Url::getCurrentUrlWithoutQueryString() . '?' . Piwik_Url::getQueryStringFromParameters(array('module' => 'CoreHome', 'action' => 'index', 'idSite' => Piwik_Common::getRequestVar('idSite'), 'period' => $period->getLabel(), 'date' => $dateInUrl));
$axisXOnClick[] = $link;
}
$this->view->setAxisXOnClick($axisXOnClick);
}
}