Skip to content

Commit

Permalink
Merge pull request joomla#15 from joomla-projects/blogposting
Browse files Browse the repository at this point in the history
Blogposting Plugin
  • Loading branch information
bembelimen committed Dec 31, 2022
2 parents bdc7acb + 78c903e commit 3053881
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 2 deletions.
3 changes: 2 additions & 1 deletion administrator/components/com_admin/sql/updates/mysql/4.2.3-2022-12-10.sql
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ CREATE TABLE IF NOT EXISTS `#__schemaorg` (

-- Add plugins to `#__extensions`
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_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
3 changes: 2 additions & 1 deletion administrator/components/com_admin/sql/updates/postgresql/4.2.3-2022-12-10.sql
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ CREATE TABLE IF NOT EXISTS "#__schemaorg"

-- Add plugins to "#__extensions"
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_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
21 changes: 21 additions & 0 deletions administrator/language/en-GB/plg_schemaorg_blogposting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PLG_SCHEMAORG_BLOGPOSTING_DESCRIPTION_LABEL="A blog post <a href=\"https://schema.org/BlogPosting\" target=\"_blank\">More information</a>"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_ADDRESS_LABEL="Address"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_AUTHOR_LABEL="Author"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_DATE_MODIFIED_LABEL="Date Modified"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_DATE_PUBLISHED_LABEL="Date Published"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_DESCRIPTION_LABEL="Description"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_EMAIL_LABEL="Email"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_GENERIC_FIELD_LABEL="Generic Field"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_GENERIC_TITLE_LABEL="Title"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_GENERIC_VALUE_LABEL="Value"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_HEADLINE_LABEL="Headline"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_IMAGE_LABEL="Image"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_LOCALITY_LABEL="Locality"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_NAME_LABEL="Name"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_ORGANIZATION_LABEL="Organization"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_PERSON_LABEL="Person"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_POSTAL_CODE_LABEL="Postal Code"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_STREET_ADDRESS_LABEL="Street Address"
PLG_SCHEMAORG_BLOGPOSTING_FIELD_URL_LABEL="Url"
PLG_SCHEMAORG_BLOGPOSTING_XML_DESCRIPTION="Adds Blog as a new schema type in existing schemas"
PLG_SCHEMAORG_BLOGPOSTING="Schema.org Blogposting Plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLG_SCHEMAORG_BLOGPOSTING="Schema.org Blogposting Plugin"
PLG_SCHEMAORG_BLOGPOSTING_XML_DESCRIPTION="Adds Blog as a new schema type in existing schemas"
1 change: 1 addition & 0 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 6, 0),
(0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 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),
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 @@ -332,6 +332,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 6, 0),
(0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 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),
Expand Down
43 changes: 43 additions & 0 deletions plugins/schemaorg/blogposting/blogposting.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_blogposting</name>
<author>Joomla! Project</author>
<creationDate>June 2022</creationDate>
<copyright>(C) 2022 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_BLOGPOSTING_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Schemaorg\Blogposting</namespace>
<files>
<folder plugin="blogposting">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_schemaorg_blogposting.ini</language>
<language tag="en-GB">language/en-GB/plg_schemaorg_blogposting.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>
48 changes: 48 additions & 0 deletions plugins/schemaorg/blogposting/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Schemaorg.blogposting
*
* @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\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Schemaorg\Blogposting\Extension\Blogposting;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.2.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Blogposting(
$dispatcher,
(array) PluginHelper::getPlugin('schemaorg', 'blogposting')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
160 changes: 160 additions & 0 deletions plugins/schemaorg/blogposting/src/Extension/Blogposting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

/**
* @package Joomla.Plugin
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

namespace Joomla\Plugin\Schemaorg\Blogposting\Extension;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Schemaorg\SchemaorgPluginTrait;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\Registry\Registry;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Schemaorg Plugin
*
* @since 4.0.0
*/
final class Blogposting extends CMSPlugin implements SubscriberInterface
{
use SchemaorgPluginTrait;

/**
* @var \Joomla\Database\DatabaseDriver
*
*/
protected $db;

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

/**
* Loads the CMS Application for direct access
*
* @var CMSApplicationInterface
* @since 4.0.0
*/
protected $app;

/**
* The name of the supported name to check against
*
* @var string
* @since 4.0.0
*/
protected $supportFunctionality = 'core.state';

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

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 4.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSchemaPrepareData' => 'onSchemaPrepareData',
'onSchemaPrepareForm' => 'onSchemaPrepareForm',
'onSchemaAfterSave' => 'onSchemaAfterSave',
'onSchemaBeforeCompileHead' => 'pushSchema',
];
}

/**
* Update existing schema form with data from database
*
* @param $data The form to be altered.
*
* @return boolean
*/
public function onSchemaPrepareData(AbstractEvent $event)
{
$context = $event->getArgument('context');
if (!$this->isSupported($context) || !$this->isSchemaSupported($event)) {
return false;
}
$this->updateSchemaForm($event);
return true;
}

/**
* Add a new option to the schema type in the article editing page
*
* @param Form $form The form to be altered.
*
* @return boolean
*/
public function onSchemaPrepareForm(AbstractEvent $event)
{
$form = $event->getArgument('subject');
$context = $form->getName();
if (!$this->isSupported($context)) {
return false;
}
$this->addSchemaType($event);
//Load the form fields
$form->loadFile(JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/src/forms/schemaorg.xml');
return true;
}

/**
* Saves the schema to the database
*
* @param AbstractEvent $event
*
* @return boolean
*/
public function onSchemaAfterSave(AbstractEvent $event)
{
$data = $event->getArgument('data')->toArray();
$form = $data['schema']['schemaType'];

if ($form != $this->pluginName) {
return false;
}
$this->storeSchemaToStandardLocation($event);
return true;
}

/**
* To add plugin specific functions
*
* @param Registry $schema Schema form
*
* @return Registry $schema Updated schema form
*/
public function cleanupIndividualSchema(Registry $schema)
{
if (is_object($schema)) {
$schema = $this->cleanupDate($schema, ['datePublished','dateModified']);
}
return $schema;
}
}
Loading

0 comments on commit 3053881

Please sign in to comment.