Re: Need some help diagnosing functions_general,php errors
I had one last idea before shutting down
PHP Code:
// bof dynamic filter 1 of 3
if ( (!in_array($key, $exclude_array)) && (strlen((int)$value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
I added (int) to the strlen and it seems to do the job, but I am no expert.
p.s. I wasn't getting any errors at first because I made some other stupid mistake. after fixing that the errors started coming in :blush: until I added the int
Re: Need some help diagnosing functions_general,php errors
PHP Code:
if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
The statement is testing conditions for some situation, based on $key which stands for the name of the current array-item key in the array being evaluated, and $value which holds the value of the current key.
Breaking down the statement,
if ( (!in_array($key, $exclude_array))
---> the key is not in a list of keys to exclude,
&& (strlen($value) > 0 || is_array($value) && array_filter($value) )
---> and the value is a string that is longer than '' (empty or blank) or the value is an array and this filter applied to it gives "true' or a positive result
&& ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
---> and the key is not one of these names.
Apparently $value should not be an array if the key passes the "exclude" test. Casting it to int seems to make it safe, but destroys the test's value (unless it is a string starting with a number, it will be viewed as 0 (zero)); casting it to string will keep the information if it is a string, and hopefully make it safe if it is an array.
Best would be to find out why it is being an array when it apparently should not, and fixing that, or testing for it being an array and handling it appropriately if it is.
Re: Need some help diagnosing functions_general,php errors
PHP Code:
&& (strlen($value) > 0 || is_array($value) && array_filter($value) )
could be rewritten as
PHP Code:
&& (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) )
Re: Need some help diagnosing functions_general,php errors
Perhaps the version of functions_general you're using is based on old code?
http://www.zen-cart.com/showthread.p...09#post1136209
Re: Need some help diagnosing functions_general,php errors
Thanks very much. Speak soon :-)
Re: Need some help diagnosing functions_general,php errors
Wow loads of ideas, just replied to what I thought was te last post then boom all of a sudden I had all these great suggestions.
Now @Design75 did your fix work? Does it work when applying a filter and then going to the second page of te filter results
@gjh42 I will try your suggestion also thanks for your input, and thank you for explaining the code :-)
@DrByte how can I incorporate that fix with the dynamic filter code?
Thanks all
Re: Need some help diagnosing functions_general,php errors
Quote:
Originally Posted by
philip937
Wow loads of ideas, just replied to what I thought was te last post then boom all of a sudden I had all these great suggestions.
Now @Design75 did your fix work? Does it work when applying a filter and then going to the second page of te filter results
@gjh42 I will try your suggestion also thanks for your input, and thank you for explaining the code :-)
@DrByte how can I incorporate that fix with the dynamic filter code?
Thanks all
Wow indeed ;)
@philip937: My fix worked, but gjh42 is better. Like he said, my fix always assumes an integer, which may not be the case.
@gjh42 :thumbsup: thank you for the lesson:smartalec:, like said before. I am learning PHP bit by bit. Everyday I am understanding a little more.
@DrByte, I am using the functions_general.php that came with ZC 1.5.1, and merged the dynamic filter code in to it.
This is how the merged result looks like, including Glenn's fix.
PHP Code:
function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
$get_url = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
reset($_GET);
while (list($key, $value) = each($_GET)) {
// bof dynamic filter 1 of 3
if ( (!in_array($key, $exclude_array)) && (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
// bof dynamic filter 2 of 3
if (is_array($value)) {
foreach($value as $arr){
$get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
}
} else {
// eof dynamic filter 2 of 3
$get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
}
// eof dynamic filter 3 of 3
}
}
}
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
return $get_url;
}
Re: Need some help diagnosing functions_general,php errors
Thanks guys, just got to work so will have to test later this evening on my set up.
Many many many thanks :)
Re: Need some help diagnosing functions_general,php errors
Quote:
Originally Posted by
Design75
Wow indeed ;)
@philip937: My fix worked, but gjh42 is better. Like he said, my fix always assumes an integer, which may not be the case.
@gjh42 :thumbsup: thank you for the lesson:smartalec:, like said before. I am learning PHP bit by bit. Everyday I am understanding a little more.
@DrByte, I am using the functions_general.php that came with ZC 1.5.1, and merged the dynamic filter code in to it.
This is how the merged result looks like, including Glenn's fix.
PHP Code:
function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
$get_url = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
reset($_GET);
while (list($key, $value) = each($_GET)) {
// bof dynamic filter 1 of 3
if ( (!in_array($key, $exclude_array)) && (is_string($value) && strlen($value) > 0 || is_array($value) && array_filter($value) ) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
// eof dynamic filter 1 of 3
// bof dynamic filter 2 of 3
if (is_array($value)) {
foreach($value as $arr){
$get_url .= zen_sanitize_string($key) . '[]=' . rawurlencode(stripslashes($arr)) . '&';
}
} else {
// eof dynamic filter 2 of 3
$get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
// bof dynamic filter 3 of 3
}
// eof dynamic filter 3 of 3
}
}
}
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
return $get_url;
}
LOVE YOU ALL!!!! SORTED. :hug:
Re: Need some help diagnosing functions_general,php errors
Quote:
Originally Posted by
gjh42
&& ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
---> and the key is not one of these names.
... and that part is fully redundant because the test for $exclude_array already handles those names.