How to add a list of users in your GeekShed IRC channel to your website
GeekShed now provides a live XML formatted output of users in your channel. This can be parsed and placed on your own website in the form of a list, table, etc.
The XML output can be found at http://www.geekshed.net/usertable.php?chan=. An example of the use of this for #phil is http://www.geekshed.net/usertable.php?chan=phil. To parse this into a table on your website, you can use the following PHP code. All you need do is place the code at the required location on the page and adjust the channel name at the top of the code. Following this, you can adjust the HTML to fit your site’s requirements.
You can also access the away message left by a user who is away using $user->awaymsg inside the foreach loop.
The DTD for the XML can be found at http://www.geekshed.net/xml/userlist.dtd.
As at 08 April 2010 the returned XML now has double escaped entities (e.g. < goes to < and ASCII char 2 goes to ). SimpleXML in the above example will do a single unescape on these such that < goes to < such that it can be used in web pages whilst keeping them valid. If you use it for anything else you will need to be sure to unescape sufficiently to give you the original characters.
If you have any questions about this, ask in #help.
The XML output can be found at http://www.geekshed.net/usertable.php?chan=
<?php
// Edit This
$chan = 'phil';
// Don't edit this
$xml = simplexml_load_file('http://www.geekshed.net/usertable.php?chan='.$chan);
?>
<!-- Edit this HTML to suit your layout -->
<table>
<tr>
<td style="text-align: center;"><strong>Nickname</strong></td>
<td style="text-align: center;"><strong>Status</strong></td>
<td style="text-align: center;"><strong>Clones</strong></td>
<td style="text-align: center;"><strong>Active (Not Away)</strong></td>
</tr>
<?php
foreach ($xml->user as $user) {
echo "\t<tr>\n";
echo "\t\t<td style=\"text-align: center;\">{$user->nick}</td>\n";
echo "\t\t<td style=\"text-align: center;\">{$user->status}</td>\n";
echo "\t\t<td style=\"text-align: center;\">{$user->clones}</td>\n";
echo "\t\t<td style=\"text-align: center;\">{$user->away}</td>\n";
echo "\t</tr>\n";
}
?>
</table>
You can also access the away message left by a user who is away using $user->awaymsg inside the foreach loop.
The DTD for the XML can be found at http://www.geekshed.net/xml/userlist.dtd.
As at 08 April 2010 the returned XML now has double escaped entities (e.g. < goes to < and ASCII char 2 goes to ). SimpleXML in the above example will do a single unescape on these such that < goes to < such that it can be used in web pages whilst keeping them valid. If you use it for anything else you will need to be sure to unescape sufficiently to give you the original characters.
If you have any questions about this, ask in #help.
April 4, 2010 - 8:27 pm
This is pretty cool. Have you ever thought about merging this with the channel topic RSS feed into a tiny API?
April 5, 2010 - 5:34 am
Little need to do that. RSS is just XML anyway so it’s a very similar concept to put the topic from RSS on your site:
< ?php // Edit This $chan = 'phil'; // Don't edit this $xml = simplexml_load_file('http://rss.geekshed.net/?type=single&channel='.$chan); ?>
#< ?php echo $chan; ?> Topic: < ?php echo $xml->channel->item->description; ?>
April 5, 2010 - 8:19 am
It crashes firefox, and google chrome.
April 5, 2010 - 9:09 am
I believe that phil fixed a minor issue with it. If you are still having issues, let us know.
It works fine here
April 5, 2010 - 11:00 am
Eh, it’s server side code that does nothing but generate a HTML table. If your browsers crash then it is the fault of your computer.
Phil
April 8, 2010 - 9:28 am
Wow thats fairly handy. Ive been playing with the XML logs my chat client outputs and using PHP in combination with some AJAX.
As a little mini project to test my abilities/to learn something new i made a web view of these logs which update as the logs grow.
Now with this I could have a user list next to this which would be nice. Something for me to do to reinforce what i have learnt so far.
One thing though, this may be picking at something purely cosmetic but I noticed that the Content-type of this XML is text/html and iirc ive had issues with some javascript engines not liking this and wanted a text/xml content type. I cant remember the exactly what i was trying to do or which browsers but to avoid issues maybe
header('Content-type: text/xml');
could be added into your PHP script (not to the example but the file located at http://www.geekshed.net/usertable.php)Up to you whether you bother doing this or not as it could be more effort than worth. Its up to you :).
April 8, 2010 - 9:42 am
Put in a
header('Content-Type: text/xml; charset=ISO-8859-1');
which should fix some issues people are having with various parsers. Also means that browsers with XML support will parse the raw XML into a pretty style.Phil