diff --git a/src/Backend.php b/src/Backend.php index 8ab4859..b0fa89a 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -43,7 +43,7 @@ class Backend extends dcNsProcess 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl->get(My::id()), + 'url' => dcCore::app()->adminurl?->get(My::id()), 'small-icon' => urldecode(dcPage::getPF(My::id() . '/icon.svg')), 'large-icon' => urldecode(dcPage::getPF(My::id() . '/icon.svg')), //'permissions' => null, @@ -53,13 +53,13 @@ class Backend extends dcNsProcess dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( My::name(), - dcCore::app()->adminurl->get(My::id()), + dcCore::app()->adminurl?->get(My::id()), dcPage::getPF(My::id() . '/icon.svg'), preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get(My::id())) . '(&.*)?$/', + '/' . preg_quote((string) dcCore::app()->adminurl?->get(My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), - dcCore::app()->auth->isSuperAdmin() + dcCore::app()->auth?->isSuperAdmin() ); return true; diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index f6ed398..c42654a 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -51,7 +51,7 @@ class BackendBehaviors { if ($list->getList() != $prop['type'] . '-activate' || !self::translater()->getSetting($prop['type'] . '_menu') - || !dcCore::app()->auth->isSuperAdmin() + || !dcCore::app()->auth?->isSuperAdmin() ) { return null; } @@ -77,7 +77,7 @@ class BackendBehaviors return; } - dcCore::app()->adminurl->redirect( + dcCore::app()->adminurl?->redirect( My::id(), ['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])], '#module-lang' diff --git a/src/Config.php b/src/Config.php index 7c06103..d3a967c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -63,7 +63,7 @@ class Config extends dcNsProcess dcPage::addSuccessNotice( __('Configuration successfully updated.') ); - dcCore::app()->adminurl->redirect( + dcCore::app()->adminurl?->redirect( 'admin.plugins', ['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] ); diff --git a/src/Manage.php b/src/Manage.php index 7136507..3bb5ea2 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -92,7 +92,7 @@ class Manage extends dcNsProcess } if ($current->action == 'module_import_pack') { - if (empty($_FILES['packfile']['name'])) { + if (empty($current->module) || empty($_FILES['packfile']['name'])) { throw new Exception(__('Nothing to import')); } $current->module->importPack($_FILES['packfile']); @@ -146,23 +146,23 @@ class Manage extends dcNsProcess public static function render(): void { - if (!self::$init) { + if (!static::$init) { return; } $current = ManageVars::init(); - $breadcrumb = [My::name() => dcCore::app()->adminurl->get(My::id(), ['type' => '-'])]; + $breadcrumb = [My::name() => dcCore::app()->adminurl?->get(My::id(), ['type' => '-'])]; if (empty($current->type)) { $breadcrumb = [My::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[$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[$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))] = ''; } @@ -187,7 +187,7 @@ class Manage extends dcNsProcess if (empty($current->module) && $current->type != '') { // modules list - echo '
'; + echo ''; $res = ''; $modules = $current->translater->getModules($current->type); @@ -199,7 +199,7 @@ class Manage extends dcNsProcess if ($module->root_writable) { $res .= sprintf( '%s', - dcCore::app()->adminurl->get(My::id(), ['type' => $module->type, 'module' => $module->id]), + dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id]), html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))), html::escapeHTML($module->id) ); @@ -215,7 +215,7 @@ class Manage extends dcNsProcess $codes[$code_id] = sprintf( '%s (%s)', 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]), + dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), html::escapeHTML($code_name), $code_id ); @@ -267,7 +267,7 @@ class Manage extends dcNsProcess if (count($codes)) { echo '

' . __('Translations') . '

' . - '' . + '' . '' . '' . '' . @@ -283,7 +283,7 @@ class Manage extends dcNsProcess '' . '' . ''; @@ -297,7 +297,7 @@ class Manage extends dcNsProcess echo '' . ''; } else { echo ''; @@ -316,7 +316,7 @@ class Manage extends dcNsProcess ]) . '

' . dcCore::app()->formNonce() . - dcCore::app()->adminurl->getHiddenFormFields( + dcCore::app()->adminurl?->getHiddenFormFields( My::id(), ['type' => $current->module->type, 'module' => $current->module->id] ) . ' @@ -328,7 +328,7 @@ class Manage extends dcNsProcess // delete / retore backups if (!empty($backups)) { echo '

' . __('Backups') . '

