TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 629
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 466
  • Total: 466

AJAX Chat

Started by Wantonio, May 08, 2007, 03:24:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Wantonio

From my point of view, I like it to view the DEMO first: 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

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)





IchBin

Also be aware, that ajax stuff like this is pretty taxing on a server. Thanks for the share.

RoarinRow


SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

tiochus

 :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?

G6Cad

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.

Crip

not very private --> eh??
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



tiochus

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.

Wantonio

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 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

tiochus

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:



bicho


This website is proudly hosted on Crocweb Cloud Website Hosting.