TinyPortal

Development => Block Codes => Topic started by: Wantonio on May 08, 2007, 03:24:47 AM

Title: AJAX Chat
Post by: Wantonio on May 08, 2007, 03:24:47 AM
From my point of view, I like it to view the DEMO first: http://www.kulturwochenende.com (http://www.kulturwochenende.com)

This is the code for the block and the files you need for a real AJAX Chat.
So, your portal needs no more refreshes.

Things to do:

1. Create a new block (centered block and phpbox)

2. Fill this block with this code (and edit the "your-url/chat.js" line):

$chatuser=$context["user"]["name"];

echo "<input  type=\"hidden\" id=\"chatnick\" name=\"chatnick\" value=\"$chatuser\">";

echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\"  cellspacing=\"0\"><tr><td width=\"99%\"><input id=\"chatmsg\" name=\"chatmsg\" type=\"text\" style=\"width:99%\" onkeyup=\"keyup(event.keyCode);\"></td><td width=\"1%\"><input type=\"button\" value=\"Chat\" onclick=\"submit_msg();\"></td></tr></table>";

echo "<div id=\"chatwindow\" style=\"margin-top:3px; width:100%; height:150px; overflow:scroll; border: 1px none #000000; background-color: #FFFFFF; layer-background-color: #FFFFFF;\"></div>";

echo "<script type=\"text/javascript\" src=\"http://your-url/chat.js\"></script>";


3. Download: http://www.janwerthmann.de/web/ajax_chat.zip (http://www.janwerthmann.de/web/ajax_chat.zip)

4. Search in the file chat.js for "www.kulturwochenende.com/forum/" and replace it with your URL.

5. Extract the folder and upload the single files to the folder where the index.php is.

6. Edit the w.php file. The comments are only in German, sorry. But when you're fit in php, you'll find it out. The nicknames between line 114 and 138 are nicks from my friends and when they submit a post, a special color will be posted.

7. But be careful... This was a quick work and take care of the security...

Please write me for security-updates or if you need support!

This work based on the scripts from chris (chris at linuxuser dot at)
most simple ajax chat script (www.linuxuser.at) (GPLv2)




Title: Re: AJAX Chat
Post by: IchBin on May 08, 2007, 03:39:29 AM
Also be aware, that ajax stuff like this is pretty taxing on a server. Thanks for the share.
Title: Re: AJAX Chat
Post by: RoarinRow on May 08, 2007, 04:37:41 AM
Looks cool!   8)
Title: Re: AJAX Chat
Post by: tiochus on May 09, 2007, 09:28:10 AM
 :up: Good job! I've been testing it and I've changed the parameter in .js which makes it to display last post on bottom instead of top, but when it reachs the number of posts which activates the scroll bars, the last post is written out of the window. Is there a way to automatically go to the last post in this way?


Thanks for this!

Quote from: IchBinâ„¢ on May 08, 2007, 03:39:29 AM
Also be aware, that ajax stuff like this is pretty taxing on a server.

Do you mean the amount of data per month to transfer?
Title: Re: AJAX Chat
Post by: G6Cad on May 09, 2007, 09:34:50 AM
Yes, the AJAX is using a lot of resources both BW and MEM CPU, so many shared hosting services can complain a lot about it and i have even heard and read of sites being closed down for some members.
Title: Re: AJAX Chat
Post by: Crip on May 09, 2007, 10:36:17 AM
not very private --> eh??
Title: Re: AJAX Chat
Post by: tiochus on May 15, 2007, 06:46:48 PM
One more question: I'm using it on a spanish board and we use "special" characters like á é í ñ and so more, I've seen that the script saves it on the chat.txt correctly but when they aere displayed this characters are replaced whith this other ?, anyone knows how to fix it?

Thanks.
Title: Re: AJAX Chat
Post by: Wantonio on May 16, 2007, 12:47:20 AM
Quote from: crip~ on May 09, 2007, 10:36:17 AM
not very private --> eh??
You can change this in the administation-center. For demonstration it's open for everyone at my website.




Quote from: tiochus on May 15, 2007, 06:46:48 PM
One more question: I'm using it on a spanish board and we use "special" characters like á é í ñ and so more, I've seen that the script saves it on the chat.txt correctly but when they aere displayed this characters are replaced whith this other ?, anyone knows how to fix it?

Thanks.

Open the file w.php and search for this:

