cvs: pear /Structures_DataGrid/DataGrid Renderer.php

From: Date: Tue, 20 Jun 2006 20:11:00 +0000
Subject: cvs: pear /Structures_DataGrid/DataGrid Renderer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-40844@lists.php.net to get a copy of this message
wiesemann Tue Jun 20 20:11:00 2006 UTC Modified files: /pear/Structures_DataGrid/DataGrid Renderer.php Log: - use native http_build_query() if PHP 5 is installed http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/Renderer.php?r1=1.51&r2=1.52&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer.php diff -u pear/Structures_DataGrid/DataGrid/Renderer.php:1.51 pear/Structures_DataGrid/DataGrid/Renderer.php:1.52 --- pear/Structures_DataGrid/DataGrid/Renderer.php:1.51 Mon Jun 19 18:07:24 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer.php Tue Jun 20 20:10:59 2006 @@ -17,7 +17,7 @@ // | Olivier Guilyardi <olivier@samalyse.com> | // +----------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.51 2006/06/19 18:07:24 olivierg Exp $ +// $Id: Renderer.php,v 1.52 2006/06/20 20:10:59 wiesemann Exp $ /** * Base class of all Renderer drivers @@ -97,7 +97,7 @@ * - extraVars * - excludeVars * - * @version $Revision: 1.51 $ + * @version $Revision: 1.52 $ * @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(Structures_DataGrid_http_build_query($get),ENT_QUOTES, - $this->_options['encoding']); + $query = htmlentities(http_build_query($get),ENT_QUOTES, + $this->_options['encoding']); } else { - $query = Structures_DataGrid_http_build_query($get); + $query = http_build_query($get); } return $query; @@ -928,69 +928,83 @@ } // This function is here because we can't depend on PHP_Compat -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); - } +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); + } - // 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; - } + // 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; + } - // 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'); + if (strlen($separator) == 0) { + $separator = '&'; + } + + // Start building the query + $tmp = array (); + foreach ($formdata as $key => $val) { + if (is_null($val)) { + continue; + } - // Argument seperator - $separator = ini_get('arg_separator.output'); + if (is_integer($key) && $numeric_prefix != null) { + $key = $numeric_prefix . $key; + } - // Start building the query - $tmp = array (); - foreach ($formdata as $key => $val) { - if (is_integer($key) && $numeric_prefix != null) { - $key = $numeric_prefix . $key; - } + if (is_scalar($val)) { + array_push($tmp, urlencode($key) . '=' . urlencode($val)); + continue; + } - if (is_scalar($val)) { - array_push($tmp, urlencode($key).'='.urlencode($val)); - continue; - } + // If the value is an array, recursively parse it + if (is_array($val) || is_object($val)) { + array_push($tmp, http_build_query_helper($val, urlencode($key))); + continue; + } - // 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; + // The value is a resource + return null; } - } - return implode($separator, $tmp); -} + 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))); + // Helper function + function http_build_query_helper($array, $name) + { + $tmp = array (); + foreach ($array as $key => $value) { + if (is_array($value)) { + array_push($tmp, 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, 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'); + if (strlen($separator) == 0) { + $separator = '&'; + } - return implode($separator, $tmp); + return implode($separator, $tmp); + } } - ?>

« previous php.pear.cvs (#40844) next »