aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-08-11 10:18:29 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-08-11 10:18:29 +0000
commitbf1e40afcf8da4ea6e9d663531dfe3bc934483dc (patch)
tree374a9b640ab1cf21948fc466eeecda4c826882b7
parentb805a9bd7f1356e66fed15ced2c591cf4e9071fc (diff)
downloadelgg-bf1e40afcf8da4ea6e9d663531dfe3bc934483dc.tar.gz
elgg-bf1e40afcf8da4ea6e9d663531dfe3bc934483dc.tar.bz2
Added a search submenu.
git-svn-id: https://code.elgg.org/elgg/trunk@1819 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php64
-rw-r--r--engine/lib/group.php12
-rw-r--r--engine/lib/users.php6
-rw-r--r--search/index.php21
4 files changed, 99 insertions, 4 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index c938727ff..4cbc4eccc 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1866,6 +1866,70 @@
return $url;
}
+ }
+
+ /**
+ * Registers and entity type and subtype to return in search and other places.
+ * A description in the elgg_echo languages file of the form item:type:subtype
+ * is also expected.
+ *
+ * @param string $type The type of entity (object, site, user, group)
+ * @param string $subtype The subtype to register (may be blank)
+ * @return true|false Depending on success
+ */
+ function register_entity_type($type, $subtype) {
+
+ global $CONFIG;
+
+ $type = strtolower($type);
+ if (!in_array($type,array('object','site','group','user'))) return false;
+
+ if (!isset($CONFIG->registered_entities)) $CONFIG->registered_entities = array();
+ $CONFIG->registered_entities[$type][] = $subtype;
+
+ return true;
+
+ }
+
+ /**
+ * Returns registered entity types and subtypes
+ *
+ * @see register_entity_type
+ *
+ * @param string $type The type of entity (object, site, user, group) or blank for all
+ * @return array|false Depending on whether entities have been registered
+ */
+ function get_registered_entity_types($type = '') {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->registered_entities)) return false;
+ if (!empty($type)) $type = strtolower($type);
+ if (!empty($type) && empty($CONFIG->registered_entities[$type])) return false;
+
+ if (empty($type))
+ return $CONFIG->registered_entities;
+
+ return $CONFIG->registered_entities[$type];
+
+ }
+
+ /**
+ * Determines whether or not the specified entity type and subtype have been registered in the system
+ *
+ * @param string $type The type of entity (object, site, user, group)
+ * @param string $subtype The subtype (may be blank)
+ * @return true|false Depending on whether or not the type has been registered
+ */
+ function is_registered_entity_type($type, $subtype) {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->registered_entities)) return false;
+ $type = strtolower($type);
+ if (empty($CONFIG->registered_entities[$type])) return false;
+ if (in_array($subtype, $CONFIG->registered_entities[$type])) return true;
+
}
/**
diff --git a/engine/lib/group.php b/engine/lib/group.php
index da6876be9..f9bcd4b32 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -774,6 +774,16 @@
function get_users_membership($user_guid)
{
return get_entities_from_relationship('member', $user_guid, true);
- }
+ }
+
+ /**
+ * Performs initialisation functions for groups
+ *
+ */
+ function group_init() {
+ register_entity_type('group','');
+ }
+
+ register_elgg_event_handler('init','system','group_init');
?> \ No newline at end of file
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 80e9286fb..4939cc7fb 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -1161,6 +1161,8 @@
extend_elgg_settings_page('user/settings/language', 'usersettings/user', 1);
//register_action("user/language");
+ // Register the user type
+ register_entity_type('user','');
register_plugin_hook('usersettings:save','user','users_settings_save');
register_plugin_hook('search','all','search_list_users_by_name');
@@ -1176,7 +1178,9 @@
// Change this to set the number of users that display on the search page
$threshold = 4;
- if (!get_input('offset'))
+ $object = get_input('object');
+
+ if (!get_input('offset') && (empty($object) || $object == 'user'))
if ($users = search_for_user($tag,$threshold)) {
$countusers = search_for_user($tag,0,0,"",true);
diff --git a/search/index.php b/search/index.php
index 375d2fbdc..71e223d37 100644
--- a/search/index.php
+++ b/search/index.php
@@ -29,7 +29,24 @@
}
$owner_guid = get_input('owner_guid',0);
if (substr_count($owner_guid,',')) {
- $owner_guid = explode(",",$owner_guid);
+ $owner_guid_array = explode(",",$owner_guid);
+ } else {
+ $owner_guid_array = $owner_guid;
+ }
+
+ // Set up submenus
+ if ($object_types = get_registered_entity_types()) {
+
+ foreach($object_types as $object_type => $subtype_array) {
+ if (is_array($subtype_array) && sizeof($subtype_array))
+ foreach($subtype_array as $object_subtype) {
+ $label = 'item:' . $object_type;
+ if (!empty($object_subtype)) $label .= ':' . $object_subtype;
+ global $CONFIG;
+ add_submenu_item(elgg_echo($label), $CONFIG->wwwroot . "search/?tag=". urlencode($tag) ."&object=". urlencode($object_type) ."&tagtype=" . urlencode($md_type) . "&owner_guid=" . urlencode($owner_guid));
+ }
+ }
+
}
if (!empty($tag)) {
@@ -37,7 +54,7 @@
$body .= elgg_view_title(sprintf(elgg_echo('searchtitle'),$tag));
$body .= trigger_plugin_hook('search','',$tag,"");
$body .= elgg_view('search/startblurb',array('tag' => $tag));
- $body .= list_entities_from_metadata($md_type, $tag, $objecttype, $subtype, $owner_guid, 10, false, false);
+ $body .= list_entities_from_metadata($md_type, $tag, $objecttype, $subtype, $owner_guid_array, 10, false, false);
$body = elgg_view_layout('two_column_left_sidebar','',$body);
}