protected function validateAndCleanNotificationData($notificationData) { // Very similar to the vB_Notification_Content, but has to skip the "channel" check since // VM's go to their own channel. Instead, there's a isVisitorMessage() check. $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); // we need to get the full content, to ensure 'channeltype' is there. if (!isset($node['nodeid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } if (!isset($node['setfor'])) { throw new Exception("Invalid Node Data: setfor"); } // only explictly specified content types are allowed to send notifications $topLevelContentTypes = array('Gallery' => 1, 'Link' => 1, 'Poll' => 1, 'Text' => 1, 'Video' => 1); $contenttypeclass = vB_Types::instance()->getContentTypeClass($node['contenttypeid']); if (!isset($topLevelContentTypes[$contenttypeclass])) { throw new Exception("Cannot send this notification for the node's content type."); } // Only allow visitor messages. /* // node lib's fetchClosureParent() does not seem functional for the 2nd param that content lib's isVisitorMessage() // relies on, VBV-14367. Let's just check the closure table directly for now. $contentLib = vB_Library::instance('Content_' . vB_Types::instance()->getContentTypeClass($node['contenttypeid'])); if (!$contentLib->isVisitorMessage($nodeid)) { throw new Exception("Not a visitor message."); } */ $vmChannel = vB_Library::instance('node')->fetchVMChannel(); $closureCheck = vB::getDbAssertor()->getRows('vBForum:closure', array('child' => $nodeid, 'parent' => $vmChannel)); if (empty($closureCheck)) { throw new Exception("Not a visitor message."); } // We're good if we got to this point. $newData['sentbynodeid'] = (int) $node['nodeid']; if (!isset($node['userid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } $newData['sender'] = (int) $node['userid']; return $newData; }
protected final function validateAndCleanNotificationData($notificationData) { $newData = parent::validateAndCleanNotificationData($notificationData); unset($notificationData); if (!isset($newData['sender'])) { throw new Exception("Missing Notification Data: sender"); } // sender cannot be a guest, as guests cannot have relations with members ATM. if (empty($newData['sender'])) { throw new Exception("Invalid Notification Data: sender"); } $newData['sentbynodeid'] = NULL; /* If we could, we'd also check recipients here, but recipients are added later */ return $newData; }
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); // we need to get the full content, to ensure 'channeltype' is there. if (!isset($node['nodeid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } // Don't send notification if it's not visible to a "regular" user. if (!($node['showpublished'] and $node['showapproved'])) { throw new Exception("Invalid Notification Data: showpublished or showapproved"); } // The sentbynodeid MUST BE A POLL TYPE $topLevelContentTypes = array('Poll' => 1); $contenttypeclass = vB_Types::instance()->getContentTypeClass($node['contenttypeid']); if (!isset($topLevelContentTypes[$contenttypeclass])) { throw new Exception("Cannot send this notification for the node's content type."); } // Let's restrict it to certain channel types, just in case we can create polls anywhere. // Keep this in sync with vB_Channel::$channelTypes $allowedChannelTypes = array('forum' => 1, 'blog' => 1, 'article' => 1, 'group' => 1); if (!isset($allowedChannelTypes[$node['channeltype']])) { throw new Exception("Cannot send this notification for the node's channel type."); } // We're good if we got to this point. $newData['sentbynodeid'] = (int) $node['nodeid']; // Sender must be specified when constructing this type. Set by parent::validateAndCleanNotificationData() if (!isset($newData['sender'])) { throw new Exception("Invalid Notification Data: sender"); } return $newData; }
/** * Validates the notification data, checks the context to see if we should send this * notification type, and throws exceptions if we should not or cannot send this notification * type. If all is okay, it may set additional notification data specific to this notification type. * * @param Array $notificationData * * @throws Exception() If for some reason this notification type cannot be sent given * the context data in $notificationData * * @access protected */ 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); // we need to get the full content, to ensure 'channeltype' is there. if (!isset($node['nodeid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } // Don't send notification if it's not visible to a "regular" user. if (!($node['showpublished'] and $node['showapproved'])) { throw new Exception("Invalid Notification Data: showpublished or showapproved"); } // only explictly specified content types are allowed to send notifications $topLevelContentTypes = array('Gallery' => 1, 'Link' => 1, 'Poll' => 1, 'Text' => 1, 'Video' => 1); $contenttypeclass = vB_Types::instance()->getContentTypeClass($node['contenttypeid']); if (!isset($topLevelContentTypes[$contenttypeclass])) { throw new Exception("Cannot send this notification for the node's content type."); } // Similar to above, but for channeltypes. Keep this in sync with vB_Channel::$channelTypes $allowedChannelTypes = array('forum' => 1, 'blog' => 1, 'article' => 1, 'group' => 1); if (!isset($allowedChannelTypes[$node['channeltype']])) { throw new Exception("Cannot send this notification for the node's channel type."); } // We're good if we got to this point. $newData['sentbynodeid'] = (int) $node['nodeid']; if (!isset($node['userid'])) { throw new Exception("Invalid Notification Data: sentbynodeid"); } $newData['sender'] = (int) $node['userid']; return $newData; }