[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 3 require_once 'Horde/MIME/Viewer/zip.php'; 4 5 /** 6 * The MIME_Viewer_zip class renders out the contents of ZIP files in HTML 7 * format and allows downloading of extractable files. 8 * 9 * $Horde: imp/lib/MIME/Viewer/zip.php,v 1.25.10.8 2007/01/02 13:55:00 jan Exp $ 10 * 11 * Copyright 2002-2007 Mike Cochrane <mike@graftonhall.co.nz> 12 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 13 * 14 * See the enclosed file COPYING for license information (GPL). If you 15 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 16 * 17 * @author Mike Cochrane <mike@graftonhall.co.nz> 18 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 19 * @since IMP 4.0 20 * @package Horde_MIME_Viewer 21 */ 22 class IMP_MIME_Viewer_zip extends MIME_Viewer_zip { 23 24 /** 25 * The IMP_Contents object, needed for the _callback() function. 26 * 27 * @var IMP_Contents 28 */ 29 var $_contents; 30 31 /** 32 * Render out the currently set contents. 33 * 34 * @param array $params An array with a reference to a MIME_Contents 35 * object. 36 * 37 * @return string Either the list of zip files or the data of an 38 * individual zip file. 39 */ 40 function render($params) 41 { 42 $contents = &$params[0]; 43 44 $data = $this->mime_part->getContents(); 45 $text = ''; 46 47 /* Send the requested file. Its position in the zip archive is 48 located in 'zip_attachment'. */ 49 if (Util::getFormData('zip_attachment')) { 50 require_once 'Horde/Compress.php'; 51 $zip = &Horde_Compress::singleton('zip'); 52 $fileKey = Util::getFormData('zip_attachment') - 1; 53 $zipInfo = $zip->decompress($data, array('action' => HORDE_COMPRESS_ZIP_LIST)); 54 /* Verify that the requested file exists. */ 55 if (isset($zipInfo[$fileKey])) { 56 $text = $zip->decompress($data, array('action' => HORDE_COMPRESS_ZIP_DATA, 'info' => &$zipInfo, 'key' => $fileKey)); 57 if (empty($text)) { 58 $text = '<pre>' . _("Could not extract the requested file from the Zip archive.") . '</pre>'; 59 } else { 60 $this->mime_part->setType('application/octet-stream'); 61 $this->mime_part->setName(basename($zipInfo[$fileKey]['name'])); 62 } 63 } else { 64 $text = '<pre>' . _("The requested file does not exist in the Zip attachment.") . '</pre>'; 65 } 66 } else { 67 $this->_contents = $contents; 68 $text = parent::_render($data, array($this, '_callback')); 69 } 70 71 return $text; 72 } 73 74 /** 75 * The function to use as a callback to parent::_render(). 76 * 77 * @access private 78 * 79 * @param integer $key The position of the file in the zip archive. 80 * @param array $val The information array for the archived file. 81 * 82 * @return string The content-type of the output. 83 */ 84 function _callback($key, $val) 85 { 86 $name = str_replace(' ', '', $val['name']); 87 if (!empty($val['size']) && (strstr($val['attr'], 'D') === false) && 88 ((($val['_method'] == 0x8) && Util::extensionExists('zlib')) || 89 ($val['_method'] == 0x0))) { 90 $old_name = $this->mime_part->getName(); 91 $this->mime_part->setName(basename($name)); 92 $val['name'] = str_replace($name, $this->_contents->linkView($this->mime_part, 'download_render', $name, array('jstext' => sprintf(_("View %s"), $name), 'class' => 'fixed', 'viewparams' => array('zip_attachment' => (urlencode($key) + 1)))), $val['name']); 93 $this->mime_part->setName($old_name); 94 } 95 96 return $val; 97 } 98 99 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |