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

+61 -9
View File
@@ -323,15 +323,20 @@ class _Lang extends \IPS\Node\Model
* @param string $app Application Key
* @param string $key Word key
* @param string $newKey New Word Key
* @param string $newApp New Application Key, if different
* @return void
*/
public static function copyCustom( $app, $key, $newKey )
public static function copyCustom( $app, $key, $newKey, $newApp=NULL )
{
$values = iterator_to_array( \IPS\Db::i()->select( 'lang_id, word_custom', 'core_sys_lang_words', array( 'word_app=? AND word_key=?', $app, $key ) )->setKeyField('lang_id')->setValueField('word_custom') );
$values = array();
foreach ( \IPS\Db::i()->select( 'lang_id, word_default, word_custom', 'core_sys_lang_words', array( 'word_app=? AND word_key=?', $app, $key ) )->setKeyField('lang_id') as $langId => $data )
{
$values[ $langId ] = $data['word_custom'] ?: $data['word_default'];
}
foreach( $values as $row )
{
static::saveCustom( $app, $newKey, $values );
static::saveCustom( $newApp ?: $app, $newKey, $values );
}
}
@@ -506,6 +511,9 @@ class _Lang extends \IPS\Node\Model
*/
public function preferredDateFormat()
{
/* Make sure the locale has been set, important for things like the js date_format variable */
$this->setLocale();
$date = new \IPS\DateTime('1992-03-04');
return str_replace( array( '1992', '92', '03', '3', $date->strFormat('%B'), '04', ' 4', '4' ), array( 'yy', 'yy', 'mm', 'mm', 'mm', 'dd', 'dd', 'dd' ), $date->localeDate() );
}
@@ -671,7 +679,7 @@ class _Lang extends \IPS\Node\Model
/* Get it */
if( isset( $this->outputStack[ $key ] ) )
{
return htmlentities( $key, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE );
return htmlspecialchars( $key, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', FALSE );
}
$id = md5( 'ipslang_' . static::$outputSalt . $key . json_encode( $options ) );
@@ -1432,6 +1440,35 @@ class _Lang extends \IPS\Node\Model
$this->replaceWords( $output );
}
/**
* Emails require some additional work on top of replacing the language stack
*
* @param string $output Unparsed
* @return void
*/
public function parseEmail( &$output )
{
$this->parseOutputForDisplay( $output );
$dir = ( $this->isrtl ) ? 'rtl' : 'ltr';
if ( mb_stristr( $output, '{dir}' ) )
{
$output = preg_replace( '#(<td\s+?)dir=([\'"]){dir}([\'"])#i', '\1dir=\2' . $dir . '\3', $output );
preg_match_all( '#<(body|html)([^>]+?)>#i', $output, $matches, PREG_SET_ORDER );
foreach( $matches as $match )
{
if ( mb_stristr( $match[2], '{dir}' ) )
{
$parsed = str_replace( '{dir}', $dir, $match[0] );
$output = str_replace( $match[0], $parsed, $output );
}
}
}
}
/**
* Strip VLE tags, useful for AJAX responses where you can't edit the string anyways
*
@@ -1513,9 +1550,23 @@ class _Lang extends \IPS\Node\Model
*/
public static function replace( $find, $replace, $haystack )
{
if ( !is_array( $haystack ) )
/* Reduce the number of str_replace with arrays */
static $replaceTable = array();
if ( ! is_array( $haystack ) )
{
return str_replace( $find, $replace, $haystack );
$hash = md5( json_encode($find) . json_encode($replace) . $haystack );
if ( isset( $replaceTable[ $hash ] ) )
{
return $replaceTable[ $hash ];
}
else
{
$output = str_replace( $find, $replace, $haystack );
$replaceTable[ $hash ] = $output;
return $output;
}
}
$replacement = array();
@@ -1573,7 +1624,7 @@ class _Lang extends \IPS\Node\Model
$sprintf = array_map(
function ( $val ) use ( $replacement )
{
return htmlentities( trim( $val ), ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', false );
return htmlspecialchars( trim( $val ), ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', false );
},
( is_array(
$values[ 'options' ][ 'sprintf' ]
@@ -1647,7 +1698,7 @@ class _Lang extends \IPS\Node\Model
if ( isset( $values[ 'options' ][ 'escape' ] ) )
{
$replacement = htmlentities( $replacement, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', false );
$replacement = htmlspecialchars( $replacement, ENT_QUOTES | \IPS\HTMLENTITIES, 'UTF-8', false );
}
/* Parse URLs */
@@ -1711,7 +1762,8 @@ class _Lang extends \IPS\Node\Model
$replacements[ $key ] = $replacement;
}
/* We do this 3 times in case a replacement contains another replacement, etc. */
/* We do this 4 times in case a replacement contains another replacement, etc. */
$output = static::replace( array_keys( $replacements ), array_values( $replacements ), $output );
$output = static::replace( array_keys( $replacements ), array_values( $replacements ), $output );
$output = static::replace( array_keys( $replacements ), array_values( $replacements ), $output );
$output = static::replace( array_keys( $replacements ), array_values( $replacements ), $output );