primo commit
This commit is contained in:
141
plugins/system/jooa11y/jooa11y.xml
Normal file
141
plugins/system/jooa11y/jooa11y.xml
Normal file
@ -0,0 +1,141 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="system" method="upgrade">
|
||||
<name>plg_system_jooa11y</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2022-02</creationDate>
|
||||
<copyright>(C) 2021 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.2.0</version>
|
||||
<description>PLG_SYSTEM_JOOA11Y_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\System\Jooa11y</namespace>
|
||||
<files>
|
||||
<folder plugin="jooa11y">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_system_jooa11y.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_system_jooa11y.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="showAlways"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_SHOW_ALWAYS"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_SHOW_ALWAYS_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="contrastPlugin"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_CONTRAST"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_CONTRAST_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="formLabelsPlugin"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_FORM_LABELS"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_FORM_LABELS_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="linksAdvancedPlugin"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_LINKS_ADVANCED"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_LINKS_ADVANCED_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="colourFilterPlugin"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_COLOUR_FILTER"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_COLOUR_FILTER_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="additionalChecks"
|
||||
type="radio"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_ADDITIONAL_CHECKS"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_ADDITIONAL_CHECKS_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
<field
|
||||
name="checkRoot"
|
||||
type="text"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_CHECK_ROOT"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_CHECK_ROOT_DESC"
|
||||
default="main"
|
||||
filter="string"
|
||||
/>
|
||||
<field
|
||||
name="readabilityRoot"
|
||||
type="text"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_READABILITY_ROOT"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_READABILITY_ROOT_DESC"
|
||||
default="main"
|
||||
filter="string"
|
||||
/>
|
||||
<field
|
||||
name="containerIgnore"
|
||||
type="text"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_CONTAINER_IGNORE"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_CONTAINER_IGNORE_DESC"
|
||||
filter="string"
|
||||
/>
|
||||
<field
|
||||
name="shadowComponents"
|
||||
type="text"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_WEB_COMPONENTS"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_WEB_COMPONENTS_DESC"
|
||||
filter="string"
|
||||
/>
|
||||
<field
|
||||
name="extraProps"
|
||||
type="subform"
|
||||
label="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS"
|
||||
description="PLG_SYSTEM_JOOA11Y_FIELD_EXTRA_PROPS_DESC"
|
||||
multiple="true"
|
||||
>
|
||||
<form>
|
||||
<field type="text" name="key" label="PLG_SYSTEM_JOOA11Y_KEY"/>
|
||||
<field type="text" name="value" label="PLG_SYSTEM_JOOA11Y_VALUE"/>
|
||||
</form>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
46
plugins/system/jooa11y/services/provider.php
Normal file
46
plugins/system/jooa11y/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage System.jooa11y
|
||||
*
|
||||
* @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\System\Jooa11y\Extension\Jooa11y;
|
||||
|
||||
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): void
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Jooa11y(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('system', 'jooa11y')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
201
plugins/system/jooa11y/src/Extension/Jooa11y.php
Normal file
201
plugins/system/jooa11y/src/Extension/Jooa11y.php
Normal file
@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage System.jooa11y
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\System\Jooa11y\Extension;
|
||||
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Jooa11y plugin to add an accessibility checker
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
final class Jooa11y extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Subscribe to certain events
|
||||
*
|
||||
* @return string[] An array of event mappings
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return ['onBeforeCompileHead' => 'initJooa11y'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if the current user is allowed to see the debug information or not.
|
||||
*
|
||||
* @return boolean True if access is allowed.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
private function isAuthorisedDisplayChecker(): bool
|
||||
{
|
||||
static $result;
|
||||
|
||||
if (\is_bool($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// If the user is not allowed to view the output then end here.
|
||||
$filterGroups = (array) $this->params->get('filter_groups', []);
|
||||
|
||||
if (!empty($filterGroups)) {
|
||||
$userGroups = $this->getApplication()
|
||||
->getIdentity()
|
||||
->get('groups');
|
||||
|
||||
if (!array_intersect($filterGroups, $userGroups)) {
|
||||
$result = false;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$result = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the checker.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function initJooa11y()
|
||||
{
|
||||
if (!$this->getApplication()->isClient('site')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we are in a preview modal or the plugin has enforced loading
|
||||
$showJooa11y = $this->getApplication()
|
||||
->getInput()
|
||||
->get('jooa11y', $this->params->get('showAlways', 0));
|
||||
|
||||
// Load the checker if authorised
|
||||
if (!$showJooa11y || !$this->isAuthorisedDisplayChecker()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load translations
|
||||
$this->loadLanguage();
|
||||
|
||||
// Detect the current active language
|
||||
$getLang = $this->getApplication()
|
||||
->getLanguage()
|
||||
->getTag();
|
||||
|
||||
// Get the right locale
|
||||
$splitLang = explode('-', $getLang);
|
||||
$lang = $splitLang[0];
|
||||
$country = $splitLang[1] ?? '';
|
||||
|
||||
// Sa11y is available in the following languages
|
||||
$supportedLang = [
|
||||
'bg',
|
||||
'cs',
|
||||
'da',
|
||||
'de',
|
||||
'el',
|
||||
'en',
|
||||
'es',
|
||||
'et',
|
||||
'fi',
|
||||
'fr',
|
||||
'hu',
|
||||
'id',
|
||||
'it',
|
||||
'ja',
|
||||
'ko',
|
||||
'lt',
|
||||
'lv',
|
||||
'nb',
|
||||
'nl',
|
||||
'pl',
|
||||
'pt',
|
||||
'ro',
|
||||
'sl',
|
||||
'sk',
|
||||
'sv',
|
||||
'tr',
|
||||
'uk',
|
||||
'ua',
|
||||
'zh',
|
||||
];
|
||||
|
||||
// Check if Sa11y supports language
|
||||
if (!\in_array($lang, $supportedLang)) {
|
||||
$lang = 'en';
|
||||
} elseif ($lang === 'pt') {
|
||||
$lang = $country === 'BR' ? 'ptBR' : 'ptPT';
|
||||
} elseif ($lang === 'uk') {
|
||||
$lang = 'ua';
|
||||
} elseif ($lang === 'en') {
|
||||
$lang = $country === 'US' ? 'enUS' : 'en';
|
||||
}
|
||||
|
||||
// Get the document object
|
||||
$document = $this->getApplication()->getDocument();
|
||||
|
||||
// Get plugin options from xml
|
||||
$getOptions = [
|
||||
'checkRoot' => $this->params->get('checkRoot', 'main'),
|
||||
'readabilityRoot' => $this->params->get('readabilityRoot', 'main'),
|
||||
'containerIgnore' => $this->params->get('containerIgnore'),
|
||||
'contrastPlugin' => $this->params->get('contrastPlugin', 1),
|
||||
'formLabelsPlugin' => $this->params->get('formLabelsPlugin', 1),
|
||||
'linksAdvancedPlugin' => $this->params->get('linksAdvancedPlugin', 1),
|
||||
'colourFilterPlugin' => $this->params->get('colourFilterPlugin', 1),
|
||||
'checkAllHideToggles' => $this->params->get('additionalChecks', 0),
|
||||
'shadowComponents' => $this->params->get('shadowComponents'),
|
||||
];
|
||||
$getExtraProps = $this->params->get('extraProps', []);
|
||||
|
||||
|
||||
// Process extra props
|
||||
$extraProps = [];
|
||||
foreach ($getExtraProps as $prop) {
|
||||
$decodedValue = json_decode($prop->value);
|
||||
if (is_numeric($decodedValue) || \is_bool($decodedValue)) {
|
||||
$extraProps[$prop->key] = $decodedValue;
|
||||
} else {
|
||||
$extraProps[$prop->key] = "{$prop->value}";
|
||||
}
|
||||
}
|
||||
|
||||
// Merge all options together and add to page
|
||||
$allOptions = array_merge($getOptions, $extraProps);
|
||||
$document->addScriptOptions('jooa11yOptions', $allOptions);
|
||||
|
||||
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa*/
|
||||
$wa = $document->getWebAssetManager();
|
||||
$wa->getRegistry()->addExtensionRegistryFile('plg_system_jooa11y');
|
||||
|
||||
// Load scripts and instantiate
|
||||
$wa->useStyle('sa11y')
|
||||
->useScript('sa11y')
|
||||
->registerAndUseScript(
|
||||
'sa11y-lang',
|
||||
'vendor/sa11y/' . $lang . '.js',
|
||||
['importmap' => true]
|
||||
)
|
||||
->useScript('plg_system_jooa11y.jooa11y');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user