I figure since I used Rollie's code as a base, I'd post here what I ended up with.
First, I split it out into two files, rostergrab.php which checks for new status file, and roster.php which is the main roster, and I just cron rostergrab.php. I don't really need my page hitting warcraftrealms everytime someone hits the page, so I wanted it separate.
So for rostergrab.php, I have this (which is just Rollie's code with the display part ripped out):
Code: Select all
<?php
//
// Rostergrab.php
//
// Sample guild export downloader and display
// You may use this script as you wish. This is only some sample code
// provided to help get a jumpstart!
//
// Created: 1/27/2005
//
// Author: Cooper Sellers aka Rollie - Bloodscalp
//
$local_directory = "download/"; // this is the directory where your local files
// will be written to and read from. Make sure
// you have WRITE privileges on this directory
$guild_id = 18447; // get this number from the link posted on the
// guilddisplay.php page
//
// Remember to check the status file so that you are not pulling data
// more than once per day
//
$localstatusfile = $local_directory . "status.txt";
$infile = fopen ($localstatusfile, "r");
$current_timestamp = 0;
if (!$infile)
{
echo "<p>No status file available, assuming this is the first run<br>";
}
else
{
// read our status file time
$buffer = fgets($infile, 4096);
$current_timestamp = trim( $buffer );
echo 'Local status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$current_timestamp) . '<br>';
}
fclose( $infile ); // close our local status file
$filename = "http://www.warcraftrealms.com/exports/status.txt";
$infile = fopen ($filename, "r"); // open remote status file
if (!$infile)
{
echo "<p>Unable to open status file.<br>";
exit;
}
$remote_timestamp = 0;
if(!feof ($infile)) // only 1 read should be needed for the status file
{
$buffer = fgets($infile, 4096);
$remote_timestamp = trim( $buffer );
echo 'Remote status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$remote_timestamp) . '<br>';
}
fclose( $infile ); // close the remote status file
if( $remote_timestamp - $current_timestamp > 79200 ) // 1 day = 60*60*24
{
//
// We can do a full get
//
// write our new status file
$outfilename = $local_directory . "status.txt";
$outfile = fopen($outfilename, "w");
if( !$outfile )
{
echo "<p>Unable to open save file => " . $outfilename . "<br>";
exit;
}
fputs($outfile, $buffer);
fclose($outfile);
//
// Now get our guild roster file
//
$filename = 'http://www.warcraftrealms.com/exports/guildexport.php?guildid=' . $guild_id;
$infile = fopen ($filename, "r");
if (!$infile)
{
echo "<p>Unable to open remote file.<br>\n";
exit;
}
$outfilename = $local_directory . "guildroster.csv";
$outfile = fopen($outfilename, "w");
if( !$outfile )
{
echo "<p>Unable to open save file => " . $outfilename . "<br>\n";
exit;
}
while (!feof ($infile))
{
$buffer = fgets($infile, 4096);
fputs($outfile, $buffer);
}
fclose($outfile);
fclose($infile);
}
?>
And then for my main guild list, I wanted it split out by class, and sorted by guild rank, display pvp rank and activity, so I came up with the following:
Code: Select all
<?php
// Author: Skraggy of Aggramar, based on Rollie's sample code
$local_directory = "download/"; // this is the directory where your local files
// will be written to and read from. Make sure
// you have WRITE privileges on this directory
$rankorder = array('High Champion','Chief','Chieftan','Elder','Tribal Guardian','Oathsworn','Tribesman','Brave','Officer Alt','Tribealt','Unknown');
$classorder = array('Druid','Hunter','Mage','Priest','Rogue','Shaman','Warlock','Warrior');
// Read in roster file
$filename = $local_directory . "guildroster.csv";
$infile = fopen ($filename, "r");
if (!$infile)
{
echo "<p>Unable to open local roster file.<br>";
exit;
}
// Read header
$header = fgetcsv($infile, 4096, ",");
// Populate Guild List array
while (($data = fgetcsv($infile, 4096, ",")) !== FALSE) {
if (isset($header)) {
foreach ($header as $key=>$heading) {
$row[$heading]=(isset($data[$key])) ? $data[$key] : '';
}
$guildlist[]=$row;
}
}
fclose($infile);
while (list($key,$class) = each($classorder)) {
printClass($class,$guildlist,$rankorder);
}
// don't forget our credit link =)
echo "<p> Guild data provided by <a href='http://www.warcraftrealms.com/'>WarcraftRealms.com</a>.</p>";
function printClass($classname,$guildarray,$ranks) {
while (list($key,$member) = each($guildarray)) {
if ($member['Class'] == $classname) {
$classlist[] = $member;
}
}
$num = count($classlist);
echo "<h3><a name=\"$classname\">$classname</a>: $num</h3>\n";
echo '<table width="640" bgcolor="#5A1F0C"><tr><th>Name</th><th>Race</th><th>Level</th><th>Guild Rank</th><th>PvP Rank</th><th>Status</th></tr>';
foreach ($ranks as $key=>$rank) {
$ranklist = getRankList($rank,$classlist);
if ($ranklist) {
outputTable($ranklist);
}
}
echo '</table>';
return;
}
function getRankList($rankname,$classarray) {
$return = false;
while (list($key,$member) = each($classarray)) {
if ($member['GuildRank'] == $rankname) {
$return[] = $member;
}
}
return $return;
}
function outputTable($sortedclass) {
while (list($key,$member) = each($sortedclass)) {
list($name,$race,$class,$level,$lastseen,$guildrank,$pvprank) = array_values($member);
//Activity threshold variables in DAYS
$idle = 14;
$inactive = 30;
$interval = ((time() - strtotime($lastseen))/86400);
$status = '<font color="red">Inactive</font>';
if ($interval <= $idle) {
$status = '<font color="#ccffcc">Active</font>';
}
else if ($interval > $idle && $interval < $inactive) {
$status = '<font color="#ffcc99">Idle</font>';
}
// Horde Ranks
$pvpranklist = array('','','','','', 'Scout', 'Grunt', 'Sergeant', 'Senior Sergeant', 'First Sergeant', 'Stone Guard', 'Blood Guard', 'Legionnaire', 'Centurion', 'Champion', 'Lieutenant General', 'General', 'General', 'Warlord', 'High Warlord');
if (!$pvprank) $pvprank = '000004';
$pvptitle = $pvpranklist[intval($pvprank)];
echo '<tr><td>' . $name . '</td><td>' . $race . '</td><td>' . $level . '</td><td>' . $guildrank . '</td><td>' . $pvptitle . '</td><td>' . $status . '</td></tr>';
}
return;
}
?>
Items to note if you want to use this is you'll have to change the rankorder value to list the ranks your guild has, and the order you want them displayed per class. Also, if you're alliance, you'll need to change the pvpranklist to the alliance ranks.
Anyway.... the result is you get something like this (which includes the other two activity and summary code snippets earlier in the thread):
http://gamehaven.org/wow/tribe/roster.php