public static function hook(GWF_User $user, GWF_Download $dl) { $dlid = $dl->getID(); if ($dlid > 2) { return true; } $demo = $dlid == 2; if (false === ($row = BAIM_MC::generate($user, $demo))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $mime = $dl->getVar('dl_mime'); $path = $dl->getDownloadPath(); $temp_path = GWF_PATH . 'extra/temp/baim/' . $user->getVar('user_id') . '_' . $row->getToken(); if (!Common::isFile($path)) { return GWF_HTML::err('ERR_FILE_NOT_FOUND', htmlspecialchars($path)); } if (Common::isFile($temp_path)) { if (false === unlink($temp_path)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } } if ($mime === 'application/zip') { if (false === copy($path, $temp_path)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } $have_zip = true; } else { $have_zip = false; } $zip = new GWF_ZipArchive(); if (false === $zip->open($temp_path, GWF_ZipArchive::CREATE)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } if ($have_zip === false) { $filename = $dl->getVar('dl_filename'); $zip->addFile($path, $filename); $dl->setCustomDownloadName($filename . '.zip'); } if (false === $zip->addFromString('B.AiM/key.dat', self::getIniContent($row))) { return GWF_HTML::error('BAIM', 'The download slot is not a zip archive!'); } $zip->addFromString('B.AiM/readme.txt', self::getReadmeContent($row)); $zip->addFromString('B.AiM/release_notes.txt', self::getReleaseNotes($row)); $zip->close(); $dl->setCustomDownloadPath($temp_path); return ''; }
private function addFiles(GWF_ZipArchive $archive, array $files) { foreach ($files as $file) { if (!$this->isFileWanted($file)) { continue; } if (!Common::isFile($file)) { echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array(GWF_HTML::display($file))); return false; } if (false === $archive->addFile($file)) { echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array(GWF_HTML::display($file))); return false; } } return true; }
private function templateUpgrade() { $haveError = false; $modules = GWF_Module::loadModulesFS(); GWF_Module::sortModules($modules, 'module_name', 'asc'); # No ZIP extension? if (!class_exists('ZipArchive', false)) { return $this->module->error('err_no_zip'); } // require_once 'core/inc/util/GWF_ZipArchive.php'; # Populate the DB again GWF_VersionFiles::populateAll(); # Open temp manifest file. $manifestName = sprintf('extra/temp/upgrade_manifest_%s_%s.gwf_manifest', $this->client->getVar('vsc_uid'), $this->datestamp); if (false === ($fhManifest = fopen($manifestName, 'w'))) { return GWF_HTML::err('ERR_WRITE_FILE', array($manifestName)); } # Create ZIP $archive = new GWF_ZipArchive(); $archivename = sprintf('extra/temp/upgrade_%s_%s.zip', $this->client->getVar('vsc_uid'), $this->datestamp); if (false === $archive->open($archivename, ZipArchive::CREATE | ZipArchive::CM_REDUCE_4)) { fclose($fhManifest); return $this->module->error('err_zip', __FILE__, __LINE__); } $files = GDO::table('GWF_VersionFiles'); if (false === ($result = $files->queryReadAll('', 'vsf_path ASC'))) { // if (false === ($result = $files->queryReadAll("vsf_date>='$this->datestamp'", "vsf_path ASC"))) { // if (false === ($result = $files->queryAll())) { fclose($fhManifest); $archive->close(); @unlink($archivename); return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } fprintf($fhManifest, 'GWF2:DATESTAMP:%s' . PHP_EOL, date('YmdHis')); while (false !== ($file = $files->fetchObject($result))) { // echo GWF_HTML::message('VS_Upgrade', 'Adding File: '.$file->getVar('vsf_path')); $file instanceof GWF_VersionFiles; if (!$this->client->ownsModule($file->getVar('vsf_module'))) { continue; } if (!$this->client->ownsDesign($file->getVar('vsf_design'))) { continue; } $path = $file->getVar('vsf_path'); if (!file_exists($path)) { $file->delete(); continue; } if (!is_readable($path)) { echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array($path)); $haveError = true; break; } // is file new? $isNew = $file->getVar('vsf_date') >= $this->datestamp; if ($isNew) { // add it to archive if (false === $archive->addFile($path)) { echo GWF_HTML::err('ERR_WRITE_FILE', array($file->getVar('vsf_path'))); $haveError = true; break; } } // echo GWF_HTML::message('VS_Upgrade', 'Added File: '.$file->getVar('vsf_path')); // write manifest info fwrite($fhManifest, $file->asManifest($isNew)); } fclose($fhManifest); if (false === $archive->addFile($manifestName)) { echo GWF_HTML::err('ERR_WRITE_FILE', array($manifestName)); $haveError = true; } if (false === $archive->close()) { echo GWF_HTML::err('ERR_WRITE_FILE', array($archivename)); $haveError = true; } if (!$haveError) { GWF_Upload::outputFile($archivename); } // Delete stuff?? @unlink($manifestName); @unlink($archivename); return ''; }
private function onBundleTarget($target) { # Create ZIP $archive = new GWF_ZipArchive(); $archivename = sprintf('protected/zipped/language_bundle_%s.zip', $target); if (false === $archive->open($archivename, ZipArchive::CREATE)) { return $this->module->error('err_zip', __FILE__, __LINE__); } $files = $this->getLanguageFiles($target); foreach ($files as $file) { $archive->addFile($file); } if (false === $archive->close()) { return $this->module->error('err_zip', __FILE__, __LINE__); } return $this->module->message('msg_bundled', array($archivename, $archive->getTotalFilesCounter())); }