Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -40,19 +40,10 @@ class _Facebook extends PromoteAbstract
|
||||
'tags' => NULL,
|
||||
'image' => NULL,
|
||||
'last_sync' => 0,
|
||||
'shareable' => array()
|
||||
'shareable' => array(),
|
||||
'member_token' => array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return ( $this->member->fb_uid and $this->member->fb_token );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image
|
||||
*
|
||||
@@ -103,7 +94,7 @@ class _Facebook extends PromoteAbstract
|
||||
*/
|
||||
public function canPostToPage()
|
||||
{
|
||||
$facebook = \IPS\Login\Handler::findMethod('IPS\Login\Handler\Oauth2\Facebook');
|
||||
$facebook = static::getLoginHandler();
|
||||
|
||||
$authorizedScopes = $facebook->authorizedScopes( $this->member );
|
||||
|
||||
@@ -112,7 +103,7 @@ class _Facebook extends PromoteAbstract
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
foreach( array( 'user_managed_groups', 'manage_pages', 'publish_pages', 'publish_actions' ) as $perm )
|
||||
foreach( array( 'publish_to_groups', 'manage_pages', 'publish_pages' ) as $perm )
|
||||
{
|
||||
if ( ! in_array( $perm, $authorizedScopes ) )
|
||||
{
|
||||
@@ -131,7 +122,7 @@ class _Facebook extends PromoteAbstract
|
||||
*/
|
||||
protected static function appSecretProof( $token )
|
||||
{
|
||||
$facebook = \IPS\Login\Handler::findMethod('IPS\Login\Handler\Oauth2\Facebook');
|
||||
$facebook = static::getLoginHandler();
|
||||
return hash_hmac( 'sha256', $token, $facebook->settings['client_secret'] );
|
||||
}
|
||||
|
||||
@@ -218,7 +209,7 @@ class _Facebook extends PromoteAbstract
|
||||
$settings = $promote->form_data['facebook'];
|
||||
$shareable = $this->settings['shareable'];
|
||||
$responses = array();
|
||||
|
||||
|
||||
foreach( $settings['shareable'] as $id )
|
||||
{
|
||||
$feedId = mb_substr( $id, 2 );
|
||||
@@ -229,7 +220,7 @@ class _Facebook extends PromoteAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
$responses[ $id ][] = $this->_post( $promote, $photos, $feedId, $this->settings['token'] );
|
||||
$responses[ $id ][] = $this->_post( $promote, $photos, $feedId, isset( $this->settings['member_token']['access_token'] ) ? $this->settings['member_token']['access_token'] : $this->settings['token'] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,14 +283,14 @@ class _Facebook extends PromoteAbstract
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/" . $feedId . "/photos" )->request()->post( $this->_addToken( array(
|
||||
'message' => $promote->text['facebook'],
|
||||
'url' => (string) $this->returnUrlWithProtocol( $thePhoto->url ),
|
||||
'link' => $promote->short_link
|
||||
'link' => (string) $promote->short_link
|
||||
), $token ) )->decodeJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/" . $feedId . "/feed" )->request()->post( $this->_addToken( array(
|
||||
'message' => $promote->text['facebook'],
|
||||
'link' => $promote->short_link
|
||||
'link' => (string) $promote->short_link
|
||||
), $token ) )->decodeJson();
|
||||
}
|
||||
}
|
||||
@@ -315,6 +306,11 @@ class _Facebook extends PromoteAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $response['error'] ) )
|
||||
{
|
||||
\IPS\Log::log( $response['error']['message'], 'facebook' );
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('facebook_publish_exception') );
|
||||
}
|
||||
}
|
||||
@@ -400,6 +396,30 @@ class _Facebook extends PromoteAbstract
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this member connected to the Facebook app?
|
||||
*
|
||||
* @param \IPS\Member $member A member object
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected( $member )
|
||||
{
|
||||
if ( \is_numeric( \IPS\Settings::i()->promote_facebook_auth ) )
|
||||
{
|
||||
/* Standard handler */
|
||||
$facebook = \IPS\Login\Handler::findMethod('IPS\Login\Handler\Oauth2\Facebook');
|
||||
return $facebook->canProcess( $member );
|
||||
}
|
||||
|
||||
/* Custom */
|
||||
if ( isset( $this->settings['member_token']['access_token'] ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the URL is not protocol relative
|
||||
*
|
||||
@@ -414,4 +434,22 @@ class _Facebook extends PromoteAbstract
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to Facebook log in handler with the correct settings
|
||||
*
|
||||
* @return \IPS\Login object
|
||||
*/
|
||||
public static function getLoginHandler()
|
||||
{
|
||||
$facebook = \IPS\Login\Handler::findMethod('IPS\Login\Handler\Oauth2\Facebook');
|
||||
|
||||
/* We are using the default app here */
|
||||
if ( ! \is_numeric( \IPS\Settings::i()->promote_facebook_auth ) )
|
||||
{
|
||||
$facebook->settings = json_decode( \IPS\Settings::i()->promote_facebook_auth, TRUE );
|
||||
}
|
||||
|
||||
return $facebook;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user