Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -1,12 +1,12 @@
<?php
/**
* @brief Twitter Profile Sync
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
* @brief Twitter Profile Sync
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\ProfileSync;
@@ -23,35 +23,39 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _Twitter extends ProfileSyncAbstract
{
/**
* @brief Login handler key
/**
* @brief Login handler key
*/
public static $loginKey = 'Twitter';
/**
* @brief Icon
/**
* @brief Icon
*/
public static $icon = 'twitter';
/**
* @brief User data
* @brief User data
*/
protected $user = NULL;
/**
* Get user data
*
* @return array
* @return array
*/
protected function user()
{
if ( $this->user === NULL and $this->member->twitter_token )
if ( ( $this->user === NULL ) and $this->member->twitter_token )
{
try
{
$loginHandler = \IPS\Login\LoginAbstract::load('twitter');
$this->user = $loginHandler->sendRequest( 'get', "https://api.twitter.com/1.1/account/verify_credentials.json", array(), $this->member->twitter_token, $this->member->twitter_secret )->decodeJson();
$loginHandler = \IPS\Login\LoginAbstract::load( 'twitter' );
$this->user = $loginHandler->sendRequest(
'get', "https://api.twitter.com/1.1/account/verify_credentials.json", array(),
$this->member->twitter_token, $this->member->twitter_secret
)->decodeJson();
if ( isset( $this->user['errors'] ) )
{
throw new \Exception;
@@ -59,137 +63,133 @@ class _Twitter extends ProfileSyncAbstract
}
catch ( \Exception $e )
{
$this->member->twitter_token = '';
$this->member->twitter_token = '';
$this->member->twitter_secret = '';
$this->member->save();
\IPS\Log::log( isset( $this->user['errors'] ) ? var_export( $this->user['errors'], true ) : $e, 'twitter' );
}
}
return $this->user;
}
/**
* Is connected?
*
* @return bool
* @return bool
*/
public function connected()
{
return (bool) ( $this->member->twitter_id and $this->member->twitter_token and $this->member->twitter_secret );
return ( $this->member->twitter_id and $this->member->twitter_token and $this->member->twitter_secret );
}
/**
* Get photo
*
* @return \IPS\Http\Url
* @return \IPS\Http\Url
*/
public function photo()
{
$user = $this->user();
if ( ( \IPS\Http\Url::internal('')->data['scheme'] == 'https' or \IPS\Settings::i()->logins_over_https ) and isset( $user['profile_image_url_https'] ) and $user['profile_image_url_https'] )
{
try
{
return \IPS\Http\Url::external( $user['profile_image_url_https'] );
}
catch ( \Exception $e ) {}
}
if( isset( $user['profile_image_url'] ) AND $user['profile_image_url'] )
{
try
{
return \IPS\Http\Url::external($user['profile_image_url']);
}
catch (\Exception $e) {}
}
return NULL;
return $this->resourceUrl( $this->user(), 'profile_image_url' );
}
/**
* Get cover photo
*
* @return \IPS\File|NULL
* @return \IPS\File|NULL
*/
public function cover()
{
$user = $this->user();
if ( ( \IPS\Http\Url::internal('')->data['scheme'] == 'https' or \IPS\Settings::i()->logins_over_https ) and isset( $user['profile_image_url_https'] ) and $user['profile_background_image_url_https'] )
if ( $coverUrl = $this->resourceUrl( $this->user(), 'profile_background_image_url' ) )
{
try
{
return \IPS\Http\Url::external( $user['profile_background_image_url_https'] );
return $coverUrl->import( 'core_Profile' );
}
catch ( \Exception $e ) {}
}
if( isset( $user['profile_background_image_url'] ) AND $user['profile_background_image_url'] )
{
try
catch ( \IPS\Http\Request\Exception $e )
{
return \IPS\Http\Url::external( $user['profile_background_image_url'] )->import( 'core_Profile' );
\IPS\Log::log( $e, 'twitter' );
}
catch ( \Exception $e ) {}
}
return NULL;
}
/**
* Get name
*
* @return string
* @return string
*/
public function name()
{
$user = $this->user();
return ( isset( $user['screen_name'] ) ) ? $user['screen_name'] : '';
if ( isset( $user['screen_name'] ) )
{
return $user['screen_name'];
}
}
/**
* Get status
*
* @return \IPS\core\Statuses\Status|null
* @return \IPS\core\Statuses\Status|null
*/
public function status()
{
$user = $this->user();
if ( isset( $user['status'] ) )
if ( !empty( $user['status'] ) )
{
$status = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $user['status']['created_at'] ) );
$status->content = \IPS\Text\Parser::utf8mb4SafeDecode( $user['status']['text'] );
$status = \IPS\core\Statuses\Status::createItem(
$this->member, $this->member->ip_address, new \IPS\DateTime( $user['status']['created_at'] )
);
$status->content = $this->_parseStatusText( $user['status']['text'] );
return $status;
}
return NULL;
}
/**
* Export Status
*
* @param \IPS\core\Statuses\Status $status The status
* @return void
*/
public function exportStatus( \IPS\core\Statuses\Status $status )
{
$loginHandler = \IPS\Login\LoginAbstract::load('twitter');
$loginHandler->sendRequest( 'post', "https://api.twitter.com/1.1/statuses/update.json", array( 'status' => trim( strip_tags( $status->content ) ) ), $this->member->twitter_token, $this->member->twitter_secret )->decodeJson();
}
/**
* Disassociate
*
* @return void
* @return void
*/
protected function _disassociate()
{
$this->member->twitter_id = 0;
$this->member->twitter_token = '';
$this->member->twitter_id = 0;
$this->member->twitter_token = '';
$this->member->twitter_secret = '';
$this->member->save();
}
/**
* Get an HTTPS or HTTP resource URL (HTTPS if available and we are using it locally, otherwise HTTP)
*
* @param array $user
* @param string $fieldName
* @return \IPS\Http\Url|NULL
*/
protected function resourceUrl( $user, $fieldName )
{
$scheme = \IPS\Http\Url::internal( '' )->data['scheme'];
if ( ( $scheme === 'https' ) or \IPS\Settings::i()->logins_over_https )
{
if ( !empty( $user[ $fieldName . '_https' ] ) )
{
return \IPS\Http\Url::external( $user[ $fieldName . '_https' ] );
}
}
if ( !empty( $user[ $fieldName ] ) )
{
return \IPS\Http\Url::external( $user[ $fieldName ] );
}
return NULL;
}
}