function menu_editor_path_autocomplete in Menu Editor 6
Same name and namespace in other branches
- 6.3 me_path_autocomplete/menu_editor_path_autocomplete.module \menu_editor_path_autocomplete()
- 6.2 me_path_autocomplete/menu_editor_path_autocomplete.module \menu_editor_path_autocomplete()
Find nodes and URL aliases based on title.
Parameters
$string: Title of element to find.
Return value
List of elements with path as key.
1 string reference to 'menu_editor_path_autocomplete'
- menu_editor_path_autocomplete_menu in me_path_autocomplete/
menu_editor_path_autocomplete.module - Implement hook_menu().
File
- me_path_autocomplete/
menu_editor_path_autocomplete.module, line 39 - Find node paths on menu item creation via autocomplete.
Code
function menu_editor_path_autocomplete($string) {
$string = strtolower($string);
$title = filter_xss_admin($string);
$matches = array(
$string => $string,
);
foreach (module_invoke_all('menu_editor_placeholders') as $placeholder_code => $placeholder_path) {
if (!strlen($string) || count(explode($string, $placeholder_code)) > 1) {
$matches[$placeholder_code] = htmlentities($placeholder_code);
}
}
// Get a list of all nodes where the title matches the given string.
$query = db_query("SELECT * FROM {node} n WHERE n.title LIKE '%%%s%%'", $title);
while ($node = db_fetch_object($query)) {
// Add node path and title to list.
if (node_access('view', $node) && $node->status) {
$matches['node/' . $node->nid] = check_plain($node->title);
}
}
if (module_exists('path')) {
// Get a list of all URL aliases where the destination matches the given
// string.
$query = db_query("SELECT * FROM {url_alias} WHERE dst LIKE '%%%s%%'", $title);
while ($alias = db_fetch_object($query)) {
// Add alias source and destination to list (and add a special marker to
// the item).
$matches[$alias->src] = check_plain($alias->dst) . t('*');
}
}
drupal_json($matches);
}