diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index a3061ae2da..a6377f6b49 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -77,7 +77,8 @@ class acp_search continue; } - $name = ucfirst(strtolower(str_replace('_', ' ', $type))); + $name = $search->get_name(); + $selected = ($config['search_type'] == $type) ? ' selected="selected"' : ''; $search_options .= ''; @@ -275,7 +276,7 @@ class acp_search { trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); } - $name = ucfirst(strtolower(str_replace('_', ' ', $this->state[0]))); + $name = $this->search->get_name(); $action = &$this->state[1]; @@ -454,7 +455,7 @@ class acp_search continue; } - $name = ucfirst(strtolower(str_replace('_', ' ', $type))); + $name = $search->get_name(); $data = array(); if (method_exists($search, 'index_stats')) @@ -553,8 +554,19 @@ class acp_search function get_search_types() { - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx, $phpbb_extension_manager; + $finder = $phpbb_extension_manager->get_finder(); + + return $finder + ->suffix('_backend') + ->directory('/search') + ->default_path('includes/search/') + ->default_suffix('') + ->default_directory('') + ->get_classes(); + +/* $search_types = array(); $dp = @opendir($phpbb_root_path . 'includes/search'); @@ -574,6 +586,7 @@ class acp_search } return $search_types; +*/ } function get_max_post_id() @@ -610,14 +623,6 @@ class acp_search { global $phpbb_root_path, $phpEx, $user; - if (!preg_match('#^\w+$#', $type) || !file_exists("{$phpbb_root_path}includes/search/$type.$phpEx")) - { - $error = $user->lang['NO_SUCH_SEARCH_MODULE']; - return $error; - } - - include_once("{$phpbb_root_path}includes/search/$type.$phpEx"); - if (!class_exists($type)) { $error = $user->lang['NO_SUCH_SEARCH_MODULE']; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4ca76344de..adc285cf6e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2350,16 +2350,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($update_search_index && $data['enable_indexing']) { // Select the search method and do some additional checks to ensure it can actually be utilised - $search_type = basename($config['search_type']); - - if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) - { - trigger_error('NO_SUCH_SEARCH_MODULE'); - } + $search_type = $config['search_type']; if (!class_exists($search_type)) { - include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); + trigger_error('NO_SUCH_SEARCH_MODULE'); } $error = false; diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/base.php similarity index 99% rename from phpBB/includes/search/search.php rename to phpBB/includes/search/base.php index 7c34ce9ff6..bb63957aba 100644 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/base.php @@ -24,12 +24,12 @@ define('SEARCH_RESULT_IN_CACHE', 1); define('SEARCH_RESULT_INCOMPLETE', 2); /** -* search_backend +* phpbb_search_base * optional base class for search plugins providing simple caching based on ACM * and functions to retrieve ignore_words and synonyms * @package search */ -class search_backend +class phpbb_search_base { var $ignore_words = array(); var $match_synonym = array(); diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 827205f20d..b9920da624 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -16,17 +16,12 @@ if (!defined('IN_PHPBB')) exit; } -/** -* @ignore -*/ -include_once($phpbb_root_path . 'includes/search/search.' . $phpEx); - /** * fulltext_mysql * Fulltext search for MySQL * @package search */ -class fulltext_mysql extends search_backend +class phpbb_search_fulltext_mysql extends phpbb_search_base { var $stats = array(); var $word_length = array(); @@ -36,7 +31,7 @@ class fulltext_mysql extends search_backend var $pcre_properties = false; var $mbstring_regex = false; - function fulltext_mysql(&$error) + public function __construct(&$error) { global $config; @@ -57,6 +52,11 @@ class fulltext_mysql extends search_backend $error = false; } + function get_name() + { + return 'MySQL Fulltext'; + } + /** * Checks for correct MySQL version and stores min/max word length in the config */ diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index e749e86f68..7c792bba24 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -16,17 +16,12 @@ if (!defined('IN_PHPBB')) exit; } -/** -* @ignore -*/ -include_once($phpbb_root_path . 'includes/search/search.' . $phpEx); - /** * fulltext_native * phpBB's own db driven fulltext search, version 2 * @package search */ -class fulltext_native extends search_backend +class phpbb_search_fulltext_native extends phpbb_search_base { var $stats = array(); var $word_length = array(); @@ -41,10 +36,8 @@ class fulltext_native extends search_backend * Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded. * * @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure. - * - * @access public */ - function fulltext_native(&$error) + public function __construct(&$error) { global $phpbb_root_path, $phpEx, $config; @@ -58,10 +51,14 @@ class fulltext_native extends search_backend include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); } - $error = false; } + function get_name() + { + return 'phpBB Native Fulltext'; + } + /** * This function fills $this->search_query with the cleaned user search query. * diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index b2419df3c9..1f3c01ee3e 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2106,6 +2106,10 @@ function change_database_data(&$no_updates, $version) // Changes from 3.1.0-dev to 3.1.0-A1 case '3.1.0-dev': + // try to guess the new auto loaded search class name + // works for native and mysql fulltext + set_config('search_type', 'phpbb_search_' . $config['search_type']); + set_config('use_system_cron', 0); $sql = 'UPDATE ' . GROUPS_TABLE . ' diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 5506922e17..bd7334f9d4 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -223,7 +223,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_block_size' INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_interval', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_anonymous_interval', '0'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', 'fulltext_native'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', 'phpbb_search_fulltext_native'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_store_results', '1800'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_deny', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_empty_referer', '1'); diff --git a/phpBB/search.php b/phpBB/search.php index 1d35dfb062..c6189051a3 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -73,7 +73,7 @@ switch ($search_id) login_box('', $user->lang['LOGIN_EXPLAIN_UNREADSEARCH']); } break; - + // The "new posts" search uses user_lastvisit which is user based, so it should require user to log in. case 'newposts': if ($user->data['user_id'] == ANONYMOUS) @@ -81,7 +81,7 @@ switch ($search_id) login_box('', $user->lang['LOGIN_EXPLAIN_NEWPOSTS']); } break; - + default: // There's nothing to do here for now ;) break; @@ -273,15 +273,12 @@ if ($keywords || $author || $author_id || $search_id || $submit) } // Select which method we'll use to obtain the post_id or topic_id information - $search_type = basename($config['search_type']); + $search_type = $config['search_type']; - if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) + if (!class_exists($search_type)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } - - require("{$phpbb_root_path}includes/search/$search_type.$phpEx"); - // We do some additional checks in the module to ensure it can actually be utilised $error = false; $search = new $search_type($error);