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

+13 -52
View File
@@ -53,7 +53,11 @@ class _Twitter
*/
public static function canAutoshare()
{
return (boolean) \IPS\Member::loggedIn()->twitter_token AND \IPS\Member::loggedIn()->twitter_secret;
if ( $method = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth1\Twitter' ) and $method->canProcess( \IPS\Member::loggedIn() ) )
{
return TRUE;
}
return FALSE;
}
/**
@@ -65,63 +69,20 @@ class _Twitter
*/
public static function publish( $content, $url=null )
{
if ( static::canAutoshare() )
{
$loginHandler = \IPS\Login\LoginAbstract::load('twitter');
if ( isset( \IPS\Data\Store::i()->twitter_config ) AND isset( \IPS\Data\Store::i()->twitter_config['time'] ) AND ( \IPS\Data\Store::i()->twitter_config['time'] <= time() - 86400 ) )
{
$maxUrlLen = \IPS\Data\Store::i()->twitter_config['short_url_length'];
}
else
{
try
{
$response = $loginHandler->sendRequest( 'get', "https://api.twitter.com/1.1/help/configuration.json", array(), \IPS\Member::loggedIn()->twitter_token, \IPS\Member::loggedIn()->twitter_secret )->decodeJson();
if ( isset( $response['short_url_length'] ) )
{
\IPS\Data\Store::i()->twitter_config = array_merge( $response, array( 'time' => time() ) );
$maxUrlLen = $response['short_url_length'];
}
else
{
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('twitter_publish_exception') );
}
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( \IPS\Member::loggedIn()->id . ': '. $e->getMessage(), 'twitter' );
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('twitter_publish_exception') );
}
}
if ( $url !== null )
{
$content = mb_substr( $content, 0, ( 140 - ( $maxUrlLen + 1 ) ) ) . ' ' . $url;
}
if ( static::canAutoshare() and $method = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth1\Twitter' ) )
{
try
{
$response = $loginHandler->sendRequest( 'post', "https://api.twitter.com/1.1/statuses/update.json", array( 'status' => $content ), \IPS\Member::loggedIn()->twitter_token, \IPS\Member::loggedIn()->twitter_secret )->decodeJson();
if ( isset( $response['id_str'] ) )
if ( !$method->postToTwitter( \IPS\Member::loggedIn(), $content, $url ) )
{
return $response['id_str'];
}
else
{
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('twitter_publish_exception') );
throw new \Exception;
}
}
catch ( \IPS\Http\Request\Exception $e )
catch( \Exception $e )
{
\IPS\Log::log( \IPS\Member::loggedIn()->id . ': '. $e->getMessage(), 'twitter' );
\IPS\Log::log( \IPS\Member::loggedIn()->member_id . ': '. $e->getMessage(), 'twitter' );
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('twitter_publish_exception') );
}
}
}
else
{
@@ -140,7 +101,7 @@ class _Twitter
{
$form->add( new \IPS\Helpers\Form\Text( 'twitter_hashtag', \IPS\Settings::i()->twitter_hashtag, FALSE ) );
if ( array_key_exists( 'Twitter', \IPS\Login::handlers( TRUE ) ) )
if ( \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\OAuth2\Twitter' ) )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'share_autoshare_Twitter', $service->autoshare, false ) );
}