public function getShortUrlLengthHttps($token) { $data = XenForo_Application::getSimpleCacheData(self::SIMPLE_CACHE_DATA_KEY_SHORT_URL_LENGTH_HTTPS); if (empty($data) or XenForo_Application::$time - $data['timestamp'] > 86400) { $response = bdSocialShare_Helper_Twitter::helpConfiguration($token['oauth_token'], $token['oauth_token_secret']); if (!empty($response['short_url_length_https'])) { $data = array('value' => $response['short_url_length_https'], 'timestamp' => time()); XenForo_Application::setSimpleCacheData(self::SIMPLE_CACHE_DATA_KEY_SHORT_URL_LENGTH_HTTPS, $data); } else { // for some reason we cannot get configuration from Twitter, // return our best guess then: as of September 13, 2014 it is 23 return 30; } } return $data['value']; }
public function twitterPublish($targetId, bdSocialShare_Shareable_Abstract $shareable, array $viewingUser = null) { $twitterUid = false; $token = false; $originalTargetId = $targetId; $targetIdParsed = bdSocialShare_Helper_Common::parseTargetId($targetId); if (!empty($targetIdParsed)) { $targetId = $targetIdParsed['user_id']; $token = $targetIdParsed; } if (empty($token)) { $this->standardizeViewingUserReference($viewingUser); $twitterUid = bdSocialShare_Helper_Common::getAuthId($viewingUser, 'twitter'); if (empty($twitterUid)) { throw new bdSocialShare_Exception_NotConnected(); } $auth = $this->_getUserExternalModel()->getExternalAuthAssociation('twitter', $twitterUid); if (empty($auth)) { throw new bdSocialShare_Exception_NotConnected(); } $token = bdSocialShare_Helper_Twitter::getTokenAndSecretFromAuth($auth); if (empty($token)) { throw new bdSocialShare_Exception_Interrupted(); } } if (strval($targetId) === '1') { if (!empty($twitterUid)) { $targetId = $twitterUid; } } $response = $this->_getTwitterModel()->publish($targetId, $shareable, $token); if (!empty($response)) { // successfully posted $shareable->markPublished('twitter', array_merge($response, array('target_id' => $targetId, 'shared_id' => $response['id_str'], 'original_target_id' => $originalTargetId))); $this->log($viewingUser['user_id'], $shareable, 'twitter', $targetId, $response['id_str']); return true; } return false; }
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); }