1#!/usr/bin/env php -d memory_limit=256M
35$listOfModuleContent = [
73function detectModule()
75 $name = $version =
"";
76 $tab = glob(
"core/modules/mod*.class.php");
77 if (count($tab) == 0) {
78 echo
"[fail] Error on auto detect data : there is no mod*.class.php file into core/modules dir\n";
81 if (count($tab) == 1) {
83 $pattern =
"/.*mod(?<mod>.*)\.class\.php/";
84 if (preg_match_all($pattern, $file, $matches)) {
85 $name = strtolower(reset($matches[
'mod']));
88 echo
"extract data from $file\n";
89 if (!file_exists($file) || $name ==
"") {
90 echo
"[fail] Error on auto detect data\n";
94 echo
"[fail] Error there is more than one mod*.class.php file into core/modules dir\n";
99 $contents = file_get_contents($file);
100 $pattern =
"/^.*this->version\s*=\s*'(?<version>.*)'\s*;.*\$/m";
103 if (preg_match_all($pattern, $contents, $matches)) {
104 $version = reset($matches[
'version']);
107 if (version_compare($version,
'0.0.1',
'>=') != 1) {
108 echo
"[fail] Error auto extract version fail\n";
112 echo
"module name = $name, version = $version\n";
113 return [(string) $name, (
string) $version];
123function delTree($dir)
125 $files = array_diff(scandir($dir), array(
'.',
'..'));
126 foreach ($files as $file) {
127 (is_dir(
"$dir/$file")) ? delTree(
"$dir/$file") : secureUnlink(
"$dir/$file");
141function secureUnlink($path)
143 if (file_exists($path)) {
147 if (file_exists($path)) {
148 echo
"[fail] unlink of $path fail !\n";
152 echo
"[fail] unlink of $path fail !\n";
166function mkdirAndCheck($path)
174 echo
"[fail] Error on $path (mkdir)\n";
185function is_excluded($filename)
187 global $exclude_list;
189 $notused = preg_filter($exclude_list,
'1', $filename, -1, $count);
191 echo
" - exclude $filename\n";
205function rcopy($src, $dst)
211 $dir = opendir($src);
214 while ($file = readdir($dir)) {
215 if (($file !=
'.') && ($file !=
'..')) {
216 if (is_dir($src .
'/' . $file)) {
219 if (!rcopy($src .
'/' . $file, $dst .
'/' . $file)) {
223 if (!is_excluded($file)) {
224 if (!copy($src .
'/' . $file, $dst .
'/' . $file)) {
232 } elseif (is_file($src)) {
233 if (!is_excluded($src)) {
234 if (!copy($src, $dst)) {
252function zipDir($folder, &$zip, $root =
"")
254 foreach (
new \DirectoryIterator($folder) as $f) {
258 $src = $folder .
'/' . $f;
259 $dst = substr($f->getPathname(), strlen($root));
261 if ($zip->addEmptyDir($dst)) {
262 if (zipDir($src, $zip, $root)) {
272 if (! $zip->addFile($src, $dst)) {
284list($mod, $version) = detectModule();
285$outzip = sys_get_temp_dir() .
"/module_" . $mod .
"-" . $version .
".zip";
286if (file_exists($outzip)) {
287 secureUnlink($outzip);
291$tmpdir = tempnam(sys_get_temp_dir(), $mod .
"-module");
292secureUnlink($tmpdir);
293mkdirAndCheck($tmpdir);
294$dst = $tmpdir .
"/" . $mod;
297foreach ($listOfModuleContent as $moduleContent) {
298 foreach (glob($moduleContent) as $entry) {
299 if (!rcopy($entry, $dst .
'/' . $entry)) {
300 echo
"[fail] Error on copy " . $entry .
" to " . $dst .
"/" . $entry .
"\n";
301 echo
"Please take time to analyze the problem and fix the bug\n";
307$z =
new ZipArchive();
308$z->open($outzip, ZipArchive::CREATE);
309zipDir($tmpdir, $z, $tmpdir .
'/');
312if (file_exists($outzip)) {
313 echo
"[success] module archive is ready : $outzip ...\n";
315 echo
"[fail] build zip error\n";