_iswin = (substr(PHP_OS, 0, 3) == 'WIN'); $this->_elementdir =JPath::clean( JPATH_COMPONENT_ADMINISTRATOR. DS.'contentelements' ); } /** * Installation of a single file or archive for the joomfish files * @param array uploadfile retrieved information transferred by the upload form */ function install( $uploadfile = null ) { if( $uploadfile === null ) { return false; } $this->_uploadfile = $uploadfile['tmp_name']; $this->_realname = $uploadfile['name']; return $this->upload(); } /** * Uploads and unpacks a file * @return boolean True on success, False on error */ function upload() { if( !eregi( '.xml$', $this->_realname ) ) { if(! $this->extractArchive() ) { return false; } } if( !is_array( $this->_uploadfile ) ) { if(!@JFile::copy($this->_uploadfile, $this->_elementdir .DS. $this->_realname) ) { $this->errno = 2; $this->error = JText::_('FILEUPLOAD_ERROR'); return false; } } else { foreach ($this->_uploadfile as $file ) { if(! @JFile::copy($this->_unpackdir .DS . $file, $this->_elementdir .DS. $file) ) { $this->errno = 2; $this->error = JText::_('FILEUPLOAD_ERROR'); return false; } } } return true; } /** * Extracts the package archive file * @return boolean True on success, False on error */ function extractArchive() { $base_Dir =JPath::clean( JPATH_BASE. '/media' ); $archivename = $base_Dir . $this->_realname; $tmpdir = uniqid( 'install_' ); $extractdir =JPath::clean( $base_Dir . $tmpdir ); $archivename =JPath::clean( $archivename, false ); $this->_unpackdir = $extractdir; if (eregi( '.zip$', $archivename )) { // Extract functions require_once( JPATH_ADMINISTRATOR . '/includes/pcl/pclzip.lib.php' ); require_once( JPATH_ADMINISTRATOR. '/includes/pcl/pclerror.lib.php' ); $zipfile = new PclZip( $this->_uploadfile ); if($this->_iswin) { define('OS_WINDOWS',1); } else { define('OS_WINDOWS',0); } $ret = $zipfile->extract( PCLZIP_OPT_PATH, $extractdir ); if($ret == 0) { $this->errno = 1; $this->error = 'Unrecoverable error "'.$zipfile->errorName(true).'"'; return false; } } else { require_once( JPATH_SITE . '/includes/Archive/Tar.php' ); $archive = new Archive_Tar( $this->_uploadfile ); $archive->setErrorHandling( PEAR_ERROR_PRINT ); if (!$archive->extractModify( $extractdir, '' )) { $this->setError( 1, 'Extract Error' ); return false; } } // Try to find the correct install dir. in case that the package have subdirs // Save the install dir for later cleanup jimport('joomla.filesystem.folder'); $this->_uploadfile =JFolder::files($extractdir, '' ); if (count( $this->_uploadfile ) == 1) { if (is_dir( $extractdir . $this->_uploadfile[0] )) { $this->_unpackdir =JPath::clean( $extractdir . $this->_uploadfile[0] ); $this->_uploadfile = JFolder::files( $extractdir, '' ); } } return true; } } ?>