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 ;
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 :Pok. 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;
} Code:
get_votes($time); get_new_stories($time); get_new_published($time); get_comments($time);
Code:
get_chat($time); get_votes($time); get_new_stories($time); get_new_published($time); get_comments($time);
add the user.php library
Code:
include(mnminclude.'user.php');
Code:
$login=$current_user->user_login;
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;
} Code:
var chat_url = '<?php echo my_base_url;?>'+'<?php echo my_pligg_base;?>/api/chattest.php';
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" /> <input type="submit" value="enviar" class="sendmessage"/></form>';
}
{/php} 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




Linear Mode




