Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+12 -30
View File
@@ -53,7 +53,11 @@ class _Facebook
*/
public static function canAutoshare()
{
return (boolean) \IPS\Member::loggedIn()->fb_token AND \IPS\Member::loggedIn()->fb_uid;
if ( $method = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth2\Facebook' ) and $authorizedScopes = $method->authorizedScopes( \IPS\Member::loggedIn() ) )
{
return in_array( 'publish_actions', $authorizedScopes );
}
return FALSE;
}
/**
@@ -65,41 +69,19 @@ class _Facebook
*/
public static function publish( $content, $url=null )
{
if ( static::canAutoshare() )
if ( static::canAutoshare() and $method = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth2\Facebook' ) )
{
try
{
/* If we include a URL, we'll post it as a link to the wall, otherwise we'll just update the user's status */
if ( $url !== NULL )
if ( !$method->postToFacebook( \IPS\Member::loggedIn(), $content, $url ) )
{
$response = \IPS\Http\Url::external( "https://graph.facebook.com/" . \IPS\Member::loggedIn()->fb_uid . "/feed" )->request()->post( array(
'message' => $content,
'link' => (string) $url,
'access_token' => \IPS\Member::loggedIn()->fb_token,
) )->decodeJson();
if ( ! isset( $response['id'] ) )
{
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('facebook_publish_exception') );
}
}
else
{
$response = \IPS\Http\Url::external( "https://graph.facebook.com/" . \IPS\Member::loggedIn()->fb_uid . "/feed" )->request()->post( array(
'message' => $content,
'access_token' => \IPS\Member::loggedIn()->fb_token,
) )->decodeJson();
if ( ! isset( $response['id'] ) )
{
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('facebook_publish_exception') );
}
throw new \Exception;
}
}
catch( \IPS\Http\Request\Exception $e )
catch( \Exception $e )
{
\IPS\Log::log( \IPS\Member::loggedIn()->id . ': '. $e->getMessage(), 'facebook' );
\IPS\Log::log( \IPS\Member::loggedIn()->member_id . ': '. $e->getMessage(), 'facebook' );
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('facebook_publish_exception') );
}
}
@@ -120,7 +102,7 @@ class _Facebook
{
$form->add( new \IPS\Helpers\Form\Select( 'fbc_bot_group', \IPS\Settings::i()->fbc_bot_group, TRUE, array( 'options' => array_combine( array_keys( \IPS\Member\Group::groups() ), array_map( function( $_group ) { return (string) $_group; }, \IPS\Member\Group::groups() ) ) ) ) );
if ( array_key_exists( 'Facebook', \IPS\Login::handlers( TRUE ) ) )
if ( \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth2\Facebook' ) )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'share_autoshare_Facebook', $service->autoshare, false ) );
}