[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_notifications.php (source)

   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;
  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 => $data)
  61                          {
  62                              foreach ($notification_methods as $method => $method_data)
  63                              {
  64                                  if ($request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id'])) && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type])))
  65                                  {
  66                                      $phpbb_notifications->add_subscription($type, 0, $method_data['id']);
  67                                  }
  68                                  else if (!$request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id'])) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type]))
  69                                  {
  70                                      $phpbb_notifications->delete_subscription($type, 0, $method_data['id']);
  71                                  }
  72                              }
  73                          }
  74                      }
  75  
  76                      meta_refresh(3, $this->u_action);
  77                      $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  78                      trigger_error($message);
  79                  }
  80  
  81                  $this->output_notification_methods($phpbb_notifications, $template, $user, 'notification_methods');
  82  
  83                  $this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, 'notification_types');
  84  
  85                  $this->tpl_name = 'ucp_notifications';
  86                  $this->page_title = 'UCP_NOTIFICATION_OPTIONS';
  87              break;
  88  
  89              case 'notification_list':
  90              default:
  91                  // Mark all items read
  92                  if ($request->variable('mark', '') == 'all' && check_link_hash($request->variable('token', ''), 'mark_all_notifications_read'))
  93                  {
  94                      $phpbb_notifications->mark_notifications(false, false, $user->data['user_id'], $form_time);
  95  
  96                      meta_refresh(3, $this->u_action);
  97                      $message = $user->lang['NOTIFICATIONS_MARK_ALL_READ_SUCCESS'];
  98  
  99                      if ($request->is_ajax())
 100                      {
 101                          $json_response = new \phpbb\json_response();
 102                          $json_response->send(array(
 103                              'MESSAGE_TITLE'    => $user->lang['INFORMATION'],
 104                              'MESSAGE_TEXT'    => $message,
 105                              'success'        => true,
 106                          ));
 107                      }
 108                      $message .= '<br /><br />' . $user->lang('RETURN_UCP', '<a href="' . $this->u_action . '">', '</a>');
 109  
 110                      trigger_error($message);
 111                  }
 112  
 113                  // Mark specific notifications read
 114                  if ($request->is_set_post('submit'))
 115                  {
 116                      if (!check_form_key('ucp_notification'))
 117                      {
 118                          trigger_error('FORM_INVALID');
 119                      }
 120  
 121                      $mark_read = $request->variable('mark', array(0));
 122  
 123                      if (!empty($mark_read))
 124                      {
 125                          $phpbb_notifications->mark_notifications_by_id('notification.method.board', $mark_read, $form_time);
 126                      }
 127                  }
 128  
 129                  $notifications = $phpbb_notifications->load_notifications('notification.method.board', array(
 130                      'start'            => $start,
 131                      'limit'            => $config['topics_per_page'],
 132                      'count_total'    => true,
 133                  ));
 134  
 135                  foreach ($notifications['notifications'] as $notification)
 136                  {
 137                      $template->assign_block_vars('notification_list', $notification->prepare_for_display());
 138                  }
 139  
 140                  $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&amp;mode=notification_list");
 141                  $start = $pagination->validate_start($start, $config['topics_per_page'], $notifications['total_count']);
 142                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start);
 143  
 144                  $template->assign_vars(array(
 145                      'TOTAL_COUNT'    => $notifications['total_count'],
 146                      'U_MARK_ALL'    => $base_url . '&amp;mark=all&amp;token=' . generate_link_hash('mark_all_notifications_read'),
 147                  ));
 148  
 149                  $this->tpl_name = 'ucp_notifications';
 150                  $this->page_title = 'UCP_NOTIFICATION_LIST';
 151              break;
 152          }
 153  
 154          $template->assign_vars(array(
 155              'TITLE'                => $user->lang($this->page_title),
 156              'TITLE_EXPLAIN'        => $user->lang($this->page_title . '_EXPLAIN'),
 157  
 158              'MODE'                => $mode,
 159  
 160              'FORM_TIME'            => time(),
 161          ));
 162      }
 163  
 164      /**
 165      * Output all the notification types to the template
 166      *
 167      * @param array $subscriptions Array containing global subscriptions
 168      * @param \phpbb\notification\manager $phpbb_notifications
 169      * @param \phpbb\template\template $template
 170      * @param \phpbb\user $user
 171      * @param string $block
 172      */
 173  	public function output_notification_types($subscriptions, \phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, $block = 'notification_types')
 174      {
 175          $notification_methods = $phpbb_notifications->get_subscription_methods();
 176  
 177          foreach ($phpbb_notifications->get_subscription_types() as $group => $subscription_types)
 178          {
 179              $template->assign_block_vars($block, array(
 180                  'GROUP_NAME'    => $user->lang($group),
 181              ));
 182  
 183              foreach ($subscription_types as $type => $type_data)
 184              {
 185                  $template->assign_block_vars($block, array(
 186                      'TYPE'                => $type,
 187  
 188                      'NAME'                => $user->lang($type_data['lang']),
 189                      'EXPLAIN'            => (isset($user->lang[$type_data['lang'] . '_EXPLAIN'])) ? $user->lang($type_data['lang'] . '_EXPLAIN') : '',
 190                  ));
 191  
 192                  foreach ($notification_methods as $method => $method_data)
 193                  {
 194                      $template->assign_block_vars($block . '.notification_methods', array(
 195                          'METHOD'            => $method_data['id'],
 196  
 197                          'NAME'                => $user->lang($method_data['lang']),
 198  
 199                          'AVAILABLE'            => $method_data['method']->is_available($type_data['type']),
 200  
 201                          'SUBSCRIBED'        => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false,
 202                      ));
 203                  }
 204              }
 205          }
 206  
 207          $template->assign_vars(array(
 208              strtoupper($block) . '_COLS' => count($notification_methods) + 1,
 209          ));
 210      }
 211  
 212      /**
 213      * Output all the notification methods to the template
 214      *
 215      * @param \phpbb\notification\manager $phpbb_notifications
 216      * @param \phpbb\template\template $template
 217      * @param \phpbb\user $user
 218      * @param string $block
 219      */
 220  	public function output_notification_methods(\phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, $block = 'notification_methods')
 221      {
 222          $notification_methods = $phpbb_notifications->get_subscription_methods();
 223  
 224          foreach ($notification_methods as $method => $method_data)
 225          {
 226              $template->assign_block_vars($block, array(
 227                  'METHOD'            => $method_data['id'],
 228  
 229                  'NAME'                => $user->lang($method_data['lang']),
 230              ));
 231          }
 232      }
 233  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1