$out = str_replace("ä", "&auml;", $out);
$out = str_replace("ä", "&Auml;", $out);
$out = str_replace("ü", "&uuml;", $out);
$out = str_replace("ÃÅ"", "&Uuml;", $out);
$out = str_replace("ö", "&ouml;", $out);
$out = str_replace("ö", "&Ouml;", $out);
$out = str_replace("ß", "&szlig;", $out);


You can add here your own special characters. This site (http://www.webmonkey.com/webmonkey/reference/special_characters/) gives you a survey of special characters.
For example, if you want to add the ñ,  you have to add:
$out = str_replace("ñ", "&ntilde;", $out);

Greetz
Title: Re: AJAX Chat
Post by: tiochus on May 16, 2007, 09:02:44 AM
Thank you very much. I've added the new characters and it works perfectly.  :up:
I soupossed I have to make changes in this portion of code, but as I was not sure....  :smiley6600:

Thanks  :coolsmiley:


Title: Re: AJAX Chat
Post by: bicho on May 16, 2007, 03:31:15 PM
very good mod!
Title: Re: AJAX Chat
Post by: glx on May 16, 2007, 07:58:09 PM
So I've put it on my server, but it's a little broken.  For whatever reason it only shows the last line that was typed, not everything (should show the last 20 lines according to the variable).  Any ideas?
Title: Re: AJAX Chat
Post by: Wantonio on May 17, 2007, 12:12:18 PM
Send me the URL and I will have a look!
Title: Re: AJAX Chat
Post by: tiochus on May 18, 2007, 09:35:14 AM
Is there an easy way to use any function which could regconize BBC codes like the shoutbox to display it in this mod?
I think shoutbox function to do this is tp_doUBBC. Could it be possible?

??? ???

Thanks.
Title: Re: AJAX Chat
Post by: Solomon on May 25, 2007, 03:01:06 PM
Thanks  :up:

I have placed it in a centre block, within a board which has restricted access. Good security that way.
Title: Re: AJAX Chat
Post by: katoona on June 04, 2007, 12:01:45 PM
Great script  ;D

One problem for me - I need to be able to use norwegian letters (utf-8).

Do you know how I can fix this - I guess I need to add something in th .js file.

Title: Re: AJAX Chat
Post by: Wantonio on June 04, 2007, 12:21:37 PM
Yes, look here (http://www.tinyportal.net/index.php?topic=15772.msg132692#msg132692)  ;)
There it is explained for spanish characters
Greetz
Title: Re: AJAX Chat
Post by: katoona on June 04, 2007, 12:46:41 PM
Lol, should have seen this fix.

Thanks.
Title: Re: AJAX Chat
Post by: katoona on June 04, 2007, 12:49:58 PM
My Chat shows the time 2 hours ahead, is there any way I can adjust the time by 2 hours?

Probably an easy fix but I am blind today.  ;D
Title: Re: AJAX Chat
Post by: Wantonio on June 04, 2007, 03:16:22 PM
QuoteMy Chat shows the time 2 hours ahead, is there any way I can adjust the time by 2 hours?

Open the file w.php

Search for the line:
$uhrzeit = "[".date("H:i")."] ";

Replace it with:
$twohoursback = time()-7200;
$uhrzeit = "[".date("H:i", $twohoursback)."] ";


That should work  :)
Title: Re: AJAX Chat
Post by: katoona on June 04, 2007, 07:39:47 PM
Yes it worked, Thank you.  ;D

Is it possible to use any kind of smilies with this script?
Title: Re: AJAX Chat
Post by: Wantonio on June 05, 2007, 04:29:04 PM
Yes, sure...  :)

An easy way to replace ":)" with a smiley is the following:

1. Open the file w.php
2. Insert the line:
$out = str_replace(":)", "<img src='http://www....your_webspace.../smile.gif' />", $out);

Feel free to program your own features.
For example you can add the smileys under the input-field and make them clickable.
Or you can add a checkbox for "Show smileys"

If I have time enough, I will code a more exclusiv Chat with more security and more features.
Besides I don't like it, that the chat reloads every time when you open a new page.

Perhaps I should make a ToDo-List :)
Title: Re: AJAX Chat
Post by: katoona on June 05, 2007, 06:18:31 PM
QuoteFor example you can add the smileys under the input-field and make them clickable.
Or you can add a checkbox for "Show smileys"

Do you know how to do this? I am still a newbie but I am trying to learn.

Great support on this forum.  ;)
Title: Re: AJAX Chat
Post by: Wantonio on June 05, 2007, 06:26:47 PM
Yes, I know.

