1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* User menu callbacks for privatemsg_filter module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Return autocomplete results for tags.
|
10 |
|
|
*
|
11 |
|
|
* Most of this code has been lifted/modified from privatemsg_user_name_autocomplete().
|
12 |
|
|
*/
|
13 |
|
|
function privatemsg_filter_tags_autocomplete($string) {
|
14 |
|
|
|
15 |
|
|
// 1: Parse $string and build a list of tags.
|
16 |
|
|
$tags = array();
|
17 |
|
|
$fragments = explode(',', $string);
|
18 |
|
|
foreach ($fragments as $tag) {
|
19 |
|
|
$tag = trim($tag);
|
20 |
|
|
$tags[$tag] = $tag;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
// 2: Find the next tag suggestion.
|
24 |
|
|
$fragment = array_pop($tags);
|
25 |
|
|
$matches = array();
|
26 |
|
|
if (!empty($fragment)) {
|
27 |
|
|
$query = _privatemsg_assemble_query(array('tags_autocomplete', 'privatemsg_filter'), $fragment, $tags);
|
28 |
|
|
$prefix = count($tags) ? implode(", ", $tags) . ", " : '';
|
29 |
|
|
// 3: Build proper suggestions and print.
|
30 |
|
|
foreach ($query->execute() as $tag) {
|
31 |
|
|
$matches[$prefix . $tag->tag . ", "] = $tag->tag;
|
32 |
|
|
}
|
33 |
|
|
}
|
34 |
|
|
// convert to object to prevent drupal bug, see http://drupal.org/node/175361
|
35 |
|
|
drupal_json_output((object)$matches);
|
36 |
|
|
} |