Annotation of /mambo/branches/4.6/administrator/components/com_installer/admin.installer.php
Parent Directory
|
Revision Log
Revision 149 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: admin.installer.php,v 1.1 2005/07/22 01:52:25 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @subpackage Installer | ||
| 6 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 7 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 8 : | * Mambo is Free Software | ||
| 9 : | */ | ||
| 10 : | |||
| 11 : | /** ensure this file is being included by a parent file */ | ||
| 12 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 13 : | |||
| 14 : | // XML library | ||
| 15 : | require_once( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' ); | ||
| 16 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 17 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 18 : | |||
| 19 : | $element = mosGetParam( $_REQUEST, 'element', '' ); | ||
| 20 : | $client = mosGetParam( $_REQUEST, 'client', '' ); | ||
| 21 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php"; | ||
| 22 : | |||
| 23 : | // ensure user has access to this function | ||
| 24 : | if ( !$acl->acl_check( 'administration', 'install', 'users', $my->usertype, $element . 's', 'all' ) ) { | ||
| 25 : | mosRedirect( 'index2.php', _NOT_AUTH ); | ||
| 26 : | } | ||
| 27 : | |||
| 28 : | // map the element to the required derived class | ||
| 29 : | $classMap = array( | ||
| 30 : | 'component' => 'mosInstallerComponent', | ||
| 31 : | 'language' => 'mosInstallerLanguage', | ||
| 32 : | 'mambot' => 'mosInstallerMambot', | ||
| 33 : | 'module' => 'mosInstallerModule', | ||
| 34 : | 'template' => 'mosInstallerTemplate' | ||
| 35 : | ); | ||
| 36 : | |||
| 37 : | if (array_key_exists ( $element, $classMap )) { | ||
| 38 : | require_once( $mainframe->getPath( 'installer_class', $element ) ); | ||
| 39 : | |||
| 40 : | switch ($task) { | ||
| 41 : | |||
| 42 : | case 'uploadfile': | ||
| 43 : | uploadPackage( $classMap[$element], $option, $element, $client ); | ||
| 44 : | break; | ||
| 45 : | |||
| 46 : | case 'installfromdir': | ||
| 47 : | installFromDirectory( $classMap[$element], $option, $element, $client ); | ||
| 48 : | break; | ||
| 49 : | |||
| 50 : | case 'remove': | ||
| 51 : | removeElement( $classMap[$element], $option, $element, $client ); | ||
| 52 : | break; | ||
| 53 : | |||
| 54 : | default: | ||
| 55 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php"; | ||
| 56 : | |||
| 57 : | if (file_exists( $path )) { | ||
| 58 : | require $path; | ||
| 59 : | } else { | ||
| 60 : | csouza | 149 | echo T_('Installer not found for element')." [$element]"; |
| 61 : | root | 1 | } |
| 62 : | break; | ||
| 63 : | } | ||
| 64 : | } else { | ||
| 65 : | csouza | 149 | echo T_('Installer not available for element')." [$element]"; |
| 66 : | root | 1 | } |
| 67 : | |||
| 68 : | /** | ||
| 69 : | * @param string The class name for the installer | ||
| 70 : | * @param string The URL option | ||
| 71 : | * @param string The element name | ||
| 72 : | */ | ||
| 73 : | function uploadPackage( $installerClass, $option, $element, $client ) { | ||
| 74 : | global $mainframe; | ||
| 75 : | |||
| 76 : | $installer = new $installerClass(); | ||
| 77 : | |||
| 78 : | // Check if file uploads are enabled | ||
| 79 : | if (!(bool)ini_get('file_uploads')) { | ||
| 80 : | csouza | 149 | HTML_installer::showInstallMessage( T_("The installer can't continue before file uploads are enabled. Please use the install from directory method."), |
| 81 : | root | 1 | 'Installer - Error', $installer->returnTo( $option, $element, $client ) ); |
| 82 : | exit(); | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | // Check that the zlib is available | ||
| 86 : | if(!extension_loaded('zlib')) { | ||
| 87 : | csouza | 149 | HTML_installer::showInstallMessage( T_("The installer can't continue before zlib is installed"), |
| 88 : | T_('Installer - Error'), $installer->returnTo( $option, $element, $client ) ); | ||
| 89 : | root | 1 | exit(); |
| 90 : | } | ||
| 91 : | |||
| 92 : | $userfile = mosGetParam( $_FILES, 'userfile', null ); | ||
| 93 : | |||
| 94 : | if (!$userfile) { | ||
| 95 : | csouza | 149 | HTML_installer::showInstallMessage( T_('No file selected'), T_('Upload new module - error'), |
| 96 : | root | 1 | $installer->returnTo( $option, $element, $client )); |
| 97 : | exit(); | ||
| 98 : | } | ||
| 99 : | |||
| 100 : | $userfile_name = $userfile['name']; | ||
| 101 : | |||
| 102 : | $msg = ''; | ||
| 103 : | $resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg ); | ||
| 104 : | |||
| 105 : | if ($resultdir !== false) { | ||
| 106 : | if (!$installer->upload( $userfile['name'] )) { | ||
| 107 : | csouza | 149 | HTML_installer::showInstallMessage( $installer->getError(), T_('Upload').' '.$element.' - '.T_('Upload Failed'), |
| 108 : | root | 1 | $installer->returnTo( $option, $element, $client ) ); |
| 109 : | } | ||
| 110 : | $ret = $installer->install(); | ||
| 111 : | |||
| 112 : | csouza | 149 | HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - '.($ret ? T_('Success') : T_('Failed')), |
| 113 : | root | 1 | $installer->returnTo( $option, $element, $client ) ); |
| 114 : | cleanupInstall( $userfile['name'], $installer->unpackDir() ); | ||
| 115 : | } else { | ||
| 116 : | csouza | 149 | HTML_installer::showInstallMessage( $msg, T_('Upload').' '.$element.' - '.T_('Upload Error'), |
| 117 : | root | 1 | $installer->returnTo( $option, $element, $client ) ); |
| 118 : | } | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | /** | ||
| 122 : | * Install a template from a directory | ||
| 123 : | * @param string The URL option | ||
| 124 : | */ | ||
| 125 : | function installFromDirectory( $installerClass, $option, $element, $client ) { | ||
| 126 : | $userfile = mosGetParam( $_REQUEST, 'userfile', '' ); | ||
| 127 : | |||
| 128 : | if (!$userfile) { | ||
| 129 : | csouza | 149 | mosRedirect( "index2.php?option=$option&element=module", T_("Please select a directory") ); |
| 130 : | root | 1 | } |
| 131 : | |||
| 132 : | $installer = new $installerClass(); | ||
| 133 : | |||
| 134 : | $path = mosPathName( $userfile ); | ||
| 135 : | if (!is_dir( $path )) { | ||
| 136 : | $path = dirname( $path ); | ||
| 137 : | } | ||
| 138 : | |||
| 139 : | $ret = $installer->install( $path ); | ||
| 140 : | csouza | 149 | HTML_installer::showInstallMessage( $installer->getError(), T_('Upload new').' '.$element.' - '.($ret ? T_('Success') : T_('Error')), |
| 141 : | root | 1 | $installer->returnTo( $option, $element, $client ) ); |
| 142 : | } | ||
| 143 : | /** | ||
| 144 : | * | ||
| 145 : | * @param | ||
| 146 : | */ | ||
| 147 : | function removeElement( $installerClass, $option, $element, $client ) { | ||
| 148 : | $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); | ||
| 149 : | if (!is_array( $cid )) { | ||
| 150 : | $cid = array(0); | ||
| 151 : | } | ||
| 152 : | |||
| 153 : | $installer = new $installerClass(); | ||
| 154 : | $result = false; | ||
| 155 : | if ($cid[0]) { | ||
| 156 : | $result = $installer->uninstall( $cid[0], $option, $client ); | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | $msg = $installer->getError(); | ||
| 160 : | |||
| 161 : | csouza | 149 | mosRedirect( $installer->returnTo( $option, $element, $client ), $result ? T_('Success').' ' . $msg : T_('Failed').' '. $msg ); |
| 162 : | root | 1 | } |
| 163 : | /** | ||
| 164 : | * @param string The name of the php (temporary) uploaded file | ||
| 165 : | * @param string The name of the file to put in the temp directory | ||
| 166 : | * @param string The message to return | ||
| 167 : | */ | ||
| 168 : | function uploadFile( $filename, $userfile_name, &$msg ) { | ||
| 169 : | global $mosConfig_absolute_path; | ||
| 170 : | $baseDir = mosPathName( $mosConfig_absolute_path . '/media' ); | ||
| 171 : | |||
| 172 : | if (file_exists( $baseDir )) { | ||
| 173 : | if (is_writable( $baseDir )) { | ||
| 174 : | if (move_uploaded_file( $filename, $baseDir . $userfile_name )) { | ||
| 175 : | if (mosChmod( $baseDir . $userfile_name )) { | ||
| 176 : | return true; | ||
| 177 : | } else { | ||
| 178 : | csouza | 149 | $msg = T_('Failed to change the permissions of the uploaded file.'); |
| 179 : | root | 1 | } |
| 180 : | } else { | ||
| 181 : | csouza | 149 | $msg = T_('Failed to move uploaded file to <code>/media</code> directory.'); |
| 182 : | root | 1 | } |
| 183 : | } else { | ||
| 184 : | csouza | 149 | $msg = T_('Upload failed as <code>/media</code> directory is not writable.'); |
| 185 : | root | 1 | } |
| 186 : | } else { | ||
| 187 : | csouza | 149 | $msg = T_('Upload failed as <code>/media</code> directory does not exist.'); |
| 188 : | root | 1 | } |
| 189 : | return false; | ||
| 190 : | } | ||
| 191 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

