Skip to content

Commit

Permalink
This commit was manufactured by cvs2svn to create branch 'PHP_5_2'.
Browse files Browse the repository at this point in the history
  • Loading branch information
SVN Migration committed Jul 24, 2006
1 parent 467e129 commit 664d102
Show file tree
Hide file tree
Showing 102 changed files with 8,730 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/zip/CREDITS
@@ -0,0 +1,2 @@
Zip
Pierre-Alain Joye
4 changes: 4 additions & 0 deletions ext/zip/TODO
@@ -0,0 +1,4 @@
- add pattern support to extract or add files
- stream to add or modify entries
- crypt support for zip (read and write)
- Iterators
68 changes: 68 additions & 0 deletions ext/zip/config.m4
@@ -0,0 +1,68 @@
dnl
dnl $Id$
dnl

PHP_ARG_ENABLE(zip, for zip archive read/writesupport,
[ --enable-zip Include Zip read/write support.])

if test -z "$PHP_ZLIB_DIR"; then
PHP_ARG_WITH(zlib-dir, for the location of libz,
[ --with-zlib-dir[=DIR] zip: Set the path to libz install prefix.], no, no)
fi

if test "$PHP_ZIP" != "no"; then

if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
else
AC_MSG_ERROR([Can't find zlib headers under "$PHP_ZLIB_DIR"])
fi
else
for i in /usr/local /usr; do
if test -f "$i/include/zlib/zlib.h"; then
PHP_ZLIB_DIR="$i"
PHP_ZLIB_INCDIR="$i/include/zlib"
elif test -f "$i/include/zlib.h"; then
PHP_ZLIB_DIR="$i"
PHP_ZLIB_INCDIR="$i/include"
fi
done
fi

dnl # zlib
AC_MSG_CHECKING([for the location of zlib])
if test "$PHP_ZLIB_DIR" = "no"; then
AC_MSG_ERROR([zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located])
else
AC_MSG_RESULT([$PHP_ZLIB_DIR])
PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/lib, ZIP_SHARED_LIBADD)
PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
fi

PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
lib/zip_fread.c lib/zip_open.c lib/zip_source_filep.c \
lib/zip_strerror.c lib/zip_close.c lib/zip_error_get.c \
lib/zip_file_error_get.c lib/zip_free.c lib/zip_rename.c \
lib/zip_source_free.c lib/zip_unchange_all.c lib/zip_delete.c \
lib/zip_error_get_sys_type.c lib/zip_file_get_offset.c \
lib/zip_get_name.c lib/zip_replace.c lib/zip_source_function.c \
lib/zip_unchange.c lib/zip_dirent.c lib/zip_error_strerror.c \
lib/zip_file_strerror.c lib/zip_get_num_files.c \
lib/zip_set_name.c lib/zip_source_zip.c lib/zip_unchange_data.c \
lib/zip_entry_free.c lib/zip_error_to_str.c lib/zip_fopen.c \
lib/zip_name_locate.c lib/zip_source_buffer.c lib/zip_stat.c \
lib/zip_entry_new.c lib/zip_err_str.c lib/zip_fopen_index.c \
lib/zip_new.c lib/zip_source_file.c lib/zip_stat_index.c lib/zip_get_archive_comment.c \
lib/zip_get_file_comment.c lib/zip_set_archive_comment.c lib/zip_set_file_comment.c \
lib/zip_unchange_archive.c lib/zip_memdup.c"

AC_DEFINE(HAVE_ZIP,1,[ ])
PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)
PHP_ADD_BUILD_DIR($ext_builddir/lib, 1)
PHP_SUBST(ZIP_SHARED_LIBADD)
fi
37 changes: 37 additions & 0 deletions ext/zip/config.w32
@@ -0,0 +1,37 @@
// $Id$
// vim:ft=javascript

ARG_ENABLE("zip", "ZIP support", "no");

