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

+193 -159
View File
@@ -11,33 +11,66 @@
namespace IPS\core\modules\admin\staff;
/* 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\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Interval;
use IPS\Helpers\Form\Member as FormMember;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Table\Db as TableDb;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Group;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function in_array;
use function intval;
use function is_array;
use const IPS\CIC;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_MEMBER;
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;
}
/**
* Admin CP Restrictions
*/
class _admin extends \IPS\Dispatcher\Controller
class admin extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
Dispatcher::i()->checkAcpPermission( 'restrictions_manage' );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
return parent::execute();
parent::execute();
}
/**
@@ -45,41 +78,41 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_permission_rows', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
$table = new TableDb( 'core_admin_permission_rows', Url::internal( 'app=core&module=staff&controller=admin' ) );
/* Columns */
$table->selects = array( 'row_perm_cache', 'row_updated', 'row_id', 'row_id_type' );
$table->langPrefix = 'acprestrictions_';
$table->joins = array(
array( 'select' => "IF(core_admin_permission_rows.row_id_type= 'group', w.word_custom, m.name) as name", 'from' => array( 'core_members', 'm' ), 'where' => "m.member_id=core_admin_permission_rows.row_id AND core_admin_permission_rows.row_id_type='member'" ),
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_admin_permission_rows.row_id ) AND core_admin_permission_rows.row_id_type='group' AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_admin_permission_rows.row_id ) AND core_admin_permission_rows.row_id_type='group' AND w.lang_id=" . Member::loggedIn()->language()->id )
);
$table->include = array( 'name', 'row_updated', 'row_perm_cache' );
$table->parsers = array(
'name' => function( $val, $row )
{
$return = \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( $row['row_id_type'], array( 'ipsBadge', 'ipsBadge_neutral', 'ipsBadge_label' ) );
$return = Theme::i()->getTemplate( 'global' )->shortMessage( $row['row_id_type'], array( 'ipsBadge', 'ipsBadge--neutral', 'ipsBadge--label' ) );
try
{
$name = empty( $row['name'] ) ? \IPS\Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['row_id_type'] === 'group' ) ? \IPS\Member\Group::load( $row['row_id'] )->formattedName : $name;
$name = empty( $row['name'] ) ? Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['row_id_type'] === 'group' ) ? Group::load( $row['row_id'] )->formattedName : $name;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$return .= \IPS\Member::loggedIn()->language()->addToStack('deleted_group');
$return .= Member::loggedIn()->language()->addToStack('deleted_group');
}
return $return;
},
'row_updated' => function( $val )
{
return ( $val ) ? \IPS\DateTime::ts( $val )->localeDate() : \IPS\Member::loggedIn()->language()->addToStack('never');
return ( $val ) ? DateTime::ts( $val )->localeDate() : Member::loggedIn()->language()->addToStack('never');
},
'row_perm_cache' => function( $val )
{
return \IPS\Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
return Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
}
);
$table->mainColumn = 'name';
@@ -91,15 +124,15 @@ class _admin extends \IPS\Dispatcher\Controller
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) or \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) or Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'add' => array(
'primary' => TRUE,
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=add' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=add' ),
'title' => 'acprestrictions_add',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_add') )
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('acprestrictions_add') )
),
);
}
@@ -110,13 +143,13 @@ class _admin extends \IPS\Dispatcher\Controller
$buttons = array(
'edit' => array(
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=admin&do=edit&id={$row['row_id']}&type={$row['row_id_type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=admin&do=edit&id={$row['row_id']}&type={$row['row_id_type']}" ),
'title' => 'edit',
'class' => '',
),
'delete' => array(
'icon' => 'times-circle',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=admin&do=delete&id={$row['row_id']}&type={$row['row_id_type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=admin&do=delete&id={$row['row_id']}&type={$row['row_id_type']}" ),
'title' => 'delete',
'data' => array( 'delete' => '' ),
)
@@ -124,17 +157,17 @@ class _admin extends \IPS\Dispatcher\Controller
if ( $row['row_id_type'] === 'member' )
{
if ( $row['row_id'] == \IPS\Member::loggedIn()->member_id )
if ( $row['row_id'] == Member::loggedIn()->member_id )
{
return array();
}
else
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_member' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_member' ) )
{
unset( $buttons['delete'] );
}
@@ -142,17 +175,17 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
if ( \IPS\Member::loggedIn()->inGroup( $row['row_id'] ) )
if ( Member::loggedIn()->inGroup( $row['row_id'] ) )
{
return array();
}
else
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_group' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_group' ) )
{
unset( $buttons['delete'] );
}
@@ -163,36 +196,36 @@ class _admin extends \IPS\Dispatcher\Controller
};
/* Buttons for logs */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs' ) )
{
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
Output::i()->sidebar['actions']['actionLogs'] = array(
'title' => 'acplogs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ),
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs' ) )
{
\IPS\Output::i()->sidebar['actions']['loginLogs'] = array(
Output::i()->sidebar['actions']['loginLogs'] = array(
'title' => 'adminloginlogs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ),
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'members' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'members' ) )
{
\IPS\Output::i()->sidebar['actions']['list_admins'] = array(
Output::i()->sidebar['actions']['list_admins'] = array(
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=members&controller=members&filter=members_filter_administrators' ),
'link' => Url::internal( 'app=core&module=members&controller=members&filter=members_filter_administrators' ),
'title' => 'security_list_admins',
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions');
\IPS\Output::i()->output = (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack('acprestrictions');
Output::i()->output = (string) $table;
}
/**
@@ -200,33 +233,33 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function add()
protected function add() : void
{
$form = new \IPS\Helpers\Form();
$form = new Form();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) and Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Radio( 'acprestrictions_type', NULL, TRUE, array( 'options' => array( 'group' => 'group', 'member' => 'member' ), 'toggles' => array( 'group' => array( 'acprestrictions_group' ), 'member' => array( 'acprestrictions_member' ) ) ) ) );
$form->add( new Radio( 'acprestrictions_type', NULL, TRUE, array( 'options' => array( 'group' => 'group', 'member' => 'member' ), 'toggles' => array( 'group' => array( 'acprestrictions_group' ), 'member' => array( 'acprestrictions_member' ) ) ) ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
{
$form->add( new \IPS\Helpers\Form\Select( 'acprestrictions_group', NULL, FALSE, array( 'options' => \IPS\Member\Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'acprestrictions_group' ) );
$form->add( new Select( 'acprestrictions_group', NULL, FALSE, array( 'options' => Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'acprestrictions_group' ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Member( 'acprestrictions_member', NULL, ( \IPS\Request::i()->acprestrictions_type === 'member' ), array( 'multiple' => 1 ), NULL, NULL, NULL, 'acprestrictions_member' ) );
$form->add( new FormMember( 'acprestrictions_member', NULL, ( Request::i()->acprestrictions_type === 'member' ), array( 'multiple' => 1 ), NULL, NULL, NULL, 'acprestrictions_member' ) );
}
if ( $values = $form->values() )
{
$rowId = NULL;
if ( $values['acprestrictions_type'] === 'group' or !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
if ( $values['acprestrictions_type'] === 'group' or !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_group' );
if ( \IPS\Member::loggedIn()->inGroup( $values['acprestrictions_group'] ) )
Dispatcher::i()->checkAcpPermission( 'restrictions_add_group' );
if ( Member::loggedIn()->inGroup( $values['acprestrictions_group'] ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
$form->error = Member::loggedIn()->language()->addToStack('acprestrictions_noself');
}
else
{
@@ -235,10 +268,10 @@ class _admin extends \IPS\Dispatcher\Controller
}
elseif ( $values['acprestrictions_member'] )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_member' );
if ( $values['acprestrictions_member']->member_id === \IPS\Member::loggedIn()->member_id )
Dispatcher::i()->checkAcpPermission( 'restrictions_add_member' );
if ( $values['acprestrictions_member']->member_id === Member::loggedIn()->member_id )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
$form->error = Member::loggedIn()->language()->addToStack('acprestrictions_noself');
}
else
{
@@ -248,9 +281,9 @@ class _admin extends \IPS\Dispatcher\Controller
if ( $rowId !== NULL )
{
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", $rowId, $values['acprestrictions_type'] ) );
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", $rowId, $values['acprestrictions_type'] ) );
if ( !\count( $current ) )
if ( !count( $current ) )
{
$current = array(
'row_id' => $rowId,
@@ -258,7 +291,7 @@ class _admin extends \IPS\Dispatcher\Controller
'row_perm_cache' => '*',
'row_updated' => time()
);
\IPS\Db::i()->insert( 'core_admin_permission_rows', $current );
Db::i()->insert( 'core_admin_permission_rows', $current );
if( $values['acprestrictions_type'] == 'group' )
{
@@ -269,21 +302,21 @@ class _admin extends \IPS\Dispatcher\Controller
$logValue = array( $values['acprestrictions_member']->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__acpr_created', $logValue );
Session::i()->log( 'acplog__acpr_created', $logValue );
}
else
{
$current = $current->first();
}
unset( \IPS\Data\Store::i()->administrators );
unset( Store::i()->administrators );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=staff&controller=admin" ) );
Output::i()->redirect( Url::internal( "app=core&module=staff&controller=admin" ) );
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_add');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'acprestrictions_add', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('acprestrictions_add');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'acprestrictions_add', $form, FALSE );
}
/**
@@ -292,41 +325,41 @@ class _admin extends \IPS\Dispatcher\Controller
* @csrfChecked Uses form helper 7 Oct 2019
* @return void
*/
protected function edit()
protected function edit() : void
{
try
{
/* Get record */
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2C113/1', 404, '' );
Output::i()->error( 'node_error', '2C113/1', 404, '' );
}
/* Check permissions */
if ( $current['row_id_type'] === 'member' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_edit_member' );
if ( $current['row_id'] == \IPS\Member::loggedIn()->member_id )
Dispatcher::i()->checkAcpPermission( 'restrictions_edit_member' );
if ( $current['row_id'] == Member::loggedIn()->member_id )
{
\IPS\Output::i()->error( 'acprestrictions_noself', '1C113/3', 403, '' );
Output::i()->error( 'acprestrictions_noself', '1C113/3', 403, '' );
}
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_edit_group' );
if ( $current['row_id_type'] === 'group' and \IPS\Member::loggedIn()->inGroup( $current['row_id'] ) )
Dispatcher::i()->checkAcpPermission( 'restrictions_edit_group' );
if ( $current['row_id_type'] === 'group' and Member::loggedIn()->inGroup( $current['row_id'] ) )
{
\IPS\Output::i()->error( 'acprestrictions_noself', '1C113/4', 403, '' );
Output::i()->error( 'acprestrictions_noself', '1C113/4', 403, '' );
}
}
/* Get available restrictions */
$restrictions = array();
foreach ( \IPS\Application::applications() as $app )
foreach ( Application::applications() as $app )
{
if ( !\IPS\CIC or !\in_array( "{$app->directory}", \IPS\Member::$cicBlockedAcpRestrictions ) )
if ( !CIC or !in_array( "{$app->directory}", Member::$cicBlockedAcpRestrictions ) )
{
$restrictions['applications'][ $app->directory ] = $app->id;
@@ -340,7 +373,7 @@ class _admin extends \IPS\Dispatcher\Controller
foreach ( $app->modules( 'admin' ) as $module )
{
if ( !$module->protected and ( !\IPS\CIC or !\in_array( "{$app->directory}.{$module->key}", \IPS\Member::$cicBlockedAcpRestrictions ) ) )
if ( !$module->protected and ( !CIC or !in_array( "{$app->directory}.{$module->key}", Member::$cicBlockedAcpRestrictions ) ) )
{
$restrictions['modules'][ $app->id ][ $module->key ] = $module->id;
@@ -350,7 +383,7 @@ class _admin extends \IPS\Dispatcher\Controller
{
foreach ( $items as $restrictionKey => $langKey )
{
if ( !\IPS\CIC or !\in_array( "{$app->directory}.{$module->key}.{$restrictionKey}", \IPS\Member::$cicBlockedAcpRestrictions ) )
if ( !CIC or !in_array( "{$app->directory}.{$module->key}.{$restrictionKey}", Member::$cicBlockedAcpRestrictions ) )
{
$restrictions['items'][ $module->id ][ $group ][ $restrictionKey ] = $langKey;
}
@@ -363,9 +396,9 @@ class _admin extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
\IPS\Output::i()->title = $current['row_id_type'] === 'group' ? \IPS\Member\Group::load( $current['row_id'] )->name : \IPS\Member::load( $current['row_id'] )->name;
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'acprestrictions', \IPS\Theme::i()->getTemplate( 'members' )->acpRestrictions( $current['row_perm_cache'] === '*' ? '*' : json_decode( $current['row_perm_cache'], TRUE ), $restrictions, $current ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
Output::i()->title = $current['row_id_type'] === 'group' ? Group::load( $current['row_id'] )->name : Member::load( $current['row_id'] )->name;
Output::i()->output .= Theme::i()->getTemplate( 'global' )->block( 'acprestrictions', Theme::i()->getTemplate( 'members' )->acpRestrictions( $current['row_perm_cache'] === '*' ? '*' : json_decode( $current['row_perm_cache'], TRUE ), $restrictions, $current ) );
}
/**
@@ -373,23 +406,23 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function save()
protected function save() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* Get record */
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
if ( !$current )
{
\IPS\Output::i()->error( 'node_error', '2C113/2', 404, '' );
Output::i()->error( 'node_error', '2C113/2', 404, '' );
}
$permissions = ( \IPS\Request::i()->admin_use_restrictions == 'no' ) ? '*' : json_encode( ( \is_array( \IPS\Request::i()->r ) ) ? \IPS\Request::i()->r : array() );
$permissions = ( Request::i()->admin_use_restrictions == 'no' ) ? '*' : json_encode( ( is_array( Request::i()->r ) ) ? Request::i()->r : array() );
/* Save */
\IPS\Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => $permissions, 'row_updated' => time() ), array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) );
Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => $permissions, 'row_updated' => time() ), array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) );
unset( \IPS\Data\Store::i()->administrators );
unset( Store::i()->administrators );
/* Log */
if( $current['row_id_type'] == 'group' )
@@ -398,13 +431,13 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
$logValue = array( \IPS\Member::load( $current['row_id'] )->name => FALSE );
$logValue = array( Member::load( $current['row_id'] )->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__acpr_edited', $logValue );
Session::i()->log( 'acplog__acpr_edited', $logValue );
/* Boink */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
}
/**
@@ -412,21 +445,21 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function delete()
protected function delete() : void
{
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
if ( $current['row_id_type'] === 'member' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_delete_member' );
Dispatcher::i()->checkAcpPermission( 'restrictions_delete_member' );
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_delete_group' );
Dispatcher::i()->checkAcpPermission( 'restrictions_delete_group' );
}
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
if( $current['row_id_type'] == 'group' )
{
@@ -434,7 +467,7 @@ class _admin extends \IPS\Dispatcher\Controller
{
$name = 'core_group_' . $current['row_id'];
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$name = 'deleted_group';
}
@@ -443,7 +476,7 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
$member = \IPS\Member::load( $current['row_id'] );
$member = Member::load( $current['row_id'] );
if( $member->member_id )
{
@@ -455,12 +488,12 @@ class _admin extends \IPS\Dispatcher\Controller
}
}
\IPS\Session::i()->log( 'acplog__acpr_deleted', $logValue );
Session::i()->log( 'acplog__acpr_deleted', $logValue );
\IPS\Db::i()->delete( 'core_admin_permission_rows', array( 'row_id=? AND row_id_type=?', \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) );
unset ( \IPS\Data\Store::i()->administrators );
Db::i()->delete( 'core_admin_permission_rows', array( 'row_id=? AND row_id_type=?', intval( Request::i()->id ), Request::i()->type ) );
unset ( Store::i()->administrators );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ) );
}
/**
@@ -468,22 +501,22 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogs()
protected function actionLogs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs' );
Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_logs', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ) );
$table = new TableDb( 'core_admin_logs', Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ) );
$table->langPrefix = 'acplogs_';
$table->include = array( 'member_id', 'action', 'ip_address', 'ctime' );
$table->mainColumn = 'action';
$table->parsers = array(
'member_id' => function( $val, $row )
{
$member = \IPS\Member::load( $val );
$member = Member::load( $val );
if ( $member->member_id )
{
return htmlentities( \IPS\Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
return htmlentities( Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
}
else if ( $row['member_name'] != '' )
{
@@ -505,10 +538,10 @@ class _admin extends \IPS\Dispatcher\Controller
$params = array();
foreach ( json_decode( $row['note'], TRUE ) as $k => $v )
{
$params[] = ( $v ? \IPS\Member::loggedIn()->language()->addToStack( $k ) : $k );
$params[] = ( $v ? Member::loggedIn()->language()->addToStack( $k ) : $k );
}
return \IPS\Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
return Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
}
else
{
@@ -517,15 +550,15 @@ class _admin extends \IPS\Dispatcher\Controller
},
'ip_address'=> function( $val )
{
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
{
return "<a href='" . \IPS\Http\Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
return "<a href='" . Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
}
return $val;
},
'ctime' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
return (string) DateTime::ts( $val );
}
);
$table->sortBy = $table->sortBy ?: 'ctime';
@@ -533,16 +566,16 @@ class _admin extends \IPS\Dispatcher\Controller
/* Search */
$table->advancedSearch = array(
'member_id' => \IPS\Helpers\Table\SEARCH_MEMBER,
'ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'ctime' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'member_id' => SEARCH_MEMBER,
'ip_address' => SEARCH_CONTAINS_TEXT,
'ctime' => SEARCH_DATE_RANGE,
);
/* Custom quick search function to search unicode entities in JSON encoded data */
$table->quickSearch = function( $val )
{
$searchTerm = mb_strtolower( trim( \IPS\Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( \IPS\Request::i()->quicksearch ) ), '"' ) );
$searchTerm = mb_strtolower( trim( Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( Request::i()->quicksearch ) ), '"' ) );
return array(
"(`note` LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_custom`) LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_default`) LIKE CONCAT( '%', ?, '%' ))",
@@ -553,26 +586,26 @@ class _admin extends \IPS\Dispatcher\Controller
};
$table->joins = array(
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . Member::loggedIn()->language()->id )
);
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs_prune' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), \IPS\Member::loggedIn()->language()->addToStack( 'acplogs' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acplogs');
\IPS\Output::i()->output = (string) $table;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), Member::loggedIn()->language()->addToStack( 'acplogs' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('acplogs');
Output::i()->output = (string) $table;
}
/**
@@ -580,22 +613,22 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogSettings()
protected function actionLogSettings() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs_prune' );
Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_log_admin', \IPS\Settings::i()->prune_log_admin, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_admin' ) );
$form = new Form;
$form->add( new Interval( 'prune_log_admin', Settings::i()->prune_log_admin, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_admin' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__adminlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), 'saved' );
Session::i()->log( 'acplog__adminlog_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminlogssettings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminlogssettings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'adminlogssettings', $form, FALSE );
}
/**
@@ -603,12 +636,12 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function loginLogs()
protected function loginLogs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs' );
Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_login_logs', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ) );
$table = new TableDb( 'core_admin_login_logs', Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ) );
$table->joins[] = array( 'from' => 'core_members', 'where' => 'core_admin_login_logs.admin_username=core_members.email' );
$table->langPrefix = 'adminloginlogs_';
$table->sortBy = $table->sortBy ?: 'admin_time';
@@ -619,17 +652,18 @@ class _admin extends \IPS\Dispatcher\Controller
$table->quickSearch = 'admin_username';
$table->advancedSearch = array(
'admin_username' => array(
\IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
SEARCH_CONTAINS_TEXT,
array(),
function( $val ){
if( !empty( $val ) )
{
return array( "(core_members.name LIKE CONCAT(?, '%') OR admin_username LIKE CONCAT(?,'%'))", $val, $val );
}
return null;
}
),
'admin_ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'admin_time' => \IPS\Helpers\Table\SEARCH_DATE_RANGE
'admin_ip_address' => SEARCH_CONTAINS_TEXT,
'admin_time' => SEARCH_DATE_RANGE
);
/* Filters */
@@ -642,40 +676,40 @@ class _admin extends \IPS\Dispatcher\Controller
$table->parsers = array(
'admin_username' => function( $val, $row )
{
$member = \IPS\Member::constructFromData( $row );
$member = Member::constructFromData( $row );
if( $member->member_id )
{
return "<a href='{$member->acpUrl()}'>" . htmlentities( $member->name, ENT_DISALLOWED, 'UTF-8', FALSE ) . "</a>";
}
return $val;
},
'admin_time' => function( $val, $row )
'admin_time' => function( $val )
{
return \IPS\DateTime::ts( $val );
return DateTime::ts( $val );
},
'admin_success' => function( $val, $row )
'admin_success' => function( $val )
{
return ( $val ) ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
return ( $val ) ? "<i class='fa-solid fa-check'></i>" : "<i class='fa-solid fa-xmark'></i>";
},
);
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs_prune' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogsSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=loginLogsSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ), \IPS\Member::loggedIn()->language()->addToStack( 'adminloginlogs' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminloginlogs');
\IPS\Output::i()->output = (string) $table;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ), Member::loggedIn()->language()->addToStack( 'adminloginlogs' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminloginlogs');
Output::i()->output = (string) $table;
}
/**
@@ -683,21 +717,21 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function loginLogsSettings()
protected function loginLogsSettings() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs_prune' );
Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_log_adminlogin', \IPS\Settings::i()->prune_log_adminlogin, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_adminlogin' ) );
$form = new Form;
$form->add( new Interval( 'prune_log_adminlogin', Settings::i()->prune_log_adminlogin, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_adminlogin' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__adminloginlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
Session::i()->log( 'acplog__adminloginlog_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminloginlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminloginlogssettings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminloginlogssettings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'adminloginlogssettings', $form, FALSE );
}
}
@@ -11,37 +11,44 @@
namespace IPS\core\modules\admin\staff;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Dispatcher;
use IPS\Node\Controller;
use IPS\Output;
use IPS\Theme;
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;
}
/**
* Staff directory management
*/
class _directory extends \IPS\Node\Controller
class directory extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Node Class
*/
protected $nodeClass = '\IPS\core\StaffDirectory\Group';
protected string $nodeClass = '\IPS\core\StaffDirectory\Group';
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'leaders_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'staffdirectory/staffdirectory.css', 'core', 'admin' ) );
return parent::execute();
Dispatcher::i()->checkAcpPermission( 'leaders_manage' );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'staffdirectory/staffdirectory.css', 'core', 'admin' ) );
parent::execute();
}
/**
@@ -49,7 +56,7 @@ class _directory extends \IPS\Node\Controller
*
* @return array
*/
public function _getRootButtons()
public function _getRootButtons(): array
{
$buttons = parent::_getRootButtons();
@@ -11,38 +11,67 @@
namespace IPS\core\modules\admin\staff;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Content\ModeratorPermissions;
use IPS\Data\Store;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Interval;
use IPS\Helpers\Form\Member as FormMember;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Form\YesNo;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Group;
use IPS\Node\Model;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function in_array;
use function intval;
use function is_array;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_MEMBER;
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;
}
/**
* moderators
*/
class _moderators extends \IPS\Dispatcher\Controller
class moderators extends Controller
{
/**
* @brief Allow MySQL RW separation for efficiency
*/
public static $allowRWSeparation = TRUE;
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
Dispatcher::i()->checkAcpPermission( 'moderators_manage' );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
return parent::execute();
parent::execute();
}
/**
@@ -50,41 +79,41 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_moderators', \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ) );
$table = new \IPS\Helpers\Table\Db( 'core_moderators', Url::internal( 'app=core&module=staff&controller=moderators' ) );
/* Columns */
$table->langPrefix = 'moderators_';
$table->selects = array( 'perms', 'id', 'type', 'updated' );
$table->joins = array(
array( 'select' => "IF(core_moderators.type= 'g', w.word_custom, m.name) as name", 'from' => array( 'core_members', 'm' ), 'where' => "m.member_id=core_moderators.id AND core_moderators.type='m'" ),
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_moderators.id ) AND core_moderators.type='g' AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_moderators.id ) AND core_moderators.type='g' AND w.lang_id=" . Member::loggedIn()->language()->id )
);
$table->include = array( 'name', 'updated', 'perms' );
$table->parsers = array(
'name' => function( $val, $row )
{
$return = \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( $row['type'] === 'g' ? 'group' : 'member', array( 'ipsBadge', 'ipsBadge_neutral', 'ipsBadge_label' ) );
$return = Theme::i()->getTemplate( 'global' )->shortMessage( $row['type'] === 'g' ? 'group' : 'member', array( 'ipsBadge', 'ipsBadge--neutral', 'ipsBadge--label' ) );
try
{
$name = empty( $row['name'] ) ? \IPS\Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['type'] === 'g' ) ? \IPS\Member\Group::load( $row['id'] )->formattedName : $name;
$name = empty( $row['name'] ) ? Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['type'] === 'g' ) ? Group::load( $row['id'] )->formattedName : $name;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$return .= \IPS\Member::loggedIn()->language()->addToStack('deleted_group');
$return .= Member::loggedIn()->language()->addToStack('deleted_group');
}
return $return;
},
'updated' => function( $val )
{
return ( $val ) ? \IPS\DateTime::ts( $val )->localeDate() : \IPS\Member::loggedIn()->language()->addToStack('never');
return ( $val ) ? DateTime::ts( $val )->localeDate() : Member::loggedIn()->language()->addToStack('never');
},
'perms' => function( $val )
{
return \IPS\Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
return Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
}
);
$table->mainColumn = 'name';
@@ -96,15 +125,15 @@ class _moderators extends \IPS\Dispatcher\Controller
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) or \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) or Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'add' => array(
'primary' => TRUE,
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=add' ),
'link' => Url::internal( 'app=core&module=staff&controller=moderators&do=add' ),
'title' => 'add_moderator',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_moderator') )
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add_moderator') )
),
);
}
@@ -113,13 +142,13 @@ class _moderators extends \IPS\Dispatcher\Controller
$buttons = array(
'edit' => array(
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=moderators&do=edit&id={$row['id']}&type={$row['type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=moderators&do=edit&id={$row['id']}&type={$row['type']}" ),
'title' => 'edit',
'class' => '',
),
'delete' => array(
'icon' => 'times-circle',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=moderators&do=delete&id={$row['id']}&type={$row['type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=moderators&do=delete&id={$row['id']}&type={$row['type']}" ),
'title' => 'delete',
'data' => array( 'delete' => '' ),
)
@@ -127,22 +156,22 @@ class _moderators extends \IPS\Dispatcher\Controller
if ( $row['type'] === 'm' )
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_member' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_member' ) )
{
unset( $buttons['delete'] );
}
}
else
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_group' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_group' ) )
{
unset( $buttons['delete'] );
}
@@ -152,18 +181,18 @@ class _moderators extends \IPS\Dispatcher\Controller
};
/* Buttons for logs */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs' ) )
{
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
Output::i()->sidebar['actions']['actionLogs'] = array(
'title' => 'modlogs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ),
'link' => Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ),
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('moderators');
\IPS\Output::i()->output = (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack('moderators');
Output::i()->output = (string) $table;
}
/**
@@ -171,21 +200,21 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function add()
protected function add() : void
{
$form = new \IPS\Helpers\Form();
$form = new Form();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) and Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Radio( 'moderators_type', NULL, TRUE, array( 'options' => array( 'g' => 'group', 'm' => 'member' ), 'toggles' => array( 'g' => array( 'moderators_group' ), 'm' => array( 'moderators_member' ) ) ) ) );
$form->add( new Radio( 'moderators_type', NULL, TRUE, array( 'options' => array( 'g' => 'group', 'm' => 'member' ), 'toggles' => array( 'g' => array( 'moderators_group' ), 'm' => array( 'moderators_member' ) ) ) ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Select( 'moderators_group', NULL, FALSE, array( 'options' => \IPS\Member\Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'moderators_group' ) );
$form->add( new Select( 'moderators_group', NULL, FALSE, array( 'options' => Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'moderators_group' ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) )
{
$form->add( new \IPS\Helpers\Form\Member( 'moderators_member', NULL, ( \IPS\Request::i()->moderators_type === 'member' ), array(), NULL, NULL, NULL, 'moderators_member' ) );
$form->add( new FormMember( 'moderators_member', NULL, ( Request::i()->moderators_type === 'member' ), array(), NULL, NULL, NULL, 'moderators_member' ) );
}
if ( $values = $form->values() )
@@ -197,14 +226,14 @@ class _moderators extends \IPS\Dispatcher\Controller
$values['moderators_type'] = isset( $values['moderators_group'] ) ? 'g' : 'm';
}
if ( $values['moderators_type'] === 'g' or !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) )
if ( $values['moderators_type'] === 'g' or !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_add_group' );
Dispatcher::i()->checkAcpPermission( 'moderators_add_group' );
$rowId = $values['moderators_group'];
}
elseif ( $values['moderators_member'] )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_add_member' );
Dispatcher::i()->checkAcpPermission( 'moderators_add_member' );
$rowId = $values['moderators_member']->member_id;
}
@@ -212,14 +241,14 @@ class _moderators extends \IPS\Dispatcher\Controller
{
try
{
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", $rowId, $values['moderators_type'] ) )->first();
$current = Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", $rowId, $values['moderators_type'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$current = array();
}
if ( !\count( $current ) )
if ( !count( $current ) )
{
$current = array(
'id' => $rowId,
@@ -228,9 +257,9 @@ class _moderators extends \IPS\Dispatcher\Controller
'updated' => time()
);
\IPS\Db::i()->insert( 'core_moderators', $current );
Db::i()->insert( 'core_moderators', $current );
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
$ext->onChange( $current, $values );
}
@@ -244,17 +273,17 @@ class _moderators extends \IPS\Dispatcher\Controller
$logValue = array( $values['moderators_member']->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__moderator_created', $logValue );
Session::i()->log( 'acplog__moderator_created', $logValue );
unset (\IPS\Data\Store::i()->moderators);
unset (Store::i()->moderators);
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=staff&controller=moderators" ) );
Output::i()->redirect( Url::internal( "app=core&module=staff&controller=moderators" ) );
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('add_moderator');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'add_moderator', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('add_moderator');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'add_moderator', $form, FALSE );
}
/**
@@ -262,44 +291,44 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function edit()
protected function edit() : void
{
try
{
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2C118/2', 404, '' );
Output::i()->error( 'node_error', '2C118/2', 404, '' );
}
/* Check acp restrictions */
if ( $current['type'] === 'm' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_edit_member' );
Dispatcher::i()->checkAcpPermission( 'moderators_edit_member' );
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_edit_group' );
Dispatcher::i()->checkAcpPermission( 'moderators_edit_group' );
}
/* Load */
try
{
$_name = ( $current['type'] === 'm' ) ? \IPS\Member::load( $current['id'] )->name : \IPS\Member\Group::load( $current['id'] )->name;
$_name = ( $current['type'] === 'm' ) ? Member::load( $current['id'] )->name : Group::load( $current['id'] )->name;
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2C118/2', 404, '' );
Output::i()->error( 'node_error', '2C118/2', 404, '' );
}
$currentPermissions = ( $current['perms'] === '*' ) ? '*' : ( $current['perms'] ? json_decode( $current['perms'], TRUE ) : array() );
/* Define content field toggles */
$toggles = array( 'view_future' => array(), 'future_publish' => array(), 'pin' => array(), 'unpin' => array(), 'feature' => array(), 'unfeature' => array(), 'edit' => array(), 'hide' => array(), 'unhide' => array(), 'view_hidden' => array(), 'move' => array(), 'lock' => array(), 'unlock' => array(), 'reply_to_locked' => array(), 'delete' => array(), 'split_merge' => array(), 'feature_comments' => array(), 'unfeature_comments' => array(), 'add_item_message' => array(), 'edit_item_message' => array(), 'delete_item_message' => array(), 'toggle_item_moderation' => array() );
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
$toggles = array( 'view_future' => array(), 'future_publish' => array(), 'pin' => array(), 'unpin' => array(), 'feature' => array(), 'unfeature' => array(), 'edit' => array(), 'hide' => array(), 'unhide' => array(), 'view_hidden' => array(), 'move' => array(), 'lock' => array(), 'unlock' => array(), 'reply_to_locked' => array(), 'assign' => array(), 'delete' => array(), 'split_merge' => array(), 'feature_comments' => array(), 'unfeature_comments' => array(), 'add_item_message' => array(), 'edit_item_message' => array(), 'delete_item_message' => array(), 'toggle_item_moderation' => array(), 'view_reports' => array() );
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
if ( $ext instanceof \IPS\Content\ModeratorPermissions )
if ( $ext instanceof ModeratorPermissions )
{
foreach ( $ext->actions as $s )
{
@@ -331,17 +360,17 @@ class _moderators extends \IPS\Dispatcher\Controller
$nodeFields = array();
/* Build */
$form = new \IPS\Helpers\Form;
$form = new Form;
/* Add the restricted/unrestricted option first */
$form->add(
new \IPS\Helpers\Form\Radio( 'mod_use_restrictions', ( $currentPermissions === '*' ) ? 'no' : 'yes', TRUE, array( 'options' => array( 'no' => 'mod_all_permissions', 'yes' => 'mod_restricted' ), 'toggles' => array( 'yes' => array( 'permission_form_wrapper' ) ) ), NULL, NULL, NULL, 'use_restrictions_id' )
new Radio( 'mod_use_restrictions', ( $currentPermissions === '*' ) ? 'no' : 'yes', TRUE, array( 'options' => array( 'no' => 'mod_all_permissions', 'yes' => 'mod_restricted' ), 'toggles' => array( 'yes' => array( 'permission_form_wrapper' ) ) ), NULL, NULL, NULL, 'use_restrictions_id' )
);
$form->add( new \IPS\Helpers\Form\YesNo( 'mod_show_badge', ( $current ) ? $current['show_badge'] : TRUE, TRUE ) );
$form->add( new YesNo( 'mod_show_badge', ( $current ) ? $current['show_badge'] : TRUE, TRUE ) );
$extensions = array();
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE, 'core' ) as $k => $ext )
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE, 'core' ) as $k => $ext )
{
$extensions[ $k ] = $ext;
}
@@ -360,7 +389,7 @@ class _moderators extends \IPS\Dispatcher\Controller
foreach ( $ext->getPermissions( $toggles ) as $name => $data )
{
/* Class */
$type = \is_array( $data ) ? $data[0] : $data;
$type = is_array( $data ) ? $data[0] : $data;
$class = '\IPS\Helpers\Form\\' . ( $type );
/* Remember 'nodes' */
@@ -389,7 +418,7 @@ class _moderators extends \IPS\Dispatcher\Controller
}
else
{
$currentValue = ( isset( $currentPermissions[ $name ] ) ? $currentPermissions[ $name ] : NULL );
$currentValue = ( $currentPermissions[$name] ?? NULL );
/* We translate nodes to -1 so the moderator permissions merging works as expected allowing "all" to override individual node selections */
if( $type == 'Node' AND $currentValue == -1 )
@@ -399,7 +428,7 @@ class _moderators extends \IPS\Dispatcher\Controller
}
/* Options */
$options = \is_array( $data ) ? $data[1] : array();
$options = is_array( $data ) ? $data[1] : array();
if ( $type === 'Number' )
{
$options['unlimited'] = -1;
@@ -408,7 +437,7 @@ class _moderators extends \IPS\Dispatcher\Controller
/* Prefix/Suffix */
$prefix = NULL;
$suffix = NULL;
if ( \is_array( $data ) )
if ( is_array( $data ) )
{
if ( isset( $data[2] ) )
{
@@ -429,7 +458,7 @@ class _moderators extends \IPS\Dispatcher\Controller
if ( $values = $form->values() )
{
/* Allow extensions an opportunity to inspect the values and make adjustments */
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
if( method_exists( $ext, 'preSave' ) )
{
@@ -450,7 +479,7 @@ class _moderators extends \IPS\Dispatcher\Controller
foreach ( $values as $k => $v )
{
/* For node fields, if the value is 0 translate it to -1 so mod permissions can merge properly */
if( \in_array( $k, $nodeFields ) )
if( in_array( $k, $nodeFields ) )
{
/* If nothing is checked we have '', but if 'all' is checked then the value is 0 */
if( $v === 0 )
@@ -460,11 +489,11 @@ class _moderators extends \IPS\Dispatcher\Controller
}
}
if ( \is_array( $v ) )
if ( is_array( $v ) )
{
foreach ( $v as $l => $w )
{
if ( $w instanceof \IPS\Node\Model )
if ( $w instanceof Model )
{
$values[ $k ][ $l ] = $w->_id;
}
@@ -491,11 +520,11 @@ class _moderators extends \IPS\Dispatcher\Controller
$permissions = json_encode( $values );
}
\IPS\Db::i()->update( 'core_moderators', array( 'perms' => $permissions, 'updated' => time(), 'show_badge' => $values['mod_show_badge'] ), array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
Db::i()->update( 'core_moderators', array( 'perms' => $permissions, 'updated' => time(), 'show_badge' => $values['mod_show_badge'] ), array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
if( !( $currentPermissions == '*' AND $changed == '*' ) )
{
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
$ext->onChange( $current, $changed );
}
@@ -507,22 +536,22 @@ class _moderators extends \IPS\Dispatcher\Controller
}
else
{
$logValue = array( \IPS\Member::load( $current['id'] )->name => FALSE );
$logValue = array( Member::load( $current['id'] )->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__moderator_edited', $logValue );
Session::i()->log( 'acplog__moderator_edited', $logValue );
$currentPermissions = $values;
unset( \IPS\Data\Store::i()->moderators );
unset( Store::i()->moderators );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=moderators' ), 'saved' );
}
/* Display */
\IPS\Output::i()->title = $_name;
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
\IPS\Output::i()->output .= $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'members' ), 'moderatorPermissions' ) );
Output::i()->title = $_name;
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
Output::i()->output .= $form->customTemplate( array( Theme::i()->getTemplate( 'members' ), 'moderatorPermissions' ) );
}
/**
@@ -530,39 +559,39 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function delete()
protected function delete() : void
{
/* Load */
try
{
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2C118/4', 404, '' );
Output::i()->error( 'node_error', '2C118/4', 404, '' );
}
/* Check acp restrictions */
if ( $current['type'] === 'm' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_delete_member' );
Dispatcher::i()->checkAcpPermission( 'moderators_delete_member' );
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_delete_group' );
Dispatcher::i()->checkAcpPermission( 'moderators_delete_group' );
}
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
/* Delete */
\IPS\Db::i()->delete( 'core_moderators', array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
Db::i()->delete( 'core_moderators', array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
foreach ( Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
$ext->onDelete( $current );
}
unset (\IPS\Data\Store::i()->moderators);
unset (Store::i()->moderators);
/* Log and redirect */
if( $current['type'] == 'g' )
@@ -571,7 +600,7 @@ class _moderators extends \IPS\Dispatcher\Controller
{
$name = 'core_group_' . $current['id'];
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$name = 'deleted_group';
}
@@ -580,7 +609,7 @@ class _moderators extends \IPS\Dispatcher\Controller
}
else
{
$member = \IPS\Member::load( $current['id'] );
$member = Member::load( $current['id'] );
if( $member->member_id )
{
@@ -592,9 +621,9 @@ class _moderators extends \IPS\Dispatcher\Controller
}
}
\IPS\Session::i()->log( 'acplog__moderator_deleted', $logValue );
Session::i()->log( 'acplog__moderator_deleted', $logValue );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ) );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=moderators' ) );
}
/**
@@ -602,22 +631,22 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogs()
protected function actionLogs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_moderatorlogs' );
Dispatcher::i()->checkAcpPermission( 'restrictions_moderatorlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_moderator_logs', \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ) );
$table = new \IPS\Helpers\Table\Db( 'core_moderator_logs', Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ) );
$table->langPrefix = 'modlogs_';
$table->include = array( 'member_id', 'action', 'ip_address', 'ctime' );
$table->mainColumn = 'action';
$table->parsers = array(
'member_id' => function( $val, $row )
{
$member = \IPS\Member::load( $val );
$member = Member::load( $val );
if ( $member->member_id )
{
return htmlentities( \IPS\Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
return htmlentities( Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
}
else if ( $row['member_name'] != '' )
{
@@ -640,10 +669,10 @@ class _moderators extends \IPS\Dispatcher\Controller
{
foreach ($note as $k => $v)
{
$params[] = $v ? \IPS\Member::loggedIn()->language()->addToStack($k) : $k;
$params[] = $v ? Member::loggedIn()->language()->addToStack($k) : $k;
}
}
return \IPS\Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
return Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
}
else
{
@@ -652,15 +681,15 @@ class _moderators extends \IPS\Dispatcher\Controller
},
'ip_address'=> function( $val )
{
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
{
return "<a href='" . \IPS\Http\Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
return "<a href='" . Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
}
return $val;
},
'ctime' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
return (string) DateTime::ts( $val );
}
);
$table->sortBy = $table->sortBy ?: 'ctime';
@@ -668,16 +697,16 @@ class _moderators extends \IPS\Dispatcher\Controller
/* Search */
$table->advancedSearch = array(
'member_id' => \IPS\Helpers\Table\SEARCH_MEMBER,
'ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'ctime' => \IPS\Helpers\Table\SEARCH_DATE_RANGE
'member_id' => SEARCH_MEMBER,
'ip_address' => SEARCH_CONTAINS_TEXT,
'ctime' => SEARCH_DATE_RANGE
);
/* Custom quick search function to search unicode entities in JSON encoded data */
$table->quickSearch = function( $val )
{
$searchTerm = mb_strtolower( trim( \IPS\Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( \IPS\Request::i()->quicksearch ) ), '"' ) );
$searchTerm = mb_strtolower( trim( Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( Request::i()->quicksearch ) ), '"' ) );
return array(
"(`note` LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_custom`) LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_default`) LIKE CONCAT( '%', ?, '%' ))",
@@ -688,26 +717,26 @@ class _moderators extends \IPS\Dispatcher\Controller
};
$table->joins = array(
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . Member::loggedIn()->language()->id )
);
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs_prune' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ), \IPS\Member::loggedIn()->language()->addToStack( 'modlogs' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'modlogs' );
\IPS\Output::i()->output = (string) $table;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ), Member::loggedIn()->language()->addToStack( 'modlogs' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack( 'modlogs' );
Output::i()->output = (string) $table;
}
/**
@@ -715,21 +744,21 @@ class _moderators extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogSettings()
protected function actionLogSettings() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_moderatorlogs_prune' );
Dispatcher::i()->checkAcpPermission( 'restrictions_moderatorlogs_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_log_moderator', \IPS\Settings::i()->prune_log_moderator, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_moderator' ) );
$form = new Form;
$form->add( new Interval( 'prune_log_moderator', Settings::i()->prune_log_moderator, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_moderator' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__moderatorlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ), 'saved' );
Session::i()->log( 'acplog__moderatorlog_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=moderators&do=actionLogs' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('moderatorlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'moderatorlogssettings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('moderatorlogssettings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'moderatorlogssettings', $form, FALSE );
}
}