__('Settings'), 'modules_plugin' => __('Plugins'), 'modules_theme' => __('Themes'), 'pack' => __('Import/Export') ]; $combo_backup_limit = [ 5 => 5, 10 => 10, 15 => 15, 20 => 20, 40 => 40, 60 => 60 ]; $combo_backup_folder = [ 'module' => __('locales folders of each module'), 'plugin' => __('plugins folder root'), 'public' => __('public folder root'), 'cache' => __('cache folder of Dotclear'), 'translater' =>__('locales folder of translater') ]; $succes = [ 'save_setting' => __('Configuration successfully updated'), 'update_lang' => __('Translation successfully updated'), 'add_lang' => __('Translation successfully created'), 'delete_lang' => __('Translation successfully deleted'), 'create_backup' => __('Backups successfully create'), 'restore_backup' => __('Backups successfully restored'), 'delete_backup' => __('Backups successfully deleted'), 'import_pack' => __('Package successfully imported'), 'export_pack' => __('Package successfully exported') ]; $errors = [ 'save_setting' => __('Failed to update settings: %s'), 'update_lang' => __('Failed to update translation: %s'), 'add_lang' => __('Failed to create translation: %s'), 'delete_lang' => __('Failed to delete translation: %s'), 'create_backup' => __('Failed to create backups: %s'), 'restore_backup' => __('Failed to restore backups: %s'), 'delete_backup' => __('Failed to delete backups: %s'), 'import_pack' => __('Failed to import package: %s'), 'export_pack' => __('Failed to export package: %s') ]; $p_url = 'plugin.php?p=translater'; $start_page = @explode('_', $translater->start_page); if (count($start_page) < 2) { $start_page[1] = ''; } # # Parse request # $msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : $start_page[0]; $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : $start_page[1]; $module = isset($_REQUEST['module']) ? $_REQUEST['module'] : ''; $from = isset($_POST['from']) && $_POST['from'] != '-' ? $_POST['from'] : ''; $lang = isset($_REQUEST['lang']) && $_REQUEST['lang'] != '-' ? $_REQUEST['lang'] : ''; if ($type == '-' || $module == '-') { $type = $module = ''; } # # Manage action # switch ($action) { case '': break; /** * Create lang for a module */ case 'module_add_lang': try { if (empty($lang)) { throw new Exception(__('No lang to create')); } $translater->addLang($module, $lang, $from); http::redirect($p_url . '&part=lang&module=' . $module . '&type=' . $type . '&lang=' . $lang . '&msg=add_lang'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Delete lang for a module */ case 'module_delete_lang': try { if (empty($lang)) { throw new Exception(__('No lang to delete')); } $translater->delLang($module, $lang); http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-lang&msg=delete_lang'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Create backup for a module */ case 'module_create_backup': try { if (empty($_POST['modules']) || empty($_POST['langs'])) { throw new Exception(__('No lang to backup')); } foreach($_POST['modules'] as $b_module) { $b_list = $translater->listLangs($b_module); foreach($_POST['langs'] as $b_lang) { if (isset($b_list[$b_lang])) { $translater->createBackup($b_module, $b_lang); } } } http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-backup&msg=creat_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Restore backup for a module */ case 'module_restore_backup': try { if (empty($_POST['modules']) || empty($_POST['files'])) { throw New Exception(__('No blackup to restore')); } sort($_POST['files']); $done = false; foreach($_POST['modules'] as $b_module) { $b_list = $translater->listBackups($b_module, true); foreach($_POST['files'] as $b_file) { if (in_array($b_file, $b_list)) { $translater->restoreBackup($b_module, $b_file); $done = true; } } } if (!$done) { throw new Exception(__('No bakcup to to restore')); } http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-backup&msg=restore_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Delete backup for a module */ case 'module_delete_backup': try { if (empty($_POST['modules']) || empty($_POST['files'])) { throw New Exception(__('No backup to delete')); } $done = false; foreach($_POST['modules'] as $b_module) { $b_list = $translater->listBackups($b_module, true); foreach($_POST['files'] as $b_file) { if (in_array($b_file, $b_list)) { $translater->deleteBackup($b_module, $b_file); $done = true; } } } if (!$done) { throw new Exception(__('No backup to delete')); } http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-backup&msg=delete_backup'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action],$e->getMessage())); } break; /** * Import language package for a module */ case 'module_import_pack': try { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $translater->importPack($_POST['modules'], $_FILES['packfile']); http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-pack&msg=import_pack'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Export language package for a module */ case 'module_export_pack': try { if (empty($_POST['modules']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to export')); } $translater->exportPack($_POST['modules'], $_POST['entries']); http::redirect($p_url . '&part=module&module=' . $module . '&type=' . $type . '&tab=module-pack&msg=export_pack'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Update language */ case 'update_lang': try { if (empty($_POST['entries']) || empty($lang) || empty($module)) { throw new Exception(__('No language to update')); } foreach($_POST['entries'] as $i => $entry) { if (isset($entry['check']) && isset($_POST['multigroup'])) { $_POST['entries'][$i]['group'] = $_POST['multigroup']; unset($_POST['entries'][$i]['check']); } } $translater->updLang($module, $lang, $_POST['entries']); http::redirect($p_url . '&part=lang&module=' . $module . '&type=' . $type . '&lang=' . $lang . '&msg=' . $action); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Import language packages */ case 'import_pack': try { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $translater->importPack($_POST['modules'], $_FILES['packfile']); http::redirect($p_url . '&part=pack&msg=' . $action . '&tab=pack-import'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Export language packages */ case 'export_pack': try { if (empty($_POST['modules']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to export')); } $translater->exportPack($_POST['modules'], $_POST['entries']); http::redirect($p_url . '&part=pack&msg=' . $action . '&tab=pack-export'); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Save settings */ case 'save_setting': try { if (empty($_POST['translater_write_po']) && empty($_POST['translater_write_langphp'])) { throw new Exception('You must choose one file format at least'); } foreach($translater->getDefaultSettings() as $k => $v) { $translater->set($k,(isset($_POST['translater_' . $k]) ? $_POST['translater_' . $k] : '')); } foreach($translater->proposal->getTools() AS $k => $v) { $v->save(); } http::redirect($p_url . '&part=setting&msg=' . $action); } catch (Exception $e) { $core->error->add(sprintf($errors[$action], $e->getMessage())); } break; /** * Modules / Unknow / None */ default: break; } # # Fill in title and prepare display # switch ($part) { /** * Modules */ case 'modules': $title = '' . ($type == 'theme' ? __('Themes') : __('Plugins')) . ''; break; /** * Module */ case 'module': # Get info about requested module try { $M = $translater->getModule($module, $type); } catch(Exception $e) { $core->error->add(sprintf(__('Failed to launch translater: %s'), $e->getMessage())); $action = $module = $type = ''; $M = false; } if (!empty($module) && !empty($type) && !$M) { $action = $module = $type = ''; $M = false; } $M->langs = $translater->listLangs($module); $M->backups = $translater->listBackups($module); $M->unused_langs = array_flip(array_diff($translater->getIsoCodes(), $M->langs)); $M->used_langs = array_flip(array_diff($M->langs, array_flip($translater->getIsoCodes()))); $allowed_groups = array_combine( dcTranslater::$allowed_l10n_groups, dcTranslater::$allowed_l10n_groups ); $title = '' . ($type == 'theme' ? __('Themes') : __('Plugins')) . '' . ' › ' . $module . ''; break; /** * Lang */ case 'lang': # Get infos on module wanted try { $M = $translater->getModule($module, $type); # Retrieve some infos $M->langs = $translater->listLangs($module); $M->backups = $translater->listBackups($module); $M->unused_langs = array_flip(array_diff($translater->getIsoCodes(), $M->langs)); $M->used_langs = array_flip(array_diff($M->langs, array_flip($translater->getIsoCodes()))); $allowed_groups = array_combine( dcTranslater::$allowed_l10n_groups, dcTranslater::$allowed_l10n_groups ); } catch(Exception $e) { $core->error->add(sprintf(__('Failed to launch translater: %s'), $e->getMessage())); $action = $module = $type = ''; $M = false; } if (!empty($module) && !empty($type) && !$M) { $action = $module = $type = ''; $M = false; } $title = '' . ($type == 'theme' ? __('Themes') : __('Plugins')) . '' . ' › ' . '' . $module . ''; if (!empty($M->langs) && isset($M->langs[$lang])) { $title .= ' › ' . $M->langs[$lang] . ''; } break; /** * Import/Export (pack) */ case 'pack': $title = '' . __('Import/Export') . ''; break; /** * Settings */ case 'setting': default: $title = '' . __('Settings') . ''; break; } # # Display page # echo '
' . __('About') . ' | |
---|---|
' . __('Name') . ' | ' . $M->name . ' |
' . __('Version') . ' | ' . $M->version . ' |
' . __('Author') . ' | ' . $M->author . ' |
' . __('Type') . ' | ' . $M->type . ' |
' . __('Root') . ' | ' . $M->root . ' |
' . __('Backups') . ' | ' . $translater->getBackupFolder($module) . ' |
'; if (count($M->langs)) { echo '
' . __('Languages') . ' | ' . '' . __('Code') . ' | ' . '' . __('Backups') . ' | ' . '' . __('Last backup') . ' | ' . '||||
---|---|---|---|---|---|---|---|
' . '' . $name . '' . ' | ' . '' . $lang . ' | '; if (isset($M->backups[$lang])) { foreach($M->backups[$lang] AS $file => $info) { $time[$lang] = isset($time[$lang]) && $time[$lang] > $info['time'] ? $time[$lang] : $info['time']; } echo '' . count($M->backups[$lang]) . ' | ' . '' . dt::str('%Y-%m-%d %H:%M', $time[$lang], $core->blog->settings->system->blog_timezone) . ' | '; } else { echo '' . __('no backup') . ' | '; } echo '
'; } # New lang if (!empty($M->unused_langs)) { echo '
'; } # Delete lang if (!empty($M->used_langs)) { echo '
'; } echo '
'; } if (!empty($M->backups)) { echo '
'; } echo '
'; # Export if (!empty($M->used_langs)) { echo '
'; } echo '
' . '