|
1
|
|
|
<?php |
|
2
|
|
|
// $Id: notification.inc.php 8112 2011-11-06 13:41:14Z beckmi $ |
|
3
|
|
|
// ------------------------------------------------------------------------ // |
|
4
|
|
|
// XOOPS - PHP Content Management System // |
|
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
|
6
|
|
|
// <http://www.xoops.org/> // |
|
7
|
|
|
// ------------------------------------------------------------------------ // |
|
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
11
|
|
|
// (at your option) any later version. // |
|
12
|
|
|
// // |
|
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
14
|
|
|
// of supporting developers from this source code or any supporting // |
|
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
16
|
|
|
// original comment or credit authors. // |
|
17
|
|
|
// // |
|
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
21
|
|
|
// GNU General Public License for more details. // |
|
22
|
|
|
// // |
|
23
|
|
|
// You should have received a copy of the GNU General Public License // |
|
24
|
|
|
// along with this program; if not, write to the Free Software // |
|
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
26
|
|
|
// ------------------------------------------------------------------------ // |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param $category |
|
30
|
|
|
* @param $item_id |
|
31
|
|
|
* @return mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
function mylinks_notify_iteminfo($category, $item_id) |
|
34
|
|
|
{ |
|
35
|
|
|
global $xoopsModule, $xoopsModuleConfig, $xoopsConfig, $xoopsDB; |
|
36
|
|
|
$dirname = basename(dirname(__DIR__)); |
|
37
|
|
|
|
|
38
|
|
|
$item_id = (isset($item_id) && ((int)$item_id > 0)) ? (int)$item_id : 0; |
|
39
|
|
|
|
|
40
|
|
|
if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != $dirname) { |
|
41
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
42
|
|
|
$module = $moduleHandler->getByDirname($dirname); |
|
43
|
|
|
$configHandler = xoops_getHandler('config'); |
|
44
|
|
|
$config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
|
45
|
|
|
} else { |
|
46
|
|
|
$module = $xoopsModule; |
|
47
|
|
|
$config = $xoopsModuleConfig; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
switch ($category) { |
|
51
|
|
|
case 'category': |
|
52
|
|
|
// Assume we have a valid category id |
|
53
|
|
|
$mylinksCatHandler = xoops_getModuleHandler('category', $dirname); |
|
54
|
|
|
$catObj = $mylinksCatHandler->get($item_id); |
|
55
|
|
|
if ($catObj) { |
|
56
|
|
|
$item['name'] = $catObj->getVar('title'); |
|
|
|
|
|
|
57
|
|
|
$item['url'] = XOOPS_URL . "/modules/{$dirname}/viewcat.php?cid={$item_id}"; |
|
58
|
|
|
/* |
|
59
|
|
|
$sql = "SELECT title FROM " . $xoopsDB->prefix('mylinks_cat') . " WHERE cid={$item_id}"; |
|
60
|
|
|
$result = $xoopsDB->query($sql); // TODO: error check |
|
61
|
|
|
$result_array = $xoopsDB->fetchArray($result); |
|
62
|
|
|
$item['name'] = $result_array['title']; |
|
63
|
|
|
$item['url'] = XOOPS_URL . "/modules/" . $module->getVar('dirname') . "/viewcat.php?cid={$item_id}"; |
|
64
|
|
|
*/ |
|
65
|
|
|
} else { |
|
66
|
|
|
$item['name'] = ''; |
|
|
|
|
|
|
67
|
|
|
$item['url'] = ''; |
|
68
|
|
|
} |
|
69
|
|
|
break; |
|
70
|
|
|
case 'link': |
|
71
|
|
|
$sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE lid={$item_id}"; |
|
72
|
|
|
$result = $xoopsDB->query($sql); // TODO: error check |
|
73
|
|
|
$result_array = $xoopsDB->fetchArray($result); |
|
74
|
|
|
if (!empty($result_array['title'])) { |
|
75
|
|
|
$item['name'] = $result_array['title']; |
|
|
|
|
|
|
76
|
|
|
$item['url'] = XOOPS_URL . "/modules/{$dirname}/singlelink.php?cid={$result_array['cid']}&lid={$item_id}"; |
|
77
|
|
|
} else { |
|
78
|
|
|
$item['name'] = ''; |
|
|
|
|
|
|
79
|
|
|
$item['url'] = ''; |
|
80
|
|
|
} |
|
81
|
|
|
break; |
|
82
|
|
|
case 'global': |
|
83
|
|
|
default: |
|
84
|
|
|
$item['name'] = ''; |
|
|
|
|
|
|
85
|
|
|
$item['url'] = ''; |
|
86
|
|
|
break; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $item; |
|
90
|
|
|
} |
|
91
|
|
|
|
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.