Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+40 -29
View File
@@ -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;
+81 -48
View File
@@ -12,40 +12,61 @@
namespace IPS\core\Followed;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Content\Tag;
use IPS\Db;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Node\Model;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfRangeException;
use function defined;
use function in_array;
use function is_array;
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;
}
/**
* Table Builder for followed content
*/
class _Table extends \IPS\Helpers\Table\Db
class Table extends \IPS\Helpers\Table\Db
{
/**
* @brief Follow class data
*/
protected $currentType;
protected array $currentType = [];
/**
* @var string
*/
protected string $className = '';
/**
* Constructor
*
* @param string $className Name of class to load data from
* @param array $currentType Follow class data
* @return void
*/
public function __construct( $className, $currentType )
{
$this->className = $className;
$this->currentType = $currentType;
$this->include = array( 'follow_added', 'follow_app', 'follow_area', 'follow_rel_id', 'follow_notify_freq', 'follow_is_anon' );
$this->classes[] = 'ipsDataList_zebra';
$this->classes[] = 'ipsData--zebra';
/* Allow to filter by digests only */
$this->filters['digest'] = array( "follow_notify_freq IN('daily','weekly')" );
$return = parent::__construct( 'core_follow', \IPS\Http\Url::internal( 'app=core&module=system&controller=followed', 'front', 'followed_content' )->setQueryString( 'type', "{$currentType[0]}_{$currentType[1]}" ), array( 'follow_member_id=? AND follow_app=? AND follow_area=?', \IPS\Member::loggedIn()->member_id, $currentType[0], $currentType[1] ) );
$return = parent::__construct( 'core_follow', Url::internal( 'app=core&module=system&controller=followed', 'front', 'followed_content' )->setQueryString( 'type', "{$currentType[0]}_{$currentType[1]}" ), array( 'follow_member_id=? AND follow_app=? AND follow_area=?', Member::loggedIn()->member_id, $currentType[0], $currentType[1] ) );
if ( !$this->sortBy )
{
@@ -55,6 +76,7 @@ class _Table extends \IPS\Helpers\Table\Db
if( is_subclass_of( $className, 'IPS\Content\Item' ) )
{
/* @var array $databaseColumnMap */
$this->rowsTemplate = $className::manageFollowRows();
$containerClass = $className::$containerNodeClass;
@@ -63,37 +85,36 @@ class _Table extends \IPS\Helpers\Table\Db
);
/* Exclude hidden items */
if ( \in_array( 'IPS\Content\Hideable', class_implements( $className ) ) and !$className::canViewHiddenItems() )
if ( IPS::classUSesTrait( $className, 'IPS\Content\Hideable' ) and !$className::canViewHiddenItems() )
{
$authorCol = $className::$databaseTable . '.' . $className::$databasePrefix . $className::$databaseColumnMap['author'];
if ( isset( $className::$databaseColumnMap['approved'] ) )
{
$col = $className::$databaseTable . '.' . $className::$databasePrefix . $className::$databaseColumnMap['approved'];
$this->where[0] .= " AND ( {$col}=1 OR ( {$col}=0 AND {$authorCol}=" . \IPS\Member::loggedIn()->member_id . " ) )";
$this->where[0] .= " AND ( {$col}=1 OR ( {$col}=0 AND {$authorCol}=" . Member::loggedIn()->member_id . " ) )";
}
elseif ( isset( $className::$databaseColumnMap['hidden'] ) )
{
$col = $className::$databaseTable . '.' . $className::$databasePrefix . $className::$databaseColumnMap['hidden'];
$this->where[0] .= " AND ( {$col}=0 OR ( {$col}=1 AND {$authorCol}=" . \IPS\Member::loggedIn()->member_id . " ) )";
$this->where[0] .= " AND ( {$col}=0 OR ( {$col}=1 AND {$authorCol}=" . Member::loggedIn()->member_id . " ) )";
}
}
/* Additional where */
$joinContainer = $className::$containerNodeClass ? TRUE : FALSE;
$joinContainer = (bool )$className::$containerNodeClass;
$joins = array();
$extraWhere = $className::followWhere( $joinContainer, $joins );
if ( $joinContainer )
{
$containerClass = $className::$containerNodeClass;
$this->joins[] = array( 'from' => $containerClass::$databaseTable, 'where' => $containerClass::$databaseTable . '.' . $containerClass::$databasePrefix . $containerClass::$databaseColumnId . '=' . $className::$databaseTable . '.' . $className::$databasePrefix . $className::$databaseColumnMap['container'], 'type' => 'STRAIGHT_JOIN' );
}
/* Permissions */
if ( \in_array( 'IPS\Content\Permissions', class_implements( $className ) ) )
if( in_array( 'IPS\Node\Permissions', class_implements( $containerClass ) ) )
{
$containerClass = $className::$containerNodeClass;
$this->where[0] .= ' AND (' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . $containerClass::$permissionMap['view'], \IPS\Member::loggedIn()->permissionArray() ) . ' OR core_permission_index.perm_' . $containerClass::$permissionMap['view'] . "='*' )";
/* @var array $permissionMap */
$this->where[0] .= ' AND (' . Db::i()->findInSet( 'core_permission_index.perm_' . $containerClass::$permissionMap['view'], Member::loggedIn()->permissionArray() ) . ' OR core_permission_index.perm_' . $containerClass::$permissionMap['view'] . "='*' )";
}
$this->joins[] = array( 'from' => 'core_permission_index', 'where' => array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . $containerClass::$databaseTable . '.' . $containerClass::$databasePrefix . $containerClass::$databaseColumnId, $containerClass::$permApp, $containerClass::$permType ) );
@@ -124,10 +145,15 @@ class _Table extends \IPS\Helpers\Table\Db
}
elseif( $className == "\IPS\Member" )
{
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'system', 'core', 'front' ), 'followedContentMemberRow' );
$this->rowsTemplate = array( Theme::i()->getTemplate( 'system', 'core', 'front' ), 'followedContentMemberRow' );
}
elseif( $className == "IPS\Content\Tag" )
{
$this->rowsTemplate = array( Theme::i()->getTemplate( 'system', 'core', 'front' ), 'followedContentTagRow' );
}
else
{
/* @var Model $className */
$this->rowsTemplate = $className::manageFollowNodeRow();
$this->joins = array(
@@ -136,9 +162,10 @@ class _Table extends \IPS\Helpers\Table\Db
);
/* Permission check? */
if ( \in_array( 'IPS\Node\Permissions', class_implements( $className ) ) )
if ( in_array( 'IPS\Node\Permissions', class_implements( $className ) ) )
{
$this->where[0] .= ' AND (' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . $className::$permissionMap['view'], \IPS\Member::loggedIn()->permissionArray() ) . ' OR ' . 'core_permission_index.perm_' . $className::$permissionMap['view'] . "='*' )";
/* @var array $permissionMap */
$this->where[0] .= ' AND (' . Db::i()->findInSet( 'core_permission_index.perm_' . $className::$permissionMap['view'], Member::loggedIn()->permissionArray() ) . ' OR ' . 'core_permission_index.perm_' . $className::$permissionMap['view'] . "='*' )";
}
/* Additional where */
@@ -165,7 +192,7 @@ class _Table extends \IPS\Helpers\Table\Db
}
/* Do any multi-mod */
if ( isset( \IPS\Request::i()->modaction ) )
if ( isset( Request::i()->modaction ) )
{
$this->multiMod();
}
@@ -176,10 +203,10 @@ class _Table extends \IPS\Helpers\Table\Db
/**
* Get rows
*
* @param array $advancedSearchValues Values from the advanced search form
* @param array|null $advancedSearchValues Values from the advanced search form
* @return array
*/
public function getRows( $advancedSearchValues )
public function getRows( array $advancedSearchValues = NULL ): array
{
$rows = parent::getRows( $advancedSearchValues );
@@ -187,13 +214,19 @@ class _Table extends \IPS\Helpers\Table\Db
{
if( $row['follow_area'] == 'member' AND $row['follow_app'] == 'core' )
{
$object = \IPS\Member::load( $row['follow_rel_id'] );
$object = Member::load( $row['follow_rel_id'] );
$object->_followData = $row;
$rows[ $index ] = $object;
}
elseif( $row['follow_area'] == 'tag' and $row['follow_app'] == 'core' )
{
$object = Tag::load( $row['follow_rel_id'] );
$object->_followData = $row;
$rows[ $index ] = $object;
}
else
{
foreach( \IPS\Application::load( $row['follow_app'] )->extensions( 'core', 'ContentRouter' ) as $key => $router )
foreach( Application::load( $row['follow_app'] )->extensions( 'core', 'ContentRouter' ) as $key => $router )
{
foreach( $router->classes as $class )
{
@@ -207,12 +240,12 @@ class _Table extends \IPS\Helpers\Table\Db
$object->_followData = $row;
$rows[ $index ] = $object;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
unset( $rows[ $index ] );
/* If the item doesn't exist we may as well clean up core_follow */
\IPS\Db::i()->delete( 'core_follow', array( array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', $row['follow_app'], $row['follow_area'], $row['follow_rel_id'] ) ) );
Db::i()->delete( 'core_follow', array( array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', $row['follow_app'], $row['follow_area'], $row['follow_rel_id'] ) ) );
}
}
else
@@ -240,16 +273,16 @@ class _Table extends \IPS\Helpers\Table\Db
{
try
{
$object = $container::load( $row['follow_rel_id'] );;
$object = $container::load( $row['follow_rel_id'] );
$object->_followData = $row;
$rows[ $index ] = $object;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
unset( $rows[ $index ] );
/* If the item doesn't exist we may as well clean up core_follow */
\IPS\Db::i()->delete( 'core_follow', array( array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', $row['follow_app'], $row['follow_area'], $row['follow_rel_id'] ) ) );
Db::i()->delete( 'core_follow', array( array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', $row['follow_app'], $row['follow_area'], $row['follow_rel_id'] ) ) );
}
}
}
@@ -265,19 +298,19 @@ class _Table extends \IPS\Helpers\Table\Db
/**
* @brief Return table filters
*/
public $showFilters = TRUE;
public bool $showFilters = TRUE;
/**
* Saved Actions (for multi-moderation)
*/
public $savedActions = array();
public array $savedActions = array();
/**
* Return the filters that are available for selecting table rows
*
* @return array
*/
public function getFilters()
public function getFilters() : array
{
return array(
'follow_freq_immediate', 'follow_freq_daily', 'follow_freq_weekly', 'follow_freq_none',
@@ -292,7 +325,7 @@ class _Table extends \IPS\Helpers\Table\Db
* @param string|null $action Specific action to check (hide/unhide, etc.) or NULL for a generic check
* @return bool
*/
public function canModerate( $action=NULL )
public function canModerate( ?string $action=NULL ): bool
{
if ( $action === NULL )
{
@@ -307,13 +340,13 @@ class _Table extends \IPS\Helpers\Table\Db
* @param object $item Item
* @return array
*/
public function multimodActions( $item )
public function multimodActions( object $item ) : array
{
$return = array();
if ( $item->_followData )
{
if ( !( $item instanceof \IPS\Member ) )
if ( !( $item instanceof Member ) )
{
foreach ( array( 'immediate', 'daily', 'weekly', 'none' ) as $k )
{
@@ -344,45 +377,45 @@ class _Table extends \IPS\Helpers\Table\Db
*
* @return void
*/
protected function multimod()
protected function multimod() : void
{
if( !\is_array( \IPS\Request::i()->moderate ) )
if( !is_array( Request::i()->moderate ) )
{
return;
}
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
$where = array( array( 'follow_member_id=? AND follow_app=? AND follow_area=?', \IPS\Member::loggedIn()->member_id, $this->currentType[0], $this->currentType[1] ), \IPS\Db::i()->in( 'follow_rel_id', array_keys( \IPS\Request::i()->moderate ) ) );
$where = array( array( 'follow_member_id=? AND follow_app=? AND follow_area=?', Member::loggedIn()->member_id, $this->currentType[0], $this->currentType[1] ), Db::i()->in( 'follow_rel_id', array_keys( Request::i()->moderate ) ) );
$update = array();
switch ( \IPS\Request::i()->modaction )
switch ( Request::i()->modaction )
{
case 'follow_immediate':
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'immediate' ), $where );
Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'immediate' ), $where );
break;
case 'follow_daily':
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'daily' ), $where );
Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'daily' ), $where );
break;
case 'follow_weekly':
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'weekly' ), $where );
Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'weekly' ), $where );
break;
case 'follow_none':
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'none' ), $where );
Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'none' ), $where );
break;
case 'follow_public':
\IPS\Db::i()->update( 'core_follow', array( 'follow_is_anon' => 0 ), $where );
Db::i()->update( 'core_follow', array( 'follow_is_anon' => 0 ), $where );
break;
case 'follow_anonymous':
\IPS\Db::i()->update( 'core_follow', array( 'follow_is_anon' => 1 ), $where );
Db::i()->update( 'core_follow', array( 'follow_is_anon' => 1 ), $where );
break;
case 'unfollow':
\IPS\Db::i()->delete( 'core_follow', $where );
Db::i()->delete( 'core_follow', $where );
break;
}
\IPS\Output::i()->redirect( $this->baseUrl );
Output::i()->redirect( $this->baseUrl );
}
}