Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chat Quest2 1

Status
Not open for further replies.

MAWarGod

Programmer
Feb 15, 2002
352
US
the other day I was searching for a examples and I came across a old thread I started trying to make a chat script..


The thread was closed so I couldn't ask My question there..
in the thread jpadie shared a script with me..
ChatRoomServer.php
Code:
<?php
$chat = new chats;

class chats{

    private $timestamp = 0;
    private $action;
    
    function chats(){

        $this->timestamp = time();
        $dbserver = mysql_connect('localhost', 'mychat', 'mychat') or die('error');
@mysql_select_db('mychat',$dbserver) or die('error');
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
    
    function switchBoard(){
        switch ($this->action){
            case 'writeChatData':
                if ($this->writeChatData()){
                    echo '1';
                } else {
                    echo '0';
;                }
            break;
            default:
                echo $this->getChatData();
        }    
    }
    
    function getChatData(){
        $return ='';
        $timestamp = isset($_POST['timestamp']) ? $_POST['timestamp'] : 0;
        if ($timestamp == 'null') $timestamp = 0;
        $query = "Select chatID, chatPerson, chatTimestamp, chatText from chat where chatTimestamp > ? order by chatTimestamp DESC limit 50 ";
        $stmnt = $this->pdo->prepare($query);
        $stmnt->execute(array($timestamp));
        $chats = $stmnt->fetchAll();
        foreach ($chats as $chat){
            $date = date('Y-m-d H:i:s', $chat['chatTimestamp']);
            $chatText = nl2br($chat['chatText']);
            $return .= <<<HTML
<tr>
    <td id="{$chat['chatID']}">{$chat['chatPerson']}<br/>$date</td>
    <td>{$chatText}</td>
</tr>
HTML;
        }
        if (empty($return)){
            return 'none';
        } else {
            return json_encode(array('timestamp'=>$this->timestamp,'chatText'=>$return));
        }
    }
    
    function writeChatData(){
        $chatPerson = empty($_POST['chatPerson']) ? NULL : trim($_POST['chatPerson']);
        $chatText = empty($_POST['chatText']) ? NULL : trim($_POST['chatText']);
        if (empty($chatText) || empty($chatPerson)){
            return false;
        } else {
            if (get_magic_quotes_gpc()){
                $chatPerson = stripslashes($chatPerson);
                $chatText = stripslashes($chatText);
            }
            $query = "Insert into chat (chatTimestamp, chatPerson, chatText) values (?,?,?)";
            $stmnt = $this->pdo->prepare($query);
            if ($stmnt){
                $stmnt->execute(array(time(), $chatPerson, $chatText));
            } else {
                print_r($this->pdo->errorInfo());
            }
            if ($stmnt !== false){
                return true;
            } else {
                return false;
            }
        }
    }
    
    function createDatabaseSchema(){
        $query = "    create table 
                    chat
                    (
                    chatID integer NOT NULL PRIMARY KEY AUTOINCREMENT,
                    chatTimestamp integer NOT NULL,
                    chatPerson text NOT NULL,
                    chatText varchar NOT NULL
                    )";
        $this->pdo->exec($query);
    }
}
?>
ChatRoomServer.js
Code:
var timer = null;
var chatTable;
var timestamp = null;
var xo = null;
var url = 'chatRoomServer.php';

function createObject(){
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        xo = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        xo = new XMLHttpRequest();
    }
    
}
function updateChatRoom(){
    if (!xo) {createObject();}
    xo.onreadystatechange = function () {
            if (xo.readyState == 4) {
                if (xo.status == 200) {
                    if(xo.responseText == 'none'){
                        //do nothing
                    } else {
                        var rObj = eval('(' + xo.responseText + ')');
                        timestamp = rObj.timestamp;
                        //console.log('timestamp is '+ timestamp);
                        displayUpdatedChats(rObj.chatText)
                    }
                }
            }
        };
    try {
        xo.open("POST",url, true);
        } catch (e) {    
        console.log('problem in open command') ;
    }
    try {
        xo.setRequestHeader("Content-type", "application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
        xo.send('action=getChatData&timestamp='+timestamp);
    } catch (E) {
        console.log('problem retrieving new chats');
    }
}
function displayUpdatedChats(txt){
    chatTable.innerHTML = txt + chatTable.innerHTML;
}

function sendChat(){
    var cP = document.getElementById('chatPerson');
    var cT = document.getElementById('chatText');
    var chatPerson = cP.value;
    var chatText =  cT.value;
    var data = "action=writeChatData&chatPerson="+chatPerson+"&chatText="+chatText;
    if (!xo) {createObject();}
    xo.onreadystatechange = function () {
            if (xo.readyState == 4) {
                if (xo.status == 200) {
                    if(xo.responseText == '0'){
                        console.log ('problem saving chat data');
                    } else {
                        //cP.value = '';
                        cT.value = '';
                    }
                }
            }
        };
    try {
        xo.open("POST", url, true);
        } catch (e) {    
        console.log('problem in open command') ;
    }
    try {
        xo.setRequestHeader("Content-type", "application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
        xo.send(data);
    } catch (E) {
        console.log('problem sending data');
    }
    return false;
}
window.onload = function(){
    chatTable = document.getElementById('chatTable');
    timer = setInterval(updateChatRoom, 5000);
};
index.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script src="chatRoomServer.js"></script>
        <title>Chat Room</title>
    </head>
    <body>
        <div id="chatForm">
            
                Your Name: <input type="text" name="chatPerson" id="chatPerson"/><br/>
                Message: <textarea name="chatText" id="chatText"></textarea><br/>
                <input type="button" name="submit" value="Chat" onclick="sendChat();"/>
        
        </div>
        <div id="chatDiv">
            <table id="chatTable" border="1">
                
            </table>
        </div>
    </body>
</html>

Now I did change the function chats
from
Code:
    function chats(){
        require 'databaseConfig.txt';
        $this->timestamp = time();
        mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die (mysql_error());
        mysql_select_db(DATABASENAME);
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
to
Code:
    function chats(){

        $this->timestamp = time();
        $dbserver = mysql_connect('localhost', 'mychat', 'mychat') or die('error');
@mysql_select_db('mychat',$dbserver) or die('error');
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
and it is connecting and passing variables to the Database but the chat is not returning the results to the page?.. what have I missed?

I should mention I am using xamp as a local host..

MA WarGod

I believe if someone can think it, it can be programmed
 
there is a mixture of native mysql and PDO in there. which probably won't work.

why are you mixing them up? i posted a pure mysql soln in that old thread. and a pure PDO.sqlite one on the old server (which is no longer available but i might be able to find in an archive somewhere).

 
well to be honest I don't understand the PDO.sqlite or even how to set it up..

Code:
<?php
$chat = new chats;

class chats{

    private $timestamp = 0;
    private $action;
    
    function chats(){
        $this->timestamp = time();
       $dbserver = mysql_connect('localhost', 'mychat_user', 'mypw') or die('error');
@mysql_select_db('mychat',$dbserver) or die('error');
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
    
    function switchBoard(){
        switch ($this->action){
            case 'writeChatData':
                if ($this->writeChatData()){
                    echo '1';
                } else {
                    echo '0';
;                }
            break;
            default:
                echo $this->getChatData();
        }    
    }
    
    function buffer(& $result){
        $temp = array();
        while ($row = myqsl_fetch_assoc($result)){
            $temp[] = $row;
        }
        return $temp;
    }
    
    function getChatData(){
        $return ='';
        $timestamp = isset($_POST['timestamp']) ? $_POST['timestamp'] : 0;
        if ($timestamp == 'null') $timestamp = 0;
        $query = "Select chatID, chatPerson, chatTimestamp, chatText from chat where chatTimestamp > ? order by chatTimestamp DESC limit 50 ";
        $result = mysql_query($query) or die(mysql_error());
        $chats = buffer($result);
        foreach ($chats as $chat){
            $date = date('Y-m-d H:i:s', $chat['chatTimestamp']);
            $chatText = nl2br($chat['chatText']);
            $return .= <<<HTML
<tr>
    <td id="{$chat['chatID']}">{$chat['chatPerson']}<br/>$date</td>
    <td>{$chatText}</td>
</tr>
HTML;
        }
        if (empty($return)){
            return 'none';
        } else {
            return json_encode(array('timestamp'=>$this->timestamp,'chatText'=>$return));
        }
    }
    
    function writeChatData(){
        $chatPerson = empty($_POST['chatPerson']) ? NULL : trim($_POST['chatPerson']);
        $chatText = empty($_POST['chatText']) ? NULL : trim($_POST['chatText']);
        if (empty($chatText) || empty($chatPerson)){
            return false;
        } else {
            $query = "Insert into chat (chatTimestamp, chatPerson, chatText) values ('%s','%s','%s')";
            $params = array(time(), $chatPerson, $chatText);
            array_walk($params, 'mysql_real_escape_string');
            $query = vsprintf($query, $params);
            $result = mysql_query($query);
            if (!$result){
                echo mysql_error();
                return false;
            }
            return true;
            
        }
    }
    
    function createDatabaseSchema(){
        $query = "    CREATE TABLE  chat (
                             chatID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                             chatTimestamp INT( 11 ) NOT NULL ,
                             chatPerson VARCHAR( 255 ) NOT NULL ,
                             chatText LONGTEXT NOT NULL
                            ) ;
                    )";
        mysql_query($query);
    }
}
?>
not sure how I mismatched that but I posted it wrong I see..what I am using is above
I went and signed up for a free host to test this I thought was my xamp but still having the same issue..


it is passing to DB and saving, but its not showing in div?

MA WarGod

I believe if someone can think it, it can be programmed
 
there are two errors in the above script.
1. in line 28 there is a superfluous semi-colon.
2. in line 49 the code
Code:
        $chats = [red]$this->[/red]buffer($result);

should be changed as shown in red
 
Ok I corrected those. but still having a issue

[10-Oct-2011 12:38:37] PHP Warning: mysql_real_escape_string() expects parameter 2 to be resource, integer given in /the_path/chatRoomServer.php on line 75

from my errorlog

line 75
Code:
            array_walk($params, 'mysql_real_escape_string');

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
<?php
$chat = new chats;

class chats{

    private $timestamp = 0;
    private $action;
    
    function chats(){
        $this->timestamp = time();
       $dbserver = mysql_connect('localhost', 'htmlland_user', '1qaz2wsx') or die('error');
@mysql_select_db('htmlland_db101',$dbserver) or die('error');
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
    
    function switchBoard(){
        switch ($this->action){
            case 'writeChatData':
                if ($this->writeChatData()){
                    echo '1';
                } else {
                    echo '0';
                }
            break;
            default:
                echo $this->getChatData();
        }    
    }
    
    function buffer(& $result){
        $temp = array();
        while ($row = myqsl_fetch_assoc($result)){
            $temp[] = $row;
        }
        return $temp;
    }
    
    function getChatData(){
        $return ='';
        $timestamp = isset($_POST['timestamp']) ? $_POST['timestamp'] : 0;
        if ($timestamp == 'null') $timestamp = 0;
        $query = "Select chatID, chatPerson, chatTimestamp, chatText from chat where chatTimestamp > ? order by chatTimestamp DESC limit 50 ";
        $result = mysql_query($query) or die(mysql_error());
        $chats = $this->buffer($result);
        foreach ($chats as $chat){
            $date = date('Y-m-d H:i:s', $chat['chatTimestamp']);
            $chatText = nl2br($chat['chatText']);
            $return .= <<<HTML
<tr>
    <td id="{$chat['chatID']}">{$chat['chatPerson']}<br/>$date</td>
    <td>{$chatText}</td>
</tr>
HTML;
        }
        if (empty($return)){
            return 'none';
        } else {
            return json_encode(array('timestamp'=>$this->timestamp,'chatText'=>$return));
        }
    }
    
    function writeChatData(){
        $chatPerson = empty($_POST['chatPerson']) ? NULL : trim($_POST['chatPerson']);
        $chatText = empty($_POST['chatText']) ? NULL : trim($_POST['chatText']);
        if (empty($chatText) || empty($chatPerson)){
            return false;
        } else {
            $query = "Insert into chat (chatTimestamp, chatPerson, chatText) values ('%s','%s','%s')";
            $params = array(time(), $chatPerson, $chatText);
            array_walk($params, 'mysql_real_escape_string');
            $query = vsprintf($query, $params);
            $result = mysql_query($query);
            if (!$result){
                echo mysql_error();
                return false;
            }
            return true;
            
        }
    }
    
    function createDatabaseSchema(){
        $query = "    CREATE TABLE  chat (
                             chatID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                             chatTimestamp INT( 11 ) NOT NULL ,
                             chatPerson VARCHAR( 255 ) NOT NULL ,
                             chatText LONGTEXT NOT NULL
                            ) ;
                    )";
        mysql_query($query);
    }
}
?>
[code]
sorry should of posted full code!!

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
<?php
$chat = new chats;

class chats{

    private $timestamp = 0;
    private $action;
    
    function chats(){
        $this->timestamp = time();
       $dbserver = mysql_connect('localhost', 'htmlland_user', '1qaz2wsx') or die('error');
@mysql_select_db('htmlland_db101',$dbserver) or die('error');
        $result = mysql_query("SHOW TABLES LIKE 'chat'");
        if (mysql_num_rows($result) === 0){
            $this->createDatabaseSchema();
        }
        $this->action = isset($_POST['action']) ? $_POST['action'] : 'getChatData';
        $this->switchBoard();
    }
    
    function switchBoard(){
        switch ($this->action){
            case 'writeChatData':
                if ($this->writeChatData()){
                    echo '1';
                } else {
                    echo '0';
                }
            break;
            default:
                echo $this->getChatData();
        }    
    }
    
    function buffer(& $result){
        $temp = array();
        while ($row = myqsl_fetch_assoc($result)){
            $temp[] = $row;
        }
        return $temp;
    }
    
    function getChatData(){
        $return ='';
        $timestamp = isset($_POST['timestamp']) ? $_POST['timestamp'] : 0;
        if ($timestamp == 'null') $timestamp = 0;
        $query = "Select chatID, chatPerson, chatTimestamp, chatText from chat where chatTimestamp > ? order by chatTimestamp DESC limit 50 ";
        $result = mysql_query($query) or die(mysql_error());
        $chats = $this->buffer($result);
        foreach ($chats as $chat){
            $date = date('Y-m-d H:i:s', $chat['chatTimestamp']);
            $chatText = nl2br($chat['chatText']);
            $return .= <<<HTML
<tr>
    <td id="{$chat['chatID']}">{$chat['chatPerson']}<br/>$date</td>
    <td>{$chatText}</td>
</tr>
HTML;
        }
        if (empty($return)){
            return 'none';
        } else {
            return json_encode(array('timestamp'=>$this->timestamp,'chatText'=>$return));
        }
    }
    
    function writeChatData(){
        $chatPerson = empty($_POST['chatPerson']) ? NULL : trim($_POST['chatPerson']);
        $chatText = empty($_POST['chatText']) ? NULL : trim($_POST['chatText']);
        if (empty($chatText) || empty($chatPerson)){
            return false;
        } else {
            $query = "Insert into chat (chatTimestamp, chatPerson, chatText) values ('%s','%s','%s')";
            $params = array(time(), $chatPerson, $chatText);
            array_walk($params, 'mysql_real_escape_string');
            $query = vsprintf($query, $params);
            $result = mysql_query($query);
            if (!$result){
                echo mysql_error();
                return false;
            }
            return true;
            
        }
    }
    
    function createDatabaseSchema(){
        $query = "    CREATE TABLE  chat (
                             chatID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                             chatTimestamp INT( 11 ) NOT NULL ,
                             chatPerson VARCHAR( 255 ) NOT NULL ,
                             chatText LONGTEXT NOT NULL
                            ) ;
                    )";
        mysql_query($query);
    }
}
?>
sorry should of posted full code!!

