my mod sneak.php + chat

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-2007, 03:53 PM
New Pligger
 
Join Date: Jan 2007
Posts: 11
ok people. in the last night i develope a mod that make the sneak.php a chat window just like the last version of meneame :P

so here is my mods.

first you need to add the next table to you database
Code:
CREATE TABLE `prefix_chat` (
  `chat_id` int(6) NOT NULL auto_increment,
  `chat_user_id` varchar(6) collate utf8_spanish_ci NOT NULL,
  `chat_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `chat_mensaje` varchar(70) collate utf8_spanish_ci NOT NULL,
  PRIMARY KEY  (`chat_id`),
  KEY `chat_time` (`chat_time`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci AUTO_INCREMENT=1 ;
of corse prefix is you prefix :P

then with this table created you need to do the right with sneaker.php .yersterday i discoveded (tanks kbeeveer46 ) sneaker is a feeder. this feeder send data to xhtml script in sneak.php :P

ok. in sneaker.php you need to add this funcion

Code:
function get_chat($time) {
	global $db,$events,$last_timestamp;
	$res = $db->get_results("select chat_id,chat_user_id,chat_mensaje , unix_timestamp(chat_time) as timestamp from ".table_chat." where  chat_time > from_unixtime($time) order by chat_time desc");
        if (!$res) return; 
	foreach ($res as $event) {
         	$id=$event->chat_id;
	 	$uid=$event->chat_user_id;
		$type='chat';
	 	$who=$db->get_var("select user_login from " . table_users . " where user_id = $event->chat_user_id ");
		$status = "publicado";
		$key=$event->timestamp . ':chat:'.$id;
		$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"1", link:"malapata", title:"'.$event->chat_mensaje.'", who:"'.$who.'", status:"'.$status.'", uid:"'.$uid.'"';
		//echo "($key)". $events[$key] ." ";
		if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
 	}
and in the start of the sneaker.php file you will see this section

Code:
get_votes($time);
get_new_stories($time);
get_new_published($time);
get_comments($time);
just add
Code:
get_chat($time);
get_votes($time);
get_new_stories($time);
get_new_published($time);
get_comments($time);
ok. now the sneak.php

add the user.php library

Code:
include(mnminclude.'user.php');
and at the end of all smarty functions add

Code:
$login=$current_user->user_login;
in the cdata secition add this function.

Code:
function send_chat(form) {
	var currentTime = new Date();
	if (busy) return false;
	busy=true;
	comment=form.comment.value;
	if (comment.length < 6){ alert ("minimo 6 caracteres");busy=false;return false;}
	if (comment.length > 70){ alert ("maximo 70 caracteres");busy=false;return false;}

	if (currentTime.getTime() < ultimoenvio + 10 * 1000) {alert("momento campeon esperate 10 segundos mas para poder enviar otro mensaje");busy=false;return false;}
	
		
	ultimoenvio = currentTime.getTime()
	url=chat_url+'?userid=<?echo $login ?>&mensaje='+comment;
	chatxml.open("GET",url,true);
	chatxml.send(null);
	form.comment.value="";
	busy=false;
        timer = setTimeout('get_data()', 3000)

return false;

}
in the var section of cdata add
Code:
var chat_url = '<?php echo my_base_url;?>'+'<?php echo my_pligg_base;?>/api/chattest.php';
also need to edit funcion to_html to prevent to make link of messages.

Code:
function to_html(data) {
	var ts=new Date(data.ts*1000);
	var timeStr;

	var hours = ts.getHours();
	var minutes = ts.getMinutes();
	var seconds = ts.getSeconds();

	timeStr  = ((hours < 10) ? "0" : "") + hours;
	timeStr  += ((minutes < 10) ? ":0" : ":") + minutes;
	timeStr  += ((seconds < 10) ? ":0" : ":") + seconds;

	html = '<div class="sneaker-ts">'+timeStr+'</div>';

	if (data.type == 'problem')
		html += '<div class="sneaker-type"><span class="sneaker-problem">'+data.type+'</span></div>';
	else if (data.type == 'new' || data.type == 'published')
		html += '<div class="sneaker-type"><strong>'+data.type+'</strong></div>';
	else
		html += '<div class="sneaker-type">'+data.type+'</div>';

	html += '<div class="sneaker-votes">'+data.votes+'</div>';
	
	if (data.type == 'chat')
	html += '<div class="sneaker-story">'+data.title+'</div>';
	else 
	html += '<div class="sneaker-story"><a href="<?php echo my_base_url.my_pligg_base; ?>/story.php?id='+data.link+'">'+data.title+'</a></div>';
	
	if (data.type == 'problem')
		html += '<div class="sneaker-who"><span class="sneaker-problem">'+data.who+'</span></div>';
	else if (data.uid > 0) 
		html += '<div class="sneaker-who"><a href="<?php echo my_base_url.my_pligg_base; ?>/user.php?login='+data.who+'">'+data.who+'</a></div>';
	else 
		html += '<div class="sneaker-who">'+data.who+'</div>';
	html += '<div class="sneaker-status">'+data.status+'</div>';
	return html;
}




now. add the file /api/chattest.php (the name can be changed :P)

Code:
<?
include('../config.php');
include(mnminclude.'user.php');
include(mnminclude.'html1.php');
$now = time();


force_authentication();

if (empty($_GET['userid']) || empty($_GET['mensaje']))
	{
		die;
	}

else {
	$id_usuario=$_GET['userid'];
	$user = $db->get_var("select user_id from " . table_users . " where user_login = '$id_usuario'");
	$mensaje=$_GET['mensaje'];
	$consulta="insert into catalog_chat ( chat_id , chat_user_id , chat_time , chat_mensaje) values (NULL,'".$user."',NOW(),'".addslashes($mensaje)."') ";
	$db->query($consulta);
}

?>

ok folks now the final part

in the sneak_center.tlp of your election. just add this just before the "div sneaker"

Code:
{php}
global $login;
if ($login=="") {
} else {
echo '<form name="chat_form" action="" onsubmit="return send_chat(this);">mensaje: <input type="text" name="comment" id="comment-input" value="" size="90" maxlength="230" autocomplete="off" />&nbsp;<input type="submit" value="enviar" class="sendmessage"/></form>';
}

{/php}
$login contain the $current_user data :P

ok people. i can explain all the changes if u want. but c&p in you files will work :P

just take a look. http://freakmachine.gotdns.org/sneak.php

this is the first beta beta beta version of corse chattest.php need more secure options may add the library and the function "$force_autentication()" will add the security what need :P


update- I found some bug . and add some security stuff (forcing autentication in chattest.php) chattest.php check the data before insert into database :P

seeya :P

-i actually named this mod - "live chat ver 0.2"
-i forget my edit of "to_html" in sneak.php ^^ sorry is posted now

update2- add the funcion "addslashes" into chattest.php . if you don't do that and a user send a messaje with " or ' can stop the funcion of live

Last edited by neoyagami; 02-10-2007 at 03:41 AM.
Reply With Quote
  #2 (permalink)  
Old 02-09-2007, 04:11 PM
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,215
I've tested this out and it's pretty cool. The "live" page turns into a chat and a "live" page. They both work together. As you chat the messages pop up and fade color. As you're chatting you can see all the other activity on the site.
Reply With Quote
  #3 (permalink)  
Old 02-09-2007, 04:21 PM
New Pligger
 
Join Date: Jan 2007
Posts: 11
in a future i will add the posibility of filter what you want to see

chat-votes-news-commens . isnt too dificult :P
Reply With Quote
  #4 (permalink)  
Old 08-07-2007, 11:32 PM
Constant Pligger
Pligg Version: Pligg 9.9
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Ottawa, Ontario
Posts: 146
Is this compatible with 9.7? Also is there a demo?

http://freakmachine.gotdns.org/sneak.php is offline.
Reply With Quote
  #5 (permalink)  
Old 08-20-2007, 07:58 AM
Casual Pligger
 
Join Date: Jul 2007
Posts: 60
wow.

any word on whether this is 9.7 ready? it sounds fun and i'm going to wind up testing it regardless within the next few days. BUT, if someone already knows the answer, i'd appreciate it.

Thx!
Reply With Quote
  #6 (permalink)  
Old 08-20-2007, 08:05 AM
dollars5's Avatar
Pligg Donor
 
Join Date: Dec 2006
Location: India
Posts: 1,960
It is a seperate mode and has to be installed following the above instructions. Not yet tested with 9.7 - you can feel free to test and let others know if it works on 9.7.
Reply With Quote
  #7 (permalink)  
Old 08-20-2007, 09:47 AM
Casual Pligger
 
Join Date: Jul 2007
Posts: 60
Thanks, dollars. I'll test it out with a friend sometime this week.
Reply With Quote
  #8 (permalink)  
Old 08-20-2007, 01:12 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
This concept would rock together with an who´s online mod!
Reply With Quote
  #9 (permalink)  
Old 08-20-2007, 03:54 PM
Casual Pligger
 
Join Date: Jul 2007
Posts: 60
ah, the ever-lusted for who's online mod . . .
Reply With Quote
  #10 (permalink)  
Old 08-20-2007, 07:04 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
kb,
Do you remember whether something like who´s chatting was visible except of the chat messages?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax Chat v0.2 for Pligg CMS 1.0 chuckroast Modules for Sale 3 12-17-2009 09:41 PM
can i integrate chat? sweinrib Questions and Comments 14 11-10-2008 04:18 PM
Is there a current chat box Mod? auctionguy Questions and Comments 3 04-17-2008 05:45 PM
Who´s online and logged chat tbones Questions and Comments 11 02-06-2008 09:39 AM
Open Source Chat Software TrailofDead Questions and Comments 0 03-06-2007 10:45 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development