Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/public_html/administrator/components/com_falang/helpers/ |
<?php
/**
* @package Falang for Joomla!
* @author Stéphane Bouey <stephane.bouey@faboba.com> - http://www.faboba.com
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @copyright Copyright (C) 2010-2017. Faboba.com All rights reserved.
*/
// No direct access to this file
defined('_JEXEC') or die;
jimport('joomla.filesystem.file');
/**
* This class allows general installation of files related to the Joom!Fish project
* It is a light version of the mosInstaller class without the particular handling of
* special package XML files within the archieves. All XML files are automatically
* interpreterted as content element files and installed in the related directories
*
*/
class jfInstaller {
var $_iswin = false;
var $errno = 0;
var $error = "";
var $_unpackdir = "";
/** @var string The directory where the element is to be installed */
var $_elementdir = '';
var $_uploadfile = null;
var $_realname = null;
var $_contentelements = array();
/**
* Constructor
*/
function jfInstaller() {
$this->_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 falang 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( !preg_match( '/.xml$/i', $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::_('COM_FALANG_CONTENT_ELEMENT_INSTALLER_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::_('COM_FALANG_CONTENT_ELEMENT_INSTALLER_FILEUPLOAD_ERROR');
return false;
}
}
}
return true;
}
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
function extractArchive() {
//TODO sbou Check installation temp path
$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 (preg_match( '/.zip$/', $archivename )) {
// Extract functions
$zip = new ZipArchive;
$res = $zip->open($this->_uploadfile);
if ($res === TRUE) {
$zip->extractTo($extractdir);
$zip->close();
} else {
$this->errno = 2;
$this->error = JText::_('COM_FALANG_CONTENT_ELEMENT_INSTALLER_UNZIP_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;
}
}