1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
twitter.php
См. документацию.
1<?
2
4
6
8{
9 const ID = "Twitter";
10
11 public function GetSettings()
12 {
13 return array(
14 array("twitter_key", GetMessage("socserv_tw_key"), "", Array("text", 40)),
15 array("twitter_secret", GetMessage("socserv_tw_secret"), "", Array("text", 40)),
16 array("note"=>GetMessage("socserv_tw_sett_note", array('#URL#'=>\CHTTP::URN2URI("/bitrix/tools/oauth/twitter.php")))),
17 );
18 }
19
20 public function GetFormHtml($arParams)
21 {
22 global $APPLICATION;
23
24 $phrase = ($arParams["FOR_INTRANET"]) ? GetMessage("socserv_tw_note_intranet") : GetMessage("socserv_tw_note");
25
26 $arParams['BACKURL'] = $APPLICATION->GetCurPageParam('', array("logout", "auth_service_error", "auth_service_id", "current_fieldset"));
27
28 $url = $this->getUrl($arParams);
29
30 if($arParams["FOR_INTRANET"])
31 return array("ON_CLICK" => 'onclick="BX.util.popup(\''.htmlspecialcharsbx(CUtil::JSEscape($url)).'\', 800, 450)"');
32 return '<a href="javascript:void(0)" onclick="BX.util.popup(\''.htmlspecialcharsbx(CUtil::JSEscape($url)).'\', 800, 450)" class="bx-ss-button twitter-button"></a><span class="bx-spacer"></span><span>'.$phrase.'</span>';
33 }
34
35 public function GetOnClickJs($arParams)
36 {
37 $url = $this->getUrl($arParams);
38 return "BX.util.popup('".CUtil::JSEscape($url)."', 800, 450)";
39 }
40
41 public function getUrl($arParams)
42 {
43 // due to something strange reason Twitter does incorrect encoding of oauth_redirect parameters
44 return '/bitrix/tools/oauth/twitter.php?check_key='.\CSocServAuthManager::getUniqueKey().(isset($arParams['BACKURL']) ? "&backurl=".urlencode(urlencode($arParams['BACKURL'])) : '');
45 }
46
47 public function Authorize()
48 {
49 $GLOBALS["APPLICATION"]->RestartBuffer();
50
51 $bSuccess = false;
52
53 if(!isset($_REQUEST["oauth_token"]) || $_REQUEST["oauth_token"] == '')
54 {
55 $tw = new CTwitterInterface();
56 $callback = CSocServUtil::GetCurUrl('auth_service_id='.self::ID, false, false);
57
58 if($tw->GetRequestToken($callback))
59 {
60 $tw->RedirectAuthUrl();
61 }
62 }
63 elseif(CSocServAuthManager::CheckUniqueKey())
64 {
65 $tw = new CTwitterInterface(false, false, $_REQUEST["oauth_token"], $_REQUEST["oauth_verifier"]);
66 if(($arResult = $tw->GetAccessToken()) !== false && $arResult["user_id"] <> '')
67 {
68 $twUser = $tw->GetUserInfo($arResult["user_id"]);
69
70 $first_name = $last_name = "";
71 if(is_array($twUser) && ($twUser["name"] <> ''))
72 {
73 $aName = explode(" ", $twUser["name"]);
74 $first_name = $aName[0];
75 if(isset($aName[1]))
76 $last_name = $aName[1];
77 }
78
79 $arFields = array(
80 'EXTERNAL_AUTH_ID' => self::ID,
81 'XML_ID' => $arResult["user_id"],
82 'LOGIN' => $arResult["screen_name"],
83 'NAME'=> $first_name,
84 'LAST_NAME'=> $last_name,
85 );
86 if(isset($twUser["profile_image_url"]) && self::CheckPhotoURI($twUser["profile_image_url"]))
87 {
88 $twUser["profile_image_url"] = preg_replace("/_normal\./i", ".", $twUser["profile_image_url"]);
89 if ($arPic = CFile::MakeFileArray($twUser["profile_image_url"]))
90 {
91 $arFields["PERSONAL_PHOTO"] = $arPic;
92 }
93 }
94
95 $arFields["PERSONAL_WWW"] = "https://twitter.com/".$arResult["screen_name"];
96 if(SITE_ID <> '')
97 $arFields["SITE_ID"] = SITE_ID;
98 if(COption::GetOptionString('socialservices','last_twit_id','1') == 1)
99 {
100 if(isset($twUser["status"]["id_str"]))
101 COption::SetOptionString('socialservices', 'last_twit_id', $twUser["status"]["id_str"]);
102 }
103
104 $authError = $this->AuthorizeUser($arFields);
105 $bSuccess = $authError === true;
106 }
107 }
108
109 if($bSuccess)
110 {
111 $aRemove = array("logout", "auth_service_error", "auth_service_id", "oauth_token", "oauth_verifier", "check_key", "current_fieldset", "ncc");
112
113 $url = isset($_REQUEST['backurl']) ? $_REQUEST['backurl'] : $GLOBALS['APPLICATION']->GetCurPageParam(($bSuccess === true ? '' : 'auth_service_id='.self::ID.'&auth_service_error='.$bSuccess), $aRemove);
114 if(CModule::IncludeModule("socialnetwork") && mb_strpos($url, "current_fieldset=") === false)
115 $url = (preg_match("/\?/", $url)) ? $url."&current_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV";
116
117 $url .= (preg_match("/\?/", $url) ? '&' : '?').CSocServUtil::getOAuthProxyString();
118
119 echo '
120<script>
121if(window.opener)
122 window.opener.location = \''.CUtil::JSEscape($url).'\';
123window.close();
124</script>
125';
126 CMain::FinalActions();
127 }
128 else
129 {
130 // some error occured
131
132 }
133 }
134
135 public function GetUserMessage($socServUserArray, $sinceId = '1')
136 {
137 $result = array();
138 $token = false;
139 $secret = false;
140 if(!empty($socServUserArray))
141 {
142 $hash = COption::GetOptionString("socialservices", "twitter_search_hash", "#b24");
143 $appID = trim(self::GetOption("twitter_key"));
144 $appSecret = trim(self::GetOption("twitter_secret"));
145 if(is_array($socServUserArray[1]) && $arToken = $socServUserArray[1])
146 {
147 $key = array_rand($arToken, 1);
148 $token = $arToken[$key];
149 if(is_array($socServUserArray[2]))
150 $secret = $socServUserArray[2][$key];
151 }
152
153 $tw = new CTwitterInterface($appID, $appSecret, $token, false, $secret);
154 $result = $tw->SearchByHash($hash, $socServUserArray, $sinceId);
155 }
156 return $result;
157 }
158
159
160 public function setUser($userId)
161 {
162 $this->userId = $userId;
163 }
164
165 public function getFriendsList($limit, &$next)
166 {
167 global $USER;
168
169 $currentUser = $this->userId;
170 if(!$currentUser)
171 {
172 $currentUser = $USER->GetID();
173 }
174
175 $tw = new CTwitterInterface();
176 $userId = self::TwitterUserId($currentUser);
177
178 if($userId > 0)
179 {
180 $res = $tw->getUserFriends($userId, $limit, $next);
181
182 if(is_array($res) && is_array($res['users']))
183 {
184 foreach($res['users'] as $key => $contact)
185 {
186 $res['users'][$key]['uid'] = $contact['id_str'];
187 $res['users'][$key]['url'] = "https://twitter.com/".$contact["screen_name"];
188 $res['users'][$key]['first_name'] = $contact['name'];
189
190 if($contact['profile_image_url'])
191 {
192 $res['users'][$key]['picture'] = CMain::IsHTTPS()
193 ? $contact['profile_image_url_https']
194 : $contact['profile_image_url'];
195 $res['users'][$key]['picture'] = preg_replace("/_normal\./i", ".",
196 $res['users'][$key]['picture']);
197 }
198 }
199
200 return $res['users'];
201 }
202 }
203
204 return false;
205 }
206
207 public static function sendMessage($uid, $message)
208 {
209 global $USER;
210
211 $tw = new CTwitterInterface();
212 $userId = self::TwitterUserId($USER->GetID());
213
214 if($userId > 0)
215 {
216 $res = $tw->sendMessage($userId, $uid, $message);
217 }
218
219 return $res;
220 }
221
222 public static function TwitterUserId($userId)
223 {
224 $dbSocservUser = \Bitrix\Socialservices\UserTable::getList([
225 'filter' => ['=USER_ID' => intval($userId), "=EXTERNAL_AUTH_ID" => self::ID],
226 'select' => ["ID"]
227 ]);
228 $arOauth = $dbSocservUser->fetch();
229 if($arOauth["ID"])
230 return $arOauth["ID"];
231 return false;
232 }
233
234 public static function SendUserFeed($userId, $message, $messageId)
235 {
236
237 $appID = trim(self::GetOption("twitter_key"));
238 $appSecret = trim(self::GetOption("twitter_secret"));
239 $tw = new CTwitterInterface($appID, $appSecret);
240 return $tw->SendTwit($userId, $message, $messageId);
241 }
242
243}
244
245class CTwitterInterface
246{
247 const REQUEST_URL = "https://api.twitter.com/oauth/request_token";
248 const AUTH_URL = "https://api.twitter.com/oauth/authenticate";
249 const TOKEN_URL = "https://api.twitter.com/oauth/access_token";
250 const API_URL = "https://api.twitter.com/1.1/users/show.json";
251 const POST_URL = "https://api.twitter.com/1.1/statuses/update.json";
252 const SEARCH_URL = "https://api.twitter.com/1.1/search/tweets.json";
253 const FRIENDS_URL = "https://api.twitter.com/1.1/friends/list.json";
254 const MESSAGE_URL = "https://api.twitter.com/1.1/direct_messages/new.json";
255
256 protected $appID;
257 protected $appSecret;
258 protected $token = false;
259 protected $tokenVerifier = false;
260 protected $tokenSecret = false;
261 protected $oauthArray;
262
263 public function __construct($appID = false, $appSecret = false, $token = false, $tokenVerifier = false, $tokenSecret = false)
264 {
265 if($appID === false)
266 {
267 $appID = trim(CSocServTwitter::GetOption("twitter_key"));
268 }
269
270 if($appSecret === false)
271 {
272 $appSecret = trim(CSocServTwitter::GetOption("twitter_secret"));
273 }
274
275 $this->httpTimeout = SOCSERV_DEFAULT_HTTP_TIMEOUT;
276 $this->appID = $appID;
277 $this->appSecret = $appSecret;
278
279 $this->token = $token;
280 $this->tokenVerifier = $tokenVerifier;
281 if($this->token && isset($_SESSION["twitter_token_secret"]))
282 {
283 $this->tokenSecret = $_SESSION["twitter_token_secret"];
284 }
285 if($this->token && $tokenSecret)
286 {
287 $this->tokenSecret = $tokenSecret;
288 }
289 }
290
291 protected function GetDefParams()
292 {
293 $this->oauthArray = array(
294 "oauth_consumer_key" => $this->appID,
295 "oauth_nonce" => md5(microtime().mt_rand()),
296 "oauth_signature_method" => "HMAC-SHA1",
297 "oauth_timestamp" => time(),
298 "oauth_version" => "1.0",
299 );
300
301 return $this->oauthArray;
302 }
303
304 public function GetRequestToken($callback)
305 {
306 $arParams = array_merge($this->GetDefParams(), array(
307 "oauth_callback" => $callback,
308 ));
309
310 $arParams["oauth_signature"] = $this->BuildSignature($this->GetSignatureString($arParams, self::REQUEST_URL));
311
312 $result = CHTTP::sPostHeader(self::REQUEST_URL, $arParams, array(), $this->httpTimeout);
313 parse_str($result, $arResult);
314 if(isset($arResult["oauth_token"]) && $arResult["oauth_token"] <> '')
315 {
316 $this->token = $arResult["oauth_token"];
317 $this->tokenSecret = $arResult["oauth_token_secret"];
318 $_SESSION["twitter_token_secret"] = $this->tokenSecret;
319 return true;
320 }
321 return false;
322 }
323
324 public function RedirectAuthUrl()
325 {
326 if(!$this->token)
327 return false;
328
329 LocalRedirect(self::AUTH_URL."?oauth_token=".urlencode($this->token).'&check_key='.\CSocServAuthManager::getUniqueKey()/*."&state=".urlencode($state)*/, true);
330 }
331
332 public function GetAccessToken()
333 {
334 if(!$this->token || !$this->tokenVerifier || !$this->tokenSecret)
335 return false;
336
337 $arParams = array_merge($this->GetDefParams(), array(
338 "oauth_token" => $this->token,
339 "oauth_verifier" => $this->tokenVerifier,
340 ));
341
342 $arParams["oauth_signature"] = $this->BuildSignature($this->GetSignatureString($arParams, self::TOKEN_URL));
343 $result = CHTTP::sPostHeader(self::TOKEN_URL, $arParams, array(), $this->httpTimeout);
344 parse_str($result, $arResult);
345 if(isset($arResult["oauth_token"]) && $arResult["oauth_token"] <> '')
346 {
347 $this->token = $arResult["oauth_token"];
348 $this->tokenSecret = $arResult["oauth_token_secret"];
349 $_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->token, "OASECRET" => $this->tokenSecret);
350 return $arResult;
351 }
352 return false;
353 }
354
355 public function GetUserInfo($user_id)
356 {
357 $arParams = array_merge($this->GetDefParams(), array(
358 "oauth_token" => $this->token,
359 "user_id" => $user_id,
360 ));
361 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, self::API_URL)));
362
363 $arHeaders = array(
364 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
365 "Content-type" => "application/x-www-form-urlencoded",
366 );
367
368 $result = CHTTP::sGetHeader(self::API_URL.'?user_id='.$user_id, $arHeaders, $this->httpTimeout);
369
370 return CUtil::JsObjectToPhp($result);
371 }
372
373 public function getUserFriends($user_id, $limit, &$next)
374 {
375 if($limit === 0)
376 {
377 $limit = 100;
378 }
379
380 if(empty($next))
381 {
382 $next = '-1';
383 }
384
385 $this->SetOauthKeys($user_id);
386
387 $arParams = array_merge($this->GetDefParams(), array(
388 "oauth_token" => $this->token,
389 "cursor" => $next,
390 "skip_status" => "true",
391 "include_user_entities" => "false",
392 ));
393
394 $url = self::FRIENDS_URL.'?cursor='.urlencode($next).'&skip_status=true&include_user_entities=false';
395
396 if($limit > 0)
397 {
398 $arParams["count"] = intval($limit);
399 $url .= '&count='.$arParams["count"];
400 }
401
402 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, self::FRIENDS_URL)));
403
404 $arHeaders = array(
405 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
406 "Content-type" => "application/x-www-form-urlencoded",
407 );
408 $result = CHTTP::sGetHeader($url, $arHeaders, $this->httpTimeout);
409
410 $res = CUtil::JsObjectToPhp($result);
411
412 $next = $res['next_cursor_str'];
413 if($next == '0')
414 {
415 $next = '';
416 }
417
418 return $res;
419 }
420
421 public function sendMessage($user_id, $uid, $message)
422 {
423 $this->SetOauthKeys($user_id);
424
425 if($this->access_token === false)
426 return false;
427
428 $arParams = array_merge($this->GetDefParams(), array(
429 "oauth_token" => $this->token,
430 "user_id" => $uid,
431 "text" => $message,
432 ));
433
434 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, self::MESSAGE_URL)));
435
436 $arHeaders = array(
437 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
438 );
439
440 $arPost = array(
441 "user_id" => $uid,
442 "text" => $message,
443 );
444
445 $ob = new \Bitrix\Main\Web\HttpClient();
446 foreach($arHeaders as $header => $value)
447 {
448 $ob->setHeader($header, $value);
449 }
450
451 return $ob->post(self::MESSAGE_URL, $arPost);
452 }
453
454 public function SetOauthKeys($socServUserId)
455 {
456 $dbSocservUser = \Bitrix\Socialservices\UserTable::getList([
457 'filter' => ['=ID' => $socServUserId],
458 'select' => ["OATOKEN", "OASECRET"]
459 ]);
460 while($arOauth = $dbSocservUser->fetch())
461 {
462 $this->token = $arOauth["OATOKEN"];
463 $this->tokenSecret = $arOauth["OASECRET"];
464 }
465 if(!$this->token || !$this->tokenSecret)
466 return false;
467 return true;
468 }
469
470 public function SearchByHash($hash, $socServUserArray, $sinceId)
471 {
472 $arParams = array_merge(array("count" => 100, "include_entities" => "false"), $this->GetDefParams());
473 $arParams = array_merge($arParams, array(
474 "oauth_token" => $this->token,
475 "q" => $hash,
476 "since_id" => $sinceId,
477 ));
478 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, self::SEARCH_URL)));
479 $arHeaders = array(
480 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
481 "Content-type" => "application/x-www-form-urlencoded",
482 );
483 $result = @CHTTP::sGetHeader(self::SEARCH_URL."?count=100&include_entities=false&q=".urlencode($hash)."&since_id=".$sinceId, $arHeaders, $this->httpTimeout);
484 if($result)
485 {
486 $arResult = Json::decode($result);
487 if (empty($arResult) || !is_array($arResult))
488 {
489 return false;
490 }
491
492 if(is_array($arResult["statuses"]))
493 foreach($arResult["statuses"] as $key => $value)
494 {
495 if(!$find = array_search($value["user"]["id_str"], $socServUserArray[0]))
496 unset($arResult["statuses"][$key]);
497 else
498 {
499 $arResult["statuses"][$key]["kp_user_id"] = $find;
500 $arResult["statuses"][$key]["user_perms"] = self::GetUserPerms($value["user"]["id_str"]);
501 }
502 }
503 return $arResult;
504 }
505 return false;
506 }
507
508 private function GetAllPages($arResult)
509 {
510 static $arTwits = array();
511 if(!isset($arResult["search_metadata"]["next_results"]))
512 return $arTwits;
513 parse_str(preg_replace("|\?|", '', $arResult["search_metadata"]["next_results"]), $searchMetaData);
514 $arParams = array_merge(array("count" => $searchMetaData["count"], "include_entities" => $searchMetaData["include_entities"], "max_id" => $searchMetaData["max_id"]), $this->GetDefParams());
515 $arParams = array_merge($arParams, array(
516 "oauth_token" => $this->token,
517 "q" => $searchMetaData["q"],
518 ));
519 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, self::SEARCH_URL)));
520 $arHeaders = array(
521 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
522 "Content-type" => "application/x-www-form-urlencoded",
523 );
524 $result = CHTTP::sGetHeader(self::SEARCH_URL."?count=".$searchMetaData["count"]."&include_entities=".$searchMetaData["include_entities"]."&max_id=".$searchMetaData["max_id"]."&q=".urlencode($searchMetaData["q"]), $arHeaders, $this->httpTimeout);
525
526 $arResult = CUtil::JsObjectToPhp($result);
527 if(is_array($arResult["statuses"]))
528 $arTwits = array_merge($arTwits, $arResult["statuses"]);
529 return self::GetAllPages($arResult);
530 }
531
532 private function GetAllPagesNotAuth($arResult)
533 {
534 static $arTwits = array();
535 if(!isset($arResult["next_page"]) || $arResult["page"] == 15 || intval($arResult["page"]) < 1)
536 return $arTwits;
537 $result = CHTTP::sGet(self::SEARCH_URL.$arResult["next_page"]);
538 $arResult = CUtil::JsObjectToPhp($result);
539 $arTwits = array_merge($arTwits, $arResult["results"]);
540 return self::GetAllPages($arResult);
541 }
542
543 public function SendTwit($socServUserId, $message, $messageId)
544 {
545 $isSetOauthKeys = true;
546 if(!$this->token || !$this->tokenSecret)
547 $isSetOauthKeys = self::SetOauthKeys($socServUserId);
548
549 if($isSetOauthKeys === false)
550 {
551 CSocServMessage::Delete($messageId);
552 return false;
553 }
554
555 if(mb_strlen($message) > 139)
556 $message = mb_substr($message, 0, 137)."...";
557
558 $arParams = array_merge($this->GetDefParams(), array(
559 "oauth_token" => $this->token,
560 "status"=> $message,
561 ));
562 $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, $this::POST_URL)));
563
564 $arHeaders = array(
565 "Authorization" => 'OAuth oauth_consumer_key="'.$arParams["oauth_consumer_key"].'", oauth_nonce="'.$arParams["oauth_nonce"].'", oauth_signature="'.$arParams["oauth_signature"].'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$arParams["oauth_timestamp"].'", oauth_token="'.$this->token.'", oauth_version="1.0"',
566 );
567 $arPost = array("status"=> $message);
568 $result = @CHTTP::sPostHeader($this::POST_URL, $arPost, $arHeaders, $this->httpTimeout);
569 if($result !== false)
570 {
571 return CUtil::JsObjectToPhp($result);
572 }
573 else
574 return false;
575
576 }
577
578 private function GetUserPerms($userXmlId)
579 {
580 $arUserPermis = array();
581 $dbSocUser = \Bitrix\Socialservices\UserTable::getList([
582 'filter' => [
583 '=EXTERNAL_AUTH_ID'=>'Twitter',
584 '=XML_ID'=>$userXmlId
585 ],
586 'select' => ["PERMISSIONS"]
587 ]);
588 while($arSocUser = $dbSocUser->fetch())
589 {
590 $arUserPermis = unserialize($arSocUser["PERMISSIONS"], ['allowed_classes' => false]);
591 if(is_array($arUserPermis))
592 foreach($arUserPermis as $key=>$value)
593 if($value == "UA")
594 $arUserPermis[$key] = "G2";
595 }
596 if(!empty($arUserPermis))
597 return $arUserPermis;
598 else
599 return array("UA" => array("UA"));
600 }
601
602 protected function urlencode($mixParams)
603 {
604 if(is_array($mixParams))
605 return array_map(array($this, 'urlencode'), $mixParams);
606 elseif (is_scalar($mixParams))
607 return str_replace(array('+','%7E'), array(' ','~'), rawurlencode($mixParams));
608 else
609 return '';
610 }
611
612 protected function GetSignatureString($arParams, $url)
613 {
614 $typeRequest = "POST";
615 if($url === self::API_URL || $url === self::SEARCH_URL || $url == self::FRIENDS_URL)
616 $typeRequest = "GET";
617 if(array_key_exists('oauth_signature', $arParams))
618 unset($arParams['oauth_signature']);
619
620 return implode('&',
621 $this->urlencode(
622 array(
623 $typeRequest,
624 $url,
625 $this->BuildQuery($arParams),
626 )
627 )
628 );
629 }
630
631 protected function BuildQuery($params)
632 {
633 if (!$params)
634 return '';
635
636 $keys = $this->urlencode(array_keys($params));
637 $values = $this->urlencode(array_values($params));
638 $params = array_combine($keys, $values);
639
640 uksort($params, 'strcmp');
641
642 $pairs = array();
643 foreach ($params as $parameter => $value)
644 {
645 if(is_array($value))
646 {
647 natsort($value);
648 foreach ($value as $duplicate_value)
649 $pairs[] = $parameter . '=' . $duplicate_value;
650 }
651 else
652 $pairs[] = $parameter . '=' . $value;
653 }
654 return implode('&', $pairs);
655 }
656
657 protected function BuildSignature($sigString)
658 {
659 if(!function_exists("hash_hmac"))
660 return null;
661
662 $key = implode('&',
663 $this->urlencode(
664 array(
665 $this->appSecret,
666 ($this->tokenSecret? $this->tokenSecret : ''),
667 )
668 )
669 );
670 return base64_encode(hash_hmac('sha1', $sigString, $key, true));
671 }
672}
673
674?>
$arParams
Определения access_dialog.php:21
return select
Определения access_edit.php:440
global $APPLICATION
Определения include.php:80
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
Определения change_password.php:57
Определения json.php:9
static URN2URI($urn, $server_name='')
Определения http.php:39
Определения authmanager.php:985
AuthorizeUser($socservUserFields, $bSave=false)
Определения authmanager.php:1395
Определения twitter.php:8
const ID
Определения twitter.php:9
GetSettings()
Определения twitter.php:11
getUrl($arParams)
Определения twitter.php:41
GetFormHtml($arParams)
Определения twitter.php:20
static getOAuthProxyString()
Определения authmanager.php:1790
urlencode($mixParams)
Определения twitter.php:602
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
const SITE_ID
Определения sonet_set_content_view.php:12
$GLOBALS['_____370096793']
Определения update_client.php:1
$url
Определения iframe.php:7