Skip to content

Commit

Permalink
Merge branch 'release/3.3.42' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed May 18, 2021
2 parents d013074 + cf43ea0 commit cec9a38
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 38 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# SEOmatic Changelog

## 3.3.42 - 2021.05.18
### Changed
* Strip the query params from next/prev pagination meta tags if we're not using query-string based pagination (https://github.com/nystudio107/craft-seomatic/issues/896)
* Ensure that frontend templates are checked first, so things like `humans.twig` and `robots.twig` can be overridden (https://github.com/nystudio107/craft-seomatic/issues/891)

### Fixed
* If sitemaps aren't enabled globally, return nothing for the sitemap index (https://github.com/nystudio107/craft-seomatic/issues/895)
* Fixed an issue where an empty transform mode could cause errors generating social image transforms (https://github.com/nystudio107/craft-seomatic/issues/892)

## 3.3.41 - 2021.05.06
### Added
* Only add a sitemap to the sitemap index if there's at least 1 element in the resulting sitemap (https://github.com/nystudio107/craft-seomatic/issues/873)
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.41",
"version": "3.3.42",
"keywords": [
"craft",
"cms",
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/DynamicMeta.php
Expand Up @@ -113,8 +113,19 @@ public static function paginate(Paginate $pageInfo)
$canonical->href = $url;
}
}
// See if we should strip the query params
$stripQueryParams = true;
$pageTrigger = Craft::$app->getConfig()->getGeneral()->pageTrigger;
// Is this query string-based pagination?
if ($pageTrigger[0] === '?') {
$stripQueryParams = false;
}

// Set the previous URL
$url = $pageInfo->getPrevUrl();
if ($stripQueryParams) {
$url = preg_replace('/\?.*/', '', $url);
}
if (!empty($url)) {
$metaTag = Seomatic::$plugin->link->create([
'rel' => 'prev',
Expand All @@ -123,6 +134,9 @@ public static function paginate(Paginate $pageInfo)
}
// Set the next URL
$url = $pageInfo->getNextUrl();
if ($stripQueryParams) {
$url = preg_replace('/\?.*/', '', $url);
}
if (!empty($url)) {
$metaTag = Seomatic::$plugin->link->create([
'rel' => 'next',
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/ImageTransform.php
Expand Up @@ -100,6 +100,9 @@ public static function socialTransform(
$url = '';
$transform = self::createSocialTransform($transformName);
// Let them override the mode
if (empty($transformMode)) {
$transformMode = $transform->mode ?? 'crop';
}
if ($transform !== null) {
$transform->mode = $transformMode ?? $transform->mode;
}
Expand Down
63 changes: 32 additions & 31 deletions src/helpers/PluginTemplate.php
Expand Up @@ -13,9 +13,12 @@

use nystudio107\seomatic\Seomatic;

use nystudio107\minify\Minify;

use Craft;
use craft\helpers\Template;
use craft\web\View;

use yii\base\Exception;

/**
Expand All @@ -25,6 +28,11 @@
*/
class PluginTemplate
{
// Constants
// =========================================================================

const MINIFY_PLUGIN_HANDLE = 'minify';

// Static Methods
// =========================================================================

Expand All @@ -47,55 +55,48 @@ public static function renderStringTemplate(string $templateString, array $param
/**
* Render a plugin template
*
* @param $templatePath
* @param $params
* @param string $templatePath
* @param array $params
* @param string|null $minifier
*
* @return string
*/
public static function renderPluginTemplate(string $templatePath, array $params = []): string
{
// Stash the old template mode, and set it Control Panel template mode
public static function renderPluginTemplate(
string $templatePath,
array $params = [],
string $minifier = null
): string {
$template = 'seomatic/' . $templatePath;
$oldMode = Craft::$app->view->getTemplateMode();
// Look for the template on the frontend first
try {
Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_CP);
$templateMode = View::TEMPLATE_MODE_CP;
if (Craft::$app->view->doesTemplateExist($template, View::TEMPLATE_MODE_SITE)) {
$templateMode = View::TEMPLATE_MODE_SITE;
}
Craft::$app->view->setTemplateMode($templateMode);
} catch (Exception $e) {
Craft::error($e->getMessage(), __METHOD__);
}

// Render the template with our vars passed in
try {
$htmlText = Craft::$app->view->renderTemplate('seomatic/' . $templatePath, $params);
$templateRendered = true;
$htmlText = Craft::$app->view->renderTemplate($template, $params);
if ($minifier) {
// If Minify is installed, use it to minify the template
$minify = Craft::$app->getPlugins()->getPlugin(self::MINIFY_PLUGIN_HANDLE);
if ($minify) {
$htmlText = Minify::$plugin->minify->$minifier($htmlText);
}

}
} catch (\Exception $e) {
$htmlText = Craft::t(
'seomatic',
'Error rendering `{template}` -> {error}',
['template' => $templatePath, 'error' => $e->getMessage()]
);
Craft::error($htmlText, __METHOD__);
$templateRendered = false;
}

// If we couldn't find a plugin template, look for a frontend template
if (!$templateRendered) {
try {
Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE);
} catch (Exception $e) {
Craft::error($e->getMessage(), __METHOD__);
}
// Render the template with our vars passed in
try {
$htmlText = Craft::$app->view->renderTemplate($templatePath, $params);
$templateRendered = true;
} catch (\Exception $e) {
$htmlText = Craft::t(
'seomatic',
'Error rendering `{template}` -> {error}',
['template' => $templatePath, 'error' => $e->getMessage()]
);
Craft::error($htmlText, __METHOD__);
$templateRendered = false;
}
}

// Restore the old template mode
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/PullField.php
Expand Up @@ -152,6 +152,9 @@ public static function parseImageSources($elementName, &$globalsSettings, &$bund
$seoField = $fields['seoField'];
$tranformModeField = $fields['transformModeField'];
$transformMode = $bundleSettings[$tranformModeField] ?? 'crop';
if (empty($transformMode)) {
$transformMode = 'crop';
}
$seoFieldWidth = $fields['seoField'].'Width';
$seoFieldHeight = $fields['seoField'].'Height';
$transformName = $fields['transformName'] ?? 'base';
Expand Down
12 changes: 6 additions & 6 deletions src/models/EditableTemplate.php
Expand Up @@ -78,15 +78,15 @@ public static function create(array $config = [])
public function loadTemplate()
{
$this->templateString = '';
// Try it from our plugin directory first
$path = Craft::getAlias('@nystudio107/seomatic/templates/')
.$this->template;
// First try it from the Craft template directory
$path = Craft::getAlias('@templates/')
. $this->template;
if (file_exists($path)) {
$this->templateString = @file_get_contents($path);
} else {
// Next try it from the Craft template directory
$path = Craft::getAlias('@templates/')
. $this->template;
// Next try from our plugin directory first
$path = Craft::getAlias('@nystudio107/seomatic/templates/')
.$this->template;
if (file_exists($path)) {
$this->templateString = @file_get_contents($path);
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/Sitemaps.php
Expand Up @@ -342,6 +342,10 @@ public function sitemapIndex(): string
{
$result = '';
$sites = [];
// If sitemaps aren't enabled globally, return nothing for the sitemap index
if (!Seomatic::$settings->sitemapsEnabled) {
return '';
}
if (Seomatic::$settings->siteGroupsSeparate) {
// Get only the sites that are in the current site's group
try {
Expand Down

0 comments on commit cec9a38

Please sign in to comment.