diff options
| author | David M <davidmj@users.sourceforge.net> | 2008-01-03 17:00:40 +0000 |
|---|---|---|
| committer | David M <davidmj@users.sourceforge.net> | 2008-01-03 17:00:40 +0000 |
| commit | 85055ac97fa57ca339924cef719115d85bdf6c2e (patch) | |
| tree | 1e19230af2689c3837356c0f7947719c0cdf67ef /phpBB/includes/search | |
| parent | 0f26ffbadea13d97b841dfe56b21da7a5479000a (diff) | |
| download | forums-85055ac97fa57ca339924cef719115d85bdf6c2e.tar forums-85055ac97fa57ca339924cef719115d85bdf6c2e.tar.gz forums-85055ac97fa57ca339924cef719115d85bdf6c2e.tar.bz2 forums-85055ac97fa57ca339924cef719115d85bdf6c2e.tar.xz forums-85055ac97fa57ca339924cef719115d85bdf6c2e.zip | |
oh boy...
- Migrate code base to PHP 5.1+
git-svn-id: file:///svn/phpbb/trunk@8295 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/search')
| -rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 149 | ||||
| -rwxr-xr-x | phpBB/includes/search/fulltext_native.php | 54 | ||||
| -rwxr-xr-x | phpBB/includes/search/search.php | 37 |
3 files changed, 72 insertions, 168 deletions
diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 1cd28fc6d2..b359b3ba1c 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -28,42 +28,25 @@ include_once($phpbb_root_path . 'includes/search/search.' . $phpEx); */ class fulltext_mysql extends search_backend { - var $stats = array(); - var $word_length = array(); - var $split_words = array(); - var $search_query; - var $common_words = array(); - var $pcre_properties = false; - var $mbstring_regex = false; - - function fulltext_mysql(&$error) + private $stats = array(); + public $word_length = array(); + private $split_words = array(); + public $search_query; + public $common_words = array(); + + function __construct(&$error) { global $config; $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']); - if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) - { - // While this is the proper range of PHP versions, PHP may not be linked with the bundled PCRE lib and instead with an older version - if (@preg_match('/\p{L}/u', 'a') !== false) - { - $this->pcre_properties = true; - } - } - - if (function_exists('mb_ereg')) - { - $this->mbstring_regex = true; - mb_regex_encoding('UTF-8'); - } - $error = false; } /** * Checks for correct MySQL version and stores min/max word length in the config */ - function init() + public function init() { global $db, $user; @@ -116,7 +99,7 @@ class fulltext_mysql extends search_backend * @param string $terms is either 'all' or 'any' * @return bool false if no valid keywords were found and otherwise true */ - function split_keywords(&$keywords, $terms) + public function split_keywords(&$keywords, $terms) { global $config; @@ -132,40 +115,11 @@ class fulltext_mysql extends search_backend $split_keywords = preg_replace("#[\n\r\t]+#", ' ', trim(htmlspecialchars_decode($keywords))); // Split words - if ($this->pcre_properties) - { - $split_keywords = preg_replace('#([^\p{L}\p{N}\'*"()])#u', '$1$1', str_replace('\'\'', '\' \'', trim($split_keywords))); - } - else if ($this->mbstring_regex) - { - $split_keywords = mb_ereg_replace('([^\w\'*"()])', '\\1\\1', str_replace('\'\'', '\' \'', trim($split_keywords))); - } - else - { - $split_keywords = preg_replace('#([^\w\'*"()])#u', '$1$1', str_replace('\'\'', '\' \'', trim($split_keywords))); - } + $split_keywords = preg_replace('#([^\p{L}\p{N}\'*"()])#u', '$1$1', str_replace('\'\'', '\' \'', trim($split_keywords))); - if ($this->pcre_properties) - { - $matches = array(); - preg_match_all('#(?:[^\p{L}\p{N}*"()]|^)([+\-|]?(?:[\p{L}\p{N}*"()]+\'?)*[\p{L}\p{N}*"()])(?:[^\p{L}\p{N}*"()]|$)#u', $split_keywords, $matches); - $this->split_words = $matches[1]; - } - else if ($this->mbstring_regex) - { - mb_ereg_search_init($split_keywords, '(?:[^\w*"()]|^)([+\-|]?(?:[\w*"()]+\'?)*[\w*"()])(?:[^\w*"()]|$)'); - - while (($word = mb_ereg_search_regs())) - { - $this->split_words[] = $word[1]; - } - } - else - { - $matches = array(); - preg_match_all('#(?:[^\w*"()]|^)([+\-|]?(?:[\w*"()]+\'?)*[\w*"()])(?:[^\w*"()]|$)#u', $split_keywords, $matches); - $this->split_words = $matches[1]; - } + $matches = array(); + preg_match_all('#(?:[^\p{L}\p{N}*"()]|^)([+\-|]?(?:[\p{L}\p{N}*"()]+\'?)*[\p{L}\p{N}*"()])(?:[^\p{L}\p{N}*"()]|$)#u', $split_keywords, $matches); + $this->split_words = $matches[1]; // to allow phrase search, we need to concatenate quoted words $tmp_split_words = array(); @@ -259,46 +213,16 @@ class fulltext_mysql extends search_backend /** * Turns text into an array of words */ - function split_message($text) + private function split_message($text) { global $config; // Split words - if ($this->pcre_properties) - { - $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); - } - else if ($this->mbstring_regex) - { - $text = mb_ereg_replace('([^\w\'*])', '\\1\\1', str_replace('\'\'', '\' \'', trim($text))); - } - else - { - $text = preg_replace('#([^\w\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); - } + $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); - if ($this->pcre_properties) - { - $matches = array(); - preg_match_all('#(?:[^\p{L}\p{N}*]|^)([+\-|]?(?:[\p{L}\p{N}*]+\'?)*[\p{L}\p{N}*])(?:[^\p{L}\p{N}*]|$)#u', $text, $matches); - $text = $matches[1]; - } - else if ($this->mbstring_regex) - { - mb_ereg_search_init($text, '(?:[^\w*]|^)([+\-|]?(?:[\w*]+\'?)*[\w*])(?:[^\w*]|$)'); - - $text = array(); - while (($word = mb_ereg_search_regs())) - { - $text[] = $word[1]; - } - } - else - { - $matches = array(); - preg_match_all('#(?:[^\w*]|^)([+\-|]?(?:[\w*]+\'?)*[\w*])(?:[^\w*]|$)#u', $text, $matches); - $text = $matches[1]; - } + $matches = array(); + preg_match_all('#(?:[^\p{L}\p{N}*]|^)([+\-|]?(?:[\p{L}\p{N}*]+\'?)*[\p{L}\p{N}*])(?:[^\p{L}\p{N}*]|$)#u', $text, $matches); + $text = $matches[1]; // remove too short or too long words $text = array_values($text); @@ -335,7 +259,7 @@ class fulltext_mysql extends search_backend * * @access public */ - function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + public function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -361,7 +285,7 @@ class fulltext_mysql extends search_backend // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE) { return $result_count; } @@ -494,7 +418,7 @@ class fulltext_mysql extends search_backend * @param int $per_page number of ids each page is supposed to contain * @return total number of results */ - function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -521,7 +445,7 @@ class fulltext_mysql extends search_backend // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE) { return $result_count; } @@ -642,7 +566,7 @@ class fulltext_mysql extends search_backend * * @param string $mode contains the post mode: edit, post, reply, quote ... */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { global $db; @@ -664,7 +588,7 @@ class fulltext_mysql extends search_backend /** * Destroy cached results, that might be outdated after deleting a post */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { $this->destroy_cache(array(), $author_ids); } @@ -672,7 +596,7 @@ class fulltext_mysql extends search_backend /** * Destroy old cache entries */ - function tidy() + public function tidy() { global $db, $config; @@ -685,7 +609,7 @@ class fulltext_mysql extends search_backend /** * Create fulltext index */ - function create_index($acp_module, $u_action) + public function create_index($acp_module, $u_action) { global $db; @@ -746,7 +670,7 @@ class fulltext_mysql extends search_backend /** * Drop fulltext index */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { global $db; @@ -791,7 +715,7 @@ class fulltext_mysql extends search_backend /** * Returns true if both FULLTEXT indexes exist */ - function index_created() + public function index_created() { if (empty($this->stats)) { @@ -804,7 +728,7 @@ class fulltext_mysql extends search_backend /** * Returns an associative array containing information about the indexes */ - function index_stats() + public function index_stats() { global $user; @@ -818,7 +742,7 @@ class fulltext_mysql extends search_backend ); } - function get_stats() + private function get_stats() { global $db; @@ -863,22 +787,13 @@ class fulltext_mysql extends search_backend } /** - * Display a note, that UTF-8 support is not available with certain versions of PHP + * Display nothing, we force UTF-8 support in all versions of PHP */ function acp() { global $user, $config; - $tpl = ' - <dl> - <dt><label>' . $user->lang['FULLTEXT_MYSQL_PCRE'] . '</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_PCRE_EXPLAIN'] . '</span></dt> - <dd>' . (($this->pcre_properties) ? $user->lang['YES'] : $user->lang['NO']) . ' (PHP ' . PHP_VERSION . ')</dd> - </dl> - <dl> - <dt><label>' . $user->lang['FULLTEXT_MYSQL_MBSTRING'] . '</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_MBSTRING_EXPLAIN'] . '</span></dt> - <dd>' . (($this->mbstring_regex) ? $user->lang['YES'] : $user->lang['NO']). '</dd> - </dl> - '; + $tpl = ''; // These are fields required in the config table return array( diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index bfcb02f8e6..89689151fe 100755 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -28,14 +28,14 @@ include_once($phpbb_root_path . 'includes/search/search.' . $phpEx); */ class fulltext_native extends search_backend { - var $stats = array(); - var $word_length = array(); - var $search_query; - var $common_words = array(); + private $stats = array(); + public $word_length = array(); + public $search_query; + public $common_words = array(); - var $must_contain_ids = array(); - var $must_not_contain_ids = array(); - var $must_exclude_one_ids = array(); + private $must_contain_ids = array(); + private $must_not_contain_ids = array(); + private $must_exclude_one_ids = array(); /** * Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded. @@ -44,7 +44,7 @@ class fulltext_native extends search_backend * * @access public */ - function fulltext_native(&$error) + function __construct(&$error) { global $phpbb_root_path, $phpEx, $config; @@ -79,7 +79,7 @@ class fulltext_native extends search_backend * * @access public */ - function split_keywords($keywords, $terms) + public function split_keywords($keywords, $terms) { global $db, $user; @@ -402,7 +402,7 @@ class fulltext_native extends search_backend * * @access public */ - function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + public function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -430,7 +430,7 @@ class fulltext_native extends search_backend // try reading the results from cache $total_results = 0; - if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE) { return $total_results; } @@ -761,7 +761,7 @@ class fulltext_native extends search_backend * * @access public */ - function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -788,7 +788,7 @@ class fulltext_native extends search_backend // try reading the results from cache $total_results = 0; - if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE) { return $total_results; } @@ -973,7 +973,7 @@ class fulltext_native extends search_backend * * @access private */ - function split_message($text) + private function split_message($text) { global $phpbb_root_path, $phpEx, $user; @@ -1052,7 +1052,7 @@ class fulltext_native extends search_backend * * @access public */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { global $config, $db, $user; @@ -1211,7 +1211,7 @@ class fulltext_native extends search_backend /** * Removes entries from the wordmatch table for the specified post_ids */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { global $db; @@ -1271,7 +1271,7 @@ class fulltext_native extends search_backend * Tidy up indexes: Tag 'common words' and remove * words no longer referenced in the match table */ - function tidy() + public function tidy() { global $db, $config; @@ -1336,7 +1336,7 @@ class fulltext_native extends search_backend /** * Deletes all words from the index */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { global $db; @@ -1360,7 +1360,7 @@ class fulltext_native extends search_backend /** * Returns true if both FULLTEXT indexes exist */ - function index_created() + public function index_created() { if (!sizeof($this->stats)) { @@ -1373,7 +1373,7 @@ class fulltext_native extends search_backend /** * Returns an associative array containing information about the indexes */ - function index_stats() + public function index_stats() { global $user; @@ -1387,7 +1387,7 @@ class fulltext_native extends search_backend $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } - function get_stats() + private function get_stats() { global $db; @@ -1414,24 +1414,16 @@ class fulltext_native extends search_backend * * @param string $text Text to split, in UTF-8 (not normalized or sanitized) * @param string $allowed_chars String of special chars to allow - * @param string $encoding Text encoding * @return string Cleaned up text, only alphanumeric chars are left * * @todo normalizer::cleanup being able to be used? */ - function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') + private function cleanup($text, $allowed_chars = null) { global $phpbb_root_path, $phpEx; static $conv = array(), $conv_loaded = array(); $words = $allow = array(); - // Convert the text to UTF-8 - $encoding = strtolower($encoding); - if ($encoding != 'utf-8') - { - $text = utf8_recode($text, $encoding); - } - $utf_len_mask = array( "\xC0" => 2, "\xD0" => 2, @@ -1649,7 +1641,7 @@ class fulltext_native extends search_backend /** * Returns a list of options for the ACP to display */ - function acp() + public function acp() { global $user, $config; diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php index 32d7ed595f..e13a59caed 100755 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/search.php @@ -17,13 +17,6 @@ if (!defined('IN_PHPBB')) } /** -* @ignore -*/ -define('SEARCH_RESULT_NOT_IN_CACHE', 0); -define('SEARCH_RESULT_IN_CACHE', 1); -define('SEARCH_RESULT_INCOMPLETE', 2); - -/** * search_backend * optional base class for search plugins providing simple caching based on ACM * and functions to retrieve ignore_words and synonyms @@ -31,11 +24,15 @@ define('SEARCH_RESULT_INCOMPLETE', 2); */ class search_backend { - var $ignore_words = array(); - var $match_synonym = array(); - var $replace_synonym = array(); + const SEARCH_RESULT_NOT_IN_CACHE = 0; + const SEARCH_RESULT_IN_CACHE = 1; + const SEARCH_RESULT_INCOMPLETE = 2; + + public $ignore_words = array(); + public $match_synonym = array(); + public $replace_synonym = array(); - function search_backend(&$error) + function __construct(&$error) { // This class cannot be used as a search plugin $error = true; @@ -44,7 +41,7 @@ class search_backend /** * Retrieves a language dependend list of words that should be ignored by the search */ - function get_ignore_words() + public function get_ignore_words() { if (!sizeof($this->ignore_words)) { @@ -66,7 +63,7 @@ class search_backend /** * Stores a list of synonyms that should be replaced in $this->match_synonym and $this->replace_synonym and caches them */ - function get_synonyms() + public function get_synonyms() { if (!sizeof($this->match_synonym)) { @@ -95,14 +92,14 @@ class search_backend * * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE */ - function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) + protected function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { global $cache; if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key - return SEARCH_RESULT_NOT_IN_CACHE; + return self::SEARCH_RESULT_NOT_IN_CACHE; } else { @@ -119,7 +116,7 @@ class search_backend // the user requested a page past the last index if ($start < 0) { - return SEARCH_RESULT_NOT_IN_CACHE; + return self::SEARCH_RESULT_NOT_IN_CACHE; } } @@ -143,9 +140,9 @@ class search_backend if (!$complete) { - return SEARCH_RESULT_INCOMPLETE; + return self::SEARCH_RESULT_INCOMPLETE; } - return SEARCH_RESULT_IN_CACHE; + return self::SEARCH_RESULT_IN_CACHE; } } @@ -155,7 +152,7 @@ class search_backend * @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element * must have the absolute index $start in the result set. */ - function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir) + protected function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir) { global $cache, $config, $db, $user; @@ -264,7 +261,7 @@ class search_backend /** * Removes old entries from the search results table and removes searches with keywords that contain a word in $words. */ - function destroy_cache($words, $authors = false) + public function destroy_cache($words, $authors = false) { global $db, $cache, $config; |
