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: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87:
<?php
/*
* In this file we add method shortcuts
*/
/**
* @param string $var Returns the value of $config[$var].
* @param string $subVar (optional) Returns the value of $config[$var][$subVar].
* @aliasFor Config::singleton()->get($var)
*
* @return mixed|null
*/
function config($var, $subVar = null) {
return \Core\Config::singleton()->get($var, $subVar);
}
/**
* @param string $view The location of the $template within the /src/view folder
* @param array $vars The vars to add to the view
* @param string $template An optional template if we don't want to use defaultTemplate.php
*
* @return string The rendered $template with $vars
* @throws Exception If a render problem occurs
*/
function view($view, $vars = [], $template = '') {
echo \Core\ParentController::singleton()->get(str_replace('.', '/', $view), $vars, $template);
}
function t($translationKey) {
$l = \Core\Language::singleton();
$word = $l->getTranslation($translationKey);
return $word ?: $l->getDefaultTranslation($translationKey);
}
/**
* @return string The environment (global var <b>__ENVIRONMENT__</b>) you're working in.
*/
function env() {
return defined('__ENVIRONMENT__') ? __ENVIRONMENT__ : FALSE;
}
/**
* @return bool Whether the environment (global var <b>__ENVIRONMENT__</b>) is production (<b>= "prod"</b>)
*/
function isProd() {
return defined('__ENVIRONMENT__') && __ENVIRONMENT__ == 'prod';
}
/**
* @return bool Whether the environment (global var <b>__ENVIRONMENT__</b>) is developement (<b>= "dev"</b>)
*/
function isDev() {
return defined('__ENVIRONMENT__') && __ENVIRONMENT__ == 'dev';
}
/**
* @return bool Whether the user is authenticated (true) or not (false)
*/
function isAuth() {
return \Core\Providers\Session::getUser('role') >= __ROLE_ADMIN__;
}
/**
* @return bool Whether the request was made through an AJAX call
*/
function isAjax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
/**
* Returns whether the PHP server is localhost or remote. True if the host matches <b>*.local</b> or <b>localhost</b>.
* From the Symfony framework.
* @return bool TRUE if the $_SERVER is a local machine; FALSE if it's a remote machine
*/
function isLocalServer() {
$remoteServer = (
isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
|| php_sapi_name() === 'cli-server')
);
return !$remoteServer;
}