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
|
|
|
* presenter module for xoops |
13
|
|
|
* |
14
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
15
|
|
|
* @license GPL 2.0 or later |
16
|
|
|
* @package presenter |
17
|
|
|
* @since 2.5.5 |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <https://xoops.org> |
19
|
|
|
* @param $category |
20
|
|
|
* @param $item_id |
21
|
|
|
* @return mixed |
22
|
|
|
*/ |
23
|
|
|
// comment callback functions |
24
|
|
|
function presenter_notify_iteminfo($category, $item_id) |
25
|
|
|
{ |
26
|
|
|
global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
27
|
|
|
|
28
|
|
|
if (empty($xoopsModule) || 'presenter' != $xoopsModule->getVar('dirname')) { |
29
|
|
|
/** @var XoopsModuleHandler $moduleHandler */ |
30
|
|
|
$moduleHandler = xoops_getHandler('module'); |
31
|
|
|
$module = $moduleHandler->getByDirname('presenter'); |
32
|
|
|
$configHandler = xoops_getHandler('config'); |
33
|
|
|
$config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
34
|
|
|
} else { |
35
|
|
|
$module =& $xoopsModule; |
36
|
|
|
$config =& $xoopsModuleConfig; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
xoops_loadLanguage('main', 'presenter'); |
40
|
|
|
|
41
|
|
|
if ('global' === $category) { |
42
|
|
|
$item['name'] = ''; |
|
|
|
|
43
|
|
|
$item['url'] = ''; |
44
|
|
|
|
45
|
|
|
return $item; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
global $xoopsDB; |
49
|
|
|
if ('category' === $category) { |
50
|
|
|
// Assume we have a valid category id |
51
|
|
|
$sql = 'SELECT slides_cid FROM ' . $xoopsDB->prefix('presenter_slides') . ' WHERE slides_cid = ' . $item_id; |
52
|
|
|
$result = $xoopsDB->query($sql); // TODO: error check |
53
|
|
|
$result_array = $xoopsDB->fetchArray($result); |
54
|
|
|
$item['name'] = $result_array['slides_cid']; |
|
|
|
|
55
|
|
|
$item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/slides.php?slides_cid=' . $item_id; |
56
|
|
|
|
57
|
|
|
return $item; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ('slides' === $category) { |
61
|
|
|
// Assume we have a valid link id |
62
|
|
|
$sql = 'SELECT slides_cid, slides_cid FROM ' . $xoopsDB->prefix('slides') . ' WHERE slides_id = ' . $item_id; |
63
|
|
|
$result = $xoopsDB->query($sql); // TODO: error check |
64
|
|
|
$result_array = $xoopsDB->fetchArray($result); |
65
|
|
|
$item['name'] = $result_array['title']; |
|
|
|
|
66
|
|
|
$item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/slides.php?slides_cid=' . $result_array['slides_cid'] . '&slides_id=' . $item_id; |
67
|
|
|
|
68
|
|
|
return $item; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return ''; |
72
|
|
|
} |
73
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.