This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/main/imageserve.php

146 lines
4.5 KiB
PHP
Raw Normal View History

2015-04-01 15:46:10 +00:00
<?php
/*
* Sakura user image serving
*/
// Declare Namespace
namespace Sakura;
// 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
header('Content-Type: application/octet-stream');
2015-06-04 12:41:55 +00:00
// Path to user uploads
$userDirPath = ROOT .'content/images/user/';
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-04-27 16:30:31 +00:00
$noAvatar = ROOT .'content/images/no-av.png';
$deactiveAvatar = ROOT .'content/images/deactivated-av.png';
$bannedAvatar = ROOT .'content/images/banned-av.png';
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-04-01 15:46:10 +00:00
$serveImage = $noAvatar;
break;
}
2015-04-27 16:30:31 +00:00
// Get user data
$user = Users::getUser($_GET['u']);
2015-06-04 12:41:55 +00:00
$data = Users::getUserProfileData($user, true);
2015-04-27 16:30:31 +00:00
// If user is deactivated use deactive avatar
if(Users::checkIfUserHasRanks([0, 1], $user, true)) {
$serveImage = $deactiveAvatar;
break;
}
// Check if user is banned
if(false) { // [Flashwave 2015-04-27] Banning isn't implemented yet
$serveImage = $bannedAvatar;
break;
}
// Check if user has an avatar set
2015-06-04 12:41:55 +00:00
if(empty($data['userAvatar']) || !file_exists($userDirPath . $data['userAvatar'])) {
2015-04-27 16:30:31 +00:00
$serveImage = $noAvatar;
break;
}
2015-04-01 15:46:10 +00:00
// Check if the avatar exist and assign it to a value
2015-06-04 12:41:55 +00:00
$serveImage = $userDirPath . $data['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-06-04 12:41:55 +00:00
$noBackground = ROOT .'content/pixel.png';
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'])) {
$serveImage = $noBackground;
break;
}
2015-05-03 21:43:25 +00:00
// Get user data
$user = Users::getUser($_GET['u']);
2015-06-04 12:41:55 +00:00
$data = Users::getUserProfileData($user, true);
2015-05-03 21:43:25 +00:00
2015-06-04 12:41:55 +00:00
// If user is deactivated use deactive avatar
if(Users::checkIfUserHasRanks([0, 1], $user, true)) {
$serveImage = $noBackground;
break;
}
// Check if user is banned
if(false) { // [Flashwave 2015-04-27] Banning isn't implemented yet
$serveImage = $noBackground;
break;
}
// Check if user has a background set
if(empty($data['profileBackground']) || !file_exists($userDirPath . $data['profileBackground'])) {
$serveImage = $noBackground;
break;
}
// Check if the avatar exist and assign it to a value
$serveImage = $userDirPath . $data['profileBackground'];
break;
case 'header':
// Set paths
$noHeader = ROOT .'content/images/triangles.png';
// 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
$user = Users::getUser($_GET['u']);
$data = Users::getUserProfileData($user, true);
// If user is deactivated use deactive avatar
if(Users::checkIfUserHasRanks([0, 1], $user, true)) {
$serveImage = $noHeader;
break;
}
// Check if user is banned
if(false) { // [Flashwave 2015-04-27] Banning isn't implemented yet
$serveImage = $noHeader;
break;
}
// Check if user has a background set
if(empty($data['profileHeader']) || !file_exists($userDirPath . $data['profileHeader'])) {
$serveImage = $noHeader;
2015-05-03 21:43:25 +00:00
break;
}
2015-04-01 15:46:10 +00:00
// Check if the avatar exist and assign it to a value
2015-06-04 12:41:55 +00:00
$serveImage = $userDirPath . $data['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:
$serveImage = ROOT .'content/pixel.png';
2015-05-03 21:43:25 +00:00
2015-04-01 15:46:10 +00:00
}
2015-05-03 21:43:25 +00:00
} else
2015-04-01 15:46:10 +00:00
$serveImage = ROOT .'content/pixel.png';
$serveImage = file_get_contents($serveImage);
header('Content-Type: ' .getimagesizefromstring($serveImage)['mime']);
print $serveImage;