function uc_termsofservice_node_autocomplete in Ubercart Terms of Service 6
Same name and namespace in other branches
- 7 uc_termsofservice.module \uc_termsofservice_node_autocomplete()
Autocomplete callback, taken from panels module.
1 string reference to 'uc_termsofservice_node_autocomplete'
- uc_termsofservice_menu in ./
uc_termsofservice.module - Implements hook_menu().
File
- ./
uc_termsofservice.module, line 371 - Ubercart Terms of Service.
Code
function uc_termsofservice_node_autocomplete($string) {
// If there are node_types passed, we'll use those in a MySQL IN query.
if ($string != '') {
$preg_matches = array();
$match = preg_match('/\\[nid: (\\d+)\\]/', $string, $preg_matches);
if (!$match) {
$match = preg_match('/^nid: (\\d+)/', $string, $preg_matches);
}
if ($match) {
$arg = $preg_matches[1];
$where = "n.nid = %d";
}
else {
$arg = $string;
$where = "LOWER(title) LIKE LOWER('%%%s%%')";
}
if (!user_access('administer nodes')) {
$where .= " AND n.status = 1";
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE {$where}"), $arg, 0, 10);
$matches = array();
while ($node = db_fetch_object($result)) {
$name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name);
$matches[$node->title . " [nid: {$node->nid}]"] = '<span class="autocomplete_title">' . check_plain($node->title) . '</span> <span class="autocomplete_user">(' . t('by @user', array(
'@user' => $name,
)) . ')</span>';
}
drupal_json($matches);
}
}