You are here

function yandex_metrics_report in Yandex.Metrics 6

Same name and namespace in other branches
  1. 7 yandex_metrics.module \yandex_metrics_report()

Menu callback; displays a Summary page containing reports and charts.

1 string reference to 'yandex_metrics_report'
yandex_metrics_menu in ./yandex_metrics.module
Implementation of hook_menu().

File

./yandex_metrics.module, line 273
The main code of Yandex.Metrics module.

Code

function yandex_metrics_report($filter = 'week') {
  $counter_id = yandex_metrics_get_counter_for_current_site();
  if (empty($counter_id)) {
    drupal_set_message(t('Please create Yandex.Metrics counter for the site first. See more details !link.', array(
      '!link' => l(t('here'), 'admin/settings/yandex_metrics'),
    )), 'error');
    return '';
  }
  $counter_code = variable_get('yandex_metrics_counter_code', '');
  if (empty($counter_code)) {
    drupal_set_message(t('Perhaps you have not yet placed Yandex.Metrics counter code on the site. You can do this !link.', array(
      '!link' => l(t('here'), 'admin/settings/yandex_metrics'),
    )), 'notice');
  }
  $authorisation_token = variable_get('yandex_metrics_auth_token', '');
  if (empty($authorisation_token)) {
    drupal_set_message(t('Please make sure that your application is authorized !link.', array(
      '!link' => l(t('here'), 'admin/settings/yandex_metrics/authorization'),
    )), 'error');
    return '';
  }
  drupal_add_css(drupal_get_path('module', 'yandex_metrics') . '/css/yandex_metrics.css');
  $output = '';
  $output .= drupal_get_form('yandex_metrics_filter_form');
  $use_ajax = variable_get('yandex_metrics_use_ajax', FALSE);
  if ($use_ajax) {
    $js_settings = array(
      'modulePath' => drupal_get_path('module', 'yandex_metrics'),
      'cleanUrls' => variable_get('clean_url', 0),
    );
    drupal_add_js(array(
      'yandex_metrics' => $js_settings,
    ), 'setting');
    drupal_add_js(drupal_get_path('module', 'yandex_metrics') . '/js/yandex_metrics.js');
    $output .= '<input type="hidden" id="yandex_metrics_counter_id" value="' . $counter_id . '" />';
    $output .= '<input type="hidden" id="yandex_metrics_filter" value="' . $filter . '" />';
    if (variable_get('yandex_metrics_visits_chart_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report" id="yandex_metrics_visits_chart"></div>';
    }
    if (variable_get('yandex_metrics_sources_chart_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report" id="yandex_metrics_sources_chart"></div>';
    }
    if (variable_get('yandex_metrics_search_phrases_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report" id="yandex_metrics_search_phrases"></div>';
    }
    if (variable_get('yandex_metrics_popular_content_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report" id="yandex_metrics_popular_content"></div>';
    }
    if (variable_get('yandex_metrics_geo_chart_visible', FALSE)) {
      $output .= '<div class="yandex_metrics-report" id="yandex_metrics_geo_chart"></div>';
    }
  }
  else {
    if (variable_get('yandex_metrics_visits_chart_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report">' . _yandex_metrics_visits_chart($counter_id, $filter) . '</div>';
    }
    if (variable_get('yandex_metrics_sources_chart_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report">' . _yandex_metrics_sources_chart($counter_id, $filter) . '</div>';
    }
    if (variable_get('yandex_metrics_search_phrases_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report">' . _yandex_metrics_search_phrases($counter_id, $filter) . '</div>';
    }
    if (variable_get('yandex_metrics_popular_content_visible', TRUE)) {
      $output .= '<div class="yandex_metrics-report">' . _yandex_metrics_popular_content($counter_id, $filter) . '</div>';
    }
    if (variable_get('yandex_metrics_geo_chart_visible', FALSE)) {
      $output .= '<div class="yandex_metrics-report">' . _yandex_metrics_geo_chart($counter_id, $filter) . '</div>';
    }
  }
  return $output;
}