Example #1
0
function members_extended_search($options = array())
{
    $db_prefix = elgg_get_config('dbprefix');
    $query = sanitise_string($options['query']);
    $options['joins'] = array("JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid", "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid", "JOIN {$db_prefix}metastrings msv ON n_table.value_id = msv.id");
    $r_where = "";
    $group_guid = $options['group_guid'];
    if ($group_guid) {
        $group = get_entity($group_guid);
        if (elgg_instanceof($group, 'group')) {
            elgg_set_page_owner_guid($group_guid);
            $options['joins'][] = "JOIN {$db_prefix}entity_relationships r ON e.guid = r.guid_one";
            $r_where = "AND (r.relationship = 'member' AND r.guid_two = '{$group_guid}')";
        }
    }
    // username and display name
    $fields = array('username', 'name');
    $where = search_get_where_sql('ue', $fields, $options, FALSE);
    // get the where clauses for the md names
    // can't use egef_metadata() because the n_table join comes too late.
    $clauses = _elgg_entities_get_metastrings_options('metadata', array('metadata_names' => $options['metadata_names']));
    $options['joins'] = array_merge($clauses['joins'], $options['joins']);
    // no fulltext index, can't disable fulltext search in this function.
    // $md_where .= " AND " . search_get_where_sql('msv', array('string'), $options, FALSE);
    $md_where = "(({$clauses['wheres'][0]}) AND msv.string LIKE '%{$query}%')";
    $options['wheres'] = array("(({$where}) OR ({$md_where}) {$r_where})");
    // override subtype -- All users should be returned regardless of subtype.
    $options['subtype'] = ELGG_ENTITIES_ANY_VALUE;
    $options['count'] = true;
    $count = elgg_get_entities($options);
    // no need to continue if nothing here.
    if (!$count) {
        return array('entities' => array(), 'count' => $count);
    }
    $options['count'] = FALSE;
    $options['order_by'] = search_get_order_by_sql('e', 'ue', $options['sort'], $options['order']);
    $entities = elgg_get_entities($options);
    return array('entities' => $entities, 'count' => $count);
}
Example #2
0
/**
 * Get users that match the search parameters.
 *
 * Searches on username, display name, and profile fields
 * 
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param array  $value  Empty array
 * @param array  $params Search parameters
 * @return array
 */
