aboutsummaryrefslogtreecommitdiff
path: root/mod/search/index.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-09 20:44:34 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-09 20:44:34 +0000
commit867c8c94a1bed4bc862bc22f05922a5d9492b401 (patch)
tree119a91d5ba0276e0be3ce1c627b28ebe124144c0 /mod/search/index.php
parentf803e43dbb0d81c29ad47ddab850cd4a637eb975 (diff)
downloadelgg-867c8c94a1bed4bc862bc22f05922a5d9492b401.tar.gz
elgg-867c8c94a1bed4bc862bc22f05922a5d9492b401.tar.bz2
Updated search to allow filtering of results by clicking on submenu items.
Fixes #1358: Using raw mysql_query() / fetch() to get ft_min/max vars since they aren't set on some versions of MySQL. git-svn-id: http://code.elgg.org/elgg/trunk@3645 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/search/index.php')
-rw-r--r--mod/search/index.php123
1 files changed, 110 insertions, 13 deletions
diff --git a/mod/search/index.php b/mod/search/index.php
index f9a96a60b..2927e6616 100644
--- a/mod/search/index.php
+++ b/mod/search/index.php
@@ -4,15 +4,15 @@
$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);
@@ -22,17 +22,97 @@ $params = array(
'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';
@@ -41,8 +121,17 @@ if ($search_type == 'entities' || $search_type == 'all') {
// 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;
@@ -83,12 +172,16 @@ if ($search_type == 'entities' || $search_type == 'all') {
}
// 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']);
@@ -115,11 +208,15 @@ if ($search_type == 'all' || $search_type != 'entities') {
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);