b_marquee_mydownloads()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 39
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 30
c 0
b 0
f 0
nc 6
nop 3
dl 0
loc 39
rs 9.1288
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 mydownloads module version 1.10
27
function b_marquee_mydownloads($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, u.name, u.uname FROM '
35
        . $db->prefix('mydownloads_downloads')
36
        . ' m, '
37
        . $db->prefix('mydownloads_cat')
38
        . '  c, '
39
        . $db->prefix('users')
40
        . ' u  WHERE (c.cid=m.cid) AND (m.submitter=u.uid) AND (m.status>0) ORDER BY m.date DESC';
41
    $result = $db->query($sql, $limit, 0);
42
    if (!$db->isResultSet($result)) {
43
        throw new \RuntimeException(
44
            \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR);
45
    }
46
    while (false !== ($myrow = $db->fetchArray($result))) {
47
        $title = htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
48
        if ($itemsSize > 0) {
49
            $title = xoops_substr($title, 0, $itemsSize + 3);
50
        }
51
        $author = htmlspecialchars($myrow['uname'], ENT_QUOTES | ENT_HTML5);
52
        if ('' !== xoops_trim($myrow['catitle'])) {
53
            $author = htmlspecialchars($myrow['name'], ENT_QUOTES | ENT_HTML5);
54
        }
55
        $category = htmlspecialchars($myrow['catitle'], ENT_QUOTES | ENT_HTML5);
56
        $block[]  = [
57
            'date'     => formatTimestamp($myrow['date'], $dateFormat),
58
            'category' => $category,
59
            'author'   => $author,
60
            'title'    => $title,
61
            'link'     => "<a href='" . XOOPS_URL . '/modules/mydownloads/singlefile.php?cid=' . $myrow['cid'] . '&amp;lid=' . $myrow['lid'] . "'>" . $title . '</a>',
62
        ];
63
    }
64
65
    return $block;
66
}
67