error->add( __('Cache directory is not writable.') ); } if (!is_writable($repo)) { dcCore::app()->error->add( __('Path to repository is not writable.') ); } if (empty($file_a)) { dcCore::app()->error->add( __('You must specify the name of package to export.') ); } if (!is_writable(dirname($repo . '/' . $file_a))) { dcCore::app()->error->add( __('Path to first export package is not writable.') ); } if (!empty($file_b) && !is_writable(dirname($repo . '/' . $file_b))) { dcCore::app()->error->add( __('Path to second export package is not writable.') ); } return !dcCore::app()->error->flag(); } public static function is_writable(string $path, string $file): bool { return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file))); } public static function getRepositoryDir($dir) { if (empty($dir)) { try { $dir = DC_VAR . DIRECTORY_SEPARATOR . 'packman'; @files::makeDir($dir, true); } catch (Exception $e) { $dir = ''; } } return $dir; } public static function getModules(string $type, ?string $id = null): ?array { $type = $type == 'themes' ? 'themes' : 'plugins'; $modules = array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules()); if (empty($id)) { return $modules; } elseif (array_key_exists($id, $modules)) { return $modules[$id]; } return null; } public static function moduleExists(string $type, ?string $id): bool { $type = $type == 'themes' ? 'themes' : 'plugins'; return array_key_exists($id, array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules())); } public static function modules(array $modules, string $type, string $title): ?bool { if (empty($modules) || !is_array($modules)) { return null; } $type = $type == 'themes' ? 'themes' : 'plugins'; echo '
' . '

' . $title . '

' . '
' . '' . '' . '' . '' . '' . ''; foreach (self::sort($modules) as $id => $module) { echo '' . '' . '' . '' . '' . ''; } echo '
' . __('Id') . '' . __('Version') . '' . __('Name') . '' . __('Root') . '
' . html::escapeHTML($module['version']) . '' . __(html::escapeHTML($module['name'])) . '' . dirname((string) path::real($module['root'], false)) . '
' . '

' . '

' . ( !empty($_REQUEST['redir']) ? form::hidden( ['redir'], html::escapeHTML($_REQUEST['redir']) ) : '' ) . form::hidden(['p'], basename(dirname('../' . __DIR__))) . form::hidden(['type'], $type) . form::hidden(['action'], 'packup') . '' . dcCore::app()->formNonce() . '

' . '
' . '
'; return true; } public static function repository(array $modules, string $type, string $title): ?bool { if (empty($modules) || !is_array($modules)) { return null; } if (!in_array($type, ['plugins', 'themes', 'repository'])) { return null; } echo '
' . '

' . $title . '

'; $combo_action = [__('delete') => 'delete']; if ($type == 'plugins' || $type == 'themes') { $combo_action[__('install')] = 'install'; } if ($type != 'plugins') { $combo_action[sprintf(__('copy to %s directory'), __('plugins'))] = 'copy_to_plugins'; $combo_action[sprintf(__('move to %s directory'), __('plugins'))] = 'move_to_plugins'; } if ($type != 'themes') { $combo_action[sprintf(__('copy to %s directory'), __('themes'))] = 'copy_to_themes'; $combo_action[sprintf(__('move to %s directory'), __('themes'))] = 'move_to_themes'; } if ($type != 'repository') { $combo_action[sprintf(__('copy to %s directory'), __('repository'))] = 'copy_to_repository'; $combo_action[sprintf(__('move to %s directory'), __('repository'))] = 'move_to_repository'; } echo '
' . '' . '' . '' . '' . '' . '' . ''; $dup = []; foreach (self::sort($modules) as $module) { if (isset($dup[$module['root']])) { continue; } $dup[$module['root']] = 1; echo '' . '' . '' . '' . '' . '' . ''; } echo '
' . __('Id') . '' . __('Version') . '' . __('Name') . '' . __('File') . '' . __('Date') . '
' . html::escapeHTML($module['version']) . '' . __(html::escapeHTML($module['name'])) . '' . '' . html::escapeHTML(basename($module['root'])) . '' . '' . html::escapeHTML(dt::str(__('%Y-%m-%d %H:%M'), (int) @filemtime($module['root']))) . '
' . '
' . '

' . '

' . __('Selected modules action:') . ' ' . form::combo(['action'], $combo_action) . '' . form::hidden(['p'], basename(dirname('../' . __DIR__))) . form::hidden(['tab'], 'repository') . form::hidden(['type'], $type) . dcCore::app()->formNonce() . '

' . '
' . '
' . '
'; return true; } protected static function sort(array $modules): array { $key = $ver = []; foreach ($modules as $i => $module) { $key[$i] = $module['id'] ?? $i; $ver[$i] = $module['version']; } array_multisort($key, SORT_ASC, $ver, SORT_ASC, $modules); return $modules; } }