Example #1
0
 public function __construct($appID = false, $appSecret = false, $token = false, $tokenVerifier = false, $tokenSecret = false)
 {
     if ($appID === false) {
         $appID = trim(CSocServTwitter::GetOption("twitter_key"));
     }
     if ($appSecret === false) {
         $appSecret = trim(CSocServTwitter::GetOption("twitter_secret"));
     }
     $this->httpTimeout = SOCSERV_DEFAULT_HTTP_TIMEOUT;
     $this->appID = $appID;
     $this->appSecret = $appSecret;
     $this->token = $token;
     $this->tokenVerifier = $tokenVerifier;
     if ($this->token && isset($_SESSION["twitter_token_secret"])) {
         $this->tokenSecret = $_SESSION["twitter_token_secret"];
     }
     if ($this->token && $tokenSecret) {
         $this->tokenSecret = $tokenSecret;
     }
 }
 function GetTwitMessages($lastTwitId = "1", $counter = 1)
 {
     $oAuthManager = new CSocServAuthManager();
     $arActiveSocServ = $oAuthManager->GetActiveAuthServices(array());
     if (!(isset($arActiveSocServ["Twitter"]) && isset($arActiveSocServ["Twitter"]["__active"])) || !function_exists("hash_hmac")) {
         return false;
     }
     if (!CModule::IncludeModule("socialnetwork")) {
         return "CSocServAuthManager::GetTwitMessages(\"{$lastTwitId}\", {$counter});";
     }
     global $USER;
     $bTmpUserCreated = false;
     if (!isset($USER) || !($USER instanceof CUser && 'CUser' == get_class($USER))) {
         $bTmpUserCreated = true;
         if (isset($USER)) {
             $USER_TMP = $USER;
             unset($USER);
         }
         $USER = new CUser();
     }
     if (intval($lastTwitId) <= 1 || $counter == 1) {
         $lastTwitId = COption::GetOptionString('socialservices', 'last_twit_id', '1');
     }
     $socServUserArray = self::GetUserArray('Twitter');
     $arSiteId = array();
     if (isset($socServUserArray[3]) && is_array($socServUserArray[3])) {
         $arSiteId = $socServUserArray[3];
     }
     $twitManager = new CSocServTwitter();
     $arUserTwit = $twitManager->GetUserMessage($socServUserArray, $lastTwitId);
     if (!empty($arUserTwit["statuses"])) {
         $lastTwitId = self::PostIntoBuzz($arUserTwit, $lastTwitId, $arSiteId);
     } elseif (is_array($arUserTwit["search_metadata"]) && isset($arUserTwit["search_metadata"]["max_id_str"]) && strlen($arUserTwit["search_metadata"]["max_id_str"]) > 0) {
         $lastTwitId = $arUserTwit["search_metadata"]["max_id_str"];
     }
     $counter++;
     if ($counter >= 20) {
         COption::SetOptionString('socialservices', 'last_twit_id', $lastTwitId);
         $counter = 1;
     }
     $lastTwitId = preg_replace("|\\D|", '', $lastTwitId);
     if ($bTmpUserCreated) {
         unset($USER);
         if (isset($USER_TMP)) {
             $USER = $USER_TMP;
             unset($USER_TMP);
         }
     }
     return "CSocServAuthManager::GetTwitMessages(\"{$lastTwitId}\", {$counter});";
 }
Example #3
0
	function GetTwitMessages($siteId=SITE_ID)
	{
		if(!CModule::IncludeModule("socialnetwork"))
			return "CSocServAuthManager::GetTwitMessages($siteId);";
		global $USER;
		if (!is_object($USER)) $USER = new CUser;
		$lastTwitId = COption::GetOptionString('socialservices','last_twit_id','1');
		$socServUserArray = self::GetUserArray('Twitter');
		$twitManager = new CSocServTwitter();
		$arUserTwit = $twitManager->GetUserMessage($socServUserArray, $lastTwitId);
		if(!empty($arUserTwit["statuses"]))
			self::PostIntoBuzz($arUserTwit, $lastTwitId, $siteId);
		elseif((strlen($arUserTwit["search_metadata"]["max_id_str"]) > 0) && ((COption::GetOptionString('socialservices','last_twit_id','1')).'/' !== ($arUserTwit["search_metadata"]["max_id_str"]).'/'))
			COption::SetOptionString('socialservices', 'last_twit_id', $arUserTwit["search_metadata"]["max_id_str"]);
		return "CSocServAuthManager::GetTwitMessages($siteId);";
	}