Version 4.7.6

This commit is contained in:
Neo committed 2025-12-19 16:05:19 -08:00
1 parent 8ba7d43898
commit 7b7404e741
1085 files changed
+30590 -7837

No files matched your search

+29 -5
View File
@@ -402,7 +402,13 @@ class _Twitter extends \IPS\Login\Handler\OAuth1
}
return $this->_cachedUserData[ $accessToken ];
}
/**
* @brief The length of the shortened URLs returned by Twitter's text parser https://developer.twitter.com/en/docs/counting-characters#:~:text=The%20current%20length%20of%20a,count%20towards%20the%20character%20limit.
*/
protected static $defaultShortenedUrlLength = 23;
/**
* Post something to Twitter
*
@@ -419,15 +425,33 @@ class _Twitter extends \IPS\Login\Handler\OAuth1
}
$data = array( 'status' => $content );
/* If we have a url, add it to the end prepended by a space */
if ( $url !== NULL )
{
/* Try to refresh if the stored response is more than a day old */
if ( !isset( \IPS\Data\Store::i()->twitter_config ) or \IPS\Data\Store::i()->twitter_config['time'] > time() - 86400 )
{
$response = $this->_sendRequest( 'get', \IPS\Http\Url::external('https://api.twitter.com/1.1/help/configuration.json'), array(), $link['token_access_token'], $link['token_secret'] )->decodeJson();
\IPS\Data\Store::i()->twitter_config = array_merge( $response, array( 'time' => time() ) );
try
{
$response = $this->_sendRequest( 'get', \IPS\Http\Url::external('https://api.twitter.com/1.1/help/configuration.json'), array(), $link['token_access_token'], $link['token_secret'] );
if ( ( $response->httpResponseCode === 200 ) AND ( $payload = $response->decodeJson() ) AND \is_array( $payload ) )
{
\IPS\Data\Store::i()->twitter_config = array_merge( $payload, array( 'time' => time() ) );
}
else
{
throw new \UnexpectedValueException();
}
}
catch ( \Exception|\UnexpectedValueException $e )
{
/* We should be fine hard coding to 23 if the deprecated configuration endpoint is no longer online https://developer.twitter.com/en/docs/counting-characters#:~:text=The%20current%20length%20of%20a,count%20towards%20the%20character%20limit. */
\IPS\Data\Store::i()->twitter_config['short_url_length'] = static::$defaultShortenedUrlLength;
}
}
$maxUrlLen = \IPS\Data\Store::i()->twitter_config['short_url_length'];
$maxUrlLen = \IPS\Data\Store::i()->twitter_config['short_url_length'] ?? static::$defaultShortenedUrlLength;
$data['status'] = mb_substr( $data['status'], 0, ( 140 - ( $maxUrlLen + 1 ) ) ) . ' ' . $url;
}