Version 5.0.14

This commit is contained in:
Neo committed 2025-12-19 19:17:57 -08:00
1 parent 5efe744c5f
commit dbd774b30c
364 files changed
+7048 -1377

No files matched your search

@@ -2077,175 +2077,6 @@ class Categories extends Model implements Permissions
Index::i()->massUpdate( 'IPS\cms\Records\Comment' . static::database()->_id, $this->_id, NULL, $permissions, NULL, NULL, NULL, NULL, NULL, TRUE );
}
}
/**
* Get the filter cookie for this category
*
* @return array|null
*/
public function getFilterCookie(): ?array
{
if ( isset( Request::i()->cookie['cms_filters'] ) )
{
$saved = json_decode( Request::i()->cookie['cms_filters'], TRUE );
if ( array_key_exists( $this->id, $saved ) and count( $saved[ $this->id ] ) )
{
return $saved[ $this->id ];
}
}
return NULL;
}
/**
* Save filter cookie for this category
*
* @param array|bool $values Filter values to save (array) or FALSE to remove cookie
* @return void
*/
public function saveFilterCookie( array|bool $values ): void
{
$cookie = ( isset( Request::i()->cookie['cms_filters'] ) ) ? json_decode( Request::i()->cookie['cms_filters'], TRUE ) : array();
if ( $values === FALSE )
{
if ( array_key_exists( $this->id, $cookie ) )
{
unset( $cookie[ $this->id ] );
}
}
else
{
/* We only want to include ones where we have actually specified values to filter on */
$toSave = array();
foreach( $values AS $key => $data )
{
if ( is_numeric( $key ) or $key == 'cms_record_i_started' )
{
$toSave[$key] = $data;
}
}
$cookie[ $this->id ] = $toSave;
}
Request::i()->setCookie( 'cms_filters', json_encode( $cookie ), DateTime::create()->add( new DateInterval( 'P7D' ) ) );
}
/**
* Use the cookie to build filters
*
* @param array $cookie
* @return array
*/
public function buildWhereFromCookie( array $cookie ) : array
{
$where = [];
$database = static::database();
/** @var Fields $fieldClass */
$fieldClass = 'IPS\cms\Fields' . $database->id;
$customFields = $fieldClass::data( 'view', $this, $fieldClass::FIELD_SKIP_TITLE_CONTENT );
foreach( $cookie as $f => $v )
{
if ( $f == 'cms_record_i_started' and Member::loggedIn()->member_id )
{
$where[] = array( 'cms_custom_database_' . $database->id . '.member_id=' . Member::loggedIn()->member_id );
continue;
}
$k = 'content_field_' . $f;
if ( $customFields[ $f ]->type === 'Member' )
{
if ( ! empty( $v ) )
{
if ( is_array( $v ) )
{
foreach( $v as $m )
{
$member = Member::load( $m );
$where[] = [ "FIND_IN_SET( " . $member->member_id . ", REPLACE(field_" . $f . ", '\n',','))" ];
}
}
else
{
$member = Member::load( $v );
$where[] = [ "FIND_IN_SET( " . $member->member_id . ", REPLACE(field_" . $f . ", '\n',','))" ];
}
}
continue;
}
if ( isset( $customFields[ $f ] ) and $v !== '___any___' )
{
if ( is_array( $v ) )
{
if ( array_key_exists( 'start', $v ) or array_key_exists( 'end', $v ) )
{
$start = ( $v['start'] instanceof DateTime ) ? $v['start']->getTimestamp() : intval( $v['start'] );
$end = ( $v['end'] instanceof DateTime ) ? $v['end']->getTimestamp() : intval( $v['end'] );
if ( $start or $end )
{
$where[] = array( '( ' . mb_substr( $k, 8 ) . ' BETWEEN ' . $start . ' AND ' . $end . ' )' );
}
}
else
{
$like = array();
foreach( $v as $val )
{
if ( $val === 0 or ! empty( $val ) )
{
$like[] = $val;
}
}
if( $customFields[ $f ]->default_value and in_array( $customFields[ $f ]->default_value, $v ) )
{
$where[] = array( "( " . mb_substr( $k, 8 ) . " IS NULL OR " . Db::i()->findInSet( mb_substr( $k, 8 ), $like ) . ")" );
}
else
{
$where[] = array( Db::i()->findInSet( mb_substr( $k, 8 ), $like ) );
}
}
}
else
{
if ( is_bool( $v ) )
{
/* YesNo fields are false or true */
if ( $v === false )
{
$where[] = array( '(' . mb_substr( $k, 8 ) . ' IS NULL or ' . mb_substr( $k, 8 ) . '=0)' );
}
else
{
$where[] = array( mb_substr( $k, 8 ) . "=1" );
}
}
else
{
if ( $v !== 0 and ! $v )
{
$where[] = array( mb_substr( $k, 8 ) . " IS NULL" );
}
else
{
$where[] = array( mb_substr( $k, 8 ) . "=?", $v );
}
}
}
}
}
return $where;
}
/**
* [Node] Get meta description
@@ -13,12 +13,14 @@ namespace IPS\cms;
/* To prevent PHP errors (extending class does not exist) revealing path */
use DateInterval;
use Exception;
use IPS\Application;
use IPS\cms\Pages\Page;
use IPS\Content\Search\Index;
use IPS\Content\ViewUpdates;
use IPS\Data\Store;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\File;
@@ -32,6 +34,7 @@ use IPS\Node\Permissions;
use IPS\Patterns\ActiveRecord;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Platform\Bridge;
use IPS\Request;
use IPS\Settings;
use IPS\Task;
use IPS\Widget\Area;
@@ -1490,6 +1493,179 @@ class Databases extends Model implements Permissions
}
}
/**
* Get the filter cookie for this category/database
*
* @param Categories|null $category
* @return array|null
*/
public function getFilterCookie( ?Categories $category=null ): ?array
{
$key = $category ? $category->id : 'd' . $this->id;
if ( isset( Request::i()->cookie['cms_filters'] ) )
{
$saved = json_decode( Request::i()->cookie['cms_filters'], TRUE );
if ( array_key_exists( $key, $saved ) and count( $saved[ $key ] ) )
{
return $saved[ $key ];
}
}
return NULL;
}
/**
* Save filter cookie for this category
*
* @param array|bool $values Filter values to save (array) or FALSE to remove cookie
* @param Categories|null $category
* @return void
*/
public function saveFilterCookie( array|bool $values, ?Categories $category=null ): void
{
$key = $category ? $category->id : 'd' . $this->id;
$cookie = ( isset( Request::i()->cookie['cms_filters'] ) ) ? json_decode( Request::i()->cookie['cms_filters'], TRUE ) : array();
if ( $values === FALSE )
{
if ( array_key_exists( $key, $cookie ) )
{
unset( $cookie[ $key ] );
}
}
else
{
/* We only want to include ones where we have actually specified values to filter on */
$toSave = array();
foreach( $values AS $k => $v )
{
if ( is_numeric( $k ) or $k == 'cms_record_i_started' )
{
$toSave[ $k ] = $v;
}
}
$cookie[ $key ] = $toSave;
}
Request::i()->setCookie( 'cms_filters', json_encode( $cookie ), DateTime::create()->add( new DateInterval( 'P7D' ) ) );
}
/**
* Use the cookie to build filters
*
* @param array $cookie
* @param Categories|null $category
* @return array
*/
public function buildWhereFromCookie( array $cookie, ?Categories $category=null ) : array
{
$where = [];
/** @var Fields $fieldClass */
$fieldClass = 'IPS\cms\Fields' . $this->id;
$customFields = $fieldClass::data( 'view', $category, $fieldClass::FIELD_SKIP_TITLE_CONTENT );
foreach( $cookie as $f => $v )
{
if ( $f == 'cms_record_i_started' and Member::loggedIn()->member_id )
{
$where[] = array( 'cms_custom_database_' . $this->id . '.member_id=' . Member::loggedIn()->member_id );
continue;
}
$k = 'content_field_' . $f;
if ( $customFields[ $f ]->type === 'Member' )
{
if ( ! empty( $v ) )
{
if ( is_array( $v ) )
{
foreach( $v as $m )
{
$member = Member::load( $m );
$where[] = [ "FIND_IN_SET( " . $member->member_id . ", REPLACE(field_" . $f . ", '\n',','))" ];
}
}
else
{
$member = Member::load( $v );
$where[] = [ "FIND_IN_SET( " . $member->member_id . ", REPLACE(field_" . $f . ", '\n',','))" ];
}
}
continue;
}
if ( isset( $customFields[ $f ] ) and $v !== '___any___' )
{
if ( is_array( $v ) )
{
if ( array_key_exists( 'start', $v ) or array_key_exists( 'end', $v ) )
{
$start = ( $v['start'] instanceof DateTime ) ? $v['start']->getTimestamp() : intval( $v['start'] );
$end = ( $v['end'] instanceof DateTime ) ? $v['end']->getTimestamp() : intval( $v['end'] );
if ( $start or $end )
{
$where[] = array( '( ' . mb_substr( $k, 8 ) . ' BETWEEN ' . $start . ' AND ' . $end . ' )' );
}
}
else
{
$like = array();
foreach( $v as $val )
{
if ( $val === 0 or ! empty( $val ) )
{
$like[] = $val;
}
}
if( $customFields[ $f ]->default_value and in_array( $customFields[ $f ]->default_value, $v ) )
{
$where[] = array( "( " . mb_substr( $k, 8 ) . " IS NULL OR " . Db::i()->findInSet( mb_substr( $k, 8 ), $like ) . ")" );
}
else
{
$where[] = array( Db::i()->findInSet( mb_substr( $k, 8 ), $like ) );
}
}
}
else
{
if ( is_bool( $v ) )
{
/* YesNo fields are false or true */
if ( $v === false )
{
$where[] = array( '(' . mb_substr( $k, 8 ) . ' IS NULL or ' . mb_substr( $k, 8 ) . '=0)' );
}
else
{
$where[] = array( mb_substr( $k, 8 ) . "=1" );
}
}
else
{
if ( $v !== 0 and ! $v )
{
$where[] = array( mb_substr( $k, 8 ) . " IS NULL" );
}
else
{
$where[] = array( mb_substr( $k, 8 ) . "=?", $v );
}
}
}
}
}
return $where;
}
/**
* Get output for API
*
+1 -1
View File
@@ -1241,7 +1241,7 @@ class Fields extends CustomField implements Permissions
*/
public function get_display_json(): array
{
return ( is_array( $this->_data['display_json'] ) ) ? $this->_data['display_json'] : json_decode( $this->_data['display_json'], TRUE );
return ( is_array( $this->_data['display_json'] ) ) ? $this->_data['display_json'] : ( isset( $this->_data['display_json'] ) ? json_decode( $this->_data['display_json'], TRUE ) : [] );
}
/**
+14
View File
@@ -1268,6 +1268,13 @@ class Page extends Model implements Permissions
try
{
$template = Templates::load( $key );
/* If this is an empty file, don't bother loading it */
if( empty( $template->content ) )
{
continue;
}
$object = $template->_file_object;
$return['js'][ $key ] = $object;
@@ -1287,6 +1294,13 @@ class Page extends Model implements Permissions
try
{
$template = Templates::load( $key );
/* Skip if empty */
if( empty( $template->content ) )
{
continue;
}
$object = $template->_file_object;
$return['css'][ $key ] = $object;
+10 -2
View File
@@ -3771,7 +3771,11 @@ class Records extends Item implements
{
$title = '';
if( $prefix = static::database()->forum_prefix )
if ( $prefix = $this->container()->forum_prefix )
{
$title .= $prefix . ' ';
}
else if( $prefix = static::database()->forum_prefix )
{
$title .= $prefix . ' ';
}
@@ -3779,7 +3783,11 @@ class Records extends Item implements
$column = 'field_' . static::database()->field_title;
$title .= $this->$column;
if( $suffix = static::database()->forum_suffix )
if ( $suffix = $this->container()->forum_suffix )
{
$title .= ' ' . $suffix;
}
else if( $suffix = static::database()->forum_suffix )
{
$title .= ' ' . $suffix;
}