You are here

function seotools_dashboard_page in Drupal SEO Tools 7

Same name and namespace in other branches
  1. 6 seotools.report.inc \seotools_dashboard_page()

File

./seotools.report.inc, line 3

Code

function seotools_dashboard_page($rid = 'dashboard', $range = 30) {

  // Check that kwresearch and linkintel are install as this will crash if not.
  // Check enabled modules.
  $enabled_modules = array(
    'linkintel' => module_exists('linkintel'),
    'kwresearch' => module_exists('kwresearch'),
    'google_analytics_api' => module_exists('google_analytics_api'),
  );
  if (module_exists('google_analytics_api')) {
    if (!google_analytics_api_current_profile_id()) {
      $enabled_modules['google_analytics_api'] = FALSE;
      $msg = t('You enable full dashboard reporting you need to !link.', array(
        '!link' => l(t('set your Google Analytics ID'), 'admin/settings/google-analytics-api', array(
          'attributes' => array(
            'target' => 'google_analytics_api',
          ),
        )),
      ));
    }
  }
  else {
    $enabled_modules['google_analytics_api'] = FALSE;
    $msg = t('You enable full dashboard reporting you need to !link.', array(
      '!link' => l(t('enable the Google Analytics API module.'), 'http://drupal.org/project/google_analytics_api', array(
        'attributes' => array(
          'target' => 'drupal.org',
        ),
      )),
    ));
  }
  if (!$enabled_modules['google_analytics_api']) {
    $msg = t('SEO Tools has not been configured properly.  Please go to ' . l('seotools presets', 'admin/presets/seotools') . ' and ensure that it is configured properly.');
    drupal_set_message($msg, 'error');
    return t('Unable to generate dashboard.');
  }
  drupal_add_css(drupal_get_path('module', 'seotools') . '/seotools.css');
  drupal_add_js(drupal_get_path('module', 'seotools') . '/seotools.js');
  $gid = variable_get('google_analytics_api_profile_id', 0);
  if (!$gid) {
    return t('Google Analytics id not set.');
  }
  global $base_url;
  $siteURL = variable_get('seotools_base_url', $base_url);
  $e = explode('-', $range);
  if (count($e) == 1) {
    $date_range = seotools_get_dates($range);
  }
  else {

    // @todo Allow custom ranges.
  }
  $labels = array(
    'keywords' => t('keywords'),
  );
  if ($rid == 'dashboard') {
    $output .= '<div id="seotools-dashboard">' . "\n";
    $output .= '<div id="dashboard-pane-top">' . "\n";
    $output .= seotools_dashboard_analytics_box($gid, $siteURL, $date_range, $enabled_modules);
    $output .= '</div>' . "\n";
    $output .= '<div id="dashboard-pane-left">' . "\n";
    $output .= seotools_dashboard_keywords_box($gid, $siteURL, $date_range, $enabled_modules);
    $output .= seotools_dashboard_sources_box($gid, $siteURL, $date_range, $enabled_modules, $mediums_data);
    $output .= seotools_dashboard_map_box($gid, $siteURL, $date_range, $enabled_modules, $mediums_data);
    $output .= '</div>' . "\n";
    $output .= '<div class="dashboard-spacer">&nbsp;</div>';
    $output .= '<div id="dashboard-pane-right">' . "\n";
    $output .= seotools_dashboard_entrances_box($gid, $siteURL, $date_range, $enabled_modules);
    $output .= seotools_dashboard_referrers_box($gid, $siteURL, $date_range, $enabled_modules, $mediums_data);
    $output .= seotools_dashboard_pageviews_box($gid, $siteURL, $date_range, $enabled_modules, $mediums_data);
    $output .= '</div>' . "\n";
    $output .= '</div>' . "\n";
  }
  else {
    $output .= seotools_generate_report_top_and_trends($rid, $labels[$rid], 'full', $gid, $siteURL, $date_range, $enabled_modules);
  }
  return $output;
}