Translation update done using Pootle.
[phpmyadmin/crack.git] / libraries / zip_extension.lib.php
blob435d3191477a81112b9b63b9c9eb926739c0e606
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * Interface for the zip extension
6 * @package phpMyAdmin
7 */
9 /**
10 * Gets zip file contents
12 * @param string $file
13 * @return array ($error_message, $file_data); $error_message
14 * is empty if no error
17 function PMA_getZipContents($file)
19 $error_message = '';
20 $file_data = '';
21 $zip_handle = zip_open($file);
22 if (is_resource($zip_handle)) {
23 $first_zip_entry = zip_read($zip_handle);
24 if (false === $first_zip_entry) {
25 $error_message = __('No files found inside ZIP archive!');
26 } else {
27 /* Is the the zip really an ODS file? */
28 $read = zip_entry_read($first_zip_entry);
29 $ods_mime = 'application/vnd.oasis.opendocument.spreadsheet';
30 if (!strcmp($ods_mime, $read)) {
31 /* Return the correct contents, not just the first entry */
32 for ( ; ; ) {
33 $entry = zip_read($zip_handle);
34 if (is_resource($entry)) {
35 if (!strcmp('content.xml', zip_entry_name($entry))) {
36 zip_entry_open($zip_handle, $entry, 'r');
37 $file_data = zip_entry_read($entry, zip_entry_filesize($entry));
38 zip_entry_close($entry);
39 break;
41 } else {
42 /**
43 * Either we have reached the end of the zip and still
44 * haven't found 'content.xml' or there was a parsing
45 * error that we must display
47 if ($entry === FALSE) {
48 $error_message = __('Error in ZIP archive:') . ' Could not find "content.xml"';
49 } else {
50 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
53 break;
56 } else {
57 zip_entry_open($zip_handle, $first_zip_entry, 'r');
58 /* File pointer has already been moved, so include what was read above */
59 $file_data = $read;
60 $file_data .= zip_entry_read($first_zip_entry, zip_entry_filesize($first_zip_entry));
61 zip_entry_close($first_zip_entry);
64 } else {
65 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
67 zip_close($zip_handle);
68 return (array('error' => $error_message, 'data' => $file_data));
71 /**
72 * Gets zip error message
74 * @param integer error code
75 * @return string error message
77 function PMA_getZipError($code)
79 // I don't think this needs translation
80 switch ($code) {
81 case ZIPARCHIVE::ER_MULTIDISK:
82 $message = 'Multi-disk zip archives not supported';
83 break;
84 case ZIPARCHIVE::ER_READ:
85 $message = 'Read error';
86 break;
87 case ZIPARCHIVE::ER_CRC:
88 $message = 'CRC error';
89 break;
90 case ZIPARCHIVE::ER_NOZIP:
91 $message = 'Not a zip archive';
92 break;
93 case ZIPARCHIVE::ER_INCONS:
94 $message = 'Zip archive inconsistent';
95 break;
96 default:
97 $message = $code;
99 return $message;