Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\languages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -22,11 +22,26 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _languages extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\Lang';
|
||||
|
||||
/**
|
||||
* Title can contain HTML?
|
||||
*/
|
||||
public $_titleHtml = TRUE;
|
||||
|
||||
/**
|
||||
* Description can contain HTML?
|
||||
*/
|
||||
public $_descriptionHtml = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -38,6 +53,29 @@ class _languages extends \IPS\Node\Controller
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow overloading to change how the title is displayed in the tree
|
||||
*
|
||||
* @param $node \IPS\Node Node
|
||||
* @return string
|
||||
*/
|
||||
protected static function nodeTitle( $node )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('customization')->langRowTitle( $node );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch any additional HTML for this row
|
||||
*
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
{
|
||||
$hasBeenCustomized = \IPS\Db::i()->select( 'COUNT(*)', 'core_sys_lang_words', array( 'lang_id=? AND word_export=1 AND word_custom IS NOT NULL', $node->id ) )->first();
|
||||
return \IPS\Theme::i()->getTemplate('customization' )->langRowAdditional( $node, $hasBeenCustomized );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
@@ -55,11 +93,130 @@ class _languages extends \IPS\Node\Controller
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=vle' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('lang_vle') )
|
||||
);
|
||||
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'plus',
|
||||
'title' => 'add_word',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=addWord" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'add_word' ) )
|
||||
);
|
||||
|
||||
/* @note If any more settings are added, then this condition needs to be moved. */
|
||||
if ( \count( \IPS\Lang::languages() ) > 1 )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'cogs',
|
||||
'title' => 'settings',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=settings' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('settings') )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Word
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addWord(): void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'wordForm', 'save', NULL, array( 'data-role' => 'wordForm' ) );
|
||||
\IPS\Lang::wordForm( $form );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Save */
|
||||
\IPS\Lang::saveCustom( 'core', $values['word_key'], $values['word_custom'] ?? NULL, FALSE, $values['word_default'] );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=languages&controller=languages" ), 'saved' );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'add_word' );
|
||||
\IPS\Output::i()->output = (string) $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Word
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteWord(): void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Make sure this is actually a custom phrase */
|
||||
try
|
||||
{
|
||||
$word = \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( "word_key=? AND lang_id=?", \IPS\Request::i()->key, \IPS\Request::i()->langId ) )->first();
|
||||
|
||||
if ( !$word['word_is_custom'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1C126/9', 403, '' );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1C126/A', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_sys_lang_words', array( "word_key=?", \IPS\Request::i()->key ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=translate&id=" . \IPS\Request::i()->langId ), 'deleted' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual Upload Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function upload()
|
||||
{
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage('languages_manual_install_warning');
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'lang_upload', NULL, TRUE, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
|
||||
\IPS\Lang::localeField( $form );
|
||||
|
||||
$activeTabContents = $form;
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Move it to a temporary location */
|
||||
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
|
||||
move_uploaded_file( $values['lang_upload'], $tempFile );
|
||||
|
||||
/* Work out locale */
|
||||
if( isset( $values['lang_short_custom'] ) )
|
||||
{
|
||||
if ( !isset($values['lang_short']) OR $values['lang_short'] === 'x' )
|
||||
{
|
||||
$locale = $values['lang_short_custom'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$locale = $values['lang_short'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Initate a redirector */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'locale' => $locale ) )->csrf() );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit Form
|
||||
*
|
||||
@@ -69,126 +226,80 @@ class _languages extends \IPS\Node\Controller
|
||||
{
|
||||
/* If we have no ID number, this is the add form, which is handled differently to the edit */
|
||||
if ( !\IPS\Request::i()->id )
|
||||
{
|
||||
$tab = \IPS\Request::i()->tab ?: 'new';
|
||||
|
||||
{
|
||||
/* CREATE NEW */
|
||||
$max = \IPS\Db::i()->select( 'MAX(lang_order)', 'core_sys_lang' )->first();
|
||||
if ( $tab === 'new' )
|
||||
{
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$lang = new \IPS\Lang( array( 'lang_short' => 'en_US' ) );
|
||||
$lang->form( $form );
|
||||
$activeTabContents = $form;
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Find the correct locale */
|
||||
if ( !isset($values['lang_short']) OR $values['lang_short'] === 'x' )
|
||||
{
|
||||
$values['lang_short'] = $values['lang_short_custom'];
|
||||
}
|
||||
unset( $values['lang_short_custom'] );
|
||||
|
||||
/* reset default language if we want this to be default */
|
||||
if( isset( $values['lang_default'] ) and $values['lang_default'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_sys_lang', array( 'lang_default' => 0 ) );
|
||||
}
|
||||
|
||||
/* Add "UTF8" if we can */
|
||||
$currentLocale = setlocale( LC_ALL, '0' );
|
||||
|
||||
foreach ( array( "{$values['lang_short']}.UTF-8", "{$values['lang_short']}.UTF8" ) as $l )
|
||||
{
|
||||
$test = setlocale( LC_ALL, $l );
|
||||
if ( $test !== FALSE )
|
||||
{
|
||||
$values['lang_short'] = $l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( explode( ";", $currentLocale ) as $locale )
|
||||
{
|
||||
$parts = explode( "=", $locale );
|
||||
if( in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
|
||||
{
|
||||
setlocale( constant( $parts[0] ), $parts[1] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert the actual language */
|
||||
$values['lang_order'] = ++$max;
|
||||
$insertId = \IPS\Db::i()->insert( 'core_sys_lang', $values );
|
||||
|
||||
/* Copy over language strings */
|
||||
$default = \IPS\Lang::defaultLanguage();
|
||||
$prefix = \IPS\Db::i()->prefix;
|
||||
$defaultStmt = \IPS\Db::i()->prepare( "INSERT INTO `{$prefix}core_sys_lang_words` ( `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export` ) SELECT {$insertId} AS `lang_id`, `word_app`, `word_key`, `word_default`, NULL AS `word_custom`, `word_default_version`, NULL AS `word_custom_version`, `word_js`, `word_export` FROM `{$prefix}core_sys_lang_words` WHERE `lang_id`={$default} AND `word_export`=1" );
|
||||
$defaultStmt->execute();
|
||||
$customStmt = \IPS\Db::i()->prepare( "INSERT INTO `{$prefix}core_sys_lang_words` ( `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export` ) SELECT {$insertId} AS `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export` FROM `{$prefix}core_sys_lang_words` WHERE `lang_id`={$default} AND `word_export`=0" );
|
||||
$customStmt->execute();
|
||||
|
||||
unset( \IPS\Data\Store::i()->languages );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Log */
|
||||
\IPS\Session::i()->log( 'acplogs__lang_created', array( $values['lang_title'] => FALSE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages' ), 'saved' );
|
||||
}
|
||||
}
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage('languages_create_blurb');
|
||||
$lang = new \IPS\Lang( array( 'lang_short' => 'en_US' ) );
|
||||
$lang->form( $form );
|
||||
|
||||
/* UPLOAD */
|
||||
else
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'lang_upload', NULL, TRUE, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
|
||||
\IPS\Lang::localeField( $form );
|
||||
|
||||
$activeTabContents = $form;
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
/* Find the correct locale */
|
||||
if ( !isset($values['lang_short']) OR $values['lang_short'] === 'x' )
|
||||
{
|
||||
/* Move it to a temporary location */
|
||||
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
|
||||
move_uploaded_file( $values['lang_upload'], $tempFile );
|
||||
|
||||
/* Work out locale */
|
||||
if( isset( $values['lang_short_custom'] ) )
|
||||
{
|
||||
if ( !isset($values['lang_short']) OR $values['lang_short'] === 'x' )
|
||||
{
|
||||
$locale = $values['lang_short_custom'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$locale = $values['lang_short'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Initate a redirector */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'locale' => $locale ) ) );
|
||||
$values['lang_short'] = $values['lang_short_custom'];
|
||||
}
|
||||
unset( $values['lang_short_custom'] );
|
||||
|
||||
/* reset default language if we want this to be default */
|
||||
if( isset( $values['lang_default'] ) and $values['lang_default'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_sys_lang', array( 'lang_default' => 0 ) );
|
||||
}
|
||||
|
||||
/* Add "UTF8" if we can */
|
||||
$currentLocale = setlocale( LC_ALL, '0' );
|
||||
|
||||
foreach ( array( "{$values['lang_short']}.UTF-8", "{$values['lang_short']}.UTF8" ) as $l )
|
||||
{
|
||||
$test = setlocale( LC_ALL, $l );
|
||||
if ( $test !== FALSE )
|
||||
{
|
||||
$values['lang_short'] = $l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( explode( ";", $currentLocale ) as $locale )
|
||||
{
|
||||
$parts = explode( "=", $locale );
|
||||
if( \in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
|
||||
{
|
||||
setlocale( \constant( $parts[0] ), $parts[1] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert the actual language */
|
||||
$values['lang_order'] = ++$max;
|
||||
$insertId = \IPS\Db::i()->insert( 'core_sys_lang', $values );
|
||||
|
||||
/* Copy over language strings */
|
||||
$default = \IPS\Lang::defaultLanguage();
|
||||
$prefix = \IPS\Db::i()->prefix;
|
||||
$defaultStmt = \IPS\Db::i()->prepare( "INSERT INTO `{$prefix}core_sys_lang_words` ( `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export` ) SELECT {$insertId} AS `lang_id`, `word_app`, `word_key`, `word_default`, NULL AS `word_custom`, `word_default_version`, NULL AS `word_custom_version`, `word_js`, `word_export` FROM `{$prefix}core_sys_lang_words` WHERE `lang_id`={$default} AND `word_export`=1" );
|
||||
$defaultStmt->execute();
|
||||
$customStmt = \IPS\Db::i()->prepare( "INSERT INTO `{$prefix}core_sys_lang_words` ( `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export`, `word_is_custom` ) SELECT {$insertId} AS `lang_id`, `word_app`, `word_key`, `word_default`, `word_custom`, `word_default_version`, `word_custom_version`, `word_js`, `word_export`, `word_is_custom` FROM `{$prefix}core_sys_lang_words` WHERE `lang_id`={$default} AND `word_export`=0" );
|
||||
$customStmt->execute();
|
||||
|
||||
unset( \IPS\Data\Store::i()->languages );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Log */
|
||||
\IPS\Session::i()->log( 'acplogs__lang_created', array( $values['lang_title'] => FALSE ) );
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages' ), 'saved' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
if( \IPS\Request::i()->isAjax() and \IPS\Request::i()->existing and !isset( \IPS\Request::i()->ajaxValidate ) )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( array( 'new' => 'add', 'upload' => 'upload' ), $tab, $activeTabContents, \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=form&existing=1" ) );
|
||||
}
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
/* If it's an edit, we can just let the node controller handle it */
|
||||
else
|
||||
@@ -204,6 +315,8 @@ class _languages extends \IPS\Node\Controller
|
||||
*/
|
||||
protected function enableToggle()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Load Language */
|
||||
try
|
||||
{
|
||||
@@ -306,11 +419,11 @@ class _languages extends \IPS\Node\Controller
|
||||
{
|
||||
if ( $values[ 'lang_' . $k ] )
|
||||
{
|
||||
\IPS\Request::i()->setcookie( $k, 1 );
|
||||
\IPS\Request::i()->setCookie( $k, 1 );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->cookie[ $k ] ) )
|
||||
{
|
||||
\IPS\Request::i()->setcookie( $k, 0 );
|
||||
\IPS\Request::i()->setCookie( $k, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,6 +433,25 @@ class _languages extends \IPS\Node\Controller
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Language Setting
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'lang_auto_detect', \IPS\Settings::i()->lang_auto_detect, TRUE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate
|
||||
*
|
||||
@@ -342,7 +474,7 @@ class _languages extends \IPS\Node\Controller
|
||||
}
|
||||
|
||||
$where = array(
|
||||
array( 'lang_id=? AND word_export=1', \IPS\Request::i()->id ),
|
||||
array( 'lang_id=? AND (word_export=1 OR word_is_custom=1)', \IPS\Request::i()->id ),
|
||||
);
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_sys_lang_words', \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=translate&id=' . \IPS\Request::i()->id ), $where );
|
||||
@@ -408,15 +540,35 @@ class _languages extends \IPS\Node\Controller
|
||||
'word_key' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'word_default' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'word_custom' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'word_app' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\Application', 'subnodes' => FALSE ) ),
|
||||
'word_plugin' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => 'IPS\Plugin', 'subnodes' => FALSE ) )
|
||||
);
|
||||
|
||||
$table->filters = array(
|
||||
'lang_filter_translated' => 'word_custom IS NOT NULL',
|
||||
'lang_filter_untranslated' => 'word_custom IS NULL',
|
||||
'lang_filter_out_of_date' => 'word_custom IS NOT NULL AND word_custom_version<word_default_version'
|
||||
'lang_filter_out_of_date' => 'word_custom IS NOT NULL AND word_custom_version<word_default_version',
|
||||
'lang_filter_admin_custom' => 'word_is_custom!=0'
|
||||
);
|
||||
|
||||
$table->widths = array( 'word_key' => 15, 'word_default' => 35, 'word_custom' => 50 );
|
||||
$table->rowButtons = function( $row ) {
|
||||
if ( $row['word_is_custom'] )
|
||||
{
|
||||
return array(
|
||||
'delete' => array(
|
||||
'icon' => 'times',
|
||||
'title' => 'delete',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=deleteWord&key={$row['word_key']}&langId=" . \IPS\Request::i()->id )->csrf(),
|
||||
'data' => array( 'confirm' => '', 'confirmMessage' => \IPS\Member::loggedIn()->language()->addToStack('delete_word_all_languages') )
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
};
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['lang_word_custom'] = $lang->title;
|
||||
|
||||
@@ -445,7 +597,7 @@ class _languages extends \IPS\Node\Controller
|
||||
$word = \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_key=? AND word_js=?', \IPS\Request::i()->lang, \IPS\Request::i()->key, (int) \IPS\Request::i()->js ) )->first();
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addDummy( 'lang_word_default', $word['word_default'] );
|
||||
$form->addDummy( 'lang_word_default', htmlspecialchars( $word['word_default'],ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'lang_word_custom', $word['word_custom'] ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
@@ -480,6 +632,11 @@ class _languages extends \IPS\Node\Controller
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->listFormats );
|
||||
}
|
||||
|
||||
if ( \substr( $word['word_key'], 0, 10 ) === 'num_short_' )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->shortFormats );
|
||||
}
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
@@ -505,17 +662,20 @@ class _languages extends \IPS\Node\Controller
|
||||
*/
|
||||
protected function copy()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=copy&id=" . intval( \IPS\Request::i()->id ) ),
|
||||
\IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=copy&id=" . \intval( \IPS\Request::i()->id ) )->csrf(),
|
||||
function( $data )
|
||||
{
|
||||
if ( !is_array( $data ) )
|
||||
if ( !\is_array( $data ) )
|
||||
{
|
||||
$lang = \IPS\Db::i()->select( '*', 'core_sys_lang', array( 'lang_id=?', \IPS\Request::i()->id ) )->first();
|
||||
unset( $lang['lang_id'] );
|
||||
|
||||
$lang['lang_title'] = $lang['lang_title'] . ' ' . \IPS\Member::loggedIn()->language()->get('copy_noun');
|
||||
$lang['lang_default'] = FALSE;
|
||||
$lang['lang_marketplace_id'] = NULL;
|
||||
|
||||
$insertId = \IPS\Db::i()->insert( 'core_sys_lang', $lang );
|
||||
|
||||
@@ -528,7 +688,7 @@ class _languages extends \IPS\Node\Controller
|
||||
else
|
||||
{
|
||||
$words = \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=?', \IPS\Request::i()->id ), 'word_id', array( $data['done'], 100 ) );
|
||||
if ( !count( $words ) )
|
||||
if ( !\count( $words ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -577,86 +737,125 @@ class _languages extends \IPS\Node\Controller
|
||||
\IPS\Output::i()->error( 'node_error', '2C126/5', 404, '' );
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
try
|
||||
{
|
||||
$count = \IPS\Db::i()->select( 'COUNT(word_id)', 'core_sys_lang_words', array( 'lang_id=? AND word_export=1 AND word_custom IS NOT NULL', $lang->id ), 'word_id', NULL, 'word_id' )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
$form = new \IPS\Helpers\Form( 'form', 'langauge_export_button' );
|
||||
|
||||
if ( $count < 1 )
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'language_export_author_name', $lang->author_name, false ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'language_export_author_url', $lang->author_url, false ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'language_export_update_check', $lang->update_url, false ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'language_export_version', $lang->version, true, array( 'placeholder' => '1.0.0' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'language_export_long_version', $lang->version_long ?: 10000, true ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'core_lang_download_empty', '1C126/7', 404, '' );
|
||||
}
|
||||
|
||||
/* Init */
|
||||
$xml = new \XMLWriter;
|
||||
$xml->openMemory();
|
||||
$xml->setIndent( TRUE );
|
||||
$xml->startDocument( '1.0', 'UTF-8' );
|
||||
|
||||
/* Root tag */
|
||||
$xml->startElement('language');
|
||||
$xml->startAttribute('name');
|
||||
$xml->text( $lang->title );
|
||||
$xml->endAttribute();
|
||||
$xml->startAttribute('rtl');
|
||||
$xml->text( $lang->isrtl );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Loop applications */
|
||||
foreach ( \IPS\Application::applications() as $app )
|
||||
{
|
||||
/* Initiate the <app> tag */
|
||||
$xml->startElement('app');
|
||||
|
||||
/* Set key */
|
||||
$xml->startAttribute('key');
|
||||
$xml->text( $app->directory );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Set version */
|
||||
$xml->startAttribute('version');
|
||||
$xml->text( $app->long_version );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Add words */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_app=? AND word_export=1 AND word_custom IS NOT NULL', $lang->id, $app->directory ), 'word_id' ) as $row )
|
||||
$lang->author_name = $values['language_export_author_name'];
|
||||
$lang->author_url = $values['language_export_author_url'];
|
||||
$lang->update_url = $values['language_export_update_check'];
|
||||
$lang->version = $values['language_export_version'];
|
||||
$lang->version_long = (int) $values['language_export_long_version'];
|
||||
$lang->save();
|
||||
|
||||
$count = 0;
|
||||
try
|
||||
{
|
||||
/* Start */
|
||||
$xml->startElement( 'word' );
|
||||
|
||||
/* Add key */
|
||||
$xml->startAttribute('key');
|
||||
$xml->text( $row['word_key'] );
|
||||
$count = \IPS\Db::i()->select( 'COUNT(word_id)', 'core_sys_lang_words', array( 'lang_id=? AND word_export=1 AND word_custom IS NOT NULL', $lang->id ), 'word_id', NULL, 'word_id' )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
|
||||
if ( $count < 1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'core_lang_download_empty', '1C126/7', 404, '' );
|
||||
}
|
||||
|
||||
/* Init */
|
||||
$xml = new \XMLWriter;
|
||||
$xml->openMemory();
|
||||
$xml->setIndent( TRUE );
|
||||
$xml->startDocument( '1.0', 'UTF-8' );
|
||||
|
||||
/* Root tag */
|
||||
$xml->startElement( 'language' );
|
||||
$xml->startAttribute( 'name' );
|
||||
$xml->text( $lang->title );
|
||||
$xml->endAttribute();
|
||||
$xml->startAttribute( 'rtl' );
|
||||
$xml->text( $lang->isrtl );
|
||||
$xml->endAttribute();
|
||||
|
||||
$xml->startAttribute( 'author_name' );
|
||||
$xml->text( $lang->author_name );
|
||||
$xml->endAttribute();
|
||||
$xml->startAttribute( 'author_url' );
|
||||
$xml->text( $lang->author_url );
|
||||
$xml->endAttribute();
|
||||
|
||||
$xml->startAttribute( 'version' );
|
||||
$xml->text( $lang->version );
|
||||
$xml->endAttribute();
|
||||
$xml->startAttribute( 'long_version' );
|
||||
$xml->text( $lang->version_long );
|
||||
$xml->endAttribute();
|
||||
|
||||
$xml->startAttribute( 'update_check' );
|
||||
$xml->text( $lang->update_url );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Loop applications */
|
||||
foreach ( \IPS\Application::applications() as $app )
|
||||
{
|
||||
/* Initiate the <app> tag */
|
||||
$xml->startElement( 'app' );
|
||||
|
||||
/* Set key */
|
||||
$xml->startAttribute( 'key' );
|
||||
$xml->text( $app->directory );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Is this a javascript string? */
|
||||
$xml->startAttribute('js');
|
||||
$xml->text( $row['word_js'] );
|
||||
/* Set version */
|
||||
$xml->startAttribute( 'version' );
|
||||
$xml->text( $app->version_long );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Write value */
|
||||
if ( preg_match( '/<|>|&/', $row['word_custom'] ) )
|
||||
|
||||
/* Add words */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_app=? AND word_export=1 AND word_custom IS NOT NULL', $lang->id, $app->directory ), 'word_id' ) as $row )
|
||||
{
|
||||
$xml->writeCData( str_replace( ']]>', ']]]]><![CDATA[>', $row['word_custom'] ) );
|
||||
/* Start */
|
||||
$xml->startElement( 'word' );
|
||||
|
||||
/* Add key */
|
||||
$xml->startAttribute( 'key' );
|
||||
$xml->text( $row['word_key'] );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Is this a javascript string? */
|
||||
$xml->startAttribute( 'js' );
|
||||
$xml->text( $row['word_js'] );
|
||||
$xml->endAttribute();
|
||||
|
||||
/* Write value */
|
||||
if ( preg_match( '/<|>|&/', $row['word_custom'] ) )
|
||||
{
|
||||
$xml->writeCData( str_replace( ']]>', ']]]]><![CDATA[>', $row['word_custom'] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml->text( $row['word_custom'] );
|
||||
}
|
||||
|
||||
/* End */
|
||||
$xml->endElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml->text( $row['word_custom'] );
|
||||
}
|
||||
|
||||
/* End */
|
||||
|
||||
/* </app> */
|
||||
$xml->endElement();
|
||||
}
|
||||
|
||||
/* </app> */
|
||||
$xml->endElement();
|
||||
|
||||
/* Finish */
|
||||
$xml->endDocument();
|
||||
\IPS\Output::i()->sendOutput( $xml->outputMemory(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', $lang->title . '.xml' ) ), FALSE, FALSE, FALSE );
|
||||
}
|
||||
|
||||
/* Finish */
|
||||
$xml->endDocument();
|
||||
\IPS\Output::i()->sendOutput( $xml->outputMemory(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', $lang->title . '.xml' ) ), FALSE, FALSE, FALSE );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Member::loggedIn()->language()->addToStack('language_export_title', FALSE, array( 'sprintf' => array( $lang->title ) ) ), $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -667,6 +866,13 @@ class _languages extends \IPS\Node\Controller
|
||||
public function uploadNewVersion()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'lang_words' );
|
||||
|
||||
$language = \IPS\Lang::load( \IPS\Request::i()->id );
|
||||
|
||||
if( $language->marketplace_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'app_upload_marketplace_only', '2C126/B', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'lang_upload', NULL, TRUE, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
|
||||
@@ -679,7 +885,7 @@ class _languages extends \IPS\Node\Controller
|
||||
move_uploaded_file( $values['lang_upload'], $tempFile );
|
||||
|
||||
/* Initate a redirector */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'into' => \IPS\Request::i()->id ) ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'into' => \IPS\Request::i()->id ) )->csrf() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
@@ -690,18 +896,24 @@ class _languages extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function import()
|
||||
public function import()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
if ( !file_exists( \IPS\Request::i()->file ) or md5_file( \IPS\Request::i()->file ) !== \IPS\Request::i()->key )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '3C126/6', 500, '' );
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => \IPS\Request::i()->file, 'key' => \IPS\Request::i()->key, 'locale' => \IPS\Request::i()->locale ) );
|
||||
$url = \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages&do=import' )->setQueryString( array( 'file' => \IPS\Request::i()->file, 'key' => \IPS\Request::i()->key, 'locale' => \IPS\Request::i()->locale ) )->csrf();
|
||||
if ( isset( \IPS\Request::i()->into ) )
|
||||
{
|
||||
$url = $url->setQueryString( 'into', \IPS\Request::i()->into );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->marketplace ) )
|
||||
{
|
||||
$url = $url->setQueryString( 'marketplace', \IPS\Request::i()->marketplace );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
$url,
|
||||
@@ -713,12 +925,23 @@ class _languages extends \IPS\Node\Controller
|
||||
$xml->read();
|
||||
|
||||
/* If this is the first batch, create the language record */
|
||||
if ( !is_array( $data ) )
|
||||
if ( !\is_array( $data ) )
|
||||
{
|
||||
/* Create the record */
|
||||
if ( isset( \IPS\Request::i()->into ) )
|
||||
{
|
||||
$insertId = \IPS\Request::i()->into;
|
||||
|
||||
\IPS\Db::i()->update( 'core_sys_lang', array(
|
||||
'lang_title' => $xml->getAttribute('name'),
|
||||
'lang_isrtl' => $xml->getAttribute('rtl'),
|
||||
'lang_version' => $xml->getAttribute('version'),
|
||||
'lang_version_long' => $xml->getAttribute('long_version'),
|
||||
'lang_author_name' => $xml->getAttribute('author_name'),
|
||||
'lang_author_url' => $xml->getAttribute('author_url'),
|
||||
'lang_update_url' => $xml->getAttribute('update_check')
|
||||
),
|
||||
array( 'lang_id=?', $insertId) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -738,19 +961,25 @@ class _languages extends \IPS\Node\Controller
|
||||
foreach( explode( ";", $currentLocale ) as $locale )
|
||||
{
|
||||
$parts = explode( "=", $locale );
|
||||
if( in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
|
||||
if( \in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
|
||||
{
|
||||
setlocale( constant( $parts[0] ), $parts[1] );
|
||||
setlocale( \constant( $parts[0] ), $parts[1] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert the language pack record */
|
||||
$max = \IPS\Db::i()->select( 'MAX(lang_order)', 'core_sys_lang' )->first();
|
||||
$insertId = \IPS\Db::i()->insert( 'core_sys_lang', array(
|
||||
'lang_short' => \IPS\Request::i()->locale,
|
||||
'lang_title' => $xml->getAttribute('name'),
|
||||
'lang_isrtl' => $xml->getAttribute('rtl'),
|
||||
'lang_order' => $max['max'] + 1
|
||||
'lang_short' => \IPS\Request::i()->locale,
|
||||
'lang_title' => $xml->getAttribute('name'),
|
||||
'lang_isrtl' => $xml->getAttribute('rtl'),
|
||||
'lang_order' => $max + 1,
|
||||
'lang_version' => $xml->getAttribute('version'),
|
||||
'lang_version_long' => $xml->getAttribute('long_version'),
|
||||
'lang_author_name' => $xml->getAttribute('author_name'),
|
||||
'lang_author_url' => $xml->getAttribute('author_url'),
|
||||
'lang_update_url' => $xml->getAttribute('update_check'),
|
||||
'lang_marketplace_id' => \IPS\Request::i()->marketplace ? (int) \IPS\Request::i()->marketplace : NULL
|
||||
) );
|
||||
|
||||
/* Copy over default language strings */
|
||||
@@ -780,7 +1009,7 @@ class _languages extends \IPS\Node\Controller
|
||||
while ( $xml->read() )
|
||||
{
|
||||
$appKey = $xml->getAttribute('key');
|
||||
if ( !array_key_exists( $appKey, $data['apps'] ) AND in_array( $appKey, $applications ) )
|
||||
if ( !array_key_exists( $appKey, $data['apps'] ) AND \in_array( $appKey, $applications ) )
|
||||
{
|
||||
/* Get version */
|
||||
$version = $xml->getAttribute('version');
|
||||
@@ -816,13 +1045,20 @@ class _languages extends \IPS\Node\Controller
|
||||
},
|
||||
function()
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->languages );
|
||||
/* Clear language caches, including update counter */
|
||||
unset( \IPS\Data\Store::i()->languages, \IPS\Data\Store::i()->listFormats, \IPS\Data\Store::i()->updatecount_languages );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
@unlink( \IPS\Request::i()->file );
|
||||
|
||||
/* Redirect back to marketplace if it was installed from there. */
|
||||
if( \IPS\Request::i()->marketplace )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=marketplace&controller=marketplace&do=viewFile&id=' . \IPS\Request::i()->marketplace ), 'lang_installed' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=languages&controller=languages' ) );
|
||||
}
|
||||
);
|
||||
@@ -835,11 +1071,13 @@ class _languages extends \IPS\Node\Controller
|
||||
*/
|
||||
protected function devimport()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=devimport&id=" . intval( \IPS\Request::i()->id ) ),
|
||||
\IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=devimport&id=" . \intval( \IPS\Request::i()->id ) )->csrf(),
|
||||
function ( $data )
|
||||
{
|
||||
if ( !is_array( $data ) )
|
||||
if ( !\is_array( $data ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_sys_lang_words', array( 'lang_id=? AND word_export=1', \IPS\Request::i()->id ) );
|
||||
return array( array(), \IPS\Member::loggedIn()->language()->addToStack('lang_dev_importing'), 1 );
|
||||
@@ -903,7 +1141,7 @@ class _languages extends \IPS\Node\Controller
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('lang_dev_importing'), ( 100 / ( count( \IPS\Application::applications() ) * 2 ) * count( $data ) ) );
|
||||
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('lang_dev_importing'), ( 100 / ( \count( \IPS\Application::applications() ) * 2 ) * \count( $data ) ) );
|
||||
},
|
||||
function ()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user