diff --git a/.hgflow b/.hgflow
new file mode 100644
index 00000000..ad6e56e0
--- /dev/null
+++ b/.hgflow
@@ -0,0 +1,8 @@
+[Basic]
+develop = develop
+feature = feature/
+version_tag =
+publish = default
+release = release/
+hotfix = hotfix/
+
diff --git a/.hgignore b/.hgignore
index 880040b3..5ee4d823 100644
--- a/.hgignore
+++ b/.hgignore
@@ -3,4 +3,5 @@ syntax: glob
.DS_Store
syntax: regexp
-system/cache/(?!index\.html|\.htaccess)
\ No newline at end of file
+application/cache/(?!index\.html|\.htaccess)
+application/logs/(?!index\.html|\.htaccess)
diff --git a/.hgtags b/.hgtags
index 8fb6def3..d14ae5a4 100644
--- a/.hgtags
+++ b/.hgtags
@@ -6,3 +6,18 @@ be717c80433bd1466202ea00d40e5dae5239f952 v1.6.1
c859ee06332f440d2135b916d3a9c926708de72a v1.6.3
3b6f3beea1262d35735167ee77c1fa8ea8d78d0c v1.7.2
0000000000000000000000000000000000000000 v1.7.2
+ca87887086193cf375ea30e7d4e5139dbf330783 v2.0.0
+1941a814526f8aa7186112e6b9bfd868c5c4afbf v2.0.1
+1941a814526f8aa7186112e6b9bfd868c5c4afbf v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+f97a33039a37fc0c3f12e48407ca08e281b6b375 v2.0.1
+f97a33039a37fc0c3f12e48407ca08e281b6b375 v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+52cd3ed4a9ea5c2b0e2bdd38e9822161ef547f9a v2.0.1
+52cd3ed4a9ea5c2b0e2bdd38e9822161ef547f9a v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+0000000000000000000000000000000000000000 v2.0.1
+1941a814526f8aa7186112e6b9bfd868c5c4afbf v2.0.1
+52107601203719d6149219b28ec93d1d90c748a7 v2.0.2
diff --git a/system/cache/.htaccess b/application/cache/.htaccess
similarity index 100%
rename from system/cache/.htaccess
rename to application/cache/.htaccess
diff --git a/system/cache/index.html b/application/cache/index.html
similarity index 100%
rename from system/cache/index.html
rename to application/cache/index.html
diff --git a/application/config/autoload.php b/application/config/autoload.php
index 90b1a808..53129c9c 100644
--- a/application/config/autoload.php
+++ b/application/config/autoload.php
@@ -37,7 +37,7 @@
|
*/
-$autoload['packages'] = array(APPPATH.'third_party');
+$autoload['packages'] = array();
/*
diff --git a/application/config/config.php b/application/config/config.php
index 5c6cc0ae..1ec65435 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -262,11 +262,13 @@
| 'cookie_prefix' = Set a prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
+| 'cookie_secure' = Cookies will only be set if a secure HTTPS connection exists.
|
*/
-$config['cookie_prefix'] = '';
-$config['cookie_domain'] = '';
-$config['cookie_path'] = '/';
+$config['cookie_prefix'] = "";
+$config['cookie_domain'] = "";
+$config['cookie_path'] = "/";
+$config['cookie_secure'] = FALSE;
/*
|--------------------------------------------------------------------------
@@ -286,9 +288,15 @@
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
| checked on a submitted form. If you are accepting user data, it is strongly
| recommended CSRF protection be enabled.
+|
+| 'csrf_token_name' = The token name
+| 'csrf_cookie_name' = The cookie name
+| 'csrf_expire' = The number in seconds the token should expire.
*/
$config['csrf_protection'] = FALSE;
-
+$config['csrf_token_name'] = 'csrf_test_name';
+$config['csrf_cookie_name'] = 'csrf_cookie_name';
+$config['csrf_expire'] = 7200;
/*
|--------------------------------------------------------------------------
@@ -351,4 +359,4 @@
/* End of file config.php */
-/* Location: ./application/config/config.php */
\ No newline at end of file
+/* Location: ./application/config/config.php */
diff --git a/application/config/database.php b/application/config/database.php
index 24d611ac..b4b34bf6 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -26,6 +26,13 @@
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
+| NOTE: For MySQL and MySQLi databases, this setting is only used
+| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
+| (and in table creation queries made with DB Forge).
+| There is an incompatibility in PHP with mysql_real_escape_string() which
+| can make your site vulnerable to SQL injection if you are using a
+| multi-byte character set and are running versions lower than these.
+| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
diff --git a/application/config/migration.php b/application/config/migration.php
new file mode 100644
index 00000000..509fd90a
--- /dev/null
+++ b/application/config/migration.php
@@ -0,0 +1,42 @@
+migration->latest() this is the version that schema will
+| be upgraded / downgraded to.
+|
+*/
+$config['migration_version'] = 0;
+
+
+/*
+|--------------------------------------------------------------------------
+| Migrations Path
+|--------------------------------------------------------------------------
+|
+| Path to your migrations folder.
+| Typically, it will be within your application path.
+| Also, writing permission is required within the migrations path.
+|
+*/
+$config['migration_path'] = APPPATH . 'migrations/';
+
+
+/* End of file migration.php */
+/* Location: ./application/config/migration.php */
\ No newline at end of file
diff --git a/application/config/mimes.php b/application/config/mimes.php
index 3815a5aa..8065794f 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -56,7 +56,7 @@
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
- 'mp3' => array('audio/mpeg', 'audio/mpg'),
+ 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
@@ -97,7 +97,8 @@
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
- 'eml' => 'message/rfc822'
+ 'eml' => 'message/rfc822',
+ 'json' => array('application/json', 'text/json')
);
diff --git a/application/controllers/test_redis.php b/application/controllers/test_redis.php
new file mode 100644
index 00000000..576c77a2
--- /dev/null
+++ b/application/controllers/test_redis.php
@@ -0,0 +1,43 @@
+load->library('unit_test');
+
+ $this->load->driver('cache', array('adapter' => 'redis'));
+ }
+
+ function index()
+ {
+ $this->unit->run($this->cache->redis->is_supported(), 'is_true');
+
+ $this->unit->run($this->cache->redis->save('foo', 'bar'), 'is_true');
+
+ $this->unit->run($this->cache->redis->get('foo'), 'bar');
+
+ $this->unit->run($this->cache->redis->delete('foo'), 'is_true');
+
+ $this->unit->run($this->cache->redis->save('foo', 'bar', 1800), 'is_true');
+
+ $this->unit->run(
+ $this->cache->redis->get_metadata('foo'),
+ array(
+ 'data' => 'bar',
+ 'expire' => time() + 1800
+ )
+ );
+
+ $this->unit->run($this->cache->redis->clean(), 'is_true');
+
+ $this->unit->run($this->cache->redis->get('foo'), 'is_false');
+
+ $this->unit->run($this->cache->redis->cache_info(), 'is_array');
+
+ echo $this->unit->report();
+ }
+
+}
diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php
index 79689f01..21bef43d 100644
--- a/application/controllers/welcome.php
+++ b/application/controllers/welcome.php
@@ -2,12 +2,22 @@
class Welcome extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- }
-
- function index()
+ /**
+ * Index Page for this controller.
+ *
+ * Maps to the following URL
+ * http://example.com/index.php/welcome
+ * - or -
+ * http://example.com/index.php/welcome/index
+ * - or -
+ * Since this controller is set as the default controller in
+ * config/routes.php, it's displayed at http://example.com/
+ *
+ * So any other public methods not prefixed with an underscore will
+ * map to /index.php/welcome/
+ * @see http://codeigniter.com/user_guide/general/urls.html
+ */
+ public function index()
{
$this->load->view('welcome_message');
}
diff --git a/application/errors/error_404.php b/application/errors/error_404.php
index a304f456..792726a6 100644
--- a/application/errors/error_404.php
+++ b/application/errors/error_404.php
@@ -1,32 +1,60 @@
-
+
+
404 Page Not Found
-
+
diff --git a/application/errors/error_db.php b/application/errors/error_db.php
index 181de960..b396cda9 100644
--- a/application/errors/error_db.php
+++ b/application/errors/error_db.php
@@ -1,32 +1,60 @@
-
+
+
Database Error
-
+
diff --git a/application/errors/error_general.php b/application/errors/error_general.php
index 7734d34c..fd63ce2c 100644
--- a/application/errors/error_general.php
+++ b/application/errors/error_general.php
@@ -1,32 +1,60 @@
-
+
+
Error
-
+
diff --git a/system/logs/index.html b/application/logs/index.html
similarity index 100%
rename from system/logs/index.html
rename to application/logs/index.html
diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php
index ca68fc10..0bf5a8d2 100644
--- a/application/views/welcome_message.php
+++ b/application/views/welcome_message.php
@@ -4,61 +4,85 @@
Welcome to CodeIgniter
-
+ code {
+ font-family: Consolas, Monaco, Courier New, Courier, monospace;
+ font-size: 12px;
+ background-color: #f9f9f9;
+ border: 1px solid #D0D0D0;
+ color: #002166;
+ display: block;
+ margin: 14px 0 14px 0;
+ padding: 12px 10px 12px 10px;
+ }
+
+ #body{
+ margin: 0 15px 0 15px;
+ }
+
+ p.footer{
+ text-align: right;
+ font-size: 11px;
+ border-top: 1px solid #D0D0D0;
+ line-height: 32px;
+ padding: 0 10px 0 10px;
+ margin: 20px 0 0 0;
+ }
+
+ #container{
+ margin: 10px;
+ border: 1px solid #D0D0D0;
+ -webkit-box-shadow: 0 0 8px #D0D0D0;
+ }
+
-
Welcome to CodeIgniter!
-
-
The page you are looking at is being generated dynamically by CodeIgniter.
+
+
Welcome to CodeIgniter!
-
If you would like to edit this page you'll find it located at:
-
application/views/welcome_message.php
+
+
The page you are looking at is being generated dynamically by CodeIgniter.
-
The corresponding controller for this page is found at:
-
application/controllers/welcome.php
+
If you would like to edit this page you'll find it located at:
+
application/views/welcome_message.php
-
If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.
+
The corresponding controller for this page is found at:
+
application/controllers/welcome.php
+
If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.
+
-
Page rendered in {elapsed_time} seconds
+
+
\ No newline at end of file
diff --git a/index.php b/index.php
index 5bb53d2f..12618c62 100644
--- a/index.php
+++ b/index.php
@@ -2,15 +2,54 @@
/*
*---------------------------------------------------------------
- * PHP ERROR REPORTING LEVEL
+ * APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
- * By default CI runs with error reporting set to ALL. For security
- * reasons you are encouraged to change this to 0 when your site goes live.
- * For more info visit: http://www.php.net/error_reporting
+ * You can load different configurations depending on your
+ * current environment. Setting the environment also influences
+ * things like logging and error reporting.
+ *
+ * This can be set to anything, but default usage is:
+ *
+ * development
+ * testing
+ * production
+ *
+ * NOTE: If you change these, also change the error_reporting() code below
*
*/
- error_reporting(E_ALL);
+ define('ENVIRONMENT', 'development');
+/*
+ *---------------------------------------------------------------
+ * ERROR REPORTING
+ *---------------------------------------------------------------
+ *
+ * Different environments will require different levels of error reporting.
+ * By default development will show errors but testing and live will hide them.
+ */
+
+if (defined('ENVIRONMENT'))
+{
+ switch (ENVIRONMENT)
+ {
+ case 'development':
+ $error_level = E_ALL;
+ break;
+
+ case 'testing':
+ case 'production':
+ $error_level = 0;
+ break;
+
+ default:
+ exit('The application environment is not set correctly.');
+ }
+
+ if (isset($error_level) && function_exists('error_reporting'))
+ {
+ error_reporting($error_level);
+ }
+}
/*
*---------------------------------------------------------------
@@ -22,7 +61,7 @@
* as this file.
*
*/
- $system_path = "system";
+ $system_path = 'system';
/*
*---------------------------------------------------------------
@@ -38,7 +77,7 @@
* NO TRAILING SLASH!
*
*/
- $application_folder = "application";
+ $application_folder = 'application';
/*
* --------------------------------------------------------------------
@@ -64,7 +103,7 @@
// if your controller is not in a sub-folder within the "controllers" folder
// $routing['directory'] = '';
- // The controller class file name. Example: Mycontroller.php
+ // The controller class file name. Example: Mycontroller
// $routing['controller'] = '';
// The controller function you wish to be called.
@@ -94,14 +133,18 @@
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
// --------------------------------------------------------------------
-
-
-
/*
* ---------------------------------------------------------------
* Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
+
+ // Set the current directory correctly for CLI requests
+ if (defined('STDIN'))
+ {
+ chdir(dirname(__FILE__));
+ }
+
if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
@@ -125,6 +168,7 @@
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// The PHP file extension
+ // this global constant is deprecated.
define('EXT', '.php');
// Path to the system folder
@@ -160,7 +204,7 @@
* And away we go...
*
*/
-require_once BASEPATH.'core/CodeIgniter'.EXT;
+require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
/* Location: ./index.php */
\ No newline at end of file
diff --git a/license.txt b/license.txt
index 6ec79425..061cdb9d 100644
--- a/license.txt
+++ b/license.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2008 - 2010, EllisLab, Inc.
+Copyright (c) 2008 - 2011, EllisLab, Inc.
All rights reserved.
This license is a legal agreement between you and EllisLab Inc. for the use
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index d0e1fc68..a200727a 100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -29,6 +29,11 @@
*/
class CI_Benchmark {
+ /**
+ * List of all benchmark markers and when they were added
+ *
+ * @var array
+ */
var $marker = array();
// --------------------------------------------------------------------
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 595e00f2..7b92ddf1 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -32,21 +32,47 @@
* Define the CodeIgniter Version
* ------------------------------------------------------
*/
- define('CI_VERSION', '2.0');
+ /**
+ * CodeIgniter Version
+ *
+ * @var string
+ *
+ */
+ define('CI_VERSION', '2.0.2');
+
+/*
+ * ------------------------------------------------------
+ * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
+ * ------------------------------------------------------
+ */
+ /**
+ * CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
+ *
+ * @var string
+ *
+ */
+ define('CI_CORE', FALSE);
/*
* ------------------------------------------------------
* Load the global functions
* ------------------------------------------------------
*/
- require(BASEPATH.'core/Common'.EXT);
+ require(BASEPATH.'core/Common.php');
/*
* ------------------------------------------------------
* Load the framework constants
* ------------------------------------------------------
*/
- require(APPPATH.'config/constants'.EXT);
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
+ {
+ require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
+ }
+ else
+ {
+ require(APPPATH.'config/constants.php');
+ }
/*
* ------------------------------------------------------
@@ -80,7 +106,7 @@
{
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
}
-
+
/*
* ------------------------------------------------------
* Set a liberal script execution time limit
@@ -129,17 +155,17 @@
/*
* ------------------------------------------------------
- * Instantiate the Unicode class
+ * Instantiate the UTF-8 class
* ------------------------------------------------------
*
- * Note: Order here is rather important as the Unicode
+ * Note: Order here is rather important as the UTF-8
* class needs to be used very early on, but it cannot
* properly determine if UTf-8 can be supported until
* after the Config class is instantiated.
*
*/
- $UNI =& load_class('Unicode', 'core');
+ $UNI =& load_class('Utf8', 'core');
/*
* ------------------------------------------------------
@@ -182,6 +208,13 @@
}
}
+/*
+ * -----------------------------------------------------
+ * Load the security class for xss and csrf support
+ * -----------------------------------------------------
+ */
+ $SEC =& load_class('Security', 'core');
+
/*
* ------------------------------------------------------
* Load the Input class and sanitize globals
@@ -203,7 +236,7 @@
*
*/
// Load the base controller class
- require BASEPATH.'core/Controller'.EXT;
+ require BASEPATH.'core/Controller.php';
function &get_instance()
{
@@ -211,20 +244,20 @@ function &get_instance()
}
- if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
+ if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
{
- require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
+ require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
}
// Load the local application controller
// Note: The Router class automatically validates the controller path using the router->_validate_request().
// If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
- if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
+ if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
- include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
+ include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
@@ -246,7 +279,25 @@ function &get_instance()
OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
)
{
- show_404("{$class}/{$method}");
+ if ( ! empty($RTR->routes['404_override']))
+ {
+ $x = explode('/', $RTR->routes['404_override']);
+ $class = $x[0];
+ $method = (isset($x[1]) ? $x[1] : 'index');
+ if ( ! class_exists($class))
+ {
+ if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ {
+ show_404("{$class}/{$method}");
+ }
+
+ include_once(APPPATH.'controllers/'.$class.'.php');
+ }
+ }
+ else
+ {
+ show_404("{$class}/{$method}");
+ }
}
/*
@@ -289,7 +340,28 @@ function &get_instance()
// methods, so we'll use this workaround for consistent behavior
if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
{
- show_404("{$class}/{$method}");
+ // Check and see if we are using a 404 override and use it.
+ if ( ! empty($RTR->routes['404_override']))
+ {
+ $x = explode('/', $RTR->routes['404_override']);
+ $class = $x[0];
+ $method = (isset($x[1]) ? $x[1] : 'index');
+ if ( ! class_exists($class))
+ {
+ if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ {
+ show_404("{$class}/{$method}");
+ }
+
+ include_once(APPPATH.'controllers/'.$class.'.php');
+ unset($CI);
+ $CI = new $class();
+ }
+ }
+ else
+ {
+ show_404("{$class}/{$method}");
+ }
}
// Call the requested method.
diff --git a/system/core/Common.php b/system/core/Common.php
index 6a3d5ac0..98b84300 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -39,6 +39,8 @@
* @param string
* @return bool TRUE if the current version is $version or higher
*/
+if ( ! function_exists('is_php'))
+{
function is_php($version = '5.0.0')
{
static $_is_php;
@@ -51,6 +53,7 @@ function is_php($version = '5.0.0')
return $_is_php[$version];
}
+}
// ------------------------------------------------------------------------
@@ -64,6 +67,8 @@ function is_php($version = '5.0.0')
* @access private
* @return void
*/
+if ( ! function_exists('is_really_writable'))
+{
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
@@ -88,7 +93,7 @@ function is_really_writable($file)
@unlink($file);
return TRUE;
}
- elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
+ elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
{
return FALSE;
}
@@ -96,6 +101,7 @@ function is_really_writable($file)
fclose($fp);
return TRUE;
}
+}
// ------------------------------------------------------------------------
@@ -112,6 +118,8 @@ function is_really_writable($file)
* @param string the class name prefix
* @return object
*/
+if ( ! function_exists('load_class'))
+{
function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
static $_classes = array();
@@ -128,13 +136,13 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
// thenin the local application/libraries folder
foreach (array(BASEPATH, APPPATH) as $path)
{
- if (file_exists($path.$directory.'/'.$class.EXT))
+ if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = $prefix.$class;
if (class_exists($name) === FALSE)
{
- require($path.$directory.'/'.$class.EXT);
+ require($path.$directory.'/'.$class.'.php');
}
break;
@@ -142,13 +150,13 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
}
// Is the request a class extension? If so we load it too
- if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT))
+ if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
{
$name = config_item('subclass_prefix').$class;
if (class_exists($name) === FALSE)
{
- require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT);
+ require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
}
}
@@ -157,7 +165,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
// Note: We use exit() rather then show_error() in order to avoid a
// self-referencing loop with the Excptions class
- exit('Unable to locate the specified class: '.$class.EXT);
+ exit('Unable to locate the specified class: '.$class.'.php');
}
// Keep track of what we just loaded
@@ -166,6 +174,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
$_classes[$class] = new $name();
return $_classes[$class];
}
+}
// --------------------------------------------------------------------
@@ -176,6 +185,8 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
* @access public
* @return array
*/
+if ( ! function_exists('is_loaded'))
+{
function is_loaded($class = '')
{
static $_is_loaded = array();
@@ -187,6 +198,7 @@ function is_loaded($class = '')
return $_is_loaded;
}
+}
// ------------------------------------------------------------------------
@@ -199,6 +211,8 @@ function is_loaded($class = '')
* @access private
* @return array
*/
+if ( ! function_exists('get_config'))
+{
function &get_config($replace = array())
{
static $_config;
@@ -208,16 +222,20 @@ function &get_config($replace = array())
return $_config[0];
}
- // Fetch the config file
- if ( ! file_exists(APPPATH.'config/config'.EXT))
+ // Is the config file in the environment folder?
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
- exit('The configuration file does not exist.');
+ $file_path = APPPATH.'config/config.php';
}
- else
+
+ // Fetch the config file
+ if ( ! file_exists($file_path))
{
- require(APPPATH.'config/config'.EXT);
+ exit('The configuration file does not exist.');
}
+ require($file_path);
+
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
@@ -238,6 +256,7 @@ function &get_config($replace = array())
return $_config[0] =& $config;
}
+}
// ------------------------------------------------------------------------
@@ -247,6 +266,8 @@ function &get_config($replace = array())
* @access public
* @return mixed
*/
+if ( ! function_exists('config_item'))
+{
function config_item($item)
{
static $_config_item = array();
@@ -264,6 +285,7 @@ function config_item($item)
return $_config_item[$item];
}
+}
// ------------------------------------------------------------------------
@@ -279,12 +301,15 @@ function config_item($item)
* @access public
* @return void
*/
+if ( ! function_exists('show_error'))
+{
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
$_error =& load_class('Exceptions', 'core');
echo $_error->show_error($heading, $message, 'error_general', $status_code);
exit;
}
+}
// ------------------------------------------------------------------------
@@ -298,12 +323,15 @@ function show_error($message, $status_code = 500, $heading = 'An Error Was Encou
* @access public
* @return void
*/
+if ( ! function_exists('show_404'))
+{
function show_404($page = '', $log_error = TRUE)
{
$_error =& load_class('Exceptions', 'core');
$_error->show_404($page, $log_error);
exit;
}
+}
// ------------------------------------------------------------------------
@@ -316,6 +344,8 @@ function show_404($page = '', $log_error = TRUE)
* @access public
* @return void
*/
+if ( ! function_exists('log_message'))
+{
function log_message($level = 'error', $message, $php_error = FALSE)
{
static $_log;
@@ -328,6 +358,7 @@ function log_message($level = 'error', $message, $php_error = FALSE)
$_log =& load_class('Log');
$_log->write_log($level, $message, $php_error);
}
+}
// ------------------------------------------------------------------------
@@ -339,6 +370,8 @@ function log_message($level = 'error', $message, $php_error = FALSE)
* @param string
* @return void
*/
+if ( ! function_exists('set_status_header'))
+{
function set_status_header($code = 200, $text = '')
{
$stati = array(
@@ -413,6 +446,7 @@ function set_status_header($code = 200, $text = '')
header("HTTP/1.1 {$code} {$text}", TRUE, $code);
}
}
+}
// --------------------------------------------------------------------
@@ -430,6 +464,8 @@ function set_status_header($code = 200, $text = '')
* @access private
* @return void
*/
+if ( ! function_exists('_exception_handler'))
+{
function _exception_handler($severity, $message, $filepath, $line)
{
// We don't bother with "strict" notices since they tend to fill up
@@ -446,7 +482,7 @@ function _exception_handler($severity, $message, $filepath, $line)
// Should we display the error? We'll get the current error_reporting
// level and add its bits with the severity bits to find out.
- if (($severity & error_reporting()) == $severity)
+ if (($severity & (int)ini_get('error_reporting')) == $severity)
{
$_error->show_php_error($severity, $message, $filepath, $line);
}
@@ -459,45 +495,46 @@ function _exception_handler($severity, $message, $filepath, $line)
$_error->log_exception($severity, $message, $filepath, $line);
}
+}
- // --------------------------------------------------------------------
-
- /**
- * Remove Invisible Characters
- *
- * This prevents sandwiching null characters
- * between ascii characters, like Java\0script.
- *
- * @access public
- * @param string
- * @return string
- */
- function remove_invisible_characters($str)
- {
- static $non_displayables;
+// --------------------------------------------------------------------
- if ( ! isset($non_displayables))
+/**
+ * Remove Invisible Characters
+ *
+ * This prevents sandwiching null characters
+ * between ascii characters, like Java\0script.
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+if ( ! function_exists('remove_invisible_characters'))
+{
+ function remove_invisible_characters($str, $url_encoded = TRUE)
+ {
+ $non_displayables = array();
+
+ // every control character except newline (dec 10)
+ // carriage return (dec 13), and horizontal tab (dec 09)
+
+ if ($url_encoded)
{
- // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
- $non_displayables = array(
- '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
- '/%1[0-9a-f]/', // url encoded 16-31
- '/[\x00-\x08]/', // 00-08
- '/\x0b/', '/\x0c/', // 11, 12
- '/[\x0e-\x1f]/' // 14-31
- );
+ $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
+ $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
}
+
+ $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
do
{
- $cleaned = $str;
- $str = preg_replace($non_displayables, '', $str);
+ $str = preg_replace($non_displayables, '', $str, -1, $count);
}
- while ($cleaned != $str);
+ while ($count);
return $str;
}
-
+}
/* End of file Common.php */
/* Location: ./system/core/Common.php */
\ No newline at end of file
diff --git a/system/core/Config.php b/system/core/Config.php
index 8ecfba73..5cacf867 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -28,8 +28,23 @@
*/
class CI_Config {
+ /**
+ * List of all loaded config values
+ *
+ * @var array
+ */
var $config = array();
+ /**
+ * List of all loaded config files
+ *
+ * @var array
+ */
var $is_loaded = array();
+ /**
+ * List of paths to search when trying to load a config file
+ *
+ * @var array
+ */
var $_config_paths = array(APPPATH);
/**
@@ -51,7 +66,7 @@ function __construct()
// Set the base_url automatically if none was provided
if ($this->config['base_url'] == '')
{
- if(isset($_SERVER['HTTP_HOST']))
+ if (isset($_SERVER['HTTP_HOST']))
{
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST'];
@@ -74,24 +89,40 @@ function __construct()
*
* @access public
* @param string the config file name
+ * @param boolean if configuration values should be loaded into their own section
+ * @param boolean true if errors should just return false, false if an error message should be displayed
* @return boolean if the file was loaded correctly
*/
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
- $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
+ $file = ($file == '') ? 'config' : str_replace('.php', '', $file);
+ $found = FALSE;
$loaded = FALSE;
- foreach($this->_config_paths as $path)
+ foreach ($this->_config_paths as $path)
{
- $file_path = $path.'config/'.$file.EXT;
+ $check_locations = defined('ENVIRONMENT')
+ ? array(ENVIRONMENT.'/'.$file, $file)
+ : array($file);
- if (in_array($file_path, $this->is_loaded, TRUE))
+ foreach ($check_locations as $location)
{
- $loaded = TRUE;
- continue;
+ $file_path = $path.'config/'.$location.'.php';
+
+ if (in_array($file_path, $this->is_loaded, TRUE))
+ {
+ $loaded = TRUE;
+ continue 2;
+ }
+
+ if (file_exists($file_path))
+ {
+ $found = TRUE;
+ break;
+ }
}
- if ( ! file_exists($path.'config/'.$file.EXT))
+ if ($found === FALSE)
{
continue;
}
@@ -128,6 +159,7 @@ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
$loaded = TRUE;
log_message('debug', 'Config file loaded: '.$file_path);
+ break;
}
if ($loaded === FALSE)
@@ -136,7 +168,7 @@ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
return FALSE;
}
- show_error('The configuration file '.$file.EXT.' does not exist.');
+ show_error('The configuration file '.$file.'.php'.' does not exist.');
}
return TRUE;
@@ -229,8 +261,9 @@ function site_url($uri = '')
$uri = implode('/', $uri);
}
+ $index = $this->item('index_page') == '' ? '' : $this->slash_item('index_page');
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
- return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
+ return $this->slash_item('base_url').$index.trim($uri, '/').$suffix;
}
else
{
@@ -309,4 +342,4 @@ function _assign_to_config($items = array())
// END CI_Config class
/* End of file Config.php */
-/* Location: ./system/core/Config.php */
\ No newline at end of file
+/* Location: ./system/core/Config.php */
diff --git a/system/core/Controller.php b/system/core/Controller.php
index c78be872..fddb81e1 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -48,12 +48,9 @@ public function __construct()
$this->load =& load_class('Loader', 'core');
- $this->load->_base_classes =& is_loaded();
-
- $this->load->_ci_autoloader();
-
+ $this->load->initialize();
+
log_message('debug', "Controller Class Initialized");
-
}
public static function &get_instance()
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 32cb77ba..869739a5 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -30,8 +30,21 @@ class CI_Exceptions {
var $message;
var $filename;
var $line;
+
+ /**
+ * Nesting level of the output buffering mechanism
+ *
+ * @var int
+ * @access public
+ */
var $ob_level;
+ /**
+ * List if available error levels
+ *
+ * @var array
+ * @access public
+ */
var $levels = array(
E_ERROR => 'Error',
E_WARNING => 'Warning',
@@ -84,7 +97,8 @@ function log_exception($severity, $message, $filepath, $line)
* 404 Page Not Found Handler
*
* @access private
- * @param string
+ * @param string the page
+ * @param bool log error yes/no
* @return string
*/
function show_404($page = '', $log_error = TRUE)
@@ -115,6 +129,7 @@ function show_404($page = '', $log_error = TRUE)
* @param string the heading
* @param string the message
* @param string the template name
+ * @param int the status code
* @return string
*/
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
@@ -128,7 +143,7 @@ function show_error($heading, $message, $template = 'error_general', $status_cod
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.$template.EXT);
+ include(APPPATH.'errors/'.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
@@ -164,7 +179,7 @@ function show_php_error($severity, $message, $filepath, $line)
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/error_php'.EXT);
+ include(APPPATH.'errors/error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 70dc6870..33f1c034 100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -28,8 +28,23 @@
*/
class CI_Hooks {
+ /**
+ * Determines wether hooks are enabled
+ *
+ * @var bool
+ */
var $enabled = FALSE;
+ /**
+ * List of all hooks set in config/hooks.php
+ *
+ * @var array
+ */
var $hooks = array();
+ /**
+ * Determines wether hook is in progress, used to prevent infinte loops
+ *
+ * @var bool
+ */
var $in_progress = FALSE;
/**
@@ -65,7 +80,15 @@ function _initialize()
// Grab the "hooks" definition file.
// If there are no hooks, we're done.
- @include(APPPATH.'config/hooks'.EXT);
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
+ }
+ elseif (is_file(APPPATH.'config/hooks.php'))
+ {
+ include(APPPATH.'config/hooks.php');
+ }
+
if ( ! isset($hook) OR ! is_array($hook))
{
diff --git a/system/core/Input.php b/system/core/Input.php
index eb2048e5..bc202b3f 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -28,15 +28,51 @@
*/
class CI_Input {
+ /**
+ * IP address of the current user
+ *
+ * @var string
+ */
var $ip_address = FALSE;
+ /**
+ * user agent (web browser) being used by the current user
+ *
+ * @var string
+ */
var $user_agent = FALSE;
+ /**
+ * If FALSE, then $_GET will be set to an empty array
+ *
+ * @var bool
+ */
var $_allow_get_array = TRUE;
+ /**
+ * If TRUE, then newlines are standardized
+ *
+ * @var bool
+ */
var $_standardize_newlines = TRUE;
- var $_enable_xss = FALSE; // Set automatically based on config setting
- var $_enable_csrf = FALSE; // Set automatically based on config setting
-
+ /**
+ * Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
+ * Set automatically based on config setting
+ *
+ * @var bool
+ */
+ var $_enable_xss = FALSE;
+ /**
+ * Enables a CSRF cookie token to be set.
+ * Set automatically based on config setting
+ *
+ * @var bool
+ */
+ var $_enable_csrf = FALSE;
+ /**
+ * List of all HTTP request headers
+ *
+ * @var array
+ */
protected $headers = array();
-
+
/**
* Constructor
@@ -53,13 +89,10 @@ public function __construct()
$this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
$this->_enable_csrf = (config_item('csrf_protection') === TRUE);
- // Do we need to load the security class?
- if ($this->_enable_xss == TRUE OR $this->_enable_csrf == TRUE)
- {
- $this->security =& load_class('Security');
- }
+ global $SEC;
+ $this->security =& $SEC;
- // Do we need the Unicode class?
+ // Do we need the UTF-8 class?
if (UTF8_ENABLED === TRUE)
{
global $UNI;
@@ -92,8 +125,7 @@ function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
if ($xss_clean === TRUE)
{
- $_security =& load_class('Security');
- return $_security->xss_clean($array[$index]);
+ return $this->security->xss_clean($array[$index]);
}
return $array[$index];
@@ -109,8 +141,21 @@ function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
* @param bool
* @return string
*/
- function get($index = '', $xss_clean = FALSE)
+ function get($index = NULL, $xss_clean = FALSE)
{
+ // Check if a field has been provided
+ if ($index === NULL AND ! empty($_GET))
+ {
+ $get = array();
+
+ // loop through the full _GET array
+ foreach (array_keys($_GET) as $key)
+ {
+ $get[$key] = $this->_fetch_from_array($_GET, $key, $xss_clean);
+ }
+ return $get;
+ }
+
return $this->_fetch_from_array($_GET, $index, $xss_clean);
}
@@ -124,8 +169,21 @@ function get($index = '', $xss_clean = FALSE)
* @param bool
* @return string
*/
- function post($index = '', $xss_clean = FALSE)
+ function post($index = NULL, $xss_clean = FALSE)
{
+ // Check if a field has been provided
+ if ($index === NULL AND ! empty($_POST))
+ {
+ $post = array();
+
+ // Loop through the full _POST array and return it
+ foreach (array_keys($_POST) as $key)
+ {
+ $post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean);
+ }
+ return $post;
+ }
+
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
@@ -182,13 +240,15 @@ function cookie($index = '', $xss_clean = FALSE)
* @param string the cookie domain. Usually: .yourdomain.com
* @param string the cookie path
* @param string the cookie prefix
+ * @param bool true makes the cookie secure
* @return void
*/
- function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
+ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
{
if (is_array($name))
{
- foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
+ // always leave 'name' in last place, as the loop will break otherwise, due to $$item
+ foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item)
{
if (isset($name[$item]))
{
@@ -209,6 +269,10 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path =
{
$path = config_item('cookie_path');
}
+ if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+ {
+ $secure = config_item('cookie_secure');
+ }
if ( ! is_numeric($expire))
{
@@ -219,7 +283,7 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path =
$expire = ($expire > 0) ? time() + $expire : 0;
}
- setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
+ setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
}
// --------------------------------------------------------------------
@@ -374,9 +438,9 @@ function user_agent()
function _sanitize_globals()
{
// It would be "wrong" to unset any of these GLOBALS.
- $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
+ $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
'_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
- 'system_folder', 'application_folder', 'BM', 'EXT',
+ 'system_folder', 'application_folder', 'BM', 'EXT',
'CFG', 'URI', 'RTR', 'OUT', 'IN');
// Unset globals for securiy.
@@ -413,7 +477,7 @@ function _sanitize_globals()
{
if (is_array($_GET) AND count($_GET) > 0)
{
- foreach($_GET as $key => $val)
+ foreach ($_GET as $key => $val)
{
$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
@@ -423,7 +487,7 @@ function _sanitize_globals()
// Clean $_POST Data
if (is_array($_POST) AND count($_POST) > 0)
{
- foreach($_POST as $key => $val)
+ foreach ($_POST as $key => $val)
{
$_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
@@ -441,7 +505,7 @@ function _sanitize_globals()
unset($_COOKIE['$Path']);
unset($_COOKIE['$Domain']);
- foreach($_COOKIE as $key => $val)
+ foreach ($_COOKIE as $key => $val)
{
$_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
@@ -496,6 +560,9 @@ function _clean_input_data($str)
$str = $this->uni->clean_string($str);
}
+ // Remove control characters
+ $str = remove_invisible_characters($str);
+
// Should we filter the input data?
if ($this->_enable_xss === TRUE)
{
@@ -507,7 +574,7 @@ function _clean_input_data($str)
{
if (strpos($str, "\r") !== FALSE)
{
- $str = str_replace(array("\r\n", "\r"), PHP_EOL, $str);
+ $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
}
}
@@ -548,9 +615,11 @@ function _clean_input_keys($str)
/**
* Request Headers
*
- * In Apache, you can simply call apache_request_headers(), however for
+ * In Apache, you can simply call apache_request_headers(), however for
* people running other webservers the function is undefined.
*
+ * @param bool XSS cleaning
+ *
* @return array
*/
public function request_headers($xss_clean = FALSE)
@@ -578,10 +647,10 @@ public function request_headers($xss_clean = FALSE)
{
$key = str_replace('_', ' ', strtolower($key));
$key = str_replace(' ', '-', ucwords($key));
-
+
$this->headers[$key] = $val;
}
-
+
return $this->headers;
}
@@ -602,7 +671,7 @@ public function get_request_header($index, $xss_clean = FALSE)
{
$this->request_headers();
}
-
+
if ( ! isset($this->headers[$index]))
{
return FALSE;
@@ -610,29 +679,42 @@ public function get_request_header($index, $xss_clean = FALSE)
if ($xss_clean === TRUE)
{
- $_security =& load_class('Security');
- return $_security->xss_clean($this->headers[$index]);
+ return $this->security->xss_clean($this->headers[$index]);
}
- return $this->headers[$index];
+ return $this->headers[$index];
}
// --------------------------------------------------------------------
-
+
/**
* Is ajax Request?
*
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header
*
- * @return boolean
+ * @return boolean
*/
public function is_ajax_request()
{
return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Is cli Request?
+ *
+ * Test to see if a request was made from the command line
+ *
+ * @return boolean
+ */
+ public function is_cli_request()
+ {
+ return (bool) defined('STDIN');
+ }
+
}
// END Input class
/* End of file Input.php */
-/* Location: ./system/core/Input.php */
\ No newline at end of file
+/* Location: ./system/core/Input.php */
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 8ec17977..5ac67183 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -26,7 +26,17 @@
*/
class CI_Lang {
+ /**
+ * List of translations
+ *
+ * @var array
+ */
var $language = array();
+ /**
+ * List of loaded language files
+ *
+ * @var array
+ */
var $is_loaded = array();
/**
@@ -47,18 +57,21 @@ function __construct()
* @access public
* @param mixed the name of the language file to be loaded. Can be an array
* @param string the language (english, etc.)
+ * @param bool return loaded array of translations
+ * @param bool add suffix to $langfile
+ * @param string alternative path to look for language file
* @return mixed
*/
function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
- $langfile = str_replace(EXT, '', $langfile);
+ $langfile = str_replace('.php', '', $langfile);
if ($add_suffix == TRUE)
{
$langfile = str_replace('_lang.', '', $langfile).'_lang';
}
- $langfile .= EXT;
+ $langfile .= '.php';
if (in_array($langfile, $this->is_loaded, TRUE))
{
@@ -129,12 +142,19 @@ function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE,
*/
function line($line = '')
{
- $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
- return $line;
+ $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
+
+ // Because killer robots like unicorns!
+ if ($value === FALSE)
+ {
+ log_message('error', 'Could not find the language line "'.$line.'"');
+ }
+
+ return $value;
}
}
// END Language Class
/* End of file Lang.php */
-/* Location: ./system/core/Lang.php */
\ No newline at end of file
+/* Location: ./system/core/Lang.php */
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 225b4391..31c93078 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -29,59 +29,175 @@
class CI_Loader {
// All these are set automatically. Don't mess with them.
- var $_ci_ob_level;
- var $_ci_view_path = '';
- var $_ci_library_paths = array();
- var $_ci_model_paths = array();
- var $_ci_helper_paths = array();
- var $_base_classes = array(); // Set by the controller class
- var $_ci_cached_vars = array();
- var $_ci_classes = array();
- var $_ci_loaded_files = array();
- var $_ci_models = array();
- var $_ci_helpers = array();
- var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
-
+ /**
+ * Nesting level of the output buffering mechanism
+ *
+ * @var int
+ * @access protected
+ */
+ protected $_ci_ob_level;
+ /**
+ * List of paths to load views from
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_view_paths = array();
+ /**
+ * List of paths to load libraries from
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_library_paths = array();
+ /**
+ * List of paths to load models from
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_model_paths = array();
+ /**
+ * List of paths to load helpers from
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_helper_paths = array();
+ /**
+ * List of loaded base classes
+ * Set by the controller class
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_base_classes = array(); // Set by the controller class
+ /**
+ * List of cached variables
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_cached_vars = array();
+ /**
+ * List of loaded classes
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_classes = array();
+ /**
+ * List of loaded files
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_loaded_files = array();
+ /**
+ * List of loaded models
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_models = array();
+ /**
+ * List of loaded helpers
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_helpers = array();
+ /**
+ * List of class name mappings
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_ci_varmap = array('unit_test' => 'unit',
+ 'user_agent' => 'agent');
/**
* Constructor
*
* Sets the path to the view files and gets the initial output buffering level
- *
- * @access public
*/
- function __construct()
+ public function __construct()
{
- $this->_ci_view_path = APPPATH.'views/';
$this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(APPPATH, BASEPATH);
$this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH);
+ $this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
log_message('debug', "Loader Class Initialized");
}
// --------------------------------------------------------------------
+ /**
+ * Initialize the Loader
+ *
+ * This method is called once in CI_Controller.
+ *
+ * @param array
+ * @return object
+ */
+ public function initialize()
+ {
+ $this->_ci_classes = array();
+ $this->_ci_loaded_files = array();
+ $this->_ci_models = array();
+ $this->_base_classes =& is_loaded();
+
+ $this->_ci_autoloader();
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Is Loaded
+ *
+ * A utility function to test if a class is in the self::$_ci_classes array.
+ * This function returns the object name if the class tested for is loaded,
+ * and returns FALSE if it isn't.
+ *
+ * It is mainly used in the form_helper -> _get_validation_object()
+ *
+ * @param string class being checked for
+ * @return mixed class object name on the CI SuperObject or FALSE
+ */
+ public function is_loaded($class)
+ {
+ if (isset($this->_ci_classes[$class]))
+ {
+ return $this->_ci_classes[$class];
+ }
+
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Class Loader
*
* This function lets users load and instantiate classes.
* It is designed to be called from a user's app controllers.
*
- * @access public
* @param string the name of the class
* @param mixed the optional parameters
* @param string an optional object name
* @return void
*/
- function library($library = '', $params = NULL, $object_name = NULL)
+ public function library($library = '', $params = NULL, $object_name = NULL)
{
if (is_array($library))
{
- foreach($library as $read)
+ foreach ($library as $class)
{
- $this->library($read);
+ $this->library($class, $params);
}
return;
@@ -97,17 +213,7 @@ function library($library = '', $params = NULL, $object_name = NULL)
$params = NULL;
}
- if (is_array($library))
- {
- foreach ($library as $class)
- {
- $this->_ci_load_class($class, $params, $object_name);
- }
- }
- else
- {
- $this->_ci_load_class($library, $params, $object_name);
- }
+ $this->_ci_load_class($library, $params, $object_name);
}
// --------------------------------------------------------------------
@@ -117,17 +223,16 @@ function library($library = '', $params = NULL, $object_name = NULL)
*
* This function lets users load and instantiate models.
*
- * @access public
* @param string the name of the class
* @param string name for the model
* @param bool database connection
* @return void
*/
- function model($model, $name = '', $db_conn = FALSE)
+ public function model($model, $name = '', $db_conn = FALSE)
{
if (is_array($model))
{
- foreach($model as $babe)
+ foreach ($model as $babe)
{
$this->model($babe);
}
@@ -171,7 +276,7 @@ function model($model, $name = '', $db_conn = FALSE)
foreach ($this->_ci_model_paths as $mod_path)
{
- if ( ! file_exists($mod_path.'models/'.$path.$model.EXT))
+ if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
continue;
}
@@ -191,7 +296,7 @@ function model($model, $name = '', $db_conn = FALSE)
load_class('Model', 'core');
}
- require_once($mod_path.'models/'.$path.$model.EXT);
+ require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model);
@@ -210,13 +315,12 @@ function model($model, $name = '', $db_conn = FALSE)
/**
* Database Loader
*
- * @access public
* @param string the DB credentials
* @param bool whether to return the DB object
* @param bool whether to enable active record (this allows us to override the config setting)
* @return object
*/
- function database($params = '', $return = FALSE, $active_record = NULL)
+ public function database($params = '', $return = FALSE, $active_record = NULL)
{
// Grab the super object
$CI =& get_instance();
@@ -227,7 +331,7 @@ function database($params = '', $return = FALSE, $active_record = NULL)
return FALSE;
}
- require_once(BASEPATH.'database/DB'.EXT);
+ require_once(BASEPATH.'database/DB.php');
if ($return === TRUE)
{
@@ -247,10 +351,9 @@ function database($params = '', $return = FALSE, $active_record = NULL)
/**
* Load the Utilities Class
*
- * @access public
* @return string
*/
- function dbutil()
+ public function dbutil()
{
if ( ! class_exists('CI_DB'))
{
@@ -263,8 +366,8 @@ function dbutil()
// this use is deprecated and strongly discouraged
$CI->load->dbforge();
- require_once(BASEPATH.'database/DB_utility'.EXT);
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
+ require_once(BASEPATH.'database/DB_utility.php');
+ require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
$CI->dbutil = new $class();
@@ -275,10 +378,9 @@ function dbutil()
/**
* Load the Database Forge Class
*
- * @access public
* @return string
*/
- function dbforge()
+ public function dbforge()
{
if ( ! class_exists('CI_DB'))
{
@@ -287,8 +389,8 @@ function dbforge()
$CI =& get_instance();
- require_once(BASEPATH.'database/DB_forge'.EXT);
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT);
+ require_once(BASEPATH.'database/DB_forge.php');
+ require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
$class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
$CI->dbforge = new $class();
@@ -307,13 +409,12 @@ function dbforge()
* some cases it's advantageous to be able to return data so that
* a developer can process it in some way.
*
- * @access public
* @param string
* @param array
* @param bool
* @return void
*/
- function view($view, $vars = array(), $return = FALSE)
+ public function view($view, $vars = array(), $return = FALSE)
{
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
@@ -325,12 +426,11 @@ function view($view, $vars = array(), $return = FALSE)
*
* This is a generic file loader
*
- * @access public
* @param string
* @param bool
* @return string
*/
- function file($path, $return = FALSE)
+ public function file($path, $return = FALSE)
{
return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
}
@@ -343,11 +443,11 @@ function file($path, $return = FALSE)
* Once variables are set they become available within
* the controller class and its "view" files.
*
- * @access public
* @param array
+ * @param string
* @return void
*/
- function vars($vars = array(), $val = '')
+ public function vars($vars = array(), $val = '')
{
if ($val != '' AND is_string($vars))
{
@@ -367,16 +467,30 @@ function vars($vars = array(), $val = '')
// --------------------------------------------------------------------
+ /**
+ * Get Variable
+ *
+ * Check if a variable is set and retrieve it.
+ *
+ * @param array
+ * @return void
+ */
+ public function get_var($key)
+ {
+ return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Load Helper
*
* This function loads the specified helper file.
*
- * @access public
* @param mixed
* @return void
*/
- function helper($helpers = array())
+ public function helper($helpers = array())
{
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
{
@@ -385,16 +499,16 @@ function helper($helpers = array())
continue;
}
- $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
+ $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
// Is this a helper extension request?
if (file_exists($ext_helper))
{
- $base_helper = BASEPATH.'helpers/'.$helper.EXT;
+ $base_helper = BASEPATH.'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper))
{
- show_error('Unable to load the requested file: helpers/'.$helper.EXT);
+ show_error('Unable to load the requested file: helpers/'.$helper.'.php');
}
include_once($ext_helper);
@@ -408,9 +522,9 @@ function helper($helpers = array())
// Try to load the helper
foreach ($this->_ci_helper_paths as $path)
{
- if (file_exists($path.'helpers/'.$helper.EXT))
+ if (file_exists($path.'helpers/'.$helper.'.php'))
{
- include_once($path.'helpers/'.$helper.EXT);
+ include_once($path.'helpers/'.$helper.'.php');
$this->_ci_helpers[$helper] = TRUE;
log_message('debug', 'Helper loaded: '.$helper);
@@ -421,7 +535,7 @@ function helper($helpers = array())
// unable to load the helper
if ( ! isset($this->_ci_helpers[$helper]))
{
- show_error('Unable to load the requested file: helpers/'.$helper.EXT);
+ show_error('Unable to load the requested file: helpers/'.$helper.'.php');
}
}
}
@@ -434,11 +548,10 @@ function helper($helpers = array())
* This is simply an alias to the above function in case the
* user has written the plural form of this function.
*
- * @access public
* @param array
* @return void
*/
- function helpers($helpers = array())
+ public function helpers($helpers = array())
{
$this->helper($helpers);
}
@@ -448,12 +561,11 @@ function helpers($helpers = array())
/**
* Loads a language file
*
- * @access public
* @param array
* @param string
* @return void
*/
- function language($file = array(), $lang = '')
+ public function language($file = array(), $lang = '')
{
$CI =& get_instance();
@@ -473,11 +585,12 @@ function language($file = array(), $lang = '')
/**
* Loads a config file
*
- * @access public
* @param string
+ * @param bool
+ * @param bool
* @return void
*/
- function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
+ public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$CI =& get_instance();
$CI->config->load($file, $use_sections, $fail_gracefully);
@@ -495,12 +608,12 @@ function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
* @param string an optional object name
* @return void
*/
- function driver($library = '', $params = NULL, $object_name = NULL)
+ public function driver($library = '', $params = NULL, $object_name = NULL)
{
if ( ! class_exists('CI_Driver_Library'))
{
// we aren't instantiating an object here, that'll be done by the Library itself
- require BASEPATH.'libraries/Driver'.EXT;
+ require BASEPATH.'libraries/Driver.php';
}
// We can save the loader some time since Drivers will *always* be in a subfolder,
@@ -520,11 +633,11 @@ function driver($library = '', $params = NULL, $object_name = NULL)
*
* Prepends a parent path to the library, model, helper, and config path arrays
*
- * @access public
* @param string
+ * @param boolean
* @return void
*/
- function add_package_path($path)
+ public function add_package_path($path, $view_cascade=TRUE)
{
$path = rtrim($path, '/').'/';
@@ -532,6 +645,8 @@ function add_package_path($path)
array_unshift($this->_ci_model_paths, $path);
array_unshift($this->_ci_helper_paths, $path);
+ $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
+
// Add config file path
$config =& $this->_ci_get_component('config');
array_unshift($config->_config_paths, $path);
@@ -544,11 +659,10 @@ function add_package_path($path)
*
* Return a list of all package paths, by default it will ignore BASEPATH.
*
- * @access public
* @param string
* @return void
*/
- function get_package_paths($include_base = FALSE)
+ public function get_package_paths($include_base = FALSE)
{
return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
}
@@ -561,11 +675,11 @@ function get_package_paths($include_base = FALSE)
* Remove a path from the library, model, and helper path arrays if it exists
* If no path is provided, the most recently added path is removed.
*
- * @access public
* @param type
+ * @param bool
* @return type
*/
- function remove_package_path($path = '', $remove_config_path = TRUE)
+ public function remove_package_path($path = '', $remove_config_path = TRUE)
{
$config =& $this->_ci_get_component('config');
@@ -574,12 +688,12 @@ function remove_package_path($path = '', $remove_config_path = TRUE)
$void = array_shift($this->_ci_library_paths);
$void = array_shift($this->_ci_model_paths);
$void = array_shift($this->_ci_helper_paths);
+ $void = array_shift($this->_ci_view_paths);
$void = array_shift($config->_config_paths);
}
else
{
$path = rtrim($path, '/').'/';
-
foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
{
if (($key = array_search($path, $this->{$var})) !== FALSE)
@@ -588,6 +702,11 @@ function remove_package_path($path = '', $remove_config_path = TRUE)
}
}
+ if (isset($this->_ci_view_paths[$path.'views/']))
+ {
+ unset($this->_ci_view_paths[$path.'views/']);
+ }
+
if (($key = array_search($path, $config->_config_paths)) !== FALSE)
{
unset($config->_config_paths[$key]);
@@ -598,6 +717,7 @@ function remove_package_path($path = '', $remove_config_path = TRUE)
$this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
$this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
$this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
+ $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
$config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
}
@@ -610,11 +730,10 @@ function remove_package_path($path = '', $remove_config_path = TRUE)
* Variables are prefixed with _ci_ to avoid symbol collision with
* variables made available to view files
*
- * @access private
* @param array
* @return void
*/
- function _ci_load($_ci_data)
+ protected function _ci_load($_ci_data)
{
// Set the default data variables
foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
@@ -622,20 +741,36 @@ function _ci_load($_ci_data)
$$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
}
+ $file_exists = FALSE;
+
// Set the path to the requested file
- if ($_ci_path == '')
+ if ($_ci_path != '')
{
- $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
- $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
- $_ci_path = $this->_ci_view_path.$_ci_file;
+ $_ci_x = explode('/', $_ci_path);
+ $_ci_file = end($_ci_x);
}
else
{
- $_ci_x = explode('/', $_ci_path);
- $_ci_file = end($_ci_x);
+ $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
+ $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;
+
+ foreach ($this->_ci_view_paths as $view_file => $cascade)
+ {
+ if (file_exists($view_file.$_ci_file))
+ {
+ $_ci_path = $view_file.$_ci_file;
+ $file_exists = TRUE;
+ break;
+ }
+
+ if ( ! $cascade)
+ {
+ break;
+ }
+ }
}
- if ( ! file_exists($_ci_path))
+ if ( ! $file_exists && ! file_exists($_ci_path))
{
show_error('Unable to load the requested file: '.$_ci_file);
}
@@ -731,18 +866,17 @@ function _ci_load($_ci_data)
*
* This function loads the requested class.
*
- * @access private
* @param string the item that is being loaded
* @param mixed any additional parameters
* @param string an optional object name
* @return void
*/
- function _ci_load_class($class, $params = NULL, $object_name = NULL)
+ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
{
// Get the class name, and while we're at it trim any slashes.
// The directory path can be included as part of the class name,
// but we don't want a leading slash
- $class = str_replace(EXT, '', trim($class, '/'));
+ $class = str_replace('.php', '', trim($class, '/'));
// Was the path included with the class name?
// We look for a slash to determine this
@@ -759,12 +893,12 @@ function _ci_load_class($class, $params = NULL, $object_name = NULL)
// We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class)
{
- $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;
+ $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
// Is this a class extension request?
if (file_exists($subclass))
{
- $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
+ $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
if ( ! file_exists($baseclass))
{
@@ -803,7 +937,7 @@ function _ci_load_class($class, $params = NULL, $object_name = NULL)
$is_duplicate = FALSE;
foreach ($this->_ci_library_paths as $path)
{
- $filepath = $path.'libraries/'.$subdir.$class.EXT;
+ $filepath = $path.'libraries/'.$subdir.$class.'.php';
// Does the file exist? No? Bummer...
if ( ! file_exists($filepath))
@@ -859,13 +993,13 @@ function _ci_load_class($class, $params = NULL, $object_name = NULL)
/**
* Instantiates a class
*
- * @access private
* @param string
* @param string
+ * @param bool
* @param string an optional object name
* @return null
*/
- function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
+ protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
{
// Is there an associated config file for this class? Note: these should always be lowercase
if ($config === NULL)
@@ -880,15 +1014,26 @@ function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NU
foreach ($config_component->_config_paths as $path)
{
// We test for both uppercase and lowercase, for servers that
- // are case-sensitive with regard to file names
- if (file_exists($path .'config/'.strtolower($class).EXT))
+ // are case-sensitive with regard to file names. Check for environment
+ // first, global next
+ if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
+ {
+ include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
+ break;
+ }
+ elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
{
- include_once($path .'config/'.strtolower($class).EXT);
+ include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
break;
}
- elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).EXT))
+ elseif (file_exists($path .'config/'.strtolower($class).'.php'))
{
- include_once($path .'config/'.ucfirst(strtolower($class)).EXT);
+ include_once($path .'config/'.strtolower($class).'.php');
+ break;
+ }
+ elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php'))
+ {
+ include_once($path .'config/'.ucfirst(strtolower($class)).'.php');
break;
}
}
@@ -958,19 +1103,34 @@ function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NU
* The config/autoload.php file contains an array that permits sub-systems,
* libraries, and helpers to be loaded automatically.
*
- * @access private
* @param array
* @return void
*/
- function _ci_autoloader()
+ private function _ci_autoloader()
{
- include_once(APPPATH.'config/autoload'.EXT);
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
+ }
+ else
+ {
+ include(APPPATH.'config/autoload.php');
+ }
if ( ! isset($autoload))
{
return FALSE;
}
+ // Autoload packages
+ if (isset($autoload['packages']))
+ {
+ foreach ($autoload['packages'] as $package_path)
+ {
+ $this->add_package_path($package_path);
+ }
+ }
+
// Load any custom config file
if (count($autoload['config']) > 0)
{
@@ -1028,11 +1188,10 @@ function _ci_autoloader()
*
* Takes an object as input and converts the class variables to array key/vals
*
- * @access private
* @param object
* @return array
*/
- function _ci_object_to_array($object)
+ protected function _ci_object_to_array($object)
{
return (is_object($object)) ? get_object_vars($object) : $object;
}
@@ -1042,10 +1201,10 @@ function _ci_object_to_array($object)
/**
* Get a reference to a specific library or model
*
- * @access private
+ * @param string
* @return bool
*/
- function &_ci_get_component($component)
+ protected function &_ci_get_component($component)
{
$CI =& get_instance();
return $CI->$component;
@@ -1058,29 +1217,27 @@ function &_ci_get_component($component)
*
* This function preps the name of various items to make loading them more reliable.
*
- * @access private
* @param mixed
+ * @param string
* @return array
*/
- function _ci_prep_filename($filename, $extension)
+ protected function _ci_prep_filename($filename, $extension)
{
if ( ! is_array($filename))
{
- return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension));
+ return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension));
}
else
{
foreach ($filename as $key => $val)
{
- $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension);
+ $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension);
}
return $filename;
}
}
-
-
}
/* End of file Loader.php */
-/* Location: ./system/core/Loader.php */
\ No newline at end of file
+/* Location: ./system/core/Loader.php */
diff --git a/system/core/Model.php b/system/core/Model.php
index 80f4b04a..e15ffbeb 100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -42,6 +42,7 @@ function __construct()
* Allows models to access CI's loaded classes using the same
* syntax as controllers.
*
+ * @param string
* @access private
*/
function __get($key)
diff --git a/system/core/Output.php b/system/core/Output.php
index 0b708e11..ccecafd2 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -28,19 +28,84 @@
*/
class CI_Output {
- var $final_output;
- var $cache_expiration = 0;
- var $headers = array();
- var $enable_profiler = FALSE;
- var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
-
- var $_zlib_oc = FALSE;
- var $_profiler_sections = array();
+ /**
+ * Current output string
+ *
+ * @var string
+ * @access protected
+ */
+ protected $final_output;
+ /**
+ * Cache expiration time
+ *
+ * @var int
+ * @access protected
+ */
+ protected $cache_expiration = 0;
+ /**
+ * List of server headers
+ *
+ * @var array
+ * @access protected
+ */
+ protected $headers = array();
+ /**
+ * List of mime types
+ *
+ * @var array
+ * @access protected
+ */
+ protected $mime_types = array();
+ /**
+ * Determines wether profiler is enabled
+ *
+ * @var book
+ * @access protected
+ */
+ protected $enable_profiler = FALSE;
+ /**
+ * Determines if output compression is enabled
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $_zlib_oc = FALSE;
+ /**
+ * List of profiler sections
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_profiler_sections = array();
+ /**
+ * Whether or not to parse variables like {elapsed_time} and {memory_usage}
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $parse_exec_vars = TRUE;
+ /**
+ * Constructor
+ *
+ */
function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
+ // Get mime types for later
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ {
+ include APPPATH.'config/'.ENVIRONMENT.'/mimes.php';
+ }
+ else
+ {
+ include APPPATH.'config/mimes.php';
+ }
+
+
+ $this->mime_types = $mimes;
+
log_message('debug', "Output Class Initialized");
}
@@ -73,6 +138,8 @@ function get_output()
function set_output($output)
{
$this->final_output = $output;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -96,6 +163,8 @@ function append_output($output)
{
$this->final_output .= $output;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -110,6 +179,7 @@ function append_output($output)
*
* @access public
* @param string
+ * @param bool
* @return void
*/
function set_header($header, $replace = TRUE)
@@ -125,6 +195,42 @@ function set_header($header, $replace = TRUE)
}
$this->headers[] = array($header, $replace);
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set Content Type Header
+ *
+ * @access public
+ * @param string extension of the file we're outputting
+ * @return void
+ */
+ function set_content_type($mime_type)
+ {
+ if (strpos($mime_type, '/') === FALSE)
+ {
+ $extension = ltrim($mime_type, '.');
+
+ // Is this extension supported?
+ if (isset($this->mime_types[$extension]))
+ {
+ $mime_type =& $this->mime_types[$extension];
+
+ if (is_array($mime_type))
+ {
+ $mime_type = current($mime_type);
+ }
+ }
+ }
+
+ $header = 'Content-Type: '.$mime_type;
+
+ $this->headers[] = array($header, TRUE);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -141,6 +247,8 @@ function set_header($header, $replace = TRUE)
function set_status_header($code = 200, $text = '')
{
set_status_header($code, $text);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -155,6 +263,8 @@ function set_status_header($code = 200, $text = '')
function enable_profiler($val = TRUE)
{
$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -174,6 +284,8 @@ function set_profiler_sections($sections)
{
$this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -188,6 +300,8 @@ function set_profiler_sections($sections)
function cache($time)
{
$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -204,6 +318,7 @@ function cache($time)
* benchmark timer so the page rendering speed and memory usage can be shown.
*
* @access public
+ * @param string
* @return mixed
*/
function _display($output = '')
@@ -340,6 +455,7 @@ function _display($output = '')
* Write a Cache File
*
* @access public
+ * @param string
* @return void
*/
function _write_cache($output)
@@ -347,7 +463,7 @@ function _write_cache($output)
$CI =& get_instance();
$path = $CI->config->item('cache_path');
- $cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
+ $cache_path = ($path == '') ? APPPATH.'cache/' : $path;
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
@@ -391,11 +507,13 @@ function _write_cache($output)
* Update/serve a cached file
*
* @access public
+ * @param object config class
+ * @param object uri class
* @return void
*/
function _display_cache(&$CFG, &$URI)
{
- $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path');
+ $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
// Build the file path. The file name is an MD5 hash of the full URI
$uri = $CFG->item('base_url').
diff --git a/system/core/Router.php b/system/core/Router.php
index 79a8b4fc..6da66747 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -28,12 +28,54 @@
*/
class CI_Router {
+ /**
+ * Config class
+ *
+ * @var object
+ * @access public
+ */
var $config;
+ /**
+ * List of routes
+ *
+ * @var array
+ * @access public
+ */
var $routes = array();
+ /**
+ * List of error routes
+ *
+ * @var array
+ * @access public
+ */
var $error_routes = array();
+ /**
+ * Current class name
+ *
+ * @var string
+ * @access public
+ */
var $class = '';
+ /**
+ * Current method name
+ *
+ * @var string
+ * @access public
+ */
var $method = 'index';
+ /**
+ * Sub-directory that contains the requested controller class
+ *
+ * @var string
+ * @access public
+ */
var $directory = '';
+ /**
+ * Default controller (and method if specific)
+ *
+ * @var string
+ * @access public
+ */
var $default_controller;
/**
@@ -87,7 +129,15 @@ function _set_routing()
}
// Load the routes.php file.
- @include(APPPATH.'config/routes'.EXT);
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
+ }
+ elseif (is_file(APPPATH.'config/routes.php'))
+ {
+ include(APPPATH.'config/routes.php');
+ }
+
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);
@@ -144,7 +194,7 @@ function _set_default_controller()
$this->set_class($x[0]);
$this->set_method($x[1]);
- $this->_set_request(array($x[0], $x[1]));
+ $this->_set_request($x);
}
else
{
@@ -219,7 +269,7 @@ function _validate_request($segments)
}
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
+ if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
{
return $segments;
}
@@ -234,9 +284,22 @@ function _validate_request($segments)
if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
+ if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
- show_404($this->fetch_directory().$segments[0]);
+ if ( ! empty($this->routes['404_override']))
+ {
+ $x = explode('/', $this->routes['404_override']);
+
+ $this->set_directory('');
+ $this->set_class($x[0]);
+ $this->set_method(isset($x[1]) ? $x[1] : 'index');
+
+ return $x;
+ }
+ else
+ {
+ show_404($this->fetch_directory().$segments[0]);
+ }
}
}
else
@@ -256,7 +319,7 @@ function _validate_request($segments)
}
// Does the default controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
+ if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
{
$this->directory = '';
return array();
@@ -270,7 +333,7 @@ function _validate_request($segments)
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
- if (!empty($this->routes['404_override']))
+ if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
diff --git a/system/libraries/Security.php b/system/core/Security.php
similarity index 60%
rename from system/libraries/Security.php
rename to system/core/Security.php
index d2638560..dcc680a1 100644
--- a/system/libraries/Security.php
+++ b/system/core/Security.php
@@ -6,7 +6,7 @@
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -22,39 +22,97 @@
* @subpackage Libraries
* @category Security
* @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/libraries/sessions.html
+ * @link http://codeigniter.com/user_guide/libraries/security.html
*/
class CI_Security {
- var $xss_hash = '';
- var $csrf_hash = '';
- var $csrf_expire = 7200; // Two hours (in seconds)
- var $csrf_token_name = 'ci_csrf_token';
- var $csrf_cookie_name = 'ci_csrf_token';
-
- /* never allowed, string replacement */
- var $never_allowed_str = array(
- 'document.cookie' => '[removed]',
- 'document.write' => '[removed]',
- '.parentNode' => '[removed]',
- '.innerHTML' => '[removed]',
- 'window.location' => '[removed]',
- '-moz-binding' => '[removed]',
- '' => '-->',
- ' '<![CDATA['
- );
+
+ /**
+ * Random Hash for protecting URLs
+ *
+ * @var string
+ * @access protected
+ */
+ protected $_xss_hash = '';
+ /**
+ * Random Hash for Cross Site Request Forgery Protection Cookie
+ *
+ * @var string
+ * @access protected
+ */
+ protected $_csrf_hash = '';
+ /**
+ * Expiration time for Cross Site Request Forgery Protection Cookie
+ * Defaults to two hours (in seconds)
+ *
+ * @var int
+ * @access protected
+ */
+ protected $_csrf_expire = 7200;
+ /**
+ * Token name for Cross Site Request Forgery Protection Cookie
+ *
+ * @var string
+ * @access protected
+ */
+ protected $_csrf_token_name = 'ci_csrf_token';
+ /**
+ * Cookie name for Cross Site Request Forgery Protection Cookie
+ *
+ * @var string
+ * @access protected
+ */
+ protected $_csrf_cookie_name = 'ci_csrf_token';
+ /**
+ * List of never allowed strings
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_never_allowed_str = array(
+ 'document.cookie' => '[removed]',
+ 'document.write' => '[removed]',
+ '.parentNode' => '[removed]',
+ '.innerHTML' => '[removed]',
+ 'window.location' => '[removed]',
+ '-moz-binding' => '[removed]',
+ '' => '-->',
+ ' '<![CDATA['
+ );
+
/* never allowed, regex replacement */
- var $never_allowed_regex = array(
- "javascript\s*:" => '[removed]',
- "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE
- "vbscript\s*:" => '[removed]', // IE, surprise!
- "Redirect\s+302" => '[removed]'
- );
+ /**
+ * List of never allowed regex replacement
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_never_allowed_regex = array(
+ "javascript\s*:" => '[removed]',
+ "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE
+ "vbscript\s*:" => '[removed]', // IE, surprise!
+ "Redirect\s+302" => '[removed]'
+ );
+ /**
+ * Constructor
+ */
public function __construct()
{
- // Append application specific cookie prefix to token name
- $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name;
+ // CSRF config
+ foreach(array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
+ {
+ if (FALSE !== ($val = config_item($key)))
+ {
+ $this->{'_'.$key} = $val;
+ }
+ }
+
+ // Append application specific cookie prefix
+ if (config_item('cookie_prefix'))
+ {
+ $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
+ }
// Set the CSRF hash
$this->_csrf_set_hash();
@@ -67,10 +125,9 @@ public function __construct()
/**
* Verify Cross Site Request Forgery Protection
*
- * @access public
- * @return null
+ * @return object
*/
- function csrf_verify()
+ public function csrf_verify()
{
// If no POST data exists we will set the CSRF cookie
if (count($_POST) == 0)
@@ -79,26 +136,30 @@ function csrf_verify()
}
// Do the tokens exist in both the _POST and _COOKIE arrays?
- if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name]))
+ if ( ! isset($_POST[$this->_csrf_token_name]) OR
+ ! isset($_COOKIE[$this->_csrf_cookie_name]))
{
$this->csrf_show_error();
}
// Do the tokens match?
- if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name])
+ if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name])
{
$this->csrf_show_error();
}
- // We kill this since we're done and we don't want to polute the _POST array
- unset($_POST[$this->csrf_token_name]);
+ // We kill this since we're done and we don't want to
+ // polute the _POST array
+ unset($_POST[$this->_csrf_token_name]);
// Nothing should last forever
- unset($_COOKIE[$this->csrf_cookie_name]);
+ unset($_COOKIE[$this->_csrf_cookie_name]);
$this->_csrf_set_hash();
$this->csrf_set_cookie();
log_message('debug', "CSRF token verified ");
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -106,56 +167,68 @@ function csrf_verify()
/**
* Set Cross Site Request Forgery Protection Cookie
*
- * @access public
- * @return null
+ * @return object
*/
- function csrf_set_cookie()
+ public function csrf_set_cookie()
{
- $expire = time() + $this->csrf_expire;
+ $expire = time() + $this->_csrf_expire;
+ $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0;
- setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0);
+ if ($secure_cookie)
+ {
+ $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE;
+
+ if ( ! $req OR $req == 'off')
+ {
+ return FALSE;
+ }
+ }
+
+ setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie);
log_message('debug', "CRSF cookie Set");
+
+ return $this;
}
// --------------------------------------------------------------------
/**
- * Set Cross Site Request Forgery Protection Cookie
+ * Show CSRF Error
*
- * @access public
- * @return null
+ * @return void
*/
- function _csrf_set_hash()
+ public function csrf_show_error()
{
- if ($this->csrf_hash == '')
- {
- // If the cookie exists we will use it's value. We don't necessarily want to regenerate it with
- // each page load since a page could contain embedded sub-pages causing this feature to fail
- if (isset($_COOKIE[$this->csrf_cookie_name]) AND $_COOKIE[$this->csrf_cookie_name] != '')
- {
- $this->csrf_hash = $_COOKIE[$this->csrf_cookie_name];
- }
- else
- {
- $this->csrf_hash = md5(uniqid(rand(), TRUE));
- }
- }
+ show_error('The action you have requested is not allowed.');
+ }
- return $this->csrf_hash;
+ // --------------------------------------------------------------------
+
+ /**
+ * Get CSRF Hash
+ *
+ * Getter Method
+ *
+ * @return string self::_csrf_hash
+ */
+ public function get_csrf_hash()
+ {
+ return $this->_csrf_hash;
}
// --------------------------------------------------------------------
/**
- * Show CSRF Error
+ * Get CSRF Token Name
+ *
+ * Getter Method
*
- * @access public
- * @return null
+ * @return string self::csrf_token_name
*/
- function csrf_show_error()
+ public function get_csrf_token_name()
{
- show_error('The action you have requested is not allowed.');
+ return $this->_csrf_token_name;
}
// --------------------------------------------------------------------
@@ -182,11 +255,11 @@ function csrf_show_error()
* harvested from examining vulnerabilities in other programs:
* http://ha.ckers.org/xss.html
*
- * @access public
* @param mixed string or array
+ * @param bool
* @return string
*/
- function xss_clean($str, $is_image = FALSE)
+ public function xss_clean($str, $is_image = FALSE)
{
/*
* Is the string an array?
@@ -207,35 +280,8 @@ function xss_clean($str, $is_image = FALSE)
*/
$str = remove_invisible_characters($str);
- /*
- * Protect GET variables in URLs
- */
-
- // 901119URL5918AMP18930PROTECT8198
-
- $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str);
-
- /*
- * Validate standard character entities
- *
- * Add a semicolon if missing. We do this to enable
- * the conversion of entities to ASCII later.
- *
- */
- $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str);
-
- /*
- * Validate UTF16 two byte encoding (x00)
- *
- * Just as above, adds a semicolon if missing.
- *
- */
- $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str);
-
- /*
- * Un-Protect GET variables in URLs
- */
- $str = str_replace($this->xss_hash(), '&', $str);
+ // Validate Entities in URLs
+ $str = $this->_validate_entities($str);
/*
* URL Decode
@@ -259,7 +305,7 @@ function xss_clean($str, $is_image = FALSE)
*/
$str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
-
+
$str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str);
/*
@@ -272,9 +318,8 @@ function xss_clean($str, $is_image = FALSE)
*
* This prevents strings like this: ja vascript
* NOTE: we deal with spaces between characters later.
- * NOTE: preg_replace was found to be amazingly slow here on large blocks of data,
- * so we use str_replace.
- *
+ * NOTE: preg_replace was found to be amazingly slow here on
+ * large blocks of data, so we use str_replace.
*/
if (strpos($str, "\t") !== FALSE)
@@ -287,34 +332,23 @@ function xss_clean($str, $is_image = FALSE)
*/
$converted_string = $str;
- /*
- * Not Allowed Under Any Conditions
- */
-
- foreach ($this->never_allowed_str as $key => $val)
- {
- $str = str_replace($key, $val, $str);
- }
-
- foreach ($this->never_allowed_regex as $key => $val)
- {
- $str = preg_replace("#".$key."#i", $val, $str);
- }
+ // Remove Strings that are never allowed
+ $str = $this->_do_never_allowed($str);
/*
* Makes PHP tags safe
*
- * Note: XML tags are inadvertently replaced too:
+ * Note: XML tags are inadvertently replaced too:
*
- * ,
- * but it's unlikely to be a problem.
- *
- */
- $event_handlers = array('[^a-z_\-]on\w*','xmlns');
-
- if ($is_image === TRUE)
- {
- /*
- * Adobe Photoshop puts XML metadata into JFIF images, including namespacing,
- * so we have to allow this for images. -Paul
- */
- unset($event_handlers[array_search('xmlns', $event_handlers)]);
- }
-
- $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str);
+ // Remove evil attributes such as style, onclick and xmlns
+ $str = $this->_remove_evil_attributes($str, $is_image);
/*
* Sanitize naughty HTML elements
@@ -401,7 +421,6 @@ function xss_clean($str, $is_image = FALSE)
*
* So this:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Handling Multiple Environments
+
+
+ Developers often desire different system behavior depending on whether
+ an application is running in a development or production
+ environment. For example, verbose error output is something that would
+ be useful while developing an application, but it may also pose a security issue when "live".
+
+
+
The ENVIRONMENT Constant
+
+
+ By default, CodeIgniter comes with the environment constant set to
+ 'development'. At the top of index.php, you will see:
+
+
+
+define('ENVIRONMENT', 'development');
+
+
+
+ In addition to affecting some basic framework behavior (see the next section),
+ you may use this constant in your own development to differentiate
+ between which environment you are running in.
+
+
+
Effects On Default Framework Behavior
+
+
+ There are some places in the CodeIgniter system where the ENVIRONMENT
+ constant is used. This section describes how default framework behavior is
+ affected.
+
+
+
Error Reporting
+
+
+ Setting the ENVIRONMENT constant to a value of 'development' will
+ cause all PHP errors to be rendered to the browser when they occur. Conversely,
+ setting the constant to 'production' will disable all error output. Disabling
+ error reporting in production is a good security practice.
+
+
+
Configuration Files
+
+
+ Optionally, you can have CodeIgniter load environment-specific
+ configuration files. This may be useful for managing things like differing API keys
+ across multiple environments. This is described in more detail in the
+ environment section of the Config Class documentation.
+
+
+
+
+
+
+
+
+
diff --git a/user_guide/general/drivers.html b/user_guide/general/drivers.html
index 3163c11a..8dbeb93a 100644
--- a/user_guide/general/drivers.html
+++ b/user_guide/general/drivers.html
@@ -28,7 +28,7 @@
diff --git a/user_guide/general/environments.html b/user_guide/general/environments.html
new file mode 100644
index 00000000..175a1531
--- /dev/null
+++ b/user_guide/general/environments.html
@@ -0,0 +1,126 @@
+
+
+