[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/notification/type/ -> topic.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  * Topic notifications class
  18  * This class handles notifications for new topics
  19  */
  20  
  21  class topic extends \phpbb\notification\type\base
  22  {
  23      /**
  24      * Get notification type name
  25      *
  26      * @return string
  27      */
  28  	public function get_type()
  29      {
  30          return 'notification.type.topic';
  31      }
  32  
  33      /**
  34      * Language key used to output the text
  35      *
  36      * @var string
  37      */
  38      protected $language_key = 'NOTIFICATION_TOPIC';
  39  
  40      /**
  41      * Inherit notification read status from topic.
  42      *
  43      * @var bool
  44      */
  45      protected $inherit_read_status = true;
  46  
  47      /**
  48      * Notification option data (for outputting to the user)
  49      *
  50      * @var bool|array False if the service should use it's default data
  51      *                     Array of data (including keys 'id', 'lang', and 'group')
  52      */
  53      public static $notification_option = array(
  54          'lang'    => 'NOTIFICATION_TYPE_TOPIC',
  55          'group'    => 'NOTIFICATION_GROUP_POSTING',
  56      );
  57  
  58      /**
  59      * Is available
  60      */
  61  	public function is_available()
  62      {
  63          return $this->config['allow_forum_notify'];
  64      }
  65  
  66      /**
  67      * Get the id of the item
  68      *
  69      * @param array $post The data from the post
  70      */
  71  	public static function get_item_id($post)
  72      {
  73          return (int) $post['topic_id'];
  74      }
  75  
  76      /**
  77      * Get the id of the parent
  78      *
  79      * @param array $post The data from the post
  80      */
  81  	public static function get_item_parent_id($post)
  82      {
  83          return (int) $post['forum_id'];
  84      }
  85  
  86      /**
  87      * Find the users who want to receive notifications
  88      *
  89      * @param array $topic Data from the topic
  90      * @param array $options Options for finding users for notification
  91      *
  92      * @return array
  93      */
  94  	public function find_users_for_notification($topic, $options = array())
  95      {
  96          $options = array_merge(array(
  97              'ignore_users'            => array(),
  98          ), $options);
  99  
 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'), false, true);
 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          $this->db->sql_freeresult($result);
 261  
 262          return $tracking_data;
 263      }
 264  
 265      /**
 266      * Function for preparing the data for insertion in an SQL query
 267      * (The service handles insertion)
 268      *
 269      * @param array $post Data from submit_post
 270      * @param array $pre_create_data Data from pre_create_insert_array()
 271      *
 272      * @return array Array of data ready to be inserted into the database
 273      */
 274  	public function create_insert_array($post, $pre_create_data = array())
 275      {
 276          $this->set_data('poster_id', $post['poster_id']);
 277  
 278          $this->set_data('topic_title', $post['topic_title']);
 279  
 280          $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''));
 281  
 282          $this->set_data('forum_name', $post['forum_name']);
 283  
 284          $this->notification_time = $post['post_time'];
 285  
 286          // Topics can be "read" before they are public (while awaiting approval).
 287          // Make sure that if the user has read the topic, it's marked as read in the notification
 288          if ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
 289          {
 290              $this->notification_read = true;
 291          }
 292  
 293          return parent::create_insert_array($post, $pre_create_data);
 294      }
 295  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1