'search', 'module' => 'navigate_search', 'content' => navigate_add_widget_link('', ''), ), ); break; } } /** * Generate search widget */ function navigate_search_widget($wid) { $settings = navigate_widget_settings_get($wid); if (user_access('navigate_search search menu')) { $inputs['menu'] = navigate_button(array( 'name' => 'menu', 'content' => t('menu'), 'class' => 'navigate-search-menu', 'default' => '1', 'on' => 1, 'off' => 0, 'help' => 'When this is checked, searching will search menu items.', 'wid' => $wid, )); } if (user_access('navigate_search search content')) { $inputs['quick'] = navigate_button(array( 'name' => 'type', 'content' => t('Quick'), 'class' => 'navigate-search-quick', 'group' => 'navigate_search_type', 'default' => 'quick', 'help' => 'When selected, this will search titles for your search phrase.', 'on' => 'quick', 'wid' => $wid, )); $inputs['full'] = navigate_button(array( 'name' => 'type', 'content' => t('Full'), 'class' => 'navigate-search-full', 'group' => 'navigate_search_type', 'default' => 'quick', 'help' => 'When selected, the search will be done using the site\'s search functions. This means that you will need to run cron.php before this will return any results.', 'on' => 'full', 'wid' => $wid, )); } $inputs['search'] = navigate_input(array( 'name' => 'search_phrase', 'class' => 'navigate-search-phrase', 'select_all' => TRUE, 'callback' => 'navigate_search_process', 'help' => 'Type a search phrase and press Enter to submit.', 'wid' => $wid, )); $inputs['search_button'] = navigate_callback_button(array( 'class' => 'navigate-search-button', 'callback' => 'navigate_search_process', 'content' => '', 'help' => 'Click to run search.', )); // Get content types $result = db_query('SELECT type FROM {node_type}'); while ($row = db_fetch_array($result)) { $content_type_inputs[$row['type']] = navigate_button(array( 'name' => 'content_type_'. $row['type'], 'content' => ucwords(str_replace('_', ' ', $row['type'])), 'class' => 'navigate-content-type-'. $row['type'], 'default' => 1, 'on' => 1, 'wid' => $wid, )); } $output = theme('navigate_search_widget', $inputs, $content_type_inputs, $wid); return $output; } /** * Theme search widget */ function theme_navigate_search_widget($inputs, $content_type_inputs, $wid) { //navigate_button('menu', t('menu'), 'navigate-search-menu', $wid); $content['widget'] = ' '; $content['title'] = t('Search'); foreach ($content_type_inputs as $type) { $content_types .= ''; } $content['settings'] = ''; return $content; } /** * Implementation of hook_perm() */ function navigate_search_perm() { return array("navigate_search search content", "navigate_search search menu"); } /** * Implementation of hook_navigate_widget_process() */ function navigate_search_navigate_widget_process($wid, $action) { switch ($action) { case 'search': navigate_search_search(); } } function navigate_search_search() { global $_navigate_search_matches; $settings = navigate_widget_settings_get($_POST['wid']); foreach ($settings as $key => $val) { if (strpos($key, 'content_type_') !== FALSE && $val == 1) { $types[] = str_replace('content_type_', '', $key); } } $phrase = check_plain($_POST['phrase']); if ($phrase == '') { return FALSE; } // Quick content search if (user_access('navigate_search search content')) { // Search content if ($settings['type'] == 'quick') { $search_content = TRUE; // Search by title $divider = ''; $search_array = explode(' ', $phrase); foreach ($search_array as $value) { $search_query .= $and .' title LIKE "%%%s%" '; $search_values[] = $value; $and = ' AND '; } // Get types foreach ($types as $type) { $type_query .= $or .' type="%s" '; $search_values[] = $type; $or = ' OR '; } if ($type_query) { $type_query = ' AND ('. $type_query .') '; } // Full query if ($search_query) { $full_query = 'SELECT title,nid FROM {node} WHERE ('. $search_query .') '. $type_query .' ORDER BY {node}.changed DESC, {node}.title ASC'; } $result = db_query_range($full_query, $search_values, 0, 50); while ($row = db_fetch_array($result)) { $menu_item = array( 'path' => 'node/'. $row['nid'], 'title' => $row['title'], ); $menu_item['wid'] = $_POST['wid']; $content_matches .= theme('navigate_link', $menu_item); $content_results = TRUE; } // Full content search } elseif ($settings['type'] == 'full') { if (strlen($phrase) < 3) { $output .= '
'. t('Please enter a longer phrase') .'
'; $divider = ''; } else { $search_content = TRUE; // Search using drupal search $divider = ''; // Get types if ($types) { $types_key = ' type:'. implode(',', $types); } //$phrase .= ' type:page '; $results = module_invoke('node', 'search', 'search', $phrase . $types_key); foreach ($results as $result) { $menu_item = array( 'path' => 'node/'. $result['node']->nid, 'title' => $result['title'], 'description' => '
Type: '. $result['type'] .'
'. $result['snippet'], ); $menu_item['wid'] = $_POST['wid']; $content_matches .= theme('navigate_link', $menu_item); $content_results = TRUE; } } } if ($search_content) { if (!$content_results) { $output .= '
'. t('No content results') .'
'; } else { $output .= ''. $content_matches; } } } // Search menu items if (user_access('navigate_search search menu')) { // Search menu if ($settings['menu'] == 1) { $output .= $divider; navigate_search_menu_tree(); $_navigate_search_matches = navigate_devel_menu($_navigate_search_matches); $phrase_array = explode(' ', $phrase); foreach ($_navigate_search_matches as $menu_item) { $searchable = $menu_item['title'] .' '. $menu_item['path'] .' '. $menu_item['description']; $match = 1; foreach ($phrase_array as $phrase) { if (stripos($searchable, $phrase, 0) === FALSE) { $match = 0; } } if ($match != 0) { $menu_item['wid'] = $wid; $menu_matches .= theme('navigate_link', $menu_item); $menu_results = TRUE; } } if (!$menu_results) { $output .= '
'. t('No menu results') .'
'; } else { $output .= ''. $menu_matches; } } } echo $output; } /** * Create an array of all menu items */ function navigate_search_menu_tree($pid = 1) { global $_navigate_search_matches; $menu = menu_get_menu(); if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { foreach ($menu['visible'][$pid]['children'] as $mid) { $_navigate_search_matches[] = menu_get_item($mid); navigate_menu_sub_tree($mid); } } } /** * Used with navigate_search_menu_tree to iterate through menu */ function navigate_menu_sub_tree($pid = 1) { $tree = navigate_search_menu_tree($pid); } /** * Implementation of hook_navigate_help_page() */ function navigate_search_navigate_help_page() { $help['access'] = FALSE; if (user_access('navigate_search search content') || user_access('navigate_search search menu')) { $help['access'] = TRUE; } $help['content'] = t('

The Search widget allows a user to search content and / or menu items. To use, type a word or two in the search box, and then presses enter or click the search icon to conduct the search. You can use partial words in your search as well. Here\'s a quick rundown of the settings:

'); $help['title'] = 'Search'; return $help; }