summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/core/Config.php45
-rw-r--r--system/core/Input.php19
-rw-r--r--system/core/Lang.php18
-rw-r--r--system/core/Loader.php26
-rw-r--r--system/core/Router.php14
-rw-r--r--system/core/URI.php18
-rw-r--r--system/database/DB_forge.php6
-rw-r--r--system/libraries/Cache/Cache.php216
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php151
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php129
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php196
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php209
-rw-r--r--system/libraries/Table.php2
-rw-r--r--system/libraries/Upload.php13
14 files changed, 995 insertions, 67 deletions
diff --git a/system/core/Config.php b/system/core/Config.php
index bdd1b8333..8ecfba73a 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -47,6 +47,24 @@ class CI_Config {
{
$this->config =& get_config();
log_message('debug', "Config Class Initialized");
+
+ // Set the base_url automatically if none was provided
+ if ($this->config['base_url'] == '')
+ {
+ if(isset($_SERVER['HTTP_HOST']))
+ {
+ $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
+ $base_url .= '://'. $_SERVER['HTTP_HOST'];
+ $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+ }
+
+ else
+ {
+ $base_url = 'http://localhost/';
+ }
+
+ $this->set_item('base_url', $base_url);
+ }
}
// --------------------------------------------------------------------
@@ -185,14 +203,7 @@ class CI_Config {
return FALSE;
}
- $pref = $this->config[$item];
-
- if ($pref != '' && substr($pref, -1) != '/')
- {
- $pref .= '/';
- }
-
- return $pref;
+ return rtrim($this->config[$item], '/').'/';
}
// --------------------------------------------------------------------
@@ -208,14 +219,7 @@ class CI_Config {
{
if ($uri == '')
{
- if ($this->item('base_url') == '')
- {
- return $this->item('index_page');
- }
- else
- {
- return $this->slash_item('base_url').$this->item('index_page');
- }
+ return $this->slash_item('base_url').$this->item('index_page');
}
if ($this->item('enable_query_strings') == FALSE)
@@ -244,14 +248,7 @@ class CI_Config {
$uri = $str;
}
- if ($this->item('base_url') == '')
- {
- return $this->item('index_page').'?'.$uri;
- }
- else
- {
- return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
- }
+ return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
}
}
diff --git a/system/core/Input.php b/system/core/Input.php
index 4ddc402ee..eb2048e58 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -49,9 +49,9 @@ class CI_Input {
{
log_message('debug', "Input Class Initialized");
- $this->_allow_get_array = (config_item('allow_get_array') === TRUE) ? TRUE : FALSE;
- $this->_enable_xss = (config_item('global_xss_filtering') === TRUE) ? TRUE : FALSE;
- $this->_enable_csrf = (config_item('csrf_protection') === TRUE) ? TRUE : FALSE;
+ $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
+ $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)
@@ -216,14 +216,7 @@ class CI_Input {
}
else
{
- if ($expire > 0)
- {
- $expire = time() + $expire;
- }
- else
- {
- $expire = 0;
- }
+ $expire = ($expire > 0) ? time() + $expire : 0;
}
setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
@@ -492,7 +485,7 @@ class CI_Input {
}
// We strip slashes if magic quotes is on to keep things consistent
- if (get_magic_quotes_gpc())
+ if (function_exists('get_magic_quotes_gpc') AND get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
@@ -514,7 +507,7 @@ class CI_Input {
{
if (strpos($str, "\r") !== FALSE)
{
- $str = str_replace(array("\r\n", "\r"), "\n", $str);
+ $str = str_replace(array("\r\n", "\r"), PHP_EOL, $str);
}
}
diff --git a/system/core/Lang.php b/system/core/Lang.php
index e7867b354..8ec179771 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -78,17 +78,21 @@ class CI_Lang {
{
include($alt_path.'language/'.$idiom.'/'.$langfile);
}
- elseif (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile))
- {
- include(APPPATH.'language/'.$idiom.'/'.$langfile);
- }
else
{
- if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile))
+ $found = FALSE;
+
+ foreach (get_instance()->load->get_package_paths(TRUE) as $package_path)
{
- include(BASEPATH.'language/'.$idiom.'/'.$langfile);
+ if (file_exists($package_path.'language/'.$idiom.'/'.$langfile))
+ {
+ include($package_path.'language/'.$idiom.'/'.$langfile);
+ $found = TRUE;
+ break;
+ }
}
- else
+
+ if ($found !== TRUE)
{
show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
}
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 4b6b19eea..136cae9bf 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -81,12 +81,12 @@ class CI_Loader {
{
foreach($library as $read)
{
- $this->library($read);
+ $this->library($read);
}
-
+
return;
}
-
+
if ($library == '' OR isset($this->_base_classes[$library]))
{
return FALSE;
@@ -527,7 +527,7 @@ class CI_Loader {
function add_package_path($path)
{
$path = rtrim($path, '/').'/';
-
+
array_unshift($this->_ci_library_paths, $path);
array_unshift($this->_ci_model_paths, $path);
array_unshift($this->_ci_helper_paths, $path);
@@ -540,6 +540,22 @@ class CI_Loader {
// --------------------------------------------------------------------
/**
+ * Get Package Paths
+ *
+ * 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)
+ {
+ return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Remove Package Path
*
* Remove a path from the library, model, and helper path arrays if it exists
@@ -563,7 +579,7 @@ class CI_Loader {
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)
diff --git a/system/core/Router.php b/system/core/Router.php
index 9276800c3..79a8b4fcc 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -270,19 +270,17 @@ class CI_Router {
// 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 (isset($this->routes['404_override']) AND $this->routes['404_override'] != '')
+ if (!empty($this->routes['404_override']))
{
- if (strpos($this->routes['404_override'], '/') !== FALSE)
- {
- $x = explode('/', $this->routes['404_override']);
+ $x = explode('/', $this->routes['404_override']);
- $this->set_class($x[0]);
- $this->set_method($x[1]);
+ $this->set_class($x[0]);
+ $this->set_method(isset($x[1]) ? $x[1] : 'index');
- return $x;
- }
+ return $x;
}
+
// Nothing else to do at this point but show a 404
show_404($segments[0]);
}
diff --git a/system/core/URI.php b/system/core/URI.php
index f6487d3f9..047e3c9bc 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -133,23 +133,25 @@ class CI_URI {
if (isset($_SERVER['REQUEST_URI']))
{
$uri = $_SERVER['REQUEST_URI'];
- if (strpos($uri, $_SERVER['HTTP_HOST']) !== FALSE)
+ if (strpos($uri, $_SERVER['SERVER_NAME']) !== FALSE)
{
- $uri = preg_replace('/^\w+:\/\/[^\/]+/','',$uri);
+ $uri = preg_replace('/^\w+:\/\/[^\/]+/', '', $uri);
}
}
+
// Now lets check for IIS
elseif (isset($_SERVER['HTTP_X_REWRITE_URL']))
{
$uri = $_SERVER['HTTP_X_REWRITE_URL'];
}
+
// Last ditch effort (for older CGI servers, like IIS 5)
elseif (isset($_SERVER['ORIG_PATH_INFO']))
{
$uri = $_SERVER['ORIG_PATH_INFO'];
if ( ! empty($_SERVER['QUERY_STRING']))
{
- $uri .= '?'.$_SERVER['QUERY_STRING'];
+ $uri .= '?' . $_SERVER['QUERY_STRING'];
}
}
@@ -173,8 +175,8 @@ class CI_URI {
{
// Some server's require URL's like index.php?/whatever If that is the case,
// then we need to add that to our parsing.
- $fc_path = ltrim(FCPATH.SELF, '/');
- if (strpos($uri, SELF.'?') !== FALSE)
+ $fc_path = ltrim(FCPATH . SELF, '/');
+ if (strpos($uri, SELF . '?') !== FALSE)
{
$fc_path .= '?';
}
@@ -182,7 +184,7 @@ class CI_URI {
$parsed_uri = explode('/', ltrim($uri, '/'));
$i = 0;
- foreach(explode("/", $fc_path) as $segment)
+ foreach (explode("/", $fc_path) as $segment)
{
if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i])
{
@@ -203,7 +205,7 @@ class CI_URI {
}
// If it is just a / or index.php then just empty it.
- if ($uri == '/' || $uri == SELF)
+ if ($uri == '/' OR $uri == SELF)
{
$uri = '';
}
@@ -266,7 +268,7 @@ class CI_URI {
*/
function _explode_segments()
{
- foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
+ foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
{
// Filter segments for security
$val = trim($this->_filter_uri($val));
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index f40eac82d..ce505f4ee 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -333,6 +333,12 @@ class CI_DB_forge {
foreach ($field as $k => $v)
{
+ // If no name provided, use the current name
+ if ( ! isset($field[$k]['name']))
+ {
+ $field[$k]['name'] = $k;
+ }
+
$this->add_field(array($k => $field[$k]));
if (count($this->fields) == 0)
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
new file mode 100644
index 000000000..ea3194237
--- /dev/null
+++ b/system/libraries/Cache/Cache.php
@@ -0,0 +1,216 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author ExpressionEngine Dev Team
+ * @link
+ */
+class Cache extends CI_Driver_Library {
+
+ protected $valid_drivers = array(
+ 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
+ );
+
+ protected $_cache_path = NULL; // Path of cache files (if file-based cache)
+ protected $_adapter = 'dummy';
+ protected $_backup_driver;
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param array
+ */
+ public function __construct($config = array())
+ {
+ if ( ! empty($config))
+ {
+ $this->_initialize($config);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get
+ *
+ * Look for a value in the cache. If it exists, return the data
+ * if not, return FALSE
+ *
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
+ */
+ public function get($id)
+ {
+ return $this->{$this->_adapter}->get($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Save
+ *
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ *
+ * @return boolean true on success/false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return $this->{$this->_adapter}->save($id, $data, $ttl);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of the item in the cache
+ * @return boolean true on success/false on failure
+ */
+ public function delete($id)
+ {
+ return $this->{$this->_adapter}->delete($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the cache
+ *
+ * @return boolean false on failure/true on success
+ */
+ public function clean()
+ {
+ return $this->{$this->_adapter}->clean();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @param string user/filehits
+ * @return mixed array on success, false on failure
+ */
+ public function cache_info($type = 'user')
+ {
+ return $this->{$this->_adapter}->cache_info($type);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed return value from child method
+ */
+ public function get_metadata($id)
+ {
+ return $this->{$this->_adapter}->get_metadata($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Initialize
+ *
+ * Initialize class properties based on the configuration array.
+ *
+ * @param array
+ * @return void
+ */
+ private function _initialize($config)
+ {
+ $default_config = array(
+ 'adapter',
+ 'memcached'
+ );
+
+ foreach ($default_config as $key)
+ {
+ if (isset($config[$key]))
+ {
+ $param = '_'.$key;
+
+ $this->{$param} = $config[$key];
+ }
+ }
+
+ if (isset($config['backup']))
+ {
+ if (in_array('cache_'.$config['backup'], $this->valid_drivers))
+ {
+ $this->_backup_driver = $config['backup'];
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Is the requested driver supported in this environment?
+ *
+ * @param string The driver to test.
+ * @return array
+ */
+ public function is_supported($driver)
+ {
+ static $support = array();
+
+ if ( ! isset($support[$driver]))
+ {
+ $support[$driver] = $this->{$driver}->is_supported();
+ }
+
+ return $support[$driver];
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * __get()
+ *
+ * @param child
+ * @return object
+ */
+ public function __get($child)
+ {
+ $obj = parent::__get($child);
+
+ if ( ! $this->is_supported($child))
+ {
+ $this->_adapter = $this->_backup_driver;
+ }
+
+ return $obj;
+ }
+
+ // ------------------------------------------------------------------------
+}
+// End Class
+
+/* End of file Cache.php */
+/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
new file mode 100644
index 000000000..9c716a971
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -0,0 +1,151 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter APC Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author ExpressionEngine Dev Team
+ * @link
+ */
+
+class Cache_apc extends CI_Driver {
+
+ /**
+ * Get
+ *
+ * Look for a value in the cache. If it exists, return the data
+ * if not, return FALSE
+ *
+ * @param string
+ * @return mixed value that is stored/FALSE on failure
+ */
+ public function get($id)
+ {
+ $data = apc_fetch($id);
+
+ return (is_array($data)) ? $data[0] : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Save
+ *
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ *
+ * @return boolean true on success/false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return apc_store($id, array($data, time(), $ttl), $ttl);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of the item in the cache
+ * @param boolean true on success/false on failure
+ */
+ public function delete($id)
+ {
+ return apc_delete($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the cache
+ *
+ * @return boolean false on failure/true on success
+ */
+ public function clean()
+ {
+ return apc_clear_cache('user');
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @param string user/filehits
+ * @return mixed array on success, false on failure
+ */
+ public function cache_info($type = NULL)
+ {
+ return apc_cache_info($type);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed array on success/false on failure
+ */
+ public function get_metadata($id)
+ {
+ $stored = apc_fetch($id);
+
+ if (count($stored) !== 3)
+ {
+ return FALSE;
+ }
+
+ list($value, $time, $ttl) = $stored;
+
+ return array(
+ 'expire' => $time + $ttl,
+ 'mtime' => $time,
+ 'data' => $data
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * is_supported()
+ *
+ * Check to see if APC is available on this system, bail if it isn't.
+ */
+ public function is_supported()
+ {
+ if ( ! extension_loaded('apc') OR ! function_exists('apc_store'))
+ {
+ log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+
+}
+// End Class
+
+/* End of file Cache_apc.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
new file mode 100644
index 000000000..13c1f5cde
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -0,0 +1,129 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Dummy Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author ExpressionEngine Dev Team
+ * @link
+ */
+
+class Cache_dummy extends CI_Driver {
+
+ /**
+ * Get
+ *
+ * Since this is the dummy class, it's always going to return FALSE.
+ *
+ * @param string
+ * @return Boolean FALSE
+ */
+ public function get($id)
+ {
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Save
+ *
+ * @param string Unique Key
+ * @param mixed Data to store
+ * @param int Length of time (in seconds) to cache the data
+ *
+ * @return boolean TRUE, Simulating success
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of the item in the cache
+ * @param boolean TRUE, simulating success
+ */
+ public function delete($id)
+ {
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the cache
+ *
+ * @return boolean TRUE, simulating success
+ */
+ public function clean()
+ {
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @param string user/filehits
+ * @return boolean FALSE
+ */
+ public function cache_info($type = NULL)
+ {
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return boolean FALSE
+ */
+ public function get_metadata($id)
+ {
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Is this caching driver supported on the system?
+ * Of course this one is.
+ *
+ * @return TRUE;
+ */
+ public function is_supported()
+ {
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+}
+// End Class
+
+/* End of file Cache_apc.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
new file mode 100644
index 000000000..bedbfaff8
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -0,0 +1,196 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Memcached Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author ExpressionEngine Dev Team
+ * @link
+ */
+
+class Cache_file extends CI_Driver {
+
+ protected $_cache_path;
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $CI =& get_instance();
+ $CI->load->helper('file');
+
+ $path = $CI->config->item('cache_path');
+
+ $this->_cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch from cache
+ *
+ * @param mixed unique key id
+ * @return mixed data on success/false on failure
+ */
+ public function get($id)
+ {
+ if ( ! file_exists($this->_cache_path.$id))
+ {
+ return FALSE;
+ }
+
+ $data = read_file($this->_cache_path.$id);
+ $data = unserialize($data);
+
+ if (time() > $data['time'] + $data['ttl'])
+ {
+ unlink($this->_cache_path.$id);
+ return FALSE;
+ }
+
+ return $data['data'];
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save into cache
+ *
+ * @param string unique key
+ * @param mixed data to store
+ * @param int length of time (in seconds) the cache is valid
+ * - Default is 60 seconds
+ * @return boolean true on success/false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ $contents = array(
+ 'time' => time(),
+ 'ttl' => $ttl,
+ 'data' => $data
+ );
+
+ if (write_file($this->_cache_path.$id, serialize($contents)))
+ {
+ @chmod($this->_cache_path.$id, 0777);
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed unique identifier of item in cache
+ * @return boolean true on success/false on failure
+ */
+ public function delete($id)
+ {
+ return unlink($this->_cache_path.$id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the Cache
+ *
+ * @return boolean false on failure/true on success
+ */
+ public function clean()
+ {
+ return delete_files($this->_cache_path);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * Not supported by file-based caching
+ *
+ * @param string user/filehits
+ * @return mixed FALSE
+ */
+ public function cache_info($type = NULL)
+ {
+ return get_dir_file_info($this->_cache_path);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed FALSE on failure, array on success.
+ */
+ public function get_metadata($id)
+ {
+ if ( ! file_exists($this->_cache_path.$id))
+ {
+ return FALSE;
+ }
+
+ $data = read_file($this->_cache_path.$id);
+ $data = unserialize($data);
+
+ if (is_array($data))
+ {
+ $data = $data['data'];
+ $mtime = filemtime($this->_cache_path.$id);
+
+ if ( ! isset($data['ttl']))
+ {
+ return FALSE;
+ }
+
+ return array(
+ 'expire' => $mtime + $data['ttl'],
+ 'mtime' => $mtime
+ );
+ }
+
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Is supported
+ *
+ * In the file driver, check to see that the cache directory is indeed writable
+ *
+ * @return boolean
+ */
+ public function is_supported()
+ {
+ return is_really_writable($this->_cache_path);
+ }
+
+ // ------------------------------------------------------------------------
+}
+// End Class
+
+/* End of file Cache_file.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
new file mode 100644
index 000000000..adc7fbf44
--- /dev/null
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -0,0 +1,209 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 2.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Memcached Caching Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Core
+ * @author ExpressionEngine Dev Team
+ * @link
+ */
+
+class Cache_memcached extends CI_Driver {
+
+ private $_memcached; // Holds the memcached object
+
+ protected $_memcache_conf = array(
+ 'default' => array(
+ 'default_host' => '127.0.0.1',
+ 'default_port' => 11211,
+ 'default_weight' => 1
+ )
+ );
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Fetch from cache
+ *
+ * @param mixed unique key id
+ * @return mixed data on success/false on failure
+ */
+ public function get($id)
+ {
+ $data = $this->_memcached->get($id);
+
+ return (is_array($data)) ? $data[0] : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Save
+ *
+ * @param string unique identifier
+ * @param mixed data being cached
+ * @param int time to live
+ * @return boolean true on success, false on failure
+ */
+ public function save($id, $data, $ttl = 60)
+ {
+ return $this->_memcached->add($id, array($data, time(), $ttl), $ttl);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Delete from Cache
+ *
+ * @param mixed key to be deleted.
+ * @return boolean true on success, false on failure
+ */
+ public function delete($id)
+ {
+ return $this->_memcached->delete($id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Clean the Cache
+ *
+ * @return boolean false on failure/true on success
+ */
+ public function clean()
+ {
+ return $this->_memcached->flush();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Cache Info
+ *
+ * @param null type not supported in memcached
+ * @return mixed array on success, false on failure
+ */
+ public function cache_info($type = NULL)
+ {
+ return $this->_memcached->getStats();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get Cache Metadata
+ *
+ * @param mixed key to get cache metadata on
+ * @return mixed FALSE on failure, array on success.
+ */
+ public function get_metadata($id)
+ {
+ $stored = $this->_memcached->get($id);
+
+ if (count($stored) !== 3)
+ {
+ return FALSE;
+ }
+
+ list($value, $time, $ttl) = $stored;
+
+ return array(
+ 'expire' => $time + $ttl,
+ 'mtime' => $time,
+ 'data' => $data
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Setup memcached.
+ */
+ private function _setup_memcached()
+ {
+ // Try to load memcached server info from the config file.
+ $CI =& get_instance();
+ if ($CI->config->load('memcached', TRUE, TRUE))
+ {
+ if (is_array($CI->config->config['memcached']))
+ {
+ $this->_memcache_conf = NULL;
+
+ foreach ($CI->config->config['memcached'] as $name => $conf)
+ {
+ $this->_memcache_conf[$name] = $conf;
+ }
+ }
+ }
+
+ $this->_memcached = new Memcached();
+
+ foreach ($this->_memcache_conf as $name => $cache_server)
+ {
+ if ( ! array_key_exists('hostname', $cache_server))
+ {
+ $cache_server['hostname'] = $this->_default_options['default_host'];
+ }
+
+ if ( ! array_key_exists('port', $cache_server))
+ {
+ $cache_server['port'] = $this->_default_options['default_port'];
+ }
+
+ if ( ! array_key_exists('weight', $cache_server))
+ {
+ $cache_server['weight'] = $this->_default_options['default_weight'];
+ }
+
+ $this->_memcached->addServer(
+ $cache_server['hostname'], $cache_server['port'], $cache_server['weight']
+ );
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Is supported
+ *
+ * Returns FALSE if memcached is not supported on the system.
+ * If it is, we setup the memcached object & return TRUE
+ */
+ public function is_supported()
+ {
+ if ( ! extension_loaded('memcached'))
+ {
+ log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.');
+
+ return FALSE;
+ }
+
+ $this->_setup_memcached();
+ return TRUE;
+ }
+
+ // ------------------------------------------------------------------------
+
+}
+// End Class
+
+/* End of file Cache_memcached.php */
+/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ \ No newline at end of file
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index a57781c29..b4c6d366e 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -346,7 +346,7 @@ class CI_Table {
{
if ($function !== FALSE && is_callable($function))
{
- $out .= $function($cell);
+ $out .= call_user_func($function, $cell);
}
else
{
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 4ccbdde90..b0e1f4c6c 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -212,7 +212,18 @@ class CI_Upload {
if ($this->_file_name_override != '')
{
$this->file_name = $this->_prep_filename($this->_file_name_override);
- $this->file_ext = $this->get_extension($this->file_name);
+
+ // If no extension was provided in the file_name config item, use the uploaded one
+ if(strpos($this->_file_name_override, '.') === FALSE)
+ {
+ $this->file_name .= $this->file_ext;
+ }
+
+ // An extension was provided, lets have it!
+ else
+ {
+ $this->file_ext = $this->get_extension($this->_file_name_override);
+ }
if ( ! $this->is_allowed_filetype(TRUE))
{