1#!/usr/bin/env php -d memory_limit=256M
34$listOfModuleContent = [
72function detectModule()
74 $name = $version =
"";
75 $tab = glob(
"core/modules/mod*.class.php");
76 if (count($tab) == 0) {
77 echo
"[fail] Error on auto detect data : there is no mod*.class.php file into core/modules dir\n";
80 if (count($tab) == 1) {
82 $pattern =
"/.*mod(?<mod>.*)\.class\.php/";
83 if (preg_match_all($pattern, $file, $matches)) {
84 $name = strtolower(reset($matches[
'mod']));
87 echo
"extract data from $file\n";
88 if (!file_exists($file) || $name ==
"") {
89 echo
"[fail] Error on auto detect data\n";
93 echo
"[fail] Error there is more than one mod*.class.php file into core/modules dir\n";
98 $contents = file_get_contents($file);
99 $pattern =
"/^.*this->version\s*=\s*'(?<version>.*)'\s*;.*\$/m";
102 if (preg_match_all($pattern, $contents, $matches)) {
103 $version = reset($matches[
'version']);
106 if (version_compare($version,
'0.0.1',
'>=') != 1) {
107 echo
"[fail] Error auto extract version fail\n";
111 echo
"module name = $name, version = $version\n";
112 return [(string) $name, (
string) $version];
122function delTree($dir)
124 $files = array_diff(scandir($dir), array(
'.',
'..'));
125 foreach ($files as $file) {
126 (is_dir(
"$dir/$file")) ? delTree(
"$dir/$file") : secureUnlink(
"$dir/$file");
140function secureUnlink($path)
142 if (file_exists($path)) {
146 if (file_exists($path)) {
147 echo
"[fail] unlink of $path fail !\n";
151 echo
"[fail] unlink of $path fail !\n";
165function mkdirAndCheck($path)
173 echo
"[fail] Error on $path (mkdir)\n";
184function is_excluded($filename)
186 global $exclude_list;
188 $notused = preg_filter($exclude_list,
'1', $filename, -1, $count);
190 echo
" - exclude $filename\n";
204function rcopy($src, $dst)
210 $dir = opendir($src);
213 while ($file = readdir($dir)) {
214 if (($file !=
'.') && ($file !=
'..')) {
215 if (is_dir($src .
'/' . $file)) {
218 if (!rcopy($src .
'/' . $file, $dst .
'/' . $file)) {
222 if (!is_excluded($file)) {
223 if (!copy($src .
'/' . $file, $dst .
'/' . $file)) {
231 } elseif (is_file($src)) {
232 if (!is_excluded($src)) {
233 if (!copy($src, $dst)) {
251function zipDir($folder, &$zip, $root =
"")
253 foreach (
new \DirectoryIterator($folder) as $f) {
257 $src = $folder .
'/' . $f;
258 $dst = substr($f->getPathname(), strlen($root));
260 if ($zip->addEmptyDir($dst)) {
261 if (zipDir($src, $zip, $root)) {
271 if (! $zip->addFile($src, $dst)) {
283list($mod, $version) = detectModule();
284$outzip = sys_get_temp_dir() .
"/module_" . $mod .
"-" . $version .
".zip";
285if (file_exists($outzip)) {
286 secureUnlink($outzip);
290$tmpdir = tempnam(sys_get_temp_dir(), $mod .
"-module");
291secureUnlink($tmpdir);
292mkdirAndCheck($tmpdir);
293$dst = $tmpdir .
"/" . $mod;
296foreach ($listOfModuleContent as $moduleContent) {
297 foreach (glob($moduleContent) as $entry) {
298 if (!rcopy($entry, $dst .
'/' . $entry)) {
299 echo
"[fail] Error on copy " . $entry .
" to " . $dst .
"/" . $entry .
"\n";
300 echo
"Please take time to analyze the problem and fix the bug\n";
306$z =
new ZipArchive();
307$z->open($outzip, ZIPARCHIVE::CREATE);
308zipDir($tmpdir, $z, $tmpdir .
'/');
311if (file_exists($outzip)) {
312 echo
"[success] module archive is ready : $outzip ...\n";
314 echo
"[fail] build zip error\n";