git-svn-id: https://192.168.0.254/svn/Proyectos.MatritumCantat_Web/trunk@2 8e3496fd-7892-4c45-be36-0ff06e9dacc6
189 lines
6.3 KiB
PHP
189 lines
6.3 KiB
PHP
<?php
|
|
/**
|
|
* @version $Id: admin.installer.php 328 2005-10-02 15:39:51Z Jinx $
|
|
* @package Joomla
|
|
* @subpackage Installer
|
|
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
|
|
* Joomla! is free software. This version may have been modified pursuant
|
|
* to the GNU General Public License, and as distributed it includes or
|
|
* is derivative of works licensed under the GNU General Public License or
|
|
* other free or open source software licenses.
|
|
* See COPYRIGHT.php for copyright notices and details.
|
|
*/
|
|
|
|
// no direct access
|
|
defined( '_VALID_MOS' ) or die( 'Restricted access' );
|
|
|
|
// XML library
|
|
require_once( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' );
|
|
require_once( $mosConfig_absolute_path . "/administrator/components/com_jce/installer/installer.html.php" );
|
|
require_once( $mosConfig_absolute_path . "/administrator/components/com_jce/installer/installer.class.php" );
|
|
|
|
function jceInstaller( $option, $client, $opt )
|
|
{
|
|
global $mosConfig_absolute_path;
|
|
$element = mosGetParam( $_REQUEST, 'element', '' );
|
|
|
|
$path = $mosConfig_absolute_path . "/administrator/components/com_jce/installer/$element/$element.php";
|
|
|
|
// map the element to the required derived class
|
|
$classMap = array(
|
|
'plugins' => 'JCEPluginInstaller',
|
|
'language' => 'JCELanguageInstaller'
|
|
);
|
|
|
|
if (array_key_exists ( $element, $classMap )) {
|
|
require_once( $mosConfig_absolute_path . "/administrator/components/com_jce/installer/$element/$element.class.php" );
|
|
|
|
switch ( $opt ) {
|
|
|
|
case 'uploadfile':
|
|
uploadPackage( $classMap[$element], $option, $element, $client );
|
|
break;
|
|
|
|
case 'installfromdir':
|
|
installFromDirectory( $classMap[$element], $option, $element, $client );
|
|
break;
|
|
|
|
case 'remove':
|
|
removeElement( $classMap[$element], $option, $element, $client );
|
|
break;
|
|
|
|
case 'show':
|
|
$path = $mosConfig_absolute_path . "/administrator/components/com_jce/installer/$element/$element.php";
|
|
|
|
if (file_exists( $path )) {
|
|
require $path;
|
|
} else {
|
|
echo "Installer not found for element [$element]";
|
|
}
|
|
break;
|
|
}
|
|
} else {
|
|
echo "Installer not available for element [$element]";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string The class name for the installer
|
|
* @param string The URL option
|
|
* @param string The element name
|
|
*/
|
|
function uploadPackage( $installerClass, $option, $element, $client ) {
|
|
$installer = new $installerClass();
|
|
|
|
// Check if file uploads are enabled
|
|
if (!(bool)ini_get('file_uploads')) {
|
|
HTML_installer::showInstallMessage( "The installer can't continue before file uploads are enabled. Please use the install from directory method.",
|
|
'Installer - Error', $installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
exit();
|
|
}
|
|
|
|
// Check that the zlib is available
|
|
if(!extension_loaded('zlib')) {
|
|
HTML_installer::showInstallMessage( "The installer can't continue before zlib is installed",
|
|
'Installer - Error', $installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
exit();
|
|
}
|
|
|
|
$userfile = mosGetParam( $_FILES, 'userfile', null );
|
|
|
|
if (!$userfile) {
|
|
HTML_installer::showInstallMessage( 'No file selected', 'Upload new module - error',
|
|
$installer->returnTo( $option, '&task=install&element='.$element, $client ));
|
|
exit();
|
|
}
|
|
|
|
$userfile_name = $userfile['name'];
|
|
|
|
$msg = '';
|
|
$resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg );
|
|
|
|
if ($resultdir !== false) {
|
|
if (!$installer->upload( $userfile['name'] )) {
|
|
HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - Upload Failed',
|
|
$installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
}
|
|
$ret = $installer->install();
|
|
|
|
HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - '.($ret ? 'Success' : 'Failed'),
|
|
$installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
cleanupInstall( $userfile['name'], $installer->unpackDir() );
|
|
} else {
|
|
HTML_installer::showInstallMessage( $msg, 'Upload '.$element.' - Upload Error',
|
|
$installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Install a template from a directory
|
|
* @param string The URL option
|
|
*/
|
|
function installFromDirectory( $installerClass, $option, $element, $client ) {
|
|
$userfile = mosGetParam( $_REQUEST, 'userfile', '' );
|
|
|
|
if (!$userfile) {
|
|
mosRedirect( "index2.php?option=$option&element=module", "Please select a directory" );
|
|
}
|
|
|
|
$installer = new $installerClass();
|
|
|
|
$path = mosPathName( $userfile );
|
|
if (!is_dir( $path )) {
|
|
$path = dirname( $path );
|
|
}
|
|
|
|
$ret = $installer->install( $path );
|
|
HTML_installer::showInstallMessage( $installer->getError(), 'Upload new '.$element.' - '.($ret ? 'Success' : 'Error'), $installer->returnTo( $option, '&task=install&element='.$element, $client ) );
|
|
}
|
|
/**
|
|
*
|
|
* @param
|
|
*/
|
|
function removeElement( $installerClass, $option, $element, $client ) {
|
|
$cid = mosGetParam( $_REQUEST, 'cid', array(0) );
|
|
if (!is_array( $cid )) {
|
|
$cid = array(0);
|
|
}
|
|
|
|
$installer = new $installerClass();
|
|
$result = false;
|
|
if ($cid[0]) {
|
|
$result = $installer->uninstall( $cid[0], $option, $client );
|
|
}
|
|
|
|
$msg = $installer->getError();
|
|
|
|
mosRedirect( $installer->returnTo( $option, '&task=install&element='.$element, $client ), $result ? 'Success ' . $msg : 'Failed ' . $msg );
|
|
}
|
|
/**
|
|
* @param string The name of the php (temporary) uploaded file
|
|
* @param string The name of the file to put in the temp directory
|
|
* @param string The message to return
|
|
*/
|
|
function uploadFile( $filename, $userfile_name, &$msg ) {
|
|
global $mosConfig_absolute_path;
|
|
$baseDir = mosPathName( $mosConfig_absolute_path . '/media' );
|
|
|
|
if (file_exists( $baseDir )) {
|
|
if (is_writable( $baseDir )) {
|
|
if (move_uploaded_file( $filename, $baseDir . $userfile_name )) {
|
|
if (mosChmod( $baseDir . $userfile_name )) {
|
|
return true;
|
|
} else {
|
|
$msg = 'Failed to change the permissions of the uploaded file.';
|
|
}
|
|
} else {
|
|
$msg = 'Failed to move uploaded file to <code>/media</code> directory.';
|
|
}
|
|
} else {
|
|
$msg = 'Upload failed as <code>/media</code> directory is not writable.';
|
|
}
|
|
} else {
|
|
$msg = 'Upload failed as <code>/media</code> directory does not exist.';
|
|
}
|
|
return false;
|
|
}
|
|
?>
|