forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request joomla#15 from joomla-projects/blogposting
Blogposting Plugin
- Loading branch information
Showing
10 changed files
with
480 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
administrator/language/en-GB/plg_schemaorg_blogposting.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
2 changes: 2 additions & 0 deletions
2
administrator/language/en-GB/plg_schemaorg_blogposting.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
160
plugins/schemaorg/blogposting/src/Extension/Blogposting.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.