<?php
//================================================================
//TODO: Remove when done working on the website
//================================================================
if ($_SERVER['REMOTE_ADDR'] !== '107.192.130.48') {
	echo file_get_contents('index.html');
	die();
}
//================================================================
// API
//================================================================
if ($_SERVER['HTTP_HOST'] == 'api.soganatsu.com' || $_SERVER['HTTP_HOST'] == 'api.soganatsu.net') {
	require_once('php/api.php');
	return;
}
// Include common.php for API and Page
require_once('php/common.php');
//================================================================
// Source File Specialization
//================================================================
if (isset($_GET['code']) && !isset($_GET['page'])) {
	require_once('php/code-files.php');
	OutputSourceFile(getQSA('code'), getQSA('file'), getQSA('sub'));
	return;
}
//================================================================
// MIME Type Specializations
//================================================================
if (isset($_GET['mime'])) {
	$mime = getQSA('mime');
	$path = getQSA('data');
	switch ($mime) {
		case 'html': {
			if (isset($path)) {
				fetchHTML(dirname(__FILE__).$path.getQSA('html'));
				return;
			}
		} break;
		case 'js': {
			if (!isset($path)) $path = '/js/';
			fetchJS(dirname(__FILE__).$path.getQSA('js'));
			return;
		} break;
		case 'css': {
			if (!isset($path)) $path = '/css/';
			fetchCSS(dirname(__FILE__).$path.getQSA('css'));
			return;
		} break;
		case 'img': {
			if (!isset($path)) $path = '/img/';
			fetchImage(dirname(__FILE__).$path.getQSA('img'),getQSA('ext'));
			return;
		} break;
		case 'font': {
			if (!isset($path)) $path = '/font/';
			fetchFont(dirname(__FILE__).$path.getQSA('font'),getQSA('ext'));
			return;
		} break;
		case 'glsl': {
			if (!isset($path)) $path = '/glsl/';
			fetchGLSL(dirname(__FILE__).$path.getQSA('glsl'),getQSA('ext'));
			return;
		} break;
		case 'json': {
			if (!isset($path)) $path = '/data/json/';
			fetchJSON(dirname(__FILE__).$path.getQSA('json'));
			return;
		} break;
		case 'zip': {
			if (!isset($path)) $path = '/data/zip/';
			fetchZIP(dirname(__FILE__).$path.getQSA('zip'));
			return;
		} break;
		case 'video': {
			if (!isset($path)) $path = '/data/video/';
			fetchVideo(dirname(__FILE__).$path.getQSA('video'),getQSA('ext'));
			return;
		} break;
		//default: { fileNotFound(); } break;
	}
}
//================================================================
// SITE PAGE
//================================================================
//$_MOBILE = false;
$_TITLE = 'Soganatsu';
require_once('php/site.php');
//$_SESSION['test'] = '12345';
// Setup default header meta tags
SiteHeader::addTag('<meta charset="UTF-8" />');
SiteHeader::addTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
SiteHeader::addTag('<meta name="theme-color" content="#205597" media="(prefers-color-scheme: light)" />');
SiteHeader::addTag('<meta name="theme-color" content="#205597" media="(prefers-color-scheme: dark)" />');
SiteHeader::addTag('<meta name="background_color" content="#205597" media="(prefers-color-scheme: light)" />');
SiteHeader::addTag('<meta name="background_color" content="#205597" media="(prefers-color-scheme: dark)" />');
SiteHeader::addTag('<meta name="description" content="Soganatsu personal website" />');
SiteHeader::addTag('<meta name="keywords" content="soganatsu, programming, art, 2d, 3d, video games" />');
SiteHeader::addTag('<link rel="apple-touch-icon" href="/soganatsu-thumb-512.png" />');
SiteHeader::addTag('<link rel="apple-touch-icon-precomposed" href="/soganatsu-thumb-512.png" />');
SiteHeader::addTag('<link rel="apple-touch-startup-image" href="/soganatsu-thumb-512.png" media="orientation: portrait" />');
SiteHeader::addTag('<link rel="apple-touch-startup-image" href="/soganatsu-thumb-512.png" media="orientation: landscape" />');
SiteHeader::addTag('<link rel="icon" href="/favicon.png" />');
SiteHeader::addTag('<link rel="manifest" href="/site.webmanifest" crossorigin="anonymous" />');
// Set the default page title
SiteHeader::setTitle($_TITLE.' - '.(MOBILE ? 'mobile' : 'desktop'));
SiteHeader::addClass('dark-theme');
// Output Page
if (isset($_GET['page'])) {
	// Switch between supported pages
	switch (getQSA('page')) {
		case 'home': { include_once('php/pages/home.php'); } break;
		case 'guides': { include_once('php/pages/guides.php'); } break;
		case 'blog': { include_once('php/pages/blog.php'); } break;
		case 'portfolio': { include_once('php/pages/portfolio.php'); } break;
		case 'projects': { include_once('php/pages/projects.php'); } break;
		//case 'store': { include_once('php/pages/store.php'); } break;
		//case 'download': { include_once('php/pages/download.php'); } break;
		case 'phpinfo': {
			phpinfo();
			die();
		} break;
		// Default to 'Error - Page Not Found'
		default: { include_once('php/pages/errors/page_not_found.php'); } break;
	}
}
// Default Page (home)
else { include_once('php/pages/home.php'); }
/*

https://soganatsu.com
https://soganatsu.com/home

// Error Page(s)
https://soganatsu.com/error/<error_code>

// Admin Control Panel
https://soganatsu.com/acp/

// Pages
https://soganatsu.com/blog/
https://soganatsu.com/guide/
# https://soganatsu.com/tools/
# https://soganatsu.com/projects/
# https://soganatsu.com/search/
# https://soganatsu.com/download/

// Portfolio
https://soganatsu.com/portfolio/
https://soganatsu.com/portfolio/web/(frontend/backend)
https://soganatsu.com/portfolio/software/(games/graphics/codec/networking/crypto/audio/ux/embedded)
# https://soganatsu.com/portfolio/2d/(concept/traditional/digital/pixel/animation)
# https://soganatsu.com/portfolio/3d/(modeling/sculpting/NURBS/texturing/rigging/animation/reels/printing)
# https://soganatsu.com/portfolio/vfx/
# https://soganatsu.com/portfolio/hardware/(fpga/embedded/drawings/products)

// Join the discord (redirects to an invite URL)
https://soganatsu.com/discord

# OAuth2 stuff
https://soganatsu.com/auth/
https://soganatsu.com/login
https://soganatsu.com/logout

// API Endpoints
https://api.soganatsu.com/version
https://api.soganatsu.com/v1/

// Other Ideas
https://soganatsu.com/webcast/
https://soganatsu.com/user/
https://soganatsu.com/vip/
https://soganatsu.com/forum/
https://soganatsu.com/news/
https://soganatsu.com/settings/
https://soganatsu.com/profile/

*/
