From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/search/base.php | 330 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 phpBB/phpbb/search/base.php (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php new file mode 100644 index 0000000000..914cef9167 --- /dev/null +++ b/phpBB/phpbb/search/base.php @@ -0,0 +1,330 @@ +ignore_words)) + { + global $user, $phpEx; + + $words = array(); + + if (file_exists("{$user->lang_path}{$user->lang_name}/search_ignore_words.$phpEx")) + { + // include the file containing ignore words + include("{$user->lang_path}{$user->lang_name}/search_ignore_words.$phpEx"); + } + + $this->ignore_words = $words; + unset($words); + } + } + + /** + * Stores a list of synonyms that should be replaced in $this->match_synonym and $this->replace_synonym and caches them + */ + function get_synonyms() + { + if (!sizeof($this->match_synonym)) + { + global $user, $phpEx; + + $synonyms = array(); + + if (file_exists("{$user->lang_path}{$user->lang_name}/search_synonyms.$phpEx")) + { + // include the file containing synonyms + include("{$user->lang_path}{$user->lang_name}/search_synonyms.$phpEx"); + } + + $this->match_synonym = array_keys($synonyms); + $this->replace_synonym = array_values($synonyms); + + unset($synonyms); + } + } + + /** + * Retrieves cached search results + * + * @param int &$result_count will contain the number of all results for the search (not only for the current page) + * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache + * + * @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) + { + 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; + } + else + { + $result_count = $stored_ids[-1]; + $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; + $complete = true; + + // Change start parameter in case out of bounds + if ($result_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + } + + // change the start to the actual end of the current request if the sort direction differs + // from the dirction in the cache and reverse the ids later + if ($reverse_ids) + { + $start = $result_count - $start - $per_page; + + // the user requested a page past the last index + if ($start < 0) + { + return SEARCH_RESULT_NOT_IN_CACHE; + } + } + + for ($i = $start, $n = $start + $per_page; ($i < $n) && ($i < $result_count); $i++) + { + if (!isset($stored_ids[$i])) + { + $complete = false; + } + else + { + $id_ary[] = $stored_ids[$i]; + } + } + unset($stored_ids); + + if ($reverse_ids) + { + $id_ary = array_reverse($id_ary); + } + + if (!$complete) + { + return SEARCH_RESULT_INCOMPLETE; + } + return SEARCH_RESULT_IN_CACHE; + } + } + + /** + * Caches post/topic ids + * + * @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) + { + global $cache, $config, $db, $user; + + $length = min(sizeof($id_ary), $config['search_block_size']); + + // nothing to cache so exit + if (!$length) + { + return; + } + + $store_ids = array_slice($id_ary, 0, $length); + + // create a new resultset if there is none for this search_key yet + // or add the ids to the existing resultset + if (!($store = $cache->get('_search_results_' . $search_key))) + { + // add the current keywords to the recent searches in the cache which are listed on the search page + if (!empty($keywords) || sizeof($author_ary)) + { + $sql = 'SELECT search_time + FROM ' . SEARCH_RESULTS_TABLE . ' + WHERE search_key = \'' . $db->sql_escape($search_key) . '\''; + $result = $db->sql_query($sql); + + if (!$db->sql_fetchrow($result)) + { + $sql_ary = array( + 'search_key' => $search_key, + 'search_time' => time(), + 'search_keywords' => $keywords, + 'search_authors' => ' ' . implode(' ', $author_ary) . ' ' + ); + + $sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + $db->sql_freeresult($result); + } + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_last_search = ' . time() . ' + WHERE user_id = ' . $user->data['user_id']; + $db->sql_query($sql); + + $store = array(-1 => $result_count, -2 => $sort_dir); + $id_range = range($start, $start + $length - 1); + } + else + { + // we use one set of results for both sort directions so we have to calculate the indizes + // for the reversed array and we also have to reverse the ids themselves + if ($store[-2] != $sort_dir) + { + $store_ids = array_reverse($store_ids); + $id_range = range($store[-1] - $start - $length, $store[-1] - $start - 1); + } + else + { + $id_range = range($start, $start + $length - 1); + } + } + + $store_ids = array_combine($id_range, $store_ids); + + // append the ids + if (is_array($store_ids)) + { + $store += $store_ids; + + // if the cache is too big + if (sizeof($store) - 2 > 20 * $config['search_block_size']) + { + // remove everything in front of two blocks in front of the current start index + for ($i = 0, $n = $id_range[0] - 2 * $config['search_block_size']; $i < $n; $i++) + { + if (isset($store[$i])) + { + unset($store[$i]); + } + } + + // remove everything after two blocks after the current stop index + end($id_range); + for ($i = $store[-1] - 1, $n = current($id_range) + 2 * $config['search_block_size']; $i > $n; $i--) + { + if (isset($store[$i])) + { + unset($store[$i]); + } + } + } + $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']); + + $sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . ' + SET search_time = ' . time() . ' + WHERE search_key = \'' . $db->sql_escape($search_key) . '\''; + $db->sql_query($sql); + } + + unset($store); + unset($store_ids); + unset($id_range); + } + + /** + * 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) + { + global $db, $cache, $config; + + // clear all searches that searched for the specified words + if (sizeof($words)) + { + $sql_where = ''; + foreach ($words as $word) + { + $sql_where .= " OR search_keywords " . $db->sql_like_expression($db->any_char . $word . $db->any_char); + } + + $sql = 'SELECT search_key + FROM ' . SEARCH_RESULTS_TABLE . " + WHERE search_keywords LIKE '%*%' $sql_where"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $cache->destroy('_search_results_' . $row['search_key']); + } + $db->sql_freeresult($result); + } + + // clear all searches that searched for the specified authors + if (is_array($authors) && sizeof($authors)) + { + $sql_where = ''; + foreach ($authors as $author) + { + $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $db->sql_like_expression($db->any_char . ' ' . (int) $author . ' ' . $db->any_char); + } + + $sql = 'SELECT search_key + FROM ' . SEARCH_RESULTS_TABLE . " + WHERE $sql_where"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $cache->destroy('_search_results_' . $row['search_key']); + } + $db->sql_freeresult($result); + } + + $sql = 'DELETE + FROM ' . SEARCH_RESULTS_TABLE . ' + WHERE search_time < ' . (time() - $config['search_store_results']); + $db->sql_query($sql); + } +} -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/search/base.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 914cef9167..2f6b225b99 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\search; + /** * @ignore */ @@ -23,12 +25,12 @@ define('SEARCH_RESULT_IN_CACHE', 1); define('SEARCH_RESULT_INCOMPLETE', 2); /** -* phpbb_search_base +* \phpbb\search\base * optional base class for search plugins providing simple caching based on ACM * and functions to retrieve ignore_words and synonyms * @package search */ -class phpbb_search_base +class base { var $ignore_words = array(); var $match_synonym = array(); @@ -181,7 +183,7 @@ class phpbb_search_base $store_ids = array_slice($id_ary, 0, $length); - // create a new resultset if there is none for this search_key yet + // create a new \resultset if there is none for this search_key yet // or add the ids to the existing resultset if (!($store = $cache->get('_search_results_' . $search_key))) { -- cgit v1.2.1 From 390dc86344c23b658085bae4a719399e5eb579f0 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 16 Sep 2013 05:00:18 +0200 Subject: [ticket/11700] And some last comments with backslashes PHPBB3-11700 --- phpBB/phpbb/search/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 2f6b225b99..f2f982c31b 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -183,7 +183,7 @@ class base $store_ids = array_slice($id_ary, 0, $length); - // create a new \resultset if there is none for this search_key yet + // create a new resultset if there is none for this search_key yet // or add the ids to the existing resultset if (!($store = $cache->get('_search_results_' . $search_key))) { -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/search/base.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index f2f982c31b..9ecf3751d0 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -9,14 +9,6 @@ namespace phpbb\search; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @ignore */ -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/search/base.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 9ecf3751d0..861b1f9328 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -17,10 +21,8 @@ define('SEARCH_RESULT_IN_CACHE', 1); define('SEARCH_RESULT_INCOMPLETE', 2); /** -* \phpbb\search\base * optional base class for search plugins providing simple caching based on ACM * and functions to retrieve ignore_words and synonyms -* @package search */ class base { -- cgit v1.2.1 From ff6e026a403a622bd1aa498bff396a737735faed Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 26 Jun 2014 17:17:35 +0200 Subject: [ticket/12446] Unnecessary db connect inphpbb_bootstrap_enabled_exts PHPBB3-12446 --- phpBB/phpbb/search/base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 861b1f9328..9395b6a273 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -282,7 +282,7 @@ class base $sql_where = ''; foreach ($words as $word) { - $sql_where .= " OR search_keywords " . $db->sql_like_expression($db->any_char . $word . $db->any_char); + $sql_where .= " OR search_keywords " . $db->sql_like_expression($db->get_any_char() . $word . $db->get_any_char()); } $sql = 'SELECT search_key @@ -303,7 +303,7 @@ class base $sql_where = ''; foreach ($authors as $author) { - $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $db->sql_like_expression($db->any_char . ' ' . (int) $author . ' ' . $db->any_char); + $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $db->sql_like_expression($db->get_any_char() . ' ' . (int) $author . ' ' . $db->get_any_char()); } $sql = 'SELECT search_key -- cgit v1.2.1 From 19b9df7e630031e3bdf0640a91f7025da3a00257 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Sat, 17 May 2014 03:43:34 +0300 Subject: [ticket/12557] Fix doc block errors found by Sami PHPBB3-12557 --- phpBB/phpbb/search/base.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 9395b6a273..90f11fc45a 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -85,8 +85,12 @@ class base /** * Retrieves cached search results * - * @param int &$result_count will contain the number of all results for the search (not only for the current page) - * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache + * @param string $search_key an md5 string generated from all the passed search options to identify the results + * @param int &$result_count will contain the number of all results for the search (not only for the current page) + * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache + * @param int $start indicates the first index of the page + * @param int $per_page number of ids each page is supposed to contain + * @param string $sort_dir is either a or d representing ASC and DESC * * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE */ @@ -160,8 +164,15 @@ class base /** * Caches post/topic ids * - * @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element + * @param string $search_key an md5 string generated from all the passed search options to identify the results + * @param string $keywords contains the keywords as entered by the user + * @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty + * @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. + * @param int $start indicates the first index of the page + * @param string $sort_dir is either a or d representing ASC and DESC + * + * @return null */ function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir) { -- cgit v1.2.1 From 8ac8c9ec616d8a53cdf02459ae08b2b44e7fd4cb Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 05:50:29 +0300 Subject: [ticket/12557] Fix doc block errors found by Sami More corrections. PHPBB3-12557 --- phpBB/phpbb/search/base.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 90f11fc45a..f90abe10a8 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -167,6 +167,7 @@ class base * @param string $search_key an md5 string generated from all the passed search options to identify the results * @param string $keywords contains the keywords as entered by the user * @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty + * @param int $result_count contains the number of all results for the search (not only for the current page) * @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. * @param int $start indicates the first index of the page -- cgit v1.2.1 From 8f2395857e785cf8b7ccb338937b7cd30b329aab Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 04:07:08 +0300 Subject: [ticket/12557] Search, cron and profilefields fixes PHPBB3-12557 --- phpBB/phpbb/search/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index f90abe10a8..c41a7b50d5 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -86,8 +86,8 @@ class base * Retrieves cached search results * * @param string $search_key an md5 string generated from all the passed search options to identify the results - * @param int &$result_count will contain the number of all results for the search (not only for the current page) - * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache + * @param int $result_count will contain the number of all results for the search (not only for the current page) + * @param array $id_ary is filled with the ids belonging to the requested page that are stored in the cache * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @param string $sort_dir is either a or d representing ASC and DESC @@ -168,7 +168,7 @@ class base * @param string $keywords contains the keywords as entered by the user * @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty * @param int $result_count contains the number of all results for the search (not only for the current page) - * @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element + * @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. * @param int $start indicates the first index of the page * @param string $sort_dir is either a or d representing ASC and DESC -- cgit v1.2.1 From c355b60c62441d15b5c2ee7044329af784c234f2 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 05:50:29 +0300 Subject: [ticket/12557] Fix doc block errors found by Sami More corrections. PHPBB3-12557 --- phpBB/phpbb/search/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index c41a7b50d5..26e3218b14 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -170,7 +170,7 @@ class base * @param int $result_count contains the number of all results for the search (not only for the current page) * @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. - * @param int $start indicates the first index of the page + * @param int $start indicates the first index of the page * @param string $sort_dir is either a or d representing ASC and DESC * * @return null -- cgit v1.2.1 From 9d285bdcf51f6e7b7a53e68eb377d4c70c184844 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Thu, 7 Aug 2014 11:39:04 +0300 Subject: [ticket/12557] Fix pass by reference doc blocks PHPBB3-12557 --- phpBB/phpbb/search/base.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 26e3218b14..30781975d8 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -86,9 +86,9 @@ class base * Retrieves cached search results * * @param string $search_key an md5 string generated from all the passed search options to identify the results - * @param int $result_count will contain the number of all results for the search (not only for the current page) - * @param array $id_ary is filled with the ids belonging to the requested page that are stored in the cache - * @param int $start indicates the first index of the page + * @param int &$result_count will contain the number of all results for the search (not only for the current page) + * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache + * @param int &$start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @param string $sort_dir is either a or d representing ASC and DESC * @@ -168,7 +168,7 @@ class base * @param string $keywords contains the keywords as entered by the user * @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty * @param int $result_count contains the number of all results for the search (not only for the current page) - * @param array $id_ary contains a list of post or topic ids that shall be cached, the first element + * @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. * @param int $start indicates the first index of the page * @param string $sort_dir is either a or d representing ASC and DESC -- cgit v1.2.1 From 53b9216c784e0d9688d565f85ef2a97c308fdaa2 Mon Sep 17 00:00:00 2001 From: Crizzo Date: Sun, 3 Jul 2016 14:22:08 +0200 Subject: [ticket/14704] Removes unused function and language files in base.php PHPBB3-14704 --- phpBB/phpbb/search/base.php | 46 --------------------------------------------- 1 file changed, 46 deletions(-) (limited to 'phpBB/phpbb/search/base.php') diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index 30781975d8..d9313dddab 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -36,52 +36,6 @@ class base $error = true; } - /** - * Retrieves a language dependend list of words that should be ignored by the search - */ - function get_ignore_words() - { - if (!sizeof($this->ignore_words)) - { - global $user, $phpEx; - - $words = array(); - - if (file_exists("{$user->lang_path}{$user->lang_name}/search_ignore_words.$phpEx")) - { - // include the file containing ignore words - include("{$user->lang_path}{$user->lang_name}/search_ignore_words.$phpEx"); - } - - $this->ignore_words = $words; - unset($words); - } - } - - /** - * Stores a list of synonyms that should be replaced in $this->match_synonym and $this->replace_synonym and caches them - */ - function get_synonyms() - { - if (!sizeof($this->match_synonym)) - { - global $user, $phpEx; - - $synonyms = array(); - - if (file_exists("{$user->lang_path}{$user->lang_name}/search_synonyms.$phpEx")) - { - // include the file containing synonyms - include("{$user->lang_path}{$user->lang_name}/search_synonyms.$phpEx"); - } - - $this->match_synonym = array_keys($synonyms); - $this->replace_synonym = array_values($synonyms); - - unset($synonyms); - } - } - /** * Retrieves cached search results * -- cgit v1.2.1