mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-13 20:28:44 +01:00
[feature/extension-manager] Make search backends loadable from extensions
Search backends are now required to be autoloadable. The database updater to 3.1 tries to guess the class name as phpbb_search_<oldname> which works for the default backends we ship. PHPBB3-10323
This commit is contained in:
parent
fb943d4d6b
commit
dcc5ca5377
@ -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 .= '<option value="' . $type . '"' . $selected . '>' . $name . '</option>';
|
||||
|
||||
@ -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'];
|
||||
|
@ -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;
|
||||
|
@ -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();
|
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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 . '
|
||||
|
@ -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');
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user