You are here

function panels_node_autocomplete in Panels 5

Same name and namespace in other branches
  1. 5.2 panels.module \panels_node_autocomplete()
  2. 6.2 includes/callbacks.inc \panels_node_autocomplete()

Helper function for autocompletion of node titles. This is mostly stolen from clipper.

1 string reference to 'panels_node_autocomplete'
panels_menu in ./panels.module
Implementation of hook_menu()

File

./panels.module, line 840

Code

function panels_node_autocomplete($string) {
  if ($string != '') {

    // if there are node_types passed, we'll use those in a MySQL IN query.
    $result = db_query_range(db_rewrite_sql('SELECT n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE LOWER(title) LIKE LOWER("%%%s%%")'), $string, 0, 10);
    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
    $matches = array();
    while ($node = db_fetch_object($result)) {
      $n = $node->title;

      // Commas and quotes in terms are special cases, so encode 'em.
      if (preg_match('/,/', $node->title) || preg_match('/"/', $node->title)) {
        $n = '"' . preg_replace('/"/', '""', $node->title) . '"';
      }
      $matches[$prefix . $n] = '<span class="autocomplete_title">' . check_plain($node->title) . '</span> <span class="autocomplete_user">(' . t('by %user', array(
        '%user' => check_plain($node->name),
      )) . ')</span>';
    }
    print drupal_to_js($matches);
    exit;
  }
}