<?php

function isSuperGlobal($name){
    switch($name){
        case 'GLOBALS':
        case '_SERVER':
        case '_GET':
        case '_POST':
        case '_FILES':
        case '_COOKIE':
        case '_SESSION':
        case '_REQUEST':
        case '_ENV':        return true;    break;
        default:            return false;   break;
    }
}

function i($i = '') {
	foreach($GLOBALS as $key=>$val){
	    if(!isSuperGlobal($key))                     
	        global $$key;
	}
	
	ob_start();
	global $basedir;
	include $basedir . 'pages/' . $i . '.php';
	return ob_get_clean();
}

function url($url = '') {
	global $baseurl;
	return $baseurl . $url;
}

function url_origin($s, $use_forwarded_host=false) {
    $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
    $sp = strtolower($s['SERVER_PROTOCOL']);
    $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
    $port = $s['SERVER_PORT'];
    $port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
    $host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : $s['SERVER_NAME']);
    return $protocol . '://' . $host . $port;
}
function full_url($s, $use_forwarded_host=false)
{
    return url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
}