X-Git-Url: http://git.onelab.eu/?p=www-register-wizard.git;a=blobdiff_plain;f=codeigniter%2FCommon.php;h=eb9dce6484c369ca5a0dc669ec44b5d8eee66ffa;hp=3c75f5e6cf592867c5467354a24e85899c53c9de;hb=47598daa8c32dbbd72db83dc33f2ce91b3f6f7b0;hpb=4afb2fe256f094a1caf6bff14f51c6a88938cc9f diff --git a/codeigniter/Common.php b/codeigniter/Common.php index 3c75f5e..eb9dce6 100644 --- a/codeigniter/Common.php +++ b/codeigniter/Common.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 @@ -16,16 +16,27 @@ // ------------------------------------------------------------------------ /** - * Common Functions - * - * Loads the base classes and executes the request. - * - * @package CodeIgniter - * @subpackage codeigniter - * @category Common Functions - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/ - */ +* Determines if the current version of PHP is greater then the supplied value +* +* Since there are a few places where we conditionally test for PHP > 5 +* we'll set a static variable. +* +* @access public +* @param string +* @return bool +*/ +function is_php($version = '5.0.0') +{ + static $_is_php; + $version = (string)$version; + + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; + } + + return $_is_php[$version]; +} // ------------------------------------------------------------------------ @@ -127,16 +138,34 @@ function &load_class($class, $instantiate = TRUE) if ($is_subclass == TRUE) { $name = config_item('subclass_prefix').$class; - $objects[$class] =& new $name(); + + $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } $name = ($class != 'Controller') ? 'CI_'.$class : $class; - - $objects[$class] =& new $name(); + + $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } +/** + * Instantiate Class + * + * Returns a new class object by reference, used by load_class() and the DB class. + * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. + * + * Use: $obj =& instantiate_class(new Foo()); + * + * @access public + * @param object + * @return object + */ +function &instantiate_class(&$class_object) +{ + return $class_object; +} + /** * Loads the main config.php file * @@ -203,10 +232,10 @@ function config_item($item) * @access public * @return void */ -function show_error($message) +function show_error($message, $status_code = 500) { $error =& load_class('Exceptions'); - echo $error->show_error('An Error Was Encountered', $message); + echo $error->show_error('An Error Was Encountered', $message, 'error_general', $status_code); exit; } @@ -252,6 +281,91 @@ function log_message($level = 'error', $message, $php_error = FALSE) $LOG->write_log($level, $message, $php_error); } + +/** + * Set HTTP Status Header + * + * @access public + * @param int the status code + * @param string + * @return void + */ +function set_status_header($code = 200, $text = '') +{ + $stati = array( + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + + 400 => 'Bad Request', + 401 => 'Unauthorized', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported' + ); + + if ($code == '' OR ! is_numeric($code)) + { + show_error('Status codes must be numeric', 500); + } + + if (isset($stati[$code]) AND $text == '') + { + $text = $stati[$code]; + } + + if ($text == '') + { + show_error('No status text available. Please check your status code number or supply your own message text.', 500); + } + + $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; + + if (substr(php_sapi_name(), 0, 3) == 'cgi') + { + header("Status: {$code} {$text}", TRUE); + } + elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0') + { + header($server_protocol." {$code} {$text}", TRUE, $code); + } + else + { + header("HTTP/1.1 {$code} {$text}", TRUE, $code); + } +} + + /** * Exception Handler *