[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_joomlaupdate/src/Controller/ -> DisplayController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_joomlaupdate
   6   *
   7   * @copyright   (C) 2012 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\Joomlaupdate\Administrator\Controller;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\MVC\Controller\BaseController;
  15  use Joomla\CMS\Response\JsonResponse;
  16  use Joomla\CMS\Router\Route;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Joomla! Update Controller
  24   *
  25   * @since  2.5.4
  26   */
  27  class DisplayController extends BaseController
  28  {
  29      /**
  30       * Method to display a view.
  31       *
  32       * @param   boolean  $cachable   If true, the view output will be cached.
  33       * @param   array    $urlparams  An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}.
  34       *
  35       * @return  static   This object to support chaining.
  36       *
  37       * @since   2.5.4
  38       */
  39      public function display($cachable = false, $urlparams = false)
  40      {
  41          // Get the document object.
  42          $document = $this->app->getDocument();
  43  
  44          // Set the default view name and format from the Request.
  45          $vName   = $this->input->get('view', 'Joomlaupdate');
  46          $vFormat = $document->getType();
  47          $lName   = $this->input->get('layout', 'default', 'string');
  48  
  49          // Get and render the view.
  50          if ($view = $this->getView($vName, $vFormat)) {
  51              // Only super user can access file upload
  52              if ($view == 'upload' && !$this->app->getIdentity()->authorise('core.admin', 'com_joomlaupdate')) {
  53                  $this->app->redirect(Route::_('index.php?option=com_joomlaupdate', true));
  54              }
  55  
  56              // Get the model for the view.
  57              /** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
  58              $model = $this->getModel('Update');
  59  
  60              /** @var ?\Joomla\Component\Installer\Administrator\Model\WarningsModel $warningsModel */
  61              $warningsModel = $this->app->bootComponent('com_installer')
  62                  ->getMVCFactory()->createModel('Warnings', 'Administrator', ['ignore_request' => true]);
  63  
  64              if ($warningsModel !== null) {
  65                  $view->setModel($warningsModel, false);
  66              }
  67  
  68              // Perform update source preference check and refresh update information.
  69              $model->applyUpdateSite();
  70              $model->refreshUpdates();
  71  
  72              // Push the model into the view (as default).
  73              $view->setModel($model, true);
  74              $view->setLayout($lName);
  75  
  76              // Push document object into the view.
  77              $view->document = $document;
  78              $view->display();
  79          }
  80  
  81          return $this;
  82      }
  83  
  84      /**
  85       * Provide the data for a badge in a menu item via JSON
  86       *
  87       * @return  void
  88       *
  89       * @since   4.0.0
  90       * @throws  \Exception
  91       */
  92      public function getMenuBadgeData()
  93      {
  94          if (!$this->app->getIdentity()->authorise('core.manage', 'com_joomlaupdate')) {
  95              throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
  96          }
  97  
  98          $model = $this->getModel('Update');
  99  
 100          $model->refreshUpdates();
 101  
 102          $joomlaUpdate = $model->getUpdateInformation();
 103  
 104          $hasUpdate = $joomlaUpdate['hasUpdate'] ? $joomlaUpdate['latest'] : '';
 105  
 106          echo new JsonResponse($hasUpdate);
 107      }
 108  }


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