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( '
' . __('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 '
'; } // Import - echo '
' . - '
' . - 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";