Version 4.1.19.4

This commit is contained in:
Neo committed 2025-12-19 05:42:01 -08:00
1 parent 2bd5025018
commit 0dc2aee5ed
312 files changed
+53730 -32118

No files matched your search

+83 -115
View File
@@ -1843,23 +1843,15 @@ EOF;
*/
public function installLanguages( $offset=null, $limit=null )
{
$languages = array_keys( \IPS\Lang::languages() );
$langs = \IPS\Lang::languages();
$inserted = 0;
$current = array();
$rusCurrent = array();
foreach( $languages as $languageId )
{
foreach( iterator_to_array( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'word_app=? AND lang_id=?', $this->directory, $languageId ) ) ) as $word )
foreach( iterator_to_array( \IPS\Db::i()->select( 'word_key, word_default, word_js', 'core_sys_lang_words', array( 'word_app=? AND lang_id=?', $this->directory, $languageId ) ) ) as $word )
{
if(\mb_strpos($langs[$languageId]->short,'ru_RU')!==false) {
foreach ($word as $key => $value) {
$rusCurrent[ $word['word_key'] . '-.-' . $word['word_js'] ][$key] = $value;
}
}
else $current[ $languageId ][ $word['word_key'] . '-.-' . $word['word_js'] ] = $word['word_default'];
$current[ $languageId ][ $word['word_key'] . '-.-' . $word['word_js'] ] = $word['word_default'];
}
}
@@ -1893,131 +1885,107 @@ EOF;
}
}
$xmlFile = '';
foreach( $languages as $languageId ) {
if( file_exists( \IPS\ROOT_PATH . "/applications/{$this->directory}/data/lang.xml" ) )
{
/* Open XML file */
$xml = new \IPS\Xml\XMLReader;
$xml->open( \IPS\ROOT_PATH . "/applications/{$this->directory}/data/lang.xml" );
$xml->read();
$xmlFile = \IPS\ROOT_PATH . "/applications/{$this->directory}/data/lang".(\mb_strpos($langs[$languageId]->short,'ru_RU')!==false?'_rus':'').".xml" ;
/* Get the version */
$xml->read();
$xml->read();
$version = $xml->getAttribute('version');
if( !file_exists( $xmlFile ) ) continue;
/* Get all installed languages */
$inserts = array();
$batchSize = 25;
$batchesDone = 0;
$i = 0;
/* Try to prevent timeouts to the extent possible */
$cutOff = null;
$inserted = 0;
/* Open XML file */
$xml = new \IPS\Xml\XMLReader;
$xml->open( $xmlFile );
$xml->read();
/* Get the version */
$xml->read();
$xml->read();
$version = $xml->getAttribute('version');
/* Get all installed languages */
$inserts = array();
$insertsRus = array();
$batchSize = 25;
$batchesDone = 0;
$i = 0;
/* Try to prevent timeouts to the extent possible */
$cutOff = null;
if( $maxExecution = @ini_get( 'max_execution_time' ) )
if( $maxExecution = @ini_get( 'max_execution_time' ) )
{
/* If max_execution_time is set to "no limit" we should add a hard limit to prevent browser timeouts */
if ( $maxExecution == -1 )
{
/* If max_execution_time is set to "no limit" we should add a hard limit to prevent browser timeouts */
if ( $maxExecution == -1 )
{
$maxExecution = 30;
}
$cutOff = time() + ( $maxExecution * .5 );
$maxExecution = 30;
}
/* Start looping through each word */
while ( $xml->read() )
$cutOff = time() + ( $maxExecution * .5 );
}
/* Start looping through each word */
while ( $xml->read() )
{
if( $xml->name != 'word' OR $xml->nodeType != \XMLReader::ELEMENT )
{
if( $xml->name != 'word' OR $xml->nodeType != \XMLReader::ELEMENT )
continue;
}
if( $cutOff !== null AND time() >= $cutOff )
{
return $inserted;
}
$i++;
if ( $offset !== null )
{
if ( $i - 1 < $offset )
{
$xml->next();
continue;
}
}
if( $cutOff !== null AND time() >= $cutOff )
$inserted++;
$key = $xml->getAttribute('key');
$value = $xml->readString();
foreach( $languages as $languageId )
{
if ( !isset( $current[ $languageId ][ $key . '-.-' . (int) $xml->getAttribute('js') ] ) or $current[ $languageId ][ $key . '-.-' . (int) $xml->getAttribute('js') ] != $value )
{
return $inserted;
$inserts[] = array(
'word_app' => $this->directory,
'word_key' => $key,
'lang_id' => $languageId,
'word_default' => $value,
'word_default_version' => $version,
'word_js' => (int) $xml->getAttribute('js'),
'word_export' => 1,
);
}
$i++;
if ( $offset !== null )
{
if ( $i - 1 < $offset )
{
$xml->next();
continue;
}
}
$inserted++;
$key = $xml->getAttribute('key');
$value = $xml->readString();
if(\mb_strpos($langs[$languageId]->short,'ru_RU')!==false and isset( $rusCurrent[ $key . '-.-' . (int) $xml->getAttribute('js') ] ) and
$rusCurrent[ $key . '-.-' . (int) $xml->getAttribute('js') ]['word_custom']!=$xml->getAttribute('key_rus')) {
$rusCurrent[ $key . '-.-' . (int) $xml->getAttribute('js') ]['word_custom'] = $xml->getAttribute('key_rus');
$insertsRus[] = $rusCurrent[ $key . '-.-' . (int) $xml->getAttribute('js') ];
}
elseif ( !isset( $current[ $languageId ][ $key . '-.-' . (int) $xml->getAttribute('js') ] ) or $current[ $languageId ][ $key . '-.-' . (int) $xml->getAttribute('js') ] != $value )
{
$inserts[] = array(
'word_app' => $this->directory,
'word_key' => $key,
'lang_id' => $languageId,
'word_default' => $value,
'word_default_version' => $version,
'word_custom' => $xml->getAttribute('key_rus'),
'word_js' => (int) $xml->getAttribute('js'),
'word_export' => 1,
'word_id'=>'', 'word_plugin'=>'' , 'word_theme'=>'' , 'word_custom_version'=>'',
);
}
$done = ( $limit !== null AND $i === ( $limit + $offset ) );
if ( $done OR $i % $batchSize === 0 )
{
if ( count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $inserts, TRUE );
$inserts = array();
}
if ( count( $insertsRus ) )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $insertsRus, TRUE );
$insertsRus = array();
}
$batchesDone++;
}
if ( $done )
{
break;
}
$xml->next();
}
if ( count( $inserts ) )
$done = ( $limit !== null AND $i === ( $limit + $offset ) );
if ( $done OR $i % $batchSize === 0 )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $inserts, TRUE );
if ( count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $inserts, TRUE );
$inserts = array();
}
$batchesDone++;
}
if ( count( $insertsRus ) )
if ( $done )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $insertsRus, TRUE );
break;
}
$xml->next();
}
if ( count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_sys_lang_words', $inserts, TRUE );
}
}
return $inserted;
}