diff --git a/src/Manage.php b/src/Manage.php index 576fbb6..171fdac 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -39,123 +39,91 @@ class Manage extends dcNsProcess return false; } - // set vars used in process and render methods - dcCore::app()->admin->translater = new Translater(); - dcCore::app()->admin->type = $_REQUEST['type'] ?? dcCore::app()->admin->translater->start_page ?: ''; - dcCore::app()->admin->module = $_REQUEST['module'] ?? ''; - dcCore::app()->admin->lang = $_REQUEST['lang'] ?? ''; - $action = $_POST['action'] ?? ''; - - // check module type - if (!in_array(dcCore::app()->admin->type, ['plugin', 'theme'])) { - dcCore::app()->admin->type = ''; - } - // check if module exists - if (!empty(dcCore::app()->admin->type) && !empty(dcCore::app()->admin->module)) { - try { - dcCore::app()->admin->module = dcCore::app()->admin->translater->getModule(dcCore::app()->admin->type, dcCore::app()->admin->module); - } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); - dcCore::app()->admin->module = ''; - } - } - //check if module lang exists - if (!empty(dcCore::app()->admin->module) && !empty(dcCore::app()->admin->lang)) { - try { - dcCore::app()->admin->lang = dcCore::app()->admin->translater->getLang(dcCore::app()->admin->module, dcCore::app()->admin->lang); - } catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); - dcCore::app()->admin->lang = ''; - } - } + $current = ManageContainer::init(); // execute action try { - if ($action == 'module_create_backups') { - if (empty(dcCore::app()->admin->module) || empty($_POST['codes'])) { + if ($current->action == 'module_create_backups') { + if (empty($current->module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to backup')); } - $module_codes = dcCore::app()->admin->module->getUsedlangs(); - foreach ($module_codes as $code_id) { + foreach ($current->module->getUsedlangs() as $code_id) { if (in_array($code_id, $_POST['codes'])) { - dcCore::app()->admin->module->createBackup($code_id); + $current->module->createBackup($code_id); } } self::redirect(__('Backup successfully created')); } - if ($action == 'module_restore_backup') { - if (empty(dcCore::app()->admin->module) || empty($_POST['files'])) { + if ($current->action == 'module_restore_backup') { + if (empty($current->module) || empty($_POST['files'])) { throw new Exception(__('Nothing to restore')); } - $module_backups = dcCore::app()->admin->module->getBackups(true); - foreach ($module_backups as $backup_file) { + foreach ($current->module->getBackups(true) as $backup_file) { if (in_array($backup_file, $_POST['files'])) { - dcCore::app()->admin->module->restoreBackup($backup_file); + $current->module->restoreBackup($backup_file); } } self::redirect(__('Backup successfully restored')); } - if ($action == 'module_delete_backup') { - if (empty(dcCore::app()->admin->module) || empty($_POST['files'])) { + if ($current->action == 'module_delete_backup') { + if (empty($current->module) || empty($_POST['files'])) { throw new Exception(__('Nothing to delete')); } - $module_backups = dcCore::app()->admin->module->getBackups(true); - foreach ($module_backups as $backup_file) { + foreach ($current->module->getBackups(true) as $backup_file) { if (in_array($backup_file, $_POST['files'])) { - dcCore::app()->admin->module->deleteBackup($backup_file); + $current->module->deleteBackup($backup_file); } } self::redirect(__('Backup successfully deleted')); } - if ($action == 'module_export_pack') { - if (empty(dcCore::app()->admin->module) || empty($_POST['codes'])) { + if ($current->action == 'module_export_pack') { + if (empty($current->module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to export')); } - dcCore::app()->admin->module->exportPack($_POST['codes']); + $current->module->exportPack($_POST['codes']); self::redirect(__('Language successfully exported')); } - if ($action == 'module_import_pack') { + if ($current->action == 'module_import_pack') { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } - dcCore::app()->admin->module->importPack($_FILES['packfile']); + $current->module->importPack($_FILES['packfile']); self::redirect(__('Language successfully imported')); } - if ($action == 'module_add_code') { - if (empty(dcCore::app()->admin->module) || empty($_POST['code'])) { + if ($current->action == 'module_add_code') { + if (empty($current->module) || empty($_POST['code'])) { throw new Exception(__('Nothing to create')); } - dcCore::app()->admin->module->addLang($_POST['code'], $_POST['from'] ?? ''); + $current->module->addLang($_POST['code'], $_POST['from'] ?? ''); self::redirect(__('Language successfully added'), $_POST['code']); } - if ($action == 'module_delete_codes') { - if (empty(dcCore::app()->admin->module) || empty($_POST['codes'])) { + if ($current->action == 'module_delete_codes') { + if (empty($current->module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to delete')); } - $module_codes = dcCore::app()->admin->module->getUsedlangs(); - foreach ($module_codes as $code_id) { + foreach ($current->module->getUsedlangs() as $code_id) { if (in_array($code_id, $_POST['codes'])) { - dcCore::app()->admin->module->delLang($code_id); + $current->module->delLang($code_id); } } self::redirect(__('Language successfully deleted'), $_POST['code']); } - if ($action == 'module_update_code') { - if (empty(dcCore::app()->admin->module) || empty($_POST['code']) || empty($_POST['entries'])) { + if ($current->action == 'module_update_code') { + if (empty($current->module) || empty($_POST['code']) || empty($_POST['entries'])) { throw new Exception(__('Nothing to update')); } if (!empty($_POST['update_group'])) { @@ -165,7 +133,7 @@ class Manage extends dcNsProcess } } } - dcCore::app()->admin->module->updLang($_POST['code'], $_POST['entries']); + $current->module->updLang($_POST['code'], $_POST['entries']); self::redirect(__('Language successfully updated'), $_POST['code']); } @@ -182,18 +150,20 @@ class Manage extends dcNsProcess return; } + $current = ManageContainer::init(); + $breadcrumb = [My::name() => dcCore::app()->adminurl->get(My::id(), ['type' => '-'])]; - if (empty(dcCore::app()->admin->type)) { + if (empty($current->type)) { $breadcrumb = [My::name() => '']; - } elseif (empty(dcCore::app()->admin->module)) { - $breadcrumb[dcCore::app()->admin->type == 'plugin' ? __('Plugins') : __('Themes')] = ''; - } elseif (empty(dcCore::app()->admin->lang)) { - $breadcrumb[dcCore::app()->admin->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(My::id(), ['type' => dcCore::app()->admin->type]); - $breadcrumb[html::escapeHTML(dcCore::app()->admin->module->name)] = ''; - } elseif (!empty(dcCore::app()->admin->lang)) { - $breadcrumb[dcCore::app()->admin->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(My::id(), ['type' => dcCore::app()->admin->type]); - $breadcrumb[html::escapeHTML(dcCore::app()->admin->module->name)] = dcCore::app()->adminurl->get(My::id(), ['type' => dcCore::app()->admin->type, 'module' => dcCore::app()->admin->module->id]); - $breadcrumb[html::escapeHTML(sprintf(__('%s language edition'), dcCore::app()->admin->lang->name))] = ''; + } elseif (empty($current->module)) { + $breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = ''; + } elseif (empty($current->lang)) { + $breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(My::id(), ['type' => $current->type]); + $breadcrumb[html::escapeHTML($current->module->name)] = ''; + } elseif (!empty($current->lang)) { + $breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(My::id(), ['type' => $current->type]); + $breadcrumb[html::escapeHTML($current->module->name)] = dcCore::app()->adminurl->get(My::id(), ['type' => $current->type, 'module' => $current->module->id]); + $breadcrumb[html::escapeHTML(sprintf(__('%s language edition'), $current->lang->name))] = ''; } dcPage::openModule( @@ -215,15 +185,15 @@ class Manage extends dcNsProcess dcPage::breadcrumb($breadcrumb) . dcPage::notices(); - if (empty(dcCore::app()->admin->module) && dcCore::app()->admin->type != '') { + if (empty($current->module) && $current->type != '') { // modules list echo '