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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

post.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 11.46 KiB


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 notifications class
018  * This class handles notifications for replies to a topic
019  */
020   
021  class post 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.post';
031      }
032   
033      /**
034      * Language key used to output the text
035      *
036      * @var string
037      */
038      protected $language_key = 'NOTIFICATION_POST';
039   
040      /**
041      * Inherit notification read status from post.
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_POST',
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_topic_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 post id
087      */
088      static public function get_item_id($post)
089      {
090          return (int) $post['post_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 topic id
098      */
099      static public function get_item_parent_id($post)
100      {
101          return (int) $post['topic_id'];
102      }
103   
104      /**
105      * Find the users who want to receive notifications
106      *
107      * @param array $post Data from submit_post
108      * @param array $options Options for finding users for notification
109      *
110      * @return array
111      */
112      public function find_users_for_notification($post, $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 ' . TOPICS_WATCH_TABLE . '
122              WHERE topic_id = ' . (int) $post['topic_id'] . '
123                  AND notify_status = ' . NOTIFY_YES . '
124                  AND user_id <> ' . (int) $post['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          $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
133   
134          if (empty($notify_users))
135          {
136              return array();
137          }
138   
139          // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
140          $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
141              'item_parent_id'    => static::get_item_parent_id($post),
142              'read'                => 0,
143          ));
144   
145          foreach ($notified_users as $user => $notification_data)
146          {
147              unset($notify_users[$user]);
148   
149              /** @var post $notification */
150              $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
151              $update_responders = $notification->add_responders($post);
152              if (!empty($update_responders))
153              {
154                  $this->notification_manager->update_notification($notification, $update_responders, array(
155                      'item_parent_id'    => self::get_item_parent_id($post),
156                      'read'                => 0,
157                      'user_id'            => $user,
158                  ));
159              }
160          }
161   
162          return $notify_users;
163      }
164   
165      /**
166      * Get the user's avatar
167      */
168      public function get_avatar()
169      {
170          return $this->user_loader->get_avatar($this->get_data('poster_id'), false, true);
171      }
172   
173      /**
174      * Get the HTML formatted title of this notification
175      *
176      * @return string
177      */
178      public function get_title()
179      {
180          $responders = $this->get_data('responders');
181          $usernames = array();
182   
183          if (!is_array($responders))
184          {
185              $responders = array();
186          }
187   
188          $responders = array_merge(array(array(
189              'poster_id'        => $this->get_data('poster_id'),
190              'username'        => $this->get_data('post_username'),
191          )), $responders);
192   
193          $responders_cnt = count($responders);
194          $responders = $this->trim_user_ary($responders);
195          $trimmed_responders_cnt = $responders_cnt - count($responders);
196   
197          foreach ($responders as $responder)
198          {
199              if ($responder['username'])
200              {
201                  $usernames[] = $responder['username'];
202              }
203              else
204              {
205                  $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile');
206              }
207          }
208   
209          if ($trimmed_responders_cnt > 20)
210          {
211              $usernames[] = $this->language->lang('NOTIFICATION_MANY_OTHERS');
212          }
213          else if ($trimmed_responders_cnt)
214          {
215              $usernames[] = $this->language->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
216          }
217   
218          return $this->language->lang(
219              $this->language_key,
220              phpbb_generate_string_list($usernames, $this->user),
221              $responders_cnt
222          );
223      }
224   
225      /**
226      * Get the HTML formatted reference of the notification
227      *
228      * @return string
229      */
230      public function get_reference()
231      {
232          return $this->language->lang(
233              'NOTIFICATION_REFERENCE',
234              censor_text($this->get_data('topic_title'))
235          );
236      }
237   
238      /**
239      * Get email template
240      *
241      * @return string|bool
242      */
243      public function get_email_template()
244      {
245          return 'topic_notify';
246      }
247   
248      /**
249      * Get email template variables
250      *
251      * @return array
252      */
253      public function get_email_template_variables()
254      {
255          if ($this->get_data('post_username'))
256          {
257              $username = $this->get_data('post_username');
258          }
259          else
260          {
261              $username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
262          }
263   
264          return array(
265              'AUTHOR_NAME'                => html_entity_decode($username, ENT_COMPAT),
266              'POST_SUBJECT'                => html_entity_decode(censor_text($this->get_data('post_subject')), ENT_COMPAT),
267              'TOPIC_TITLE'                => html_entity_decode(censor_text($this->get_data('topic_title')), ENT_COMPAT),
268   
269              'U_VIEW_POST'                => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
270              'U_NEWEST_POST'                => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}&e=1&view=unread#unread",
271              'U_TOPIC'                    => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}",
272              'U_VIEW_TOPIC'                => generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_parent_id}",
273              'U_FORUM'                    => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}",
274              'U_STOP_WATCHING_TOPIC'        => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&t={$this->item_parent_id}&unwatch=topic",
275          );
276      }
277   
278      /**
279      * Get the url to this item
280      *
281      * @return string URL
282      */
283      public function get_url()
284      {
285          return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}");
286      }
287   
288      /**
289      * {inheritDoc}
290      */
291      public function get_redirect_url()
292      {
293          return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_parent_id}&amp;view=unread#unread");
294      }
295   
296      /**
297      * Users needed to query before this notification can be displayed
298      *
299      * @return array Array of user_ids
300      */
301      public function users_to_query()
302      {
303          $responders = $this->get_data('responders');
304          $users = array(
305              $this->get_data('poster_id'),
306          );
307   
308          if (is_array($responders))
309          {
310              foreach ($responders as $responder)
311              {
312                  $users[] = $responder['poster_id'];
313              }
314          }
315   
316          return $this->trim_user_ary($users);
317      }
318   
319      /**
320      * Trim the user array passed down to 3 users if the array contains
321      * more than 4 users.
322      *
323      * @param array $users Array of users
324      * @return array Trimmed array of user_ids
325      */
326      public function trim_user_ary($users)
327      {
328          if (count($users) > 4)
329          {
330              array_splice($users, 3);
331          }
332          return $users;
333      }
334   
335      /**
336      * Pre create insert array function
337      * This allows you to perform certain actions, like run a query
338      * and load data, before create_insert_array() is run. The data
339      * returned from this function will be sent to create_insert_array().
340      *
341      * @param array $post Post data from submit_post
342      * @param array $notify_users Notify users list
343      *         Formatted from find_users_for_notification()
344      * @return array Whatever you want to send to create_insert_array().
345      */
346      public function pre_create_insert_array($post, $notify_users)
347      {
348          if (!count($notify_users) || !$this->inherit_read_status)
349          {
350              return array();
351          }
352   
353          $tracking_data = array();
354          $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . '
355              WHERE topic_id = ' . (int) $post['topic_id'] . '
356                  AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users));
357          $result = $this->db->sql_query($sql);
358          while ($row = $this->db->sql_fetchrow($result))
359          {
360              $tracking_data[$row['user_id']] = $row['mark_time'];
361          }
362          $this->db->sql_freeresult($result);
363   
364          return $tracking_data;
365      }
366   
367      /**
368      * {@inheritdoc}
369      */
370      public function create_insert_array($post, $pre_create_data = array())
371      {
372          $this->set_data('poster_id', $post['poster_id']);
373   
374          $this->set_data('topic_title', $post['topic_title']);
375   
376          $this->set_data('post_subject', $post['post_subject']);
377   
378          $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
379   
380          $this->set_data('forum_id', $post['forum_id']);
381   
382          $this->set_data('forum_name', $post['forum_name']);
383   
384          $this->notification_time = $post['post_time'];
385   
386          // Topics can be "read" before they are public (while awaiting approval).
387          // Make sure that if the user has read the topic, it's marked as read in the notification
388          if ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
389          {
390              $this->notification_read = true;
391          }
392   
393          parent::create_insert_array($post, $pre_create_data);
394      }
395   
396      /**
397      * Add responders to the notification
398      *
399      * @param mixed $post
400      * @return array Array of responder data
401      */
402      public function add_responders($post)
403      {
404          // Do not add them as a responder if they were the original poster that created the notification
405          if ($this->get_data('poster_id') == $post['poster_id'])
406          {
407              return array();
408          }
409   
410          $responders = $this->get_data('responders');
411   
412          $responders = ($responders === null) ? array() : $responders;
413   
414          // Do not add more than 25 responders,
415          // we trim the username list to "a, b, c and x others" anyway
416          // so there is no use to add all of them anyway.
417          if (count($responders) > 25)
418          {
419              return array();
420          }
421   
422          foreach ($responders as $responder)
423          {
424              // Do not add them as a responder multiple times
425              if ($responder['poster_id'] == $post['poster_id'])
426              {
427                  return array();
428              }
429          }
430   
431          $responders[] = array(
432              'poster_id'        => $post['poster_id'],
433              'username'        => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''),
434          );
435   
436          $this->set_data('responders', $responders);
437   
438          $serialized_data = serialize($this->get_data(false));
439   
440          // If the data is longer then 4000 characters, it would cause a SQL error.
441          // We don't add the username to the list if this is the case.
442          if (utf8_strlen($serialized_data) >= 4000)
443          {
444              return array();
445          }
446   
447          $data_array = array_merge(array(
448              'poster_id'        => $post['poster_id'],
449              'topic_title'    => $post['topic_title'],
450              'post_subject'    => $post['post_subject'],
451              'post_username'    => $post['post_username'],
452              'forum_id'        => $post['forum_id'],
453              'forum_name'    => $post['forum_name'],
454              'post_time'        => $post['post_time'],
455              'post_id'        => $post['post_id'],
456              'topic_id'        => $post['topic_id']
457          ), $this->get_data(false));
458   
459          return $data_array;
460      }
461  }
462