wfdownloads_notify_iteminfo()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 28
nc 8
nop 2
dl 0
loc 44
rs 8.8497
c 0
b 0
f 0
1
<?php
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
 * Wfdownloads module
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package         wfdownload
18
 * @since           3.23
19
 * @author          Xoops Development Team
20
 *
21
 * @param $category
22
 * @param $item_id
23
 * @return null
24
 */
25
function wfdownloads_notify_iteminfo($category, $item_id)
26
{
27
    global $xoopsModule, $xoopsModuleConfig;
28
29
    if (empty($xoopsModule) || 'wfdownloads' !== $xoopsModule->dirname()) {
30
        /** @var \XoopsModuleHandler $moduleHandler */
31
        $moduleHandler = xoops_getHandler('module');
32
        /** @var \XoopsModule $module */
33
        $module = $moduleHandler->getByDirname('wfdownloads');
34
        /** @var \XoopsConfigHandler $configHandler */
35
        $configHandler = xoops_getHandler('config');
36
        $config        = $configHandler->getConfigsByCat(0, (int)$module->mid());
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
37
    } else {
38
        $module = $xoopsModule;
0 ignored issues
show
Unused Code introduced by
The assignment to $module is dead and can be removed.
Loading history...
39
        $config = $xoopsModuleConfig;
40
    }
41
    if ('global' === $category) {
42
        $item['name'] = '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.
Loading history...
43
        $item['url']  = '';
44
45
        return $item;
46
    }
47
    if ('category' === $category) {
48
        // Assume we have a valid category id
49
        $sql          = 'SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_cat') . " WHERE cid = '" . (int)$item_id . "'";
50
        $result       = $GLOBALS['xoopsDB']->query($sql); // TODO: error check
51
        $result_array = $GLOBALS['xoopsDB']->fetchArray($result);
52
        $item['name'] = $result_array['title'];
53
        $item['url']  = WFDOWNLOADS_URL . '/viewcat.php?cid=' . (int)$item_id;
0 ignored issues
show
Bug introduced by
The constant WFDOWNLOADS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
55
        return $item;
56
    }
57
    if ('file' === $category) {
58
        // Assume we have a valid file id
59
        $sql          = 'SELECT cid,title FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads') . " WHERE lid = '" . (int)$item_id . "'";
60
        $result       = $GLOBALS['xoopsDB']->query($sql); // TODO: error check
61
        $result_array = $GLOBALS['xoopsDB']->fetchArray($result);
62
        $item['name'] = $result_array['title'];
63
        $item['url']  = WFDOWNLOADS_URL . '/singlefile.php?cid=' . (int)$result_array['cid'] . '&amp;lid=' . (int)$item_id;
64
65
        return $item;
66
    }
67
68
    return null;
69
}
70