• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Bugs in pfctools.php and pfcclient.js.tpl.php (plus some fix

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
4 posts • Page 1 of 1

Postby macinta » Mon Jul 17, 2006 4:24 am

Hello,

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
macinta
New member
 
Posts: 5
Joined: Tue Jul 11, 2006 6:55 pm
Location: Boston, USA
  • Website
Top

Postby phpfreechat » Mon Jul 17, 2006 10:26 am

I will look at your patches soon.
But could you post your patches on sourceforge as explained in this post : http://www.phpfreechat.net/forum/viewtopic.php?id=471 ? It will be easier for me to work..
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby macinta » Mon Jul 17, 2006 2:10 pm

Hello,

Oops, I didn't see that post before. I've added the patches to SourceForge now at the following URLs:

http://sourceforge.net/tracker/index.ph ... tid=809603

http://sourceforge.net/tracker/index.ph ... tid=809603

Thanks,
- Tim Macinta
macinta
New member
 
Posts: 5
Joined: Tue Jul 11, 2006 6:55 pm
Location: Boston, USA
  • Website
Top

Postby phpfreechat » Mon Jul 17, 2006 3:39 pm

Thank you,
Your patches are now integrated to pfc source code.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top


Post a reply
4 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 7 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub