2
0

MemberReport-Notify.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * This task handles notifying users when another member's profile gets reported.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2014 Simple Machines and individual contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. class MemberReport_Notify_Background extends SMF_BackgroundTask
  15. {
  16. public function execute()
  17. {
  18. global $smcFunc, $sourcedir, $modSettings, $language, $scripturl;
  19. // Anyone with moderate_forum can see this report
  20. require_once($sourcedir . '/Subs-Members.php');
  21. $members = membersAllowedTo('moderate_forum');
  22. // And don't send it to them if they're the one who reported it.
  23. $members = array_diff($members, array($this->_details['sender_id']));
  24. // Having successfully figured this out, now let's get the preferences of everyone.
  25. require_once($sourcedir . '/Subs-Notify.php');
  26. $prefs = getNotifyPrefs($members, 'member_report', true);
  27. // So now we find out who wants what.
  28. $alert_bits = array(
  29. 'alert' => 0x01,
  30. 'email' => 0x02,
  31. );
  32. $notifies = array();
  33. foreach ($prefs as $member => $pref_option)
  34. {
  35. foreach ($alert_bits as $type => $bitvalue)
  36. if ($pref_option['member_report'] & $bitvalue)
  37. $notifies[$type][] = $member;
  38. }
  39. // Firstly, anyone who wants alerts.
  40. if (!empty($notifies['alert']))
  41. {
  42. // Alerts are relatively easy.
  43. $insert_rows = array();
  44. foreach ($notifies['alert'] as $member)
  45. {
  46. $insert_rows[] = array(
  47. 'alert_time' => $this->_details['time'],
  48. 'id_member' => $member,
  49. 'id_member_started' => $this->_details['sender_id'],
  50. 'member_name' => $this->_details['sender_name'],
  51. 'content_type' => 'profile',
  52. 'content_id' => $this->_details['user_id'],
  53. 'content_action' => 'report',
  54. 'is_read' => 0,
  55. 'extra' => serialize(
  56. array(
  57. 'report_link' => '?action=moderate;area=memberreports;report=' . $this->_details['report_id'], // We don't put $scripturl in these!
  58. 'user_name' => $this->_details['membername'],
  59. )
  60. ),
  61. );
  62. }
  63. $smcFunc['db_insert']('insert',
  64. '{db_prefix}user_alerts',
  65. array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int',
  66. 'member_name' => 'string', 'content_type' => 'string', 'content_id' => 'int',
  67. 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
  68. $insert_rows,
  69. array('id_alert')
  70. );
  71. // And update the count of alerts for those people.
  72. updateMemberData($notifies['alert'], array('alerts' => '+'));
  73. }
  74. // Secondly, anyone who wants emails.
  75. if (!empty($notifies['email']))
  76. {
  77. // Emails are a bit complicated. We have to do language stuff.
  78. require_once($sourcedir . '/Subs-Post.php');
  79. require_once($sourcedir . '/ScheduledTasks.php');
  80. loadEssentialThemeData();
  81. // First, get everyone's language and details.
  82. $emails = array();
  83. $request = $smcFunc['db_query']('', '
  84. SELECT id_member, lngfile, email_address
  85. FROM {db_prefix}members
  86. WHERE id_member IN ({array_int:members})',
  87. array(
  88. 'members' => $notifies['email'],
  89. )
  90. );
  91. while ($row = $smcFunc['db_fetch_assoc']($request))
  92. {
  93. if (empty($row['lngfile']))
  94. $row['lngfile'] = $language;
  95. $emails[$row['lngfile']][$row['id_member']] = $row['email_address'];
  96. }
  97. $smcFunc['db_free_result']($request);
  98. // Iterate through each language, load the relevant templates and set up sending.
  99. foreach ($emails as $this_lang => $recipients)
  100. {
  101. $replacements = array(
  102. 'MEMBERNAME' => $member_name,
  103. 'REPORTERNAME' => $this->_details['sender_name'],
  104. 'PROFILELINK' => $scripturl . '?action=profile;u=' . $this->_details['user_id'],
  105. 'REPORTLINK' => $scripturl . '?action=moderate;area=reports;report=' . $this->_details['report_id'],
  106. 'COMMENT' => $this->_details['comment'],
  107. );
  108. $emaildata = loadEmailTemplate('report_member_profile', $replacements, empty($modSettings['userLanguage']) ? $language : $this_lang);
  109. // And do the actual sending...
  110. foreach ($recipients as $id_member => $email_address)
  111. sendmail($email_address, $emaildata['subject'], $emaildata['body'], null, 'ureport' . $this->_details['report_id'], false, 2);
  112. }
  113. }
  114. // And now we're all done.
  115. return true;
  116. }
  117. }
  118. ?>