Welcome to Geeklog, Anonymous Sunday, September 01 2024 @ 01:29 am EDT
Geeklog Forums
Turn script into block
New
Anonymous
Hey, there's a server status script from 53x11.com that really really would like to get into a block and have been poking at for about 2 hours trying to get it in with its HTML img option but no go
So I guess my next option is to try and make it into a PHP block, and since I don't know much about writing PHP I was hoping someone would be able to help me out
I'm thinking it might be easy with an include function, but if not probably slap the code from the script right into lib-custom (somehow
).. but I really don't know where to begin.
I'm pasting the code now so I hope I don't irritate anyone
// 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 = "Archimonde"; // 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 = true; // 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;
}
?>
Thanks much.
![Crying or Very sad Crying or Very sad](http://www.geeklog.net/images/smiles/icon_cry.gif)
So I guess my next option is to try and make it into a PHP block, and since I don't know much about writing PHP I was hoping someone would be able to help me out
![praying it will work praying it will work](http://www.geeklog.net/images/smiles/pray.gif)
I'm thinking it might be easy with an include function, but if not probably slap the code from the script right into lib-custom (somehow
![Shocked Shocked](http://www.geeklog.net/images/smiles/icon_eek.gif)
I'm pasting the code now so I hope I don't irritate anyone
![Doh! - that was a mistake Doh! - that was a mistake](http://www.geeklog.net/images/smiles/doh.gif)
Text Formatted 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 = "Archimonde"; // 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 = true; // 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;
}
?>
Thanks much.
10
12
Quote
I_D
Anonymous
![sleepy sleepy](https://www.geeklog.net/forum/image_set/moods/sleepy.gif)
I'd love to know the answer to this question too...
12
14
Quote
All times are EDT. The time is now 01:29 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content