| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 246 |
| Code Lines | 161 |
| 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 |
||
| 322 | public static function showArticles($showCreate = 0) |
||
| 323 | { |
||
| 324 | global $xoopsModule; |
||
| 325 | $myts = \MyTextSanitizer::getInstance(); |
||
| 326 | /** @var Soapbox\Helper $helper */ |
||
| 327 | $helper = Soapbox\Helper::getInstance(); |
||
| 328 | |||
| 329 | $pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16); |
||
| 330 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
| 331 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 332 | require_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php'; |
||
| 333 | // require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/cleantags.php'; |
||
| 334 | |||
| 335 | $module_id = $xoopsModule->getVar('mid'); |
||
| 336 | $startart = \Xmf\Request::getInt('startart', 0, 'GET'); |
||
| 337 | if (\Xmf\Request::hasVar('entries', 'POST')) { |
||
| 338 | $entries = \Xmf\Request::getInt('entries', 0, 'POST'); |
||
| 339 | } else { |
||
| 340 | $entries = \Xmf\Request::getInt('entries', 0, 'GET'); |
||
| 341 | } |
||
| 342 | //---GET view sort -- |
||
| 343 | $sortname = isset($_GET['sortname']) ? mb_strtolower(trim(strip_tags($myts->stripSlashesGPC($_GET['sortname'])))) : 'datesub'; |
||
| 344 | if (!in_array($sortname, ['datesub', 'weight', 'counter', 'rating', 'headline'], true)) { |
||
| 345 | $sortname = 'datesub'; |
||
| 346 | } |
||
| 347 | $sortorder = isset($_GET['sortorder']) ? mb_strtoupper(trim(strip_tags($myts->stripSlashesGPC($_GET['sortorder'])))) : 'DESC'; |
||
| 348 | if (!in_array($sortorder, ['ASC', 'DESC'], true)) { |
||
| 349 | $sortorder = 'DESC'; |
||
| 350 | } |
||
| 351 | //--------------- |
||
| 352 | /* Code to show existing articles */ |
||
| 353 | echo "<h3 style='color: #2F5376; margin: 0 0 4px 0;'>" . _AM_SOAPBOX_SHOWARTS . '</h3>'; |
||
| 354 | echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SOAPBOX_ARTSTEXT . '</span>'; |
||
| 355 | |||
| 356 | // if ($showCreate == 1) { |
||
| 357 | // echo |
||
| 358 | // "<a style='border: 1px solid #5E5D63; color: #000000; font-family: verdana, tahoma, arial, helvetica, sans-serif; font-size: 1em; padding: 4px 8px; text-align:center;' href='article.php'>" |
||
| 359 | // . _AM_SOAPBOX_CREATEART . "</a><br><br>"; |
||
| 360 | // } |
||
| 361 | // Articles count |
||
| 362 | /** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */ |
||
| 363 | $entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler(); |
||
| 364 | //---------------------------- |
||
| 365 | $criteria = new \CriteriaCompo(); |
||
| 366 | $criteria->add(new \Criteria('submit', 0)); |
||
| 367 | $criteria->add(new \Criteria('offline', 0)); |
||
| 368 | $tot_published = $entrydataHandler->getArticleCount($criteria); |
||
| 369 | unset($criteria); |
||
| 370 | //---------------------------- |
||
| 371 | $criteria = new \CriteriaCompo(); |
||
| 372 | $criteria->add(new \Criteria('submit', 0)); |
||
| 373 | $criteria->add(new \Criteria('offline', 1)); |
||
| 374 | $tot_offline = $entrydataHandler->getArticleCount($criteria); |
||
| 375 | unset($criteria); |
||
| 376 | //---------------------------- |
||
| 377 | $criteria = new \CriteriaCompo(); |
||
| 378 | $criteria->add(new \Criteria('submit', 1)); |
||
| 379 | $tot_submitted = $entrydataHandler->getArticleCount($criteria); |
||
| 380 | unset($criteria); |
||
| 381 | //---------------------------- |
||
| 382 | $tot_all = $entrydataHandler->getArticleCount(); |
||
| 383 | //---------------------------- |
||
| 384 | $criteria = new \CriteriaCompo(); |
||
| 385 | $criteria->add(new \Criteria('submit', 0)); |
||
| 386 | $tot_ok = $entrydataHandler->getArticleCount($criteria); |
||
| 387 | unset($criteria); |
||
| 388 | //---------------------------- |
||
| 389 | |||
| 390 | // Prepare string for table head |
||
| 391 | if (0 === $entries) { |
||
| 392 | $string = _AM_SOAPBOX_SHWALL; |
||
| 393 | } |
||
| 394 | if (1 === $entries) { |
||
| 395 | $string = _AM_SOAPBOX_SHWONL; |
||
| 396 | } |
||
| 397 | if (2 === $entries) { |
||
| 398 | $string = _AM_SOAPBOX_SHWOFF; |
||
| 399 | } |
||
| 400 | if (3 === $entries) { |
||
| 401 | $string = _AM_SOAPBOX_SHWSUB; |
||
| 402 | } |
||
| 403 | if (4 === $entries) { |
||
| 404 | $string = _AM_SOAPBOX_SHWAPV; |
||
| 405 | } |
||
| 406 | |||
| 407 | /* Code to show selected articles */ |
||
| 408 | echo "<form name='pick' id='pick' action='" . $myts->htmlSpecialChars(xoops_getenv('PHP_SELF')) . "' method='POST' style='margin: 0;'>"; ?> |
||
| 409 | <table width='100%' cellspacing='1' cellpadding='2' border='0' |
||
| 410 | style='border-left: 1px solid #c0c0c0; border-top: 1px solid #c0c0c0; border-right: 1px solid #c0c0c0;'> |
||
| 411 | <tr> |
||
| 412 | <td class='odd'><span style='font-weight: bold; font-variant: small-caps;'><?php echo $string ?></span></td> |
||
| 413 | <td class='odd' width='40%' align='right'><?php echo _AM_SOAPBOX_SELECTSTATUS; ?> |
||
| 414 | <select name='entries' onchange='submit()'> |
||
| 415 | <option value='0' |
||
| 416 | <?php |
||
| 417 | if (0 === $entries) { |
||
| 418 | echo 'selected'; |
||
| 419 | } ?>> |
||
| 420 | <?php echo _AM_SOAPBOX_SELALL; ?> |
||
| 421 | [<?php echo $tot_all; ?>] |
||
| 422 | </option> |
||
| 423 | <option value='1' <?php if (1 === $entries) { |
||
| 424 | echo 'selected'; |
||
| 425 | } ?>><?php echo _AM_SOAPBOX_SELONL; ?> |
||
| 426 | [<?php echo $tot_published; ?>] |
||
| 427 | </option> |
||
| 428 | <option value='2' <?php if (2 === $entries) { |
||
| 429 | echo 'selected'; |
||
| 430 | } ?>> |
||
| 431 | <?php echo _AM_SOAPBOX_SELOFF; ?> |
||
| 432 | [<?php echo $tot_offline; ?>] |
||
| 433 | </option> |
||
| 434 | <option value='3' <?php if (3 === $entries) { |
||
| 435 | echo 'selected'; |
||
| 436 | } ?>> |
||
| 437 | <?php echo _AM_SOAPBOX_SELSUB; ?> |
||
| 438 | [<?php echo $tot_submitted; ?>] |
||
| 439 | </option> |
||
| 440 | <option value='4' <?php if (4 === $entries) { |
||
| 441 | echo 'selected'; |
||
| 442 | } ?>><?php echo _AM_SOAPBOX_SELAPV; ?> |
||
| 443 | [<?php echo $tot_ok; ?>] |
||
| 444 | </option> |
||
| 445 | </select> |
||
| 446 | </td> |
||
| 447 | </tr> |
||
| 448 | </table> |
||
| 449 | </form> |
||
| 450 | <?php |
||
| 451 | |||
| 452 | //---------------------------- |
||
| 453 | // Put column names in an array, to avoid a query in the while loop further ahead |
||
| 454 | switch ($entries) { |
||
| 455 | case 1: |
||
| 456 | $submit = 0; |
||
| 457 | $offline = 0; |
||
| 458 | break; |
||
| 459 | case 2: |
||
| 460 | //---------------------------- |
||
| 461 | $submit = 0; |
||
| 462 | $offline = 1; |
||
| 463 | break; |
||
| 464 | case 3: |
||
| 465 | //---------------------------- |
||
| 466 | $submit = 1; |
||
| 467 | $offline = null; |
||
| 468 | break; |
||
| 469 | case 4: |
||
| 470 | //---------------------------- |
||
| 471 | $submit = 0; |
||
| 472 | break; |
||
| 473 | case 0: |
||
| 474 | default: |
||
| 475 | $submit = null; |
||
| 476 | $offline = null; |
||
| 477 | break; |
||
| 478 | } |
||
| 479 | // function getArticlesAllPermcheck( |
||
| 480 | // $limit=0, $start=0, |
||
| 481 | // $checkRight = true, $published = true, $submit = 0, $offline = 0, $block = null , |
||
| 482 | // $sortname = 'datesub', $sortorder = 'DESC', |
||
| 483 | // $select_sbcolumns = null , $NOTarticleIDs = null , |
||
| 484 | // $approve_submit = false , |
||
| 485 | // $id_as_key = false ) |
||
| 486 | //------------------------------------- |
||
| 487 | $entryobArray = $entrydataHandler->getArticlesAllPermcheck((int)$helper->getConfig('perpage'), $startart, false, false, $submit, $offline, null, $sortname, $sortorder, null, null, false, true); |
||
| 488 | // Get number of articles in the selected condition ($cond) |
||
| 489 | $numrows = $entrydataHandler->total_getArticlesAllPermcheck; |
||
| 490 | if ($numrows > 0) { |
||
| 491 | echo '<form action="article.php" method="post" name="reorderarticles\">'; |
||
| 492 | } |
||
| 493 | echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
||
| 494 | echo '<tr>'; |
||
| 495 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_ARTID . '</b></td>'; |
||
| 496 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_WEIGHT . '</b></td>'; |
||
| 497 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_ARTCOLNAME . '</b></td>'; |
||
| 498 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_ARTHEADLINE . '</b></td>'; |
||
| 499 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_ARTCREATED . '</b></td>'; |
||
| 500 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_STATUS . '</b></td>'; |
||
| 501 | echo '<th class="txtcenter"><b>' . _AM_SOAPBOX_ACTION . '</b></td>'; |
||
| 502 | echo '</tr>'; |
||
| 503 | |||
| 504 | if ($numrows > 0) { // That is, if there ARE articles in the said condition |
||
| 505 | // Retrieve rows for those items |
||
| 506 | |||
| 507 | $colarray = []; |
||
| 508 | $cont = 0; |
||
| 509 | |||
| 510 | foreach ($entryobArray as $key => $_entryob) { |
||
| 511 | //get vars |
||
| 512 | ++$cont; |
||
| 513 | //------------------------------------- |
||
| 514 | $articles = $_entryob->toArray(); |
||
| 515 | //-------------------- |
||
| 516 | $colname = !empty($_entryob->_sbcolumns) ? $_entryob->_sbcolumns->getVar('name') : ''; |
||
| 517 | //-------------------- |
||
| 518 | $created = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $helper->getConfig('dateformat'))); |
||
| 519 | $modify = "<a href='article.php?op=mod&articleID=" . $articles['articleID'] . "'><img src='" . $pathIcon16 . "/edit.png' ALT='" . _AM_SOAPBOX_EDITART . "'></a>"; |
||
| 520 | $delete = "<a href='article.php?op=del&articleID=" . $articles['articleID'] . "'><img src='" . $pathIcon16 . "/delete.png' ALT='" . _AM_SOAPBOX_DELETEART . "'></a>"; |
||
| 521 | |||
| 522 | //if ($offline == 0) { |
||
| 523 | if (0 === $articles['offline']) { |
||
| 524 | $status = "<img src='" . $pathIcon16 . "/1.png' alt='" . _AM_SOAPBOX_ARTISON . "'>"; |
||
| 525 | } else { |
||
| 526 | //if ($offline == 1 && $submit == 0) { |
||
| 527 | if (0 === $submit && 1 === $articles['offline']) { |
||
| 528 | $status = "<img src='" . $pathIcon16 . "/0.png' alt='" . _AM_SOAPBOX_ARTISOFF . "'>"; |
||
| 529 | } else { |
||
| 530 | if (1 === $submit) { |
||
| 531 | $status = '<img src=' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/sub.gif alt='" . _AM_SOAPBOX_ARTISSUB . "'>"; |
||
| 532 | } |
||
| 533 | } |
||
| 534 | } |
||
| 535 | |||
| 536 | //mb ---------------------------- |
||
| 537 | //echo $cont.' - '.$offline.': '.$status.'</br>'; |
||
| 538 | |||
| 539 | $style = (0 === ($cont % 2)) ? 'even' : 'odd'; |
||
| 540 | echo '<tr class="' . $style . '">'; |
||
| 541 | echo '<td align="center"><a href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?articleID=' . $articles['articleID'] . '" title="' . $articles['headline'] . '" target="_blank">' . $articles['articleID'] . '</a></td>'; |
||
| 542 | echo '<td class="txtcenter"><input type="text" name="articleweight[' . $articles['articleID'] . ']" value="' . $articles['weight'] . '" size="3" maxlength="3" style="text-align: center;"></td>'; |
||
| 543 | echo '<td class="txtcenter">' . $colname . '</td>'; |
||
| 544 | echo '<td>' . $articles['headline'] . '</td>'; |
||
| 545 | echo '<td class="txtcenter">' . $created . '</td>'; |
||
| 546 | echo '<td class="txtcenter">' . $status . '</td>'; |
||
| 547 | echo '<td class="txtcenter">' . $modify . $delete . '</td>'; |
||
| 548 | echo '</tr>'; |
||
| 549 | } |
||
| 550 | } else { // that is, $numrows = 0, there's no columns yet |
||
| 551 | echo '<tr>'; |
||
| 552 | echo "<td class='head' align='center' colspan= '7'>" . _AM_SOAPBOX_NOARTS . '</td>'; |
||
| 553 | echo '</tr>'; |
||
| 554 | } |
||
| 555 | echo "</table>\n"; |
||
| 556 | $pagenav = new \XoopsPageNav($numrows, (int)$helper->getConfig('perpage'), $startart, 'startart', 'entries=' . $entries . '&sortname=' . $sortname . '&sortorder=' . $sortorder); |
||
| 557 | echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
||
| 558 | |||
| 559 | if ($numrows > 0) { |
||
| 560 | echo "<input type='hidden' name='op' value='reorder'>"; |
||
| 561 | //-------------------- |
||
| 562 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 563 | //-------------------- |
||
| 564 | echo '<div style="margin-bottom: 18px;"><input type="submit" name="submit" class="formButton" value="' . _AM_SOAPBOX_REORDERART . '"></div>'; |
||
| 565 | echo '</form>'; |
||
| 566 | } |
||
| 567 | echo "<br>\n"; |
||
| 568 | } |
||
| 683 |