From f0debe050ff60bb9efb5c936fcc95b5dbf2246ad Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 7 Apr 2023 23:32:00 +0200 Subject: [PATCH] use Dotclear Helper --- src/BackendBehaviors.php | 4 +- src/Config.php | 3 +- src/Exception.php | 21 ---- src/Install.php | 11 +- src/Manage.php | 229 ++++++++++++++++++++++----------------- src/ManageVars.php | 1 + src/Translater.php | 17 +-- src/TranslaterLang.php | 8 +- src/TranslaterModule.php | 58 +++++----- 9 files changed, 183 insertions(+), 169 deletions(-) delete mode 100644 src/Exception.php diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index c42654a..a0f0331 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -17,7 +17,7 @@ namespace Dotclear\Plugin\translater; use adminModulesList; use dcCore; use Dotclear\Helper\Html\Form\Submit; -use html; +use Dotclear\Helper\Html\Html; class BackendBehaviors { @@ -61,7 +61,7 @@ class BackendBehaviors return null; } - return (new Submit(['translater[' . html::escapeHTML($id) . ']', null]))->value(__('Translate'))->render(); + return (new Submit(['translater[' . Html::escapeHTML($id) . ']', null]))->value(__('Translate'))->render(); } /** diff --git a/src/Config.php b/src/Config.php index d3a967c..0e2295a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -17,7 +17,6 @@ namespace Dotclear\Plugin\translater; use dcCore; use dcNsProcess; use dcPage; - use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -30,6 +29,8 @@ use Dotclear\Helper\Html\Form\{ Para, Select }; +use Dotclear\Helper\Html\Html; +use Exception; class Config extends dcNsProcess { diff --git a/src/Exception.php b/src/Exception.php deleted file mode 100644 index 3279487..0000000 --- a/src/Exception.php +++ /dev/null @@ -1,21 +0,0 @@ -fetch()) { - if (preg_match('/^translater_(.*?)$/', $record->setting_id, $match)) { + if (preg_match('/^translater_(.*?)$/', $record->f('setting_id'), $match)) { $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); - $cur->setting_id = $match[1]; - $cur->setting_ns = My::id(); + $cur->setField('setting_id', $match[1]); + $cur->setField('setting_ns', My::id()); $cur->update( - "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'translater' " . - 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' ")) + "WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'translater' " . + 'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->f('blog_id')) . "' ")) ); } } diff --git a/src/Manage.php b/src/Manage.php index 3bb5ea2..29c50ca 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -17,10 +17,23 @@ namespace Dotclear\Plugin\translater; use dcCore; use dcNsProcess; use dcPage; +use Dotclear\Helper\File\Files; +use Dotclear\Helper\Html\Form\{ + Checkbox, + File, + Form, + Hidden, + Input, + Label, + Note, + Para, + Select, + Submit, + Text +}; +use Dotclear\Helper\Html\Html; +use Exception; use dt; -use html; -use files; -use form; class Manage extends dcNsProcess { @@ -159,11 +172,11 @@ class Manage extends dcNsProcess $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)] = ''; + $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))] = ''; + $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( @@ -200,13 +213,13 @@ class Manage extends dcNsProcess $res .= sprintf( '%s', dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id]), - html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))), - html::escapeHTML($module->id) + Html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))), + Html::escapeHTML($module->id) ); } else { $res .= sprintf( '%s', - html::escapeHTML($module->id) + Html::escapeHTML($module->id) ); } $codes = $module->getLangs(); @@ -214,19 +227,19 @@ class Manage extends dcNsProcess if ($module->root_writable) { $codes[$code_id] = sprintf( '%s (%s)', - html::escapeHTML(sprintf(__('Edit language %s of module %s'), html::escapeHTML($code_name), __($module->name))), + Html::escapeHTML(sprintf(__('Edit language %s of module %s'), Html::escapeHTML($code_name), __($module->name))), dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), - html::escapeHTML($code_name), + Html::escapeHTML($code_name), $code_id ); } else { - $codes[$code_id] = html::escapeHTML($code_name) . '(' . $code_id . ')'; + $codes[$code_id] = Html::escapeHTML($code_name) . '(' . $code_id . ')'; } } $res .= sprintf( '%s%s%s', implode(', ', $codes), - html::escapeHTML(__($module->name)), + Html::escapeHTML(__($module->name)), $module->version ); } @@ -280,11 +293,11 @@ class Manage extends dcNsProcess foreach ($codes as $code_name => $code_id) { echo '' . - '' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '' . + '' . (new Checkbox(['codes[]', 'existing_code_' . $code_id]))->value($code_id)->render() . '' . '' . '' . $code_name . '' . + . '" title="' . sprintf(__('Edit %s language'), Html::escapeHTML($code_name)) . '">' . $code_name . '' . '' . ' ' . $code_id . ''; @@ -306,21 +319,23 @@ class Manage extends dcNsProcess } echo '
-

+

' . -

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

' . - dcCore::app()->formNonce() . - dcCore::app()->adminurl?->getHiddenFormFields( - My::id(), - ['type' => $current->module->type, 'module' => $current->module->id] - ) . ' -

 

'; + (new Para())->class('col right')->items(array_merge([ + (new Text('', __('Selected languages action:'))), + (new Select('action'))->items([ + __('Backup languages') => 'module_create_backups', + __('Delete languages') => 'module_delete_codes', + __('Export languages') => 'module_export_pack', + ]), + (new Submit('do-action'))->value(__('ok')), + dcCore::app()->formNonce(false), + ], dcCore::app()->adminurl?->hiddenFormFields( + My::id(), + ['type' => $current->module->type, 'module' => $current->module->id] + ) + ))->render() . + '

 

'; } // backups @@ -355,7 +370,7 @@ class Manage extends dcNsProcess $form_id = 'form_file_' . $backup_code['code'] . $backup_code['time']; echo sprintf( $table_line, - form::checkbox(['files[]', $form_id], $backup_file, '', '', '', false), + (new Checkbox(['files[]', $form_id]))->value($backup_file)->render(), $form_id, $backup_code['name'], $backup_code['code'], @@ -365,27 +380,29 @@ class Manage extends dcNsProcess dcCore::app()->blog?->settings->get('system')->get('blog_timezone') ), $backup_code['path']['basename'], - files::size($backup_code['size']) + Files::size($backup_code['size']) ); } } echo '
-

+

' . -

' . __('Selected backups action:') . ' ' . - form::combo('action', [ - __('Restore backups') => 'module_restore_backup', - __('Delete backups') => 'module_delete_backup', - ]) . ' -

' . - dcCore::app()->formNonce() . - dcCore::app()->adminurl?->getHiddenFormFields( - My::id(), - ['type' => $current->module->type, 'module' => $current->module->id] - ) . ' -

 

'; + (new Para())->class('col right')->items(array_merge([ + (new Text('', __('Selected backups action:'))), + (new Select('action'))->items([ + __('Restore backups') => 'module_restore_backup', + __('Delete backups') => 'module_delete_backup', + ]), + (new Submit('do-action'))->value(__('ok')), + dcCore::app()->formNonce(false), + ], dcCore::app()->adminurl?->hiddenFormFields( + My::id(), + ['type' => $current->module->type, 'module' => $current->module->id] + ) + ))->render() . + '

 

'; } } @@ -394,39 +411,52 @@ class Manage extends dcNsProcess // add language if (!empty($unused_codes)) { echo '

' . __('Add language') . '

-
-

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

'; + ' . + (new Para())->class('field')->items([ + (new Label(__('Select language:')))->for('code'), + (new Select(['code']))->default((string) dcCore::app()->auth?->getInfo('user_lang'))->items(array_merge(['-' => '-'], $unused_codes)), + ])->render(); + if (empty($codes)) { - echo '

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

'; + echo (new Para())->items([(new Hidden(['from'], ''))])->render(); } else { echo - '

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

'; + (new Para())->class('field')->items([ + (new Label(__('Copy from language:')))->for('from'), + (new Select(['from']))->items(array_merge(['-' => ''], $codes)), + (new Note())->class('form-note')->text(__('optionnal')), + ])->render(); } - echo ' -

' . - dcCore::app()->formNonce() . - dcCore::app()->adminurl?->getHiddenFormFields( - My::id(), - ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code'] - ) . ' -

 

'; + echo + (new Para())->items(array_merge([ + (new Submit(['save']))->value(__('Create')), + dcCore::app()->formNonce(false), + ], dcCore::app()->adminurl?->hiddenFormFields( + My::id(), + ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code'] + ) + ))->render() . + '

 

'; } // Import - echo '

' . __('Import') . '

-
-

-

- ' . - dcCore::app()->formNonce() . - dcCore::app()->adminurl?->getHiddenFormFields( - My::id(), - ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack'] - ) . ' -

 

'; + echo '

' . __('Import') . '

' . + (new Form('module-pack-import-form'))->method('post')->action(dcCore::app()->adminurl?->get(My::id()))->extra('enctype="multipart/form-data"')->fields([ + (new Para())->items([ + (new Label(__('Select languages package to import:')))->for('packfile'), + (new File('packfile')), + + ]), + (new Para())->items(array_merge([ + (new Submit(['save']))->value(__('Import')), + dcCore::app()->formNonce(false), + ], dcCore::app()->adminurl?->hiddenFormFields( + My::id(), + ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack'] + ) + )), + ])->render() . + '

 

'; echo ''; @@ -473,9 +503,9 @@ class Manage extends dcNsProcess foreach ($strin as $k => $v) { $res = []; foreach ($v as $str) { - $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); + $res[] = sprintf($table_li, Html::escapeHTML($str['module'] . ':' . $str['file'])); } - $t_msgstr[] = sprintf($table_ul, html::escapeHTML((string) $k), implode('', $res)); + $t_msgstr[] = sprintf($table_ul, Html::escapeHTML((string) $k), implode('', $res)); } if (!empty($rs['files'][0])) { @@ -494,11 +524,11 @@ class Manage extends dcNsProcess echo sprintf( $table_line, $in_dc ? ' offline' : ' translaterline', - form::checkbox(['entries[' . $i . '][check]'], 1), - form::combo(['entries[' . $i . '][group]'], My::l10nGroupsCombo(), $rs['group'], '', '', $in_dc), - html::escapeHTML($msgid), - form::hidden(['entries[' . $i . '][msgid]'], html::escapeHTML($msgid)) . - form::field(['entries[' . $i . '][msgstr][0]'], 48, 255, html::escapeHTML($rs['msgstr'][0]), '', '', $in_dc), + (new Checkbox(['entries[' . $i . '][check]']))->value(1)->render(), + (new Select(['entries[' . $i . '][group]']))->default($rs['group'])->items(My::l10nGroupsCombo())->disabled($in_dc)->render(), + Html::escapeHTML($msgid), + (new Hidden(['entries[' . $i . '][msgid]'], Html::escapeHTML($msgid)))->render() . + (new Input(['entries[' . $i . '][msgstr][0]']))->size(48)->maxlenght(255)->value(Html::escapeHTML($rs['msgstr'][0]))->disabled($in_dc)->render(), implode('', $t_msgstr), implode('', $t_files) ); @@ -517,9 +547,9 @@ class Manage extends dcNsProcess foreach ($strin as $k => $v) { $res = []; foreach ($v as $str) { - $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); + $res[] = sprintf($table_li, Html::escapeHTML($str['module'] . ':' . $str['file'])); } - $t_msgstr[] = sprintf($table_ul, html::escapeHTML((string) $k), implode('', $res)); + $t_msgstr[] = sprintf($table_ul, Html::escapeHTML((string) $k), implode('', $res)); } echo sprintf( @@ -528,8 +558,8 @@ class Manage extends dcNsProcess '+', sprintf(__('Plural "%s"'), $plural), sprintf(__('Plural form of "%s"'), $rs['plural']), - form::hidden(['entries[' . $i . '][msgid_plural]'], html::escapeHTML($rs['plural'])) . - form::field(['entries[' . $i . '][msgstr][' . ($j + 1) . ']'], 48, 255, html::escapeHTML($rs['msgstr'][$j + 1] ?? ''), '', '', $in_dc), + (new Hidden(['entries[' . $i . '][msgid_plural]'], Html::escapeHTML($rs['plural'])))->render() . + (new Input(['entries[' . $i . '][msgstr][' . ($j + 1) . ']']))->size(48)->maxlenght(255)->value(Html::escapeHTML($rs['msgstr'][$j + 1] ?? ''))->disbaled($in_dc)->render(), implode('', $t_msgstr), '' ); @@ -540,10 +570,10 @@ class Manage extends dcNsProcess echo sprintf( $table_line, ' offline', - form::checkbox(['entries[' . $i . '][check]'], 1), - form::combo(['entries[' . $i . '][group]'], My::l10nGroupsCombo(), 'main'), - form::field(['entries[' . $i . '][msgid]'], 48, 255, ''), - form::field(['entries[' . $i . '][msgstr][0]'], 48, 255, ''), + (new Checkbox(['entries[' . $i . '][check]']))->value(1)->render(), + (new Select(['entries[' . $i . '][group]']))->items(My::l10nGroupsCombo())->default('main')->render(), + (new Input(['entries[' . $i . '][msgid]']))->size(48)->maxlenght(255)->render(), + (new Input(['entries[' . $i . '][msgstr][0]']))->size(48)->maxlenght(255)->render(), '', '' ); @@ -553,20 +583,23 @@ class Manage extends dcNsProcess '
' . '
' . '

' . - '

' . + + (new Para())->items([ + (new Checkbox('update_group'))->value(1), + (new Label(__('Change the group of the selected translations to:'), Label::OUTSIDE_LABEL_AFTER))->for('update_group')->class('classic'), + (new Select('multigroup'))->items(My::l10nGroupsCombo()), + ])->render() . + '
' . + (new Para())->class('col right')->items(array_merge([ + (new Submit('do-action'))->value(__('Save') . ' (s)')->accesskey('s'), + dcCore::app()->formNonce(false), + (new Hidden(['code'], $current->lang->code)), + ], dcCore::app()->adminurl?->hiddenFormFields( + My::id(), + ['type' => $current->module?->type, 'module' => $current->module?->id, 'lang' => $current->lang->code, 'action' => 'module_update_code'] + ) + ))->render() . '
' . - '

' . - '

' . - dcCore::app()->formNonce() . - form::hidden(['code'], $current->lang->code) . - dcCore::app()->adminurl?->getHiddenFormFields( - My::id(), - ['type' => $current->module?->type, 'module' => $current->module?->id, 'lang' => $current->lang->code, 'action' => 'module_update_code'] - ) . - '

' . '' . '

 

' . ''; diff --git a/src/ManageVars.php b/src/ManageVars.php index 71864c3..3baba17 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\translater; use dcCore; +use Exception; class ManageVars { diff --git a/src/Translater.php b/src/Translater.php index 7035bb3..df1b5f1 100644 --- a/src/Translater.php +++ b/src/Translater.php @@ -17,10 +17,11 @@ namespace Dotclear\Plugin\translater; use dcCore; use dcModuleDefine; use dcThemes; -use files; +use Dotclear\Helper\File\Files; +use Dotclear\Helper\File\Path; +use Dotclear\Helper\Text; +use Exception; use l10n; -use path; -use text; /** * Translater tools. @@ -133,12 +134,12 @@ class Translater extends Settings */ public static function scandir(string $path, string $dir = '', array $res = []): array { - $path = (string) path::real($path, false); + $path = (string) Path::real($path, false); if (empty($path) || !is_dir($path) || !is_readable($path)) { return []; } - $files = files::scandir($path); + $files = Files::scandir($path); foreach ($files as $file) { if (in_array($file, ['.', '..'])) { continue; @@ -163,7 +164,7 @@ class Translater extends Settings */ public static function encodeMsg(string $str): string { - return text::toUTF8(stripslashes(trim($str))); + return Text::toUTF8(stripslashes(trim($str))); } /** @@ -195,7 +196,7 @@ class Translater extends Settings */ public static function isPoFile(string $file): bool { - return files::getExtension($file) == 'po'; + return Files::getExtension($file) == 'po'; } /** @@ -206,7 +207,7 @@ class Translater extends Settings */ public static function isLangphpFile(string $file): bool { - return files::getExtension($file) == 'php' && stristr($file, '.lang.php'); + return Files::getExtension($file) == 'php' && stristr($file, '.lang.php'); } /** diff --git a/src/TranslaterLang.php b/src/TranslaterLang.php index 8a1ddd7..0b1fb14 100644 --- a/src/TranslaterLang.php +++ b/src/TranslaterLang.php @@ -15,9 +15,9 @@ declare(strict_types=1); namespace Dotclear\Plugin\translater; use dcModuleDefine; -use files; +use Dotclear\Helper\File\Files; +use Dotclear\Helper\File\Path; use l10n; -use path; class TranslaterLang { @@ -123,7 +123,7 @@ class TranslaterLang $files = Translater::scandir($this->module->root); foreach ($files as $file) { - $extension = files::getExtension($file); + $extension = Files::getExtension($file); if (is_dir($this->module->root . DIRECTORY_SEPARATOR . $file) || !in_array($extension, $scan_ext)) { continue; } @@ -171,7 +171,7 @@ class TranslaterLang continue; } $scanned[] = $file; - $path = path::clean($this->module->locales . DIRECTORY_SEPARATOR . $file); + $path = Path::clean($this->module->locales . DIRECTORY_SEPARATOR . $file); if (Translater::isPoFile($file)) { $po = l10n::parsePoFile($path); diff --git a/src/TranslaterModule.php b/src/TranslaterModule.php index bd82fa6..fd117e9 100644 --- a/src/TranslaterModule.php +++ b/src/TranslaterModule.php @@ -16,13 +16,14 @@ namespace Dotclear\Plugin\translater; use dcCore; use dcModuleDefine; +use Dotclear\Helper\File\Files; +use Dotclear\Helper\File\Path; +use Dotclear\Helper\File\Zip\Unzip; +use Dotclear\Helper\File\Zip\Zip; +use Dotclear\Helper\Html\Html; +use Exception; use dt; -use html; -use files; -use fileZip; -use fileUnzip; use l10n; -use path; /** * Translater tools. @@ -68,7 +69,7 @@ class TranslaterModule $this->author = $define->get('author'); $this->version = $define->get('version'); $this->root_writable = $define->get('root_writable'); - $this->root = (string) path::real($define->get('root'), false); + $this->root = (string) Path::real($define->get('root'), false); $this->locales = $this->root . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER; } @@ -93,7 +94,7 @@ class TranslaterModule case 'plugin': $exp = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); - $tmp = path::real(array_pop($exp)); + $tmp = Path::real(array_pop($exp)); if ($tmp !== false && is_writable($tmp)) { $dir = $tmp; } @@ -101,7 +102,7 @@ class TranslaterModule break; case 'public': - $tmp = path::real((string) dcCore::app()->blog?->public_path); + $tmp = Path::real((string) dcCore::app()->blog?->public_path); if ($tmp !== false && is_writable($tmp)) { $dir = $tmp; } @@ -109,7 +110,7 @@ class TranslaterModule break; case 'cache': - $tmp = path::real(DC_TPL_CACHE); + $tmp = Path::real(DC_TPL_CACHE); if ($tmp !== false && is_writable($tmp)) { @mkDir($tmp . '/l10n'); $dir = $tmp . '/l10n'; @@ -118,7 +119,7 @@ class TranslaterModule break; case 'translater': - $tmp = path::real(dcCore::app()->plugins->moduleRoot(My::id())); + $tmp = Path::real(dcCore::app()->plugins->moduleRoot(My::id())); if ($tmp !== false && is_writable($tmp)) { @mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER); $dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER; @@ -166,7 +167,7 @@ class TranslaterModule } else { $res[$m[1]][$file]['code'] = $m[1]; $res[$m[1]][$file]['name'] = l10n::getLanguageName($m[1]); - $res[$m[1]][$file]['path'] = path::info($backup . '/' . $file); + $res[$m[1]][$file]['path'] = Path::info($backup . '/' . $file); $res[$m[1]][$file]['time'] = filemtime($backup . '/' . $file); $res[$m[1]][$file]['size'] = filesize($backup . '/' . $file); $res[$m[1]][$file]['module'] = $this->id; @@ -211,12 +212,10 @@ class TranslaterModule Translater::isBackupLimit($this->id, $backup, $this->translater->backup_limit, true); @set_time_limit(300); - $fp = fopen($backup . '/l10n-' . $this->id . '-' . $lang . '-' . time() . '.bck.zip', 'wb'); - $zip = new fileZip($fp); + $zip = new Zip($backup . '/l10n-' . $this->id . '-' . $lang . '-' . time() . '.bck.zip'); foreach ($res as $from => $to) { $zip->addFile($from, $to); } - $zip->write(); $zip->close(); unset($zip); @@ -243,7 +242,7 @@ class TranslaterModule )); } - $zip = new fileUnzip($backup . '/' . $file); + $zip = new Unzip($backup . '/' . $file); $zip_files = $zip->getFilesList(); foreach ($zip_files as $zip_file) { @@ -276,7 +275,7 @@ class TranslaterModule return false; } - if (!files::isDeletable($backup . '/' . $file)) { + if (!Files::isDeletable($backup . '/' . $file)) { throw new Exception(sprintf( __('Failed to delete file %s'), $file @@ -296,14 +295,14 @@ class TranslaterModule */ public function importPack(array $zip_file): bool { - files::uploadStatus($zip_file); + Files::uploadStatus($zip_file); $imported = false; $not_overwrited = []; $res = []; # Load Unzip object - $zip = new fileUnzip($zip_file['tmp_name']); + $zip = new Unzip($zip_file['tmp_name']); $files = $zip->getFilesList(); foreach ($files as $file) { @@ -326,7 +325,7 @@ class TranslaterModule foreach ($res as $rs) { if (!is_dir($rs['root'])) { - files::makeDir($rs['root'], true); + Files::makeDir($rs['root'], true); } $zip->unzip($rs['from'], $rs['to']); @@ -363,7 +362,7 @@ class TranslaterModule ); } - $filename = files::tidyFileName($this->translater->export_filename); + $filename = Files::tidyFileName($this->translater->export_filename); if (empty($filename)) { throw new Exception( __('Export mask is not set in plugin configuration') @@ -396,13 +395,12 @@ class TranslaterModule } @set_time_limit(300); - $fp = fopen('php://output', 'wb'); - $zip = new fileZip($fp); + $zip = new Zip('php://output'); foreach ($res as $from => $to) { $zip->addFile($from, $to); } - $filename = files::tidyFileName(dt::str(str_replace( + $filename = Files::tidyFileName(dt::str(str_replace( ['timestamp', 'module', 'type', 'version'], [time(), $this->id, $this->type, $this->version], $this->translater->export_filename @@ -410,7 +408,7 @@ class TranslaterModule header('Content-Disposition: attachment;filename=' . $filename . '.zip'); header('Content-Type: application/x-zip'); - $zip->write(); + $zip->close(); unset($zip); exit; } @@ -531,7 +529,7 @@ class TranslaterModule )); } - files::makeDir($this->locales . DIRECTORY_SEPARATOR . $lang, true); + Files::makeDir($this->locales . DIRECTORY_SEPARATOR . $lang, true); if (!empty($from_lang) && !isset($langs[$from_lang])) { throw new Exception(sprintf( @@ -550,7 +548,7 @@ class TranslaterModule continue; } - files::putContent( + Files::putContent( implode(DIRECTORY_SEPARATOR, [$this->locales, $lang, $file]), (string) file_get_contents(implode(DIRECTORY_SEPARATOR, [$this->locales, $from_lang, $file])) ); @@ -695,7 +693,7 @@ class TranslaterModule } $info = trim(str_replace($search, $replace, $this->translater->parse_userinfo)); if (!empty($info)) { - $content .= '# Author: ' . html::escapeHTML($info) . "\n"; + $content .= '# Author: ' . Html::escapeHTML($info) . "\n"; } } $content .= '# Translated with translater ' . dcCore::app()->plugins->moduleInfo(My::id(), 'version') . "\n\n"; @@ -741,7 +739,7 @@ class TranslaterModule } $file = implode(DIRECTORY_SEPARATOR, [$this->locales, $lang->code, $group . '.po']); - $path = path::info($file); + $path = Path::info($file); if (is_dir($path['dirname']) && !is_writable($path['dirname']) || file_exists($file) && !is_writable($file)) { throw new Exception(sprintf( @@ -750,7 +748,7 @@ class TranslaterModule )); } - if (!($f = @files::putContent($file, $content))) { + if (!($f = @Files::putContent($file, $content))) { throw new Exception(sprintf( __('Failed to write file %s'), $file @@ -787,7 +785,7 @@ class TranslaterModule } $info = trim(str_replace($search, $replace, $this->translater->parse_userinfo)); if (!empty($info)) { - $content .= '// Author: ' . html::escapeHTML($info) . "\n"; + $content .= '// Author: ' . Html::escapeHTML($info) . "\n"; } } $content .= '// Translated with Translater - ' . dcCore::app()->plugins->moduleInfo(My::id(), 'version') . "\n\n";