test php-cs-fixer module on itself

master
Jean-Christian Paul Denis 2021-11-01 22:17:44 +01:00
parent 2f84837479
commit 102c4e128a
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
11 changed files with 314 additions and 297 deletions

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}

View File

@ -30,20 +30,20 @@
abstract class ImproveAction
{
protected $core;
protected $module = [];
protected $path_full = '';
protected $module = [];
protected $path_full = '';
protected $path_extension = '';
protected $path_is_dir = null;
protected $path_is_dir = null;
private $logs = ['success' => [], 'warning' => [], 'error' => []];
private $settings = [];
private $logs = ['success' => [], 'warning' => [], 'error' => []];
private $settings = [];
private $properties = [
'id' => '',
'name' => '',
'desc' => '',
'id' => '',
'name' => '',
'desc' => '',
'priority' => 500,
'config' => false, //mixed bool for internal, string for ext url
'types' => ['plugin']
'config' => false, //mixed bool for internal, string for ext url
'types' => ['plugin']
];
/**
@ -55,13 +55,13 @@ abstract class ImproveAction
{
$this->core = $core;
$settings = @unserialize($core->blog->settings->improve->get('settings_' . get_called_class()));
$settings = @unserialize($core->blog->settings->improve->get('settings_' . get_called_class()));
$this->settings = is_array($settings) ? $settings : [];
$this->init();
// can overload priority by settings
if (1 < ($p = (int) $core->blog->settings->improve->get('priority_'. get_called_class()))) {
if (1 < ($p = (int) $core->blog->settings->improve->get('priority_' . get_called_class()))) {
$this->priority = $p;
}
}
@ -127,7 +127,7 @@ abstract class ImproveAction
final protected function setProperties($property, $value = null): bool
{
$properties = is_array($property) ? $property : [$property => $value];
foreach($properties as $k => $v) {
foreach ($properties as $k => $v) {
if (isset($this->properties[$k])) {
if ($k == 'types' && !is_array($v)) {
$v = [$v];
@ -135,6 +135,7 @@ abstract class ImproveAction
$this->properties[$k] = $v;
}
}
return true;
}
//@}
@ -164,9 +165,10 @@ abstract class ImproveAction
final protected function setSettings($settings, $value = null)
{
$settings = is_array($settings) ? $settings : [$settings => $value];
foreach($settings as $k => $v) {
foreach ($settings as $k => $v) {
$this->settings[$k] = $v;
}
return true;
}
@ -239,9 +241,9 @@ abstract class ImproveAction
*/
final public function setPath(string $path_full, string $path_extension, bool $path_is_dir)
{
$this->path_full = $path_full;
$this->path_full = $path_full;
$this->path_extension = $path_extension;
$this->path_is_dir = $path_is_dir;
$this->path_is_dir = $path_is_dir;
}
/// @name Fix methods
@ -320,6 +322,7 @@ abstract class ImproveAction
return false;
}
$this->logs[$type][$this->path_full][] = $message;
return true;
}
@ -353,6 +356,7 @@ abstract class ImproveAction
) {
return [];
}
return $this->logs[$type][$this->path_full];
}

View File

