| Conditions | 39 |
| Paths | > 20000 |
| Total Lines | 273 |
| Code Lines | 112 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 208 | function template_results() |
||
| 209 | { |
||
| 210 | global $context, $options, $txt, $scripturl, $message; |
||
| 211 | |||
| 212 | // Let them know if we ignored a word in the search |
||
| 213 | if (!empty($context['search_ignored'])) |
||
| 214 | { |
||
| 215 | echo ' |
||
| 216 | <div id="search_results"> |
||
| 217 | <h2 class="category_header"> |
||
| 218 | ', $txt['generic_warning'], ' |
||
| 219 | </h2> |
||
| 220 | <p class="warningbox">', $txt['search_warning_ignored_word' . (count($context['search_ignored']) === 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '</p> |
||
| 221 | </div>'; |
||
| 222 | } |
||
| 223 | |||
| 224 | // Or perhaps they made a spelling error, lets give them a hint |
||
| 225 | if (!empty($context['did_you_mean']) || empty($context['topics'])) |
||
| 226 | { |
||
| 227 | echo ' |
||
| 228 | <div id="search_results"> |
||
| 229 | <h2 class="category_header">', $txt['search_adjust_query'], '</h2> |
||
| 230 | <div class="well">'; |
||
| 231 | |||
| 232 | // Did they make any typos or mistakes, perhaps? |
||
| 233 | if (isset($context['did_you_mean'])) |
||
| 234 | { |
||
| 235 | echo ' |
||
| 236 | <p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search;sa=results;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>'; |
||
| 237 | } |
||
| 238 | |||
| 239 | echo ' |
||
| 240 | <form action="', $scripturl, '?action=search;sa=results" method="post" accept-charset="UTF-8"> |
||
| 241 | <dl class="settings"> |
||
| 242 | <dt class="righttext"> |
||
| 243 | <label for="search"><strong>', $txt['search_for'], ':</strong></label> |
||
| 244 | </dt> |
||
| 245 | <dd> |
||
| 246 | <input type="text" id="search" name="search" value="', $context['search_params']['search'], '" maxlength="', $context['search_string_limit'], '" size="40" class="input_text" /> |
||
| 247 | </dd> |
||
| 248 | </dl> |
||
| 249 | <div class="submitbutton" > |
||
| 250 | <input type="submit" name="edit_search" value="', $txt['search_adjust_submit'], '" /> |
||
| 251 | <input type="hidden" name="searchtype" value="', $context['search_params']['searchtype'], '" /> |
||
| 252 | <input type="hidden" name="userspec" value="', $context['search_params']['userspec'], '" /> |
||
| 253 | <input type="hidden" name="show_complete" value="', $context['search_params']['show_complete'], '" /> |
||
| 254 | <input type="hidden" name="subject_only" value="', $context['search_params']['subject_only'], '" /> |
||
| 255 | <input type="hidden" name="minage" value="', $context['search_params']['minage'], '" /> |
||
| 256 | <input type="hidden" name="maxage" value="', $context['search_params']['maxage'], '" /> |
||
| 257 | <input type="hidden" name="sort" value="', $context['search_params']['sort'], '" />'; |
||
| 258 | |||
| 259 | if (!empty($context['search_params']['brd'])) |
||
| 260 | { |
||
| 261 | foreach ($context['search_params']['brd'] as $board_id) |
||
| 262 | { |
||
| 263 | echo ' |
||
| 264 | <input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '" />'; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | echo ' |
||
| 269 | </div> |
||
| 270 | </form> |
||
| 271 | </div> |
||
| 272 | </div> |
||
| 273 | <br />'; |
||
| 274 | } |
||
| 275 | |||
| 276 | // Quick moderation set to checkboxes? Oh, how fun :/. |
||
| 277 | if (!empty($options['display_quick_mod'])) |
||
| 278 | { |
||
| 279 | echo ' |
||
| 280 | <form id="quickModForm" class="search_results_posts', $context['compact'] ? ' compact_view' : '', '" action="', $scripturl, '?action=quickmod" method="post" accept-charset="UTF-8" name="quickModForm">'; |
||
| 281 | } |
||
| 282 | |||
| 283 | echo ' |
||
| 284 | <h2 class="category_header hdicon i-search">', |
||
| 285 | $txt['mlist_search_results'], ': ', $context['search_params']['search'], ' |
||
| 286 | <span class="flow_flex_right">'; |
||
| 287 | |||
| 288 | if (!empty($options['display_quick_mod'])) |
||
| 289 | { |
||
| 290 | echo ' |
||
| 291 | <input id="select_all" type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" />'; |
||
| 292 | } |
||
| 293 | |||
| 294 | echo ' |
||
| 295 | </span> |
||
| 296 | </h2>'; |
||
| 297 | |||
| 298 | // Was anything even found? |
||
| 299 | if (!empty($context['topics'])) |
||
| 300 | { |
||
| 301 | template_pagesection(); |
||
| 302 | } |
||
| 303 | else |
||
| 304 | { |
||
| 305 | echo ' |
||
| 306 | <div class="well">', $txt['find_no_results'], '</div>'; |
||
| 307 | } |
||
| 308 | |||
| 309 | if ($context['compact']) |
||
| 310 | { |
||
| 311 | echo ' |
||
| 312 | <ul class="compact_view search_results_posts">'; |
||
| 313 | } |
||
| 314 | else |
||
| 315 | { |
||
| 316 | echo ' |
||
| 317 | <ul class="forumposts search_results_posts">'; |
||
| 318 | } |
||
| 319 | |||
| 320 | // Quick mod counters |
||
| 321 | $context['allow_qm'] = []; |
||
| 322 | |||
| 323 | // While we have results to show ... |
||
| 324 | $controller = $context['get_topics'][0]; |
||
| 325 | while (($topic = $controller->{$context['get_topics'][1]}())) |
||
| 326 | { |
||
| 327 | $context['allow_qm']['can_remove'][] = isset($topic['quick_mod']['remove']) ? $topic['id'] : null; |
||
| 328 | $context['allow_qm']['can_move'][] = isset($topic['quick_mod']['move']) ? $topic['id'] : null; |
||
| 329 | $context['allow_qm']['can_lock'][] = isset($topic['quick_mod']['lock']) ? $topic['id'] : null; |
||
| 330 | $context['allow_qm']['can_sticky'][] = isset($topic['quick_mod']['sticky']) ? $topic['id'] : null; |
||
| 331 | |||
| 332 | if ($context['compact']) |
||
| 333 | { |
||
| 334 | // We start with locked and sticky topics. |
||
| 335 | if ($topic['is_sticky'] && $topic['is_locked']) |
||
| 336 | { |
||
| 337 | $color_class = 'locked_row sticky_row'; |
||
| 338 | } |
||
| 339 | // Sticky topics should get a different color, too. |
||
| 340 | elseif ($topic['is_sticky']) |
||
| 341 | { |
||
| 342 | $color_class = 'sticky_row'; |
||
| 343 | } |
||
| 344 | // Locked topics get special treatment as well. |
||
| 345 | elseif ($topic['is_locked']) |
||
| 346 | { |
||
| 347 | $color_class = 'locked_row'; |
||
| 348 | } |
||
| 349 | // Last, but not least: regular topics. |
||
| 350 | else |
||
| 351 | { |
||
| 352 | $color_class = 'basic_row'; |
||
| 353 | } |
||
| 354 | } |
||
| 355 | else |
||
| 356 | { |
||
| 357 | $color_class = 'basic_row'; |
||
| 358 | } |
||
| 359 | |||
| 360 | foreach ($topic['matches'] as $message) |
||
| 361 | { |
||
| 362 | echo ' |
||
| 363 | <li class="', $color_class, '"> |
||
| 364 | <div class="topic_details"> |
||
| 365 | <div class="counter">', $message['counter'] + 1, '</div> |
||
| 366 | <h5>', $topic['board']['link'], ' / <a href="', getUrl('topic', ['topic' => $topic['id'], 'subject' => $topic['subject'], 'start' => 'msg' . $message['id']]), '#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5> |
||
| 367 | <span class="smalltext">', $txt['by'], ' <strong>', $message['member']['link'], '</strong> ', $txt['on'], ' <em>', $message['time'], '</em></span> |
||
| 368 | </div>'; |
||
| 369 | |||
| 370 | if (!$context['compact'] || $message['body_highlighted'] !== '') |
||
| 371 | { |
||
| 372 | echo ' |
||
| 373 | <div class="topic_body">', $message['body_highlighted'], '</div>'; |
||
| 374 | } |
||
| 375 | |||
| 376 | // Quote, Reply, etc ... only when not viewing compact |
||
| 377 | if (!empty($topic['buttons'])) |
||
| 378 | { |
||
| 379 | template_button_strip($topic['buttons'], 'quickbuttons no_js', ['no-class' => true]); |
||
| 380 | } |
||
| 381 | |||
| 382 | // Show QM checkbox, by the count indicator, only if compact view is on |
||
| 383 | if (!empty($options['display_quick_mod']) && $context['compact']) |
||
| 384 | { |
||
| 385 | echo ' |
||
| 386 | <p class="topic_moderation"> |
||
| 387 | <input type="checkbox" class="inline_mod_check" name="topics[]" value="', $topic['id'], '" /> |
||
| 388 | </p>'; |
||
| 389 | } |
||
| 390 | |||
| 391 | echo ' |
||
| 392 | </li>'; |
||
| 393 | } |
||
| 394 | } |
||
| 395 | |||
| 396 | echo ' |
||
| 397 | </ul>'; |
||
| 398 | |||
| 399 | // Quick moderation enabled, then show an action area |
||
| 400 | if (!empty($context['topics']) && !empty($options['display_quick_mod'])) |
||
| 401 | { |
||
| 402 | echo ' |
||
| 403 | <div id="moderationbuttons">'; |
||
| 404 | |||
| 405 | template_button_strip($context['mod_buttons'], '', ['id' => 'moderationbuttons_strip']); |
||
| 406 | |||
| 407 | // Show a list of boards they can move the topic to. |
||
| 408 | if ($context['can_move']) |
||
| 409 | { |
||
| 410 | echo ' |
||
| 411 | <span id="quick_mod_jump_to"> </span>'; |
||
| 412 | } |
||
| 413 | |||
| 414 | echo ' |
||
| 415 | <input type="hidden" name="qaction" id="qaction" value="na" /> |
||
| 416 | <input type="hidden" name="redirect_url" value="', $scripturl . '?action=search;sa=results;params=' . $context['params'], '" /> |
||
| 417 | <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" /> |
||
| 418 | </div> |
||
| 419 | </form>'; |
||
| 420 | |||
| 421 | // Show the move to box? |
||
| 422 | if ($context['can_move']) |
||
| 423 | { |
||
| 424 | theme()->addInlineJavascript(' |
||
| 425 | aJumpTo[aJumpTo.length] = new JumpTo({ |
||
| 426 | sContainerId: "quick_mod_jump_to", |
||
| 427 | sClassName: "qaction", |
||
| 428 | sJumpToTemplate: "%dropdown_list%", |
||
| 429 | sCurBoardName: "' . $context['jump_to']['board_name'] . '", |
||
| 430 | sBoardChildLevelIndicator: " ", |
||
| 431 | sBoardPrefix: "➤ ", |
||
| 432 | sCatClass: "jump_to_header", |
||
| 433 | sCatPrefix: "", |
||
| 434 | bNoRedirect: true, |
||
| 435 | bDisabled: false, |
||
| 436 | sCustomName: "move_to" |
||
| 437 | });', true); |
||
| 438 | } |
||
| 439 | |||
| 440 | theme()->addInlineJavascript(' |
||
| 441 | let oInTopicListModeration = new InTopicListModeration({ |
||
| 442 | aQmActions: ["remove", "lock", "sticky", "move", "markread"], |
||
| 443 | sButtonStrip: "moderationbuttons", |
||
| 444 | sButtonStripDisplay: "moderationbuttons_strip", |
||
| 445 | bUseImageButton: false, |
||
| 446 | sFormId: "quickModForm", |
||
| 447 | |||
| 448 | bCanRemove: ' . (empty($context['can_remove']) ? 'false' : 'true') . ', |
||
| 449 | aActionRemove: [' . implode(',', array_filter(array_unique($context['allow_qm']['can_remove']))) . '], |
||
| 450 | sRemoveButtonLabel: "' . $txt['remove_topic'] . '", |
||
| 451 | sRemoveButtonImage: "i-delete", |
||
| 452 | sRemoveButtonConfirm: "' . $txt['quickmod_confirm'] . '", |
||
| 453 | |||
| 454 | bCanMove: ' . (empty($context['can_move']) ? 'false' : 'true') . ', |
||
| 455 | aActionMove: [' . implode(',', array_filter(array_unique($context['allow_qm']['can_move']))) . '], |
||
| 456 | sMoveButtonLabel: "' . $txt['move_topic'] . '", |
||
| 457 | sMoveButtonImage: "i-move", |
||
| 458 | sMoveButtonConfirm: "' . $txt['quickmod_confirm'] . '", |
||
| 459 | |||
| 460 | bCanLock: ' . ($context['can_lock'] ? 'true' : 'false') . ', |
||
| 461 | aActionLock: [' . implode(',', array_filter(array_unique($context['allow_qm']['can_lock']))) . '], |
||
| 462 | sLockButtonLabel: "' . $txt['set_lock'] . '", |
||
| 463 | sLockButtonImage: "i-lock", |
||
| 464 | |||
| 465 | bCanSticky: ' . ($context['can_sticky'] ? 'true' : 'false') . ', |
||
| 466 | aActionSticky: [' . implode(',', array_filter(array_unique($context['allow_qm']['can_sticky']))) . '], |
||
| 467 | sStickyButtonLabel: "' . $txt['set_sticky'] . '", |
||
| 468 | sStickyButtonImage: "i-pin", |
||
| 469 | |||
| 470 | bCanMarkread: ' . ($context['can_markread'] ? 'true' : 'false') . ', |
||
| 471 | sMarkreadButtonLabel: "' . $txt['mark_read_short'] . '", |
||
| 472 | sMarkreadButtonImage: "i-view", |
||
| 473 | sMarkreadButtonConfirm: "' . $txt['mark_these_as_read_confirm'] . '", |
||
| 474 | });', true); |
||
| 475 | } |
||
| 476 | |||
| 477 | // If we have results show a page index |
||
| 478 | if (!empty($context['topics'])) |
||
| 479 | { |
||
| 480 | template_pagesection(); |
||
| 481 | } |
||
| 483 |