public static function on_download(Context $ctx) { zip::fromFolder($zipFile = os::path($ctx->config->getPath('main/tmpdir'), 'backup.zip'), MCMS_ROOT, realpath($ctx->config->getPath('main/tmpdir'))); $filename = $ctx->host() . '-' . date('YmdHi', time() - date('Z', time())) . '.zip'; header('Content-Type: application/zip'); header('Content-Length: ' . filesize($zipFile)); header('Content-Disposition: attachment; filename="' . $filename . '"'); readfile($zipFile); unlink($zipFile); die; }
public function run() { $tmpdir = os::mkdir(os::path('tmp', 'modules')); $existing = $this->getExistingModules(); foreach (glob(os::path('lib', 'modules', '*', 'module.ini')) as $inifile) { $module = basename(dirname($inifile)); $ini = array_merge(array('priority' => 'optional', 'section' => 'service'), ini::read($inifile)); foreach (array('section', 'version', 'name') as $k) { if (!array_key_exists($k, $ini)) { printf("warning: %s has no '%s' key, module ignored.\n", $module, $k); continue 2; } } if (!in_array($zipname = $module . '-' . $ini['version'] . '.zip', $existing)) { zip::fromFolder($fullzipname = os::path($tmpdir, $zipname), dirname($inifile)); printf("new file: %s\n", basename($fullzipname)); } foreach ($ini as $k => $v) { if (is_array($v)) { unset($ini[$k]); } } $ini['filename'] = $zipname; $this->modules[$module] = $ini; } ksort($this->modules); ini::write($this->inifile, $this->modules); }