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 |
topic.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 * Topic notifications class
018 * This class handles notifications for new topics
019 */
020
021 class topic extends \phpbb\notification\type\base
022 {
023 /**
024 * Get notification type name
025 *
026 * @return string
027 */
028 public function get_type()
029 {
030 return 'notification.type.topic';
031 }
032
033 /**
034 * Language key used to output the text
035 *
036 * @var string
037 */
038 protected $language_key = 'NOTIFICATION_TOPIC';
039
040 /**
041 * Inherit notification read status from topic.
042 *
043 * @var bool
044 */
045 protected $inherit_read_status = true;
046
047 /**
048 * Notification option data (for outputting to the user)
049 *
050 * @var bool|array False if the service should use it's default data
051 * Array of data (including keys 'id', 'lang', and 'group')
052 */
053 static public $notification_option = array(
054 'lang' => 'NOTIFICATION_TYPE_TOPIC',
055 'group' => 'NOTIFICATION_GROUP_POSTING',
056 );
057
058 /** @var \phpbb\user_loader */
059 protected $user_loader;
060
061 /** @var \phpbb\config\config */
062 protected $config;
063
064 public function set_config(\phpbb\config\config $config)
065 {
066 $this->config = $config;
067 }
068
069 public function set_user_loader(\phpbb\user_loader $user_loader)
070 {
071 $this->user_loader = $user_loader;
072 }
073
074 /**
075 * Is available
076 */
077 public function is_available()
078 {
079 return $this->config['allow_forum_notify'];
080 }
081
082 /**
083 * Get the id of the item
084 *
085 * @param array $post The data from the post
086 * @return int The topic id
087 */
088 static public function get_item_id($post)
089 {
090 return (int) $post['topic_id'];
091 }
092
093 /**
094 * Get the id of the parent
095 *
096 * @param array $post The data from the post
097 * @return int The forum id
098 */
099 static public function get_item_parent_id($post)
100 {
101 return (int) $post['forum_id'];
102 }
103
104 /**
105 * Find the users who want to receive notifications
106 *
107 * @param array $topic Data from the topic
108 * @param array $options Options for finding users for notification
109 *
110 * @return array
111 */
112 public function find_users_for_notification($topic, $options = array())
113 {
114 $options = array_merge(array(
115 'ignore_users' => array(),
116 ), $options);
117
118 $users = array();
119
120 $sql = 'SELECT user_id
121 FROM ' . FORUMS_WATCH_TABLE . '
122 WHERE forum_id = ' . (int) $topic['forum_id'] . '
123 AND notify_status = ' . NOTIFY_YES . '
124 AND user_id <> ' . (int) $topic['poster_id'];
125 $result = $this->db->sql_query($sql);
126 while ($row = $this->db->sql_fetchrow($result))
127 {
128 $users[] = (int) $row['user_id'];
129 }
130 $this->db->sql_freeresult($result);
131
132 return $this->get_authorised_recipients($users, $topic['forum_id'], $options);
133 }
134
135 /**
136 * Get the user's avatar
137 */
138 public function get_avatar()
139 {
140 return $this->user_loader->get_avatar($this->get_data('poster_id'), false, true);
141 }
142
143 /**
144 * Get the HTML formatted title of this notification
145 *
146 * @return string
147 */
148 public function get_title()
149 {
150 if ($this->get_data('post_username'))
151 {
152 $username = $this->get_data('post_username');
153 }
154 else
155 {
156 $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile');
157 }
158
159 return $this->language->lang(
160 $this->language_key,
161 $username
162 );
163 }
164
165 /**
166 * Get the HTML formatted reference of the notification
167 *
168 * @return string
169 */
170 public function get_reference()
171 {
172 return $this->language->lang(
173 'NOTIFICATION_REFERENCE',
174 censor_text($this->get_data('topic_title'))
175 );
176 }
177
178 /**
179 * Get the forum of the notification reference
180 *
181 * @return string
182 */
183 public function get_forum()
184 {
185 return $this->language->lang(
186 'NOTIFICATION_FORUM',
187 $this->get_data('forum_name')
188 );
189 }
190
191 /**
192 * Get email template
193 *
194 * @return string|bool
195 */
196 public function get_email_template()
197 {
198 return 'newtopic_notify';
199 }
200
201 /**
202 * Get email template variables
203 *
204 * @return array
205 */
206 public function get_email_template_variables()
207 {
208 $board_url = generate_board_url();
209
210 if ($this->get_data('post_username'))
211 {
212 $username = $this->get_data('post_username');
213 }
214 else
215 {
216 $username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
217 }
218
219 return array(
220 'AUTHOR_NAME' => html_entity_decode($username, ENT_COMPAT),
221 'FORUM_NAME' => html_entity_decode($this->get_data('forum_name'), ENT_COMPAT),
222 'TOPIC_TITLE' => html_entity_decode(censor_text($this->get_data('topic_title')), ENT_COMPAT),
223
224 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?t={$this->item_id}",
225 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?t={$this->item_id}",
226 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->item_parent_id}",
227 'U_STOP_WATCHING_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum",
228 );
229 }
230
231 /**
232 * Get the url to this item
233 *
234 * @return string URL
235 */
236 public function get_url()
237 {
238 return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_id}");
239 }
240
241 /**
242 * Users needed to query before this notification can be displayed
243 *
244 * @return array Array of user_ids
245 */
246 public function users_to_query()
247 {
248 return array($this->get_data('poster_id'));
249 }
250
251 /**
252 * Pre create insert array function
253 * This allows you to perform certain actions, like run a query
254 * and load data, before create_insert_array() is run. The data
255 * returned from this function will be sent to create_insert_array().
256 *
257 * @param array $post Post data from submit_post
258 * @param array $notify_users Notify users list
259 * Formatted from find_users_for_notification()
260 * @return array Whatever you want to send to create_insert_array().
261 */
262 public function pre_create_insert_array($post, $notify_users)
263 {
264 if (!count($notify_users) || !$this->inherit_read_status)
265 {
266 return array();
267 }
268
269 $tracking_data = array();
270 $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . '
271 WHERE topic_id = ' . (int) $post['topic_id'] . '
272 AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users));
273 $result = $this->db->sql_query($sql);
274 while ($row = $this->db->sql_fetchrow($result))
275 {
276 $tracking_data[$row['user_id']] = $row['mark_time'];
277 }
278 $this->db->sql_freeresult($result);
279
280 return $tracking_data;
281 }
282
283 /**
284 * {@inheritdoc}
285 */
286 public function create_insert_array($post, $pre_create_data = array())
287 {
288 $this->set_data('poster_id', $post['poster_id']);
289
290 $this->set_data('topic_title', $post['topic_title']);
291
292 $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
293
294 $this->set_data('forum_name', $post['forum_name']);
295
296 $this->notification_time = $post['post_time'];
297
298 // Topics can be "read" before they are public (while awaiting approval).
299 // Make sure that if the user has read the topic, it's marked as read in the notification
300 if ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
301 {
302 $this->notification_read = true;
303 }
304
305 parent::create_insert_array($post, $pre_create_data);
306 }
307 }
308