Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
SS4.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed May 7, 2018
1 parent 9ce82e5 commit 7332db4
Show file tree
Hide file tree
Showing 31 changed files with 449 additions and 780 deletions.
11 changes: 11 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mappings:
MisdirectionAdmin: 'nglasl\misdirection\MisdirectionAdmin'
MisdirectionAdminTestingExtension: 'nglasl\misdirection\MisdirectionAdminTestingExtension'
MisdirectionFallbackExtension: 'nglasl\misdirection\MisdirectionFallbackExtension'
SiteTreeMisdirectionExtension: 'nglasl\misdirection\SiteTreeMisdirectionExtension'
MisdirectionTesting: 'nglasl\misdirection\MisdirectionTesting'
LinkMapping: 'nglasl\misdirection\LinkMapping'
MisdirectionRequestFilter: 'nglasl\misdirection\MisdirectionRequestFilter'
MisdirectionService: 'nglasl\misdirection\MisdirectionService'
MisdirectionFunctionalTests: 'nglasl\misdirection\tests\MisdirectionFunctionalTests'
MisdirectionUnitTests: 'nglasl\misdirection\tests\MisdirectionUnitTests'
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# [misdirection](https://packagist.org/packages/nglasl/silverstripe-misdirection)

_The current release is **2.2.26**_
_The current release is **3.0.0**_

> A module for SilverStripe which will allow both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling.
> This module allows both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling.
## Requirement

* SilverStripe 3.1 → **3.5**
* SilverStripe 3.1 → **4.0**

This module does **not** require the CMS.

Expand All @@ -24,25 +24,25 @@ This module does **not** require the CMS.

These allow both simple and regular expression link redirections, and can be used for legacy page redirection, vanity URLs (more below), or redirection based on specific URL patterns.

![link-mapping](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/images/misdirection-link-mapping.png)
![link-mapping](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/client/images/misdirection-link-mapping.png)

The link mapping with the highest priority (followed by greatest specificity) will be used, and replaces the default automated URL handling out of the box. This default behaviour may be configured to only hook into a page not found:

```yaml
MisdirectionRequestFilter:
nglasl\misdirection\MisdirectionRequestFilter:
enforce_misdirection: false
```
When there are multiple matches, the link mapping first created will be used. This default behaviour may be configured to prioritise the link mapping most recently created:
```yaml
LinkMapping:
nglasl\misdirection\LinkMapping:
priority: 'DESC'
```
### Vanity URLs and Fallbacks
![vanity-URLs-and-fallbacks](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/images/misdirection-vanity-URLs-and-fallbacks.png)
![vanity-URLs-and-fallbacks](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/client/images/misdirection-vanity-URLs-and-fallbacks.png)
#### Vanity URLs
Expand All @@ -61,16 +61,16 @@ The link mappings are processed server side to prevent inefficient and problemat

When you want to see exactly what is happening behind the scenes for a given URL, the model admin provides a powerful testing interface!

![testing](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/images/misdirection-testing.png)
![testing](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/client/images/misdirection-testing.png)

Once a maximum number of requests has been reached, the server will respond with a page not found. The following is the default configuration:

```yaml
MisdirectionRequestFilter:
nglasl\misdirection\MisdirectionRequestFilter:
maximum_requests: 9
```

