6 const ID =
"Odnoklassniki";
14 array(
"odnoklassniki_appid",
GetMessage(
"socserv_odnoklassniki_client_id"),
"", Array(
"text", 40)),
15 array(
"odnoklassniki_appkey",
GetMessage(
"socserv_odnoklassniki_client_key"),
"", Array(
"text", 40)),
16 array(
"odnoklassniki_appsecret",
GetMessage(
"socserv_odnoklassniki_client_secret"),
"", Array(
"text", 40)),
33 return '<a href="javascript:void(0)
" onclick="BX.util.popup(\
''.
htmlspecialcharsbx(CUtil::JSEscape(
$url)).
'\', 580, 400)
" class="bx-ss-button odnoklassniki-button
"></a><span class="bx-spacer
"></span><span>'.$phrase.'</span>';
36 public function GetOnClickJs($arParams)
38 $url = $this->getUrl('opener', null, $arParams);
39 return "BX.util.popup(
'".CUtil::JSEscape($url)."', 580, 400)
";
43 public function getUrl($location = 'opener', $addScope = null, $arParams = array())
47 $this->entityOAuth = new COdnoklassnikiInterface();
49 if(IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME'))
51 $redirect_uri = self::CONTROLLER_URL."/redirect.php
";
52 $state = \CHTTP::URN2URI("/bitrix/tools/oauth/odnoklassniki.php
")."?state=
";
53 $backurl = urlencode($GLOBALS["APPLICATION
"]->GetCurPageParam('check_key='.\CSocServAuthManager::getUniqueKey(), array("logout
", "auth_service_error
", "auth_service_id
", "backurl
"))).'&mode='.$location;
54 $state .= urlencode(urlencode("backurl=
".$backurl));
58 $backurl = $APPLICATION->GetCurPageParam(
59 'check_key='.\CSocServAuthManager::getUniqueKey(),
60 array("logout
", "auth_service_error
", "auth_service_id
", "backurl
")
62 $redirect_uri = \CHTTP::URN2URI("/bitrix/tools/oauth/odnoklassniki.php
");
63 $state = 'site_id='.SITE_ID.'&backurl='.urlencode($backurl).(isset($arParams['BACKURL']) ? '&redirect_url='.urlencode($arParams['BACKURL']) : '').'&mode='.$location;
66 return $this->entityOAuth->GetAuthUrl($redirect_uri, $state);
69 public function Authorize()
73 $APPLICATION->RestartBuffer();
74 $bSuccess = SOCSERV_AUTHORISATION_ERROR;
75 $bProcessState = false;
77 if((isset($_REQUEST["code
"]) && $_REQUEST["code
"] <> '') && CSocServAuthManager::CheckUniqueKey())
79 $bProcessState = true;
81 if(IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME'))
82 $redirect_uri = self::CONTROLLER_URL."/redirect.php
";
84 $redirect_uri= \CHTTP::URN2URI("/bitrix/tools/oauth/odnoklassniki.php
");
86 $appID = trim(self::GetOption("odnoklassniki_appid
"));
87 $appSecret = trim(self::GetOption("odnoklassniki_appsecret
"));
88 $appKey = trim(self::GetOption("odnoklassniki_appkey
"));
90 $gAuth = new COdnoklassnikiInterface($appID, $appSecret, $appKey, $_REQUEST["code
"]);
92 if($gAuth->GetAccessToken($redirect_uri) !== false)
94 $arOdnoklUser = $gAuth->GetCurrentUser();
96 if(is_array($arOdnoklUser) && ($arOdnoklUser['uid'] <> ''))
98 $uid = $arOdnoklUser['uid'];
99 $first_name = $last_name = $gender = "";
100 if($arOdnoklUser['first_name'] <> '')
101 $first_name = $arOdnoklUser['first_name'];
102 if($arOdnoklUser['last_name'] <> '')
103 $last_name = $arOdnoklUser['last_name'];
104 if(isset($arOdnoklUser['gender']) && $arOdnoklUser['gender'] != '')
106 if($arOdnoklUser['gender'] == 'male')
108 elseif($arOdnoklUser['gender'] == 'female')
113 'EXTERNAL_AUTH_ID' => self::ID,
114 'XML_ID' => "OK
".$uid,
115 'LOGIN' => "OKuser
".$uid,
116 'NAME'=> $first_name,
117 'LAST_NAME'=> $last_name,
118 'PERSONAL_GENDER' => $gender,
120 if(isset($arOdnoklUser['birthday']))
121 if($date = MakeTimeStamp($arOdnoklUser['birthday'], "YYYY-MM-DD
"))
122 $arFields["PERSONAL_BIRTHDAY
"] = ConvertTimeStamp($date);
123 if(isset($arOdnoklUser['pic_2']) && self::CheckPhotoURI($arOdnoklUser['pic_2']))
125 if($arPic = CFile::MakeFileArray($arOdnoklUser['pic_2']))
127 $arPic['name'] = md5($arOdnoklUser['pic_2']).'.jpg';
128 $arFields["PERSONAL_PHOTO
"] = $arPic;
131 $arFields["PERSONAL_WWW
"] = "http:
146 $aRemove =
array(
"logout",
"auth_service_error",
"auth_service_id",
"code",
"error_reason",
"error",
"error_description",
"check_key",
"current_fieldset");
153 if(isset($arState[
'backurl']) || isset($arState[
'redirect_url']))
155 $parseUrl = parse_url(!empty($arState[
'redirect_url']) ? $arState[
'redirect_url'] : $arState[
'backurl']);
156 $urlPath = $parseUrl[
"path"];
157 $arUrlQuery = explode(
'&', $parseUrl[
"query"]);
159 foreach($arUrlQuery as
$key => $value)
161 foreach($aRemove as $param)
163 if(mb_strpos($value, $param.
"=") === 0)
165 unset($arUrlQuery[
$key]);
171 $url = (!empty($arUrlQuery)) ? $urlPath.
'?'.implode(
"&", $arUrlQuery) : $urlPath;
174 if(isset($arState[
'mode']))
176 $mode = $arState[
'mode'];
185 elseif($bSuccess !==
true)
187 $url = (isset($parseUrl))
188 ? $urlPath.
'?auth_service_id='.self::ID.
'&auth_service_error='.$bSuccess
189 :
$APPLICATION->GetCurPageParam((
'auth_service_id='.self::ID.
'&auth_service_error='.$bSuccess), $aRemove);
192 if(CModule::IncludeModule(
"socialnetwork") && mb_strpos(
$url,
"current_fieldset=") ===
false)
193 $url = (preg_match(
"/\?/",
$url)) ?
$url.
"¤t_fieldset=SOCSERV" :
$url.
"?current_fieldset=SOCSERV";
196 $location = ($mode ==
"opener") ?
'if(window.opener) window.opener.location = \''.$url.
'\'; window.close();
' : ' window.location = \
''.$url.
'\';
';
206 CMain::FinalActions();
209 public static function SendUserFeed($userId, $message)
211 $appID = trim(self::GetOption("odnoklassniki_appid"));
212 $appSecret = trim(self::GetOption("odnoklassniki_appsecret"));
213 $appKey = trim(self::GetOption("odnoklassniki_appkey"));
214 $gAuth = new COdnoklassnikiInterface($appID, $appSecret, $appKey);
215 $result = $gAuth->SendFeed($userId, $message);
221class COdnoklassnikiInterface
223 const AUTH_URL = "https://www.odnoklassniki.ru/oauth/authorize";
224 const TOKEN_URL = "https://api.odnoklassniki.ru/oauth/token.do";
225 const CONTACTS_URL = "https://api.odnoklassniki.ru/fb.do";
228 protected $appSecret;
230 protected $code = false;
231 protected $access_token = false;
232 protected $sign = false;
233 protected $refresh_token = '';
234 protected $userId = 0;
236 public function __construct($appID = false, $appSecret = false, $appKey = false, $code=false)
240 $appID = trim(CSocServLiveIDOAuth::GetOption("odnoklassniki_appid"));
243 if($appSecret === false)
245 $appSecret = trim(CSocServLiveIDOAuth::GetOption("odnoklassniki_appsecret"));
248 if($appKey === false)
250 $appKey = trim(CSocServLiveIDOAuth::GetOption("odnoklassniki_appkey"));
253 $this->httpTimeout = SOCSERV_DEFAULT_HTTP_TIMEOUT;
254 $this->appID = $appID;
255 $this->appSecret = $appSecret;
257 $this->appKey = $appKey;
260 public function GetAuthUrl($redirect_uri, $state='')
262 return self::AUTH_URL.
263 "?client_id=".urlencode($this->appID).
264 "&redirect_uri=".urlencode($redirect_uri).
265 "&response_type=code".
266 ($state <> ''? '&state=
'.urlencode($state):'');
269 public function GetAccessToken($redirect_uri)
271 if($this->code === false)
274 $result = CHTTP::sPostHeader(self::TOKEN_URL, array(
276 "client_id"=>$this->appID,
277 "client_secret"=>$this->appSecret,
278 "redirect_uri"=>$redirect_uri,
279 "grant_type"=>"authorization_code",
280 ), array(), $this->httpTimeout);
282 $arResult = CUtil::JsObjectToPhp($result);
284 if(isset($arResult["access_token"]) && $arResult["access_token"] <> '')
286 $this->access_token = $arResult["access_token"];
287 $_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token);
288 if(isset($arResult["refresh_token"]) && $arResult["refresh_token"] <> '')
290 $this->refresh_token = $arResult["refresh_token"];
291 $_SESSION["OAUTH_DATA"]["REFRESH_TOKEN"] = $this->refresh_token;
294 $arguments = array();
295 $arguments["application_key"] = $this->appKey;
296 $arguments['method
'] = 'users.getCurrentUser
';
298 $this->sign = mb_strtolower(md5('application_key=
'.$arguments["application_key"].'method=
'.$arguments['method
'].md5($this->access_token.$this->appSecret)));
304 public function GetCurrentUser()
306 if($this->access_token === false)
309 $result = CHTTP::sGetHeader(self::CONTACTS_URL."?method=users.getCurrentUser&application_key=".$this->appKey."&access_token=".$this->access_token."&sig=".$this->sign, array(), $this->httpTimeout);
311 return CUtil::JsObjectToPhp($result);
314 public function SendFeed($socServUserId, $message, $getNewToken=true)
316 if(!$this->access_token || intval($this->userId) < 1)
317 self::SetOauthKeys($socServUserId);
319 $this->sign = mb_strtolower(md5('application_key=
'.$this->appKey.'method=users.setStatusstatus=
'.$message.md5($this->access_token.$this->appSecret)));
320 $result = CHTTP::sGetHeader(self::CONTACTS_URL."?method=users.setStatus&application_key=".$this->appKey."&access_token=".$this->access_token."&sig=".$this->sign."&status=".urlencode($message), array(), $this->httpTimeout);
322 $arResult = CUtil::JsObjectToPhp($result);
323 if($getNewToken === true && isset($arResult["error_code"]) && $arResult["error_code"] == "102")
325 $newToken = self::RefreshToken($socServUserId);
326 if($newToken === true)
327 self::SendFeed($socServUserId, $message, false);
334 private function SetOauthKeys($socServUserId)
336 $dbSocservUser = \Bitrix\Socialservices\UserTable::getList([
337 'filter
' => ['=ID
' => $socServUserId],
338 'select' => ["OATOKEN", "XML_ID", "REFRESH_TOKEN"]
340 while($arOauth = $dbSocservUser->fetch())
342 $this->access_token = $arOauth["OATOKEN"];
343 $this->userId = preg_replace("|\D|", '', $arOauth["XML_ID"]);
344 $this->refresh_token = $arOauth["REFRESH_TOKEN"];
348 private function RefreshToken($socServUserId)
350 $result = CHTTP::sPostHeader(self::TOKEN_URL, array(
351 "refresh_token"=>$this->refresh_token,
352 "client_id"=>$this->appID,
353 "client_secret"=>$this->appSecret,
354 "grant_type"=>"refresh_token",
355 ), array(), $this->httpTimeout);
356 $arResult = CUtil::JsObjectToPhp($result);
358 if(isset($arResult["access_token"]) && $arResult["access_token"] <> '')
360 $this->access_token = $arResult["access_token"];
361 \Bitrix\Socialservices\UserTable::update($socServUserId, array("OATOKEN" => $arResult["access_token"]));
change_password_forgot_link login popup forget pas AUTH_GOTO_FORGOT_FORM login btn wrap change_password_button login popup link login popup return auth javascript
static URN2URI($urn, $server_name='')
AuthorizeUser($socservUserFields, $bSave=false)
getUrl($location='opener', $addScope=null, $arParams=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
<? if( $useEditor3):?>< tr class="heading">< td colspan="2"><? echo GetMessage("FILEMAN_OPTION_SPELL_SET");?></td ></tr ><? if(function_exists( 'pspell_config_create')):$use_pspell_checked=(COption::GetOptionString( $module_id, "use_pspell", "Y")=="Y") ? "checked" :"";?>< tr >< td valign="top">< label for="use_pspell"><?echo GetMessage("FILEMAN_OPTION_USE_PSPELL");?></label >< br >< a title="<?echo GetMessage("FILEMAN_OPTION_ADDISH_DICS_TITLE");?> http
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
const SOCSERV_REGISTRATION_DENY