summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries')
-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/Email.php163
-rw-r--r--system/libraries/Form_validation.php33
-rw-r--r--system/libraries/Security.php67
-rw-r--r--system/libraries/Table.php2
-rw-r--r--system/libraries/Upload.php13
-rw-r--r--system/libraries/User_agent.php95
11 files changed, 1128 insertions, 146 deletions
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/Email.php b/system/libraries/Email.php
index c6d8944df..e5af38f45 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -82,7 +82,7 @@ class CI_Email {
*
* The constructor can be passed an array of config values
*/
- function __construct($config = array())
+ public function __construct($config = array())
{
if (count($config) > 0)
{
@@ -106,9 +106,8 @@ class CI_Email {
* @param array
* @return void
*/
- function initialize($config = array())
+ public function initialize($config = array())
{
- $this->clear();
foreach ($config as $key => $val)
{
if (isset($this->$key))
@@ -125,9 +124,12 @@ class CI_Email {
}
}
}
+ $this->clear();
$this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
$this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -138,7 +140,7 @@ class CI_Email {
* @access public
* @return void
*/
- function clear($clear_attachments = FALSE)
+ public function clear($clear_attachments = FALSE)
{
$this->_subject = "";
$this->_body = "";
@@ -160,7 +162,7 @@ class CI_Email {
$this->_attach_type = array();
$this->_attach_disp = array();
}
-
+
return $this;
}
@@ -174,7 +176,7 @@ class CI_Email {
* @param string
* @return void
*/
- function from($from, $name = '')
+ public function from($from, $name = '')
{
if (preg_match( '/\<(.*)\>/', $from, $match))
{
@@ -203,7 +205,7 @@ class CI_Email {
$this->_set_header('From', $name.' <'.$from.'>');
$this->_set_header('Return-Path', '<'.$from.'>');
-
+
return $this;
}
@@ -217,7 +219,7 @@ class CI_Email {
* @param string
* @return void
*/
- function reply_to($replyto, $name = '')
+ public function reply_to($replyto, $name = '')
{
if (preg_match( '/\<(.*)\>/', $replyto, $match))
{
@@ -254,7 +256,7 @@ class CI_Email {
* @param string
* @return void
*/
- function to($to)
+ public function to($to)
{
$to = $this->_str_to_array($to);
$to = $this->clean_email($to);
@@ -271,14 +273,15 @@ class CI_Email {
switch ($this->_get_protocol())
{
- case 'smtp' : $this->_recipients = $to;
+ case 'smtp' :
+ $this->_recipients = $to;
break;
- case 'sendmail' : $this->_recipients = implode(", ", $to);
- break;
- case 'mail' : $this->_recipients = implode(", ", $to);
+ case 'sendmail' :
+ case 'mail' :
+ $this->_recipients = implode(", ", $to);
break;
}
-
+
return $this;
}
@@ -291,7 +294,7 @@ class CI_Email {
* @param string
* @return void
*/
- function cc($cc)
+ public function cc($cc)
{
$cc = $this->_str_to_array($cc);
$cc = $this->clean_email($cc);
@@ -307,7 +310,7 @@ class CI_Email {
{
$this->_cc_array = $cc;
}
-
+
return $this;
}
@@ -321,7 +324,7 @@ class CI_Email {
* @param string
* @return void
*/
- function bcc($bcc, $limit = '')
+ public function bcc($bcc, $limit = '')
{
if ($limit != '' && is_numeric($limit))
{
@@ -345,7 +348,7 @@ class CI_Email {
{
$this->_set_header('Bcc', implode(", ", $bcc));
}
-
+
return $this;
}
@@ -358,7 +361,7 @@ class CI_Email {
* @param string
* @return void
*/
- function subject($subject)
+ public function subject($subject)
{
$subject = $this->_prep_q_encoding($subject);
$this->_set_header('Subject', $subject);
@@ -374,7 +377,7 @@ class CI_Email {
* @param string
* @return void
*/
- function message($body)
+ public function message($body)
{
$this->_body = stripslashes(rtrim(str_replace("\r", "", $body)));
return $this;
@@ -389,7 +392,7 @@ class CI_Email {
* @param string
* @return void
*/
- function attach($filename, $disposition = 'attachment')
+ public function attach($filename, $disposition = 'attachment')
{
$this->_attach_name[] = $filename;
$this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename))));
@@ -407,7 +410,7 @@ class CI_Email {
* @param string
* @return void
*/
- function _set_header($header, $value)
+ private function _set_header($header, $value)
{
$this->_headers[$header] = $value;
}
@@ -421,7 +424,7 @@ class CI_Email {
* @param string
* @return array
*/
- function _str_to_array($email)
+ private function _str_to_array($email)
{
if ( ! is_array($email))
{
@@ -447,7 +450,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_alt_message($str = '')
+ public function set_alt_message($str = '')
{
$this->alt_message = ($str == '') ? '' : $str;
return $this;
@@ -462,7 +465,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_mailtype($type = 'text')
+ public function set_mailtype($type = 'text')
{
$this->mailtype = ($type == 'html') ? 'html' : 'text';
return $this;
@@ -477,7 +480,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_wordwrap($wordwrap = TRUE)
+ public function set_wordwrap($wordwrap = TRUE)
{
$this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE;
return $this;
@@ -492,7 +495,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_protocol($protocol = 'mail')
+ public function set_protocol($protocol = 'mail')
{
$this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
return $this;
@@ -507,7 +510,7 @@ class CI_Email {
* @param integer
* @return void
*/
- function set_priority($n = 3)
+ public function set_priority($n = 3)
{
if ( ! is_numeric($n))
{
@@ -534,7 +537,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_newline($newline = "\n")
+ public function set_newline($newline = "\n")
{
if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r")
{
@@ -543,7 +546,7 @@ class CI_Email {
}
$this->newline = $newline;
-
+
return $this;
}
@@ -556,7 +559,7 @@ class CI_Email {
* @param string
* @return void
*/
- function set_crlf($crlf = "\n")
+ public function set_crlf($crlf = "\n")
{
if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r")
{
@@ -565,7 +568,7 @@ class CI_Email {
}
$this->crlf = $crlf;
-
+
return $this;
}
@@ -577,7 +580,7 @@ class CI_Email {
* @access private
* @return void
*/
- function _set_boundaries()
+ private function _set_boundaries()
{
$this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
$this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
@@ -591,7 +594,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_message_id()
+ private function _get_message_id()
{
$from = $this->_headers['Return-Path'];
$from = str_replace(">", "", $from);
@@ -609,7 +612,7 @@ class CI_Email {
* @param bool
* @return string
*/
- function _get_protocol($return = TRUE)
+ private function _get_protocol($return = TRUE)
{
$this->protocol = strtolower($this->protocol);
$this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
@@ -629,7 +632,7 @@ class CI_Email {
* @param bool
* @return string
*/
- function _get_encoding($return = TRUE)
+ private function _get_encoding($return = TRUE)
{
$this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
@@ -655,7 +658,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_content_type()
+ private function _get_content_type()
{
if ($this->mailtype == 'html' && count($this->_attach_name) == 0)
{
@@ -683,7 +686,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _set_date()
+ private function _set_date()
{
$timezone = date("Z");
$operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+';
@@ -701,7 +704,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_mime_message()
+ private function _get_mime_message()
{
return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
}
@@ -715,7 +718,7 @@ class CI_Email {
* @param string
* @return bool
*/
- function validate_email($email)
+ public function validate_email($email)
{
if ( ! is_array($email))
{
@@ -744,7 +747,7 @@ class CI_Email {
* @param string
* @return bool
*/
- function valid_email($address)
+ public function valid_email($address)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
}
@@ -758,7 +761,7 @@ class CI_Email {
* @param string
* @return string
*/
- function clean_email($email)
+ public function clean_email($email)
{
if ( ! is_array($email))
{
@@ -794,7 +797,7 @@ class CI_Email {
/**
* Build alternative plain text message
*
- * This function provides the raw message for use
+ * This public function provides the raw message for use
* in plain-text headers of HTML-formatted emails.
* If the user hasn't specified his own alternative message
* it creates one by stripping the HTML
@@ -802,7 +805,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_alt_message()
+ private function _get_alt_message()
{
if ($this->alt_message != "")
{
@@ -847,7 +850,7 @@ class CI_Email {
* @param integer
* @return string
*/
- function word_wrap($str, $charlim = '')
+ public function word_wrap($str, $charlim = '')
{
// Se the character limit
if ($charlim == '')
@@ -876,7 +879,7 @@ class CI_Email {
}
}
- // Use PHP's native function to do the initial wordwrap.
+ // Use PHP's native public function to do the initial wordwrap.
// We set the cut flag to FALSE so that any individual words that are
// too long get left alone. In the next step we'll deal with them.
$str = wordwrap($str, $charlim, "\n", FALSE);
@@ -942,7 +945,7 @@ class CI_Email {
* @param string
* @return string
*/
- function _build_headers()
+ private function _build_headers()
{
$this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
$this->_set_header('X-Mailer', $this->useragent);
@@ -959,7 +962,7 @@ class CI_Email {
* @access private
* @return void
*/
- function _write_headers()
+ private function _write_headers()
{
if ($this->protocol == 'mail')
{
@@ -994,7 +997,7 @@ class CI_Email {
* @access private
* @return void
*/
- function _build_message()
+ private function _build_message()
{
if ($this->wordwrap === TRUE AND $this->mailtype != 'html')
{
@@ -1023,7 +1026,7 @@ class CI_Email {
{
$this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
}
-
+
return;
break;
@@ -1048,10 +1051,10 @@ class CI_Email {
$body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
}
-
+
$this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
-
-
+
+
if ($this->_get_protocol() == 'mail')
{
$this->_header_str .= $hdr;
@@ -1077,8 +1080,8 @@ class CI_Email {
if ($this->_get_protocol() == 'mail')
{
$this->_header_str .= $hdr;
- }
-
+ }
+
$body .= $this->_get_mime_message() . $this->newline . $this->newline;
$body .= "--" . $this->_atc_boundary . $this->newline;
@@ -1091,7 +1094,7 @@ class CI_Email {
case 'html-attach' :
$hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
-
+
if ($this->_get_protocol() == 'mail')
{
$this->_header_str .= $hdr;
@@ -1152,7 +1155,7 @@ class CI_Email {
}
$body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
-
+
if ($this->_get_protocol() == 'mail')
{
@@ -1162,7 +1165,7 @@ class CI_Email {
{
$this->_finalbody = $hdr . $body;
}
-
+
return;
}
@@ -1179,7 +1182,7 @@ class CI_Email {
* @param integer
* @return string
*/
- function _prep_quoted_printable($str, $charlim = '')
+ private function _prep_quoted_printable($str, $charlim = '')
{
// Set the character limit
// Don't allow over 76, as that will make servers and MUAs barf
@@ -1272,7 +1275,7 @@ class CI_Email {
* @param bool // set to TRUE for processing From: headers
* @return str
*/
- function _prep_q_encoding($str, $from = FALSE)
+ private function _prep_q_encoding($str, $from = FALSE)
{
$str = str_replace(array("\r", "\n"), array('', ''), $str);
@@ -1339,7 +1342,7 @@ class CI_Email {
* @access public
* @return bool
*/
- function send()
+ public function send()
{
if ($this->_replyto_flag == FALSE)
{
@@ -1382,7 +1385,7 @@ class CI_Email {
* @access public
* @return bool
*/
- function batch_bcc_send()
+ public function batch_bcc_send()
{
$float = $this->bcc_batch_size -1;
@@ -1440,7 +1443,7 @@ class CI_Email {
* @access private
* @return void
*/
- function _unwrap_specials()
+ private function _unwrap_specials()
{
$this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
}
@@ -1453,7 +1456,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _remove_nl_callback($matches)
+ private function _remove_nl_callback($matches)
{
if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
{
@@ -1471,7 +1474,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _spool_email()
+ private function _spool_email()
{
$this->_unwrap_specials();
@@ -1516,7 +1519,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _send_with_mail()
+ private function _send_with_mail()
{
if ($this->_safe_mode == TRUE)
{
@@ -1533,7 +1536,7 @@ class CI_Email {
{
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
-
+
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
{
return FALSE;
@@ -1553,7 +1556,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _send_with_sendmail()
+ private function _send_with_sendmail()
{
$fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
@@ -1567,7 +1570,7 @@ class CI_Email {
fputs($fp, $this->_finalbody);
$status = pclose($fp);
-
+
if (version_compare(PHP_VERSION, '4.2.3') == -1)
{
$status = $status >> 8 & 0xFF;
@@ -1591,7 +1594,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _send_with_smtp()
+ private function _send_with_smtp()
{
if ($this->smtp_host == '')
{
@@ -1661,7 +1664,7 @@ class CI_Email {
* @param string
* @return string
*/
- function _smtp_connect()
+ private function _smtp_connect()
{
$this->_smtp_connect = fsockopen($this->smtp_host,
$this->smtp_port,
@@ -1689,7 +1692,7 @@ class CI_Email {
* @param string
* @return string
*/
- function _send_command($cmd, $data = '')
+ private function _send_command($cmd, $data = '')
{
switch ($cmd)
{
@@ -1754,7 +1757,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _smtp_authenticate()
+ private function _smtp_authenticate()
{
if ( ! $this->_smtp_auth)
{
@@ -1808,7 +1811,7 @@ class CI_Email {
* @access private
* @return bool
*/
- function _send_data($data)
+ private function _send_data($data)
{
if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
{
@@ -1829,7 +1832,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_smtp_data()
+ private function _get_smtp_data()
{
$data = "";
@@ -1854,7 +1857,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_hostname()
+ private function _get_hostname()
{
return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
}
@@ -1867,7 +1870,7 @@ class CI_Email {
* @access private
* @return string
*/
- function _get_ip()
+ private function _get_ip()
{
if ($this->_IP !== FALSE)
{
@@ -1909,7 +1912,7 @@ class CI_Email {
* @access public
* @return string
*/
- function print_debugger()
+ public function print_debugger()
{
$msg = '';
@@ -1934,7 +1937,7 @@ class CI_Email {
* @param string
* @return string
*/
- function _set_error_message($msg, $val = '')
+ private function _set_error_message($msg, $val = '')
{
$CI =& get_instance();
$CI->lang->load('email');
@@ -1958,7 +1961,7 @@ class CI_Email {
* @param string
* @return string
*/
- function _mime_types($ext = "")
+ private function _mime_types($ext = "")
{
$mimes = array( 'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index cbefca104..fc5b82ee3 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -171,7 +171,7 @@ class CI_Form_validation {
}
$this->_error_messages = array_merge($this->_error_messages, $lang);
-
+
return $this;
}
@@ -191,7 +191,7 @@ class CI_Form_validation {
{
$this->_error_prefix = $prefix;
$this->_error_suffix = $suffix;
-
+
return $this;
}
@@ -576,7 +576,7 @@ class CI_Form_validation {
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
- if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match))
+ if (preg_match("/(.*?)\[(.*)\]/", $rule, $match))
{
$rule = $match[1];
$param = $match[2];
@@ -730,6 +730,13 @@ class CI_Form_validation {
return $default;
}
+ // If the data is an array output them one at a time.
+ // E.g: form_input('name[]', set_value('name[]');
+ if (is_array($this->_field_data[$field]['postdata']))
+ {
+ return array_shift($this->_field_data[$field]['postdata']);
+ }
+
return $this->_field_data[$field]['postdata'];
}
@@ -889,6 +896,26 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Performs a Regular Expression match test.
+ *
+ * @access public
+ * @param string
+ * @param regex
+ * @return bool
+ */
+ function regex_match($str, $regex)
+ {
+ if ( ! preg_match($regex, $str))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Match one field to another
*
* @access public
diff --git a/system/libraries/Security.php b/system/libraries/Security.php
index 018001ac8..ba64c7326 100644
--- a/system/libraries/Security.php
+++ b/system/libraries/Security.php
@@ -25,14 +25,15 @@
* @link http://codeigniter.com/user_guide/libraries/sessions.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';
+
+ public $xss_hash = '';
+ public $csrf_hash = '';
+ public $csrf_expire = 7200; // Two hours (in seconds)
+ public $csrf_token_name = 'ci_csrf_token';
+ public $csrf_cookie_name = 'ci_csrf_token';
/* never allowed, string replacement */
- var $never_allowed_str = array(
+ public $never_allowed_str = array(
'document.cookie' => '[removed]',
'document.write' => '[removed]',
'.parentNode' => '[removed]',
@@ -44,7 +45,7 @@ class CI_Security {
'<![CDATA[' => '&lt;![CDATA['
);
/* never allowed, regex replacement */
- var $never_allowed_regex = array(
+ public $never_allowed_regex = array(
"javascript\s*:" => '[removed]',
"expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE
"vbscript\s*:" => '[removed]', // IE, surprise!
@@ -53,6 +54,10 @@ class CI_Security {
public function __construct()
{
+ $this->csrf_token_name = (config_item('csrf_token_name')) ? config_item('csrf_token_name') : 'csrf_token_name';
+ $this->csrf_cookie_name = (config_item('csrf_cookie_name')) ? config_item('csrf_cookie_name') : 'csrf_cookie_name';
+ $this->csrf_expire = (config_item('csrf_expire')) ? config_item('csrf_expire') : 7200;
+
// 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;
@@ -70,7 +75,7 @@ class CI_Security {
* @access public
* @return null
*/
- function csrf_verify()
+ public function csrf_verify()
{
// If no POST data exists we will set the CSRF cookie
if (count($_POST) == 0)
@@ -109,7 +114,7 @@ class CI_Security {
* @access public
* @return null
*/
- function csrf_set_cookie()
+ public function csrf_set_cookie()
{
$expire = time() + $this->csrf_expire;
@@ -123,10 +128,10 @@ class CI_Security {
/**
* Set Cross Site Request Forgery Protection Cookie
*
- * @access public
+ * @access private
* @return null
*/
- function _csrf_set_hash()
+ private function _csrf_set_hash()
{
if ($this->csrf_hash == '')
{
@@ -153,7 +158,7 @@ class CI_Security {
* @access public
* @return null
*/
- function csrf_show_error()
+ public function csrf_show_error()
{
show_error('The action you have requested is not allowed.');
}
@@ -186,7 +191,7 @@ class CI_Security {
* @param mixed string or array
* @return string
*/
- function xss_clean($str, $is_image = FALSE)
+ public function xss_clean($str, $is_image = FALSE)
{
/*
* Is the string an array?
@@ -210,9 +215,9 @@ class CI_Security {
/*
* Protect GET variables in URLs
*/
-
+
// 901119URL5918AMP18930PROTECT8198
-
+
$str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str);
/*
@@ -259,7 +264,7 @@ class CI_Security {
*/
$str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
-
+
$str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str);
/*
@@ -470,7 +475,7 @@ class CI_Security {
* @access public
* @return string
*/
- function xss_hash()
+ public function xss_hash()
{
if ($this->xss_hash == '')
{
@@ -493,11 +498,11 @@ class CI_Security {
* Callback function for xss_clean() to remove whitespace from
* things like j a v a s c r i p t
*
- * @access public
+ * @access private
* @param type
* @return type
*/
- function _compact_exploded_words($matches)
+ private function _compact_exploded_words($matches)
{
return preg_replace('/\s+/s', '', $matches[1]).$matches[2];
}
@@ -513,7 +518,7 @@ class CI_Security {
* @param array
* @return string
*/
- function _sanitize_naughty_html($matches)
+ private function _sanitize_naughty_html($matches)
{
// encode opening brace
$str = '&lt;'.$matches[1].$matches[2].$matches[3];
@@ -538,7 +543,7 @@ class CI_Security {
* @param array
* @return string
*/
- function _js_link_removal($match)
+ private function _js_link_removal($match)
{
$attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
@@ -556,7 +561,7 @@ class CI_Security {
* @param array
* @return string
*/
- function _js_img_removal($match)
+ private function _js_img_removal($match)
{
$attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
@@ -569,11 +574,11 @@ class CI_Security {
*
* Used as a callback for XSS Clean
*
- * @access public
+ * @access private
* @param array
* @return string
*/
- function _convert_attribute($match)
+ private function _convert_attribute($match)
{
return str_replace(array('>', '<', '\\'), array('&gt;', '&lt;', '\\\\'), $match[0]);
}
@@ -585,11 +590,11 @@ class CI_Security {
*
* Filters tag attributes for consistency and safety
*
- * @access public
+ * @access private
* @param string
* @return string
*/
- function _filter_attributes($str)
+ private function _filter_attributes($str)
{
$out = '';
@@ -611,11 +616,11 @@ class CI_Security {
*
* Used as a callback for XSS Clean
*
- * @access public
+ * @access private
* @param array
* @return string
*/
- function _decode_entity($match)
+ private function _decode_entity($match)
{
return $this->entity_decode($match[0], strtoupper(config_item('charset')));
}
@@ -641,7 +646,7 @@ class CI_Security {
* @param string
* @return string
*/
- function entity_decode($str, $charset='UTF-8')
+ public function entity_decode($str, $charset='UTF-8')
{
if (stristr($str, '&') === FALSE) return $str;
@@ -680,7 +685,7 @@ class CI_Security {
* @param string
* @return string
*/
- function sanitize_filename($str, $relative_path = FALSE)
+ public function sanitize_filename($str, $relative_path = FALSE)
{
$bad = array(
"../",
@@ -715,7 +720,7 @@ class CI_Security {
"%3b", // ;
"%3d" // =
);
-
+
if ( ! $relative_path)
{
$bad[] = './';
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index 207ccc21d..485541630 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 4ccc032e9..8f84ffd7e 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))
{
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 863faba52..c62174836 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -82,7 +82,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _load_agent_file()
+ private function _load_agent_file()
{
if ( ! @include(APPPATH.'config/user_agents'.EXT))
{
@@ -130,7 +130,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _compile_data()
+ private function _compile_data()
{
$this->_set_platform();
@@ -151,7 +151,7 @@ class CI_User_agent {
* @access private
* @return mixed
*/
- function _set_platform()
+ private function _set_platform()
{
if (is_array($this->platforms) AND count($this->platforms) > 0)
{
@@ -175,7 +175,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_browser()
+ private function _set_browser()
{
if (is_array($this->browsers) AND count($this->browsers) > 0)
{
@@ -202,7 +202,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_robot()
+ private function _set_robot()
{
if (is_array($this->robots) AND count($this->robots) > 0)
{
@@ -227,7 +227,7 @@ class CI_User_agent {
* @access private
* @return bool
*/
- function _set_mobile()
+ private function _set_mobile()
{
if (is_array($this->mobiles) AND count($this->mobiles) > 0)
{
@@ -252,7 +252,7 @@ class CI_User_agent {
* @access private
* @return void
*/
- function _set_languages()
+ private function _set_languages()
{
if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
{
@@ -275,7 +275,7 @@ class CI_User_agent {
* @access private
* @return void
*/
- function _set_charsets()
+ private function _set_charsets()
{
if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
{
@@ -298,9 +298,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_browser()
+ public function is_browser($key = NULL)
{
- return $this->is_browser;
+ if ( ! $this->is_browser)
+ {
+ return FALSE;
+ }
+
+ // No need to be specific, it's a browser
+ if ($key === NULL)
+ {
+ return TRUE;
+ }
+
+ // Check for a specific browser
+ return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
}
// --------------------------------------------------------------------
@@ -311,9 +323,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_robot()
+ public function is_robot($key = NULL)
{
- return $this->is_robot;
+ if ( ! $this->is_robot)
+ {
+ return FALSE;
+ }
+
+ // No need to be specific, it's a robot
+ if ($key === NULL)
+ {
+ return TRUE;
+ }
+
+ // Check for a specific robot
+ return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
}
// --------------------------------------------------------------------
@@ -324,9 +348,21 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_mobile()
+ public function is_mobile($key = NULL)
{
- return $this->is_mobile;
+ if ( ! $this->is_mobile)
+ {
+ return FALSE;
+ }
+
+ // No need to be specific, it's a mobile
+ if ($key === NULL)
+ {
+ return TRUE;
+ }
+
+ // Check for a specific robot
+ return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
}
// --------------------------------------------------------------------
@@ -337,9 +373,9 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function is_referral()
+ public function is_referral()
{
- return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE;
+ return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '');
}
// --------------------------------------------------------------------
@@ -350,7 +386,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function agent_string()
+ public function agent_string()
{
return $this->agent;
}
@@ -363,7 +399,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function platform()
+ public function platform()
{
return $this->platform;
}
@@ -376,7 +412,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function browser()
+ public function browser()
{
return $this->browser;
}
@@ -389,7 +425,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function version()
+ public function version()
{
return $this->version;
}
@@ -402,7 +438,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function robot()
+ public function robot()
{
return $this->robot;
}
@@ -414,7 +450,7 @@ class CI_User_agent {
* @access public
* @return string
*/
- function mobile()
+ public function mobile()
{
return $this->mobile;
}
@@ -427,7 +463,7 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function referrer()
+ public function referrer()
{
return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
}
@@ -440,7 +476,7 @@ class CI_User_agent {
* @access public
* @return array
*/
- function languages()
+ public function languages()
{
if (count($this->languages) == 0)
{
@@ -458,7 +494,7 @@ class CI_User_agent {
* @access public
* @return array
*/
- function charsets()
+ public function charsets()
{
if (count($this->charsets) == 0)
{
@@ -476,9 +512,9 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function accept_lang($lang = 'en')
+ public function accept_lang($lang = 'en')
{
- return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE;
+ return (in_array(strtolower($lang), $this->languages(), TRUE));
}
// --------------------------------------------------------------------
@@ -489,12 +525,11 @@ class CI_User_agent {
* @access public
* @return bool
*/
- function accept_charset($charset = 'utf-8')
+ public function accept_charset($charset = 'utf-8')
{
- return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE;
+ return (in_array(strtolower($charset), $this->charsets(), TRUE));
}
-
}