} else { // build a zip archive include_once '../shared/zipfile.php'; $zipfile = new zipfile(); // get related files from the database $items = array(); if (isset($type) && isset($id)) { $items = Files::list_by_date_for_anchor($type . ':' . $id, 0, 20, 'raw'); } // archive each file $file_path = $context['path_to_root'] . Files::get_path($type . ':' . $id); foreach ($items as $id => $attributes) { // read file content if ($content = Safe::file_get_contents($file_path . '/' . $attributes['file_name'], 'rb')) { // add the binary data $zipfile->deflate($attributes['file_name'], Safe::filemtime($file_path . '/' . $attributes['file_name']), $content); } } // // transfer to the user agent // // send the archive content if ($archive = $zipfile->get()) { // suggest a download Safe::header('Content-Type: application/octet-stream'); // suggest a name for the saved file $file_name = utf8::to_ascii($item['title']) . '.zip'; Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"'); // file size Safe::header('Content-Length: ' . strlen($archive)); // already encoded
// process every reference file $all_files = array(); $index = 0; foreach ($references as $reference) { // let's go list($path, $file) = $reference; if (strlen(trim($path)) > 0) { $file = $path . '/' . $file; } // read file content if (($content = Safe::file_get_contents($file_path . $file)) !== FALSE) { // compress textual content if ($content && preg_match('/\\.(css|htc|htm|html|include|js|mo|php|po|pot|sql|txt|xml)$/i', $file)) { $zipfile->deflate('yacs/' . $file, Safe::filemtime($file_path . $file), $content); } else { $zipfile->store('yacs/' . $file, Safe::filemtime($file_path . $file), $content); } // to be included in tar file as well $all_files[] = $file_path . $file; } else { $context['text'] .= BR . 'cannot read ' . $file_path . $file; } // avoid timeouts if (!($index++ % 50)) { Safe::set_time_limit(30); SQL::ping(); } } // save the zipfile if ($handle = Safe::fopen($context['path_to_root'] . $file_name . '.zip', 'wb')) { fwrite($handle, $zipfile->get());
// not part of the reference set anymore $content = preg_replace('/\\s*\\*\\s+@reference\\s*\\n/i', "\n", $content); // save it as the new cache file if (Safe::file_put_contents($target, $content)) { $context['text'] .= sprintf(i18n::s('%s has been transcoded'), $target) . BR . "\n"; } else { $context['text'] .= sprintf(i18n::s('Impossible to write to %s.'), $target) . BR . "\n"; $errors++; } // copy the file } elseif (!Safe::copy($context['path_to_root'] . $origin, $context['path_to_root'] . $target)) { $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $target) . BR . "\n"; $errors++; // attempt to preserve the modification date of the origin file } else { Safe::touch($context['path_to_root'] . $target, Safe::filemtime($context['path_to_root'] . $origin)); $context['text'] .= sprintf(i18n::s('%s has been copied'), $target) . BR . "\n"; } // this will be filtered by umask anyway Safe::chmod($context['path_to_root'] . $target, $context['file_mask']); } $context['text'] .= "</p>\n"; } // some errors have occured if ($errors) { $context['text'] .= '<p>' . i18n::s('Operation has failed.') . "</p>\n"; } else { $context['text'] .= '<p>' . i18n::s('Congratulations, themes have been updated.') . '</p>' . '<p>' . sprintf(i18n::s('Feel free to change and adjust files at skins/%s to better suit your needs.'), $directory) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array();
include_once '../shared/zipfile.php'; $zipfile = new zipfile(); // process every skin/current_skin/ file $index = 0; foreach ($datafiles as $datafile) { // let's go list($path, $filename) = $datafile; if ($path) { $file = $path . '/' . $filename; } else { $file = $filename; } // read file content if (($content = Safe::file_get_contents($file_prefix . $file)) !== FALSE) { // store binary data $zipfile->store($file, Safe::filemtime($file_prefix . $file), $content); // avoid timeouts if (!($index++ % 50)) { Safe::set_time_limit(30); SQL::ping(); } } } // suggest a download Safe::header('Content-Type: application/zip'); Safe::header('Content-Disposition: attachment; filename="backup_' . $context['skin'] . '.zip"'); // send the archive content echo $zipfile->get(); // do not allow for regular rendering return; // no file