8 require_once(CH_DIRECTORY_PATH_INC .
'profiles.inc.php');
36 require_once(CH_DIRECTORY_PATH_PLUGINS .
'facebook-php-sdk/src/Facebook/autoload.php');
39 $this->oFacebook =
null;
41 if (!
empty($this->_oConfig->mApiID) && !
empty($this->_oConfig->mApiSecret)) {
44 'app_id' => $this->_oConfig->mApiID,
45 'app_secret' => $this->_oConfig->mApiSecret,
46 'default_graph_version' =>
'v2.4',
58 parent::_actionAdministration(
'ch_facebook_connect_api_key',
'_ch_facebook_settings',
59 '_ch_facebook_information',
'_ch_facebook_information_block', $this->_oConfig->sPageReciver);
70 header(
'Location:' . $this->_oConfig->sDefaultRedirectUrl);
74 if (!$this->_oConfig->mApiID || !$this->_oConfig->mApiSecret) {
86 $oResponse = $this->oFacebook->get(
'/me?fields=' . $this->_oConfig->sFaceBookFields);
87 $aFacebookProfileInfo = $oResponse->getDecodedBody();
88 $aFacebookProfileInfo[
'nick_name'] = $aFacebookProfileInfo[
'name'];
90 }
catch (
Facebook\Exceptions\FacebookResponseException $e) {
92 }
catch (
Facebook\Exceptions\FacebookSDKException $e) {
97 if ($aFacebookProfileInfo) {
101 ->getProfileId($aFacebookProfileInfo[
'id']);
108 $sAlternativeNickName =
'';
111 $aFacebookProfileInfo[
'nick_name'] = $this
112 ->_proccesNickName($aFacebookProfileInfo[
'first_name']);
115 if (
getID($aFacebookProfileInfo[
'nick_name'])) {
116 $sAlternativeNickName = $this
117 ->getAlternativeName($aFacebookProfileInfo[
'nick_name']);
122 if ($oFacebookProfileImageResponse = $this->oFacebook->get(
'/me/picture?type=large&redirect=false')) {
124 $aFacebookProfileImage = $oFacebookProfileImageResponse->getDecodedBody();
125 $aFacebookProfileInfo[
'picture'] = isset($aFacebookProfileImage[
'data'][
'url']) && !$aFacebookProfileImage[
'data'][
'is_silhouette']
126 ? $aFacebookProfileImage[
'data'][
'url']
133 $this->
_createProfile($aFacebookProfileInfo, $sAlternativeNickName);
142 $this->_oTemplate->getPage(
_t(
'_ch_facebook'),
$sCode);
155 header(
'Location:' . $this->_oConfig->sDefaultRedirectUrl);
159 if (!$this->_oConfig->mApiID || !$this->_oConfig->mApiSecret) {
163 $oFacebookRedirectLoginHelper = $this->oFacebook->getRedirectLoginHelper();
166 $sLoginUrl = $oFacebookRedirectLoginHelper->getLoginUrl(
167 $this->_oConfig->aFaceBookReqParams[
'redirect_uri'],
168 explode(
',', $this->_oConfig->aFaceBookReqParams[
'scope'])
171 header(
'location: ' . $sLoginUrl);
175 $this->_oTemplate->getPage(
_t(
'_ch_facebook'),
$sCode);
185 if (
getParam(
'enable_cheetah_footer') ==
'on') {
186 return array(
'error' =>
_t(
'_ch_facebook_error_unlicensed_site'));
190 return array(
'error' =>
$sError);
195 ->getProfileId($aFacebookProfileInfo[
'id']);
198 $aFacebookProfileInfoCheck =
false;
200 $oResponse = $this->oFacebook->get(
'/' . $aFacebookProfileInfo[
'id'] .
'?fields=' . $this->_oConfig->sFaceBookFields);
201 $aFacebookProfileInfoCheck = $oResponse->getDecodedBody();
202 }
catch (
Facebook\Exceptions\FacebookResponseException $e) {
203 return array(
'error' => $e->getMessage());
204 }
catch (
Facebook\Exceptions\FacebookSDKException $e) {
205 return array(
'error' => $e->getMessage());
208 if (!isset($aFacebookProfileInfoCheck[
'id']) || $aFacebookProfileInfoCheck[
'id'] != $aFacebookProfileInfo[
'id']) {
209 return array(
'error' =>
_t(
'_ch_facebook_profile_error_info'));
217 require_once(CH_DIRECTORY_PATH_ROOT .
'xmlrpc/ChWsbXMLRPCUser.php');
221 'member_pwd_hash' => $aCheetahProfileInfo[
'Password'],
227 $sAlternativeNickName =
'';
230 $aFacebookProfileInfo[
'nick_name'] = $this->
_proccesNickName($aFacebookProfileInfo[
'name']);
233 if (
getID($aFacebookProfileInfo[
'nick_name'])) {
234 $sAlternativeNickName = $this
235 ->getAlternativeName($aFacebookProfileInfo[
'nick_name']);
240 if ($oFacebookProfileImageResponse = $this->oFacebook->get(
'/' . $aFacebookProfileInfo[
'id'] .
'/picture?type=large&redirect=false')) {
242 $aFacebookProfileImage = $oFacebookProfileImageResponse->getDecodedBody();
243 $aFacebookProfileInfo[
'picture'] = isset($aFacebookProfileImage[
'data'][
'url']) && !$aFacebookProfileImage[
'data'][
'is_silhouette']
244 ? $aFacebookProfileImage[
'data'][
'url']
249 if (
'join' == $this->_oConfig->sRedirectPage) {
250 $this->_oConfig->sRedirectPage =
'pedit';
254 $mixed = $this->
_createProfileRaw($aFacebookProfileInfo, $sAlternativeNickName,
false,
true);
256 if (is_string($mixed)) {
263 } elseif (is_array($mixed) && isset($mixed[
'profile_id'])) {
267 $sMemberAvatar = !
empty($mixed[
'remote_profile_info'][
'picture']) ? $mixed[
'remote_profile_info'][
'picture'] :
'';
270 if ($sMemberAvatar && !$mixed[
'existing_profile']) {
276 'member_pwd_hash' => $aCheetahProfileInfo[
'Password'],
279 'existing_profile' => isset($mixed[
'existing_profile']) && $mixed[
'existing_profile'],
285 'error' =>
_t(
'_Error Occured'),
302 if (!$this->_oConfig->bAutoFriends) {
308 $oFriendsResponse = $this->oFacebook->get(
'/me/friends?limit=5000');
309 }
catch (
Facebook\Exceptions\FacebookResponseException $e) {
311 }
catch (
Facebook\Exceptions\FacebookSDKException $e) {
316 $oPagesEdge = $oFriendsResponse->getGraphEdge();
319 $aFriend =
$oPage->asArray();
321 $iFriendId = $this->_oDb->getProfileId($aFriend[
'id']);
331 }
while ($oPagesEdge = $this->oFacebook->next($oPagesEdge));
350 $aLocation = array();
358 $aCountryInfo = explode(
',', $aLocation);
359 $sCountry = $this->_oDb->getCountryCode(trim($aCountryInfo[1]));
360 $sCity = trim($aCountryInfo[0]);
364 $sCountry = $this->_oConfig->sDefaultCountryCode;
374 $aProfileFields = array(
375 'NickName' =>
$aProfileInfo[
'nick_name'] . $sAlternativeName,
392 return $aProfileFields;
403 $sProfileName = preg_replace(
"/^http:\/\/|^https:\/\/|\/$/",
'', $sProfileName);
404 $sProfileName = str_replace(
'/',
'_', $sProfileName);
405 $sProfileName = str_replace(
'.',
'-', $sProfileName);
407 return $sProfileName;
413 $this->oFacebook->setDefaultAccessToken(
$sToken);
418 $oFacebookRedirectLoginHelper = $this->oFacebook->getRedirectLoginHelper();
421 $sAccessToken = $oFacebookRedirectLoginHelper->getAccessToken();
422 }
catch (
Facebook\Exceptions\FacebookResponseException $e) {
424 return $e->getMessage();
425 }
catch (
Facebook\Exceptions\FacebookSDKException $e) {
427 return $e->getMessage();
430 if (!isset($sAccessToken)) {
431 return $oFacebookRedirectLoginHelper->getError() ? $oFacebookRedirectLoginHelper->getErrorDescription() :
_t(
'_Error occured');
434 $this->oFacebook->setDefaultAccessToken($sAccessToken);