andy's php projects
Script and site usage:
All of the scripts on this site are provided free for non-commercial, personal or non-profit use. If you wish to use any of these in a commercial system, please refer to the payment plan.

Support:
Support for each of the scripts is given, free of charge, on the message board. Each script has its own message board which can be accessed by clicking on the 'project forum' link (beneath the description of each project).


Proudly hosted with Dreamhost

Save $20 when signing up for Dreamhost by using the promo code amnuts20


If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh to encourage me to continue? Every little helps!

Zend Certified Engineer logo


EWTOO Talker Lister

Provides a way for you to list the position of one or more talkers on your website, based on the talker list results from http://charts.ewtoo.org/.

class.ewtoochartposition.php

<?php

//
// class.ewtoochartposition.php
// version 1.1.0, 23 July, 2002
//
// Description
//
// This class allows you to show a talkers in the ew-too charts, based
// on the information provided by Silver at http://charts.ewtoo.org/.
//
// Author
//
// Andrew Collington, 2002
// php@amnuts.com, http://php.amnuts.com/
//
// Example of use
//
//        require "class.ewtoochartposition.php";
//        $cp = new ChartPosition("http://charts.ewtoo.org/data.txt");
//        $cp->GetDetails("uberworld.org",2020);
//
// Example of use with caching
//
//        require "class.ewtoochartposition.php";
//        $cp = new ChartPosition("http://charts.ewtoo.org/data.txt");
//        $cp->SetCacheTime(86400);
//        $cp->SetCacheDir(dirname(__FILE__));
//        $cp->GetDetails("uberworld.org",2020);
//

class ChartPosition
{

    var 
$chartFile;     // the link to the ewtoo charts
    
var $chartData;     // the raw data
    
var $_cache_dir;    // where to save the cache file
    
var $_cache_time;   // in seconds.  if 0 then don't cache

    
function ChartPosition($chartfile)
    {
        
$this->_cache_dir ".";
        
$this->_cache_time 0;
        
$this->chartFile $chartfile;
    }

    function 
GetData()
    {
        if (
$this->_cache_time && ((time() - @filemtime($this->_cache_dir "_ewcharts")) < $this->_cache_time))
        {
            
$this->chartData = @file($this->_cache_dir "_ewcharts");
        }
        else
        {
            
$this->chartData = @file($this->chartFile);
        }
        
// save file is needs be
        
if ($this->_cache_time$this->SaveCache();
    }

    function 
GetDetails($address="",$port="")
    {
        if (
$address == "" || $port == "")
        {
            echo 
"<p>You must supply the talker address and port number.</p>\n";
            return;
        }

        
// if the data is empty then try to get it
        
if (empty($this->chartData)) $this->GetData();
        
        
// if it's empty now, then we cannot get anything
        
if (empty($this->chartData))
        {
            echo 
"<p>The chart details could not be loaded at this time.</p>\n";
        }
        else
        {
            
// go through the data to get your talker's details
            
for ($i=0$i<count($this->chartData); $i++)
            {
                if (
ereg("^[0-9]",$this->chartData[$i]))
                {
                    
$row split(";",rtrim($this->chartData[$i]));
                    
// this_position;last_position;abbreviation;name;host;port;this_total;last_total
                    
if (($row[4] == $address) && ($row[5] == $port))
                    {
                        echo 
"<p>{$row[3]} is currently at number {$row[0]} in the charts.<br>\n";
                        if (
$row[0] == $row[1])
                        {
                            echo 
"It's a non-mover at number {$row[0]}.</p>\n";
                        }
                        else
                        {
                            echo 
"It was last at number {$row[1]}, which means it's gone ", ($row[0]>$row[1]?"down":"up"), " "abs($row[0]-$row[1]), " place", (abs($row[0]-$row[1])==1?"":"s"), ".</p>\n";
                        }
                        return;
                    }
                }
            }
            echo 
"<p>Could not find details for the talker at $address ($port).</p>\n";
        }
    }

    function 
SetCacheTime($len=0)
    {
        
$this->_cache_time $len;
    }

    function 
SetCacheDir($dir=".")
    {
        
$this->_cache_dir $dir . ($dir[strlen($dir)-1] != "/" "/" "");
    }

    function 
SaveCache()
    {
        
$fp = @fopen($this->_cache_dir "_ewcharts""w");
        if (
$fp)
        {
            
fwrite($fpjoin('',$this->chartData));
            
fclose($fp);
            return 
TRUE;
        }
        return 
FALSE;
    }
}



$cp = new ChartPosition("http://charts.ewtoo.org/data.txt");
$cp->SetCacheTime(30);

$cp->GetDetails("doughnuts.co.uk",4000);
$cp->GetDetails("presidium.org",2222);
$cp->GetDetails("uberworld.org",2020);
$cp->GetDetails("snowplains.org",3456);

?>
3.32kb in size
last modified May 6, 2006 at 9:55pm
2925 views, 2887 downloads
list all projects :: this project's forum
added Sep 19, 2002 at 3:01pm :: updated Sep 19, 2002 at 3:01pm :: 2 files :: 11170 views

© Andrew Collington, 2002-2007.