Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Apr 15, 2020
2 parents 65e1e23 + 56ba673 commit b14da57
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 37 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ This plugin adds a 'Redirects' section to the main menu of October CMS. This plu

## Supported HTTP status codes

* HTTP/1.1 301 Moved Permanently
* HTTP/1.1 302 Found
* HTTP/1.1 303 See Other
* HTTP/1.1 404 Not Found
* HTTP/1.1 410 Gone
* `HTTP/1.1 301 Moved Permanently`
* `HTTP/1.1 302 Found`
* `HTTP/1.1 303 See Other`
* `HTTP/1.1 404 Not Found`
* `HTTP/1.1 410 Gone`

## Supported HTTP request methods

Expand Down
4 changes: 3 additions & 1 deletion classes/PublishManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function publish(): int
'requirements',
'from_date',
'to_date',
'ignore_query_parameters'
'ignore_query_parameters',
'ignore_case',
'ignore_trailing_slash',
];

/** @var Collection $redirects */
Expand Down
15 changes: 14 additions & 1 deletion classes/RedirectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Vdlp\Redirect\Classes\Contracts\RedirectConditionInterface;
use Vdlp\Redirect\Classes\Contracts\RedirectManagerInterface;
use Vdlp\Redirect\Classes\Exceptions;
use Vdlp\Redirect\Classes\Util\Str;
use Vdlp\Redirect\Models;

