recurse_copy($sourceAdsPath . $sourceAdName . "/" . $sourceAdSize . "/", $currentAdCreationPath); $varFile = ''; foreach ($currentVersionVars as $varName => $varValue) { if ($varName == "clickTag") { //Lets do something else for clickTag $currentIndexFileSrc = file_get_contents($currentAdCreationPath . "index.html"); $currentIndexFileSrc = str_replace("[clickTag]", $varValue, $currentIndexFileSrc); file_put_contents($currentAdCreationPath . "index.html", $currentIndexFileSrc); } else { $varFile .= "var " . $varName . " = '" . str_replace("'", "\\'", $varValue) . "';\n"; } } //Put vars file in root ad directory file_put_contents($currentAdCreationPath . "/vars.js", $varFile); @mkdir($generatedVersionsPath . $sourceAdName . "/zips"); zip_directory($sourceAdName . "-" . $currentVersionName . "-" . $sourceAdSize, $currentAdCreationPath, $generatedVersionsPath . $sourceAdName . "/zips"); if (!isCLI()) { echo $sourceAdSize . " Link: <a target='_blank' href='" . $url . str_replace("./", "", $currentAdCreationPath) . "'>" . $url . str_replace("./", "", $currentAdCreationPath) . "</a><br>"; } } echo "Finished.<br><br>\n\n"; //Let screen know what was finished. } } echo "Finished.\n"; /* UTILITIE FUNCTIONS !!!!DO NOT CHANGE!!!! */ function recurse_copy($src, $dst) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) {
// Run the ant build exec('ant -buildfile "' . $list_copies[WINK_PATH_XML_BUILD] . '"'); // Remove the temp directory rrmdir($tmp_directory); } // ------------------------------------------------- // Return the result according to the output format // ------------------------------------------------- $format = param('format'); if ($format == 'zip') { $pathZipFile = PROJECT_TMP_DIR . '/' . uniqid(time()) . '.zip'; $zip = new ZipArchive(); if ($zip->open($pathZipFile, ZipArchive::CREATE) !== TRUE) { throw new Exception('Zip file creation failed'); } $zip = zip_directory($build_directory, $zip); $zip->close(); $res = searchInDir(array('\\.(js)$'), $build_directory, TRUE); $zipFilename = str_replace('.min.js', '.zip', basename($res[0])); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $zipFilename . '"'); header('Content-Length: ' . filesize($pathZipFile)); readfile($pathZipFile); unlink($pathZipFile); exit; } else { if ($format == 'code') { $typeFile = 'js'; if (strtolower(param('file')) == 'css') { $typeFile = 'css'; }
require_once dirname(__FILE__) . '/../inc/config.php'; require_once dirname(__FILE__) . '/../inc/functions.inc.php'; try { $guid = get('id'); if ($guid == '') { throw new Exception('The parameter is not correct'); } if (is_dir(PROJECT_BUILD_DIR . '/' . $guid) === FALSE) { throw new Exception('The build doesn\'t exist'); } $pathZipFile = PROJECT_TMP_DIR . '/' . uniqid(time()) . '.zip'; $zip = new ZipArchive(); if ($zip->open($pathZipFile, ZipArchive::CREATE) !== TRUE) { throw new Exception('Zip file creation failed'); } $zip = zip_directory(PROJECT_BUILD_DIR . '/' . $guid, $zip); $zip->close(); if (file_exists($pathZipFile) !== TRUE) { throw new Exception("The file doesn't exist"); } $res = searchInDir(array('\\.(js)$'), PROJECT_BUILD_DIR . '/' . $guid, TRUE); $zipFilename = str_replace('.min.js', '.zip', basename($res[0])); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $zipFilename . '"'); header('Content-Length: ' . filesize($pathZipFile)); readfile($pathZipFile); unlink($pathZipFile); exit; } catch (Exception $e) { echo $e->getMessage(); }
/** * Zip a directory recursively * * @param string $directory * @param ZipArchive $zip * @param string $parent * @return \ZipArchive * @throws Exception */ function zip_directory($directory, ZipArchive $zip, $parent = '') { if (!is_dir($directory)) { throw new Exception('Is not a directory "' . $directory . '"'); } $dir_handle = opendir($directory); if ($dir_handle === FALSE) { throw new Exception('Open directory has failed'); } while (FALSE !== ($f = readdir($dir_handle))) { if ($f == '.' || $f == '..') { continue; } $path = $directory . '/' . basename($f); if (is_dir($path)) { $zip->addEmptyDir($parent . $f); $zip = zip_directory($path, $zip, $parent . $f . '/'); continue; } $zip->addFile($path, $parent . $f); } closedir($dir_handle); return $zip; }