0, 'js' => 0, 'images' => 0]; foreach (['css' => 'css', 'js' => 'js'] as $type => $folder) { $directory = $theme->path().'/'.$folder; if (! $this->files->isDirectory($directory)) continue; foreach ($this->files->files($directory) as $file) { if ($file->getExtension() !== $type || str_ends_with($file->getFilename(), '.min.'.$type)) continue; $content = $file->getContents(); $content = preg_replace('!/\*.*?\*/!s', '', $content) ?? $content; $content = preg_replace('/\s+/', ' ', $content) ?? $content; $content = preg_replace('/\s*([{}:;,>])\s*/', '$1', $content) ?? $content; $target = $file->getPath().'/'.$file->getBasename('.'.$type).'.min.'.$type; $this->files->put($target, trim($content)); $result[$type]++; } } if (function_exists('imagewebp')) { foreach (['images', 'icons'] as $folder) { $directory = $theme->path().'/'.$folder; if (! $this->files->isDirectory($directory)) continue; foreach ($this->files->files($directory) as $file) { $ext = strtolower($file->getExtension()); if (! in_array($ext, ['jpg', 'jpeg', 'png'], true)) continue; $image = $ext === 'png' ? @imagecreatefrompng($file->getPathname()) : @imagecreatefromjpeg($file->getPathname()); if ($image) { imagepalettetotruecolor($image); imagewebp($image, $file->getPath().'/'.$file->getBasename('.'.$ext).'.webp', 82); imagedestroy($image); $result['images']++; } } } } return $result; } }