| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Installer 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( T_('Direct Access to this location is not allowed.') ); 19 20 require_once( $mainframe->getPath( 'admin_html' ) ); 21 require_once( $mainframe->getPath( 'class' ) ); 22 23 $element = mosGetParam( $_REQUEST, 'element', '' ); 24 $client = mosGetParam( $_REQUEST, 'client', '' ); 25 // ensure user has access to this function 26 if (!$acl->acl_check( 'administration', 'install', 'users', $my->usertype, $element . 's', 'all' ) ) { 27 mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); 28 } 29 30 // map the element to the required derived class 31 $classMap = array( 32 'universal' => 'mosInstaller', 33 'component' => 'mosInstaller', 34 'language' => 'mosInstaller', 35 'mambot' => 'mosInstaller', 36 'module' => 'mosInstaller', 37 'template' => 'mosInstaller', 38 'include' => 'mosInstaller', 39 'parameters' => 'mosInstaller' 40 ); 41 42 if (array_key_exists ( $element, $classMap )) { 43 // require_once( $mainframe->getPath( 'installer_class', $element ) ); 44 45 switch ($task) { 46 47 case 'uploadfile': 48 uploadPackage( $classMap[$element], $option, $element, $client ); 49 break; 50 51 case 'installfromdir': 52 installFromDirectory( $classMap[$element], $option, $element, $client ); 53 break; 54 55 case 'installfromurl': 56 installFromUrl ($classMap[$element], $option, $element, $client); 57 break; 58 59 case 'thesource': 60 HTML_installer::theSourceForm($option, $element, $client); 61 break; 62 63 case 'addon': 64 HTML_installer::AddonForm($classMap[$element], $option, $element, $client); 65 break; 66 67 case 'remove': 68 $uninstaller = $element.'_uninstall'; 69 if (is_callable($uninstaller)) { 70 $cid = mosGetParam($_REQUEST, 'cid', array(0)); 71 if (is_array($cid) AND isset($cid[0])) { 72 $uninstaller ($cid[0], $option, $client); 73 exit (); 74 } 75 mosRedirect(returnTo($option, $element, $client), T_('There was nothing selected to be uninstalled') ); 76 } 77 else mosRedirect(returnTo($option, $element, $client), T_('Uninstaller not found for element [%s]') ); 78 break; 79 80 default: 81 $path = $mosConfig_absolute_path . "/administrator/components/com_installer/$element/$element.php"; 82 83 if (file_exists( $path )) { 84 require $path; 85 } else { 86 echo sprintf(T_('Installer not found for element [%s]'), $element); 87 } 88 break; 89 } 90 } 91 else { 92 echo sprintf(T_('Installer not available for element [%s]'), $element); 93 } 94 95 96 function returnTo ($option, $element, $client) { 97 switch ($element) { 98 case 'template': 99 return "index2.php?option=com_templates&client=$client"; 100 case 'language': 101 return "index2.php?option=com_languages"; 102 default: 103 return "index2.php?option=$option&element=$element"; 104 } 105 } 106 107 /** 108 * @param string Path to the addons xml file 109 */ 110 function getCurrentAddonVersion ($xmlfile) { 111 global $mosConfig_absolute_path; 112 $xmlfilepath = $mosConfig_absolute_path . $xmlfile; 113 //Check the file exists and is thus installed 114 if (file_exists($xmlfilepath)) { 115 //Load the XML files 116 if (!$mXML = simplexml_load_file($xmlfilepath)) { 117 return "Can't parse XML"; 118 } else { 119 //Look for current version 120 /* Note: Ampersands in the XML data create an issue for SimpleXML. The solution 121 is to either wrap the text in CDATA or enter in the XML file as &. More info 122 on the issue here - http://changelog.ca/log/2005/06/14/php-simplexml-cdata-problem--and-my-solution. 123 Need to revisit later... for now the current XML files have been corrected.*/ 124 $version = $mXML->version; 125 return $version; 126 } 127 } else { 128 return "Not Installed"; 129 } 130 } 131 132 /** 133 * @param string The class name for the installer 134 * @param string The URL option 135 * @param string The element name 136 */ 137 function uploadPackage( $installerClass, $option, $element, $client ) { 138 global $mainframe; 139 140 // Check if file uploads are enabled 141 if (!(bool)ini_get('file_uploads')) { 142 $message = new mosError (T_('The installer can\'t continue before file uploads are enabled. Please use the install from directory method.'), _MOS_ERROR_FATAL); 143 HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo( $option, $element, $client )); 144 exit(); 145 } 146 147 // Check that the zlib is available 148 if(!extension_loaded('zlib')) { 149 $message = new mosError (T_('The installer can\'t continue before zlib is installed'), _MOS_ERROR_FATAL); 150 HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo( $option, $element, $client )); 151 exit(); 152 } 153 154 $userfile = mosGetParam( $_FILES, 'userfile', null ); 155 156 if (!$userfile) { 157 $message = new mosError (T_('No file selected'), _MOS_ERROR_FATAL); 158 HTML_installer::showInstallMessage($message, T_('Upload new module - error'), returnTo($option, $element, $client)); 159 exit(); 160 } 161 162 $userfile_name = $userfile['name']; 163 164 165 if (get_magic_quotes_gpc()==0) $userfile['tmp_name'] = stripslashes($userfile['tmp_name']); 166 if (uploadFile( $userfile['tmp_name'], $userfile['name'], $message )) { 167 // if (uploadFile( stripslashes($userfile['tmp_name']), $userfile['name'], $message )) { 168 $installer =& new $installerClass(); 169 if (!$installer->extractArchive( $userfile['name'] )) { 170 $installer->cleanUpInstall(); 171 HTML_installer::showInstallMessage( $installer->getErrors(), sprintf(T_('Upload %s - Upload Failed'), $element), 172 returnTo( $option, $element, $client ) ); 173 } 174 $ret = $installer->install(); 175 $installer->cleanUpInstall(); 176 HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.($ret ? T_('Success') : T_('Failed')), 177 returnTo( $option, $element, $client ) ); 178 } 179 else HTML_installer::showInstallMessage( $message, sprintf(T_('Upload %s - Upload Error'), $element), 180 returnTo( $option, $element, $client ) ); 181 } 182 183 /** 184 * Install a template from a directory 185 * @param string The URL option 186 */ 187 function installFromDirectory( $installerClass, $option, $element, $client ) { 188 $userfile = mosGetParam( $_REQUEST, 'userfile', '' ); 189 if (!$userfile) { 190 mosRedirect( "index2.php?option=$option&element=module", T_('Please select a directory') ); 191 } 192 $path = mosPathName( $userfile ); 193 if (!is_dir( $path )) { 194 $path = dirname( $path ); 195 } 196 $installer =& new $installerClass(); 197 $ret = $installer->install( $path ); 198 $installer->cleanUpInstall(); 199 HTML_installer::showInstallMessage( $installer->getErrors(), T_('Install new ').$element.' - '.($ret ? T_('Success') : T_('Error')), 200 returnTo( $option, $element, $client ) ); 201 } 202 /** 203 * Install a template from an HTTP URL 204 * @param string The URL option 205 */ 206 function installFromUrl( $installerClass, $option, $element, $client ) { 207 // Check that the zlib is available 208 if(!extension_loaded('zlib')) { 209 $message = new mosError (T_('The installer can\'t continue before zlib is installed'), _MOS_ERROR_FATAL); 210 HTML_installer::showInstallMessage($message, 'Installer - Error', returnTo( $option, $element, $client )); 211 exit(); 212 } 213 $userurl = mosGetParam( $_REQUEST, 'userurl', '' ); 214 if (!$userurl || $userurl[0]=='http://') { 215 $message = new mosError (T_('Please select an HTTP URL'), _MOS_ERROR_FATAL); 216 HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo($option, $element, $client)); 217 exit(); 218 } 219 foreach ($userurl as $value) { 220 $url_data = parse_url($value); 221 if (isset($url_data['path'])) $userfilename = basename($url_data['path']); 222 else $userfilename = ''; 223 if (!$userfilename) { 224 $message = new mosError (T_('The URL did not define a file name'), _MOS_ERROR_FATAL); 225 HTML_installer::showInstallMessage($message, T_('Installer - Error'), returnTo($option, $element, $client)); 226 } 227 if (uploadUrl($value, $userfilename, $message )) { 228 $installer = new $installerClass(); 229 if (!$installer->extractArchive($userfilename)) { 230 $installer->cleanUpInstall(); 231 HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.T_('Failed'), 232 returnTo( $option, $element, $client ) ); 233 } 234 $ret = $installer->install(); 235 $installer->cleanUpInstall(); 236 HTML_installer::showInstallMessage( $installer->getErrors(), T_('Upload ').$element.' - '.($ret ? T_('Success') : T_('Failed')), 237 returnTo( $option, $element, $client ) ); 238 } else { 239 HTML_installer::showInstallMessage( $message, T_('Upload ').$element.' - '.T_('Error'), 240 returnTo( $option, $element, $client ) ); 241 } 242 } 243 } 244 /** 245 * @param string The name of the php (temporary) uploaded file 246 * @param string The name of the file to put in the temp directory 247 * @param string The message to return 248 */ 249 function uploadFile( $filename, $userfile_name, &$error ) { 250 global $mosConfig_absolute_path; 251 $baseDir = mosPathName( $mosConfig_absolute_path . '/media' ); 252 253 if (file_exists( $baseDir )) { 254 if (is_writable( $baseDir )) { 255 if (move_uploaded_file( $filename, $baseDir . $userfile_name )) { 256 if (mosChmod( $baseDir . $userfile_name )) { 257 return true; 258 } else { 259 $msg = T_('Failed to change the permissions of the uploaded file.'); 260 } 261 } else { 262 $msg = T_('Failed to move uploaded file to <code>/media</code> directory.'); 263 } 264 } else { 265 $msg = ""; 266 switch($_FILES['userfile']['error']) { 267 case UPLOAD_ERR_INI_SIZE: 268 $msg = T_("<font color='red'>The uploaded file exceeds the 'upload_max_filesize' directive in php.ini.</font><br />"); 269 break; 270 case UPLOAD_ERR_FORM_SIZE: 271 $msg = T_("<font color='red'>The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.</font><br />"); 272 break; 273 case UPLOAD_ERR_PARTIAL: 274 $msg = T_("<font color='red'>The uploaded file was only partially uploaded.</font><br />"); 275 break; 276 case UPLOAD_ERR_NO_FILE: 277 $msg = T_("<font color='red'>No file was uploaded.</font><br />"); 278 break; 279 case UPLOAD_ERR_NO_TMP_DIR: 280 $msg = T_("<font color='red'>Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.</font><br />"); 281 break; 282 case UPLOAD_ERR_CANT_WRITE: 283 $msg = T_("<font color='red'>Failed to write file to disk. Introduced in PHP 5.1.0.</font><br />"); 284 } 285 $msg .= T_('Failed to move uploaded file to <code>/media</code> directory.'); 286 } 287 } else { 288 $msg = T_('Upload failed as <code>/media</code> directory is not writable.'); 289 } 290 $error = new mosError ($msg, _MOS_ERROR_FATAL); 291 return false; 292 } 293 /** 294 * @param string The name of the php (temporary) uploaded file 295 * @param string The name of the file to put in the temp directory 296 * @param string The message to return 297 */ 298 function uploadUrl( $userurl, $userfilename, &$error ) { 299 global $mosConfig_absolute_path; 300 $baseDir = mosPathName( $mosConfig_absolute_path . '/media' ); 301 if (file_exists( $baseDir )) { 302 if (is_writable( $baseDir )) { 303 if ($fpin = @fopen($userurl, 'rb') AND is_resource($fpin)) { 304 if ($fpout = @fopen($baseDir.$userfilename, 'wb') AND is_resource($fpout)) { 305 while (!feof($fpin)) { 306 $data = fgets($fpin, 1024); 307 fwrite($fpout, $data); 308 } 309 fclose($fpout); 310 fclose($fpin); 311 if (mosChmod( $baseDir.$userfilename )) return true; 312 else $msg = T_('Failed to change the permissions of the uploaded file.'); 313 } 314 else $msg = T_('Failed to open the local file from the URL.'); 315 } 316 else $msg = T_('Failed to open the specified URL.'); 317 } 318 else $msg = T_('Upload failed as <code>/media</code> directory is not writable.'); 319 } 320 else $msg = T_('Upload failed as <code>/media</code> directory does not exist.'); 321 $error = new mosError ($msg, _MOS_ERROR_FATAL); 322 return false; 323 } 324 325 /** 326 * Component uninstall method 327 * @param int The id of the module 328 * @param string The URL option 329 * @param int The client id 330 */ 331 function component_uninstall( $cid, $option, $client=0 ) { 332 $database =& mamboDatabase::getInstance(); 333 // @RawSQLUse, trivial_implementation, SELECT, CONCEPT 334 $sql = "SELECT * FROM #__components WHERE id=$cid"; 335 $database->setQuery($sql); 336 if (!$database->loadObject( $row )) { 337 $message = new mosError ($database->stderr(true), _MOS_ERROR_FATAL); 338 HTML_installer::showInstallMessage($message, T_('Uninstall - error'), "index2.php?option=$option&element=component"); 339 exit(); 340 } 341 if ($row->iscore) { 342 $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); 343 HTML_installer::showInstallMessage($message, 'Uninstall - error', "index2.php?option=$option&element=component"); 344 exit(); 345 } 346 // Try to find the XML file 347 $here = mosPathName( mamboCore::get('mosConfig_absolute_path').'/administrator/components/'.$row->option ); 348 $filesindir = mosReadDirectory($here, '.xml$'); 349 if (count($filesindir) > 0) { 350 $allerrors = new mosErrorSet(); 351 foreach ($filesindir as $file) { 352 $parser =& new mosUninstallXML ($here.$file); 353 $parser->uninstall(); 354 $allerrors->mergeAnother($parser->errors); 355 } 356 $ret = ($allerrors->getMaxLevel() < _MOS_ERROR_FATAL); 357 HTML_installer::showInstallMessage( $allerrors->getErrors(), T_('Uninstall component - ').($ret ? T_('Success') : T_('Error')), 358 returnTo( $option, 'component', $client ) ); 359 } 360 else { 361 $com_name = $row->option; 362 $dir = new mosDirectory(mosPathName(mamboCore::get('mosConfig_absolute_path').'/components/'.$com_name)); 363 $dir->deleteAll(); 364 $dir = new mosDirectory(mosPathName(mamboCore::get('mosConfig_absolute_path').'/administrator/components/'.$com_name)); 365 $dir->deleteAll(); 366 // @RawSQLUse, trivial_implementation, DELETE 367 $sql = "DELETE FROM #__components WHERE `option`='$com_name'"; 368 $database->setQuery($sql); 369 $database->query(); 370 $message = new mosError (T_('Uninstaller could not find XML file, but cleaned database'), _MOS_ERROR_WARN); 371 HTML_installer::showInstallMessage($message, T_('Uninstall ').T_('component - ').T_('Success'), returnTo($option, 'component', $client)); 372 } 373 exit(); 374 } 375 376 /** 377 * Module uninstall method 378 * @param int The id of the module 379 * @param string The URL option 380 * @param int The client id 381 */ 382 function module_uninstall( $id, $option, $client=0 ) { 383 $database =& mamboDatabase::getInstance(); 384 $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); 385 // @RawSQLUse, trivial_implementation, SELECT 386 $query = "SELECT module, iscore, client_id FROM #__modules WHERE id = '$id'"; 387 $database->setQuery( $query ); 388 $database->loadObject( $row ); 389 if ($row->iscore) { 390 $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); 391 HTML_installer::showInstallMessage($message, 'Uninstall - error', returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) ); 392 exit(); 393 } 394 // @RawSQLUse, trivial_implementation, DELETE 395 $query = "DELETE FROM #__modules_menu WHERE moduleid=$id"; 396 $database->setQuery( $query ); 397 if (!$database->query()) { 398 $msg = $database->stderr; 399 die( $msg ); 400 } 401 if ( $row->client_id ) $basepath = $mosConfig_absolute_path . '/administrator/modules/'; 402 else $basepath = $mosConfig_absolute_path . '/modules/'; 403 $xmlfile = $basepath . $row->module . '.xml'; 404 $parser =& new mosUninstallXML ($xmlfile); 405 $parser->uninstall(); 406 $ret = ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL); 407 HTML_installer::showInstallMessage( $parser->errors->getErrors(), T_('Uninstall module - ').($ret ? T_('Success') : T_('Error')), 408 returnTo( $option, 'module', $client ) ); 409 exit (); 410 } 411 412 /** 413 * Mambot install method 414 * @param int The id of the module 415 * @param string The URL option 416 * @param int The client id 417 */ 418 function mambot_uninstall( $id, $option, $client=0 ) { 419 $database =& mamboDatabase::getInstance(); 420 $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); 421 // @RawSQLUse, trivial_implementation, SELECT 422 $database->setQuery( "SELECT name, folder, element, iscore FROM #__mambots WHERE id = $id" ); 423 $database->loadObject( $row ); 424 if ($database->getErrorNum()) { 425 $message = new mosError ($database->stderr(), _MOS_ERROR_FATAL); 426 HTML_installer::showInstallMessage($message, T_('Uninstall - error'), 427 returnTo( $option, 'mambot', $client ) ); 428 exit(); 429 } 430 if ($row == null) { 431 $message = new mosError (T_('Invalid object id'), _MOS_ERROR_FATAL); 432 HTML_installer::showInstallMessage($message, T_('Uninstall - error'), returnTo($option, 'mambot', $client)); 433 exit(); 434 } 435 if (trim( $row->folder ) == '') { 436 $message = new mosError (T_('Folder field empty, cannot remove files'), _MOS_ERROR_FATAL); 437 HTML_installer::showInstallMessage($message, T_('Uninstall - error'), returnTo($option, 'mambot', $client)); 438 exit(); 439 } 440 $xmlfile = $mosConfig_absolute_path.'/mambots/'.$row->folder.'/'.$row->element.'.xml'; 441 if (file_exists($xmlfile)) { 442 $parser =& new mosUninstallXML ($xmlfile); 443 $ret = $parser->uninstall(); 444 $showerrors = $parser->getErrors(); 445 } 446 else { 447 // @RawSQLUse, trivial_implementation, DELETE 448 $database->setQuery("DELETE FROM #__mambots WHERE id = $id"); 449 $ret = $database->query(); 450 $showerrors = new mosError (T_('Uninstaller did its best with no XML file present'), _MOS_ERROR_WARN); 451 } 452 HTML_installer::showInstallMessage( $showerrors, T_('Uninstall mambot - ').($ret ? T_('Success') : T_('Error')), 453 returnTo( $option, 'mambot', $client ) ); 454 exit (); 455 } 456 457 /** 458 * Template uninstall method 459 * @param int The id of the module 460 * @param string The URL option 461 * @param int The client id 462 */ 463 function template_uninstall( $id, $option, $client=0 ) { 464 $id = str_replace( array( '\\', '/' ), '', $id ); 465 $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); 466 // Find if normal or admin template and delete corresponding files & directories 467 if ($client=='admin') { 468 $basepath = mamboCore::get('mosConfig_absolute_path').'/administrator/templates/' . $id; 469 } 470 else { 471 $basepath = mamboCore::get('mosConfig_absolute_path').'/templates/' . $id; 472 } 473 //Use $basepath to remove the template files and directory 474 $tdir = new mosDirectory($basepath); 475 $tdir->deleteAll(); 476 477 $message = new mosError (T_('Uninstall template - '), _MOS_ERROR_INFORM); 478 HTML_installer::showInstallMessage($message, T_('Success'), returnTo($option, 'template', $client)); 479 exit (); 480 } 481 482 /** 483 * Language uninstall method 484 * @param int The id of the module 485 * @param string The URL option 486 * @param int The client id 487 */ 488 function language_uninstall( $id, $option, $client=0 ) { 489 $id = str_replace( array( '\\', '/' ), '', $id ); 490 $basepath = mamboCore::get('mosConfig_absolute_path').'/language/'; 491 $xmlfile = $basepath . $id . '.xml'; 492 // see if there is an xml install file, must be same name as element 493 if (file_exists( $xmlfile )) { 494 $parser =& new mosUninstallXML ($xmlfile); 495 $parser->uninstall(); 496 $ret = ($parser->errors->getMaxLevel() < _MOS_ERROR_FATAL); 497 HTML_installer::showInstallMessage( $parser->errors->getErrors(), T_('Uninstall language - ').($ret ? T_('Success') : T_('Error')), 498 returnTo( $option, 'language', $client ) ); 499 } 500 else { 501 $message = new mosError (T_('Language id empty, cannot remove files'), _MOS_ERROR_FATAL); 502 HTML_installer::showInstallMessage($message, T_('Uninstall - error'), "index2.php?option=com_languages"); 503 } 504 exit(); 505 } 506 507 508 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |