<?PHP
class signature
{
# v-- CONFIGURATION BELOW --v #
var $config = array
(
'database' => array ( "localhost" , "root" , "password" , "theforgottenserver" ),
'vocations' => array ( "No Vocation" , "Sorcerer" , "Druid" , "Paladin" , "Knight" , "Master Sorcerer" , "Elder Druid" , "Royal Paladin" , "Elite Knight" ),
'towns' => array ( 0 => "Rookgaard" , 1 => "Thais" , 2 => "Venore" ),
'groups' => array ( 2 => "Tutor" , 3 => "Senior Tutor" , 4 => "Gamemaster" , 5 => "Community Manager" , 6 => "God" , 7 => "God" ),
'backgrounds' => array ( 'background1' , 'background2' ),
'color' => "#FF0000"
);
# ^-- CONFIGURATION ABOVE --^ #
// Database functions.
function connectDatabase ( $database ) { @mysql_connect ( $database[0] , $database[1] , $database[2] ); @mysql_select_db ( $database[3] ); }
function query ( $query ) { return @mysql_query ( $query ); }
function fetchArray ( $query ) { return @mysql_fetch_array ( $query ); }
function secure ( $query ) { return @mysql_real_escape_string ( $query ); }
function numRows ( $query ) { return @mysql_num_rows ( $query ); }
// Convert the color (HEX) into RGB format.
function convertHex ( $hex )
{
$hex = ereg_replace ( "#" , "" , $hex );
$color = array();
if ( strlen ( $hex ) == 6 ):
$color['r'] = hexdec ( substr ( $hex , 0 , 2 ) );
$color['g'] = hexdec ( substr ( $hex , 2 , 2 ) );
$color['b'] = hexdec ( substr ( $hex , 4 , 2 ) );
endif;
return $color;
}
// Signature functions.
function character ( $character )
{
// Define presets.
$query = "SELECT `id` , `account_id` , `group_id` , `name` , `sex` , `promotion` , `vocation` , `town_id` , `rank_id` , `online` , `level` , `lastlogin` FROM `players` WHERE `name` = '{$character}'";
$fetchRow = $this -> fetchArray ( $this -> query ( $query ) );
$numRows = $this -> numRows ( $this -> query ( $query ) );
$rank = $this -> fetchArray ( $this -> query ( "SELECT `guild_id` , `name` FROM `guild_ranks` WHERE `id` = '{$fetchRow[rank_id]}'" ) );
$guild = $this -> fetchArray ( $this -> query ( "SELECT `name` FROM `guilds` WHERE `id` = '{$rank[guild_id]}'" ) );
$status = $this -> fetchArray ( $this -> query ( "SELECT `premdays` FROM `accounts` WHERE `account_id` = '{$numRows[account_id]}'" ) );
// Define certain arrays into one variable.
$arrays['status'] = ( $fetchRow['online'] == 1 ? 'online' : 'offline' );
$arrays['gender'] = ( $fetchRow['sex'] == 1 ? 'Male' : 'Female' );
$arrays['vocation'] = ( $fetchRow['promotion'] != 0 ? $this -> config['vocations'][$fetchRow['vocation']+4] : $this -> config['vocations'][$fetchRow['vocation']] );
$arrays['guild'] = ( $fetchRow['rank_id'] > 0 ? "Guild: " . ( $fetchRow['sex'] == 1 ? 'He' : 'She' ) . " is " . $rank['name'] . " of the " . $guild['name'] . "\q" : NULL );
$arrays['position'] = ( $fetchRow['group_id'] > 1 ? "Position: " . $this -> config['groups'][$fetchRow['group_id']] . "\q" : NULL );
$arrays['lastlogin'] = ( date ( "M d Y, H:i:s" , $fetchRow['lastlogin'] "\q" ) );
$arrays['statusprem'] = ( $status['premdays'] < 1 ? 'free account' : 'premium account' );
// Showable fields (\q equals new line, had to create my own shortcut as I clear all whitespaces further down in the script).
$return = "
Name: {$fetchRow[name]} ({$arrays[status]}) \q
Sex: {$arrays[gender]} \q
Level: {$fetchRow[level]} \q
Profession: {$arrays[vocation]} \q
Residence: {$this -> config[towns][$fetchRow[town_id]]} \q
{$arrays[guild]}
{$arrays[position]}
Last Login: {$arrays[lastlogin]} \q
Status: {$arrays[statusprem]}
";
// Make certain fields bold.
$bolds = "Name: \nSex: \nLevel: \nProfession: \nResidence: \n" . ( $fetchRow['rank_id'] > 0 ? "Guild: \n" : NULL ) . ( $fetchRow['group_id'] > 1 ? "Position: \n" : NULL ) . "Last Login:";
// Return output.
if ( $numRows == 1 )
return $return . "|||" . $bolds;
else
return "A character with that name does not exist.";
}
// Create a function to generate the signature.
function generate ( $character , $background )
{
// Connect to the database.
$this -> connectDatabase ( $this -> config['database'] );
$split = explode ( "|||" , $this -> character ( $this -> secure ( $character ) ) );
header ( "Content-type: image/png" );
// Check if the background exists, if not - create one.
if ( file_exists ( "{$this -> config[backgrounds][$background]}.png" ) != 1 ):
$image = imagecreate ( 400 , 120 );
imagecolorallocate ( $image , 255 , 255 , 255 );
$split[0] = "The requested image does not exist.";
$split[1] = NULL;
else:
$image = imagecreatefrompng ( $this -> config['backgrounds'][$background] . ".png" );
endif;
$color = $this -> convertHex ( $this -> config['color'] );
$content = explode ( "\q" , str_replace ( array ( "\n" , "\r" , "\t" , "\o" , "\xOB" ) , '' , $split[0] ) );
$bolds = explode ( "\n" , str_replace ( array ( "\r" , "\t" , "\o" , "\xOB" ) , '' , $split[1] ) );
// Print text.
for ( $i = 0.5; $i <= count ( $content ) ; $i++ ):
imagestring ( $image, 2, 7, 12 * $i, $content[$i], imagecolorallocate ( $image , $color['r'] , $color['g'] , $color['b'] ) );
endfor;
// Print bold text.
for ( $i = 0.5; $i <= count ( $bolds ) ; $i++ ):
imagestring ( $image, 2, 6, 12 * $i, $bolds[$i], imagecolorallocate ( $image , $color['r'] , $color['g'] , $color['b'] ) );
endfor;
imagepng ( $image );
imagedestroy ( $image );
}
}
$signature = new signature();
// Check if it should print the signature or the form.
if ( !empty ( $_GET ) ):
$signature -> generate ( $_GET['character'] , $_GET['image'] );
else:
?>
<form method="get">
Name: <input type="text" name="character" /><br /><br />
<?PHP
// Loop backgrounds.
foreach ( $signature -> config['backgrounds'] as $bg => $value ):
echo '<input type="radio" name="image" value="' . $bg . '" /> <img src="' . $value . '.png" /><br />';
endforeach;
?>
<input type="submit" value="Create Signature" />
</form>
<?PHP
endif;
?>