1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 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: 21: 22: 23: 24: 25:
26: class NotificationsPreload extends PreloadItem
27: {
28: 29: 30: 31: 32: 33: 34: 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: 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: 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: 142: 143: 144: 145: 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: 163: 164: 165:
166: public static function eventCoreIncludeCheckloginSuccess()
167: {
168:
169:
170:
171: $xoops = Xoops::getInstance();
172: if ($xoops->user instanceof XoopsUser) {
173: Notifications::getInstance()->getHandlerNotification()->doLoginMaintenance($xoops->user->getVar('uid'));
174: }
175: }
176: }
177: