You are here

function evercurrent_key in Evercurrent 7.2

Same name and namespace in other branches
  1. 7 evercurrent.module \evercurrent_key()

Page callback for retrieving a new key. To be run only if evercurrent actually want a new key.

4 string references to 'evercurrent_key'
evercurrent_install in ./evercurrent.install
Implements hook_install().
evercurrent_menu in ./evercurrent.module
Implements hook_menu().
evercurrent_settings_form in ./evercurrent.admin.inc
Evercurrent settings form.
_evercurrent_get_key in ./evercurrent.send.inc
Helper function.

File

./evercurrent.module, line 60
evercurrent.module

Code

function evercurrent_key() {
  $received = json_decode($_POST['data'], TRUE);
  if (isset($received['key']) && _evercurrent_key_pattern_is_valid($received['key'])) {
    $key = $received['key'];
    variable_set('evercurrent_key', $key);

    // Even if the key is valid or not, close the listen mode.
    // We get an error immediately about the wrong key.
    variable_set('evercurrent_listen', FALSE);
    $message = 'Received';
    $type = 'status';
    module_load_include('inc', 'evercurrent', 'evercurrent.send');
    evercurrent_run_update_check(check_plain($key));
  }
  else {
    watchdog('evercurrent', 'Ditched key request with missing / buggy key.', 'error');
    variable_set('evercurrent_listen_status', 'error');
    $message = 'Invalid request.';
    $type = 'error';
  }
  $return_json = array(
    'message' => $message,
    'type' => $type,
  );
  drupal_json_output($return_json);
  drupal_exit();
}