Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

+366 -99
View File
@@ -167,6 +167,16 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
*/
const FIELD_DISPLAY_FILTERS = 16;
/**
* @brief Fields that cannot be title fields
*/
public static $cannotBeTitleFields = array( 'Editor', 'CheckboxSet', 'YesNo', 'Radio' );
/**
* @brief Fields that cannot be title fields
*/
public static $cannotBeContentFields = array();
/**
* Load Record
*
@@ -198,7 +208,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
*/
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
{
$permissionCheck = ( \IPS\Dispatcher::i()->controllerLocation === 'admin' ) ? NULL : $permissionCheck;
$permissionCheck = ( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation === 'admin' ) ? NULL : $permissionCheck;
if ( ! isset( static::$cache[ static::$customDatabaseId ][ $permissionCheck ] ) )
{
@@ -209,7 +219,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
foreach( static::$cache[ static::$customDatabaseId ][ $permissionCheck ] as $id => $obj )
{
if ( ! in_array( $obj->type, static::$additionalFieldTypes ) AND ( ! class_exists( '\IPS\Helpers\Form\\' . ucfirst( $obj->type ) ) AND ! class_exists( '\IPS\cms\Fields\\' . ucfirst( $obj->type ) ) ) )
if ( ! array_key_exists( $obj->type, static::$additionalFieldTypes ) AND ( ! class_exists( '\IPS\Helpers\Form\\' . ucfirst( $obj->type ) ) AND ! class_exists( '\IPS\cms\Fields\\' . ucfirst( $obj->type ) ) ) )
{
unset( static::$cache[ static::$customDatabaseId ][ $permissionCheck ][ $id ] );
continue;
@@ -229,6 +239,23 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
return static::$cache[ static::$customDatabaseId ][ $permissionCheck ];
}
/**
* Just return all field IDs in a database without permission checking
*
* @return array
*/
public static function databaseFieldIds()
{
$key = 'cms_fieldids_' . static::$customDatabaseId;
if ( ! isset( \IPS\Data\Store::i()->$key ) )
{
\IPS\Data\Store::i()->$key = iterator_to_array( \IPS\Db::i()->select( 'field_id', 'cms_database_fields', array( array( 'field_database_id=?', static::$customDatabaseId ) ) )->setKeyField('field_id') );
}
return \IPS\Data\Store::i()->$key;
}
/**
* Get Field Data
*
@@ -432,26 +459,53 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
if ( $display === 'listing' )
{
if ( $display === 'listing' and ! $row->display_listing )
if ( ! $row->display_listing )
{
continue;
}
$value = $row->truncate( $value, TRUE );
if ( $value or $value === "0" )
if ( $value )
{
$value = $row->formatForDisplay( $value, $formValue, 'listing', $record );
}
}
else if ( $display === 'display' )
else if ( $display === 'display' or $display === 'display_top' or $display === 'display_bottom' )
{
if ( $display === 'display' and ! $row->display_display )
if ( ! $row->display_display )
{
continue;
}
if ( $value or $value === "0" )
$displayData = $row->display_json;
if ( $display === 'display_bottom' )
{
if ( isset( $displayData['display']['where'] ) )
{
if ( $displayData['display']['where'] !== 'bottom' )
{
continue;
}
}
else
{
continue;
}
}
else if ( $display === 'display_top' )
{
if ( isset( $displayData['display']['where'] ) )
{
if ( $displayData['display']['where'] !== 'top' )
{
continue;
}
}
}
if ( $value )
{
$value = $row->formatForDisplay( $value, $formValue, 'display', $record );
}
@@ -488,7 +542,34 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
return (string) \IPS\File::get( static::$uploadStorageExtension, $value )->url;
}
if ( $this->type === 'Item' )
{
if ( ! is_array( $formValue ) and mbs_trstr( $formValue, ',' ) )
{
$value = explode( ',', $formValue );
}
else
{
$value = array( $formValue );
}
if ( count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
{
$results = array();
$class = '\IPS\cms\Records' . $this->extra['database'];
$field = $class::$databasePrefix . $class::$databaseColumnMap['title'];
$where = array( \IPS\Db::i()->in( $class::$databaseColumnId, $value ) );
foreach ( $class::getItemsWithPermission( array( $where ), $field, NULL ) as $item )
{
$results[ $item->_id ] = $item;
}
return $results;
}
}
return $formValue;
}
else if ( $type === 'processed' )
@@ -498,7 +579,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
$options = $this->display_json;
if ( isset( $options[ $type ]['method'] ) )
if ( isset( $options[ $type ]['method'] ) AND $options[ $type ]['method'] !== 'simple' )
{
if ( in_array( $this->type, static::$mediaFields ) )
{
@@ -1044,7 +1125,18 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
public function displayValue( $value=NULL )
{
$database = \IPS\cms\Databases::load( static::$customDatabaseId );
if ( class_exists( '\IPS\cms\Fields\\' . ucfirst( $this->type ) ) )
{
/* Is special! */
$class = '\IPS\cms\Fields\\' . ucfirst( $this->type );
if ( method_exists( $class, 'displayValue' ) )
{
return $class::displayValue( $value, $this );
}
}
switch( ucfirst( $this->type ) )
{
case 'Upload':
@@ -1052,7 +1144,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
break;
case 'Text':
case 'TextArea':
$this->applyFormatter( $value );
$value = $this->applyFormatter( $value );
/* We don't want the parent adding wordbreak to the title */
if ( $this->id == $database->field_title OR $this->id == $database->field_content )
@@ -1084,14 +1176,14 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
$return = array();
foreach( $value as $key )
{
$return[] = isset( $this->extra[ $key ] ) ? htmlentities( $this->extra[ $key ], \IPS\HTMLENTITIES, 'UTF-8', FALSE ) : htmlentities( $key, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
$return[] = isset( $this->extra[ $key ] ) ? htmlspecialchars( $this->extra[ $key ], \IPS\HTMLENTITIES, 'UTF-8', FALSE ) : htmlspecialchars( $key, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
}
return implode( ', ', $return );
}
else
{
return ( isset( $this->extra[ $value ] ) ? htmlentities( $this->extra[ $value ], \IPS\HTMLENTITIES, 'UTF-8', FALSE ) : htmlentities( $value, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) );
return ( isset( $this->extra[ $value ] ) ? htmlspecialchars( $this->extra[ $value ], \IPS\HTMLENTITIES, 'UTF-8', FALSE ) : htmlspecialchars( $value, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) );
}
break;
case 'Member':
@@ -1099,6 +1191,13 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
return NULL;
}
else
{
return implode( ', ', array_map( function( $id )
{
return \IPS\Member::load( $id )->link();
}, explode( ',', $value ) ) );
}
break;
case 'Url':
if ( \IPS\Dispatcher::hasInstance() AND class_exists( '\IPS\Dispatcher', FALSE ) and \IPS\Dispatcher::i()->controllerLocation === 'front' )
@@ -1121,6 +1220,33 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
return \IPS\Lang::wordbreak( $time->localeDate() );
break;
case 'Item':
if ( ! is_array( $value ) and mb_strstr( $value, ',' ) )
{
$value = explode( ',', $value );
}
else
{
$value = array( $value );
}
if ( count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
{
$results = array();
$class = '\IPS\cms\Records' . $this->extra['database'];
$field = $class::$databasePrefix . $class::$databaseColumnMap['title'];
$where = array( \IPS\Db::i()->in( $class::$databaseColumnId, $value ) );
foreach( $class::getItemsWithPermission( array( $where ), $field, NULL ) as $item )
{
$results[] = $item;
}
return \IPS\Theme::i()->getTemplate( 'global', 'cms', 'front' )->basicRelationship( $results );
}
return NULL;
break;
}
/* Formatters */
@@ -1142,40 +1268,46 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
*/
public function applyFormatter( $value )
{
switch( $this->format_opts )
if ( is_array( $this->format_opts ) and count( $this->format_opts ) )
{
case 'strtolower':
$value = mb_convert_case( $value, MB_CASE_LOWER );
break;
case 'strtoupper':
$value = mb_convert_case( $value, MB_CASE_UPPER );
break;
case 'ucfirst':
$value = ( mb_strtoupper( mb_substr( $value, 0, 1 ) ) . mb_substr( $value, 1, mb_strlen( $value ) ) );
break;
case 'ucwords':
$value = mb_convert_case( $value, MB_CASE_TITLE );
break;
case 'punct':
$value = preg_replace( "/\?{1,}/" , "?" , $value );
$value = preg_replace( "/(!){1,}/" , "!" , $value );
break;
case 'numerical':
$value = \IPS\Member::loggedIn()->language()->formatNumber( $value );
break;
case 'bold':
$value = '<strong>' . $value . '</strong>';
break;
case 'italic':
$value = '<em>' . $value . '</em>';
break;
foreach( $this->format_opts as $id => $type )
{
switch( $type )
{
case 'strtolower':
$value = mb_convert_case( $value, MB_CASE_LOWER );
break;
case 'strtoupper':
$value = mb_convert_case( $value, MB_CASE_UPPER );
break;
case 'ucfirst':
$value = ( mb_strtoupper( mb_substr( $value, 0, 1 ) ) . mb_substr( $value, 1, mb_strlen( $value ) ) );
break;
case 'ucwords':
$value = mb_convert_case( $value, MB_CASE_TITLE );
break;
case 'punct':
$value = preg_replace( "/\?{1,}/" , "?" , $value );
$value = preg_replace( "/(&#33;){1,}/" , "&#33;" , $value );
break;
case 'numerical':
$value = \IPS\Member::loggedIn()->language()->formatNumber( $value );
break;
case 'bold':
$value = '<strong>' . $value . '</strong>';
break;
case 'italic':
$value = '<em>' . $value . '</em>';
break;
}
}
}
return $value;
@@ -1242,9 +1374,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
*/
public function canBeTitleField()
{
$no = array( 'Address' );
if ( $this->is_multiple or in_array( ucfirst( $this->type ), $no ) )
if ( $this->is_multiple or in_array( ucfirst( $this->type ), static::$cannotBeTitleFields ) )
{
return FALSE;
}
@@ -1261,7 +1391,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
$no = array();
if ( $this->is_multiple or in_array( ucfirst( $this->type ), $no ) )
if ( $this->is_multiple or in_array( ucfirst( $this->type ), static::$cannotBeContentFields ) )
{
return FALSE;
}
@@ -1331,30 +1461,31 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
$form->add( new \IPS\Helpers\Form\Translatable( 'field_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? static::$langKey . '_' . $this->id : NULL ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'field_description', NULL, FALSE, array( 'app' => 'core', 'key' => ( $this->id ? static::$langKey . '_' . $this->id . '_desc' : NULL ) ) ) );
$displayDefaults = array( 'field_display_listing_json_badge', 'field_display_listing_json_badge_right', 'field_display_listing_json_custom', 'field_display_display_json_badge', 'field_display_display_json_custom' );
$displayDefaults = array( 'field_display_listing_json_badge', 'field_display_listing_json_badge_right', 'field_display_listing_json_custom', 'field_display_display_json_badge', 'field_display_display_json_custom', 'field_display_display_json_where' );
$options = array_merge( array(
'Address' => 'pf_type_Address',
'Checkbox' => 'pf_type_Checkbox',
'Address' => 'pf_type_Address',
'Checkbox' => 'pf_type_Checkbox',
'CheckboxSet' => 'pf_type_CheckboxSet',
'Codemirror'=> 'pf_type_Codemirror',
'Date' => 'pf_type_Date',
'Editor' => 'pf_type_Editor',
'Email' => 'pf_type_Email',
'Member' => 'pf_type_Member',
'Number' => 'pf_type_Number',
'Password' => 'pf_type_Password',
'Radio' => 'pf_type_Radio',
'Select' => 'pf_type_Select',
'Tel' => 'pf_type_Tel',
'Text' => 'pf_type_Text',
'TextArea' => 'pf_type_TextArea',
'Upload' => 'pf_type_Upload',
'Url' => 'pf_type_Url',
'YesNo' => 'pf_type_YesNo',
'Youtube' => 'pf_type_Youtube',
'Spotify' => 'pf_type_Spotify',
'Soundcloud'=> 'pf_type_Soundcloud',
'Codemirror' => 'pf_type_Codemirror',
'Item' => 'pf_type_Relational',
'Date' => 'pf_type_Date',
'Editor' => 'pf_type_Editor',
'Email' => 'pf_type_Email',
'Member' => 'pf_type_Member',
'Number' => 'pf_type_Number',
'Password' => 'pf_type_Password',
'Radio' => 'pf_type_Radio',
'Select' => 'pf_type_Select',
'Tel' => 'pf_type_Tel',
'Text' => 'pf_type_Text',
'TextArea' => 'pf_type_TextArea',
'Upload' => 'pf_type_Upload',
'Url' => 'pf_type_Url',
'YesNo' => 'pf_type_YesNo',
'Youtube' => 'pf_type_Youtube',
'Spotify' => 'pf_type_Spotify',
'Soundcloud' => 'pf_type_Soundcloud',
), static::$additionalFieldTypes );
$toggles = array(
@@ -1365,6 +1496,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
'Date' => array_merge( array( 'field_default_value', 'field_date_time_override' ), $displayDefaults ),
'Editor' => array_merge( array( 'field_max_length', 'field_default_value', 'field_truncate' ), $displayDefaults ),
'Email' => array_merge( array( 'field_max_length', 'field_default_value' ), $displayDefaults ),
'Item' => array_merge( array( 'field_is_multiple', 'field_relational_db' ), $displayDefaults ),
'Member' => array_merge( array( 'field_is_multiple' ), $displayDefaults ),
'Number' => array_merge( array( 'field_default_value' ), $displayDefaults ),
'Password' => array_merge( array( 'field_default_value' ), $displayDefaults ),
@@ -1385,7 +1517,30 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
$toggles[ $k ] = isset( static::$additionalFieldToggles[ $k ] ) ? static::$additionalFieldToggles[ $k ] : array( 'pf_not_null' );
}
/* Title or content? */
if ( $this->id )
{
$database = \IPS\cms\Databases::load( static::$customDatabaseId );
if ( $this->id == $database->field_title )
{
foreach( static::$cannotBeTitleFields as $type )
{
unset( $options[ $type ] );
unset( $toggles[ $type ] );
}
}
else if ( $this->id == $database->field_content )
{
foreach( static::$cannotBeContentFields as $type )
{
unset( $options[ $type ] );
unset( $toggles[ $type ] );
}
}
}
ksort( $options );
if ( !$this->_new )
@@ -1406,6 +1561,26 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
'toggles' => $toggles
) ) );
/* Relational specific */
$databases = array();
$disabled = array();
foreach( \IPS\cms\Databases::databases() as $db )
{
if ( $db->page_id and $db->id !== static::$customDatabaseId )
{
$databases[ $db->id ] = $db->_title;
}
}
if ( ! count( $databases ) )
{
$databases[0] = \IPS\Member::loggedIn()->language()->addToStack('cms_relational_field_no_dbs');
$disabled[] = 0;
}
$form->add( new \IPS\Helpers\Form\Select( 'field_relational_db', ( isset( $this->extra['database'] ) ? $this->extra['database'] : NULL ), FALSE, array( 'options' => $databases, 'disabled' => $disabled ), NULL, NULL, NULL, 'field_relational_db' ) );
/* Upload specific */
$form->add( new \IPS\Helpers\Form\YesNo( 'field_upload_is_multiple', $this->id ? $this->is_multiple : 0, FALSE, array( ), NULL, NULL, NULL, 'field_upload_is_multiple' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'field_upload_is_image', $this->id ? ( ( isset( $this->extra['type'] ) and $this->extra['type'] == 'image' ) ? 'yes' : 'no' ) : 'yes', TRUE, array(
@@ -1592,6 +1767,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
$listingToggles[ $id ] = array( 'field_display_listing_json_badge_right' );
}
$displayOptions['simple'] = $listingOptions['simple'] = \IPS\Theme::i()->getTemplate( 'records', 'cms', 'global' )->fieldDefault( \IPS\Member::loggedIn()->language()->addToStack('cms_badge_label'), \IPS\Member::loggedIn()->language()->addToStack('cms_badge_value' ) );
$displayOptions['custom'] = $listingOptions['custom'] = \IPS\Member::loggedIn()->language()->addToStack('field_display_custom');
$displayOptions['none'] = $listingOptions['none'] = \IPS\Member::loggedIn()->language()->addToStack('field_display_none');
@@ -1659,6 +1835,9 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
}, NULL, NULL, 'field_display_display_json_custom' ) );
/* Display where? */
$form->add( new \IPS\Helpers\Form\Radio( 'field_display_display_json_where', ( isset( $displayJson['display']['where'] ) ? $displayJson['display']['where'] : 'top' ), FALSE, array( 'options' => array( 'top' => 'cms_field_display_top', 'bottom' => 'cms_field_display_bottom' ) ), NULL, NULL, NULL, 'field_display_display_json_where' ) );
/* Media display */
$form->add( new \IPS\Helpers\Form\Radio( 'media_display_display_method', $mediaDisplayDefault, FALSE, array( 'options' => $mediaListingOptions ), NULL, NULL, NULL, 'media_display_display_method' ) );
@@ -1723,7 +1902,6 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
$values['field_extra'] = $extra;
}
}
if ( $values['field_type'] === 'Select' )
{
$columnDefinition['type'] = 'TEXT';
@@ -1817,15 +1995,26 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
\IPS\Db::i()->addColumn( static::$contentDatabaseTable, $columnDefinition );
if ( $values['field_type'] != 'Upload' )
if ( ! empty( $values['field_filter'] ) and $values['field_type'] != 'Upload' )
{
if ( $columnDefinition['type'] == 'TEXT' )
try
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
if ( $columnDefinition['type'] == 'TEXT' )
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
else
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'key', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
}
else
catch( \IPS\Db\Exception $e )
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'key', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
if ( $e->getCode() !== 1069 )
{
# 1069: MyISAM can only have 64 indexes per table. This should be really rare though so we silently ignore it.
throw $e;
}
}
}
}
@@ -1837,28 +2026,60 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
\IPS\Db::i()->dropIndex( static::$contentDatabaseTable, "field_{$this->id}" );
\IPS\Db::i()->dropColumn( static::$contentDatabaseTable, "field_{$this->id}" );
}
catch ( \IPS\Db\Exception $e )
{
}
catch ( \IPS\Db\Exception $e ) { }
\IPS\Db::i()->addColumn( static::$contentDatabaseTable, $columnDefinition );
if ( $values['field_type'] != 'Upload' )
{
if ( $columnDefinition['type'] == 'TEXT' )
try
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
if ( $columnDefinition['type'] == 'TEXT' )
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
else
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'key', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
}
else
catch( \IPS\Db\Exception $e )
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'key', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
if ( $e->getCode() !== 1069 )
{
# 1069: MyISAM can only have 64 indexes per table. This should be really rare though so we silently ignore it.
throw $e;
}
}
}
}
elseif ( isset( static::$contentDatabaseTable ) AND isset( $columnDefinition ) )
{
\IPS\Db::i()->dropIndex( static::$contentDatabaseTable, "field_{$this->id}" );
\IPS\Db::i()->changeColumn( static::$contentDatabaseTable, "field_{$this->id}", $columnDefinition );
if ( $values['field_filter'] and $values['field_type'] != 'Upload' )
{
try
{
if ( $columnDefinition['type'] == 'TEXT' )
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
else
{
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'key', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
}
}
catch( \IPS\Db\Exception $e )
{
if ( $e->getCode() !== 1069 )
{
# 1069: MyISAM can only have 64 indexes per table. This should be really rare though so we silently ignore it.
throw $e;
}
}
}
}
/* Save the name and desctipn */
@@ -1998,6 +2219,11 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
$displayJson['display']['method'] = $values['field_display_display_json_badge'];
}
if ( isset( $values['field_display_display_json_where'] ) )
{
$displayJson['display']['where'] = $values['field_display_display_json_where'];
}
}
}
@@ -2041,13 +2267,24 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
}
}
/* Special relational stuff */
if ( isset( $values['field_type'] ) AND $values['field_type'] === 'Item' )
{
if ( array_key_exists( 'field_relational_db', $values ) and empty( $values['field_relational_db'] ) )
{
throw new \LogicException( \IPS\Member::loggedIn()->language()->addToStack('cms_relational_field_no_db_selected') );
}
$values['extra'] = array( 'database' => $values['field_relational_db'] );
}
if ( ! $this->new AND isset( $values['field_default_update_existing'] ) AND $values['field_default_update_existing'] and $values['field_default_value'] !== $this->default_value )
{
$this->_updateDefaultValue = TRUE;
$this->_oldDefaultValue = $this->default_value;
}
foreach( array( 'field_upload_is_multiple', 'field_default_update_existing', 'field_date_time_override', 'field_date_timezone', 'field_upload_is_image', 'field_image_size', 'field_title', 'field_display_display_json_badge', 'field_display_display_json_custom', 'field_display_listing_json_badge', 'field_display_listing_json_custom', 'field_display_listing_json_badge_right', 'media_display_listing_method', 'media_display_display_method', 'field_show_map_listing', 'field_show_map_listing_dims', 'field_show_map_display', 'field_show_map_display_dims' ) as $field )
foreach( array( 'field_relational_db', 'field_upload_is_multiple', 'field_default_update_existing', 'field_date_time_override', 'field_date_timezone', 'field_upload_is_image', 'field_image_size', 'field_title', 'field_display_display_json_badge', 'field_display_display_json_custom', 'field_display_listing_json_badge', 'field_display_listing_json_custom', 'field_display_listing_json_badge_right', 'media_display_listing_method', 'media_display_display_method', 'field_show_map_listing', 'field_show_map_listing_dims', 'field_show_map_display', 'field_show_map_display_dims', 'field_display_display_json_where' ) as $field )
{
if ( array_key_exists( $field, $values ) )
{
@@ -2086,7 +2323,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
*/
protected function canKeepValueOnChange( $newType )
{
$custom = array( 'Youtube', 'Spotify', 'Soundcloud');
$custom = array( 'Youtube', 'Spotify', 'Soundcloud', 'Relational' );
if ( ! in_array( $this->type, $custom ) )
{
@@ -2131,15 +2368,15 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
unset( \IPS\Data\Store::i()->$functionName );
}
$key = 'cms_fieldids_' . static::$customDatabaseId;
if ( isset( \IPS\Data\Store::i()->$key ) )
{
unset( \IPS\Data\Store::i()->$key );
}
if ( $this->_new )
{
parent::save();
}
else
{
parent::save();
}
parent::save();
}
/**
@@ -2152,7 +2389,14 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
{
static::$contentDatabaseTable = 'cms_custom_database_' . static::$customDatabaseId;
static::$cache = array();
$key = 'cms_fieldids_' . static::$customDatabaseId;
if ( isset( \IPS\Data\Store::i()->$key ) )
{
unset( \IPS\Data\Store::i()->$key );
}
parent::delete();
if( $skipDrop === TRUE )
@@ -2302,9 +2546,28 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
if ( $this->is_multiple and ! is_array( $value ) and mb_stristr( $value, ',' ) )
{
$value = explode( ',', $value );
$exp = explode( ',', $value );
$value = array();
foreach( $exp as $val )
{
if ( is_numeric( $val ) and intval( $val ) == $val )
{
$value[] = intval( $val );
}
else
{
$value[] = $val;
}
}
}
else
{
if ( is_numeric( $value ) and intval( $value ) == $value )
{
$value = intval( $value );
}
}
$json = $this->extra;
$options['options'] = ( $json ) ? $json : array();
break;
@@ -2356,6 +2619,10 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
}
}
break;
case 'Item':
$options['maxItems'] = ( $this->is_multiple ) ? NULL : 1;
$options['class'] = '\IPS\cms\Records' . $this->extra['database'];
break;
}