Merge pull request #120 from Alvaritos/master

Guild logo upload and Market item name
This commit is contained in:
Stefan A. Brannfjell 2014-05-18 22:32:43 +02:00
commit e52fb6a2ef
5 changed files with 196 additions and 61 deletions

View File

@ -296,6 +296,9 @@
// Restricted names
$config['invalidNameTags'] = array("god", "gm", "cm", "gamemaster", "hoster", "admin", "admim", "adm", "owner", "staff");
// Use guild logo system
$config['use_guild_logos'] = 4;
// Level requirement to create guild? (Just set it to 1 to allow all levels).
$config['create_guild_level'] = 8;

View File

@ -407,4 +407,103 @@ function sanitize($data) {
function output_errors($errors) {
return '<ul><li>'. implode('</li><li>', $errors) .'</li></ul>';
}
// Resize images
function resize_imagex($file, $width, $height) {
list($w, $h) = getimagesize($file['tmp']);
$ratio = max($width/$w, $height/$h);
$h = ceil($height / $ratio);
$x = ($w - $width / $ratio) / 2;
$w = ceil($width / $ratio);
$path = 'engine/guildimg/'.$file['new_name'];
$imgString = file_get_contents($file['tmp']);
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
imagegif($tmp, $path);
imagedestroy($image);
imagedestroy($tmp);
return true;
}
// Guild logo upload security
function check_image($image) {
$image_data = array('new_name' => $_GET['name'].'.gif', 'name' => $image['name'], 'tmp' => $image['tmp_name'], 'error' => $image['error'], 'size' => $image['size'], 'type' => $image['type']);
// First security check, quite useless but still do its job
if ($image_data['type'] === 'image/gif') {
// Second security check, lets go
$check = getimagesize($image_data['tmp']);
if ($check) {
// Third
if ($check['mime'] === 'image/gif') {
$path_info = pathinfo($image_data['name']);
// Last one
if ($path_info['extension'] === 'gif') {
// Resize image
$img = resize_imagex($image_data, 150, 150);
if ($img) {
header('Location: guilds.php?name='. $_GET['name']);
exit();
}
} else {
header('Location: guilds.php?name='. $_GET['name']);
exit();
}
} else {
header('Location: guilds.php?name='. $_GET['name']);
exit();
}
} else {
header('Location: guilds.php?name='. $_GET['name']);
exit();
}
} else {
header('Location: guilds.php?name='. $_GET['name']);
exit();
}
}
// Check guild logo
function logo_exists($guild) {
if (file_exists('engine/guildimg/'.$guild.'.gif')) {
echo'engine/guildimg/'.$guild.'.gif';
} else {
echo'engine/guildimg/default@logo.gif';
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -167,7 +167,7 @@ if (user_logged_in() === true) {
// Display the specific guild page
?>
<h1>Guild: <?php echo sanitize($_GET['name']);
<h1><img src="<?php logo_exists(sanitize($_GET['name'])); ?>"></img> Guild: <?php echo sanitize($_GET['name']);
?> </h1>
<table id="guildViewTable" class="table table-striped">
<tr class="yellow">
@ -534,8 +534,31 @@ if ($highest_access >= 2) {
<?php
}
}
if ($config['use_guild_logos']) {
?>
<!-- form to upload guild logo -->
<form action="" method="post" enctype="multipart/form-data">
<ul>
<li>Upload guild logo:<br>
<input type="file" name="file" id="file" accept="image/gif">
<input type="submit" name="submit" value="Upload guild logo">
</li>
</ul>
</form>
<?php
if (!empty($_FILES['file'])) {
check_image($_FILES['file']);
echo '<br><br>';
}
} ?>
<!-- forms to invite character -->
<form action="" method="post">
<ul>

View File

@ -25,6 +25,7 @@ if (!$compare) {
<h2>WTS: Want to sell</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
@ -36,6 +37,7 @@ if (!$compare) {
foreach (($offers['wts'] ? $offers['wts'] : array()) as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
@ -50,6 +52,7 @@ if (!$compare) {
<h2>WTB: Want to buy</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
@ -61,6 +64,7 @@ if (!$compare) {
foreach (($offers['wtb'] ? $offers['wtb'] : array()) as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
@ -88,6 +92,7 @@ if (!$compare) {
<h2>Active offers</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
@ -104,6 +109,7 @@ if (!$compare) {
} else {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
@ -121,6 +127,7 @@ if (!$compare) {
<h2>Want to buy:</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
@ -131,6 +138,7 @@ if (!$compare) {
foreach ($buylist as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>
@ -147,6 +155,7 @@ if (!$compare) {
<h2>Old purchased offers</h2>
<table class="table tbl-hover">
<tr class="yellow">
<td>Item name</td>
<td>Item</td>
<td>Count</td>
<td>Price for 1</td>
@ -156,6 +165,7 @@ if (!$compare) {
foreach (($historyOffers ? $historyOffers : array()) as $o) {
?>
<tr>
<td><?php getItemNameById($o['item_id']); ?></td>
<td><img src="<?php echo "http://".$server."/".$o['item_id'].".".$imageType; ?>" alt="Item Image"></td>
<td><?php echo $o['amount']; ?></td>
<td><?php echo number_format($o['price'], 0, "", " "); ?></td>