[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/installer/webinstaller/ -> webinstaller.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Installer.webinstaller
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9  
  10   * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
  11   */
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Form\Rule\UrlRule;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Plugin\CMSPlugin;
  17  use Joomla\CMS\Plugin\PluginHelper;
  18  use Joomla\CMS\Updater\Update;
  19  use Joomla\CMS\Uri\Uri;
  20  use Joomla\CMS\Version;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Support for the "Install from Web" tab
  28   *
  29   * @since  3.2
  30   */
  31  class PlgInstallerWebinstaller extends CMSPlugin
  32  {
  33      /**
  34       * The URL for the remote server.
  35       *
  36       * @var    string
  37       * @since  4.0.0
  38       */
  39      public const REMOTE_URL = 'https://appscdn.joomla.org/webapps/';
  40  
  41      /**
  42       * The application object.
  43       *
  44       * @var    CMSApplication
  45       * @since  4.0.0
  46       */
  47      protected $app;
  48  
  49      /**
  50       * The URL to install from
  51       *
  52       * @var    string|null
  53       * @since  4.0.0
  54       */
  55      private $installfrom = null;
  56  
  57      /**
  58       * Flag if the document is in a RTL direction
  59       *
  60       * @var    integer|null
  61       * @since  4.0.0
  62       */
  63      private $rtl = null;
  64  
  65      /**
  66       * Event listener for the `onInstallerAddInstallationTab` event.
  67       *
  68       * @return  array  Returns an array with the tab information
  69       *
  70       * @since   4.0.0
  71       */
  72      public function onInstallerAddInstallationTab()
  73      {
  74          // Load language files
  75          $this->loadLanguage();
  76  
  77          $installfrom = $this->getInstallFrom();
  78          $doc         = $this->app->getDocument();
  79          $lang        = $this->app->getLanguage();
  80  
  81          // Push language strings to the JavaScript store
  82          Text::script('PLG_INSTALLER_WEBINSTALLER_CANNOT_INSTALL_EXTENSION_IN_PLUGIN');
  83          Text::script('PLG_INSTALLER_WEBINSTALLER_REDIRECT_TO_EXTERNAL_SITE_TO_INSTALL');
  84  
  85          $doc->getWebAssetManager()
  86              ->registerAndUseStyle('plg_installer_webinstaller.client', 'plg_installer_webinstaller/client.min.css')
  87              ->registerAndUseScript(
  88                  'plg_installer_webinstaller.client',
  89                  'plg_installer_webinstaller/client.min.js',
  90                  [],
  91                  ['type' => 'module'],
  92                  ['core']
  93              );
  94  
  95          $devLevel = Version::PATCH_VERSION;
  96  
  97          if (!empty(Version::EXTRA_VERSION)) {
  98              $devLevel .= '-' . Version::EXTRA_VERSION;
  99          }
 100  
 101          $doc->addScriptOptions(
 102              'plg_installer_webinstaller',
 103              [
 104                  'base_url'        => addslashes(self::REMOTE_URL),
 105                  'installat_url'   => base64_encode(Uri::current() . '?option=com_installer&view=install'),
 106                  'installfrom_url' => addslashes($installfrom),
 107                  'product'         => base64_encode(Version::PRODUCT),
 108                  'release'         => base64_encode(Version::MAJOR_VERSION . '.' . Version::MINOR_VERSION),
 109                  'dev_level'       => base64_encode($devLevel),
 110                  'installfromon'   => $installfrom ? 1 : 0,
 111                  'language'        => base64_encode($lang->getTag()),
 112                  'installFrom'     => $installfrom != '' ? 4 : 5,
 113              ]
 114          );
 115  
 116          $tab = [
 117              'name'  => 'web',
 118              'label' => Text::_('PLG_INSTALLER_WEBINSTALLER_TAB_LABEL'),
 119          ];
 120  
 121          // Render the input
 122          ob_start();
 123          include PluginHelper::getLayoutPath('installer', 'webinstaller');
 124          $tab['content'] = ob_get_clean();
 125          $tab['content'] = '<legend>' . $tab['label'] . '</legend>' . $tab['content'];
 126  
 127          return $tab;
 128      }
 129  
 130      /**
 131       * Internal check to determine if the output is in a RTL direction
 132       *
 133       * @return  integer
 134       *
 135       * @since   3.2
 136       */
 137      private function isRTL()
 138      {
 139          if ($this->rtl === null) {
 140              $this->rtl = strtolower($this->app->getDocument()->getDirection()) === 'rtl' ? 1 : 0;
 141          }
 142  
 143          return $this->rtl;
 144      }
 145  
 146      /**
 147       * Get the install from URL
 148       *
 149       * @return  string
 150       *
 151       * @since   3.2
 152       */
 153      private function getInstallFrom()
 154      {
 155          if ($this->installfrom === null) {
 156              $installfrom = base64_decode($this->app->input->getBase64('installfrom', ''));
 157  
 158              $field = new SimpleXMLElement('<field></field>');
 159  
 160              if ((new UrlRule())->test($field, $installfrom) && preg_match('/\.xml\s*$/', $installfrom)) {
 161                  $update = new Update();
 162                  $update->loadFromXml($installfrom);
 163                  $package_url = trim($update->get('downloadurl', false)->_data);
 164  
 165                  if ($package_url) {
 166                      $installfrom = $package_url;
 167                  }
 168              }
 169  
 170              $this->installfrom = $installfrom;
 171          }
 172  
 173          return $this->installfrom;
 174      }
 175  }


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