Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

topic.php

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