b_marquee_mylinks()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 20
c 0
b 0
f 0
nc 4
nop 3
dl 0
loc 28
rs 9.6
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
 *
19
 * @param $limit
20
 * @param $dateFormat
21
 * @param $itemsSize
22
 *
23
 * @return array
24
 */
25
26
// Script to list the recent links from the mylinks module version 1.10
27
function b_marquee_mylinks($limit, $dateFormat, $itemsSize)
28
{
29
    //    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
30
    require XOOPS_ROOT_PATH . '/include/comment_constants.php';
31
    $block  = [];
32
    $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
33
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
34
    $sql = 'SELECT m.lid, m.cid, m.title, m.date, m.hits, m.submitter, c.title AS catitle FROM ' . $db->prefix('mylinks_links') . ' m, ' . $db->prefix('mylinks_cat') . ' c WHERE (c.cid=m.cid) AND (m.status>0) ORDER BY date DESC';
35
    $result = $db->query($sql, $limit, 0);
36
    if (!$db->isResultSet($result)) {
37
        throw new \RuntimeException(
38
            \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR);
39
    }
40
    while (false !== ($myrow = $db->fetchArray($result))) {
41
        $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
42
        if ($itemsSize > 0) {
43
            $title = xoops_substr($title, 0, $itemsSize + 3);
44
        }
45
        $block[] = [
46
            'date'     => formatTimestamp($myrow['date'], $dateFormat),
47
            'category' => htmlspecialchars($myrow['catitle'], ENT_QUOTES | ENT_HTML5),
48
            'author'   => $myrow['submitter'],
49
            'title'    => $title,
50
            'link'     => "<a href='" . XOOPS_URL . '/modules/mylinks/singlelink.php?cid=' . $myrow['cid'] . '&amp;lid=' . $myrow['lid'] . "'>" . $title . '</a>',
51
        ];
52
    }
53
54
    return $block;
55
}
56