You are here

function kwresearch_toggle_site_keyword_js in Keyword Research 6

Same name and namespace in other branches
  1. 7 kwresearch.module \kwresearch_toggle_site_keyword_js()

AJAX handler to enable site keyword priority to be set

1 string reference to 'kwresearch_toggle_site_keyword_js'
kwresearch_menu in ./kwresearch.module
Implementation of hook_menu().

File

./kwresearch.module, line 645

Code

function kwresearch_toggle_site_keyword_js() {
  global $user;

  // check if valid request containing Drupal generated token
  if (empty($_POST['token']) || !drupal_valid_token($_POST['token'], 'kwresearch')) {
    drupal_access_denied();
    drupal_exit();
  }
  $keyword = check_plain($_POST['kwresearch_keyword']);
  $priority = check_plain($_POST['priority']);
  $keyword_obj = new stdClass();
  $keyword = strtolower(check_plain($_POST['kwresearch_keyword']));
  $keyword_obj->priority = check_plain($_POST['priority']);
  $kid = kwresearch_save_site_keyword($keyword, NULL, $keyword_obj);
  $keyword_obj = kwresearch_load_site_keyword($kid);
  if ($user->uid != $keyword_obj->uid) {
    $theuser = user_load($keyword_obj->uid);
  }
  else {
    $theuser = $user;
  }
  $site_priority_options = kwresearch_get_priority_options();
  $output = array();
  $output['data'] = array(
    'kid' => (int) $keyword_obj->kid,
    'keyword' => $keyword,
    'priority' => (int) $keyword_obj->priority,
    'priority_out' => $keyword_obj->priority >= 0 ? $site_priority_options[$keyword_obj->priority] : '-',
    'value' => (double) $keyword_obj->value,
    'value_out' => $keyword_obj->value >= 0 ? t('$') . number_format($keyword_obj->value, 2) : '-',
    'user_out' => $theuser->uid ? l($theuser->name, 'user/' . $theuser->uid) : '-',
  );
  drupal_json($output);
}