public function publishPendingDrafts() { $GLOBALS[bdSocialShare_Listener::XI_BLOG_MODEL_DRAFT_PUBLISH_PENDING] = $this; $response = parent::publishPendingDrafts(); /* @var $publisherModel bdSocialShare_Model_Publisher */ $publisherModel = $this->getModelFromCache('bdSocialShare_Model_Publisher'); /* @var $userModel XenForo_Model_User */ $userModel = $this->getModelFromCache('XenForo_Model_User'); foreach ($this->_bdSocialShare_publishPendingDrafts_drafts as $hash => &$draftDw) { $entryDw =& $this->_bdSocialShare_publishPendingDrafts_entries[$hash]; $scheduled = bdSocialShare_Helper_Common::unserializeOrFalse($draftDw->get('bdsocialshare_scheduled')); if (!empty($scheduled) and !empty($scheduled['targets'])) { if (empty($users[$entryDw->get('user_id')])) { $users[$entryDw->get('user_id')] = $userModel->getVisitingUserById($entryDw->get('user_id')); $users[$entryDw->get('user_id')] = $userModel->prepareUser($users[$entryDw->get('user_id')]); $users[$entryDw->get('user_id')]['permissions'] = XenForo_Permission::unserializePermissions($users[$entryDw->get('user_id')]['global_permission_cache']); } if (!empty($users[$entryDw->get('user_id')])) { $shareable = new bdSocialShare_Shareable_XI_Blog_Entry($entryDw); $publisherModel->publishScheduled($scheduled, $shareable, $users[$entryDw->get('user_id')]); $publisherModel->postPublish($shareable, false, $users[$entryDw->get('user_id')]); } } } return $response; }
public static function checkedOptInOptOutOff($systemOptionId, $visitorOptionsOfTarget) { $value = bdSocialShare_Helper_Common::getOptInOptOutOffEffectiveValue($systemOptionId, $visitorOptionsOfTarget); if (!empty($value)) { return ' checked="checked"'; } }
public function renderHtml() { if (isset($this->_params['draft'])) { $draft =& $this->_params['draft']; if (isset($draft['bdsocialshare_scheduled'])) { $draft['bdsocialshare_scheduled'] = bdSocialShare_Helper_Common::unserializeOrFalse($draft, 'bdsocialshare_scheduled'); } } return parent::renderHtml(); }
public static function visitor_setup(XenForo_Visitor &$visitor) { $options = $visitor->get('bdsocialshare_options'); if (!empty($options)) { $visitor['_bdSocialShare_options'] = bdSocialShare_Helper_Common::unserializeOrFalse($options); } else { $visitor['_bdSocialShare_options'] = array(); } $visitor['_bdSocialShare_canStaffShare'] = $visitor->hasPermission('general', 'bdSocialShare_staffShare'); }
public function awardUserTrophy(array $user, $username, array $trophy, $awardDate = null) { $response = parent::awardUserTrophy($user, $username, $trophy, $awardDate); $options = bdSocialShare_Helper_Common::unserializeOrFalse($user, 'bdsocialshare_options'); $supportedTargets = $this->getModelFromCache('bdSocialShare_Model_Publisher')->getSupportedTargets(); $targets = bdSocialShare_Helper_Common::getOptInOptOutOffTargets('trophyAward', $options, $supportedTargets); if (!empty($targets)) { $shareable = new bdSocialShare_Shareable_Trophy($trophy['trophy_id'], $user); $this->getModelFromCache('bdSocialShare_Model_ShareQueue')->insertQueue($shareable, $targets, false, $user); } return $response; }
public static function getTokenAndSecretFromAuth(array $auth) { $extraData = bdSocialShare_Helper_Common::unserializeOrFalse($auth, 'extra_data'); if (empty($extraData) or empty($extraData['token'])) { return false; } if (XenForo_Application::$versionId > 1030000) { // XenForo 1.3 stores token/secret diffrently from Social add-on $token = array('oauth_token' => $extraData['token'], 'oauth_token_secret' => $extraData['secret'], 'user_id' => $auth['provider_key'], 'screen_name' => sprintf('#%d', $auth['provider_key'])); } else { // Social add-on $token = $extraData['token']; } return $token; }
public function bdSocialShare_actionIcon(XenResource_DataWriter_Resource $resourceDw) { $resource = $resourceDw->getMergedData(); $queueDate = $resource['resource_date'] + bdSocialShare_Shareable_XenResource_Resource::SECONDS_WAIT_FOR_ICON; $shareQueueModel = $this->getModelFromCache('bdSocialShare_Model_ShareQueue'); $queue = $shareQueueModel->getQueueAt($queueDate); if (!empty($queue)) { foreach ($queue as $id => $record) { $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data'); if (!empty($data) and !empty($data['shareable'])) { $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']); if ($shareable instanceof bdSocialShare_Shareable_XenResource_Resource and $shareable->getId() == $resource['resource_id']) { $shareQueueModel->reInsertQueue($record, XenForo_Application::$time); } } } } unset($GLOBALS[bdSocialShare_Listener::XENRESOURCE_CONTROLLERPUBLIC_RESOURCE_ICON]); }
public static function getGroups($accessToken) { try { $client = XenForo_Helper_Http::getClient('https://graph.facebook.com/v2.0/me/groups'); $client->setParameterGet('access_token', $accessToken); $response = $client->request('GET'); $jsonDecoded = json_decode($response->getBody(), true); if (!empty($jsonDecoded['data'])) { $groups = array(); foreach ($jsonDecoded['data'] as $entry) { $groups[$entry['id']] = array('name' => $entry['name'], 'target_id' => bdSocialShare_Helper_Common::encryptTargetId($entry['name'], array('targetId' => $entry['id'], 'accessToken' => $accessToken, 'type' => 'group'))); } return $groups; } } catch (Zend_Http_Client_Exception $e) { if (XenForo_Application::debugMode()) { XenForo_Error::logException($e, false); } } return false; }
protected function _getFacebookPagesOrGroups($getPages = true) { $visitor = XenForo_Visitor::getInstance(); $facebookUid = bdSocialShare_Helper_Common::getAuthId($visitor->toArray(), 'facebook'); if (empty($facebookUid)) { return false; } $auth = $this->getModelFromCache('XenForo_Model_UserExternal')->getExternalAuthAssociation('facebook', $facebookUid); if (empty($auth)) { return false; } $extraData = bdSocialShare_Helper_Common::unserializeOrFalse($auth, 'extra_data'); if (empty($extraData) or empty($extraData['token'])) { return false; } $accessToken = $extraData['token']; if ($getPages) { return bdSocialShare_Helper_Facebook::getPages($accessToken); } else { return bdSocialShare_Helper_Facebook::getGroups($accessToken); } }
public static function renderThreadAuto(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit) { $templateObj = self::renderAuto($view, $fieldPrefix, $preparedOption, $canEdit); /* @var $nodeModel XenForo_Model_Node */ $nodeModel = XenForo_Model::create('XenForo_Model_Node'); /* @var $forumModel XenForo_Model_Forum */ $forumModel = $nodeModel->getModelFromCache('XenForo_Model_Forum'); $nodes = $nodeModel->getAllNodes(); $forumIds = array(); foreach ($nodes as $node) { if ($node['node_type_id'] === 'Forum') { $forumIds[] = $node['node_id']; } } $forums = $forumModel->getForumsByIds($forumIds); $configuredForums = array(); foreach ($forumIds as $forumId) { $forumRef =& $forums[$forumId]; $forumThreadAuto = bdSocialShare_Helper_Common::unserializeOrFalse($forumRef, 'bdsocialshare_threadauto'); if ($forumThreadAuto !== false) { $configuredForums[$forumId] = $forumRef; $configuredForums[$forumId]['_bdSocialShare_threadAuto'] = $forumThreadAuto; } } $ourTemplateParams = array('configuredForums' => $configuredForums); $ourTemplateObj = $view->createTemplateObject('bdsocialshare_option_threadauto_extra_html', $ourTemplateParams); $templateObj->setParam('_bdSocialShare_extraHtml', $ourTemplateObj); return $templateObj; }
public function doRecovery($target, $targetId, XenForo_Controller $controller) { switch ($target) { case 'facebook': $extraParams = array('publish_actions' => 1); $targetIdParsed = bdSocialShare_Helper_Common::parseTargetId($targetId); if (!empty($targetIdParsed) and !empty($targetIdParsed['type'])) { switch ($targetIdParsed['type']) { case 'page': $extraParams['manage_pages'] = 1; break; case 'group': $extraParams['user_groups'] = 1; break; } } $link = XenForo_Link::buildPublicLink('register/facebook', '', array_merge(array('reg' => 1), $extraParams)); return $controller->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $link); break; case 'twitter': $link = XenForo_Link::buildPublicLink('register/twitter', '', array_merge(array('reg' => 1))); return $controller->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $link); break; } return false; }
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 runQueue($targetRunTime = 0) { $s = microtime(true); $db = $this->_getDb(); do { $queue = $this->getQueue($targetRunTime ? 20 : 0); foreach ($queue as $id => $record) { if (!$db->delete('xf_bdsocialshare_share_queue', 'share_queue_id = ' . $db->quote($id))) { // already been deleted - run elsewhere continue; } $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data'); if (empty($data) or empty($data['shareable'])) { if (XenForo_Application::debugMode()) { XenForo_Error::logException(new XenForo_Exception('Insufficient data'), false); } continue; } $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']); if (empty($shareable)) { if (XenForo_Application::debugMode()) { XenForo_Error::logException(new XenForo_Exception('Unable to create shareable from recovery data'), false); } return false; } $userModel = $this->getModelFromCache('XenForo_Model_User'); if (!empty($data['user_id'])) { $viewingUser = $userModel->getVisitingUserById($data['user_id']); } else { $viewingUser = $userModel->getVisitingGuestUser(); } if (empty($viewingUser)) { if (XenForo_Application::debugMode()) { XenForo_Error::logException(new XenForo_Exception('User could not be found'), false); } return false; } $userModel->bdSocialShare_prepareViewingUser($viewingUser); $this->publish($shareable, $data['targets'], !empty($data['default']), $viewingUser); if ($targetRunTime && microtime(true) - $s > $targetRunTime) { $queue = false; break; } } } while ($queue); return $this->hasQueue(); }
public function actionSocialShareTestTwitter() { $this->assertAdminPermission('option'); $targetId = $this->_input->filterSingle('targetId', XenForo_Input::STRING); $targetIdParsed = bdSocialShare_Helper_Common::parseTargetId($targetId); if (!empty($targetIdParsed)) { $token = $targetIdParsed; } else { return $this->responseNoPermission(); } $targetInfo = bdSocialShare_Helper_Twitter::accountVerifyCredentials($token['oauth_token'], $token['oauth_token_secret']); if (!empty($targetInfo['screen_name'])) { $link = sprintf('https://twitter.com/%s', $targetInfo['screen_name']); } else { throw new bdSocialShare_Exception_Interrupted(serialize($targetInfo)); } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_UPDATED, $link); }
public function renderHtml() { $this->_params['_bdSocialShare_threadAuto'] = bdSocialShare_Helper_Common::unserializeOrFalse($this->_params['forum'], 'bdsocialshare_threadauto'); return parent::renderHtml(); }