- md5
- 6325c06b011956ac37eff2e47514f71f
- sha1
- ea0747896d13f9d5d1d7e4b2308c4f5cb6b3b008
- sha256
- 0b6bfd5e7ba23ce24fc631d88d69f095918ca219ebef91106ee119fde2f0610d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
<?php
/**
* @package Joomla.Plugin
* @subpackage Schemaorg.jobposting
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Schemaorg\JobPosting\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\Event\Priority;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Schemaorg Plugin
*
* @since 5.0.0
*/
final class JobPosting extends CMSPlugin implements SubscriberInterface
{
use SchemaorgPluginTrait;
use SchemaorgPrepareDateTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* The name of the schema form
*
* @var string
* @since 5.0.0
*/
protected $pluginName = 'JobPosting';
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSchemaPrepareForm' => 'onSchemaPrepareForm',
'onSchemaBeforeCompileHead' => ['onSchemaBeforeCompileHead', Priority::BELOW_NORMAL],
];
}
/**
* Cleanup all JobPosting types
*
* @param BeforeCompileHeadEvent $event The given event
*
* @return void
*
* @since 5.0.0
*/
public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event)
{
$schema = $event->getSchema();
$graph = $schema->get('@graph');
foreach ($graph as &$entry) {
if (!isset($entry['@type']) || $entry['@type'] !== 'JobPosting') {
continue;
}
if (!empty($entry['datePosted'])) {
$entry['datePosted'] = $this->prepareDate($entry['datePosted']);
}
if (!empty($entry['validThrough'])) {
$entry['validThrough'] = $this->prepareDate($entry['validThrough']);
}
/**
* Search engines only accept TELECOMMUTE as jobLocationType. A remote job is
* marked TELECOMMUTE, a hybrid job is marked TELECOMMUTE combined with the
* physical jobLocation and an on-site job must not emit a jobLocationType at
* all and relies on jobLocation alone.
*/
switch ($entry['jobLocationType'] ?? '') {
case 'Telecommute':
case 'Hybrid':
$entry['jobLocationType'] = 'TELECOMMUTE';
break;
case 'Onsite':
unset($entry['jobLocationType']);
break;
}
}
$schema->set('@graph', $graph);
}
}
The same content is in 12 releases, Joomla 5.4.9-rc1 to 6.2.1-rc1. See them all, or every version of this file.