@ -21,7 +21,7 @@ class Improve
];
private $core;
private $actions = [];
private $logs = [];
private $logs = [];
private $has_log = ['success' => false, 'warning' => false, 'error' => false];
public function __construct(dcCore $core)
@ -33,8 +33,8 @@ class Improve
try {
$this->core->callBehavior('improveAddAction', $list, $this->core);
foreach($list as $action) {
if ($action instanceOf ImproveAction && !isset($this->actions[$action->id])) {
foreach ($list as $action) {
if ($action instanceof ImproveAction && !isset($this->actions[$action->id])) {
$this->actions[$action->id] = $action;
}
}
@ -59,21 +59,22 @@ class Improve
if (empty($this->logs)) {
return '';
}
$cur = $this->core->con->openCursor($this->core->prefix . 'log');
$cur->log_msg = serialize($this->logs);
$cur = $this->core->con->openCursor($this->core->prefix . 'log');
$cur->log_msg = serialize($this->logs);
$cur->log_table = 'improve';
$id = $this->core->log->addLog($cur);
$id = $this->core->log->addLog($cur);
return $id;
}
public function readLogs(int $id ): array
public function readLogs(int $id): array
{
$rs = $this->core->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]);
if ($rs->isEmpty()) {
return [];
}
$this->core->log->delLogs($rs->log_id);
return unserialize($rs->log_msg);
}
@ -84,14 +85,14 @@ class Improve
return [];
}
$lines = [];
foreach($logs['improve'] as $path => $tools) {
foreach ($logs['improve'] as $path => $tools) {
$l_types = [];
foreach(['success', 'warning', 'error'] as $type) {
foreach (['success', 'warning', 'error'] as $type) {
$l_tools = [];
foreach($tools as $tool) {
foreach ($tools as $tool) {
$l_msg = [];
if (!empty($logs[$tool][$type][$path])) {
foreach($logs[$tool][$type][$path] as $msg) {
foreach ($logs[$tool][$type][$path] as $msg) {
$l_msg[] = $msg;
}
}
@ -107,6 +108,7 @@ class Improve
$lines[$path] = $l_types;
}
}
return $lines;
}
@ -115,6 +117,7 @@ class Improve
if (empty($id)) {
return $this->actions;
}
return $this->actions[$id] ?? null;
}
@ -123,21 +126,22 @@ class Improve
if (empty($id)) {
return $this->actions;
}
return $this->actions[$id] ?? null;
}
public function fixModule(string $type, string $id, array $properties, array $actions): float
{
$time_start = microtime(true);
$module = ImproveDefinition::clean($type, $id, $properties);
$module = ImproveDefinition::clean($type, $id, $properties);
$workers = [];
foreach($actions as $action) {
foreach ($actions as $action) {
if (isset($this->actions[$action]) && $this->actions[$action]->isConfigured()) {
$workers[] = $this->actions[$action];
}
}
foreach($workers as $action) {
foreach ($workers as $action) {
// trace all path and action in logs
$this->logs['improve'][__('Begin')][] = $action->id;
// info: set current module
@ -150,48 +154,50 @@ class Improve
throw new Exception(__('Module path is not writable'));
}
$tree = self::getModuleFiles($module['sroot']);
foreach($tree as $file) {
foreach ($tree as $file) {
if (!file_exists($file[0])) {
continue;
}
foreach($workers as $action) {
foreach ($workers as $action) {
// trace all path and action in logs
$this->logs['improve'][$file[0]][] = $action->id;
// info: set current path
$action->setPath($file[0], $file[1], $file[2]);
}
if (!$file[2]) {
foreach($workers as $action) {
foreach ($workers as $action) {
// action: open a directory. full path
$action->openDirectory();
}
} else {
foreach($workers as $action) {
foreach ($workers as $action) {
// action: before openning a file. full path, extension
$action->openFile();
}
if (in_array($file[1], self::$readfile_extensions)) {
if (false !== ($content = file_get_contents($file[0]))) {
$no_content = empty($content);
foreach($workers as $action) {
foreach ($workers as $action) {
// action: read a file content. full path, extension, content
$action->readFile($content);
if (empty($content) && !$no_content) {
throw new Exception(sprintf(
__('File content has been removed: %s by %s'), $file[0], $action->name
__('File content has been removed: %s by %s'),
$file[0],
$action->name
));
}
}
files::putContent($file[0], $content);
}
foreach($workers as $action) {
foreach ($workers as $action) {
// action: after closing a file. full path, extension
$action->closeFile();
}
}
}
}
foreach($workers as $action) {
foreach ($workers as $action) {
// trace all path and action in logs
$this->logs['improve'][__('End')][] = $action->id;
// info: set current module
@ -200,9 +206,9 @@ class Improve
$action->closeModule();
}
// info: get acions reports
foreach($workers as $action) {
foreach ($workers as $action) {
$this->logs[$action->id] = $action->getLogs();
foreach($this->has_log as $type => $v) {
foreach ($this->has_log as $type => $v) {
if ($action->hasLog($type)) {
$this->has_log[$type] = true;
}
@ -224,19 +230,21 @@ class Improve
$res[] = [$dir, '', false];
$files = files::scandir($path);
foreach($files AS $file) {
foreach ($files as $file) {
if (substr($file, 0, 1) == '.') {
continue;
}
if (is_dir($path . '/' . $file)) {
$res = self::getModuleFiles(
$path . '/' . $file, $dir . '/' . $file,
$path . '/' . $file,
$dir . '/' . $file,
$res
);
} else {
$res[] = [empty($dir) ? $file : $dir . '/' . $file, files::getExtension($file), true];
}
}
return $res;
}
@ -252,13 +260,14 @@ class Improve
$in = explode(',', $in);
}
if (!empty($in)) {
foreach($in as $v) {
foreach ($in as $v) {
$v = trim(files::getExtension('a.' . $v));
if (!empty($v)) {
$out[] = $v;
}
}
}
return $out;
}
@ -267,6 +276,7 @@ class Improve
if ($a->priority == $b->priority) {
return strcasecmp($a->name, $b->name);
}
return $a->priority < $b->priority ? -1 : 1;
}
}
@ -290,6 +300,7 @@ class ImproveDefinition
public static function clean(string $type, string $id, array $properties): array
{
$p = new self($type, $id, $properties);
return $p->get();
}
@ -314,7 +325,7 @@ class ImproveDefinition
$properties['permissions'] = $args[4];
}
if (isset($args[5])) {
$properties['priority'] = (integer) $args[5];
$properties['priority'] = (int) $args[5];
}
}
@ -328,7 +339,8 @@ class ImproveDefinition
'requires' => [],
'settings' => [],
'repository' => ''
], $properties
],
$properties
);
}
@ -337,7 +349,7 @@ class ImproveDefinition
{
$label = empty($properties['label']) ? $id : $properties['label'];
$name = __(empty($properties['name']) ? $label : $properties['name']);
$oname = empty($properties['name']) ? $label : $properties['name'];
$oname = empty($properties['name']) ? $label : $properties['name'];
return array_merge(
# Default values

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionDcdeprecated extends ImproveAction
{
/** @var array Deprecated functions [filetype [pattern, deprecated, replacement, version]] */
@ -63,11 +62,11 @@ class ImproveActionDcdeprecated extends ImproveAction
protected function init(): bool
{
$this->setProperties([
'id' => 'dcdeprecated',
'name' => __('Dotclear deprecated'),
'desc' => __('Search for use of deprecated Dotclear functions'),
'id' => 'dcdeprecated',
'name' => __('Dotclear deprecated'),
'desc' => __('Search for use of deprecated Dotclear functions'),
'priority' => 520,
'types' => ['plugin', 'theme']
'types' => ['plugin', 'theme']
]);
return true;
@ -83,7 +82,7 @@ class ImproveActionDcdeprecated extends ImproveAction
if (!in_array($this->path_extension, array_keys(self::$deprecated))) {
return null;
}
foreach(self::$deprecated[$this->path_extension] as $d) {
foreach (self::$deprecated[$this->path_extension] as $d) {
if (preg_match('/' . $d[0] . '/i', $content)) {
$this->setWarning(sprintf(__('Use of deprecated "%s", you should use "%s" instead.'), $d[1], __($d[2])));
}

View File

@ -10,18 +10,17 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionDcstore extends ImproveAction
{
protected function init(): bool
{
$this->setProperties([
'id' => 'dcstore',
'name' => __('Store file'),
'desc' => __('Re-create dcstore.xml file according to _define.php variables'),
'id' => 'dcstore',
'name' => __('Store file'),
'desc' => __('Re-create dcstore.xml file according to _define.php variables'),
'priority' => 420,
'config' => true,
'types' => ['plugin', 'theme']
'config' => true,
'types' => ['plugin', 'theme']
]);
return true;
@ -60,10 +59,11 @@ class ImproveActionDcstore extends ImproveAction
if ($this->hasError()) {
return false;
}
try {
files::putContent($this->module['sroot'] . '/dcstore.xml', $content);
$this->setSuccess(__('Write dcstore.xml file.'));
} catch(Exception $e) {
} catch (Exception $e) {
$this->setError(__('Failed to write dcstore.xml file'));
return false;
@ -98,7 +98,6 @@ class ImproveActionDcstore extends ImproveAction
# author
if (empty($this->module['author'])) {
$this->setError(__('unknow module author'));
}
$rsp->author($this->module['author']);
@ -128,6 +127,7 @@ class ImproveActionDcstore extends ImproveAction
}
if ($req[0] == 'core') {
$this->module['dc_min'] = $req[1];
break;
}
}

View File

@ -10,21 +10,20 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionGitshields extends ImproveAction
{
private $stop_scan = false;
private $stop_scan = false;
protected $bloc_pattern = [
'remove' => '/\[!\[Release(.*)LICENSE\)/ms',
'target' => '/^([^\n]+)[\r\n|\n]{1,}/ms'
];
protected $bloc_content = [
'release' => '[![Release](https://img.shields.io/github/v/release/%username%/%module%)](https://github.com/%username%/%module%/releases)',
'date' => '[![Date](https://img.shields.io/github/release-date/%username%/%module%)](https://github.com/%username%/%module%/releases)',
'issues' => '[![Issues](https://img.shields.io/github/issues/%username%/%module%)](https://github.com/%username%/%module%/issues)',
'dotclear' => '[![Dotclear](https://img.shields.io/badge/dotclear-v%dotclear%-blue.svg)](https://fr.dotclear.org/download)',
'release' => '[![Release](https://img.shields.io/github/v/release/%username%/%module%)](https://github.com/%username%/%module%/releases)',
'date' => '[![Date](https://img.shields.io/github/release-date/%username%/%module%)](https://github.com/%username%/%module%/releases)',
'issues' => '[![Issues](https://img.shields.io/github/issues/%username%/%module%)](https://github.com/%username%/%module%/issues)',
'dotclear' => '[![Dotclear](https://img.shields.io/badge/dotclear-v%dotclear%-blue.svg)](https://fr.dotclear.org/download)',
'dotaddict' => '[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://%type%s.dotaddict.org/dc2/details/%module%)',
'license' => '[![License](https://img.shields.io/github/license/%username%/%module%)](https://github.com/%username%/%module%/blob/master/LICENSE)'
'license' => '[![License](https://img.shields.io/github/license/%username%/%module%)](https://github.com/%username%/%module%/blob/master/LICENSE)'
];
protected function init(): bool
@ -50,7 +49,7 @@ class ImproveActionGitshields extends ImproveAction
{
if (!empty($_POST['save']) && !empty($_POST['username'])) {
$this->setSettings([
'username' => (string) $_POST['username'],
'username' => (string) $_POST['username'],
'dotaddict' => !empty($_POST['dotaddict'])
]);
$this->redirect($url);
@ -63,7 +62,7 @@ class ImproveActionGitshields extends ImproveAction
__('If you have badges not created by this tool in the README.md file you should remove them manually.') . '</p>
<p><label for="dotaddict">' .
form::checkbox('dotaddict', 1, !empty($this->getSetting('dotaddict'))) . ' '.
form::checkbox('dotaddict', 1, !empty($this->getSetting('dotaddict'))) . ' ' .
__('Include Dotaddict badge') . '</label>
</p><p class="form-note">' . __('If your plugin or theme is on Dotaddict, you can add a badge to link to its details in Dotaddict.') . '</p>';
}
@ -81,8 +80,8 @@ class ImproveActionGitshields extends ImproveAction
return null;
}
$clean = $this->deleteShieldsBloc($content);
$content = $this->writeShieldsBloc($clean);
$clean = $this->deleteShieldsBloc($content);
$content = $this->writeShieldsBloc($clean);
$this->stop_scan = true;
return true;
@ -91,7 +90,7 @@ class ImproveActionGitshields extends ImproveAction
private function replaceInfo()
{
$bloc = [];
foreach($this->bloc_content as $k => $v) {
foreach ($this->bloc_content as $k => $v) {
if ($k == 'dotaddict' && empty($this->getSetting('dotaddict'))) {
continue;
}
@ -127,12 +126,14 @@ class ImproveActionGitshields extends ImproveAction
}
if ($req[0] == 'core') {
$version = $req[1];
break;
}
}
} elseif (!empty($this->module['dc_min'])) {
$version = $this->module['dc_min'];
}
return $version ?: $this->core->getVersion('core');
}
@ -148,6 +149,7 @@ class ImproveActionGitshields extends ImproveAction
if ($count) {
$this->setSuccess(__('Write new shield bloc'));
}
return $res;
}
@ -163,6 +165,7 @@ class ImproveActionGitshields extends ImproveAction
if ($count) {
$this->setSuccess(__('Delete old shield bloc'));
}
return $res;
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionLicensefile extends ImproveAction
{
protected static $license_filenames = [
@ -19,8 +18,8 @@ class ImproveActionLicensefile extends ImproveAction
'license.txt'
];
private $action_version = [];
private $action_full = [];
private $stop_scan = false;
private $action_full = [];
private $stop_scan = false;
protected function init(): bool
{
@ -46,6 +45,7 @@ class ImproveActionLicensefile extends ImproveAction
__('Add file and remove others') => 'full',
__('Remove license files') => 'remove'
];
return true;
}
@ -58,8 +58,8 @@ class ImproveActionLicensefile extends ImproveAction
{
if (!empty($_POST['save'])) {
$this->setSettings([
'action_version' => !empty($_POST['action_version']) ? $_POST['action_version'] : '',
'action_full' => !empty($_POST['action_full']) ? $_POST['action_full'] : ''
'action_version' => !empty($_POST['action_version']) ? $_POST['action_version'] : '',
'action_full' => !empty($_POST['action_full']) ? $_POST['action_full'] : ''
]);
$this->redirect($url);
}
@ -86,6 +86,7 @@ class ImproveActionLicensefile extends ImproveAction
$this->writeFullLicense();
}
}
return null;
}
@ -105,12 +106,13 @@ class ImproveActionLicensefile extends ImproveAction
return null;
}
return true;
}
private function deleteFullLicense($only_one = false)
{
foreach(self::fileExists($this->module['root']) as $file) {
foreach (self::fileExists($this->module['root']) as $file) {
if ($only_one && $file != 'LICENSE') {
continue;
}
@ -122,17 +124,19 @@ class ImproveActionLicensefile extends ImproveAction
$this->setSuccess(sprintf(__('Delete old license file "%s"'), $file));
}
}
return true;
}
private static function fileExists($root)
{
$existing = [];
foreach(self::$license_filenames as $file) {
foreach (self::$license_filenames as $file) {
if (file_exists($root . '/' . strtolower($file))) {
$existing[] = strtolower($file);
}
}
return $existing;
}
}

View File

@ -10,17 +10,16 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionTab extends ImproveAction
{
protected function init(): bool
{
$this->setProperties([
'id' => 'tab',
'name' => __('Tabulations'),
'desc' => __('Replace tabulation by four space in php files'),
'id' => 'tab',
'name' => __('Tabulations'),
'desc' => __('Replace tabulation by four space in php files'),
'priority' => 820,
'types' => ['plugin', 'theme']
'types' => ['plugin', 'theme']
]);
return true;
@ -53,20 +52,20 @@ class ImproveActionNewline extends ImproveAction
protected function init(): bool
{
$this->setProperties([
'id' => 'newline',
'name' => __('Newlines'),
'desc' => __('Replace bad and repetitive and empty newline by single newline in files'),
'id' => 'newline',
'name' => __('Newlines'),
'desc' => __('Replace bad and repetitive and empty newline by single newline in files'),
'priority' => 840,
'config' => true,
'types' => ['plugin', 'theme']
'config' => true,
'types' => ['plugin', 'theme']
]);
/*
$ext = @unserialize($this->core->blog->settings->improve->newline_extensions);
$ext = Improve::cleanExtensions($ext);
if (!empty($ext)) {
$this->extensions = $ext;
}
*/
/*
$ext = @unserialize($this->core->blog->settings->improve->newline_extensions);
$ext = Improve::cleanExtensions($ext);
if (!empty($ext)) {
$this->extensions = $ext;
}
*/
return true;
}
@ -134,12 +133,12 @@ class ImproveActionEndoffile extends ImproveAction
protected function init(): bool
{
$this->setProperties([
'id' => 'endoffile',
'name' => __('End of files'),
'desc' => __('Remove php tag and empty lines from end of files'),
'id' => 'endoffile',
'name' => __('End of files'),
'desc' => __('Remove php tag and empty lines from end of files'),
'priority' => 860,
'config' => true,
'types' => ['plugin', 'theme']
'config' => true,
'types' => ['plugin', 'theme']
]);
return true;

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionPhpheader extends ImproveAction
{
private static $exemple = "
@ -38,7 +37,7 @@ class ImproveActionPhpheader extends ImproveAction
private $bloc_action = [];
private $bloc_content = '';
private $stop_scan = false;
private $stop_scan = false;
protected function init(): bool
{
@ -54,7 +53,7 @@ class ImproveActionPhpheader extends ImproveAction
$this->action_bloc = [
__('Do nothing') => 0,
__('Add bloc if it does not exist') => 'create',
__('Add and overwrite bloc') => 'overwrite' ,
__('Add and overwrite bloc') => 'overwrite',
__('Overwrite bloc only if it exists') => 'replace',
__('Remove existing bloc header') => 'remove'
];
@ -99,10 +98,10 @@ class ImproveActionPhpheader extends ImproveAction
form::textarea('bloc_content', 50, 10, html::escapeHTML($this->getSetting('bloc_content'))) . '
</p><p class="form-note">' .
sprintf(
__('You can use wildcards %s') ,
__('You can use wildcards %s'),
'%year%, %module_id%, %module_name%, %module_author%, %module_type%, %user_cn%, %user_name%, %user_email%, %user_url%'
) . '<br />' . __('Do not put structural elements to the begining of lines.') . '</p>' .
'<div class="fieldset box"><h4>' . __('Exemple') .'</h4><pre class="code">' . self::$exemple . '</pre></div>';
'<div class="fieldset box"><h4>' . __('Exemple') . '</h4><pre class="code">' . self::$exemple . '</pre></div>';
}
public function openModule(): ?bool
@ -114,7 +113,7 @@ class ImproveActionPhpheader extends ImproveAction
public function openDirectory(): ?bool
{
$skipped = $this->stop_scan;
$skipped = $this->stop_scan;
$this->stop_scan = false;
if (!empty($this->getSetting('exclude_locales')) && preg_match('/\/(locales|libs)(\/.*?|)$/', $this->path_full)) {
if (!$skipped) {
@ -128,7 +127,7 @@ class ImproveActionPhpheader extends ImproveAction
public function readFile(&$content): ?bool
{
if ($this->stop_scan || $this->path_extension !='php' || $this->hasError()) {
if ($this->stop_scan || $this->path_extension != 'php' || $this->hasError()) {
return null;
}
@ -136,7 +135,6 @@ class ImproveActionPhpheader extends ImproveAction
$content = $this->deleteOldBloc($content);
}
if (empty($this->getSetting('bloc_action'))) {
return null;
}
$clean = $this->deleteDocBloc($content);
@ -146,11 +144,9 @@ class ImproveActionPhpheader extends ImproveAction
return null;
}
if ($content != $clean && $this->getSetting('bloc_action') == 'create') {
return null;
}
if ($content == $clean && $this->getSetting('bloc_action') == 'replace') {
return null;
}
@ -175,7 +171,9 @@ class ImproveActionPhpheader extends ImproveAction
$this->bloc = preg_replace_callback(
// use \u in bloc content for first_upper_case
'/(\\\u([a-z]{1}))/',
function($str) { return ucfirst($str[2]); },
function ($str) {
return ucfirst($str[2]);
},
str_replace(
$this->bloc_wildcards,
[
@ -213,6 +211,7 @@ class ImproveActionPhpheader extends ImproveAction
$res = str_replace("\n * \n", "\n *\n", $res);
$this->setSuccess(__('Write new doc bloc content'));
}
return $res;
}
@ -228,6 +227,7 @@ class ImproveActionPhpheader extends ImproveAction
if ($count) {
$this->setSuccess(__('Delete old doc bloc content'));
}
return $res;
}
@ -235,7 +235,7 @@ class ImproveActionPhpheader extends ImproveAction
{
$res = preg_replace(
'/((# -- BEGIN LICENSE BLOCK ([-]+))(.*?)(# -- END LICENSE BLOCK ([-]+))([\n|\r\n]{1,}))/msi',
"",
'',
$content,
-1,
$count
@ -243,6 +243,7 @@ class ImproveActionPhpheader extends ImproveAction
if ($count) {
$this->setSuccess(__('Delete old style bloc content'));
}
return $res;
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImproveActionZip extends ImproveAction
{
public static $exclude = [
@ -38,12 +37,12 @@ class ImproveActionZip extends ImproveAction
protected function init(): bool
{
$this->setProperties([
'id' => 'zip',
'name' => __('Zip module'),
'desc' => __('Compress module into a ready to install package'),
'id' => 'zip',
'name' => __('Zip module'),
'desc' => __('Compress module into a ready to install package'),
'priority' => 980,
'config' => true,
'types' => ['plugin', 'theme']
'config' => true,
'types' => ['plugin', 'theme']
]);
return true;
@ -75,7 +74,9 @@ class ImproveActionZip extends ImproveAction
<p><label for="pack_repository">' . __('Path to repository:') . ' ' .
form::field('pack_repository', 65, 255, $this->getSetting('pack_repository'), 'maximal') .
'</label></p>' .
'<p class="form-note">' . sprintf(__('Preconization: %s'), $this->core->blog->public_path ?
'<p class="form-note">' . sprintf(
__('Preconization: %s'),
$this->core->blog->public_path ?
path::real($this->core->blog->public_path) : __("Blog's public directory")
) . '</p>
</div>
@ -93,7 +94,7 @@ class ImproveActionZip extends ImproveAction
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '</p>
<p><label class="classic" for="pack_overwrite">'.
<p><label class="classic" for="pack_overwrite">' .
form::checkbox('pack_overwrite', 1, !empty($this->getSetting('pack_overwrite'))) . ' ' .
__('Overwrite existing package') . '</label></p>
@ -132,6 +133,7 @@ class ImproveActionZip extends ImproveAction
if (!empty($this->getSetting('secondpack_filename'))) {
$this->zipModule($this->getSetting('secondpack_filename'), $exclude);
}
return null;
}
@ -149,7 +151,7 @@ class ImproveActionZip extends ImproveAction
$file
);
$parts = explode('/', $file);
foreach($parts as $i => $part) {
foreach ($parts as $i => $part) {
$parts[$i] = files::tidyFileName($part);
}
$path = $this->getSetting('pack_repository') . '/' . implode('/', $parts) . '.zip';
@ -164,9 +166,9 @@ class ImproveActionZip extends ImproveAction
return null;
}
@set_time_limit(300);
$fp = fopen($path, 'wb');
$fp = fopen($path, 'wb');
$zip = new ImproveZipFileZip($fp);
foreach($exclude as $e) {
foreach ($exclude as $e) {
$e = '#(^|/)(' . str_replace(
['.', '*'],
['\.', '.*?'],
@ -209,9 +211,9 @@ class ImproveZipFileZip extends fileZip
}
$unc_len = strlen($content);
$crc = crc32($content);
$zdata = gzdeflate($content);
$c_len = strlen($zdata);
$crc = crc32($content);
$zdata = gzdeflate($content);
$c_len = strlen($zdata);
unset($content);
@ -219,8 +221,7 @@ class ImproveZipFileZip extends fileZip
$mtime = $this->makeTime($mtime);
# Data descriptor
$data_desc =
"\x50\x4b\x03\x04" .
$data_desc = "\x50\x4b\x03\x04" .
"\x14\x00" . # ver needed to extract
"\x00\x00" . # gen purpose bit flag
"\x08\x00" . # compression method
@ -243,8 +244,7 @@ class ImproveZipFileZip extends fileZip
$new_offset = $this->old_offset + strlen($data_desc);
# Add to central directory record
$cdrec =
"\x50\x4b\x01\x02" .
$cdrec = "\x50\x4b\x01\x02" .
"\x00\x00" . # version made by
"\x14\x00" . # version needed to extract
"\x00\x00" . # gen purpose bit flag
@ -260,7 +260,7 @@ class ImproveZipFileZip extends fileZip
pack('v', 0) . # disk number start
pack('v', 0) . # internal file attributes
pack('V', 32) . # external file attributes - 'archive' bit set
pack('V', $this->old_offset). # relative offset of local header
pack('V', $this->old_offset) . # relative offset of local header
$name;
$this->old_offset = $new_offset;
@ -291,6 +291,7 @@ class ImproveZipFileZip extends fileZip
$newStr .= $token;
}
}
return $newStr;
}
}

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
@ -20,7 +19,7 @@ dcPage::checkSuper();
$improve = new Improve($core);
$show_filters = false;
$type = $_REQUEST['type'] ?? 'plugin';
$type = $_REQUEST['type'] ?? 'plugin';
$preferences = @unserialize($core->blog->settings->improve->preferences);
if (!is_array($preferences)) {
@ -31,7 +30,7 @@ $preferences = array_merge(['plugin' => [], 'theme' => []], $preferences);
if (!empty($_POST['save_preferences'])) {
$preferences[$type] = [];
if (!empty($_POST['actions'])) {
foreach($improve->modules() as $action) {
foreach ($improve->modules() as $action) {
if (in_array($type, $action->types) && in_array($action->id, $_POST['actions'])) {
$preferences[$type][] = $action->id;
}
@ -41,10 +40,10 @@ if (!empty($_POST['save_preferences'])) {
dcPage::addSuccessNotice(__('Configuration successfully updated'));
}
$allow_distrib = (boolean) $core->blog->settings->improve->allow_distrib;
$official = [
$allow_distrib = (bool) $core->blog->settings->improve->allow_distrib;
$official = [
'plugin' => explode(',', DC_DISTRIB_PLUGINS),
'theme' => explode(',', DC_DISTRIB_THEMES)
'theme' => explode(',', DC_DISTRIB_THEMES)
];
if (!isset($core->themes)) {
@ -53,8 +52,8 @@ if (!isset($core->themes)) {
}
$combo_modules = [__('Select a module') => '-'];
$modules = $type == 'plugin' ? $core->plugins->getModules() : $core->themes->getModules();
foreach($modules as $id => $m) {
$modules = $type == 'plugin' ? $core->plugins->getModules() : $core->themes->getModules();
foreach ($modules as $id => $m) {
if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[$type])) {
continue;
}
@ -102,21 +101,19 @@ if (!empty($_POST['fix'])) {
$breadcrumb = [];
if (!empty($_REQUEST['config'])) {
$breadcrumb = [
($type == 'plugin' ? __('Plugins') : __('Themes')) =>
$core->adminurl->get('admin.plugin.improve', ['type' => ($type == 'plugin' ? 'plugin' : 'theme')]),
'<span class="page-title">' . __('Configure module') . '</span>' => ''
($type == 'plugin' ? __('Plugins') : __('Themes')) => $core->adminurl->get('admin.plugin.improve', ['type' => ($type == 'plugin' ? 'plugin' : 'theme')]),
'<span class="page-title">' . __('Configure module') . '</span>' => ''
];
} else {
$breadcrumb = [
'<span class="page-title">' . ($type == 'plugin' ? __('Plugins') : __('Themes')) . '</span>' => '',
($type == 'theme' ? __('Plugins') : __('Themes')) =>
$core->adminurl->get('admin.plugin.improve', ['type' => ($type == 'theme' ? 'plugin' : 'theme')])
'<span class="page-title">' . ($type == 'plugin' ? __('Plugins') : __('Themes')) . '</span>' => '',
($type == 'theme' ? __('Plugins') : __('Themes')) => $core->adminurl->get('admin.plugin.improve', ['type' => ($type == 'theme' ? 'plugin' : 'theme')])
];
}
# display header
echo '<html><head><title>' . __('improve') . '</title></head><body>' .
dcPage::breadcrumb(array_merge([__('improve') => ''], $breadcrumb),['hl' => false]) .
dcPage::breadcrumb(array_merge([__('improve') => ''], $breadcrumb), ['hl' => false]) .
dcPage::notices();
if (!empty($_REQUEST['config'])) {
@ -124,14 +121,14 @@ if (!empty($_REQUEST['config'])) {
if (null !== ($action = $improve->module($_REQUEST['config']))) {
$redir = $_REQUEST['redir'] ?? $core->adminurl->get('admin.plugin.improve', ['type' => $type, 'config' => $action->id]);
$res = $action->configure($redir);
$res = $action->configure($redir);
echo '
<h3>' . sprintf(__('Configure module "%s"'), $action->name) . '</h3>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>
<p class="info">' . html::escapeHTML($action->desc) . '</p>
<form action="' . $core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">' .
(empty($res) ? '<p class="message">' . __('Nothing to configure'). '</p>' : $res) . '
(empty($res) ? '<p class="message">' . __('Nothing to configure') . '</p>' : $res) . '
<p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' .
form::hidden('type', $type) .
form::hidden('config', $action->id) .
@ -143,25 +140,23 @@ if (!empty($_REQUEST['config'])) {
<p class="warning">' . __('Unknow module') . '</p>
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>';
}
} else {
echo '<h3>' . ($type == 'plugin' ? __('Plugins') : __('Themes')) . '</h3>';
if (count($combo_modules) == 1) {
echo '<p class="message">' . __('No module to manage') . '</p>';
} else {
echo '<form action="' . $core->adminurl->get('admin.plugin.improve') . '" method="post" id="form-actions">';
foreach($improve->modules() as $action) {
foreach ($improve->modules() as $action) {
if (!in_array($type, $action->types)) {
continue;
}
$p = DC_DEBUG ? '<span class="debug">' . $action->priority. '</span> ' : '';
$p = DC_DEBUG ? '<span class="debug">' . $action->priority . '</span> ' : '';
echo
'<p class="modules">' . $p . '<label for="action_' . $action->id . '" class="classic">' .
form::checkbox(
['actions[]',
'action_' . $action->id],
'action_' . $action->id],
$action->id,
in_array($action->id, $preferences[$type]) && $action->isConfigured(),
'',
@ -184,7 +179,7 @@ if (!empty($_REQUEST['config'])) {
<hr />
<p><label for="save_preferences" class="classic">' .
form::checkbox('save_preferences', 1, !empty($_POST['save_preferences'])) .
__('Save fields selection as preference') .'</label></p>
__('Save fields selection as preference') . '</label></p>
<p class="field"><label for="module" class="classic">' . __('Select a module:') . '</label>' .
form::combo('module', $combo_modules, $module) . '
</p></p>
@ -203,13 +198,13 @@ if (!empty($_REQUEST['config'])) {
if (!empty($logs)) {
echo '<div class="fieldset"><h4>' . __('Details') . '</h4>';
foreach($logs as $path => $types) {
echo '<h5>' . $path .'</h5>';
foreach($types as $type => $tools) {
foreach ($logs as $path => $types) {
echo '<h5>' . $path . '</h5>';
foreach ($types as $type => $tools) {
echo '<div class="' . $type . '"><ul>';
foreach($tools as $tool => $msgs) {
foreach ($tools as $tool => $msgs) {
echo '<li>' . $improve->module($tool)->name . '<ul>';
foreach($msgs as $msg) {
foreach ($msgs as $msg) {
echo '<li>' . $msg . '</li>';
}
echo '</ul></li>';