[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/notification/type/ -> quote.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  namespace phpbb\notification\type;
  15  
  16  /**
  17  * Post quoting notifications class
  18  * This class handles notifying users when they have been quoted in a post
  19  */
  20  
  21  class quote extends \phpbb\notification\type\post
  22  {
  23      /**
  24      * Get notification type name
  25      *
  26      * @return string
  27      */
  28  	public function get_type()
  29      {
  30          return 'notification.type.quote';
  31      }
  32  
  33      /**
  34      * regular expression to match to find usernames
  35      *
  36      * @var string
  37      */
  38      protected static $regular_expression_match = '#\[quote=&quot;(.+?)&quot;#';
  39  
  40      /**
  41      * Language key used to output the text
  42      *
  43      * @var string
  44      */
  45      protected $language_key = 'NOTIFICATION_QUOTE';
  46  
  47      /**
  48      * Notification option data (for outputting to the user)
  49      *
  50      * @var bool|array False if the service should use it's default data
  51      *                     Array of data (including keys 'id', 'lang', and 'group')
  52      */
  53      public static $notification_option = array(
  54          'lang'    => 'NOTIFICATION_TYPE_QUOTE',
  55          'group'    => 'NOTIFICATION_GROUP_POSTING',
  56      );
  57  
  58      /**
  59      * Is available
  60      */
  61  	public function is_available()
  62      {
  63          return true;
  64      }
  65  
  66      /**
  67      * Find the users who want to receive notifications
  68      *
  69      * @param array $post Data from submit_post
  70      * @param array $options Options for finding users for notification
  71      *
  72      * @return array
  73      */
  74  	public function find_users_for_notification($post, $options = array())
  75      {
  76          $options = array_merge(array(
  77              'ignore_users'        => array(),
  78          ), $options);
  79  
  80          $usernames = false;
  81          preg_match_all(static::$regular_expression_match, $post['post_text'], $usernames);
  82  
  83          if (empty($usernames[1]))
  84          {
  85              return array();
  86          }
  87  
  88          $usernames[1] = array_unique($usernames[1]);
  89  
  90          $usernames = array_map('utf8_clean_string', $usernames[1]);
  91  
  92          $users = array();
  93  
  94          $sql = 'SELECT user_id
  95              FROM ' . USERS_TABLE . '
  96              WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
  97                  AND user_id <> ' . (int) $post['poster_id'];
  98          $result = $this->db->sql_query($sql);
  99          while ($row = $this->db->sql_fetchrow($result))
 100          {
 101              $users[] = (int) $row['user_id'];
 102          }
 103          $this->db->sql_freeresult($result);
 104  
 105          return $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
 106      }
 107  
 108      /**
 109      * Update a notification
 110      *
 111      * @param array $post Data specific for this type that will be updated
 112      */
 113  	public function update_notifications($post)
 114      {
 115          $old_notifications = array();
 116          $sql = 'SELECT n.user_id
 117              FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
 118              WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
 119                  AND n.item_id = ' . static::get_item_id($post) . '
 120                  AND nt.notification_type_id = n.notification_type_id
 121                  AND nt.notification_type_enabled = 1';
 122          $result = $this->db->sql_query($sql);
 123          while ($row = $this->db->sql_fetchrow($result))
 124          {
 125              $old_notifications[] = $row['user_id'];
 126          }
 127          $this->db->sql_freeresult($result);
 128  
 129          // Find the new users to notify
 130          $notifications = $this->find_users_for_notification($post);
 131  
 132          // Find the notifications we must delete
 133          $remove_notifications = array_diff($old_notifications, array_keys($notifications));
 134  
 135          // Find the notifications we must add
 136          $add_notifications = array();
 137          foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id)
 138          {
 139              $add_notifications[$user_id] = $notifications[$user_id];
 140          }
 141  
 142          // Add the necessary notifications
 143          $this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications);
 144  
 145          // Remove the necessary notifications
 146          if (!empty($remove_notifications))
 147          {
 148              $sql = 'DELETE FROM ' . $this->notifications_table . '
 149                  WHERE notification_type_id = ' . (int) $this->notification_type_id . '
 150                      AND item_id = ' . static::get_item_id($post) . '
 151                      AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
 152              $this->db->sql_query($sql);
 153          }
 154  
 155          // return true to continue with the update code in the notifications service (this will update the rest of the notifications)
 156          return true;
 157      }
 158  
 159      /**
 160      * {inheritDoc}
 161      */
 162  	public function get_redirect_url()
 163      {
 164          return $this->get_url();
 165      }
 166  
 167      /**
 168      * Get email template
 169      *
 170      * @return string|bool
 171      */
 172  	public function get_email_template()
 173      {
 174          return 'quote';
 175      }
 176  
 177      /**
 178      * Get email template variables
 179      *
 180      * @return array
 181      */
 182  	public function get_email_template_variables()
 183      {
 184          $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
 185  
 186          return array_merge(parent::get_email_template_variables(), array(
 187              'AUTHOR_NAME'        => htmlspecialchars_decode($user_data['username']),
 188          ));
 189      }
 190  }


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