<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Notification_LikedNode extends vB_Notification { protected static $triggers = array( 'node-reputation-vote' => 20, ); protected static $updateEvents = array( 'read_topic', 'read_channel', 'soft_deleted_node', 'physically_deleted_node', 'deleted_user', ); const TYPENAME = 'LikedNode'; protected function validateProvidedRecipients($recipients) { return array(); } protected function validateAndCleanNotificationData($notificationData) { $newData = parent::validateAndCleanNotificationData($notificationData); unset($notificationData); if (!isset($newData['sentbynodeid'])) { throw new Exception("Missing Notification Data: sentbynodeid"); } $nodeid = $newData['sentbynodeid']; $node = vB_Library::instance('node')->getNode($nodeid, false, true); if (!isset($node['nodeid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } if (!($node['showpublished'] AND $node['showapproved'])) { throw new Exception("Invalid Notification Data: showpublished or showapproved"); } $this->validateSourceContentType($node['contenttypeid']); $this->validateSourceChannelType($node['channeltype']); $newData['sentbynodeid'] = (int) $node['nodeid']; if (!isset($newData['sender'])) { throw new Exception("Invalid Notification Data: sender"); } return $newData; } protected function overwriteRule() { return 'always'; } final protected static function defineUnique($notificationData, $skipValidation) { return array('liked_nodeid' => (int) $notificationData['sentbynodeid']); } protected function addAdditionalRecipients() { $nodeid = $this->notificationData['sentbynodeid']; $node = vB_Library::instance('node')->getNodeBare($nodeid); if (!empty($node['userid']) AND $node['userid'] != $this->notificationData['sender']) { return array($node['userid']); } return array(); } 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_likespost'])); } public static function fetchPhraseArray($notificationData) { $nodelink = vB5_Route::buildUrl('node|fullurl', array('nodeid' => $notificationData['sentbynodeid'])); $phraseTitle = "missing phrase for " . __CLASS__; $phraseData = array(); if ($notificationData['showdetail']) { if (empty($notificationData['sender']) OR is_null($notificationData['sender_username'])) { switch ($notificationData['otherRatersCount']) { case 0: $phraseTitle = 'guest_rated_y'; $phraseData = array( $nodelink, $notificationData['aboutstartertitle'] ); break; case 1: $phraseTitle = 'guest_and_one_other_rated_y'; $phraseData = array( $notificationData['sentbynodeid'], $nodelink, $notificationData['aboutstartertitle'] ); break; default: $phraseTitle = 'guest_and_y_others_rated_z'; $phraseData = array( $notificationData['sentbynodeid'], $notificationData['otherRatersCount'], $nodelink, $notificationData['aboutstartertitle'] ); break; } } 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 = "#"; } switch ($notificationData['otherRatersCount']) { case 0: $phraseTitle = 'x_rated_y'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $nodelink, $notificationData['aboutstartertitle'] ]; break; case 1: $phraseTitle = 'x_and_one_other_rated_y'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $notificationData['sentbynodeid'], $nodelink, $notificationData['aboutstartertitle'] ]; break; default: $phraseTitle = 'x_and_y_others_rated_z'; $phraseData = [ $userProfileUrl, $userid, $notificationData['sender_musername'], $notificationData['sentbynodeid'], $notificationData['otherRatersCount'], $nodelink, $notificationData['aboutstartertitle'] ]; break; } } } else { switch ($notificationData['totalRatersCount']) { case 1: $phraseTitle = 'one_user_rated_x'; $phraseData = array( $nodelink, $notificationData['aboutstartertitle'] ); break; default: $phraseTitle = 'x_users_rated_y'; $phraseData = array( $notificationData['totalRatersCount'], $nodelink, $notificationData['aboutstartertitle'] ); break; } } return array($phraseTitle, $phraseData); } } 