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
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Records Model
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
@@ -12,33 +13,63 @@
|
||||
namespace IPS\cms\modules\admin\databases;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use IPS\cms\Categories as CategoriesClass;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Fields as FieldsClass;
|
||||
use IPS\cms\Records as RecordsClass;
|
||||
use IPS\Data\Cache;
|
||||
use IPS\DateTime;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Table\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use const IPS\Helpers\Table\SEARCH_NODE;
|
||||
use const IPS\Helpers\Table\SEARCH_SELECT;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* records
|
||||
*/
|
||||
class _records extends \IPS\Dispatcher\Controller
|
||||
class records 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
|
||||
{
|
||||
$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 ) );
|
||||
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'databases_use' );
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'records_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'databases_use' );
|
||||
Dispatcher::i()->checkAcpPermission( 'records_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -47,26 +78,26 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* There may be no database ID if the admin only has permission to view records and not the database list itself */
|
||||
if ( !\IPS\Request::i()->database_id )
|
||||
if ( !Request::i()->database_id )
|
||||
{
|
||||
foreach ( \IPS\cms\Databases::databases() as $database )
|
||||
foreach ( Databases::databases() as $database )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=manage&database_id=' . $database->_id ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=databases&controller=records&do=manage&database_id=' . $database->_id ) );
|
||||
}
|
||||
}
|
||||
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
$title = Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
|
||||
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'cms_custom_database_' . \IPS\Request::i()->database_id, \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records' ) );
|
||||
$table = new Db( 'cms_custom_database_' . Request::i()->database_id, Url::internal( 'app=cms&module=databases&controller=records' ) );
|
||||
$table->langPrefix = 'content_db_table_';
|
||||
$table->title = $title;
|
||||
$table->quickSearch = 'field_' . $database->field_title;
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'database_id' => Request::i()->database_id ) );
|
||||
|
||||
/* Only specify these if we are not re-ordering via the table headers, which are set in the Table contructor */
|
||||
if ( ! $table->sortBy )
|
||||
@@ -105,16 +136,16 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Add title header */
|
||||
\IPS\Member::loggedIn()->language()->words['content_db_table_field_' . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack( 'content_db_table_title' );
|
||||
Member::loggedIn()->language()->words['content_db_table_field_' . $database->field_title ] = Member::loggedIn()->language()->addToStack( 'content_db_table_title' );
|
||||
|
||||
$table->advancedSearch = array(
|
||||
'category_id' => array( \IPS\Helpers\Table\SEARCH_NODE, array(
|
||||
'category_id' => array( SEARCH_NODE, array(
|
||||
'class' => '\IPS\cms\Categories' . $database->id,
|
||||
'disabled' => false,
|
||||
'zeroVal' => 'content_db_table_as_no_cat'
|
||||
),
|
||||
),
|
||||
'record_comments'=> array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
|
||||
'record_comments'=> array( SEARCH_SELECT, array( 'options' => array(
|
||||
'null' => 'content_db_table_as_comments_null',
|
||||
1 => 'content_db_table_as_comments_yes',
|
||||
2 => 'content_db_table_as_comments_no'
|
||||
@@ -125,21 +156,21 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
/* Buttons */
|
||||
if ( $database->use_categories )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add'] = array(
|
||||
Output::i()->sidebar['actions']['add'] = array(
|
||||
'primary' => true,
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . \IPS\Request::i()->database_id ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('database_select_category' ) )
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . Request::i()->database_id ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('database_select_category' ), 'ipsDialog-size' => 'narrow' )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add'] = array(
|
||||
Output::i()->sidebar['actions']['add'] = array(
|
||||
'primary' => true,
|
||||
'title' => 'add',
|
||||
'icon' => 'plus',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . \IPS\Request::i()->database_id )
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . Request::i()->database_id )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,12 +179,12 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'records_edit' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'records_edit' ) )
|
||||
{
|
||||
$return['edit'] = array(
|
||||
'title' => 'edit',
|
||||
'icon' => 'pencil',
|
||||
'link' => \IPS\Http\Url::internal('app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=form'),
|
||||
'link' => Url::internal('app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=form'),
|
||||
'data' => array()
|
||||
);
|
||||
}
|
||||
@@ -161,16 +192,16 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$return['move'] = array(
|
||||
'title' => 'move',
|
||||
'icon' => 'arrow-right',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&do=select&move=' . $row['primary_id_field'] ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('database_select_category' ) )
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id . '&do=select&move=' . $row['primary_id_field'] ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('database_select_category' ) )
|
||||
);
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'records_delete' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'records_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=delete' ),
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=delete' ),
|
||||
'data' => array( 'delete' => '' )
|
||||
);
|
||||
}
|
||||
@@ -180,10 +211,11 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$table->parsers = array(
|
||||
'field_' . $database->field_title => function( $val, $row ) use ($database)
|
||||
{
|
||||
/* @var RecordsClass $class */
|
||||
$class = '\IPS\cms\Records' . $database->id;
|
||||
$val = $class::load( $row['primary_id_field'] )->_title;
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'records', 'cms', 'admin' )->title( $row, $val );
|
||||
return Theme::i()->getTemplate( 'records', 'cms', 'admin' )->title( $row, $val );
|
||||
},
|
||||
'category_id' => function( $val ) use ($database)
|
||||
{
|
||||
@@ -191,11 +223,12 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var CategoriesClass $class */
|
||||
$class = '\IPS\cms\Categories' . $database->id;
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'records', 'cms', 'admin' )->category( $class::load( $val ) );
|
||||
return Theme::i()->getTemplate( 'records', 'cms', 'admin' )->category( $class::load( $val ) );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -205,34 +238,34 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
'record_publish_date' => function( $val, $row )
|
||||
{
|
||||
$val = ( ! empty( $val ) ) ? $val : $row['record_saved'];
|
||||
return \IPS\DateTime::ts( $val )->localeDate();
|
||||
return DateTime::ts( $val )->localeDate();
|
||||
}
|
||||
);
|
||||
|
||||
/* Add a button for managing DB settings */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_edit' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_edit' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['databasemanage'] = array(
|
||||
Output::i()->sidebar['actions']['databasemanage'] = array(
|
||||
'title' => 'cms_manage_database',
|
||||
'icon' => 'wrench',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=form&id=' . $database->_id ),
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=databases&do=form&id=' . $database->_id ),
|
||||
'data' => NULL
|
||||
);
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['actions']['databasepermissions'] = array(
|
||||
Output::i()->sidebar['actions']['databasepermissions'] = array(
|
||||
'title' => 'cms_database_permissions',
|
||||
'icon' => 'lock',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=permissions&id=' . $database->_id ),
|
||||
'link' => Url::internal( 'app=cms&module=databases&controller=databases&do=permissions&id=' . $database->_id ),
|
||||
'data' => NULL
|
||||
);
|
||||
|
||||
/* Reset languages */
|
||||
\IPS\Member::loggedIn()->language()->words[ $table->langPrefix . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack($table->langPrefix . 'title');
|
||||
Member::loggedIn()->language()->words[ $table->langPrefix . $database->field_title ] = Member::loggedIn()->language()->addToStack($table->langPrefix . 'title');
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
\IPS\Output::i()->title = $title;
|
||||
Output::i()->output = (string) $table;
|
||||
Output::i()->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,31 +273,29 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'records_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'records_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
/* @var RecordsClass $recordClass */
|
||||
$recordClass = '\IPS\cms\Records' . Request::i()->database_id;
|
||||
|
||||
try
|
||||
{
|
||||
$record = $recordClass::load( \IPS\Request::i()->id );
|
||||
$record = $recordClass::load( Request::i()->id );
|
||||
$record->delete();
|
||||
|
||||
\IPS\Session::i()->modLog( 'acplogs__cms_deleted_record', array( $record->mapped('title') => FALSE, 'content_db_' . $record->database()->_id => TRUE ) );
|
||||
Session::i()->modLog( 'acplogs__cms_deleted_record', array( $record->mapped('title') => FALSE, 'content_db_' . $record->database()->_id => TRUE ) );
|
||||
}
|
||||
catch( \OutofRangeException $ex )
|
||||
catch( OutofRangeException $ex )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2T253/1', 403, '' );
|
||||
}
|
||||
Output::i()->error( 'no_module_permission', '2T253/1', 403, '' );
|
||||
}
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'record_deleted' );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id ), 'record_deleted' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,11 +303,13 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function select()
|
||||
protected function select() : void
|
||||
{
|
||||
$move = isset( \IPS\Request::i()->move ) ? \IPS\Request::i()->move : NULL;
|
||||
$catClass = 'IPS\cms\Categories' . \IPS\Request::i()->database_id;
|
||||
$recordClass = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
/* @var RecordsClass $recordClass
|
||||
* @var CategoriesClass $catClass */
|
||||
$move = isset( Request::i()->move ) ? Request::i()->move : NULL;
|
||||
$catClass = 'IPS\cms\Categories' . Request::i()->database_id;
|
||||
$recordClass = 'IPS\cms\Records' . Request::i()->database_id;
|
||||
$category = NULL;
|
||||
$record = NULL;
|
||||
|
||||
@@ -287,13 +320,13 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$record = $recordClass::load( $move );
|
||||
$category = $catClass::load( $record->category_id );
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
catch( OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'select_category', 'continue' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'category', $category, TRUE, array(
|
||||
'url' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . \IPS\Request::i()->database_id . ( ( $move ) ? '&move=' . $move : '' ) ),
|
||||
$form = new Form( 'select_category', 'continue' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--pre-add-record ipsForm_noLabels';
|
||||
$form->add( new Node( 'content_db_table_category_id', $category, TRUE, array(
|
||||
'url' => Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . Request::i()->database_id . ( ( $move ) ? '&move=' . $move : '' ) ),
|
||||
'class' => $catClass,
|
||||
'multiple' => false,
|
||||
'permissionCheck' => function( $node )
|
||||
@@ -316,25 +349,25 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
if ( $move and $record )
|
||||
{
|
||||
$record->move( $values['category'] );
|
||||
$record->move( $values['content_db_table_category_id'] );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_moved_record', array(
|
||||
Session::i()->log( 'acplogs__cms_moved_record', array(
|
||||
$record->mapped('title') => FALSE,
|
||||
$category->_title => TRUE,
|
||||
$values['category']->_title => TRUE,
|
||||
$record->database()->_title => TRUE
|
||||
) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'completed' );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id ), 'completed' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . \IPS\Request::i()->database_id . '&category_id=' . $values['category']->id ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . Request::i()->database_id . '&category_id=' . $values['content_db_table_category_id']->id ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'database_select_category' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'records' )->categorySelector( $form );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'database_select_category' );
|
||||
Output::i()->output = (string) $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,30 +375,29 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function form()
|
||||
public function form() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'records_edit' );
|
||||
Dispatcher::i()->checkAcpPermission( 'records_edit' );
|
||||
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
$title = Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
|
||||
|
||||
$current = NULL;
|
||||
$customValues = array();
|
||||
|
||||
/* @var RecordsClass $class */
|
||||
$class = 'IPS\cms\Records' . Request::i()->database_id;
|
||||
|
||||
$class = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
|
||||
if ( \IPS\Request::i()->id )
|
||||
if ( Request::i()->id )
|
||||
{
|
||||
$current = $class::load( \IPS\Request::i()->id );
|
||||
$customValues = $current->fieldValues();
|
||||
$current = $class::load( Request::i()->id );
|
||||
}
|
||||
|
||||
$fieldsClass = 'IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
$catClass = 'IPS\cms\Categories' . \IPS\Request::i()->database_id;
|
||||
$container = ( $current ) ? $catClass::load( $current->category_id ) : ( isset( \IPS\Request::i()->category_id ) ? $catClass::load( \IPS\Request::i()->category_id ) : NULL );
|
||||
|
||||
/* @var CategoriesClass $catClass */
|
||||
$catClass = 'IPS\cms\Categories' . Request::i()->database_id;
|
||||
$container = ( $current ) ? $catClass::load( $current->category_id ) : ( isset( Request::i()->category_id ) ? $catClass::load( Request::i()->category_id ) : NULL );
|
||||
$manuallyHandledFields = array( 'record_publish_date', 'record_expiry_date', 'record_allow_comments', 'record_comment_cutoff', 'record_meta_keywords', 'record_meta_description' );
|
||||
|
||||
$form = new \IPS\Helpers\Form();
|
||||
$form = new Form();
|
||||
|
||||
$form->addTab( 'content_database_record_tab_content' );
|
||||
|
||||
@@ -374,7 +406,7 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
|
||||
foreach( $formElements as $name => $field )
|
||||
{
|
||||
if ( \in_array( $name, $manuallyHandledFields ) )
|
||||
if ( in_array( $name, $manuallyHandledFields ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -405,7 +437,7 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$form->add( $formElements['record_expiry_date'] );
|
||||
}
|
||||
|
||||
$currentMember = ( $current ? \IPS\Member::load( $current->member_id ) : NULL );
|
||||
$currentMember = ( $current ? Member::load( $current->member_id ) : NULL );
|
||||
$options = array(
|
||||
'me' => 'record_author_choice_me',
|
||||
'notme' => 'record_author_choice_notme'
|
||||
@@ -416,17 +448,21 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$options['guest'] = 'record_author_choice_guest';
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'record_author_choice', $currentMember ? ( $currentMember->member_id === \IPS\Member::loggedIn()->member_id ? 'me' : ( $currentMember->member_id ? 'notme' : 'guest' ) ) : 'me', FALSE, array(
|
||||
$form->add( new Radio( 'record_author_choice', $currentMember ? ( $currentMember->member_id === Member::loggedIn()->member_id ? 'me' : ( $currentMember->member_id ? 'notme' : 'guest' ) ) : 'me', FALSE, array(
|
||||
'options' => $options,
|
||||
'toggles' => array(
|
||||
'notme' => array( 'record_member_id' )
|
||||
)
|
||||
), NULL, NULL, NULL, 'record_author_choice' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'record_member_id', ( $currentMember and $currentMember->member_id ) ? $currentMember : NULL, FALSE, array(), function( $val ) {
|
||||
if( !$val AND \IPS\Request::i()->record_author_choice == 'notme' )
|
||||
$form->add( new Form\Member( 'record_member_id', ( $currentMember and $currentMember->member_id ) ? $currentMember : NULL, null, array(), function($val ) {
|
||||
if( !$val AND Request::i()->record_author_choice == 'notme' )
|
||||
{
|
||||
throw new \DomainException( 'form_required' );
|
||||
throw new DomainException( 'form_required' );
|
||||
}
|
||||
elseif( Request::i()->record_author_choice == 'me' )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}, NULL, NULL, 'record_member_id' ) );
|
||||
|
||||
@@ -442,7 +478,7 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
|
||||
if ( Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
|
||||
{
|
||||
$form->addTab( 'content_database_record_tab_meta' );
|
||||
$form->add( $formElements['record_meta_keywords'] );
|
||||
@@ -451,8 +487,11 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
$fieldClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
|
||||
/* @var RecordsClass $recordClass */
|
||||
$recordClass = '\IPS\cms\Records' . Request::i()->database_id;
|
||||
|
||||
/* @var FieldsClass $fieldClass */
|
||||
$fieldClass = '\IPS\cms\Fields' . Request::i()->database_id;
|
||||
|
||||
$new = false;
|
||||
if ( empty( $current ) )
|
||||
@@ -462,14 +501,15 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( ! $database->use_categories )
|
||||
{
|
||||
/* @var CategoriesClass $catClass */
|
||||
$catClass = 'IPS\cms\Categories' . $database->id;
|
||||
$category = $catClass::load( $database->get__default_category() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->category_id ) )
|
||||
if ( isset( Request::i()->category_id ) )
|
||||
{
|
||||
$category = $catClass::load( \IPS\Request::i()->category_id );
|
||||
$category = $catClass::load( Request::i()->category_id );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,9 +520,9 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
/* Claim attachments */
|
||||
foreach( $fieldClass::data() as $key => $field )
|
||||
{
|
||||
if ( mb_ucfirst( $field->type ) === 'Editor' )
|
||||
if ( IPS::mb_ucfirst( $field->type ) === 'Editor' )
|
||||
{
|
||||
\IPS\File::claimAttachments( 'RecordField_' . ( $new ? 'new' : $current->primary_id_field ) . '_' . $field->id , $current->primary_id_field, $field->id, \IPS\Request::i()->database_id );
|
||||
File::claimAttachments( 'RecordField_' . $current->primary_id_field . '_' . $field->id , $current->primary_id_field, $field->id, Request::i()->database_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -492,24 +532,24 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
$current->record_meta_description = $values['record_meta_description'];
|
||||
|
||||
$changeAuthor = FALSE;
|
||||
if ( ! empty( \IPS\Request::i()->id ) )
|
||||
if ( ! empty( Request::i()->id ) )
|
||||
{
|
||||
if ( $values['record_author_choice'] === 'guest' )
|
||||
{
|
||||
if ( $current->member_id )
|
||||
{
|
||||
$values['record_member_id'] = new \IPS\Member;
|
||||
$values['record_member_id'] = new Member;
|
||||
$changeAuthor = TRUE;
|
||||
}
|
||||
}
|
||||
else if ( ! $current->member_id and $values['record_author_choice'] !== 'guest' )
|
||||
else if ( ! $current->member_id )
|
||||
{
|
||||
$values['record_member_id'] = ( $values['record_author_choice'] === 'me' ) ? \IPS\Member::loggedIn() : $values['record_member_id'];
|
||||
$values['record_member_id'] = ( $values['record_author_choice'] === 'me' ) ? Member::loggedIn() : $values['record_member_id'];
|
||||
$changeAuthor = TRUE;
|
||||
}
|
||||
else if ( $values['record_author_choice'] === 'me' )
|
||||
{
|
||||
$values['record_member_id'] = \IPS\Member::loggedIn();
|
||||
$values['record_member_id'] = Member::loggedIn();
|
||||
$changeAuthor = TRUE;
|
||||
}
|
||||
else if ( $values['record_author_choice'] === 'notme' and ! empty( $values['record_member_id'] ) )
|
||||
@@ -521,6 +561,7 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
/* Just editing, thanks */
|
||||
if ( ! $new )
|
||||
{
|
||||
$current->processBeforeEdit( $values );
|
||||
$current->processForm( $values );
|
||||
$current->processAfterEdit( $values );
|
||||
|
||||
@@ -528,7 +569,7 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$column = $recordClass::$databaseColumnMap['date'];
|
||||
|
||||
if ( $values[ $recordClass::$formLangPrefix . 'date' ] instanceof \IPS\DateTime )
|
||||
if ( $values[ $recordClass::$formLangPrefix . 'date' ] instanceof DateTime )
|
||||
{
|
||||
$current->$column = $values[ $recordClass::$formLangPrefix . 'date' ]->getTimestamp();
|
||||
}
|
||||
@@ -543,11 +584,11 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( $new )
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__cms_added_record', array( $current->mapped('title') => FALSE, $current->database()->_title => TRUE ) );
|
||||
Session::i()->log( 'acplogs__cms_added_record', array( $current->mapped('title') => FALSE, $current->database()->_title => TRUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Session::i()->modLog( 'acplogs__cms_edited_record', array( $current->mapped('title') => FALSE, $current->database()->_title => TRUE ) );
|
||||
Session::i()->modLog( 'acplogs__cms_edited_record', array( $current->mapped('title') => FALSE, $current->database()->_title => TRUE ) );
|
||||
}
|
||||
|
||||
if ( $changeAuthor )
|
||||
@@ -556,20 +597,17 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$current->changeAuthor( $values['record_member_id'] );
|
||||
}
|
||||
catch( \LogicException $ex )
|
||||
catch( LogicException $ex )
|
||||
{
|
||||
/* If the database isn't attached to a page, a call to url() when logging an author change throws this */
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'saved' );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=databases&controller=records&database_id=' . Request::i()->database_id ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $current ? $title : 'add', $form, FALSE );
|
||||
\IPS\Output::i()->title = $title;
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->block( $current ? $title : 'add', $form, FALSE );
|
||||
Output::i()->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -577,19 +615,20 @@ class _records extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function categoryTree()
|
||||
public function categoryTree() : void
|
||||
{
|
||||
$class = '\IPS\cms\Categories' . \IPS\Request::i()->database_id;
|
||||
/* @var CategoriesClass $class */
|
||||
$class = '\IPS\cms\Categories' . Request::i()->database_id;
|
||||
try
|
||||
{
|
||||
$category = $class::load( \IPS\Request::i()->id );
|
||||
$category = $class::load( Request::i()->id );
|
||||
$parents = iterator_to_array( $category->parents() );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( \IPS\Member::loggedIn()->language()->addToStack('content_tree_title'), \IPS\Theme::i()->getTemplate( 'records', 'cms', 'admin' )->categoryTree( $category, $parents ), FALSE );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_tree_title');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->block( Member::loggedIn()->language()->addToStack('content_tree_title'), Theme::i()->getTemplate( 'records', 'cms', 'admin' )->categoryTree( $category, $parents ), FALSE );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('content_tree_title');
|
||||
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user