From 64aafb5ca73d329663a93f80ac9cf3e68a082866 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 21 Aug 2010 20:51:26 +0000 Subject: Merged r6534-6559 from 1.7 branch to trunk git-svn-id: http://code.elgg.org/elgg/trunk@6840 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/groups/languages/en.php | 2 +- mod/groups/start.php | 22 +++---- mod/groups/views/default/groups/grouplisting.php | 2 +- mod/search/search_hooks.php | 76 ++++++++++++++---------- mod/search/start.php | 40 ++++++++----- 5 files changed, 82 insertions(+), 60 deletions(-) (limited to 'mod') diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php index 58a6c7f31..7ecd00f57 100644 --- a/mod/groups/languages/en.php +++ b/mod/groups/languages/en.php @@ -133,7 +133,7 @@ $english = array( 'grouptopic:error' => 'Your group topic could not be created. Please try again or contact a system administrator.', 'groups:forumpost:edited' => "You have successfully edited the forum post.", 'groups:forumpost:error' => "There was a problem editing the forum post.", - 'groups:privategroup' => 'This group is private, requesting membership.', + 'groups:privategroup' => 'This group is closed. Requesting membership.', 'groups:notitle' => 'Groups must have a title', 'groups:cantjoin' => 'Can not join group', 'groups:cantleave' => 'Could not leave group', diff --git a/mod/groups/start.php b/mod/groups/start.php index 3278b6682..215311ef9 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -356,20 +356,18 @@ } /** - * Groups created, so add users to access lists. + * Groups created so create an access list for it */ function groups_create_event_listener($event, $object_type, $object) { - //if (($event == 'create') && ($object_type == 'group') && ($object instanceof ElggGroup)) - //{ - $group_id = create_access_collection(elgg_echo('groups:group') . ": " . $object->name); - if ($group_id) - { - $object->group_acl = $group_id; - } - else - return false; - //} + $ac_name = elgg_echo('groups:group') . ": " . $object->name; + $group_id = create_access_collection($ac_name, $object->guid); + if ($group_id) { + $object->group_acl = $group_id; + } else { + // delete group if access creation fails + return false; + } return true; } @@ -459,7 +457,6 @@ add_user_to_access_collection($user->guid, $acl); return true; - } /** @@ -475,7 +472,6 @@ remove_user_from_access_collection($user->guid, $acl); return true; - } /** diff --git a/mod/groups/views/default/groups/grouplisting.php b/mod/groups/views/default/groups/grouplisting.php index 48a7b1ace..687aebfa0 100644 --- a/mod/groups/views/default/groups/grouplisting.php +++ b/mod/groups/views/default/groups/grouplisting.php @@ -19,7 +19,7 @@ $icon = elgg_view( //get the membership type $membership = $vars['entity']->membership; -if($membership == 2) { +if($membership == ACCESS_PUBLIC) { $mem = elgg_echo("groups:open"); } else { $mem = elgg_echo("groups:closed"); diff --git a/mod/search/search_hooks.php b/mod/search/search_hooks.php index 86a6b452f..516bb2098 100644 --- a/mod/search/search_hooks.php +++ b/mod/search/search_hooks.php @@ -24,18 +24,19 @@ function search_objects_hook($hook, $type, $value, $params) { $params['joins'] = array($join); $fields = array('title', 'description'); - $where = search_get_where_sql('oe', $fields, $params); + $where = search_get_where_sql('oe', $fields, $params, FALSE); $params['wheres'] = array($where); - - $entities = elgg_get_entities($params); $params['count'] = TRUE; $count = elgg_get_entities($params); - + // no need to continue if nothing here. if (!$count) { return array('entities' => array(), 'count' => $count); } + + $params['count'] = FALSE; + $entities = elgg_get_entities($params); // add the volatile data for why these entities have been returned. foreach ($entities as $entity) { @@ -68,25 +69,28 @@ function search_groups_hook($hook, $type, $value, $params) { $join = "JOIN {$CONFIG->dbprefix}groups_entity ge ON e.guid = ge.guid"; $params['joins'] = array($join); + + $fields = array('name', 'description'); + + // force into boolean mode because we've having problems with the + // "if > 50% match 0 sets are returns" problem. + $where = search_get_where_sql('ge', $fields, $params, FALSE); - $where = "(ge.guid = e.guid - AND (ge.name LIKE '%$query%' - OR ge.description LIKE '%$query%' - ) - )"; $params['wheres'] = array($where); // override subtype -- All groups should be returned regardless of subtype. $params['subtype'] = ELGG_ENTITIES_ANY_VALUE; - $entities = elgg_get_entities($params); $params['count'] = TRUE; $count = elgg_get_entities($params); - + // no need to continue if nothing here. if (!$count) { return array('entities' => array(), 'count' => $count); } + + $params['count'] = FALSE; + $entities = elgg_get_entities($params); // add the volatile data for why these entities have been returned. foreach ($entities as $entity) { @@ -122,17 +126,20 @@ function search_users_hook($hook, $type, $value, $params) { $join = "JOIN {$CONFIG->dbprefix}users_entity ue ON e.guid = ue.guid"; $params['joins'] = array($join); - $where = "(ue.guid = e.guid - AND (ue.username LIKE '%$query%' - OR ue.name LIKE '%$query%' - ) - )"; +// $where = "(ue.guid = e.guid +// AND (ue.username LIKE '%$query%' +// OR ue.name LIKE '%$query%' +// ) +// )"; + + $fields = array('username', 'name'); + $where = search_get_where_sql('ue', $fields, $params, FALSE); + $params['wheres'] = array($where); // override subtype -- All users should be returned regardless of subtype. $params['subtype'] = ELGG_ENTITIES_ANY_VALUE; - $entities = elgg_get_entities($params); $params['count'] = TRUE; $count = elgg_get_entities($params); @@ -140,6 +147,9 @@ function search_users_hook($hook, $type, $value, $params) { if (!$count) { return array('entities' => array(), 'count' => $count); } + + $params['count'] = FALSE; + $entities = elgg_get_entities($params); // add the volatile data for why these entities have been returned. foreach ($entities as $entity) { @@ -212,7 +222,6 @@ function search_tags_hook($hook, $type, $value, $params) { $params['wheres'][] = "(msn.string IN ($tags_in) AND msv.string = '$query' AND $access)"; - $entities = elgg_get_entities($params); $params['count'] = TRUE; $count = elgg_get_entities($params); @@ -220,6 +229,9 @@ function search_tags_hook($hook, $type, $value, $params) { if (!$count) { return array('entities' => array(), 'count' => $count); } + + $params['count'] = FALSE; + $entities = elgg_get_entities($params); // add the volatile data for why these entities have been returned. foreach ($entities as $entity) { @@ -332,7 +344,7 @@ function search_comments_hook($hook, $type, $value, $params) { $e_access = get_access_sql_suffix('e'); $a_access = get_access_sql_suffix('a'); // @todo this can probably be done through the api.. - $q = "SELECT DISTINCT a.*, msv.string as comment FROM {$CONFIG->dbprefix}annotations a + $q = "SELECT count(DISTINCT a.id) as total FROM {$CONFIG->dbprefix}annotations a JOIN {$CONFIG->dbprefix}metastrings msn ON a.name_id = msn.id JOIN {$CONFIG->dbprefix}metastrings msv ON a.value_id = msv.id JOIN {$CONFIG->dbprefix}entities e ON a.entity_guid = e.guid @@ -341,13 +353,20 @@ function search_comments_hook($hook, $type, $value, $params) { AND $e_access AND $a_access $container_and - - LIMIT {$params['offset']}, {$params['limit']} "; - $comments = get_data($q); - - $q = "SELECT count(DISTINCT a.id) as total FROM {$CONFIG->dbprefix}annotations a + if (!$result = get_data($q)) { + return FALSE; + } + + $count = $result[0]->total; + + // don't continue if nothing there... + if (!$count) { + return array ('entities' => array(), 'count' => 0); + } + + $q = "SELECT DISTINCT a.*, msv.string as comment FROM {$CONFIG->dbprefix}annotations a JOIN {$CONFIG->dbprefix}metastrings msn ON a.name_id = msn.id JOIN {$CONFIG->dbprefix}metastrings msv ON a.value_id = msv.id JOIN {$CONFIG->dbprefix}entities e ON a.entity_guid = e.guid @@ -356,14 +375,11 @@ function search_comments_hook($hook, $type, $value, $params) { AND $e_access AND $a_access $container_and - "; - $result = get_data($q); - $count = $result[0]->total; + LIMIT {$params['offset']}, {$params['limit']} + "; - if (!is_array($comments)) { - return FALSE; - } + $comments = get_data($q); // @todo if plugins are disabled causing subtypes // to be invalid and there are comments on entities of those subtypes, diff --git a/mod/search/start.php b/mod/search/start.php index 781afb8ec..ae5e71c97 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -259,8 +259,12 @@ function search_highlight_words($words, $string) { ); foreach ($words as $word) { + // remove any boolean mode operators + $word = preg_replace("/([\-\+~])([\w]+)/i", '$2', $word); + // escape the delimiter and any other regexp special chars $word = preg_quote($word, '/'); + $search = "/($word)/i"; // must replace with placeholders in case one of the search terms is @@ -297,7 +301,9 @@ function search_remove_ignored_words($query, $format = 'array') { global $CONFIG; // don't worry about "s or boolean operators - $query = str_replace(array('"', '-', '+', '~'), '', stripslashes(strip_tags($query))); + //$query = str_replace(array('"', '-', '+', '~'), '', stripslashes(strip_tags($query))); + $query = stripslashes(strip_tags($query)); + $words = explode(' ', $query); $min_chars = $CONFIG->search_info['min_chars']; @@ -386,12 +392,8 @@ function search_get_where_sql($table, $fields, $params, $use_fulltext = TRUE) { $fields[$i] = "$table.$field"; } } - - // if we're not using full text, rewrite the query for bool mode. - // exploiting a feature(ish) of bool mode where +-word is the same as -word - if (!$use_fulltext) { - $query = '+' . str_replace(' ', ' +', $query); - } + + $where = ''; // if query is shorter than the min for fts words // it's likely a single acronym or similar @@ -405,22 +407,30 @@ function search_get_where_sql($table, $fields, $params, $use_fulltext = TRUE) { $likes_str = implode(' OR ', $likes); $where = "($likes_str)"; } else { - // if using advanced or paired "s, switch into boolean mode - if (!$use_fulltext - || (isset($params['advanced_search']) && $params['advanced_search']) - || elgg_substr_count($query, '"') >= 2 ) { + // if we're not using full text, rewrite the query for bool mode. + // exploiting a feature(ish) of bool mode where +-word is the same as -word + if (!$use_fulltext) { + $query = '+' . str_replace(' ', ' +', $query); + } + + // if using advanced, boolean operators, or paired "s, switch into boolean mode + $booleans_used = preg_match("/([\-\+~])([\w]+)/i", $query); + $advanced_search = (isset($params['advanced_search']) && $params['advanced_search']); + $quotes_used = (elgg_substr_count($query, '"') >= 2); + + if (!$use_fulltext || $booleans_used || $advanced_search || $quotes_used) { $options = 'IN BOOLEAN MODE'; } else { // natural language mode is default and this keyword isn't supported in < 5.1 //$options = 'IN NATURAL LANGUAGE MODE'; $options = ''; } - + // if short query, use query expansion. // @todo doesn't seem to be working well. - if (elgg_strlen($query) < 5) { - //$options .= ' WITH QUERY EXPANSION'; - } +// if (elgg_strlen($query) < 5) { +// $options .= ' WITH QUERY EXPANSION'; +// } $query = sanitise_string($query); $fields_str = implode(',', $fields); -- cgit v1.2.3