if (PHP_ZIP != "no") {

if (CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS_ZIP", "..\\zlib;" + php_usual_include_suspects + ";" + PHP_ZIP)) {
if (PHP_ZLIB_SHARED) {
CHECK_LIB("zlib.lib", "zip", PHP_ZIP);
}
EXTENSION('zip', 'php_zip.c zip_stream.c');
ADD_SOURCES(configure_module_dirname + "/lib", "zip_add.c zip_error.c zip_fclose.c \
zip_fread.c zip_open.c zip_source_filep.c \
zip_strerror.c zip_close.c zip_error_get.c \
zip_file_error_get.c zip_free.c zip_rename.c \
zip_source_free.c zip_unchange_all.c zip_delete.c \
zip_error_get_sys_type.c zip_file_get_offset.c \
zip_get_name.c zip_replace.c zip_source_function.c \
zip_unchange.c zip_dirent.c zip_error_strerror.c \
zip_file_strerror.c zip_get_num_files.c \
zip_set_name.c zip_source_zip.c zip_unchange_data.c \
zip_entry_free.c zip_error_to_str.c zip_fopen.c \
zip_name_locate.c zip_source_buffer.c zip_stat.c \
zip_entry_new.c zip_err_str.c zip_fopen_index.c \
zip_new.c zip_source_file.c zip_stat_index.c \
zip_get_archive_comment.c zip_get_file_comment.c \
zip_set_archive_comment.c zip_set_file_comment.c \
zip_unchange_archive.c zip_memdup.c", "zip");

AC_DEFINE('HAVE_ZLIB', 1);
AC_DEFINE('HAVE_ZIP', 1);
} else {
WARNING("zip not enabled; libraries and headers not found");
}
}

6 changes: 6 additions & 0 deletions ext/zip/examples/comment.php
@@ -0,0 +1,6 @@
<?php
$z = new ZipArchive;
$z->open('test_with_comment.zip');
// Add "Foo Comment" as comment for the foo entry
$z->setCommentName('foo', 'Too Comment ' . time());
$z->close();
23 changes: 23 additions & 0 deletions ext/zip/examples/create.php
@@ -0,0 +1,23 @@
<?php
error_reporting(E_ALL);
if (!extension_loaded('zip')) {
dl('zip.so');
}
$thisdir = dirname(__FILE__);
unlink("./test112.zip");
$zip = new ZipArchive();
$filename = "./test112.zip";

