[ Index ]

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


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1