står såhär när jag trycker där
<?php
// erig.net Tibia Online/Offline Userbar Dynamic Image Generation Script
//
// Requires PHP to be compiled with:
// --with-gd --with-png-dir --with-freetype-dir --enable-gd-native-ttf
//
// Database schema is specific to erig.net. Use this script as a basis
// only.
// Bring's in $time, the timestamp of the last online update
require_once 'online.inc.php';
// Convert a vocation from its integer representation to a compressed textual one
function convert_voc($voc)
{
switch ($voc) {
case 0: return 'ROOK';
case 1: return 'K';
case 2: return 'P';
case 3: return 'S';
case 4: return 'D';
case 5: return 'EK';
case 6: return 'RP';
case 7: return 'MS';
case 8: return 'ED';
default: return '??';
}
}
// If the client is happy enough to do the caching for us, let them!
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] != '') {
$t = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ($t && $time <= $t) {
header('HTTP/1.0 304 Not Modified');
header('Date: ' . gmdate('D, j M Y H:i:s') . ' GMT');
header('Last-Modified: ' . gmdate('D, j M Y H:i:s', $time) . ' GMT');
header('Content-Type: image/png');
exit;
}
}
// Some player name instanciations. Removes evil characters and characters that can't be in a Tibia player name
$_GET['player'] = str_replace('userbar/', '', $_GET['player']);
$name = substr($_GET['player'], 0, 32);
$name = preg_replace('/[\x00-\x1f]/', '', $name);
$name = str_replace('_', ' ', $name);
$name = str_replace(array('`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '[', '{', ']', '}', '\\', '|', ':', ';', '<', '>', '.', '/', '?'), '', $name);
if ($name == '')
return;
// Names in Tibia always start with an uppercase letter
$name = ucfirst($name);
// Write cache hits/misses to a log file
$fp = fopen('log.txt', 'a');
// Set up memcache
$mc = new Memcache();
$mc->connect('127.0.0.1', 11211);
// Our memcache key, or, potentially a file-based method of storage.
$x = './data/' . $time . '/userbar_' . md5($name) . '.png';
$y = false;
if ($mc) {
$y = $mc->get($x);
}
else {
echo "Error: couldn't connect to memcache";
exit;
}
// Image was in memcache, serve it
if ($y !== false) {
header('Date: ' . gmdate('D, j M Y H:i:s') . ' GMT');
header('Last-Modified: ' . gmdate('D, j M Y H:i:s', $time) . ' GMT');
header('Content-Type: image/png');
fwrite($fp, "hit $x\n");
fclose($fp);
echo $y;
exit;
}
else {
fwrite($fp, "miss $x\n");
fclose($fp);
}
// Save the original name as we change it later
$namepng = $name;
// Connect to the database
mysql_connect('localhost', 'username', 'password');
mysql_select_db('databasename');
$res = mysql_query($x = 'SELECT * FROM online WHERE name=\'' . @mysql_real_escape_string($name) . '\'');
if (@mysql_num_rows($res) > 0) {
// Player is currently online
$online = true;
$row = @mysql_fetch_array($res);
$name = $row['name'];
$level = $row['level'];
$voc = convert_voc($row['vocation']);
}
else {
$online = false;
}
// Image dimensions
$w = 350;
$h = 19;
// Create the image
$im = imagecreatetruecolor($w, $h);
// Set up some colours
$col = imagecolorallocate($im, 255, 255, 255);
$col2 = imagecolorallocate($im, 0, 0, 0);
$col3 = imagecolorallocate($im, 69, 69, 69);
$coloff = imagecolorallocate($im, 246, 94, 94);
$colon = imagecolorallocate($im, 94, 246, 94);
$colstuff = imagecolorallocate($im, 94, 246, 246);
// Set up the background colour and the border
imagefilledrectangle($im, 0, 0, $w, $h, $col2);
imagefilledrectangle($im, 1, 1, $w - 2, $h - 2, $col3);
// Font path
$font = 'visitor.fon';
// Include ": " in the name so we can calculate dimensions properly
$name .= ': ';
// Find out name dimensions so we know where to put online/offline text
$namebb = imagettfbbox(7, 0, $font, $name);
// Draw name
imagefttext($im, 7, 0, 8, 12, $col, $font, $name);
// Draw online/offline status
if ($online)
imagefttext($im, 7, 0, $namebb[4] + 4, 12, $colon, $font, 'online');
else
imagefttext($im, 7, 0, $namebb[4] + 4, 12, $coloff, $font, 'offline');
if ($online) {
// Player is online, draw level/vocation status
$levelbb = imagettfbbox(7, 0, $font, $level);
imagefttext($im, 7, 0, $w - $levelbb[4] - 8, 12, $colstuff, $font, $level);
imagefttext($im, 7, 0, $w - $levelbb[4] - 46, 12, $col, $font, 'Level: ');
$vocbb = imagettfbbox(7, 0, $font, $voc);
imagefttext($im, 7, 0, $w - $levelbb[4] - 46 - $vocbb[4] - 20, 12, $colstuff, $font, $voc);
imagefttext($im, 7, 0, $w - $levelbb[4] - 46 - $vocbb[4] - 46, 12, $col, $font, 'Voc: ');
}
// Headers. Last-Modified is used for client-side caching
header('Date: ' . gmdate('D, j M Y H:i:s') . ' GMT');
header('Last-Modified: ' . gmdate('D, j M Y H:i:s', $time) . ' GMT');
header('Content-type: image/png');
// Capture the image so we can store it in memcache
ob_start();
imagepng($im);
$data = ob_get_contents();
ob_end_clean();
// Output the image
echo $data;
// Store the image in memcache
$mc->set('./data/' . $time . '/userbar_' . md5($namepng) . '.png', $data, 0, 600);
// Destroy gd resources
imagecolordeallocate($im, $col);
imagecolordeallocate($im, $col2);
imagecolordeallocate($im, $col3);
imagecolordeallocate($im, $coloff);
imagecolordeallocate($im, $colon);
imagecolordeallocate($im, $colstuff);
imagedestroy($im);
?>
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.