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,40 +11,61 @@
|
||||
namespace IPS\core\modules\admin\moderation;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warnings
|
||||
*/
|
||||
class _warnings extends \IPS\Node\Controller
|
||||
class warnings extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\core\Warnings\Reason';
|
||||
protected string $nodeClass = '\IPS\core\Warnings\Reason';
|
||||
|
||||
/**
|
||||
* Show the "add" button in the page root rather than the table root
|
||||
*/
|
||||
protected $_addButtonInRoot = FALSE;
|
||||
protected bool $_addButtonInRoot = FALSE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'warn_settings' );
|
||||
Dispatcher::i()->checkAcpPermission( 'warn_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -53,32 +74,32 @@ class _warnings extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
/* Init */
|
||||
$activeTab = \IPS\Request::i()->tab ?: NULL;
|
||||
$activeTab = Request::i()->tab ?: NULL;
|
||||
$activeTabContents = '';
|
||||
$tabs = array();
|
||||
|
||||
/* Reasons */
|
||||
if ( \IPS\Settings::i()->warn_on and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'reasons_view' ) )
|
||||
if ( Settings::i()->warn_on and Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'reasons_view' ) )
|
||||
{
|
||||
$tabs['reasons'] = 'warn_reasons';
|
||||
if ( $activeTab == 'reasons' )
|
||||
{
|
||||
parent::manage();
|
||||
$activeTabContents = \IPS\Output::i()->output;
|
||||
$activeTabContents = Output::i()->output;
|
||||
}
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
if ( \IPS\Settings::i()->warn_on and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_view' ) )
|
||||
if ( Settings::i()->warn_on and Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_view' ) )
|
||||
{
|
||||
$tabs['actions'] = 'warn_actions';
|
||||
if ( $activeTab == 'actions' )
|
||||
{
|
||||
/* Init */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_members_warn_actions', \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings' ) );
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_members_warn_actions', Url::internal( 'app=core&module=moderation&controller=warnings' ) );
|
||||
$table->include = array( 'wa_points', 'wa_mq', 'wa_rpa', 'wa_suspend' );
|
||||
$table->sortBy = $table->sortBy ?: 'wa_points';
|
||||
$table->sortDirection = $table->sortDirection ?: 'asc';
|
||||
@@ -88,21 +109,21 @@ class _warnings extends \IPS\Node\Controller
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_edit' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_edit' ) )
|
||||
{
|
||||
$return['edit'] = array(
|
||||
'icon' => 'pencil',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&do=actionForm&id=' ) . $row['wa_id'],
|
||||
'link' => Url::internal( 'app=core&module=moderation&controller=warnings&do=actionForm&id=' ) . $row['wa_id'],
|
||||
'title' => 'edit',
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add') )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add') )
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_delete' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'icon' => 'times-circle',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&do=actionDelete&id=' ) . $row['wa_id'],
|
||||
'link' => Url::internal( 'app=core&module=moderation&controller=warnings&do=actionDelete&id=' ) . $row['wa_id'],
|
||||
'title' => 'delete',
|
||||
'data' => array( 'delete' => '' )
|
||||
);
|
||||
@@ -115,27 +136,27 @@ class _warnings extends \IPS\Node\Controller
|
||||
$table->parsers = array(
|
||||
'wa_mq' => function( $val, $row )
|
||||
{
|
||||
return $val ? ( ( $val == -1 ) ? \IPS\Member::loggedIn()->language()->addToStack('indefinitely') : ( \IPS\Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_mq_unit'] == 'd' ? \IPS\Member::loggedIn()->language()->addToStack('days') : \IPS\Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
return $val ? ( ( $val == -1 ) ? Member::loggedIn()->language()->addToStack('indefinitely') : ( Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_mq_unit'] == 'd' ? Member::loggedIn()->language()->addToStack('days') : Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
},
|
||||
'wa_rpa' => function( $val, $row )
|
||||
{
|
||||
return $val ? ( ( $val == -1 ) ? \IPS\Member::loggedIn()->language()->addToStack('indefinitely') : ( \IPS\Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_rpa_unit'] == 'd' ? \IPS\Member::loggedIn()->language()->addToStack('days') : \IPS\Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
return $val ? ( ( $val == -1 ) ? Member::loggedIn()->language()->addToStack('indefinitely') : ( Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_rpa_unit'] == 'd' ? Member::loggedIn()->language()->addToStack('days') : Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
},
|
||||
'wa_suspend' => function( $val, $row )
|
||||
{
|
||||
return $val ? ( ( $val == -1 ) ? \IPS\Member::loggedIn()->language()->addToStack('indefinitely') : ( \IPS\Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_suspend_unit'] == 'd' ? \IPS\Member::loggedIn()->language()->addToStack('days') : \IPS\Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
return $val ? ( ( $val == -1 ) ? Member::loggedIn()->language()->addToStack('indefinitely') : ( Member::loggedIn()->language()->addToStack('for') . ' ' . $val . ' ' . ( $row['wa_suspend_unit'] == 'd' ? Member::loggedIn()->language()->addToStack('days') : Member::loggedIn()->language()->addToStack('hours') ) ) ) : '-';
|
||||
}
|
||||
);
|
||||
|
||||
/* Add button */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'moderation', 'actions_add' ) )
|
||||
{
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&do=actionForm' ),
|
||||
'link' => Url::internal( 'app=core&module=moderation&controller=warnings&do=actionForm' ),
|
||||
'title' => 'add',
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add') )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add') )
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -149,22 +170,22 @@ class _warnings extends \IPS\Node\Controller
|
||||
$tabs['settings'] = 'settings';
|
||||
if ( $activeTab == 'settings' )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'warn_on', \IPS\Settings::i()->warn_on, FALSE, array( 'togglesOn' => array(
|
||||
$form->add( new YesNo( 'warn_on', Settings::i()->warn_on, FALSE, array( 'togglesOn' => array(
|
||||
'warn_protected',
|
||||
'warn_show_own',
|
||||
'warnings_acknowledge'
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'warn_protected', explode( ',', \IPS\Settings::i()->warn_protected ), FALSE, array( 'options' => \IPS\Member\Group::groups( TRUE, FALSE ), 'parse' => 'normal', 'multiple' => TRUE ), NULL, NULL, NULL, 'warn_protected' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'warn_show_own', \IPS\Settings::i()->warn_show_own, FALSE, array(), NULL, NULL, NULL, 'warn_show_own' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'warnings_acknowledge', \IPS\Settings::i()->warnings_acknowledge, FALSE, array(), NULL, NULL, NULL, 'warnings_acknowledge' ) );
|
||||
$form->add( new CheckboxSet( 'warn_protected', explode( ',', Settings::i()->warn_protected ), FALSE, array( 'options' => Group::groups( TRUE, FALSE ), 'parse' => 'normal', 'multiple' => TRUE ), NULL, NULL, NULL, 'warn_protected' ) );
|
||||
$form->add( new YesNo( 'warn_show_own', Settings::i()->warn_show_own, FALSE, array(), NULL, NULL, NULL, 'warn_show_own' ) );
|
||||
$form->add( new YesNo( 'warnings_acknowledge', Settings::i()->warnings_acknowledge, FALSE, array(), NULL, NULL, NULL, 'warnings_acknowledge' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
\IPS\Session::i()->log( 'acplog__warn_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&tab=settings' ), 'saved' );
|
||||
Session::i()->log( 'acplog__warn_settings' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=moderation&controller=warnings&tab=settings' ), 'saved' );
|
||||
}
|
||||
|
||||
$activeTabContents = (string) $form;
|
||||
@@ -173,18 +194,19 @@ class _warnings extends \IPS\Node\Controller
|
||||
/* Add the blurb in */
|
||||
if ( $activeTab != 'settings' )
|
||||
{
|
||||
$activeTabContents = \IPS\Theme::i()->getTemplate( 'forms' )->blurb( 'warn_' . $activeTab . '_blurb', TRUE, TRUE ) . $activeTabContents;
|
||||
$activeTabContents = Theme::i()->getTemplate( 'forms' )->blurb( 'warn_' . $activeTab . '_blurb', TRUE, TRUE ) . $activeTabContents;
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('warnings');
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('warnings');
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=moderation&controller=warnings" ) );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'moderation_warnings_blurb' );
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'global' )->tabs( $tabs, $activeTab, $activeTabContents, Url::internal( "app=core&module=moderation&controller=warnings" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,29 +215,29 @@ class _warnings extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionForm()
|
||||
protected function actionForm() : void
|
||||
{
|
||||
$current = NULL;
|
||||
if ( \IPS\Request::i()->id )
|
||||
if ( Request::i()->id )
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_members_warn_actions', array( 'wa_id=?', \IPS\Request::i()->id ) )->first();
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'actions_edit' );
|
||||
$current = Db::i()->select( '*', 'core_members_warn_actions', array( 'wa_id=?', Request::i()->id ) )->first();
|
||||
Dispatcher::i()->checkAcpPermission( 'actions_edit' );
|
||||
}
|
||||
|
||||
if ( !$current )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'actions_add' );
|
||||
Dispatcher::i()->checkAcpPermission( 'actions_add' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'wa_points', ( $current ? $current['wa_points'] : 0 ), TRUE ) );
|
||||
$form->add( new Number( 'wa_points', ( $current ? $current['wa_points'] : 0 ), TRUE ) );
|
||||
foreach ( array( 'mq', 'rpa', 'suspend' ) as $k )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'wa_' . $k, ( $current ? array( $current[ 'wa_' . $k ], $current[ 'wa_' . $k . '_unit' ] ) : array( NULL, NULL ) ), FALSE, array(
|
||||
$form->add( new Custom( 'wa_' . $k, ( $current ? array( $current[ 'wa_' . $k ], $current[ 'wa_' . $k . '_unit' ] ) : array( NULL, NULL ) ), FALSE, array(
|
||||
'getHtml' => function( $element )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'members' )->warningTime( $element->name, $element->value, 'for', 'indefinitely' );
|
||||
return Theme::i()->getTemplate( 'members' )->warningTime( $element->name, $element->value, 'for', 'indefinitely' );
|
||||
},
|
||||
'formatValue'=> function( $element )
|
||||
{
|
||||
@@ -229,32 +251,32 @@ class _warnings extends \IPS\Node\Controller
|
||||
}
|
||||
) ) );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'wa_override', ( $current ? $current['wa_override'] : FALSE ) ) );
|
||||
$form->add( new YesNo( 'wa_override', ( $current ? $current['wa_override'] : FALSE ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$save = array( 'wa_points' => $values['wa_points'], 'wa_override' => $values['wa_override'] );
|
||||
foreach ( array( 'mq', 'rpa', 'suspend' ) as $k )
|
||||
{
|
||||
$save[ 'wa_' . $k ] = \intval( $values[ 'wa_' . $k ][0] );
|
||||
$save[ 'wa_' . $k ] = intval( $values[ 'wa_' . $k ][0] );
|
||||
$save[ 'wa_' . $k . '_unit' ] = $values[ 'wa_' . $k ][1];
|
||||
}
|
||||
|
||||
if ( $current )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_members_warn_actions', $save, array( 'wa_id=?', $current['wa_id'] ) );
|
||||
\IPS\Session::i()->log( 'acplog__wa_edited', array( $save['wa_points'] => FALSE ) );
|
||||
Db::i()->update( 'core_members_warn_actions', $save, array( 'wa_id=?', $current['wa_id'] ) );
|
||||
Session::i()->log( 'acplog__wa_edited', array( $save['wa_points'] => FALSE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_members_warn_actions', $save );
|
||||
\IPS\Session::i()->log( 'acplog__wa_created', array( $save['wa_points'] => FALSE ) );
|
||||
Db::i()->insert( 'core_members_warn_actions', $save );
|
||||
Session::i()->log( 'acplog__wa_created', array( $save['wa_points'] => FALSE ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&tab=actions' ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=moderation&controller=warnings&tab=actions' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'warn_action', $form, FALSE );
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'global' )->block( 'warn_action', $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,22 +284,22 @@ class _warnings extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionDelete()
|
||||
protected function actionDelete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'actions_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'actions_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
try
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_members_warn_actions', array( 'wa_id=?', \IPS\Request::i()->id ) )->first();
|
||||
$current = Db::i()->select( '*', 'core_members_warn_actions', array( 'wa_id=?', Request::i()->id ) )->first();
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__wa_deleted', array( $current['wa_points'] => FALSE ) );
|
||||
\IPS\Db::i()->delete( 'core_members_warn_actions', array( 'wa_id=?', \IPS\Request::i()->id ) );
|
||||
Session::i()->log( 'acplog__wa_deleted', array( $current['wa_points'] => FALSE ) );
|
||||
Db::i()->delete( 'core_members_warn_actions', array( 'wa_id=?', Request::i()->id ) );
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
catch ( UnderflowException $e ) { }
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=moderation&controller=warnings&tab=actions' ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=moderation&controller=warnings&tab=actions' ), 'saved' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user