Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,40 +12,62 @@
|
||||
namespace IPS\cms\modules\admin\databases;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Fields as FieldsClass;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Checkbox;
|
||||
use IPS\Helpers\Form\Matrix;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Tree\Tree;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
class _fields extends \IPS\Node\Controller
|
||||
class fields extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\cms\Fields';
|
||||
protected string $nodeClass = '\IPS\cms\Fields';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
|
||||
$this->url = $this->url->setQueryString( array( 'database_id' => Request::i()->database_id ) );
|
||||
|
||||
$this->nodeClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$this->nodeClass = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'databases_use' );
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'cms_fields_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'databases_use' );
|
||||
Dispatcher::i()->checkAcpPermission( 'cms_fields_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -54,42 +76,43 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* If we lose the database id because of a log in, do something more useful than an uncaught exception */
|
||||
if ( ! isset( \IPS\Request::i()->database_id ) )
|
||||
if ( ! isset( Request::i()->database_id ) )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases" ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases" ) );
|
||||
}
|
||||
|
||||
parent::manage();
|
||||
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id );
|
||||
|
||||
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$url = Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id );
|
||||
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
|
||||
/* Build fixed fields */
|
||||
$fixed = array_merge( array( 'record_publish_date' => array(), 'record_expiry_date' => array(), 'record_allow_comments' => array(), 'record_comment_cutoff' => array(), 'record_image' => array() ), $class::fixedFieldPermissions() );
|
||||
|
||||
/* Fixed fields */
|
||||
$fixedFields = new \IPS\Helpers\Tree\Tree(
|
||||
$fixedFields = new Tree(
|
||||
$url,
|
||||
\IPS\Member::loggedIn()->language()->addToStack('content_fields_fixed_title'),
|
||||
Member::loggedIn()->language()->addToStack('content_fields_fixed_title'),
|
||||
function() use ( $fixed, $url )
|
||||
{
|
||||
$rows = array();
|
||||
|
||||
foreach( $fixed as $field => $data )
|
||||
{
|
||||
$description = ( $field === 'record_publish_date' ) ? \IPS\Member::loggedIn()->language()->addToStack( 'content_fields_fixed_record_publish_date_desc' ) : NULL;
|
||||
$rows[ $field ] = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $field, \IPS\Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ), FALSE, array(
|
||||
$description = ( $field === 'record_publish_date' ) ? Member::loggedIn()->language()->addToStack( 'content_fields_fixed_record_publish_date_desc' ) : NULL;
|
||||
$rows[ $field ] = Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $field, Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ), FALSE, array(
|
||||
'permission' => array(
|
||||
'icon' => 'lock',
|
||||
'title' => 'permissions',
|
||||
'link' => $url->setQueryString( array( 'field' => $field, 'do' => 'fixedPermissions' ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ) )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ) )
|
||||
)
|
||||
), $description, NULL, NULL, NULL, ( empty( $data['visible'] ) ? FALSE : TRUE ) );
|
||||
), $description, NULL, NULL, NULL, !empty($data['visible']));
|
||||
}
|
||||
|
||||
return $rows;
|
||||
@@ -103,9 +126,9 @@ class _fields extends \IPS\Node\Controller
|
||||
TRUE
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'databases' )->fieldsWrapper( $fixedFields );
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'databases' )->fieldsWrapper( $fixedFields );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_database_field_area', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( \IPS\Request::i()->database_id)->_title ) ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('content_database_field_area', FALSE, array( 'sprintf' => array( Databases::load( Request::i()->database_id)->_title ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,14 +136,15 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRoots()
|
||||
public function _getRoots(): array
|
||||
{
|
||||
/* @var FieldsClass $nodeClass */
|
||||
$nodeClass = $this->nodeClass;
|
||||
$rows = array();
|
||||
|
||||
foreach( $nodeClass::roots( NULL ) as $node )
|
||||
{
|
||||
if ( $node->database_id == \IPS\Request::i()->database_id )
|
||||
if ( $node->database_id == Request::i()->database_id )
|
||||
{
|
||||
$rows[ $node->_id ] = $this->_getRow( $node );
|
||||
}
|
||||
@@ -134,22 +158,23 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableToggle()
|
||||
public function enableToggle() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
|
||||
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
|
||||
$class::setFixedFieldVisibility( \IPS\Request::i()->id, (boolean) \IPS\Request::i()->status );
|
||||
$class::setFixedFieldVisibility( Request::i()->id, (boolean) Request::i()->status );
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->status )
|
||||
if ( Request::i()->status )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id . '&do=fixedPermissions&field=' . \IPS\Request::i()->id ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id . '&do=fixedPermissions&field=' . Request::i()->id ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id ), 'saved' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,16 +183,17 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAsTitle()
|
||||
public function setAsTitle() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
|
||||
try
|
||||
{
|
||||
$field = $class::load( \IPS\Request::i()->id );
|
||||
$field = $class::load( Request::i()->id );
|
||||
|
||||
if ( $field->canBeTitleField() )
|
||||
{
|
||||
@@ -175,11 +201,11 @@ class _fields extends \IPS\Node\Controller
|
||||
$database->save();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id ), 'saved' );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/1', 403, '' );
|
||||
Output::i()->error( 'cms_cannot_find_field', '2T255/1', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,16 +214,17 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAsContent()
|
||||
public function setAsContent() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
|
||||
try
|
||||
{
|
||||
$field = $class::load( \IPS\Request::i()->id );
|
||||
$field = $class::load( Request::i()->id );
|
||||
|
||||
if ( $field->canBeContentField() )
|
||||
{
|
||||
@@ -205,11 +232,11 @@ class _fields extends \IPS\Node\Controller
|
||||
$database->save();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id ), 'saved' );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/2', 403, '' );
|
||||
Output::i()->error( 'cms_cannot_find_field', '2T255/2', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,10 +245,11 @@ class _fields extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fixedPermissions()
|
||||
public function fixedPermissions() : void
|
||||
{
|
||||
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$perms = $class::fixedFieldPermissions( \IPS\Request::i()->field );
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
$perms = $class::fixedFieldPermissions( Request::i()->field );
|
||||
|
||||
$permMap = array( 'view' => 'view', 'edit' => 2, 'add' => 3 );
|
||||
|
||||
@@ -234,7 +262,7 @@ class _fields extends \IPS\Node\Controller
|
||||
}
|
||||
|
||||
/* Build Matrix */
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix = new Matrix;
|
||||
$matrix->manageable = FALSE;
|
||||
$matrix->langPrefix = 'content_perm_fixed_fields__';
|
||||
$matrix->columns = array(
|
||||
@@ -248,14 +276,14 @@ class _fields extends \IPS\Node\Controller
|
||||
$matrix->columns[ $k ] = function( $key, $value, $data ) use ( $perms, $k, $v )
|
||||
{
|
||||
$groupId = mb_substr( $key, 0, -( 2 + mb_strlen( $k ) ) );
|
||||
return new \IPS\Helpers\Form\Checkbox( $key, isset( $perms[ "perm_{$v}" ] ) and ( $perms[ "perm_{$v}" ] === '*' or \in_array( $groupId, explode( ',', $perms[ "perm_{$v}" ] ) ) ) );
|
||||
return new Checkbox( $key, isset( $perms[ "perm_{$v}" ] ) and ( $perms[ "perm_{$v}" ] === '*' or in_array( $groupId, explode( ',', $perms[ "perm_{$v}" ] ) ) ) );
|
||||
};
|
||||
$matrix->checkAlls[ $k ] = ( $perms[ "perm_{$v}" ] === '*' );
|
||||
}
|
||||
$matrix->checkAllRows = TRUE;
|
||||
|
||||
$rows = array();
|
||||
foreach ( \IPS\Member\Group::groups() as $group )
|
||||
foreach ( Group::groups() as $group )
|
||||
{
|
||||
$rows[ $group->g_id ] = array(
|
||||
'label' => $group->name,
|
||||
@@ -273,7 +301,7 @@ class _fields extends \IPS\Node\Controller
|
||||
/* Check for "all" checkboxes */
|
||||
foreach ( $permMap as $k => $v )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->__all[ $k ] ) )
|
||||
if ( isset( Request::i()->__all[ $k ] ) )
|
||||
{
|
||||
$_perms[ $v ] = '*';
|
||||
}
|
||||
@@ -288,7 +316,7 @@ class _fields extends \IPS\Node\Controller
|
||||
{
|
||||
foreach ( $permMap as $k => $v )
|
||||
{
|
||||
if ( isset( $perms[ $k ] ) and $perms[ $k ] and \is_array( $_perms[ $v ] ) )
|
||||
if ( isset( $perms[ $k ] ) and $perms[ $k ] and is_array( $_perms[ $v ] ) )
|
||||
{
|
||||
$_perms[ $v ][] = $group;
|
||||
}
|
||||
@@ -298,18 +326,89 @@ class _fields extends \IPS\Node\Controller
|
||||
/* Finalise */
|
||||
foreach ( $_perms as $k => $v )
|
||||
{
|
||||
$save[ "perm_{$k}" ] = \is_array( $v ) ? implode( ',', $v ) : $v;
|
||||
$save[ "perm_{$k}" ] = is_array( $v ) ? implode( ',', $v ) : $v;
|
||||
}
|
||||
|
||||
$class::setFixedFieldPermissions( \IPS\Request::i()->field, $save );
|
||||
$class::setFixedFieldPermissions( Request::i()->field, $save );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=fields&database_id=" . Request::i()->database_id ), 'saved' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output .= $matrix;
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_database_manage_fields');
|
||||
|
||||
Output::i()->output .= $matrix;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('content_database_manage_fields');
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage field toggles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function toggles() : void
|
||||
{
|
||||
/* @var FieldsClass $class */
|
||||
$class = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
try
|
||||
{
|
||||
$field = $class::load( Request::i()->id );
|
||||
if( !in_array( $field->type, $class::$canUseTogglesFields ) )
|
||||
{
|
||||
Output::i()->error( 'This field type cannot use toggles', 'CMSFT/2' );
|
||||
}
|
||||
}
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
Output::i()->error( 'node_error', '1CMSFT/1', 404 );
|
||||
}
|
||||
|
||||
$form = new Form;
|
||||
$form->class = 'ipsPad';
|
||||
|
||||
$form->addMessage( 'cms_fields_toggles_info', 'ipsMessage ipsMessage--info' );
|
||||
if( $field->type == 'YesNo' OR $field->type == 'Checkbox' )
|
||||
{
|
||||
$options = array(
|
||||
'togglesOn' => Member::loggedIn()->language()->addToStack( 'field_toggles_on' ),
|
||||
'togglesOff' => Member::loggedIn()->language()->addToStack( 'field_toggles_off' )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = $field->extra;
|
||||
}
|
||||
|
||||
$currentToggles = ( $field->toggles ? json_decode( $field->toggles, true ) : array() );
|
||||
foreach( $options as $k => $v )
|
||||
{
|
||||
$formField = new Node( 'field_field_toggles_' . $k, ( $currentToggles[$k] ?? null ), false, array(
|
||||
'class' => $class,
|
||||
'multiple' => true,
|
||||
'disabledIds' => array( $field->id, $database->field_title, $database->field_content )
|
||||
) );
|
||||
$formField->label = $v;
|
||||
$form->add( $formField );
|
||||
}
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$toggles = array();
|
||||
foreach( $options as $k => $v )
|
||||
{
|
||||
$key = 'field_field_toggles_' . $k;
|
||||
if( isset( $values[$key] ) AND is_array( $values[$key] ) AND count( $values[$key] ) )
|
||||
{
|
||||
$toggles[$k] = array_keys( $values[$key] );
|
||||
}
|
||||
}
|
||||
|
||||
$field->toggles = json_encode( $toggles );
|
||||
$field->save();
|
||||
|
||||
Output::i()->redirect( $this->url );
|
||||
}
|
||||
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user