diff --git a/administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-01-25.sql b/administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-01-25.sql new file mode 100644 index 0000000000000..6cf7227290406 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-01-25.sql @@ -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_product', 'plugin', 'product', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0); diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-01-25.sql b/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-01-25.sql new file mode 100644 index 0000000000000..9d04e475260c2 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-01-25.sql @@ -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_product', 'plugin', 'product', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0); diff --git a/administrator/language/en-GB/plg_schemaorg_product.ini b/administrator/language/en-GB/plg_schemaorg_product.ini new file mode 100644 index 0000000000000..c7566e2b05234 --- /dev/null +++ b/administrator/language/en-GB/plg_schemaorg_product.ini @@ -0,0 +1,39 @@ +; Joomla! Project +; (C) 2024 Open Source Matters, Inc. +; 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_PRODUCT="Schema.org - Product" +PLG_SCHEMAORG_PRODUCT_DESCRIPTION_LABEL="More information on the Schema.org Product Type can be found at https://schema.org/Product" +PLG_SCHEMAORG_PRODUCT_FIELD_ADDRESS_LABEL="Address" +PLG_SCHEMAORG_PRODUCT_FIELD_BRAND_LABEL="Brand" +PLG_SCHEMAORG_PRODUCT_FIELD_CATEGORY_LABEL="Category" +PLG_SCHEMAORG_PRODUCT_FIELD_COLOR_LABEL="Color" +PLG_SCHEMAORG_PRODUCT_FIELD_CURRENCY_LABEL="Currency" +PLG_SCHEMAORG_PRODUCT_FIELD_DATE_PRODUCTION_LABEL="Date Produced" +PLG_SCHEMAORG_PRODUCT_FIELD_DATE_RELEASE_LABEL="Date Released" +PLG_SCHEMAORG_PRODUCT_FIELD_DEPTH_LABEL="Depth" +PLG_SCHEMAORG_PRODUCT_FIELD_DESCRIPTION_LABEL="Description" +PLG_SCHEMAORG_PRODUCT_FIELD_EMAIL_LABEL="Email" +PLG_SCHEMAORG_PRODUCT_FIELD_GENERIC_FIELD_LABEL="Generic Field" +PLG_SCHEMAORG_PRODUCT_FIELD_GENERIC_TITLE_LABEL="Title" +PLG_SCHEMAORG_PRODUCT_FIELD_GENERIC_VALUE_LABEL="Value" +PLG_SCHEMAORG_PRODUCT_FIELD_HEIGHT_LABEL="Height" +PLG_SCHEMAORG_PRODUCT_FIELD_IMAGE_LABEL="Image" +PLG_SCHEMAORG_PRODUCT_FIELD_LOCALITY_LABEL="Locality" +PLG_SCHEMAORG_PRODUCT_FIELD_LOGO_LABEL="Logo" +PLG_SCHEMAORG_PRODUCT_FIELD_MANUFACTURER_LABEL="Manufacturer" +PLG_SCHEMAORG_PRODUCT_FIELD_MATERIAL_LABEL="Material" +PLG_SCHEMAORG_PRODUCT_FIELD_MODEL_LABEL="Model" +PLG_SCHEMAORG_PRODUCT_FIELD_NAME_LABEL="Name" +PLG_SCHEMAORG_PRODUCT_FIELD_OFFERS_LABEL="Price" +PLG_SCHEMAORG_PRODUCT_FIELD_ORGANIZATION_LABEL="Organization" +PLG_SCHEMAORG_PRODUCT_FIELD_POSTAL_CODE_LABEL="Postal Code" +PLG_SCHEMAORG_PRODUCT_FIELD_SIZE_LABEL="Size" +PLG_SCHEMAORG_PRODUCT_FIELD_SKU_LABEL="SKU" +PLG_SCHEMAORG_PRODUCT_FIELD_STREET_ADDRESS_LABEL="Street Address" +PLG_SCHEMAORG_PRODUCT_FIELD_TYPE_LABEL="Type" +PLG_SCHEMAORG_PRODUCT_FIELD_URL_LABEL="Url" +PLG_SCHEMAORG_PRODUCT_FIELD_VALUE_LABEL="Value" +PLG_SCHEMAORG_PRODUCT_FIELD_WIDTH_LABEL="Width" +PLG_SCHEMAORG_PRODUCT_XML_DESCRIPTION="Adds Product as a new schema type in existing schemas." diff --git a/administrator/language/en-GB/plg_schemaorg_product.sys.ini b/administrator/language/en-GB/plg_schemaorg_product.sys.ini new file mode 100644 index 0000000000000..a36dff24f861b --- /dev/null +++ b/administrator/language/en-GB/plg_schemaorg_product.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; (C) 2024 Open Source Matters, Inc. +; 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_PRODUCT="Schema.org - Product" +PLG_SCHEMAORG_PRODUCT_XML_DESCRIPTION="Adds Product as a new schema type in existing schemas." diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index c34c49dd41e0a..b3a659be88858 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -340,7 +340,8 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0), (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_product', 'plugin', 'product', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0), +(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', '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), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index 435afc0ee2112..7db6e70e69305 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -346,7 +346,8 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0), (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_product', 'plugin', 'product', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0), +(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', '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), diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index f74d6bed987e9..48a35dfb5615b 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -284,6 +284,7 @@ class ExtensionHelper ['plugin', 'jobposting', 'schemaorg', 0], ['plugin', 'organization', 'schemaorg', 0], ['plugin', 'person', 'schemaorg', 0], + ['plugin', 'product', 'schemaorg', 0], ['plugin', 'recipe', 'schemaorg', 0], // Core plugin extensions - system diff --git a/plugins/schemaorg/product/forms/schemaorg.xml b/plugins/schemaorg/product/forms/schemaorg.xml new file mode 100644 index 0000000000000..92c33d1ee2610 --- /dev/null +++ b/plugins/schemaorg/product/forms/schemaorg.xml @@ -0,0 +1,435 @@ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + + +
+
+
+ diff --git a/plugins/schemaorg/product/product.xml b/plugins/schemaorg/product/product.xml new file mode 100644 index 0000000000000..e83aa258b09e6 --- /dev/null +++ b/plugins/schemaorg/product/product.xml @@ -0,0 +1,43 @@ + + + plg_schemaorg_product + Joomla! Project + 2024-01 + (C) 2024 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + __DEPLOY_VERSION__ + PLG_SCHEMAORG_PRODUCT_XML_DESCRIPTION + Joomla\Plugin\Schemaorg\Product + + services + src + + + language/en-GB/plg_schemaorg_product.ini + language/en-GB/plg_schemaorg_product.sys.ini + + + +
+ + +
+
+
+
diff --git a/plugins/schemaorg/product/services/provider.php b/plugins/schemaorg/product/services/provider.php new file mode 100644 index 0000000000000..acff2dc6f8773 --- /dev/null +++ b/plugins/schemaorg/product/services/provider.php @@ -0,0 +1,47 @@ + + * @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\Product\Extension\Product; + +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 Product( + $dispatcher, + (array) PluginHelper::getPlugin('schemaorg', 'product') + ); + $plugin->setApplication(Factory::getApplication()); + + return $plugin; + } + ); + } +}; diff --git a/plugins/schemaorg/product/src/Extension/Product.php b/plugins/schemaorg/product/src/Extension/Product.php new file mode 100644 index 0000000000000..53ad8d3d31049 --- /dev/null +++ b/plugins/schemaorg/product/src/Extension/Product.php @@ -0,0 +1,102 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Plugin\Schemaorg\Product\Extension; + +use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Schemaorg\SchemaorgPluginTrait; +use Joomla\CMS\Schemaorg\SchemaorgPrepareDateTrait; +use Joomla\CMS\Schemaorg\SchemaorgPrepareImageTrait; +use Joomla\Event\Priority; +use Joomla\Event\SubscriberInterface; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Schemaorg Plugin + * + * @since __DEPLOY_VERSION__ + */ +final class Product extends CMSPlugin implements SubscriberInterface +{ + use SchemaorgPluginTrait; + use SchemaorgPrepareDateTrait; + use SchemaorgPrepareImageTrait; + + /** + * 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 = 'Product'; + + /** + * 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], + ]; + } + + /** + * Cleanup all Product 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 &$entry) { + if (!isset($entry['@type']) || $entry['@type'] !== 'Product') { + continue; + } + + if (!empty($entry['productionDate'])) { + $entry['productionDate'] = $this->prepareDate($entry['productionDate']); + } + + if (!empty($entry['releaseDate'])) { + $entry['releaseDate'] = $this->prepareDate($entry['releaseDate']); + } + + if (!empty($entry['image'])) { + $entry['image'] = $this->prepareImage($entry['image']); + } + } + + $schema->set('@graph', $graph); + } +}