From 87d0888feeaef2716b38fbc933c4a16777a217d3 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sat, 11 Apr 2020 22:05:06 +0200 Subject: [PATCH 1/6] [ticket/16426] Search results return characters as input box PHPBB3-16426 --- phpBB/adm/style/acp_search.html | 7 ++++ phpBB/includes/acp/acp_search.php | 38 ++++++++++--------- phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/search.php | 2 + phpBB/language/en/search.php | 1 + phpBB/search.php | 20 ++-------- .../prosilver/template/search_body.html | 7 +++- 7 files changed, 40 insertions(+), 36 deletions(-) diff --git a/phpBB/adm/style/acp_search.html b/phpBB/adm/style/acp_search.html index 99620058dc..7fecc0f691 100644 --- a/phpBB/adm/style/acp_search.html +++ b/phpBB/adm/style/acp_search.html @@ -36,6 +36,13 @@

{L_MAX_NUM_SEARCH_KEYWORDS_EXPLAIN}
+
+
+ +
{{ lang('DEFAULT_SEARCH_RETURN_CHARS_EXPLAIN') }} +
+
+

{L_SEARCH_STORE_RESULTS_EXPLAIN}
{L_SECONDS}
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 538a28a926..e59e06e1cd 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -62,15 +62,16 @@ class acp_search $search_types = $this->get_search_types(); - $settings = array( - 'search_interval' => 'float', - 'search_anonymous_interval' => 'float', - 'load_search' => 'bool', - 'limit_search_load' => 'float', - 'min_search_author_chars' => 'integer', - 'max_num_search_keywords' => 'integer', - 'search_store_results' => 'integer', - ); + $settings = [ + 'search_interval' => 'float', + 'search_anonymous_interval' => 'float', + 'load_search' => 'bool', + 'limit_search_load' => 'float', + 'min_search_author_chars' => 'integer', + 'max_num_search_keywords' => 'integer', + 'default_search_return_chars' => 'integer', + 'search_store_results' => 'integer', + ]; $search = null; $error = false; @@ -219,20 +220,21 @@ class acp_search $this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_SETTINGS'; - $template->assign_vars(array( - 'LIMIT_SEARCH_LOAD' => (float) $config['limit_search_load'], - 'MIN_SEARCH_AUTHOR_CHARS' => (int) $config['min_search_author_chars'], - 'SEARCH_INTERVAL' => (float) $config['search_interval'], - 'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'], - 'SEARCH_STORE_RESULTS' => (int) $config['search_store_results'], - 'MAX_NUM_SEARCH_KEYWORDS' => (int) $config['max_num_search_keywords'], + $template->assign_vars([ + 'DEFAULT_SEARCH_RETURN_CHARS' => (int) $config['default_search_return_chars'], + 'LIMIT_SEARCH_LOAD' => (float) $config['limit_search_load'], + 'MIN_SEARCH_AUTHOR_CHARS' => (int) $config['min_search_author_chars'], + 'SEARCH_INTERVAL' => (float) $config['search_interval'], + 'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'], + 'SEARCH_STORE_RESULTS' => (int) $config['search_store_results'], + 'MAX_NUM_SEARCH_KEYWORDS' => (int) $config['max_num_search_keywords'], 'S_SEARCH_TYPES' => $search_options, 'S_YES_SEARCH' => (bool) $config['load_search'], 'S_SETTINGS' => true, - 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search')) - ); + 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), + ]); } function index($id, $mode) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index ef61bb4daf..3e70231873 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -100,6 +100,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_subje INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_order', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('edit_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('extension_force_unstable', '0'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_search_return_chars', '300'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('delete_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_check_mx', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_enable', '1'); diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 443dbb7fb7..a79c67fd8e 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -49,6 +49,8 @@ $lang = array_merge($lang, array( 'CONTINUE_INDEXING_EXPLAIN' => 'An indexing process has been started. In order to access the search index page you will have to complete it or cancel it.', 'CREATE_INDEX' => 'Create index', + 'DEFAULT_SEARCH_RETURN_CHARS' => 'Default number of returned characters', + 'DEFAULT_SEARCH_RETURN_CHARS_EXPLAIN' => 'The default number of characters that will be returned while searching. A value of 0 will return the entire post.', 'DELETE_INDEX' => 'Delete index', 'DELETING_INDEX_IN_PROGRESS' => 'Deleting the index in progress', 'DELETING_INDEX_IN_PROGRESS_EXPLAIN' => 'The search backend is currently cleaning its index. This can take a few minutes.', diff --git a/phpBB/language/en/search.php b/phpBB/language/en/search.php index 13e5bf7a97..f89107ed1b 100644 --- a/phpBB/language/en/search.php +++ b/phpBB/language/en/search.php @@ -87,6 +87,7 @@ $lang = array_merge($lang, array( 'RESULT_DAYS' => 'Limit results to previous', 'RESULT_SORT' => 'Sort results by', 'RETURN_FIRST' => 'Return first', + 'RETURN_FIRST_EXPLAIN' => 'Set to 0 to display the entire post.', 'GO_TO_SEARCH_ADV' => 'Go to advanced search', 'SEARCHED_FOR' => 'Search term used', diff --git a/phpBB/search.php b/phpBB/search.php index 5d5e9f5f8a..f1bae7f276 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -47,7 +47,7 @@ $sort_days = $request->variable('st', 0); $sort_key = $request->variable('sk', 't'); $sort_dir = $request->variable('sd', 'd'); -$return_chars = $request->variable('ch', ($topic_id) ? -1 : 300); +$return_chars = $request->variable('ch', $topic_id ? 0 : (int) $config['default_search_return_chars']); $search_forum = $request->variable('fid', array(0)); // We put login boxes for the case if search_id is newposts, egosearch or unreadposts @@ -692,7 +692,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) $u_search .= ($u_search_forum) ? '&fid%5B%5D=' . $u_search_forum : ''; $u_search .= (!$search_child) ? '&sc=0' : ''; $u_search .= ($search_fields != 'all') ? '&sf=' . $search_fields : ''; - $u_search .= ($return_chars != 300) ? '&ch=' . $return_chars : ''; + $u_search .= $return_chars !== (int) $config['default_search_return_chars'] ? '&ch=' . $return_chars : ''; /** * Event to add or modify search URL parameters @@ -975,7 +975,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) strip_bbcode($text_only_message, $row['bbcode_uid']); } - if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3)) + if ($return_chars === 0 || utf8_strlen($text_only_message) < ($return_chars + 3)) { $row['display_text_only'] = false; @@ -1475,18 +1475,6 @@ if (!$s_forums) trigger_error('NO_SEARCH'); } -// Number of chars returned -$s_characters = ''; -$s_characters .= ''; -$s_characters .= ''; -$s_characters .= ''; - -for ($i = 100; $i <= 1000; $i += 100) -{ - $selected = ($i == 300) ? ' selected="selected"' : ''; - $s_characters .= ''; -} - $s_hidden_fields = array('t' => $topic_id); if ($_SID) @@ -1504,9 +1492,9 @@ if (!empty($_EXTRA_URL)) } $template->assign_vars(array( + 'DEFAULT_RETURN_CHARS' => (int) $config['default_search_return_chars'], 'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", false, true, 0), // We force no ?sid= appending by using 0 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields), - 'S_CHARACTER_OPTIONS' => $s_characters, 'S_FORUM_OPTIONS' => $s_forums, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, diff --git a/phpBB/styles/prosilver/template/search_body.html b/phpBB/styles/prosilver/template/search_body.html index 618e2680ba..2f667a3349 100644 --- a/phpBB/styles/prosilver/template/search_body.html +++ b/phpBB/styles/prosilver/template/search_body.html @@ -79,8 +79,11 @@
{S_SELECT_SORT_DAYS}
-
-
{L_POST_CHARACTERS}
+
+ +
{{ lang('RETURN_FIRST_EXPLAIN') }} +
+
{{ lang('POST_CHARACTERS') }}
From d1aefbea625ed916477a09c9a3ecc7be03592208 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sun, 12 Apr 2020 13:21:36 +0200 Subject: [PATCH 2/6] [ticket/16426] Add default search return chars migration PHPBB3-16426 --- .../data/v330/default_search_return_chars.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php diff --git a/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php b/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php new file mode 100644 index 0000000000..1cae2da8d0 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php @@ -0,0 +1,36 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\db\migration\data\v330; + +class default_search_return_chars extends \phpbb\db\migration\migration +{ + public function effectively_installed() + { + return $this->config->offsetExists('default_search_return_chars'); + } + + public static function depends_on() + { + return [ + '\phpbb\db\migration\data\v330\dev', + ]; + } + + public function update_data() + { + return [ + ['config.add', ['default_search_return_chars', 300]], + ]; + } +} From 9a72f39ff3c7b44431268dff0c6a517bcb41fd93 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sat, 2 May 2020 23:38:56 +0200 Subject: [PATCH 3/6] [ticket/16426] Add BC for select characters PHPBB3-16426 --- phpBB/search.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/phpBB/search.php b/phpBB/search.php index f1bae7f276..eba8338fec 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -1475,6 +1475,28 @@ if (!$s_forums) trigger_error('NO_SEARCH'); } +/** + * Build options for a select list for the number of characters returned. + * + * If the admin defined amount is not available, we add that option. + * + * @deprecated 3.3.1-RC1 Templates should use an numeric input, in favor of a select. + */ +$s_characters = ''; +$i_characters = array_merge([25, 50], range(100, 1000, 100)); + +if (!in_array((int) $config['default_search_return_chars'], $i_characters)) +{ + $i_characters[] = (int) $config['default_search_return_chars']; + sort($i_characters); +} + +foreach ($i_characters as $i) +{ + $selected = $i === (int) $config['default_search_return_chars'] ? '" selected="selected' : ''; + $s_characters .= sprintf('', $i, $selected); +} + $s_hidden_fields = array('t' => $topic_id); if ($_SID) @@ -1495,6 +1517,7 @@ $template->assign_vars(array( 'DEFAULT_RETURN_CHARS' => (int) $config['default_search_return_chars'], 'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", false, true, 0), // We force no ?sid= appending by using 0 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields), + 'S_CHARACTER_OPTIONS' => $s_characters, 'S_FORUM_OPTIONS' => $s_forums, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, From d9e07b3b2935e4a607da1816a2a0ca68a4898e70 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sat, 2 May 2020 23:43:22 +0200 Subject: [PATCH 4/6] [ticket/16426] Ensure 0 is not added as an option PHPBB3-16426 --- phpBB/search.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index eba8338fec..edf6360caa 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -1478,14 +1478,15 @@ if (!$s_forums) /** * Build options for a select list for the number of characters returned. * - * If the admin defined amount is not available, we add that option. + * If the admin defined amount is not within the predefined range, + * and the admin did not set it to unlimited (0), we add that option aswell. * * @deprecated 3.3.1-RC1 Templates should use an numeric input, in favor of a select. */ $s_characters = ''; $i_characters = array_merge([25, 50], range(100, 1000, 100)); -if (!in_array((int) $config['default_search_return_chars'], $i_characters)) +if ($config['default_search_return_chars'] && !in_array((int) $config['default_search_return_chars'], $i_characters)) { $i_characters[] = (int) $config['default_search_return_chars']; sort($i_characters); From b8bab306846ca502aa76be4d23c2a8f09c2a9bde Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Mon, 4 May 2020 12:01:26 +0200 Subject: [PATCH 5/6] [ticket/16426] Correct migration dependent and common 'selected' approach PHPBB3-16426 --- .../db/migration/data/v330/default_search_return_chars.php | 2 +- phpBB/search.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php b/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php index 1cae2da8d0..a0b80c4de0 100644 --- a/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php +++ b/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php @@ -23,7 +23,7 @@ class default_search_return_chars extends \phpbb\db\migration\migration public static function depends_on() { return [ - '\phpbb\db\migration\data\v330\dev', + '\phpbb\db\migration\data\v330\v330', ]; } diff --git a/phpBB/search.php b/phpBB/search.php index edf6360caa..678b4d9ff8 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -1483,7 +1483,7 @@ if (!$s_forums) * * @deprecated 3.3.1-RC1 Templates should use an numeric input, in favor of a select. */ -$s_characters = ''; +$s_characters = ''; $i_characters = array_merge([25, 50], range(100, 1000, 100)); if ($config['default_search_return_chars'] && !in_array((int) $config['default_search_return_chars'], $i_characters)) @@ -1494,8 +1494,8 @@ if ($config['default_search_return_chars'] && !in_array((int) $config['default_s foreach ($i_characters as $i) { - $selected = $i === (int) $config['default_search_return_chars'] ? '" selected="selected' : ''; - $s_characters .= sprintf('', $i, $selected); + $selected = $i === (int) $config['default_search_return_chars'] ? ' selected="selected"' : ''; + $s_characters .= sprintf('', $i, $selected); } $s_hidden_fields = array('t' => $topic_id); From 47b1973cb653e3eef6cc642e6fddd98f26f470d8 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Mon, 4 May 2020 21:32:42 +0200 Subject: [PATCH 6/6] [ticket/16426] Correct migration namespace PHPBB3-16426 --- .../data/{v330 => v33x}/default_search_return_chars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename phpBB/phpbb/db/migration/data/{v330 => v33x}/default_search_return_chars.php (94%) diff --git a/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php b/phpBB/phpbb/db/migration/data/v33x/default_search_return_chars.php similarity index 94% rename from phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php rename to phpBB/phpbb/db/migration/data/v33x/default_search_return_chars.php index a0b80c4de0..ec1e7af11f 100644 --- a/phpBB/phpbb/db/migration/data/v330/default_search_return_chars.php +++ b/phpBB/phpbb/db/migration/data/v33x/default_search_return_chars.php @@ -11,7 +11,7 @@ * */ -namespace phpbb\db\migration\data\v330; +namespace phpbb\db\migration\data\v33x; class default_search_return_chars extends \phpbb\db\migration\migration {