Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from sheadawson/master

ENHANCEMENT check for link mappings that match url get vars, in any orde...
  • Loading branch information...
commit 9a14855392993829438f5e1e295d6eae2011165a 2 parents 1c14bcc + 7923607
@nyeholt nyeholt authored
View
17 code/controllers/LinkMappingFrontController.php
@@ -18,7 +18,9 @@ public function getNestedController() {
}
// Find page by link, regardless of current locale settings
- Translatable::disable_locale_filter();
+ $translatable = class_exists('Translatable');
+ if($translatable) Translatable::disable_locale_filter();
+
$sitetree = DataObject::get_one(
'SiteTree',
sprintf(
@@ -27,12 +29,17 @@ public function getNestedController() {
(SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null)
)
);
- Translatable::enable_locale_filter();
- if(!$sitetree) {
+ if($translatable) Translatable::enable_locale_filter();
+
+ if(!$sitetree) {
// first check for a link mapping to direct away to.
- $link = $request->getURL();
- $map = LinkMapping::get_by_link($link);
+ $link = $request->getURL();//
+ if(count($request->getVars()) > 1){
+ $link = $link . str_replace('url=' . $request->requestVar('url') . '&', '?', $_SERVER['QUERY_STRING']);
+ }
+
+ $map = LinkMapping::get_by_link($link);
if ($map) {
$this->response = new SS_HTTPResponse();
View
29 code/dataobjects/LinkMapping.php
@@ -36,9 +36,30 @@ class LinkMapping extends DataObject {
* @return LinkMapping
*/
public static function get_by_link($link) {
- return DataObject::get_one('LinkMapping', sprintf(
- '"MappedLink" = \'%s\'', Convert::raw2sql(self::unify_link($link))
- ));
+ $link = Convert::raw2sql(self::unify_link($link));
+
+ // check for an exact match
+ $match = LinkMapping::get()->filter('MappedLink', $link)->first();
+ if($match) return $match;
+
+ // check for a match with the same get vars in a different order
+ if(strpos($link, '?')){
+ $linkParts = explode('?', $link);
+ $url = $linkParts[0];
+ $matches = LinkMapping::get()->where("MappedLink like '$url%'");
+ parse_str($linkParts[1], $queryParams);
+
+ if($matches->count()){
+ foreach ($matches as $match) {
+ $matchQueryString = explode('?', $match->MappedLink);
+ parse_str($matchQueryString[1], $matchParams);
+ if($matchParams == $queryParams){
+ return $match;
+ }
+ }
+ }
+
+ }
}
/**
@@ -48,7 +69,7 @@ public static function get_by_link($link) {
* @return string
*/
public static function unify_link($link) {
- return strtolower(trim(Director::makeRelative(strtok($link, '?')), '/'));
+ return strtolower(trim(trim(Director::makeRelative($link), '/'), '?'));
}
public function getCMSFields() {
Please sign in to comment.
Something went wrong with that request. Please try again.