Commit 52b0ecef authored by Damien McKenna's avatar Damien McKenna Committed by Greg Knaddison
Browse files

Issue #3241330 by DamienMcKenna, klausi, Berdir, greggles: Remove unused AJAX callback

parent dcd99785
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -52,27 +52,6 @@ function _token_core_supported_modules() {
 * Implements hook_menu().
 */
function token_menu() {
  /*$items['token/autocomplete/all/%menu_tail'] = array(
    'page callback' => 'token_autocomplete',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'token.pages.inc',
  );*/
  $items['token/autocomplete/%token_type'] = array(
    'page callback' => 'token_autocomplete_token',
    'page arguments' => array(2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'token.pages.inc',
  );
  /*$items['token/autocomplete/%token_type/%menu_tail'] = array(
    'page callback' => 'token_autocomplete_token',
    'page arguments' => array(2, 3),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'token.pages.inc',
  );*/

  $items['token/tree'] = array(
    'page callback' => 'token_page_output_tree',
    'access callback' => TRUE,
+0 −75
Original line number Diff line number Diff line
@@ -293,78 +293,3 @@ function token_flush_cache_callback() {
  drupal_set_message(t('Token registry caches cleared.'));
  drupal_goto();
}

function token_autocomplete() {
  $args = func_get_args();
  $string = implode('/', $args);

  $token_info = token_info();

  preg_match_all('/\[([^\s\]:]*):?([^\s\]]*)?\]?/', $string, $matches);
  $types = $matches[1];
  $tokens = $matches[2];

  foreach ($types as $index => $type) {
    if (!empty($tokens[$index]) || isset($token_info['types'][$type])) {
      token_autocomplete_token($type, $tokens[$index]);
    }
    else {
      token_autocomplete_type($type);
    }
  }

}

function token_autocomplete_type($string = '') {
  $token_info = token_info();
  $types = $token_info['types'];
  $matches = array();

  foreach ($types as $type => $info) {
    if (!$string || strpos($type, $string) === 0) {
      $type_key = "[{$type}:";
      $matches[$type_key] = levenshtein($type, $string);
    }
  }

  if ($string) {
    asort($matches);
  }
  else {
    ksort($matches);
  }

  $matches = drupal_map_assoc(array_keys($matches));
  drupal_json_output($matches);
}

function token_autocomplete_token($token_type) {
  $args = func_get_args();
  array_shift($args);
  $string = trim(implode('/', $args));
  $string = substr($string, strrpos($string, '['));

  $token_type = $token_type['type'];
  $matches = array();

  if (!drupal_strlen($string)) {
    $matches["[{$token_type}:"] = 0;
  }
  else {
    $depth = max(1, substr_count($string, ':'));
    $tree = token_build_tree($token_type, array('flat' => TRUE, 'depth' => $depth));
    foreach (array_keys($tree) as $token) {
      if (strpos($token, $string) === 0) {
        $matches[$token] = levenshtein($token, $string);
        if (isset($tree[$token]['children'])) {
          $token = rtrim($token, ':]') . ':';
          $matches[$token] = levenshtein($token, $string);
        }
      }
    }
  }

  asort($matches);
  $matches = drupal_map_assoc(array_keys($matches));
  drupal_json_output($matches);
}