Index: trunk/globals.php =================================================================== diff -u -r2320 -r2853 --- trunk/globals.php (.../globals.php) (revision 2320) +++ trunk/globals.php (.../globals.php) (revision 2853) @@ -56,7 +56,7 @@ } } -$vars = parse_portal_ini($pathtoroot."config.php"); +$vars = parse_portal_ini(FULL_PATH.'/config.php'); while($key = key($vars)) { @@ -1679,15 +1679,26 @@ } /** - * @return int - * @desc Checks for debug mode -*/ + * Checks if debug mode is active + * + * @return bool + */ function IsDebugMode() { return defined('DEBUG_MODE') && constant('DEBUG_MODE') == 1 ? 1 : 0; } /** + * Checks if we are in admin + * + * @return bool + */ +function IsAdmin() +{ + return defined('ADMIN') && constant('ADMIN') == 1 ? 1 : 0; +} + +/** * Two strings in-case-sensitive compare. * Returns >0, when string1 > string2, * <0, when string1 > string2, @@ -1851,5 +1862,66 @@ return 0; } } + + function inp_htmlize($var, $strip = 0) + { + if( is_array($var) ) + { + foreach($var as $k => $v) $var[$k] = inp_htmlize($v, $strip); + } + else + { + $var = htmlspecialchars($strip ? stripslashes($var) : $var); + } + return $var; + } + /** + * Sets in-portal cookies, that will not harm K4 to breath free :) + * + * @param string $name + * @param mixed $value + * @param int $expire + * @author Alex + */ + function set_cookie($name, $value, $expire = 0) + { + $cookie_path = IsAdmin() ? BASE_PATH.'/admin' : BASE_PATH; + setcookie($name, $value, $expire, $cookie_path, $_SERVER['HTTP_HOST']); + } + + /** + * If we are on login required template, but we are not logged in, then logout user + * + * @return bool + */ + function require_login($condition = null, $redirect_params = 'logout=1', $pass_env = false) + { + if( !isset($condition) ) $condition = !admin_login(); + if(!$condition) return false; + + global $objSession, $adminURL; + if( !headers_sent() ) set_cookie('sid', ' ', time() - 3600); + $objSession->Logout(); + if($pass_env) $redirect_params = 'env='.BuildEnv().'&'.$redirect_params; + + header('Location: '.$adminURL.'/index.php?'.$redirect_params); + exit; + } + + if( !function_exists('safeDefine') ) + { + /** + * Define constant if it was not already defined before + * + * @param string $const_name + * @param string $const_value + * @access public + */ + function safeDefine($const_name, $const_value) + { + if(!defined($const_name)) define($const_name,$const_value); + } + } + ?>