You are here

function shs_json in Simple hierarchical select 7

Menu callback to get data in JSON format.

2 string references to 'shs_json'
shs_js in ./shs.module
Implements hook_js().
shs_menu in ./shs.module
Implements hook_menu().

File

./shs.module, line 47
Provides an additional widget for term fields to create hierarchical selects.

Code

function shs_json() {
  $result = array(
    'success' => FALSE,
    'data' => array(),
  );
  if (isset($_POST['callback'])) {

    // Get name of function we need to call to get the data.
    $_callback = check_plain($_POST['callback']);

    // Is this a valid callback?
    $valid_callbacks = shs_json_callbacks();
    if (isset($valid_callbacks[$_callback]) && !empty($valid_callbacks[$_callback]['callback']) && function_exists($valid_callbacks[$_callback]['callback'])) {

      // Get arguments and validate them.
      $post_args = isset($_POST['arguments']) && is_array($_POST['arguments']) ? $_POST['arguments'] : array();
      $arguments = _shs_json_callback_get_arguments($valid_callbacks[$_callback], $post_args);
      if (($callback_result = call_user_func_array($valid_callbacks[$_callback]['callback'], $arguments)) !== FALSE) {
        $result['success'] = TRUE;
        $result['data'] = $callback_result;
      }
    }
  }

  // Return result as JSON string.
  drupal_json_output($result);
}