Index: branches/5.3.x/core/kernel/globals.php =================================================================== diff -u -N -r15580 -r15677 --- branches/5.3.x/core/kernel/globals.php (.../globals.php) (revision 15580) +++ branches/5.3.x/core/kernel/globals.php (.../globals.php) (revision 15677) @@ -1,6 +1,6 @@ never match + if ( php_sapi_name() == 'cli' ) { return false; } $ip_match = false; $ip_addresses = $ip_list ? explode($separator, $ip_list) : Array (); + $application =& kApplication::Instance(); + $client_ip = $application->getClientIp(); + foreach ($ip_addresses as $ip_address) { - if (self::netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) { + if ( self::netMatch($ip_address, $client_ip) ) { $ip_match = true; break; } @@ -675,6 +677,45 @@ } /** + * Returns instance of DateTime class with date set based on timestamp + * + * @static + * @param int $timestamp + * @return DateTime + * @access public + */ + public static function dateFromTimestamp($timestamp) + { + if ( version_compare(PHP_VERSION, '5.3.0', '<') ) { + $date = new DateTime('@' . $timestamp); + $date->setTimezone(new DateTimeZone(getenv('TZ'))); + } + else { + $date = new DateTime(); + $date->setTimestamp($timestamp); + } + + return $date; + } + + /** + * Returns timestamp from given DateTime class instance + * + * @static + * @param DateTime $date_time + * @return int|string + * @access public + */ + public static function timestampFromDate(DateTime $date_time) + { + if ( version_compare(PHP_VERSION, '5.3.0', '<') ) { + return $date_time->format('U'); + } + + return $date_time->getTimestamp(); + } + + /** * Generates random numeric id * * @static @@ -698,6 +739,21 @@ return $id_part_1 . $id_part_2 . $id_part_3; } + + /** + * Changes script resource limits. Omitted argument results in limit removal. + * + * @static + * @param string|int $memory_limit + * @param int $time_limit + * @return void + * @access public + */ + public static function setResourceLimit($memory_limit = null, $time_limit = null) + { + set_time_limit(isset($time_limit) ? $time_limit : 0); + ini_set('memory_limit', isset($memory_limit) ? $memory_limit : -1); + } } /** @@ -735,7 +791,7 @@ * @param int $scanner_mode * @return Array */ - function parse_ini_string($ini, $process_sections = false, $scanner_mode = null) + function parse_ini_string($ini, $process_sections = false, $scanner_mode = NULL) { # Generate a temporary file. $tempname = tempnam('/tmp', 'ini');