[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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 static public $notification_option = array( 54 'lang' => 'NOTIFICATION_TYPE_TOPIC', 55 'group' => 'NOTIFICATION_GROUP_POSTING', 56 ); 57 58 /** @var \phpbb\user_loader */ 59 protected $user_loader; 60 61 /** @var \phpbb\config\config */ 62 protected $config; 63 64 public function set_config(\phpbb\config\config $config) 65 { 66 $this->config = $config; 67 } 68 69 public function set_user_loader(\phpbb\user_loader $user_loader) 70 { 71 $this->user_loader = $user_loader; 72 } 73 74 /** 75 * Is available 76 */ 77 public function is_available() 78 { 79 return $this->config['allow_forum_notify']; 80 } 81 82 /** 83 * Get the id of the item 84 * 85 * @param array $post The data from the post 86 * @return int The topic id 87 */ 88 static public function get_item_id($post) 89 { 90 return (int) $post['topic_id']; 91 } 92 93 /** 94 * Get the id of the parent 95 * 96 * @param array $post The data from the post 97 * @return int The forum id 98 */ 99 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |