Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,48 +12,59 @@
|
||||
namespace IPS\core\Followed;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow Model
|
||||
*/
|
||||
class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
class Follow extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_follow';
|
||||
public static ?string $databaseTable = 'core_follow';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'follow_';
|
||||
public static string $databasePrefix = 'follow_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if( $this->_new )
|
||||
{
|
||||
@@ -70,8 +81,8 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array|null
|
||||
* @apiresponse int followKey Unique key that represents the follow
|
||||
* @apiresponse string followApp The application of the content that was followed
|
||||
* @apiresponse string followArea The area of the content that was followed
|
||||
@@ -83,23 +94,23 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
* @apiresponse string followName Textual representation of the content that was followed (title, name, etc.)
|
||||
* @apiresponse string followUrl URL to the content that was followed
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array|null
|
||||
{
|
||||
if( $this->area == 'member' AND $this->app == 'core' )
|
||||
{
|
||||
$followed = \IPS\Member::load( $this->rel_id );
|
||||
$followed = Member::load( $this->rel_id );
|
||||
$name = $followed->name;
|
||||
$url = $followed->url();
|
||||
}
|
||||
else if( $this->area == 'club' AND $this->app == 'core')
|
||||
{
|
||||
$followed = \IPS\Member\Club::load( $this->rel_id );
|
||||
$followed = Club::load( $this->rel_id );
|
||||
$name = $followed->name;
|
||||
$url = $followed->url();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( \IPS\Application::load( $this->app )->extensions( 'core', 'ContentRouter' ) as $key => $router )
|
||||
foreach( Application::load( $this->app )->extensions( 'core', 'ContentRouter' ) as $key => $router )
|
||||
{
|
||||
foreach( $router->classes as $class )
|
||||
{
|
||||
@@ -113,7 +124,7 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
$name = $followed->mapped('title');
|
||||
$url = $followed->url();
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
/* If the item doesn't exist we may as well clean up core_follow */
|
||||
parent::delete();
|
||||
@@ -150,12 +161,12 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
$name = $followed->_title;
|
||||
$url = $followed->url();
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
/* If the item doesn't exist we may as well clean up core_follow */
|
||||
parent::delete();
|
||||
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,9 +183,9 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
'followAnon' => (bool) $this->is_anon,
|
||||
'followNotify' => (bool) $this->notify_do,
|
||||
'followType' => $this->notify_do ? $this->notify_freq : NULL,
|
||||
'followSent' => $this->notify_sent ? \IPS\DateTime::ts( $this->notify_sent )->rfc3339() : NULL,
|
||||
'followName' => $name,
|
||||
'followUrl' => (string) $url,
|
||||
'followSent' => $this->notify_sent ? DateTime::ts( $this->notify_sent )->rfc3339() : NULL,
|
||||
'followName' => $name ?? '',
|
||||
'followUrl' => ( isset( $url ) ? (string) $url : '' ),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,10 +193,10 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* @var array[<string><string>] Special follow classes
|
||||
*/
|
||||
public static $specialFollowClasses = [
|
||||
public static array $specialFollowClasses = [
|
||||
'core' => [
|
||||
'member' => \IPS\Member::class,
|
||||
'club' => \IPS\Member\Club::class,
|
||||
'member' => Member::class,
|
||||
'club' => Club::class,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -195,7 +206,7 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
* @param string $app Application key
|
||||
* @param string $area Area
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function getClassToFollow(string $app, string $area): string
|
||||
{
|
||||
@@ -205,10 +216,10 @@ class _Follow extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
else
|
||||
{
|
||||
$classToFollow = 'IPS\\' . $app . '\\' . mb_ucfirst( $area );
|
||||
if( !class_exists( $classToFollow) or !array_key_exists( $app, \IPS\Application::applications() ) )
|
||||
$classToFollow = 'IPS\\' . $app . '\\' . IPS::mb_ucfirst( $area );
|
||||
if( !class_exists( $classToFollow) or !array_key_exists( $app, Application::applications() ) )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
throw new InvalidArgumentException;
|
||||
}
|
||||
}
|
||||
return $classToFollow;
|
||||
|
||||
Reference in new issue
Block a user