From b5e2dbf292cddd56a8171b4c9cf1d9cf0fb45582 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 19 Mar 2011 15:19:02 +0000 Subject: Fixes #3158 updated search and pages plugins for page handler scripts git-svn-id: http://code.elgg.org/elgg/trunk@8769 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/search/index.php | 273 -------------------------------------- mod/search/pages/search/index.php | 273 ++++++++++++++++++++++++++++++++++++++ mod/search/start.php | 4 +- 3 files changed, 276 insertions(+), 274 deletions(-) delete mode 100644 mod/search/index.php create mode 100644 mod/search/pages/search/index.php (limited to 'mod/search') diff --git a/mod/search/index.php b/mod/search/index.php deleted file mode 100644 index 4da6f95ef..000000000 --- a/mod/search/index.php +++ /dev/null @@ -1,273 +0,0 @@ - $query, - 'offset' => $offset, - 'limit' => $limit, - 'sort' => $sort, - 'order' => $order, - 'search_type' => $search_type, - 'type' => $entity_type, - 'subtype' => $entity_subtype, -// 'tag_type' => $tag_type, - 'owner_guid' => $owner_guid, - 'container_guid' => $container_guid, -// 'friends' => $friends - 'pagination' => ($search_type == 'all') ? FALSE : TRUE -); - -$types = get_registered_entity_types(); -$custom_types = elgg_trigger_plugin_hook('search_types', 'get_types', $params, array()); - -// 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', - //'friends' => $friends -))); -$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); - } -} - -// add sidebar for custom searches -foreach ($custom_types as $type) { - $label = "search_types:$type"; - - $data = htmlspecialchars(http_build_query(array( - 'q' => $query, - 'entity_subtype' => $entity_subtype, - 'entity_type' => $entity_type, - 'owner_guid' => $owner_guid, - 'search_type' => $type, - '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); -} - - -// check that we have an actual query -if (!$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; -} - -// 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, - )); - } - } - } -} - -// call custom searches -if ($search_type != 'entities' || $search_type == 'all') { - if (is_array($custom_types)) { - foreach ($custom_types as $type) { - if ($search_type != 'all' && $search_type != $type) { - continue; - } - - $current_params = $params; - $current_params['search_type'] = $type; - // custom search types have no subtype. - unset($current_params['subtype']); - - $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 -$searched_words = search_remove_ignored_words($query, 'array'); -$highlighted_query = search_highlight_words($searched_words, $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("\"{$params['query']}\"")); - -echo elgg_view_page($title, $layout); diff --git a/mod/search/pages/search/index.php b/mod/search/pages/search/index.php new file mode 100644 index 000000000..4da6f95ef --- /dev/null +++ b/mod/search/pages/search/index.php @@ -0,0 +1,273 @@ + $query, + 'offset' => $offset, + 'limit' => $limit, + 'sort' => $sort, + 'order' => $order, + 'search_type' => $search_type, + 'type' => $entity_type, + 'subtype' => $entity_subtype, +// 'tag_type' => $tag_type, + 'owner_guid' => $owner_guid, + 'container_guid' => $container_guid, +// 'friends' => $friends + 'pagination' => ($search_type == 'all') ? FALSE : TRUE +); + +$types = get_registered_entity_types(); +$custom_types = elgg_trigger_plugin_hook('search_types', 'get_types', $params, array()); + +// 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', + //'friends' => $friends +))); +$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); + } +} + +// add sidebar for custom searches +foreach ($custom_types as $type) { + $label = "search_types:$type"; + + $data = htmlspecialchars(http_build_query(array( + 'q' => $query, + 'entity_subtype' => $entity_subtype, + 'entity_type' => $entity_type, + 'owner_guid' => $owner_guid, + 'search_type' => $type, + '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); +} + + +// check that we have an actual query +if (!$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; +} + +// 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, + )); + } + } + } +} + +// call custom searches +if ($search_type != 'entities' || $search_type == 'all') { + if (is_array($custom_types)) { + foreach ($custom_types as $type) { + if ($search_type != 'all' && $search_type != $type) { + continue; + } + + $current_params = $params; + $current_params['search_type'] = $type; + // custom search types have no subtype. + unset($current_params['subtype']); + + $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 +$searched_words = search_remove_ignored_words($query, 'array'); +$highlighted_query = search_highlight_words($searched_words, $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("\"{$params['query']}\"")); + +echo elgg_view_page($title, $layout); diff --git a/mod/search/start.php b/mod/search/start.php index ab7aa1c4c..18a0d59e3 100644 --- a/mod/search/start.php +++ b/mod/search/start.php @@ -68,7 +68,9 @@ function search_page_handler($page) { //set_input('search_type', 'tags'); } - include_once('index.php'); + $base_dir = elgg_get_plugins_path() . 'search/pages/search'; + + include_once("$base_dir/index.php"); } /** -- cgit v1.2.3