You are here

function piwik_reports_settings in Piwik Web Analytics 6

1 string reference to 'piwik_reports_settings'
piwik_reports_menu in modules/piwik_reports/piwik_reports.module
Implementation of hook_menu().

File

modules/piwik_reports/piwik_reports.pages.inc, line 124
Drupal Module: Piwik Reports

Code

function piwik_reports_settings() {
  global $user;

  // Get basic configuration variables.
  $piwik_url = variable_get('piwik_url_http', '');
  $piwik_site_id = variable_get('piwik_site_id', '');
  $piwik_auth = $user->piwik['piwik_token_auth'];
  $period = $_SESSION['piwik_reports_period'];
  if ($period == 1) {

    // Special handling for "yesterday" = 1.
    // The yesterday date value is required.
    $date = _piwik_reports_select_period($period);
  }
  else {

    // Otherwise it returns the today date value.
    $date = _piwik_reports_select_period(0);
  }
  $period_name = _piwik_reports_get_period_name($period);

  // Create an array of data URL parameters for easier maintenance.
  // Browser families
  $data1_params = array();
  $data1_params['module'] = 'UserSettings';
  $data1_params['action'] = 'getBrowserType';
  $data1_params['idSite'] = $piwik_site_id;
  $data1_params['period'] = $period_name;
  $data1_params['date'] = $date;
  $data1_params['filter_limit'] = 5;
  $data1_params['filter_sort_column'] = 'nb_uniq_visitors';
  $data1_params['filter_sort_order'] = 'desc';
  $data1_params['viewDataTable'] = 'generateDataChartPie';
  $data1_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data1_params['token_auth'] = $piwik_auth;
  }

  // Client configurations
  $data2_params = array();
  $data2_params['module'] = 'UserSettings';
  $data2_params['action'] = 'getConfiguration';
  $data2_params['idSite'] = $piwik_site_id;
  $data2_params['period'] = $period_name;
  $data2_params['date'] = $date;
  $data2_params['enable_sort'] = 1;
  $data2_params['filter_limit'] = 5;
  $data2_params['filter_sort_column'] = 'nb_uniq_visitors';
  $data2_params['filter_sort_order'] = 'desc';
  $data2_params['viewDataTable'] = 'generateDataChartPie';
  $data2_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data2_params['token_auth'] = $piwik_auth;
  }

  // Operating systems
  $data3_params = array();
  $data3_params['module'] = 'UserSettings';
  $data3_params['action'] = 'getOS';
  $data3_params['idSite'] = $piwik_site_id;
  $data3_params['period'] = $period_name;
  $data3_params['date'] = $date;
  $data3_params['filter_limit'] = 10;
  $data3_params['filter_sort_column'] = 'nb_uniq_visitors';
  $data3_params['filter_sort_order'] = 'desc';
  $data3_params['viewDataTable'] = 'generateDataChartPie';
  $data3_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data3_params['token_auth'] = $piwik_auth;
  }

  // Screen resolutions
  $data4_params = array();
  $data4_params['module'] = 'UserSettings';
  $data4_params['action'] = 'getResolution';
  $data4_params['idSite'] = $piwik_site_id;
  $data4_params['period'] = $period_name;
  $data4_params['date'] = $date;
  $data4_params['filter_limit'] = 10;
  $data4_params['filter_sort_column'] = 'nb_uniq_visitors';
  $data4_params['filter_sort_order'] = 'desc';
  $data4_params['viewDataTable'] = 'generateDataChartPie';
  $data4_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data4_params['token_auth'] = $piwik_auth;
  }

  // Build the data URL with all params and urlencode it.
  // Note: drupal_urlencode() doesn't work with Flash variables!
  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
  $data2_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data2_params));
  $data3_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data3_params));
  $data4_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data4_params));

  // Render HTML code.
  $output = theme('visitors_settings', $piwik_url, $data1_url, $data2_url, $data3_url, $data4_url);
  $form = piwik_reports_dateselect_form();
  $form['content'] = array(
    '#type' => 'markup',
    '#value' => $output,
  );
  return $form;
}