You are here

function piwik_reports_times in Piwik Web Analytics 6

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

File

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

Code

function piwik_reports_times() {
  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.
  $data1_params = array();
  $data1_params['module'] = 'VisitTime';
  $data1_params['action'] = 'getVisitInformationPerLocalTime';
  $data1_params['idSite'] = $piwik_site_id;
  $data1_params['period'] = $period_name;
  $data1_params['date'] = $date;
  $data1_params['viewDataTable'] = 'generateDataChartVerticalBar';
  $data1_params['loading'] = t('Loading data...');
  if (!empty($piwik_auth)) {
    $data1_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));
  $form = piwik_reports_dateselect_form();
  $output = theme('visitors_times', $piwik_url, $data1_url);
  $form['content'] = array(
    '#type' => 'markup',
    '#value' => $output,
  );
  return $form;
}