b_marquee_xoopsfaq()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
c 0
b 0
f 0
nc 4
nop 3
dl 0
loc 27
rs 9.6333
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_xoopsfaq($limit, $dateFormat, $itemsSize)
28
{
29
    //    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
30
    $block  = [];
31
    $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
32
    $db     = \XoopsDatabaseFactory::getDatabaseConnection();
33
    $sql = 'SELECT c.*, t.category_title FROM ' . $db->prefix('xoopsfaq_contents') . ' c, ' . $db->prefix('xoopsfaq_categories') . ' t WHERE c.contents_visible>0 AND (c. category_id=t.category_id) ORDER BY contents_time DESC';
34
    $result = $db->query($sql, $limit, 0);
35
    if (!$db->isResultSet($result)) {
36
        throw new \RuntimeException(
37
            \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR);
38
    }
39
    while (false !== ($myrow = $db->fetchArray($result))) {
40
        $title = htmlspecialchars($myrow['contents_title'], ENT_QUOTES | ENT_HTML5);
41
        if ($itemsSize > 0) {
42
            $title = xoops_substr($title, 0, $itemsSize + 3);
43
        }
44
        $block[] = [
45
            'date'     => formatTimestamp($myrow['contents_time'], $dateFormat),
46
            'category' => htmlspecialchars($myrow['category_title'], ENT_QUOTES | ENT_HTML5),
47
            'author'   => 0,
48
            'title'    => $title,
49
            'link'     => "<a href='" . XOOPS_URL . '/modules/xoopsfaq/index.php?cat_id=' . $myrow['category_id'] . '#q' . $myrow['contents_id'] . "'>" . $title . '</a>',
50
        ];
51
    }
52
53
    return $block;
54
}
55