Everything2
Near Matches
Ignore Exact
Full Text
Everything2

PHP E2 chatterbox XML ticker parser

created by wonko

(thing) by wonko (1.2 y) (print)   ?   (I like it!) 1 C! Sat Feb 10 2001 at 1:59:43

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++;           
    }
}   
?>


(thing) by Damodred (3 d) (print)   ?   (I like it!) Sun May 23 2004 at 1:51:48

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>

printable version
chaos

Perl E2 chatterbox XML ticker parser mIRC E2 chatterbox XML ticker parser E2 Link and Logger Client E2 Explorer
E2 Java Chatterbox Client PHP Perl E2 private message XML ticker parser E2 Flash Chatterbox Client
Nicknames accorded by George W. Bush really beautiful code ASP E2 random nodes XML ticker Chatterbox
E2 Message Inbox Archiver E2 Mozilla Chatterbox Client Notelet Nodelet Squawkbox Client Notelet Nodelet Chatterbox Client
127.0.0.0/8 PHP parser code for the nodelist XML The Cat Who Walks Through Walls RSS feed
Your ideas are intriguing to me and I wish to subscribe to your newsletter Paste E2 piecemaker proxy code
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Look at this mess the Death Borg made!
How to listen to the stories that cats tell us
Nike
Gaussian formula
My correspondence with the Westboro Baptist Church
In the empty mountains
chocolate sorbet
Balaclava
Garry Owen
Dirty Harry
Everything Editor Logs
Lesbian conspiracy
Ferris wheel
Formatting poems and simple HTML
New Writeups
etouffee
Wild tides guard her secrets(poetry)
Lord Brawl
Dr. Horrible's Sing-Along Blog(review)
a8ksh4
regret(idea)
Heisenberg
Editor Log: July 2008(log)
sam512
halfway homes, catacombs, twilight zones(fiction)
Timeshredder
The Texas UFO Crash of 1897(event)
Heitah
The Dark Knight(review)
ignis_glaciesque
Uppsala(place)
ignis_glaciesque
diffusion of responsibility(idea)
TheOrientalAfrican
The Soft Meadow of my Childhood(event)
BookReader
The Dragon Slayers(fiction)
kohlcass
religiously fashionable(review)
Pavlovna
waulking song(thing)
tentative
Stick Man(poetry)
Ereneta
The Fight with the Snapping Turtle: Or, the American St. George(poetry)
Everything 2 is brought to you by the letter C and The Everything Development Company