[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_joomlaupdate/src/View/Joomlaupdate/ -> HtmlView.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\View\Joomlaupdate;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  17  use Joomla\CMS\Toolbar\ToolbarHelper;
  18  use Joomla\CMS\Version;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Joomla! Update's Default View
  26   *
  27   * @since  2.5.4
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * An array with the Joomla! update information.
  33       *
  34       * @var    array
  35       *
  36       * @since  3.6.0
  37       */
  38      protected $updateInfo = null;
  39  
  40      /**
  41       * PHP options.
  42       *
  43       * @var   array  Array of PHP config options
  44       *
  45       * @since 3.10.0
  46       */
  47      protected $phpOptions = null;
  48  
  49      /**
  50       * PHP settings.
  51       *
  52       * @var   array  Array of PHP settings
  53       *
  54       * @since 3.10.0
  55       */
  56      protected $phpSettings = null;
  57  
  58      /**
  59       * Non Core Extensions.
  60       *
  61       * @var   array  Array of Non-Core-Extensions
  62       *
  63       * @since 3.10.0
  64       */
  65      protected $nonCoreExtensions = null;
  66  
  67      /**
  68       * The model state
  69       *
  70       * @var    \Joomla\CMS\Object\CMSObject
  71       *
  72       * @since  4.0.0
  73       */
  74      protected $state;
  75  
  76      /**
  77       * Flag if the update component itself has to be updated
  78       *
  79       * @var boolean  True when update is available otherwise false
  80       *
  81       * @since 4.0.0
  82       */
  83      protected $selfUpdateAvailable = false;
  84  
  85      /**
  86       * The default admin template for the major version of Joomla that should be used when
  87       * upgrading to the next major version of Joomla
  88       *
  89       * @var string
  90       *
  91       * @since 4.0.0
  92       */
  93      protected $defaultBackendTemplate = 'atum';
  94  
  95      /**
  96       * Flag if default backend template is being used
  97       *
  98       * @var boolean  True when default backend template is being used
  99       *
 100       * @since 4.0.0
 101       */
 102      protected $isDefaultBackendTemplate = false;
 103  
 104      /**
 105       * A special prefix used for the emptystate layout variable
 106       *
 107       * @var string  The prefix
 108       *
 109       * @since 4.0.0
 110       */
 111      protected $messagePrefix = '';
 112  
 113      /**
 114       * List of non core critical plugins
 115       *
 116       * @var    \stdClass[]
 117       * @since  4.0.0
 118       */
 119      protected $nonCoreCriticalPlugins = [];
 120  
 121      /**
 122       * Should I disable the confirmation checkbox for pre-update extension version checks?
 123       *
 124       * @var   boolean
 125       * @since 4.2.0
 126       */
 127      protected $noVersionCheck = false;
 128  
 129      /**
 130       * Should I disable the confirmation checkbox for taking a backup before updating?
 131       *
 132       * @var   boolean
 133       * @since 4.2.0
 134       */
 135      protected $noBackupCheck = false;
 136  
 137      /**
 138       * Renders the view
 139       *
 140       * @param   string  $tpl  Template name
 141       *
 142       * @return void
 143       *
 144       * @since  2.5.4
 145       */
 146      public function display($tpl = null)
 147      {
 148          $this->updateInfo          = $this->get('UpdateInformation');
 149          $this->selfUpdateAvailable = $this->get('CheckForSelfUpdate');
 150  
 151          // Get results of pre update check evaluations
 152          $model                          = $this->getModel();
 153          $this->phpOptions               = $this->get('PhpOptions');
 154          $this->phpSettings              = $this->get('PhpSettings');
 155          $this->nonCoreExtensions        = $this->get('NonCoreExtensions');
 156          $this->isDefaultBackendTemplate = (bool) $model->isTemplateActive($this->defaultBackendTemplate);
 157          $nextMajorVersion               = Version::MAJOR_VERSION + 1;
 158  
 159          // The critical plugins check is only available for major updates.
 160          if (version_compare($this->updateInfo['latest'], (string) $nextMajorVersion, '>=')) {
 161              $this->nonCoreCriticalPlugins = $this->get('NonCorePlugins');
 162          }
 163  
 164          // Set to true if a required PHP option is not ok
 165          $isCritical = false;
 166  
 167          foreach ($this->phpOptions as $option) {
 168              if (!$option->state) {
 169                  $isCritical = true;
 170                  break;
 171              }
 172          }
 173  
 174          $this->state = $this->get('State');
 175  
 176          $hasUpdate = !empty($this->updateInfo['hasUpdate']);
 177          $hasDownload = isset($this->updateInfo['object']->downloadurl->_data);
 178  
 179          // Fresh update, show it
 180          if ($this->getLayout() == 'complete') {
 181              // Complete message, nothing to do here
 182          } elseif ($this->selfUpdateAvailable) {
 183              // There is an update for the updater itself. So we have to update it first
 184              $this->setLayout('selfupdate');
 185          } elseif (!$hasDownload || !$hasUpdate) {
 186              // Could be that we have a download file but no update, so we offer a re-install
 187              if ($hasDownload) {
 188                  // We can reinstall if we have a URL but no update
 189                  $this->setLayout('reinstall');
 190              } else {
 191                  // No download available
 192                  if ($hasUpdate) {
 193                      $this->messagePrefix = '_NODOWNLOAD';
 194                  }
 195  
 196                  $this->setLayout('noupdate');
 197              }
 198          } elseif ($this->getLayout() != 'update' && ($isCritical || $this->shouldDisplayPreUpdateCheck())) {
 199              // Here we have now two options: preupdatecheck or update
 200              $this->setLayout('preupdatecheck');
 201          } else {
 202              $this->setLayout('update');
 203          }
 204  
 205          if (in_array($this->getLayout(), ['preupdatecheck', 'update', 'upload'])) {
 206              $language = Factory::getLanguage();
 207              $language->load('com_installer', JPATH_ADMINISTRATOR, 'en-GB', false, true);
 208              $language->load('com_installer', JPATH_ADMINISTRATOR, null, true);
 209  
 210              Factory::getApplication()->enqueueMessage(Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATE_NOTICE'), 'warning');
 211          }
 212  
 213          $params = ComponentHelper::getParams('com_joomlaupdate');
 214  
 215          switch ($params->get('updatesource', 'default')) {
 216              // "Minor & Patch Release for Current version AND Next Major Release".
 217              case 'next':
 218                  $this->langKey         = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_NEXT';
 219                  $this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT');
 220                  break;
 221  
 222              // "Testing"
 223              case 'testing':
 224                  $this->langKey         = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_TESTING';
 225                  $this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING');
 226                  break;
 227  
 228              // "Custom"
 229              case 'custom':
 230                  $this->langKey         = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_CUSTOM';
 231                  $this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_CUSTOM');
 232                  break;
 233  
 234              /**
 235               * "Minor & Patch Release for Current version (recommended and default)".
 236               * The commented "case" below are for documenting where 'default' and legacy options falls
 237               * case 'default':
 238               * case 'sts':
 239               * case 'lts':
 240               * case 'nochange':
 241               */
 242              default:
 243                  $this->langKey         = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_DEFAULT';
 244                  $this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT');
 245          }
 246  
 247          $this->noVersionCheck = $params->get('versioncheck', 1) == 0;
 248          $this->noBackupCheck  = $params->get('backupcheck', 1) == 0;
 249  
 250          // Remove temporary files
 251          $this->getModel()->removePackageFiles();
 252  
 253          $this->addToolbar();
 254  
 255          // Render the view.
 256          parent::display($tpl);
 257      }
 258  
 259      /**
 260       * Add the page title and toolbar.
 261       *
 262       * @return  void
 263       *
 264       * @since   4.0.0
 265       */
 266      protected function addToolbar()
 267      {
 268          // Set the toolbar information.
 269          ToolbarHelper::title(Text::_('COM_JOOMLAUPDATE_OVERVIEW'), 'joomla install');
 270  
 271          if (in_array($this->getLayout(), ['update', 'complete'])) {
 272              $arrow = Factory::getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left';
 273  
 274              ToolbarHelper::link('index.php?option=com_joomlaupdate', 'JTOOLBAR_BACK', $arrow);
 275  
 276              ToolbarHelper::title(Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_TAB_UPLOAD'), 'joomla install');
 277          } elseif (!$this->selfUpdateAvailable) {
 278              ToolbarHelper::custom('update.purge', 'loop', '', 'COM_JOOMLAUPDATE_TOOLBAR_CHECK', false);
 279          }
 280  
 281          // Add toolbar buttons.
 282          $currentUser = version_compare(JVERSION, '4.2.0', 'ge')
 283              ? $this->getCurrentUser()
 284              : Factory::getApplication()->getIdentity();
 285  
 286          if ($currentUser->authorise('core.admin')) {
 287              ToolbarHelper::preferences('com_joomlaupdate');
 288          }
 289  
 290          ToolbarHelper::divider();
 291          ToolbarHelper::help('Joomla_Update');
 292      }
 293  
 294      /**
 295       * Returns true, if the pre update check should be displayed.
 296       *
 297       * @return boolean
 298       *
 299       * @since 3.10.0
 300       */
 301      public function shouldDisplayPreUpdateCheck()
 302      {
 303          // When the download URL is not found there is no core upgrade path
 304          if (!isset($this->updateInfo['object']->downloadurl->_data)) {
 305              return false;
 306          }
 307  
 308          $nextMinor = Version::MAJOR_VERSION . '.' . (Version::MINOR_VERSION + 1);
 309  
 310          // Show only when we found a download URL, we have an update and when we update to the next minor or greater.
 311          return $this->updateInfo['hasUpdate']
 312              && version_compare($this->updateInfo['latest'], $nextMinor, '>=');
 313      }
 314  }


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