This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to using separate filter block
This block ensures the field is properly URL-encoded when filtering. It properly accounts for URL paths that have query strings and multiple path segments too.
- Loading branch information
Matthew Gamble
committed
Nov 16, 2015
1 parent
62a07b7
commit 92e692c
Showing
3 changed files
with
109 additions
and
14 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Filter/Text/Urldecoded.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/osl-3.0.php | ||
* | ||
* @category BL | ||
* @package BL_CustomGrid | ||
* @copyright Copyright (c) 2015 Benoît Leulliette <[email protected]> | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
class BL_CustomGrid_Block_Widget_Grid_Column_Filter_Text_Urldecoded extends BL_CustomGrid_Block_Widget_Grid_Column_Filter_Text | ||
{ | ||
/** | ||
* Overridden to strip domain from filter value, as it does not make sense | ||
* | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
$value = parent::getValue(); | ||
if ($this->getColumn()->getIsUrlPath()) { | ||
$parsedUrl = parse_url($value); | ||
return (isset($parsedUrl["path"]) ? $parsedUrl["path"] : "") . | ||
(isset($parsedUrl["query"]) ? "?" . $parsedUrl["query"] : "") . | ||
(isset($parsedUrl["fragment"]) ? "#" . $parsedUrl["fragment"] : ""); | ||
} else { | ||
return $value; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUrlencodedValue() | ||
{ | ||
$value = $this->getValue(); | ||
if ($this->getColumn()->getIsUrlPath()) { | ||
$parsedUrl = parse_url($value); | ||
$urlPath = ""; | ||
if (isset($parsedUrl["path"])) { | ||
$urlPath .= implode("/", array_map("rawurlencode", explode("/", $parsedUrl["path"]))); | ||
} | ||
if (isset($parsedUrl["query"])) { | ||
// This urlencodes all the query parameters properly for us | ||
parse_str($parsedUrl["query"], $parsedQuery); | ||
$urlPath .= "?" . http_build_query($parsedQuery); | ||
} | ||
if (isset($parsedUrl["fragment"])) { | ||
$urlPath .= "#" . urlencode($parsedUrl["fragment"]); | ||
} | ||
return $urlPath; | ||
} else { | ||
return urlencode($value); | ||
} | ||
} | ||
|
||
/** | ||
* Return the collection condition(s) usable to filter on the given value with the LIKE function. Overridden to | ||
* URL-encode the filter value. | ||
* | ||
* @param string $value Filter value | ||
* @param string $filterMode Filter mode | ||
* @param bool $isNegative Whether negative filter is enabled | ||
* @return array | ||
*/ | ||
public function getLikeCondition($value, $filterMode, $isNegative) | ||
{ | ||
return parent::getLikeCondition($this->getUrlencodedValue(), $filterMode, $isNegative); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters