'navigate_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 users')) { $inputs['users'] = navigate_button(array( 'name' => 'users', 'content' => t('Users'), 'class' => 'navigate-search-users', 'default' => '0', 'on' => 1, 'off' => 0, 'help' => 'When this is checked, searching will search users.', '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-submit', '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, )); } // Get cache $cache = navigate_widget_cache_get($wid, 'content'); $output = theme('navigate_search_widget', $inputs, $content_type_inputs, $wid, $cache); return $output; } /** * Theme search widget */ function theme_navigate_search_widget($inputs, $content_type_inputs, $wid, $cache) { //navigate_button('menu', t('menu'), 'navigate-search-menu', $wid); // Hide results if there's no cache $hide = ''; if (!$cache) { $hide = ' style="display:none" '; } $search_inputs = ''; if (!user_access('navigate customize')) { $search_inputs = ' '; } $menu = ''; if (user_access('navigate_search search menu')) { $menu = ' '; } $users = ''; if (user_access('navigate_search search users')) { $users = ' '; } $content['widget'] = ' '. $search_inputs .' '; $content['title'] = t('Search'); $content_types = ''; 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", "navigate_search search users"); } /** * Implementation of hook_navigate_widget_process(). */ function navigate_search_navigate_widget_process($wid, $action) { switch ($action) { case 'search': navigate_search_search(); break; case 'search_content_type_all': navigate_search_select_all_types(); break; } } /** * Select all or none for content type select */ function navigate_search_select_all_types() { global $user; if (!$wid = db_result(db_query("SELECT wid FROM {navigate_widgets} WHERE wid = '%d' AND uid = '%d'", $_POST['wid'], $user->uid))) { return FALSE; } $before = 0; $after = 1; if (isset($_POST['none'])) { $before = 1; $after = 0; } $settings = navigate_widget_settings_get($wid); foreach ($settings as $key => $val) { if (strpos($key, 'content_type_') !== FALSE && $val == $before) { navigate_variable_set(array('name' => $key, 'value' => $after, 'wid' => $wid)); } } } function navigate_search_search() { global $_navigate_search_matches; $output = ''; $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 == '') { navigate_widget_cache_set($_POST['wid'], 'content', ''); 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 = ' '; $and = ''; $search_query = ''; $search_array = explode(' ', $phrase); foreach ($search_array as $value) { $search_query .= $and .' title LIKE "%%%s%" '; $search_values[] = $value; $and = ' AND '; } // Get types $or = ''; $type_query = ''; if (isset($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); $content_matches = ''; 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') { $content_matches = ''; if (drupal_strlen($phrase) < 3) { $output .= '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:
Press CTL+SHIFT+S to focus on the search bar, even if Navigate is hidden.
'); $help['title'] = 'Search'; return $help; } /** * Implementation of hook_theme(). */ function navigate_search_theme() { return array( 'navigate_search_widget' => array( 'arguments' => array('inputs' => NULL, 'content_type_inputs' => NULL, 'wid' => NULL), ), 'navigate_search_link' => array( 'arguments' => array('uid' => NULL, 'username' => NULL), ), ); } /** * Define stripos for php 4 */ if (!function_exists('stripos')) { function stripos($haystack, $needle) { return strpos($haystack, stristr( $haystack, $needle )); } }