[ Index ]

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1