Skip to content

Commit

Permalink
Merge branch 'release/4.1.17' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jun 19, 2024
2 parents 61a6c48 + aca5d0a commit d6a5613
Show file tree
Hide file tree
Showing 82 changed files with 3,368 additions and 1,892 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Retour Changelog

## 4.1.17 - 2024.06.19
### Fixed
* Fixed an issue where the down and up arrows were reversed for sorting purposes ([#299](https://github.com/nystudio107/craft-retour/issues/299))
* Fixed an issue where the "File Not Found URL" link could be wrong when clicked on in some multi-site setups ([#290](https://github.com/nystudio107/craft-retour/issues/290))
* Fixed an issue where the Short Link wouldn't display properly in the element index view ([#301](https://github.com/nystudio107/craft-retour/issues/301))
* Fixed an issue where Short Links wouldn't work properly if they were added to Asset elements ([#300](https://github.com/nystudio107/craft-retour/issues/300))
* Fixed an issue where a "Integrity constraint violation" error could occurr if malformed `redirectSrcUrl`s was introduced into the statistics table ([#305](https://github.com/nystudio107/craft-retour/issues/305))

## 4.1.16 - 2024.03.25
### Fixed
* Added the unused `static` to the Tailwind CSS `blocklist` to avoid a name collision with a Craft CSS class ([#1412](https://github.com/nystudio107/craft-seomatic/issues/1412))
Expand Down
1,599 changes: 1,021 additions & 578 deletions buildchain/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions buildchain/src/css/components/tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ table.vuetable {

.retour-menubtn-asc::before {
font-weight: bold;
content: "downangle";
content: "upangle";
}

.retour-menubtn-desc::before {
font-weight: bold;
content: "upangle";
content: "downangle";
}

/**
Expand Down
4 changes: 1 addition & 3 deletions buildchain/src/vue/FileNotFoundUrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ export default {
},
computed: {
linkHref: function () {
let url = this.rowData.redirectSrcUrl;
let url = this.rowData.redirectSrcUrlFull;
if (typeof url === 'undefined' || url === '') {
return '';
}
let absoluteUrl = new RegExp('^(?:[a-z]+:)?//', 'i');
if (!absoluteUrl.test(url) && !url.includes('$')) {
// Strip off a leading `/` because otherwise `Craft.getUrl()` considers it an absolute URL and returns it
url = url.replace(/^\//, '');
url = Craft.getSiteUrl(url);
}
Expand Down
2 changes: 0 additions & 2 deletions buildchain/src/vue/RedirectsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ export default {
let url = value;
let absoluteUrl = new RegExp('^(?:[a-z]+:)?//', 'i');
if (!absoluteUrl.test(url) && !url.includes('$')) {
// Strip off a leading `/` because otherwise `Craft.getUrl()` considers it an absolute URL and returns it
url = url.replace(/^\//, '');
url = Craft.getSiteUrl(url);
}
return `
Expand Down
2 changes: 0 additions & 2 deletions buildchain/src/vue/ShortlinksTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ export default {
let url = value;
let absoluteUrl = new RegExp('^(?:[a-z]+:)?//', 'i');
if (!absoluteUrl.test(url) && !url.includes('$')) {
// Strip off a leading `/` because otherwise `Craft.getUrl()` considers it an absolute URL and returns it
url = url.replace(/^\//, '');
url = Craft.getSiteUrl(url);
}
return `
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-retour",
"description": "Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website",
"type": "craft-plugin",
"version": "4.1.16",
"version": "4.1.17",
"keywords": [
"craftcms",
"craft-plugin",
Expand Down
1,896 changes: 1,437 additions & 459 deletions docs/package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/controllers/TablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\helpers\UrlHelper;
use craft\web\Controller;
use nystudio107\retour\helpers\Permission as PermissionHelper;
use Throwable;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\Response;
Expand Down Expand Up @@ -133,6 +134,15 @@ public function actionDashboard(
if ($stats) {
// Add in the `addLink` field
foreach ($stats as &$stat) {
// Normalize the `redirectSrcUrl` to point to a valid frontend site URL
$stat['redirectSrcUrlFull'] = $stat['redirectSrcUrl'];
if (!UrlHelper::isAbsoluteUrl($stat['redirectSrcUrlFull'])) {
try {
$stat['redirectSrcUrlFull'] = UrlHelper::siteUrl($stat['redirectSrcUrlFull'], null, null, $stat['siteId']);
} catch (Throwable $e) {
// That's fine
}
}
$stat['addLink'] = '';
if (!$stat['handledByRetour']) {
$encodedUrl = urlencode('/' . ltrim($stat['redirectSrcUrl'], '/'));
Expand Down
20 changes: 12 additions & 8 deletions src/fields/ShortLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace nystudio107\retour\fields;

use Craft;
use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\Field;
use craft\base\PreviewableFieldInterface;
Expand All @@ -29,11 +28,10 @@
*/
class ShortLink extends Field implements PreviewableFieldInterface
{
protected static bool $allowShortLinkUpdates = true;
public string $redirectSrcMatch = 'pathonly';
public int $redirectHttpCode = 301;

protected static bool $allowShortLinkUpdates = true;

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

Expand Down Expand Up @@ -149,11 +147,17 @@ public function afterElementDelete(ElementInterface $element): void
public function getTableAttributeHtml($value, ElementInterface $element): string
{
$decoded = Json::decodeIfJson($value);
if ($decoded) {
return $decoded['legacyUrl'] ?? '';
if (is_array($decoded)) {
$value = $decoded['legacyUrl'] ?? '';
}

// Render the input template
return $value;
// Render the preview template
return Craft::$app->getView()->renderTemplate(
'retour/_components/fields/ShortLink_preview',
[
'name' => $this->handle,
'value' => $value,
'field' => $this,
]
);
}
}
6 changes: 5 additions & 1 deletion src/services/Redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,18 @@ public function enableElementRedirect(ElementInterface $element, string $sourceU
{
$siteId = $element->siteId;

$destUrl = $redirectSrcMatch === 'pathonly' ? $element->uri : $element->getUrl();
if ($destUrl === null) {
$destUrl = $element->getUrl();
}
$redirectConfig = [
'redirectMatchType' => 'exactmatch',
'redirectSrcUrl' => $sourceUrl,
'siteId' => $siteId,
'associatedElementId' => $element->getCanonicalId(),
'enabled' => $element->getEnabledForSite($siteId),
'redirectSrcMatch' => $redirectSrcMatch,
'redirectDestUrl' => $redirectSrcMatch === 'pathonly' ? $element->uri : $element->getUrl(),
'redirectDestUrl' => $destUrl,
'redirectHttpCode' => $redirectHttpCode,
];

Expand Down
4 changes: 2 additions & 2 deletions src/services/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ public function incrementStatistics(string $url, bool $handled = false, $siteId
}
// Normalize the $url via the validator
$stats = new StatsModel([
'redirectSrcUrl' => $url,
'redirectSrcUrl' => TextHelper::cleanupText($url),
]);
$stats->validate();
// Find any existing retour_stats record
$statsConfig = (new Query())
->from(['{{%retour_stats}}'])
->where(['redirectSrcUrl' => TextHelper::cleanupText($stats->redirectSrcUrl)])
->where(['redirectSrcUrl' => $stats->redirectSrcUrl])
->one();
// If no record is found, initialize some values
if ($statsConfig === null) {
Expand Down
24 changes: 24 additions & 0 deletions src/templates/_components/fields/ShortLink_preview.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% import "_includes/forms" as forms %}

{%- set class = ['retour-shortlink-preview'] %}
{%- set class = (class ?? [])|explodeClass|merge([
]|filter) %}

{% set config = {
name: name,
text: value,
class: class,
readonly: true,
} %}

<style>
.retour-shortlink-preview {
padding-left: 25px;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAAoCAMAAACVZWnNAAAAP1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzJYIvAAAAFXRSTlMAS09SBUIRSAglPhcOMik2LTgbOh9vs7GRAAABUklEQVRIx93USXaEMAwEUEklj4yhuf9ZYxkSkp3Vu6RW7vf6Y0nG0L9LtOS36FkBCMKqbqo7hDklZgT12g9wc7AnSFCnNcR7KRXMqOq2IdpyMX04LV73nBdhqU67fZWaE0vw2eVpM8gw1g1mbenHq9ndVv6yD+lWvwtpTxseWCtaWs2PnZgZ05CNzCwz0V6n29qJbzSG0f6qdEI42u9u0zyIhVGICpKk3G3LSNGzXju/tE1YGCtplSQjNldO89Vz7EOX2joGhmwQ27NP+6MfLiOSxiOP2d7tJNclWmAVDEWrmdWWOxgn6UsYg3jFbe0Cc7uMs415DMfL6t2C7S/Dr8YmjOXn+3xaF+cYDvK7xmJ2cOPnxj5WQn4Lr93O5MV+a5il3APbnZYK2HQ/Za+lnIwsMR7BbfsHpCEAftu1cGphRvVapVgZFl7onUxracn0N/IJlGEKSScEDxoAAAAASUVORK5CYII=");
background-repeat: no-repeat;
background-position: left center;
background-size: 30px 20px;
}
</style>

{{ tag('div', config) }}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file removed src/web/assets/dist/assets/LegacyUrl-8NcnlGd1.js.map.gz
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Binary file not shown.

This file was deleted.

Loading

0 comments on commit d6a5613

Please sign in to comment.