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

+207 -32
View File
@@ -11,41 +11,57 @@
namespace IPS\core;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Content;
use IPS\Content\Comment;
use IPS\Content\Item;
use IPS\Content\Review;
use IPS\Db;
use IPS\Member;
use IPS\Patterns\ActiveRecord;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
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;
}
/**
* Deletion Log Model
*/
class _Approval extends \IPS\Patterns\ActiveRecord
class Approval extends ActiveRecord
{
/**
* @brief Database Table
*/
public static $databaseTable = 'core_approval_queue';
public static ?string $databaseTable = 'core_approval_queue';
/**
* @brief Database Prefix
*/
public static $databasePrefix = 'approval_';
public static string $databasePrefix = 'approval_';
/**
* @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 Held Data
@@ -53,9 +69,9 @@ class _Approval extends \IPS\Patterns\ActiveRecord
* @param NULL|array $data The data indicating why the content was held for approval
* @return void
*/
public function set_held_data( ?array $data )
public function set_held_data( ?array $data ) : void
{
if ( \is_array( $data ) )
if ( is_array( $data ) )
{
$this->_data['held_data'] = json_encode( $data );
return;
@@ -67,7 +83,7 @@ class _Approval extends \IPS\Patterns\ActiveRecord
/**
* Get Held Data
*
* @return array
* @return array|null
*/
public function get_held_data(): ?array
{
@@ -85,9 +101,9 @@ class _Approval extends \IPS\Patterns\ActiveRecord
* @param NULL|string $reason The reason for requiring approval.
* @return void
*/
public function set_held_reason( ?string $reason )
public function set_held_reason( ?string $reason ) : void
{
if ( $reason AND \in_array( $reason, static::availableReasons() ) )
if ( $reason AND in_array( $reason, static::availableReasons() ) )
{
$this->_data['held_reason'] = $reason;
return;
@@ -99,12 +115,12 @@ class _Approval extends \IPS\Patterns\ActiveRecord
/**
* Get Held Reason
*
* @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 NULL|string
*/
public function reason( ?\IPS\Member $member = NULL ): string
public function reason( ?Member $member = NULL ): string
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
if ( $this->held_reason )
{
if ( $extra = $this->parseReason() )
@@ -125,12 +141,12 @@ class _Approval extends \IPS\Patterns\ActiveRecord
/**
* Parse Reason
*
* @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 NULL|array
*/
public function parseReason( ?\IPS\Member $member = NULL ): ?array
public function parseReason( ?Member $member = NULL ): ?array
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
if ( $this->held_reason )
{
switch( $this->held_reason )
@@ -140,21 +156,18 @@ class _Approval extends \IPS\Patterns\ActiveRecord
'lang' => 'approval_reason_profanity',
'sprintf' => array( $this->held_data['word'] )
);
break;
case 'url':
return array(
'lang' => 'approval_reason_url',
'sprintf' => array( $this->held_data['url'] )
);
break;
case 'email':
return array(
'lang' => 'approval_reason_email',
'sprintf' => array( $this->held_data['email'] )
);
break;
case 'node':
$contentClass = $this->content_class;
@@ -163,21 +176,26 @@ class _Approval extends \IPS\Patterns\ActiveRecord
'lang' => 'approval_reason_node',
'sprintf' => array( $content->indefiniteArticle(), $content->container()->url(), $content->container()->getTitleForLanguage( $member->language() ), $content->definiteArticle( $member->language(), 2 ) )
);
break;
case 'item':
$contentClass = $this->content_class;
$content = $contentClass::load( $this->content_id );
$title = ( $content instanceof \IPS\Content\Comment ) ? $content->item()->mapped('title') : $content->mapped('title');
$title = ( $content instanceof Comment ) ? $content->item()->mapped('title') : $content->mapped('title');
return array(
'lang' => 'approval_reason_item',
'sprintf' => array( $content->url(), $title )
);
break;
default:
/* See if we have an extension */
foreach( Application::allExtensions( 'core', 'ApprovalReason' ) AS $ext )
{
if ( $ext->reasonKey() === $this->held_reason AND $data = $ext->parseReason( $this ) )
{
return $data;
}
}
return NULL;
break;
}
}
@@ -191,7 +209,7 @@ class _Approval extends \IPS\Patterns\ActiveRecord
*/
public static function availableReasons(): array
{
return array(
$reasons = array(
'profanity',
'url',
'email',
@@ -200,6 +218,18 @@ class _Approval extends \IPS\Patterns\ActiveRecord
'node',
'item'
);
if ( Application::appIsEnabled( 'cloud' ) )
{
$reasons[] = 'image';
}
foreach( Application::allExtensions( 'core', 'ApprovalReason' ) AS $ext )
{
$reasons[] = $ext->reasonKey();
}
return $reasons;
}
/**
@@ -208,17 +238,162 @@ class _Approval extends \IPS\Patterns\ActiveRecord
* @param string $class Content class
* @param int $id Content ID
* @return static
* @throws OutOfRangeException
*/
public static function loadFromContent( string $class, int $id ): \IPS\core\Approval
public static function loadFromContent( string $class, int $id ): static
{
try
{
return static::constructFromData( \IPS\Db::i()->select( '*', 'core_approval_queue', array( "approval_content_class=? AND approval_content_id=?", $class, $id ) )->first() );
return static::constructFromData( Db::i()->select( '*', 'core_approval_queue', array( "approval_content_class=? AND approval_content_id=?", $class, $id ) )->first() );
}
catch( \UnderflowException $e )
catch( UnderflowException )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
/**
* Load the item that is pending approval
*
* @return Content|Member\Club|null
*/
public function item() : Content|Member\Club|null
{
$class = $this->content_class;
try
{
return $class::load( $this->content_id );
}
catch( OutOfRangeException )
{
return null;
}
}
/**
* Output of the row for the ModCP
*
* @return string
*/
public function html() : string
{
$item = $this->item();
if( !$item )
{
return "";
}
$container = NULL;
$actions = $this->modActions( $item );
if( $item instanceof Member\Club )
{
return Theme::i()->getTemplate( 'modcp', 'core', 'front' )->approvalQueueClubWrapper( Theme::i()->getTemplate('clubs')->clubCard( $item, TRUE ), $actions );
}
if ( $item instanceof Comment )
{
$itemClass = $item::$itemClass;
$ref = base64_encode( json_encode( array( 'app' => $itemClass::$application, 'module' => $itemClass::$module, 'id_1' => $item->mapped('item'), 'id_2' => $item->id ) ) );
$title = $item->item()->mapped('title');
$container = $item->item()->container();
}
else
{
$ref = base64_encode( json_encode( array( 'app' => $item::$application, 'module' => $item::$module, 'id_1' => $item->id ) ) );
try
{
$container = $item->container();
}
catch ( Exception ) { }
$title = $item->mapped('title');
}
return Theme::i()->getTemplate( 'modcp', 'core', 'front' )->approvalQueueItemWrapper( $item->approvalQueueHtml( $ref, $container, $title ), $actions, $this->id );
}
/**
* Figure out which moderation actions are available for this item
*
* @param Content|Member\Club $item
* @return array
*/
public function modActions( Content|Member\Club $item ) : array
{
$idColumn = $item::$databaseColumnId;
$actions = [];
if( $item instanceof Member\Club )
{
$actions['approve'] = $item->url()->setQueryString( array( 'do' => 'approve', 'approved' => 1 ) )->csrf();
$actions['delete'] = $item->url()->setQueryString( array( 'do' => 'approve', 'approved' => 0 ) )->csrf();
return $actions;
}
if ( $item instanceof Comment )
{
$classType = ( $item instanceof Review ) ? 'Review' : 'Comment';
if( $item->canUnhide() )
{
$actions['approve'] = $item->url()->setQueryString( array( 'do' => 'unhide' . $classType, strtolower( $classType ) => $item->$idColumn ) )->csrf();
}
if( $item->canDelete() )
{
$actions['delete'] = $item->url()->setQueryString( array( 'do' => 'delete' . $classType, strtolower( $classType ) => $item->$idColumn ) )->csrf();
}
if( $item->canHide() )
{
$actions['hide'] = $item->url()->setQueryString( array( 'do' => 'hide' . $classType, strtolower( $classType ) => $item->$idColumn ) )->csrf();
}
}
else
{
if( $item->canUnhide() )
{
$actions['approve'] = $item->url()->setQueryString( array( 'do' => 'moderate', 'action' => 'unhide' ) )->csrf();
}
if( $item->canDelete() )
{
$actions['delete'] = $item->url()->setQueryString( array( 'do' => 'moderate', 'action' => 'delete' ) )->csrf();
}
if( $item->canHide() )
{
$actions['hide'] = $item->url()->setQueryString( array( 'do' => 'moderate', 'action' => 'hide', '_fromApproval' => 1 ) )->csrf();
}
}
return $actions;
}
/**
* Save Changed Columns
*
* @return void
*/
public function save(): void
{
/* Store the container ID */
if( $this->_new OR $this->container_id === null )
{
try
{
$class = $this->content_class;
$item = $class::load( $this->content_id );
if( $item instanceof Item )
{
$this->container_id = $item->mapped( 'container' );
}
elseif( $item instanceof Comment )
{
$this->container_id = $item->item()->mapped( 'container' );
}
}
catch( OutOfRangeException ){}
}
parent::save();
}
}