本文整理汇总了PHP中Archive_Tar::listContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Archive_Tar::listContent方法的具体用法?PHP Archive_Tar::listContent怎么用?PHP Archive_Tar::listContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Archive_Tar
的用法示例。
在下文中一共展示了Archive_Tar::listContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listFiles
/**
* Method to return a listing of the contents of an archived file
*
* @param boolean $full
* @return array
*/
public function listFiles($full = false)
{
$files = array();
$list = $this->archive->listContent();
if (!$full) {
foreach ($list as $file) {
$files[] = $file['filename'];
}
} else {
$files = $list;
}
return $files;
}
示例2: uploadPackage
public function uploadPackage()
{
$tgz = $this->getValue('tgz_file');
$svn = $this->getValue('svn_url');
$gitUrl = $this->getValue('git_url');
$gitCommit = $this->getValue('git_commit');
$memberId = sfContext::getInstance()->getUser()->getMemberId();
$pear = opPluginChannelServerToolkit::registerPearChannel($this->getChannel());
if ($tgz) {
require_once 'Archive/Tar.php';
$info = $pear->infoFromTgzFile($tgz->getTempName());
if ($info instanceof PEAR_Error) {
throw new RuntimeException($info->getMessage());
}
$tar = new Archive_Tar($tgz->getTempName());
$xml = '';
foreach ($tar->listContent() as $file) {
if ('package.xml' === $file['filename']) {
$xml = $tar->extractInString($file['filename']);
}
}
$file = new File();
$file->setFromValidatedFile($tgz);
$file->save();
$this->uploadToS3($file);
$release = Doctrine::getTable('PluginRelease')->createByPackageInfo($info, $file, $memberId, $xml);
$this->package->PluginRelease[] = $release;
$this->package->save();
} elseif ($svn) {
$dir = $this->importFromSvn($svn);
$this->importSCMFile($pear, $memberId, $dir);
} elseif ($gitUrl && $gitCommit) {
$dir = $this->importFromGit($gitUrl, $gitCommit);
$this->importSCMFile($pear, $memberId, $dir);
}
}
示例3: extractSource
function extractSource($tarfile, $target_dir, $modes)
{
$tar = new Archive_Tar($tarfile);
$root_folders = array();
foreach ($tar->listContent() as $value) {
if (substr($value["filename"], -1) == "/" && substr_count($value["filename"], "/") == 1) {
$root_folders[] = $value["filename"];
}
}
if (count($root_folders) > 1) {
echo "Error: too much root folders found.";
}
$root_folder = $root_folders[0];
$extract_list = array();
foreach ($tar->listContent() as $value) {
if (substr($value["filename"], 0, strlen($root_folder)) == $root_folder && strlen($value["filename"]) > strlen($root_folder)) {
$extract_list[] = $value["filename"];
}
}
$tar->extractList($extract_list, $target_dir, $root_folder, true);
chmod_r($target_dir, $modes);
}
示例4: decompressArchive
/**
* Decompress a tar archive of a site.
*
* @param string $archivePath
* @param string $decompressDir
* @return void
* @access public
* @since 3/14/08
*/
public function decompressArchive($archivePath, $decompressDir)
{
if (!file_exists($archivePath)) {
throw new Exception("Archive, '" . basename($archivePath) . "' does not exist.");
}
if (!is_readable($archivePath)) {
throw new Exception("Archive, '" . basename($archivePath) . "' is not readable.");
}
// Decompress the archive into our temp-dir
$archive = new Archive_Tar($archivePath);
// Check for a containing directory and strip it if needed.
$content = @$archive->listContent();
if (!is_array($content) || !count($content)) {
throw new Exception("Invalid Segue archive. '" . basename($archivePath) . "' is not a valid GZIPed Tar archive.");
}
$containerName = null;
// printpre($content);
if ($content[0]['typeflag'] == 5) {
$containerName = trim($content[0]['filename'], '/') . '/';
for ($i = 1; $i < count($content); $i++) {
// if one of the files isn't in the container, then we don't have a container of all
if (strpos($content[$i]['filename'], $containerName) === false) {
$containerName = null;
break;
}
}
}
// printpre($containerName);
$decompressResult = @$archive->extractModify($decompressDir, $containerName);
if (!$decompressResult) {
throw new Exception("Could not decompress Segue archive: '" . basename($archivePath) . "' size, " . ByteSize::withValue(filesize($archivePath))->asString() . ".");
}
if (!file_exists($decompressDir . "/site.xml")) {
throw new Exception("Invalid Segue archive. 'site.xml' was not found in '" . implode("', '", scandir($decompressDir)) . "'.");
}
}
示例5: getBackupInfo
public static function getBackupInfo($filename)
{
G::LoadThirdParty('pear/Archive', 'Tar');
$backup = new Archive_Tar($filename);
//Get a temporary directory in the upgrade directory
$tempDirectory = PATH_DATA . "upgrade/" . basename(tempnam(__FILE__, ''));
mkdir($tempDirectory);
$metafiles = array();
foreach ($backup->listContent() as $backupFile) {
$filename = $backupFile["filename"];
if (strpos($filename, "/") === false && substr_compare($filename, ".meta", -5, 5, true) === 0) {
if (!$backup->extractList(array($filename), $tempDirectory)) {
throw new Exception("Could not extract backup");
}
$metafiles[] = "{$tempDirectory}/{$filename}";
}
}
CLI::logging("Found " . count($metafiles) . " workspace(s) in backup\n");
foreach ($metafiles as $metafile) {
$data = file_get_contents($metafile);
$workspaceData = G::json_decode($data);
CLI::logging("\n");
workspaceTools::printInfo((array) $workspaceData);
}
G::rm_dir($tempDirectory);
}
示例6: submitAddLang
public function submitAddLang()
{
global $currentIndex;
$arr_import_lang = explode('|', Tools::getValue('params_import_language'));
/* 0 = Language ISO code, 1 = PS version */
if (Validate::isLangIsoCode($arr_import_lang[0])) {
if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/' . $arr_import_lang[1] . '/' . $arr_import_lang[0] . '.gzip', false, @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5))))) {
$file = _PS_TRANSLATIONS_DIR_ . $arr_import_lang[0] . '.gzip';
if (file_put_contents($file, $content)) {
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
if ($gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$this->checkAndAddMailsFiles($arr_import_lang[0], $files_list);
if (!Language::checkAndAddLanguage($arr_import_lang[0])) {
$conf = 20;
}
if (!unlink($file)) {
$this->_errors[] = Tools::displayError('Cannot delete archive');
}
Tools::redirectAdmin($currentIndex . '&conf=' . (isset($conf) ? $conf : '15') . '&token=' . $this->token);
}
$this->_errors[] = Tools::displayError('Archive cannot be extracted.');
if (!unlink($file)) {
$this->_errors[] = Tools::displayError('Cannot delete archive');
}
} else {
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
} else {
$this->_errors[] = Tools::displayError('Language not found');
}
} else {
$this->_errors[] = Tools::displayError('Invalid parameter');
}
}
示例7: installPluginArchive
/**
* Install a plugin archive. If pluginName is specified, the archive will
* only be installed if it contains this plugin.
*
* @return bool true if enabled, false otherwise
*/
function installPluginArchive($filename, $pluginName)
{
G::LoadThirdParty("pear/Archive", "Tar");
$tar = new Archive_Tar($filename);
$files = $tar->listContent();
$plugins = array();
$namePlugin = array();
foreach ($files as $f) {
//if (preg_match("/^([\w\.]*).ini$/", $f["filename"], $matches)) {
if (preg_match("/^(.*pluginConfig)\\.ini\$/", $f["filename"], $matches)) {
$plugins[] = $matches[1];
}
if (preg_match("/^.*({$pluginName})\\.php\$/", $f["filename"], $matches)) {
$namePlugin[] = $matches[1];
}
}
if (count($plugins) > 1) {
throw new Exception("Multiple plugins in one archive are not supported currently");
}
//if (isset($pluginName) && !in_array($pluginName, $plugins)) {
if (isset($pluginName) && !in_array($pluginName, $namePlugin)) {
throw new Exception("Plugin '{$pluginName}' not found in archive");
}
//$pluginName = $plugins[0];
$pluginFile = "{$pluginName}.php";
/*
$oldPluginStatus = $this->getStatusPlugin($pluginFile);
if ($pluginStatus != 0) {
$oldDetails = $this->getPluginDetails($pluginFile);
$oldVersion = $oldDetails->iVersion;
} else {
$oldDetails = NULL;
$oldVersion = NULL;
}
*/
//$pluginIni = $tar->extractInString("$pluginName.ini");
//$pluginConfig = parse_ini_string($pluginIni);
/*
if (!empty($oClass->aDependences)) {
foreach ($oClass->aDependences as $aDependence) {
if (file_exists(PATH_PLUGINS . $aDependence['sClassName'] . '.php')) {
require_once PATH_PLUGINS . $aDependence['sClassName'] . '.php';
if (!$oPluginRegistry->getPluginDetails($aDependence['sClassName'] . '.php')) {
throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin');
}
}
else {
throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin');
}
}
}
unset($oClass);
if ($fVersionOld > $fVersionNew) {
throw new Exception('A recent version of this plugin was already installed.');
}
*/
$res = $tar->extract(PATH_PLUGINS);
if (!file_exists(PATH_PLUGINS . $pluginFile)) {
throw new Exception("File \"{$pluginFile}\" doesn't exist");
}
require_once PATH_PLUGINS . $pluginFile;
$details = $this->getPluginDetails($pluginFile);
$this->installPlugin($details->sNamespace);
$this->setupPlugins();
$this->enablePlugin($details->sNamespace);
$this->save();
}
示例8: implode
}
if (count(explode('.', $BASE_VERSION)) < 3) {
I2CE::raiseError("Bad version {$BASE_VERSION}");
}
I2CE::raiseError("Base version is {$BASE_VERSION}");
$BASE_VERSION_SHORT = implode('.', array_slice(explode('.', $BASE_VERSION), 0, 2));
$BASE_VERSION_SHORT_NEXT = array_slice(explode('.', $BASE_VERSION), 0, 2);
$BASE_VERSION_SHORT_NEXT[1]++;
$BASE_VERSION_SHORT_NEXT = implode('.', $BASE_VERSION_SHORT_NEXT);
if (!$booleans['read_po_files']) {
I2CE::raiseError("Using archive: " . realpath($archive));
$tar = new Archive_Tar($archive);
$tar->setErrorHandling(PEAR_ERROR_CALLBACK, array('I2CE', 'raiseError'));
$tar_files = array();
$tar_dirs = array();
$files = $tar->listContent();
foreach ($files as $data) {
if (!array_key_exists('filename', $data)) {
continue;
}
if ($data['typeflag'] == 5) {
$tar_dirs[] = $data['filename'];
} else {
if ($data['typeflag'] == 0) {
$tar_files[] = $data['filename'];
}
}
}
if ($locales == false) {
$locales = array();
foreach ($tar_dirs as $dir) {
示例9: usage
case 'bz2':
$compression = 'bz2';
case 'tar':
$compression = null;
break;
default:
echo "Could not determine archive type for {$archive_file}";
}
$tar = new Archive_Tar($archive_file, $compression);
if (!$tar->create(array())) {
usage("Could not create tar {$archive_file}");
}
$glob = preg_replace('/(\\*|\\?|\\[)/', '[$1]', $translations_dir . DIRECTORY_SEPARATOR) . '*.pot';
foreach (glob($glob) as $file) {
if (!$tar->addModify($file, 'translations/' . basename($file, '.pot'), $translations_dir)) {
usage("Could not add {$base}");
}
}
echo "Created {$archive_file} with:\n";
$contents = $tar->listContent();
foreach ($contents as $content) {
echo "\t{$content['filename']}\n";
}
echo "Upload translations by browsing to:\n\t";
echo 'https://translations.edge.launchpad.net/' . $module . '/trunk/+translations-upload' . "\n";
# Local Variables:
# mode: php
# c-default-style: "bsd"
# indent-tabs-mode: nil
# c-basic-offset: 4
# End:
示例10: infoFromTgzFile
/**
* Returns information about a package file. Expects the name of
* a gzipped tar file as input.
*
* @param string $file name of .tgz file
*
* @return array array with package information
*
* @access public
*
*/
function infoFromTgzFile($file)
{
if (!@is_file($file)) {
return $this->raiseError("could not open file \"{$file}\"");
}
$tar = new Archive_Tar($file);
if ($this->debug <= 1) {
$tar->pushErrorHandling(PEAR_ERROR_RETURN);
}
$content = $tar->listContent();
if ($this->debug <= 1) {
$tar->popErrorHandling();
}
if (!is_array($content)) {
$file = realpath($file);
return $this->raiseError("Could not get contents of package \"{$file}\"" . '. Invalid tgz file.');
}
$xml = null;
foreach ($content as $file) {
$name = $file['filename'];
if ($name == 'package.xml') {
$xml = $name;
break;
} elseif (ereg('package.xml$', $name, $match)) {
$xml = $match[0];
break;
}
}
$tmpdir = System::mkTemp(array('-d', 'pear'));
$this->addTempFile($tmpdir);
if (!$xml || !$tar->extractList(array($xml), $tmpdir)) {
return $this->raiseError('could not extract the package.xml file');
}
return $this->infoFromDescriptionFile("{$tmpdir}/{$xml}");
}
示例11: createPatch
function createPatch($updatecache = false)
{
include_once "Lib/Archive/Tar.php";
include_once 'Lib/Text/Diff.php';
include_once 'Lib/Text/Diff/Renderer/unified.php';
$start = microtime(true);
$tar_object = new Archive_Tar(_bmoddir . "Data/Cache.tar");
$tar_object->setErrorHandling(PEAR_ERROR_PRINT);
$tardata = $tar_object->listContent();
$working = checkDir2("");
$fmerged = array_merge($tardata, $working);
$tarf_db = reIndexByFile($tardata);
$work_db = reIndexByFile($working);
$workidx = indexFilename($working);
$tar_idx = indexFilename($tardata);
$f_names = array_unique(array_merge($workidx, $tar_idx));
$out = "";
foreach ($f_names as $file) {
//speed optimization
if ($tarf_db[$file] && $work_db[$file] && $tarf_db[$file]["mtime"] == $work_db[$file]["mtime"] && $updatecache != true) {
continue;
}
if ($tarf_db[$file]) {
$fts1 = $tarf_db[$file]["mtime"];
$fdata = $tar_object->extractInString($file);
$lines1 = explode("\n", $fdata);
//$lines1 = file("Data/$file");
if (substr($fdata, -1, 1) == "\n") {
//$lines1[] = "";
}
} else {
$fts1 = 0;
$lines1 = array();
}
if ($work_db[$file]) {
$fts2 = $work_db[$file]["mtime"];
//$lines2 = file(_bpatdir."$file");
$filetext = file_get_contents(_bmoddir . _bpatdir . "{$file}");
$lines2 = explode("\n", $filetext);
} else {
$fts2 = 0;
$lines2 = array();
$filetext = "";
}
if (array_search($file, $workidx) === false && array_search($file, $tar_idx) !== false) {
//delted file
$out .= renderHeader($file, $fts1, $fts2);
$out .= "@@ -0,0 @@\n\n";
continue;
}
if (array_search($file, $workidx) !== false && array_search($file, $tar_idx) === false) {
//added file
}
if ($filetext == $fdata) {
continue;
}
$diff = new Text_Diff('auto', array($lines1, $lines2));
$renderer = new Text_Diff_Renderer_unified();
$render = $renderer->render($diff);
if ($render != "") {
$out .= renderHeader($file, $fts1, $fts2);
//get ts to work!
$out .= $render . "\n";
if (substr($filetext, -1, 1) != "\n") {
$out .= "\\ No newline at end of file\n\n";
}
}
}
if ($updatecache == true) {
$tar_object->create(array());
foreach ($f_names as $file) {
$tar_object->addString($file, file_get_contents(_bmoddir . _bpatdir . "{$file}"));
}
}
return array(microtime(true) - $start, $out, count($addlist));
}
示例12: extract
/**
*
* Extract theme from archive
* @throws Exception
* @param string $source_path archive path
*
* @return waTheme
*/
public static function extract($source_path)
{
$autoload = waAutoload::getInstance();
$autoload->add('Archive_Tar', 'wa-installer/lib/vendors/PEAR/Tar.php');
$autoload->add('PEAR', 'wa-installer/lib/vendors/PEAR/PEAR.php');
if (class_exists('Archive_Tar')) {
try {
$tar_object = new Archive_Tar($source_path, true);
$files = $tar_object->listContent();
if (!$files) {
self::throwArchiveException('INVALID_OR_EMPTY_ARCHIVE');
}
//search theme info
$theme_check_files = array(self::PATH);
$theme_files_map = array();
$info = false;
$pattern = "/(\\/|^)" . wa_make_pattern(self::PATH) . "\$/";
foreach ($files as $file) {
if (preg_match($pattern, $file['filename'])) {
$info = $tar_object->extractInString($file['filename']);
break;
}
}
if (!$info) {
self::throwThemeException('MISSING_THEME_XML');
}
$xml = @simplexml_load_string($info);
$app_id = (string) $xml['app'];
$id = (string) $xml['id'];
if (!$app_id) {
self::throwThemeException('MISSING_APP_ID');
} elseif (!$id) {
self::throwThemeException('MISSING_THEME_ID');
} else {
if ($app_info = wa()->getAppInfo($app_id)) {
//TODO check theme support
} else {
$message = sprintf(_w('Theme “%s” is for app “%s”, which is not installed in your Webasyst. Install the app, and upload theme once again.'), $id, $app_id);
throw new waException($message);
}
}
$wa_path = "wa-apps/{$app_id}/themes/{$id}";
$wa_pattern = wa_make_pattern($wa_path);
$file = reset($files);
if (preg_match("@^{$wa_pattern}(/|\$)@", $file['filename'])) {
$extract_path = $wa_path;
$extract_pattern = $wa_pattern;
} else {
$extract_path = $id;
$extract_pattern = wa_make_pattern($id);
if (!preg_match("@^{$extract_pattern}(/|\$)@", $file['filename'])) {
$extract_path = '';
$extract_pattern = false;
}
}
foreach ($files as $file) {
if ($extract_pattern && !preg_match("@^{$extract_pattern}(/|\$)@", $file['filename'])) {
self::throwThemeException('UNEXPECTED_FILE_PATH', "{$file['filename']}. Expect files in [{$extract_path}] directory");
} elseif (preg_match('@\\.(php\\d*|pl)@', $file['filename'], $matches)) {
self::throwThemeException('UNEXPECTED_FILE_TYPE', $file['filename']);
}
}
self::verify($id);
self::protect($app_id);
$target_path = wa()->getDataPath("themes/{$id}", true, $app_id, false);
waFiles::delete($target_path);
if ($extract_path && !$tar_object->extractModify($target_path, $extract_path)) {
self::throwArchiveException('INTERNAL_ARCHIVE_ERROR');
} elseif (!$tar_object->extract($target_path)) {
self::throwArchiveException('INTERNAL_ARCHIVE_ERROR');
}
$instance = new self($id, $app_id);
$instance->check();
} catch (Exception $ex) {
if (isset($target_path) && $target_path) {
waFiles::delete($target_path, true);
}
throw $ex;
}
} else {
self::throwArchiveException('UNSUPPORTED_ARCHIVE_TYPE');
}
return $instance;
}
示例13: _installLanguages
protected function _installLanguages($xml, $install_mode = false)
{
$attributes = array();
if (isset($xml->languages->language)) {
foreach ($xml->languages->language as $data) {
$attributes = $data->attributes();
if (Language::getIdByIso($attributes['iso_code'])) {
continue;
}
$native_lang = Language::getLanguages();
$native_iso_code = array();
foreach ($native_lang as $lang) {
$native_iso_code[] = $lang['iso_code'];
}
// if we are not in an installation context or if the pack is not available in the local directory
if (!$install_mode || !in_array((string) $attributes['iso_code'], $native_iso_code)) {
$errno = 0;
$errstr = '';
if (!@fsockopen('api.prestashop.com', 80, $errno, $errstr, 5)) {
$this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
} elseif (!($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . $attributes['iso_code'])))) {
$this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
} elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $attributes['iso_code'] . '.gzip')) {
$file = _PS_TRANSLATIONS_DIR_ . $attributes['iso_code'] . '.gzip';
if (file_put_contents($file, $content)) {
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
if (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) {
$this->_errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ') . (string) $attributes['iso_code'];
return false;
} else {
AdminTranslationsController::checkAndAddMailsFiles($attributes['iso_code'], $files_list);
AdminTranslationsController::addNewTabs($attributes['iso_code'], $files_list);
}
if (!Language::checkAndAddLanguage((string) $attributes['iso_code'])) {
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ') . (string) $attributes['iso_code'];
return false;
}
@unlink($file);
} else {
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
}
}
}
}
// change the default language if there is only one language in the localization pack
if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->languages->language) == 1) {
$this->iso_code_lang = $attributes['iso_code'];
}
return true;
}
示例14: substr
function _doTAR($upfile, $path)
{
// get validator object
$validate = get_validator('upload');
// check file exists, ask overwrite ... todo
// get required pear-class
require_once "Archive/Tar.php";
//
$tar = new Archive_Tar($upfile);
$dir = $this->upload_dir . $path;
$dir = substr($dir, 0, strlen($dir) - 1);
$tarfiles = array();
if (($v_list = $tar->listContent()) != 0) {
$max = count($v_list);
// get a list of files to extract regadring the restrictions on filenames and directories
// since we can not rename file while extracting, all filenames may not include special chars
// and the trouble_chars that are set in the configuration
// aborts the extraction if a invalid directory name is in the tar-file
for ($i = 0; $i < $max; $i++) {
$name = $v_list[$i]['filename'];
if (empty($v_list[$i]['typeflag'])) {
// compressed file
if ($validate->filename($tar_name, $this->cfg_cms['trouble_chars'])) {
$tarfiles[] = $name;
} else {
$this->error_files[] = $name;
}
} else {
// directory
if (!$validate->filepath($tar_name, true, $this->cfg_cms['trouble_chars'])) {
$this->errno = '1422';
return;
}
$tarfiles[] = $name;
}
}
$tar->extractList($tarfiles, $dir);
}
}
示例15: getFiles
/**
* Get list of files in the bundle
*
* @return array
*/
public function getFiles()
{
$tar = new BundleArchive($this->getInputFile());
return $tar->listContent();
}