--- mambo/branches/4.6/administrator/components/com_installer/admin.installer.php 2006/01/19 14:24:56 151
+++ mambo/branches/4.6/administrator/components/com_installer/admin.installer.php 2006/04/03 08:46:54 442
@@ -1,39 +1,42 @@
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', _NOT_AUTH );
+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'
+ 'universal' => 'mosInstaller',
+ 'component' => 'mosInstaller',
+ 'language' => 'mosInstaller',
+ 'mambot' => 'mosInstaller',
+ 'module' => 'mosInstaller',
+ 'template' => 'mosInstaller',
+ 'include' => 'mosInstaller',
+ 'parameters' => 'mosInstaller'
);
if (array_key_exists ( $element, $classMap )) {
- require_once( $mainframe->getPath( 'installer_class', $element ) );
+// require_once( $mainframe->getPath( 'installer_class', $element ) );
switch ($task) {
@@ -44,18 +47,26 @@
case 'installfromdir':
installFromDirectory( $classMap[$element], $option, $element, $client );
break;
+
+ case 'installfromurl':
+ installFromUrl ($classMap[$element], $option, $element, $client);
+ break;
+
+ case 'thesource':
+ HTML_installer::theSourceForm($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 = '';
+ $uninstaller ($cid[0], $option, $client);
+ exit ();
}
- mosRedirect(returnTo($option, $element, $client), $result ? 'Success ' . $msg : 'Failed ' . $msg );
+ mosRedirect(returnTo($option, $element, $client), T_('There was nothing selected to be uninstalled') );
}
- else echo "Uninstaller not found for element [$element]";
+ else mosRedirect(returnTo($option, $element, $client), T_('Uninstaller not found for element [%s]') );
break;
default:
@@ -64,13 +75,13 @@
if (file_exists( $path )) {
require $path;
} else {
- echo "Installer not found for element [$element]";
+ echo sprintf(T_('Installer not found for element [%s]'), $element);
}
break;
}
}
else {
- echo "Installer not available for element [$element]";
+ echo sprintf(T_('Installer not available for element [%s]'), $element);
}
@@ -93,49 +104,44 @@
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 ) );
+ $message = new mosError (T_('The installer can\'t continue before file uploads are enabled. Please use the install from directory method.'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('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 ) );
+ $message = new mosError (T_('The installer can\'t continue before zlib is installed'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('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 ));
+ $message = new mosError (T_('No file selected'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('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 (uploadFile( $userfile['tmp_name'], $userfile['name'], $message )) {
+ $installer =& new $installerClass();
if (!$installer->extractArchive( $userfile['name'] )) {
- HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - Upload Failed',
+ $installer->cleanUpInstall();
+ HTML_installer::showInstallMessage( $installer->getErrors(), sprintf(T_('Upload %s - Upload Failed'), $element),
returnTo( $option, $element, $client ) );
}
$ret = $installer->install();
-
- HTML_installer::showInstallMessage( $installer->getError(), '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 ) );
+ HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.($ret ? T_('Success') : T_('Failed')),
+ returnTo( $option, $element, $client ) );
}
+ else HTML_installer::showInstallMessage( $message, sprintf(T_('Upload %s - Upload Error'), $element),
+ returnTo( $option, $element, $client ) );
}
/**
@@ -144,48 +150,64 @@
*/
function installFromDirectory( $installerClass, $option, $element, $client ) {
$userfile = mosGetParam( $_REQUEST, 'userfile', '' );
-
if (!$userfile) {
- mosRedirect( "index2.php?option=$option&element=module", "Please select a directory" );
+ 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 );
}
-
+ $installer =& new $installerClass();
$ret = $installer->install( $path );
- HTML_installer::showInstallMessage( $installer->getError(), 'Upload new '.$element.' - '.($ret ? 'Success' : 'Error'),
+ $installer->cleanUpInstall();
+ HTML_installer::showInstallMessage( $installer->getErrors(), T_('Install new ').$element.' - '.($ret ? T_('Success') : T_('Error')),
returnTo( $option, $element, $client ) );
}
/**
-*
-* @param
+* Install a template from an HTTP URL
+* @param string The URL option
*/
-function removeElement( $installerClass, $option, $element, $client ) {
- $cid = mosGetParam( $_REQUEST, 'cid', array(0) );
- if (!is_array( $cid )) {
- $cid = array(0);
+function installFromUrl( $installerClass, $option, $element, $client ) {
+ // Check that the zlib is available
+ if(!extension_loaded('zlib')) {
+ $message = new mosError (T_('The installer can\'t continue before zlib is installed'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, 'Installer - Error', returnTo( $option, $element, $client ));
+ exit();
}
-
- $installer = new $installerClass();
- $result = false;
- if ($cid[0]) {
- $result = $installer->uninstall( $cid[0], $option, $client );
+ $userurl = mosGetParam( $_REQUEST, 'userurl', '' );
+ if (!$userurl) {
+ $message = new mosError (T_('Please select an HTTP URL'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo($option, $element, $client));
+ }
+ $url_data = parse_url($userurl);
+ if (isset($url_data['path'])) $userfilename = basename($url_data['path']);
+ else $userfilename = '';
+ if (!$userfilename) {
+ $message = new mosError (T_('The URL did not define a file name'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo($option, $element, $client));
+ }
+ if (uploadUrl($userurl, $userfilename, $message )) {
+ $installer = new $installerClass();
+ if (!$installer->extractArchive($userfilename)) {
+ $installer->cleanUpInstall();
+ HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.T_('Failed'),
+ returnTo( $option, $element, $client ) );
+ }
+ $ret = $installer->install();
+ $installer->cleanUpInstall();
+ HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.($ret ? T_('Success') : T_('Failed')),
+ returnTo( $option, $element, $client ) );
+ } else {
+ HTML_installer::showInstallMessage( $message, T_('Upload ').$element.' - '.T_('Error'),
+ returnTo( $option, $element, $client ) );
}
-
- $msg = $installer->getError();
-
- mosRedirect( returnTo( $option, $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 ) {
+function uploadFile( $filename, $userfile_name, &$error ) {
global $mosConfig_absolute_path;
$baseDir = mosPathName( $mosConfig_absolute_path . '/media' );
@@ -195,17 +217,49 @@
if (mosChmod( $baseDir . $userfile_name )) {
return true;
} else {
- $msg = 'Failed to change the permissions of the uploaded file.';
+ $msg = T_('Failed to change the permissions of the uploaded file.');
}
} else {
- $msg = 'Failed to move uploaded file to /media directory.';
+ $msg = T_('Failed to move uploaded file to /media directory.');
}
} else {
- $msg = 'Upload failed as /media directory is not writable.';
+ $msg = T_('Upload failed as /media directory is not writable.');
}
} else {
- $msg = 'Upload failed as /media directory does not exist.';
+ $msg = T_('Upload failed as /media directory does not exist.');
+ }
+ $error = new mosError ($msg, _MOS_ERROR_FATAL);
+ return false;
+}
+/**
+* @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' );
+ if (file_exists( $baseDir )) {
+ if (is_writable( $baseDir )) {
+ if ($fpin = fopen($userurl, 'rb') AND is_resource($fpin)) {
+ if ($fpout = fopen($baseDir.$userfilename, 'wb') AND is_resource($fpout)) {
+ while (!feof($fpin)) {
+ $data = fgets($fpin, 1024);
+ fwrite($fpout, $data);
+ }
+ fclose($fpout);
+ fclose($fpin);
+ 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 /media directory is not writable.');
}
+ else $msg = T_('Upload failed as /media directory does not exist.');
+ $error = new mosError ($msg, _MOS_ERROR_FATAL);
return false;
}
@@ -216,43 +270,46 @@
* @param int The client id
*/
function component_uninstall( $cid, $option, $client=0 ) {
- $database = mamboDatabase::getInstance();
+ $database =& mamboDatabase::getInstance();
$sql = "SELECT * FROM #__components WHERE id=$cid";
$database->setQuery($sql);
if (!$database->loadObject( $row )) {
- HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error',
- "index2.php?option=$option&element=component");
+ $message = new mosError ($database->stderr(true), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Uninstall - error'), "index2.php?option=$option&element=component");
exit();
}
if ($row->iscore) {
- die('Is core component - may not be deleted');
- HTML_installer::showInstallMessage("Component $row->name is a core component, and can not be uninstalled.
You need to unpublish it if you don't want to use it", 'Uninstall - error',
- "index2.php?option=$option&element=component");
+ $message = new mosError (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), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, '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) {
+ $allerrors = new mosErrorSet();
foreach ($filesindir as $file) {
- $parser = new mosUninstallXML ($here.$file);
+ $parser =& new mosUninstallXML ($here.$file);
$parser->uninstall();
- if ($parser->terminalError) {
- var_dump ($parser->errors);
- return false;
- }
+ $allerrors->mergeAnother($parser->errors);
}
+ $ret = ($allerrors->getMaxLevel() < _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage( $allerrors->getErrors(), T_('Uninstall component - ').($ret ? T_('Success') : T_('Error')),
+ returnTo( $option, 'component', $client ) );
}
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();
- */
+ $com_name = $row->option;
+ $dir = new mosDirectory(mosPathName(mamboCore::get('mosConfig_absolute_path').'/components/'.$com_name));
+ $dir->deleteAll();
+ $dir = new mosDirectory(mosPathName(mamboCore::get('mosConfig_absolute_path').'/administrator/components/'.$com_name));
+ $dir->deleteAll();
+ $sql = "DELETE FROM #__components WHERE `option`='$com_name'";
+ $database->setQuery($sql);
+ $database->query();
+ $message = new mosError (T_('Uninstaller could not find XML file, but cleaned database'), _MOS_ERROR_WARN);
+ HTML_installer::showInstallMessage($message, T_('Uninstall ').T_('component - ').T_('Success'), returnTo($option, 'component', $client));
}
- return true;
+ exit();
}
/**
@@ -262,13 +319,14 @@
* @param int The client id
*/
function module_uninstall( $id, $option, $client=0 ) {
- $database = mamboDatabase::getInstance();
+ $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( $row->title .'is a core module, and can not be uninstalled.
You need to unpublish it if you don\'t want to use it', 'Uninstall - error', returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) );
+ $message = new mosError (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), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, 'Uninstall - error', returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) );
exit();
}
$query = "DELETE FROM #__modules_menu WHERE moduleid=$id";
@@ -280,13 +338,12 @@
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 =& new mosUninstallXML ($xmlfile);
$parser->uninstall();
- if ($parser->terminalError) {
- var_dump($parser->errors);
- die('Uninstall failed');
- }
- return true;
+ $ret = ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage( $parser->errors->getErrors(), T_('Uninstall module - ').($ret ? T_('Success') : T_('Error')),
+ returnTo( $option, 'module', $client ) );
+ exit ();
}
/**
@@ -296,33 +353,40 @@
* @param int The client id
*/
function mambot_uninstall( $id, $option, $client=0 ) {
- $database = mamboDatabase::getInstance();
+ $database =& mamboDatabase::getInstance();
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path');
- $database->setQuery( "SELECT name, folder, element, iscore FROM #__mambots WHERE id = '$id'" );
+ $database->setQuery( "SELECT name, folder, element, iscore FROM #__mambots WHERE id = $id" );
$database->loadObject( $row );
if ($database->getErrorNum()) {
- HTML_installer::showInstallMessage( $database->stderr(), 'Uninstall - error',
+ $message = new mosError ($database->stderr(), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Uninstall - error'),
returnTo( $option, 'mambot', $client ) );
exit();
}
if ($row == null) {
- HTML_installer::showInstallMessage( 'Invalid object id', 'Uninstall - error',
- returnTo( $option, 'mambot', $client ) );
+ $message = new mosError (T_('Invalid object id'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Uninstall - error'), returnTo($option, 'mambot', $client));
exit();
}
if (trim( $row->folder ) == '') {
- HTML_installer::showInstallMessage( 'Folder field empty, cannot remove files', 'Uninstall - error',
- returnTo( $option, 'mambot', $client ) );
+ $message = new mosError (T_('Folder field empty, cannot remove files'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, 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->terminalError) {
- var_dump($parser->errors);
- die('Uninstall failed');
- }
- return true;
+ if (file_exists($xmlfile)) {
+ $parser =& new mosUninstallXML ($xmlfile);
+ $ret = $parser->uninstall();
+ $showerrors = $parser->getErrors();
+ }
+ else {
+ $database->setQuery("DELETE FROM #__mambots WHERE id = $id");
+ $ret = $database->query();
+ $showerrors = new mosError (T_('Uninstaller did its best with no XML file present'), _MOS_ERROR_WARN);
+ }
+ HTML_installer::showInstallMessage( $showerrors, T_('Uninstall mambot - ').($ret ? T_('Success') : T_('Error')),
+ returnTo( $option, 'mambot', $client ) );
+ exit ();
}
/**
@@ -340,12 +404,9 @@
$filesindir = mosReadDirectory($path, '.xml$');
if (count($filesindir) > 0) {
foreach ($filesindir as $file) {
- $parser = new mosUninstallXML ($path.$file);
+ $parser =& new mosUninstallXML ($path.$file);
$parser->uninstall();
- if ($parser->terminalError) {
- var_dump ($parser->errors);
- return false;
- }
+ if ($parser->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return false;
}
}
else {
@@ -353,7 +414,9 @@
$tdir = new mosDirectory($path);
$tdir->deleteAll();
}
- return true;
+ $message = new mosError (T_('Uninstall template - '), _MOS_ERROR_INFORM);
+ HTML_installer::showInstallMessage($message, T_('Success'), returnTo($option, 'template', $client));
+ exit ();
}
/**
@@ -368,18 +431,17 @@
$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 =& new mosUninstallXML ($xmlfile);
$parser->uninstall();
- if ($parser->terminalError) {
- var_dump($parser->errors);
- die('Uninstall failed');
- }
- return true;
+ $ret = ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage( $parser->errors->getErrors(), T_('Uninstall language - ').($ret ? T_('Success') : T_('Error')),
+ returnTo( $option, 'language', $client ) );
}
else {
- HTML_installer::showInstallMessage( 'Language id empty, cannot remove files', 'Uninstall - error', "index2.php?option=com_languages");
- exit();
+ $message = new mosError (T_('Language id empty, cannot remove files'), _MOS_ERROR_FATAL);
+ HTML_installer::showInstallMessage($message, T_('Uninstall - error'), "index2.php?option=com_languages");
}
+ exit();
}