diff --git a/index.php b/index.php index 5390f18..9172d9f 100644 --- a/index.php +++ b/index.php @@ -61,9 +61,9 @@ if (empty($type)) { } try { - if ($action == 'module_create_backup') { + if ($action == 'module_create_backups') { if (empty($module) || empty($_POST['codes'])) { - throw new Exception(__('No lang to backup')); + throw new Exception(__('Nothing to backup')); } $module_codes = $module->getUsedlangs(); foreach($module_codes as $code_id) { @@ -72,12 +72,12 @@ try { } } dcPage::addSuccessNotice(__('Backup successfully created')); - $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id], '#module-backup'); + $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_restore_backup') { if (empty($module) || empty($_POST['files'])) { - throw New Exception(__('No backup to restore')); + throw New Exception(__('Nothing to restore')); } $module_backups = $module->getBackups(true); foreach($module_backups as $backup_file) { @@ -86,12 +86,12 @@ try { } } dcPage::addSuccessNotice(__('Backup successfully restored')); - $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id], '#module-backup'); + $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_delete_backup') { if (empty($module) || empty($_POST['files'])) { - throw New Exception(__('No backup to delete')); + throw New Exception(__('Nothing to delete')); } $module_backups = $module->getBackups(true); foreach($module_backups as $backup_file) { @@ -100,7 +100,7 @@ try { } } dcPage::addSuccessNotice(__('Backup successfully deleted')); - $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id], '#module-backup'); + $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_export_pack') { @@ -109,8 +109,8 @@ try { } $module->exportPack($_POST['codes']); - dcPage::addSuccessNotice(__('Package successfully exported')); - $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id], '#module-pack'); + dcPage::addSuccessNotice(__('Language successfully exported')); + $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_import_pack') { @@ -119,33 +119,37 @@ try { } $module->importPack($_FILES['packfile']); - dcPage::addSuccessNotice(__('Package successfully imported')); - $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id], '#module-pack'); + dcPage::addSuccessNotice(__('Language successfully imported')); + $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); } if ($action == 'module_add_code') { if (empty($module) || empty($_POST['code'])) { - throw new Exception(__('No lang to create')); + throw new Exception(__('Nothing to create')); } $module->addLang($_POST['code'], $_POST['from'] ?? ''); - dcPage::addSuccessNotice(__('Lang successfully added')); + dcPage::addSuccessNotice(__('Language successfully added')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } - if ($action == 'module_delete_code') { - if (empty($module) || empty($_POST['code'])) { - throw new Exception(__('No lang to delete')); + if ($action == 'module_delete_codes') { + if (empty($module) || empty($_POST['codes'])) { + throw new Exception(__('Nothing to delete')); } - $module->delLang($_POST['code']); - - dcPage::addSuccessNotice(__('Lang successfully deleted')); + $module_codes = $module->getUsedlangs(); + foreach($module_codes as $code_id) { + if (in_array($code_id, $_POST['codes'])) { + $module->delLang($code_id); + } + } + dcPage::addSuccessNotice(__('Language successfully deleted')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } if ($action == 'module_update_code') { if (empty($module) || empty($_POST['code']) || empty($_POST['entries'])) { - throw new Exception(__('No lang to update')); + throw new Exception(__('Nothing to update')); } if (!empty($_POST['update_group'])) { foreach($_POST['entries'] as $i => $entry) { @@ -156,7 +160,7 @@ try { } $module->updLang($_POST['code'], $_POST['entries']); - dcPage::addSuccessNotice(__('Lang successfully updated')); + dcPage::addSuccessNotice(__('Language successfully updated')); $core->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } @@ -211,7 +215,7 @@ if (empty($module) && $type != '') { if ($module->root_writable) { $codes[$code_id] = sprintf( '%s (%s)', - html::escapeHTML(sprintf(__('Edit translation %s of the module %s'), html::escapeHTML($code_name), __($module->name))), + html::escapeHTML(sprintf(__('Edit language %s of module %s'), html::escapeHTML($code_name), __($module->name))), $core->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), html::escapeHTML($code_name), $code_id @@ -233,10 +237,10 @@ if (empty($module) && $type != '') { - - - - + + + + ' . $res . '
' . __('Name') . '' . __('Languages') . '' . __('Id') . '' . __('Version') . '' . __('Name') . '' . __('Languages') . '' . __('Id') . '' . __('Version') . '
'; @@ -251,50 +255,39 @@ if (empty($module) && $type != '') { $backups = $module->getBackups(); $unused_codes = $module->getUnusedLangs(); - // module summary - echo ' -
-

' . __('Module') . '

- - - - - - - - - - - - - - - - - -
' .__('Module summary') . '
' . __('Name') . ' ' . $module->name . '
' . __('Version') . ' ' . $module->version . '
' . __('Author') . ' ' . $module->author . '
' . __('Type') . ' ' . $module->type . '
' . __('Root') . ' ' . $module->root . '
' . __('Locales') . ' ' . $module->locales . '
' . __('Backups') . ' ' . $module->getBackupRoot() . '
+ // module summary + echo '

' . sprintf(__('Module %s %s by %s'), $module->name, $module->version, $module->author) . '

+

 

'; + + // existing languages if (count($codes)) { echo - '

' . __('Translations') . '

' . + '

' . __('Translations') . '

' . + '
' . '' . - '' . + '' . '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . ''; foreach($codes AS $code_name => $code_id) { echo '' . + '' . '' . - ''; + ''; if (isset($backups[$code_id])) { foreach($backups[$code_id] AS $file => $info) { @@ -303,143 +296,76 @@ if (empty($module) && $type != '') { } echo '' . - ''; } else { - echo ''; + echo ''; } echo ''; } - echo '
' . __('Existing module languages') .'' . __('Existing languages translations') .'
' . __('Languages') . '' . __('Code') . '' . __('Backups') . '' . __('Last backup') . '' . __('Languages') . '' . __('Code') . '' . __('Backups') . '' . __('Last backup') . '
' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '' . '' . $code_name . '' . + . '" title="' . sprintf(__('Edit %s language'), html::escapeHTML($code_name)) . '">' . $code_name . '' . ' ' . $code_id . ' ' . $code_id . '' . count($backups[$code_id]) . ' ' . + ' ' . dt::str('%Y-%m-%d %H:%M', $time[$code_id], $core->blog->settings->system->blog_timezone) . '' . __('no backup') . '-' . __('no backups') . '-
'; - } - echo '
'; + echo ' +
+

- // Add/Remove/Edit lang - echo '
'; - - // edit lang - if (!empty($codes)) { - echo '

' . __('Edit language') . '

- -

' . - form::combo(['lang'], $codes, $core->auth->getInfo('user_lang')) . '

-

' . - $core->formNonce() . +

' . __('Selected languages action:') . ' ' . + form::combo('action', [ + __('Backup languages') => 'module_create_backups', + __('Delete languages') => 'module_delete_codes', + __('Export languages') => 'module_export_pack' + ]) . ' +

' . + $core->formNonce() . $core->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id] ) . ' -

 

'; +

 

'; } - // add lang - if (!empty($unused_codes)) { - echo '

' . __('Add language') . '

-
-

' . - form::combo(['code'], array_merge(['-' => '-'], $unused_codes), $core->auth->getInfo('user_lang')) . '

'; - if (empty($codes)) { - echo '

' . form::hidden(['from'], '') . '

'; - } else { - echo - '

' . - form::combo(['from'], array_merge(['-' => ''], $codes)) . ' (' . __('Optionnal') . ')

'; - } - echo ' -

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( - 'translater', - ['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code'] - ) . ' -

 

'; - } - - // delete langs - if (!empty($codes)) { - echo '

' . __('Delete language') . '

-
-

' . - form::combo(['code'], array_merge(['-' => ''], $codes)) . '

-

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( - 'translater', - ['type' => $module->type, 'module' => $module->id, 'action' => 'module_delete_code'] - ) . ' -

 

'; - } - echo '
'; - // backups if (!empty($codes) || !empty($backups)) { - - echo '
'; - - // create backups - if (!empty($codes)) { - echo '

' . __('Create backups') . '

-
- - - '; - $i=0; - foreach($codes AS $code_name => $code_id) { - $i++; - echo ' - - - - - '; - } - echo ' -
' . __('Existing module languages') . '
' . __('Language') . '' . __('Code') . '
' . form::checkbox(['codes[]', 'backup_code_' . $code_id], $code_id, '', '', '', false) . '' . $code_id . '
-
-

- -

-

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( - 'translater', - ['type' => $module->type, 'module' => $module->id, 'action' => 'module_create_backup'] - ) . ' -

 

'; - } - // delete / retore backups if (!empty($backups)) { - echo '

' . __('List of backups') . '

' . - '
' . + echo '

' . __('Backups') . '

' . + '' . '' . - '' . + '' . '' . - '' . - '' . - '' . - '' . - '' . + '' . + '' . + '' . + '' . + '' . ''; + + $table_line = + '' . + '' . + '' . + '' . + '' . + '' . + '' . + ''; + $i=0; foreach($backups as $backup_codes) { foreach($backup_codes as $backup_file => $backup_code) { $i++; $form_id = 'form_file_' . $backup_code['code'] . $backup_code['time']; - echo - '' . - '' . - '' . - '' . - '' . - '' . - '' . - ''; + echo sprintf($table_line, + form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false), + $form_id, $backup_code['name'], + $backup_code['code'], + dt::str( + $core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format, + $backup_code['time'], + $core->blog->settings->system->blog_timezone + ), + $backup_code['path']['basename'], + files::size($backup_code['size']) + ); } } echo ' @@ -458,18 +384,39 @@ if (empty($module) && $type != '') { 'translater', ['type' => $module->type, 'module' => $module->id] ) . ' -

 

'; +

 

'; } - echo ''; } - // Import/Export pack - echo '
'; + echo '
'; + + // add language + if (!empty($unused_codes)) { + echo '

' . __('Add language') . '

+
+

' . + form::combo(['code'], array_merge(['-' => '-'], $unused_codes), $core->auth->getInfo('user_lang')) . '

'; + if (empty($codes)) { + echo '

' . form::hidden(['from'], '') . '

'; + } else { + echo + '

' . + form::combo(['from'], array_merge(['-' => ''], $codes)) . ' (' . __('Optionnal') . ')

'; + } + echo ' +

' . + $core->formNonce() . + $core->adminurl->getHiddenFormFields( + 'translater', + ['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code'] + ) . ' +

 

'; + } // Import - echo '

' . __('Import') . '

-
-

' . __('Import') . '

+ +

' . @@ -478,41 +425,8 @@ if (empty($module) && $type != '') { 'translater', ['type' => $module->type, 'module' => $module->id, 'action' => 'module_import_pack'] ) . ' -

 

'; +

 

'; - // Export - if (!empty($codes)) { - echo '

' . __('Export') . '

' . - '
' . - '
' . __('Existing backuped languages') . '' . __('Existing languages backups') . '
' . __('Name') . '' . __('Code') . '' . __('Date') . '' . __('File') . '' . __('Size') . '' . __('Name') . '' . __('Code') . '' . __('Date') . '' . __('File') . '' . __('Size') . '
%s%s%s%s%s
' . form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false) . '' . $backup_code['code'] . '' . dt::str( - $core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format, - $backup_code['time'], - $core->blog->settings->system->blog_timezone - ) . '' . $backup_code['path']['basename'] . '' . files::size($backup_code['size']) . '
' . - '' . - ''; - $i=0; - foreach($codes AS $code_name => $code_id) { - $i++; - echo - '' . - '' . - '' . - '' . - ''; - } - echo - '
' . __('Existing module languages') . '
' . __('Language') . '' . __('Code') . '
' . - form::checkbox(['codes[]', 'export_code_' . $code_id], $code_id, '', '', '', false) . - '' . $code_id . '
' . - '
' . - '

' . - - '

' . - '

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( - 'translater', - ['type' => $module->type, 'module' => $module->id, 'action' => 'module_export_pack'] - ) . - '

 

'; - } echo '
'; } elseif (!empty($lang)) { @@ -633,7 +547,7 @@ if (empty($module) && $type != '') { '

' . '

' . '
' . '

' . diff --git a/js/translater.js b/js/translater.js index f2aa1de..ddd55f2 100644 --- a/js/translater.js +++ b/js/translater.js @@ -1,23 +1,17 @@ /*global $, dotclear */ 'use strict'; $(function () { - $('#module-backup-create-form .checkboxes-helpers').each(function () { - dotclear.checkboxesHelpers(this, undefined, '#module-backup-create-form td input[type=checkbox]', '#module-backup-create-form #do-action'); + $('#module-translations-form .checkboxes-helpers').each(function () { + dotclear.checkboxesHelpers(this, undefined, '#module-translations-form td input[type=checkbox]', '#module-translations-form #do-action'); }); - $('#module-backup-create-form td input[type=checkbox]').enableShiftClick(); - dotclear.condSubmit('#module-backup-create-form td input[type=checkbox]', '#module-backup-create-form #do-action'); + $('#module-translations-form td input[type=checkbox]').enableShiftClick(); + dotclear.condSubmit('#module-translations-form td input[type=checkbox]', '#module-translations-form #do-action'); - $('#module-backup-edit-form .checkboxes-helpers').each(function () { - dotclear.checkboxesHelpers(this, undefined, '#module-backup-edit-form td input[type=checkbox]', '#module-backup-edit-form #do-action'); + $('#module-backups-form .checkboxes-helpers').each(function () { + dotclear.checkboxesHelpers(this, undefined, '#module-backups-form td input[type=checkbox]', '#module-backups-form #do-action'); }); - $('#module-backup-edit-form td input[type=checkbox]').enableShiftClick(); - dotclear.condSubmit('#module-backup-edit-form td input[type=checkbox]', '#module-backup-edit-form #do-action'); - - $('#module-pack-export-form .checkboxes-helpers').each(function () { - dotclear.checkboxesHelpers(this, undefined, '#module-pack-export-form td input[type=checkbox]', '#module-pack-export-form #do-action'); - }); - $('#module-pack-export-form td input[type=checkbox]').enableShiftClick(); - dotclear.condSubmit('#module-pack-export-form td input[type=checkbox]', '#module-pack-export-form #do-action'); + $('#module-backups-form td input[type=checkbox]').enableShiftClick(); + dotclear.condSubmit('#module-backups-form td input[type=checkbox]', '#module-backups-form #do-action'); $('#lang-edit-form .checkboxes-helpers').each(function () { dotclear.checkboxesHelpers(this, undefined, '#lang-edit-form td input[type=checkbox]', undefined);