b_marquee_wfsection()   B
last analyzed

Complexity

Conditions 7
Paths 3

Size

Total Lines 42
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 30
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 42
rs 8.5066
1
<?php declare(strict_types=1);
2
/**
3
 * ****************************************************************************
4
 * Marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright         Hervé Thouzard (https://www.herve-thouzard.com)
15
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author            Hervé Thouzard (https://www.herve-thouzard.com)
17
 *
18
 * Version :
19
 * ****************************************************************************
20
 *
21
 * @param $limit
22
 * @param $dateFormat
23
 * @param $itemsSize
24
 *
25
 * @return array
26
 */
27
28
// Script to list recent articles from wfsection 1 & 2
29
function b_marquee_wfsection($limit, $dateFormat, $itemsSize)
30
{
31
    //    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
32
    $block = [];
33
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
34
    /** @var \XoopsModuleHandler $moduleHandler */
35
    $moduleHandler    = xoops_getHandler('module');
36
    $wfsection        = $moduleHandler->getByDirname('wfsection');
37
    $wfsectionVersion = (int)$wfsection->getInfo('version');
38
    if ($wfsectionVersion >= 2) {
39
    } else { // wfsection 1
40
        require_once XOOPS_ROOT_PATH . '/modules/wfsection/include/groupaccess.php';
41
        global $xoopsDB;
42
        $sql    = 'SELECT articleid, title, published, expired, counter, groupid, uid FROM ' . $xoopsDB->prefix('wfs_article') . ' WHERE published < ' . time() . ' AND published > 0 AND (expired = 0 OR expired > ' . time() . ') AND noshowart = 0 AND offline = 0 ORDER BY published DESC';
43
        $result = $xoopsDB->query($sql, $limit, 0);
44
        if (!$xoopsDB->isResultSet($result)) {
45
            throw new \RuntimeException(
46
                \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR);
47
        }
48
        while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
49
            if (checkAccess($myrow['groupid'])) {
0 ignored issues
show
Bug introduced by
The function checkAccess was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            if (/** @scrutinizer ignore-call */ checkAccess($myrow['groupid'])) {
Loading history...
50
                $wfs   = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $wfs is dead and can be removed.
Loading history...
51
                $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
52
                if (!XOOPS_USE_MULTIBYTES) {
53
                    if ($itemsSize > 0) {
54
                        $title = htmlspecialchars(mb_substr($myrow['title'], 0, $itemsSize), ENT_QUOTES | ENT_HTML5);
55
                    } else {
56
                        $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
57
                    }
58
                }
59
                $block[] = [
60
                    'date'     => formatTimestamp($myrow['published'], $dateFormat),
61
                    'category' => '',
62
                    'author'   => \XoopsUser::getUnameFromId($myrow['uid']),
63
                    'title'    => $title,
64
                    'link'     => "<a href='" . XOOPS_URL . '/modules/wfsection/article.php?articleid=' . $myrow['articleid'] . "'>" . $title . '</a>',
65
                ];
66
            }
67
        }
68
    } // wfsection 1 ou 2 ?
69
70
    return $block;
71
}
72