if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
exit("cannot open <$filename>\n");
} else {
echo "file <$filename> OK\n";
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
unset($zip);
21 changes: 21 additions & 0 deletions ext/zip/examples/dir.php
@@ -0,0 +1,21 @@
<?php
if (!extension_loaded('zip')) {
dl('zip.so');
}

$za = new ZipArchive();

$za->open('test_with_comment.zip');
print_r($za);
var_dump($za);
echo "numFiles: " . $za->numFiles . "\n";
echo "status: " . $za->status . "\n";
echo "statusSys: " . $za->statusSys . "\n";
echo "filename: " . $za->filename . "\n";
echo "comment: " . $za->comment . "\n";

for ($i=0; $i<$za->numFiles;$i++) {
echo "index: $i\n";
print_r($za->statIndex($i));
}
echo "numFile:" . $za->numFiles . "\n";
28 changes: 28 additions & 0 deletions ext/zip/examples/extract.php
@@ -0,0 +1,28 @@
<?php
if (!extension_loaded('zip')) {
dl('zip.so');
}

$zip = new ZipArchive();

echo $zip->filename . "\n";
$zip->open("test.zip");
/*
$zip->addFile("./modules/");
$zip->addFile("./testempty");
*/
echo $zip->status . "\n";
echo $zip->statusSys . "\n";

echo $zip->numFiles . "\n";
echo $zip->filename . "\n";
var_dump($zip);
$files = array('test', 'testdir/test2');
if (!$zip->extractTo("./testext/path/to", $files)) {
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";

}

$zip->close();
24 changes: 24 additions & 0 deletions ext/zip/examples/extractAll.php
@@ -0,0 +1,24 @@
<?php
$zip = new ZipArchive();

echo $zip->filename . "\n";
$zip->open("test.zip");
/*
$zip->addFile("./modules/");
$zip->addFile("./testempty");
*/
echo $zip->status . "\n";
echo $zip->statusSys . "\n";

echo $zip->numFiles . "\n";
echo $zip->filename . "\n";
var_dump($zip);
$files = array('test', 'testdir/test2');
if (!$zip->extractTo("./testext/path/to")) {
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";

}

$zip->close();
35 changes: 35 additions & 0 deletions ext/zip/examples/fopen.php
@@ -0,0 +1,35 @@
<?php
if (!extension_loaded('zip')) {
dl('zip.so');
}


$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
if (!$fp) {
exit("cannot open\n");
}
while (!feof($fp)) {
$contents .= fread($fp, 2);
echo "$contents\n";
}

fclose($fp);
echo "done.\n";


$content = '';
$z = new ZipArchive();
$z->open(dirname(__FILE__) . '/test.zip');
$fp = $z->getStream('test');

var_dump($fp);
if(!$fp) exit("\n");
while (!feof($fp)) {
$contents .= fread($fp, 2);
}

fclose($fp);
file_put_contents('t',$contents);
echo "done.\n";


38 changes: 38 additions & 0 deletions ext/zip/examples/get_set_comments.php
@@ -0,0 +1,38 @@
<?php
error_reporting(E_ALL|E_STRICT);

copy('test_with_comment.zip', 't.zip');
$z = new ZipArchive;
$z->open('t.zip');

print_r($z);

for ($i=0; $i<$z->numFiles; $i++) {
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
}
echo "foobar/ " . $z->getCommentName('foobar/') . "\n";

echo "Archive comment: " . $z->getArchiveComment() . "\n";


$z->setCommentIndex(1, 'new comment idx 1');
$z->setCommentName('foobar/', 'new comment foobar/');

$z->setArchiveComment( 'new archive comment');

for ($i=0; $i<$z->numFiles; $i++) {
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
}

echo $z->getCommentName('foobar/') . "\n";

// Get the original comment
echo $z->getCommentName('foobar/', ZIPARCHIVE::FL_UNCHANGED) . "\n";

echo "Archive comment: " . $z->getArchiveComment() . "\n";
echo "Archive comment (original): " . $z->getArchiveComment(ZIPARCHIVE::FL_UNCHANGED) . "\n";

11 changes: 11 additions & 0 deletions ext/zip/examples/im.php
@@ -0,0 +1,11 @@
<?php
/* $Id$ */
$im = imagecreatefromgif('zip://' . dirname(__FILE__) . '/test_im.zip#pear_item.gif');
imagepng($im, 'a.png');

$z = new ZipArchive();
$z->open(dirname(__FILE__) . '/test_im.zip');
$im_string = $z->getFromName("pear_item.gif");
$im = imagecreatefromstring($im_string);
imagepng($im, 'b.png');

20 changes: 20 additions & 0 deletions ext/zip/examples/odt.php
@@ -0,0 +1,20 @@
<?php
/* $Id$ */
$reader = new XMLReader();

$reader->open('zip://' . dirname(__FILE__) . '/test.odt#meta.xml');
$odt_meta = array();
while ($reader->read()) {
if ($reader->nodeType == XMLREADER::ELEMENT) {
$elm = $reader->name;
} else {
if ($reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == 'office:meta') {
break;
}
if (!trim($reader->value)) {
continue;
}
$odt_meta[$elm] = $reader->value;
}
}
print_r($odt_meta);
17 changes: 17 additions & 0 deletions ext/zip/examples/oldapi.php
@@ -0,0 +1,17 @@
<?php

$zip = zip_open('examples/test1.zip');
var_dump($zip);

if ($zip) {
$i = 0;
while ($zip_entry = zip_read($zip)) {
var_dump($zip_entry);
$txt = zip_entry_read($zip_entry, 10);
echo $i . ": " . $txt . "size: " . zip_entry_filesize($zip_entry) .
"comp_method: " . zip_entry_compressionmethod($zip_entry) .
"\n";
$i++;
}
var_dump($zip_entry);
}
Binary file added ext/zip/examples/test.odt
Binary file not shown.
Binary file added ext/zip/examples/test.zip
Binary file not shown.
Binary file added ext/zip/examples/test1.zip
Binary file not shown.
Binary file added ext/zip/examples/test_im.zip
Binary file not shown.
Binary file added ext/zip/examples/test_with_comment.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions ext/zip/examples/too.php
@@ -0,0 +1,2 @@
<?php
echo "too";

0 comments on commit 664d102

Please sign in to comment.