You are here

function kwresearch_toggle_page_keyword_js in Keyword Research 6

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

AJAX handler to create, delete and set priorities for page keywords

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

File

./kwresearch.module, line 717

Code

function kwresearch_toggle_page_keyword_js() {

  // check if valid request containing Drupal generated token
  if (empty($_POST['token']) || !drupal_valid_token($_POST['token'], 'kwresearch')) {
    drupal_access_denied();
    drupal_exit();
  }
  $keyword = strtolower(check_plain($_POST['kwresearch_keyword']));
  $nid = check_plain($_POST['nid']);
  $path = check_plain($_POST['path']);
  $pid = !$nid ? $path : $nid;
  $page_keyword_obj = new stdClass();
  $page_keyword_obj->priority = check_plain($_POST['priority']);
  kwresearch_save_page_keyword($pid, $keyword, NULL, $page_keyword_obj);
  $output = array();
  $output['data'] = array(
    'keyword' => $keyword,
    'priority' => (int) $page_keyword_obj->priority,
  );
  drupal_json($output);
}