MA WarGod

I believe if someone can think it, it can be programmed
 
as a note any info I shared by over looking it has been changed all db's, users, and passwords.. a edit feature here would be great for cases like this!!! Sorry again!!!

MA WarGod

I believe if someone can think it, it can be programmed
 
that's odd. try changing these lines
Code:
$params = array(time(), $chatPerson, $chatText);
            array_walk($params, 'mysql_real_escape_string');

to

Code:
$params = array(time(), $chatPerson, $chatText);
$params = array_map('mysql_real_escape_string', $params);
 
ok that resolves that error!!!Thank You





But still no out put as far as in chat..

MA WarGod

I believe if someone can think it, it can be programmed
 
I don't get it no errors and it is connecting and saving to the db, but no out put?

MA WarGod

I believe if someone can think it, it can be programmed
 
Code:
function updateChatRoom(){
    if (!xo) {createObject();}
    xo.onreadystatechange = function () {
            if (xo.readyState == 4) {
              if (xo.status == 200) {
                    if(xo.responseText == 'none'){
						 alert('You broke it!!! ...nope got nothing!!');
                        //do nothing
                    } else {
                        var rObj = eval('(' + xo.responseText + ')');
                      //  var rObj = JSON.parse(xo.responseText, reviver); // tryed to define reviver and failed badly lol!!!
                      //  var rObj = JSON.stringify(xo.responseText, replacer); // have no clue how to define a replacer
                        timestamp = rObj.timestamp;
                        //console.log('timestamp is '+ timestamp);
                        displayUpdatedChats(rObj.chatText)
                    }
               }
            }
        };

MA WarGod

I believe if someone can think it, it can be programmed
 
lol I need sleep no it isn't...

MA WarGod

I believe if someone can think it, it can be programmed
 
it is still pretty crude but i have improved the code a little and made it into a single file. this replaces the previous three files
Code:
[COLOR=#990000 ]<?php[/color]
[b][COLOR=#000000 ]session_start[/color][/b][COLOR=#990000 ]();[/color]
[COLOR=#009900 ]$chat[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]new[/color][/b] chats[COLOR=#990000 ];[/color]

[b][COLOR=#0000FF ]class[/color][/b] chats[COLOR=#FF0000 ]{[/color]

[tab]private [COLOR=#009900 ]$timestamp[/color] [COLOR=#990000 ]=[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ];[/color]
[tab]private [COLOR=#009900 ]$action[/color][COLOR=#990000 ];[/color]
[tab]private [COLOR=#009900 ]$table[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'chat'[/color][COLOR=#990000 ];[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]__construct[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]timestamp [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]time[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][b][COLOR=#000000 ]mysql_connect[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'localhost'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'root'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'root'[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'error'[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#000000 ]mysql_select_db[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'mychat'[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'error'[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_query[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"SHOW TABLES LIKE '{$this->table}'"[/color][COLOR=#990000 ]);[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_num_rows[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]===[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]createDatabaseSchema[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]action [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'action'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]?[/color] [COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'action'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]:[/color] [COLOR=#FF0000 ]''[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]switchBoard[/color][/b][COLOR=#990000 ]();[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab]public [b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]switchBoard[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][b][COLOR=#0000FF ]switch[/color][/b] [COLOR=#990000 ]([/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]action[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'writeChatData'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]writeChatData[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color] [b][COLOR=#000000 ]json_encode[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color][COLOR=#990000 ]));[/color]
[tab][tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]case[/color][/b] [COLOR=#FF0000 ]'getChatData'[/color][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$r[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]getChatData[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color] [b][COLOR=#000000 ]json_encode[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$r[/color][COLOR=#990000 ]));[/color]
[tab][tab][tab][b][COLOR=#0000FF ]break[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][tab][b][COLOR=#0000FF ]default[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][tab][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color][b][COLOR=#000000 ]serveHTML[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]exit[/color][/b][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#FF0000 ]}[/color][tab]
[tab][tab]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab][b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]getChatData[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ]=[/color][COLOR=#FF0000 ]''[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$timestamp[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]isset[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'timestamp'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]&&[/color] [COLOR=#990000 ]![/color][b][COLOR=#000000 ]is_null[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'timestamp'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]&&[/color] [COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'timestamp'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]!=[/color] [COLOR=#FF0000 ]''[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#000000 ]intval[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'timestamp'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]:[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ];[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]vsprintf[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]"Select chatID, chatPerson, chatTimestamp, chatText from {$this->table} where chatTimestamp > '%s' order by chatTimestamp DESC limit 50 "[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_real_escape_string[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$timestamp[/color][COLOR=#990000 ])));[/color]
[tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_query[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_error[/color][/b][COLOR=#990000 ]());[/color]
[tab][tab][b][COLOR=#0000FF ]while[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$chat[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_fetch_assoc[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$result[/color][COLOR=#990000 ])):[/color]
[tab][tab][tab][COLOR=#009900 ]$date[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]date[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'Y-m-d H:i:s'[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$chat[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatTimestamp'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][COLOR=#009900 ]$chatText[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]nl2br[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$chat[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatText'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][tab][COLOR=#009900 ]$return[/color] [COLOR=#990000 ].=[/color] [COLOR=#990000 ]<<<[/color]HTML
[COLOR=#990000 ]<[/color]tr[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]td id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"{$chat['chatID']}"[/color][COLOR=#990000 ]>[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$chat[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]][/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]<[/color]br[COLOR=#990000 ]/>[/color][COLOR=#009900 ]$date[/color][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]td[COLOR=#990000 ]>[/color][COLOR=#FF0000 ]{[/color][COLOR=#009900 ]$chatText[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]</[/color]td[COLOR=#990000 ]>[/color]
[COLOR=#990000 ]</[/color]tr[COLOR=#990000 ]>[/color]
HTML[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endwhile[/color][/b][COLOR=#990000 ];[/color]
[tab]   [b][COLOR=#0000FF ]return[/color][/b] [b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'timestamp'[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$this[/color][COLOR=#990000 ]->[/color]timestamp[COLOR=#990000 ],[/color][COLOR=#FF0000 ]'chatText'[/color][COLOR=#990000 ]=>[/color][COLOR=#009900 ]$return[/color][COLOR=#990000 ]);[/color]
[tab]   
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab][b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]writeChatData[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$chatPerson[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]?[/color] [b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]?[/color] NULL [COLOR=#990000 ]:[/color] [COLOR=#990000 ]([/color][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]:[/color] [b][COLOR=#000000 ]trim[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][COLOR=#009900 ]$chatText[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatText'[/color][COLOR=#990000 ]])[/color] [COLOR=#990000 ]?[/color] NULL [COLOR=#990000 ]:[/color] [b][COLOR=#000000 ]trim[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$_POST[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatText'[/color][COLOR=#990000 ]]);[/color]
[tab][tab][COLOR=#009900 ]$_SESSION[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'chatPerson'[/color][COLOR=#990000 ]][/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$chatPerson[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]if[/color][/b] [COLOR=#990000 ]([/color][b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$chatText[/color][COLOR=#990000 ])[/color] [COLOR=#990000 ]||[/color] [b][COLOR=#0000FF ]empty[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$chatPerson[/color][COLOR=#990000 ])):[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]else[/color][/b][COLOR=#990000 ]:[/color]
[tab][tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"Insert into {$this->table} (chatTimestamp, chatPerson, chatText) values ('%s','%s','%s')"[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][COLOR=#009900 ]$result[/color] [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]mysql_query[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]vsprintf[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ],[/color] [b][COLOR=#000000 ]array_map[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'mysql_real_escape_string'[/color][COLOR=#990000 ],[/color][b][COLOR=#0000FF ]array[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]time[/color][/b][COLOR=#990000 ](),[/color] [COLOR=#009900 ]$chatPerson[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$chatText[/color][COLOR=#990000 ]))));[/color]
[tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] [COLOR=#009900 ]$result[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#0000FF ]endif[/color][/b][COLOR=#990000 ];[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab][b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]createDatabaseSchema[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#009900 ]$query[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]"[tab]CREATE TABLE  {$this->table} ([/color]
[COLOR=#FF0000 ][tab][tab][tab][tab][tab][tab][tab] chatID INT( 11 ) NOT NULL PRIMARY KEY AUTO_INCREMENT ,[/color]
[COLOR=#FF0000 ][tab][tab][tab][tab][tab][tab][tab] chatTimestamp INT( 11 ) NOT NULL ,[/color]
[COLOR=#FF0000 ][tab][tab][tab][tab][tab][tab][tab] chatPerson VARCHAR( 255 ) NOT NULL ,[/color]
[COLOR=#FF0000 ][tab][tab][tab][tab][tab][tab][tab] chatText LONGTEXT NOT NULL[/color]
[COLOR=#FF0000 ][tab][tab][tab][tab][tab][tab][tab])[/color]
[COLOR=#FF0000 ][tab][tab][tab][tab]  "[/color][COLOR=#990000 ];[/color]
[tab][tab][b][COLOR=#000000 ]mysql_query[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$query[/color][COLOR=#990000 ])[/color] [b][COLOR=#0000FF ]or[/color][/b] [b][COLOR=#0000FF ]die[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#000000 ]mysql_error[/color][/b][COLOR=#990000 ]());[/color]
[tab][COLOR=#FF0000 ]}[/color]
[tab]
[tab][b][COLOR=#0000FF ]function[/color][/b] [b][COLOR=#000000 ]serveHTML[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][COLOR=#990000 ]?>[/color]
[COLOR=#990000 ]<![/color]DOCTYPE HTML PUBLIC [COLOR=#FF0000 ]"-//W3C//DTD HTML 4.01//EN"[/color] [COLOR=#FF0000 ]"[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"[/URL][/color][COLOR=#990000 ]>[/color]
[COLOR=#990000 ]<[/color]html[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]head[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]meta http[COLOR=#990000 ]-[/color]equiv[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"Content-Type"[/color] content[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text/html; charset=iso-8859-1"[/color] [COLOR=#990000 ]/>[/color]
[tab][tab][COLOR=#990000 ]<[/color]script src[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"[URL unfurl="true"]https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"[/URL][/color] type[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text/javascript"[/color][COLOR=#990000 ]></[/color]script[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]script type[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text/javascript"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab]$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'document'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]ready[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] url [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'<?php echo $_SERVER['[/color]PHP_SELF[COLOR=#FF0000 ]'];?>'[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] timestamp [COLOR=#990000 ]=[/color] [COLOR=#993399 ]0[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] interval [COLOR=#990000 ]=[/color] [COLOR=#993399 ]5000[/color][COLOR=#990000 ];[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] first [COLOR=#990000 ]=[/color] true[COLOR=#990000 ];[/color]
[tab][tab][tab][tab]$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'#formChatForm'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]bind[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'submit'[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]([/color]e[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab]e[COLOR=#990000 ].[/color][b][COLOR=#000000 ]preventDefault[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][tab][tab]$[COLOR=#990000 ].[/color][b][COLOR=#000000 ]post[/color][/b][COLOR=#990000 ]([/color]url[COLOR=#990000 ],[/color]$[COLOR=#990000 ]([/color]this[COLOR=#990000 ]).[/color][b][COLOR=#000000 ]serialize[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]'&action=writeChatData'[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]([/color]d[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color][b][COLOR=#000000 ]update[/color][/b][COLOR=#990000 ]();[/color][COLOR=#FF0000 ]}[/color][COLOR=#990000 ],[/color][COLOR=#FF0000 ]'json'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][b][COLOR=#0000FF ]if[/color][/b][COLOR=#990000 ]([/color]first [COLOR=#990000 ]&&[/color] $[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'input[name="chatPerson"]'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]val[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]!=[/color] [COLOR=#FF0000 ]""[/color][COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab]$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'input[name="chatPerson"]'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]replaceWith[/color][/b][COLOR=#990000 ]([/color]$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'<span>'[/color][COLOR=#990000 ]+[/color] $[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'input[name="chatPerson"]'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]val[/color][/b][COLOR=#990000 ]()[/color] [COLOR=#990000 ]+[/color] [COLOR=#FF0000 ]'</span>'[/color][COLOR=#990000 ]));[/color]
[tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][tab][b][COLOR=#0000FF ]return[/color][/b] false[COLOR=#990000 ];[/color]
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] update [COLOR=#990000 ]=[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab]$[COLOR=#990000 ].[/color][b][COLOR=#000000 ]post[/color][/b][COLOR=#990000 ]([/color]url[COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'action=getChatData&timestamp='[/color][COLOR=#990000 ]+[/color]timestamp[COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]([/color]d[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color]
[tab][tab][tab][tab][tab][tab][tab]timestamp [COLOR=#990000 ]=[/color] d[COLOR=#990000 ].[/color]timestamp[COLOR=#990000 ];[/color]
[tab][tab][tab][tab][tab][tab][tab]$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'#chatTable'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]prepend[/color][/b][COLOR=#990000 ]([/color]d[COLOR=#990000 ].[/color]chatText[COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][tab][COLOR=#FF0000 ]}[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'json'[/color][COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][COLOR=#FF0000 ]}[/color]
[tab][tab][tab][tab][b][COLOR=#0000FF ]var[/color][/b] timer [COLOR=#990000 ]=[/color] [b][COLOR=#000000 ]setInterval[/color][/b][COLOR=#990000 ]([/color]update[COLOR=#990000 ],[/color] interval[COLOR=#990000 ]);[/color]
[tab][tab][tab][tab][b][COLOR=#000000 ]update[/color][/b][COLOR=#990000 ]();[/color]
[tab][tab][tab][COLOR=#FF0000 ]}[/color][COLOR=#990000 ]);[/color]
[tab][tab][COLOR=#990000 ]</[/color]script[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]title[COLOR=#990000 ]>[/color]Chat Room[COLOR=#990000 ]</[/color]title[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]</[/color]head[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]<[/color]body[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]div id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatForm"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]<[/color]form id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"formChatForm"[/color] action[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"<?php echo $_SERVER['PHP_SELF'];?>"[/color] method[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"post"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][tab]Your Name[COLOR=#990000 ]:[/color] [COLOR=#990000 ]<[/color]input type[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"text"[/color] name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatPerson"[/color] id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatPerson"[/color][COLOR=#990000 ]/><[/color]br[COLOR=#990000 ]/>[/color]
[tab][tab][tab][tab]Message[COLOR=#990000 ]:[/color] [COLOR=#990000 ]<[/color]textarea name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatText"[/color] id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatText"[/color][COLOR=#990000 ]></[/color]textarea[COLOR=#990000 ]><[/color]br[COLOR=#990000 ]/>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]<[/color]input type[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"submit"[/color] id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"xsubmit"[/color] name[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"xsubmit"[/color] value[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"Chat"[/color][COLOR=#990000 ]/>[/color]
[tab][tab][tab][tab][COLOR=#990000 ]</[/color]form[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]</[/color]div[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]<[/color]div id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatDiv"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][COLOR=#990000 ]<[/color]table id[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"chatTable"[/color] border[COLOR=#990000 ]=[/color][COLOR=#FF0000 ]"1"[/color][COLOR=#990000 ]>[/color]
[tab][tab][tab][COLOR=#990000 ]</[/color]table[COLOR=#990000 ]>[/color]
[tab][tab][COLOR=#990000 ]</[/color]div[COLOR=#990000 ]>[/color]
[tab][COLOR=#990000 ]</[/color]body[COLOR=#990000 ]>[/color]
[COLOR=#990000 ]</[/color]html[COLOR=#990000 ]>[/color]

[tab][tab]
[tab][tab][COLOR=#990000 ]<?php[/color]
[tab][COLOR=#FF0000 ]}[/color]
[COLOR=#FF0000 ]}[/color]
[COLOR=#990000 ]?>[/color]
 
Awesome!!! Thank You so much..

Ok I had to change host as their add wrapper was creating a error I think with the script..

I also have it on xamp where I am testing and tweaking it..

I added tables to the chat output so if its a long post it displays nicely..

I also added a function

Code:
    function html2text($html){
    $tags = ARRAY (
    0 => '~<h[123][^>]+>~si',
    1 => '~<h[456][^>]+>~si',
    2 => '~<table[^>]+>~si',
    3 => '~<tr[^>]+>~si',
    4 => '~<li[^>]+>~si',
    5 => '~<br[^>]+>~si',
    6 => '~<p[^>]+>~si',
    7 => '~<div[^>]+>~si',
    );
    $html = PREG_REPLACE($tags,"\n",$html);
    $html = PREG_REPLACE('~</t(d|h)>\s*<t(d|h)[^>]+>~si',' - ',$html);
    $html = PREG_REPLACE('~<[^>]+>~s','',$html);
    // reducing spaces
    $html = PREG_REPLACE('~ +~s',' ',$html);
    $html = PREG_REPLACE('~^\s+~m','',$html);
    $html = PREG_REPLACE('~\s+$~m','',$html);
    // reducing newlines
    $html = PREG_REPLACE('~\n+~s',"\n",$html);
    RETURN $html;
}

Now I would like to add at the replacewith
Code:
 $('input[name="chatPerson"]').replaceWith($('<span>'+ $('input[name="schatPerson"]').val() + '</span>'));

not if I need the function or if it can be done with
Code:
strip_tag()
I would assume, of course I am learning the val() could be made a string? or am I off track?
I been trying to from it with both and coming up with error
or
maybe create a new string valuable named $schatPerson as I am trying to do also with errors..

Code:
        $_SESSION['chatPerson'] = $chatPerson = $schatPerson;

any advice here would be greatly excepted..

The reasoning behided trying to make it a valuable is I believe it could come into play with trying to from a whoto fuction or action, and a userlist..

I am looking at southbeach's userlist and trying to see how they did it..
again any advice here would be greatly excepted..

jpadie I want to say thank you for sharing your work and taking the time not only here in this thread but over the years now and helping me learn in many threads..


MA WarGod

I believe if someone can think it, it can be programmed
 
Instead of doing HTML to text (why?) you could treat the text as is and then adjustthe output using
Code:
nl2br(htmlspecialchars($chat['chatText']))

If you want to do it on the input (and this also makes sense) then consider just using striptags
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top