[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The MIME_Viewer_zip class renders out the contents of ZIP files in HTML 4 * format. 5 * 6 * $Horde: framework/MIME/MIME/Viewer/zip.php,v 1.30.10.10 2006/02/10 13:54:04 jan Exp $ 7 * 8 * Copyright 2000-2006 Chuck Hagenbuch <chuck@horde.org> 9 * Copyright 2002-2006 Michael Cochrane <mike@graftonhall.co.nz> 10 * 11 * See the enclosed file COPYING for license information (LGPL). If you 12 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 13 * 14 * @author Chuck Hagenbuch <chuck@horde.org> 15 * @author Michael Cochrane <mike@graftonhall.co.nz> 16 * @since Horde 2.0 17 * @package Horde_MIME_Viewer 18 */ 19 class MIME_Viewer_zip extends MIME_Viewer { 20 21 /** 22 * Render out the current zip contents. 23 * 24 * @param array $params Any parameters the Viewer may need. 25 * 26 * @return string The rendered contents. 27 */ 28 function render($params = array()) 29 { 30 return $this->_render($this->mime_part->getContents()); 31 } 32 33 /** 34 * Output the file list. 35 * 36 * @access private 37 * 38 * @param string $contents The contents of the zip archive. 39 * @param mixed $callback The callback function to use on the zipfile 40 * information. 41 * 42 * @return string The file list. 43 */ 44 function _render($contents, $callback = null) 45 { 46 require_once 'Horde/Compress.php'; 47 48 $zip = &Horde_Compress::singleton('zip'); 49 50 /* Make sure this is a valid zip file. */ 51 if ($zip->checkZipData($contents) === false) { 52 return '<pre>' . _("This does not appear to be a valid zip file.") . '</pre>'; 53 } 54 55 $zipInfo = $zip->decompress($contents, array('action' => HORDE_COMPRESS_ZIP_LIST)); 56 if (is_a($zipInfo, 'PEAR_Error')) { 57 return $zipInfo->getMessage(); 58 } 59 $fileCount = count($zipInfo); 60 61 require_once 'Horde/Text.php'; 62 63 $text = '<strong>' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $this->mime_part->getName())) . ':</strong>' . "\n"; 64 $text .= '<table><tr><td align="left"><tt><span class="fixed">'; 65 $text .= Text::htmlAllSpaces(_("Archive Name") . ': ' . $this->mime_part->getName()) . "\n"; 66 $text .= Text::htmlAllSpaces(_("Archive File Size") . ': ' . strlen($contents) . ' bytes') . "\n"; 67 $text .= Text::htmlAllSpaces(($fileCount != 1) ? sprintf(_("File Count: %s files"), $fileCount) : sprintf(_("File Count: %s file"), $fileCount)); 68 $text .= "\n\n"; 69 $text .= Text::htmlAllSpaces( 70 str_pad(_("File Name"), 50, ' ', STR_PAD_RIGHT) . 71 str_pad(_("Attributes"), 10, ' ', STR_PAD_LEFT) . 72 str_pad(_("Size"), 10, ' ', STR_PAD_LEFT) . 73 str_pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) . 74 str_pad(_("Method"), 10, ' ', STR_PAD_LEFT) . 75 str_pad(_("CRC"), 10, ' ', STR_PAD_LEFT) . 76 str_pad(_("Ratio"), 7, ' ', STR_PAD_LEFT) 77 ) . "\n"; 78 79 $text .= str_repeat('-', 116) . "\n"; 80 81 foreach ($zipInfo as $key => $val) { 82 $ratio = (empty($val['size'])) ? 0 : 100 * ($val['csize'] / $val['size']); 83 84 $val['name'] = str_pad($val['name'], 50, ' ', STR_PAD_RIGHT); 85 $val['attr'] = str_pad($val['attr'], 10, ' ', STR_PAD_LEFT); 86 $val['size'] = str_pad($val['size'], 10, ' ', STR_PAD_LEFT); 87 $val['date'] = str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT); 88 $val['method'] = str_pad($val['method'], 10, ' ', STR_PAD_LEFT); 89 $val['crc'] = str_pad($val['crc'], 10, ' ', STR_PAD_LEFT); 90 $val['ratio'] = str_pad(sprintf("%1.1f%%", $ratio), 7, ' ', STR_PAD_LEFT); 91 92 $val = array_map(array('Text', 'htmlAllSpaces'), $val); 93 94 if (!is_null($callback)) { 95 $val = call_user_func($callback, $key, $val); 96 } 97 98 $text .= $val['name'] . $val['attr'] . $val['size'] . 99 $val['date'] . $val['method'] . $val['crc'] . 100 $val['ratio'] . "\n"; 101 } 102 103 $text .= str_repeat('-', 116) . "\n"; 104 $text .= '</span></tt></td></tr></table>'; 105 106 return nl2br($text); 107 } 108 109 /** 110 * Return the content-type 111 * 112 * @return string The content-type of the output. 113 */ 114 function getType() 115 { 116 return 'text/html; charset=' . NLS::getCharset(); 117 } 118 119 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |