first commit
This commit is contained in:
34
plugins/quickicon/downloadkey/downloadkey.xml
Normal file
34
plugins/quickicon/downloadkey/downloadkey.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="quickicon" method="upgrade">
|
||||
<name>plg_quickicon_downloadkey</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2019-10</creationDate>
|
||||
<copyright>(C) 2019 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_QUICKICON_DOWNLOADKEY_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Quickicon\Downloadkey</namespace>
|
||||
<files>
|
||||
<folder plugin="downloadkey">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_quickicon_downloadkey.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_quickicon_downloadkey.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="context"
|
||||
type="text"
|
||||
label="PLG_QUICKICON_DOWNLOADKEY_GROUP_LABEL"
|
||||
description="PLG_QUICKICON_DOWNLOADKEY_GROUP_DESC"
|
||||
default="update_quickicon"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
46
plugins/quickicon/downloadkey/services/provider.php
Normal file
46
plugins/quickicon/downloadkey/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Quickicon.downloadkey
|
||||
*
|
||||
* @copyright (C) 2022 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\Quickicon\Downloadkey\Extension\Downloadkey;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Downloadkey(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('quickicon', 'downloadkey')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
150
plugins/quickicon/downloadkey/src/Extension/Downloadkey.php
Normal file
150
plugins/quickicon/downloadkey/src/Extension/Downloadkey.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Quickicon.downloadkey
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Quickicon\Downloadkey\Extension;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper as ComInstallerHelper;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Joomla! update notification plugin
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class Downloadkey extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Returns an array of events this subscriber will listen to.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'onGetIcons' => 'onGetIcons',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an icon definition for an icon which looks for extensions updates
|
||||
* via AJAX and displays a notification when such updates are found.
|
||||
*
|
||||
* @param QuickIconsEvent $event The event object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onGetIcons(QuickIconsEvent $event): void
|
||||
{
|
||||
$context = $event->getContext();
|
||||
|
||||
if (
|
||||
$context !== $this->params->get('context', 'update_quickicon')
|
||||
|| !$this->getApplication()->getIdentity()->authorise('core.manage', 'com_installer')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$info = $this->getMissingDownloadKeyInfo();
|
||||
|
||||
// No extensions need a download key. The icon is not rendered.
|
||||
if (!$info['supported']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$iconDefinition = [
|
||||
'link' => 'index.php?option=com_installer&view=updatesites&filter[supported]=1',
|
||||
'image' => 'icon-key',
|
||||
'icon' => '',
|
||||
'text' => Text::_('PLG_QUICKICON_DOWNLOADKEY_OK'),
|
||||
'class' => 'success',
|
||||
'id' => 'plg_quickicon_downloadkey',
|
||||
'group' => 'MOD_QUICKICON_MAINTENANCE',
|
||||
];
|
||||
|
||||
if ($info['missing'] !== 0) {
|
||||
$iconDefinition = array_merge(
|
||||
$iconDefinition,
|
||||
[
|
||||
'link' => 'index.php?option=com_installer&view=updatesites&filter[supported]=-1',
|
||||
'text' => Text::plural('PLG_QUICKICON_DOWNLOADKEY_N_MISSING', $info['missing']),
|
||||
'class' => 'danger',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Add the icon to the result array
|
||||
$result = $event->getArgument('result', []);
|
||||
|
||||
$result[] = [
|
||||
$iconDefinition,
|
||||
];
|
||||
|
||||
$event->setArgument('result', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the information about update sites requiring but missing a download key.
|
||||
*
|
||||
* The return array has two keys:
|
||||
* - supported Number of update sites supporting Download Key
|
||||
* - missing Number of update sites missing a Download Key
|
||||
*
|
||||
* If 'supported' is zero you do not need to provide any download keys. All your extensions are free downloads.
|
||||
*
|
||||
* If 'supported' is non-zero and 'missing' is zero you have entered a download key for all paid extensions.
|
||||
*
|
||||
* If 'supported' is non-zero and 'missing' is also non-zero you need to enter one or more download keys.
|
||||
*
|
||||
* @return array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getMissingDownloadKeyInfo(): array
|
||||
{
|
||||
$ret = [
|
||||
'supported' => 0,
|
||||
'missing' => 0,
|
||||
];
|
||||
|
||||
if (!class_exists('Joomla\Component\Installer\Administrator\Helper\InstallerHelper')) {
|
||||
require_once JPATH_ADMINISTRATOR . '/components/com_installer/Helper/InstallerHelper.php';
|
||||
}
|
||||
|
||||
$supported = ComInstallerHelper::getDownloadKeySupportedSites(true);
|
||||
$ret['supported'] = \count($supported);
|
||||
|
||||
if ($ret['supported'] === 0) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$missing = ComInstallerHelper::getDownloadKeyExistsSites(false, true);
|
||||
$ret['missing'] = \count($missing);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user