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')); |
|
|
|
|
46
|
|
|
} else { |
47
|
|
|
$module = $xoopsModule; |
48
|
|
|
$config = $xoopsModuleConfig; |
49
|
|
|
} |
50
|
|
|
if ('global' === $category) { |
51
|
|
|
$item['name'] = ''; |
|
|
|
|
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']; |
|
|
|
|
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'] . '&lid=' . $item_id; |
76
|
|
|
return $item; |
77
|
|
|
} |
78
|
|
|
return null; |
79
|
|
|
} |
80
|
|
|
|