Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\Warnings;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
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' );
|
||||
exit;
|
||||
@@ -264,10 +264,8 @@ class _Warning extends \IPS\Content\Item
|
||||
/* Get the reasons */
|
||||
$reasons = array();
|
||||
$roots = \IPS\core\Warnings\Reason::roots();
|
||||
$default = NULL;
|
||||
foreach ( $roots as $reason )
|
||||
{
|
||||
$default = $default ?: $reason;
|
||||
$reasons[ $reason->_id ] = $reason->_title;
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->modPermission('warnings_enable_other') )
|
||||
@@ -285,7 +283,7 @@ class _Warning extends \IPS\Content\Item
|
||||
$elements[] = new \IPS\Helpers\Form\Select( 'warn_reason', NULL, TRUE, array( 'options' => $reasons ) );
|
||||
$elements[] = new \IPS\Helpers\Form\Number( 'warn_points', 0, FALSE, array( 'valueToggles' => array( 'warn_remove' ), 'disabled' => ( !$first->points_override ) ) );
|
||||
$elements[] = new \IPS\Helpers\Form\Date( 'warn_remove', -1, FALSE, array( 'time' => TRUE, 'unlimited' => -1, 'unlimitedLang' => 'never' ), NULL, NULL, NULL, 'warn_remove' );
|
||||
$elements[] = new \IPS\Helpers\Form\Editor( 'warn_member_note', $default ? $default->notes : NULL, FALSE, array( 'app' => 'core', 'key' => 'Modcp', 'autoSaveKey' => "warn-member-" . \IPS\Request::i()->id, 'attachIds' => ( $item === NULL ? NULL : array( $item->id, NULL, 'member' ) ), 'minimize' => ( $default AND $default->notes ) ? NULL : 'warn_member_note_placeholder' ) );
|
||||
$elements[] = new \IPS\Helpers\Form\Editor( 'warn_member_note', NULL, FALSE, array( 'app' => 'core', 'key' => 'Modcp', 'autoSaveKey' => "warn-member-" . \IPS\Request::i()->id, 'attachIds' => ( $item === NULL ? NULL : array( $item->id, NULL, 'member' ) ), 'minimize' => 'warn_member_note_placeholder' ) );
|
||||
$elements[] = new \IPS\Helpers\Form\Editor( 'warn_mod_note', NULL, FALSE, array( 'app' => 'core', 'key' => 'Modcp', 'autoSaveKey' => "warn-mod-" . \IPS\Request::i()->id, 'attachIds' => ( $item === NULL ? NULL : array( $item->id, NULL, 'mod' ) ), 'minimize' => 'warn_mod_note_placeholder' ) );
|
||||
$elements[] = new \IPS\Helpers\Form\CheckboxSet( 'warn_punishment', array(), FALSE, array(
|
||||
'options' => array( 'mq' => 'warn_mq', 'rpa' => 'warn_rpa', 'suspend' => 'warn_suspend' ),
|
||||
@@ -360,13 +358,68 @@ class _Warning extends \IPS\Content\Item
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2C150/3', 403, '' );
|
||||
}
|
||||
|
||||
$values = $this->processWarning( $values, \IPS\Member::loggedIn() );
|
||||
|
||||
parent::processBeforeCreate( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process created object AFTER the object has been created
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The first comment
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
protected function processAfterCreate( $comment, $values )
|
||||
{
|
||||
\IPS\File::claimAttachments( "warn-member-{$this->member}", $this->id, NULL, 'member' );
|
||||
\IPS\File::claimAttachments( "warn-mod-{$this->member}", $this->id, NULL, 'mod' );
|
||||
|
||||
$member = \IPS\Member::load( $this->member );
|
||||
if ( $this->points )
|
||||
{
|
||||
$member->warn_level += $this->points;
|
||||
}
|
||||
$consequences = array();
|
||||
foreach ( array( 'mq' => 'mod_posts', 'rpa' => 'restrict_post', 'suspend' => 'temp_ban' ) as $k => $v )
|
||||
{
|
||||
if ( $this->$k )
|
||||
{
|
||||
$consequences[ $v ] = $this->$k;
|
||||
if ( $this->$k != -1 )
|
||||
{
|
||||
$member->$v = \IPS\DateTime::create()->add( new \DateInterval( $this->$k ) )->getTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
$member->$v = $this->$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
$member->members_bitoptions['unacknowledged_warnings'] = (bool) \IPS\Settings::i()->warnings_acknowledge;
|
||||
$member->save();
|
||||
$member->logHistory( 'core', 'warning', array( 'wid' => $this->id, 'points' => $this->points, 'reason' => $this->reason, 'consequences' => $consequences ) );
|
||||
|
||||
parent::processAfterCreate( $comment, $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the warning values
|
||||
*
|
||||
* @param array $values Values from form submission
|
||||
* @param \IPS\Member $member Moderator to process warning under
|
||||
* @param bool $reset Reset points based on reason
|
||||
* @return array
|
||||
*/
|
||||
public function processWarning( $values, $member, $reset=FALSE )
|
||||
{
|
||||
/* Work out points and expiry date */
|
||||
$this->expire_date = NULL;
|
||||
$this->points = $values['warn_points'];
|
||||
if ( is_numeric( $values['warn_reason'] ) )
|
||||
if ( \is_numeric( $values['warn_reason'] ) )
|
||||
{
|
||||
$reason = \IPS\core\Warnings\Reason::load( $values['warn_reason'] );
|
||||
if ( !$reason->points_override )
|
||||
if ( !$reason->points_override OR ( !$this->points AND $reset ) )
|
||||
{
|
||||
$this->points = $reason->points;
|
||||
}
|
||||
@@ -437,6 +490,11 @@ class _Warning extends \IPS\Content\Item
|
||||
{
|
||||
foreach ( array( 'mq', 'rpa', 'suspend' ) as $k )
|
||||
{
|
||||
if( !\in_array( $k, $values['warn_punishment'] ) )
|
||||
{
|
||||
$values['warn_punishment'][] = $k;
|
||||
}
|
||||
|
||||
if ( $action[ 'wa_' . $k ] == -1 )
|
||||
{
|
||||
$values[ 'warn_' . $k ] = -1;
|
||||
@@ -447,14 +505,14 @@ class _Warning extends \IPS\Content\Item
|
||||
}
|
||||
else
|
||||
{
|
||||
$values[ 'warn_' . $k ] = NULL;
|
||||
$values[ 'warn_' . $k ] = 0;//NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->modPermission('warning_custom_noaction') )
|
||||
if ( !$member->modPermission('warning_custom_noaction') )
|
||||
{
|
||||
foreach ( array( 'mq', 'rpa', 'suspend' ) as $k )
|
||||
{
|
||||
@@ -462,7 +520,7 @@ class _Warning extends \IPS\Content\Item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* We do this after the action is checked because the moderator may not be able to override the action, in which case the actual values won't have been submitted */
|
||||
foreach( $values['warn_punishment'] AS $p )
|
||||
{
|
||||
@@ -494,11 +552,11 @@ class _Warning extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* Work out the timeframes for the penalties */
|
||||
if ( count( $values['warn_punishment'] ) )
|
||||
if ( \count( $values['warn_punishment'] ) )
|
||||
{
|
||||
foreach ( array( 'mq', 'rpa', 'suspend' ) as $f )
|
||||
{
|
||||
if ( !in_array( $f, $values['warn_punishment'] ) )
|
||||
if ( !\in_array( $f, $values['warn_punishment'] ) OR $values['warn_' . $f ] === 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -536,47 +594,7 @@ class _Warning extends \IPS\Content\Item
|
||||
}
|
||||
}
|
||||
|
||||
parent::processBeforeCreate( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process created object AFTER the object has been created
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The first comment
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
protected function processAfterCreate( $comment, $values )
|
||||
{
|
||||
\IPS\File::claimAttachments( "warn-member-{$this->member}", $this->id, NULL, 'member' );
|
||||
\IPS\File::claimAttachments( "warn-mod-{$this->member}", $this->id, NULL, 'mod' );
|
||||
|
||||
$member = \IPS\Member::load( $this->member );
|
||||
if ( $this->points )
|
||||
{
|
||||
$member->warn_level += $this->points;
|
||||
}
|
||||
$consequences = array();
|
||||
foreach ( array( 'mq' => 'mod_posts', 'rpa' => 'restrict_post', 'suspend' => 'temp_ban' ) as $k => $v )
|
||||
{
|
||||
if ( $this->$k )
|
||||
{
|
||||
$consequences[ $v ] = $this->$k;
|
||||
if ( $this->$k != -1 )
|
||||
{
|
||||
$member->$v = \IPS\DateTime::create()->add( new \DateInterval( $this->$k ) )->getTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
$member->$v = $this->$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
$member->members_bitoptions['unacknowledged_warnings'] = (bool) \IPS\Settings::i()->warnings_acknowledge;
|
||||
$member->save();
|
||||
$member->logHistory( 'core', 'warning', array( 'wid' => $this->id, 'points' => $this->points, 'reason' => $this->reason, 'consequences' => $consequences ) );
|
||||
|
||||
parent::processAfterCreate( $comment, $values );
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -668,7 +686,7 @@ class _Warning extends \IPS\Content\Item
|
||||
/* Queue if there's lots, or just send them */
|
||||
if ( $this->notificationsCount( $this->getModerators() ) > static::NOTIFICATIONS_PER_BATCH )
|
||||
{
|
||||
\IPS\Task::queue( 'core', 'WarnNotifications', array( 'class' => get_class( $this ), 'item' => $this->id, 'sentTo' => array() ), 1 );
|
||||
\IPS\Task::queue( 'core', 'WarnNotifications', array( 'class' => \get_class( $this ), 'item' => $this->id, 'sentTo' => array() ), 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -824,7 +842,7 @@ class _Warning extends \IPS\Content\Item
|
||||
public function canAcknowledge( $member=NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return intval($this->member) === intval($member->member_id);
|
||||
return \intval($this->member) === \intval($member->member_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -841,6 +859,9 @@ class _Warning extends \IPS\Content\Item
|
||||
|
||||
/* !\IPS\Helpers\Table */
|
||||
|
||||
/**
|
||||
* @brief Enable table hover URL
|
||||
*/
|
||||
public $tableHoverUrl = TRUE;
|
||||
|
||||
/**
|
||||
@@ -862,4 +883,54 @@ class _Warning extends \IPS\Content\Item
|
||||
{
|
||||
return $this->note_mods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse \IPS\Member member Member who was warned
|
||||
* @apiresponse \IPS\Member moderator Moderator who performed the warning
|
||||
* @apiresponse int points The points issued for the warning
|
||||
* @apiresponse \IPS\core\Warnings\Reason reason Warn reason if one was specified
|
||||
* @apiresponse datetime|int expiration Date the warning expires, or -1 if the warning does not expire
|
||||
* @apiresponse datetime date Date the warning was issued
|
||||
* @apiresponse bool acknowledged Whether or not the warning has been acknowledged
|
||||
* @apiresponse string memberNotes Warn notes left for the member
|
||||
* @clientapiresponse string moderatorNotes Warn notes visible to moderators
|
||||
* @apiresponse bool modQueuePermanent Member is permanently moderator queued
|
||||
* @apiresponse string|NULL modQueue DateTimeInterval (from date) when the member will be removed from the moderator queue or null
|
||||
* @apiresponse bool restrictPostsPermanent Member is permanently on post restriction
|
||||
* @apiresponse string|NULL restrictPosts DateTimeInterval (from date) when the member will be removed from post restriction or null
|
||||
* @apiresponse bool suspendPermanent Member is permanently on suspension
|
||||
* @apiresponse string|NULL suspend DateTimeInterval (from date) when the member will be unsuspended or null
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
$response = array(
|
||||
'id' => $this->id,
|
||||
'member' => \IPS\Member::load( $this->member )->apiOutput( $authorizedMember ),
|
||||
'moderator' => \IPS\Member::load( $this->moderator )->apiOutput( $authorizedMember ),
|
||||
'points' => $this->points,
|
||||
'reason' => $this->reason ? \IPS\core\Warnings\Reason::load( $this->reason )->apiOutput() : NULL,
|
||||
'expiration' => ( $this->expire_date == -1 ) ? $this->expire_date : \IPS\DateTime::ts( $this->expire_date )->rfc3339(),
|
||||
'date' => \IPS\DateTime::ts( $this->date )->rfc3339(),
|
||||
'acknowledged' => (bool) $this->acknowledged,
|
||||
'memberNotes' => $this->note_member,
|
||||
'modQueue' => ( $this->mq != -1 ) ? $this->mq : null,
|
||||
'restrictPosts' => ( $this->rpa != -1 ) ? $this->rpa : null,
|
||||
'suspend' => ( $this->suspend != -1 ) ? $this->suspend : null,
|
||||
'modQueuePermanent' => ( $this->mq == -1 ) ? true : false,
|
||||
'restrictPostsPermanent' => ( $this->restrictPosts == -1 ) ? true : false,
|
||||
'suspendPermanent' => ( $this->suspend == -1 ) ? true : false,
|
||||
);
|
||||
|
||||
if( $authorizedMember === NULL )
|
||||
{
|
||||
$response['moderatorNotes'] = $this->note_mods;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user