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/public/imageserve.php

192 lines
5.5 KiB
PHP
Raw Normal View History

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
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
2015-04-01 15:46:10 +00:00
// Check if the m(ode) GET request is set
if (isset($_GET['m'])) {
switch ($_GET['m']) {
2015-04-01 15:46:10 +00:00
case 'avatar':
2015-05-03 21:43:25 +00:00
// Set paths
2015-09-14 21:41:43 +00:00
$noAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
2015-12-04 14:19:10 +00:00
Config::get('no_avatar_img')
2015-09-14 21:41:43 +00:00
);
$deactiveAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
2015-12-04 14:19:10 +00:00
Config::get('deactivated_avatar_img')
2015-09-14 21:41:43 +00:00
);
$bannedAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
2015-12-04 14:19:10 +00:00
Config::get('banned_avatar_img')
2015-09-14 21:41:43 +00:00
);
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-04-01 15:46:10 +00:00
$serveImage = $noAvatar;
break;
}
2015-04-27 16:30:31 +00:00
// Get user data
2015-12-29 01:27:49 +00:00
$user = User::construct($_GET['u']);
2015-04-27 16:30:31 +00:00
// If user is deactivated use deactive avatar
2016-01-10 18:24:47 +00:00
if ($user->permission(Perms\Site::DEACTIVATED)) {
2015-04-27 16:30:31 +00:00
$serveImage = $deactiveAvatar;
break;
}
// Check if user is banned
2016-01-10 18:24:47 +00:00
if ($user->checkBan() || $user->permission(Perms\Site::RESTRICTED)) {
2015-04-27 16:30:31 +00:00
$serveImage = $bannedAvatar;
break;
}
// Check if user has an avatar set
2016-01-17 01:58:31 +00:00
if (!$user->avatar) {
$serveImage = $noAvatar;
break;
}
// Attempt to get the file
$serve = new File($user->avatar);
// Check if the file exists
if (!$serve->id) {
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
2016-01-17 01:58:31 +00:00
$serveImage = $serve->data;
$serveMime = $serve->mime;
$serveName = $serve->name;
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-12-04 14:19:10 +00:00
$noBackground = ROOT . Config::get('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-04-01 15:46:10 +00:00
$serveImage = $noBackground;
break;
}
2015-05-03 21:43:25 +00:00
// Get user data
2015-12-29 01:27:49 +00:00
$user = User::construct($_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
2016-01-10 18:24:47 +00:00
if ($user->permission(Perms\Site::DEACTIVATED)) {
2015-06-04 12:41:55 +00:00
$serveImage = $noBackground;
break;
}
// Check if user is banned
2016-01-10 18:24:47 +00:00
if (Bans::checkBan($_GET['u']) || $user->permission(Perms\Site::RESTRICTED)) {
2015-06-04 12:41:55 +00:00
$serveImage = $noBackground;
break;
}
// Check if user has a background set
2016-01-17 01:58:31 +00:00
if (!$user->background) {
$serveImage = $noBackground;
break;
}
// Attempt to get the file
$serve = new File($user->background);
// Check if the file exists
if (!$serve->id) {
2015-06-04 12:41:55 +00:00
$serveImage = $noBackground;
break;
}
// Check if the avatar exist and assign it to a value
2016-01-17 01:58:31 +00:00
$serveImage = $serve->data;
$serveMime = $serve->mime;
$serveName = $serve->name;
2015-06-04 12:41:55 +00:00
break;
case 'header':
// Set paths
2015-12-04 14:19:10 +00:00
$noHeader = ROOT . Config::get('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'])) {
2015-06-04 12:41:55 +00:00
$serveImage = $noHeader;
break;
}
// Get user data
2015-12-29 01:27:49 +00:00
$user = User::construct($_GET['u']);
2015-06-04 12:41:55 +00:00
// If user is deactivated use deactive avatar
2016-01-10 18:24:47 +00:00
if ($user->permission(Perms\Site::DEACTIVATED)) {
2015-06-04 12:41:55 +00:00
$serveImage = $noHeader;
break;
}
// Check if user is banned
2016-01-10 18:24:47 +00:00
if (Bans::checkBan($_GET['u']) || $user->permission(Perms\Site::RESTRICTED)) {
2015-06-04 12:41:55 +00:00
$serveImage = $noHeader;
break;
}
2016-01-17 01:58:31 +00:00
// Check if user has a header set
if (!$user->header) {
$serveImage = $noHeader;
break;
}
// Attempt to get the file
$serve = new File($user->header);
// Check if the file exists
if (!$serve->id) {
2015-06-04 12:41:55 +00:00
$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
2016-01-17 01:58:31 +00:00
$serveImage = $serve->data;
$serveMime = $serve->mime;
$serveName = $serve->name;
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-12-04 14:19:10 +00:00
$serveImage = ROOT . Config::get('pixel_img');
2015-05-03 21:43:25 +00:00
2015-04-01 15:46:10 +00:00
}
2015-08-21 22:07:45 +00:00
} else {
2015-12-04 14:19:10 +00:00
$serveImage = ROOT . Config::get('pixel_img');
2015-08-21 22:07:45 +00:00
}
2016-01-17 01:58:31 +00:00
// Do some more checks
if (!isset($serveName) || !isset($serveMime)) {
$serveName = basename($serveImage);
$serveImage = file_get_contents($serveImage);
$serveMime = getimagesizefromstring($serveImage)['mime'];
}
2016-01-17 01:58:31 +00:00
// Add original filename
header('Content-Disposition: inline; filename="' . $serveName . '"');
2015-04-01 15:46:10 +00:00
// Set content type
2016-01-17 01:58:31 +00:00
header('Content-Type: ' . $serveMime);
2015-04-01 15:46:10 +00:00
2016-01-17 01:58:31 +00:00
echo $serveImage;