1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* include/notification.inc.php - notification lookup |
4
|
|
|
* |
5
|
|
|
* This file is part of gwiki - geekwright wiki |
6
|
|
|
* |
7
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
8
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
9
|
|
|
* @since 1.0 |
10
|
|
|
* @author Richard Griffith <[email protected]> |
11
|
|
|
* @package gwiki |
12
|
|
|
*/ |
13
|
|
|
if (!defined('GWIKI_NOTIFY_ITEMINFO')) { |
14
|
|
|
define('GWIKI_NOTIFY_ITEMINFO', 1); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param $category |
18
|
|
|
* @param $item_id |
19
|
|
|
* |
20
|
|
|
* @return mixed |
21
|
|
|
*/ |
22
|
|
|
function gwiki_notify_iteminfo($category, $item_id) |
23
|
|
|
{ |
24
|
|
|
global $xoopsDB; |
25
|
|
|
|
26
|
|
|
$dir = basename(dirname(__DIR__)); |
27
|
|
|
//include_once XOOPS_ROOT_PATH.'/modules/'.$dir.'/class/GwikiPage.php'; |
28
|
|
|
//$wikiPage = new GwikiPage; |
29
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper($dir); |
30
|
|
|
|
31
|
|
|
switch ($category) { |
32
|
|
|
case 'page': |
33
|
|
|
$item_id = (int)$item_id; |
34
|
|
|
$sql = 'SELECT i.keyword as keyword, display_keyword, title FROM '; |
35
|
|
|
$sql .= $xoopsDB->prefix('gwiki_pageids') . ' i, ' . $xoopsDB->prefix('gwiki_pages') . ' p '; |
36
|
|
|
// $sql .= ' WHERE i.keyword = p.keyword AND active = 1 AND page_id = '.$item_id; |
37
|
|
|
$sql .= " WHERE i.keyword = p.keyword AND active = 1 AND page_id = {$item_id}"; |
38
|
|
|
|
39
|
|
|
$result = $xoopsDB->query($sql); |
40
|
|
|
$row = $xoopsDB->fetchArray($result); |
41
|
|
|
|
42
|
|
|
$item['name'] = $row['display_keyword']; |
|
|
|
|
43
|
|
|
if (empty($item['name'])) { |
44
|
|
|
$item['name'] = $row['title']; |
45
|
|
|
} |
46
|
|
|
if (empty($item['name'])) { |
47
|
|
|
$item['name'] = $row['keyword']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$item['url'] = sprintf($moduleHelper->getConfig('wikilink_template'), $row['keyword']); |
51
|
|
|
break; |
52
|
|
|
case 'namespace': |
53
|
|
|
$item_id = (int)$item_id; |
54
|
|
|
$sql = 'SELECT prefix, prefix_home FROM ' . $xoopsDB->prefix('gwiki_prefix'); |
55
|
|
|
// $sql .= ' WHERE prefix_id = '.$item_id; |
56
|
|
|
$sql .= " WHERE prefix_id = {$item_id}"; |
57
|
|
|
|
58
|
|
|
$result = $xoopsDB->query($sql); |
59
|
|
|
$row = $xoopsDB->fetchArray($result); |
60
|
|
|
|
61
|
|
|
$item['name'] = $row['prefix']; |
|
|
|
|
62
|
|
|
$item['url'] = sprintf($moduleHelper->getConfig('wikilink_template'), $row['prefix'] . ':' . $row['prefix_home']); |
63
|
|
|
break; |
64
|
|
|
default: |
65
|
|
|
$item['name'] = $category; |
|
|
|
|
66
|
|
|
$item['url'] = XOOPS_URL . '/modules/' . $dir . '/'; |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $item; |
71
|
|
|
} |
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.