Skip to content

Commit

Permalink
Merge branch '4.0-dev' into feature/rtl-atum
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Jul 16, 2018
2 parents 04d3851 + edec487 commit 1ef2f58
Show file tree
Hide file tree
Showing 44 changed files with 542 additions and 477 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Component\Installer\Administrator\Model\WarningsModel;
use Joomla\CMS\Client\ClientHelper;
use Joomla\CMS\Factory;

/**
* Joomla! Update Controller
Expand All @@ -33,7 +35,7 @@ class DisplayController extends BaseController
public function display($cachable = false, $urlparams = false)
{
// Get the document object.
$document = \JFactory::getDocument();
$document = Factory::getDocument();

// Set the default view name and format from the Request.
$vName = $this->input->get('view', 'Joomlaupdate');
Expand All @@ -43,7 +45,7 @@ public function display($cachable = false, $urlparams = false)
// Get and render the view.
if ($view = $this->getView($vName, $vFormat))
{
$ftp = \JClientHelper::setCredentialsFromRequest('ftp');
$ftp = ClientHelper::setCredentialsFromRequest('ftp');
$view->ftp = &$ftp;

// Get the model for the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
defined('_JEXEC') or die;

use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Client\ClientHelper;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Factory;

/**
* The Joomla! update controller for the Update view
Expand All @@ -28,16 +35,16 @@ class UpdateController extends BaseController
*/
public function download()
{
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
\JLog::addLogger($options, \JLog::INFO, array('Update', 'databasequery', 'jerror'));
$user = \JFactory::getUser();
Log::addLogger($options, Log::INFO, array('Update', 'databasequery', 'jerror'));
$user = Factory::getUser();

try
{
\JLog::add(\JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_START', $user->id, $user->name, \JVERSION), \JLog::INFO, 'Update');
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_START', $user->id, $user->name, \JVERSION), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -60,7 +67,7 @@ public function download()

try
{
\JLog::add(\JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_FILE', $file), \JLog::INFO, 'Update');
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_FILE', $file), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -71,7 +78,7 @@ public function download()
{
$this->app->setUserState('com_joomlaupdate.file', null);
$url = 'index.php?option=com_joomlaupdate';
$message = \JText::_('COM_JOOMLAUPDATE_VIEW_UPDATE_DOWNLOADFAILED');
$message = Text::_('COM_JOOMLAUPDATE_VIEW_UPDATE_DOWNLOADFAILED');
$messageType = 'error';
}

Expand All @@ -87,15 +94,15 @@ public function download()
*/
public function install()
{
\JSession::checkToken('get') or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken('get') or jexit(Text::_('JINVALID_TOKEN'));

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
\JLog::addLogger($options, \JLog::INFO, array('Update', 'databasequery', 'jerror'));
Log::addLogger($options, Log::INFO, array('Update', 'databasequery', 'jerror'));

try
{
\JLog::add(\JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_INSTALL'), \JLog::INFO, 'Update');
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_INSTALL'), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -107,7 +114,7 @@ public function install()
/* @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

$file = \JFactory::getApplication()->getUserState('com_joomlaupdate.file', null);
$file = Factory::getApplication()->getUserState('com_joomlaupdate.file', null);
$model->createRestorationFile($file);

$this->display();
Expand All @@ -126,7 +133,7 @@ public function finalise()
* Finalize with login page. Used for pre-token check versions
* to allow updates without problems but with a maximum of security.
*/
if (!\JSession::checkToken('get'))
if (!Session::checkToken('get'))
{
$this->setRedirect('index.php?option=com_joomlaupdate&view=update&layout=finaliseconfirm');

Expand All @@ -135,11 +142,11 @@ public function finalise()

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
\JLog::addLogger($options, \JLog::INFO, array('Update', 'databasequery', 'jerror'));
Log::addLogger($options, Log::INFO, array('Update', 'databasequery', 'jerror'));

try
{
\JLog::add(\JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_FINALISE'), \JLog::INFO, 'Update');
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_FINALISE'), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -153,7 +160,7 @@ public function finalise()

$model->finaliseUpgrade();

$url = 'index.php?option=com_joomlaupdate&task=update.cleanup&' . \JSession::getFormToken() . '=1';
$url = 'index.php?option=com_joomlaupdate&task=update.cleanup&' . Session::getFormToken() . '=1';
$this->setRedirect($url);
}

Expand All @@ -170,7 +177,7 @@ public function cleanup()
* Cleanup with login page. Used for pre-token check versions to be able to update
* from =< 3.2.7 to allow updates without problems but with a maximum of security.
*/
if (!\JSession::checkToken('get'))
if (!Session::checkToken('get'))
{
$this->setRedirect('index.php?option=com_joomlaupdate&view=update&layout=finaliseconfirm');

Expand All @@ -179,11 +186,11 @@ public function cleanup()

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
\JLog::addLogger($options, \JLog::INFO, array('Update', 'databasequery', 'jerror'));
Log::addLogger($options, Log::INFO, array('Update', 'databasequery', 'jerror'));

try
{
\JLog::add(\JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP'), \JLog::INFO, 'Update');
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP'), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -202,7 +209,7 @@ public function cleanup()

try
{
\JLog::add(\JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', \JVERSION), \JLog::INFO, 'Update');
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', \JVERSION), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
Expand All @@ -220,7 +227,7 @@ public function cleanup()
public function purge()
{
// Check for request forgeries
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

// Purge updates
/* @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
Expand All @@ -241,10 +248,10 @@ public function purge()
public function upload()
{
// Check for request forgeries
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

// Did a non Super User tried to upload something (a.k.a. pathetic hacking attempt)?
\JFactory::getUser()->authorise('core.admin') or jexit(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
Factory::getUser()->authorise('core.admin') or jexit(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));

$this->_applyCredentials();

Expand All @@ -261,7 +268,7 @@ public function upload()
$this->setRedirect($url, $e->getMessage(), 'error');
}

$token = \JSession::getFormToken();
$token = Session::getFormToken();
$url = 'index.php?option=com_joomlaupdate&task=update.captive&' . $token . '=1';
$this->setRedirect($url);
}
Expand All @@ -276,22 +283,22 @@ public function upload()
public function captive()
{
// Check for request forgeries
\JSession::checkToken('get') or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken('get') or jexit(Text::_('JINVALID_TOKEN'));

// Did a non Super User tried to upload something (a.k.a. pathetic hacking attempt)?
if (!\JFactory::getUser()->authorise('core.admin'))
if (!Factory::getUser()->authorise('core.admin'))
{
throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

// Do I really have an update package?
$tempFile = \JFactory::getApplication()->getUserState('com_joomlaupdate.temp_file', null);
$tempFile = Factory::getApplication()->getUserState('com_joomlaupdate.temp_file', null);

\JLoader::import('joomla.filesystem.file');

if (empty($tempFile) || !\JFile::exists($tempFile))
if (empty($tempFile) || !File::exists($tempFile))
{
throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

$this->input->set('view', 'upload');
Expand All @@ -310,12 +317,12 @@ public function captive()
public function confirm()
{
// Check for request forgeries
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

// Did a non Super User tried to upload something (a.k.a. pathetic hacking attempt)?
if (!$this->app->getIdentity()->authorise('core.admin'))
{
throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

// Get the model
Expand All @@ -328,7 +335,7 @@ public function confirm()
// Do I really have an update package?
if (!$model->captiveFileExists())
{
throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

// Try to log in
Expand All @@ -344,23 +351,23 @@ public function confirm()
{
$model->removePackageFiles();

throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

// Set the update source in the session
$this->app->setUserState('com_joomlaupdate.file', basename($tempFile));

try
{
\JLog::add(\JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_FILE', $tempFile), \JLog::INFO, 'Update');
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_FILE', $tempFile), Log::INFO, 'Update');
}
catch (\RuntimeException $exception)
{
// Informational log only
}

// Redirect to the actual update page
$url = 'index.php?option=com_joomlaupdate&task=update.install&' . \JSession::getFormToken() . '=1';
$url = 'index.php?option=com_joomlaupdate&task=update.install&' . Session::getFormToken() . '=1';
$this->setRedirect($url);
}

Expand All @@ -377,7 +384,7 @@ public function confirm()
public function display($cachable = false, $urlparams = array())
{
// Get the document object.
$document = \JFactory::getDocument();
$document = Factory::getDocument();

// Set the default view name and format from the Request.
$vName = $this->input->get('view', 'update');
Expand Down Expand Up @@ -414,17 +421,17 @@ protected function _applyCredentials()
{
$this->app->getUserStateFromRequest('com_joomlaupdate.method', 'method', 'direct', 'cmd');

if (!\JClientHelper::hasCredentials('ftp'))
if (!ClientHelper::hasCredentials('ftp'))
{
$user = $this->app->getUserStateFromRequest('com_joomlaupdate.ftp_user', 'ftp_user', null, 'raw');
$pass = $this->app->getUserStateFromRequest('com_joomlaupdate.ftp_pass', 'ftp_pass', null, 'raw');

if ($user != '' && $pass != '')
{
// Add credentials to the session
if (!\JClientHelper::setCredentials('ftp', $user, $pass))
if (!ClientHelper::setCredentials('ftp', $user, $pass))
{
$this->app->enqueueMessage(\JText::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED'), 'warning');
$this->app->enqueueMessage(Text::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED'), 'warning');
}
}
}
Expand All @@ -440,12 +447,12 @@ protected function _applyCredentials()
public function finaliseconfirm()
{
// Check for request forgeries
\JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN'));
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));

// Did a non Super User try do this?
if (!\JFactory::getUser()->authorise('core.admin'))
if (!Factory::getUser()->authorise('core.admin'))
{
throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

// Get the model
Expand All @@ -464,14 +471,14 @@ public function finaliseconfirm()
// The login fails?
if (!$result)
{
$this->setMessage(\JText::_('JGLOBAL_AUTH_INVALID_PASS'), 'warning');
$this->setMessage(Text::_('JGLOBAL_AUTH_INVALID_PASS'), 'warning');
$this->setRedirect('index.php?option=com_joomlaupdate&view=update&layout=finaliseconfirm');

return false;
}

// Redirect back to the actual finalise page
$this->setRedirect('index.php?option=com_joomlaupdate&task=update.finalise&' . \JSession::getFormToken() . '=1');
$this->setRedirect('index.php?option=com_joomlaupdate&task=update.finalise&' . Session::getFormToken() . '=1');
}

/**
Expand All @@ -492,15 +499,15 @@ public function fetchExtensionCompatibility()
$model = $this->getModel('default');
$updateFileUrl = $model->fetchCompatibility($extensionID, $joomlaTargetVersion);

$this->app = JFactory::getApplication();
$this->app = Factory::getApplication();
$this->app->mimeType = 'application/json';
$this->app->charSet = 'utf-8';
$this->app->setHeader('Content-Type', $this->app->mimeType . '; charset=' . $this->app->charSet);
$this->app->sendHeaders();

try
{
echo new JResponseJson($updateFileUrl);
echo new JsonResponse($updateFileUrl);
}
catch (Exception $e)
{
Expand Down
11 changes: 7 additions & 4 deletions administrator/components/com_joomlaupdate/Helper/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;

/**
* Joomla! update selection list helper.
*
Expand All @@ -31,10 +34,10 @@ class Select
public static function getMethods($default = 'hybrid', $name = 'method', $id = 'extraction_method')
{
$options = array();
$options[] = \JHtml::_('select.option', 'direct', \JText::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_DIRECT'));
$options[] = \JHtml::_('select.option', 'hybrid', \JText::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_HYBRID'));
$options[] = \JHtml::_('select.option', 'ftp', \JText::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_FTP'));
$options[] = HTMLHelper::_('select.option', 'direct', Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_DIRECT'));
$options[] = HTMLHelper::_('select.option', 'hybrid', Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_HYBRID'));
$options[] = HTMLHelper::_('select.option', 'ftp', Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_METHOD_FTP'));

return \JHtml::_('select.genericlist', $options, $name, 'class="custom-select"', 'value', 'text', $default, $id);
return HTMLHelper::_('select.genericlist', $options, $name, 'class="custom-select"', 'value', 'text', $default, $id);
}
}

0 comments on commit 1ef2f58

Please sign in to comment.