Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8346ffc
First version of generic plugin
bembelimen Oct 4, 2023
93d7ffa
Add plugin to the database
bembelimen Jan 18, 2024
3535b4e
Add translations
bembelimen Jan 18, 2024
81cfb15
Implement output & saving
bembelimen Jan 22, 2024
80c9b8d
Add some spacing nd ordering
bembelimen Jan 22, 2024
816823c
Code style
bembelimen Jan 23, 2024
03a8d60
Apply suggestions from code review
bembelimen Jan 23, 2024
b4eeabd
Update administrator/language/en-GB/plg_schemaorg_generic.ini
bembelimen Jan 23, 2024
3c17c17
Rename schemaorg Generic to Custom
bembelimen Jan 23, 2024
4f52bea
Merge branch '5.1-dev' into schemaorg/generic-plugin-type
bembelimen Jan 23, 2024
05d1f73
Add plugin to core extensions
bembelimen Jan 23, 2024
94ad3ca
Merge branch 'schemaorg/generic-plugin-type' of github.com:bembelimen…
bembelimen Jan 23, 2024
bdc054c
Apply suggestions from code review
bembelimen Jan 23, 2024
1b92f9d
Rename generic to custom in language file
bembelimen Jan 23, 2024
c35db76
Fix language constants
bembelimen Jan 23, 2024
13737cb
Cleanup language strings
bembelimen Jan 23, 2024
a1ae93d
Code style
bembelimen Jan 24, 2024
271bc54
Update administrator/language/en-GB/plg_schemaorg_custom.ini
bembelimen Jan 25, 2024
133e9ae
Apply suggestions from code review
bembelimen Feb 5, 2024
ef57b03
Merge branch '5.1-dev' into schemaorg/generic-plugin-type
bembelimen Feb 5, 2024
5233f25
Merge branch '5.1-dev' into schemaorg/generic-plugin-type
LadySolveig Feb 11, 2024
9e72b02
Update schemaorg.xml
bembelimen Feb 14, 2024
53793d0
Update plg_schemaorg_custom.ini
bembelimen Feb 14, 2024
9182a05
Merge branch '5.1-dev' into schemaorg/generic-plugin-type
LadySolveig Feb 24, 2024
2d03bbb
Rename 5.1.0-2024-01-18.sql to 5.1.0-2024-02-25.sql
bembelimen Feb 24, 2024
e9d4468
Rename 5.1.0-2024-01-18.sql to 5.1.0-2024-02-25.sql
bembelimen Feb 24, 2024
600d3b7
Merge branch '5.1-dev' into schemaorg/generic-plugin-type
richard67 Feb 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
(0, 'plg_schemaorg_custom', 'plugin', 'custom', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
(0, 'plg_schemaorg_custom', 'plugin', 'custom', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
10 changes: 10 additions & 0 deletions administrator/language/en-GB/plg_schemaorg_custom.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; Joomla! Project
; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SCHEMAORG_CUSTOM="Schema.org - Custom"
PLG_SCHEMAORG_CUSTOM_XML_DESCRIPTION="Adds a custom field to add any schema type."
PLG_SCHEMAORG_CUSTOM_DESCRIPTION_LABEL="Use any JSON-LD code here to add currently unsupported schema types."
PLG_SCHEMAORG_CUSTOM_JSON_ERROR="The JSON code is not valid or @context or @type is missing."
PLG_SCHEMAORG_CUSTOM_JSON_FIELD_LABEL="JSON Code"
8 changes: 8 additions & 0 deletions administrator/language/en-GB/plg_schemaorg_custom.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Joomla! Project
; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>

; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SCHEMAORG_CUSTOM="Schema.org - Custom"
PLG_SCHEMAORG_CUSTOM_XML_DESCRIPTION="Adds a custom field to add any schema type."
1 change: 1 addition & 0 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0),
(0, 'plg_schemaorg_custom', 'plugin', 'custom', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 9, 0),
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
(0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
(0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0),
(0, 'plg_schemaorg_custom', 'plugin', 'custom', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 9, 0),
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
(0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
(0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),
Expand Down
1 change: 1 addition & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class ExtensionHelper
['plugin', 'article', 'schemaorg', 0],
['plugin', 'blogposting', 'schemaorg', 0],
['plugin', 'book', 'schemaorg', 0],
['plugin', 'custom', 'schemaorg', 0],
['plugin', 'event', 'schemaorg', 0],
['plugin', 'jobposting', 'schemaorg', 0],
['plugin', 'organization', 'schemaorg', 0],
Expand Down
43 changes: 43 additions & 0 deletions plugins/schemaorg/custom/custom.xml
Original file line number Diff line number Diff line change
@@ -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-01</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>__DEPLOY_VERSION__</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>
39 changes: 39 additions & 0 deletions plugins/schemaorg/custom/forms/schemaorg.xml
Original file line number Diff line number Diff line change
@@ -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>
48 changes: 48 additions & 0 deletions plugins/schemaorg/custom/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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 __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Custom(
$dispatcher,
(array) PluginHelper::getPlugin('schemaorg', 'custom')
);

$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
127 changes: 127 additions & 0 deletions plugins/schemaorg/custom/src/Extension/Custom.php
Original file line number Diff line number Diff line change
@@ -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 __DEPLOY_VERSION__
*/
final class Custom extends CMSPlugin implements SubscriberInterface
{
use SchemaorgPluginTrait;

/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* The name of the schema form
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $pluginName = 'Custom';

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
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 __DEPLOY_VERSION__
*/
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);
}
}