- md5
- 5ed1282c3f2c1a708f94d9492528b932
- sha1
- 1b01ace272853353643ec2541a2ba3837372290c
- sha256
- 2379c6634e5976e2a3bb391f3682204eda024a85e4e287f93c33328622b98fde
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
<?php
/**
* @version $Id: setup.json.php 20954 2011-03-11 18:52:35Z infograf768 $
* @package Joomla.Installation
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Setup controller for the Joomla Core Installer.
* - JSON Protocol -
*
* @package Joomla.Installation
* @since 1.6
*/
class JInstallationControllerSetup extends JController
{
function loadSampleData()
{
// Check for a valid token. If invalid, send a 403 with the error message.
JRequest::checkToken('request') or $this->sendResponse(new JException(JText::_('JINVALID_TOKEN'), 403));
// Get the posted config options.
$vars = JRequest::getVar('jform', array());
// Get the setup model.
$model = $this->getModel('Setup', 'JInstallationModel', array('dbo' => null));
// Get the options from the session.
$vars = $model->storeOptions($vars);
// Get the database model.
$database = $this->getModel('Database', 'JInstallationModel', array('dbo' => null));
// Attempt to load the database sample data.
$return = $database->installSampleData($vars);
// If an error was encountered return an error.
if (!$return) {
$this->sendResponse(new JException($database->getError(), 500));
} else {
// Mark sample content as installed
$data = array(
'sample_installed' => '1'
);
$dummy = $model->storeOptions($data);
}
// Create a response body.
$r = new JObject();
$r->text = JText::_('INSTL_SITE_SAMPLE_LOADED');
// Send the response.
$this->sendResponse($r);
}
function detectFtpRoot()
{
// Check for a valid token. If invalid, send a 403 with the error message.
JRequest::checkToken('request') or $this->sendResponse(new JException(JText::_('JINVALID_TOKEN'), 403));
// Get the posted config options.
$vars = JRequest::getVar('jform', array());
// Get the setup model.
$model = $this->getModel('Setup', 'JInstallationModel', array('dbo' => null));
// Store the options in the session.
$vars = $model->storeOptions($vars);
// Get the database model.
$filesystem = $this->getModel('Filesystem', 'JInstallationModel', array('dbo' => null));
// Attempt to detect the Joomla root from the ftp account.
$return = $filesystem->detectFtpRoot($vars);
// If an error was encountered return an error.
if (!$return) {
$this->sendResponse(new JException($filesystem->getError(), 500));
}
// Create a response body.
$r = new JObject();
$r->root = $return;
// Send the response.
$this->sendResponse($r);
}
function verifyFtpSettings()
{
// Check for a valid token. If invalid, send a 403 with the error message.
JRequest::checkToken('request') or $this->sendResponse(new JException(JText::_('JINVALID_TOKEN'), 403));
// Get the posted config options.
$vars = JRequest::getVar('jform', array());
// Get the setup model.
$model = $this->getModel('Setup', 'JInstallationModel', array('dbo' => null));
// Store the options in the session.
$vars = $model->storeOptions($vars);
// Get the database model.
$filesystem = $this->getModel('Filesystem', 'JInstallationModel', array('dbo' => null));
// Verify the FTP settings.
$return = $filesystem->verifyFtpSettings($vars);
// If an error was encountered return an error.
if (!$return) {
$this->sendResponse(new JException($filesystem->getError(), 500));
}
// Create a response body.
$r = new JObject();
$r->valid = $return;
// Send the response.
$this->sendResponse($r);
}
function removeFolder()
{
jimport('joomla.filesystem.folder');
// Check for a valid token. If invalid, send a 403 with the error message.
JRequest::checkToken('request') or $this->sendResponse(new JException(JText::_('JINVALID_TOKEN'), 403));
// Get the posted config options.
$vars = JRequest::getVar('jform', array());
$path = JPATH_INSTALLATION;
//check whether the folder still exists
if (!file_exists($path)) {
$this->sendResponse(new JException(JText::sprintf('INSTL_COMPLETE_ERROR_FOLDER_ALREADY_REMOVED'), 500));
}
// check whether we need to use FTP
$useFTP = false;
if ((file_exists($path) && !is_writable($path))) {
$useFTP = true;
}
// Check for safe mode
if (ini_get('safe_mode')) {
$useFTP = true;
}
// Enable/Disable override
if (!isset($options->ftpEnable) || ($options->ftpEnable != 1)) {
$useFTP = false;
}
if ($useFTP == true) {
// Connect the FTP client
jimport('joomla.client.ftp');
jimport('joomla.filesystem.path');
$ftp = JFTP::getInstance($options->ftp_host, $options->ftp_port);
$ftp->login($options->ftp_user, $options->ftp_pass);
// Translate path for the FTP account
$file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/');
$return = $ftp->delete($file);
// Delete the extra XML file while we're at it
if ($return)
{
$file = JPath::clean($options->ftp_root.'/joomla.xml');
if (file_exists($file))
{
$return = $ftp->delete($file);
}
}
$ftp->quit();
} else {
// Try to delete the folder.
// We use output buffering so that any error message echoed JFolder::delete
// doesn't land in our JSON output.
ob_start();
$return = JFolder::delete($path) && (!file_exists(JPATH_ROOT.'/joomla.xml') || JFile::delete(JPATH_ROOT.'/joomla.xml'));
ob_end_clean();
}
// If an error was encountered return an error.
if (!$return) {
$this->sendResponse(new JException(JText::_('INSTL_COMPLETE_ERROR_FOLDER_DELETE'), 500));
}
// Create a response body.
$r = new JObject();
$r->text = JText::_('INSTL_COMPLETE_FOLDER_REMOVED');
// Send the response.
$this->sendResponse($r);
}
/**
* Method to handle a send a JSON response. The data parameter
* can be a JException object for when an error has occurred or
* a JObject for a good response.
*
* @access public
* @param object JObject on success, JException on failure.
* @return void
* @since 1.6
*/
function sendResponse($response)
{
// Check if we need to send an error code.
if (JError::isError($response))
{
// Send the appropriate error code response.
JResponse::setHeader('status', $response->getCode());
JResponse::setHeader('Content-Type', 'application/json; charset=utf-8');
JResponse::sendHeaders();
}
// Send the JSON response.
echo json_encode(new JInstallationJsonResponse($response));
// Close the application.
$app = JFactory::getApplication();
$app->close();
}
}
/**
* Joomla Core Installation JSON Response Class
*
* @package Joomla.Installation
* @since 1.6
*/
class JInstallationJsonResponse
{
function __construct($state)
{
// The old token is invalid so send a new one.
$this->token = JUtility::getToken(true);
// Check if we are dealing with an error.
if (JError::isError($state))
{
// Prepare the error response.
$this->error = true;
$this->header = JText::_('INSTL_HEADER_ERROR');
$this->message = $state->getMessage();
}
else
{
// Prepare the response data.
$this->error = false;
$this->data = $state;
}
}
}
// Set the error handler.
//JError::setErrorHandling(E_ALL, 'callback', array('JInstallationControllerSetup', 'sendResponse'));
The same content is in 5 releases, Joomla 1.6.2 to 1.6.6. See them all, or every version of this file.