Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/filesystem/archive.php

Documentation is available at archive.php

  1. <?php
  2. /**
  3.  * @version        $Id: archive.php 6766 2007-03-03 17:38:21Z louis $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    FileSystem
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. /**
  16.  * An Archive handling class
  17.  *
  18.  * @static
  19.  * @package     Joomla.Framework
  20.  * @subpackage        FileSystem
  21.  * @since        1.5
  22.  */
  23. class JArchive
  24. {
  25.     /**
  26.      * @param string The name of the archive file
  27.      * @param string Directory to unpack into
  28.      *  $return boolean for success
  29.      */
  30.     function extract$archivename$extractdir)
  31.     {
  32.         jimport('joomla.filesystem.file');
  33.         jimport('joomla.filesystem.folder');
  34.  
  35.         $ext JFile::getExt(strtolower($archivename));
  36.         switch ($ext)
  37.         {
  38.             case 'zip':
  39.                 $adapter =JArchive::getAdapter('zip');
  40.                 if ($adapter{
  41.                     $result $adapter->extract($archivename$extractdir);
  42.                 }
  43.                 break;
  44.             case 'tar':
  45.                 $adapter =JArchive::getAdapter('tar');
  46.                 if ($adapter{
  47.                     $result $adapter->extract($archivename$extractdir);
  48.                 }
  49.                 break;
  50.             case 'gz';
  51.             case 'tgz';
  52.             case 'gzip';
  53.                 $adapter =JArchive::getAdapter('gzip');
  54.                 if ($adapter{
  55.                     $config =JFactory::getConfig();
  56.                     $tmpfname $config->getValue('config.tmp_path').DS.uniqid('gzip');
  57.                     $gzresult $adapter->extract($archivename$tmpfname);
  58.                     if (JError::isError($gzresult)) {
  59.                         @unlink($tmpfname);
  60.                         return false;
  61.                     }
  62.                     // Try to untar the file
  63.                     $tadapter =JArchive::getAdapter('tar');
  64.                     if ($tadapter{
  65.                         $result $tadapter->extract($tmpfname$extractdir);
  66.                     }
  67.                     @unlink($tmpfname);
  68.                 }
  69.                 break;
  70.             case 'bz2';
  71.             case 'tbz2';
  72.             case 'bzip2';
  73.                 $adapter =JArchive::getAdapter('bzip2');
  74.                 if ($adapter{
  75.                     $config =JFactory::getConfig();
  76.                     $tmpfname $config->getValue('config.tmp_path').DS.uniqid('bzip2');
  77.                     $bzresult $adapter->extract($archivename$tmpfname);
  78.                     if (JError::isError($bzresult)) {
  79.                         @unlink($tmpfname);
  80.                         return false;
  81.                     }
  82.                     // Try to untar the file
  83.                     $tadapter =JArchive::getAdapter('tar');
  84.                     if ($tadapter{
  85.                         $result $tadapter->extract($tmpfname$extractdir);
  86.                     }
  87.                     @unlink($tmpfname);
  88.                 }
  89.                 break;
  90.             default:
  91.                 JError::raiseWarning(10JText::_('UNKNOWNARCHIVETYPE'));
  92.                 return false;
  93.                 break;
  94.         }
  95.  
  96.         if (JError::isError($result)) {
  97.             return false;
  98.         }
  99.         return true;
  100.     }
  101.  
  102.     function &getAdapter($type)
  103.     {
  104.         static $adapters;
  105.  
  106.         if (!isset($adapters)) {
  107.             $adapters array();
  108.         }
  109.  
  110.         if (!isset($adapters[$type])) {
  111.             // Try to load the adapter object
  112.             jimport('joomla.filesystem.archive.'.strtolower($type));
  113.             $class 'JArchive'.ucfirst($type);
  114.             if (!class_exists($class)) {
  115.                 $false false;
  116.                 return $false;
  117.             }
  118.             $adapters[$typenew $class();
  119.         }
  120.         return $adapters[$type];
  121.     }
  122. }
  123. ?>

Documentation generated on Mon, 05 Mar 2007 20:52:20 +0000 by phpDocumentor 1.3.1