- md5
- 8f1b98be229ecc8bdf6e15fff598c5ab
- sha1
- fddc83cffd9d4c49c7f26ccc2426f7308e25f841
- sha256
- e8d77fa2444f1b271177a2dcafc236717dbf693e1d9e4a108e23518f761c2ef0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
<?php
/**
* @package Joomla.Plugin
* @subpackage Installer.webinstaller
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Installer\Web\Extension;
use Joomla\CMS\Event\Installer\AddInstallationTabEvent;
use Joomla\CMS\Form\Rule\UrlRule;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Updater\Update;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Version;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Support for the "Install from Web" tab
*
* @since 3.2
*/
final class WebInstaller extends CMSPlugin implements SubscriberInterface
{
/**
* The URL for the remote server.
*
* @var string
* @since 4.0.0
*/
public const REMOTE_URL = 'https://appscdn.joomla.org/webapps/';
/**
* The URL to install from
*
* @var string|null
* @since 4.0.0
*/
private $installfrom = null;
/**
* Flag if the document is in a RTL direction
*
* @var integer|null
* @since 4.0.0
*/
private $rtl = null;
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return ['onInstallerAddInstallationTab' => 'onInstallerAddInstallationTab'];
}
/**
* Event listener for the `onInstallerAddInstallationTab` event.
*
* @param AddInstallationTabEvent $event The event instance
*
* @return void
*
* @since 4.0.0
*/
public function onInstallerAddInstallationTab(AddInstallationTabEvent $event)
{
// Load language files
$this->loadLanguage();
$installfrom = $this->getInstallFrom();
$doc = $this->getApplication()->getDocument();
$lang = $this->getApplication()->getLanguage();
// Push language strings to the JavaScript store
Text::script('PLG_INSTALLER_WEBINSTALLER_CANNOT_INSTALL_EXTENSION_IN_PLUGIN');
Text::script('PLG_INSTALLER_WEBINSTALLER_REDIRECT_TO_EXTERNAL_SITE_TO_INSTALL');
$doc->getWebAssetManager()
->registerAndUseStyle('plg_installer_webinstaller.client', 'plg_installer_webinstaller/client.min.css')
->registerAndUseScript(
'plg_installer_webinstaller.client',
'plg_installer_webinstaller/client.min.js',
[],
['type' => 'module'],
['core']
);
$devLevel = Version::PATCH_VERSION;
if (!empty(Version::EXTRA_VERSION)) {
$devLevel .= '-' . Version::EXTRA_VERSION;
}
$doc->addScriptOptions(
'plg_installer_webinstaller',
[
'base_url' => addslashes(self::REMOTE_URL),
'installat_url' => base64_encode(Uri::current() . '?option=com_installer&view=install'),
'installfrom_url' => addslashes($installfrom),
'product' => base64_encode(Version::PRODUCT),
'release' => base64_encode(Version::MAJOR_VERSION . '.' . Version::MINOR_VERSION),
'dev_level' => base64_encode($devLevel),
'installfromon' => $installfrom ? 1 : 0,
'language' => base64_encode($lang->getTag()),
'installFrom' => $installfrom != '' ? 4 : 5,
]
);
$tab = [
'name' => 'web',
'label' => $lang->_('PLG_INSTALLER_WEBINSTALLER_TAB_LABEL'),
];
// Render the input
ob_start();
include PluginHelper::getLayoutPath('installer', 'webinstaller');
$tab['content'] = ob_get_clean();
$tab['content'] = '<legend>' . $tab['label'] . '</legend>' . $tab['content'];
$event->addResult($tab);
}
/**
* Internal check to determine if the output is in a RTL direction
*
* @return integer
*
* @since 3.2
*/
private function isRTL()
{
if ($this->rtl === null) {
$this->rtl = strtolower($this->getApplication()->getDocument()->getDirection()) === 'rtl' ? 1 : 0;
}
return $this->rtl;
}
/**
* Get the install from URL
*
* @return string
*
* @since 3.2
*/
private function getInstallFrom()
{
if ($this->installfrom === null) {
$installfrom = base64_decode($this->getApplication()->getInput()->getBase64('installfrom', ''));
$field = new \SimpleXMLElement('<field></field>');
if ((new UrlRule())->test($field, $installfrom) && preg_match('/\.xml\s*$/', $installfrom)) {
$update = new Update();
$update->loadFromXml($installfrom);
$package_url = trim($update->get('downloadurl', false)->_data);
if ($package_url) {
$installfrom = $package_url;
}
}
$this->installfrom = $installfrom;
}
return $this->installfrom;
}
}
The same content is in 50 releases, Joomla 6.0.0-alpha1 to 6.2.1-rc1. See them all, or every version of this file.