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
@@ -11,59 +11,83 @@
|
||||
namespace IPS\core;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use BadMethodCallException;
|
||||
use DateInterval;
|
||||
use IPS\Content;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function class_exists;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function substr;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletion Log Model
|
||||
*/
|
||||
class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
class DeletionLog extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_deletion_log';
|
||||
public static ?string $databaseTable = 'core_deletion_log';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'dellog_';
|
||||
public static string $databasePrefix = 'dellog_';
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$this->deleted_date = \IPS\DateTime::create();
|
||||
$this->deleted_date = DateTime::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set deleted date
|
||||
*
|
||||
* @param \IPS\DateTime $time A DateTime object
|
||||
* @param DateTime $time A DateTime object
|
||||
* @return void
|
||||
*/
|
||||
public function set_deleted_date( \IPS\DateTime $time )
|
||||
public function set_deleted_date( DateTime $time ) : void
|
||||
{
|
||||
$this->_data['deleted_date'] = $time->getTimestamp();
|
||||
}
|
||||
@@ -71,20 +95,20 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get deleted date
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_deleted_date()
|
||||
public function get_deleted_date() : DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['deleted_date'] );
|
||||
return DateTime::ts( $this->_data['deleted_date'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Deleted By
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param Member $member The member
|
||||
* @return void
|
||||
*/
|
||||
public function set_deleted_by( \IPS\Member $member )
|
||||
public function set_deleted_by( Member $member ) : void
|
||||
{
|
||||
$this->_data['deleted_by'] = $member->member_id;
|
||||
$this->_data['deleted_by_name'] = $member->real_name;
|
||||
@@ -94,18 +118,18 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* @brief Deleted By Cache
|
||||
*/
|
||||
protected $_deletedBy = NULL;
|
||||
protected ?Member $_deletedBy = NULL;
|
||||
|
||||
/**
|
||||
* Get Deleted By
|
||||
*
|
||||
* @return \IPS\Member
|
||||
* @return Member
|
||||
*/
|
||||
public function get__deleted_by()
|
||||
public function get__deleted_by() : Member
|
||||
{
|
||||
if ( $this->_deletedBy === NULL AND $this->_data['deleted_by'] !== NULL )
|
||||
{
|
||||
$this->_deletedBy = \IPS\Member::load( $this->_data['deleted_by'] );
|
||||
$this->_deletedBy = Member::load( $this->_data['deleted_by'] );
|
||||
}
|
||||
return $this->_deletedBy;
|
||||
}
|
||||
@@ -115,7 +139,7 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function get_content_permissions()
|
||||
public function get_content_permissions() : array|string
|
||||
{
|
||||
if ( $this->_data['content_permissions'] == '*' )
|
||||
{
|
||||
@@ -127,7 +151,7 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
$return = array( 'members' => array(), 'groups' => array() );
|
||||
foreach( $perms AS $perm )
|
||||
{
|
||||
if ( \substr( $perm, 0, 1 ) == 'm' )
|
||||
if ( substr( $perm, 0, 1 ) == 'm' )
|
||||
{
|
||||
$return['members'][] = str_replace( 'm', '', $perm );
|
||||
}
|
||||
@@ -143,41 +167,41 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get the date the content will be permanently removed on
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_deletion_date()
|
||||
public function get_deletion_date() : DateTime
|
||||
{
|
||||
return $this->deleted_date->add( new \DateInterval( 'P' . \IPS\Settings::i()->dellog_retention_period . 'D' ) );
|
||||
return $this->deleted_date->add( new DateInterval( 'P' . Settings::i()->dellog_retention_period . 'D' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content and Member
|
||||
*
|
||||
* @param \IPS\Content $content The content being deleted.
|
||||
* @param \IPS\Member|NULL $member The member performing the deletion, NULL for the currently logged in member, or FALSE for no member (i.e. system task)
|
||||
* @param Content $content The content being deleted.
|
||||
* @param Member|NULL $member The member performing the deletion, NULL for the currently logged in member, or FALSE for no member (i.e. system task)
|
||||
* @return void
|
||||
* @note Convenience ftw
|
||||
*/
|
||||
public function setContentAndMember( \IPS\Content $content, $member = NULL )
|
||||
public function setContentAndMember( Content $content, ?Member $member = NULL ) : void
|
||||
{
|
||||
if( $member === NULL )
|
||||
{
|
||||
$member = \IPS\Member::loggedIn();
|
||||
$member = Member::loggedIn();
|
||||
}
|
||||
|
||||
|
||||
$idField = $content::$databaseColumnId;
|
||||
|
||||
$item = $content;
|
||||
if ( $content instanceof \IPS\Content\Comment )
|
||||
if ( $content instanceof Comment )
|
||||
{
|
||||
$item = $content->item();
|
||||
}
|
||||
|
||||
/* Content Data */
|
||||
$this->content_class = \get_class( $content );
|
||||
$this->content_class = get_class( $content );
|
||||
$this->content_id = $content->$idField;
|
||||
$this->content_title = $item->mapped('title');
|
||||
$this->content_seo_title = \IPS\Http\Url\Friendly::seoTitle( $item->mapped('title') );
|
||||
$this->content_seo_title = Friendly::seoTitle( $item->mapped('title') );
|
||||
$this->content_permissions = $item->deleteLogPermissions();
|
||||
|
||||
try
|
||||
@@ -185,7 +209,7 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
$this->content_container_id = $item->container()->_id;
|
||||
$this->content_container_class = $item::$containerNodeClass;
|
||||
}
|
||||
catch( \BadMethodCallException | \OutOfRangeException $e )
|
||||
catch( BadMethodCallException | OutOfRangeException $e )
|
||||
{
|
||||
$this->content_container_id = 0;
|
||||
$this->content_container_class = NULL;
|
||||
@@ -201,18 +225,18 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$contentClass = $this->content_class;
|
||||
$content = $contentClass::load( $this->content_id );
|
||||
|
||||
if( $content instanceof \IPS\Content\Searchable )
|
||||
if( Content\Search\SearchContent::isSearchable( $contentClass ) )
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->removeFromSearchIndex( $content );
|
||||
/* @var Content $contentClass */
|
||||
$content = $contentClass::load( $this->content_id );
|
||||
Index::i()->removeFromSearchIndex( $content );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,15 +248,15 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @param int $id ID
|
||||
* @return static
|
||||
* @throws \OutOfRangeException
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function loadAndCheckPerms( $id )
|
||||
public static function loadAndCheckPerms( int $id ) : static
|
||||
{
|
||||
$obj = parent::load( $id );
|
||||
|
||||
if ( !$obj->canView() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@@ -241,28 +265,28 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Load from content
|
||||
*
|
||||
* @param \IPS\Content $content The content object
|
||||
* @param \IPS\Member $member Member for permission checking
|
||||
* @param Content $content The content object
|
||||
* @param Member|null $member Member for permission checking
|
||||
* @return static
|
||||
* @throws \OutOfRangeException
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function loadFromContent( \IPS\Content $content, ?\IPS\Member $member = NULL ): \IPS\core\DeletionLog
|
||||
public static function loadFromContent( Content $content, ?Member $member = NULL ): static
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
try
|
||||
{
|
||||
$idColumn = $content::$databaseColumnId;
|
||||
$log = static::constructFromData( \IPS\Db::i()->select( '*', 'core_deletion_log', array( "dellog_content_class=? AND dellog_content_id=?", \get_class( $content ), $content->$idColumn ) )->first() );
|
||||
$log = static::constructFromData( Db::i()->select( '*', 'core_deletion_log', array( "dellog_content_class=? AND dellog_content_id=?", get_class( $content ), $content->$idColumn ) )->first() );
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if ( !$log->canView( $member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return $log;
|
||||
@@ -271,19 +295,19 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Can View
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member, or NULL for currently logged in
|
||||
* @param Member|NULL $member The member, or NULL for currently logged in
|
||||
* @return bool
|
||||
*/
|
||||
public function canView( \IPS\Member $member = NULL )
|
||||
public function canView( ?Member $member = null ) : bool
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if ( !\is_array( $this->content_permissions ) AND $this->content_permissions == '*' )
|
||||
if ( !is_array( $this->content_permissions ) AND $this->content_permissions == '*' )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ( \in_array( $member->member_id, $this->content_permissions['members'] ) )
|
||||
if ( in_array( $member->member_id, $this->content_permissions['members'] ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -305,41 +329,100 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
* URL
|
||||
*
|
||||
* @param string|NULL $action "action" parameter or NULL to go to the content
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public function url( $action=NULL )
|
||||
public function url( string|null $action=NULL ): Url
|
||||
{
|
||||
if ( $action === NULL )
|
||||
{
|
||||
try
|
||||
if ( $object = $this->object() )
|
||||
{
|
||||
$class = $this->content_class;
|
||||
if ( class_exists( $this->content_class ) )
|
||||
{
|
||||
$item = $class::load( $this->content_id );
|
||||
return $item->url()->setQueryString( 'showDeleted', 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Content class doesn't exist anymore */
|
||||
$this->delete();
|
||||
return \IPS\Http\Url::internal( "app=core&module=modcp&controller=modcp&tab=deleted", 'front', 'modcp_deleted' )->setQueryString( array( 'id' => $this->id, 'action' => $action ) );
|
||||
}
|
||||
return $object->url()->setQueryString( 'showDeleted', 1 );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
else
|
||||
{
|
||||
/* Orphaned item */
|
||||
$this->delete();
|
||||
|
||||
return \IPS\Http\Url::internal( "app=core&module=modcp&controller=modcp&tab=deleted", 'front', 'modcp_deleted' )->setQueryString( array( 'id' => $this->id, 'action' => $action ) );
|
||||
return Url::internal( "app=core&module=modcp&controller=modcp&tab=deleted", 'front', 'modcp_deleted' )->setQueryString( array( 'id' => $this->id, 'action' => $action ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Http\Url::internal( "app=core&module=modcp&controller=modcp&tab=deleted", 'front', 'modcp_deleted' )->setQueryString( array( 'id' => $this->id, 'action' => $action ) );
|
||||
return Url::internal( "app=core&module=modcp&controller=modcp&tab=deleted", 'front', 'modcp_deleted' )->setQueryString( array( 'id' => $this->id, 'action' => $action ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The content object
|
||||
*
|
||||
* @return ?Content
|
||||
*/
|
||||
public function object() : ?Content
|
||||
{
|
||||
$class = $this->content_class;
|
||||
if ( class_exists( $this->content_class ) )
|
||||
{
|
||||
/* @var Content $class */
|
||||
try
|
||||
{
|
||||
return $class::load( $this->content_id );
|
||||
}
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* Orphaned item */
|
||||
$this->delete();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Content class doesn't exist anymore */
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title wrapper for items and nodes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function objectTitle() : string
|
||||
{
|
||||
$object = $this->object();
|
||||
|
||||
if ( $object instanceof Item )
|
||||
{
|
||||
return $object->mapped('title');
|
||||
}
|
||||
else if ( $object instanceof Comment )
|
||||
{
|
||||
return $object->item()->mapped('title');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title wrapper for items and nodes
|
||||
*
|
||||
* @return Model|null
|
||||
*/
|
||||
public function objectContainer() : ?Model
|
||||
{
|
||||
$object = $this->object();
|
||||
|
||||
if ( $object instanceof Item )
|
||||
{
|
||||
return $object->containerWrapper() ? $object->container() : null;
|
||||
}
|
||||
else if ( $object instanceof Comment )
|
||||
{
|
||||
return $object->item()->containerWrapper() ? $object->item()->container() : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass update permissions for a specific node
|
||||
*
|
||||
@@ -348,14 +431,14 @@ class _DeletionLog extends \IPS\Patterns\ActiveRecord
|
||||
* @param string|array $perms The permissions to update with
|
||||
* @return void
|
||||
*/
|
||||
public static function updateNodePermissions( $class, $id, $perms )
|
||||
public static function updateNodePermissions( string $class, int $id, string|array $perms ) : void
|
||||
{
|
||||
if ( \is_array( $perms ) )
|
||||
if ( is_array( $perms ) )
|
||||
{
|
||||
$perms = implode( ',', $perms );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_deletion_log', array(
|
||||
Db::i()->update( 'core_deletion_log', array(
|
||||
'dellog_content_permissions' => $perms
|
||||
), array( "dellog_content_container_id=? AND dellog_content_container_class=?", $id, $class ) );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user