discussthis.autocomplete.inc in Discuss This! 6
Same filename and directory in other branches
Function to compute the auto-complete string used in the discussion title.
File
discussthis.autocomplete.incView source
<?php
/**
* @file
* Function to compute the auto-complete string used in the discussion title.
*/
/**
* \brief Autocomplete a forum topic discussion title.
*
* The function does not return if the auto-complete feature
* worked. Otherwise, it returns NULL.
*
* \note
* The previous version included a $tid parameter. It was not
* being used and it would not work properly if the user was
* creating a new node (i.e. you cannot select a forum, then a
* title, at least, not dynamically... and it was shown as being
* like that before.)
*
* \param[in] $string The user string so far
*/
function discussthis_autocomplete($string = '') {
// anything yet?
if (!$string) {
echo drupal_to_js(array());
exit;
}
// current user has the right to do that?!
if (!user_access('access content')) {
drupal_access_denied();
return;
}
// Grab the first 10 forum nodes with titles like the string typed by the user so far
$sql = "SELECT n.nid, n.title FROM {node} n" . " WHERE n.type = 'forum' AND LOWER(n.title) LIKE LOWER";
if (variable_get('discussthis_autocomplete_contains', 0)) {
// a LIKE pattern that starts with % can be slow...
$sql .= "('%%%s%%')";
}
else {
$sql .= "('%s%%')";
}
$result = db_query_range(db_rewrite_sql($sql), $string, 0, 10);
$matches = array();
while ($node = db_fetch_object($result)) {
$matches[$node->nid] = check_plain($node->title) . ' [nid:' . $node->nid . ']';
}
echo drupal_to_js($matches);
exit;
}
// vim: ts=2 sw=2 et syntax=php
Functions
Name![]() |
Description |
---|---|
discussthis_autocomplete | \brief Autocomplete a forum topic discussion title. |