final class RedirectManager implements RedirectManagerInterface
Expand Down Expand Up @@ -361,7 +362,19 @@ private function matchesRule(RedirectRule $rule, string $requestPath, string $sc
*/
private function matchExact(RedirectRule $rule, string $url): RedirectRule
{
if ($url === $rule->getFromUrl()) {
$urlA = $rule->getFromUrl();
$urlB = $url;

if ($rule->isIgnoreTrailingSlash()) {
$urlA = Str::removeTrailingSlash($urlA);
$urlB = Str::removeTrailingSlash($urlB);
}

if ($rule->isIgnoreCase() && strcasecmp($urlA, $urlB) === 0) {
return $rule;
}

if ($urlA === $urlB) {
return $rule;
}

Expand Down
22 changes: 22 additions & 0 deletions classes/RedirectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,21 @@ final class RedirectRule
*/
private $ignoreQueryParameters;

/**
* @var bool
*/
private $ignoreCase;

/**
* @var bool
*/
private $ignoreTrailingSlash;

public function __construct(array $attributes)
{
$this->ignoreQueryParameters = false;
$this->ignoreCase = false;
$this->ignoreTrailingSlash = false;

foreach ($attributes as $key => $value) {
$property = camel_case($key);
Expand Down Expand Up @@ -225,4 +237,14 @@ public function isIgnoreQueryParameters(): bool
{
return (bool) $this->ignoreQueryParameters;
}

public function isIgnoreCase(): bool
{
return (bool) $this->ignoreCase;
}

public function isIgnoreTrailingSlash(): bool
{
return (bool) $this->ignoreTrailingSlash;
}
}
2 changes: 1 addition & 1 deletion classes/testers/RedirectFinalDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function test(): TesterResult
);

$message = $error
?? e(trans('vdlp.redirect::lang.test_lab.final_destination_is', ['destination' => $finalDestination]));
?? trans('vdlp.redirect::lang.test_lab.final_destination_is', ['destination' => $finalDestination]);
}

return new TesterResult($error === null, $message);
Expand Down
19 changes: 19 additions & 0 deletions classes/util/Str.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Vdlp\Redirect\Classes\Util;

final class Str
{
public static function removeTrailingSlash(string $url): string
{
if (strpos($url, '?') !== false) {
[$part1, $part2] = explode('?', $url, 2);

return implode('?', [rtrim($part1, '/'), $part2]);
}

return rtrim($url, '/');
}
}
8 changes: 3 additions & 5 deletions controllers/redirects/update.htm
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
<?php if (!$this->fatalError): ?>

<?php Block::put('form-contents') ?>

<?php if (isset($warningMessage)): ?>
<?= $this->makePartial('warning', ['warningMessage' => $warningMessage]); ?>
<?php endif; ?>

<div class="layout">

<div class="layout-row">
<?php if (isset($warningMessage)): ?>
<?= $this->makePartial('warning', ['warningMessage' => $warningMessage]); ?>
<?php endif; ?>
<?= $this->formRenderOutsideFields() ?>
<?= $this->formRenderPrimaryTabs() ?>
</div>
Expand Down
15 changes: 9 additions & 6 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
'caching_enabled_comment' => 'Improves the redirect engine when having a lot of redirects. '
. 'CAUTION: Cache driver `file` and `database` are NOT supported. '
. 'Recommended driver is `memcached` or a similar "in-memory" caching driver.',
'auto_redirect_creation_enabled_label' => 'Auto redirect creation',
'auto_redirect_creation_enabled_comment' => 'Automatically create redirects when the slug of a '
. 'Page or Static Page was changed.',
],
'redirect' => [
'redirect' => 'Redirect',
Expand Down Expand Up @@ -108,8 +105,12 @@
'sparkline_30d' => 'Hits (30d)',
'has_hits' => 'Has hits',
'minimum_hits' => 'Minimum # hits',
'ignore_query_parameters' => 'Ignore query parameters (recommended).',
'ignore_query_parameters_comment' => 'The engine will ignore all query parameters from the Source Path.',
'ignore_query_parameters' => 'Ignore query parameters',
'ignore_query_parameters_comment' => 'The redirect engine will ignore all query parameters.',
'ignore_case' => 'Ignore case',
'ignore_case_comment' => 'The redirect engine will do case-insensitive matching.',
'ignore_trailing_slash' => 'Ignore trailing slash',
'ignore_trailing_slash_comment' => 'The redirect engine will ignore trailing slashes.',
'last_used_at' => 'Last hit',
'updated_at' => 'Updated at',
'invalid_regex' => 'Invalid regular expression.',
Expand Down Expand Up @@ -274,7 +275,9 @@
'to_date' => 'Scheduled date to [to_date] (YYYY-MM-DD or empty)',
'sort_order' => 'Priority [sort_order]',
'is_enabled' => 'Enabled [is_enabled] (1 = enable redirect, 0 = disable redirect [default])',
'ignore_query_parameters' => 'Ignore Query Parameters [ignore_query_parameters] (1 = ignore query parameters, 0 = include query parameters [default])',
'ignore_query_parameters' => 'Ignore Query Parameters [ignore_query_parameters] (1 = yes, 0 = no [default])',
'ignore_case' => 'Ignore Case [ignore_case] (1 = yes, 0 = no [default])',
'ignore_trailing_slash' => 'Ignore Trailing Slashes [ignore_trailing_slash] (1 = yes, 0 = no [default])',
'test_lab' => 'Test Lab [test_lab] (1 = enable Test Lab, 0 = disable TestLab [default])',
'test_lab_path' => 'Test Lab path [test_lab_path] (required if match_type = placeholders)',
'system' => 'System [system] (1 = system generated redirect, 0 = user generated redirect [default])',
Expand Down
37 changes: 23 additions & 14 deletions lang/nl/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
'sparkline_30d' => 'Treffers (30d)',
'has_hits' => 'Heeft treffers',
'minimum_hits' => 'Minimum treffers',
'ignore_query_parameters' => 'Negeer query parameters',
'ignore_query_parameters_comment' => 'Het matching-algoritme negeert aanwezige query parameters.',
'ignore_case' => 'Niet hoofdlettergevoelig',
'ignore_case_comment' => 'Het matching-algoritme is niet hoofdlettergevoelig.',
'ignore_trailing_slash' => 'Negeer slashes aan het einde van het bronpad.',
'ignore_trailing_slash_comment' => '',
'last_used_at' => 'Laatste treffer',
'updated_at' => 'Bijgewerkt op',
'invalid_regex' => 'Ongeldige reguliere expressie.',
Expand All @@ -116,12 +122,12 @@
],
'scheduling' => [
'from_date' => 'Beschikbaar van',
'from_date_comment' => 'De datum wanneer deze redirect actief wordt mag weggelaten worden.',
'from_date_comment' => '',
'to_date' => 'Beschikbaar tot',
'to_date_comment' => 'De datum tot wanneer deze redirect actief is mag weggelaten worden.',
'to_date_comment' => '',
'scheduling_comment' => 'Hier kan een periode ingegeven worden wanneer de redirect beschikbaar is. '
. 'Alle combinatie data zijn mogelijk.',
'not_active_warning' => 'Redirect is not available anymore, please check \'Scheduling\' tab.',
'not_active_warning' => 'Deze redirect valt buiten het gestelde tijdschema. Controleer instellingen onder tabblad \'Tijdschema\'.',
],
'test' => [
'test_comment' => 'Test uw redirect voordat u deze opslaat.',
Expand All @@ -144,16 +150,16 @@
'test_lab_path_label' => 'Test pad',
'test_lab_path_comment' => 'Dit pad zal gebruikt worden wanneer test worden uitgevoerd. '
. 'Vervang placeholders met echt waardes.',
'start_tests' => 'Start testen',
'start_tests_description' => 'Klik de \'Start Testen\' button om te beginnen.',
'start_tests' => 'Start tests',
'start_tests_description' => 'Klik de \'Start Tests\' button om te beginnen.',
'edit' => 'Bewerk',
'exclude' => 'Sluit uit',
'exclude_confirm' => 'Weet u zeker dat u deze redirect wilt uitsluiten in het TestLab?',
'exclude_indicator' => 'Redirect uitsluiten in het TestLab',
're_run' => 'Opnieuw',
're_run_indicator' => 'Testen aan het uitvoeren, wacht uw even...',
're_run_indicator' => 'Tests aan het uitvoeren, even geduld...',
'loop' => 'Lus',
'match' => 'Overeenkomst',
'match' => 'Match',
'response_http_code' => 'Response HTTP code',
'response_http_code_should_be' => 'Response HTTP code zou een van de volgende moeten zijn:',
'redirect_count' => 'Redirect aantal',
Expand All @@ -172,10 +178,10 @@
'no_loop' => 'Geen redirect lus gedetecteerd.',
'not_match_redirect' => 'Komt niet overeen met een redirect.',
'matched' => 'Overeenkomstig',
'redirect' => 'verwijs',
'matched_not_http_code' => 'Redirect komt overeen maar de HTTP response code komt niet overeen! '
'redirect' => 'redirect',
'matched_not_http_code' => 'Redirect komt overeen, maar de HTTP antwoord code komt niet overeen! '
. 'Verwachte :expected maar ontving :received.',
'matched_http_code' => 'Overeenkomstige redirect, response HTTP code :code.',
'matched_http_code' => 'Overeenkomstig redirect, antwoord HTTP code :code.',
'executing_tests' => 'Uitvoeren tests...',
],
'statistics' => [
Expand Down Expand Up @@ -207,10 +213,10 @@
'test_lab' => 'TestLab (beta)',
],
'buttons' => [
'add' => 'Toevoegen', // since 2.0.3
'from_request_log' => 'Van aanvraag log', // since 2.0.3
'new_redirect' => 'Nieuwe redirect', // changed since 2.0.3
'create_redirects' => 'Maak redirects', // since 2.0.3
'add' => 'Toevoegen',
'from_request_log' => 'Van aanvraag log',
'new_redirect' => 'Nieuwe redirect',
'create_redirects' => 'Maak redirects',
'create_redirect' => 'Maak redirect',
'create_and_new' => 'Maken en nieuw',
'delete' => 'Verwijderen',
Expand Down Expand Up @@ -269,6 +275,9 @@
'to_date' => 'Scheduled date to [to_date] (YYYY-MM-DD of leeg)',
'sort_order' => 'Priority [sort_order]',
'is_enabled' => 'Enabled [is_enabled] (1 = enable redirect, 0 = disable redirect [standaard])',
'ignore_query_parameters' => 'Ignore Query Parameters [ignore_query_parameters] (1 = yes, 0 = no [default])',
'ignore_case' => 'Ignore Case [ignore_case] (1 = yes, 0 = no [default])',
'ignore_trailing_slash' => 'Ignore Trailing Slashes [ignore_trailing_slash] (1 = yes, 0 = no [default])',
'test_lab' => 'Test Lab [test_lab] (1 = enable Test Lab, 0 = disable TestLab [standaard])',
'test_lab_path' => 'Test Lab path [test_lab_path] (verplicht als match_type = placeholders)',
'system' => 'System [system] (1 = system generated redirect, 0 = user generated redirect [standaard])',
Expand Down
2 changes: 2 additions & 0 deletions models/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ final class Redirect extends Model
*/
protected $casts = [
'ignore_query_parameters' => 'boolean',
'ignore_case' => 'boolean',
'ignore_trailing_slash' => 'boolean',
'is_enabled' => 'boolean',
'test_lab' => 'boolean',
'system' => 'boolean',
Expand Down
15 changes: 15 additions & 0 deletions models/redirect/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,24 @@ tabs:
label: vdlp.redirect::lang.redirect.description
span: right
type: text
ignore_case:
label: vdlp.redirect::lang.redirect.ignore_case
type: checkbox
span: left
default: false
comment: vdlp.redirect::lang.redirect.ignore_case_comment
sort_order:
label: vdlp.redirect::lang.redirect.priority
type: text
span: right
context: update
ignore_trailing_slash:
label: vdlp.redirect::lang.redirect.ignore_trailing_slash
type: checkbox
span: left
default: false
comment: vdlp.redirect::lang.redirect.ignore_trailing_slash_comment

#
# Requirements
#
Expand Down Expand Up @@ -170,13 +183,15 @@ tabs:
type: datepicker
mode: date
span: left
ignoreTimezone: true
to_date:
tab: vdlp.redirect::lang.tab.tab_scheduling
label: vdlp.redirect::lang.scheduling.to_date
comment: vdlp.redirect::lang.scheduling.to_date_comment
type: datepicker
mode: date
span: right
ignoreTimezone: true
#
# TestLab
#
Expand Down
2 changes: 2 additions & 0 deletions models/redirectexport/columns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ columns:
to_date: vdlp.redirect::lang.import_export.to_date
sort_order: vdlp.redirect::lang.import_export.sort_order
ignore_query_parameters: vdlp.redirect::lang.import_export.ignore_query_parameters
ignore_case: vdlp.redirect::lang.import_export.ignore_case
ignore_trailing_slash: vdlp.redirect::lang.import_export.ignore_trailing_slash
is_enabled: vdlp.redirect::lang.import_export.is_enabled
test_lab: vdlp.redirect::lang.import_export.test_lab
test_lab_path: vdlp.redirect::lang.import_export.test_lab_path
Expand Down
2 changes: 2 additions & 0 deletions models/redirectimport/columns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ columns:
to_date: vdlp.redirect::lang.import_export.to_date
sort_order: vdlp.redirect::lang.import_export.sort_order
ignore_query_parameters: vdlp.redirect::lang.import_export.ignore_query_parameters
ignore_case: vdlp.redirect::lang.import_export.ignore_case
ignore_trailing_slash: vdlp.redirect::lang.import_export.ignore_trailing_slash
is_enabled: vdlp.redirect::lang.import_export.is_enabled
test_lab: vdlp.redirect::lang.import_export.test_lab
test_lab_path: vdlp.redirect::lang.import_export.test_lab_path
Expand Down
Loading

0 comments on commit b14da57

Please sign in to comment.