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

@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -83,6 +83,8 @@ class _Facebook extends ProfileSyncAbstract
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'facebook' );
return NULL;
}
}
@@ -94,12 +96,20 @@ class _Facebook extends ProfileSyncAbstract
*/
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'] ) )
try
{
return \IPS\Http\Url::external( $response['cover']['source'] )->import( 'core_Profile' );
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}" )->setQueryString( array( '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' );
}
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'facebook' );
return NULL;
}
return NULL;
}
/**
@@ -111,7 +121,7 @@ class _Facebook extends ProfileSyncAbstract
{
try
{
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}?access_token={$this->member->fb_token}" )->request()->get()->decodeJson();
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}" )->setQueryString( 'access_token', $this->member->fb_token )->request()->get()->decodeJson();
if ( isset( $response['name'] ) )
{
return $response['name'];
@@ -119,10 +129,30 @@ class _Facebook extends ProfileSyncAbstract
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'facebook' );
return NULL;
}
}
/**
* Member can import statuses?
*
* @return array
*/
public function canImportStatus( \IPS\Member $member )
{
if ( parent::canImportStatus( $member ) )
{
$loginHandlers = \IPS\Login::handlers( TRUE );
if ( isset( $loginHandlers['Facebook'] ) AND isset( $loginHandlers['Facebook']->settings['allow_status_import'] ) )
{
return $loginHandlers['Facebook']->settings['allow_status_import'];
}
}
return FALSE;
}
/**
* Get status
*
@@ -132,34 +162,27 @@ class _Facebook extends ProfileSyncAbstract
{
try
{
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}/statuses?access_token={$this->member->fb_token}" )->request()->get()->decodeJson();
$response = \IPS\Http\Url::external( "https://graph.facebook.com/{$this->member->fb_uid}/feed" )->setQueryString( '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( \IPS\Text\Parser::utf8mb4SafeDecode( $statusData['message'] ), FALSE );
$status = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $statusData['created_time'] ) );
$status->content = $this->_parseStatusText( nl2br( $statusData['message'], FALSE ) );
return $status;
}
}
}
catch ( \IPS\Http\Request\Exception $e ) { }
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'facebook' );
}
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
*
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -55,14 +55,14 @@ class _Google extends ProfileSyncAbstract
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'];
@@ -73,9 +73,11 @@ class _Google extends ProfileSyncAbstract
{
$this->member->google_token = NULL;
$this->member->save();
\IPS\Log::log( $e, 'google' );
}
}
return $this->user;
}
@@ -97,11 +99,20 @@ class _Google extends ProfileSyncAbstract
*/
public function photo()
{
$user = $this->user();
if ( isset( $user['image'] ) )
try
{
return \IPS\Http\Url::external( preg_replace( '/\?sz=\d+$/', '', $user['image']['url'] ) );
$user = $this->user();
if ( isset( $user['image'] ) )
{
return \IPS\Http\Url::external( preg_replace( '/\?sz=\d+$/', '', $user['image']['url'] ) );
}
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'google' );
}
return NULL;
}
/**
@@ -111,11 +122,19 @@ class _Google extends ProfileSyncAbstract
*/
public function cover()
{
$user = $this->user();
if ( isset( $user['cover'] ) )
try
{
return \IPS\Http\Url::external( $user['cover']['coverPhoto']['url'] )->import( 'core_Profile' );
$user = $this->user();
if ( isset( $user['cover'] ) )
{
return \IPS\Http\Url::external( $user['cover']['coverPhoto']['url'] )->import( 'core_Profile' );
}
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'google' );
}
return NULL;
}
@@ -127,7 +146,11 @@ class _Google extends ProfileSyncAbstract
public function name()
{
$user = $this->user();
return $user['displayName'];
if ( isset( $user['displayName'] ) )
{
return $user['displayName'];
}
}
/**
@@ -137,20 +160,28 @@ class _Google extends ProfileSyncAbstract
*/
public function status()
{
$this->user();
$statuses = $this->get( "people/me/activities/public" );
if ( isset( $statuses['items'] ) )
try
{
foreach ( $statuses['items'] as $status )
$this->user();
$statuses = $this->get( "people/me/activities/public" );
if ( isset( $statuses['items'] ) )
{
if ( $status['object']['content'] )
foreach ( $statuses['items'] as $status )
{
$statusObj = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $status['published'] ) );
$statusObj->content = nl2br( \IPS\Text\Parser::utf8mb4SafeDecode( $status['object']['content'] ), FALSE );
return $statusObj;
if ( $status['object']['content'] )
{
$statusObj = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( $status['published'] ) );
$statusObj->content = $this->_parseStatusText( nl2br( $status['object']['content'], FALSE ) );
return $statusObj;
}
}
}
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Log::log( $e, 'google' );
}
return NULL;
}
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -61,7 +61,7 @@ class _Linkedin extends ProfileSyncAbstract
$this->member->save();
}
}
return $this->user;
}
@@ -78,7 +78,7 @@ class _Linkedin extends ProfileSyncAbstract
/**
* Get photo
*
* @return \IPS\Http\Url|null
* @return \IPS\Http\Url|NULL
*/
public function photo()
{
@@ -87,6 +87,7 @@ class _Linkedin extends ProfileSyncAbstract
{
return \IPS\Http\Url::external( $user['picture-url'] );
}
return NULL;
}
@@ -98,7 +99,10 @@ class _Linkedin extends ProfileSyncAbstract
public function name()
{
$user = $this->user();
return $user['formatted-name'];
if ( isset( $user['formatted-name'] ) )
{
return $user['formatted-name'];
}
}
/**
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -97,14 +97,7 @@ class _Microsoft extends ProfileSyncAbstract
*/
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;
}
return \IPS\Http\Url::external( "https://apis.live.net/v5.0/{$this->member->live_id}/picture?type=large" );
}
/**
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 13 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -40,13 +40,15 @@ abstract class _ProfileSyncAbstract
{
if ( !$file->isDot() and mb_substr( $file, -4 ) === '.php' and mb_substr( $file, 0, 2 ) != '._' )
{
require_once $file->getPathname();
$class = 'IPS\core\ProfileSync\\' . mb_substr( $file, 0, -4 );
if ( $class::enabled() )
if ( class_exists( 'IPS\core\ProfileSync\\' . mb_substr( $file, 0, -4 ) ) )
{
$services[ mb_substr( $file, 0, -4 ) ] = $class;
}
$class = 'IPS\core\ProfileSync\\' . mb_substr( $file, 0, -4 );
if ( $class::enabled() )
{
$services[ mb_substr( $file, 0, -4 ) ] = $class;
}
}
}
}
return $services;
@@ -97,19 +99,22 @@ abstract class _ProfileSyncAbstract
*/
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();
/**
* Member can import statuses?
*
* @return array
*/
public function canImportStatus( \IPS\Member $member )
{
return \IPS\Settings::i()->profile_comments and method_exists( $this, 'status' ) and $member->canAccessModule( \IPS\Application\Module::get( 'core', 'members', 'front' ) ) and $member->pp_setting_count_comments and !$member->members_bitoptions['bw_no_status_update'] and !$member->group['gbw_no_status_import'];
}
/**
* Get settings
@@ -156,7 +161,7 @@ abstract class _ProfileSyncAbstract
$return[] = $_return[0];
}
}
if ( $settings['status'] )
if ( $settings['status'] and \IPS\Settings::i()->profile_comments )
{
$langKey = 'sync_settings_status_' . $settings['status'];
$return[] = \IPS\Member::loggedIn()->language()->addToStack( $langKey );
@@ -186,7 +191,7 @@ abstract class _ProfileSyncAbstract
$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'] == 'none' ) ? FALSE : $values['profilesync_status'] : ( isset( $settings[ static::$loginKey ]['status'] ) ? $settings[ static::$loginKey ]['status'] : FALSE ),
'status' => isset( $values['profilesync_status'] ) ? ( $values['profilesync_status'] ? 'import' : '' ) : ( isset( $settings[ static::$loginKey ]['status'] ) ? $settings[ static::$loginKey ]['status'] : FALSE ),
);
/* We cannot have more than one service syncing photos/cover photos - otherwise they conflict */
@@ -224,6 +229,12 @@ abstract class _ProfileSyncAbstract
*/
public function sync()
{
/* Don't sync for banned users */
if( $this->member->isBanned() )
{
return;
}
$settings = $this->settings();
if ( $settings['photo'] )
{
@@ -250,22 +261,32 @@ abstract class _ProfileSyncAbstract
}
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 ) { }
}
/* Download and import the synced cover photo */
try
{
$this->member->pp_cover_photo = (string) $this->cover();
$coverPhoto = (string) $this->cover();
}
catch ( \RuntimeException $e ) {}
/* Did we get a cover photo returned? */
if ( !empty( $coverPhoto ) )
{
/* Delete any existing */
if ( $this->member->pp_cover_photo )
{
try
{
\IPS\File::get( 'core_Profile', $this->member->pp_cover_photo )->delete();
}
catch ( \Exception $e ) { }
}
/* Save */
$this->member->pp_cover_photo = $coverPhoto;
}
}
if ( $settings['status'] and $settings['status'] == 'import' and !$this->member->group['gbw_no_status_import'] )
/* We check against canImportStatus() to ensure we check all appropriate restrictions, including group and member restrictions */
if ( $settings['status'] and $settings['status'] == 'import' and $this->canImportStatus( $this->member ) )
{
if ( $status = $this->status() )
{
@@ -276,6 +297,8 @@ abstract class _ProfileSyncAbstract
$status->member_id = $this->member->member_id;
$status->imported = TRUE;
$status->save();
\IPS\Content\Search\Index::i()->index( $status );
}
catch ( \Exception $e )
{
@@ -304,4 +327,22 @@ abstract class _ProfileSyncAbstract
$this->_disassociate();
}
/**
* Parse status text - ensures valid and safe HTML, filters profanity, etc.
*
* @param string $value
* @return void
*/
protected function _parseStatusText( $value )
{
/* Make sure utf8mb4 characters won't cause us issues */
$value = \IPS\Text\Parser::utf8mb4SafeDecode( $value );
/* Parse */
$value = \IPS\Text\Parser::parseStatic( $value, FALSE, NULL, $this->member, 'core_Members' );
/* Return */
return $value;
}
}
@@ -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;
}
}
@@ -0,0 +1,160 @@
<?php
/**
* @brief Vkontakte 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 _VK extends ProfileSyncAbstract
{
/**
* @brief Login handler key
*/
public static $loginKey = 'vkontakte';
/**
* @brief Icon
*/
public static $icon = 'vk';
/**
* Is connected?
*
* @return bool
*/
public function connected()
{
return ( $this->member->vk_uid and $this->member->vk_token );
}
/**
* Get photo
*
* @return \IPS\Http\Url|null
*/
public function photo()
{
try
{
$response = \IPS\Http\Url::external( "https://api.vk.com/method/users.get?user_id={$this->member->vk_uid}&v=5.29&access_token={$this->member->vk_token}&fields=photo_400_orig" )->request()->get()->decodeJson();
if ( isset( $response['response'][0]['photo_400_orig'] ))
{
$file = \IPS\Http\Url::external( $response['response'][0]['photo_400_orig'] )->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\File|NULL
*/
/*public function cover()
{
$response = \IPS\Http\Url::external( "https://api.vk.com/method/users.get?user_id={$this->member->vk_uid}&v=5.29&access_token={$this->member->vk_token}&fields=photo_100" )->request()->get()->decodeJson();
if ( isset( $response['response'][0]['photo_100'] ) )
{
return \IPS\Http\Url::external( $response['response'][0]['photo_100'] )->import( 'core_Profile' );
}
return NULL;
}*/
/**
* Get name
*
* @return string
*/
public function name()
{
try
{
$response = \IPS\Http\Url::external( "https://api.vk.com/method/users.get?user_id={$this->member->vk_uid}&v=5.29&access_token={$this->member->vk_token}" )->request()->get()->decodeJson();
if ( isset( $response['response'][0]['first_name'], $response['response'][0]['last_name'] ) )
{
return $response['response'][0]['first_name'].' '.$response['response'][0]['last_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://api.vk.com/method/users.get?user_id={$this->member->vk_uid}&v=5.29&access_token={$this->member->vk_token}&fields=status" )->request()->get()->decodeJson();
if ( !empty( $response['response'][0]['status'] ) )
{
$status = \IPS\core\Statuses\Status::createItem( $this->member, $this->member->ip_address, new \IPS\DateTime( ) );
$status->content = nl2br( $response['response'][0]['status'], FALSE );
return $status;
}
}
catch ( \IPS\Http\Request\Exception $e ) { }
return NULL;
}
/**
* Disassociate
*
* @return void
*/
protected function _disassociate()
{
$this->member->vk_uid = 0;
$this->member->vk_token = NULL;
$this->member->save();
}
}