Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Facebook 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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Facebook Profile Sync
|
||||
*/
|
||||
class _Facebook extends ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handler key
|
||||
*/
|
||||
public static $loginKey = 'Facebook';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'facebook-square';
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return ( $this->member->fb_uid and $this->member->fb_token );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @return \IPS\Http\Url|\IPS\File|NULL
|
||||
*/
|
||||
public function photo()
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}/picture?type=large&redirect=false" )->request()->get()->decodeJson();
|
||||
if ( isset( $response['data']['is_silhouette'] ) AND $response['data']['is_silhouette'] === false )
|
||||
{
|
||||
$file = \IPS\Http\Url::external( $response['data']['url'] )->import( 'core_Profile' );
|
||||
$photo = \IPS\Image::create( $file->contents() );
|
||||
|
||||
if ( ( $photo->width > $photo->height ) OR ( $photo->height > $photo->width ) )
|
||||
{
|
||||
if ( $photo->width > $photo->height )
|
||||
{
|
||||
$difference = $photo->width - $photo->height;
|
||||
$photo->cropToPoints( ceil( $difference / 2 ), 0, ceil( $photo->width - ( $difference / 2 ) ), $photo->height );
|
||||
$file->replace( (string) $photo );
|
||||
}
|
||||
else if ( $photo->height > $photo->width )
|
||||
{
|
||||
$difference = $photo->height - $photo->width;
|
||||
$photo->cropToPoints( 0, ceil( $difference / 2 ), $photo->width, ceil( $photo->height - ( $difference / 2 ) ) );
|
||||
$file->replace( (string) $photo );
|
||||
}
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cover photo
|
||||
*
|
||||
* @return \IPS\Http\Url|NULL
|
||||
*/
|
||||
public function cover()
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}?access_token={$this->member->fb_token}&fields=cover" )->request()->get()->decodeJson();
|
||||
if ( isset( $response['cover'] ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( $response['cover']['source'] )->import( 'core_Profile' );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}?access_token={$this->member->fb_token}" )->request()->get()->decodeJson();
|
||||
if ( isset( $response['name'] ) )
|
||||
{
|
||||
return $response['name'];
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status
|
||||
*
|
||||
* @return \IPS\core\Statuses\Status|null
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}/statuses?access_token={$this->member->fb_token}" )->request()->get()->decodeJson();
|
||||
if ( !empty( $response['data'] ) )
|
||||
{
|
||||
$statusData = array_shift( $response['data'] );
|
||||
|
||||
if( isset( $statusData['message'] ) )
|
||||
{
|
||||
$status = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $statusData['updated_time'] ) );
|
||||
$status->content = nl2br( $statusData['message'], FALSE );
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e ) { }
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export Status
|
||||
*
|
||||
* @param \IPS\core\Statuses\Status $status The status
|
||||
* @return void
|
||||
*/
|
||||
public function exportStatus( \IPS\core\Statuses\Status $status )
|
||||
{
|
||||
\IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}/feed" )->request()->post( array( 'access_token' => $this->member->fb_token, 'message' => strip_tags( $status->content ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _disassociate()
|
||||
{
|
||||
$this->member->fb_uid = 0;
|
||||
$this->member->fb_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Google 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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Google Profile Sync
|
||||
*/
|
||||
class _Google extends ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handler key
|
||||
*/
|
||||
public static $loginKey = 'Google';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'google-plus';
|
||||
|
||||
/**
|
||||
* @brief Authorization token
|
||||
*/
|
||||
protected $authToken = NULL;
|
||||
|
||||
/**
|
||||
* @brief User data
|
||||
*/
|
||||
protected $user = NULL;
|
||||
|
||||
/**
|
||||
* Get user data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function user()
|
||||
{
|
||||
if ( $this->user === NULL and $this->member->google_token )
|
||||
{
|
||||
try
|
||||
{
|
||||
$loginHandler = \IPS\Login\LoginAbstract::load('google');
|
||||
|
||||
$response = \IPS\Http\Url::external( 'https://accounts.google.com/o/oauth2/token' )->request()->post( array(
|
||||
'client_id' => $loginHandler->settings['client_id'],
|
||||
'client_secret' => $loginHandler->settings['client_secret'],
|
||||
'refresh_token' => $this->member->google_token,
|
||||
'grant_type' => 'refresh_token'
|
||||
) )->decodeJson();
|
||||
|
||||
if ( isset( $response['access_token'] ) )
|
||||
{
|
||||
$this->authToken = $response['access_token'];
|
||||
$this->user = $this->get( 'people/' . $this->member->google_id );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
$this->member->google_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return (bool) ( $this->member->google_id and $this->member->google_token );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @return \IPS\Http\Url|\IPS\File|NULL
|
||||
*/
|
||||
public function photo()
|
||||
{
|
||||
$user = $this->user();
|
||||
if ( isset( $user['image'] ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( preg_replace( '/\?sz=\d+$/', '', $user['image']['url'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cover photo
|
||||
*
|
||||
* @return \IPS\Http\Url|NULL
|
||||
*/
|
||||
public function cover()
|
||||
{
|
||||
$user = $this->user();
|
||||
if ( isset( $user['cover'] ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( $user['cover']['coverPhoto']['url'] )->import( 'core_Profile' );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
$user = $this->user();
|
||||
return $user['displayName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status
|
||||
*
|
||||
* @return \IPS\core\Statuses\Status|null
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
$this->user();
|
||||
$statuses = $this->get( "people/me/activities/public" );
|
||||
if ( isset( $statuses['items'] ) )
|
||||
{
|
||||
foreach ( $statuses['items'] as $status )
|
||||
{
|
||||
if ( $status['object']['content'] )
|
||||
{
|
||||
$statusObj = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $status['published'] ) );
|
||||
$statusObj->content = nl2br( $status['object']['content'], FALSE );
|
||||
return $statusObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _disassociate()
|
||||
{
|
||||
$this->member->google_id = 0;
|
||||
$this->member->google_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API data
|
||||
*
|
||||
* @param string $uri The API URI
|
||||
* @return array
|
||||
* @throws \IPS\Http\Request\Exception
|
||||
*/
|
||||
protected function get( $uri )
|
||||
{
|
||||
return \IPS\Http\Url::external( 'https://www.googleapis.com/plus/v1/' . $uri )->request()->setHeaders( array( 'Authorization' => "Bearer {$this->authToken}" ) )->get()->decodeJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief LinkedIn 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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* LinkedIn Profile Sync
|
||||
*/
|
||||
class _Linkedin extends ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handler key
|
||||
*/
|
||||
public static $loginKey = 'Linkedin';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'linkedin';
|
||||
|
||||
/**
|
||||
* @brief User data
|
||||
*/
|
||||
protected $user = NULL;
|
||||
|
||||
/**
|
||||
* Get user data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function user()
|
||||
{
|
||||
if ( $this->user === NULL and $this->member->linkedin_token )
|
||||
{
|
||||
$this->user = array();
|
||||
try
|
||||
{
|
||||
foreach ( \IPS\Http\Url::external( "https://api.linkedin.com/v1/people/{$this->member->linkedin_id}:(formatted-name,picture-url,current-status)?oauth2_access_token={$this->member->linkedin_token}" )->request()->get()->decodeXml() as $k => $v )
|
||||
{
|
||||
$this->user[ $k ] = (string) $v;
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
$this->member->linkedin_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return $this->member->linkedin_id and $this->member->linkedin_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @return \IPS\Http\Url|null
|
||||
*/
|
||||
public function photo()
|
||||
{
|
||||
$user = $this->user();
|
||||
if ( isset( $user['picture-url'] ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( $user['picture-url'] );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
$user = $this->user();
|
||||
return $user['formatted-name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _disassociate()
|
||||
{
|
||||
$this->member->linkedin_id = 0;
|
||||
$this->member->linkedin_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Microsoft 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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Microsoft Profile Sync
|
||||
*/
|
||||
class _Microsoft extends ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handler key
|
||||
*/
|
||||
public static $loginKey = 'Live';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'windows';
|
||||
|
||||
/**
|
||||
* @brief Authorization token
|
||||
*/
|
||||
protected $authToken = NULL;
|
||||
|
||||
/**
|
||||
* Get user data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function authToken()
|
||||
{
|
||||
if ( $this->authToken === NULL and $this->member->live_token )
|
||||
{
|
||||
try
|
||||
{
|
||||
$loginHandler = \IPS\Login\LoginAbstract::load('live');
|
||||
|
||||
$response = \IPS\Http\Url::external( 'https://login.live.com/oauth20_token.srf' )->request()->post( array(
|
||||
'client_id' => $loginHandler->settings['client_id'],
|
||||
'client_secret' => $loginHandler->settings['client_secret'],
|
||||
'refresh_token' => $this->member->live_token,
|
||||
'grant_type' => 'refresh_token'
|
||||
) )->decodeJson();
|
||||
|
||||
if ( isset( $response['access_token'] ) and isset( $response['refresh_token'] ) )
|
||||
{
|
||||
$this->authToken = $response['access_token'];
|
||||
$this->member->live_token = $response['refresh_token'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->member->live_token = NULL;
|
||||
}
|
||||
|
||||
$this->member->save();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
$this->member->live_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->authToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return (bool) ( $this->member->live_id and $this->member->live_token );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @return \IPS\Http\Url|null
|
||||
*/
|
||||
public function photo()
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Http\Url::external( "https://apis.live.net/v5.0/{$this->member->live_id}/picture?type=large" );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = \IPS\Http\Url::external( "https://apis.live.net/v5.0/{$this->member->live_id}?access_token={$this->authToken()}" )->request()->get()->decodeJson();
|
||||
if ( isset( $user['name'] ) )
|
||||
{
|
||||
return $user['name'];
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _disassociate()
|
||||
{
|
||||
$this->member->live_id = 0;
|
||||
$this->member->live_token = NULL;
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Profile Sync Abstract Class
|
||||
* @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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Profile Sync Interface
|
||||
*/
|
||||
abstract class _ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handlers
|
||||
*/
|
||||
protected static $loginHandlers = NULL;
|
||||
|
||||
/**
|
||||
* Get services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function services()
|
||||
{
|
||||
$services = array();
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/core/sources/ProfileSync' ) as $file )
|
||||
{
|
||||
if ( !$file->isDot() and mb_substr( $file, -4 ) === '.php' )
|
||||
{
|
||||
require_once $file->getPathname();
|
||||
$class = 'IPS\core\ProfileSync\\' . mb_substr( $file, 0, -4 );
|
||||
|
||||
if ( $class::enabled() )
|
||||
{
|
||||
$services[ mb_substr( $file, 0, -4 ) ] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enabled?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function enabled()
|
||||
{
|
||||
if ( isset( static::$loginKey ) )
|
||||
{
|
||||
if ( static::$loginHandlers === NULL )
|
||||
{
|
||||
static::$loginHandlers = iterator_to_array( \IPS\Db::i()->select( '*', 'core_login_handlers' )->setKeyField( 'login_key' ) );
|
||||
}
|
||||
|
||||
if ( isset( static::$loginHandlers[ static::$loginKey ] ) )
|
||||
{
|
||||
return (bool) static::$loginHandlers[ static::$loginKey ]['login_enabled'];
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Member
|
||||
*/
|
||||
protected $member;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \IPS\Member $member The member
|
||||
*/
|
||||
public function __construct( \IPS\Member $member )
|
||||
{
|
||||
$this->member = $member;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function connected();
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @return \IPS\Http\Url|\IPS\File|NULL
|
||||
*/
|
||||
abstract public function photo();
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function name();
|
||||
|
||||
/**
|
||||
* Get settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function settings()
|
||||
{
|
||||
$settings = $this->member->profilesync ? json_decode( $this->member->profilesync, TRUE ) : array();
|
||||
return ( isset( $settings[ static::$loginKey ] ) ? $settings[ static::$loginKey ] : array(
|
||||
'photo' => FALSE,
|
||||
'cover' => FALSE,
|
||||
'status' => ''
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings as string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function settingsDesc()
|
||||
{
|
||||
$settings = $this->settings();
|
||||
$return = array();
|
||||
if ( $settings['photo'] or $settings['cover'] )
|
||||
{
|
||||
$_return = array();
|
||||
if ( $settings['photo'] )
|
||||
{
|
||||
$_return[] = \IPS\Member::loggedIn()->language()->addToStack('sync_settings_photo');
|
||||
}
|
||||
if ( $settings['cover'] )
|
||||
{
|
||||
$_return[] = \IPS\Member::loggedIn()->language()->addToStack('sync_settings_cover');
|
||||
}
|
||||
|
||||
if ( count( $_return ) > 1 )
|
||||
{
|
||||
$return[] = \IPS\Member::loggedIn()->language()->formatList( $_return, \IPS\Member::loggedIn()->language()->get('sync_settings_syncing') );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return[] = $_return[0];
|
||||
}
|
||||
}
|
||||
if ( $settings['status'] )
|
||||
{
|
||||
$langKey = 'sync_settings_status_' . $settings['status'];
|
||||
$return[] = \IPS\Member::loggedIn()->language()->addToStack( $langKey );
|
||||
}
|
||||
|
||||
return empty( $return ) ? \IPS\Member::loggedIn()->language()->addToStack('profilesync_not_syncing') : \IPS\Member::loggedIn()->language()->formatList( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Settings
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
public function save( $values )
|
||||
{
|
||||
$settings = $this->member->profilesync ? json_decode( $this->member->profilesync, TRUE ) : array(
|
||||
static::$loginKey => array(
|
||||
'photo' => FALSE,
|
||||
'cover' => FALSE,
|
||||
'status' => ''
|
||||
)
|
||||
);
|
||||
|
||||
$settings[ static::$loginKey ] = array(
|
||||
'photo' => isset( $values['profilesync_photo'] ) ? $values['profilesync_photo'] : ( isset( $settings[ static::$loginKey ]['photo'] ) ? $settings[ static::$loginKey ]['photo'] : FALSE ),
|
||||
'cover' => isset( $values['profilesync_cover'] ) ? $values['profilesync_cover'] : ( isset( $settings[ static::$loginKey ]['cover'] ) ? $settings[ static::$loginKey ]['cover'] : FALSE ),
|
||||
'status' => isset( $values['profilesync_status'] ) ? $values['profilesync_status'] : ( isset( $settings[ static::$loginKey ]['status'] ) ? $settings[ static::$loginKey ]['status'] : FALSE ),
|
||||
);
|
||||
$this->member->profilesync = json_encode( $settings );
|
||||
|
||||
/* If we're enabling status import, reset last sync time so we import the latest status */
|
||||
if ( isset( $values['profilesync_status'] ) AND $values['profilesync_status'] == 'import' )
|
||||
{
|
||||
$this->member->profilesync_lastsync = 0;
|
||||
}
|
||||
|
||||
$this->member->save();
|
||||
$this->sync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sync()
|
||||
{
|
||||
$settings = $this->settings();
|
||||
if ( $settings['photo'] )
|
||||
{
|
||||
$class = get_called_class();
|
||||
try
|
||||
{
|
||||
if ( $photo = $this->photo() )
|
||||
{
|
||||
if ( $photo instanceof \IPS\File )
|
||||
{
|
||||
$this->member->pp_main_photo = (string) $photo;
|
||||
$this->member->pp_thumb_photo = NULL;
|
||||
$this->member->pp_photo_type = 'custom';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->member->pp_main_photo = (string) $photo;
|
||||
$this->member->pp_thumb_photo = NULL;
|
||||
$this->member->pp_photo_type = 'sync-' . mb_substr( $class, mb_strrpos( $class, '\\' ) + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e ) {}
|
||||
}
|
||||
if ( $settings['cover'] and $this->member->group['gbw_allow_upload_bgimage'] )
|
||||
{
|
||||
if ( $this->member->pp_cover_photo )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Profile', $this->member->pp_cover_photo )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$this->member->pp_cover_photo = (string) $this->cover();
|
||||
}
|
||||
if ( $settings['status'] and $settings['status'] == 'import' )
|
||||
{
|
||||
if ( $status = $this->status() )
|
||||
{
|
||||
if ( $status->date > $this->member->profilesync_lastsync )
|
||||
{
|
||||
try
|
||||
{
|
||||
$status->member_id = $this->member->member_id;
|
||||
$status->imported = TRUE;
|
||||
$status->save();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
// May fail if status contains invalid data (like utf8mb4 characters if the database doesn't support that, etc)
|
||||
// In this case, we will just skip over the status
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->member->profilesync_lastsync = time();
|
||||
$this->member->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disassociate()
|
||||
{
|
||||
$settings = $this->member->profilesync ? json_decode( $this->member->profilesync, TRUE ) : array();
|
||||
$class = get_called_class();
|
||||
unset( $settings[ $class::$loginKey ] );
|
||||
$this->member->profilesync = empty( $settings ) ? NULL : json_encode( $settings );
|
||||
|
||||
$this->_disassociate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
namespace IPS\core\ProfileSync;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Twitter Profile Sync
|
||||
*/
|
||||
class _Twitter extends ProfileSyncAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Login handler key
|
||||
*/
|
||||
public static $loginKey = 'Twitter';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'twitter';
|
||||
|
||||
/**
|
||||
* @brief User data
|
||||
*/
|
||||
protected $user = NULL;
|
||||
|
||||
/**
|
||||
* Get user data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function user()
|
||||
{
|
||||
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();
|
||||
|
||||
if ( isset( $this->user['errors'] ) )
|
||||
{
|
||||
throw new \Exception;
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$this->member->twitter_token = '';
|
||||
$this->member->twitter_secret = '';
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
{
|
||||
return (bool) ( $this->member->twitter_id and $this->member->twitter_token and $this->member->twitter_secret );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photo
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cover photo
|
||||
*
|
||||
* @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'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Http\Url::external( $user['profile_background_image_url_https'] );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
if( isset( $user['profile_background_image_url'] ) AND $user['profile_background_image_url'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Http\Url::external( $user['profile_background_image_url'] )->import( 'core_Profile' );
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
$user = $this->user();
|
||||
return ( isset( $user['screen_name'] ) ) ? $user['screen_name'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status
|
||||
*
|
||||
* @return \IPS\core\Statuses\Status|null
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
if ( isset( $user['status'] ) )
|
||||
{
|
||||
$status = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $user['status']['created_at'] ) );
|
||||
$status->content = $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
|
||||
*/
|
||||
protected function _disassociate()
|
||||
{
|
||||
$this->member->twitter_id = 0;
|
||||
$this->member->twitter_token = '';
|
||||
$this->member->twitter_secret = '';
|
||||
$this->member->save();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user