' . - '' . + '' . '
' . __('Existing languages translations') . '
' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '' . '' . $code_name . '' . ' ' . $code_id . '' . count($backups[$code_id]) . ' ' . - dt::str('%Y-%m-%d %H:%M', (int) $time[$code_id], dcCore::app()->blog->settings->get('system')->get('blog_timezone')) . + dt::str('%Y-%m-%d %H:%M', (int) $time[$code_id], (string) dcCore::app()->blog?->settings->get('system')->get('blog_timezone')) . '' . __('no backups') . '-
' . '' . '' . @@ -360,9 +360,9 @@ class Manage extends dcNsProcess $backup_code['name'], $backup_code['code'], dt::str( - dcCore::app()->blog->settings->get('system')->get('date_format') . ' ' . dcCore::app()->blog->settings->get('system')->get('time_format'), + dcCore::app()->blog?->settings->get('system')->get('date_format') . ' ' . dcCore::app()->blog?->settings->get('system')->get('time_format'), (int) $backup_code['time'], - dcCore::app()->blog->settings->get('system')->get('blog_timezone') + dcCore::app()->blog?->settings->get('system')->get('blog_timezone') ), $backup_code['path']['basename'], files::size($backup_code['size']) @@ -381,7 +381,7 @@ class Manage extends dcNsProcess ]) . '

' . dcCore::app()->formNonce() . - dcCore::app()->adminurl->getHiddenFormFields( + dcCore::app()->adminurl?->getHiddenFormFields( My::id(), ['type' => $current->module->type, 'module' => $current->module->id] ) . ' @@ -394,9 +394,9 @@ class Manage extends dcNsProcess // add language if (!empty($unused_codes)) { echo '

' . __('Add language') . '

- +

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

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

'; if (empty($codes)) { echo '

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

'; } else { @@ -407,7 +407,7 @@ class Manage extends dcNsProcess echo '

' . dcCore::app()->formNonce() . - dcCore::app()->adminurl->getHiddenFormFields( + dcCore::app()->adminurl?->getHiddenFormFields( My::id(), ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code'] ) . ' @@ -416,13 +416,13 @@ class Manage extends dcNsProcess // Import echo '

' . __('Import') . '

- +

' . dcCore::app()->formNonce() . - dcCore::app()->adminurl->getHiddenFormFields( + dcCore::app()->adminurl?->getHiddenFormFields( My::id(), ['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack'] ) . ' @@ -437,7 +437,7 @@ class Manage extends dcNsProcess echo '

' . - '' . + '' . '
' . __('Existing languages backups') . '
' . '' . '' . @@ -475,7 +475,7 @@ class Manage extends dcNsProcess foreach ($v as $str) { $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); } - $t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res)); + $t_msgstr[] = sprintf($table_ul, html::escapeHTML((string) $k), implode('', $res)); } if (!empty($rs['files'][0])) { @@ -519,7 +519,7 @@ class Manage extends dcNsProcess foreach ($v as $str) { $res[] = sprintf($table_li, html::escapeHTML($str['module'] . ':' . $str['file'])); } - $t_msgstr[] = sprintf($table_ul, html::escapeHTML($k), implode('', $res)); + $t_msgstr[] = sprintf($table_ul, html::escapeHTML((string) $k), implode('', $res)); } echo sprintf( @@ -562,9 +562,9 @@ class Manage extends dcNsProcess '

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

' . '' . @@ -579,13 +579,13 @@ class Manage extends dcNsProcess '

    %s

