function themedrive_unzip($file, $dir) { if (!current_user_can('edit_files')) { echo 'Oops, sorry you are not authorized to do this'; return false; } if (!class_exists('PclZip')) { require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; } $unzipArchive = new PclZip($file); $list = $unzipArchive->properties(); if (!$list['nb']) { return false; } //echo "Number of files in archive : ".$list['nb']."<br>"; echo "Copying the files<br>"; $result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir); if ($result == 0) { echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . ' <br />'; return false; } else { //print_r($result); foreach ($result as $item) { if ($item['status'] != 'ok') { echo $item['stored_filename'] . ' ... ' . $item['status'] . '<br>'; } } return true; } }
function get_comment($zip_file) { // Use ZipArchive if available if (in_array('ziparchive', $this->_zip_methods)) { // Make doubly sure it is available if (class_exists('ZipArchive', false)) { $za = new ZipArchive(); $result = $za->open($zip_file); // Make sure that at least the zip file opened ok if ($result === true) { // Get the comment or false on failure for some reason $comment = $za->getArchiveComment(); $za->close(); // If we have a comment (even if empty) then return it if ($comment !== false) { // Note: new archives will return an empty comment if one was not added at creation pb_backupbuddy::status('details', sprintf(__('ZipArchive retrieved comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); // Format has changed and no longer encoding as htmlemtities when setting comment // For older backups may need to remove encoding - action _should_ be null if N/A // Only spanner would be if someone had put an entity in their comment but that is // really an outsider and in any case the correction is simply to edit and resave // TODO: Remove this when new format has been in use for some time $comment = html_entity_decode($comment); return $comment; } else { // If we failed to get the commnent then log it (?) and drop through pb_backupbuddy::status('details', sprintf(__('ZipArchive failed to retrieve comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); } } else { // If we couldn't open the zip file then log it (?) and drop through $error_string = $this->ziparchive_error_info($result); pb_backupbuddy::status('details', sprintf(__('ZipArchive failed to open file to retrieve comment in file %1$s - Error Info: %2$s', 'it-l10n-backupbuddy'), $zip_file, $error_string)); } } else { // Something fishy - the methods indicated ziparchive but we couldn't find the class pb_backupbuddy::status('details', __('ziparchive indicated as available method but ZipArchive class non-existent', 'it-l10n-backupbuddy')); } } // Dropped through because ZipArchive not available or failed for some reason if (in_array('pclzip', $this->_zip_methods)) { // Make sure we have it if (!class_exists('PclZip', false)) { // It's not already loaded so try and find/load it from possible locations if (file_exists(ABSPATH . 'wp-admin/includes/class-pclzip.php')) { // Running under WordPress @(include_once ABSPATH . 'wp-admin/includes/class-pclzip.php'); } elseif (file_exists(pb_backupbuddy::plugin_path() . '/lib/pclzip/pclzip.php')) { // Running Standalone (importbuddy) @(include_once pb_backupbuddy::plugin_path() . '/lib/pclzip/pclzip.php'); } } // Make sure we did load it if (class_exists('PclZip', false)) { $za = new PclZip($zip_file); // Make sure we opened the zip ok and it has properties if (($properties = $za->properties()) !== 0) { // We got properties so should have a comment to return, even if empty pb_backupbuddy::status('details', sprintf(__('PclZip retrieved comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file)); $comment = $properties['comment']; // Format has changed and no longer encoding as htmlemtities when setting comment // For older backups may need to remove encoding - action _should_ be null if N/A // Only spanner would be if someone had put an entity in their comment but that is // really an outsider and in any case the correction is simply to edit and resave // TODO: Remove this when new format has been in use for some time $comment = html_entity_decode($comment); return $comment; } else { // If we failed to get the commnent then log it (?) and drop through $error_string = $za->errorInfo(true); pb_backupbuddy::status('details', sprintf(__('PclZip failed to retrieve comment in file %1$s - Error Info: %2$s', 'it-l10n-backupbuddy'), $zip_file, $error_string)); } } else { // Something fishy - the methods indicated pclzip but we couldn't find the class pb_backupbuddy::status('details', __('pclzip indicated as available method but class PclZip non-existent', 'it-l10n-backupbuddy')); } } // We couldn't get a comment at all - either no available method or all methods failed pb_backupbuddy::status('details', __('Unable to get comment: No compatible zip method found.', 'it-l10n-backupbuddy')); return false; }
* @Createdate 2-2-2010 12:55 */ if (!defined('NV_IS_FILE_THEMES')) { die('Stop!!!'); } $title = $note = $module_file = ""; $page_title = $lang_module['autoinstall']; $xauto = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . 'theme' . md5(session_id()) . '.list'; $filename = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . 'theme' . md5(session_id()) . '.zip'; $xfolder = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . 'themefolder' . md5(session_id()) . '.list'; if ($nv_Request->isset_request('op', 'post')) { require_once NV_ROOTDIR . '/includes/class/pclzip.class.php'; if (is_uploaded_file($_FILES['themefile']['tmp_name'])) { if (move_uploaded_file($_FILES['themefile']['tmp_name'], $filename)) { $zip = new PclZip($filename); $status = $zip->properties(); $check_number = 0; if ($status['status'] == 'ok') { $list = $zip->listContent(); $theme = $list[0]['filename']; foreach ($list as $file_i) { if ($file_i['filename'] == $theme . "theme.php" or $file_i['filename'] == $theme . "config.ini") { $check_number++; } } } if ($check_number == 2) { nv_insert_logs(NV_LANG_DATA, $module_name, 'log_intall_theme', "theme " . $theme, $admin_info['userid']); $filefolder = ''; $filelist = ''; $validfolder = array();
// Guess why we might have failed... if (preg_match('/^https:/', $download_url) && !in_array('ssl', stream_get_transports())) { echo '<br>', WT_I18N::translate('This server does not support secure downloads using HTTPS.'); } } echo '</li>'; flush(); //////////////////////////////////////////////////////////////////////////////// // Unzip the file - this checks we have enough free disk space, that the .zip // file is valid, etc. //////////////////////////////////////////////////////////////////////////////// echo '<li>', WT_I18N::translate('Unzip %s to a temporary folder…', basename($download_url)); WT_File::delete($zip_dir); WT_File::mkdir($zip_dir); $archive = new PclZip($zip_file); $res = $archive->properties(); if (!is_array($res) || $res['status'] != 'ok') { echo '<br>', WT_I18N::translate('An error occurred when unzipping the file.'), $icon_failure; echo '</li></ul></form>'; exit; } $num_files = $res['nb']; reset_timeout(); $start_time = microtime(true); $res = $archive->extract(PCLZIP_OPT_PATH, $zip_dir, PCLZIP_OPT_REMOVE_PATH, 'webtrees', PCLZIP_OPT_REPLACE_NEWER); $end_time = microtime(true); if (is_array($res)) { foreach ($res as $result) { // Note that we're stripping the initial "webtrees/", so the top folder will fail. if ($result['status'] != 'ok' && $result['filename'] != 'webtrees/') { echo '<br>', WT_I18N::translate('An error occurred when unzipping the file.'), $icon_failure;
$act = isset($_GET['act']) ? check($_GET['act']) : 'index'; $start = isset($_GET['start']) ? abs(intval($_GET['start'])) : 0; show_title('Просмотр архива'); switch ($act) { ############################################################################################ ## Главная страница ## ############################################################################################ case 'index': $downs = DB::run()->queryFetch("SELECT `downs`.*, `cats`.`cats_id`, `cats`.`cats_name` FROM `downs` LEFT JOIN `cats` ON `downs`.`downs_cats_id`=`cats`.`cats_id` WHERE `downs_id`=? LIMIT 1;", array($id)); if (!empty($downs)) { if (!empty($downs['downs_active'])) { if (getExtension($downs['downs_link']) == 'zip') { $config['newtitle'] = 'Просмотр архива - ' . $downs['downs_title']; $zip = new PclZip('files/' . $downs['downs_link']); if (($list = $zip->listContent()) != 0) { $intotal = $zip->properties(); $total = $intotal['nb']; sort($list); if ($total > 0) { echo '<img src="/images/img/zip.gif" alt="image" /> <b>' . $downs['downs_title'] . '</b><br /><br />'; echo 'Всего файлов: ' . $total . '<hr />'; $arrext = array('xml', 'wml', 'asp', 'aspx', 'shtml', 'htm', 'phtml', 'html', 'php', 'htt', 'dat', 'tpl', 'htaccess', 'pl', 'js', 'jsp', 'css', 'txt', 'sql', 'gif', 'png', 'bmp', 'wbmp', 'jpg', 'jpeg'); if ($start < 0 || $start >= $total) { $start = 0; } if ($total < $start + $config['ziplist']) { $end = $total; } else { $end = $start + $config['ziplist']; } for ($i = $start; $i < $end; $i++) {
function unzip_file($file_name, $dir_name = '', $testonly = false){ $ret = true; if ($GLOBALS['ZIP_USE_INTERNAL']){ $archive = new PclZip($file_name); if ($testonly){ $prop = $archive->properties(); $ret = (!is_array($prop)); } else { $ok = $archive->extract(PCLZIP_OPT_PATH, $dir_name, PCLZIP_CB_PRE_EXTRACT, 'pclzip_convert_filename_cb', PCLZIP_OPT_STOP_ON_ERROR); $ret = (!is_array($ok)); } } else if (@file_exists($GLOBALS['UNZIP_PATH']) || ini_get('safe_mode')){ if ($testonly){ exec($GLOBALS['UNZIP_PATH'] . " -t -qq $file_name ", $output, $ret); } else { exec($GLOBALS['UNZIP_PATH'] . " -qq $file_name " . ($dir_name ? "-d $dir_name" : ""), $output, $ret); } } return $ret; }
function __opf_upload_check_zip($upload) { if (file_exists(WB_PATH . '/include/pclzip/pclzip.lib.php')) { require_once WB_PATH . '/include/pclzip/pclzip.lib.php'; } $archive = new PclZip($upload['tmp_name']); if ($archive->properties() == 0) { return FALSE; } else { return TRUE; } }
/** * Create a zip archive using the PclZip class * * You should not use this function directly. Use the 'zip' function above. * * @param array $sources List of paths to files and directories to be archived. * @param string $destination Destination file where the archive will be stored. * @param array $exclude Directories and/or files to exclude from archive, defaults to empty array. * @return mixed Returns TRUE on success or an instance of WP_Error on failure. */ function _zip_create_pclzip($sources, $destination, $exclude = array()) { require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; $zip = new PclZip($destination); foreach ($sources as $source) { if (!@is_readable($source)) { continue; } if (@is_dir($source)) { $files = directory_list($source, true, $exclude); if (is_wp_error($files)) { delete_path($destination); return $files; } $res = $zip->add($files, PCLZIP_OPT_REMOVE_PATH, parent_dir($source)); if (0 == $res) { return new WP_Error('pclzip', $zip->errorInfo(true)); } } elseif (@is_file($source)) { $res = $zip->add($source, PCLZIP_OPT_REMOVE_PATH, parent_dir($source)); if (0 == $res) { return new WP_Error('pclzip', $zip->errorInfo(true)); } } } $prop = $zip->properties(); return $prop['nb']; }