2015-04-01 15:46:10 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura user image serving
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-07-30 01:12:53 +00:00
|
|
|
// Define that this page won't require templating
|
|
|
|
define('SAKURA_NO_TPL', true);
|
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
// Include components
|
2015-04-06 16:15:20 +00:00
|
|
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php';
|
2015-04-01 15:46:10 +00:00
|
|
|
|
|
|
|
// Set Content type
|
2015-08-21 22:07:45 +00:00
|
|
|
//header('Content-Type: application/octet-stream');
|
2015-04-01 15:46:10 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
// Path to user uploads
|
2015-08-09 20:27:03 +00:00
|
|
|
$userDirPath = ROOT . Configuration::getConfig('user_uploads') . '/';
|
2015-06-04 12:41:55 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
// Check if the m(ode) GET request is set
|
|
|
|
if(isset($_GET['m'])) {
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
switch($_GET['m']) {
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
case 'avatar':
|
2015-05-03 21:43:25 +00:00
|
|
|
// Set paths
|
2015-08-29 13:25:57 +00:00
|
|
|
$noAvatar = ROOT . str_replace('{{ TPL }}', $templateName, Configuration::getConfig('no_avatar_img'));
|
|
|
|
$deactiveAvatar = ROOT . str_replace('{{ TPL }}', $templateName, Configuration::getConfig('deactivated_avatar_img'));
|
|
|
|
$bannedAvatar = ROOT . str_replace('{{ TPL }}', $templateName, Configuration::getConfig('banned_avatar_img'));
|
2015-04-01 15:46:10 +00:00
|
|
|
|
|
|
|
// If ?u= isn't set or if it isn't numeric
|
2015-06-19 16:12:44 +00:00
|
|
|
if(!isset($_GET['u']) || !is_numeric($_GET['u']) || $_GET['u'] == 0) {
|
2015-08-29 13:25:57 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
$serveImage = $noAvatar;
|
|
|
|
break;
|
2015-08-29 13:25:57 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
// Get user data
|
2015-08-21 22:07:45 +00:00
|
|
|
$user = new User($_GET['u']);
|
2015-04-27 16:30:31 +00:00
|
|
|
|
|
|
|
// If user is deactivated use deactive avatar
|
2015-08-21 22:07:45 +00:00
|
|
|
if($user->checkIfUserHasRanks([0, 1])) {
|
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
$serveImage = $deactiveAvatar;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user is banned
|
2015-08-21 22:07:45 +00:00
|
|
|
if($user->checkBan()) {
|
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
$serveImage = $bannedAvatar;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user has an avatar set
|
2015-08-21 22:07:45 +00:00
|
|
|
if(empty($user->data['userData']['userAvatar']) || !file_exists($userDirPath . $user->data['userData']['userAvatar'])) {
|
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
$serveImage = $noAvatar;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-04-27 16:30:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
// Check if the avatar exist and assign it to a value
|
2015-08-21 22:07:45 +00:00
|
|
|
$serveImage = $userDirPath . $user->data['userData']['userAvatar'];
|
2015-04-27 16:30:31 +00:00
|
|
|
break;
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
case 'background':
|
2015-05-03 21:43:25 +00:00
|
|
|
// Set paths
|
2015-08-09 20:27:03 +00:00
|
|
|
$noBackground = ROOT . Configuration::getConfig('no_background_img');
|
2015-04-01 15:46:10 +00:00
|
|
|
|
|
|
|
// If ?u= isn't set or if it isn't numeric
|
|
|
|
if(!isset($_GET['u']) || !is_numeric($_GET['u'])) {
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
$serveImage = $noBackground;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 21:43:25 +00:00
|
|
|
// Get user data
|
2015-08-21 22:07:45 +00:00
|
|
|
$user = new User($_GET['u']);
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
// If user is deactivated use deactive avatar
|
2015-08-21 22:07:45 +00:00
|
|
|
if($user->checkIfUserHasRanks([0, 1])) {
|
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noBackground;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user is banned
|
2015-08-09 18:26:01 +00:00
|
|
|
if(Bans::checkBan($_GET['u'])) {
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noBackground;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user has a background set
|
2015-08-21 22:07:45 +00:00
|
|
|
if(empty($user->data['userData']['profileBackground']) || !file_exists($userDirPath . $user->data['userData']['profileBackground'])) {
|
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noBackground;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the avatar exist and assign it to a value
|
2015-08-21 22:07:45 +00:00
|
|
|
$serveImage = $userDirPath . $user->data['userData']['profileBackground'];
|
2015-06-04 12:41:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'header':
|
|
|
|
// Set paths
|
2015-08-09 20:27:03 +00:00
|
|
|
$noHeader = ROOT . Configuration::getConfig('no_header_img');
|
2015-06-04 12:41:55 +00:00
|
|
|
|
|
|
|
// If ?u= isn't set or if it isn't numeric
|
|
|
|
if(!isset($_GET['u']) || !is_numeric($_GET['u'])) {
|
|
|
|
$serveImage = $noHeader;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get user data
|
2015-08-21 22:07:45 +00:00
|
|
|
$user = new User($_GET['u']);
|
2015-06-04 12:41:55 +00:00
|
|
|
|
|
|
|
// If user is deactivated use deactive avatar
|
2015-08-21 22:07:45 +00:00
|
|
|
if($user->checkIfUserHasRanks([0, 1])) {
|
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noHeader;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user is banned
|
2015-08-09 18:26:01 +00:00
|
|
|
if(Bans::checkBan($_GET['u'])) {
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noHeader;
|
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user has a background set
|
2015-08-21 22:07:45 +00:00
|
|
|
if(empty($user->data['userData']['profileHeader']) || !file_exists($userDirPath . $user->data['userData']['profileHeader'])) {
|
|
|
|
|
2015-06-04 12:41:55 +00:00
|
|
|
$serveImage = $noHeader;
|
2015-05-03 21:43:25 +00:00
|
|
|
break;
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-05-03 21:43:25 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
// Check if the avatar exist and assign it to a value
|
2015-08-21 22:07:45 +00:00
|
|
|
$serveImage = $userDirPath . $user->data['userData']['profileHeader'];
|
2015-04-27 16:30:31 +00:00
|
|
|
break;
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
default:
|
2015-08-09 20:27:03 +00:00
|
|
|
$serveImage = ROOT . Configuration::getConfig('pixel_img');
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
}
|
2015-05-03 21:43:25 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
} else {
|
|
|
|
|
2015-08-09 20:27:03 +00:00
|
|
|
$serveImage = ROOT . Configuration::getConfig('pixel_img');
|
2015-04-01 15:46:10 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 15:46:10 +00:00
|
|
|
$serveImage = file_get_contents($serveImage);
|
|
|
|
|
2015-08-10 19:09:47 +00:00
|
|
|
header('Content-Type: '. getimagesizefromstring($serveImage)['mime']);
|
2015-04-01 15:46:10 +00:00
|
|
|
|
|
|
|
print $serveImage;
|