protected function _getTargets($optionId, $key) { $included = $this->_controller->getInput()->filterSingle('_bdSocialShare_included', XenForo_Input::UINT); $enabled = $this->_controller->getRequest()->getParam('_bdSocialShare_enabled'); $targets = array(); if (strval(bdSocialShare_Option::get($optionId)) !== '' and !empty($included)) { // only work if our template has been rendered properly // the flag `included` is used to determine that if (empty($enabled)) { $enabled = array(); } if ($key !== false) { // support request with multiple data items // therefore multiple enabled flag if (isset($enabled[$key])) { $enabled = $enabled[$key]; } else { $enabled = array(); } } foreach ($enabled as $target => $targetId) { if ($target === '_default') { continue; } if (!empty($targetId)) { $targets[$target] = $targetId; } } } return array('included' => !empty($included), 'targets' => $targets, 'default' => !empty($enabled['_default'])); }
public static function checked($noDefault, $scheduled, $target, $value = false) { $visitor = XenForo_Visitor::getInstance(); $checked = false; if (is_array($scheduled)) { // scheduled value has the highest priority if (!empty($scheduled['targets'][$target])) { if ($value === false or $value == $scheduled['targets'][$target]) { $checked = true; } } } else { if ($noDefault) { // no default flag is set } elseif (!bdSocialShare_Option::get('remember')) { // the remember option is not turned on } else { $visitorOptionValue = $visitor->get('bdsocialshare_' . $target); if (!empty($visitorOptionValue)) { if ($value === false) { // any value $checked = true; } else { $visitorOptions = self::getOptions($visitorOptionValue); if (in_array(strval($value), $visitorOptions, true)) { $checked = true; } } } } } if ($checked) { return ' checked="checked"'; } }
public static function getOptInOptOutOffEffectiveValue($systemOptionId, $visitorOptionsOfTarget) { if (isset($visitorOptionsOfTarget[$systemOptionId])) { return $visitorOptionsOfTarget[$systemOptionId]; } else { if (bdSocialShare_Option::get($systemOptionId) == 'optOut') { return '1'; } else { return ''; } } }
public function getPreConfiguredTargets() { $resource = $this->_resourceDw->getMergedData(); $visitor = XenForo_Visitor::getInstance(); if ($resource['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_resourceAut')) { $option = bdSocialShare_Option::get('resourceAddAuto'); if (is_array($option)) { return $option; } } return parent::getPreConfiguredTargets(); }
public function getPreConfiguredTargets() { $profilePost = $this->_profilePostDw->getMergedData(); if ($profilePost['user_id'] != $profilePost['profile_user_id']) { // not a status return parent::getPreConfiguredTargets(); } if (isset($profilePost['message_state']) and $profilePost['message_state'] !== 'visible') { // not visible, no auto share return parent::getPreConfiguredTargets(); } $visitor = XenForo_Visitor::getInstance(); if ($profilePost['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_statusAuto')) { $option = bdSocialShare_Option::get('statusAuto'); if (is_array($option)) { return $option; } } return parent::getPreConfiguredTargets(); }
public function actionView() { $customAccessDenied = bdSocialShare_Option::get('customAccessDenied'); if ($customAccessDenied) { $categoryModel = $this->getModelFromCache('XenResource_Model_Category'); $resourceModel = $this->getModelFromCache('XenResource_Model_Resource'); $categoryModel->bdSocialShare_setCanViewCategory(true); $resourceModel->bdSocialShare_setCanViewResource(true); } $response = parent::actionView(); if ($customAccessDenied and $response instanceof XenForo_ControllerResponse_View) { $paramsRef =& $response->params; $categoryModel->bdSocialShare_setCanViewCategory(null); $resourceModel->bdSocialShare_setCanViewResource(null); if (!$categoryModel->canViewCategory($paramsRef['category'], $errorPhraseKey) or !$resourceModel->canViewResource($paramsRef['resource'], $paramsRef['category'], $errorPhraseKey)) { $response = $this->getHelper('bdSocialShare_ControllerHelper_Content')->getErrorOrNoPermissionResponse($response, $errorPhraseKey); } } return $response; }
public function actionIndex() { $customAccessDenied = bdSocialShare_Option::get('customAccessDenied'); if ($customAccessDenied) { $forumModel = $this->getModelFromCache('XenForo_Model_Forum'); $threadModel = $this->getModelFromCache('XenForo_Model_Thread'); $forumModel->bdSocialShare_setCanViewForum(true); $threadModel->bdSocialShare_setCanViewThread(true); } $response = parent::actionIndex(); if ($customAccessDenied and $response instanceof XenForo_ControllerResponse_View) { $paramsRef =& $response->params; $forumModel->bdSocialShare_setCanViewForum(null); $threadModel->bdSocialShare_setCanViewThread(null); if (!$forumModel->canViewForum($paramsRef['forum'], $errorPhraseKey) or !$threadModel->canViewThread($paramsRef['thread'], $paramsRef['forum'], $errorPhraseKey)) { $response = $this->getHelper('bdSocialShare_ControllerHelper_Content')->getErrorOrNoPermissionResponse($response, $errorPhraseKey); } } return $response; }
public function publish($targetId, bdSocialShare_Shareable_Abstract $shareable, $accessToken) { try { $link = $shareable->getLink($this); $imageDataPath = $shareable->getImageDataPath($this); $userText = $shareable->getUserText($this); $title = $shareable->getTitle($this); $description = $shareable->getDescription($this); $image = $shareable->getImage($this); $userText = strval($userText); $title = strval($title); $description = strval($description); $sendLinkData = (bdSocialShare_Option::get('facebookSendLinkData') or $shareable instanceof bdSocialShare_Shareable_StaffShare); if ($sendLinkData and !empty($imageDataPath)) { // upload as a new photo in the app album $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/photos', $targetId)); $client->setFileUpload($imageDataPath, 'source'); $parts = array(); if (!empty($title)) { $parts[] = $title; } if (empty($parts)) { if (!empty($description)) { $parts[] = $description; } } if (!empty($link)) { $parts[] = $link; } if (!empty($parts)) { $client->setParameterPost('message', implode("\n", $parts)); } } if (empty($client) and !empty($link)) { // publish as a link $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/feed', $targetId)); $client->setParameterPost('link', $link); if ($sendLinkData and !empty($title)) { // send link data $client->setParameterPost('name', $title); if (!empty($image)) { $client->setParameterPost('picture', $image); } if (!empty($description)) { $client->setParameterPost('description', $description); } } if (!empty($userText)) { $client->setParameterPost('message', $userText); } } if (empty($client) and !empty($userText)) { // publish as a status $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/feed', $targetId)); if (!empty($link)) { // merge user text and link $client->setParameterPost('message', sprintf('%s %s', $userText, $link)); } else { $client->setParameterPost('message', $userText); } } if (empty($client)) { return false; } $client->setParameterPost('access_token', $accessToken); $response = $client->request('POST'); $responseBody = $response->getBody(); $responseArray = json_decode($responseBody, true); if (isset($responseArray['id'])) { return $responseArray; } else { throw new bdSocialShare_Exception_Interrupted($responseBody); } } catch (Zend_Http_Client_Exception $e) { throw new bdSocialShare_Exception_HttpClient($e->getMessage()); } // MUST NOT REACH HERE!!!! }
public function getPreConfiguredTargets() { $post = $this->_postDw->getMergedData(); if (isset($post['message_state']) and $post['message_state'] !== 'visible') { // not visible, no auto share return parent::getPreConfiguredTargets(); } if ($post['position'] == 0) { $visitor = XenForo_Visitor::getInstance(); if ($post['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_threadAuto')) { $threadDw = $this->_postDw->getDiscussionDataWriter(); if (!empty($threadDw)) { $forumData = $threadDw->bdSocialShare_getForumData(); $forumDataThreadAuto = bdSocialShare_Helper_Common::unserializeOrFalse($forumData, 'bdsocialshare_threadauto'); if ($forumDataThreadAuto !== false) { // forum configuration takes precedence return $forumDataThreadAuto; } else { // use system configuration $option = bdSocialShare_Option::get('threadAuto'); if (is_array($option)) { return $option; } } } } } return parent::getPreConfiguredTargets(); }
public function canQueue() { $optionDeferred = bdSocialShare_Option::get('deferred'); return !empty($optionDeferred); }