From cd5f98d66f82817aefac3f99cba35b3959081a46 Mon Sep 17 00:00:00 2001 From: Nathan Yam Date: Wed, 13 May 2015 16:42:50 +1000 Subject: [PATCH 1/5] Add urldecoded text column renderer Also created grid type for URL rewrites grid, and setup urldecoded renderer for request and target path custom columns. --- .../Grid/Column/Renderer/Text/Urldecoded.php | 27 +++++++++++++++++ .../CustomGrid/Model/Grid/Type/Urlrewrite.php | 12 ++++++++ .../BL/CustomGrid/etc/customgrid.xml | 29 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Renderer/Text/Urldecoded.php create mode 100644 app/code/community/BL/CustomGrid/Model/Grid/Type/Urlrewrite.php diff --git a/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Renderer/Text/Urldecoded.php b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Renderer/Text/Urldecoded.php new file mode 100644 index 0000000..d8b9c15 --- /dev/null +++ b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Renderer/Text/Urldecoded.php @@ -0,0 +1,27 @@ + + + URL Rewrite + 400000 + + + Request Path (URL Decoded) + Duplicated + 1 + + request_path + + + customgrid/widget_grid_column_renderer_text_urldecoded + + + + Target Path (URL Decoded) + Duplicated + 1 + + target_path + + + customgrid/widget_grid_column_renderer_text_urldecoded + + + + + Other 1000000000 From 0facddaf190f09cd8605a7b786ade5d58694aa88 Mon Sep 17 00:00:00 2001 From: Nathan Yam Date: Thu, 14 May 2015 14:05:20 +1000 Subject: [PATCH 2/5] Urldecode the ID path on the URL rewrite page --- app/code/community/BL/CustomGrid/etc/customgrid.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/code/community/BL/CustomGrid/etc/customgrid.xml b/app/code/community/BL/CustomGrid/etc/customgrid.xml index b5dfa32..5ffdfcd 100644 --- a/app/code/community/BL/CustomGrid/etc/customgrid.xml +++ b/app/code/community/BL/CustomGrid/etc/customgrid.xml @@ -516,6 +516,17 @@ customgrid/widget_grid_column_renderer_text_urldecoded + + ID Path (URL Decoded) + Duplicated + 1 + + target_path + + + customgrid/widget_grid_column_renderer_text_urldecoded + + From 3f33907407831c0d9262f98144095facd7ae3568 Mon Sep 17 00:00:00 2001 From: Nathan Yam Date: Fri, 15 May 2015 16:26:12 +1000 Subject: [PATCH 3/5] Add column filter for non-English URL rewrites --- .../Model/Custom/Column/Urldecoded.php | 44 +++++++++++++++++++ .../BL/CustomGrid/etc/customgrid.xml | 29 +++++------- 2 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php diff --git a/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php b/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php new file mode 100644 index 0000000..fb1b2b3 --- /dev/null +++ b/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php @@ -0,0 +1,44 @@ + 'customgrid/widget_grid_column_renderer_text_urldecoded', + 'filter_condition_callback' => array($this, 'addFilterToGridCollection'), + ); + } + + /** + * @param Mage_Core_Model_Resource_Url_Rewrite_Collection $collection + * @param Mage_Adminhtml_Block_Widget_Grid_Column $columnBlock + */ + public function addFilterToGridCollection($collection, Mage_Adminhtml_Block_Widget_Grid_Column $columnBlock) + { + $filter = $columnBlock->getFilter(); + $value = $filter->getValue(); + $filter->setValue(urlencode($value)); + $collection->addFieldToFilter($this->getDuplicatedFieldName(), $filter->getCondition()); + $filter->setValue($value); + } +} diff --git a/app/code/community/BL/CustomGrid/etc/customgrid.xml b/app/code/community/BL/CustomGrid/etc/customgrid.xml index 5ffdfcd..3ce9520 100644 --- a/app/code/community/BL/CustomGrid/etc/customgrid.xml +++ b/app/code/community/BL/CustomGrid/etc/customgrid.xml @@ -494,39 +494,30 @@ URL Rewrite 400000 - + + ID Path (URL Decoded) + Duplicated + 1 + + id_path + + + Request Path (URL Decoded) Duplicated 1 request_path - - customgrid/widget_grid_column_renderer_text_urldecoded - - + Target Path (URL Decoded) Duplicated 1 target_path - - customgrid/widget_grid_column_renderer_text_urldecoded - - - ID Path (URL Decoded) - Duplicated - 1 - - target_path - - - customgrid/widget_grid_column_renderer_text_urldecoded - - From 62a07b7bddd89fa6c555e1a9a17ba1ebe554cc63 Mon Sep 17 00:00:00 2001 From: Matthew Gamble Date: Mon, 16 Nov 2015 15:16:05 +1100 Subject: [PATCH 4/5] Remove allow_renderers from urldecoded column renderers There's no need to allow custom renderers for these columns, as we need to force urldecoding of the values. --- app/code/community/BL/CustomGrid/etc/customgrid.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/community/BL/CustomGrid/etc/customgrid.xml b/app/code/community/BL/CustomGrid/etc/customgrid.xml index 3ce9520..60b608b 100644 --- a/app/code/community/BL/CustomGrid/etc/customgrid.xml +++ b/app/code/community/BL/CustomGrid/etc/customgrid.xml @@ -497,7 +497,6 @@ ID Path (URL Decoded) Duplicated - 1 id_path @@ -505,7 +504,6 @@ Request Path (URL Decoded) Duplicated - 1 request_path @@ -513,7 +511,6 @@ Target Path (URL Decoded) Duplicated - 1 target_path From 8ae31cb372aea552e3f8ffe9d2fdd7656ee66194 Mon Sep 17 00:00:00 2001 From: Matthew Gamble Date: Mon, 16 Nov 2015 17:42:19 +1100 Subject: [PATCH 5/5] 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. --- .../Grid/Column/Filter/Text/Urldecoded.php | 65 +++++++++++++++++++ .../Model/Custom/Column/Urldecoded.php | 16 +---- 2 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Filter/Text/Urldecoded.php diff --git a/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Filter/Text/Urldecoded.php b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Filter/Text/Urldecoded.php new file mode 100644 index 0000000..d933b0c --- /dev/null +++ b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Column/Filter/Text/Urldecoded.php @@ -0,0 +1,65 @@ + + * @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() + { + $parsedUrl = parse_url(parent::getValue()); + return (isset($parsedUrl["path"]) ? $parsedUrl["path"] : "") . + (isset($parsedUrl["query"]) ? "?" . $parsedUrl["query"] : "") . + (isset($parsedUrl["fragment"]) ? "#" . $parsedUrl["fragment"] : ""); + } + + /** + * @return string + */ + public function getUrlencodedValue() + { + $parsedUrl = parse_url($this->getValue()); + $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; + } + + /** + * 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); + } +} diff --git a/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php b/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php index fb1b2b3..2d364e5 100644 --- a/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php +++ b/app/code/community/BL/CustomGrid/Model/Custom/Column/Urldecoded.php @@ -24,21 +24,9 @@ public function getForcedBlockValues( Mage_Core_Model_Store $store ) { return array( + 'filter_mode' => BL_CustomGrid_Block_Widget_Grid_Column_Filter_Text::MODE_INSIDE_LIKE, + 'filter' => 'customgrid/widget_grid_column_filter_text_urldecoded', 'renderer' => 'customgrid/widget_grid_column_renderer_text_urldecoded', - 'filter_condition_callback' => array($this, 'addFilterToGridCollection'), ); } - - /** - * @param Mage_Core_Model_Resource_Url_Rewrite_Collection $collection - * @param Mage_Adminhtml_Block_Widget_Grid_Column $columnBlock - */ - public function addFilterToGridCollection($collection, Mage_Adminhtml_Block_Widget_Grid_Column $columnBlock) - { - $filter = $columnBlock->getFilter(); - $value = $filter->getValue(); - $filter->setValue(urlencode($value)); - $collection->addFieldToFilter($this->getDuplicatedFieldName(), $filter->getCondition()); - $filter->setValue($value); - } }