typos
[phpmyadmin/madhuracj.git] / libraries / zip_extension.lib.php
blobb68285176964f1e12bf0c626f3aec56c32364c56
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * Interface for the zip extension
6 * @package phpMyAdmin
7 * @version $Id$
8 */
10 /**
11 * Gets zip file contents
13 * @param string $file
14 * @return array ($error_message, $file_data); $error_message
15 * is empty if no error
16 * @author lem9
19 function PMA_getZipContents($file)
21 $error_message = '';
22 $file_data = '';
23 $zip_handle = zip_open($file);
24 if (is_resource($zip_handle)) {
25 $first_zip_entry = zip_read($zip_handle);
26 if (false === $first_zip_entry) {
27 $error_message = $GLOBALS['strNoFilesFoundInZip'];
28 } else {
29 /* Is the the zip really an ODS file? */
30 $read = zip_entry_read($first_zip_entry);
31 $ods_mime = 'application/vnd.oasis.opendocument.spreadsheet';
32 if (!strcmp($ods_mime, $read)) {
33 /* Return the correct contents, not just the first entry */
34 for ( ; ; ) {
35 $entry = zip_read($zip_handle);
36 if (is_resource($entry)) {
37 if (!strcmp('content.xml', zip_entry_name($entry))) {
38 zip_entry_open($zip_handle, $entry, 'r');
39 $file_data = zip_entry_read($entry, zip_entry_filesize($entry));
40 zip_entry_close($entry);
41 break;
43 } else {
44 /**
45 * Either we have reached the end of the zip and still
46 * haven't found 'content.xml' or there was a parsing
47 * error that we must display
49 if ($entry === FALSE) {
50 $error_message = $GLOBALS['strErrorInZipFile'] . ' Could not find "content.xml"';
51 } else {
52 $error_message = $GLOBALS['strErrorInZipFile'] . ' ' . PMA_getZipError($zip_handle);
55 break;
58 } else {
59 zip_entry_open($zip_handle, $first_zip_entry, 'r');
60 /* File pointer has already been moved, so include what was read above */
61 $file_data = $read;
62 $file_data .= zip_entry_read($first_zip_entry, zip_entry_filesize($first_zip_entry));
63 zip_entry_close($first_zip_entry);
66 } else {
67 $error_message = $GLOBALS['strErrorInZipFile'] . ' ' . PMA_getZipError($zip_handle);
69 zip_close($zip_handle);
70 return (array('error' => $error_message, 'data' => $file_data));
73 /**
74 * Gets zip error message
76 * @param integer error code
77 * @return string error message
78 * @author lem9
80 function PMA_getZipError($code)
82 // I don't think this needs translation
83 switch ($code) {
84 case ZIPARCHIVE::ER_MULTIDISK:
85 $message = 'Multi-disk zip archives not supported';
86 break;
87 case ZIPARCHIVE::ER_READ:
88 $message = 'Read error';
89 break;
90 case ZIPARCHIVE::ER_CRC:
91 $message = 'CRC error';
92 break;
93 case ZIPARCHIVE::ER_NOZIP:
94 $message = 'Not a zip archive';
95 break;
96 case ZIPARCHIVE::ER_INCONS:
97 $message = 'Zip archive inconsistent';
98 break;
99 default:
100 $message = $code;
102 return $message;