<?php

/* php library for accessing the bbs-scene.org api.
Edit the variables below to match your settings. 

By Frank Linhars aka netsurge
http://bbs-scene.org/contact.php
 
Include this file with a php include in your document like this:
 
<?php include "inc/class.bbs-scene.org.php"; ?>

There are currently two built in functions that you can call.  
The first is to display the global onelinerz by inclduing the 
following statement in your php code where you want to display
them:

<?php parseOnelinerz($username, $password, "number of oneliners"); ?>

All you have to do is chnage the number of onelinerz to the actual
number of onelinerz you want to display, for exmaple if you wanted to
display 10 onelinerz your statement would be the following:

<?php parseOnelinerz($username, $password, "10"); ?>

The second function is to display a random png of one of the bbses
listed in the bbs-scene.org bbs list.  To do that place the following
statement in your code where you want to display the random image:

<?php randomPng($username, $password, "size of image"); ?>

All you have to do is change the size of image statement to reflect
the size of the png you want in a percentage where 100 is the full size,
50 is half, 25 is a quarter, etc..  If you wanted to display an image that
is 35% the size of the original you would issue the following:

<?php randomPng($username, $password, "35"); ?>

*/

/* Edit the css style of the onelinerz display below */
?>

<style type="text/css">
.oneliner {
	color: #999;
}
.alias_bracket {
	color: #666;
}
.oneliner_bbsname {
	color: #09C;
	font-style: italic;
}                      
</style>

<?php
/* Edit settings below */

$username = "me@bbs-scene.org"; // bbs-scene.org username
$password = "password"; // bbs-scene.org password

/* DON'T EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING */ 

 function parseOnelinerz($username, $password, $number) // Function to parse and display onelinerz
{

	$url = "http://bbs-scene.org/api/onelinerz.php?limit=" . $number;

	$ch = curl_init($url); // Initialize curl and set curl options

	curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, 0);

	$data = curl_exec($ch);
	curl_close($ch);

	$xml = new SimpleXmlElement($data, LIBXML_NOCDATA); // Set XML element

    $cnt = count($xml->node);
    for($i=0; $i<$cnt; $i++)
    {
	$oneliner 	= $xml->node[$i]->oneliner;
	$alias 	= $xml->node[$i]->alias;
	$bbs = $xml->node[$i]->bbsname;
 
	echo("<span class=\"oneliner\">" . $oneliner . "</span> <span class=\"alias_bracket\">(</span>" . $alias . "<span class=\"alias_bracket\">)</span> - <span class=\"oneliner_bbsname\">" . $bbs . "</span><br />");
    }
}

function randomPng($username, $password, $pngsize) // Function to display random png's from bbs-scene.org bbs list
{
	
	$pngurl = "http://bbs-scene.org/api/bbslist.php?randomansi";

	$pngch = curl_init($pngurl); // Initialize curl and set curl options

	curl_setopt($pngch, CURLOPT_USERPWD, "$username:$password");
	curl_setopt($pngch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($pngch, CURLOPT_HEADER, 0);

	$pngdata = curl_exec($pngch);
	curl_close($pngch);

	$xml = new SimpleXmlElement($pngdata, LIBXML_NOCDATA); // Set XML element

	$name 	 = $xml->node->bbsname;
	$address = $xml->node->address;
	$port    = $xml->node->port;
	$id		 = $xml->node->id;
	$sysop   = $xml->node->sysop;
	
    echo("<a href=\"telnet://". $address . "\"><img border=\"0\" src=\"http://bbs-scene.org/grab.php?png=". $id ."&size=". $pngsize . "\" alt=\"" . $name . "\"/></a>");
}
?>