<?php
const FILENAME = 'version.txt';

if(!file_exists(FILENAME)) {
	header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
	header('Content-Type: text/plain; charset=utf-8');
	echo 'The file "'.FILENAME.'" is missing.';
	exit;
}

$version = trim(file_get_contents(FILENAME));

header('Last-Modified: '.gmdate(TIMESTAMP_FORMAT, filemtime(FILENAME)).' GMT');
header('Expires: 7200');

if(filter_has_var(INPUT_GET, 'callback')) {
	header('Content-Type: application/javascript; charset=utf-8');
	$content = filter_input(INPUT_GET, 'callback', FILTER_SANITIZE_STRING).'(\''.$version.'\')';
	echo $content;
	exit;
}

header('Content-Type: text/plain; charset=utf-8');
echo $version;
?>