public function actionSocialShareFacebookTargets() { $this->assertAdminPermission('option'); if (!bdSocialShare_Option::hasPermissionFacebook()) { return $this->responseError(new XenForo_Phrase('bdsocialshare_facebook_must_be_configured')); } $viewParams = array('type' => 'facebook', 'accounts' => $this->getModelFromCache('bdSocialShare_Model_Facebook')->getAccounts()); return $this->responseView('bdSocialShare_ViewAdmin_Tools_Targets', 'bdsocialshare_tools_targets', $viewParams); }
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); }
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; }