Annotation of /mambo/branches/4.6/administrator/components/com_installer/admin.installer.php
Parent Directory
|
Revision Log
Revision 154 - (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 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 15 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 16 : | |||
| 17 : | $element = mosGetParam( $_REQUEST, 'element', '' ); | ||
| 18 : | $client = mosGetParam( $_REQUEST, 'client', '' ); | ||
| 19 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php"; | ||
| 20 : | |||
| 21 : | // ensure user has access to this function | ||
| 22 : | if ( !$acl->acl_check( 'administration', 'install', 'users', $my->usertype, $element . 's', 'all' ) ) { | ||
| 23 : | mosRedirect( 'index2.php', _NOT_AUTH ); | ||
| 24 : | } | ||
| 25 : | |||
| 26 : | // map the element to the required derived class | ||
| 27 : | $classMap = array( | ||
| 28 : | 'component' => 'mosInstallerComponent', | ||
| 29 : | 'language' => 'mosInstallerLanguage', | ||
| 30 : | 'mambot' => 'mosInstallerMambot', | ||
| 31 : | 'module' => 'mosInstallerModule', | ||
| 32 : | 'template' => 'mosInstallerTemplate' | ||
| 33 : | ); | ||
| 34 : | |||
| 35 : | if (array_key_exists ( $element, $classMap )) { | ||
| 36 : | require_once( $mainframe->getPath( 'installer_class', $element ) ); | ||
| 37 : | |||
| 38 : | switch ($task) { | ||
| 39 : | |||
| 40 : | case 'uploadfile': | ||
| 41 : | uploadPackage( $classMap[$element], $option, $element, $client ); | ||
| 42 : | break; | ||
| 43 : | |||
| 44 : | case 'installfromdir': | ||
| 45 : | installFromDirectory( $classMap[$element], $option, $element, $client ); | ||
| 46 : | break; | ||
| 47 : | |||
| 48 : | case 'remove': | ||
| 49 : | csouza | 151 | $uninstaller = $element.'_uninstall'; |
| 50 : | if (is_callable($uninstaller)) { | ||
| 51 : | $cid = mosGetParam($_REQUEST, 'cid', array(0)); | ||
| 52 : | if (is_array($cid) AND isset($cid[0])) { | ||
| 53 : | $result = $uninstaller ($cid[0], $option, $client); | ||
| 54 : | $msg = ''; | ||
| 55 : | } | ||
| 56 : | mosRedirect(returnTo($option, $element, $client), $result ? 'Success ' . $msg : 'Failed ' . $msg ); | ||
| 57 : | } | ||
| 58 : | else echo "Uninstaller not found for element [$element]"; | ||
| 59 : | root | 1 | break; |
| 60 : | |||
| 61 : | default: | ||
| 62 : | $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php"; | ||
| 63 : | |||
| 64 : | if (file_exists( $path )) { | ||
| 65 : | require $path; | ||
| 66 : | } else { | ||
| 67 : | csouza | 151 | echo "Installer not found for element [$element]"; |
| 68 : | root | 1 | } |
| 69 : | break; | ||
| 70 : | } | ||
| 71 : | } | ||
| 72 : | csouza | 151 | else { |
| 73 : | echo "Installer not available for element [$element]"; | ||
| 74 : | } | ||
| 75 : | root | 1 | |
| 76 : | csouza | 151 | |
| 77 : | function returnTo ($option, $element, $client) { | ||
| 78 : | switch ($element) { | ||
| 79 : | case 'template': | ||
| 80 : | return "index2.php?option=com_templates&client=$client"; | ||
| 81 : | case 'language': | ||
| 82 : | return "index2.php?option=com_languages"; | ||
| 83 : | default: | ||
| 84 : | return "index2.php?option=$option&element=$element"; | ||
| 85 : | } | ||
| 86 : | } | ||
| 87 : | |||
| 88 : | root | 1 | /** |
| 89 : | * @param string The class name for the installer | ||
| 90 : | * @param string The URL option | ||
| 91 : | * @param string The element name | ||
| 92 : | */ | ||
| 93 : | function uploadPackage( $installerClass, $option, $element, $client ) { | ||
| 94 : | global $mainframe; | ||
| 95 : | |||
| 96 : | $installer = new $installerClass(); | ||
| 97 : | |||
| 98 : | // Check if file uploads are enabled | ||
| 99 : | if (!(bool)ini_get('file_uploads')) { | ||
| 100 : | csouza | 151 | HTML_installer::showInstallMessage( "The installer can't continue before file uploads are enabled. Please use the install from directory method.", |
| 101 : | 'Installer - Error', returnTo( $option, $element, $client ) ); | ||
| 102 : | root | 1 | exit(); |
| 103 : | } | ||
| 104 : | |||
| 105 : | // Check that the zlib is available | ||
| 106 : | if(!extension_loaded('zlib')) { | ||
| 107 : | csouza | 151 | HTML_installer::showInstallMessage( "The installer can't continue before zlib is installed", |
| 108 : | 'Installer - Error', returnTo( $option, $element, $client ) ); | ||
| 109 : | root | 1 | exit(); |
| 110 : | } | ||
| 111 : | |||
| 112 : | $userfile = mosGetParam( $_FILES, 'userfile', null ); | ||
| 113 : | |||
| 114 : | if (!$userfile) { | ||
| 115 : | csouza | 151 | HTML_installer::showInstallMessage( 'No file selected', 'Upload new module - error', |
| 116 : | returnTo( $option, $element, $client )); | ||
| 117 : | root | 1 | exit(); |
| 118 : | } | ||
| 119 : | |||
| 120 : | $userfile_name = $userfile['name']; | ||
| 121 : | |||
| 122 : | $msg = ''; | ||
| 123 : | $resultdir = uploadFile( $userfile['tmp_name'], $userfile['name'], $msg ); | ||
| 124 : | |||
| 125 : | if ($resultdir !== false) { | ||
| 126 : | csouza | 151 | if (!$installer->extractArchive( $userfile['name'] )) { |
| 127 : | HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - Upload Failed', | ||
| 128 : | returnTo( $option, $element, $client ) ); | ||
| 129 : | root | 1 | } |
| 130 : | $ret = $installer->install(); | ||
| 131 : | |||
| 132 : | csouza | 151 | HTML_installer::showInstallMessage( $installer->getError(), 'Upload '.$element.' - '.($ret ? 'Success' : 'Failed'), |
| 133 : | returnTo( $option, $element, $client ) ); | ||
| 134 : | $installer->cleanUpInstall(); | ||
| 135 : | root | 1 | } else { |
| 136 : | csouza | 151 | HTML_installer::showInstallMessage( $msg, 'Upload '.$element.' - Upload Error', |
| 137 : | root | 1 | $installer->returnTo( $option, $element, $client ) ); |
| 138 : | } | ||
| 139 : | } | ||
| 140 : | |||
| 141 : | /** | ||
| 142 : | * Install a template from a directory | ||
| 143 : | * @param string The URL option | ||
| 144 : | */ | ||
| 145 : | function installFromDirectory( $installerClass, $option, $element, $client ) { | ||
| 146 : | $userfile = mosGetParam( $_REQUEST, 'userfile', '' ); | ||
| 147 : | |||
| 148 : | if (!$userfile) { | ||
| 149 : | csouza | 154 | mosRedirect( "index2.php?option=$option&element=module", T_("Please select a directory") ); |
| 150 : | root | 1 | } |
| 151 : | |||
| 152 : | $installer = new $installerClass(); | ||
| 153 : | |||
| 154 : | $path = mosPathName( $userfile ); | ||
| 155 : | if (!is_dir( $path )) { | ||
| 156 : | $path = dirname( $path ); | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | $ret = $installer->install( $path ); | ||
| 160 : | csouza | 151 | HTML_installer::showInstallMessage( $installer->getError(), 'Upload new '.$element.' - '.($ret ? 'Success' : 'Error'), |
| 161 : | returnTo( $option, $element, $client ) ); | ||
| 162 : | root | 1 | } |
| 163 : | /** | ||
| 164 : | * | ||
| 165 : | * @param | ||
| 166 : | */ | ||
| 167 : | function removeElement( $installerClass, $option, $element, $client ) { | ||
| 168 : | $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); | ||
| 169 : | if (!is_array( $cid )) { | ||
| 170 : | $cid = array(0); | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | $installer = new $installerClass(); | ||
| 174 : | $result = false; | ||
| 175 : | if ($cid[0]) { | ||
| 176 : | $result = $installer->uninstall( $cid[0], $option, $client ); | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | $msg = $installer->getError(); | ||
| 180 : | |||
| 181 : | csouza | 151 | mosRedirect( returnTo( $option, $element, $client ), $result ? 'Success ' . $msg : 'Failed ' . $msg ); |
| 182 : | root | 1 | } |
| 183 : | /** | ||
| 184 : | * @param string The name of the php (temporary) uploaded file | ||
| 185 : | * @param string The name of the file to put in the temp directory | ||
| 186 : | * @param string The message to return | ||
| 187 : | */ | ||
| 188 : | function uploadFile( $filename, $userfile_name, &$msg ) { | ||
| 189 : | global $mosConfig_absolute_path; | ||
| 190 : | $baseDir = mosPathName( $mosConfig_absolute_path . '/media' ); | ||
| 191 : | |||
| 192 : | if (file_exists( $baseDir )) { | ||
| 193 : | if (is_writable( $baseDir )) { | ||
| 194 : | if (move_uploaded_file( $filename, $baseDir . $userfile_name )) { | ||
| 195 : | if (mosChmod( $baseDir . $userfile_name )) { | ||
| 196 : | return true; | ||
| 197 : | } else { | ||
| 198 : | csouza | 151 | $msg = 'Failed to change the permissions of the uploaded file.'; |
| 199 : | root | 1 | } |
| 200 : | } else { | ||
| 201 : | csouza | 151 | $msg = 'Failed to move uploaded file to <code>/media</code> directory.'; |
| 202 : | root | 1 | } |
| 203 : | } else { | ||
| 204 : | csouza | 151 | $msg = 'Upload failed as <code>/media</code> directory is not writable.'; |
| 205 : | root | 1 | } |
| 206 : | } else { | ||
| 207 : | csouza | 151 | $msg = 'Upload failed as <code>/media</code> directory does not exist.'; |
| 208 : | root | 1 | } |
| 209 : | return false; | ||
| 210 : | } | ||
| 211 : | csouza | 151 | |
| 212 : | /** | ||
| 213 : | * Component uninstall method | ||
| 214 : | * @param int The id of the module | ||
| 215 : | * @param string The URL option | ||
| 216 : | * @param int The client id | ||
| 217 : | */ | ||
| 218 : | function component_uninstall( $cid, $option, $client=0 ) { | ||
| 219 : | $database = mamboDatabase::getInstance(); | ||
| 220 : | $sql = "SELECT * FROM #__components WHERE id=$cid"; | ||
| 221 : | $database->setQuery($sql); | ||
| 222 : | if (!$database->loadObject( $row )) { | ||
| 223 : | HTML_installer::showInstallMessage($database->stderr(true),'Uninstall - error', | ||
| 224 : | "index2.php?option=$option&element=component"); | ||
| 225 : | exit(); | ||
| 226 : | } | ||
| 227 : | if ($row->iscore) { | ||
| 228 : | die('Is core component - may not be deleted'); | ||
| 229 : | HTML_installer::showInstallMessage("Component $row->name is a core component, and can not be uninstalled.<br />You need to unpublish it if you don't want to use it", 'Uninstall - error', | ||
| 230 : | "index2.php?option=$option&element=component"); | ||
| 231 : | exit(); | ||
| 232 : | } | ||
| 233 : | // Try to find the XML file | ||
| 234 : | $here = mosPathName( mamboCore::get('mosConfig_absolute_path').'/administrator/components/'.$row->option ); | ||
| 235 : | $filesindir = mosReadDirectory($here, '.xml$'); | ||
| 236 : | if (count($filesindir) > 0) { | ||
| 237 : | foreach ($filesindir as $file) { | ||
| 238 : | $parser = new mosUninstallXML ($here.$file); | ||
| 239 : | $parser->uninstall(); | ||
| 240 : | if ($parser->terminalError) { | ||
| 241 : | var_dump ($parser->errors); | ||
| 242 : | return false; | ||
| 243 : | } | ||
| 244 : | } | ||
| 245 : | } | ||
| 246 : | else { | ||
| 247 : | // no XML file | ||
| 248 : | return false; | ||
| 249 : | /* | ||
| 250 : | HTML_installer::showInstallMessage( 'Could not find XML Setup file in '.$mosConfig_absolute_path.'/administrator/components/'.$row->option, | ||
| 251 : | 'Uninstall - error', $option, 'component' ); | ||
| 252 : | exit(); | ||
| 253 : | */ | ||
| 254 : | } | ||
| 255 : | return true; | ||
| 256 : | } | ||
| 257 : | |||
| 258 : | /** | ||
| 259 : | * Module uninstall method | ||
| 260 : | * @param int The id of the module | ||
| 261 : | * @param string The URL option | ||
| 262 : | * @param int The client id | ||
| 263 : | */ | ||
| 264 : | function module_uninstall( $id, $option, $client=0 ) { | ||
| 265 : | $database = mamboDatabase::getInstance(); | ||
| 266 : | $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 267 : | $query = "SELECT module, iscore, client_id FROM #__modules WHERE id = '$id'"; | ||
| 268 : | $database->setQuery( $query ); | ||
| 269 : | $database->loadObject( $row ); | ||
| 270 : | if ($row->iscore) { | ||
| 271 : | HTML_installer::showInstallMessage( $row->title .'is a core module, and can not be uninstalled.<br />You need to unpublish it if you don\'t want to use it', 'Uninstall - error', returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) ); | ||
| 272 : | exit(); | ||
| 273 : | } | ||
| 274 : | $query = "DELETE FROM #__modules_menu WHERE moduleid=$id"; | ||
| 275 : | $database->setQuery( $query ); | ||
| 276 : | if (!$database->query()) { | ||
| 277 : | $msg = $database->stderr; | ||
| 278 : | die( $msg ); | ||
| 279 : | } | ||
| 280 : | if ( $row->client_id ) $basepath = $mosConfig_absolute_path . '/administrator/modules/'; | ||
| 281 : | else $basepath = $mosConfig_absolute_path . '/modules/'; | ||
| 282 : | $xmlfile = $basepath . $row->module . '.xml'; | ||
| 283 : | $parser = new mosUninstallXML ($xmlfile); | ||
| 284 : | $parser->uninstall(); | ||
| 285 : | if ($parser->terminalError) { | ||
| 286 : | var_dump($parser->errors); | ||
| 287 : | die('Uninstall failed'); | ||
| 288 : | } | ||
| 289 : | return true; | ||
| 290 : | } | ||
| 291 : | |||
| 292 : | /** | ||
| 293 : | * Mambot install method | ||
| 294 : | * @param int The id of the module | ||
| 295 : | * @param string The URL option | ||
| 296 : | * @param int The client id | ||
| 297 : | */ | ||
| 298 : | function mambot_uninstall( $id, $option, $client=0 ) { | ||
| 299 : | $database = mamboDatabase::getInstance(); | ||
| 300 : | $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 301 : | $database->setQuery( "SELECT name, folder, element, iscore FROM #__mambots WHERE id = '$id'" ); | ||
| 302 : | $database->loadObject( $row ); | ||
| 303 : | if ($database->getErrorNum()) { | ||
| 304 : | HTML_installer::showInstallMessage( $database->stderr(), 'Uninstall - error', | ||
| 305 : | returnTo( $option, 'mambot', $client ) ); | ||
| 306 : | exit(); | ||
| 307 : | } | ||
| 308 : | if ($row == null) { | ||
| 309 : | HTML_installer::showInstallMessage( 'Invalid object id', 'Uninstall - error', | ||
| 310 : | returnTo( $option, 'mambot', $client ) ); | ||
| 311 : | exit(); | ||
| 312 : | } | ||
| 313 : | if (trim( $row->folder ) == '') { | ||
| 314 : | HTML_installer::showInstallMessage( 'Folder field empty, cannot remove files', 'Uninstall - error', | ||
| 315 : | returnTo( $option, 'mambot', $client ) ); | ||
| 316 : | exit(); | ||
| 317 : | } | ||
| 318 : | $xmlfile = $mosConfig_absolute_path.'/mambots/'.$row->folder.'/'.$row->element.'.xml'; | ||
| 319 : | $parser = new mosUninstallXML ($xmlfile); | ||
| 320 : | $parser->uninstall(); | ||
| 321 : | if ($parser->terminalError) { | ||
| 322 : | var_dump($parser->errors); | ||
| 323 : | die('Uninstall failed'); | ||
| 324 : | } | ||
| 325 : | return true; | ||
| 326 : | } | ||
| 327 : | |||
| 328 : | /** | ||
| 329 : | * Template uninstall method | ||
| 330 : | * @param int The id of the module | ||
| 331 : | * @param string The URL option | ||
| 332 : | * @param int The client id | ||
| 333 : | */ | ||
| 334 : | function template_uninstall( $id, $option, $client=0 ) { | ||
| 335 : | $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); | ||
| 336 : | // Delete directories | ||
| 337 : | $path = mosPathName($mosConfig_absolute_path | ||
| 338 : | . ($client == 'admin' ? '/administrator' : '' ) | ||
| 339 : | . '/templates/' . $id); | ||
| 340 : | $filesindir = mosReadDirectory($path, '.xml$'); | ||
| 341 : | if (count($filesindir) > 0) { | ||
| 342 : | foreach ($filesindir as $file) { | ||
| 343 : | $parser = new mosUninstallXML ($path.$file); | ||
| 344 : | $parser->uninstall(); | ||
| 345 : | if ($parser->terminalError) { | ||
| 346 : | var_dump ($parser->errors); | ||
| 347 : | return false; | ||
| 348 : | } | ||
| 349 : | } | ||
| 350 : | } | ||
| 351 : | else { | ||
| 352 : | // no XML - just delete the template directory | ||
| 353 : | $tdir = new mosDirectory($path); | ||
| 354 : | $tdir->deleteAll(); | ||
| 355 : | } | ||
| 356 : | return true; | ||
| 357 : | } | ||
| 358 : | |||
| 359 : | /** | ||
| 360 : | * Language uninstall method | ||
| 361 : | * @param int The id of the module | ||
| 362 : | * @param string The URL option | ||
| 363 : | * @param int The client id | ||
| 364 : | */ | ||
| 365 : | function language_uninstall( $id, $option, $client=0 ) { | ||
| 366 : | $id = str_replace( array( '\\', '/' ), '', $id ); | ||
| 367 : | $basepath = mamboCore::get('mosConfig_absolute_path').'/language/'; | ||
| 368 : | $xmlfile = $basepath . $id . '.xml'; | ||
| 369 : | // see if there is an xml install file, must be same name as element | ||
| 370 : | if (file_exists( $xmlfile )) { | ||
| 371 : | $parser = new mosUninstallXML ($xmlfile); | ||
| 372 : | $parser->uninstall(); | ||
| 373 : | if ($parser->terminalError) { | ||
| 374 : | var_dump($parser->errors); | ||
| 375 : | die('Uninstall failed'); | ||
| 376 : | } | ||
| 377 : | return true; | ||
| 378 : | } | ||
| 379 : | else { | ||
| 380 : | HTML_installer::showInstallMessage( 'Language id empty, cannot remove files', 'Uninstall - error', "index2.php?option=com_languages"); | ||
| 381 : | exit(); | ||
| 382 : | } | ||
| 383 : | } | ||
| 384 : | |||
| 385 : | |||
| 386 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

