b_marquee_xfsection()   B
last analyzed

Complexity

Conditions 7
Paths 12

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 26
c 0
b 0
f 0
nc 12
nop 3
dl 0
loc 36
rs 8.5706
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 the xfsection module (tested with xfsection 1.12)
29
function b_marquee_xfsection($limit, $dateFormat, $itemsSize)
30
{
31
    $block = [];
32
    global $xoopsDB;
33
    if (!function_exists('xfblock_checkAccess')) {
34
        require_once XOOPS_ROOT_PATH . '/modules/xfsection/include/xfblock_groupaccess.php';
35
    }
36
    $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
37
    $sql    = 'SELECT articleid, title, published, expired, counter, groupid, uid FROM ' . $xoopsDB->prefix('xfs_article') . ' WHERE published < ' . time() . ' AND published > 0 AND (expired = 0 OR expired > ' . time() . ') AND noshowart = 0 AND offline = 0 ORDER BY published DESC';
38
    $result = $xoopsDB->query($sql, $limit, 0);
39
    if (!$xoopsDB->isResultSet($result)) {
40
        throw new \RuntimeException(
41
            \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR);
42
    }
43
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
44
        if (xfblock_checkAccess($myrow['groupid'])) {
45
            $wfs   = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $wfs is dead and can be removed.
Loading history...
46
            $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
47
            if (!XOOPS_USE_MULTIBYTES) {
48
                if ($itemsSize > 0) {
49
                    $title = htmlspecialchars(mb_substr($myrow['title'], 0, $itemsSize - 1), ENT_QUOTES | ENT_HTML5);
50
                } else {
51
                    $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
52
                }
53
            }
54
            $block[] = [
55
                'date'     => formatTimestamp($myrow['published'], $dateFormat),
56
                'category' => '',
57
                'author'   => \XoopsUser::getUnameFromId($myrow['uid']),
58
                'title'    => $title,
59
                'link'     => "<a href='" . XOOPS_URL . '/modules/xfsection/article.php?articleid=' . $myrow['articleid'] . "'>" . $title . '</a>',
60
            ];
61
        }
62
    }
63
64
    return $block;
65
}
66