1 | <?php |
---|
2 | // $Id: content.menu.inc,v 1.2.2.1 2010/05/20 01:43:03 sdboyer Exp $ |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Contains menu item registration for the content tool. |
---|
7 | * |
---|
8 | * The menu items registered are AJAX callbacks for the things like |
---|
9 | * autocomplete and other tools needed by the content types. |
---|
10 | */ |
---|
11 | |
---|
12 | function ctools_content_menu(&$items) { |
---|
13 | $base = array( |
---|
14 | 'access arguments' => array('access content'), |
---|
15 | 'type' => MENU_CALLBACK, |
---|
16 | 'file' => 'includes/content.menu.inc', |
---|
17 | ); |
---|
18 | $items['ctools/autocomplete/node'] = array( |
---|
19 | 'page callback' => 'ctools_content_autocomplete_node', |
---|
20 | ) + $base; |
---|
21 | } |
---|
22 | |
---|
23 | /** |
---|
24 | * Helper function for autocompletion of node titles. |
---|
25 | */ |
---|
26 | function ctools_content_autocomplete_node($string) { |
---|
27 | if ($string != '') { |
---|
28 | $preg_matches = array(); |
---|
29 | $match = preg_match('/\[nid: (\d+)\]/', $string, $preg_matches); |
---|
30 | if (!$match) { |
---|
31 | $match = preg_match('/^nid: (\d+)/', $string, $preg_matches); |
---|
32 | } |
---|
33 | if ($match) { |
---|
34 | $arg = $preg_matches[1]; |
---|
35 | $where = "n.nid = %d"; |
---|
36 | } |
---|
37 | else { |
---|
38 | $arg = $string; |
---|
39 | $where = "LOWER(n.title) LIKE LOWER('%%%s%%')"; |
---|
40 | } |
---|
41 | if (!user_access('administer nodes')) { |
---|
42 | $where .= ' AND n.status = 1'; |
---|
43 | } |
---|
44 | |
---|
45 | $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where"), $arg, 0, 10); |
---|
46 | |
---|
47 | $matches = array(); |
---|
48 | while ($node = db_fetch_object($result)) { |
---|
49 | $name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name); |
---|
50 | $matches[$node->title . " [nid: $node->nid]"] = '<span class="autocomplete_title">' . check_plain($node->title) . '</span> <span class="autocomplete_user">(' . t('by @user', array('@user' => $name)) . ')</span>'; |
---|
51 | } |
---|
52 | drupal_json($matches); |
---|
53 | } |
---|
54 | } |
---|