tdmdownloads_notify_iteminfo()   B
last analyzed

Complexity

Conditions 8
Paths 12

Size

Total Lines 45
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 33
nc 12
nop 2
dl 0
loc 45
rs 8.1475
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
//
5
//  ------------------------------------------------------------------------ //
6
//                XOOPS - PHP Content Management System                      //
7
//                  Copyright (c) 2000-2020 XOOPS.org                        //
8
//                       <https://xoops.org>                             //
9
//  ------------------------------------------------------------------------ //
10
//  This program is free software; you can redistribute it and/or modify     //
11
//  it under the terms of the GNU General Public License as published by     //
12
//  the Free Software Foundation; either version 2 of the License, or        //
13
//  (at your option) any later version.                                      //
14
//                                                                           //
15
//  You may not change or alter any portion of this comment or credits       //
16
//  of supporting developers from this source code or any supporting         //
17
//  source code which is considered copyrighted (c) material of the          //
18
//  original comment or credit authors.                                      //
19
//                                                                           //
20
//  This program is distributed in the hope that it will be useful,          //
21
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
22
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
23
//  GNU General Public License for more details.                             //
24
//                                                                           //
25
//  You should have received a copy of the GNU General Public License        //
26
//  along with this program; if not, write to the Free Software              //
27
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
28
//  ------------------------------------------------------------------------ //
29
/**
30
 * @param $category
31
 * @param $item_id
32
 * @return array|null
33
 */
34
function tdmdownloads_notify_iteminfo($category, $item_id)
35
{
36
    global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
37
    $moduleDirName = basename(dirname(__DIR__));
38
    $item_id       = (int)$item_id;
39
    if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== $moduleDirName) {
40
        /** @var \XoopsModuleHandler $moduleHandler */
41
        $moduleHandler = xoops_getHandler('module');
42
        $module        = $moduleHandler->getByDirname($moduleDirName);
43
        /** @var \XoopsConfigHandler $configHandler */
44
        $configHandler = xoops_getHandler('config');
45
        $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
46
    } else {
47
        $module = $xoopsModule;
48
        $config = $xoopsModuleConfig;
49
    }
50
    if ('global' === $category) {
51
        $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...
52
        $item['url']  = '';
53
        return $item;
54
    }
55
    global $xoopsDB;
56
    if ('category' === $category) {
57
        // Assume we have a valid category id
58
        $sql    = 'SELECT title FROM ' . $xoopsDB->prefix('tdmdownloads_cat') . ' WHERE cid = ' . $item_id;
59
        $result = $xoopsDB->query($sql); // TODO: error check
60
        if ($result instanceof \mysqli_result) {
61
            $result_array = $xoopsDB->fetchArray($result);
62
        }
63
        $item['name'] = $result_array['title'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result_array does not seem to be defined for all execution paths leading up to this point.
Loading history...
64
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewcat.php?cid=' . $item_id;
65
        return $item;
66
    }
67
    if ('file' === $category) {
68
        // Assume we have a valid file id
69
        $sql    = 'SELECT cid,title FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE lid = ' . $item_id;
70
        $result = $xoopsDB->query($sql); // TODO: error check
71
        if ($result instanceof \mysqli_result) {
72
            $result_array = $xoopsDB->fetchArray($result);
73
        }
74
        $item['name'] = $result_array['title'];
75
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/singlefile.php?cid=' . $result_array['cid'] . '&amp;lid=' . $item_id;
76
        return $item;
77
    }
78
    return null;
79
}
80