>>  Site Map >>  Forums >>  Blocks 7x

Forum module - topics in forum:



Blocks 7x - Discussions regarding PHP-Nuke Blocks. 7x



WoW Server Status - Convert into a block?

Taken from : http://53x11.com/?articleno=10

World of Warcraft Server Status

It's a couple of php files thrown together to produce a server status indicator on a website.

I was wondering how I'd go about converting it into a block. I've taken a look at the block generator you guys have. I'm no expert with programming, but would the block generator still work assuming more than one php file is involved?

It's just that there's another file which calls another function for it. Assuming I just pasted the main file into the block generator, would it still work as a block?

Here's the code from the main "wowserverstatus.php" file;

Code: :
<?php

// WOW Server Status
// Version 3.2
// Copyright 2005 Nick Schaffner
// http://53x11.com

//////// Set the following variables, make sure to remain
//////// within the quotes.  You can substitute any varible
//////// (except Server Name) with a url to a image.

if (!$realm)


$server    = "Lighting's Blade";   // Your full Server name, case sensitive


$up       = 'Server Up';      // Set your "Server Up" message
$down       = 'Server Down';   // Set your "Server Down" message
$max      = 'Max (Queued)';   // Set Maxed (Queued)
$high      = 'High';      // Set High Population
$medium      = 'Medium';      // Set Medium Population
$low      = 'Low';      // Set Low Population
$error      = 'Server Error';   // Set Error Message

$timer      = 10;         // Minutes between status update refresh 0-60


if (!$image)
$generate_image = false;      // Set to TRUE if you would like the script
               // to automatically generate an image


if (!$display)
$display    = 'full';      // Set to 'half' to only display server status      
$folder_path     = 'images/wowss/';   // Path to wowss folder

$language    = 'english';      // Set to 'german', 'english' or 'french'

$url       = 'http://www.worldofwarcraft.com/serverstatus';

// World of Wacraft status page URL,
// change to http://www.wow-europe.com/en/serverstatus for Europeon servers
// change to http://www.wow-europe.com/de/serverstatus for German servers
// change to http://www.wow-europe.com/fr/serverstatus for French servers





//////// Configure what the script outputs as text
//////// Edit if you have a knowledge of PHP and HTML

