getPath( 'admin_html' ) );
require_once( $mainframe->getPath( 'class' ) );
$element = mosGetParam( $_REQUEST, 'element', '' );
$client = mosGetParam( $_REQUEST, 'client', '' );
$path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php";
// ensure user has access to this function
if ( !$acl->acl_check( 'administration', 'install', 'users', $my->usertype, $element . 's', 'all' ) ) {
mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
}
// map the element to the required derived class
$classMap = array(
'component' => 'mosInstallerComponent',
'language' => 'mosInstallerLanguage',
'mambot' => 'mosInstallerMambot',
'module' => 'mosInstallerModule',
'template' => 'mosInstallerTemplate'
);
if (array_key_exists ( $element, $classMap )) {
require_once( $mainframe->getPath( 'installer_class', $element ) );
switch ($task) {
case 'uploadfile':
uploadPackage( $classMap[$element], $option, $element, $client );
break;
case 'installfromdir':
installFromDirectory( $classMap[$element], $option, $element, $client );
break;
case 'remove':
$uninstaller = $element.'_uninstall';
if (is_callable($uninstaller)) {
$cid = mosGetParam($_REQUEST, 'cid', array(0));
if (is_array($cid) AND isset($cid[0])) {
$result = $uninstaller ($cid[0], $option, $client);
$msg = '';
}
mosRedirect(returnTo($option, $element, $client), $result ? 'Success ' . $msg : 'Failed ' . $msg );
}
else echo "Uninstaller not found for element [$element]";
break;
default:
$path = $mosConfig_absolute_path . "/administrator/components/com_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]";
}
function returnTo ($option, $element, $client) {
switch ($element) {
case 'template':
return "index2.php?option=com_templates&client=$client";
case 'language':
return "index2.php?option=com_languages";
default:
return "index2.php?option=$option&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 ) {
global $mainframe;
$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', returnTo( $option, $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', returnTo( $option, $element, $client ) );
exit();
}
$userfile = mosGetParam( $_FILES, 'userfile', null );
if (!$userfile) {
HTML_installer::showInstallMessage( 'No file selected', 'Upload new module - error',
returnTo( $option, $element, $client ));
exit();
}
$userfile_name = $userfile['name'];
$msg = '';
$resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg );
if ($resultdir !== false) {
if (!$installer->extractArchive( $userfile['name'] )) {
HTML_installer::showInstallMessage( $installer->getErrors(), 'Upload '.$element.' - Upload Failed',
returnTo( $option, $element, $client ) );
}
$ret = $installer->install();
HTML_installer::showInstallMessage( $installer->getErrors(), 'Upload '.$element.' - '.($ret ? 'Success' : 'Failed'),
returnTo( $option, $element, $client ) );
$installer->cleanUpInstall();
} else {
HTML_installer::showInstallMessage( $msg, 'Upload '.$element.' - Upload Error',
$installer->returnTo( $option, $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", T_("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->getErrors(), T_('Install new ').$element.' - '.($ret ? T_('Success') : T_('Error')),
returnTo( $option, $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]) {
$ret = $installer->uninstall( $cid[0], $option, $client );
}
else $ret = 1;
HTML_installer::showInstallMessage( $installer->getErrors(), T_('Uninstall ').$element.' - '.($ret ? T_('Success') : T_('Error')),
returnTo( $option, $element, $client ) );
}
/**
* @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 = T_('Failed to change the permissions of the uploaded file.');
}
} else {
$msg = T_('Failed to move uploaded file to /media directory.');
}
} else {
$msg = T_('Upload failed as /media directory is not writable.');
}
} else {
$msg = T_('Upload failed as /media directory does not exist.');
}
return false;
}
/**
* Component uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
*/
function component_uninstall( $cid, $option, $client=0 ) {
$database = mamboDatabase::getInstance();
$sql = "SELECT * FROM #__components WHERE id=$cid";
$database->setQuery($sql);
if (!$database->loadObject( $row )) {
HTML_installer::showInstallMessage($database->stderr(true),T_('Uninstall - error'),
"index2.php?option=$option&element=component");
exit();
}
if ($row->iscore) {
die(T_('Is core component - may not be deleted'));
HTML_installer::showInstallMessage(sprintf(T_('Component %s is a core component, and can not be uninstalled.
You need to unpublish it if you don\'t want to use it'), $row->name), 'Uninstall - error',
"index2.php?option=$option&element=component");
exit();
}
// Try to find the XML file
$here = mosPathName( mamboCore::get('mosConfig_absolute_path').'/administrator/components/'.$row->option );
$filesindir = mosReadDirectory($here, '.xml$');
if (count($filesindir) > 0) {
foreach ($filesindir as $file) {
$parser = new mosUninstallXML ($here.$file);
$parser->uninstall();
if ($parser->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return false;
}
}
else {
// no XML file
return false;
/*
HTML_installer::showInstallMessage( 'Could not find XML Setup file in '.$mosConfig_absolute_path.'/administrator/components/'.$row->option,
'Uninstall - error', $option, 'component' );
exit();
*/
}
return true;
}
/**
* Module uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
*/
function module_uninstall( $id, $option, $client=0 ) {
$database = mamboDatabase::getInstance();
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path');
$query = "SELECT module, iscore, client_id FROM #__modules WHERE id = '$id'";
$database->setQuery( $query );
$database->loadObject( $row );
if ($row->iscore) {
HTML_installer::showInstallMessage(sprintf(T_('%s is a core module, and can not be uninstalled.
You need to unpublish it if you don\'t want to use it'), $row->title), 'Uninstall - error', returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) );
exit();
}
$query = "DELETE FROM #__modules_menu WHERE moduleid=$id";
$database->setQuery( $query );
if (!$database->query()) {
$msg = $database->stderr;
die( $msg );
}
if ( $row->client_id ) $basepath = $mosConfig_absolute_path . '/administrator/modules/';
else $basepath = $mosConfig_absolute_path . '/modules/';
$xmlfile = $basepath . $row->module . '.xml';
$parser = new mosUninstallXML ($xmlfile);
$parser->uninstall();
if ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL) return true;
return false;
}
/**
* Mambot install method
* @param int The id of the module
* @param string The URL option
* @param int The client id
*/
function mambot_uninstall( $id, $option, $client=0 ) {
$database = mamboDatabase::getInstance();
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path');
$database->setQuery( "SELECT name, folder, element, iscore FROM #__mambots WHERE id = '$id'" );
$database->loadObject( $row );
if ($database->getErrorNum()) {
HTML_installer::showInstallMessage( $database->stderr(), T_('Uninstall - error'),
returnTo( $option, 'mambot', $client ) );
exit();
}
if ($row == null) {
HTML_installer::showInstallMessage( T_('Invalid object id'), T_('Uninstall - error'),
returnTo( $option, 'mambot', $client ) );
exit();
}
if (trim( $row->folder ) == '') {
HTML_installer::showInstallMessage( T_('Folder field empty, cannot remove files'), T_('Uninstall - error'),
returnTo( $option, 'mambot', $client ) );
exit();
}
$xmlfile = $mosConfig_absolute_path.'/mambots/'.$row->folder.'/'.$row->element.'.xml';
$parser = new mosUninstallXML ($xmlfile);
$parser->uninstall();
if ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL) return true;
return false;
}
/**
* Template uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
*/
function template_uninstall( $id, $option, $client=0 ) {
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path');
// Delete directories
$path = mosPathName($mosConfig_absolute_path
. ($client == 'admin' ? '/administrator' : '' )
. '/templates/' . $id);
$filesindir = mosReadDirectory($path, '.xml$');
if (count($filesindir) > 0) {
foreach ($filesindir as $file) {
$parser = new mosUninstallXML ($path.$file);
$parser->uninstall();
if ($parser->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return false;
}
}
else {
// no XML - just delete the template directory
$tdir = new mosDirectory($path);
$tdir->deleteAll();
}
return true;
}
/**
* Language uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
*/
function language_uninstall( $id, $option, $client=0 ) {
$id = str_replace( array( '\\', '/' ), '', $id );
$basepath = mamboCore::get('mosConfig_absolute_path').'/language/';
$xmlfile = $basepath . $id . '.xml';
// see if there is an xml install file, must be same name as element
if (file_exists( $xmlfile )) {
$parser = new mosUninstallXML ($xmlfile);
$parser->uninstall();
if ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL) return true;
return false;
}
else {
HTML_installer::showInstallMessage( T_('Language id empty, cannot remove files'), T_('Uninstall - error'), "index2.php?option=com_languages");
exit();
}
}
?>