In the process of integrating phpFreeChat with a site that I'm working on, I think I found a few bugs. I'm using version 1.0 beta 3. The first batch of bugs is in "pfctools.php". The patch to apply my changes is:
- Code: Select all
--- phpfreechat-1.0-beta3.orig/src/pfctools.php 2006-07-03 08:20:40.000000000 -0500
+++ phpfreechat-1.0-beta3/src/pfctools.php 2006-07-16 21:31:43.000000000 -0500
@@ -64,14 +64,20 @@
$res = "";
//echo $p1."<br>";
//echo $p2."<br>";
- while( $p1 != "" && $p1 != "/" && strpos($p2, $p1) === FALSE)
+ while( $p1 != "" && $p1 != "/" && strpos($p2, $p1) !== 0)
{
$res .= "../";
$p1 = dirname($p1);
}
- $p2 = (isset($_SERVER["WINDIR"]) || isset($_SERVER["windir"])) ?
- str_replace("\","/",substr($p2, strlen($p1)+1, strlen($p2)-strlen($p1))) :
- substr($p2, strlen($p1)+1, strlen($p2)-strlen($p1));
+ if (isset($_SERVER["WINDIR"]) || isset($_SERVER["windir"])) {
+ $p2 = str_replace("\","/",substr($p2, strlen($p1)+1, strlen($p2)-strlen($p1)));
+ } else {
+ if ($p1 === "/" || $p1 === "") {
+ $p2 = substr($p2, strlen($p1));
+ } else {
+ $p2 = substr($p2, strlen($p1)+1);
+ }
+ }
$res .= $p2;
// remove the last "/"
if (preg_match("/.*/$/", $res)) $res = preg_replace("/(.*)//","$1",$res);
In the first diff section, the while loop looks like it was constructed to reduce $p1 until it shares a common beginning with $p2. However, this loop will end too early if $p1 happens to be contained in the middle of $p2. For example, if $p1 is "/var/www" and $p2 is "/usr/local/var/www/foo", the loop will end right away before the "../" string can be added to $res. Changing the loop predicate as shown fixes this.
In the second diff section, the main problem is that the code as originally written did not work when the paths did not share a common parent directory. For example, given my configuration $p1 was getting set to "/home/twm/www2/tmp/phpfreechat-1.0-beta3/timtest1.php" and $p2 was getting set to "/var/www/local/phpfreechat/data/public//themes". The returned value was "../../../../../ar/var/www/local/phpfreechat/data/public/themes" (note the missing "v"). The problem was that the paths don't share a common parent directory and so the substr() command cut off too much. My patch special cases this situation. I don't know if something similar may be needed for the Windows portion of the code (I only tested this on Linux).
I also removed the second argument to substr() since it was actually greater than the length of the string and not technically correct in that sense. That isn't critical though and it wasn't really hurting anything - it was mainly a touch up. The argument isn't needed since the entire remainder of the string is desired.
The other file that I patched on my installation was "pfcclient.js.tpl.php". Here is the patch:
- Code: Select all
--- phpfreechat-1.0-beta3.orig/themes/default/templates/pfcclient.js.tpl.php 2006-07-07 02:37:19.000000000 -0500
+++ phpfreechat-1.0-beta3/themes/default/templates/pfcclient.js.tpl.php 2006-07-16 22:10:16.000000000 -0500
@@ -1470,4 +1470,4 @@
};
-<?php include($c->getFileUrlFromTheme('templates/pfcclient-custo.js.tpl.php')); ?>
+<?php include($c->getFilePathFromTheme('templates/pfcclient-custo.js.tpl.php')); ?>
I hope that's right. Moving my "data/private" and "data/public" directories out from beneath the code tree did not fully work for me until I made this change, and it seems to make sense since I would expect include() to need a file path rather than a URL.
Thanks,
- Tim Macinta