Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_notifications.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 9.19 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  class ucp_notifications
023  {
024      public $u_action;
025   
026      public function main($id, $mode)
027      {
028          global $config, $template, $user, $request, $phpbb_container, $phpbb_dispatcher;
029          global $phpbb_root_path, $phpEx;
030   
031          add_form_key('ucp_notification');
032   
033          $start = $request->variable('start', 0);
034          $form_time = $request->variable('form_time', 0);
035          $form_time = ($form_time <= 0 || $form_time > time()) ? time() : $form_time;
036   
037          /* @var $phpbb_notifications \phpbb\notification\manager */
038          $phpbb_notifications = $phpbb_container->get('notification_manager');
039   
040          /* @var $pagination \phpbb\pagination */
041          $pagination = $phpbb_container->get('pagination');
042   
043          switch ($mode)
044          {
045              case 'notification_options':
046                  $subscriptions = $phpbb_notifications->get_global_subscriptions(false);
047   
048                  // Add/remove subscriptions
049                  if ($request->is_set_post('submit'))
050                  {
051                      if (!check_form_key('ucp_notification'))
052                      {
053                          trigger_error('FORM_INVALID');
054                      }
055   
056                      $notification_methods = $phpbb_notifications->get_subscription_methods();
057   
058                      foreach ($phpbb_notifications->get_subscription_types() as $group => $subscription_types)
059                      {
060                          foreach ($subscription_types as $type => $type_data)
061                          {
062                              foreach ($notification_methods as $method => $method_data)
063                              {
064                                  $is_set_notify = $request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id']));
065                                  $is_available = $method_data['method']->is_available($type_data['type']);
066   
067                                  /**
068                                  * Event to perform additional actions before ucp_notifications is submitted
069                                  *
070                                  * @event core.ucp_notifications_submit_notification_is_set
071                                  * @var    array    type_data        The notification type data
072                                  * @var    array    method_data        The notification method data
073                                  * @var    bool    is_set_notify    The notification is set or not
074                                  * @var    bool    is_available    The notification is available or not
075                                  * @var    array    subscriptions    The subscriptions data
076                                  *
077                                  * @since 3.2.10-RC1
078                                  * @since 3.3.1-RC1
079                                  */
080                                  $vars = [
081                                      'type_data',
082                                      'method_data',
083                                      'is_set_notify',
084                                      'is_available',
085                                      'subscriptions',
086                                  ];
087                                  extract($phpbb_dispatcher->trigger_event('core.ucp_notifications_submit_notification_is_set', compact($vars)));
088   
089                                  if ($is_set_notify && $is_available && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type])))
090                                  {
091                                      $phpbb_notifications->add_subscription($type, 0, $method_data['id']);
092                                  }
093                                  else if ((!$is_set_notify || !$is_available) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type]))
094                                  {
095                                      $phpbb_notifications->delete_subscription($type, 0, $method_data['id']);
096                                  }
097                              }
098                          }
099                      }
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&amp;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 . '&amp;mark=all&amp;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  }
279