<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Notification_Moderator_ReportedPost extends vB_Notification_Moderator { const TYPENAME = 'ReportedPost'; protected static $triggers = [ 'node-reported-post' => 20, ]; protected $notifyBitfieldName = 'reportedpost'; protected $emailBitfieldName = 'reportedpost'; protected function overwriteRule() { return 'always'; } final protected static function defineUnique($notificationData, $skipValidation) { $items = []; $items['senderid'] = (int) $notificationData['sender']; $items['sentbynodeid'] = (int) $notificationData['sentbynodeid']; return $items; } public static function fetchPhraseArray($notificationData) { $customData = self::normalizeCustomData($notificationData['customdata']); $senderUrl = ''; try { $senderUrl = vB5_Route::buildUrl('profile|fullurl', [ 'userid' => $notificationData['senderid'], 'username' => $notificationData['sender_username'], ]); } catch (Throwable $e){} $nodeUrl = ''; try { $nodeUrl = vB5_Route::buildUrl('node|fullurl', [ 'nodeid' => $notificationData['sentbynodeid'] ]); } catch (Throwable $e){} $userid = $notificationData['sender']; $phraseVarName = 'ab_reported_post_cd_reason_e'; $phraseData = [ $senderUrl, $notificationData['sender_musername'], $nodeUrl, $notificationData['aboutstartertitle'], vB_String::htmlSpecialCharsUni($customData['reason']), $userid, ]; return [ $phraseVarName, $phraseData, ]; } public static function renderEmailPhrases($data) { $assertor = vB::getDbAssertor(); $customData = self::normalizeCustomData($data['customdata']); $phraseAPI = vB_Api::instanceInternal('phrase'); $nodeUrl = ''; try { $nodeUrl = vB5_Route::buildUrl('node|fullurl', [ 'nodeid' => $data['sentbynodeid'] ]); } catch (Throwable $e){} if (!empty($data['sender'])) { $senderLabel = vB_User::getEmailUserLabel($data['sender']); } else { $phrase = 'a_guest_cap'; $sender = $phraseAPI->renderPhrasesNoShortcode([$phrase => $phrase], $data['languageid']); $senderLabel = $sender['phrases'][$phrase]; } $title = ''; if (!empty($data['aboutstartertitle'])) { $title = $data['aboutstartertitle']; } else if (!empty($data['sentbynodeid'])) { $node = $assertor->getRow('vBForum:node', ['nodeid' => $data['sentbynodeid']]); if (!empty($node['title'])) { $title = $node['title']; } else { $node = $assertor->getRow('vBForum:node', ['nodeid' => $node['starter']]); if (!empty($node['title'])) { $title = $node['title']; } } } $vboptions = vB::getDatastore()->getValue('options'); $string = vB::getString(); $bbtitle_escaped = $string->htmlspecialchars($vboptions['bbtitle']); $maildata = $phraseAPI->fetchEmailPhrases( 'notification_reportedpost', [ $string->htmlspecialchars($data['recipient_displayname']), $senderLabel, $nodeUrl, nl2br($string->htmlspecialchars($customData['reason'])), $bbtitle_escaped, ], [vB_String::unHtmlSpecialChars($title)], $data['languageid'] ); return $maildata; } protected function populateUsersToNotify() { if ($this->usersToNotify === null) { parent::populateUsersToNotify(); $reportedNodeid = $this->notificationData['sentbynodeid']; $relevantModerators = []; $nodeLib = vB_Library::instance('node'); $channelMods = $nodeLib->getNodeModerators($reportedNodeid); foreach ($channelMods AS $moderator) { $relevantModerators[$moderator['userid']] = $moderator['userid']; } $superModsAndAdmins = $nodeLib->getForumSupermoderatorsAdmins($relevantModerators); foreach ($superModsAndAdmins AS $moderator) { $relevantModerators[$moderator['userid']] = $moderator['userid']; } foreach ($this->usersToNotify['notify'][$this->notifyBitfieldName] AS $__userid => $__useridAgain) { if (!isset($relevantModerators[$__userid])) { unset($this->usersToNotify['notify'][$this->notifyBitfieldName][$__userid]); } } foreach ($this->usersToNotify['email'][$this->emailBitfieldName] AS $__userid => $__useridAgain) { if (!isset($relevantModerators[$__userid])) { unset($this->usersToNotify['email'][$this->emailBitfieldName][$__userid]); } } } } } 