Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+115 -13
View File
@@ -36,6 +36,11 @@ class _Settings extends \IPS\Patterns\Singleton
* @brief Settings loaded?
*/
protected $loaded = FALSE;
/**
* @brief Store $INFO so we know what came from conf_global later
*/
protected static $confGlobal = array();
/**
* Constructor
@@ -46,10 +51,12 @@ class _Settings extends \IPS\Patterns\Singleton
{
if ( file_exists( \IPS\ROOT_PATH . '/conf_global.php' ) )
{
$allowedFields = $this->getAllowedFields();
require( \IPS\ROOT_PATH . '/conf_global.php' );
if ( isset( $INFO ) )
{
if( isset( $INFO['board_url'] ) AND !isset( $INFO['base_url'] ) )
if( isset( $INFO['board_url'] ) AND ( !isset( $INFO['base_url'] ) OR !$INFO['base_url'] ) )
{
$INFO['base_url'] = $INFO['board_url'];
}
@@ -61,23 +68,32 @@ class _Settings extends \IPS\Patterns\Singleton
$INFO['base_url'] = $INFO['base_url'] . '/';
}
}
if( isset( $INFO['use_friendly_urls'] ) )
{
unset( $INFO['use_friendly_urls'] );
}
/* If this is a legacy installation, it may have the (wrong) license key defined in conf_global. */
if( isset( $INFO['ipb_reg_number'] ) )
{
unset( $INFO['ipb_reg_number'] );
}
foreach( $INFO as $k => $v )
{
if ( ! in_array( $k, $allowedFields ) )
{
unset( $INFO[ $k ] );
}
}
static::$confGlobal = $INFO;
$this->data = $INFO;
}
}
}
/**
* Fetch the allowed fields to be stored from conf_global
* Abstracted to one can use it as a hook point
*
* @return array
*/
public function getAllowedFields()
{
return array( 'sql_host', 'sql_database', 'sql_user', 'sql_pass', 'sql_port', 'sql_socket', 'sql_tbl_prefix', 'sql_utf8mb4', 'board_start', 'installed', 'base_url', 'guest_group', 'member_group', 'admin_group' );
}
/**
* Magic Method: Get
*
@@ -152,7 +168,7 @@ class _Settings extends \IPS\Patterns\Singleton
$settings = \IPS\Data\Store::i()->settings;
}
else
{
{
foreach ( \IPS\Db::i()->select( 'conf_key, conf_default, conf_value', 'core_sys_conf_settings' )->setKeyField( 'conf_key' ) as $k => $data )
{
$settings[ $k ] = ( $data['conf_value'] === '' ) ? $data['conf_default'] : $data['conf_value'];
@@ -165,4 +181,90 @@ class _Settings extends \IPS\Patterns\Singleton
$this->loaded = TRUE;
}
/**
* Purge the current settings cache
*
* @note While calling unset() on the datastore value purges it, if we still have settings loaded in memory a call to changeValues() causes
the same values to be written, which is not desired
* @return void
*/
public function clearCache()
{
unset( \IPS\Data\Store::i()->settings );
$this->data = static::$confGlobal;
$this->loaded = FALSE;
}
/**
* Change values
*
* @param array $newValues New values
* @return void
*/
public function changeValues( $newValues )
{
/* Get the current values if we don't have them already */
if ( !$this->loaded )
{
$this->loadFromDb(); // Misleading method name - will load from datastore if it's available
}
/* If we want to set any of them to an empty string, we need the default value */
$defaultValues = array();
foreach ( $newValues as $k => $v )
{
if ( $v === '' )
{
$defaultValues[] = $k;
}
}
$defaultValues = iterator_to_array( \IPS\Db::i()->select( array( 'conf_default', 'conf_key' ), 'core_sys_conf_settings', \IPS\Db::i()->in( 'conf_key', $defaultValues ) )->setKeyField( 'conf_key' )->setValueField( 'conf_default' ) );
$validKeys = iterator_to_array( \IPS\Db::i()->select( 'conf_key', 'core_sys_conf_settings', \IPS\Db::i()->in( 'conf_key', array_keys( $newValues ) ) ) );
/* Update the database */
$changed = FALSE;
foreach ( $newValues as $k => $v )
{
$valueToCache = isset( $defaultValues[ $k ] ) ? $defaultValues[ $k ] : $v;
/* Make sure the key is valid */
if( !in_array( $k, $validKeys ) )
{
if ( \IPS\IN_DEV )
{
throw new \InvalidArgumentException( 'unknown_setting: ' . $k );
}
continue;
}
if ( $this->$k != $valueToCache )
{
$this->$k = $valueToCache;
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $v ), array( 'conf_key=?', $k ) );
$changed = TRUE;
}
}
/* Update the datastore */
if ( $changed )
{
$toStore = array();
foreach( $this->data AS $dk => $dv )
{
if ( ! isset( static::$confGlobal[ $dk ] ) )
{
/* Make sure objects are cast to string as the DB bind layer will do this automatically when saving */
if ( is_object( $dv ) and method_exists( $dv, '__toString' ) )
{
$dv = (string) $dv;
}
$toStore[ $dk ] = $dv;
}
}
\IPS\Data\Store::i()->settings = $toStore;
}
}
}