setProperties([ 'id' => 'tab', 'name' => __('Tabulations'), 'desc' => __('Replace tabulation by four space in php files'), 'priority' => 820, 'types' => ['plugin', 'theme'] ]); return true; } public function readFile(&$content): ?bool { if (!in_array($this->path_extension, ['php', 'md'])) { return null; } $clean = preg_replace('/(\t)/', ' ', $content);// . "\n"; if ($content != $clean) { $this->setSuccess(__('Replace tabulation by spaces')); $content = $clean; } return true; } public function isConfigured(): bool { return true; } } 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'), 'priority' => 840, 'config' => true, 'types' => ['plugin', 'theme'] ]); /* $ext = @unserialize($this->core->blog->settings->improve->newline_extensions); $ext = Improve::cleanExtensions($ext); if (!empty($ext)) { $this->extensions = $ext; } */ return true; } public function isConfigured(): bool { return !empty($this->getSetting('extensions')); } public function configure($url): ?string { if (!empty($_POST['save']) && !empty($_POST['newline_extensions'])) { $this->setSettings( 'extensions', Improve::cleanExtensions($_POST['newline_extensions']) ); $this->redirect($url); } $ext = $this->getSetting('extensions'); if (!is_array($ext)) { $ext = []; } return '
' . __('Use comma separated list of extensions without dot, recommand "php,js,xml,txt,md".') . '
'; } public function readFile(string &$content): ?bool { $ext = $this->getSetting('extensions'); if (!is_array($ext) || !in_array($this->path_extension, $ext)) { return null; } $clean = (string) preg_replace( '/(\n\s+\n)/', "\n\n", (string) preg_replace( '/(\n\n+)/', "\n\n", (string) str_replace( ["\r\n", "\r"], "\n", $content ) ) ); if ($content != $clean) { $this->setSuccess(__('Replace bad new lines')); $content = $clean; } return true; } } 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'), 'priority' => 860, 'config' => true, 'types' => ['plugin', 'theme'] ]); return true; } public function isConfigured(): bool { return true; } public function configure($url): ?string { if (!empty($_POST['save'])) { $this->setSettings('psr2', !empty($_POST['endoffile_psr2'])); $this->redirect($url); } return '' . __('PSR2 must have a blank line, whereas PSR12 must not.') . '
'; } public function readFile(&$content): ?bool { if (!in_array($this->path_extension, ['php', 'md'])) { return null; } $clean = preg_replace( ['/(\s*)(\?>\s*)$/', '/\n+$/'], '', $content ) . ($this->getSetting('psr2') ? "\n" : ''); if ($content != $clean) { $this->setSuccess(__('Replace end of file')); $content = $clean; } return true; } }