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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
quote.php
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 namespace phpbb\notification\type;
015
016 /**
017 * Post quoting notifications class
018 * This class handles notifying users when they have been quoted in a post
019 */
020
021 class quote extends \phpbb\notification\type\post
022 {
023 /**
024 * @var \phpbb\textformatter\utils_interface
025 */
026 protected $utils;
027
028 /**
029 * Get notification type name
030 *
031 * @return string
032 */
033 public function get_type()
034 {
035 return 'notification.type.quote';
036 }
037
038 /**
039 * Language key used to output the text
040 *
041 * @var string
042 */
043 protected $language_key = 'NOTIFICATION_QUOTE';
044
045 /**
046 * Notification option data (for outputting to the user)
047 *
048 * @var bool|array False if the service should use it's default data
049 * Array of data (including keys 'id', 'lang', and 'group')
050 */
051 static public $notification_option = array(
052 'lang' => 'NOTIFICATION_TYPE_QUOTE',
053 'group' => 'NOTIFICATION_GROUP_POSTING',
054 );
055
056 /**
057 * Is available
058 */
059 public function is_available()
060 {
061 return true;
062 }
063
064 /**
065 * Find the users who want to receive notifications
066 *
067 * @param array $post Data from submit_post
068 * @param array $options Options for finding users for notification
069 *
070 * @return array
071 */
072 public function find_users_for_notification($post, $options = array())
073 {
074 $options = array_merge(array(
075 'ignore_users' => array(),
076 ), $options);
077
078 $usernames = $this->utils->get_outermost_quote_authors($post['post_text']);
079
080 if (empty($usernames))
081 {
082 return array();
083 }
084
085 $usernames = array_unique($usernames);
086
087 $usernames = array_map('utf8_clean_string', $usernames);
088
089 $users = array();
090
091 $sql = 'SELECT user_id
092 FROM ' . USERS_TABLE . '
093 WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
094 AND user_id <> ' . (int) $post['poster_id'];
095 $result = $this->db->sql_query($sql);
096 while ($row = $this->db->sql_fetchrow($result))
097 {
098 $users[] = (int) $row['user_id'];
099 }
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 }
185