I found a kludge that will accomplish this -- it's not pretty, and it doesn't fit well with the rest of the phpfreechat code, but it does work. The idea is to look for where the quit command is passed to Javascript, and hard-code an assignment to window.location within that. So, in data/public/js/pfcclient.js, look for the function handleResponse, and scroll down within that function until you find a snippet of code looking like this:
else if (cmd == "quit") { if (resp =="ok") { // stop updates this.updateChat(false); this.isconnected = false; this.refresh_loginlogout(); } }
In this, add a single line assigning your destination URL to window.location:
Now, any time you use /quit to exit, you will be sent to the URL. The redirection happens late enough in the process that the chat does register the quit command. Like I said, it isn't pretty, but it works.
I would very much like to be able to clean this up somehow, in particular by introducing a "redirect" parameter so that I can make the assignment $params["redirect"]="/your/url/here" in the chat script file, but I haven't been able to figure out how to program a custom parameter. Other posts have asked about custom parameters, too, so I will put my vote in for seeing some documentation on how to do that. The closest I have come is to get rid of the "invalid or obsolete parameter" error by introducing a "var $redirect;" statement in src/pfcglobalconfig.class, but I can't be sure that the value of $params["redirect"] is being assigned to $redirect, and I have no idea how to make sure the value gets passed to the Javascript code, where I would actually need it.
In case you are wondering, my application of this is to use it for password authentication -- the redirect when you logout takes you back to a login page. The login authentication I am using is based on the scripts at http://www.gidforums.com/t-887.html, using the password data from a MySQL database shared also by PunBB.
UPDATE: I kept plugging away at the custom parameter business, and I figured it out. Let me walk you through the steps -- it actually isn't that difficult, and can probably be applied to a lot of other problems:
Step 0: first of all, if you did what I suggested in the previous post, undo it -- remove that one line from data/public/js/pfcclient.js. It was a kludge anyway, and it will just get in the way now.
Step 1: OK, so now it's time to do the real work. Start with src/pfcglobalconfig.php -- you need to add the variable $redirect in the public parameters portion of the file. So where you see the line
var $serverid = '';
add the line
var $redirect = '';
immediately after. This will eliminate the "invalid or obsolete parameter" error, but will not get the value from $params["redirect"].
Step 2: So now it is time to get the value from $params["redirect"] into $redirect. The place to do that is in the constructor function pfcGlobalConfig($params), which you will note takes the $params array as a parameter. This function needs to do some initial setup before it is safe to set the $redirect variable. Look for the code snippet that looks like:
if (!isset($params["data_public_path"])) $this->data_public_path = dirname(__FILE__)."/../data/public"; else $this->data_public_path = $params["data_public_path"];
and immediately after it, add the following two lines:
if (isset($params["redirect"])) $this->redirect = $params["redirect"];
OK, now the value has been transfered from $params["redirect"] to $redirect.
Step 3: Now it is time to use the $redirect variable. Look in the file src/commands/quit.class.php, which is where the /quit command is defined. At the end of that file is the line:
This is where the call is made to the handleResponse() function in data/public/js/pfcclient.js, which is where my first post suggested making the modification. Instead, the change will be made in the string which is passed to the script() function in this line. In this file, the $redirect variable from the previous step can be referred to as $c->redirect. So replace this line with the following three lines:
$rs=''; if ($c->redirect!='') $rs='window.location="'.$c->redirect.'";'; $xml_reponse->script("pfc.handleResponse('quit', 'ok', '');".$rs);
This just appends the redirect command immediately after the call to handleResponse(), but includes a check to make sure that the redirect is a nonempty string. (You can probably also include a check that it is a valid URL, bit I didn't do that here.)
Step 4: Now you can make the change in the actual chat script page. Where you set all of your other parameters, include the following line:
$params["redirect"] = "/your/url/here";
You're done!
This does not use a callback, just a string parameter containing the URL, but you can probably modify this in some appropriate way to use a callback instead.
A slight improvement: Instead of the three lines given in Step 3 (starting with "$rs='';"), use the following two lines:
$xml_reponse->script("pfc.handleResponse('quit', 'ok', '');"); if ($c->redirect!='') $xml_reponse->redirect($c->redirect);
The line with the script() method call is now the same as the original, so starting from scratch, just add the second line. This should make it a bit more secure (I think the redirect() method includes a basic URL format check).