[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 class ucp_notifications 23 { 24 public $u_action; 25 26 public function main($id, $mode) 27 { 28 global $config, $template, $user, $request, $phpbb_container, $phpbb_dispatcher; 29 global $phpbb_root_path, $phpEx; 30 31 add_form_key('ucp_notification'); 32 33 $start = $request->variable('start', 0); 34 $form_time = $request->variable('form_time', 0); 35 $form_time = ($form_time <= 0 || $form_time > time()) ? time() : $form_time; 36 37 /* @var $phpbb_notifications \phpbb\notification\manager */ 38 $phpbb_notifications = $phpbb_container->get('notification_manager'); 39 40 /* @var $pagination \phpbb\pagination */ 41 $pagination = $phpbb_container->get('pagination'); 42 43 switch ($mode) 44 { 45 case 'notification_options': 46 $subscriptions = $phpbb_notifications->get_global_subscriptions(false); 47 48 // Add/remove subscriptions 49 if ($request->is_set_post('submit')) 50 { 51 if (!check_form_key('ucp_notification')) 52 { 53 trigger_error('FORM_INVALID'); 54 } 55 56 $notification_methods = $phpbb_notifications->get_subscription_methods(); 57 58 foreach ($phpbb_notifications->get_subscription_types() as $group => $subscription_types) 59 { 60 foreach ($subscription_types as $type => $type_data) 61 { 62 foreach ($notification_methods as $method => $method_data) 63 { 64 $is_set_notify = $request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id'])); 65 $is_available = $method_data['method']->is_available($type_data['type']); 66 67 /** 68 * Event to perform additional actions before ucp_notifications is submitted 69 * 70 * @event core.ucp_notifications_submit_notification_is_set 71 * @var array type_data The notification type data 72 * @var array method_data The notification method data 73 * @var bool is_set_notify The notification is set or not 74 * @var bool is_available The notification is available or not 75 * @var array subscriptions The subscriptions data 76 * 77 * @since 3.2.10-RC1 78 * @since 3.3.1-RC1 79 */ 80 $vars = [ 81 'type_data', 82 'method_data', 83 'is_set_notify', 84 'is_available', 85 'subscriptions', 86 ]; 87 extract($phpbb_dispatcher->trigger_event('core.ucp_notifications_submit_notification_is_set', compact($vars))); 88 89 if ($is_set_notify && $is_available && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type]))) 90 { 91 $phpbb_notifications->add_subscription($type, 0, $method_data['id']); 92 } 93 else if ((!$is_set_notify || !$is_available) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) 94 { 95 $phpbb_notifications->delete_subscription($type, 0, $method_data['id']); 96 } 97 } 98 } 99 } 100 101 meta_refresh(3, $this->u_action); 102 $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); 103 trigger_error($message); 104 } 105 106 $this->output_notification_methods($phpbb_notifications, $template, $user, 'notification_methods'); 107 108 $this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, $phpbb_dispatcher, 'notification_types'); 109 110 $this->tpl_name = 'ucp_notifications'; 111 $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; 112 break; 113 114 case 'notification_list': 115 default: 116 // Mark all items read 117 if ($request->variable('mark', '') == 'all' && check_link_hash($request->variable('token', ''), 'mark_all_notifications_read')) 118 { 119 $phpbb_notifications->mark_notifications(false, false, $user->data['user_id'], $form_time); 120 121 meta_refresh(3, $this->u_action); 122 $message = $user->lang['NOTIFICATIONS_MARK_ALL_READ_SUCCESS']; 123 124 if ($request->is_ajax()) 125 { 126 $json_response = new \phpbb\json_response(); 127 $json_response->send(array( 128 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 129 'MESSAGE_TEXT' => $message, 130 'success' => true, 131 )); 132 } 133 $message .= '<br /><br />' . $user->lang('RETURN_UCP', '<a href="' . $this->u_action . '">', '</a>'); 134 135 trigger_error($message); 136 } 137 138 // Mark specific notifications read 139 if ($request->is_set_post('submit')) 140 { 141 if (!check_form_key('ucp_notification')) 142 { 143 trigger_error('FORM_INVALID'); 144 } 145 146 $mark_read = $request->variable('mark', array(0)); 147 148 if (!empty($mark_read)) 149 { 150 $phpbb_notifications->mark_notifications_by_id('notification.method.board', $mark_read, $form_time); 151 } 152 } 153 154 $notifications = $phpbb_notifications->load_notifications('notification.method.board', array( 155 'start' => $start, 156 'limit' => $config['topics_per_page'], 157 'count_total' => true, 158 )); 159 160 foreach ($notifications['notifications'] as $notification) 161 { 162 $template->assign_block_vars('notification_list', $notification->prepare_for_display()); 163 } 164 165 $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&mode=notification_list"); 166 $start = $pagination->validate_start($start, $config['topics_per_page'], $notifications['total_count']); 167 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start); 168 169 $template->assign_vars(array( 170 'TOTAL_COUNT' => $notifications['total_count'], 171 'U_MARK_ALL' => $base_url . '&mark=all&token=' . generate_link_hash('mark_all_notifications_read'), 172 )); 173 174 $this->tpl_name = 'ucp_notifications'; 175 $this->page_title = 'UCP_NOTIFICATION_LIST'; 176 break; 177 } 178 179 $template->assign_vars(array( 180 'TITLE' => $user->lang($this->page_title), 181 'TITLE_EXPLAIN' => $user->lang($this->page_title . '_EXPLAIN'), 182 183 'MODE' => $mode, 184 185 'FORM_TIME' => time(), 186 )); 187 } 188 189 /** 190 * Output all the notification types to the template 191 * 192 * @param array $subscriptions Array containing global subscriptions 193 * @param \phpbb\notification\manager $phpbb_notifications 194 * @param \phpbb\template\template $template 195 * @param \phpbb\user $user 196 * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher 197 * @param string $block 198 */ 199 public function output_notification_types($subscriptions, \phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher, $block = 'notification_types') 200 { 201 $notification_methods = $phpbb_notifications->get_subscription_methods(); 202 203 foreach ($phpbb_notifications->get_subscription_types() as $group => $subscription_types) 204 { 205 $template->assign_block_vars($block, array( 206 'GROUP_NAME' => $user->lang($group), 207 )); 208 209 foreach ($subscription_types as $type => $type_data) 210 { 211 $template->assign_block_vars($block, array( 212 'TYPE' => $type, 213 214 'NAME' => $user->lang($type_data['lang']), 215 'EXPLAIN' => (isset($user->lang[$type_data['lang'] . '_EXPLAIN'])) ? $user->lang($type_data['lang'] . '_EXPLAIN') : '', 216 )); 217 218 foreach ($notification_methods as $method => $method_data) 219 { 220 $tpl_ary = [ 221 'METHOD' => $method_data['id'], 222 'NAME' => $user->lang($method_data['lang']), 223 'AVAILABLE' => $method_data['method']->is_available($type_data['type']), 224 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false, 225 ]; 226 227 /** 228 * Event to perform additional actions before ucp_notifications is displayed 229 * 230 * @event core.ucp_notifications_output_notification_types_modify_template_vars 231 * @var array type_data The notification type data 232 * @var array method_data The notification method data 233 * @var array tpl_ary The template variables 234 * @var array subscriptions The subscriptions data 235 * 236 * @since 3.2.10-RC1 237 * @since 3.3.1-RC1 238 */ 239 $vars = [ 240 'type_data', 241 'method_data', 242 'tpl_ary', 243 'subscriptions', 244 ]; 245 extract($phpbb_dispatcher->trigger_event('core.ucp_notifications_output_notification_types_modify_template_vars', compact($vars))); 246 247 $template->assign_block_vars($block . '.notification_methods', $tpl_ary); 248 } 249 } 250 } 251 252 $template->assign_vars(array( 253 strtoupper($block) . '_COLS' => count($notification_methods) + 1, 254 )); 255 } 256 257 /** 258 * Output all the notification methods to the template 259 * 260 * @param \phpbb\notification\manager $phpbb_notifications 261 * @param \phpbb\template\template $template 262 * @param \phpbb\user $user 263 * @param string $block 264 */ 265 public function output_notification_methods(\phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, $block = 'notification_methods') 266 { 267 $notification_methods = $phpbb_notifications->get_subscription_methods(); 268 269 foreach ($notification_methods as $method => $method_data) 270 { 271 $template->assign_block_vars($block, array( 272 'METHOD' => $method_data['id'], 273 274 'NAME' => $user->lang($method_data['lang']), 275 )); 276 } 277 } 278 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |