first commit
This commit is contained in:
46
plugins/installer/webinstaller/services/provider.php
Normal file
46
plugins/installer/webinstaller/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Installer.webinstaller
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Extension\PluginInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Installer\Web\Extension\WebInstaller;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new WebInstaller(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('installer', 'webinstaller')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
192
plugins/installer/webinstaller/src/Extension/WebInstaller.php
Normal file
192
plugins/installer/webinstaller/src/Extension/WebInstaller.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?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\Application\CMSApplication;
|
||||
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 application object.
|
||||
*
|
||||
* @var CMSApplication
|
||||
* @since 4.0.0
|
||||
* @deprecated 6.0 Is needed for template overrides, use getApplication instead
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
49
plugins/installer/webinstaller/tmpl/default.php
Normal file
49
plugins/installer/webinstaller/tmpl/default.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/** @var PlgInstallerWebinstaller $this */
|
||||
|
||||
$dir = $this->isRTL() ? ' dir="ltr"' : '';
|
||||
|
||||
Text::script('JSEARCH_FILTER_CLEAR');
|
||||
Text::script('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_LOADING_ERROR');
|
||||
|
||||
?>
|
||||
<div id="jed-container" class="tab-pane">
|
||||
<div class="card" id="web-loader">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title"><?php echo Text::_('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_LOADING'); ?></h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden" id="web-loader-error">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="form-group hidden" id="uploadform-web"<?php echo $dir; ?>>
|
||||
<p><strong><?php echo Text::_('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_CONFIRM'); ?></strong></p>
|
||||
<dl>
|
||||
<dt id="uploadform-web-name-label"><?php echo Text::_('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_CONFIRM_NAME'); ?></dt>
|
||||
<dd id="uploadform-web-name"></dd>
|
||||
<dt><?php echo Text::_('PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_CONFIRM_URL'); ?></dt>
|
||||
<dd id="uploadform-web-url"></dd>
|
||||
</dl>
|
||||
<div class="card card-light">
|
||||
<div class="card-body">
|
||||
<div class="card-text">
|
||||
<button type="button" class="btn btn-primary" id="uploadform-web-install"><?php echo Text::_('COM_INSTALLER_INSTALL_BUTTON'); ?></button>
|
||||
<button type="button" class="btn btn-secondary" id="uploadform-web-cancel"><?php echo Text::_('JCANCEL'); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
22
plugins/installer/webinstaller/webinstaller.xml
Normal file
22
plugins/installer/webinstaller/webinstaller.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="installer" method="upgrade">
|
||||
<name>plg_installer_webinstaller</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2017-04</creationDate>
|
||||
<copyright>(C) 2018 Open Source Matters, Inc.</copyright>
|
||||
<license>https://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_INSTALLER_WEBINSTALLER_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Installer\Web</namespace>
|
||||
<files>
|
||||
<folder plugin="webinstaller">services</folder>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_installer_webinstaller.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_installer_webinstaller.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
Reference in New Issue
Block a user