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

+26 -31
View File
@@ -11,46 +11,52 @@
namespace IPS\core\Reports;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Comment as ContentComment;
use IPS\Http\Url;
use IPS\Member;
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;
}
/**
* Report Comment Model
*/
class _Comment extends \IPS\Content\Comment
class Comment extends ContentComment
{
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'core_rc_comments';
public static ?string $databaseTable = 'core_rc_comments';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = '';
public static string $databasePrefix = '';
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\core\Reports\Report';
public static string $itemClass = 'IPS\core\Reports\Report';
/**
* @brief Application
*/
public static $application = 'core';
public static string $application = 'core';
/**
* @brief [Content\Comment] Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'item' => 'rid',
'date' => 'comment_date',
'content' => 'comment',
@@ -62,15 +68,15 @@ class _Comment extends \IPS\Content\Comment
/**
* @brief Title
*/
public static $title = 'report_comment';
public static string $title = 'report_comment';
/**
* Get mapped value
*
* @param string $key date,content,ip_address,first
* @param string $key date,content,ip_address,first
* @return mixed
*/
public function mapped( $key )
public function mapped( string $key ): mixed
{
/* Get the reported content items title */
if ( $key === 'title' )
@@ -84,16 +90,16 @@ class _Comment extends \IPS\Content\Comment
/**
* Can view this entry
*
* @param \IPS\Member|NULL $member The member or NULL for currently logged in member.
* @param Member|NULL $member The member or NULL for currently logged in member.
* @return bool
*/
public function canView( $member = NULL )
public function canView( Member|null $member = null ): bool
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
$return = parent::canView($member);
$return = parent::canView( $member );
if ( $return AND $member->modPermission('can_view_reports') )
if( $return AND $this->item()->canView( $member ) )
{
return TRUE;
}
@@ -104,9 +110,9 @@ class _Comment extends \IPS\Content\Comment
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @return Url
*/
public function url( $action='find' )
public function url( ?string $action='find' ): Url
{
$url = parent::url( $action );
$idColumn = static::$databaseColumnId;
@@ -121,16 +127,5 @@ class _Comment extends \IPS\Content\Comment
/**
* @brief Value to set for the 'tab' parameter when redirecting to the comment (via _find())
*/
public static $tabParameter = array( 'activeTab' => 'comments' );
/**
* Can promote this comment/item?
*
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
* @return boolean
*/
public function canPromoteToSocialMedia( $member=NULL )
{
return FALSE;
}
public static ?array $tabParameter = array( 'activeTab' => 'comments' );
}
+189 -322
View File
@@ -11,78 +11,98 @@
namespace IPS\core\Reports;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use InvalidArgumentException;
use IPS\Content;
use IPS\Content\Comment;
use IPS\Content\Item;
use IPS\Content\ReadMarkers;
use IPS\core\Reports\Comment as ReportComment;
use IPS\DateTime;
use IPS\Db;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Node\Model;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use RuntimeException;
use UnderflowException;
use function count;
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;
}
/**
* Report Model
*/
class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
class Report extends Item
{
use ReadMarkers;
/**
* @brief Const No type selected
*/
const TYPE_MESSAGE = 0;
/**
* @brief Const Reported content statuses
*/
const STATUS_NEW = 1;
const STATUS_OPEN = 2;
const STATUS_CLOSED = 3;
const STATUS_REJECTED = 4;
/* !\IPS\Patterns\ActiveRecord */
/**
* @brief Database Table
*/
public static $databaseTable = 'core_rc_index';
public static ?string $databaseTable = 'core_rc_index';
/**
* @brief Database Prefix
*/
public static $databasePrefix = '';
public static string $databasePrefix = '';
/**
* @brief Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief Database ID Fields
*/
protected static $databaseIdFields = array( 'content_id' );
protected static array $databaseIdFields = array( 'content_id' );
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
protected static array $multitonMap = array();
/* !\IPS\Content\Item */
/**
* @brief Application
*/
public static $application = 'core';
public static string $application = 'core';
/**
* @brief Application
*/
public static $module = 'modcp';
public static string $module = 'modcp';
/**
* @brief Allow the title to be editable via AJAX
*/
public $editableTitle = FALSE;
public bool $editableTitle = FALSE;
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'date' => 'first_report_date',
'author' => 'first_report_by',
'author_count' => 'num_reports',
@@ -94,22 +114,22 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* @brief Language prefix for forms
*/
public static $formLangPrefix = 'report_';
public static string $formLangPrefix = 'report_';
/**
* @brief Comment Class
*/
public static $commentClass = 'IPS\core\Reports\Comment';
public static ?string $commentClass = 'IPS\core\Reports\Comment';
/**
* @brief Title
*/
public static $title = 'report';
public static string $title = 'report';
/**
* @brief [Content\Item] Include these items in trending content
*/
public static $includeInTrending = FALSE;
public static bool $includeInTrending = FALSE;
/**
* Should IndexNow be skipped for this item? Can be used to prevent that Private Messages,
@@ -121,10 +141,10 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Should posting this increment the poster's post count?
*
* @param \IPS\Node\Model|NULL $container Container
* @return void
* @param Model|NULL $container Container
* @return bool
*/
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
public static function incrementPostCount( Model $container = NULL ): bool
{
return FALSE;
}
@@ -135,228 +155,27 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
* @param string $class Class to load
* @param int $id ID to load
* @return static
* @throws \OutofRangeException
* @throws OutofRangeException
*/
public static function loadByClassAndId( $class, $id )
public static function loadByClassAndId( string $class, int $id ) : static
{
try
{
return static::constructFromData( \IPS\Db::i()->select( '*', 'core_rc_index', array( 'class=? and content_id=?', $class, $id ) )->first() );
return static::constructFromData( Db::i()->select( '*', 'core_rc_index', array( 'class=? and content_id=?', $class, $id ) )->first() );
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
throw new \OutofRangeException;
throw new OutofRangeException;
}
}
/**
* Get all the report types for this report index
*
* @return array
*/
public function getReportedTypes(): array
{
$reportedTypes = [];
$reportTypes = [];
foreach ( \IPS\core\Reports\Types::roots() as $type )
{
$reportTypes[ $type->id ] = $type->_title;
}
foreach ( \IPS\Db::i()->select( '*', 'core_rc_reports', ['rid=? and report_type > 0', $this->id] ) as $report )
{
if ( isset( $reportTypes[ $report['report_type'] ] ) )
{
$reportedTypes[ $report['report_type'] ] = $reportTypes[ $report['report_type'] ];
}
}
return $reportedTypes;
}
/**
* Set the status of the report
*
* @param int $status
* @param $member
* @return void
*/
public function changeStatus( int $status, int $authorNotification=0, $member=null )
{
$member = $member ?: \IPS\Member::loggedIn();
$this->status = $status;
$this->save();
/* We only need to notify if there is an outcome */
if ( $status == static::STATUS_CLOSED or static::STATUS_REJECTED )
{
$forNotifications = [];
$forEmails = [];
/* Now go through all the individual reports and see if we need to notify anyone */
foreach ( \IPS\Db::i()->select( '*', 'core_rc_reports', ['rid=?', $this->id] ) as $report )
{
if ( !$report['report_type'] )
{
/* We have not selected a reason, no nothing to worry about */
continue;
}
/* Get the report type object */
try
{
$reportType = \IPS\core\Reports\Types::load( $report['report_type'] );
$reportMember = \IPS\Member::load( $report['report_by'] );
}
catch ( \Exception $e )
{
continue;
}
if ( $report['report_by'] )
{
/* We have a member */
$forNotifications[$report['report_type']][] = [$reportMember, $reportType, $report];
}
else
{
if ( $report['guest_email'] )
{
/* We have an email */
$forEmails[$report['report_type']][] = [$reportType, $report];
}
}
}
/* Members */
foreach ( $forNotifications as $typeId => $data )
{
foreach ( $data as $reportData )
{
$reportMember = $reportData[0];
$reportType = $reportData[1];
$userReport = $reportData[2];
if ( $this->getReportOutcomeBlurb( $userReport['id'] ) )
{
$notification = new \IPS\Notification( \IPS\Application::load( 'core' ), 'report_outcome', $this, [$this, $reportType, $userReport], ['reportType' => $reportType->id, 'userReport' => $userReport] );
$notification->recipients->attach( $reportMember );
$notification->send();
\IPS\Log::debug( "Sent notification to {$reportMember->name}", 'reports_notification' );
}
}
}
/* Guests */
foreach ( $forEmails as $typeId => $data )
{
foreach ( $data as $reportData )
{
$reportType = $reportData[0];
$guestEmail = $reportData[1]['guest_email'];
$userReport = $reportData[1];
if ( $guestEmail and $this->getReportOutcomeBlurb( $userReport['id'] ) )
{
\IPS\Email::buildFromTemplate( 'core', 'notification_report_outcome', [$this, $reportType, $userReport], \IPS\Email::TYPE_LIST )->send( $guestEmail );
}
}
}
/* Content author? */
if ( $authorNotification )
{
try
{
$class = $this->_data['class'];
$thing = $class::load( $this->_data['content_id'] );
$content = ( $thing instanceof \IPS\Content\Comment ) ? $thing->truncated() : $thing->mapped( 'title' );
if ( $thing->author() and $thing->author()->email )
{
$authorContent = static::getAuthorNotifications();
if ( isset( $authorContent[ $authorNotification ] ) )
{
$notificationContent = $authorContent[$authorNotification]['text'];
/* Substitutions */
$subs = [
'name' => $thing->author()->name,
'content' => trim( $content ),
'link' => (string) $thing->url(),
'reason' => implode( ', ', $this->getReportedTypes() )
];
foreach( $subs as $key => $value )
{
$notificationContent = str_replace( '{' . $key . '}', $value, $notificationContent );
}
\IPS\Email::buildFromTemplate( 'core', 'notification_report_content_author', [$this, $thing, $notificationContent], \IPS\Email::TYPE_LIST )->send( $thing->author()->email );
}
}
}
catch ( \Exception $e ) { }
}
}
/* Post a comment on the report */
$content = $member->language()->addToStack( 'update_report_status_content', FALSE, array( 'sprintf' => array( $member->language()->addToStack( 'report_status_' . $this->status ) ) ) );
$member->language()->parseOutputForDisplay( $content );
$comment = \IPS\core\Reports\Comment::create( $this, $content, TRUE, NULL, NULL, $member, new \IPS\DateTime );
$comment->save();
/* And add to the moderator log */
\IPS\Session::i()->modLog( 'modlog__action_update_report_status', array( $this->url()->__toString() => FALSE ) );
}
/**
* Get the author notifications
*
* @return array
*/
public static function getAuthorNotifications(): array
{
$return = [];
foreach( \IPS\Db::i()->select( '*', 'core_rc_author_notification_text', [], 'title ASC' ) as $row )
{
$return[ $row['id'] ] = $row;
}
return $return;
}
/**
* Get the report outcome blurb
*
* @param int $userReportId
* @return string
*/
public function getReportOutcomeBlurb( int $userReportId ): string
{
try
{
$userReport = \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'id=?', $userReportId ) )->first();
$reportType = \IPS\core\Reports\Types::load( $userReport['report_type'] );
return $this->status === static::STATUS_REJECTED ? $reportType->getRejectedNotificationText( \IPS\Member::load( $userReport['report_by'] ) ) : $reportType->getCompletedNotificationText( \IPS\Member::load( $userReport['report_by'] ) );
}
catch( \Exception $e )
{
return '';
}
}
/**
* Get mapped value
*
* @param string $key date,content,ip_address,first
* @param string $key date,content,ip_address,first
* @return mixed
*/
public function mapped( $key )
public function mapped( string $key ): mixed
{
/* Get the reported content items title */
if ( $key === 'title' )
@@ -365,22 +184,22 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
{
$class = $this->_data['class'];
$thing = $class::load( $this->_data['content_id'] );
$item = ( $thing instanceof \IPS\Content\Comment ) ? $thing->item() : $thing;
$item = ( $thing instanceof Comment ) ? $thing->item() : $thing;
if( isset( $item::$databaseColumnMap['content'] ) AND $item::$databaseColumnMap['content'] == $item::$databaseColumnMap['title'] )
{
$title = trim( mb_substr( strip_tags( $item->mapped( 'title' ) ), 0, 85 ) );
return $title ?: \IPS\Member::loggedIn()->language()->addToStack('report_no_title_available');
}
else
{
$title = trim( strip_tags( $item->mapped( 'title' ) ) );
return $title ?: \IPS\Member::loggedIn()->language()->addToStack('report_no_title_available');
}
return $title ?: Member::loggedIn()->language()->addToStack('report_no_title_available');
}
catch ( \Exception $e )
catch ( Exception $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'unknown' );
return Member::loggedIn()->language()->addToStack( 'unknown' );
}
}
@@ -390,21 +209,21 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* @brief Cached URLs
*/
protected $_url = array();
protected mixed $_url = array();
/**
* Get URL
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @return Url
*/
public function url( $action=NULL )
public function url( string|null $action=NULL ): Url
{
$_key = md5( $action );
$_key = $action ? md5( $action ) : NULL;
if( !isset( $this->_url[ $_key ] ) )
{
$this->_url[ $_key ] = \IPS\Http\Url::internal( "app=core&module=modcp&tab=reports&action=view&id={$this->id}", 'front', 'modcp_report' );
$this->_url[ $_key ] = Url::internal( "app=core&module=modcp&tab=reports&action=view&id={$this->id}", 'front', 'modcp_report' );
if ( $action )
{
@@ -424,7 +243,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
* @param array $rows Array of objects of this class
* @return void
*/
public static function tableGetRows( $rows )
public static function tableGetRows( array $rows ) : void
{
$types = array();
@@ -435,17 +254,20 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
foreach ( $types as $class => $objects )
{
if ( \in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
if ( in_array( 'IPS\Content\Comment', class_parents( $class ) ) )
{
/* @var Comment $class */
$itemClass = $class::$itemClass;
$databaseTable = $class::$databaseTable;
$itemDatabaseTable = $itemClass::$databaseTable;
/* @var array $databaseColumnMap */
$itemTitleField = $itemClass::$databaseColumnMap['title']; # Strange PHP issue can cause this to be lost when added to the query below.
foreach( \IPS\Db::i()->select(
foreach( Db::i()->select(
"{$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnId} as commentId, {$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnMap['item']} AS itemId, {$itemClass::$databaseTable}.{$itemClass::$databasePrefix}{$itemTitleField} AS title",
$databaseTable,
\IPS\Db::i()->in( $databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
Db::i()->in( $databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
)->join(
$itemDatabaseTable,
"{$itemDatabaseTable}.{$itemClass::$databasePrefix}{$itemClass::$databaseColumnId}={$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnMap['item']}"
@@ -455,12 +277,14 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
$objects[ $k ]->_data = array_merge( $objects[ $k ]->_data, $data );
}
}
elseif ( \in_array( 'IPS\Content\Item', class_parents( $class ) ) )
elseif ( in_array( 'IPS\Content\Item', class_parents( $class ) ) )
{
foreach( \IPS\Db::i()->select(
/* @var Item $class */
/* @var array $databaseColumnMap */
foreach( Db::i()->select(
"{$class::$databasePrefix}{$class::$databaseColumnId} as itemId, {$class::$databasePrefix}{$class::$databaseColumnMap['title']} AS title",
$class::$databaseTable,
\IPS\Db::i()->in( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
Db::i()->in( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
)->setKeyField( 'itemId' ) as $k => $data
)
{
@@ -475,14 +299,14 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return string
*/
public function tableDescription()
public function tableDescription() : string
{
$className = $this->class;
try
{
$reportedContent = $className::load( $this->content_id );
if( $reportedContent instanceof \IPS\Content\Comment )
if( $reportedContent instanceof Comment )
{
$container = ( $reportedContent->item()->containerWrapper() !== NULL ) ? $reportedContent->item()->container() : NULL;
}
@@ -491,12 +315,12 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
$container = ( $reportedContent->containerWrapper() !== NULL ) ? $reportedContent->container() : NULL;
}
}
catch ( \OutOfRangeException $ex )
catch ( OutOfRangeException $ex )
{
$container = NULL;
}
return \IPS\Theme::i()->getTemplate( 'modcp', 'core', 'front' )->reportTableDescription( $className, $this, $container );
return Theme::i()->getTemplate( 'modcp', 'core', 'front' )->reportTableDescription( $className, $this, $container );
}
/**
@@ -504,7 +328,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return string
*/
public function tableStates()
public function tableStates(): string
{
$states = explode( ' ', parent::tableStates() );
$states[] = "report_status_" . $this->status;
@@ -515,10 +339,10 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Stats for table view
*
* @param bool $includeFirstCommentInCommentCount Whether or not to include the first comment in the comment count
* @param bool $includeFirstCommentInCommentCount Whether or not to include the first comment in the comment count
* @return array
*/
public function stats( $includeFirstCommentInCommentCount=TRUE )
public function stats( bool $includeFirstCommentInCommentCount=TRUE ): array
{
return array_merge( parent::stats( $includeFirstCommentInCommentCount ), array( 'num_reports' => $this->num_reports ) );
}
@@ -528,9 +352,9 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return array
*/
public function tableIcon()
public function tableIcon() : array
{
return \IPS\Theme::i()->getTemplate( 'modcp', 'core', 'front' )->reportToggle( $this );
return Theme::i()->getTemplate( 'modcp', 'core', 'front' )->reportToggle( $this );
}
/**
@@ -538,16 +362,14 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return string
*/
public function tableClass()
public function tableClass() : string
{
switch ( $this->status )
{
case 2:
return 'warning';
break;
case 1:
return 'new';
break;
}
return '';
@@ -556,22 +378,33 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Do Moderator Action
*
* @param string $action The action
* @param \IPS\Member|NULL $member The member doing the action (NULL for currently logged in member)
* @param string|NULL $reason Reason (for hides)
* @param bool $immediately Delete immediately
* @param string $action The action
* @param Member|NULL $member The member doing the action (NULL for currently logged in member)
* @param string|null $reason Reason (for hides)
* @param bool $immediately Delete immediately
* @return void
* @throws \OutOfRangeException|\InvalidArgumentException|\RuntimeException
* @throws OutOfRangeException|InvalidArgumentException|RuntimeException
*/
public function modAction( $action, \IPS\Member $member = NULL, $reason = NULL, $immediately = FALSE )
public function modAction(string $action, Member $member = NULL, mixed $reason = NULL, bool $immediately=FALSE ): void
{
if ( mb_substr( $action, 0, -1 ) === 'report_status_' )
{
$this->changeStatus( (int) mb_substr( $action, -1 ) );
$this->status = mb_substr( $action, -1 );
$this->save();
/* Post a comment on the report */
$content = Member::loggedIn()->language()->addToStack( 'update_report_status_content', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( 'report_status_' . $this->status ) ) ) );
Member::loggedIn()->language()->parseOutputForDisplay( $content );
$comment = ReportComment::create( $this, $content, true, null, null, Member::loggedIn(), new DateTime );
$comment->save();
/* And add to the moderator log */
Session::i()->modLog( 'modlog__action_update_report_status', array( $this->url()->__toString() => FALSE ) );
}
else
{
return parent::modAction( $action, $member, $reason, $immediately );
parent::modAction( $action, $member, $reason, $immediately );
}
}
@@ -580,9 +413,9 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return array
*/
public function customMultimodActions()
public function customMultimodActions(): array
{
return array_diff( array( 'report_status_1', 'report_status_2', 'report_status_3', 'report_status_4'), array( 'report_status_' . $this->status ) );
return array_diff( array( 'report_status_1', 'report_status_2', 'report_status_3', ), array( 'report_status_' . $this->status ) );
}
/**
@@ -591,7 +424,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
* @note Return in format of array( array( 'action' => ..., 'icon' => ..., 'language' => ... ) )
* @return array
*/
public static function availableCustomMultimodActions()
public static function availableCustomMultimodActions(): array
{
return array(
array(
@@ -613,11 +446,6 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
'action' => 'report_status_3',
'icon' => 'check-circle',
'label' => 'report_status_3'
),
array(
'action' => 'report_status_4',
'icon' => 'archive',
'label' => 'report_status_4'
)
)
)
@@ -629,10 +457,10 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Get reports
*
* @param string|NULL $filterByType Report type to filter by, or NULL to not filter by type
* @param string|null $filterByType Report type to filter by, or NULL to not filter by type
* @return array
*/
public function reports( $filterByType=NULL)
public function reports( string $filterByType=NULL ): array
{
$where = array( array( 'rid=?', $this->id ) );
@@ -641,7 +469,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
$where[] = array( 'report_type=?', $filterByType );
}
return iterator_to_array( \IPS\Db::i()->select( '*', 'core_rc_reports', $where, 'date_reported' ) );
return iterator_to_array( Db::i()->select( '*', 'core_rc_reports', $where, 'date_reported' ) );
}
/**
@@ -649,16 +477,16 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return void
*/
public function rebuild()
public function rebuild() : void
{
$numReports = \IPS\Db::i()->select( 'COUNT(*)', 'core_rc_reports', array( 'rid=?', $this->id ) )->first();
$numReports = Db::i()->select( 'COUNT(*)', 'core_rc_reports', array( 'rid=?', $this->id ) )->first();
if ( !$numReports )
{
$this->delete();
}
$this->num_reports = $numReports;
$numComments = \IPS\Db::i()->select( 'COUNT(*)', 'core_rc_comments', array( 'rid=?', $this->id ) )->first();
$numComments = Db::i()->select( 'COUNT(*)', 'core_rc_comments', array( 'rid=?', $this->id ) )->first();
$this->num_comments = $numComments;
$this->save();
@@ -667,14 +495,14 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Delete Report
*
* @return void
* @return void
*/
public function delete()
public function delete(): void
{
parent::delete();
\IPS\Db::i()->delete( 'core_rc_reports', array( 'rid=?', $this->id ) );
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $this->class, $this->content_id ) );
Db::i()->delete( 'core_rc_reports', array( 'rid=?', $this->id ) );
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $this->class, $this->content_id ) );
}
/**
@@ -682,7 +510,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return void
*/
public function lockAutoModeration()
public function lockAutoModeration() : void
{
$this->auto_moderation_exempt = 1;
$this->save();
@@ -693,19 +521,19 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return bool
*/
public function isAutoModerationLocked()
public function isAutoModerationLocked() : bool
{
return (boolean) $this->auto_moderation_exempt;
return (bool) $this->auto_moderation_exempt;
}
/**
* Run any automatic moderation
*
* @return bool|void
* @return bool
*/
public function runAutomaticModeration()
public function runAutomaticModeration() : bool
{
if ( ! \IPS\Settings::i()->automoderation_enabled )
if ( ! Settings::i()->automoderation_enabled )
{
return FALSE;
}
@@ -721,14 +549,14 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
{
$reportedContent = $className::load( $this->content_id );
}
catch ( \OutOfRangeException $ex )
catch ( OutOfRangeException $ex )
{
/* No content, no moderation, no cry */
return FALSE;
}
/* Is automatic moderation supported for this content type? */
if ( !( $reportedContent instanceof \IPS\Content\Hideable ) )
if ( !IPS::classUsesTrait( $reportedContent, 'IPS\Content\hideable' ) )
{
return FALSE;
}
@@ -738,7 +566,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
$ruleToUse = NULL;
/* Loop over all group promotion rules and get the last one that matches us */
foreach( \IPS\core\Reports\Rules::roots() as $rule )
foreach(Rules::roots() as $rule )
{
if( $rule->enabled and $rule->matches( $reportedContent->author(), $typeCounts ) )
{
@@ -750,12 +578,12 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
if( $ruleToUse === NULL )
{
/* It is possible a few reports have been removed so the threshold is no longer met, delete any pending rows if this is the case */
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $className, $this->content_id ) );
Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $className, $this->content_id ) );
}
else
{
/* Log the bad boy for actioning later. A small delay allows users to retract their warning */
\IPS\Db::i()->replace( 'core_automatic_moderation_pending', array(
Db::i()->replace( 'core_automatic_moderation_pending', array(
'pending_object_class' => $className,
'pending_object_id' => $this->content_id,
'pending_report_id' => $this->id,
@@ -763,21 +591,22 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
'pending_rule_id' => $ruleToUse
) );
}
return true;
}
/**
* Fetch the report type counts
*
* @param boolean $totalOnly Return either an int of the total counts, or an array with the breakdown
* @return array( 1 => 10, 2 => 3 )|INT
* @return int|array ( 1 => 10, 2 => 3 )
*/
public function getReportTypeCounts( $totalOnly=false )
public function getReportTypeCounts( bool $totalOnly=false ) : array|int
{
$typeCounts = array();
$total = 0;
$seen = array();
/* @note SELECT_FROM_WRITE_SERVER added in 7fd46ad949b0a9b03a5c67c70afee26184c2930c pull #316 (The problem was, that the R/W separation.The new report was added and in the same step we fetched(counted) the existing reports, where the recent one wasn't taken into account.) */
foreach( \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'rid=? and report_type > 0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER ) as $row )
foreach( Db::i()->select( '*', 'core_rc_reports', array( 'rid=? and report_type > 0', $this->id ), NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER ) as $row )
{
if ( isset( $seen[ $row['report_by'] ] ) )
{
@@ -790,12 +619,12 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
}
$return = array();
foreach( array_keys( \IPS\core\Reports\Types::roots() ) as $type )
foreach(array_keys( Types::roots() ) as $type )
{
if ( isset( $typeCounts[ $type ] ) )
{
$return[ $type ] = \count( $typeCounts[ $type ] );
$total += \count( $typeCounts[ $type ] );
$return[ $type ] = count( $typeCounts[ $type ] );
$total += count( $typeCounts[ $type ] );
}
else
{
@@ -811,7 +640,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
*
* @return array
*/
public static function getTableFilters()
public static function getTableFilters(): array
{
return array(
'read', 'unread', 'report_status_1', 'report_status_2', 'report_status_3'
@@ -821,23 +650,23 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
/**
* Build the where clause for finding reports
*
* @param \IPS\Member|null $member Member to base permissions on
* @param Member|null $member Member to base permissions on
* @return array
*/
public static function where( \IPS\Member $member=NULL ): array
public static function where( Member $member=NULL ): array
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
$classWhere = [];
$extensionWhere = [];
$viewPermIds = [];
$perms = $member->modPermissions();
foreach( \IPS\Db::i()->select( 'app, perm_id', 'core_permission_index', \IPS\Db::i()->findInSet( 'perm_view', $member->permissionArray() ) . " OR perm_view='*'" ) as $perm )
foreach( Db::i()->select( 'app, perm_id', 'core_permission_index', Db::i()->findInSet( 'perm_view', $member->permissionArray() ) . " OR perm_view='*'" ) as $perm )
{
$viewPermIds[ $perm['app'] ][] = $perm['perm_id'];
}
foreach ( array_merge( ['IPS\core\Messenger\Conversation', 'IPS\core\Messenger\Message'], array_values( \IPS\Content::routedClasses( FALSE, TRUE ) ) ) as $class )
foreach ( array_merge( ['IPS\core\Messenger\Conversation', 'IPS\core\Messenger\Message'], array_values( Content::routedClasses( FALSE, TRUE ) ) ) as $class )
{
/* Got nodes? */
$item = NULL;
@@ -866,7 +695,30 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
{
if ( isset( $perms[$container::$modPerm] ) and $perms[$container::$modPerm] != '*' and $perms[$container::$modPerm] != '-1')
{
$extensionWhereClause = ' AND ' . \IPS\Db::i()->in( 'node_id', $perms[$container::$modPerm] );
$extensionWhereClause = ' AND ' . Db::i()->in( 'node_id', is_array( $perms[$container::$modPerm] ) ? $perms[$container::$modPerm] : [ $perms[$container::$modPerm] ] );
}
}
}
$extensionWhereClause = '';
/* Skip this if we have global permissions */
if( is_array( $perms ) and !$perms['can_view_reports'] )
{
/* Skip anything where we have reports disabled */
$permissionKey = 'can_view_reports_' . $item::$title;
if( !isset( $perms[$permissionKey] ) or !$perms[$permissionKey] )
{
continue;
}
/* Container-level permissions */
if ( isset( $item::$containerNodeClass ) )
{
$container = $item::$containerNodeClass;
if ( isset( $container::$modPerm ) and isset( $perms[$container::$modPerm] ) and $perms[$container::$modPerm] != '*' and $perms[$container::$modPerm] != '-1' and isset( $perms[$permissionKey] ) and $perms[$permissionKey] )
{
$extensionWhereClause = ' AND ' . Db::i()->in( 'node_id', is_array( $perms[$container::$modPerm] ) ? $perms[$container::$modPerm] : [ $perms[$container::$modPerm] ] );
}
}
}
@@ -884,7 +736,7 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
{
if ( !isset( $permIds[ $class::$application ][ $workingClass::$permissionMap['read'] ] ) )
{
$permIds[ $class::$application ][ $workingClass::$permissionMap['read'] ] = iterator_to_array( \IPS\Db::i()->select( 'perm_id', 'core_permission_index', "(" . \IPS\Db::i()->findInSet( 'perm_' . $workingClass::$permissionMap['read'], \IPS\Member::loggedIn()->permissionArray() ) . " OR perm_" . $workingClass::$permissionMap['read'] . "='*' ) AND app='{$class::$application}'" ) );
$permIds[ $class::$application ][ $workingClass::$permissionMap['read'] ] = iterator_to_array( Db::i()->select( 'perm_id', 'core_permission_index', "(" . Db::i()->findInSet( 'perm_' . $workingClass::$permissionMap['read'], Member::loggedIn()->permissionArray() ) . " OR perm_" . $workingClass::$permissionMap['read'] . "='*' ) AND app='{$class::$application}'" ) );
}
if( isset( $viewPermIds[ $class::$application ] ) AND !empty( $permIds[ $class::$application ][ $workingClass::$permissionMap['read'] ] ) )
@@ -909,21 +761,36 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
}
/**
* Can view this entry
* Can view?
*
* @param \IPS\Member|NULL $member The member or NULL for currently logged in member.
* @param Member|NULL $member The member to check for or NULL for the currently logged in member
* @return bool
*/
public function canView( $member = NULL )
public function canView( ?Member $member=NULL ): bool
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
$return = parent::canView($member);
$return = parent::canView( $member );
if ( $return AND $member->modPermission('can_view_reports') )
{
return TRUE;
}
$class = $this->_data['class'];
try
{
$thing = $class::load( $this->_data['content_id'] );
if( $thing instanceof Comment )
{
$itemClass = $thing::$itemClass;
return $itemClass::modPermission( 'view_reports', $member, $thing->item()->containerWrapper() );
}
return $class::modPermission( 'view_reports', $member, $thing->containerWrapper() );
}
catch( OutOfRangeException $e ){}
return FALSE;
}
}
+82 -74
View File
@@ -11,89 +11,105 @@
namespace IPS\core\Reports;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Data\Store;
use IPS\Db;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Translatable;
use IPS\Helpers\Form\YesNo;
use IPS\Lang;
use IPS\Member;
use IPS\Member\Group;
use IPS\Node\Model;
use IPS\Settings;
use function count;
use function defined;
use function in_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;
}
/**
* Group promotion node model
*/
class _Rules extends \IPS\Node\Model
class Rules extends Model
{
/**
* @brief Database Table
*/
public static $databaseTable = 'core_automatic_moderation_rules';
public static ?string $databaseTable = 'core_automatic_moderation_rules';
/**
* @brief Database Prefix
*/
public static $databasePrefix = 'rule_';
public static string $databasePrefix = 'rule_';
/**
* @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();
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'automaticmoderation';
public static string $nodeTitle = 'automaticmoderation';
/**
* @brief [Node] Sortable
*/
public static $nodeSortable = TRUE;
public static bool $nodeSortable = TRUE;
/**
* @brief [Node] Positon Column
*/
public static $databaseColumnOrder = 'position';
public static ?string $databaseColumnOrder = 'position';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
*/
public static $titleLangPrefix = 'automaticmoderation_';
public static ?string $titleLangPrefix = 'automaticmoderation_';
/**
* @brief [Node] Enabled/Disabled Column
*/
public static $databaseColumnEnabledDisabled = 'enabled';
public static ?string $databaseColumnEnabledDisabled = 'enabled';
/**
* Form
*
* @param \IPS\Helpers\Form $form The form
* @param Form $form The form
* @return void
*/
public function form( &$form )
public function form( Form &$form ) : void
{
$form->addHeader( 'automaticmoderation_generic_details' );
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmoderation_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmoderation_' . $this->id : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'automaticmoderation_enabled', $this->id ? $this->enabled : 1, TRUE ) );
$form->add( new \IPS\Helpers\Form\Number( 'automaticmoderation_points', $this->id ? $this->points_needed : 10, TRUE, array( 'min' => 1, 'max' => 9999 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('automaticmoderation_points_suffix') ) );
$form->add( new Translatable( 'automaticmoderation_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmoderation_' . $this->id : NULL ) ) ) );
$form->add( new YesNo( 'automaticmoderation_enabled', $this->id ? $this->enabled : 1, TRUE ) );
$form->add( new Number( 'automaticmoderation_points', $this->id ? $this->points_needed : 10, TRUE, array( 'min' => 1, 'max' => 9999 ), NULL, NULL, Member::loggedIn()->language()->addToStack('automaticmoderation_points_suffix') ) );
$options = array();
if( count( \IPS\core\Reports\Types::roots() ) > 0 )
foreach(Types::roots() as $type )
{
foreach( \IPS\core\Reports\Types::roots() as $type )
{
$options[ $type->id ] = $type->_title;
}
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'automaticmoderation_type', $this->types ? explode( ',', $this->types ) : array(), TRUE, array( 'options' => $options ) ) );
$options[ $type->id ] = $type->_title;
}
$form->add( new CheckboxSet( 'automaticmoderation_type', $this->types ? explode( ',', $this->types ) : array(), TRUE, array( 'options' => $options ) ) );
/* Loop over our member filters */
$form->addHeader( 'automaticmoderation_generic_filters' );
@@ -104,9 +120,9 @@ class _Rules extends \IPS\Node\Model
/* We take an extra step with groups to disable invalid options */
//$options['core_Group']['disabled_groups'] = $this->getDisabledGroups();
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'getSettingField' ) AND $extension->availableIn( 'automatic_moderation' ) )
if( $extension->availableIn( 'automatic_moderation' ) )
{
/* See if we need a new form header - one per app */
$_key = explode( '_', $key );
@@ -133,11 +149,11 @@ class _Rules extends \IPS\Node\Model
*
* @return array
*/
protected function getDisabledGroups()
protected function getDisabledGroups() : array
{
$return = array( \IPS\Settings::i()->guest_group );
$return = array( Settings::i()->guest_group );
foreach( \IPS\Member\Group::groups() as $group )
foreach( Group::groups() as $group )
{
if( $group->g_promote_exclude )
{
@@ -154,7 +170,7 @@ class _Rules extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if ( !$this->id )
{
@@ -162,15 +178,15 @@ class _Rules extends \IPS\Node\Model
}
/* Save the title */
\IPS\Lang::saveCustom( 'core', 'automaticmoderation_' . $this->id, $values['automaticmoderation_title'] );
Lang::saveCustom( 'core', 'automaticmoderation_' . $this->id, $values['automaticmoderation_title'] );
/* Json-encode the rules */
$_options = array();
/* Loop over bulk mail extensions to format the options */
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'save' ) AND $extension->availableIn( 'automatic_moderation' ) )
if( $extension->availableIn( 'automatic_moderation' ) )
{
/* Grab our fields and add to the form */
$_value = $extension->save( $values );
@@ -185,16 +201,12 @@ class _Rules extends \IPS\Node\Model
$values['rule_filters'] = json_encode( $_options );
$values['rule_points_needed'] = $values['automaticmoderation_points'];
$values['rule_enabled'] = $values['automaticmoderation_enabled'];
if( isset( $values['automaticmoderation_type'] ) )
{
$values['rule_types'] = $values['automaticmoderation_type'];
}
$values['rule_types'] = $values['automaticmoderation_type'];
/* Now we have to remove any fields that aren't valid... */
foreach( $values as $k => $v )
{
if( !\in_array( $k, array( 'rule_filters', 'rule_points_needed', 'rule_enabled', 'rule_types', 'rule_position' ) ) )
if( !in_array( $k, array( 'rule_filters', 'rule_points_needed', 'rule_enabled', 'rule_types', 'rule_position' ) ) )
{
unset( $values[ $k ] );
}
@@ -208,7 +220,7 @@ class _Rules extends \IPS\Node\Model
*
* @return array
*/
public function get__filters()
public function get__filters() : array
{
return json_decode( $this->filters, TRUE );
}
@@ -217,14 +229,14 @@ class _Rules extends \IPS\Node\Model
* Fetch All Root Nodes
*
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
* @param Member|NULL $member The member to check permissions for or NULL for the currently logged in member
* @param mixed $where Additional WHERE clause
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
* @return array
*/
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
public static function roots( ?string $permissionCheck='view', Member $member=NULL, mixed $where=array(), array $limit=NULL ): array
{
if ( !\count( $where ) )
if ( !count( $where ) )
{
$return = array();
foreach( static::getStore() AS $node )
@@ -246,54 +258,54 @@ class _Rules extends \IPS\Node\Model
* @return array
* @note Note that all records are returned, even disabled report rules. Enable status needs to be checked in userland code when appropriate.
*/
public static function getStore()
public static function getStore(): array
{
if ( !isset( \IPS\Data\Store::i()->automatic_moderation_rules ) )
if ( !isset( Store::i()->automatic_moderation_rules ) )
{
\IPS\Data\Store::i()->automatic_moderation_rules = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "rule_position ASC" )->setKeyField( 'rule_id' ) );
Store::i()->automatic_moderation_rules = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, "rule_position ASC" )->setKeyField( 'rule_id' ) );
}
return \IPS\Data\Store::i()->automatic_moderation_rules;
return Store::i()->automatic_moderation_rules;
}
/**
* @brief [ActiveRecord] Attempt to load from cache
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
*/
protected static $loadFromCache = TRUE;
protected static bool $loadFromCache = TRUE;
/**
* @brief [ActiveRecord] Caches
* @note Defined cache keys will be cleared automatically as needed
*/
protected $caches = array( 'automatic_moderation_rules' );
protected array $caches = array( 'automatic_moderation_rules' );
/**
* @brief Cache extensions so we only need to load them once
*/
protected static $extensions = NULL;
protected static ?array $extensions = NULL;
/**
* Check if a member matches the rule
*
* @param \IPS\Member $member Member to check
* @param Member $member Member to check
* @param array $typeCounts Array of type counts indexed by report_type (constants in \IPS\core\Reports\Report)
* @return bool
*/
public function matches( \IPS\Member $member, $typeCounts=array() )
public function matches( Member $member, array $typeCounts=array() ) : bool
{
if ( ! \IPS\Settings::i()->automoderation_enabled )
if ( ! Settings::i()->automoderation_enabled )
{
return FALSE;
}
if( static::$extensions === NULL )
{
static::$extensions = \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
static::$extensions = Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
}
/* Nothing flagged as bad? Back you go */
if ( ! \count( $typeCounts ) )
if ( ! count( $typeCounts ) )
{
return FALSE;
}
@@ -344,45 +356,41 @@ class _Rules extends \IPS\Node\Model
*
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
*/
protected function get__badge()
protected function get__badge(): ?array
{
return array(
0 => 'ipsBadge ipsBadge_positive',
1 => \IPS\Member::loggedIn()->language()->addToStack( 'automoderation_points_needed_badge', FALSE, array( 'pluralize' => array( $this->points_needed ) ) )
0 => 'ipsBadge ipsBadge--positive',
1 => Member::loggedIn()->language()->addToStack( 'automoderation_points_needed_badge', FALSE, array( 'pluralize' => array( $this->points_needed ) ) )
);
}
/**
* Return a warning if this promotion uses not existing groups
*
* @return string
* @return string|null
*/
public function get__description()
public function get__description(): ?string
{
if( static::$extensions === NULL )
{
static::$extensions = \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
static::$extensions = Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
}
/* Loop over the filters */
$descriptions = array();
if( $this->_filters )
foreach( $this->_filters as $key => $filter )
{
foreach( $this->_filters as $key => $filter )
if( isset( static::$extensions[ $key ] ) )
{
if( isset( static::$extensions[ $key ] ) )
/* Ask the extension if this member matches the defined rule...if not, just return FALSE now */
if( method_exists( static::$extensions[ $key ], 'getDescription' ) and $description = static::$extensions[ $key ]->getDescription( $filter ) )
{
/* Ask the extension if this member matches the defined rule...if not, just return FALSE now */
if( method_exists( static::$extensions[ $key ], 'getDescription' ) and $description = static::$extensions[ $key ]->getDescription( $filter ) )
{
$descriptions[] = $description; /* Is this descriptive enough? */
}
$descriptions[] = $description; /* Is this descriptive enough? */
}
}
}
return \IPS\Member::loggedIn()->language()->addToStack( 'automaticmoderation_row_desc', TRUE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $descriptions ) ) ) );
return Member::loggedIn()->language()->addToStack( 'automaticmoderation_row_desc', TRUE, array( 'sprintf' => array( Member::loggedIn()->language()->formatList( $descriptions ) ) ) );
}
/**
@@ -391,9 +399,9 @@ class _Rules extends \IPS\Node\Model
* @param null|int $languageId Language ID (or NULL to use default language)
* @return string
*/
public static function getDefaultHideReason( $languageId = NULL )
public static function getDefaultHideReason( ?int $languageId = NULL ) : string
{
$languageId = $languageId ? : \IPS\Lang::defaultLanguage() ;
return \IPS\Lang::load( $languageId )->get( 'automaticmoderation_hide_reason' );
$languageId = $languageId ? : Lang::defaultLanguage() ;
return Lang::load( $languageId )->get( 'automaticmoderation_hide_reason' );
}
}
+48 -65
View File
@@ -12,97 +12,84 @@ namespace IPS\core\Reports;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Data\Store;
use IPS\Db;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Translatable;
use IPS\Lang;
use IPS\Member;
use IPS\Node\Model;
use function count;
use function defined;
use function get_class;
use function intval;
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
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;
}
/**
* Report types node model
*/
class _Types extends \IPS\Node\Model
class Types extends Model
{
/**
* @brief Database Table
*/
public static $databaseTable = 'core_automatic_moderation_types';
public static ?string $databaseTable = 'core_automatic_moderation_types';
/**
* @brief Database Prefix
*/
public static $databasePrefix = 'type_';
public static string $databasePrefix = 'type_';
/**
* @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();
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'automaticmod_types';
public static string $nodeTitle = 'automaticmod_types';
/**
* @brief [Node] Sortable
*/
public static $nodeSortable = TRUE;
public static bool $nodeSortable = TRUE;
/**
* @brief [Node] Positon Column
*/
public static $databaseColumnOrder = 'position';
public static ?string $databaseColumnOrder = 'position';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
*/
public static $titleLangPrefix = 'automaticmod_types_';
/**
* Get the completed notification text (hits the DB to get the real value, not the hash key)
* @param Member|null $member
* @return string
*/
public function getCompletedNotificationText( \IPS\Member|null $member=null ): string
{
$member = $member ?: \IPS\Member::loggedIn();
return $member->language()->get( 'automaticmod_types_notify_complete_' . $this->id, 'core' );
}
/**
* Get the rejected notification text (hits the DB to get the real value, not the hash key)
* @param Member|null $member
* @return string
*/
public function getRejectedNotificationText( \IPS\Member|null $member=null ): string
{
$member = $member ?: \IPS\Member::loggedIn();
return $member->language()->get( 'automaticmod_types_notify_reject_' . $this->id, 'core' );
}
public static ?string $titleLangPrefix = 'automaticmod_types_';
/**
* Form
*
* @param \IPS\Helpers\Form $form The form
* @param Form $form The form
* @return void
*/
public function form( &$form )
public function form( Form &$form ) : void
{
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmod_types_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmod_types_' . $this->id : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmod_types_notify_complete', NULL, FALSE, array( 'textArea' => true, 'app' => 'core', 'key' => ( $this->id ? 'automaticmod_types_notify_complete_' . $this->id : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmod_types_notify_reject', NULL, FALSE, array( 'textArea' => true, 'app' => 'core', 'key' => ( $this->id ? 'automaticmod_types_notify_reject_' . $this->id : NULL ) ) ) );
$form->add( new Translatable( 'automaticmod_types_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmod_types_' . $this->id : NULL ) ) ) );
}
/**
@@ -111,7 +98,7 @@ class _Types extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if ( !$this->id )
{
@@ -119,13 +106,9 @@ class _Types extends \IPS\Node\Model
}
/* Save the title */
\IPS\Lang::saveCustom( 'core', 'automaticmod_types_' . $this->id, $values['automaticmod_types_title'] );
/* Save the notification text */
\IPS\Lang::saveCustom( 'core', 'automaticmod_types_notify_complete_' . $this->id, $values['automaticmod_types_notify_complete'] );
\IPS\Lang::saveCustom( 'core', 'automaticmod_types_notify_reject_' . $this->id, $values['automaticmod_types_notify_reject'] );
Lang::saveCustom( 'core', 'automaticmod_types_' . $this->id, $values['automaticmod_types_title'] );
unset( $values['automaticmod_types_title'], $values['automaticmod_types_notify_complete'], $values['automaticmod_types_notify_reject'] );
unset( $values['automaticmod_types_title'] );
return parent::formatFormValues( $values );
}
@@ -134,14 +117,14 @@ class _Types extends \IPS\Node\Model
* Fetch All Root Nodes
*
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
* @param Member|NULL $member The member to check permissions for or NULL for the currently logged in member
* @param mixed $where Additional WHERE clause
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
* @return array
*/
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
public static function roots( ?string $permissionCheck='view', Member $member=NULL, mixed $where=array(), array $limit=NULL ): array
{
if ( !\count( $where ) )
if ( !count( $where ) )
{
$return = array();
foreach( static::getStore() AS $node )
@@ -163,48 +146,48 @@ class _Types extends \IPS\Node\Model
* @return array
* @note Note that all records are returned, even disabled report type rules. Enable status needs to be checked in userland code when appropriate.
*/
public static function getStore()
public static function getStore(): array
{
if ( !isset( \IPS\Data\Store::i()->automatic_moderation_types ) )
if ( !isset( Store::i()->automatic_moderation_types ) )
{
\IPS\Data\Store::i()->automatic_moderation_types = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "type_position ASC" )->setKeyField( 'type_id' ) );
Store::i()->automatic_moderation_types = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, "type_position ASC" )->setKeyField( 'type_id' ) );
}
return \IPS\Data\Store::i()->automatic_moderation_types;
return Store::i()->automatic_moderation_types;
}
/**
* @brief [ActiveRecord] Attempt to load from cache
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
*/
protected static $loadFromCache = TRUE;
protected static bool $loadFromCache = TRUE;
/**
* Get item count
* I'm sure you could have figured that out from the method name
* but I'll spoon feed you, it's ok.
*
* @return INT
* @return int
*/
public function getItemCount()
public function getItemCount() : int
{
return \intval( \IPS\Db::i()->select( 'COUNT(*)', 'core_rc_reports', array( 'report_type=?', $this->id ) )->first() );
return intval( Db::i()->select( 'COUNT(*)', 'core_rc_reports', array( 'report_type=?', $this->id ) )->first() );
}
/**
* Form to delete or move content
*
* @param bool $showMoveToChildren If TRUE, will show "move to children" even if there are no children
* @return \IPS\Helpers\Form
* @return Form
*/
public function deleteOrMoveForm( $showMoveToChildren=FALSE )
public function deleteOrMoveForm( bool $showMoveToChildren=FALSE ): Form
{
$form = new \IPS\Helpers\Form( 'delete_node_form', 'delete' );
$form = new Form( 'delete_node_form', 'delete' );
$form->addMessage( 'node_delete_blurb' );
if ( $this->getItemCount() )
{
$form->add( new \IPS\Helpers\Form\Node( 'node_move_content', 0, TRUE, array( 'class' => \get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_content', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
$form->add( new Node( 'node_move_content', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_content', 'subnodes' => FALSE, 'permissionCheck' => function()
{
return true;
} ) ) );
@@ -219,12 +202,12 @@ class _Types extends \IPS\Node\Model
* @param array $values Values from form
* @return void
*/
public function deleteOrMoveFormSubmit( $values )
public function deleteOrMoveFormSubmit( array $values ) : void
{
if ( isset( $values['node_move_content'] ) and $values['node_move_content'] )
{
/* We're moving first */
\IPS\Db::i()->update( 'core_rc_reports', array( 'report_type' => $values['node_move_content']->_id ), array( 'report_type=?', $this->id ) );
Db::i()->update( 'core_rc_reports', array( 'report_type' => $values['node_move_content']->_id ), array( 'report_type=?', $this->id ) );
}
$this->delete();
@@ -234,5 +217,5 @@ class _Types extends \IPS\Node\Model
* @brief [ActiveRecord] Caches
* @note Defined cache keys will be cleared automatically as needed
*/
protected $caches = array( 'automatic_moderation_types' );
protected array $caches = array( 'automatic_moderation_types' );
}