auth->isSuperAdmin() && version_compare(phpversion(), My::PHP_MIN, '>='); } return self::$init; } public static function process(): bool { if (!self::$init) { 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 = ''; } } // execute action try { if ($action == 'module_create_backups') { if (empty(dcCore::app()->admin->module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to backup')); } $module_codes = dcCore::app()->admin->module->getUsedlangs(); foreach ($module_codes as $code_id) { if (in_array($code_id, $_POST['codes'])) { dcCore::app()->admin->module->createBackup($code_id); } } self::redirect(__('Backup successfully created')); } if ($action == 'module_restore_backup') { if (empty(dcCore::app()->admin->module) || empty($_POST['files'])) { throw new Exception(__('Nothing to restore')); } $module_backups = dcCore::app()->admin->module->getBackups(true); foreach ($module_backups as $backup_file) { if (in_array($backup_file, $_POST['files'])) { dcCore::app()->admin->module->restoreBackup($backup_file); } } self::redirect(__('Backup successfully restored')); } if ($action == 'module_delete_backup') { if (empty(dcCore::app()->admin->module) || empty($_POST['files'])) { throw new Exception(__('Nothing to delete')); } $module_backups = dcCore::app()->admin->module->getBackups(true); foreach ($module_backups as $backup_file) { if (in_array($backup_file, $_POST['files'])) { dcCore::app()->admin->module->deleteBackup($backup_file); } } self::redirect(__('Backup successfully deleted')); } if ($action == 'module_export_pack') { if (empty(dcCore::app()->admin->module) || empty($_POST['codes'])) { throw new Exception(__('Nothing to export')); } dcCore::app()->admin->module->exportPack($_POST['codes']); self::redirect(__('Language successfully exported')); } if ($action == 'module_import_pack') { if (empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } dcCore::app()->admin->module->importPack($_FILES['packfile']); self::redirect(__('Language successfully imported')); } if ($action == 'module_add_code') { if (empty(dcCore::app()->admin->module) || empty($_POST['code'])) { throw new Exception(__('Nothing to create')); } dcCore::app()->admin->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'])) { throw new Exception(__('Nothing to delete')); } $module_codes = dcCore::app()->admin->module->getUsedlangs(); foreach ($module_codes as $code_id) { if (in_array($code_id, $_POST['codes'])) { dcCore::app()->admin->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'])) { throw new Exception(__('Nothing to update')); } if (!empty($_POST['update_group'])) { foreach ($_POST['entries'] as $i => $entry) { if (isset($entry['check']) && isset($_POST['multigroup'])) { $_POST['entries'][$i]['group'] = $_POST['multigroup']; } } } dcCore::app()->admin->module->updLang($_POST['code'], $_POST['entries']); self::redirect(__('Language successfully updated'), $_POST['code']); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } return true; } public static function render(): void { if (!self::$init) { return; } $breadcrumb = [My::name() => dcCore::app()->adminurl->get(My::id(), ['type' => '-'])]; if (empty(dcCore::app()->admin->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))] = ''; } dcPage::openModule( My::name(), dcPage::jsPageTabs() . dcPage::cssModuleLoad(My::id() . '/css/backend.css') . dcPage::jsJson('translater', [ 'title_add_detail' => __('Use this text'), 'image_field' => dcPage::getPF(My::id() . '/img/field.png'), 'image_toggle' => dcPage::getPF(My::id() . '/img/toggle.png'), ]) . dcPage::jsModuleLoad(My::id() . '/js/backend.js') . # --BEHAVIOR-- translaterAdminHeaders dcCore::app()->callBehavior('translaterAdminHeaders') ); echo dcPage::breadcrumb($breadcrumb) . dcPage::notices(); if (empty(dcCore::app()->admin->module) && dcCore::app()->admin->type != '') { // modules list echo '
'; dcPage::helpBlock('translater.type'); } elseif (!empty(dcCore::app()->admin->module) && empty(dcCore::app()->admin->lang)) { $codes = dcCore::app()->admin->module->getUsedLangs(); $backups = dcCore::app()->admin->module->getBackups(); $unused_codes = dcCore::app()->admin->module->getUnusedLangs(); // module summary echo ''; // existing languages if (count($codes)) { echo '
' . '