You are here

function theme_keyword_stats_report in Keyword Research 7

Same name and namespace in other branches
  1. 6 includes/stats_report.inc \theme_keyword_stats_report()

Themes keyword stats report

Parameters

unknown_type $analysis:

2 calls to theme_keyword_stats_report()
kwresearch_analyze_js in ./kwresearch.module
AJAX handler to generate keyword stats report for content analysis display
kwresearch_keyword_stats_report_page in includes/stats_report.inc
Displays keyword stats report

File

includes/stats_report.inc, line 236
Functions to generate the keyword stats report

Code

function theme_keyword_stats_report($analysis) {

  // TODO: Should this theme keyword_stats_report be declared in hook_theme()?

  //dsm(func_get_args());
  $count = 0;
  if (!$analysis['analysis']) {
    if (!is_array($analysis['inputs']['keyword'])) {
      $kws = explode(',', $analysis['inputs']['keyword']);
    }
    else {
      $kws = is_array($analysis['inputs']['keyword']);
    }
    foreach ($kws as $kw) {
      $analysis['analysis'][$kw] = array(
        'wordtracker_count' => 'NA',
      );
    }
  }
  $meta = $analysis['analysis']['_meta'];
  unset($analysis['analysis']['_meta']);
  $def_values = kwresearch_get_report_data_options_defaults();
  $data_options = variable_get('kwresearch_stats_report_data_options', $def_values);
  $column_th = kwresearch_get_report_data_options('stats', TRUE);

  // remove page priority column if no pid is given
  if (!isset($analysis['inputs']['pid']) || !$analysis['inputs']['pid']) {
    unset($column_th['page_priority']);
    unset($data_options['page_priority']);
  }
  $def_values = kwresearch_get_report_links_options_defaults();
  $links_options = variable_get('kwresearch_stats_report_links_options', $def_values);
  $hdrs[] = t('Keyword');
  if (is_array($data_options)) {
    foreach ($data_options as $k => $v) {
      if ($v) {
        $hdrs[] = $column_th[$k];
      }
    }
  }
  $sources = module_invoke_all('kwresearch_sources');
  $hdrs[] = t('More tools');
  $rows = array();
  if (is_array($analysis['analysis']) && !empty($analysis['analysis'])) {
    foreach ($analysis['analysis'] as $keyword => $values) {
      $row = array();
      $row[] = kwresearch_format_report_data_value(array(
        'term' => $keyword,
      ));
      foreach ($data_options as $k => $v) {
        if ($v) {
          $values['_meta'] = $meta;
          if (!($r = kwresearch_format_report_data_value($values, $keyword, $k))) {
            if (is_array($sources)) {
              foreach ($sources as $aid => $source) {
                if ($source['stats_report_values_callback'] && ($r = call_user_func($source['stats_report_values_callback'], $values, $keyword, $k))) {
                  break;
                }
              }
            }
          }
          $row[] = $r;
        }
      }
      $links = '<span class="kwresearch-more-tools">';
      foreach ($links_options as $k => $v) {
        if ($v) {
          $links .= kwresearch_format_report_links_value($values, $keyword, $k);
        }
      }
      $links .= '</span>';
      $row[] = $links;
      if (isset($analysis['inputs']['operations'])) {
        $ops = l(t('stats'), 'admin/structure/kwresearch/keyword_report/' . $keyword);

        //$ops .= ' | ' . l(t('edit'),'admin/structure/kwresearch/keyword_list/edit/' . $values['kid'], array('query' => 'destination=admin/structure/kwresearch/keyword_report/' . $keyword));
        $ops .= ' | ' . l(t('edit'), 'admin/structure/kwresearch/keyword_list/edit/' . $values['kid'], array(
          'attributes' => array(
            'target' => '_blank',
          ),
        ));

        //$row[] = $ops;
      }
      $rows[] = array(
        'data' => $row,
        'id' => 'kid-' . $values['kid'],
      );
    }
  }
  $attr = array(
    'id' => 'kwresearch-result-table-' . check_plain(str_replace(' ', '-', $analysis['inputs']['keyword'])),
    'class' => array(
      'kwresearch-result-table',
    ),
  );
  $output = '<div id="kwresearch-result-block-' . check_plain(str_replace(' ', '-', $analysis['inputs']['keyword'])) . '" class="kwresearch-result-block">';
  $empty = t('No keywords were found.');
  $vars = array(
    'header' => $hdrs,
    'rows' => $rows,
    'attributes' => $attr,
    'empty' => $empty,
  );
  $output .= theme('table', $vars);
  if (!empty($analysis['messages'])) {
    foreach ($analysis['messages'] as $msg) {
      $messages = '<div class="' . $msg['status'] . '">' . $msg['value'] . '</div>';
    }
  }
  if (isset($messages) && $messages) {
    $output .= '<div>' . $footer . '</div>';
  }
  $output .= "</div>";
  $a = array(
    'attributes' => array(
      'target' => '_blank',
    ),
  );
  $output .= t('For more keywords try the !google_keyword_tool.', array(
    '!google_keyword_tool' => l(t('Google Keyword Tool'), 'https://adwords.google.com/ko/KeywordPlanner/Home', array(
      'attributes' => array(
        'target' => 'google_keyword_tool',
      ),
    )),
  ));
  if (module_exists('kwresearch_google')) {
    $output .= ' ' . l(t('Import Google Keyword Tool data'), 'admin/structure/kwresearch/keyword_list/import_google', array(
      'attributes' => array(
        'target' => 'kwresearch_google_import',
      ),
    ));
  }
  return $output;
}