Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,604 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Admin CP Restrictions
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 04 Apr 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\core\modules\admin\staff;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin CP Restrictions
|
||||
*/
|
||||
class _admin extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\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' ) );
|
||||
|
||||
return parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_admin_permission_rows', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
|
||||
|
||||
/* Columns */
|
||||
$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 )
|
||||
);
|
||||
$table->include = array( 'row_id_type', 'row_id', 'row_updated' );
|
||||
$table->parsers = array(
|
||||
'row_id_type' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( $val, array( 'ipsBadge', 'ipsBadge_neutral' ) );
|
||||
},
|
||||
'row_id' => function( $val, $row )
|
||||
{
|
||||
return $row['row_id_type'] === 'group' ? \IPS\Member\Group::load( $row['row_id'] )->formattedName : htmlentities( $row['name'], \IPS\HTMLENTITIES, 'UTF-8', FALSE );
|
||||
},
|
||||
'row_updated' => function( $val )
|
||||
{
|
||||
return ( $val ) ? \IPS\DateTime::ts( $val )->localeDate() : \IPS\Member::loggedIn()->language()->addToStack('never');
|
||||
}
|
||||
);
|
||||
$table->mainColumn = 'name';
|
||||
$table->quickSearch = array( array( 'name', 'word_custom' ), 'row_id' );
|
||||
$table->classes = array( 'row_id_type' => 'icon' );
|
||||
|
||||
/* Sorting */
|
||||
$table->sortBy = $table->sortBy ?: 'row_updated';
|
||||
$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' ) )
|
||||
{
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\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') )
|
||||
),
|
||||
);
|
||||
}
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
$delKey = 'acprestrictions_delwarning_' . $row['row_id_type'];
|
||||
|
||||
$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']}" ),
|
||||
'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']}" ),
|
||||
'title' => 'delete',
|
||||
'data' => array( 'delete' => '' ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( $row['row_id_type'] === 'member' )
|
||||
{
|
||||
if ( $row['row_id'] == \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_member' ) )
|
||||
{
|
||||
unset( $buttons['edit'] );
|
||||
}
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_member' ) )
|
||||
{
|
||||
unset( $buttons['delete'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->inGroup( $row['row_id'] ) )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_group' ) )
|
||||
{
|
||||
unset( $buttons['edit'] );
|
||||
}
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_group' ) )
|
||||
{
|
||||
unset( $buttons['delete'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
};
|
||||
|
||||
/* Buttons for logs */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
|
||||
'title' => 'acplogs',
|
||||
'icon' => 'search',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ),
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['loginLogs'] = array(
|
||||
'title' => 'adminloginlogs',
|
||||
'icon' => 'key',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ),
|
||||
);
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'acprestrictions', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function add()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) and \IPS\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' ) ) ) ) );
|
||||
}
|
||||
if ( \IPS\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' ) );
|
||||
}
|
||||
if ( \IPS\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' ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$rowId = NULL;
|
||||
|
||||
if ( $values['acprestrictions_type'] === 'group' or !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_group' );
|
||||
if ( \IPS\Member::loggedIn()->inGroup( $values['acprestrictions_group'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
|
||||
}
|
||||
else
|
||||
{
|
||||
$rowId = $values['acprestrictions_group'];
|
||||
}
|
||||
}
|
||||
elseif ( $values['acprestrictions_member'] )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_member' );
|
||||
if ( $values['acprestrictions_member'] === \IPS\Member::loggedIn() )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
|
||||
}
|
||||
else
|
||||
{
|
||||
$rowId = $values['acprestrictions_member']->member_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $rowId !== NULL )
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", $rowId, $values['acprestrictions_type'] ) );
|
||||
|
||||
if ( !count( $current ) )
|
||||
{
|
||||
$current = array(
|
||||
'row_id' => $rowId,
|
||||
'row_id_type' => $values['acprestrictions_type'],
|
||||
'row_perm_cache' => '*',
|
||||
'row_updated' => time()
|
||||
);
|
||||
\IPS\Db::i()->insert( 'core_admin_permission_rows', $current );
|
||||
\IPS\Session::i()->log( 'acplog__acpr_created', array( ( $values['acprestrictions_type'] == 'group' ? \IPS\Member\Group::load( $values['acprestrictions_group'] )->name : $values['acprestrictions_member']->name ) => FALSE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$current = $current->first();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=staff&controller=admin&do=edit&id={$current['row_id']}&type={$current['row_id_type']}" ) );
|
||||
}
|
||||
}
|
||||
|
||||
\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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function edit()
|
||||
{
|
||||
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();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\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 )
|
||||
{
|
||||
\IPS\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'] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'acprestrictions_noself', '1C113/4', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Get available restrictions */
|
||||
$restrictions = array();
|
||||
foreach ( \IPS\Application::applications() as $app )
|
||||
{
|
||||
$restrictions['applications'][ $app->directory ] = $app->id;
|
||||
|
||||
$_restrictions = array();
|
||||
$file = \IPS\ROOT_PATH . "/applications/{$app->directory}/data/acprestrictions.json";
|
||||
if ( file_exists( $file ) )
|
||||
{
|
||||
$_restrictions = json_decode( file_get_contents( $file ), TRUE );
|
||||
}
|
||||
|
||||
foreach ( $app->modules( 'admin' ) as $module )
|
||||
{
|
||||
if ( !$module->protected )
|
||||
{
|
||||
$restrictions['modules'][ $app->id ][ $module->key ] = $module->id;
|
||||
|
||||
if ( isset( $_restrictions[ $module->key ] ) )
|
||||
{
|
||||
$restrictions['items'][ $module->id ] = $_restrictions[ $module->key ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Warning if they have all permissions */
|
||||
if ( $current['row_perm_cache'] === '*' )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'admin_allperm_warning', 'warning' );
|
||||
}
|
||||
/* Or a button to give all */
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'all' => array(
|
||||
'title' => 'moderators_allperm',
|
||||
'icon' => 'check-circle',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=allperms&id=' ) . $current['row_id'] . '&type=' . $current['row_id_type'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/* 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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function save()
|
||||
{
|
||||
/* 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();
|
||||
if ( !$current )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C113/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Save */
|
||||
\IPS\Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => json_encode( ( is_array( \IPS\Request::i()->r ) ) ? \IPS\Request::i()->r : array() ), 'row_updated' => time() ), array( "row_id=? AND row_id_type=?", intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) );
|
||||
|
||||
unset( \IPS\Data\Store::i()->administrators );
|
||||
|
||||
/* Log */
|
||||
\IPS\Session::i()->log( 'acplog__acpr_edited', array( ( $current['row_id_type'] == 'group' ? \IPS\Member\Group::load( $current['row_id'] )->name : \IPS\Member::load( $current['row_id'] )->name ) => FALSE ) );
|
||||
|
||||
/* Boink */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Give All Permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function allperms()
|
||||
{
|
||||
/* Load */
|
||||
$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();
|
||||
if ( !$current )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C113/5', 404, '' );
|
||||
}
|
||||
|
||||
/* Set */
|
||||
\IPS\Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => '*', 'row_updated' => time() ), array( array( "row_id=? AND row_id_type=?", $current['row_id'], $current['row_id_type'] ) ) );
|
||||
|
||||
unset( \IPS\Data\Store::i()->administrators );
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__acpr_edited', array( ( $current['row_id_type'] == 'group' ? \IPS\Member\Group::load( $current['row_id'] )->name : \IPS\Member::load( $current['row_id'] )->name ) => FALSE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=edit&id=' . $current['row_id'] . '&type=' . $current['row_id_type'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
$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();
|
||||
if ( $current )
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplog__acpr_deleted', array( ( $current['row_id_type'] == 'group' ? \IPS\Member\Group::load( $current['row_id'] )->name : \IPS\Member::load( $current['row_id'] )->name ) => FALSE ) );
|
||||
\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 );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Logs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionLogs()
|
||||
{
|
||||
\IPS\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->langPrefix = 'acplogs_';
|
||||
$table->include = array( 'member_id', 'action', 'ip_address', 'ctime' );
|
||||
$table->mainColumn = 'action';
|
||||
$table->parsers = array(
|
||||
'member_id' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return htmlentities( \IPS\Member::load( $val )->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'action' => function( $val, $row )
|
||||
{
|
||||
if ( $row['lang_key'] )
|
||||
{
|
||||
$langKey = $row['lang_key'];
|
||||
$params = array();
|
||||
foreach ( json_decode( $row['note'], TRUE ) as $k => $v )
|
||||
{
|
||||
$params[] = ( $v ? \IPS\Member::loggedIn()->language()->addToStack( $k ) : $k );
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $row['note'];
|
||||
}
|
||||
},
|
||||
'ip_address'=> function( $val )
|
||||
{
|
||||
if ( \IPS\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 $val;
|
||||
},
|
||||
'ctime' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'module' => function( $val, $key )
|
||||
{
|
||||
$key = "module__{$key['appcomponent']}_{$val}";
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $key );
|
||||
}
|
||||
);
|
||||
$table->sortBy = $table->sortBy ?: 'ctime';
|
||||
$table->sortDirection = $table->sortDirection ?: 'desc';
|
||||
|
||||
/* 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,
|
||||
'module' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\Application', 'subnodeWhere' => array( 'sys_module_area=?', 'admin' ), 'searchProp' => 'key' ) ),
|
||||
'note' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
);
|
||||
$table->quickSearch = 'note';
|
||||
|
||||
/* Add a button for settings */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs_prune' ) )
|
||||
{
|
||||
\IPS\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') )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/* 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 = \IPS\Theme::i()->getTemplate( 'global' )->block( 'acplogs', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionLogSettings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs_prune' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'prune_log_admin', \IPS\Settings::i()->prune_log_admin, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), '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' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminlogssettings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminlogssettings', $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Login Logs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loginLogs()
|
||||
{
|
||||
\IPS\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->langPrefix = 'adminloginlogs_';
|
||||
$table->sortBy = $table->sortBy ?: 'admin_time';
|
||||
$table->sortDirection = $table->sortDirection ?: 'DESC';
|
||||
$table->include = array( 'admin_username', 'admin_ip_address', 'admin_time', 'admin_success' );
|
||||
|
||||
/* Search */
|
||||
$table->quickSearch = 'admin_username';
|
||||
$table->advancedSearch = array(
|
||||
'admin_username' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'admin_ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
);
|
||||
|
||||
/* Filters */
|
||||
$table->filters = array(
|
||||
'adminloginlogs_successful' => 'admin_success = 1',
|
||||
'adminloginlogs_unsuccessful' => 'admin_success = 0',
|
||||
);
|
||||
|
||||
/* Custom parsers */
|
||||
$table->parsers = array(
|
||||
'admin_time' => function( $val, $row )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'admin_success' => function( $val, $row )
|
||||
{
|
||||
return ( $val ) ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
|
||||
},
|
||||
);
|
||||
|
||||
/* Add a button for settings */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs_prune' ) )
|
||||
{
|
||||
\IPS\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') )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/* 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 = \IPS\Theme::i()->getTemplate( 'global' )->block( 'adminloginlogs', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Login Log Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loginLogsSettings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs_prune' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'prune_log_adminlogin', \IPS\Settings::i()->prune_log_adminlogin, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), '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' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminloginlogssettings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminloginlogssettings', $form, FALSE );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Staff directory management
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 18 Sep 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\core\modules\admin\staff;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Staff directory management
|
||||
*/
|
||||
class _directory extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\core\StaffDirectory\Group';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'staffdirectory/staffdirectory.css', 'core', 'admin' ) );
|
||||
return parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Root Buttons
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
{
|
||||
$buttons = parent::_getRootButtons();
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$buttons['add']['title'] = 'staff_add_group';
|
||||
unset( $buttons['add']['data'] );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,603 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief moderators
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 24 Apr 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\core\modules\admin\staff;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* moderators
|
||||
*/
|
||||
class _moderators extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_moderators', \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ) );
|
||||
|
||||
/* Columns */
|
||||
$table->langPrefix = 'moderators_';
|
||||
$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 )
|
||||
);
|
||||
$table->include = array( 'type', 'id', 'updated' );
|
||||
$table->parsers = array(
|
||||
'type' => function( $val, $row )
|
||||
{
|
||||
return "<i class='fa fa-" . ( ( $val === 'm' ) ? 'user' : 'group' ) . "' data-ipstooltip _title=' " . ( ( $val === 'm' ) ? \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_member') : \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_group') ) . "'></i>";
|
||||
},
|
||||
'id' => function( $val, $row )
|
||||
{
|
||||
return $row['type'] === 'g' ? \IPS\Member\Group::load( $row['id'] )->formattedName : htmlentities( $row['name'], \IPS\HTMLENTITIES, 'UTF-8', FALSE );
|
||||
},
|
||||
'updated' => function( $val )
|
||||
{
|
||||
return ( $val ) ? \IPS\DateTime::ts( $val )->localeDate() : \IPS\Member::loggedIn()->language()->addToStack('never');
|
||||
}
|
||||
);
|
||||
$table->mainColumn = 'name';
|
||||
$table->quickSearch = array( array( 'name', 'word_custom' ), 'id' );
|
||||
$table->classes = array( 'type' => 'icon' );
|
||||
|
||||
/* Sorting */
|
||||
$table->sortBy = $table->sortBy ?: 'updated';
|
||||
$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' ) )
|
||||
{
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\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') )
|
||||
),
|
||||
);
|
||||
}
|
||||
$table->rowButtons = function( $row )
|
||||
{
|
||||
$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']}" ),
|
||||
'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']}" ),
|
||||
'title' => 'delete',
|
||||
'data' => array( 'delete' => '' ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( $row['type'] === 'm' )
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_member' ) )
|
||||
{
|
||||
unset( $buttons['edit'] );
|
||||
}
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_member' ) )
|
||||
{
|
||||
unset( $buttons['delete'] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_edit_group' ) )
|
||||
{
|
||||
unset( $buttons['edit'] );
|
||||
}
|
||||
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_delete_group' ) )
|
||||
{
|
||||
unset( $buttons['delete'] );
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
};
|
||||
|
||||
/* Buttons for logs */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
|
||||
'title' => 'modlogs',
|
||||
'icon' => 'search',
|
||||
'link' => \IPS\Http\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 = \IPS\Theme::i()->getTemplate( 'global' )->block( 'moderators', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function add()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'acprestrictions_type', NULL, TRUE, array( 'options' => array( 'g' => 'group', 'm' => 'member' ), 'toggles' => array( 'g' => array( 'acprestrictions_group' ), 'm' => array( 'acprestrictions_member' ) ) ) ) );
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_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' ) );
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_group' ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'acprestrictions_member', NULL, ( \IPS\Request::i()->acprestrictions_type === 'member' ), array(), NULL, NULL, NULL, 'acprestrictions_member' ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$rowId = NULL;
|
||||
|
||||
if ( $values['acprestrictions_type'] === 'g' or !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'moderators_add_member' ) )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_add_group' );
|
||||
$rowId = $values['acprestrictions_group'];
|
||||
}
|
||||
elseif ( $values['acprestrictions_member'] )
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'moderators_add_member' );
|
||||
$rowId = $values['acprestrictions_member']->member_id;
|
||||
}
|
||||
|
||||
if ( $rowId !== NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", $rowId, $values['acprestrictions_type'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$current = array();
|
||||
}
|
||||
|
||||
if ( !count( $current ) )
|
||||
{
|
||||
$current = array(
|
||||
'id' => $rowId,
|
||||
'type' => $values['acprestrictions_type'],
|
||||
'perms' => '*',
|
||||
'updated' => time()
|
||||
);
|
||||
|
||||
\IPS\Db::i()->insert( 'core_moderators', $current );
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
|
||||
{
|
||||
$ext->onChange( $current, $values );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__moderator_created', array( ( $values['acprestrictions_type'] == 'g' ? \IPS\Member::loggedIn()->language()->get( "core_group_{$values['acprestrictions_group']}" ) : $values['acprestrictions_member']->name ) => FALSE ) );
|
||||
|
||||
unset (\IPS\Data\Store::i()->moderators);
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=staff&controller=moderators&do=edit&id={$current['id']}&type={$current['type']}" ) );
|
||||
}
|
||||
}
|
||||
|
||||
\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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function edit()
|
||||
{
|
||||
try
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C118/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$_name = ( $current['type'] === 'm' ) ? \IPS\Member::load( $current['id'] )->name : \IPS\Member\Group::load( $current['id'] )->name;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\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() );
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
|
||||
{
|
||||
if ( $ext instanceof \IPS\Content\ModeratorPermissions )
|
||||
{
|
||||
foreach ( $ext->actions as $s )
|
||||
{
|
||||
$class = $ext::$class;
|
||||
$toggles[ $s ][] = "can_{$s}_{$class::$title}";
|
||||
}
|
||||
|
||||
if ( isset( $class::$commentClass ) )
|
||||
{
|
||||
foreach ( $ext->commentActions as $s )
|
||||
{
|
||||
$commentClass = $class::$commentClass;
|
||||
$toggles[ $s ][] = "can_{$s}_{$commentClass::$title}";
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $class::$reviewClass ) )
|
||||
{
|
||||
foreach ( $ext->reviewActions as $s )
|
||||
{
|
||||
$reviewClass = $class::$reviewClass;
|
||||
$toggles[ $s ][] = "can_{$s}_{$reviewClass::$title}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Build */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$extensions = array();
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE, 'core' ) as $k => $ext )
|
||||
{
|
||||
$extensions[ $k ] = $ext;
|
||||
}
|
||||
|
||||
if ( isset( $extensions['core_General'] ) )
|
||||
{
|
||||
$meFirst = array( 'core_General' => $extensions['core_General'] );
|
||||
unset( $extensions['core_General'] );
|
||||
$extensions = $meFirst + $extensions;
|
||||
}
|
||||
|
||||
foreach( $extensions as $k => $ext )
|
||||
{
|
||||
$form->addTab( 'modperms__' . $k );
|
||||
|
||||
foreach ( $ext->getPermissions( $toggles ) as $name => $data )
|
||||
{
|
||||
/* Class */
|
||||
$type = is_array( $data ) ? $data[0] : $data;
|
||||
$class = '\IPS\Helpers\Form\\' . ( $type );
|
||||
|
||||
/* Current Value */
|
||||
if ( $currentPermissions === '*' )
|
||||
{
|
||||
switch ( $type )
|
||||
{
|
||||
case 'YesNo':
|
||||
$currentValue = TRUE;
|
||||
break;
|
||||
|
||||
case 'Number':
|
||||
$currentValue = -1;
|
||||
break;
|
||||
|
||||
case 'Node':
|
||||
$currentValue = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentValue = ( isset( $currentPermissions[ $name ] ) ? $currentPermissions[ $name ] : NULL );
|
||||
}
|
||||
|
||||
/* Options */
|
||||
$options = is_array( $data ) ? $data[1] : array();
|
||||
if ( $type === 'Number' )
|
||||
{
|
||||
$options['unlimited'] = -1;
|
||||
}
|
||||
|
||||
/* Prefix/Suffix */
|
||||
$prefix = NULL;
|
||||
$suffix = NULL;
|
||||
if ( is_array( $data ) )
|
||||
{
|
||||
if ( isset( $data[2] ) )
|
||||
{
|
||||
$prefix = $data[2];
|
||||
}
|
||||
if ( isset( $data[3] ) )
|
||||
{
|
||||
$suffix = $data[3];
|
||||
}
|
||||
}
|
||||
|
||||
/* Add */
|
||||
$form->add( new $class( $name, $currentValue, FALSE, $options, NULL, $prefix, $suffix, $name ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
foreach ( $v as $l => $w )
|
||||
{
|
||||
if ( $w instanceof \IPS\Node\Model )
|
||||
{
|
||||
$values[ $k ][ $l ] = $w->_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $currentPermissions == '*' )
|
||||
{
|
||||
$changed = $values;
|
||||
}
|
||||
else
|
||||
{
|
||||
$changed = array();
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
if ( !isset( $currentPermissions[ $k ] ) or $currentPermissions[ $k ] != $v )
|
||||
{
|
||||
$changed[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_moderators', array( 'perms' => json_encode( $values ), 'updated' => time() ), array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
|
||||
{
|
||||
$ext->onChange( $current, $changed );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__moderator_edited', array( ( $current['type'] == 'g' ? \IPS\Member::loggedIn()->language()->get( "core_group_{$current['id']}" ) : \IPS\Member::load( $current['id'] )->name ) => FALSE ) );
|
||||
$currentPermissions = $values;
|
||||
|
||||
unset (\IPS\Data\Store::i()->moderators);
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ), 'saved' );
|
||||
}
|
||||
|
||||
/* Warning if they have all permissions */
|
||||
if ( $currentPermissions === '*' )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'moderators_allperm_warning', 'warning' );
|
||||
}
|
||||
/* Or a button to give all */
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'all' => array(
|
||||
'title' => 'moderators_allperm',
|
||||
'icon' => 'asterisk',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=allperms&id=' ) . $current['id'] . '&type=' . $current['type'],
|
||||
'data' => array( 'confirm' => '' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = $_name;
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'members' )->moderatorPermissions( $_name, $form );
|
||||
}
|
||||
|
||||
/**
|
||||
* Give All Permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function allperms()
|
||||
{
|
||||
/* Load */
|
||||
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
|
||||
if ( !$current )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C118/3', 404, '' );
|
||||
}
|
||||
|
||||
/* Set */
|
||||
\IPS\Db::i()->update( 'core_moderators', array( 'perms' => '*', 'updated' => time() ), array( array( "id=? AND type=?", $current['id'], $current['type'] ) ) );
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
|
||||
{
|
||||
$ext->onChange( $current, '*' );
|
||||
}
|
||||
|
||||
unset ( \IPS\Data\Store::i()->moderators );
|
||||
|
||||
/* Log and redirect */
|
||||
\IPS\Session::i()->log( 'acplog__moderator_edited', array( ( $current['type'] == 'g' ? \IPS\Member::loggedIn()->language()->get( "core_group_{$current['id']}" ) : \IPS\Member::load( $current['id'] )->name ) => FALSE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators&do=edit&id=' . $current['id'] . '&type=' . $current['type'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
{
|
||||
/* Load */
|
||||
$current = \IPS\Db::i()->select( '*', 'core_moderators', array( "id=? AND type=?", intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
|
||||
if ( !$current )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C118/4', 404, '' );
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
{
|
||||
$ext->onDelete( $current );
|
||||
}
|
||||
|
||||
unset (\IPS\Data\Store::i()->moderators);
|
||||
|
||||
/* Log and redirect */
|
||||
\IPS\Session::i()->log( 'acplog__moderator_deleted', array( ( $current['type'] == 'g' ? \IPS\Member::loggedIn()->language()->get( "core_group_{$current['id']}" ) : \IPS\Member::load( $current['id'] )->name ) => FALSE ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=moderators' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Action Logs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionLogs()
|
||||
{
|
||||
\IPS\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->langPrefix = 'modlogs_';
|
||||
$table->include = array( 'member_id', 'action', 'ip_address', 'ctime' );
|
||||
$table->mainColumn = 'action';
|
||||
$table->parsers = array(
|
||||
'member_id' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return htmlentities( \IPS\Member::load( $val )->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'action' => function( $val, $row )
|
||||
{
|
||||
if ( $row['lang_key'] )
|
||||
{
|
||||
$langKey = $row['lang_key'];
|
||||
$params = array();
|
||||
$note = json_decode( $row['note'], TRUE );
|
||||
if ( !empty( $note ) )
|
||||
{
|
||||
foreach ($note as $k => $v)
|
||||
{
|
||||
$params[] = $v ? \IPS\Member::loggedIn()->language()->addToStack($k) : $k;
|
||||
}
|
||||
}
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $row['note'];
|
||||
}
|
||||
},
|
||||
'ip_address'=> function( $val )
|
||||
{
|
||||
if ( \IPS\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 $val;
|
||||
},
|
||||
'ctime' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'module' => function( $val, $key )
|
||||
{
|
||||
$key = "module__{$key['appcomponent']}_{$val}";
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( $key );
|
||||
}
|
||||
);
|
||||
$table->sortBy = $table->sortBy ?: 'ctime';
|
||||
$table->sortDirection = $table->sortDirection ?: 'desc';
|
||||
|
||||
/* 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,
|
||||
'module' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\Application', 'subnodeWhere' => array( 'sys_module_area=?', 'front' ), 'searchProp' => 'key' ) )
|
||||
);
|
||||
|
||||
/* Add a button for settings */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_moderatorlogs_prune' ) )
|
||||
{
|
||||
\IPS\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') )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/* 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 = \IPS\Theme::i()->getTemplate( 'global' )->block( 'modlogs', (string) $table );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function actionLogSettings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_moderatorlogs_prune' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'prune_log_moderator', \IPS\Settings::i()->prune_log_moderator, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), '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' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('moderatorlogssettings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'moderatorlogssettings', $form, FALSE );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user