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
|
|
|
use Xoops\Core\Kernel\Handlers\XoopsUser; |
|
|
|
|
13
|
|
|
use Xoops\Core\Kernel\Handlers\XoopsModule; |
|
|
|
|
14
|
|
|
use Xoops\Core\PreloadItem; |
15
|
|
|
use Xoops\Module\Plugin; |
16
|
|
|
use Xoops\Module\Plugin\ConfigCollector; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Notifications core preloads |
21
|
|
|
* |
22
|
|
|
* @author trabis <[email protected]> |
23
|
|
|
* @copyright 2012-2015 XOOPS Project (http://xoops.org) |
24
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
25
|
|
|
*/ |
26
|
|
|
class NotificationsPreload extends PreloadItem |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* listen for core.include.common.classmaps |
30
|
|
|
* add any module specific class map entries |
31
|
|
|
* |
32
|
|
|
* @param mixed $args not used |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public static function eventCoreIncludeCommonClassmaps($args) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$path = dirname(__DIR__); |
39
|
|
|
XoopsLoad::addMap(array( |
40
|
|
|
'notifications' => $path . '/class/helper.php', |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function eventCoreFooterStart($args) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$xoops = Xoops::getInstance(); |
47
|
|
|
$helper = Notifications::getInstance(); |
48
|
|
|
|
49
|
|
|
$notifications = array(); |
50
|
|
|
$notifications['show'] = $xoops->isModule() && $xoops->isUser() && $helper->enabled('inline') ? 1 : 0; |
51
|
|
|
if ($notifications['show']) { |
52
|
|
|
$helper->loadLanguage('main'); |
53
|
|
|
$categories = $helper->getSubscribableCategories(); |
54
|
|
|
$event_count = 0; |
55
|
|
|
if (!empty($categories)) { |
56
|
|
|
$notification_handler = $helper->getHandlerNotification(); |
57
|
|
|
foreach ($categories as $category) { |
58
|
|
|
$section['name'] = $category['name']; |
|
|
|
|
59
|
|
|
$section['title'] = $category['title']; |
|
|
|
|
60
|
|
|
$section['description'] = $category['description']; |
61
|
|
|
$section['itemid'] = $category['item_id']; |
62
|
|
|
$section['events'] = array(); |
63
|
|
|
$subscribed_events = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoops->module->getVar('mid'), $xoops->user->getVar('uid')); |
64
|
|
|
foreach ($helper->getEvents($category['name'], true, $xoops->module->getVar('dirname')) as $event) { |
65
|
|
View Code Duplication |
if (!empty($event['admin_only']) && !$xoops->user->isAdmin($xoops->module->getVar('mid'))) { |
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
if (!empty($event['invisible'])) { |
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
$subscribed = in_array($event['name'], $subscribed_events) ? 1 : 0; |
72
|
|
|
$section['events'][$event['name']] = array( |
73
|
|
|
'name' => $event['name'], |
74
|
|
|
'title' => $event['title'], |
75
|
|
|
'caption' => $event['caption'], |
76
|
|
|
'description' => $event['description'], |
77
|
|
|
'subscribed' => $subscribed |
78
|
|
|
); |
79
|
|
|
++$event_count; |
80
|
|
|
} |
81
|
|
|
$notifications['categories'][$category['name']] = $section; |
82
|
|
|
} |
83
|
|
|
$notifications['target_page'] = $helper->url('update.php'); |
84
|
|
|
$notifications['mid'] = $xoops->module->getVar('mid'); |
85
|
|
|
$notifications['redirect_script'] = $xoops->getEnv('PHP_SELF'); |
86
|
|
|
$xoops->tpl()->assign(array( |
87
|
|
|
'lang_activenotifications' => _MD_NOTIFICATIONS_ACTIVENOTIFICATIONS, |
88
|
|
|
'lang_notificationoptions' => _MD_NOTIFICATIONS_NOTIFICATIONOPTIONS, |
89
|
|
|
'lang_updateoptions' => _MD_NOTIFICATIONS_UPDATEOPTIONS, |
90
|
|
|
'lang_updatenow' => _MD_NOTIFICATIONS_UPDATENOW, |
91
|
|
|
'lang_category' => _MD_NOTIFICATIONS_CATEGORY, |
92
|
|
|
'lang_event' => _MD_NOTIFICATIONS_EVENT, |
93
|
|
|
'lang_events' => _MD_NOTIFICATIONS_EVENTS, |
94
|
|
|
'lang_checkall' => _MD_NOTIFICATIONS_CHECKALL, |
95
|
|
|
'lang_notificationmethodis' => _MD_NOTIFICATIONS_NOTIFICATIONMETHODIS, |
96
|
|
|
'lang_change' => _MD_NOTIFICATIONS_CHANGE, |
97
|
|
|
'editprofile_url' => XOOPS_URL . '/edituser.php?uid=' . $xoops->user->getVar('uid') |
98
|
|
|
)); |
99
|
|
|
switch ($xoops->user->getVar('notify_method')) { |
100
|
|
|
case NOTIFICATIONS_METHOD_DISABLE: |
101
|
|
|
$xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_DISABLE); |
102
|
|
|
break; |
103
|
|
|
case NOTIFICATIONS_METHOD_PM: |
104
|
|
|
$xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_PM); |
105
|
|
|
break; |
106
|
|
|
case NOTIFICATIONS_METHOD_EMAIL: |
107
|
|
|
$xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_EMAIL); |
108
|
|
|
break; |
109
|
|
|
} |
110
|
|
|
} else { |
111
|
|
|
$notifications['show'] = 0; |
112
|
|
|
} |
113
|
|
|
if ($event_count == 0) { |
114
|
|
|
$notifications['show'] = 0; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
$xoops->tpl()->assign('notifications', $notifications); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
public static function eventSystemModuleUpdateConfigs(ConfigCollector $collector) |
121
|
|
|
{ |
122
|
|
|
$helper = \Xoops::getModuleHelper('notifications'); |
123
|
|
|
if ($plugin = Plugin::getPlugin( |
|
|
|
|
124
|
|
|
$collector->module()->getVar('dirname'), |
125
|
|
|
'notifications', |
126
|
|
|
true |
127
|
|
|
)) { |
128
|
|
|
$pluginConfigs = $helper->getPluginableConfigs($collector->module()); |
129
|
|
|
$collector->add($pluginConfigs); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public static function eventSystemModuleInstallConfigs(XoopsModule $module) |
134
|
|
|
{ |
135
|
|
|
if ($plugin = Plugin::getPlugin($module->getVar('dirname'), 'notifications', true)) { |
|
|
|
|
136
|
|
|
Notifications::getInstance()->insertModuleRelations($module); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* remove any notifications for module being uninstalled |
142
|
|
|
* |
143
|
|
|
* @param XoopsModule $module module object |
144
|
|
|
* |
145
|
|
|
* @return void |
146
|
|
|
*/ |
147
|
|
|
public static function eventSystemModuleUninstall(XoopsModule $module) |
148
|
|
|
{ |
149
|
|
|
if ($plugin = Plugin::getPlugin($module->getVar('dirname'), 'notifications')) { |
|
|
|
|
150
|
|
|
Notifications::getInstance()->deleteModuleRelations($module); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public static function eventSystemPreferencesForm(XoopsModule $module) |
155
|
|
|
{ |
156
|
|
|
if ($plugin = Plugin::getPlugin($module->getVar('dirname'), 'notifications')) { |
|
|
|
|
157
|
|
|
Notifications::getInstance()->loadLanguage('main'); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* core.include.checklogin.success |
163
|
|
|
* |
164
|
|
|
* @return void |
165
|
|
|
*/ |
166
|
|
|
public static function eventCoreIncludeCheckloginSuccess() |
167
|
|
|
{ |
168
|
|
|
// This was in include checklogin.php, moving here for now |
169
|
|
|
// RMV-NOTIFY |
170
|
|
|
// Perform some maintenance of notification records |
171
|
|
|
$xoops = Xoops::getInstance(); |
172
|
|
|
if ($xoops->user instanceof XoopsUser) { |
173
|
|
|
Notifications::getInstance()->getHandlerNotification()->doLoginMaintenance($xoops->user->getVar('uid')); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: