[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_installer/src/Controller/ -> InstallController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_installer
   6   *
   7   * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Installer\Administrator\Controller;
  12  
  13  use Joomla\CMS\Access\Exception\NotAllowed;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\Controller\BaseController;
  16  use Joomla\CMS\Response\JsonResponse;
  17  use Joomla\CMS\Router\Route;
  18  use Joomla\CMS\Session\Session;
  19  use Joomla\CMS\Uri\Uri;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * Installer controller for Joomla! installer class.
  27   *
  28   * @since  1.5
  29   */
  30  class InstallController extends BaseController
  31  {
  32      /**
  33       * Install an extension.
  34       *
  35       * @return  mixed
  36       *
  37       * @since   1.5
  38       */
  39      public function install()
  40      {
  41          // Check for request forgeries.
  42          $this->checkToken();
  43  
  44          if (!$this->app->getIdentity()->authorise('core.admin')) {
  45              throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
  46          }
  47  
  48          /** @var \Joomla\Component\Installer\Administrator\Model\InstallModel $model */
  49          $model = $this->getModel('install');
  50  
  51          // @todo: Reset the users acl here as well to kill off any missing bits.
  52          $result = $model->install();
  53  
  54          $app          = $this->app;
  55          $redirect_url = $app->getUserState('com_installer.redirect_url');
  56          $return       = $this->input->getBase64('return');
  57  
  58          if (!$redirect_url && $return) {
  59              $redirect_url = base64_decode($return);
  60          }
  61  
  62          // Don't redirect to an external URL.
  63          if ($redirect_url && !Uri::isInternal($redirect_url)) {
  64              $redirect_url = '';
  65          }
  66  
  67          if (empty($redirect_url)) {
  68              $redirect_url = Route::_('index.php?option=com_installer&view=install', false);
  69          } else {
  70              // Wipe out the user state when we're going to redirect.
  71              $app->setUserState('com_installer.redirect_url', '');
  72              $app->setUserState('com_installer.message', '');
  73              $app->setUserState('com_installer.extension_message', '');
  74          }
  75  
  76          $this->setRedirect($redirect_url);
  77  
  78          return $result;
  79      }
  80  
  81      /**
  82       * Install an extension from drag & drop ajax upload.
  83       *
  84       * @return  void
  85       *
  86       * @since   3.7.0
  87       */
  88      public function ajax_upload()
  89      {
  90          // Check for request forgeries.
  91          Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
  92  
  93          if (!$this->app->getIdentity()->authorise('core.admin')) {
  94              throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
  95          }
  96  
  97          $message = $this->app->getUserState('com_installer.message');
  98  
  99          // Do install
 100          $result = $this->install();
 101  
 102          // Get redirect URL
 103          $redirect = $this->redirect;
 104  
 105          // Push message queue to session because we will redirect page by \Javascript, not $app->redirect().
 106          // The "application.queue" is only set in redirect() method, so we must manually store it.
 107          $this->app->getSession()->set('application.queue', $this->app->getMessageQueue());
 108  
 109          header('Content-Type: application/json');
 110  
 111          echo new JsonResponse(array('redirect' => $redirect), $message, !$result);
 112  
 113          $this->app->close();
 114      }
 115  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer