本文整理汇总了PHP中Piwik_Common::json_encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Common::json_encode方法的具体用法?PHP Piwik_Common::json_encode怎么用?PHP Piwik_Common::json_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Common
的用法示例。
在下文中一共展示了Piwik_Common::json_encode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
Piwik::checkUserIsNotAnonymous();
$view = Piwik_View::factory('index');
$this->setGeneralVariablesView($view);
$view->currentUserEmail = Piwik::getCurrentUserEmail();
$availableReports = Piwik_API_API::getInstance()->getReportMetadata($this->idSite);
$reportsByCategory = array();
foreach ($availableReports as $report) {
$reportsByCategory[$report['category']][] = $report;
}
unset($reportsByCategory['API']);
$reports = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
$reportsById = array();
foreach ($reports as &$report) {
$report['additional_emails'] = str_replace(',', "\n", $report['additional_emails']);
$report['reports'] = explode(',', str_replace('.', '_', $report['reports']));
$reportsById[$report['idreport']] = $report;
}
$view->downloadOutputType = Piwik_PDFReports_API::OUTPUT_DOWNLOAD;
$columnsCount = 2;
$view->newColumnAfter = ceil(count($reportsByCategory) / $columnsCount);
$view->reportsByCategory = $reportsByCategory;
$view->reportsJSON = Piwik_Common::json_encode($reportsById);
$view->periods = array_merge(array('never' => Piwik_Translate('General_Never')), Piwik_PDFReports_API::getPeriodToFrequency());
$view->defaultFormat = Piwik_PDFReports::DEFAULT_FORMAT;
$view->formats = Piwik_ReportRenderer::$availableReportRenderers;
$view->aggregateReportsFormats = Piwik_PDFReports_API::getAggregateReportsFormats();
$view->reports = $reports;
$view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
echo $view->render();
}
示例2: index
function index()
{
$view = Piwik_View::factory('index');
$view->availableWidgets = Piwik_Common::json_encode(Piwik_GetWidgetsList());
$this->setGeneralVariablesView($view);
echo $view->render();
}
示例3: index
public function index()
{
$view = Piwik_View::factory('index');
$this->setGeneralVariablesView($view);
$view->countWebsites = count(Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess());
// get report types
$reportTypes = Piwik_PDFReports_API::getReportTypes();
$view->reportTypes = $reportTypes;
$view->defaultReportType = self::DEFAULT_REPORT_TYPE;
$view->defaultReportFormat = Piwik_PDFReports::DEFAULT_REPORT_FORMAT;
$reportsByCategoryByType = array();
$reportFormatsByReportType = array();
$allowMultipleReportsByReportType = array();
foreach ($reportTypes as $reportType => $reportTypeIcon) {
// get report formats
$reportFormatsByReportType[$reportType] = Piwik_PDFReports_API::getReportFormats($reportType);
$allowMultipleReportsByReportType[$reportType] = Piwik_PDFReports_API::allowMultipleReports($reportType);
// get report metadata
$reportsByCategory = array();
$availableReportMetadata = Piwik_PDFReports_API::getReportMetadata($this->idSite, $reportType);
foreach ($availableReportMetadata as $reportMetadata) {
$reportsByCategory[$reportMetadata['category']][] = $reportMetadata;
}
$reportsByCategoryByType[$reportType] = $reportsByCategory;
}
$view->reportsByCategoryByReportType = $reportsByCategoryByType;
$view->reportFormatsByReportType = $reportFormatsByReportType;
$view->allowMultipleReportsByReportType = $allowMultipleReportsByReportType;
$reports = array();
$reportsById = array();
if (!Piwik::isUserIsAnonymous()) {
$reports = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
foreach ($reports as &$report) {
$report['recipients'] = Piwik_PDFReports_API::getReportRecipients($report);
$reportsById[$report['idreport']] = $report;
}
}
$view->reports = $reports;
$view->reportsJSON = Piwik_Common::json_encode($reportsById);
$view->downloadOutputType = Piwik_PDFReports_API::OUTPUT_INLINE;
$periods = array_merge(array('never' => Piwik_Translate('General_Never')), Piwik_PDFReports::getPeriodToFrequency());
// Do not display date range in selector
unset($periods['range']);
$view->periods = $periods;
$view->defaultPeriod = Piwik_PDFReports::DEFAULT_PERIOD;
$view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
echo $view->render();
}
示例4: renderTable
protected function renderTable($table)
{
$renderer = new Piwik_DataTable_Renderer_Php();
$renderer->setTable($table);
$renderer->setRenderSubTables($this->isRenderSubtables());
$renderer->setSerialize(false);
$renderer->setHideIdSubDatableFromResponse($this->hideIdSubDatatable);
$array = $renderer->flatRender();
if (!is_array($array)) {
$array = array('value' => $array);
}
// decode all entities
$callback = create_function('&$value,$key', 'if(is_string($value)){$value = html_entity_decode($value, ENT_QUOTES, "UTF-8");}');
array_walk_recursive($array, $callback);
$str = Piwik_Common::json_encode($array);
return $this->jsonpWrap($str);
}
示例5: update
static function update()
{
Piwik_Updater::updateDatabase(__FILE__, self::getSql());
if (!Piwik_PluginsManager::getInstance()->isPluginLoaded('PDFReports')) {
return;
}
try {
// Piwik_Common::prefixTable('pdf') has been heavily refactored to be more generic
// The following actions are taken in this update script :
// - create the new generic report table Piwik_Common::prefixTable('report')
// - migrate previous reports, if any, from Piwik_Common::prefixTable('pdf') to Piwik_Common::prefixTable('report')
// - delete Piwik_Common::prefixTable('pdf')
$reports = Piwik_FetchAll('SELECT * FROM `' . Piwik_Common::prefixTable('pdf') . '`');
foreach ($reports as $report) {
$idreport = $report['idreport'];
$idsite = $report['idsite'];
$login = $report['login'];
$description = $report['description'];
$period = $report['period'];
$format = $report['format'];
$display_format = $report['display_format'];
$email_me = $report['email_me'];
$additional_emails = $report['additional_emails'];
$reports = $report['reports'];
$ts_created = $report['ts_created'];
$ts_last_sent = $report['ts_last_sent'];
$deleted = $report['deleted'];
$parameters = array();
if (!is_null($additional_emails)) {
$parameters[Piwik_PDFReports::ADDITIONAL_EMAILS_PARAMETER] = preg_split('/,/', $additional_emails);
}
$parameters[Piwik_PDFReports::EMAIL_ME_PARAMETER] = is_null($email_me) ? Piwik_PDFReports::EMAIL_ME_PARAMETER_DEFAULT_VALUE : (bool) $email_me;
$parameters[Piwik_PDFReports::DISPLAY_FORMAT_PARAMETER] = $display_format;
Piwik_Query('INSERT INTO `' . Piwik_Common::prefixTable('report') . '` SET
idreport = ?, idsite = ?, login = ?, description = ?, period = ?,
type = ?, format = ?, reports = ?, parameters = ?, ts_created = ?,
ts_last_sent = ?, deleted = ?', array($idreport, $idsite, $login, $description, is_null($period) ? Piwik_PDFReports::DEFAULT_PERIOD : $period, Piwik_PDFReports::EMAIL_TYPE, is_null($format) ? Piwik_PDFReports::DEFAULT_REPORT_FORMAT : $format, Piwik_Common::json_encode(preg_split('/,/', $reports)), Piwik_Common::json_encode($parameters), $ts_created, $ts_last_sent, $deleted));
}
Piwik_Query('DROP TABLE `' . Piwik_Common::prefixTable('pdf') . '`');
} catch (Exception $e) {
}
}
示例6: exitWithException
/**
* Echos an error message & other information, then exits.
*
* @param Exception $e
* @param bool $authenticated
*/
protected function exitWithException($e, $authenticated)
{
if ($this->usingBulkTracking) {
// when doing bulk tracking we return JSON so the caller will know how many succeeded
$result = array('succeeded' => $this->countOfLoggedRequests);
// send error when in debug mode or when authenticated (which happens when doing log importing,
// for example)
if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG'] || $authenticated) {
$result['error'] = Piwik_Tracker_GetErrorMessage($e);
}
echo Piwik_Common::json_encode($result);
exit;
} else {
Piwik_Tracker_ExitWithException($e, $authenticated);
}
}
示例7: validateRequestedReports
private static function validateRequestedReports($idSite, $reportType, $requestedReports)
{
if (!self::allowMultipleReports($reportType)) {
//sms can only contain one report, we silently discard all but the first
$requestedReports = array_slice($requestedReports, 0, 1);
}
// retrieve available reports
$availableReportMetadata = self::getReportMetadata($idSite, $reportType);
$availableReportIds = array();
foreach ($availableReportMetadata as $reportMetadata) {
$availableReportIds[] = $reportMetadata['uniqueId'];
}
foreach ($requestedReports as $report) {
if (!in_array($report, $availableReportIds)) {
throw new Exception("Report {$report} is unknown or not available for report type '{$reportType}'.");
}
}
return Piwik_Common::json_encode($requestedReports);
}
示例8: getSitesForAutocompleter
function getSitesForAutocompleter()
{
$pattern = Piwik_Common::getRequestVar('term');
$sites = Piwik_SitesManager_API::getInstance()->getPatternMatchSites($pattern);
$pattern = str_replace('%', '', $pattern);
if (!count($sites)) {
$results[] = array('label' => Piwik_Translate('SitesManager_NotFound') . " <font class='autocompleteMatched'>{$pattern}</font>.", 'id' => '#');
} else {
if (strpos($pattern, '/') !== false && strpos($pattern, '\\/') === false) {
$pattern = str_replace('/', '\\/', $pattern);
}
foreach ($sites as $s) {
$hl_name = $s['name'];
if (strlen($pattern) > 0) {
@preg_match_all("/{$pattern}+/i", $hl_name, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
$hl_name = str_replace($match, '<font class="autocompleteMatched">' . $match . '</font>', $s['name']);
}
}
}
$results[] = array('label' => $hl_name, 'id' => $s['idsite'], 'name' => $s['name']);
}
}
print Piwik_Common::json_encode($results);
}
示例9: removeDisabledPluginFromLayout
protected function removeDisabledPluginFromLayout($layout)
{
$layout = str_replace("\n", "", $layout);
// if the json decoding works (ie. new Json format)
// we will only return the widgets that are from enabled plugins
$layoutObject = Piwik_Common::json_decode($layout, $assoc = false);
if (is_array($layoutObject)) {
$layoutObject = (object) array('config' => array('layout' => '33-33-33'), 'columns' => $layoutObject);
}
if (empty($layoutObject) || empty($layoutObject->columns)) {
$layoutObject = (object) array('config' => array('layout' => '33-33-33'), 'columns' => array());
}
foreach ($layoutObject->columns as &$row) {
if (!is_array($row)) {
$row = array();
continue;
}
foreach ($row as $widgetId => $widget) {
if (isset($widget->parameters->module)) {
$controllerName = $widget->parameters->module;
$controllerAction = $widget->parameters->action;
if (!Piwik_IsWidgetDefined($controllerName, $controllerAction)) {
unset($row[$widgetId]);
}
} else {
unset($row[$widgetId]);
}
}
}
$layout = Piwik_Common::json_encode($layoutObject);
return $layout;
}
示例10: render
public function render()
{
Piwik::overrideCacheControlHeaders();
$data = array('params' => array('axes' => &$this->axes, 'series' => &$this->series, 'seriesColors' => &$this->seriesColors), 'data' => &$this->data, 'tooltip' => &$this->tooltip, 'seriesPicker' => &$this->seriesPicker);
return Piwik_Common::json_encode($data);
}
示例11: setUserSettings
private function setUserSettings($user, $settings)
{
Piwik_SetOption($user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION, Piwik_Common::json_encode($settings));
}
示例12: convertMultiDimensionalArrayToJson
/**
* Render a multidimensional array to Json
* Handle Piwik_DataTable|Piwik_DataTable_Array elements in the first dimension only, following case does not work:
* array(
* array(
* Piwik_DataTable,
* 2 => array(
* 1,
* 2
* ),
* ),
* );
*
* @param array $array can contain scalar, arrays, Piwik_DataTable and Piwik_DataTable_Array
* @return string
*/
public static function convertMultiDimensionalArrayToJson($array)
{
// Naive but works for our current use cases
$arrayKeys = array_keys($array);
$isAssociative = !is_numeric($arrayKeys[0]);
if ($isAssociative) {
$json = "{";
} else {
$json = "[";
}
foreach ($array as $key => $value) {
if ($isAssociative) {
$json .= "\"" . $key . "\":";
}
switch (true) {
// Case dimension is a PHP array
case is_array($value):
$json .= Piwik_Common::json_encode($value);
break;
// Case dimension is a Piwik_DataTable_Array or a Piwik_DataTable
// Case dimension is a Piwik_DataTable_Array or a Piwik_DataTable
case $value instanceof Piwik_DataTable_Array || $value instanceof Piwik_DataTable:
$XMLRenderer = new Piwik_DataTable_Renderer_Json();
$XMLRenderer->setTable($value);
$renderedReport = $XMLRenderer->render();
$json .= $renderedReport;
break;
// Case scalar
// Case scalar
default:
$json .= Piwik_Common::json_encode($value);
break;
}
$json .= ",";
}
// Remove trailing ","
$json = substr($json, 0, strlen($json) - 1);
if ($isAssociative) {
$json .= "}";
} else {
$json .= "]";
}
return $json;
}
示例13: render
public function render()
{
Piwik::overrideCacheControlHeaders();
// See http://www.jqplot.com/docs/files/jqPlotOptions-txt.html
$data = array('params' => array('axes' => &$this->axes, 'series' => &$this->series, 'seriesColors' => &$this->seriesColors), 'data' => &$this->data, 'tooltip' => &$this->tooltip, 'seriesPicker' => &$this->seriesPicker);
Piwik_PostEvent('Visualization_Chart.render', $data);
return Piwik_Common::json_encode($data);
}