You are here

function uniqueness_dynamic_callback in Uniqueness 7

Same name and namespace in other branches
  1. 6 uniqueness.module \uniqueness_dynamic_callback()

Callback for uniqueness-search returns HTML stubs for related content.

1 string reference to 'uniqueness_dynamic_callback'
uniqueness_menu in ./uniqueness.module
Implements hook_menu().

File

./uniqueness.module, line 346
uniqueness.module

Code

function uniqueness_dynamic_callback() {

  // Build $values from $string.
  $values = array();

  // @todo refer to tags as 'terms'
  foreach (array(
    'tags',
    'title',
    'nid',
    'type',
  ) as $key) {
    if (isset($_GET[$key])) {
      $values[$key] = strip_tags($_GET[$key]);
    }
  }
  if (!empty($values)) {
    $related_content = uniqueness_content($values);
  }
  if (!empty($related_content)) {
    $items = array();
    $i = 0;
    $limit = variable_get('uniqueness_results_max', 10);
    foreach ($related_content as $nid => $item) {

      // Build items and avoid duplicates.
      if (!in_array($nid, array_keys($items))) {
        $items[$nid] = $item;
        $items[$nid]['href'] = url('node/' . $nid);
      }
      if (++$i > $limit) {

        // At least one more than the results_max limit were found
        // -> communicate "and more" to the widget
        $items[$nid]['more'] = TRUE;
        break;

        // LOOP EXIT
      }
    }
    drupal_json_output($items);
  }
  else {
    drupal_json_output('false');
  }
}