Skip to content

Commit

Permalink
Merge branch 'release/3.3.45' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jul 20, 2021
2 parents 29bf7a5 + 23c15ca commit b26f859
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# SEOmatic Changelog

## 3.3.45 - 2021.07.20
### Fixed
* Fixed an issue where `MedicalBusiness` JSON-LD type didn't inherit all of the properties from `MedicalOrganization` that it should
* Handle per-entry type settings for the sitemap generation (https://github.com/nystudio107/craft-seomatic/issues/929)

## 3.3.44 - 2021.07.09
### Added
* Added `truncateTitleTags` & `truncateDescriptionTags` settings to control whether the max title / description lengths should be enforced or not (on by default) (https://github.com/nystudio107/craft-seomatic/issues/922)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-seomatic",
"description": "SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.",
"type": "craft-plugin",
"version": "3.3.44",
"version": "3.3.45",
"keywords": [
"craft",
"cms",
Expand Down
48 changes: 45 additions & 3 deletions src/jobs/GenerateSitemap.php
Expand Up @@ -11,6 +11,7 @@

namespace nystudio107\seomatic\jobs;

use nystudio107\seomatic\base\SeoElementInterface;
use nystudio107\seomatic\fields\SeoSettings;
use nystudio107\seomatic\models\MetaBundle;
use nystudio107\seomatic\Seomatic;
Expand All @@ -27,7 +28,6 @@
use craft\console\Application as ConsoleApplication;
use craft\db\Paginator;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\elements\MatrixBlock;
use craft\fields\Assets as AssetsField;
use craft\models\SiteGroup;
Expand Down Expand Up @@ -111,8 +111,8 @@ public function execute($queue)
$this->handle,
$this->siteId
);
// If it's disabled, just exit
if ($metaBundle === null || !$metaBundle->metaSitemapVars->sitemapUrls) {
// If it doesn't exist, exit
if ($metaBundle === null) {
return;
}
$multiSite = \count($metaBundle->sourceAltSiteSettings) > 1;
Expand Down Expand Up @@ -171,6 +171,8 @@ public function execute($queue)
}
$metaBundle->metaSitemapVars->setAttributes($stashedSitemapAttrs, false);
$metaBundle->metaGlobalVars->setAttributes($stashedGlobalVarsAttrs, false);
// Combine in any per-entry type settings
$this->combineEntryTypeSettings($seoElement, $element, $metaBundle);
// Make sure this entry isn't disabled
$this->combineFieldSettings($element, $metaBundle);
// Special case for the __home__ URI
Expand Down Expand Up @@ -388,6 +390,46 @@ protected function defaultDescription(): string
// Protected Methods
// =========================================================================

/**
* Combine any per-entry type field settings from $element with the passed in
* $metaBundle
*
* @param SeoElementInterface|string $seoElement
* @param Element $element
* @param MetaBundle $metaBundle
*/
protected function combineEntryTypeSettings($seoElement, Element $element, MetaBundle $metaBundle)
{
if (!empty($seoElement::typeMenuFromHandle($metaBundle->sourceHandle))) {
list($sourceId, $sourceBundleType, $sourceHandle, $sourceSiteId, $typeId)
= Seomatic::$plugin->metaBundles->getMetaSourceFromElement($element);
$entryTypeBundle = Seomatic::$plugin->metaBundles->getMetaBundleBySourceId(
$sourceBundleType,
$sourceId,
$sourceSiteId,
$typeId
);
// Combine in any settings for this entry type
if ($entryTypeBundle) {
// Combine the meta sitemap vars
$attributes = $entryTypeBundle->metaSitemapVars->getAttributes();
$attributes = array_filter(
$attributes,
[ArrayHelper::class, 'preserveBools']
);
$metaBundle->metaSitemapVars->setAttributes($attributes, false);

// Combine the meta global vars
$attributes = $entryTypeBundle->metaGlobalVars->getAttributes();
$attributes = array_filter(
$attributes,
[ArrayHelper::class, 'preserveBools']
);
$metaBundle->metaGlobalVars->setAttributes($attributes, false);
}
}
}

/**
* Combine any SEO Settings field settings from $element with the passed in
* $metaBundle
Expand Down
7 changes: 6 additions & 1 deletion src/models/SitemapIndexTemplate.php
Expand Up @@ -152,15 +152,20 @@ public function render(array $params = []): string
Seomatic::$plugin->metaBundles->pruneVestigialMetaBundles($metaBundles);
/** @var $metaBundle MetaBundle */
foreach ($metaBundles as $metaBundle) {
$sitemapUrls = $metaBundle->metaSitemapVars->sitemapUrls;
// Check to see if robots is `none` or `no index`
$robotsEnabled = true;
if (!empty($metaBundle->metaGlobalVars->robots)) {
$robotsEnabled = $metaBundle->metaGlobalVars->robots !== 'none' &&
$metaBundle->metaGlobalVars->robots !== 'noindex';
}
if (Seomatic::$plugin->sitemaps->anyEntryTypeHasSitemapUrls($metaBundle)) {
$robotsEnabled = true;
$sitemapUrls = true;
}
// Only add in a sitemap entry if it meets our criteria
if (\in_array($metaBundle->sourceSiteId, $groupSiteIds, false)
&& $metaBundle->metaSitemapVars->sitemapUrls
&& $sitemapUrls
&& $robotsEnabled) {
$sitemapUrl = Seomatic::$plugin->sitemaps->sitemapUrlForBundle(
$metaBundle->sourceBundleType,
Expand Down
17 changes: 16 additions & 1 deletion src/models/SitemapTemplate.php
Expand Up @@ -109,8 +109,23 @@ public function render(array $params = []): string
$siteId = $params['siteId'];

$metaBundle = Seomatic::$plugin->metaBundles->getMetaBundleBySourceHandle($type, $handle, $siteId);
// If it doesn't exist, throw a 404
if ($metaBundle === null ) {
throw new NotFoundHttpException(Craft::t('seomatic', 'Page not found.'));
}
// Check to see if robots is `none` or `no index`
$robotsEnabled = true;
if (!empty($metaBundle->metaGlobalVars->robots)) {
$robotsEnabled = $metaBundle->metaGlobalVars->robots !== 'none' &&
$metaBundle->metaGlobalVars->robots !== 'noindex';
}
$sitemapUrls = $metaBundle->metaSitemapVars->sitemapUrls;
if (Seomatic::$plugin->sitemaps->anyEntryTypeHasSitemapUrls($metaBundle)) {
$robotsEnabled = true;
$sitemapUrls = true;
}
// If it's disabled, just throw a 404
if ($metaBundle === null || !$metaBundle->metaSitemapVars->sitemapUrls) {
if (!$sitemapUrls || !$robotsEnabled) {
throw new NotFoundHttpException(Craft::t('seomatic', 'Page not found.'));
}

Expand Down
43 changes: 39 additions & 4 deletions src/models/jsonld/MedicalBusiness.php
Expand Up @@ -91,7 +91,7 @@ class MedicalBusiness extends LocalBusiness
*/
static public $googleRecommendedSchema = [];

// Public Properties
// Public Properties from Self
// =========================================================================

/**
Expand Down Expand Up @@ -134,6 +134,31 @@ class MedicalBusiness extends LocalBusiness
*/
public $priceRange;

// Public Properties from MedicalOrganization
// =========================================================================

/**
* Name or unique ID of network. (Networks are often reused across different
* insurance plans).
*
* @var string [schema.org types: Text]
*/
public $healthPlanNetworkId;

/**
* Whether the provider is accepting new patients.
*
* @var bool [schema.org types: Boolean]
*/
public $isAcceptingNewPatients;

/**
* A medical specialty of the provider.
*
* @var MedicalSpecialty [schema.org types: MedicalSpecialty]
*/
public $medicalSpecialty;

// Static Protected Properties
// =========================================================================

Expand All @@ -146,7 +171,10 @@ class MedicalBusiness extends LocalBusiness
'currenciesAccepted',
'openingHours',
'paymentAccepted',
'priceRange'
'priceRange',
'healthPlanNetworkId',
'isAcceptingNewPatients',
'medicalSpecialty'
];

/**
Expand All @@ -158,7 +186,10 @@ class MedicalBusiness extends LocalBusiness
'currenciesAccepted' => ['Text'],
'openingHours' => ['Text'],
'paymentAccepted' => ['Text'],
'priceRange' => ['Text']
'priceRange' => ['Text'],
'healthPlanNetworkId' => ['Text'],
'isAcceptingNewPatients' => ['Boolean'],
'medicalSpecialty' => ['MedicalSpecialty']
];

/**
Expand All @@ -170,7 +201,10 @@ class MedicalBusiness extends LocalBusiness
'currenciesAccepted' => 'The currency accepted. Use standard formats: ISO 4217 currency format e.g. "USD"; Ticker symbol for cryptocurrencies e.g. "BTC"; well known names for Local Exchange Tradings Systems (LETS) and other currency types e.g. "Ithaca HOUR".',
'openingHours' => 'The general opening hours for a business. Opening hours can be specified as a weekly time range, starting with days, then times per day. Multiple days can be listed with commas \',\' separating each day. Day or time ranges are specified using a hyphen \'-\'. Days are specified using the following two-letter combinations: Mo, Tu, We, Th, Fr, Sa, Su. Times are specified using 24:00 time. For example, 3pm is specified as 15:00. Here is an example: <time itemprop="openingHours" datetime="Tu,Th 16:00-20:00">Tuesdays and Thursdays 4-8pm</time>. If a business is open 7 days a week, then it can be specified as <time itemprop="openingHours" datetime="Mo-Su">Monday through Sunday, all day</time>.',
'paymentAccepted' => 'Cash, Credit Card, Cryptocurrency, Local Exchange Tradings System, etc.',
'priceRange' => 'The price range of the business, for example $$$.'
'priceRange' => 'The price range of the business, for example $$$.',
'healthPlanNetworkId' => 'Name or unique ID of network. (Networks are often reused across different insurance plans).',
'isAcceptingNewPatients' => 'Whether the provider is accepting new patients.',
'medicalSpecialty' => 'A medical specialty of the provider.'
];

/**
Expand Down Expand Up @@ -232,6 +266,7 @@ public function rules()
$rules = parent::rules();
$rules = array_merge($rules, [
[['currenciesAccepted','openingHours','paymentAccepted','priceRange'], 'validateJsonSchema'],
[['healthPlanNetworkId','isAcceptingNewPatients','medicalSpecialty'], 'validateJsonSchema'],
[self::$_googleRequiredSchema, 'required', 'on' => ['google'], 'message' => 'This property is required by Google.'],
[self::$_googleRecommendedSchema, 'required', 'on' => ['google'], 'message' => 'This property is recommended by Google.']
]);
Expand Down
20 changes: 8 additions & 12 deletions src/services/MetaBundles.php
Expand Up @@ -212,9 +212,10 @@ public function updateMetaBundle(MetaBundle $metaBundle, int $siteId)
public function getMetaBundleBySourceId(string $sourceBundleType, int $sourceId, int $sourceSiteId, $typeId = null)
{
$metaBundle = null;
$typeId = (int)$typeId;
// See if we have the meta bundle cached
if (!empty($this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId])) {
$id = $this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId];
if (!empty($this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId][$typeId])) {
$id = $this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId][$typeId];
if (!empty($this->metaBundles[$id])) {
return $this->metaBundles[$id];
}
Expand All @@ -228,9 +229,6 @@ public function getMetaBundleBySourceId(string $sourceBundleType, int $sourceId,
'sourceSiteId' => $sourceSiteId,
])
;
if ($typeId !== null) {
$typeId = (int)$typeId;
}
if (!empty($typeId)) {
$query
->andWhere([
Expand All @@ -257,7 +255,7 @@ public function getMetaBundleBySourceId(string $sourceBundleType, int $sourceId,
$this->syncBundleWithConfig($metaBundle);
$id = count($this->metaBundles);
$this->metaBundles[$id] = $metaBundle;
$this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId] = $id;
$this->metaBundlesBySourceId[$sourceBundleType][$sourceId][$sourceSiteId][$typeId] = $id;
} else {
// If it doesn't exist, create it
$seoElement = Seomatic::$plugin->seoElements->getSeoElementByMetaBundleType($sourceBundleType);
Expand All @@ -283,9 +281,10 @@ public function getMetaBundleBySourceId(string $sourceBundleType, int $sourceId,
public function getMetaBundleBySourceHandle(string $sourceBundleType, string $sourceHandle, int $sourceSiteId, $typeId = null)
{
$metaBundle = null;
$typeId = (int)$typeId;
// See if we have the meta bundle cached
if (!empty($this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId])) {
$id = $this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId];
if (!empty($this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId][$typeId])) {
$id = $this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId][$typeId];
if (!empty($this->metaBundles[$id])) {
return $this->metaBundles[$id];
}
Expand All @@ -299,9 +298,6 @@ public function getMetaBundleBySourceHandle(string $sourceBundleType, string $so
'sourceSiteId' => $sourceSiteId,
])
;
if ($typeId !== null) {
$typeId = (int)$typeId;
}
if (!empty($typeId)) {
$query
->andWhere([
Expand All @@ -326,7 +322,7 @@ public function getMetaBundleBySourceHandle(string $sourceBundleType, string $so
$metaBundle = MetaBundle::create($metaBundleArray);
$id = count($this->metaBundles);
$this->metaBundles[$id] = $metaBundle;
$this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId] = $id;
$this->metaBundlesBySourceHandle[$sourceBundleType][$sourceHandle][$sourceSiteId][$typeId] = $id;
} else {
// If it doesn't exist, create it
$seoElement = Seomatic::$plugin->seoElements->getSeoElementByMetaBundleType($sourceBundleType);
Expand Down
42 changes: 42 additions & 0 deletions src/services/Sitemaps.php
Expand Up @@ -12,6 +12,7 @@
namespace nystudio107\seomatic\services;

use nystudio107\seomatic\jobs\GenerateSitemap;
use nystudio107\seomatic\models\MetaBundle;
use nystudio107\seomatic\Seomatic;
use nystudio107\seomatic\base\FrontendTemplate;
use nystudio107\seomatic\base\SitemapInterface;
Expand Down Expand Up @@ -172,6 +173,47 @@ public function sitemapRouteRules(): array
return $rules;
}

/**
* See if any of the entry types have robots enable and sitemap urls enabled
*
* @param MetaBundle $metaBundle
* @return bool
*/
public function anyEntryTypeHasSitemapUrls(MetaBundle $metaBundle): bool
{
$result = false;
$seoElement = Seomatic::$plugin->seoElements->getSeoElementByMetaBundleType($metaBundle->sourceBundleType);
if ($seoElement) {
if (!empty($seoElement::typeMenuFromHandle($metaBundle->sourceHandle))) {
$section = $seoElement::sourceModelFromHandle($metaBundle->sourceHandle);
if ($section !== null) {
$entryTypes = $section->getEntryTypes();
// Fetch each meta bundle for each entry type to see if _any_ of them have sitemap URLs
foreach ($entryTypes as $entryType) {
$entryTypeBundle = Seomatic::$plugin->metaBundles->getMetaBundleBySourceId(
$metaBundle->sourceBundleType,
$metaBundle->sourceId,
$metaBundle->sourceSiteId,
$entryType->id
);
if ($entryTypeBundle) {
$robotsEnabled = true;
if (!empty($entryTypeBundle->metaGlobalVars->robots)) {
$robotsEnabled = $entryTypeBundle->metaGlobalVars->robots !== 'none' &&
$entryTypeBundle->metaGlobalVars->robots !== 'noindex';
}
if ($entryTypeBundle->metaSitemapVars->sitemapUrls && $robotsEnabled) {
$result = true;
}
}
}
}
}
}

return $result;
}

/**
* @param string $template
* @param array $params
Expand Down

0 comments on commit b26f859

Please sign in to comment.