Showing the Smileys under the input-field should be no problem.
Then you have to write a javascript, which inserts automatically something like ":smile:" in the input-field when you click on it.
After that you have to insert:
$out = str_replace(":smile:", "<img src='http://www....your_webspace.../smile.gif' />", $out);

That's all
Title: Re: AJAX Chat
Post by: katoona on June 05, 2007, 07:33:06 PM
Ok, thanks.

I don't think that I will be able to write this javascript, but I understand for you are saying perfectly.

Is is a lot of code that will be needed in the .js, or is it just a few sentences?

Title: Re: AJAX Chat
Post by: espiman on June 07, 2007, 11:24:03 PM
Hello.

First of all, sorry for my English, iÃ,´m spanish  ;D

I have the Ajax Chat in a center block, and all is ok, but if I added a block news before, in Internet Explorer only view one line of chat, but in Mozilla Firefox view all lines correctly. If the chat block is in the top of center blocks, all is ok.

Thanks.
Title: Re: AJAX Chat
Post by: Wantonio on June 08, 2007, 12:30:01 AM
Tomorrow I'm having an important presentation, but I promise, that I'll take care of it after that ;)
Title: Re: AJAX Chat
Post by: katoona on June 08, 2007, 12:45:41 AM
I have a center block over the center block which contains the AJAX Chat, and it works in all browsers for me. I understand that this is not helping, but which IE version do you have?
Title: Re: AJAX Chat
Post by: espiman on June 08, 2007, 05:47:27 AM
Quote from: katoona on June 08, 2007, 12:45:41 AM
I have a center block over the center block which contains the AJAX Chat, and it works in all browsers for me. I understand that this is not helping, but which IE version do you have?

IE 7, thanks

Quote from: Wantonio on June 08, 2007, 12:30:01 AM
Tomorrow I'm having an important presentation, but I promise, that I'll take care of it after that ;)

   
good luck with your presentation and thanks for help me
Title: Re: AJAX Chat
Post by: katoona on June 08, 2007, 01:10:56 PM
The only browser I do not have is IE7.0, so perhaps I have the same problem without knowing it.

Title: Re: AJAX Chat
Post by: espiman on June 11, 2007, 03:32:15 PM
Wantonio, any idea?

Thanks
Title: Re: AJAX Chat
Post by: Wantonio on June 12, 2007, 12:33:18 AM
Hi!
Sorry for not saying hello for the last days, anyway I didn't forget the topic...

I read (http://www.tinyportal.net/index.php?topic=14292.0), that we should better write in the Request-Child-Board for support.
So please open a new topic here (http://www.tinyportal.net/index.php?board=133.0) for further requests, with the subject: "AJAX Chat"!

But now, to espimans question. I tested your situation in my forum respectively portal and I got no errors with IE7. This must be a special problem, I suppose, but if you set up a guest-account for me in your portal or if you post a screenshot, this would be very helpful.

The next days I'm in Hamburg and Stuttgart, but I will do what I can  ;) So please don't expect fast support from my side. You can also contact me via PM.

PS: By the way I have detected a very courious thing. My news - within a newsblock - are only visible for me as admin and not for others, but that's another problem...


Title: Re: AJAX Chat
Post by: pheadrus on July 13, 2007, 05:43:27 AM
For turkish characters use:

$out = str_replace("ü", "&uuml;", $out);
$out = str_replace("ÃÅ"", "&Uuml;", $out);
$out = str_replace("ö", "&ouml;", $out);
$out = str_replace("ö", "&Ouml;", $out);
$out = str_replace("Ã...ž", "Ş", $out);
$out = str_replace("ÅŸ", "ş", $out);
$out = str_replace("İ", "İ", $out);
$out = str_replace("ÄŸ", "ğ", $out);
$out = str_replace("Ã,,ž", "Ğ", $out);
$out = str_replace("ç", "&Ccedil;", $out);
$out = str_replace("Ç", "&ccedil;", $out);

in w.php
Title: Re: AJAX Chat
Post by: katoona on August 18, 2007, 10:35:22 PM
Anyone know how (if possible) I can make links clickable when writing a url with the Ajax Chat.

It refreshes so often that it is sometimes a little difficult to copy and paste a link. I know I can reduce refresh time, but dont want to.

Title: Re: AJAX Chat
Post by: Chanceler on August 19, 2007, 10:42:38 PM
From the example it appeared flawed as in I could easily fake the Admin's ID and the name was even red as if I were actually an admin.

Yours,
The one and only,
~Chanceler~