$search_type = get_input('search_type', 'all');
// @todo there is a bug in get_input that makes variables have slashes sometimes.
-$query = sanitise_string(stripslashes(get_input('q', get_input('tag', '', FALSE), FALSE)));
+$query = stripslashes(get_input('q', get_input('tag', '', FALSE), FALSE));
// get limit and offset. override if on search dashboard, where only 2
// of each most recent entity types will be shown.
$limit = ($search_type == 'all') ? 2 : get_input('limit', 10);
$offset = ($search_type == 'all') ? 0 : get_input('offset', 0);
-$type = get_input('type', '');
-$subtype = get_input('subtype', '');
+$entity_type = get_input('entity_type', NULL);
+$entity_subtype = get_input('entity_subtype', NULL);
$owner_guid = get_input('owner_guid', NULL);
$friends = (int)get_input('friends', 0);
'offset' => $offset,
'limit' => $limit,
'search_type' => $search_type,
- 'type' => $type,
- 'subtype' => $subtype,
- 'tag_type' => $tag_type,
+ 'type' => $entity_type,
+ 'subtype' => $entity_subtype,
+// 'tag_type' => $tag_type,
'owner_guid' => $owner_guid,
- 'friends' => $friends
+// 'friends' => $friends
);
$results_html = '';
-if ($search_type == 'entities' || $search_type == 'all') {
- $types = get_registered_entity_types();
+//$results_html .= elgg_view_title(elgg_echo('search:results')) . "<input type=\"text\" value=\"$query\" />";
+$results_html .= elgg_view_title(elgg_echo('search:results'));
+$types = get_registered_entity_types();
+$custom_types = trigger_plugin_hook('search_types', 'get_types', $params, array());
+
+// add submenu items for all and native types
+// @todo should these maintain any existing type / subtype filters or reset?
+$data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => urlencode($subtype),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'all',
+ 'friends' => $friends
+));
+$url = "{$CONFIG->wwwroot}pg/search/?$data";
+add_submenu_item(elgg_echo('all'), $url);
+
+foreach ($types as $type => $subtypes) {
+ // @todo when using index table, can include result counts on each of these.
+ if (is_array($subtypes) && count($subtypes)) {
+ foreach ($subtypes as $subtype) {
+ $label = "item:$type:$subtype";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => urlencode($subtype),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'entities',
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+ }
+ } else {
+ $label = "item:$type";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'entities',
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+ }
+}
+
+// add submenu for custom searches
+foreach ($custom_types as $type) {
+ $label = "search_types:$type";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => $entity_subtype,
+ 'entity_type' => urlencode($entity_type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => $type,
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+}
+
+// check that we have an actual query
+if (!$query) {
+ $body .= "No query.";
+ $layout = elgg_view_layout('two_column_left_sidebar', '', $body);
+ page_draw($title, $layout);
+
+ return;
+}
+
+if ($search_type == 'all' || $search_type == 'entities') {
// to pass the correct search type to the views
$params['search_type'] = 'entities';
// if a plugin returns NULL or '' for subtype, pass to generic type search function.
// if still NULL or '' or empty(array()) no results found. (== don't show??)
foreach ($types as $type => $subtypes) {
+ if ($search_type != 'all' && $entity_type != $type) {
+ continue;
+ }
+
if (is_array($subtypes) && count($subtypes)) {
foreach ($subtypes as $subtype) {
+ // no need to search if we're not interested in these results
+ // @todo when using index table, allow search to get full count.
+ if ($search_type != 'all' && $entity_subtype != $subtype) {
+ continue;
+ }
$params['subtype'] = $subtype;
$params['type'] = $type;
}
// call custom searches
-if ($search_type == 'all' || $search_type != 'entities') {
+if ($search_type != 'entities' || $search_type == 'all') {
// get custom search types
$types = trigger_plugin_hook('search_types', 'get_types', $params, array());
if (is_array($types)) {
foreach ($types as $type) {
+ if ($search_type != 'all' && $search_type != $type) {
+ continue;
+ }
+
$params['search_type'] = $type;
unset($params['subtype']);
call search_section_start to display long bar with types and titles
call search
-
-
*/
-$layout = elgg_view_layout('two_column_left_sidebar', '', $results_html);
+if (!$results_html) {
+ $body = elgg_echo('search:no_results');
+} else {
+ $body = $results_html;
+}
+
+$layout = elgg_view_layout('two_column_left_sidebar', '', $body);
page_draw($title, $layout);
register_plugin_hook('search', 'comments', 'search_comments_hook');
// get server min and max allowed chars for ft searching
- $word_lens = get_data('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max');
-
$CONFIG->search_info = array();
- $CONFIG->search_info['min_chars'] = $word_lens[0]->min;
- $CONFIG->search_info['max_chars'] = $word_lens[0]->max;
+
+ // can't use get_data() here because some servers don't have these globals set,
+ // which throws a db exception.
+ $r = mysql_query('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max');
+ if ($word_lens = mysql_fetch_assoc($r)) {
+ $CONFIG->search_info['min_chars'] = $word_lens['min'];
+ $CONFIG->search_info['max_chars'] = $word_lens['max'];
+ } else {
+ // uhhh these are good numbers.
+ $CONFIG->search_info['min_chars'] = 4;
+ $CONFIG->search_info['max_chars'] = 90;
+ }
// add in CSS for search elements
extend_view('css', 'search/css');
}
$likes_str = implode(' OR ', $likes);
//$where = "($table.guid = e.guid AND ($likes_str))";
- $where = "($likes_str))";
+ $where = "($likes_str)";
} else {
// if using advanced or paired "s, switch into boolean mode
if ((isset($params['advanced_search']) && $params['advanced_search']) || substr_count($query, '"') >= 2 ) {