public static function prepareDiscoveryParams(array &$params, Zend_Controller_Response_Http $response, $topicType, $topicId, $selfLink, $subscriptionOption) { if (!bdApi_Option::getSubscription($topicType)) { // subscription for this topic type has been disabled return false; } // subscription discovery $hubLink = bdApi_Data_Helper_Core::safeBuildApiLink('subscriptions', null, array('hub.topic' => bdApi_Model_Subscription::getTopic($topicType, $topicId), 'oauth_token' => '')); $response->setHeader('Link', sprintf('<%s>; rel=hub', $hubLink)); $response->setHeader('Link', sprintf('<%s>; rel=self', $selfLink)); // subscription info if (!empty($subscriptionOption)) { $subscriptionOption = @unserialize($subscriptionOption); if (!empty($subscriptionOption['subscriptions'])) { /* @var $session bdApi_Session */ $session = XenForo_Application::getSession(); $clientId = $session->getOAuthClientId(); foreach ($subscriptionOption['subscriptions'] as $subscription) { if ($subscription['client_id'] == $clientId) { $params['subscription_callback'] = $subscription['callback']; } } } } return true; }
public function resetUnreadAlertsCounter($userId) { if (bdApi_Option::getSubscription(bdApi_Model_Subscription::TYPE_NOTIFICATION)) { // subscription for alert is enabled $userOption = $this->bdApi_getUserNotificationOption($userId); if (!empty($userOption)) { /* @var $subscriptionModel bdApi_Model_Subscription */ $subscriptionModel = $this->getModelFromCache('bdApi_Model_Subscription'); $subscriptionModel->ping($userOption, 'read', bdApi_Model_Subscription::TYPE_NOTIFICATION, 0); } } parent::resetUnreadAlertsCounter($userId); }
protected function _bdApi_pingUser($action) { if (!bdApi_Option::getSubscription(bdApi_Model_Subscription::TYPE_USER)) { // subscription for user has been disabled return false; } $userOption = $this->get('bdapi_user'); if (!empty($userOption)) { $userOption = @unserialize($userOption); if (!empty($userOption)) { /* @var $subscriptionModel bdApi_Model_Subscription */ $subscriptionModel = $this->getModelFromCache('bdApi_Model_Subscription'); $subscriptionModel->ping($userOption, $action, bdApi_Model_Subscription::TYPE_USER, $this->get('user_id')); } } return true; }
protected function _bdApi_pingThreadPost($action) { if (!bdApi_Option::getSubscription(bdApi_Model_Subscription::TYPE_THREAD_POST)) { // subscription for thread post has been disabled return false; } $thread = $this->getDiscussionData(); if (!empty($thread['bdapi_thread_post'])) { $threadOption = @unserialize($thread['bdapi_thread_post']); if (!empty($threadOption)) { /* @var $subscriptionModel bdApi_Model_Subscription */ $subscriptionModel = $this->getModelFromCache('bdApi_Model_Subscription'); $subscriptionModel->ping($threadOption, $action, bdApi_Model_Subscription::TYPE_THREAD_POST, $this->get('post_id')); } } return true; }
protected function _postSave() { if ($this->isInsert() && bdApi_Option::getSubscription(bdApi_Model_Subscription::TYPE_NOTIFICATION)) { /* @var $subscriptionModel bdApi_Model_Subscription */ $subscriptionModel = $this->getModelFromCache('bdApi_Model_Subscription'); $alertedUserId = $this->get('alerted_user_id'); if ($alertedUserId > 0) { /* @var $alertModel bdApi_XenForo_Model_Alert */ $alertModel = $this->getModelFromCache('XenForo_Model_Alert'); $option = $alertModel->bdApi_getUserNotificationOption($this->get('alerted_user_id')); } else { $option = $subscriptionModel->getClientSubscriptionsData(); } if (!empty($option)) { $subscriptionModel->ping($option, 'insert', bdApi_Model_Subscription::TYPE_NOTIFICATION, $this->get('alert_id')); } } parent::_postSave(); }
public function insertConversationAlert(array $conversation, array $alertUser, $action, array $triggerUser = null, array $extraData = null, array &$messageInfo = null) { parent::insertConversationAlert($conversation, $alertUser, $action, $triggerUser, $extraData, $messageInfo); if (!bdApi_Option::getSubscription(bdApi_Model_Subscription::TYPE_NOTIFICATION) || !bdApi_Option::get('userNotificationConversation')) { return; } if (!$triggerUser) { $triggerUser = array('user_id' => $conversation['last_message_user_id'], 'username' => $conversation['last_message_username']); } if ($triggerUser['user_id'] == $alertUser['user_id']) { return; } if (empty($extraData)) { $extraData = array(); } $extraData['object_data'] = array('notification_id' => 0, 'notification_html' => ''); $extraData['object_data']['message'] = array('conversation_id' => $conversation['conversation_id'], 'title' => $conversation['title'], 'message' => XenForo_Template_Helper_Core::callHelper('snippet', array($messageInfo['message'], 140, array('stripQuote' => true)))); if (isset($extraData['message_id'])) { $extraData['object_data']['message']['message_id'] = $extraData['message_id']; } else { $extraData['object_data']['message']['message_id'] = $conversation['first_message_id']; } $fakeAlert = array('alert_id' => 0, 'alerted_user_id' => $alertUser['user_id'], 'user_id' => $triggerUser['user_id'], 'username' => $triggerUser['username'], 'content_type' => 'conversation', 'content_id' => $conversation['conversation_id'], 'action' => $action, 'event_date' => XenForo_Application::$time, 'view_date' => 0, 'extra_data' => serialize($extraData)); if ($fakeAlert['alerted_user_id'] > 0) { /* @var $alertModel bdApi_XenForo_Model_Alert */ $alertModel = $this->getModelFromCache('XenForo_Model_Alert'); $option = $alertModel->bdApi_getUserNotificationOption($fakeAlert['alerted_user_id']); } if (!empty($option)) { if ($fakeAlert['user_id'] == XenForo_Visitor::getUserId()) { $fakeAlert = array_merge($fakeAlert, XenForo_Visitor::getInstance()->toArray()); } else { /** @var XenForo_Model_User $userModel */ $userModel = $this->getModelFromCache('XenForo_Model_User'); $user = $userModel->getUserById($fakeAlert['user_id']); $fakeAlert = array_merge($fakeAlert, $user); } /* @var $subscriptionModel bdApi_Model_Subscription */ $subscriptionModel = $this->getModelFromCache('bdApi_Model_Subscription'); $subscriptionModel->ping($option, 'insert', bdApi_Model_Subscription::TYPE_NOTIFICATION, $fakeAlert); } return; }
public function isValidTopic(&$topic, array $viewingUser = null) { $this->standardizeViewingUserReference($viewingUser); list($type, $id) = self::parseTopic($topic); if ($type != self::TYPE_CLIENT && !bdApi_Option::getSubscription($type)) { // subscription for this topic type has been disabled return false; } switch ($type) { case self::TYPE_NOTIFICATION: if ($id === 'me') { // now supports user_notification_me $id = $viewingUser['user_id']; $topic = self::getTopic($type, $id); } return $id > 0 and $id == $viewingUser['user_id']; case self::TYPE_THREAD_POST: /* @var $threadModel XenForo_Model_Thread */ $threadModel = $this->getModelFromCache('XenForo_Model_Thread'); $thread = $threadModel->getThreadById($id); return $thread['user_id'] == $viewingUser['user_id']; case self::TYPE_USER: if ($id === 'me') { // now supports user_me $id = $viewingUser['user_id']; $topic = self::getTopic($type, $id); } return $id > 0 and $id == $viewingUser['user_id']; case self::TYPE_CLIENT: $session = bdApi_Data_Helper_Core::safeGetSession(); return $session->getOAuthClientId() !== ''; } return false; }