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 helpConfiguration($oauthToken, $oauthTokenSecret) { list($consumerKey, $consumerSecret) = bdSocialShare_Option::getTwitterConsumerPair(); $twitter = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret); $response = $twitter->get('help/configuration'); $responseArray = (array) $response; return $responseArray; }
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 actionStaffShare() { $visitor = XenForo_Visitor::getInstance(); if (!$visitor->hasPermission('general', 'bdSocialShare_staffShare')) { return $this->responseNoPermission(); } $url = $this->_input->filterSingle('url', XenForo_Input::STRING); if (empty($url)) { return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare_UrlForm', 'bdsocialshare_staff_share_url_form'); } $request = new Zend_Controller_Request_Http($url); $request->setParamSources(array()); $routeMatch = bdSocialShare_Listener::getDependencies()->route($request); $shareable = $this->getModelFromCache('bdSocialShare_Model_Publisher')->getShareableForRouteMatchAndRequest($routeMatch, $request); if (empty($shareable)) { return $this->responseMessage(new XenForo_Phrase('bdsocialshare_url_x_is_not_supported', array('url' => $url))); } $userModel = $this->getModelFromCache('XenForo_Model_User'); $viewingUserGuest = $userModel->getVisitingGuestUser(); $userModel->bdSocialShare_prepareViewingUser($viewingUserGuest); $shareable->setViewingUser($viewingUserGuest); $publisherModel = $this->getModelFromCache('bdSocialShare_Model_Publisher'); $facebookAccounts = false; if (bdSocialShare_Option::hasPermissionFacebook($viewingUserGuest)) { $facebookAccounts = $this->getModelFromCache('bdSocialShare_Model_Facebook')->getAccounts(); } $twitterAccounts = false; if (bdSocialShare_Option::hasPermissionTwitter($viewingUserGuest)) { $twitterAccounts = $this->getModelFromCache('bdSocialShare_Model_Twitter')->getAccounts(); } if ($this->isConfirmedPost()) { $target = $this->_input->filterSingle('target', XenForo_Input::STRING); $targetId = $this->_input->filterSingle('target_id', XenForo_Input::STRING); $data = $this->_input->filter(array('userText' => XenForo_Input::STRING, 'title' => XenForo_Input::STRING, 'description' => XenForo_Input::STRING, 'image' => XenForo_Input::STRING)); $data['link'] = $shareable->getLink($publisherModel); $staffShareSharable = new bdSocialShare_Shareable_StaffShare($data); $published = false; try { $published = $publisherModel->publish($target, $targetId, $staffShareSharable, $viewingUserGuest); } catch (XenForo_Exception $e) { XenForo_Error::logException($e); } if ($published) { XenForo_Model_Log::logModeratorAction('bdsocialshare_all', $data, $target, array('target_id' => $targetId)); return $this->responseMessage(new XenForo_Phrase('bdsocialshare_staff_share_published_successfully')); } else { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } } $viewParams = array('facebookAccounts' => $facebookAccounts, 'twitterAccounts' => $twitterAccounts, 'hasAdminPermissionOption' => $visitor->hasAdminPermission('option'), 'url' => $url, 'link' => $shareable->getLink($publisherModel), 'userText' => strval($shareable->getUserText($publisherModel)), 'title' => strval($shareable->getTitle($publisherModel)), 'description' => strval($shareable->getDescription($publisherModel)), 'image' => $shareable->getImage($publisherModel)); return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare', 'bdsocialshare_staff_share', $viewParams); }
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!!!! }
protected function _postPublish_getUserOptionChanges(bdSocialShare_Shareable_Abstract $shareable, array $viewingUser = null) { $this->standardizeViewingUserReference($viewingUser); $changes = array(); if (bdSocialShare_Option::hasPermissionFacebook($viewingUser)) { $optionFacebookNeeded = false; if ($shareable->isPublished('facebook')) { $published = $shareable->getPublishedExtraData('facebook'); // notice the use of original_target_id instead of target_id here // sometimes (page posting), target_id will be extracted from original_target_id // through a series of parsing. The original is the important bit that worth // saving. $optionFacebookNeeded = $published['original_target_id']; } else { $optionFacebookNeeded = ''; } if (!isset($viewingUser['bdsocialshare_facebook']) or strval($viewingUser['bdsocialshare_facebook']) !== strval($optionFacebookNeeded)) { $changes['bdsocialshare_facebook'] = $optionFacebookNeeded; } } if (bdSocialShare_Option::hasPermissionTwitter($viewingUser)) { $optionTwitterNeeded = false; if ($shareable->isPublished('twitter')) { $published = $shareable->getPublishedExtraData('twitter'); // the usage of original_target_id is similar to Facebook routine above $optionTwitterNeeded = $published['original_target_id']; } else { $optionTwitterNeeded = ''; } if (!isset($viewingUser['bdsocialshare_twitter']) or strval($viewingUser['bdsocialshare_twitter']) !== strval($optionTwitterNeeded)) { $changes['bdsocialshare_twitter'] = $optionTwitterNeeded; } } return $changes; }
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); }
public function actionSocialShareTwitterTargets() { $this->assertAdminPermission('option'); if (!bdSocialShare_Option::hasPermissionTwitter()) { return $this->responseError(new XenForo_Phrase('bdsocialshare_twitter_must_be_configured')); } $viewParams = array('type' => 'twitter', 'accounts' => $this->getModelFromCache('bdSocialShare_Model_Twitter')->getAccounts()); return $this->responseView('bdSocialShare_ViewAdmin_Tools_Targets', 'bdsocialshare_tools_targets', $viewParams); }