function quickupdate_autocomplete_search_projects in Quick update 7
Same name and namespace in other branches
- 8 quickupdate.module \quickupdate_autocomplete_search_projects()
Callback function for searching projects.
Parameters
string $string: The keywords that the user want to search. User can entry multiple words as a keyword.
1 string reference to 'quickupdate_autocomplete_search_projects'
- quickupdate_menu in ./
quickupdate.module - Implements hook_menu().
File
- ./
quickupdate.module, line 522 - Primarily Drupal hooks and global API functions.
Code
function quickupdate_autocomplete_search_projects($string = '') {
$matches = array();
$sources = array();
$searches = array();
$result = 10;
$keywords = !empty($string) ? explode(' ', $string) : array();
$projects = quickupdate_get_search_projects();
if (isset($projects['modules'])) {
foreach ($projects['modules'] as $short_name => $title) {
$sources[$short_name] = t('Module - !title (!short_name)', array(
'!short_name' => $short_name,
'!title' => $title,
));
$searches[$short_name] = $title . ' ' . $short_name;
}
}
if (isset($projects['themes'])) {
foreach ($projects['themes'] as $short_name => $title) {
$sources[$short_name] = t('Theme - !title (!short_name)', array(
'!short_name' => $short_name,
'!title' => $title,
));
$searches[$short_name] = $title . ' ' . $short_name;
}
}
foreach ($searches as $short_name => $title) {
foreach ($keywords as $keyword) {
// Wildcard search.
if (fnmatch("*" . $keyword . "*", $title)) {
$matches[$short_name] = $sources[$short_name];
continue;
}
}
if (count($matches) >= $result) {
break;
}
}
print drupal_json_output($matches);
exit;
}