function search_users_hook($hook, $type, $value, $params)
{
    $params['joins'] = (array) elgg_extract('joins', $params, array());
    $params['wheres'] = (array) elgg_extract('wheres', $params, array());
    $db_prefix = elgg_get_config('dbprefix');
    $query = sanitise_string($params['query']);
    $join = "JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid";
    array_unshift($params['joins'], $join);
    // username and display name
    $fields = array('username', 'name');
    $where = search_get_where_sql('ue', $fields, $params, FALSE);
    // profile fields
    $profile_fields = array_keys(elgg_get_config('profile_fields'));
    if (!empty($profile_fields)) {
        $params['joins'][] = "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid";
        $params['joins'][] = "JOIN {$db_prefix}metastrings msv ON n_table.value_id = msv.id";
        // get the where clauses for the md names
        // can't use egef_metadata() because the n_table join comes too late.
        $clauses = _elgg_entities_get_metastrings_options('metadata', array('metadata_names' => $profile_fields, 'metadata_values' => null, 'metadata_name_value_pairs' => null, 'metadata_name_value_pairs_operator' => null, 'metadata_case_sensitive' => null, 'order_by_metadata' => null, 'metadata_owner_guids' => null));
        $params['joins'] = array_merge($clauses['joins'], $params['joins']);
        // no fulltext index, can't disable fulltext search in this function.
        // $md_where .= " AND " . search_get_where_sql('msv', array('string'), $params, FALSE);
        $md_where = "(({$clauses['wheres'][0]}) AND msv.string LIKE '%{$query}%')";
        $params['wheres'][] = "(({$where}) OR ({$md_where}))";
    } else {
        $params['wheres'][] = "{$where}";
    }
    // override subtype -- All users should be returned regardless of subtype.
    $params['subtype'] = ELGG_ENTITIES_ANY_VALUE;
    $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;
    if (isset($params['sort']) || !isset($params['order_by'])) {
        $params['order_by'] = search_get_order_by_sql('e', 'ue', $params['sort'], $params['order']);
    }
    $entities = elgg_get_entities($params);
    // add the volatile data for why these entities have been returned.
    foreach ($entities as $entity) {
        $title = search_get_highlighted_relevant_substrings($entity->name, $query);
        // include the username if it matches but the display name doesn't.
        if (false !== strpos($entity->username, $query)) {
            $username = search_get_highlighted_relevant_substrings($entity->username, $query);
            $title .= " ({$username})";
        }
        $entity->setVolatileData('search_matched_title', $title);
        if (!empty($profile_fields)) {
            $matched = '';
            foreach ($profile_fields as $md_name) {
                $metadata = $entity->{$md_name};
                if (is_array($metadata)) {
                    foreach ($metadata as $text) {
                        if (stristr($text, $query)) {
                            $matched .= elgg_echo("profile:{$md_name}") . ': ' . search_get_highlighted_relevant_substrings($text, $query);
                        }
                    }
                } else {
                    if (stristr($metadata, $query)) {
                        $matched .= elgg_echo("profile:{$md_name}") . ': ' . search_get_highlighted_relevant_substrings($metadata, $query);
                    }
                }
            }
            $entity->setVolatileData('search_matched_description', $matched);
        }
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #3
0
/**
 * Get comments that match the search parameters.
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param array  $value  Empty array
 * @param array  $params Search parameters
 * @return array
 */
function search_comments_hook($hook, $type, $value, $params)
{
    $db_prefix = elgg_get_config('dbprefix');
    $query = sanitise_string($params['query']);
    $limit = sanitise_int($params['limit']);
    $offset = sanitise_int($params['offset']);
    $params['annotation_names'] = array('generic_comment', 'group_topic_post');
    $params['joins'] = array("JOIN {$db_prefix}annotations a on e.guid = a.entity_guid", "JOIN {$db_prefix}metastrings msn on a.name_id = msn.id", "JOIN {$db_prefix}metastrings msv on a.value_id = msv.id");
    $fields = array('string');
    // force IN BOOLEAN MODE since fulltext isn't
    // available on metastrings (and boolean mode doesn't need it)
    $search_where = search_get_where_sql('msv', $fields, $params, FALSE);
    $container_and = '';
    if ($params['container_guid'] && $params['container_guid'] !== ELGG_ENTITIES_ANY_VALUE) {
        $container_and = 'AND e.container_guid = ' . sanitise_int($params['container_guid']);
    }
    $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 count(DISTINCT a.id) as total FROM {$db_prefix}annotations a\n\t\tJOIN {$db_prefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$db_prefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$db_prefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\t\t\t{$container_and}\n\t\t";
    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);
    }
    // no full text index on metastrings table
    if ($params['sort'] == 'relevance') {
        $params['sort'] = 'created';
    }
    $order_by = search_get_order_by_sql('a', null, $params['sort'], $params['order']);
    if ($order_by) {
        $order_by = "ORDER BY {$order_by}";
    }
    $q = "SELECT DISTINCT a.*, msv.string as comment FROM {$db_prefix}annotations a\n\t\tJOIN {$db_prefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$db_prefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$db_prefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\t\t\t{$container_and}\n\t\t\n\t\t{$order_by}\n\t\tLIMIT {$offset}, {$limit}\n\t\t";
    $comments = get_data($q);
    // @todo if plugins are disabled causing subtypes
    // to be invalid and there are comments on entities of those subtypes,
    // the counts will be wrong here and results might not show up correctly,
    // especially on the search landing page, which only pulls out two results.
    // probably better to check against valid subtypes than to do what I'm doing.
    // need to return actual entities
    // add the volatile data for why these entities have been returned.
    $entities = array();
    foreach ($comments as $comment) {
        $entity = get_entity($comment->entity_guid);
        // hic sunt dracones
        if (!$entity) {
            //continue;
            $entity = new ElggObject();
            $entity->setVolatileData('search_unavailable_entity', TRUE);
        }
        $comment_str = search_get_highlighted_relevant_substrings($comment->comment, $query);
        $comments_data = $entity->getVolatileData('search_comments_data');
        if (!$comments_data) {
            $comments_data = array();
        }
        $comments_data[] = array('annotation_id' => $comment->id, 'text' => $comment_str, 'owner_guid' => $comment->owner_guid, 'time_created' => $comment->time_created);
        $entity->setVolatileData('search_comments_data', $comments_data);
        $entities[] = $entity;
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #4
0
$limit = (int) get_input("limit", 50);
$result = array();
$user = elgg_get_logged_in_user_entity();
if (!empty($q)) {
    $db_prefix = elgg_get_config('dbprefix');
    $params['type'] = 'group';
    $params['limit'] = $limit;
    if (strlen($q) <= 3) {
        $params['query'] = $q;
    } else {
        $params['query'] = '*' . $q . '*';
    }
    $join = "JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid";
    $params['joins'] = array($join);
    $fields = array('name', 'description');
    $where = search_get_where_sql('ge', $fields, $params, FALSE);
    $params['wheres'] = array($where);
    // override subtype -- All groups should be returned regardless of subtype.
    $params['subtype'] = ELGG_ENTITIES_ANY_VALUE;
    //$params['count'] = TRUE;
    $groups = elgg_get_entities($params);
    foreach ($groups as $group) {
        //if (! $group->isMember($user)) {
        if (!$group->isPublicMembership()) {
            $result[] = array("type" => "group", "value" => $group->getGUID(), "label" => $group->name, "content" => "<a class=' text-unstyled ' href='" . $group->getURL() . "'><img class='mrgn-rght-sm' src='" . $group->getIconURL("small") . "' /><span>" . $group->name . "</span></a>", "name" => $group->name);
        } else {
            $result[] = array("type" => "group", "value" => $group->getGUID(), "label" => $group->name, "content" => "<a class=' text-unstyled ' href='" . $group->getURL() . "'><img class='mrgn-rght-sm' src='" . $group->getIconURL("small") . "' /><span>" . $group->name . "</span></a>", "name" => $group->name);
        }
        //}
    }
}
<?php

// Get all received messages fromId != owner_guid
$dbprefix = elgg_get_config('dbprefix');
$fromId = elgg_get_metastring_id('fromId');
echo elgg_view('admin/inbox/search');
$query = get_input('query');
$options = array('types' => 'object', 'subtypes' => 'messages', 'joins' => array("JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$fromId}", "JOIN {$dbprefix}metastrings fromId ON fromId.id = md.value_id"), 'wheres' => array('fromId.string != e.owner_guid'), 'preload_owners' => true, 'no_results' => elgg_echo('inbox:monitor:no_results'), 'item_view' => 'object/messages/admin');
if ($query) {
    $query = sanitize_string($query);
    $options['query'] = $query;
    $options['joins'][] = "JOIN {$dbprefix}objects_entity oe ON e.guid = oe.guid";
    $fields = array('title', 'description');
    $where = search_get_where_sql('oe', $fields, $options);
    $options['wheres'][] = $where;
}
$module = elgg_view('object/messages/controls');
$module .= elgg_list_entities($options);
echo elgg_format_element('div', array('class' => 'inbox-monitor-module'), $module);
/**
 * Plugin project search hook
 * 
 * @param string $hook
 * @param string $type
 * @param <type> $value
 * @param <type> $params
 * @return array
 */
function plugins_search_hook($hook, $type, $value, $params)
{
    global $CONFIG;
    $query = sanitise_string($params['query']);
    $join = "JOIN {$CONFIG->dbprefix}objects_entity oe ON e.guid = oe.guid";
    $params['joins'] = array($join);
    $params['joins'][] = "JOIN {$CONFIG->dbprefix}metadata summary_md on e.guid = summary_md.entity_guid";
    $params['joins'][] = "JOIN {$CONFIG->dbprefix}metastrings summary_msn on summary_md.name_id = summary_msn.id";
    $params['joins'][] = "JOIN {$CONFIG->dbprefix}metastrings summary_msv on summary_md.value_id = summary_msv.id";
    $fields = array('title', 'description');
    $where = search_get_where_sql('oe', $fields, $params);
    // cheat and use LIKE for the summary field
    // this is kinda dirty.
    $likes = array();
    $query_arr = explode(' ', $query);
    foreach ($query_arr as $word) {
        $likes[] = "summary_msv.string LIKE \"%{$word}%\"";
    }
    $like_str = implode(' OR ', $likes);
    //$params['wheres'] = array("($where OR ($like_str))");
    $params['wheres'] = array($where);
    //	If metastrings were fulltext'd we could do this :(
    //	$select = "summary_msv.string summary_string";
    //	$params['selects'] = array($select);
    //
    //	$fields = array('string');
    //	$summary_where = search_get_where_sql('summary_msv', $fields, $params);
    //	$params['wheres'][] = $summary_where;
    if (($category = get_input('category')) && $category != 'all') {
        $params['metadata_name_value_pair'] = array('name' => 'plugincat', 'value' => $category, 'case_sensitive' => FALSE);
    }
    $params['order_by'] = search_get_order_by_sql('e', 'oe', $params['sort'], $params['order']);
    $entities = elgg_get_entities_from_metadata($params);
    $params['count'] = TRUE;
    $count = elgg_get_entities_from_metadata($params);
    // no need to continue if nothing here.
    if (!$count) {
        return array('entities' => array(), 'count' => $count);
    }
    // add the volatile data for why these entities have been returned.
    foreach ($entities as $entity) {
        $title = search_get_highlighted_relevant_substrings($entity->title, $params['query']);
        $entity->setVolatileData('search_matched_title', $title);
        $desc = search_get_highlighted_relevant_substrings($entity->summary, $params['query']);
        $entity->setVolatileData('search_matched_description', $desc);
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #7
0
 /**
  * Returns a where clause for a search query.
  *
  * @see search_get_where_sql
  * 
  * @param str   $table        Prefix for table to search on
  * @param array $fields       Fields to match against
  * @param array $params       Original search params
  * @param bool  $use_fulltext Use fulltext search
  * @return str
  */
 public static function getFieldSearchWhereClause($table, $fields, $params, $use_fulltext = TRUE)
 {
     if (is_callable('search_get_where_sql')) {
         return search_get_where_sql($table, $fields, $params, $use_fulltext);
     }
     $query = $params['query'];
     // add the table prefix to the fields
     foreach ($fields as $i => $field) {
         if ($table) {
             $fields[$i] = "{$table}.{$field}";
         }
     }
     $where = '';
     $search_info = elgg_get_config('search_info');
     // if query is shorter than the min for fts words
     // it's likely a single acronym or similar
     // switch to literal mode
     if (elgg_strlen($query) < $search_info['min_chars']) {
         $likes = array();
         $query = sanitise_string($query);
         foreach ($fields as $field) {
             $likes[] = "{$field} LIKE '%{$query}%'";
         }
         $likes_str = implode(' OR ', $likes);
         $where = "({$likes_str})";
     } else {
         // 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;
         $options = '';
         if (!$use_fulltext || $booleans_used || $advanced_search || $quotes_used) {
             $options = 'IN BOOLEAN MODE';
         }
         $query = sanitise_string($query);
         $fields_str = implode(',', $fields);
         $where = "(MATCH ({$fields_str}) AGAINST ('{$query}' {$options}))";
     }
     return $where;
 }
/**
 * Get groups that match the search parameters.
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param array  $value  Empty array
 * @param array  $params Search parameters
 * @return array
 */
function group_subtypes_search_hook($hook, $type, $value, $params)
{
    $params['joins'] = (array) elgg_extract('joins', $params, array());
    $params['wheres'] = (array) elgg_extract('wheres', $params, array());
    $db_prefix = elgg_get_config('dbprefix');
    $query = sanitise_string($params['query']);
    $join = "JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid";
    array_unshift($params['joins'], $join);
    $fields = array('name', 'description');
    $where = search_get_where_sql('ge', $fields, $params);
    $params['wheres'][] = $where;
    $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;
    if (isset($params['sort']) || !isset($params['order_by'])) {
        $params['order_by'] = search_get_order_by_sql('e', 'ge', $params['sort'], $params['order']);
    }
    $entities = elgg_get_entities($params);
    // add the volatile data for why these entities have been returned.
    foreach ($entities as $entity) {
        $name = search_get_highlighted_relevant_substrings($entity->name, $query);
        $entity->setVolatileData('search_matched_title', $name);
        $description = search_get_highlighted_relevant_substrings($entity->description, $query);
        $entity->setVolatileData('search_matched_description', $description);
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #9
0
/**
 * Allow subsites to be found when searching
 *
 * @param string $hook
 * @param string $type
 * @param mixed $returnvalue
 * @param mixed $params
 * @return mixed
 */
function subsite_manager_search_subsite_hook($hook, $type, $returnvalue, $params)
{
    $join = "JOIN " . get_config("dbprefix") . "sites_entity se ON e.guid = se.guid";
    $params['joins'] = array($join);
    $fields = array('name', 'description', 'url');
    $where = search_get_where_sql('se', $fields, $params, FALSE);
    $params['wheres'] = array($where);
    $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) {
        $title = search_get_highlighted_relevant_substrings($entity->name, $params['query']);
        $entity->setVolatileData('search_matched_title', $title);
        $desc = search_get_highlighted_relevant_substrings($entity->description, $params['query']);
        $entity->setVolatileData('search_matched_description', $desc);
        $icon = elgg_view_entity_icon($entity, 'tiny');
        $entity->setVolatileData("search_icon", $icon);
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #10
0
/**
 * Return default results for searches on comments.
 *
 * @param unknown_type $hook
 * @param unknown_type $type
 * @param unknown_type $value
 * @param unknown_type $params
 * @return unknown_type
 */
function search_comments_hook($hook, $type, $value, $params)
{
    global $CONFIG;
    $query = sanitise_string($params['query']);
    $params['annotation_names'] = array('generic_comment', 'group_topic_post');
    $params['joins'] = array("JOIN {$CONFIG->dbprefix}annotations a on e.guid = a.entity_guid", "JOIN {$CONFIG->dbprefix}metastrings msn on a.name_id = msn.id", "JOIN {$CONFIG->dbprefix}metastrings msv on a.value_id = msv.id");
    $fields = array('string');
    // force IN BOOLEAN MODE since fulltext isn't
    // available on metastrings (and boolean mode doesn't need it)
    $search_where = search_get_where_sql('msv', $fields, $params, FALSE);
    $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\n\t\tJOIN {$CONFIG->dbprefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$CONFIG->dbprefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$CONFIG->dbprefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\n\t\tLIMIT {$params['offset']}, {$params['limit']}\n\t\t";
    $comments = get_data($q);
    $q = "SELECT count(DISTINCT a.id) as total FROM {$CONFIG->dbprefix}annotations a\n\t\tJOIN {$CONFIG->dbprefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$CONFIG->dbprefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$CONFIG->dbprefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\t\t";
    $result = get_data($q);
    $count = $result[0]->total;
    if (!is_array($comments)) {
        return FALSE;
    }
    // @todo if plugins are disabled causing subtypes
    // to be invalid and there are comments on entities of those subtypes,
    // the counts will be wrong here and results might not show up correctly,
    // especially on the search landing page, which only pulls out two results.
    // probably better to check against valid subtypes than to do what I'm doing.
    // need to return actual entities
    // add the volatile data for why these entities have been returned.
    $entities = array();
    foreach ($comments as $comment) {
        $entity = get_entity($comment->entity_guid);
        // hic sunt dracones
        if (!$entity) {
            //continue;
            $entity = new ElggObject();
            $entity->setVolatileData('search_unavailable_entity', TRUE);
        }
        $comment_str = search_get_highlighted_relevant_substrings($comment->comment, $query);
        $entity->setVolatileData('search_match_annotation_id', $comment->id);
        $entity->setVolatileData('search_matched_comment', $comment_str);
        $entity->setVolatileData('search_matched_comment_owner_guid', $comment->owner_guid);
        $entity->setVolatileData('search_matched_comment_time_created', $comment->time_created);
        $entities[] = $entity;
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #11
0
/**
 * Adds search query options to the ege* options array
 *
 * @param array  $options   ege* options
 * @param string $query     Query
 * @return array
 */
function user_sort_add_search_query_options(array $options = array(), $query = '')
{
    if (!elgg_is_active_plugin('search') || !$query) {
        return $options;
    }
    $query = sanitize_string($query);
    $advanced = elgg_extract('advanced_search', $options, false);
    $dbprefix = elgg_get_config('dbprefix');
    $options['joins']['users_entity'] = "JOIN {$dbprefix}users_entity users_entity ON users_entity.guid = e.guid";
    $fields = array('name');
    if (elgg_get_plugin_setting('username', 'user_sort', true)) {
        $fields[] = 'username';
    }
    $where = search_get_where_sql('users_entity', $fields, ['query' => $query], false);
    $profile_fields = array_keys((array) elgg_get_config('profile_fields'));
    $profile_fields = array_diff($profile_fields, $fields);
    if ($advanced && !empty($profile_fields)) {
        $options['joins']['profile_fields_md'] = "JOIN {$dbprefix}metadata profile_fields_md on e.guid = profile_fields_md.entity_guid";
        $options['joins']['profile_fields_msv'] = "JOIN {$dbprefix}metastrings profile_fields_msv ON n_table.value_id = profile_fields_msv.id";
        $clauses = _elgg_entities_get_metastrings_options('metadata', array('metadata_names' => $profile_fields, 'metadata_values' => null, 'metadata_name_value_pairs' => null, 'metadata_name_value_pairs_operator' => null, 'metadata_case_sensitive' => null, 'order_by_metadata' => null, 'metadata_owner_guids' => null));
        $options['joins'] = array_merge($clauses['joins'], $options['joins']);
        $profile_fields_md_where = "(({$clauses['wheres'][0]}) AND profile_fields_msv.string LIKE '%{$query}%')";
        $options['wheres'][] = "(({$where}) OR ({$profile_fields_md_where}))";
    } else {
        $options['wheres'][] = "{$where}";
    }
    return $options;
}
Example #12
0
 $value = sanitise_string($value);
 // Match title and description
 $options['joins'][] = "INNER JOIN {$CONFIG->dbprefix}objects_entity o ON (e.guid = o.guid)";
 $fields = array('title', 'description');
 $wheres[] = search_get_where_sql('o', $fields, array('query' => $value, 'joins' => $options['joins']));
 //Match author name and username
 if (in_array('author-name', $settings['text']) || in_array('author-username', $settings['text'])) {
     $options['joins'][] = "INNER JOIN {$CONFIG->dbprefix}users_entity u ON (e.owner_guid = u.guid)";
     $fields = array();
     if (in_array('author-name', $settings['text'])) {
         $fields[] = 'name';
     }
     if (in_array('author-username', $settings['text'])) {
         $fields[] = 'username';
     }
     $wheres[] = search_get_where_sql('u', $fields, array('query' => $value, 'joins' => $options['joins']));
 }
 // Match summary and tags
 if (in_array('summary', $settings['text']) || in_array('tags', $settings['text'])) {
     $value_parts = explode(' ', $value);
     $fields = array();
     if (in_array('summary', $settings['text'])) {
         $fields[] = 'summary';
     }
     if (in_array('tags', $settings['text'])) {
         $fields[] = 'tags';
     }
     $fields_str = "'" . implode("','", $fields) . "'";
     $options['joins'][] = "INNER JOIN {$CONFIG->dbprefix}metadata tm ON (e.guid = tm.entity_guid)";
     $options['joins'][] = "INNER JOIN {$CONFIG->dbprefix}metastrings tm_name ON (tm.name_id = tm_name.id AND tm_name.string IN ({$fields_str}))";
     $options['joins'][] = "INNER JOIN {$CONFIG->dbprefix}metastrings tm_value ON (tm.value_id = tm_value.id)";