|
18 | 18 | use SMF\ActionInterface; |
19 | 19 | use SMF\ActionRouter; |
20 | 20 | use SMF\ActionTrait; |
21 | | -use SMF\Category; |
| 21 | +use SMF\Board; |
22 | 22 | use SMF\Config; |
23 | 23 | use SMF\Db\DatabaseApi as Db; |
24 | 24 | use SMF\ErrorHandler; |
@@ -70,6 +70,7 @@ public function execute(): void |
70 | 70 | // Don't load this in XML mode. |
71 | 71 | if (!isset($_REQUEST['xml'])) { |
72 | 72 | Theme::loadTemplate('Search'); |
| 73 | + Theme::loadTemplate('GenericControls'); |
73 | 74 | Theme::loadJavaScriptFile('suggest.js', ['defer' => false, 'minimize' => true], 'smf_suggest'); |
74 | 75 | } |
75 | 76 |
|
@@ -174,91 +175,18 @@ public function execute(): void |
174 | 175 | } |
175 | 176 | } |
176 | 177 |
|
177 | | - // Find all the boards this user is allowed to see. |
178 | | - $request = Db::$db->query( |
179 | | - 'SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level |
180 | | - FROM {db_prefix}boards AS b |
181 | | - LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
182 | | - WHERE {query_see_board} |
183 | | - AND redirect = {string:empty_string}', |
184 | | - [ |
185 | | - 'empty_string' => '', |
186 | | - ], |
187 | | - identifier: 'order_by_board_order', |
188 | | - ); |
189 | | - Utils::$context['num_boards'] = Db::$db->num_rows($request); |
190 | | - Utils::$context['boards_check_all'] = true; |
191 | | - Utils::$context['categories'] = []; |
192 | | - |
193 | | - while ($row = Db::$db->fetch_assoc($request)) { |
194 | | - // This category hasn't been set up yet.. |
195 | | - if (!isset(Utils::$context['categories'][$row['id_cat']])) { |
196 | | - Utils::$context['categories'][$row['id_cat']] = [ |
197 | | - 'id' => $row['id_cat'], |
198 | | - 'name' => $row['cat_name'], |
199 | | - 'boards' => [], |
200 | | - ]; |
201 | | - } |
202 | | - |
203 | | - $is_recycle_board = !empty(Config::$modSettings['recycle_enable']) && $row['id_board'] == Config::$modSettings['recycle_board']; |
204 | | - |
205 | | - // Set this board up, and let the template know when it's a child. (indent them..) |
206 | | - Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = [ |
207 | | - 'id' => $row['id_board'], |
208 | | - 'name' => $row['name'], |
209 | | - 'child_level' => $row['child_level'], |
210 | | - ]; |
211 | | - |
212 | | - // If user selected some particular boards, is this one of them? |
213 | | - if (!empty(Utils::$context['search_params']['brd'])) { |
214 | | - Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = \in_array($row['id_board'], Utils::$context['search_params']['brd']); |
215 | | - } |
216 | | - // User didn't select any boards, so select all except ignored and recycle boards. |
217 | | - else { |
218 | | - Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] = !$is_recycle_board && !\in_array($row['id_board'], User::$me->ignoreboards); |
219 | | - } |
220 | | - |
221 | | - // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
222 | | - if (!Utils::$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && !$is_recycle_board) { |
223 | | - Utils::$context['boards_check_all'] = false; |
224 | | - } |
225 | | - } |
226 | | - Db::$db->free_result($request); |
227 | | - |
228 | | - Category::sort(Utils::$context['categories']); |
229 | | - |
230 | | - // Now, let's sort the list of categories into the boards for templates that like that. |
231 | | - $temp_boards = []; |
232 | | - |
233 | | - foreach (Utils::$context['categories'] as $category) { |
234 | | - $temp_boards[] = [ |
235 | | - 'name' => $category['name'], |
236 | | - 'child_ids' => array_keys($category['boards']), |
237 | | - ]; |
238 | | - $temp_boards = array_merge($temp_boards, array_values($category['boards'])); |
239 | | - |
240 | | - // Include a list of boards per category for easy toggling. |
241 | | - Utils::$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']); |
| 178 | + // If user selected some particular boards, is this one of them? |
| 179 | + if (!empty(Utils::$context['search_params']['brd'])) { |
| 180 | + $boards = Utils::$context['search_params']['brd']; |
242 | 181 | } |
243 | | - |
244 | | - $max_boards = ceil(\count($temp_boards) / 2); |
245 | | - |
246 | | - if ($max_boards == 1) { |
247 | | - $max_boards = 2; |
| 182 | + // User didn't select any boards, so select all except ignored and recycle boards. |
| 183 | + elseif (!empty(Config::$modSettings['recycle_enable']) && !empty(Config::$modSettings['recycle_board'])) { |
| 184 | + $boards = array_merge(User::$me->ignoreboards, [(int) Config::$modSettings['recycle_board']]); |
| 185 | + } else { |
| 186 | + $boards = User::$me->ignoreboards; |
248 | 187 | } |
249 | 188 |
|
250 | | - // Now, alternate them so they can be shown left and right ;). |
251 | | - Utils::$context['board_columns'] = []; |
252 | | - |
253 | | - for ($i = 0; $i < $max_boards; $i++) { |
254 | | - Utils::$context['board_columns'][] = $temp_boards[$i]; |
255 | | - |
256 | | - if (isset($temp_boards[$i + $max_boards])) { |
257 | | - Utils::$context['board_columns'][] = $temp_boards[$i + $max_boards]; |
258 | | - } else { |
259 | | - Utils::$context['board_columns'][] = []; |
260 | | - } |
261 | | - } |
| 189 | + Utils::$context['categories'] = Board::getUserVisibleBoards($boards); |
262 | 190 |
|
263 | 191 | if (!empty($_REQUEST['topic'])) { |
264 | 192 | Utils::$context['search_params']['topic'] = (int) $_REQUEST['topic']; |
|
0 commit comments