Example #1
0
    public function Authorize()
    {
        $GLOBALS["APPLICATION"]->RestartBuffer();
        $bSuccess = 1;
        $appID = trim(self::GetOption("twitter_key"));
        $appSecret = trim(self::GetOption("twitter_secret"));
        if (!isset($_REQUEST["oauth_token"]) || $_REQUEST["oauth_token"] == '') {
            $tw = new CTwitterInterface($appID, $appSecret);
            $callback = CSocServUtil::GetCurUrl('auth_service_id=' . self::ID);
            //$callback = 'http://algerman.sam:6448/script.php?auth_service_id='.self::ID;
            if ($tw->GetRequestToken($callback)) {
                $tw->RedirectAuthUrl();
            }
        } elseif (CSocServAuthManager::CheckUniqueKey()) {
            $tw = new CTwitterInterface($appID, $appSecret, $_REQUEST["oauth_token"], $_REQUEST["oauth_verifier"]);
            if (($arResult = $tw->GetAccessToken()) !== false && $arResult["user_id"] != '') {
                $twUser = $tw->GetUserInfo($arResult["user_id"]);
                $first_name = $last_name = "";
                if ($twUser["name"] != '') {
                    $aName = explode(" ", $twUser["name"]);
                    $first_name = $aName[0];
                    if (isset($aName[1])) {
                        $last_name = $aName[1];
                    }
                }
                $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arResult["user_id"], 'LOGIN' => $arResult["screen_name"], 'NAME' => $first_name, 'LAST_NAME' => $last_name);
                if (isset($twUser["profile_image_url"]) && self::CheckPhotoURI($twUser["profile_image_url"])) {
                    if ($arPic = CFile::MakeFileArray($twUser["profile_image_url"])) {
                        $arFields["PERSONAL_PHOTO"] = $arPic;
                    }
                }
                $arFields["PERSONAL_WWW"] = "https://twitter.com/" . $arResult["screen_name"];
                if (strlen(SITE_ID) > 0) {
                    $arFields["SITE_ID"] = SITE_ID;
                }
                if (COption::GetOptionString('socialservices', 'last_twit_id', '1') == 1) {
                    if (isset($twUser["status"]["id_str"])) {
                        COption::SetOptionString('socialservices', 'last_twit_id', $twUser["status"]["id_str"]);
                    }
                }
                $bSuccess = $this->AuthorizeUser($arFields);
            }
        }
        $aRemove = array("logout", "auth_service_error", "auth_service_id", "oauth_token", "oauth_verifier", "check_key", "current_fieldset");
        $url = $GLOBALS['APPLICATION']->GetCurPageParam($bSuccess === true ? '' : 'auth_service_id=' . self::ID . '&auth_service_error=' . $bSuccess, $aRemove);
        if (CModule::IncludeModule("socialnetwork")) {
            $url = preg_match("/\\?/", $url) ? $url . "&current_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV";
        }
        echo '
<script type="text/javascript">
if(window.opener)
	window.opener.location = \'' . CUtil::JSEscape($url) . '\';
window.close();
</script>
';
        die;
    }
Example #2
0
	public function Authorize()
	{
		$GLOBALS["APPLICATION"]->RestartBuffer();
		$bSuccess = false;

		$appID = self::GetOption("twitter_key");
		$appSecret = self::GetOption("twitter_secret");

		if(!isset($_REQUEST["oauth_token"]) || $_REQUEST["oauth_token"] == '')
		{
			$tw = new CTwitterInterface($appID, $appSecret);
			$callback = CSocServUtil::GetCurUrl('auth_service_id='.self::ID);
			if($tw->GetRequestToken($callback))
				$tw->RedirectAuthUrl();
		}
		elseif(CSocServAuthManager::CheckUniqueKey())
		{
			$tw = new CTwitterInterface($appID, $appSecret, $_REQUEST["oauth_token"], $_REQUEST["oauth_verifier"]);
			if(($arResult = $tw->GetAccessToken()) !== false && $arResult["user_id"] <> '')
			{
				$twUser = $tw->GetUserInfo($arResult["user_id"]);

				$first_name = $last_name = "";
				if($twUser["name"] <> '')
				{
					$aName = explode(" ", $twUser["name"]);
					$first_name = $aName[0];
					if(isset($aName[1]))
						$last_name = $aName[1];
				}

				$arFields = array(
					'EXTERNAL_AUTH_ID' => self::ID,
					'XML_ID' => $arResult["user_id"],
					'LOGIN' => $arResult["screen_name"],
					'NAME'=> $first_name,
					'LAST_NAME'=> $last_name,
				);
				$arFields["PERSONAL_WWW"] = "https://twitter.com/".$twUser["screen_name"];

				$bSuccess = $this->AuthorizeUser($arFields);
			}
		}

		$aRemove = array("logout", "auth_service_error", "auth_service_id", "oauth_token", "oauth_verifier", "check_key");
		$url = $GLOBALS['APPLICATION']->GetCurPageParam(($bSuccess? '':'auth_service_id='.self::ID.'&auth_service_error=1'), $aRemove);
		echo '
<script type="text/javascript">
if(window.opener)
	window.opener.location = \''.CUtil::JSEscape($url).'\';
window.close();
</script>
';
		die();
	}