/forum/phpbb/notification/type/report_post.php

https://github.com/AJenbo/ubuntudanmark.dk · PHP · 230 lines · 102 code · 26 blank · 102 comment · 2 complexity · f24a27e265489a768cfa642534f5cd07 MD5 · raw file

  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. namespace phpbb\notification\type;
  14. /**
  15. * Reported post notifications class
  16. * This class handles notifications for reported posts
  17. */
  18. class report_post extends \phpbb\notification\type\post_in_queue
  19. {
  20. /**
  21. * Get notification type name
  22. *
  23. * @return string
  24. */
  25. public function get_type()
  26. {
  27. return 'notification.type.report_post';
  28. }
  29. /**
  30. * Get the CSS style class of the notification
  31. *
  32. * @return string
  33. */
  34. public function get_style_class()
  35. {
  36. return 'notification-reported';
  37. }
  38. /**
  39. * Language key used to output the text
  40. *
  41. * @var string
  42. */
  43. protected $language_key = 'NOTIFICATION_REPORT_POST';
  44. /**
  45. * Inherit notification read status from post.
  46. *
  47. * @var bool
  48. */
  49. protected $inherit_read_status = false;
  50. /**
  51. * Permission to check for (in find_users_for_notification)
  52. *
  53. * @var string Permission name
  54. */
  55. protected $permission = 'm_report';
  56. /**
  57. * Notification option data (for outputting to the user)
  58. *
  59. * @var bool|array False if the service should use it's default data
  60. * Array of data (including keys 'id' and 'lang')
  61. */
  62. public static $notification_option = array(
  63. 'id' => 'notification.type.report',
  64. 'lang' => 'NOTIFICATION_TYPE_REPORT',
  65. 'group' => 'NOTIFICATION_GROUP_MODERATION',
  66. );
  67. /**
  68. * Find the users who want to receive notifications
  69. *
  70. * @param array $post Data from the post
  71. * @param array $options Options for finding users for notification
  72. *
  73. * @return array
  74. */
  75. public function find_users_for_notification($post, $options = array())
  76. {
  77. $notify_users = parent::find_users_for_notification($post, $options);
  78. // never notify reporter
  79. unset($notify_users[$this->user->data['user_id']]);
  80. return $notify_users;
  81. }
  82. /**
  83. * Get email template
  84. *
  85. * @return string|bool
  86. */
  87. public function get_email_template()
  88. {
  89. return 'report_post';
  90. }
  91. /**
  92. * Get email template variables
  93. *
  94. * @return array
  95. */
  96. public function get_email_template_variables()
  97. {
  98. $board_url = generate_board_url();
  99. return array(
  100. 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
  101. 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
  102. 'U_VIEW_REPORT' => "{$board_url}/mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&amp;p={$this->item_id}&amp;i=reports&amp;mode=report_details#reports",
  103. 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
  104. 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread",
  105. 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
  106. 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
  107. 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}",
  108. );
  109. }
  110. /**
  111. * Get the url to this item
  112. *
  113. * @return string URL
  114. */
  115. public function get_url()
  116. {
  117. return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&amp;p={$this->item_id}&amp;i=reports&amp;mode=report_details#reports");
  118. }
  119. /**
  120. * Get the HTML formatted title of this notification
  121. *
  122. * @return string
  123. */
  124. public function get_title()
  125. {
  126. $this->user->add_lang('mcp');
  127. $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
  128. return $this->user->lang(
  129. $this->language_key,
  130. $username
  131. );
  132. }
  133. /**
  134. * Get the HTML formatted reference of the notification
  135. *
  136. * @return string
  137. */
  138. public function get_reference()
  139. {
  140. return $this->user->lang(
  141. 'NOTIFICATION_REFERENCE',
  142. censor_text($this->get_data('post_subject'))
  143. );
  144. }
  145. /**
  146. * Get the reason for the notification
  147. *
  148. * @return string
  149. */
  150. public function get_reason()
  151. {
  152. if ($this->get_data('report_text'))
  153. {
  154. return $this->user->lang(
  155. 'NOTIFICATION_REASON',
  156. $this->get_data('report_text')
  157. );
  158. }
  159. if (isset($this->user->lang[$this->get_data('reason_title')]))
  160. {
  161. return $this->user->lang(
  162. 'NOTIFICATION_REASON',
  163. $this->user->lang[$this->get_data('reason_title')]
  164. );
  165. }
  166. return $this->user->lang(
  167. 'NOTIFICATION_REASON',
  168. $this->get_data('reason_description')
  169. );
  170. }
  171. /**
  172. * Get the user's avatar
  173. */
  174. public function get_avatar()
  175. {
  176. return $this->user_loader->get_avatar($this->get_data('reporter_id'), false, true);
  177. }
  178. /**
  179. * Users needed to query before this notification can be displayed
  180. *
  181. * @return array Array of user_ids
  182. */
  183. public function users_to_query()
  184. {
  185. return array($this->get_data('reporter_id'));
  186. }
  187. /**
  188. * Function for preparing the data for insertion in an SQL query
  189. * (The service handles insertion)
  190. *
  191. * @param array $post Data from submit_post
  192. * @param array $pre_create_data Data from pre_create_insert_array()
  193. *
  194. * @return array Array of data ready to be inserted into the database
  195. */
  196. public function create_insert_array($post, $pre_create_data = array())
  197. {
  198. $this->set_data('reporter_id', $this->user->data['user_id']);
  199. $this->set_data('reason_title', strtoupper($post['reason_title']));
  200. $this->set_data('reason_description', $post['reason_description']);
  201. $this->set_data('report_text', $post['report_text']);
  202. return parent::create_insert_array($post, $pre_create_data);
  203. }
  204. }