From db1c80dee9c923326683252d70b6712c8432673a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 17:38:28 +0530 Subject: [PATCH 1/9] [ticket/11011] add access specifiers and docblocks Add access specifiers and docblocks to mysql search backend. PHPBB3-11011 --- phpBB/includes/search/fulltext_mysql.php | 61 +++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 20dcb74c0d..64b3feb30c 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -22,12 +22,18 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_mysql extends phpbb_search_base { - var $stats = array(); - var $word_length = array(); - var $split_words = array(); - var $search_query; - var $common_words = array(); + private $stats = array(); + private $split_words = array(); + public $word_length = array(); + public $search_query; + public $common_words = array(); + /** + * Constructor + * Creates a new phpbb_search_fulltext_mysql, which is used as a search backend. + * + * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false + */ public function __construct(&$error) { global $config; @@ -41,6 +47,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Returns the name of this search backend to be displayed to administrators * * @return string Name + * + * @access public */ public function get_name() { @@ -49,6 +57,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Checks for correct MySQL version and stores min/max word length in the config + * + * @return string|bool Language key of the error/incompatiblity occured + * + * @access public */ function init() { @@ -102,6 +114,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string &$keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return bool false if no valid keywords were found and otherwise true + * + * @access public */ function split_keywords(&$keywords, $terms) { @@ -221,6 +235,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Turns text into an array of words + * @param string $text contains post text/subject + * + * @access public */ function split_message($text) { @@ -607,7 +624,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroys cached search results, that contained one of the new words in a post so the results won't be outdated. * - * @param string $mode contains the post mode: edit, post, reply, quote ... + * @param string $mode contains the post mode: edit, post, reply, quote ... + * @param int $post_id contains the post id of the post to index + * @param string $message contains the post text of the post + * @param string $subject contains the subject of the post to index + * @param int $poster_id contains the user id of the poster + * @param int $forum_id contains the forum id of parent forum of the post + * + * @access public */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { @@ -630,6 +654,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroy cached results, that might be outdated after deleting a post + * + * @access public */ function index_remove($post_ids, $author_ids, $forum_ids) { @@ -638,6 +664,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroy old cache entries + * + * @access public */ function tidy() { @@ -651,6 +679,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Create fulltext index + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function create_index($acp_module, $u_action) { @@ -712,6 +744,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Drop fulltext index + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function delete_index($acp_module, $u_action) { @@ -757,6 +793,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns true if both FULLTEXT indexes exist + * + * @access public */ function index_created() { @@ -770,6 +808,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns an associative array containing information about the indexes + * + * @access public */ function index_stats() { @@ -785,6 +825,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base ); } + /** + * Computes the stats and store them in the $this->stats associative array + * + * @access private + */ function get_stats() { global $db; @@ -827,6 +872,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Display a note, that UTF-8 support is not available with certain versions of PHP + * + * @return associative array containing template and config variables + * + * @access public */ function acp() { From 9c7a1a147236ec21f99f6894cb0ef5324869de3d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 18:32:52 +0530 Subject: [PATCH 2/9] [ticket/11011] global variables as constructor parameters Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_mysql.php | 135 ++++++++++------------- 1 file changed, 58 insertions(+), 77 deletions(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 64b3feb30c..ccf9f49612 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -24,6 +24,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { private $stats = array(); private $split_words = array(); + private $config; + private $db; + private $user; public $word_length = array(); public $search_query; public $common_words = array(); @@ -34,11 +37,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $config; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']); + $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); $error = false; } @@ -64,16 +69,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function init() { - global $db, $user; - - if ($db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli') + if ($this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli') { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; + return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; } - $result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); - $info = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); + $info = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); $engine = ''; if (isset($info['Engine'])) @@ -87,19 +90,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($engine != 'MyISAM') { - return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; + return $this->user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; } $sql = 'SHOW VARIABLES LIKE \'ft\_%\''; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $mysql_info = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $mysql_info[$row['Variable_name']] = $row['Value']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); set_config('fulltext_mysql_max_word_len', $mysql_info['ft_max_word_len']); set_config('fulltext_mysql_min_word_len', $mysql_info['ft_min_word_len']); @@ -119,8 +122,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function split_keywords(&$keywords, $terms) { - global $config, $user; - if ($terms == 'all') { $match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#(^|\s)\+#', '#(^|\s)-#', '#(^|\s)\|#'); @@ -139,9 +140,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->split_words = $matches[1]; // We limit the number of allowed keywords to minimize load on the database - if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords']) + if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords']) { - trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words))); + trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], sizeof($this->split_words))); } // to allow phrase search, we need to concatenate quoted words @@ -183,7 +184,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // check word length $clean_len = utf8_strlen(str_replace('*', '', $clean_word)); - if (($clean_len < $config['fulltext_mysql_min_word_len']) || ($clean_len > $config['fulltext_mysql_max_word_len'])) + if (($clean_len < $this->config['fulltext_mysql_min_word_len']) || ($clean_len > $this->config['fulltext_mysql_max_word_len'])) { $this->common_words[] = $word; unset($this->split_words[$i]); @@ -241,8 +242,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function split_message($text) { - global $config; - // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); $matches = array(); @@ -254,7 +253,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base for ($i = 0, $n = sizeof($text); $i < $n; $i++) { $text[$i] = trim($text[$i]); - if (utf8_strlen($text[$i]) < $config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_mysql_max_word_len']) + if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len']) { unset($text[$i]); } @@ -287,8 +286,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (!$this->search_query) { @@ -377,7 +374,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; @@ -387,11 +384,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($author_ary) && $author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else if (sizeof($author_ary)) { - $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary); } else { @@ -401,7 +398,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql_where_options = $sql_sort_join; $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; - $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; @@ -409,16 +406,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql = "SELECT $sql_select FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE MATCH ($sql_match) AGAINST ('" . $db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) + WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) $sql_where_options ORDER BY $sql_sort"; - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $id_ary = array_unique($id_ary); @@ -431,9 +428,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!$result_count) { $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $db->sql_query($sql); - $result_count = (int) $db->sql_fetchfield('result_count'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -471,8 +468,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -508,13 +503,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -550,7 +545,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } // If the cache was completely empty count the results @@ -589,21 +584,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // retrieve the total result count if needed if (!$result_count) { $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $db->sql_query($sql); - $result_count = (int) $db->sql_fetchfield('result_count'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -635,8 +630,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $db; - // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); $split_title = ($subject) ? $this->split_message($subject) : array(); @@ -669,8 +662,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function tidy() { - global $db, $config; - // destroy too old cached search results $this->destroy_cache(array()); @@ -686,8 +677,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function create_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { @@ -703,7 +692,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!isset($this->stats['post_subject'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) + if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $alter[] = 'MODIFY post_subject varchar(255) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL'; } @@ -716,7 +705,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!isset($this->stats['post_text'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) + if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL'; } @@ -734,10 +723,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($alter)) { - $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); + $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -751,8 +740,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { @@ -783,10 +770,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($alter)) { - $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); + $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -813,15 +800,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function index_stats() { - global $user; - if (empty($this->stats)) { $this->get_stats(); } return array( - $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -832,9 +817,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function get_stats() { - global $db; - - if (strpos($db->sql_layer, 'mysql') === false) + if (strpos($this->db->sql_layer, 'mysql') === false) { $this->stats = array(); return; @@ -842,9 +825,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql = 'SHOW INDEX FROM ' . POSTS_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // deal with older MySQL versions which didn't use Index_type $index_type = (isset($row['Index_type'])) ? $row['Index_type'] : $row['Comment']; @@ -865,9 +848,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $this->stats['total_posts'] = empty($this->stats) ? 0 : $db->get_estimated_row_count(POSTS_TABLE); + $this->stats['total_posts'] = empty($this->stats) ? 0 : $this->db->get_estimated_row_count(POSTS_TABLE); } /** @@ -879,16 +862,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function acp() { - global $user, $config; - $tpl = '
-

' . $user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '
-
' . $config['fulltext_mysql_min_word_len'] . '
+

' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '
+
' . $this->config['fulltext_mysql_min_word_len'] . '
-

' . $user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '
-
' . $config['fulltext_mysql_max_word_len'] . '
+

' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '
+
' . $this->config['fulltext_mysql_max_word_len'] . '
'; From a1da7ff86182f44ad4c01698e2c526216b86031e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 16:50:09 +0530 Subject: [PATCH 3/9] [ticket/11011] remove global keyword in pgsql search Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_postgres.php | 134 +++++++++----------- 1 file changed, 57 insertions(+), 77 deletions(-) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 84ce674564..75cb48ecc6 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -28,6 +28,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base private $version; private $tsearch_query; private $phrase_search = false; + private $config; + private $db; + private $user; public $search_query; public $common_words = array(); public $word_length = array(); @@ -38,16 +41,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $db, $config; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_postgres_min_word_len'], 'max' => $config['fulltext_postgres_max_word_len']); + $this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']); - - if ($db->sql_layer == 'postgres') + if ($this->db->sql_layer == 'postgres') { - $pgsql_version = explode(',', substr($db->sql_server_info(), 10)); + $pgsql_version = explode(',', substr($this->db->sql_server_info(), 10)); $this->version = trim($pgsql_version[0]); if (version_compare($this->version, '8.3', '>=')) { @@ -91,16 +95,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function init() { - global $db, $user; - - if ($db->sql_layer != 'postgres') + if ($this->db->sql_layer != 'postgres') { - return $user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; + return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; } if (!$this->tsearch_usable) { - return $user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE']; + return $this->user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE']; } return false; @@ -118,8 +120,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function split_keywords(&$keywords, $terms) { - global $config; - if ($terms == 'all') { $match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#\+#', '#-#', '#\|#'); @@ -143,7 +143,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // check word length $clean_len = utf8_strlen(str_replace('*', '', $clean_word)); - if (($clean_len < $config['fulltext_postgres_min_word_len']) || ($clean_len > $config['fulltext_postgres_max_word_len'])) + if (($clean_len < $this->config['fulltext_postgres_min_word_len']) || ($clean_len > $this->config['fulltext_postgres_max_word_len'])) { $this->common_words[] = $word; unset($this->split_words[$i]); @@ -213,8 +213,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function split_message($text) { - global $config; - // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); $matches = array(); @@ -226,7 +224,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base for ($i = 0, $n = sizeof($text); $i < $n; $i++) { $text[$i] = trim($text[$i]); - if (utf8_strlen($text[$i]) < $config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_postgres_max_word_len']) + if (utf8_strlen($text[$i]) < $this->config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_postgres_max_word_len']) { unset($text[$i]); } @@ -259,8 +257,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (!$this->search_query) { @@ -349,7 +345,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id'; @@ -360,11 +356,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (sizeof($author_ary) && $author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else if (sizeof($author_ary)) { - $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary); } else { @@ -374,7 +370,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sql_where_options = $sql_sort_join; $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; - $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; @@ -383,7 +379,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $tmp_sql_match = array(); foreach (explode(',', $sql_match) as $sql_match_column) { - $tmp_sql_match[] = "to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', '" . $db->sql_escape($this->tsearch_query) . "')"; + $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')"; } $sql = "SELECT $sql_select @@ -391,13 +387,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base WHERE (" . implode(' OR ', $tmp_sql_match) . ") $sql_where_options ORDER BY $sql_sort"; - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $id_ary = array_unique($id_ary); @@ -447,8 +443,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -484,13 +478,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -526,7 +520,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } // Build the query for really selecting the post_ids @@ -562,13 +556,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // retrieve the total result count if needed if (!$result_count) @@ -605,8 +599,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $db; - // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); $split_title = ($subject) ? $this->split_message($subject) : array(); @@ -639,8 +631,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function tidy() { - global $db, $config; - // destroy too old cached search results $this->destroy_cache(array()); @@ -656,8 +646,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function create_index($acp_module, $u_action) { - global $db, $config; - // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { @@ -671,15 +659,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (!isset($this->stats['post_subject'])) { - $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_subject))"); + $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))"); } if (!isset($this->stats['post_text'])) { - $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_text))"); + $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text))"); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -693,8 +681,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { @@ -708,15 +694,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (isset($this->stats['post_subject'])) { - $db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']); + $this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']); } if (isset($this->stats['post_text'])) { - $db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']); + $this->db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -743,15 +729,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function index_stats() { - global $user; - if (empty($this->stats)) { $this->get_stats(); } return array( - $user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -762,9 +746,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function get_stats() { - global $db, $config; - - if ($db->sql_layer != 'postgres') + if ($this->db->sql_layer != 'postgres') { $this->stats = array(); return; @@ -776,26 +758,26 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base AND pg_catalog.pg_table_is_visible(c1.oid) AND c1.oid = i.indrelid AND i.indexrelid = c2.oid"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // deal with older PostgreSQL versions which didn't use Index_type if (strpos($row['indexdef'], 'to_tsvector') !== false) { - if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text') + if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text') { $this->stats['post_text'] = $row; } - else if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject') + else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject') { $this->stats['post_subject'] = $row; } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $this->stats['total_posts'] = $config['num_posts']; + $this->stats['total_posts'] = $this->config['num_posts']; } /** @@ -807,43 +789,41 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function acp() { - global $user, $config, $db; - $tpl = '
-

' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '
-
' . (($this->tsearch_usable) ? $user->lang['YES'] : $user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')
+

' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '
+
' . (($this->tsearch_usable) ? $this->user->lang['YES'] : $this->user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')
-

' . $user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '
+

' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '
-

' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '
+
-

' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '
+
'; From 33c6d7c8be41ddd15b4e03e5dfecfd259c77b327 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 23 Jul 2012 15:41:15 +0530 Subject: [PATCH 4/9] [ticket/11011] remove global keyword in native search Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_native.php | 274 +++++++++++----------- 1 file changed, 132 insertions(+), 142 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 1e2074b1b1..b9818d7919 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -31,23 +31,33 @@ class phpbb_search_fulltext_native extends phpbb_search_base var $must_not_contain_ids = array(); var $must_exclude_one_ids = array(); + private $phpbb_root_path; + private $phpEx; + private $config; + private $db; + private $user; + /** * 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. */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $phpbb_root_path, $phpEx, $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']); + $this->word_length = array('min' => $this->config['fulltext_native_min_chars'], 'max' => $this->config['fulltext_native_max_chars']); /** * Load the UTF tools */ if (!class_exists('utf_normalizer')) { - include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); + include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->phpEx); } $error = false; @@ -82,8 +92,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function split_keywords($keywords, $terms) { - global $db, $user, $config; - $tokens = '+-|()*'; $keywords = trim($this->cleanup($keywords, $tokens)); @@ -182,9 +190,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base $num_keywords = sizeof(explode(' ', $keywords)); // We limit the number of allowed keywords to minimize load on the database - if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords']) + if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords']) { - trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords)); + trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], $num_keywords)); } // $keywords input format: each word separated by a space, words in a bracket are not separated @@ -214,12 +222,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql = 'SELECT word_id, word_text, word_common FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $exact_words) . ' + WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . ' ORDER BY word_count ASC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); // store an array of words and ids, remove common words - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if ($row['word_common']) { @@ -230,7 +238,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $words[$row['word_text']] = (int) $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } unset($exact_words); @@ -301,7 +309,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base { if (strpos($word_part, '*') !== false) { - $id_words[] = '\'' . $db->sql_escape(str_replace('*', '%', $word_part)) . '\''; + $id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\''; $non_common_words[] = $word_part; } else if (isset($words[$word_part])) @@ -334,7 +342,11 @@ class phpbb_search_fulltext_native extends phpbb_search_base // throw an error if we shall not ignore unexistant words else if (!$ignore_no_id && sizeof($non_common_words)) { +<<<<<<< HEAD trigger_error(sprintf($user->lang['WORDS_IN_NO_POST'], implode($user->lang['COMMA_SEPARATOR'], $non_common_words))); +======= + trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode(', ', $non_common_words))); +>>>>>>> 1ee5f46... [ticket/11011] remove global keyword in native search } unset($non_common_words); } @@ -346,7 +358,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $len = utf8_strlen(str_replace('*', '', $word)); if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) { - $this->{$mode . '_ids'}[] = '\'' . $db->sql_escape(str_replace('*', '%', $word)) . '\''; + $this->{$mode . '_ids'}[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word)) . '\''; } else { @@ -366,7 +378,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $len = utf8_strlen($word); if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) { - trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word)); + trigger_error(sprintf($this->user->lang['WORD_IN_NO_POST'], $word)); } else { @@ -421,8 +433,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (empty($this->search_query)) { @@ -537,7 +547,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } - $sql_where[] = $db->sql_in_set("m$m_num.word_id", $word_ids); + $sql_where[] = $this->db->sql_in_set("m$m_num.word_id", $word_ids); unset($word_id_sql); unset($word_ids); @@ -591,7 +601,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), - 'ON' => $db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" + 'ON' => $this->db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" ); $sql_where[] = "m$m_num.word_id IS NULL"; @@ -632,7 +642,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else if ($m_approve_fid_ary !== array(-1)) { - $sql_where[] = '(p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } if ($topic_id) @@ -645,18 +655,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } $sql_where[] = $sql_author; } if (sizeof($ex_fid_ary)) { - $sql_where[] = $db->sql_in_set('p.forum_id', $ex_fid_ary, true); + $sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true); } if ($sort_days) @@ -681,7 +691,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base ); } - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'mysql4': case 'mysqli': @@ -695,17 +705,17 @@ class phpbb_search_fulltext_native extends phpbb_search_base case 'sqlite': $sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results - FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; + FROM (' . $this->db->sql_build_query('SELECT', $sql_array_count) . ')'; // no break default: $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; - $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; + $sql = (!$sql) ? $this->db->sql_build_query('SELECT', $sql_array_count) : $sql; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -751,14 +761,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base unset($sql_where, $sql_sort, $group_by); - $sql = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!sizeof($id_ary)) { @@ -772,16 +782,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_array_copy = $sql_array; $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; - $sql = $db->sql_build_query('SELECT', $sql_array_copy); + $sql = $this->db->sql_build_query('SELECT', $sql_array_copy); unset($sql_array_copy); - $db->sql_query($sql); - $db->sql_freeresult($result); + $this->db->sql_query($sql); + $this->db->sql_freeresult($result); $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -819,8 +829,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ 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, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -856,13 +864,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -898,7 +906,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; @@ -907,7 +915,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base // If the cache was completely empty count the results if (!$total_results) { - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'mysql4': case 'mysqli': @@ -929,7 +937,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else { - if ($db->sql_layer == 'sqlite') + if ($this->db->sql_layer == 'sqlite') { $sql = 'SELECT COUNT(topic_id) as total_results FROM (SELECT DISTINCT t.topic_id'; @@ -946,12 +954,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base $m_approve_fid_sql $sql_fora AND t.topic_id = p.topic_id - $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : ''); + $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : ''); } - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -994,26 +1002,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!$total_results && $is_mysql) { // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); - $db->sql_query($sql); - $db->sql_freeresult($result); + $this->db->sql_query($sql); + $this->db->sql_freeresult($result); $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -1046,8 +1054,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function split_message($text) { - global $phpbb_root_path, $phpEx, $user; - $match = $words = array(); /** @@ -1125,9 +1131,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $config, $db, $user; - - if (!$config['fulltext_native_load_upd']) + if (!$this->config['fulltext_native_load_upd']) { /** * The search indexer is disabled, return @@ -1153,14 +1157,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m WHERE m.post_id = $post_id AND w.word_id = m.word_id"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $which = ($row['title_match']) ? 'title' : 'post'; $cur_words[$which][$row['word_text']] = $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $words['add']['post'] = array_diff($split_text, array_keys($cur_words['post'])); $words['add']['title'] = array_diff($split_title, array_keys($cur_words['title'])); @@ -1188,18 +1192,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql = 'SELECT word_id, word_text FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $unique_add_words); - $result = $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words); + $result = $this->db->sql_query($sql); $word_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $word_ids[$row['word_text']] = $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $new_words = array_diff($unique_add_words, array_keys($word_ids)); - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); if (sizeof($new_words)) { $sql_ary = array(); @@ -1208,15 +1212,15 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); } - $db->sql_return_on_error(true); - $db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(true); + $this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); + $this->db->sql_return_on_error(false); } unset($new_words, $sql_ary); } else { - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); } // now update the search match table, remove links to removed words and add links to new words @@ -1233,22 +1237,22 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' + WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND post_id = ' . intval($post_id) . " AND title_match = $title_match"; - $db->sql_query($sql); + $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' + WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); unset($sql_in); } } - $db->sql_return_on_error(true); + $this->db->sql_return_on_error(true); foreach ($words['add'] as $word_in => $word_ary) { $title_match = ($word_in == 'title') ? 1 : 0; @@ -1258,18 +1262,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $word_ary); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $word_ary); + $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count + 1 - WHERE ' . $db->sql_in_set('word_text', $word_ary); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $word_ary); + $this->db->sql_query($sql); } } - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(false); - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); // destroy cached search results containing any of the words removed or added $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id)); @@ -1284,18 +1288,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index_remove($post_ids, $author_ids, $forum_ids) { - global $db; - if (sizeof($post_ids)) { $sql = 'SELECT w.word_id, w.word_text, m.title_match FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w - WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . ' + WHERE ' . $this->db->sql_in_set('m.post_id', $post_ids) . ' AND w.word_id = m.word_id'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $message_word_ids = $title_word_ids = $word_texts = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if ($row['title_match']) { @@ -1307,32 +1309,32 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $word_texts[] = $row['word_text']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($title_word_ids)) { $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $title_word_ids) . ' + WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); } if (sizeof($message_word_ids)) { $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $message_word_ids) . ' + WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); } unset($title_word_ids); unset($message_word_ids); $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('post_id', $post_ids); + $this->db->sql_query($sql); } $this->destroy_cache(array_unique($word_texts), array_unique($author_ids)); @@ -1344,11 +1346,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function tidy() { - global $db, $config; - // Is the fulltext indexer disabled? If yes then we need not // carry on ... it's okay ... I know when I'm not wanted boo hoo - if (!$config['fulltext_native_load_upd']) + if (!$this->config['fulltext_native_load_upd']) { set_config('search_last_gc', time(), true); return; @@ -1357,31 +1357,31 @@ class phpbb_search_fulltext_native extends phpbb_search_base $destroy_cache_words = array(); // Remove common words - if ($config['num_posts'] >= 100 && $config['fulltext_native_common_thres']) + if ($this->config['num_posts'] >= 100 && $this->config['fulltext_native_common_thres']) { - $common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0; + $common_threshold = ((double) $this->config['fulltext_native_common_thres']) / 100.0; // First, get the IDs of common words $sql = 'SELECT word_id, word_text FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . ' + WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . ' OR word_common = 1'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $sql_in = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $sql_in[] = $row['word_id']; $destroy_cache_words[] = $row['word_text']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($sql_in)) { // Flag the words $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_common = 1 - WHERE ' . $db->sql_in_set('word_id', $sql_in); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_id', $sql_in); + $this->db->sql_query($sql); // by setting search_last_gc to the new time here we make sure that if a user reloads because the // following query takes too long, he won't run into it again @@ -1389,8 +1389,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base // Delete the matches $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('word_id', $sql_in); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_id', $sql_in); + $this->db->sql_query($sql); } unset($sql_in); } @@ -1409,21 +1409,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'sqlite': case 'firebird': - $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); break; default: - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); break; } } @@ -1446,24 +1444,20 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index_stats() { - global $user; - if (!sizeof($this->stats)) { $this->get_stats(); } return array( - $user->lang['TOTAL_WORDS'] => $this->stats['total_words'], - $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); + $this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'], + $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } function get_stats() { - global $db; - - $this->stats['total_words'] = $db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); - $this->stats['total_matches'] = $db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); + $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); + $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); } /** @@ -1483,7 +1477,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') { - global $phpbb_root_path, $phpEx; static $conv = array(), $conv_loaded = array(); $words = $allow = array(); @@ -1680,7 +1673,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!isset($conv_loaded[$idx])) { $conv_loaded[$idx] = 1; - $file = $phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $phpEx; + $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->phpEx; if (file_exists($file)) { @@ -1713,29 +1706,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function acp() { - global $user, $config; - - /** * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed */ $tpl = '
-

' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
-
+

' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
+
-

' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
-
+

' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
+
-

' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
-
+

' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
+
-

' . $user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
-
%
+

' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
+
%
'; From 2e218776bbac82841e1ced583c83890be5080af0 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 24 Jul 2012 12:10:22 +0530 Subject: [PATCH 5/9] [ticket/11011] passing global variables Pass global variables to class constructor when making a new object. PHPBB3-11011 --- phpBB/includes/acp/acp_search.php | 4 ++-- phpBB/includes/search/fulltext_native.php | 4 ---- phpBB/search.php | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 82d9b021fe..5ae9f363f0 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -596,7 +596,7 @@ class acp_search */ function init_search($type, &$search, &$error) { - global $phpbb_root_path, $phpEx, $user; + global $phpbb_root_path, $phpEx, $user, $config, $db; if (!class_exists($type) || !method_exists($type, 'keyword_search')) { @@ -605,7 +605,7 @@ class acp_search } $error = false; - $search = new $type($error); + $search = new $type($error, $phpbb_root_path, $phpEx, $config, $db, $user); return $error; } diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index b9818d7919..a470a92458 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -342,11 +342,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base // throw an error if we shall not ignore unexistant words else if (!$ignore_no_id && sizeof($non_common_words)) { -<<<<<<< HEAD trigger_error(sprintf($user->lang['WORDS_IN_NO_POST'], implode($user->lang['COMMA_SEPARATOR'], $non_common_words))); -======= - trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode(', ', $non_common_words))); ->>>>>>> 1ee5f46... [ticket/11011] remove global keyword in native search } unset($non_common_words); } diff --git a/phpBB/search.php b/phpBB/search.php index efbf2f4dfe..68946e2a95 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -280,7 +280,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) } // We do some additional checks in the module to ensure it can actually be utilised $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $config, $db, $user); if ($error) { From d982a37f191ffb731633a6adf6f86416787080db Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:25:26 +0530 Subject: [PATCH 6/9] [ticket/11011] pass global variables in construct Use global variables passed through constructor instead of using global keyword in sphinx search backend. PHPBB3-11011 --- phpBB/includes/search/fulltext_sphinx.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 8371f6b377..9dc6e66e3a 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -40,6 +40,8 @@ class phpbb_search_fulltext_sphinx private $id; private $indexes; private $sphinx; + private $phpbb_root_path; + private $phpEx; private $auth; private $config; private $db; @@ -56,9 +58,10 @@ class phpbb_search_fulltext_sphinx * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $config, $db, $user, $auth, $phpbb_root_path, $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; $this->config = $config; $this->user = $user; $this->db = $db; @@ -66,7 +69,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('phpbb_db_tools')) { - require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->phpEx); } // Initialize phpbb_db_tools object @@ -127,8 +130,6 @@ class phpbb_search_fulltext_sphinx */ function config_generate() { - global $phpbb_root_path, $phpEx; - // Check if Database is supported by Sphinx if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli') { @@ -151,7 +152,7 @@ class phpbb_search_fulltext_sphinx return false; } - include($phpbb_root_path . 'config.' . $phpEx); + include($this->phpbb_root_path . 'config.' . $this->phpEx); /* Now that we're sure everything was entered correctly, generate a config for the index. We use a config value From 9eb6c2ba5b6fb1c1090f5a89387a8fa8ae958a85 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:50:56 +0530 Subject: [PATCH 7/9] [ticket/11011] remove global keyword from sphinx PHPBB3-11011 --- phpBB/includes/search/fulltext_sphinx.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9dc6e66e3a..0662b70a2b 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -17,13 +17,6 @@ if (!defined('IN_PHPBB')) /** * @ignore */ -/** -* This statement is necessary as this file is sometimes included from within a -* function and the variables used are in global space. -*/ -global $phpbb_root_path, $phpEx, $table_prefix; -require($phpbb_root_path . 'includes/sphinxapi.' . $phpEx); - define('SPHINX_MAX_MATCHES', 20000); define('SPHINX_CONNECT_RETRIES', 3); define('SPHINX_CONNECT_WAIT_TIME', 300); @@ -82,6 +75,12 @@ class phpbb_search_fulltext_sphinx $this->id = $this->config['fulltext_sphinx_id']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; + if (!class_exists('SphinxClient')) + { + require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->phpEx); + } + + // Initialize sphinx client $this->sphinx = new SphinxClient(); $this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312)); From 794d6ec443bd16ad2f7776d1ba2abcf2ce1c5553 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Aug 2012 11:07:47 +0530 Subject: [PATCH 8/9] [ticket/11011] pass $auth to search backend constructor $auth global var is passed to search backend constructor, as it is used by sphinx backend. PHPBB3-11011 --- phpBB/includes/acp/acp_search.php | 4 ++-- phpBB/includes/search/fulltext_mysql.php | 2 +- phpBB/includes/search/fulltext_native.php | 2 +- phpBB/includes/search/fulltext_postgres.php | 2 +- phpBB/includes/search/fulltext_sphinx.php | 2 +- phpBB/search.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 5ae9f363f0..6618e2c3f9 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -596,7 +596,7 @@ class acp_search */ function init_search($type, &$search, &$error) { - global $phpbb_root_path, $phpEx, $user, $config, $db; + global $phpbb_root_path, $phpEx, $user, $auth, $config, $db; if (!class_exists($type) || !method_exists($type, 'keyword_search')) { @@ -605,7 +605,7 @@ class acp_search } $error = false; - $search = new $type($error, $phpbb_root_path, $phpEx, $config, $db, $user); + $search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); return $error; } diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index ccf9f49612..8320b8e760 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -37,7 +37,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->config = $config; $this->db = $db; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index a470a92458..b5f1a4f52f 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -42,7 +42,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure. */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 75cb48ecc6..0e6f72f142 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -41,7 +41,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->config = $config; $this->db = $db; diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 0662b70a2b..d4ded8efc0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -51,7 +51,7 @@ class phpbb_search_fulltext_sphinx * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; diff --git a/phpBB/search.php b/phpBB/search.php index 68946e2a95..190da5247f 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -280,7 +280,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) } // We do some additional checks in the module to ensure it can actually be utilised $error = false; - $search = new $search_type($error, $phpbb_root_path, $phpEx, $config, $db, $user); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); if ($error) { From a422ddfe31af469123f3fa830a3ae313dc9e8ec7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Aug 2012 11:16:46 +0530 Subject: [PATCH 9/9] [ticket/11011] rename property phpEx to php_ext PHPBB3-11011 --- phpBB/includes/search/fulltext_native.php | 8 ++++---- phpBB/includes/search/fulltext_sphinx.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index b5f1a4f52f..ea9d050b60 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -32,7 +32,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base var $must_exclude_one_ids = array(); private $phpbb_root_path; - private $phpEx; + private $php_ext; private $config; private $db; private $user; @@ -45,7 +45,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $phpEx; $this->config = $config; $this->db = $db; $this->user = $user; @@ -57,7 +57,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ if (!class_exists('utf_normalizer')) { - include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->php_ext); } $error = false; @@ -1669,7 +1669,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!isset($conv_loaded[$idx])) { $conv_loaded[$idx] = 1; - $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->phpEx; + $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->php_ext; if (file_exists($file)) { diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index d4ded8efc0..d10d5d4942 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -34,7 +34,7 @@ class phpbb_search_fulltext_sphinx private $indexes; private $sphinx; private $phpbb_root_path; - private $phpEx; + private $php_ext; private $auth; private $config; private $db; @@ -54,7 +54,7 @@ class phpbb_search_fulltext_sphinx public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $phpEx; $this->config = $config; $this->user = $user; $this->db = $db; @@ -62,7 +62,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('phpbb_db_tools')) { - require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->phpEx); + require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->php_ext); } // Initialize phpbb_db_tools object @@ -77,7 +77,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('SphinxClient')) { - require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->phpEx); + require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->php_ext); } // Initialize sphinx client @@ -151,7 +151,7 @@ class phpbb_search_fulltext_sphinx return false; } - include($this->phpbb_root_path . 'config.' . $this->phpEx); + include($this->phpbb_root_path . 'config.' . $this->php_ext); /* Now that we're sure everything was entered correctly, generate a config for the index. We use a config value