Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -22,11 +22,6 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
/**
|
||||
* @brief Share Service
|
||||
*/
|
||||
public static $shareService = 'Facebook';
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
@@ -71,6 +66,22 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Compatibility
|
||||
*
|
||||
* @return bool
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public static function testCompatibility()
|
||||
{
|
||||
if ( mb_substr( \IPS\Settings::i()->base_url, 0, 8 ) !== 'https://' )
|
||||
{
|
||||
throw new \LogicException( \IPS\Member::loggedIn()->language()->addToStack( \IPS\CIC ? 'login_facebook_https_cic' : 'login_facebook_https' ) );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the button color
|
||||
@@ -143,25 +154,12 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
$return = array('email');
|
||||
|
||||
if ( isset( static::$shareService ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$shareService = \IPS\core\ShareLinks\Service::load( static::$shareService, 'share_key' );
|
||||
if ( $shareService->autoshare )
|
||||
{
|
||||
$return[] = 'publish_actions';
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->profile_comments and isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] )
|
||||
{
|
||||
$return[] = 'user_posts';
|
||||
}
|
||||
|
||||
$additionalPermitted = array( 'manage_pages', 'publish_pages', 'user_managed_groups', 'publish_actions' );
|
||||
$additionalPermitted = array( 'manage_pages', 'publish_pages', 'publish_to_groups' );
|
||||
if ( $additional !== NULL )
|
||||
{
|
||||
foreach( $additional as $scope )
|
||||
@@ -186,7 +184,9 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = $this->_authorizedRequest( 'me/permissions', $accessToken );
|
||||
$response = $this->_authorizedRequest( 'me/permissions', $accessToken, array(
|
||||
'appsecret_proof' => hash_hmac( 'sha256', $accessToken, $this->settings['client_secret'] )
|
||||
), 'get' );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
@@ -406,22 +406,6 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to user's remote profile
|
||||
* May return NULL if server doesn't support this
|
||||
*
|
||||
* @param string $identifier The ID Nnumber/string from remote service
|
||||
* @param string $username The username from remote service
|
||||
* @return \IPS\Http\Url|NULL
|
||||
* @throws \IPS\Login\Exception The token is invalid and the user needs to reauthenticate
|
||||
* @throws \DomainException General error where it is safe to show a message to the user
|
||||
* @throws \RuntimeException Unexpected error from service
|
||||
*/
|
||||
public function userLink( $identifier, $username )
|
||||
{
|
||||
return \IPS\Http\Url::external( "https://www.facebook.com/" . $identifier );
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncing Options
|
||||
*
|
||||
@@ -432,8 +416,9 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
public function syncOptions( \IPS\Member $member, $defaultOnly = FALSE )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( ( !isset( $this->settings['update_email_changes'] ) or $this->settings['update_email_changes'] === 'optional' ) and in_array( 'email', $this->authorizedScopes( $member ) ) )
|
||||
$scopes = $this->authorizedScopes( $member );
|
||||
|
||||
if ( ( !isset( $this->settings['update_email_changes'] ) or $this->settings['update_email_changes'] === 'optional' ) and ( $scopes and in_array( 'email', $scopes ) ) )
|
||||
{
|
||||
$return[] = 'email';
|
||||
}
|
||||
@@ -446,7 +431,7 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
$return[] = 'photo';
|
||||
$return[] = 'cover';
|
||||
|
||||
if ( \IPS\Settings::i()->profile_comments and isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] and in_array( 'user_posts', $this->authorizedScopes( $member ) ) )
|
||||
if ( \IPS\Settings::i()->profile_comments and isset( $this->settings['allow_status_import'] ) and $this->settings['allow_status_import'] and ( $scopes and in_array( 'user_posts', $this->authorizedScopes( $member ) ) ) )
|
||||
{
|
||||
$return[] = 'status';
|
||||
}
|
||||
@@ -546,6 +531,22 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
|
||||
/* ! Social Promotion */
|
||||
|
||||
/**
|
||||
* Exchange a short lived member token for a longer lived token
|
||||
*
|
||||
* @param string $shortLivedToken The short lived token to exchange for a long lived token
|
||||
* @return array
|
||||
*/
|
||||
public function exchangeMemberToken( $code )
|
||||
{
|
||||
$accessToken = $this->_exchangeAuthorizationCodeForAccessToken( $code );
|
||||
|
||||
/* Get user ID */
|
||||
$accessToken['identifier'] = $this->authenticatedUserId( $accessToken['access_token'] );
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange a short lived token for a longer lived token
|
||||
*
|
||||
@@ -579,13 +580,13 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
*/
|
||||
public function getPages( $member )
|
||||
{
|
||||
if ( !( $link = $this->_link( $member ) ) )
|
||||
{
|
||||
throw new \IPS\Login\Exception( $error['message'], \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
$pages = array();
|
||||
|
||||
$response = $this->_authorizedRequest( $link['token_identifier'] . '/accounts', $link['token_access_token'], array(
|
||||
if ( !( $link = $this->_promoteLink( $member ) ) )
|
||||
{
|
||||
return $pages;
|
||||
}
|
||||
|
||||
$response = $this->_authorizedRequest( $link['token_identifier'] . '/accounts?limit=100', $link['token_access_token'], array(
|
||||
'appsecret_proof' => hash_hmac( 'sha256', $link['token_access_token'], $this->settings['client_secret'] )
|
||||
), 'get' );
|
||||
|
||||
@@ -608,11 +609,11 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
*/
|
||||
public function getGroups( $member )
|
||||
{
|
||||
if ( !( $link = $this->_link( $member ) ) )
|
||||
{
|
||||
throw new \IPS\Login\Exception( $error['message'], \IPS\Login\Exception::INTERNAL_ERROR );
|
||||
}
|
||||
$groups = array();
|
||||
if ( !( $link = $this->_promoteLink( $member ) ) )
|
||||
{
|
||||
return $groups;
|
||||
}
|
||||
|
||||
$response = $this->_authorizedRequest( $link['token_identifier'] . '/groups', $link['token_access_token'], array(
|
||||
'appsecret_proof' => hash_hmac( 'sha256', $link['token_access_token'], $this->settings['client_secret'] )
|
||||
@@ -622,11 +623,40 @@ class _Facebook extends \IPS\Login\Handler\OAuth2
|
||||
{
|
||||
foreach( $response['data'] as $group )
|
||||
{
|
||||
$groups[ $group['id'] ] = array( $group['name'], $group['privacy'] );
|
||||
$groups[ $group['id'] ] = array( $group['name'], ( isset( $group['privacy'] ) ? $group['privacy'] : NULL ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user link
|
||||
*
|
||||
* @param \IPS\Member $member Member requesting pages
|
||||
* @return array
|
||||
*/
|
||||
protected function _promoteLink( $member )
|
||||
{
|
||||
if ( \is_numeric( \IPS\Settings::i()->promote_facebook_auth ) )
|
||||
{
|
||||
/* standard handler */
|
||||
if ( !( $link = $this->_link( $member ) ) )
|
||||
{
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$account = \IPS\core\Promote::getPromoter('Facebook')->setMember( $member );
|
||||
$this->settings = json_decode( \IPS\Settings::i()->promote_facebook_auth, TRUE );
|
||||
$link = array(
|
||||
'token_identifier' => $account->settings['member_token']['identifier'],
|
||||
'token_access_token' => $account->settings['member_token']['access_token']
|
||||
);
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user