open($strResultingFile, ZIPARCHIVE::OVERWRITE) !== true) { throw new Exeption("Could not open " . $strResultingFile . " for writing!"); } // Add files to include foreach ($aFilesToInclude as $strFile) { echo date('H:i:s') . " Adding file $strFile\n"; addFileToZIP($strFile, $objZip, $sVersion, $sDate); } // Add paths to include foreach ($aPathsToInclude as $strPath) { addPathToZIP($strPath, $objZip, $sVersion, $sDate); } // Set archive comment... echo date('H:i:s') . " Set archive comment...\n"; $objZip->setArchiveComment('PHPExcel - http://www.codeplex.com/PHPExcel'); // Close file echo date('H:i:s') . " Saving ZIP archive...\n"; $objZip->close(); // Copy classes directory echo date('H:i:s') . " Copying class directory...\n"; mkdir('./tmp'); dircopy($sClassPath, './tmp'); // Create PEAR package.xml echo date('H:i:s') . " Creating PEAR package.xml...\n"; $packageFile = file_get_contents('package.xml'); $packageFile = replaceMetaData($packageFile, $sVersion, $sDate); $packageFile = str_replace('##PEAR_DIR##', addPathToPEAR('./tmp', '', $sVersion, $sDate), $packageFile); $fh = fopen('./tmp/package.xml', 'w'); fwrite($fh, $packageFile); fclose($fh); // Create PEAR package echo date('H:i:s') . " Creating PEAR package...\n"; echo shell_exec("$sPEARPath package ./tmp/package.xml"); // Wait a minute (TortoiseSVN on USB stick is slow!) echo date('H:i:s') . " Waiting...\n"; sleep(120); // Clean temporary files echo date('H:i:s') . " Cleaning temporary files...\n"; unlink('./tmp/package.xml'); rm('./tmp'); // Finished build echo date('H:i:s') . " Finished build!\n"; fclose($stdin); /** * Add a specific path's files and folders to a ZIP object * * @param string $strPath Path to add * @param ZipArchive $objZip ZipArchive object * @param string $strVersion Version string * @param string $strDate Date string */ function addPathToZIP($strPath, $objZip, $strVersion, $strDate) { global $aIgnorePatterns; echo date('H:i:s') . " Adding path $strPath...\n"; $currentDir = opendir($strPath); while ($strFile = readdir($currentDir)) { if ($strFile != '.' && $strFile != '..') { if (is_file($strPath . '/' . $strFile)) { addFileToZIP($strPath . '/' . $strFile, $objZip, $strVersion, $strDate); } else if (is_dir($strPath . '/' . $strFile)) { if (!shouldIgnore($strFile)) { addPathToZIP( ($strPath . '/' . $strFile), $objZip, $strVersion, $strDate ); } } } } } /** * Add a specific file to ZIP * * @param string $strFile File to add * @param ZipArchive $objZip ZipArchive object * @param string $strVersion Version string * @param string $strDate Date string */ function addFileToZIP($strFile, $objZip, $strVersion, $strDate) { if (!shouldIgnore($strFile)) { $fileContents = file_get_contents($strFile); $fileContents = replaceMetaData($fileContents, $strVersion, $strDate); //$objZip->addFile($strFile, cleanFileName($strFile)); $objZip->addFromString( cleanFileName($strFile), $fileContents ); } } /** * Cleanup a filename * * @param string $strFile Filename * @return string Filename */ function cleanFileName($strFile) { $strFile = str_replace('../', '', $strFile); $strFile = str_replace('WINDOWS', '', $strFile); while (preg_match('/\/\//i', $strFile)) { $strFile = str_replace('//', '/', $strFile); } return $strFile; } /** * Replace metadata in string * * @param string $strString String contents * @param string $strVersion Version string * @param string $strDate Date string * @return string String contents */ function replaceMetaData($strString, $strVersion, $strDate) { $strString = str_replace('##VERSION##', $strVersion, $strString); $strString = str_replace('##DATE##', $strDate, $strString); return $strString; } /** * Add a specific path's files and folders to a PEAR dir list * * @param string $strPath Path to add * @param string $strPEAR String containing PEAR dir definitions * @param string $strVersion Version string * @param string $strDate Date string * @return string String containing PEAR dir definitions */ function addPathToPEAR($strPath, $strPEAR, $strVersion, $strDate) { global $aIgnorePatterns; $currentDir = opendir($strPath); while ($strFile = readdir($currentDir)) { if ($strFile != '.' && $strFile != '..') { if (is_file($strPath . '/' . $strFile) && !preg_match('/package.xml/i', $strFile)) { $strPEAR .= addFileToPEAR($strPath . '/' . $strFile, '', $strVersion, $strDate); } else if (is_dir($strPath . '/' . $strFile)) { if (!shouldIgnore($strFile)) { $strPEAR .= '