', sprintf( $line, - dcCore::app()->adminurl->get(My::id(), ['type' => 'plugin']), + dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']), $current->type == 'plugin' ? ' class="active"' : '', __('Translate plugins') ) . sprintf( $line, - dcCore::app()->adminurl->get(My::id(), ['type' => 'theme']), + dcCore::app()->adminurl?->get(My::id(), ['type' => 'theme']), $current->type == 'theme' ? ' class="active"' : '', __('Translate themes') ) @@ -603,13 +603,13 @@ class Manage extends dcNsProcess $redir = [ 'type' => $current->type, - 'module' => $current->module->id, + 'module' => $current->module?->id, ]; if ($lang) { $redir['lang'] = $lang; } dcPage::addSuccessNotice($msg); - dcCore::app()->adminurl->redirect(My::id(), $redir); + dcCore::app()->adminurl?->redirect(My::id(), $redir); } } diff --git a/src/My.php b/src/My.php index 1e1efe6..ba9e548 100644 --- a/src/My.php +++ b/src/My.php @@ -43,6 +43,14 @@ class My return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name')); } + /** + * Check php version + */ + public static function phpCompliant(): bool + { + return version_compare(phpversion(), self::PHP_MIN, '>='); + } + /** * List of allowed backup folder */ diff --git a/src/Settings.php b/src/Settings.php index 70140a8..3c480c8 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -68,23 +68,23 @@ class Settings */ public function __construct() { - $s = dcCore::app()->blog->settings->get(My::id()); + $s = dcCore::app()->blog?->settings->get(My::id()); - $this->plugin_menu = (bool) ($s->get('plugin_menu') ?? false); - $this->theme_menu = (bool) ($s->get('theme_menu') ?? false); - $this->backup_auto = (bool) ($s->get('backup_auto') ?? false); - $this->backup_limit = (int) ($s->get('backup_limit') ?? 20); - $this->backup_folder = (string) ($s->get('backup_folder') ?? 'module'); - $this->start_page = (string) ($s->get('start_page') ?? '-'); - $this->write_langphp = (bool) ($s->get('write_langphp') ?? false); - $this->scan_tpl = (bool) ($s->get('scan_tpl') ?? true); - $this->parse_nodc = (bool) ($s->get('parse_nodc') ?? true); - $this->hide_default = (bool) ($s->get('hide_default') ?? true); - $this->parse_comment = (bool) ($s->get('parse_comment') ?? false); - $this->parse_user = (bool) ($s->get('parse_user') ?? false); - $this->parse_userinfo = (string) ($s->get('parse_userinfo') ?? 'displayname, email'); - $this->import_overwrite = (bool) ($s->get('import_overwrite') ?? false); - $this->export_filename = (string) ($s->get('export_filename') ?? 'type-module-l10n-timestamp'); + $this->plugin_menu = (bool) ($s?->get('plugin_menu') ?? false); + $this->theme_menu = (bool) ($s?->get('theme_menu') ?? false); + $this->backup_auto = (bool) ($s?->get('backup_auto') ?? false); + $this->backup_limit = (int) ($s?->get('backup_limit') ?? 20); + $this->backup_folder = (string) ($s?->get('backup_folder') ?? 'module'); + $this->start_page = (string) ($s?->get('start_page') ?? '-'); + $this->write_langphp = (bool) ($s?->get('write_langphp') ?? false); + $this->scan_tpl = (bool) ($s?->get('scan_tpl') ?? true); + $this->parse_nodc = (bool) ($s?->get('parse_nodc') ?? true); + $this->hide_default = (bool) ($s?->get('hide_default') ?? true); + $this->parse_comment = (bool) ($s?->get('parse_comment') ?? false); + $this->parse_user = (bool) ($s?->get('parse_user') ?? false); + $this->parse_userinfo = (string) ($s?->get('parse_userinfo') ?? 'displayname, email'); + $this->import_overwrite = (bool) ($s?->get('import_overwrite') ?? false); + $this->export_filename = (string) ($s?->get('export_filename') ?? 'type-module-l10n-timestamp'); } public function getSetting(string $key): mixed @@ -103,8 +103,8 @@ class Settings public function writeSetting(string $key, mixed $value): bool { if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { - dcCore::app()->blog->settings->get(My::id())->drop($key); - dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); + dcCore::app()->blog?->settings->get(My::id())->drop($key); + dcCore::app()->blog?->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); return true; } diff --git a/src/Translater.php b/src/Translater.php index 2844ca9..7035bb3 100644 --- a/src/Translater.php +++ b/src/Translater.php @@ -55,7 +55,7 @@ class Translater extends Settings if (!(dcCore::app()->themes instanceof dcThemes)) { dcCore::app()->themes = new dcThemes(); - dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null); + dcCore::app()->themes->loadModules((string) dcCore::app()->blog?->themes_path, null); } foreach ([ diff --git a/src/TranslaterLang.php b/src/TranslaterLang.php index c1d480d..8a1ddd7 100644 --- a/src/TranslaterLang.php +++ b/src/TranslaterLang.php @@ -131,11 +131,11 @@ class TranslaterLang $msgs = []; # php files if ($extension == 'php') { - $msgs = Translater::extractPhpMsgs($contents); + $msgs = Translater::extractPhpMsgs((string) $contents); # tpl files } elseif ($extension == 'html') { - $msgs = Translater::extractTplMsgs($contents); + $msgs = Translater::extractTplMsgs((string) $contents); } foreach ($msgs as $msg) { $res[] = [ diff --git a/src/TranslaterModule.php b/src/TranslaterModule.php index 2ebf11d..bd82fa6 100644 --- a/src/TranslaterModule.php +++ b/src/TranslaterModule.php @@ -68,7 +68,7 @@ class TranslaterModule $this->author = $define->get('author'); $this->version = $define->get('version'); $this->root_writable = $define->get('root_writable'); - $this->root = path::real($define->get('root')); + $this->root = (string) path::real($define->get('root'), false); $this->locales = $this->root . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER; } @@ -94,15 +94,15 @@ class TranslaterModule case 'plugin': $exp = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); $tmp = path::real(array_pop($exp)); - if ($tmp && is_writable($tmp)) { + if ($tmp !== false && is_writable($tmp)) { $dir = $tmp; } break; case 'public': - $tmp = path::real(dcCore::app()->blog->public_path); - if ($tmp && is_writable($tmp)) { + $tmp = path::real((string) dcCore::app()->blog?->public_path); + if ($tmp !== false && is_writable($tmp)) { $dir = $tmp; } @@ -110,7 +110,7 @@ class TranslaterModule case 'cache': $tmp = path::real(DC_TPL_CACHE); - if ($tmp && is_writable($tmp)) { + if ($tmp !== false && is_writable($tmp)) { @mkDir($tmp . '/l10n'); $dir = $tmp . '/l10n'; } @@ -119,7 +119,7 @@ class TranslaterModule case 'translater': $tmp = path::real(dcCore::app()->plugins->moduleRoot(My::id())); - if ($tmp && is_writable($tmp)) { + if ($tmp !== false && is_writable($tmp)) { @mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER); $dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER; } @@ -185,8 +185,11 @@ class TranslaterModule public function createBackup(string $lang): bool { $backup = $this->getBackupRoot(true); - $dir = $this->locales . DIRECTORY_SEPARATOR . $lang; + if (!$backup) { + return false; + } + $dir = $this->locales . DIRECTORY_SEPARATOR . $lang; if (!is_dir($dir)) { throw new Exception(sprintf( __('Failed to find language %s'), @@ -549,7 +552,7 @@ class TranslaterModule files::putContent( implode(DIRECTORY_SEPARATOR, [$this->locales, $lang, $file]), - file_get_contents(implode(DIRECTORY_SEPARATOR, [$this->locales, $from_lang, $file])) + (string) file_get_contents(implode(DIRECTORY_SEPARATOR, [$this->locales, $from_lang, $file])) ); } } else { @@ -619,6 +622,7 @@ class TranslaterModule } foreach ($rs as $group => $msgs) { + $group = (string) $group; $this->setPoContent($lang, $group, $msgs); $this->setLangphpContent($lang, $group, $msgs); } @@ -687,7 +691,7 @@ class TranslaterModule $search = My::defaultUserInformations(); $replace = []; foreach ($search as $n) { - $replace[] = dcCore::app()->auth->getInfo('user_' . $n); + $replace[] = dcCore::app()->auth?->getInfo('user_' . $n); } $info = trim(str_replace($search, $replace, $this->translater->parse_userinfo)); if (!empty($info)) { @@ -702,7 +706,7 @@ class TranslaterModule '"Project-Id-Version: ' . $this->id . ' ' . $this->version . '\n"' . "\n" . '"POT-Creation-Date: \n"' . "\n" . '"PO-Revision-Date: ' . date('c') . '\n"' . "\n" . - '"Last-Translator: ' . dcCore::app()->auth->getInfo('user_cn') . '\n"' . "\n" . + '"Last-Translator: ' . dcCore::app()->auth?->getInfo('user_cn') . '\n"' . "\n" . '"Language-Team: \n"' . "\n" . '"MIME-Version: 1.0\n"' . "\n" . '"Content-Transfer-Encoding: 8bit\n"' . "\n" . @@ -779,7 +783,7 @@ class TranslaterModule $search = My::defaultUserInformations(); $replace = []; foreach ($search as $n) { - $replace[] = dcCore::app()->auth->getInfo('user_' . $n); + $replace[] = dcCore::app()->auth?->getInfo('user_' . $n); } $info = trim(str_replace($search, $replace, $this->translater->parse_userinfo)); if (!empty($info)) {
' . sprintf(__('List of %s localized strings'), count($lines)) . '