Exemplo n.º 1
0
 /**
  * Tests the extract Method.
  *
  * @group   JArchive
  * @return  void
  */
 public function testExtract()
 {
     if (!JArchiveZip::isSupported()) {
         $this->markTestSkipped('ZIP files can not be extracted.');
         return;
     }
     $this->object->extract(__DIR__ . '/logo.zip', self::$outputPath);
     $this->assertTrue(is_file(self::$outputPath . '/logo-zip.png'));
     if (is_file(self::$outputPath . '/logo-zip.png')) {
         unlink(self::$outputPath . '/logo-zip.png');
     }
 }
 /**
  * Test...
  *
  * @covers  JArchiveZip::checkZipData
  *
  * @return void
  */
 public function testCheckZipData()
 {
     $dataZip = file_get_contents(__DIR__ . '/logo.zip');
     $this->assertTrue($this->object->checkZipData($dataZip));
     $dataTar = file_get_contents(__DIR__ . '/logo.tar');
     $this->assertFalse($this->object->checkZipData($dataTar));
 }
Exemplo n.º 3
0
 /**
  * Tests extracting ZIP.
  *
  * @return  void
  */
 public function testExtractZip()
 {
     if (!JArchiveZip::isSupported()) {
         $this->markTestSkipped('ZIP files can not be extracted.');
     }
     JArchive::extract(__DIR__ . '/logo.zip', $this->outputPath);
     $this->assertFileExists($this->outputPath . '/logo-zip.png');
 }
Exemplo n.º 4
0
 /**
  * Upload file.
  * 
  * @param string    $dest   target directory to upload
  * @param string    $field  request fieldname
  * @param stdClass  $file  property where sets ouptput with this format:
  * $file->tmp    ...  request template file name
  * $file->name   ...  uploaded file name
  * $file->apath  ...  absolute path to file
  * $file->rpath  ...  real path to file
  * @param string    $error  property to set error messages
  * @param boolean	$unpackZip  wheater unpack zip files
  * @return boolean
  */
 function upload($dest, $field, &$file, &$error, $unpackZip = false)
 {
     $adir = $dest;
     $rdir = JURI::root() . str_replace(DS, '/', $dest);
     $rdir = str_replace('//', '/', $dest);
     if (!file_exists($adir)) {
         if (!@mkdir($adir, 0775, true)) {
             $mainframe =& JFactory::getApplication();
             /* @var $mainframe JApplication */
             $mainframe->enqueueMessage(sprintf(JText::_('Unable create directory %s'), $adir), 'error');
             return false;
         }
     }
     if (isset($_FILES[$field])) {
         $request =& $_FILES[$field];
         $file = new stdClass();
         $file->tmp = $request['tmp_name'];
         $file->name = $request['name'];
         if ($request['error'] == 0) {
             $zip = new JArchiveZip();
             $data = JFile::read($file->tmp);
             $isZip = $zip->checkZipData($data);
             unset($data);
             if ($isZip && $unpackZip) {
                 $tmpDir = AFile::getTmpDir();
                 $zip->extract($file->tmp, $tmpDir);
                 unset($zip);
                 $files =& JFolder::files($tmpDir, '.', true, true);
                 $count = count($files);
                 for ($i = 0; $i < $count; $i++) {
                     $file->tmp = $files[$i];
                     $file->name = JFile::getName($file->tmp);
                     AFile::save($file, $adir, $rdir);
                 }
                 JFolder::delete($tmpDir);
                 return true;
             } else {
                 unset($zip);
                 return AFile::save($file, $adir, $rdir);
             }
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Tests extracting ZIP.
  *
  * @group    JArchive
  * @covers    JArchive::extract
  * @return  void
  */
 public function testExtractZip()
 {
     if (!is_dir(self::$outputPath)) {
         $this->markTestSkipped("Couldn't create folder.");
         return;
     }
     if (!JArchiveZip::isSupported()) {
         $this->markTestSkipped('ZIP files can not be extracted.');
         return;
     }
     JArchive::extract(__DIR__ . '/logo.zip', self::$outputPath);
     $this->assertTrue(is_file(self::$outputPath . '/logo-zip.png'));
     if (is_file(self::$outputPath . '/logo-zip.png')) {
         unlink(self::$outputPath . '/logo-zip.png');
     }
 }
 public function accessExtractNative($archive, $destination, array $options = array())
 {
     return parent::extractNative($archive, $destination, $options);
 }
Exemplo n.º 7
0
 /**
  * Check Zip Data Function With A Zip File
  *
  * @return void
  */
 public function testCheckZipDataWithAZipFile()
 {
     $dataZip = file_get_contents(__DIR__ . '/logo.zip');
     $this->assertTrue($this->object->checkZipData($dataZip));
 }
Exemplo n.º 8
0
 /**
  * Zip Backup folder
  */
 function _backupFolder()
 {
     global $option, $mainframe;
     if (!$this->_backup) {
         return;
     }
     $zipname = uniqid('backup_') . '.zip';
     if (!JFolder::exists(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup')) {
         JFolder::create(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup');
     }
     $zipdest = JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . $zipname;
     $files = JFolder::files($this->_backup, '.', true, true);
     $fileinfos = array();
     for ($i = 0; $i < count($files); $i++) {
         $fileinfos[$i]['data'] = JFile::read($files[$i]);
         $fileinfos[$i]['name'] = str_replace($this->_backup . DS, '', $files[$i]);
     }
     $i = count($fileinfos);
     $fileinfos[$i]['data'] = JFile::read($this->_xmlname);
     $fileinfos[$i]['name'] = str_replace(dirname($this->_xmlname) . DS, '', $this->_xmlname);
     $azip = new JArchiveZip();
     $azip->create($zipdest, $fileinfos);
     JFile::write(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . 'backup.php', '<?php defined(\'_JEXEC\') or die( \'Restricted access\' ); $urlbackup= \'' . $zipdest . '\'; ?>');
 }
Exemplo n.º 9
0
 /**
  * get file zip
  *
  */
 function export()
 {
     $path_base = JPATH_COMPONENT_SITE . DS . 'resource';
     if (JFolder::exists($path_base)) {
         JFolder::delete($path_base);
     }
     JFolder::create($path_base);
     $content = $this->getXML();
     $date = JFactory::getDate();
     $date = $date->toFormat('%Y_%m_%d_%H_%M_%S');
     $filename = 'YRM_resources_' . $date;
     $path_file = $path_base . DS . $filename;
     $xml_file = $path_file . '.xml';
     JFile::write($xml_file, $content);
     $fileinfos = array();
     $fileinfos[0]['data'] = JFile::read($xml_file);
     $fileinfos[0]['name'] = 'resource.xml';
     require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'filesystem' . DS . 'archive' . DS . 'zip.php';
     $azip = new JArchiveZip();
     $azip->create($path_file . '.zip', $fileinfos);
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: public");
     header("Content-Description: File Transfer");
     header("Content-Type: application/zip");
     header("Content-Disposition: attachment; filename=" . basename($path_file . ".zip") . ";");
     header("Content-Transfer-Encoding: binary");
     header("Content-Length: " . filesize($path_file . ".zip"));
     @readfile($path_file . ".zip");
     exit;
 }