'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 .= '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: