Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,73 @@
<?php
/**
* @brief Fields Model
* @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 8 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* categories
*/
class _categories extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Categories';
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
/* Assign the correct nodeClass so contentItem is specified */
$this->nodeClass = '\IPS\cms\Categories' . \IPS\Request::i()->database_id;
\IPS\Dispatcher::i()->checkAcpPermission( 'categories_manage' );
$nodeClass = $this->nodeClass;
$childLang = \IPS\Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle . '_add_child' );
$nodeClass::$nodeTitle = \IPS\Member::loggedIn()->language()->addToStack('content_cat_db_title', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( \IPS\Request::i()->database_id)->_title ) ) );
\IPS\Member::loggedIn()->language()->words[ $nodeClass::$nodeTitle . '_add_child' ] = $childLang;
parent::execute();
}
/**
* Get Root Rows
*
* @return array
*/
public function _getRoots()
{
$nodeClass = $this->nodeClass;
$rows = array();
foreach( $nodeClass::roots( NULL ) as $node )
{
if ( $node->database_id == \IPS\Request::i()->database_id )
{
$rows[ $node->_id ] = $this->_getRow( $node );
}
}
return $rows;
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,296 @@
<?php
/**
* @brief Fields Model
* @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 31 March 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* fields
*/
class _fields extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Fields';
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
$this->nodeClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
\IPS\Dispatcher::i()->checkAcpPermission( 'fields_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
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;
/* 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(
$url,
\IPS\Member::loggedIn()->language()->addToStack('content_fields_fixed_title'),
function() use ( $fixed, $url )
{
$rows = array();
foreach( $fixed as $field => $data )
{
$rows[ $field ] = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $field, \IPS\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 ) )
)
), NULL, NULL, NULL, NULL, ( empty( $data['visible'] ) ? FALSE : TRUE ) );
}
return $rows;
},
function( $key, $root=FALSE ) use ( $fixed, $url ) {},
function() { return 0; },
function() { return array(); },
function() { return array(); },
FALSE,
TRUE,
TRUE
);
\IPS\Output::i()->output .= \IPS\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 ) ) );
}
/**
* Get Root Rows
*
* @return array
*/
public function _getRoots()
{
$nodeClass = $this->nodeClass;
$rows = array();
foreach( $nodeClass::roots( NULL ) as $node )
{
if ( $node->database_id == \IPS\Request::i()->database_id )
{
$rows[ $node->_id ] = $this->_getRow( $node );
}
}
return $rows;
}
/**
* Fixed field permissions
*
* @return void
*/
public function enableToggle()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$class::setFixedFieldVisibility( \IPS\Request::i()->id, (boolean) \IPS\Request::i()->status );
/* Redirect */
if ( \IPS\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 ) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
}
/**
* Set this field as the record title
*
* @return void
*/
public function setAsTitle()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
try
{
$field = $class::load( \IPS\Request::i()->id );
if ( $field->canBeTitleField() )
{
$database->field_title = $field->id;
$database->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/1', 403, '' );
}
}
/**
* Set this field as the record content
*
* @return void
*/
public function setAsContent()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
try
{
$field = $class::load( \IPS\Request::i()->id );
if ( $field->canBeContentField() )
{
$database->field_content = $field->id;
$database->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/2', 403, '' );
}
}
/**
* Fixed field permissions
*
* @return void
*/
public function fixedPermissions()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$perms = $class::fixedFieldPermissions( \IPS\Request::i()->field );
$permMap = array( 'view' => 'view', 'edit' => 2, 'add' => 3 );
foreach( $permMap as $k => $v )
{
if ( ! isset( $perms[ 'perm_' . $v ] ) )
{
$perms[ 'perm_' . $v ] = NULL;
}
}
/* Build Matrix */
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->manageable = FALSE;
$matrix->langPrefix = 'content_perm_fixed_fields__';
$matrix->columns = array(
'label' => function( $key, $value, $data )
{
return $value;
},
);
foreach ( $permMap as $k => $v )
{
$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}" ] ) ) ) );
};
$matrix->checkAlls[ $k ] = ( $perms[ "perm_{$v}" ] === '*' );
}
$matrix->checkAllRows = TRUE;
$rows = array();
foreach ( \IPS\Member\Group::groups() as $group )
{
$rows[ $group->g_id ] = array(
'label' => $group->name,
'view' => TRUE,
);
}
$matrix->rows = $rows;
/* Handle submissions */
if ( $values = $matrix->values() )
{
$_perms = array();
$save = array();
/* Check for "all" checkboxes */
foreach ( $permMap as $k => $v )
{
if ( isset( \IPS\Request::i()->__all[ $k ] ) )
{
$_perms[ $v ] = '*';
}
else
{
$_perms[ $v ] = array();
}
}
/* Loop groups */
foreach ( $values as $group => $perms )
{
foreach ( $permMap as $k => $v )
{
if ( isset( $perms[ $k ] ) and $perms[ $k ] and is_array( $_perms[ $v ] ) )
{
$_perms[ $v ][] = $group;
}
}
}
/* Finalise */
foreach ( $_perms as $k => $v )
{
$save[ "perm_{$k}" ] = is_array( $v ) ? implode( $v, ',' ) : $v;
}
$class::setFixedFieldPermissions( \IPS\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' );
}
/* Display */
\IPS\Output::i()->output .= $matrix;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_database_manage_fields');
}
}
Whitespace-only changes.
@@ -0,0 +1,489 @@
<?php
/**
* @brief Records Model
* @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 8 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* records
*/
class _records extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
\IPS\Dispatcher::i()->checkAcpPermission( 'records_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
$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 ) ) );
/* 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->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 ) );
/* Only specify these if we are not re-ordering via the table headers, which are set in the Table contructor */
if ( ! $table->sortBy )
{
$table->sortBy = $database->field_sort ? $database->field_sort : 'record_last_comment';
}
if ( ! $table->sortDirection )
{
$table->sortDirection = $database->field_direction ? $database->field_direction : 'desc';
}
$table->filters = array(
'content_db_table_filter_approved' => array('record_approved=?', 1 ),
'content_db_table_filter_unapproved' => array('record_approved=?', 0 ),
'content_db_table_filter_hidden' => array('record_approved=?', -1 ),
'content_db_table_filter_pinned' => array('record_pinned=?' , 1 )
);
if ( $database->use_categories )
{
$table->include = array(
'primary_id_field',
'field_' . $database->field_title,
'record_publish_date',
'category_id'
);
}
else
{
$table->include = array(
'primary_id_field',
'field_' . $database->field_title,
'record_publish_date'
);
}
/* Add title header */
\IPS\Member::loggedIn()->language()->words['content_db_table_field_' . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack( 'content_db_table_title' );
$table->advancedSearch = array(
'category_id' => array( \IPS\Helpers\Table\SEARCH_NODE, array(
'class' => '\IPS\cms\Categories',
'disabled' => false,
'zeroVal' => 'content_db_table_as_no_cat',
'permissionCheck' => function( $node )
{
return $node->database_id == \IPS\Request::i()->database_id;
}
),
),
'record_comments'=> array( \IPS\Helpers\Table\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'
)
) ),
);
/* Buttons */
if ( $database->use_categories )
{
$table->rootButtons = array(
'add' => array(
'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' ) )
),
);
}
else
{
$table->rootButtons = array(
'add' => array(
'title' => 'add',
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . \IPS\Request::i()->database_id )
),
);
}
/* Buttons */
$table->rowButtons = function( $row )
{
return array(
'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' ),
'data' => array()
),
'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' ) )
),
'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' ),
'data' => array( 'delete' => '' )
),
);
};
$table->parsers = array(
'field_' . $database->field_title => function( $val, $row ) use ($database)
{
$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 );
},
'category_id' => function( $val ) use ($database)
{
if ( $val )
{
try
{
$class = '\IPS\cms\Categories' . $database->id;
return $class::load( $val )->_title;
}
catch( \OutOfRangeException $e )
{
return '';
}
}
return '';
},
'record_publish_date' => function( $val, $row )
{
$val = ( ! empty( $val ) ) ? $val : $row['record_saved'];
return \IPS\DateTime::ts( $val )->localeDate();
}
);
/* Add a button for managing DB settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_edit' ) )
{
\IPS\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 ),
'data' => NULL
);
}
/* Reset languages */
\IPS\Member::loggedIn()->language()->words[ $table->langPrefix . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack($table->langPrefix . 'title');
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $title, (string) $table );
\IPS\Output::i()->title = $title;
}
/**
* Delete
*
* @return void
*/
public function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'records_delete' );
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
try
{
$recordClass::load( \IPS\Request::i()->id )->delete();
}
catch( \OutofRangeException $ex )
{
\IPS\Output::i()->error( 'no_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' );
}
/**
* Show the pre add record form. This is used when no category is set.
*
* @return void
*/
protected function select()
{
$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;
$category = NULL;
$record = NULL;
if ( $move )
{
try
{
$record = $recordClass::load( $move );
$category = $catClass::load( $record->category_id );
}
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 : '' ),
'class' => $catClass,
'multiple' => false,
'permissionCheck' => function( $node )
{
if ( $node->can( 'view' ) )
{
if ( $node->can( 'add' ) )
{
return TRUE;
}
return FALSE;
}
return NULL;
},
) ) );
if ( $values = $form->values() )
{
if ( $move and $record )
{
$record->category_id = $values['category']->id;
$record->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\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 ) );
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'database_select_category' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'records' )->categorySelector( $form );
}
/**
* Add/Edit
*
* @return void
*/
public function form()
{
$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 ) ) );
$current = NULL;
$customValues = array();
$class = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
if ( \IPS\Request::i()->id )
{
$current = $class::load( \IPS\Request::i()->id );
$customValues = $current->fieldValues();
}
$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 );
$customFields = $fieldsClass::fields( $customValues, 'view', $container );
$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->addtab( 'content_database_record_tab_content' );
$formElements = $class::formElements( $current, $container );
foreach( $formElements as $name => $field )
{
if ( in_array( $name, $manuallyHandledFields ) )
{
continue;
}
$form->add( $field );
}
/* Now custom fields */
foreach( $customFields as $id => $obj )
{
if ( $database->field_title === 'field_' . $obj->_id )
{
continue;
}
$form->add( $obj );
}
$form->addtab( 'content_database_record_tab_publish' );
if ( isset( $formElements['record_publish_date'] ) )
{
$form->add( $formElements['record_publish_date'] );
}
if ( isset( $formElements['record_expiry_date'] ) )
{
$form->add( $formElements['record_expiry_date'] );
}
$form->add( new \IPS\Helpers\Form\Radio( 'record_author_choice', $current ? ( $current->member_id === \IPS\Member::loggedIn()->member_id ? 'me' : 'notme' ) : 'me', FALSE, array(
'options' => array(
'me' => 'record_author_choice_me',
'notme' => 'record_author_choice_notme'
),
'toggles' => array(
'notme' => array( 'record_member_id' )
)
), NULL, NULL, NULL, 'record_author_choice' ) );
$form->add( new \IPS\Helpers\Form\Member( 'record_member_id', ( $current ? \IPS\Member::load( $current->member_id ) : NULL ), FALSE, array(), NULL, NULL, NULL, 'record_member_id' ) );
if ( isset( $formElements['record_allow_comments'] ) )
{
$form->addHeader( 'content_database_record_tab_comments' );
$form->add( $formElements['record_allow_comments'] );
if ( isset( $formElements['record_comment_cutoff'] ) )
{
$form->add( $formElements['record_comment_cutoff'] );
}
}
if ( \IPS\Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
{
$form->addtab( 'content_database_record_tab_meta' );
$form->add( $formElements['record_meta_keywords'] );
$form->add( $formElements['record_meta_description'] );
}
if ( $values = $form->values() )
{
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
$fieldClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$new = false;
if ( empty( $current ) )
{
$new = true;
$category = NULL;
if ( ! $database->use_categories )
{
$catClass = 'IPS\cms\Categories' . $database->id;
$category = $catClass::load( $database->get__default_category() );
}
else
{
if ( isset( \IPS\Request::i()->category_id ) )
{
$category = $catClass::load( \IPS\Request::i()->category_id );
}
}
$current = $recordClass::createFromForm( $values, $category );
/* Claim attachments */
foreach( $fieldClass::data() as $key => $field )
{
if ( ucfirst( $field->type ) === 'Editor' )
{
\IPS\File::claimAttachments( 'RecordField_'. $field->id , $current->id, NULL, 'RecordField_'. $field->id, FALSE );
}
}
}
/* Other data */
$current->record_meta_keywords = $values['record_meta_keywords'];
$current->record_meta_description = $values['record_meta_description'];
$changeAuthor = FALSE;
if ( ! empty( \IPS\Request::i()->id ) and $values['record_author_choice'] === 'notme' and ! empty( $values['record_member_id'] ) )
{
$changeAuthor = TRUE;
}
/* Just editing, thanks */
if ( ! $new )
{
$current->processForm( $values );
$current->processAfterEdit( $values );
if ( isset( $recordClass::$databaseColumnMap['date'] ) and isset( $values[ $recordClass::$formLangPrefix . 'date' ] ) )
{
$column = $recordClass::$databaseColumnMap['date'];
if ( $values[ $recordClass::$formLangPrefix . 'date' ] instanceof \IPS\DateTime )
{
$current->$column = $values[ $recordClass::$formLangPrefix . 'date' ]->getTimestamp();
}
else
{
$current->$column = time();
}
}
}
$current->save();
if ( $changeAuthor )
{
try
{
$current->changeAuthor( $values['record_member_id'] );
}
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' );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $current ? $title : 'add', $form, FALSE );
\IPS\Output::i()->title = $title;
}
}