This simple script downloads the contents of the chatterbox XML ticker and parses all the messages into an array for easy manipulation. More details in the comment at the top of the script. Enjoy!


<?
/*****************************************************************************
 *
 * PHP Chatterbox Parser v0.1
 * by Ryan Grove
 * ryan@wonko.com
 * http://wonko.com/
 *
 * Parses the chatterbox XML ticker into a two-dimensional array ($chatter).
 * The following array values are set:
 *
 * $chatter[0]["author"]   Author of the message
 * $chatter[0]["time"]     Timestamp of the message
 * $chatter[0]["message"]  Text of the message
 *
 * Messages are not parsed for node titles (i.e., [node]) or for actions
 * (/me). I'll leave that up to you. Enjoy!
 *
 *****************************************************************************/

// URL of the E2 chatterbox XML ticker
$url = "http://everything2.com/index.pl?node=chatterbox+xml+ticker";

// Get chatterbox XML, put it into an array
$xml = file($url);      

// Parse the XML
$e = 0;
$chatter = array();
for($i=1;$i<(count($xml) -1);$i++) 
{
    if (strpos($xml[$i], "<message author=") !== false) 
    {
        $pos = (strpos($xml[$i], "author=\"") + 8);
        $chatter[$e]["author"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));

        $pos = (strpos($xml[$i], "time=\"") + 6);
        $chatter[$e]["time"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));           
    } 
    else 
    {
        $chatter[$e]["message"] = substr($xml[$i], 0, (strlen($xml[$i]) - 11));
        $e++;           
    }
}   
?>

Update June 24, '04
During the server upgrade, the chatterbox parser introduced some <makeXmlSafe> tags into the chat. Since I wasn't actively searching for "/me" but instead substring-ing the text based on its position (originally the first 3 characters, now the 13th, 14th and 15th characters), /me stopped working. This is now fixed.
Update June 2, '04
Something changed in the chatterbox xml ticker that this has been pulling from, so I had to change how the display deals with unclosed brackets. They will now be displayed properly.
Update May 23, '04
I made softlinks actually go to the correct link (i.e., www.everything2.com). I can only explain that I made the utility to be read, not necessarily clicked on (senility, yes). Softlinks now go directly to the E2 node. I have also added line breaks to the source for easier reading (should you want to read the source of your catbox for some odd reason).
I would like to contribute my parsed and aesthetically (I hope) formatted for the eye result of the above code, for those who may have PHP capability on their site but don't know how to use it. Just paste this code into a file ending with .php (for example catbox.php) and save it on your site. Then point your browser at it and voila, instant catbox.

The following also parses the "/me" functionality, bolds softlinks and displays the time (24hr format). It'll display "And all is quiet..." if there's nothing in the buffer, and an error message if E2 cannot be reached.

Finally, this utility will refresh itself once every 60 seconds. Better than hitting "Talk" all the time, no?

If you're familiar with CSS stylesheets, it should be easy to alter the display to your liking.

*******************************************************

<html>
<head>
<title>Catbox PHP Parser</title>
<meta http-equiv="refresh" content="60">
<head>
<body>
<style>
A {
 color: #0068c2;
 text-decoration: none;
 font-weight: bold;
}
A:HOVER {
 text-decoration: underline;
}
.catbox {
 margin: 50px; 
 color: #000; 
 background: #f0f0f0; 
 padding: 5px; 
 border: 1px solid #0068c2; 
 font-family: georgia; 
 line-height: 150%;
}
</style>
<div class='catbox'>
<?
/*****************************************************************************
 *
 * PHP Chatterbox Parser v0.1
 * by Ryan Grove
 * ryan@wonko.com
 * http://wonko.com/
 *
 * Parses the chatterbox XML ticker into a two-dimensional array ($chatter).
 * The following array values are set:
 *
 * $chatter[0]["author"]   Author of the message
 * $chatter[0]["time"]     Timestamp of the message
 * $chatter[0]["message"]  Text of the message
 *
 * Messages are not parsed for node titles (i.e., [node]) or for actions
 * (/me). I'll leave that up to you. Enjoy!
 *
 * PHP Chatterbox Formatter v0.1
 * by Marcin Manek
 * marcin@damodred.net
 * http://www.damodred.net
 * /msg Damodred
 *
 * Formats the output into an easily readable screen
 * Bolds the names and italicizes the time display
 * Parses the /me functionality
 * Displays error message if site unreachable
 * Displays "all is quiet" if no messages displayed
 *
 *****************************************************************************/

// URL of the E2 chatterbox XML ticker
$url = "http://everything2.com/index.pl?node=chatterbox+xml+ticker";

// Get chatterbox XML, put it into an array
$xml = @file($url);      

if ($xml) {
// Parse the XML
$e = 0;
$chatter = array();
for($i=1;$i<(count($xml) -1);$i++) 
{
    if (strpos($xml[$i], "<message time=") !== false) 
    {
        $pos = (strpos($xml[$i], "author=\"") + 8);
        $chatter[$e]["author"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));

        $pos = (strpos($xml[$i], "time=\"") + 6);
        $chatter[$e]["time"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));           
    } 
    else 
    {
        $chatter[$e]["message"] = substr($xml[$i], 0, (strlen($xml[$i]) - 11));
        $e++;           
    }
}

// Iterate through the cbox array, format each line, output
foreach ($chatter as $v) {
 $v["message"] = str_replace("href=\"/index.pl","href=\"http://www.everything2.com/index.pl",$v["message"]);
 $v["message"] = str_replace("&amp;#91;","[",$v["message"]);
 $date = date("G:i",strtotime($v["time"]));
 $mepos = strpos($v["message"],"/me");
 if ($mepos !== false)
  echo "[<i>".$date."</i>] <i><b>* ".$v["author"]."</b><makeXmlSafe> ".substr($v["message"],($mepos+4))."</i><br>\n";
 else echo "[<i>".$date."</i>] <b>".$v["author"]."</b>: ".$v["message"]."<br>\n";
}

}
else "Could not reach site ... have some tea.</b>";
if (sizeof($chatter) == 0) echo "<i>And all is quiet...</i>";
?>
</div>
</body>
</html>

Log in or register to write something here or to contact authors.