function output($server,$servertype,$serverstatus,$serverpop) { return "




<u>$server</u> $servertype: <b>$serverstatus | $serverpop</b>




"; }

//////// PHP Magic Below, Don't Edit

$magic_array = array(min,server,servertype,serverstatus,serverpop,err);
if ($realm) $server = $realm;
if ($image == "true") $generate_image = true;
if ($image == "false") $generate_image = false;


// Check timestamp, update when ready

if (substr($folder_path, -1, 1) != "/") $folder_path = "$folder_path/";
$timestamp = $folder_path . "wowss_data.txt";
$min = date(i)*1;
$info = explode(",", file_get_contents($timestamp));
if (filesize($timestamp) == 0) { $pass = true; }
if ($min >= ($info[0]+$timer) or $min < $info[0] or $realm or $pass) {


// Get and format HTML data

error_reporting(0);
$html = file_get_contents($url);
if ($html) {
 
$server = str_replace("\\", "",str_replace("'", "'", $server));
$length = strlen($server);
$pos = strpos($html, $server);
if (!$pos) { $error = "$error, check Realm name"; $err = true; }


// Figure out Serverstatus

$serverstatus = stristr(substr(substr($html, -(strlen($html) - $pos + 164)), 0 ,20), 'up');
if (!$serverstatus) {$serverstatus = 'down'; $serverpop = 'low';
} else $serverstatus = 'up';


// Figure out Servertype

$servertype = strtolower(substr(substr($html, -(strlen($html) - ($pos + 100))), 0, 150));
if ($language == 'french')  $types = array('jcj','normal','jdr');
else $types = array('pvp','normal','rp');
foreach ($types as $i) {
if (strpos($servertype,$i)) { $servertype = translate($i); break; }
}
if ($servertype == 'rp') { $length++; $servertype = 'Roleplay'; }
else if ($servertype == 'normal') $servertype = 'PVE';
else if ($servertype == 'pvp') $servertype= 'PVP';
else $err = true;


// Figure out Server Pop.

if (!$serverpop) {$serverpop = strtolower(substr(substr($html, -(strlen($html) - ($pos + 240))),0,150));
if ($language == 'german') $levels = array('warteschlange','hoch','mittel','niedrig');
if ($language == 'french') $levels = array("file d'attente",'lev','moyenne','faible');
if ($language == 'english') $levels = array('max','high','medium','low');

foreach ($levels as $i) {
if (strpos($serverpop,$i)) { $serverpop = translate($i); break; }
}}

} else $err = true;


// Write info to data file for storage

if (!$realm) {

foreach($magic_array as $value) {
   
   $data = "$data" . $$value . ",";

}

$handle = fopen($timestamp,"w");
flock($handle, LOCK_EX);
fwrite($handle, $data);
flock($handle, LOCK_UN);
fclose($handle);

}

} // If timer isn't up yet, fetch old data and output

else {

   $i=0;
   foreach ($info as $value) {
      
   $$magic_array[$i] = $value;
   $i++;
}
            
}


// Where to go and what to do function calls

if ($generate_image) {

   imgoutput ($server,$servertype,$serverstatus,$serverpop,$err,$folder_path,$display);

   } else {
   
   $serverstatus = $$serverstatus; $serverpop = $$serverpop;
   if (!$err) { echo trim(output($server,$servertype,$serverstatus,$serverpop));
   } else { echo $error; }

}



// Begin dynamic image generation function

function imgoutput ($server,$servertype,$serverstatus,$serverpop,$err,$folder_path,$display) {

$serverfont = $folder_path . 'silkscreen.ttf';
$typefont = $folder_path . 'silkscreenb.ttf';

header("Content-type: image/png");


// Error control

if ($serverstatus == "down") $serverpop = "offline";
if ($err){$serverstatus = "unknown"; $serverpop = "error";}


// Get and combine base images, set colors

$back = imagecreatefrompng($folder_path . strtolower($serverstatus) . '.png');

if ($display == "full") {

$backwidth = imagesx($back);
   
$bottom = imagecreatefrompng($folder_path . strtolower($serverstatus) . '2.png');
$serverpop = imagecreatefrompng($folder_path . strtolower($serverpop) . '.png');
$full = imagecreate($backwidth,(imagesy($back)+imagesy($bottom)));
$bg = imagecolorallocate($full, 0, 255, 255);
$red = imagecolorallocate($full,204,0,0); // HIGH Red color
imagecolortransparent($full, $bg);
imagecopy($full,$back,0,0,0,0,$backwidth,imagesy($back));
imagecopy($full,$bottom,0,imagesy($back),0,0,imagesx($bottom),imagesy($bottom));
$back = $full;

$textcolor = imagecolorallocate($back, 51, 51, 51);
$shadow = imagecolorclosest($back, 255, 204, 0);

imagecopy($back,$serverpop,round(($backwidth-imagesx($serverpop))/2),62,0,0,imagesx($serverpop),imagesy($serverpop));


// Ouput centered $server name

$maxw = 62;
$box = imagettfbbox(6,0,$serverfont,$server);
$w = abs($box[0]) + abs($box[2]);

if ($w > $maxw) {
   
   $i = $w;
   $t = strlen($server);

   while ($i > $maxw) {
   $t--;
   $box = imagettfbbox (6, 0,$serverfont,substr($server,0,$t));
     $i = abs($box[0]) + abs($box[2]);

   }
   
   $t = strrpos(substr($server, 0, $t), " ");

   $output[0] = substr($server, 0, $t);
   $output[1] = ltrim(substr($server, $t));
   $vadj = -6;

} else { $output[0] = $server;}

$i = 0;
foreach($output as $value) {

$box = imagettfbbox(6,0,$serverfont,$value);
$w = abs($box[0]) + abs($box[2]);

imagettftext($back, 6, 0, round(($backwidth-$w)/2)+1, 58+($i*8)+$vadj, $shadow, $serverfont, $value);
imagettftext($back, 6, 0, round(($backwidth-$w)/2), 57+($i*8)+$vadj, -$textcolor, $serverfont, $value);
$i++;

}


// Ouput centered $servertype

if ($servertype and !$err) {
$box = imagettfbbox(6,0,$typefont,$servertype);
$w = abs($box[0]) + abs($box[2]);
imagettftext($back, 6, 0, round(($backwidth-$w)/2)+1, 85, $shadow, $typefont, $servertype);
imagettftext($back, 6, 0, round(($backwidth-$w)/2), 84, -$textcolor, $typefont, $servertype);

}

}

imagepng($back);
imagedestroy($back);

}

function translate($word) {
   
   global $language;
   
   if ($language == 'german') {

      if ($word == 'warteschlange') $word = 'max';
      if ($word == 'hoch') $word = 'high';
      if ($word == 'mittel') $word = 'medium';
      if ($word == 'niedrig') $word = 'low';
      
   }
   
   if ($language == 'french') {
      
      if ($word == "file d'attente") $word = 'max';
      if ($word == 'lev') $word = 'high';
      if ($word == 'moyenne') $word = 'medium';
      if ($word == 'faible') $word = 'low';
      if ($word == 'jcj') $word = 'pvp';
      if ($word == 'jdr') $word = 'rp';
      
   }
   
   return $word;
}

?>


and here's the separate file "gd_info.php";

Code: :

<?php

function describeGDdyn() {
  echo "\n<ul><li>GD support: ";
  if(function_exists("gd_info")){
   echo "<font color=\"#00ff00\">yes</font>";
   $info = gd_info();
   $keys = array_keys($info);
   for($i=0; $i<count($keys); $i++) {
       if(is_bool($info[$keys[$i]])) echo "</li>\n<li>" . $keys[$i] .": " . yesNo($info[$keys[$i]]);
       else echo "</li>\n<li>" . $keys[$i] .": " . $info[$keys[$i]];
   }
  } else { echo "<font color=\"#ff0000\">no</font>"; }
  echo "</li></ul>";
}

function yesNo($bool){
  if($bool) return "<font color=\"#00ff00\"> yes</font>";
  else return "<font color=\"#ff0000\"> no</font>";
}

echo describeGDdyn();

?>


Can anyone help?






I've converted the wowserverstatus.php into a block file, uploaded and activated the block.

However, I'm getting the error that

"There is a problem right now with this block."




Attention! You are currently viewing sitemap page!
We strongly suggest to look at original content

Search from web

Valid HTML 4.01 Valid CSS