adslight_edit()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 24
rs 9.7333
cc 3
nc 4
nop 1
1
<?php declare(strict_types=1);
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project (https://xoops.org)
14
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team
16
 * @author       Pascal Le Boustouller: original author ([email protected])
17
 * @author       Luc Bizet (www.frxoops.org)
18
 * @author       jlm69 (www.jlmzone.com)
19
 * @author       mamba (www.xoops.org)
20
 */
21
22
use XoopsModules\Adslight\Helper;
23
use XoopsModules\Adslight\Utility;
24
25
/** @var Helper $helper */
26
27
/**
28
 * @param $options
29
 *
30
 * @return array|false
31
 */
32
function adslight_show($options)
33
{
34
    if (!class_exists(Helper::class)) {
35
        return [];
36
    }
37
38
    $helper = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
39
40
    global $xoopsDB, $block_lang;
41
    $block = [];
42
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
43
44
    $moduleDirName = \basename(\dirname(__DIR__));
45
    $block_lang    = '_MB_' . mb_strtoupper($moduleDirName);
46
47
    $block['title'] = constant("{$block_lang}_TITLE");
48
49
    $sql    = 'SELECT lid, cid, title, type, date_created, hits FROM ' . $xoopsDB->prefix("{$moduleDirName}_listing") . " WHERE valid='Yes' ORDER BY {$options[0]} DESC";
50
    $result = $xoopsDB->query($sql, $options[1], 0);
51
    if (!$xoopsDB->isResultSet($result)) {
52
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
53
    }
54
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
55
        $a_item = [];
56
        $title  = \htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
57
        $type   = \htmlspecialchars($myrow['type'], ENT_QUOTES | ENT_HTML5);
58
59
        if (!XOOPS_USE_MULTIBYTES && mb_strlen($myrow['title']) >= $options[2]) {
60
            $title = \htmlspecialchars(mb_substr($myrow['title'], 0, $options[2] - 1), ENT_QUOTES | ENT_HTML5) . '...';
61
        }
62
63
        $a_item['type'] = Utility::getNameType($type);
64
        $a_item['id']   = $myrow['lid'];
65
        $a_item['cid']  = $myrow['cid'];
66
67
        $a_item['link'] = '<a href="' . XOOPS_URL . "/modules/{$moduleDirName}/viewads.php?lid=" . addslashes($myrow['lid']) . "\"><b>{$title}</b></a>";
68
69
        if ('date_created' === $options[0]) {
70
            $a_item['date_created'] = formatTimestamp($myrow['date_created'], 's');
71
        } elseif ('hits' === $options[0]) {
72
            $a_item['hits'] = $myrow['hits'];
73
        }
74
75
        $block['items'][] = $a_item;
76
    }
77
78
    $block['link'] = '<a href="' . XOOPS_URL . "/modules/{$moduleDirName}/\"><b>" . constant("{$block_lang}_ALL_LISTINGS") . '</b></a><br>';
79
    $block['add']  = '<a href="' . XOOPS_URL . "/modules/{$moduleDirName}/\"><b>" . constant("{$block_lang}_ADDNOW") . '</b></a><br>';
80
81
    return $block;
82
}
83
84
/**
85
 * @param $options
86
 * @return string
87
 */
88
function adslight_edit($options): string
89
{
90
    global $xoopsDB;
91
    $moduleDirName = \basename(\dirname(__DIR__));
92
    $block_lang    = '_MB_' . mb_strtoupper($moduleDirName);
93
94
    $form = constant("{$block_lang}_ORDER") . "&nbsp;<select name='options[]'>";
95
    $form .= "<option value='date_created'";
96
    if ('date_created' === $options[0]) {
97
        $form .= " selected='selected'";
98
    }
99
    $form .= '>' . constant("{$block_lang}_DATE") . "</option>\n";
100
101
    $form .= "<option value='hits'";
102
    if ('hits' === $options[0]) {
103
        $form .= " selected='selected'";
104
    }
105
    $form .= '>' . constant($block_lang . '_HITS') . '</option>';
106
    $form .= "</select>\n";
107
108
    $form .= '&nbsp;' . constant($block_lang . '_DISP') . "&nbsp;<input type='text' name='options[]' value='{$options[1]}'>&nbsp;" . constant("{$block_lang}_LISTINGS");
109
    $form .= '&nbsp;<br><br>' . constant("{$block_lang}_CHARS") . "&nbsp;<input type='text' name='options[]' value='{$options[2]}'>&nbsp;" . constant("{$block_lang}_LENGTH") . '<br><br>';
110
111
    return $form;
112
}
113