I already searched for the answers but there are no real answers for us non-programmers. I really appreciate your solution, thx!
Here's the link to the page.
btw, I started editing the page to use curl but it's still broke, lists the members but it still gives errors. It might be easier for others to follow with the original fopen commands so i left it in the code below just in case anyone else runs into this problem.
Code: Select all
<?php
//
// Rostertest.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 = "./"; // this is the directory where your local files
// will be written to and read from. Make sure
// you have WRITE priveledges on this directory
$guild_id = 308437; // get this number from the link posted on the
// guilddisplay.php page
$pvpranktext[1] = "<i>i.</i> Scout";
$pvpranktext[2] = "<i>ii.</i> Grunt";
$pvpranktext[3] = "<i>iii.</i> Sergeant";
$pvpranktext[4] = "<i>iv.</i> Senior Sergeant";
$pvpranktext[5] = "<i>v.</i> First Sergeant";
$pvpranktext[6] = "<i>vi.</i> Stone Guard";
$pvpranktext[7] = "<i>vii.</i> Blood Guard";
$pvpranktext[8] = "<i>viii.</i> Legionnaire";
$pvpranktext[9] = "<i>ix.</i> Centurion";
$pvpranktext[10] = "<i>x.</i> Champion";
$pvpranktext[11] = "<i>xi.</i> Lieutenant General";
$pvpranktext[12] = "<i>xii.</i> General";
$pvpranktext[13] = "<i>xiii.</i> Warlord";
$pvpranktext[14] = "<i>xiv.</i> High Warlord";
//Activity threshold variables in DAYS
$idle = 14; //before $idle days you are active
$inactive = 30; //after $idle days and before $inacive day you are idle
//after $inacive days you are... uhm... inacive
$seconds_in_a_day = 24*60*60; //self explanitory.
//Initiallize all counts
$inactive_count=0;
$idle_count=0;
$active_count=0;
echo '<head><link href="style.css" rel="stylesheet" type="text/css" /></head></head><body>';
//
// 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 '<div class="smalltext">No status file available, assuming this is the first run</div>';
}
else
{
// read our status file time
$buffer = fgets($infile, 4096);
$current_timestamp = trim( $buffer );
//echo '<div class="smalltext">Local status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$current_timestamp) . '</div>';
}
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 '<div class="smalltext">Unable to open status file.</div>';
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 '<div class="smalltext">Remote status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$remote_timestamp) . '</div><br>';
}
fclose( $infile ); // close the remote status file
if( $remote_timestamp - $current_timestamp > 86400 ) // 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 '<div class="smalltext">Unable to open save file => " . $outfilename . "</div>';
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 '<div class="smalltext">Unable to open remote file.</div>\n';
exit;
}
$outfilename = $local_directory . "guildroster.csv";
$outfile = fopen($outfilename, "w");
if( !$outfile )
{
echo '<div class="smalltext">Unable to open save file => " . $outfilename . "</div>\n';
exit;
}
while (!feof ($infile))
{
$buffer = fgets($infile, 4096);
fputs($outfile, $buffer);
}
fclose($outfile);
fclose($infile);
}
//
// Now let's just output our roster as it's given
//
$filename = $local_directory . "guildroster.csv";
$infile = fopen ($filename, "r");
if (!$infile)
{
echo '<div class="smalltext">Unable to open local roster file.</div>';
exit;
}
// do one read to get the header
$buffer = fgets($infile, 4096);
echo '<div align="center"><table><tr><th>name</th><th>race</th><th>class</th><th>lvl</th><th>last seen</th><th>rank</th><th>pvp rank</th></tr>';
// read the entries
while (!feof ($infile))
{
$buffer = fgets($infile, 4096);
list( $name, $race, $class, $level, $last_seen, $rank, $pvp_rank ) = explode(",",$buffer);
$pvp_rank_t = $pvp_rank-4;
$member_count++;
{
echo '<tr><td>' . $name . '</td><td>' . $race . '</td><td>' . $class . '</td><td>' . $level . '</td><td>' . $last_seen . '</td><td>' . $rank . '</td><td>' . $pvpranktext[$pvp_rank_t] . '</td></tr>';
}
$interval = ((time() - strtotime($last_seen))/86400); //takes the interval in seconds and converts into days
if ($interval < $idle) {
$active_count = $active_count + 1;
}
else if ( $interval >= $idle && $interval < $inactive) {
$idle_count = $idle_count + 1;
}
else if ( $interval >= $inactive ) {
$inactive_count = $inactive_count + 1;
}
}
$member_count = $member_count-1;
$active_percent = round(($active_count/$member_count)*100);
$idle_percent = round(($idle_count/$member_count)*100);
$inactive_percent = round(($inactive_count/$member_count)*100);
echo '</table></div>';
echo '<div class="smalltext" style="text-align:center">';
echo "$member_count";
echo ' members / ';
echo "$active_percent";
echo '% active / ';
echo "$idle_percent";
echo '% idle / ';
echo "$inactive_percent";
echo '% inactive';
echo ' ( last seen > 14 days = idle / last seen > 30 days = inative )</div>';
// don't forget our credit link =)
echo '<br><div class="smalltext" style="text-align:center">Last updated ' . strftime("%A %B %d, %Y - %I:%M:%p",$remote_timestamp) . '</div><br>';
echo '<br><div class="smalltext">[ <a href="http://www.warcraftrealms.com/guilds/' . $guild_id . '" target="new">list in warcraftrealms.com</a> ][ <a href="http://www.warcraftrealms.com/guildexes/' . $guild_id . '" target="new">ex-members list</a> ]</div>';
echo '<br><div class="smalltext">Guild data provided by <a href="http://www.warcraftrealms.com/" target="new">WarcraftRealms.com</a>.';
echo '</div></body>'
?>