<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Notification_Content_Quote extends vB_Notification_Content { protected static $triggers = array( 'new-content' => 30, ); const TYPENAME = 'Quote'; 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); $quotedUsers = array(); if (isset($node['rawtext'])) { $find = array( '#\[NOPARSE\].*\[/NOPARSE\]#siU', ); $replace = ''; $rawtext = preg_replace($find, $replace, $node['rawtext']); if (preg_match_all('#\[QUOTE=(?<username>[^\]]+)(;(?<node>(n?\d+)))?\](?<content>.*)\[/QUOTE\]#siU', $rawtext, $matches)) { if (!empty($matches['username'])) { $options = vB::getDatastore()->getValue('options'); $fetchUsers = array(); foreach ($matches['username'] AS $key => $username) { if (empty($matches['node'][$key]) AND !empty($matches['content'][$key])) { $limit = (int) $options['maxuserlength']; $limit -= vB_String::vbStrlen($username); $limit += 20; $content = vB_String::vbChop($matches['content'][$key], $limit); if (preg_match('/^(.*)(?<!&#[0-9]{3}|&#[0-9]{4}|&#[0-9]{5});\s*n\d+\s*\]/U', $content, $match2)) { $len = strlen($match2[1]); $username .= ']' . substr($matches['content'][$key], 0, $len); } } $fetchUsers[$username] = $username; } $useridsQuery = vB::getDbAssertor()->getRows('user', array( vB_dB_Query::COLUMNS_KEY => array('userid', 'username'), 'username' => $fetchUsers )); foreach($useridsQuery AS $row) { $quotedUsers[$row['userid']] = $row['userid']; } } } unset($rawtext, $find, $replace, $matches); } return $quotedUsers; } 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_quote'])); } 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_quoted_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_quoted_you_in_post'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $nodelink, $notificationData['aboutstartertitle'] ]; } return [$phraseTitle, $phraseData]; } public static function renderEmailPhrases($data) { $nodeid = $data['sentbynodeid']; $node = vB_Library::instance("node")->getNodeFullContent($nodeid); $node = $node[$nodeid]; if (empty($node['startertitle'])) { return false; } if (!empty($data['sender'])) { $mailPhrasePrefix = "notification_quote"; $senderLabel = vB_User::getEmailUserLabel($data['sender']); } else { $mailPhrasePrefix = "notification_quote_guest"; $senderLabel = ''; } $string = vB::getString(); $nodeurl = vB5_Route::buildUrl('node|fullurl', array('nodeid' => $nodeid)); $previewText = vB_Mail::getPreviewTextForEmail($node['rawtext'], $node['htmlstate'] ?? 'off', $string); $previewText = vB_Mail::wrapPreviewTextForEmail($previewText, $data['languageid']); $options = vB::getDatastore()->getValue('options'); $bbtitle_escaped = $string->htmlspecialchars($options['bbtitle']); $settingsURL = vB5_Route::buildUrl('settings|fullurl', ['tab' => 'notifications']); $maildata = vB_Api::instanceInternal('phrase')->fetchEmailPhrases( $mailPhrasePrefix, [ $string->htmlspecialchars($data['recipient_displayname']), $senderLabel, $nodeurl, $previewText, $bbtitle_escaped, $settingsURL, ], [vB_String::unHtmlSpecialChars($node['startertitle'])], $data['languageid'] ); return $maildata; } } 