Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+162 -49
View File
@@ -2,9 +2,9 @@
/**
* @brief Warning Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 23 Jul 2013
* @version SVN_VERSION_NUMBER
*/
@@ -66,7 +66,7 @@ class _Warning extends \IPS\Content\Item
*/
public static function loadFromUrl( \IPS\Http\Url $url )
{
return static::load( $url->queryString['w'] );
return static::load( $url->hiddenQueryString['w'] );
}
/**
@@ -174,46 +174,53 @@ class _Warning extends \IPS\Content\Item
}
else
{
$extensions = \IPS\Application::load( $this->content_app )->extensions( 'core', 'ContentRouter' );
foreach ( $extensions as $ext )
try
{
foreach ( $ext->classes as $class )
$extensions = \IPS\Application::load( $this->content_app )->extensions( 'core', 'ContentRouter' );
foreach ( $extensions as $ext )
{
if ( $class::$module == $this->content_module )
foreach ( $ext->classes as $class )
{
try
if ( $class::$module == $this->content_module )
{
return $class::load( $this->content_id1 );
try
{
return $class::load( $this->content_id1 );
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
catch ( \OutOfRangeException $e )
elseif ( $commentClass = $class::$commentClass and $class::$module . '-comment' == $this->content_module )
{
return NULL;
try
{
return $commentClass::load( $this->content_id2 );
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
}
elseif ( $commentClass = $class::$commentClass and $class::$module . '-comment' == $this->content_module )
{
try
if ( isset( $class::$reviewClass ) AND $reviewClass = $class::$reviewClass and $class::$module . '-review' == $this->content_module )
{
return $commentClass::load( $this->content_id2 );
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
if ( isset( $class::$reviewClass ) AND $reviewClass = $class::$reviewClass and $class::$module . '-review' == $this->content_module )
{
try
{
return $reviewClass::load( $this->content_id2 );
}
catch ( \OutOfRangeException $e )
{
return NULL;
try
{
return $reviewClass::load( $this->content_id2 );
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
}
}
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
}
return NULL;
@@ -252,20 +259,28 @@ 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') )
{
$reasons['other'] = 'core_warn_reason_other';
}
foreach( $roots AS $root )
{
$first = $root;
break;
}
/* Build the form */
$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' => ( !$roots[1]->points_override ) ) );
$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', 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_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_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' ),
@@ -353,16 +368,23 @@ class _Warning extends \IPS\Content\Item
}
else
{
$expire = \IPS\DateTime::create();
if ( $reason->remove_unit == 'h' )
if ( $reason->remove and $reason->remove != -1 )
{
$expire->add( new \DateInterval( "PT{$reason->remove}H" ) );
$expire = \IPS\DateTime::create();
if ( $reason->remove_unit == 'h' )
{
$expire->add( new \DateInterval( "PT{$reason->remove}H" ) );
}
else
{
$expire->add( new \DateInterval( "P{$reason->remove}D" ) );
}
$this->expire_date = $expire->getTimestamp();
}
else
{
$expire->add( new \DateInterval( "P{$reason->remove}D" ) );
$this->expire_date = -1;
}
$this->expire_date = $expire->getTimestamp();
}
}
else
@@ -529,11 +551,11 @@ class _Warning extends \IPS\Content\Item
}
/**
* Send notifications
* Get moderators to notify about warnings
*
* @return void
* @return array
*/
public function sendNotifications()
public function getModerators()
{
$moderators = array( 'm' => array(), 'g' => array() );
foreach ( \IPS\Db::i()->select( '*', 'core_moderators' ) as $mod )
@@ -560,17 +582,108 @@ class _Warning extends \IPS\Content\Item
$moderators[ $mod['type'] ][] = $mod['id'];
}
}
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'warning_mods', $this, array( $this ) );
foreach ( \IPS\Db::i()->select( '*', 'core_members', '(' . ( count( $moderators['m'] ) ? \IPS\Db::i()->in( 'member_id', $moderators['m'] ) . ' OR ' : '' ) . \IPS\Db::i()->in( 'member_group_id', $moderators['g'] ) . ' OR ' . \IPS\Db::i()->findInSet( 'mgroup_others', $moderators['g'] ) . ' ) AND member_id!=' . \IPS\Member::loggedIn()->member_id ) as $member )
return $moderators;
}
/**
* Build and return the WHERE statements for warning notifications
*
* @param array $moderators Moderator data
* @return array
*/
public function buildNotificationsWhere( $moderators )
{
$where = array();
if ( !empty( $moderators['m'] ) )
{
$where[] = \IPS\Db::i()->in( 'member_id', $moderators['m'] );
}
$where[] = \IPS\Db::i()->in( 'member_group_id', $moderators['g'] );
$where[] = \IPS\Db::i()->findInSet( 'mgroup_others', $moderators['g'] );
/* Don't annoy the acting moderator with a notification for the warning they /just/ issued */
return array(
sprintf(
'( %s ) AND %s',
implode( ' OR ', $where ),
'member_id<>?'
),
$this->mapped( 'author' )
);
}
/**
* Get notification count
*
* @param array $moderators Moderator data
* @return int
*/
public function notificationsCount( $moderators )
{
return \IPS\Db::i()->select(
'COUNT(*)',
'core_members',
$this->buildNotificationsWhere( $moderators )
)->first();
}
/**
* Send notifications
*
* @return void
*/
public function sendNotifications()
{
/* 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 );
}
else
{
$this->sendNotificationsBatch();
}
\IPS\Email::buildFromTemplate( 'core', 'warning', array( $this ), \IPS\Email::TYPE_TRANSACTIONAL )->send( \IPS\Member::load( $this->member ) );
}
/**
* Send notifications batch
*
* @param int $offset Current offset
* @param array $sentTo Members who have already received a notification and how - e.g. array( 1 => array( 'inline', 'email' )
* @param string|NULL $extra Additional data
* @return int|null New offset or NULL if complete
*/
public function sendNotificationsBatch( $offset=0, &$sentTo=array(), $extra=NULL )
{
$moderators = $this->getModerators();
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'warning_mods', $this, array( $this ) );
$members = \IPS\Db::i()->select(
'*',
'core_members',
$this->buildNotificationsWhere( $moderators ),
'member_id ASC',
array( $offset, static::NOTIFICATIONS_PER_BATCH )
);
foreach ( $members as $member )
{
\IPS\Log::debug( "Sent notification to {$member['name']}", 'warn_fix' );
$notification->recipients->attach( \IPS\Member::constructFromData( $member ) );
}
$notification->send();
$sentTo = $notification->send( $sentTo );
$email = \IPS\Email::buildFromTemplate( 'core', 'warning', array( $this ) )->send( \IPS\Member::load( $this->member ) );
/* Update the queue */
$newOffset = $offset + static::NOTIFICATIONS_PER_BATCH;
if ( $newOffset > $this->notificationsCount( $moderators ) )
{
return NULL;
}
return $newOffset;
}
/**
@@ -682,7 +795,7 @@ class _Warning extends \IPS\Content\Item
public function canAcknowledge( $member=NULL )
{
$member = $member ?: \IPS\Member::loggedIn();
return $this->member === $member->member_id;
return intval($this->member) === intval($member->member_id);
}
/**
@@ -694,7 +807,7 @@ class _Warning extends \IPS\Content\Item
public function canDelete( $member=NULL )
{
$member = $member ?: \IPS\Member::loggedIn();
return $member->modPermission('mod_revoke_warn');
return ( $member->modPermission('mod_revoke_warn') and $member->modPermission('mod_see_warn') );
}
/* !\IPS\Helpers\Table */