function _get_export_path($guid, $name = null) { it_classes_load('it-file-utility.php'); if (!is_null($name)) { $file_name = preg_replace('/[^0-9a-z]+/', '-', strtolower($name)); $file_name = preg_replace('/-+/', '-', $file_name); $file_name = trim($file_name, '-'); $args = array('name' => "builder-export-data/export-{$guid}/builder-export-{$file_name}", 'extension' => 'zip', 'rename' => false); $file = ITFileUtility::create_writable_file($args); } else { $file = ITFileUtility::locate_file("builder-export-data/export-{$guid}/builder-export-*.zip"); if (is_array($file)) { if (isset($file[0]) && is_file($file[0])) { $file = $file[0]; } else { $file = new WP_Error('builder-import-export-cannot-locate-export', 'Unable to locate the needed export file'); } } } return $file; }
function create_zip($args = array()) { if (empty($this->_path)) { return false; } if (is_string($args)) { $args = array('name' => $args); } if (!is_array($args)) { $args = array(); } $default_args = array('file' => null, 'name' => 'temp', 'extension' => '.zip', 'disable_compression' => false, 'append_zip' => false, 'paths' => array()); $args = array_merge($default_args, $args); if (!empty($args['file']) && is_file($args['file']) && !is_writable($args['file'])) { return new WP_Error('cannot_overwrite_existing_file', 'The requested zip file path to be used exists and cannot be overridden'); } if (!empty($args['file'])) { if (!ITFileUtility::is_file_writable($args['file'])) { return new WP_Error('create_zip_file_not_writable', 'Requested zip file name is not writable'); } $file = $args['file']; } else { $file = ITFileUtility::create_writable_file(array('name' => $args['name'], 'extension' => $args['extension'], 'custom_search_paths' => $args['paths'])); if (is_wp_error($file)) { return $file; } } $result = false; if (true !== $this->_args['force_compatibility']) { $result = $this->_create_native_zip($file, $args); } if (true !== $result) { $result = $this->_create_compatibility_zip($file, $args); } if (is_wp_error($result)) { return $result; } else { if (true !== $result) { return new WP_Error('unknown_zip_failure', 'Zip file creation failed for an unknown reason'); } } if (empty($args['file'])) { $this->_zip = $file; } return $file; }