Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

urldecoded URL rewrites grid custom columns #186

Open
wants to merge 5 commits into
base: 1.0.0-wip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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()
{
$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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class BL_CustomGrid_Block_Widget_Grid_Column_Renderer_Text_Urldecoded extends BL_CustomGrid_Block_Widget_Grid_Column_Renderer_Text
{
/**
* Renders grid column
*
* @param Varien_Object $row
* @return string
*/
public function render(Varien_Object $row)
{
$value = parent::_getValue($row);
return urldecode($value);
}

/**
* Render column for export
*
* @param Varien_Object $row
* @return string
*/
public function renderExport(Varien_Object $row)
{
return parent::render($row);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class BL_CustomGrid_Model_Custom_Column_Urldecoded extends BL_CustomGrid_Model_Custom_Column_Simple_Duplicate
{
/**
* Return forced grid column block values
* (you can check BL_CustomGrid_Model_Custom_Column_Abstract::getBlockValues() for the priorities
* of the different methods related to block values)
*
* @param Mage_Adminhtml_Block_Widget_Grid $gridBlock Grid block
* @param BL_CustomGrid_Model_Grid $gridModel Grid model
* @param string $columnBlockId Grid column block ID
* @param string $columnIndex Grid column index
* @param array $params Customization params values
* @param Mage_Core_Model_Store $store Column store
* @return array
*/
public function getForcedBlockValues(
Mage_Adminhtml_Block_Widget_Grid $gridBlock,
BL_CustomGrid_Model_Grid $gridModel,
$columnBlockId,
$columnIndex,
array $params,
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',
);
}
}
12 changes: 12 additions & 0 deletions app/code/community/BL/CustomGrid/Model/Grid/Type/Urlrewrite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

class BL_CustomGrid_Model_Grid_Type_Urlrewrite extends BL_CustomGrid_Model_Grid_Type_Abstract
{
/**
* @return string[]|string
*/
protected function _getSupportedBlockTypes()
{
return array('adminhtml/urlrewrite_grid');
}
}
28 changes: 28 additions & 0 deletions app/code/community/BL/CustomGrid/etc/customgrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,34 @@
</custom_columns>
</system_store>

<core_urlrewrite model="customgrid/grid_type_urlrewrite" module="customgrid">
<name>URL Rewrite</name>
<sort_order>400000</sort_order>
<custom_columns>
<id_path_urldecoded model="customgrid/custom_column_urldecoded" module="customgrid">
<name>ID Path (URL Decoded)</name>
<group>Duplicated</group>
<config_params>
<duplicated_field_name>id_path</duplicated_field_name>
</config_params>
</id_path_urldecoded>
<request_path_urldecoded model="customgrid/custom_column_urldecoded" module="customgrid">
<name>Request Path (URL Decoded)</name>
<group>Duplicated</group>
<config_params>
<duplicated_field_name>request_path</duplicated_field_name>
</config_params>
</request_path_urldecoded>
<target_path_urldecoded model="customgrid/custom_column_urldecoded" module="customgrid">
<name>Target Path (URL Decoded)</name>
<group>Duplicated</group>
<config_params>
<duplicated_field_name>target_path</duplicated_field_name>
</config_params>
</target_path_urldecoded>
</custom_columns>
</core_urlrewrite>

<other model="customgrid/grid_type_other" module="customgrid">
<name>Other</name>
<sort_order>1000000000</sort_order>
Expand Down