primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="schemaorg" method="upgrade">
<name>plg_schemaorg_custom</name>
<author>Joomla! Project</author>
<creationDate>2024-03</creationDate>
<copyright>(C) 2024 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>5.1.0</version>
<description>PLG_SCHEMAORG_CUSTOM_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Schemaorg\Custom</namespace>
<files>
<folder plugin="custom">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_schemaorg_custom.ini</language>
<language tag="en-GB">language/en-GB/plg_schemaorg_custom.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="allowedlist"
type="SchemaorgComponentSections"
label="JSCHEMAORG_EXTENSION_ALLOWED_LABEL"
description="JSCHEMAORG_EXTENSION_ALLOWED_DESCRIPTION"
multiple="multiple"
layout="joomla.form.field.list-fancy-select"
/>
<field
name="forbiddenlist"
type="SchemaorgComponentSections"
label="JSCHEMAORG_EXTENSION_FORBIDDEN_LABEL"
description="JSCHEMAORG_EXTENSION_FORBIDDEN_DESCRIPTION"
multiple="multiple"
layout="joomla.form.field.list-fancy-select"
/>
</fieldset>
</fields>
</config>
</extension>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="schema">
<fieldset
name="schema"
label="PLG_SYSTEM_SCHEMA_FIELD_SCHEMA_LABEL"
>
<field
name="Custom"
type="subform"
showon="schemaType:Custom"
>
<form>
<field
name="@type"
type="hidden"
default="Custom"
/>
<field
name="noteCustom"
type="note"
description="PLG_SCHEMAORG_CUSTOM_DESCRIPTION_LABEL"
class="alert alert-info w-100"
/>
<field
name="json"
type="textarea"
label="PLG_SCHEMAORG_CUSTOM_JSON_FIELD_LABEL"
rows="8"
/>
</form>
</field>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Schemaorg.Custom
*
* @copyright (C) 2024 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\Schemaorg\Custom\Extension\Custom;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 5.1.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new Custom(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('schemaorg', 'custom')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,127 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Schemaorg.Custom
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Schemaorg\Custom\Extension;
use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent;
use Joomla\CMS\Event\Plugin\System\Schemaorg\PrepareSaveEvent;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Schemaorg\SchemaorgPluginTrait;
use Joomla\Event\Priority;
use Joomla\Event\SubscriberInterface;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Schemaorg Plugin
*
* @since 5.1.0
*/
final class Custom extends CMSPlugin implements SubscriberInterface
{
use SchemaorgPluginTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 5.1.0
*/
protected $autoloadLanguage = true;
/**
* The name of the schema form
*
* @var string
* @since 5.1.0
*/
protected $pluginName = 'Custom';
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.1.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSchemaPrepareForm' => 'onSchemaPrepareForm',
'onSchemaBeforeCompileHead' => ['onSchemaBeforeCompileHead', Priority::BELOW_NORMAL],
'onSchemaPrepareSave' => 'onSchemaPrepareSave',
];
}
public function onSchemaPrepareSave(PrepareSaveEvent $event): void
{
$subject = $event->getData();
if (empty($subject->schemaType) || $subject->schemaType !== 'Custom' || !isset($subject->schema)) {
return;
}
try {
$schema = new Registry($subject->schema);
$json = (new Registry($schema->get('json')))->toArray();
} catch (\RuntimeException $e) {
$this->getApplication()->enqueueMessage(Text::_('PLG_SCHEMAORG_CUSTOM_JSON_ERROR'), 'error');
return;
}
if (!isset($json['@context']) || !preg_match('#^https://schema.org/?$#', $json['@context']) || !isset($json['@type'])) {
$this->getApplication()->enqueueMessage(Text::_('PLG_SCHEMAORG_CUSTOM_JSON_ERROR'), 'error');
return;
}
$schema->set('json', json_encode($json, JSON_PRETTY_PRINT));
$subject->schema = $schema->toString();
$event->setArgument('subject', $subject);
}
/**
* Cleanup all Custom types
*
* @param BeforeCompileHeadEvent $event The given event
*
* @return void
*
* @since 5.1.0
*/
public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void
{
$schema = $event->getSchema();
$graph = $schema->get('@graph');
foreach ($graph as $i => $entry) {
if (!isset($entry['@type']) || $entry['@type'] !== 'Custom') {
continue;
}
$json = (new Registry($entry['json']))->toArray();
if (isset($json['@context'])) {
unset($json['@context']);
}
$graph[$i] = $json;
}
$schema->set('@graph', $graph);
}
}