1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* references - MODULE FOR XOOPS |
5
|
|
|
* Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
6
|
|
|
* |
7
|
|
|
* You may not change or alter any portion of this comment or credits |
8
|
|
|
* of supporting developers from this source code or any supporting source code |
9
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
* |
14
|
|
|
* @copyright Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
15
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
16
|
|
|
* @package references |
17
|
|
|
* @author Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
18
|
|
|
* |
19
|
|
|
* **************************************************************************** |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Gestion des notifications |
24
|
|
|
* @param $category |
25
|
|
|
* @param $item_id |
26
|
|
|
* @return mixed |
27
|
|
|
*/ |
28
|
|
|
function references_notify_iteminfo($category, $item_id) |
29
|
|
|
{ |
30
|
|
|
global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
31
|
|
|
$item_id = (int)$item_id; |
32
|
|
|
|
33
|
|
|
if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== 'references') { |
34
|
|
|
$module_handler = xoops_getHandler('module'); |
35
|
|
|
$module = $module_handler->getByDirname('references'); |
36
|
|
|
$config_handler = xoops_getHandler('config'); |
37
|
|
|
$config = $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
38
|
|
|
} else { |
39
|
|
|
$module =& $xoopsModule; |
40
|
|
|
$config =& $xoopsModuleConfig; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($category === 'global') { |
44
|
|
|
$item['name'] = ''; |
|
|
|
|
45
|
|
|
$item['url'] = ''; |
46
|
|
|
|
47
|
|
|
return $item; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($category === 'new_article') { |
51
|
|
|
include REFERENCES_PATH . ' include/common.php'; |
52
|
|
|
$article = null; |
|
|
|
|
53
|
|
|
$article = $h_references_articles->get($item_id); |
|
|
|
|
54
|
|
|
if (is_object($article)) { |
55
|
|
|
$item['name'] = $article->getVar('article_title'); |
|
|
|
|
56
|
|
|
$item['url'] = REFERENCES_URL; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $item; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.