Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
+66
-37
@@ -47,6 +47,13 @@ use function get_declared_classes;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_callable;
|
||||
use function is_double;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
use function is_null;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function preg_replace_callback;
|
||||
use function strlen;
|
||||
@@ -334,26 +341,29 @@ class Lang extends Model
|
||||
$values[ $lang->id ] = $default;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( count( $values ) == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach ( static::languages() as $lang )
|
||||
{
|
||||
if ( !isset( $values[ $lang->id ] ) )
|
||||
{
|
||||
$values[ $lang->id ] = '';
|
||||
}
|
||||
else if ( $lang->default AND $default === NULL )
|
||||
{
|
||||
$default = $values[ $lang->id ];
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif( $default === null )
|
||||
{
|
||||
$default = $values[ static::defaultLanguage() ] ?? null;
|
||||
}
|
||||
|
||||
if ( count( $values ) == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$currentValues = iterator_to_array( Db::i()->select( '*', 'core_sys_lang_words', array( 'word_key=?', $key ) )->setKeyField('lang_id') );
|
||||
|
||||
/* Go through all the languages. If something is not set, it's disabled.
|
||||
In that case we only want to update it if the row does not exist; so we use the default value.
|
||||
If the row already existed, leave it alone. */
|
||||
foreach( static::languages() as $lang )
|
||||
{
|
||||
if( !isset( $values[ $lang->id ] ) and !isset( $currentValues[ $lang->id ] ) )
|
||||
{
|
||||
$values[ $lang->id ] = $default;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $values as $langId => $value )
|
||||
{
|
||||
if ( isset( $currentValues[ $langId ] ) )
|
||||
@@ -800,7 +810,7 @@ class Lang extends Model
|
||||
}
|
||||
else
|
||||
{
|
||||
$keysToLoad[] = "'" . Db::i()->real_escape_string( $k ) . "'";
|
||||
$keysToLoad[] = $k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,15 +826,23 @@ class Lang extends Model
|
||||
return $this->words[ $key ];
|
||||
}
|
||||
|
||||
$keysToLoad = array( "'" . Db::i()->real_escape_string( $key ) . "'" );
|
||||
$keysToLoad[] = $key;
|
||||
}
|
||||
|
||||
foreach(Db::i()->select( 'word_key, word_default, word_custom', 'core_sys_lang_words', array( "lang_id=? AND word_key IN(" . implode( ",", $keysToLoad ) . ")", ( $this->id ?? static::defaultLanguage() ) ) ) as $lang )
|
||||
foreach( Db::i()->select( 'word_key, word_default, word_custom,lang_id', 'core_sys_lang_words',
|
||||
[
|
||||
[ Db::i()->in( 'lang_id', array_unique( array_filter( [ $this->id, static::defaultLanguage() ] ) ) ) ],
|
||||
[ Db::i()->in( 'word_key', $keysToLoad ) ],
|
||||
],
|
||||
) as $lang )
|
||||
{
|
||||
$value = $lang['word_custom'] ?: $lang['word_default'];
|
||||
if( $lang['lang_id'] == $this->id or !isset( $this->words[ $lang['word_key'] ] ) )
|
||||
{
|
||||
$value = $lang['word_custom'] ?: $lang['word_default'];
|
||||
|
||||
$this->words[ $lang['word_key'] ] = $value;
|
||||
$return[ $lang['word_key' ] ] = $value;
|
||||
$this->words[ $lang['word_key'] ] = $value;
|
||||
$return[ $lang['word_key' ] ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're using an array, fill any missings strings with NULL to prevent duplicate queries */
|
||||
@@ -861,7 +879,10 @@ class Lang extends Model
|
||||
/* Setup? */
|
||||
if( $this->wordsLoaded === TRUE )
|
||||
{
|
||||
return ( isset( $this->words[ $key ] ) ) ? $this->words[ $key ] : $key;
|
||||
if( isset( $this->words[ $key ] ) )
|
||||
{
|
||||
return $this->words[ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
/* Get it */
|
||||
@@ -1771,21 +1792,29 @@ class Lang extends Model
|
||||
}
|
||||
|
||||
/* Parse out lang */
|
||||
$keys = array();
|
||||
|
||||
$keys = [];
|
||||
foreach( $this->outputStack as $word => $values )
|
||||
{
|
||||
if( !isset( $this->words[ $values['key'] ] ) )
|
||||
{
|
||||
$keys[] = "'" . Db::i()->real_escape_string( $values['key'] ) . "'";
|
||||
$keys[] = $values['key'];
|
||||
}
|
||||
}
|
||||
|
||||
if( !$this->wordsLoaded === TRUE AND count( $keys ) and !IN_DEV)
|
||||
if( !$this->wordsLoaded === TRUE AND count( $keys ) and !IN_DEV )
|
||||
{
|
||||
foreach(Db::i()->select( 'word_key, word_default, word_custom', 'core_sys_lang_words', array( "lang_id=? AND word_key IN(" . implode( ",", $keys ) . ") and word_js=0", $this->id ) ) as $row )
|
||||
foreach( Db::i()->select( 'word_key, word_default, word_custom,lang_id', 'core_sys_lang_words',
|
||||
[
|
||||
[ Db::i()->in( 'lang_id', array_unique( array_filter( [ $this->id, static::defaultLanguage() ] ) ) ) ],
|
||||
[ Db::i()->in( 'word_key', $keys ) ],
|
||||
[ 'word_js=0' ]
|
||||
],
|
||||
) as $row )
|
||||
{
|
||||
$this->words[ $row['word_key'] ] = $row['word_custom'] ?: $row['word_default'];
|
||||
if( $row['lang_id'] == $this->id or !isset( $this->words[ $row['word_key'] ] ) )
|
||||
{
|
||||
$this->words[ $row['word_key'] ] = $row['word_custom'] ?: $row['word_default'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $this->outputStack as $word => $values )
|
||||
@@ -1848,7 +1877,7 @@ class Lang extends Model
|
||||
/**
|
||||
* Strip VLE tags, useful for AJAX responses where you can't edit the string anyways
|
||||
*
|
||||
* @param array|string|null $output The output string
|
||||
* @param array|string|null $output The output string. If an array contains non-string values, they will be cast to a string if they don't correlate to JSON primitives and aren't arrays
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function stripVLETags( array|string|null $output ): array|string|null
|
||||
@@ -1857,13 +1886,13 @@ class Lang extends Model
|
||||
{
|
||||
if( ! is_array( $output ) )
|
||||
{
|
||||
return (string) $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
$replacement = array();
|
||||
foreach ( $output as $key => $value )
|
||||
{
|
||||
$replacement[ $key ] = $this->stripVLETags( $value );
|
||||
$replacement[ $key ] = ( is_int( $value ) or is_double( $value ) or is_float( $value ) or is_bool( $value ) or is_null( $value ) ) ? $value : $this->stripVLETags( is_array( $value ) ? $value : (string) $value );
|
||||
}
|
||||
|
||||
return $replacement;
|
||||
@@ -1899,7 +1928,7 @@ class Lang extends Model
|
||||
|
||||
foreach ( $output as $key => $value )
|
||||
{
|
||||
$replacement[ $key ] = $this->stripVLETags( $value );
|
||||
$replacement[ $key ] = ( is_int( $value ) or is_double( $value ) or is_float( $value ) or is_bool( $value ) or is_null( $value ) ) ? $value : $this->stripVLETags( is_array( $value ) ? $value : (string) $value );
|
||||
}
|
||||
|
||||
return $replacement;
|
||||
@@ -1912,9 +1941,9 @@ class Lang extends Model
|
||||
* @param array|string $replace The string to replace with
|
||||
* @param array|string|null $haystack The subject
|
||||
*
|
||||
* @return string|array|null|object
|
||||
* @return mixed
|
||||
*/
|
||||
public static function replace( array|string $find, array|string $replace, mixed $haystack ): array|string|null|object
|
||||
public static function replace( array|string $find, array|string $replace, mixed $haystack ): mixed
|
||||
{
|
||||
/* Reduce the number of str_replace with arrays */
|
||||
static $replaceTable = array();
|
||||
|
||||
Reference in new issue
Block a user