<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Notification_Content_UserMention extends vB_Notification_Content { protected static $triggers = array( 'new-content' => 20, ); const TYPENAME = 'UserMention'; protected function validateProvidedRecipients($recipients) { return array(); } final protected static function defineUnique($notificationData, $skipValidation) { $nodeid = $notificationData['sentbynodeid']; return array('nodeid' => (int) $nodeid); } protected function addAdditionalRecipients() { $nodeid = $this->notificationData['sentbynodeid']; $node = vB_Library::instance('node')->getNode($nodeid, false, true); $usermentions = array(); if (isset($node['rawtext'])) { $find = array( '#\[QUOTE[^\]]*\].*\[/QUOTE\]#siU', '#\[NOPARSE\].*\[/NOPARSE\]#siU', ); $replace = ''; $rawTextForUserMentions = preg_replace($find, $replace, $node['rawtext']); if (preg_match_all('#\[USER=(["\'])?([0-9]+)(\1)?\](.*)\[/USER\]#siU', $rawTextForUserMentions, $matches, PREG_SET_ORDER)) { foreach ($matches AS $match) { $userid = (int) $match[2]; $usermentions[$userid] = $userid; } } unset($rawTextForUserMentions, $find, $replace, $matches); } return $usermentions; } protected function checkExtraPermissionsForSender($sender) { $globallyEnabled = (bool) vB::getDatastore()->getOption('notification_usermention_enabled'); $userGroupEnabled = true; return ($globallyEnabled AND $userGroupEnabled); } protected function typeEnabledForUser($user) { static $bf_masks; if (empty($bf_masks)) { $bf_masks = vB::getDatastore()->getValue('bf_misc_usernotificationoptions'); } return ((bool) ($user['notification_options'] & $bf_masks['general_usermention'])); } public static function fetchPhraseArray($notificationData) { $nodelink = vB5_Route::buildUrl('node|fullurl', ['nodeid' => $notificationData['sentbynodeid']]); if (empty($notificationData['sender']) OR is_null($notificationData['sender_username'])) { $phraseTitle = 'guest_mentioned_you_in_post'; $phraseData = [ $nodelink, $notificationData['aboutstartertitle'] ]; } else { $userid = $notificationData['sender']; $username = $notificationData['sender_username']; $userInfo = ['userid' => $userid, 'username' => $username]; try { $userProfileUrl = vB5_Route::buildUrl('profile|fullurl', $userInfo); } catch (Exception $e) { $userProfileUrl = "#"; } $phraseTitle = 'x_mentioned_you_in_post'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $nodelink, $notificationData['aboutstartertitle'] ]; } return [$phraseTitle, $phraseData]; } public static function generateNotificationQueueKey($notificationData) { return parent::generateNotificationQueueKey($notificationData); } } 