![testing-maximum-requests](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/images/misdirection-testing-maximum-requests.png)
![testing-maximum-requests](https://raw.githubusercontent.com/nglasl/silverstripe-misdirection/master/client/images/misdirection-testing-maximum-requests.png)

#### Bypassing Misdirection

Expand All @@ -81,16 +81,12 @@ It is possible to bypass the request filter completely by appending `?misdirecte
This may be completely replaced, in which case legacy URLs will no longer resolve based on page version history.

```yaml
MisdirectionRequestFilter:
nglasl\misdirection\MisdirectionRequestFilter:
replace_default: true
```

When a page is moved, the appropriate link mappings are automatically created and maintained. This allows full control over which legacy URLs remain in the system.

#### Historical Link Mappings

To ensure the current page version history remains, `/dev/tasks/MisdirectionHistoricalLinkMappingsTask` may be used to instantiate the appropriate link mappings. However, this task is currently only supported by `MySQL`.

## Maintainer Contact

Nathan Glasl, [email protected]
14 changes: 0 additions & 14 deletions _config.php

This file was deleted.

14 changes: 7 additions & 7 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: misdirection-extensions
---
MisdirectionAdmin:
nglasl\misdirection\MisdirectionAdmin:
extensions:
- 'MisdirectionAdminTestingExtension'
SiteTree:
- 'nglasl\misdirection\MisdirectionAdminTestingExtension'
SilverStripe\CMS\Model\SiteTree:
extensions:
- 'SiteTreeMisdirectionExtension'
- 'MisdirectionFallbackExtension'
SiteConfig:
- 'nglasl\misdirection\SiteTreeMisdirectionExtension'
- 'nglasl\misdirection\MisdirectionFallbackExtension'
SilverStripe\SiteConfig\SiteConfig:
extensions:
- 'MisdirectionFallbackExtension'
- 'nglasl\misdirection\MisdirectionFallbackExtension'
6 changes: 3 additions & 3 deletions _config/request-filters.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: misdirection-request-filters
---
Injector:
RequestProcessor:
SilverStripe\Core\Injector\Injector:
SilverStripe\Control\RequestProcessor:
properties:
filters:
- '%$MisdirectionRequestFilter'
- '%$nglasl\misdirection\MisdirectionRequestFilter'
6 changes: 6 additions & 0 deletions _config/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: misdirection-upgrade
---
SilverStripe\ORM\DatabaseAdmin:
classname_value_remapping:
LinkMapping: 'nglasl\misdirection\LinkMapping'
75 changes: 75 additions & 0 deletions client/css/misdirection.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

/**
* The misdirection specific styling.
* @author Nathan Glasl <[email protected]>
*/

div.misdirection-testing.admin {
background: #005A93;
color: white;
padding: 10px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}

div.misdirection-testing.admin div {
margin-bottom: 10px;
}

div.misdirection-testing.admin div.wrapper {
white-space: nowrap;
}

div.misdirection-testing.admin input.url {
display: inline-block;
vertical-align: middle;
}

div.misdirection-testing.admin span.test.disabled {
filter: Alpha(opacity = 40);
opacity: 0.4;
cursor: not-allowed;
}

div.misdirection-testing.admin div.results {
overflow: hidden;
margin-bottom: 0;
}

/* Preload the required image to avoid performance issues. */

body:after {
display: none;
content: url('../images/loading.gif');
}

div.misdirection-testing.admin div.results.loading {
min-height: 40px;
background: url('../images/loading.gif') no-repeat left center;
}

div.misdirection-testing.admin div.result {
float: left;
width: 18%;
margin: 10px 1% 0;
}

div.misdirection-testing.admin div.result:not(.no-matches) {
word-wrap: break-word;
}

/* This is used to correct the float height issue, however will not be supported by IE8. */

div.misdirection-testing.admin div.result:nth-child(5n+1) {
clear: both;
}

div.misdirection-testing.admin div.result div.h3 {
text-decoration: underline;
}

div.mapped-link,
div.redirect-link {
width: 50%;
}
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// Test the link mapping chain.

var URL = input ? input.val() : $('div.misdirection-testing.admin input.url').val();
$.getJSON('admin/misdirection/LinkMapping/getMappingChain', {
$.getJSON('admin/misdirection/nglasl-misdirection-LinkMapping/getMappingChain', {
map: URL
},
function(JSON) {
Expand All @@ -49,23 +49,23 @@

output += "<div class='result'>";
if(object['ResponseCode'] !== 404) {
output += '<h3><strong>' + object['Counter'] + '</strong></h3>';
output += "<div class='h3'><strong>" + object['Counter'] + '</strong></div>';
output += '<div><strong>Link Type</strong> ' + object['LinkType'] + '</div>';
output += '<div><strong>Mapped Link</strong> ' + object['MappedLink'].replace(/</g, '&lt;').replace(/>/g, '&gt;') + '</div>';
output += '<div><strong>Redirect Link</strong> ' + object['RedirectLink'].replace(/</g, '&lt;').replace(/>/g, '&gt;') + '</div>';
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
output += '<div><strong>Priority</strong> ' + object['Priority'] + '</div>';
}
else {
output += '<h3><strong>Maximum</strong></h3>';
output += "<div class='h3'><strong>Maximum</strong></div>";
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
}
output += '</div>';
});
}
else {
output += "<div class='result'>";
output += '<h3><strong>No Matches</strong></h3>';
output += "<div class='result no-matches'>";
output += "<div class='h3'><strong>No Matches</strong></div>";
output += '</div>';
}

Expand All @@ -83,26 +83,26 @@
enable($(this));
});

page.on('change', 'div.misdirection-testing.admin input.url', function() {
page.on('blur', 'div.misdirection-testing.admin input.url', function() {

// Make sure the edit form doesn't detect changes.

$('#Form_EditForm').removeClass('changed');
$('form#Form_EditForm').removeClass('changed');
});

// The testing.

page.on('keydown', 'div.misdirection-testing.admin input.url', function(event) {
page.on('keydown', 'div.misdirection-testing.admin input.url, div.misdirection-testing.admin span.test', function(event) {

// Trigger a test request on pressing enter.

if(event.keyCode === 13) {
var input = $(this);
var input = $('div.misdirection-testing.admin input.url');
if(input.val().length > 0) {

// Test the link mapping chain for the given URL, and render this to the user.

test();
test(input);
}
return false;
}
Expand Down
Loading

0 comments on commit 7332db4

Please sign in to comment.