예제 #1
0
}
// allow overrides for titles
$search_type_str = elgg_echo("search_types:{$vars['params']['search_type']}");
if (array_key_exists('search_type', $vars['params']) && $search_type_str != "search_types:{$vars['params']['search_type']}") {
    $type_str = $search_type_str;
}
// get pagination
if (array_key_exists('pagination', $vars['params']) && $vars['params']['pagination']) {
    $nav .= elgg_view('navigation/pagination', array('baseurl' => $url, 'offset' => $vars['params']['offset'], 'count' => $vars['results']['count'], 'limit' => $vars['params']['limit']));
} else {
    $nav = '';
}
// get any more links.
$more_check = $vars['results']['count'] - ($vars['params']['offset'] + $vars['params']['limit']);
$more = $more_check > 0 ? $more_check : 0;
if ($more) {
    $title_key = $more == 1 ? 'comment' : 'comments';
    $more_str = sprintf(elgg_echo('search:more'), $count, $type_str);
    $more_link = "<div class='search_listing'><a href=\"{$url}\">{$more_str}</a></div>";
} else {
    $more_link = '';
}
$body = "<div class='search_listing_category_title'>" . elgg_view_title($type_str) . "</div>";
foreach ($entities as $entity) {
    if ($view = search_get_search_view($vars['params'], 'entity')) {
        $body .= elgg_view($view, array('entity' => $entity, 'params' => $vars['params'], 'results' => $vars['results']));
    }
}
echo $body;
echo $more_link;
echo $nav;
예제 #2
0
    $more = $more_check > 0 ? $more_check : 0;
    if ($more) {
        $title_key = $more == 1 ? 'comment' : 'comments';
        $more_str = elgg_echo('search:more', array($count, $type_str));
        $more_url = elgg_http_remove_url_query_element($url, 'limit');
        $more_link = "<li class='elgg-item search-list-more'><a href=\"{$more_url}\">{$more_str}</a></li>";
    } else {
        $more_link = '';
    }
}
// @todo once elgg_view_title() supports passing a $vars array use it
$body = elgg_view('page/elements/title', array('title' => $type_str, 'class' => 'search-heading-category'));
$body .= '<ul class="elgg-list search-list">';
foreach ($entities as $entity) {
    $view_params = array("type" => $entity->type, "subtype" => $entity->getSubtype(), "search_type" => $vars['params']["search_type"]);
    $view = search_get_search_view($view_params, 'entity');
    if ($view) {
        $id = "elgg-{$entity->getType()}-{$entity->getGUID()}";
        $body .= "<li id=\"{$id}\" class=\"elgg-item\">";
        if ($combine_search_results && get_input("search_type", "all") == "all") {
            // add a floating tag
            $subtype = $entity->getSubtype();
            $url_options = array("class" => "float-alt elgg-quiet", "href" => "search?q=" . $vars['params']['query'] . "&entity_subtype=" . $subtype . "&entity_type=" . $entity->getType() . "&search_type=entities", "text" => elgg_echo("item:" . $entity->getType() . ":" . $subtype));
            if ($vars['params']['container_guid']) {
                $url_options["href"] .= "&container_guid=" . $vars['params']['container_guid'];
            }
            $body .= elgg_view("output/url", $url_options);
        }
        $body .= elgg_view($view, array('entity' => $entity, 'params' => $vars['params'], 'results' => $vars['results']));
        $body .= '</li>';
    }
예제 #3
0
파일: index.php 프로젝트: lorea/Hydra-dev
 if (empty($params['query'])) {
     continue;
 }
 foreach ($subtypes as $subtype) {
     unset($current_params['count']);
     if ($search_type !== 'all' && $params['subtype'] !== $subtype) {
         // only want count if doing specific search
         $current_params['count'] = true;
     }
     if ($combine_search_results !== 'no' && $search_type == 'all') {
         // content comes from somewhere else
         $current_params['count'] = true;
     }
     $current_params['subtype'] = $subtype;
     $current_params['type'] = $type;
     $view = search_get_search_view($current_params, 'list');
     if (!$view) {
         // no output view, so skip this
         continue;
     }
     $results = elgg_trigger_plugin_hook('search', "{$type}:{$subtype}", $current_params, NULL);
     if ($results === FALSE) {
         // someone is saying not to display these types in searches.
         continue;
     }
     if (is_array($results) && !count($results)) {
         // no results, but results searched in hook.
     } elseif (!$results) {
         // no results and not hooked.  use default type search.
         // don't change the params here, since it's really a different subtype.
         // Will be passed to elgg_get_entities().
예제 #4
0
            $count = " <span class='elgg-quiet'>[" . $search_result_counters[$label] . "]</span>";
        }
        $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_type' => $type, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'search_type' => 'entities', 'friends' => $friends)));
        $url = elgg_get_site_url() . "search?{$data}";
        $menu_item = new ElggMenuItem($label, elgg_echo($label) . $count, $url);
        elgg_register_menu_item('page', $menu_item);
    }
}
// add sidebar for custom searches
foreach ($custom_types as $type) {
    $label = "search_types:{$type}";
    $count = "";
    if (array_key_exists($label, $search_result_counters)) {
        $count = " <span class='elgg-quiet'>[" . $search_result_counters[$label] . "]</span>";
    }
    $data = htmlspecialchars(http_build_query(array('q' => $query, 'search_type' => $type, 'container_guid' => $container_guid)));
    $url = elgg_get_site_url() . "search?{$data}";
    $menu_item = new ElggMenuItem($label, elgg_echo($label) . $count, $url);
    elgg_register_menu_item('page', $menu_item);
}
// this is passed the original params because we don't care what actually
// matched (which is out of date now anyway).
// we want to know what search type it is.
if (elgg_is_xhr()) {
    echo $body;
} else {
    $layout_view = search_get_search_view($params, 'layout');
    $layout = elgg_view($layout_view, array('params' => $params, 'body' => $body));
    $title = elgg_echo('search:results', array("\"{$display_query}\""));
    echo elgg_view_page($title, $layout);
}
예제 #5
0
function index_search()
{
    $entityTypes = array();
    if ($_GET['check']) {
        foreach ($_GET['check'] as $entityType) {
            $entityTypes[] = $entityType;
        }
    }
    // $search_type == all || entities || trigger plugin hook
    $search_type = get_input('search_type', 'all');
    // @todo there is a bug in get_input that makes variables have slashes sometimes.
    // @todo is there an example query to demonstrate ^
    // XSS protection is more important that searching for HTML.
    $query = stripslashes(get_input('index-query', get_input('tag', '')));
    if (function_exists('mb_convert_encoding')) {
        $display_query = mb_convert_encoding($query, 'HTML-ENTITIES', 'UTF-8');
    } else {
        // if no mbstring extension, we just strip characters
        $display_query = preg_replace("/[^-]/", "", $query);
    }
    $display_query = htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false);
    // check that we have an actual query
    if (!$query) {
        $title = sprintf(elgg_echo('search:results'), "\"{$display_query}\"");
        $body = elgg_view_title(elgg_echo('search:search_error'));
        $body .= elgg_echo('search:no_query');
        $layout = elgg_view_layout('one_sidebar', array('content' => $body));
        echo elgg_view_page($title, $layout);
        return;
    }
    // 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);
    $order = get_input('order', 'desc');
    if ($order != 'asc' && $order != 'desc') {
        $order = 'desc';
    }
    // set up search params
    $params = array('query' => $query, 'offset' => $offset, 'limit' => $limit, 'sort' => $sort, 'order' => $order, 'search_type' => $search_type, 'type' => $entity_type, 'subtype' => $entity_subtype, 'owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'pagination' => $search_type == 'all' ? FALSE : TRUE);
    $types = get_registered_entity_types();
    //$types['object']
    foreach ($types as $type => $subtypes) {
        //only include subtypes the user wishes to search for
        foreach ($subtypes as $key => $subtype) {
            $flag = false;
            error_log($type . $key . $subtype);
            foreach ($entityTypes as $entityType) {
                if ($subtype == $entityType) {
                    $flag = true;
                }
            }
            if ($flag !== true) {
                //var_dump($types[$type][$key]);
                unset($types[$type][$key]);
                //$types = array_values($types);
            }
        }
        //only include types user wishes to search for - this is only for groups and users as they are not sub types
        $flag = false;
        if ($type != 'object') {
            foreach ($entityTypes as $entityType) {
                if ($type == $entityType) {
                    $flag = true;
                }
            }
            if ($flag !== true) {
                unset($types[$type]);
            }
        }
    }
    // add sidebar items for all and native types
    // @todo should these maintain any existing type / subtype filters or reset?
    $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_subtype' => $entity_subtype, 'entity_type' => $entity_type, 'owner_guid' => $owner_guid, 'search_type' => 'all')));
    $url = elgg_get_site_url() . "search?{$data}";
    $menu_item = new ElggMenuItem('all', elgg_echo('all'), $url);
    elgg_register_menu_item('page', $menu_item);
    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 = htmlspecialchars(http_build_query(array('q' => $query, 'entity_subtype' => $subtype, 'entity_type' => $type, 'owner_guid' => $owner_guid, 'search_type' => 'entities', 'friends' => $friends)));
                $url = elgg_get_site_url() . "search?{$data}";
                $menu_item = new ElggMenuItem($label, elgg_echo($label), $url);
                elgg_register_menu_item('page', $menu_item);
            }
        } else {
            $label = "item:{$type}";
            $data = htmlspecialchars(http_build_query(array('q' => $query, 'entity_type' => $type, 'owner_guid' => $owner_guid, 'search_type' => 'entities', 'friends' => $friends)));
            $url = elgg_get_site_url() . "search?{$data}";
            $menu_item = new ElggMenuItem($label, elgg_echo($label), $url);
            elgg_register_menu_item('page', $menu_item);
        }
    }
    // start the actual search
    $results_html = '';
    if ($search_type == 'all' || $search_type == 'entities') {
        // to pass the correct current search type to the views
        $current_params = $params;
        $current_params['search_type'] = 'entities';
        // foreach through types.
        // if a plugin returns FALSE for subtype ignore it.
        // 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;
                    }
                    $current_params['subtype'] = $subtype;
                    $current_params['type'] = $type;
                    $results = elgg_trigger_plugin_hook('search', "{$type}:{$subtype}", $current_params, NULL);
                    if ($results === FALSE) {
                        // someone is saying not to display these types in searches.
                        continue;
                    } elseif (is_array($results) && !count($results)) {
                        // no results, but results searched in hook.
                    } elseif (!$results) {
                        // no results and not hooked.  use default type search.
                        // don't change the params here, since it's really a different subtype.
                        // Will be passed to elgg_get_entities().
                        $results = elgg_trigger_plugin_hook('search', $type, $current_params, array());
                    }
                    if (is_array($results['entities']) && $results['count']) {
                        if ($view = search_get_search_view($current_params, 'list')) {
                            $results_html .= elgg_view($view, array('results' => $results, 'params' => $current_params));
                        }
                    }
                }
            }
            // pull in default type entities with no subtypes
            $current_params['type'] = $type;
            $current_params['subtype'] = ELGG_ENTITIES_NO_VALUE;
            $results = elgg_trigger_plugin_hook('search', $type, $current_params, array());
            if ($results === FALSE) {
                // someone is saying not to display these types in searches.
                continue;
            }
            if (is_array($results['entities']) && $results['count']) {
                if ($view = search_get_search_view($current_params, 'list')) {
                    $results_html .= elgg_view($view, array('results' => $results, 'params' => $current_params));
                }
            }
        }
    }
    // highlight search terms
    if ($search_type == 'tags') {
        $searched_words = array($display_query);
    } else {
        $searched_words = search_remove_ignored_words($display_query, 'array');
    }
    $highlighted_query = search_highlight_words($searched_words, $display_query);
    $body = elgg_view_title(elgg_echo('search:results', array("\"{$highlighted_query}\"")));
    if (!$results_html) {
        $body .= elgg_view('search/no_results');
    } else {
        $body .= $results_html;
    }
    // this is passed the original params because we don't care what actually
    // matched (which is out of date now anyway).
    // we want to know what search type it is.
    $layout_view = search_get_search_view($params, 'layout');
    $layout = elgg_view($layout_view, array('params' => $params, 'body' => $body));
    $title = elgg_echo('search:results', array("\"{$display_query}\""));
    echo elgg_view_page($title, $layout);
}
예제 #6
0
function search_advanced_search_index_combined_search($combine_search_results = 'no', $params)
{
    if (elgg_extract('search_type', $params) !== 'all') {
        return;
    }
    if (empty($params['query'])) {
        return;
    }
    if (!in_array($combine_search_results, ['all', 'objects'])) {
        return;
    }
    $types = search_advanced_search_get_types();
    if (isset($types['object']) && in_array('groupforumtopic', $types['object'])) {
        $types['object'][] = 'discussion_reply';
    }
    if (isset($types['object']) && in_array('page', $types['object'])) {
        $types['object'][] = 'page_top';
    }
    $current_params = $params;
    $current_params['search_type'] = 'entities';
    if ($combine_search_results == 'objects') {
        $current_params['type'] = 'object';
        $current_params['subtype'] = elgg_extract('object', $types);
        // show a bit more content but disable pagination
        $current_params['offset'] = 0;
        $current_params['limit'] = 20;
        if (empty($current_params['subtype'])) {
            return;
        }
        $results = elgg_trigger_plugin_hook('search', 'object', $current_params, []);
        // reset count to 0 to remove the "view more" url
        $results['count'] = 0;
    } elseif ($combine_search_results == 'all') {
        unset($current_params['type']);
        unset($current_params['subtype']);
        $current_params['limit'] = (int) get_input('limit', 10);
        $current_params['offset'] = (int) get_input('offset', 0);
        $current_params['pagination'] = true;
        foreach ($types as $type => $subtypes) {
            if (empty($subtypes)) {
                $types[$type] = null;
            }
        }
        $current_params['type_subtype_pairs'] = $types;
        $results = elgg_trigger_plugin_hook('search', 'combined:all', $current_params, []);
    }
    $entities = elgg_extract('entities', $results);
    if (empty($entities)) {
        return;
    }
    elgg_push_context('combined_search');
    $view = search_get_search_view($current_params, 'list');
    if (empty($view)) {
        return;
    }
    $content = elgg_view($view, ['results' => $results, 'params' => $current_params]);
    elgg_pop_context();
    return ['content' => $content, 'count' => $results['count']];
}
예제 #7
0
function search_advanced_search_index_combined_search($combine_search_results = 'no', $params)
{
    if (elgg_extract('search_type', $params) !== 'all') {
        return;
    }
    if (empty($params['query'])) {
        return;
    }
    if (!in_array($combine_search_results, ['all', 'objects'])) {
        return;
    }
    $types = search_advanced_search_get_types();
    $current_params = $params;
    $current_params['search_type'] = 'entities';
    if ($combine_search_results == 'objects') {
        $current_params['type'] = 'object';
        $current_params['subtype'] = elgg_extract('object', $types);
        // show a bit more content but disable pagination
        $current_params['offset'] = 0;
        $current_params['limit'] = 20;
        if (empty($current_params['subtype'])) {
            return;
        }
        // let others change the search params
        $hook_params = ['combined' => $combine_search_results, 'search_params' => $current_params];
        $current_params = elgg_trigger_plugin_hook('search_params', 'search:combined', $hook_params, $current_params);
        // execute search
        $results = elgg_trigger_plugin_hook('search', 'object', $current_params, []);
        // reset count to 0 to remove the "view more" url
        $results['count'] = 0;
    } elseif ($combine_search_results == 'all') {
        unset($current_params['type']);
        unset($current_params['subtype']);
        $current_params['limit'] = (int) get_input('limit', elgg_get_config('default_limit'));
        $current_params['offset'] = (int) get_input('offset', 0);
        $current_params['pagination'] = true;
        foreach ($types as $type => $subtypes) {
            if (empty($subtypes)) {
                $types[$type] = ELGG_ENTITIES_ANY_VALUE;
            }
        }
        $current_params['type_subtype_pairs'] = $types;
        // let others change the search params
        $hook_params = ['combined' => $combine_search_results, 'search_params' => $current_params];
        $current_params = elgg_trigger_plugin_hook('search_params', 'search:combined', $hook_params, $current_params);
        // execute search
        $results = elgg_trigger_plugin_hook('search', 'combined:all', $current_params, []);
    }
    $entities = elgg_extract('entities', $results);
    if (empty($entities)) {
        return;
    }
    elgg_push_context('combined_search');
    $view = search_get_search_view($current_params, 'list');
    if (empty($view)) {
        return;
    }
    $content = elgg_view($view, ['results' => $results, 'params' => $current_params]);
    elgg_pop_context();
    return ['content' => $content, 'count' => $results['count']];
}