-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.php
More file actions
46 lines (38 loc) · 1.49 KB
/
common.php
File metadata and controls
46 lines (38 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
vIDS (virtual Information Display System) for VATSIM
Filename: common.php
Function: Catch-all for commonly used/general-purpose functions
Created: 4/1/21
Edited:
Changes:
*/
function fetch_my_url() { // Returns server URL
$ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
return $ssl."://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?').'/';
}
function is_sysad($vatsim_cid,$artcc_staff,$sso_endpoint) { // Returns system administrator authorization
return ($artcc_staff || (intval($vatsim_cid) == ACONST) || (strpos($sso_endpoint,"dev") !== false)) ? true : false;
}
function auto_version($file) { // Used to version files and bust CloudFlare's caching system for JS
if(strpos($file, '/') !== 0 || !file_exists($_SERVER['DOCUMENT_ROOT'] . $file))
return $file;
$mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $file);
return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file);
}
// Cachebuster for JS on Cloudflare
$documentRoot = '';
if(strpos(basename(__DIR__),'.') !== true) {
$documentRoot = substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],'?'));
if(strlen($documentRoot) < 1) {
$documentRoot = $_SERVER['REQUEST_URI'];
}
}
if(strlen($documentRoot) < 1) {
$documentRoot = '/';
}
// Picks a random image from the $imagesDir to display in the landing page background
$imagesDir = 'img/bg/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
?>