#!/usr/bin/php \n"; exit(1); } if (!$zip_file = tempnam('', 'comicpress')) { echo "A temp directory could not be created!\n"; exit(1); } $zip_file .= '.zip'; $ignore_filters = array( '#~$#', '#^\.#', '#^test$#', '#^build$#', '#^Makefile$', '#^phpunit.xml$#' ); $renames = array( '#^(.*)\.dist$#' => '\1' ); $zip = new ZipArchive(); $result = $zip->open($zip_file, ZipArchive::CREATE); if ($result === true) { $dir_stack = array('.'); while (!empty($dir_stack)) { $dir = array_shift($dir_stack); $zip_dir = preg_replace('#^.#', 'comicpress', $dir); $zip->addEmptyDir($zip_dir); if ($dh = opendir($dir)) { while ($file = readdir($dh)) { $ok = true; foreach ($ignore_filters as $filter) { if (preg_match($filter, $file) > 0) { $ok = false; break; } } if ($ok) { $target = $dir . '/' . $file; if (is_dir($target)) { $dir_stack[] = $target; } else { $zip_target = $file; foreach ($renames as $filter => $replacement) { $zip_target = preg_replace($filter, $replacement, $zip_target); } $zip_target = $zip_dir . '/' . $zip_target; echo $zip_target . "\n"; $zip->addFile($target, $zip_target); } } } } closedir($dh); } $zip->close(); rename($zip_file, $argv[1]); }