search_autocomplete.autocomplete.inc in Search Autocomplete 6.4
Same filename and directory in other branches
Function to compute the various autocomplete features.
File
search_autocomplete.autocomplete.incView source
<?php
/**
* @file
* Function to compute the various autocomplete features.
*/
/**
* Autocomplete the view selection in admin.
*
* The function does not return if the auto-complete feature
* worked. Otherwise, it returns NULL.
*
* The user string so far
*/
function search_autocomplete_views_autocomplete($user_input = '') {
// anything yet?
if (!$user_input) {
echo drupal_to_js(array());
exit;
}
// current user has the right to do that?!
if (!user_access('access content')) {
drupal_access_denied();
return;
}
// Load all views.
$views = views_get_all_views();
// Select views with an according name
$matches = array();
foreach ($views as $view_id => $view) {
if (strpos($view->human_name, $user_input) !== false) {
$matches[$view_id] = $view->human_name;
}
}
// Return the json inputs.
echo drupal_to_js($matches);
exit;
}
function search_autocomplete_autocomplete($fid, $user_input = '') {
//$fid = arg(1); // get the form calling
$result = db_fetch_array(db_query('SELECT data_view, no_results FROM {search_autocomplete_forms} f WHERE f.fid = %d', $fid));
$view = views_get_view($result['data_view']);
$view->exposed_input['filter'] = $user_input;
if (method_exists($view, render)) {
echo $view
->render();
}
else {
echo json_encode(array());
}
exit;
}
Functions
Name![]() |
Description |
---|---|
search_autocomplete_autocomplete | |
search_autocomplete_views_autocomplete | Autocomplete the view selection in admin. |