Source for file admin.installer.php
Documentation is available at admin.installer.php
* @copyright Refer to copyright.php
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Mambo Foundation Inc see README.php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( T_('Direct Access to this location is not allowed.') );
require_once( $mainframe->getPath( 'admin_html' ) );
require_once( $mainframe->getPath( 'class' ) );
// 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
'universal' =>
'mosInstaller',
'component' =>
'mosInstaller',
'language' =>
'mosInstaller',
'mambot' =>
'mosInstaller',
'module' =>
'mosInstaller',
'template' =>
'mosInstaller',
'include' =>
'mosInstaller',
'parameters' =>
'mosInstaller'
// require_once( $mainframe->getPath( 'installer_class', $element ) );
uploadPackage( $classMap[$element], $option, $element, $client );
$uninstaller =
$element.
'_uninstall';
if (is_array($cid) AND isset
($cid[0])) {
$uninstaller ($cid[0], $option, $client);
$path =
$mosConfig_absolute_path .
"/administrator/components/com_installer/$element/$element.php";
echo
sprintf(T_('Installer not found for element [%s]'), $element);
echo
sprintf(T_('Installer not available for element [%s]'), $element);
function returnTo ($option, $element, $client) {
return "index2.php?option=com_templates&client=$client";
return "index2.php?option=com_languages";
return "index2.php?option=$option&element=$element";
* @param string Path to the addons xml file
global $mosConfig_absolute_path;
$xmlfilepath =
$mosConfig_absolute_path .
$xmlfile;
//Check the file exists and is thus installed
return "Can't parse XML";
//Look for current version
/* Note: Ampersands in the XML data create an issue for SimpleXML. The solution
is to either wrap the text in CDATA or enter in the XML file as &. More info
on the issue here - http://changelog.ca/log/2005/06/14/php-simplexml-cdata-problem--and-my-solution.
Need to revisit later... for now the current XML files have been corrected.*/
* @param string The class name for the installer
* @param string The URL option
* @param string The element name
function uploadPackage( $installerClass, $option, $element, $client ) {
// Check if file uploads are enabled
if (!(bool)
ini_get('file_uploads')) {
$message =
new mosError (T_('The installer can\'t continue before file uploads are enabled. Please use the install from directory method.'), _MOS_ERROR_FATAL);
// Check that the zlib is available
$userfile_name =
$userfile['name'];
if (uploadFile( $userfile['tmp_name'], $userfile['name'], $message )) {
// if (uploadFile( stripslashes($userfile['tmp_name']), $userfile['name'], $message )) {
$installer =
& new $installerClass();
if (!$installer->extractArchive( $userfile['name'] )) {
$installer->cleanUpInstall();
returnTo( $option, $element, $client ) );
$ret =
$installer->install();
$installer->cleanUpInstall();
returnTo( $option, $element, $client ) );
returnTo( $option, $element, $client ) );
* Install a template from a directory
* @param string The URL option
mosRedirect( "index2.php?option=$option&element=module", T_('Please select a directory') );
$installer =
& new $installerClass();
$ret =
$installer->install( $path );
$installer->cleanUpInstall();
returnTo( $option, $element, $client ) );
* Install a template from an HTTP URL
* @param string The URL option
function installFromUrl( $installerClass, $option, $element, $client ) {
// Check that the zlib is available
if (!$userurl ||
$userurl[0]==
'http://') {
foreach ($userurl as $value) {
if (isset
($url_data['path'])) $userfilename =
basename($url_data['path']);
if (uploadUrl($value, $userfilename, $message )) {
$installer =
new $installerClass();
if (!$installer->extractArchive($userfilename)) {
$installer->cleanUpInstall();
returnTo( $option, $element, $client ) );
$ret =
$installer->install();
$installer->cleanUpInstall();
returnTo( $option, $element, $client ) );
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, &$error ) {
global $mosConfig_absolute_path;
$baseDir =
mosPathName( $mosConfig_absolute_path .
'/media' );
if (mosChmod( $baseDir .
$userfile_name )) {
$msg =
T_('Failed to change the permissions of the uploaded file.');
$msg =
T_('Failed to move uploaded file to <code>/media</code> directory.');
$msg =
T_('Upload failed as <code>/media</code> directory is not writable.');
$msg =
T_('Upload failed as <code>/media</code> directory does not exist.');
* @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 uploadUrl( $userurl, $userfilename, &$error ) {
global $mosConfig_absolute_path;
$baseDir =
mosPathName( $mosConfig_absolute_path .
'/media' );
$data =
fgets($fpin, 1024);
if (mosChmod( $baseDir.
$userfilename )) return true;
else $msg =
T_('Failed to change the permissions of the uploaded file.');
else $msg =
T_('Failed to open the local file from the URL.');
else $msg =
T_('Failed to open the specified URL.');
else $msg =
T_('Upload failed as <code>/media</code> directory is not writable.');
else $msg =
T_('Upload failed as <code>/media</code> directory does not exist.');
* Component uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
$sql =
"SELECT * FROM #__components WHERE id=$cid";
$database->setQuery($sql);
if (!$database->loadObject( $row )) {
$message =
new mosError (sprintf(T_('Component %s is a core component, and can not be uninstalled.<br />You need to unpublish it if you don\'t want to use it'), $row->name), _MOS_ERROR_FATAL);
// Try to find the XML file
if (count($filesindir) >
0) {
foreach ($filesindir as $file) {
$allerrors->mergeAnother($parser->errors);
returnTo( $option, 'component', $client ) );
$com_name =
$row->option;
$sql =
"DELETE FROM #__components WHERE `option`='$com_name'";
$database->setQuery($sql);
* Module uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
$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 );
$message =
new mosError (sprintf(T_('%s is a core module, and can not be uninstalled.<br />You need to unpublish it if you don\'t want to use it'), $row->title), _MOS_ERROR_FATAL);
$query =
"DELETE FROM #__modules_menu WHERE moduleid=$id";
$database->setQuery( $query );
if (!$database->query()) {
$msg =
$database->stderr;
if ( $row->client_id ) $basepath =
$mosConfig_absolute_path .
'/administrator/modules/';
else $basepath =
$mosConfig_absolute_path .
'/modules/';
$xmlfile =
$basepath .
$row->module .
'.xml';
returnTo( $option, 'module', $client ) );
* @param int The id of the module
* @param string The URL option
* @param int The client id
$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()) {
returnTo( $option, 'mambot', $client ) );
if (trim( $row->folder ) ==
'') {
$xmlfile =
$mosConfig_absolute_path.
'/mambots/'.
$row->folder.
'/'.
$row->element.
'.xml';
$ret =
$parser->uninstall();
$showerrors =
$parser->getErrors();
$database->setQuery("DELETE FROM #__mambots WHERE id = $id");
$ret =
$database->query();
returnTo( $option, 'mambot', $client ) );
* Template uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client id
$mosConfig_absolute_path =
mamboCore::get('mosConfig_absolute_path');
// Find if normal or admin template and delete corresponding files & directories
$basepath =
mamboCore::get('mosConfig_absolute_path').
'/administrator/templates/' .
$id;
$basepath =
mamboCore::get('mosConfig_absolute_path').
'/templates/' .
$id;
//Use $basepath to remove the template files and directory
* Language uninstall method
* @param int The id of the module
* @param string The URL option
* @param int The client 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
returnTo( $option, 'language', $client ) );
Documentation generated on Mon, 05 May 2008 16:15:19 +0400 by phpDocumentor 1.4.0