first commit
This commit is contained in:
34
plugins/quickicon/overridecheck/overridecheck.xml
Normal file
34
plugins/quickicon/overridecheck/overridecheck.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="quickicon" method="upgrade">
|
||||
<name>plg_quickicon_overridecheck</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2018-06</creationDate>
|
||||
<copyright>(C) 2018 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_OVERRIDECHECK_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Quickicon\OverrideCheck</namespace>
|
||||
<files>
|
||||
<folder plugin="overridecheck">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_quickicon_overridecheck.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_quickicon_overridecheck.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="context"
|
||||
type="text"
|
||||
label="PLG_QUICKICON_OVERRIDECHECK_GROUP_LABEL"
|
||||
description="PLG_QUICKICON_OVERRIDECHECK_GROUP_DESC"
|
||||
default="update_quickicon"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
48
plugins/quickicon/overridecheck/services/provider.php
Normal file
48
plugins/quickicon/overridecheck/services/provider.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Quickicon.overridecheck
|
||||
*
|
||||
* @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\Database\DatabaseInterface;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Quickicon\OverrideCheck\Extension\OverrideCheck;
|
||||
|
||||
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 OverrideCheck(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('quickicon', 'overridecheck')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
$plugin->setDatabase($container->get(DatabaseInterface::class));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
137
plugins/quickicon/overridecheck/src/Extension/OverrideCheck.php
Normal file
137
plugins/quickicon/overridecheck/src/Extension/OverrideCheck.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Quickicon.overridecheck
|
||||
*
|
||||
* @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\Quickicon\OverrideCheck\Extension;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
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! template override notification plugin
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class OverrideCheck extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
|
||||
/**
|
||||
* 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 overrides update
|
||||
* via AJAX and displays a notification when such overrides are updated.
|
||||
*
|
||||
* @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_templates')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$token = Session::getFormToken() . '=1';
|
||||
$options = [
|
||||
'url' => Uri::base() . 'index.php?option=com_templates&view=templates',
|
||||
'ajaxUrl' => Uri::base() . 'index.php?option=com_templates&view=templates&task=template.ajax&' . $token,
|
||||
'pluginId' => $this->getOverridePluginId(),
|
||||
];
|
||||
|
||||
$this->getApplication()->getDocument()->addScriptOptions('js-override-check', $options);
|
||||
|
||||
Text::script('PLG_QUICKICON_OVERRIDECHECK_ERROR', true);
|
||||
Text::script('PLG_QUICKICON_OVERRIDECHECK_ERROR_ENABLE', true);
|
||||
Text::script('PLG_QUICKICON_OVERRIDECHECK_UPTODATE', true);
|
||||
Text::script('PLG_QUICKICON_OVERRIDECHECK_OVERRIDEFOUND', true);
|
||||
|
||||
$this->getApplication()->getDocument()->getWebAssetManager()
|
||||
->registerAndUseScript('plg_quickicon_overridecheck', 'plg_quickicon_overridecheck/overridecheck.js', [], ['defer' => true], ['core']);
|
||||
|
||||
// Add the icon to the result array
|
||||
$result = $event->getArgument('result', []);
|
||||
|
||||
$result[] = [
|
||||
[
|
||||
'link' => 'index.php?option=com_templates&view=templates',
|
||||
'image' => 'icon-file',
|
||||
'icon' => '',
|
||||
'text' => $this->getApplication()->getLanguage()->_('PLG_QUICKICON_OVERRIDECHECK_CHECKING'),
|
||||
'id' => 'plg_quickicon_overridecheck',
|
||||
'group' => 'MOD_QUICKICON_MAINTENANCE',
|
||||
],
|
||||
];
|
||||
|
||||
$event->setArgument('result', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the installer override plugin extension id.
|
||||
*
|
||||
* @return integer The installer override plugin extension id.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getOverridePluginId()
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('extension_id'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('folder') . ' = ' . $db->quote('installer'))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote('override'));
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$result = (int) $db->loadResult();
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user