<?php
/*
Plugin Name: Donation Driver
Plugin URI: http://www.animeblogger.net/
Description: Have a bar for donation drive progress!
Version: 0.1
Author: Guru3
Author URI: http://electricpotential.net/

(C) 2008 - AnimeBlogger.net
Not for un-authorized redistribution or copying of in any part or whole.

*/

add_option('dd_lastfetch'0'DD Last Fetch');
add_option('dd_data''''DD Data');

function 
dd_display($width 125$height 20)
{        
//check every half hour
    
if (get_option('dd_lastfetch') < (time() - 1800))
        
dd_update_data();

    
$data get_option('dd_data');
    echo 
'<h2>AnimeBlogger.net Donation Drive!</h2>';
    echo 
'<ul>';
    if (!isset(
$data[2]))
        echo 
'
<table border="0" style="none; margin-left: auto; margin-right: auto; width: '
.$width.'px">
    <tr>
        <td style="text-align: left">$'
.$data[0].'</td>
        <td style="text-align: right">$'
.$data[1].'</td>
    </tr>
</table>
<table border="0" style="none; margin-left: auto; margin-right: auto; width: '
.$width.'px; height: '.$height.'px">
    <tr>
        <td style="width: '
.round(($data[0]*$width)/$data[1]).'px; background-color: #5ed577"></td>
        <td style="width: '
.round((($data[1]-$data[0])*$width)/$data[1]).'px; background-color: #ec385a"></td>
    </tr>
</table>'
;
    else
        echo 
'
<table border="0" style="none;  margin-left: auto; margin-right: auto; width: '
.$width.'px">
    <tr>    
        <td style="width: 20px">$'
.$data[0].'</td>
        <td style="width: '
.round(abs((($data[1]*$width)/$data[2])-20)).'px; text-align: right">$'.$data[1].'</td>
        <td style="text-align: right">$'
.$data[2].'</td>
    </tr>
</table>
<table border="0" style="none;  margin-left: auto; margin-right: auto; width: '
.$width.'px; height: '.$height.'px">
    <tr>
        <td style="width: '
.round(($data[0]*$width)/$data[2]).'px; background-color: #5ed577"></td>
        <td style="width: '
.round((($data[1]-$data[0])*$width)/$data[2]).'px; background-color: #ec385a"></td>
        <td style="width: '
.round((($data[2]-$data[1]-$data[0]))*$width/$data[2]).'px; background-color: #fff373"></td>
    </tr>
</table>'
;

    
$sayings[] = 'Just a bit more guys!';
    
$sayings[] = 'It can\'t hurt to help!';
    
$sayings[] = 'Be a pal, a PayPal!';
    
$sayings[] = 'We need money. Badly. :(';
    
$sayings[] = 'Keep us in business.';
    
$sayings[] = 'Feel good; lend a hand.';

    echo 
'<p style="text-align: center">'.$sayings[rand(0count($sayings) - 1)].'<br/>';
    echo 
'<a href="http://animeblogger.net/donations/" style="text-decoration: underline">Donate Now.</a></p>';
    echo 
'</ul>';
}

function 
dd_update_data()
{
    
$stream fsockopen('animeblogger.net'80$errno$errstr10);
    if (!
$stream)
    {
        
//unhandled error
    
}
    else
    {
        
$data = array();
        
$dpos 0;

        
fwrite($stream"GET /donations/DonationDriver.status HTTP/1.0\r\n");
        
fwrite($stream"User-Agent: DonationDriver WordPress Plugin (compatible; Mozilla 4.0; MSIE 5.5; http://animeblogger.net/)\r\n");
        
fwrite($stream"Accept: text/plain\r\n");
        
fwrite($stream"Host: animeblogger.net\r\n\r\n");
        while (!
feof($stream))
        {
            
$data[$dpos] = rtrim(fgets($stream1024));
            
$dpos++;
        }
        
fclose($stream);
    }

    
$ndata;
    
//remove HTTP headers
    
$offset 10;
    for (
$c $offset$c $dpos$c++)
    {
        if (
is_numeric($data[$c]))
            
$ndata[] = $data[$c];
    }
    if (
count($ndata) >= 2)
        
update_option('dd_data'$ndata);
    
update_option('dd_lastfetch'time());
}

?>