setting phpfreechat numeric parameters gives "negative value" error
permutations - May 7, 2008 - 10:31
| Project: | phpfreechat |
| Version: | 5.x-1.0-rc4 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
phpFreeChat checks that integer parameter values are greater than zero. But the Drupal forms system passes these values to phpFreeChat as strings, so they fail the test.
Here is the solution. Find the function phpfreechat_prepare_params() in phpfreechat.module. Just after the if statement for "Setup admins" and before the code to add user menu info, add this code:
foreach($params as $key => $value)
{
if (!is_array($value)) {
$integer_string = (preg_match("/[0-9]/", $value) && !preg_match("/[^0-9]/", $value)) ? true : false;
if ($integer_string) {
settype($value, "int");
}
}
}Sorry this isn't in patch format. I'll get a CVS account this weekend.

#2
I have a version of the phpFreeChat module on my Web site that fixes many different bugs. I just updated it today. If owahab makes me a module maintainer here on Drupal, I'll integrate the changes here and stop posting them separately:
http://permutations.com/drupal/phpfreechat.php
owahab - please stop deleting this link. It is not helpful to the community.
#3
I just uploaded a new version (http://permutations.com/drupal/phpfreechat.php).
I backed out setting the default timeout to 35000 in the module. It's not working because the "negative number" error is still happening after clearing the cache (/rehash). The timeout needs to be changed to avoid disconnects, and the easiest way to do this is to change it directly in pfcglobalconfig.class.php. phpFreeChat has an integer check in there, and Drupal's form API doesn't have an integer type. I tried to identify the integer strings and change them and it worked in a test file, but not in the module.
pfcglobalconfig.class.php is in the phpFreeChat src directory (it's not a module file).
To change the default timeout, find this variable assignment and change the 20000 to 35000:
var $timeout = 35000;To get rid of the negative number error, comment out this code in pfcglobalconfig.class.php:
/*$numerical_positive_params = $this->_params_type["positivenumeric"];
foreach( $numerical_positive_params as $npp )
{
if (!is_int($this->$npp) || $this->$npp < 0)
$this->errors[] = _pfc("'%s' parameter must be a positive number", $npp);
}
*/
#4
A version that solves the problem without having to edit phpFreeChat has just been uploaded (1.2).