cvs: pear /Structures_DataGrid/DataGrid Renderer.php
| From: | Olivier Guilyardi | Date: | Mon, 19 Jun 2006 18:07:24 +0000 |
| Subject: | cvs: pear /Structures_DataGrid/DataGrid Renderer.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-40826@lists.php.net to get a copy of this message | ||
olivierg Mon Jun 19 18:07:24 2006 UTC
Modified files:
/pear/Structures_DataGrid/DataGrid Renderer.php
Log:
prefixed http_build_query()
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/Renderer.php?r1=1.50&r2=1.51&diff_format=u
Index: pear/Structures_DataGrid/DataGrid/Renderer.php
diff -u pear/Structures_DataGrid/DataGrid/Renderer.php:1.50
pear/Structures_DataGrid/DataGrid/Renderer.php:1.51
--- pear/Structures_DataGrid/DataGrid/Renderer.php:1.50 Mon Jun 19 17:39:18 2006
+++ pear/Structures_DataGrid/DataGrid/Renderer.php Mon Jun 19 18:07:24 2006
@@ -17,7 +17,7 @@
// | Olivier Guilyardi <olivier@samalyse.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Renderer.php,v 1.50 2006/06/19 17:39:18 olivierg Exp $
+// $Id: Renderer.php,v 1.51 2006/06/19 18:07:24 olivierg Exp $
/**
* Base class of all Renderer drivers
@@ -97,7 +97,7 @@
* - extraVars
* - excludeVars
*
- * @version $Revision: 1.50 $
+ * @version $Revision: 1.51 $
* @author Olivier Guilyardi <olivier@samalyse.com>
* @access public
* @package Structures_DataGrid
@@ -885,10 +885,10 @@
// Build query
if ($convertAmpersand and ini_get('arg_separator.output') == '&') {
- $query = htmlentities(http_build_query($get),ENT_QUOTES,
+ $query = htmlentities(Structures_DataGrid_http_build_query($get),ENT_QUOTES,
$this->_options['encoding']);
} else {
- $query = http_build_query($get);
+ $query = Structures_DataGrid_http_build_query($get);
}
return $query;
@@ -928,70 +928,68 @@
}
// This function is here because we can't depend on PHP_Compat
-if (!function_exists('http_build_query')) {
- function http_build_query($formdata, $numeric_prefix = null)
- {
- // If $formdata is an object, convert it to an array
- if (is_object($formdata)) {
- $formdata = get_object_vars($formdata);
- }
+function Structures_DataGrid_http_build_query($formdata, $numeric_prefix = null)
+{
+ // If $formdata is an object, convert it to an array
+ if (is_object($formdata)) {
+ $formdata = get_object_vars($formdata);
+ }
- // Check we have an array to work with
- if (!is_array($formdata)) {
- user_error('http_build_query() Parameter 1 expected to be Array or Object.
Incorrect value given.',
- E_USER_WARNING);
- return false;
- }
+ // Check we have an array to work with
+ if (!is_array($formdata)) {
+ user_error('Structures_DataGrid_http_build_query() Parameter 1 expected to be Array or
Object. Incorrect value given.',
+ E_USER_WARNING);
+ return false;
+ }
- // If the array is empty, return null
- if (empty($formdata)) {
- return;
- }
+ // If the array is empty, return null
+ if (empty($formdata)) {
+ return;
+ }
- // Argument seperator
- $separator = ini_get('arg_separator.output');
-
- // Start building the query
- $tmp = array ();
- foreach ($formdata as $key => $val) {
- if (is_integer($key) && $numeric_prefix != null) {
- $key = $numeric_prefix . $key;
- }
+ // Argument seperator
+ $separator = ini_get('arg_separator.output');
- if (is_scalar($val)) {
- array_push($tmp, urlencode($key).'='.urlencode($val));
- continue;
- }
+ // Start building the query
+ $tmp = array ();
+ foreach ($formdata as $key => $val) {
+ if (is_integer($key) && $numeric_prefix != null) {
+ $key = $numeric_prefix . $key;
+ }
- // If the value is an array, recursively parse it
- if (is_array($val)) {
- array_push($tmp, __http_build_query($val, urlencode($key)));
- continue;
- }
+ if (is_scalar($val)) {
+ array_push($tmp, urlencode($key).'='.urlencode($val));
+ continue;
}
- return implode($separator, $tmp);
+ // If the value is an array, recursively parse it
+ if (is_array($val)) {
+ array_push($tmp, Structures_DataGrid_http_build_query_helper($val, urlencode($key)));
+ continue;
+ }
}
- // Helper function
- function __http_build_query ($array, $name)
- {
- $tmp = array ();
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- array_push($tmp, __http_build_query($value, sprintf('%s[%s]', $name,
$key)));
- } elseif (is_scalar($value)) {
- array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key),
urlencode($value)));
- } elseif (is_object($value)) {
- array_push($tmp, __http_build_query(get_object_vars($value),
sprintf('%s[%s]', $name, $key)));
- }
+ return implode($separator, $tmp);
+}
+
+// Helper function
+function Structures_DataGrid_http_build_query_helper ($array, $name)
+{
+ $tmp = array ();
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ array_push($tmp, Structures_DataGrid_http_build_query_helper($value,
sprintf('%s[%s]', $name, $key)));
+ } elseif (is_scalar($value)) {
+ array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key),
urlencode($value)));
+ } elseif (is_object($value)) {
+ array_push($tmp, Structures_DataGrid_http_build_query_helper(get_object_vars($value),
sprintf('%s[%s]', $name, $key)));
}
+ }
- // Argument seperator
- $separator = ini_get('arg_separator.output');
+ // Argument seperator
+ $separator = ini_get('arg_separator.output');
- return implode($separator, $tmp);
- }
+ return implode($separator, $tmp);
}