summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/core/Loader.php15
-rw-r--r--system/database/DB_active_rec.php286
-rw-r--r--system/database/drivers/mysql/mysql_driver.php11
-rw-r--r--system/database/drivers/mysql/mysql_forge.php8
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php11
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php8
-rw-r--r--system/helpers/form_helper.php4
-rw-r--r--system/helpers/html_helper.php4
-rw-r--r--system/language/english/form_validation_lang.php1
-rw-r--r--system/language/english/migration_lang.php13
-rw-r--r--system/libraries/Cart.php12
-rw-r--r--system/libraries/Email.php120
-rw-r--r--system/libraries/Form_validation.php119
-rw-r--r--system/libraries/Migration.php338
-rw-r--r--system/libraries/User_agent.php2
15 files changed, 660 insertions, 292 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 721c196cc..7c8b298ac 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -389,6 +389,21 @@ class CI_Loader {
// --------------------------------------------------------------------
/**
+ * 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.
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 52bad260a..7bab729f5 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -69,11 +69,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates the SELECT portion of the query
*
- * @access public
* @param string
* @return object
*/
- function select($select = '*', $escape = NULL)
+ public function select($select = '*', $escape = NULL)
{
if (is_string($select))
{
@@ -107,12 +106,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates a SELECT MAX(field) portion of a query
*
- * @access public
* @param string the field
* @param string an alias
* @return object
*/
- function select_max($select = '', $alias = '')
+ public function select_max($select = '', $alias = '')
{
return $this->_max_min_avg_sum($select, $alias, 'MAX');
}
@@ -124,12 +122,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates a SELECT MIN(field) portion of a query
*
- * @access public
* @param string the field
* @param string an alias
* @return object
*/
- function select_min($select = '', $alias = '')
+ public function select_min($select = '', $alias = '')
{
return $this->_max_min_avg_sum($select, $alias, 'MIN');
}
@@ -141,12 +138,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates a SELECT AVG(field) portion of a query
*
- * @access public
* @param string the field
* @param string an alias
* @return object
*/
- function select_avg($select = '', $alias = '')
+ public function select_avg($select = '', $alias = '')
{
return $this->_max_min_avg_sum($select, $alias, 'AVG');
}
@@ -158,12 +154,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates a SELECT SUM(field) portion of a query
*
- * @access public
* @param string the field
* @param string an alias
* @return object
*/
- function select_sum($select = '', $alias = '')
+ public function select_sum($select = '', $alias = '')
{
return $this->_max_min_avg_sum($select, $alias, 'SUM');
}
@@ -178,12 +173,11 @@ class CI_DB_active_record extends CI_DB_driver {
* select_avg()
* select_sum()
*
- * @access public
* @param string the field
* @param string an alias
* @return object
*/
- function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
+ protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
{
if ( ! is_string($select) OR $select == '')
{
@@ -220,11 +214,10 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Determines the alias name based on the table
*
- * @access private
* @param string
* @return string
*/
- function _create_alias_from_table($item)
+ protected function _create_alias_from_table($item)
{
if (strpos($item, '.') !== FALSE)
{
@@ -241,11 +234,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Sets a flag which tells the query string compiler to add DISTINCT
*
- * @access public
* @param bool
* @return object
*/
- function distinct($val = TRUE)
+ public function distinct($val = TRUE)
{
$this->ar_distinct = (is_bool($val)) ? $val : TRUE;
return $this;
@@ -258,11 +250,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates the FROM portion of the query
*
- * @access public
* @param mixed can be a string or array
* @return object
*/
- function from($from)
+ public function from($from)
{
foreach ((array)$from as $val)
{
@@ -311,13 +302,12 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Generates the JOIN portion of the query
*
- * @access public
* @param string
* @param string the join condition
* @param string the type of join
* @return object
*/
- function join($table, $cond, $type = '')
+ public function join($table, $cond, $type = '')
{
if ($type != '')
{
@@ -367,12 +357,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates the WHERE portion of the query. Separates
* multiple calls with AND
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function where($key, $value = NULL, $escape = TRUE)
+ public function where($key, $value = NULL, $escape = TRUE)
{
return $this->_where($key, $value, 'AND ', $escape);
}
@@ -385,12 +374,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates the WHERE portion of the query. Separates
* multiple calls with OR
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function or_where($key, $value = NULL, $escape = TRUE)
+ public function or_where($key, $value = NULL, $escape = TRUE)
{
return $this->_where($key, $value, 'OR ', $escape);
}
@@ -400,15 +388,14 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Where
*
- * Called by where() or orwhere()
+ * Called by where() or or_where()
*
- * @access private
* @param mixed
* @param mixed
* @param string
* @return object
*/
- function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
+ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{
if ( ! is_array($key))
{
@@ -471,12 +458,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field IN ('item', 'item') SQL query joined with
* AND if appropriate
*
- * @access public
* @param string The field to search
* @param array The values searched on
* @return object
*/
- function where_in($key = NULL, $values = NULL)
+ public function where_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values);
}
@@ -489,12 +475,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field IN ('item', 'item') SQL query joined with
* OR if appropriate
*
- * @access public
* @param string The field to search
* @param array The values searched on
* @return object
*/
- function or_where_in($key = NULL, $values = NULL)
+ public function or_where_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, FALSE, 'OR ');
}
@@ -507,12 +492,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field NOT IN ('item', 'item') SQL query joined
* with AND if appropriate
*
- * @access public
* @param string The field to search
* @param array The values searched on
* @return object
*/
- function where_not_in($key = NULL, $values = NULL)
+ public function where_not_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, TRUE);
}
@@ -525,12 +509,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a WHERE field NOT IN ('item', 'item') SQL query joined
* with OR if appropriate
*
- * @access public
* @param string The field to search
* @param array The values searched on
* @return object
*/
- function or_where_not_in($key = NULL, $values = NULL)
+ public function or_where_not_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, TRUE, 'OR ');
}
@@ -542,14 +525,13 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Called by where_in, where_in_or, where_not_in, where_not_in_or
*
- * @access public
* @param string The field to search
* @param array The values searched on
* @param boolean If the statement would be IN or NOT IN
* @param string
* @return object
*/
- function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
+ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
{
if ($key === NULL OR $values === NULL)
{
@@ -592,12 +574,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a %LIKE% portion of the query. Separates
* multiple calls with AND
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function like($field, $match = '', $side = 'both')
+ public function like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'AND ', $side);
}
@@ -610,12 +591,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a NOT LIKE portion of the query. Separates
* multiple calls with AND
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function not_like($field, $match = '', $side = 'both')
+ public function not_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'AND ', $side, 'NOT');
}
@@ -628,12 +608,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a %LIKE% portion of the query. Separates
* multiple calls with OR
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function or_like($field, $match = '', $side = 'both')
+ public function or_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'OR ', $side);
}
@@ -646,12 +625,11 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a NOT LIKE portion of the query. Separates
* multiple calls with OR
*
- * @access public
* @param mixed
* @param mixed
* @return object
*/
- function or_not_like($field, $match = '', $side = 'both')
+ public function or_not_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'OR ', $side, 'NOT');
}
@@ -663,13 +641,12 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Called by like() or orlike()
*
- * @access private
* @param mixed
* @param mixed
* @param string
* @return object
*/
- function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
+ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
if ( ! is_array($field))
{
@@ -719,11 +696,10 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* GROUP BY
*
- * @access public
* @param string
* @return object
*/
- function group_by($by)
+ public function group_by($by)
{
if (is_string($by))
{
@@ -755,12 +731,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Separates multiple calls with AND
*
- * @access public
* @param string
* @param string
* @return object
*/
- function having($key, $value = '', $escape = TRUE)
+ public function having($key, $value = '', $escape = TRUE)
{
return $this->_having($key, $value, 'AND ', $escape);
}
@@ -772,12 +747,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Separates multiple calls with OR
*
- * @access public
* @param string
* @param string
* @return object
*/
- function or_having($key, $value = '', $escape = TRUE)
+ public function or_having($key, $value = '', $escape = TRUE)
{
return $this->_having($key, $value, 'OR ', $escape);
}
@@ -789,12 +763,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Called by having() or or_having()
*
- * @access private
* @param string
* @param string
* @return object
*/
- function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
+ protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
{
if ( ! is_array($key))
{
@@ -817,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver {
if ($v != '')
{
- $v = ' '.$this->escape_str($v);
+ $v = ' '.$this->escape($v);
}
$this->ar_having[] = $prefix.$k.$v;
@@ -836,12 +809,11 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Sets the ORDER BY value
*
- * @access public
* @param string
* @param string direction: asc or desc
* @return object
*/
- function order_by($orderby, $direction = '')
+ public function order_by($orderby, $direction = '')
{
if (strtolower($direction) == 'random')
{
@@ -892,18 +864,17 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Sets the LIMIT value
*
- * @access public
* @param integer the limit value
* @param integer the offset value
* @return object
*/
- function limit($value, $offset = '')
+ public function limit($value, $offset = '')
{
- $this->ar_limit = $value;
+ $this->ar_limit = (int) $value;
if ($offset != '')
{
- $this->ar_offset = $offset;
+ $this->ar_offset = (int) $offset;
}
return $this;
@@ -914,11 +885,10 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Sets the OFFSET value
*
- * @access public
* @param integer the offset value
* @return object
*/
- function offset($offset)
+ public function offset($offset)
{
$this->ar_offset = $offset;
return $this;
@@ -929,13 +899,12 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* The "set" function. Allows key/value pairs to be set for inserting or updating
*
- * @access public
* @param mixed
* @param string
* @param boolean
* @return object
*/
- function set($key, $value = '', $escape = TRUE)
+ public function set($key, $value = '', $escape = TRUE)
{
$key = $this->_object_to_array($key);
@@ -967,13 +936,12 @@ class CI_DB_active_record extends CI_DB_driver {
* Compiles the select statement based on the other functions called
* and runs the query
*
- * @access public
* @param string the table
* @param string the limit clause
* @param string the offset clause
* @return object
*/
- function get($table = '', $limit = null, $offset = null)
+ public function get($table = '', $limit = null, $offset = null)
{
if ($table != '')
{
@@ -999,11 +967,10 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a platform-specific query string that counts all records
* returned by an Active Record query.
*
- * @access public
* @param string
* @return string
*/
- function count_all_results($table = '')
+ public function count_all_results($table = '')
{
if ($table != '')
{
@@ -1032,13 +999,12 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Allows the where clause, limit and offset to be added directly
*
- * @access public
* @param string the where clause
* @param string the limit clause
* @param string the offset clause
* @return object
*/
- function get_where($table = '', $where = null, $limit = null, $offset = null)
+ public function get_where($table = '', $where = null, $limit = null, $offset = null)
{
if ($table != '')
{
@@ -1069,12 +1035,11 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles batch insert strings and runs the queries
*
- * @access public
* @param string the table to retrieve the results from
* @param array an associative array of insert values
* @return object
*/
- function insert_batch($table = '', $set = NULL)
+ public function insert_batch($table = '', $set = NULL)
{
if ( ! is_null($set))
{
@@ -1127,14 +1092,12 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
*
- * @access public
* @param mixed
* @param string
* @param boolean
* @return object
*/
-
- function set_insert_batch($key, $value = '', $escape = TRUE)
+ public function set_insert_batch($key, $value = '', $escape = TRUE)
{
$key = $this->_object_to_array_batch($key);
@@ -1189,8 +1152,7 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an insert string and runs the query
*
- * @access public
- * @param string the table to retrieve the results from
+ * @param string the table to insert data into
* @param array an associative array of insert values
* @return object
*/
@@ -1230,7 +1192,18 @@ class CI_DB_active_record extends CI_DB_driver {
return $this->query($sql);
}
- function replace($table = '', $set = NULL)
+ // --------------------------------------------------------------------
+
+ /**
+ * Replace
+ *
+ * Compiles an replace into string and runs the query
+ *
+ * @param string the table to replace data into
+ * @param array an associative array of insert values
+ * @return object
+ */
+ public function replace($table = '', $set = NULL)
{
if ( ! is_null($set))
{
@@ -1273,13 +1246,12 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an update string and runs the query
*
- * @access public
* @param string the table to retrieve the results from
* @param array an associative array of update values
* @param mixed the where clause
* @return object
*/
- function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
+ public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
{
// Combine any cached components with the current statements
$this->_merge_cache();
@@ -1336,13 +1308,12 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an update string and runs the query
*
- * @access public
* @param string the table to retrieve the results from
* @param array an associative array of update values
* @param string the where key
* @return object
*/
- function update_batch($table = '', $set = NULL, $index = NULL)
+ public function update_batch($table = '', $set = NULL, $index = NULL)
{
// Combine any cached components with the current statements
$this->_merge_cache();
@@ -1351,7 +1322,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($this->db_debug)
{
- return $this->display_error('db_myst_use_index');
+ return $this->display_error('db_must_use_index');
}
return FALSE;
@@ -1402,14 +1373,12 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* The "set_update_batch" function. Allows key/value pairs to be set for batch updating
*
- * @access public
* @param array
* @param string
* @param boolean
* @return object
*/
-
- function set_update_batch($key, $index = '', $escape = TRUE)
+ public function set_update_batch($key, $index = '', $escape = TRUE)
{
$key = $this->_object_to_array_batch($key);
@@ -1462,11 +1431,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles a delete string and runs "DELETE FROM table"
*
- * @access public
* @param string the table to empty
* @return object
*/
- function empty_table($table = '')
+ public function empty_table($table = '')
{
if ($table == '')
{
@@ -1502,11 +1470,10 @@ class CI_DB_active_record extends CI_DB_driver {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table to truncate
* @return object
*/
- function truncate($table = '')
+ public function truncate($table = '')
{
if ($table == '')
{
@@ -1540,14 +1507,13 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles a delete string and runs the query
*
- * @access public
* @param mixed the table(s) to delete from. String or array
* @param mixed the where clause
* @param mixed the limit clause
* @param boolean
* @return object
*/
- function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
+ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
{
// Combine any cached components with the current statements
$this->_merge_cache();
@@ -1617,11 +1583,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Prepends a database prefix if one exists in configuration
*
- * @access public
* @param string the table
* @return string
*/
- function dbprefix($table = '')
+ public function dbprefix($table = '')
{
if ($table == '')
{
@@ -1634,15 +1599,29 @@ class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * Set DB Prefix
+ *
+ * Set's the DB Prefix to something new without needing to reconnect
+ *
+ * @param string the prefix
+ * @return string
+ */
+ public function set_dbprefix($prefix = '')
+ {
+ return $this->dbprefix = $prefix;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Track Aliases
*
* Used to track SQL statements written with aliased tables.
*
- * @access private
* @param string The table to inspect
* @return string
*/
- function _track_aliases($table)
+ protected function _track_aliases($table)
{
if (is_array($table))
{
@@ -1685,10 +1664,9 @@ class CI_DB_active_record extends CI_DB_driver {
* Generates a query string based on which functions were used.
* Should not be called directly. The get() function calls it.
*
- * @access private
* @return string
*/
- function _compile_select($select_override = FALSE)
+ protected function _compile_select($select_override = FALSE)
{
// Combine any cached components with the current statements
$this->_merge_cache();
@@ -1716,7 +1694,8 @@ class CI_DB_active_record extends CI_DB_driver {
// is because until the user calls the from() function we don't know if there are aliases
foreach ($this->ar_select as $key => $val)
{
- $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]);
+ $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL;
+ $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
}
$sql .= implode(', ', $this->ar_select);
@@ -1826,11 +1805,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Takes an object as input and converts the class variables to array key/vals
*
- * @access public
* @param object
* @return array
*/
- function _object_to_array($object)
+ public function _object_to_array($object)
{
if ( ! is_object($object))
{
@@ -1857,11 +1835,10 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Takes an object as input and converts the class variables to array key/vals
*
- * @access public
* @param object
* @return array
*/
- function _object_to_array_batch($object)
+ public function _object_to_array_batch($object)
{
if ( ! is_object($object))
{
@@ -1897,10 +1874,9 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Starts AR caching
*
- * @access public
* @return void
*/
- function start_cache()
+ public function start_cache()
{
$this->ar_caching = TRUE;
}
@@ -1912,10 +1888,9 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Stops AR caching
*
- * @access public
* @return void
*/
- function stop_cache()
+ public function stop_cache()
{
$this->ar_caching = FALSE;
}
@@ -1930,23 +1905,21 @@ class CI_DB_active_record extends CI_DB_driver {
* @access public
* @return void
*/
- function flush_cache()
+ public function flush_cache()
{
- $this->_reset_run(
- array(
- 'ar_cache_select' => array(),
- 'ar_cache_from' => array(),
- 'ar_cache_join' => array(),
- 'ar_cache_where' => array(),
- 'ar_cache_like' => array(),
- 'ar_cache_groupby' => array(),
- 'ar_cache_having' => array(),
- 'ar_cache_orderby' => array(),
- 'ar_cache_set' => array(),
- 'ar_cache_exists' => array(),
- 'ar_cache_no_escape' => array()
- )
- );
+ $this->_reset_run(array(
+ 'ar_cache_select' => array(),
+ 'ar_cache_from' => array(),
+ 'ar_cache_join' => array(),
+ 'ar_cache_where' => array(),
+ 'ar_cache_like' => array(),
+ 'ar_cache_groupby' => array(),
+ 'ar_cache_having' => array(),
+ 'ar_cache_orderby' => array(),
+ 'ar_cache_set' => array(),
+ 'ar_cache_exists' => array(),
+ 'ar_cache_no_escape' => array()
+ ));
}
// --------------------------------------------------------------------
@@ -1957,10 +1930,9 @@ class CI_DB_active_record extends CI_DB_driver {
* When called, this function merges any cached AR arrays with
* locally called ones.
*
- * @access private
* @return void
*/
- function _merge_cache()
+ protected function _merge_cache()
{
if (count($this->ar_cache_exists) == 0)
{
@@ -1995,11 +1967,10 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Resets the active record values. Called by the get() function
*
- * @access private
* @param array An array of fields to reset
* @return void
*/
- function _reset_run($ar_reset_items)
+ protected function _reset_run($ar_reset_items)
{
foreach ($ar_reset_items as $item => $default_value)
{
@@ -2015,28 +1986,27 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Resets the active record values. Called by the get() function
*
- * @access private
* @return void
*/
- function _reset_select()
+ protected function _reset_select()
{
$ar_reset_items = array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE,
- );
+ 'ar_select' => array(),
+ 'ar_from' => array(),
+ 'ar_join' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_groupby' => array(),
+ 'ar_having' => array(),
+ 'ar_orderby' => array(),
+ 'ar_wherein' => array(),
+ 'ar_aliased_tables' => array(),
+ 'ar_no_escape' => array(),
+ 'ar_distinct' => FALSE,
+ 'ar_limit' => FALSE,
+ 'ar_offset' => FALSE,
+ 'ar_order' => FALSE,
+ );
$this->_reset_run($ar_reset_items);
}
@@ -2048,25 +2018,23 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Called by the insert() update() insert_batch() update_batch() and delete() functions
*
- * @access private
* @return void
*/
- function _reset_write()
+ protected function _reset_write()
{
$ar_reset_items = array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- );
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ );
$this->_reset_run($ar_reset_items);
}
-
}
/* End of file DB_active_rec.php */
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index b7d547cc0..28c75a5e3 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -54,6 +54,9 @@ class CI_DB_mysql_driver extends CI_DB {
var $_count_string = 'SELECT COUNT(*) AS ';
var $_random_keyword = ' RAND()'; // database specific random keyword
+ // whether SET NAMES must be used to set the character set
+ var $use_set_names;
+
/**
* Non-persistent database connection
*
@@ -132,15 +135,13 @@ class CI_DB_mysql_driver extends CI_DB {
*/
function db_set_charset($charset, $collation)
{
- static $use_set_names;
-
- if ( ! isset($use_set_names))
+ if ( ! isset($this->use_set_names))
{
// mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback
- $use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
+ $this->use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
}
- if ($use_set_names)
+ if ($this->use_set_names === TRUE)
{
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 529ec980d..c1cae136c 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -119,9 +119,13 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
- if (array_key_exists('NULL', $attributes))
+ if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{
- $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';
+ $sql .= ' NULL';
+ }
+ else
+ {
+ $sql .= ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index b8586c21d..b1796c9df 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -54,6 +54,9 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
var $delete_hack = TRUE;
+ // whether SET NAMES must be used to set the character set
+ var $use_set_names;
+
// --------------------------------------------------------------------
/**
@@ -132,15 +135,13 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
function _db_set_charset($charset, $collation)
{
- static $use_set_names;
-
- if ( ! isset($use_set_names))
+ if ( ! isset($this->use_set_names))
{
// mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback
- $use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE;
+ $this->use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE;
}
- if ($use_set_names)
+ if ($this->use_set_names === TRUE)
{
return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'");
}
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index d5097335e..260549457 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -104,9 +104,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
- if (array_key_exists('NULL', $attributes))
+ if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{
- $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';
+ $sql .= ' NULL';
+ }
+ else
+ {
+ $sql .= ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index 2925d3c7c..5720a06ec 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -64,8 +64,8 @@ if ( ! function_exists('form_open'))
$form .= '>';
- // CSRF
- if ($CI->config->item('csrf_protection') === TRUE)
+ // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
+ if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"')))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 080f622dd..b64b60650 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -124,6 +124,10 @@ if ( ! function_exists('_list'))
}
$attributes = $atts;
}
+ elseif (is_string($attributes) AND strlen($attributes) > 0)
+ {
+ $attributes = ' '. $attributes;
+ }
// Write the opening list tag
$out .= "<".$type.$attributes.">\n";
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 3f2409007..3418f29ab 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -17,6 +17,7 @@ $lang['is_numeric'] = "The %s field must contain only numeric characters.";
$lang['integer'] = "The %s field must contain an integer.";
$lang['regex_match'] = "The %s field is not in the correct format.";
$lang['matches'] = "The %s field does not match the %s field.";
+$lang['is_unique'] = "The %s field must contain a unique value.";
$lang['is_natural'] = "The %s field must contain only positive numbers.";
$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
$lang['decimal'] = "The %s field must contain a decimal number.";
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
new file mode 100644
index 000000000..4763ca243
--- /dev/null
+++ b/system/language/english/migration_lang.php
@@ -0,0 +1,13 @@
+<?php
+
+$lang['migration_none_found'] = "No migrations were found.";
+$lang['migration_not_found'] = "This migration could not be found.";
+$lang['migration_multiple_version'] = "This are multiple migrations with the same version number: %d.";
+$lang['migration_class_doesnt_exist'] = "The migration class \"%s\" could not be found.";
+$lang['migration_missing_up_method'] = "The migration class \"%s\" is missing an 'up' method.";
+$lang['migration_missing_down_method'] = "The migration class \"%s\" is missing an 'up' method.";
+$lang['migration_invalid_filename'] = "Migration \"%s\" has an invalid filename.";
+
+
+/* End of file migration_lang.php */
+/* Location: ./system/language/english/migration_lang.php */ \ No newline at end of file
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index 7f65b48b9..ab5a70c98 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -99,7 +99,7 @@ class CI_Cart {
$save_cart = FALSE;
if (isset($items['id']))
{
- if ($this->_insert($items) == TRUE)
+ if (($rowid = $this->_insert($items)))
{
$save_cart = TRUE;
}
@@ -110,7 +110,7 @@ class CI_Cart {
{
if (is_array($val) AND isset($val['id']))
{
- if ($this->_insert($val) == TRUE)
+ if ($this->_insert($val))
{
$save_cart = TRUE;
}
@@ -122,7 +122,7 @@ class CI_Cart {
if ($save_cart == TRUE)
{
$this->_save_cart();
- return TRUE;
+ return isset($rowid) ? $rowid : TRUE;
}
return FALSE;
@@ -244,7 +244,7 @@ class CI_Cart {
}
// Woot!
- return TRUE;
+ return $rowid;
}
// --------------------------------------------------------------------
@@ -374,6 +374,7 @@ class CI_Cart {
// Lets add up the individual prices and set the cart sub-total
$total = 0;
+ $items = 0;
foreach ($this->_cart_contents as $key => $val)
{
// We make sure the array contains the proper indexes
@@ -383,13 +384,14 @@ class CI_Cart {
}
$total += ($val['price'] * $val['qty']);
+ $items += $val['qty'];
// Set the subtotal
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
}
// Set the cart total and total items.
- $this->_cart_contents['total_items'] = count($this->_cart_contents);
+ $this->_cart_contents['total_items'] = $items;
$this->_cart_contents['cart_total'] = $total;
// Is our cart empty? If so we delete it from the session
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index cd89f8f3d..fb9a75049 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -395,7 +395,7 @@ class CI_Email {
public function attach($filename, $disposition = 'attachment')
{
$this->_attach_name[] = $filename;
- $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename))));
+ $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
$this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters
return $this;
}
@@ -405,12 +405,12 @@ class CI_Email {
/**
* Add a Header Item
*
- * @access private
+ * @access protected
* @param string
* @param string
* @return void
*/
- private function _set_header($header, $value)
+ protected function _set_header($header, $value)
{
$this->_headers[$header] = $value;
}
@@ -420,11 +420,11 @@ class CI_Email {
/**
* Convert a String to an Array
*
- * @access private
+ * @access protected
* @param string
* @return array
*/
- private function _str_to_array($email)
+ protected function _str_to_array($email)
{
if ( ! is_array($email))
{
@@ -577,10 +577,10 @@ class CI_Email {
/**
* Set Message Boundary
*
- * @access private
+ * @access protected
* @return void
*/
- private function _set_boundaries()
+ protected function _set_boundaries()
{
$this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
$this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
@@ -591,10 +591,10 @@ class CI_Email {
/**
* Get the Message ID
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_message_id()
+ protected function _get_message_id()
{
$from = $this->_headers['Return-Path'];
$from = str_replace(">", "", $from);
@@ -608,11 +608,11 @@ class CI_Email {
/**
* Get Mail Protocol
*
- * @access private
+ * @access protected
* @param bool
* @return string
*/
- private function _get_protocol($return = TRUE)
+ protected function _get_protocol($return = TRUE)
{
$this->protocol = strtolower($this->protocol);
$this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
@@ -628,11 +628,11 @@ class CI_Email {
/**
* Get Mail Encoding
*
- * @access private
+ * @access protected
* @param bool
* @return string
*/
- private function _get_encoding($return = TRUE)
+ protected function _get_encoding($return = TRUE)
{
$this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
@@ -655,10 +655,10 @@ class CI_Email {
/**
* Get content type (text/html/attachment)
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_content_type()
+ protected function _get_content_type()
{
if ($this->mailtype == 'html' && count($this->_attach_name) == 0)
{
@@ -683,10 +683,10 @@ class CI_Email {
/**
* Set RFC 822 Date
*
- * @access private
+ * @access protected
* @return string
*/
- private function _set_date()
+ protected function _set_date()
{
$timezone = date("Z");
$operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+';
@@ -701,10 +701,10 @@ class CI_Email {
/**
* Mime message
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_mime_message()
+ protected function _get_mime_message()
{
return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
}
@@ -802,10 +802,10 @@ class CI_Email {
* If the user hasn't specified his own alternative message
* it creates one by stripping the HTML
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_alt_message()
+ protected function _get_alt_message()
{
if ($this->alt_message != "")
{
@@ -941,11 +941,11 @@ class CI_Email {
/**
* Build final headers
*
- * @access private
+ * @access protected
* @param string
* @return string
*/
- private function _build_headers()
+ protected function _build_headers()
{
$this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
$this->_set_header('X-Mailer', $this->useragent);
@@ -959,10 +959,10 @@ class CI_Email {
/**
* Write Headers as a string
*
- * @access private
+ * @access protected
* @return void
*/
- private function _write_headers()
+ protected function _write_headers()
{
if ($this->protocol == 'mail')
{
@@ -994,10 +994,10 @@ class CI_Email {
/**
* Build Final Body and attachments
*
- * @access private
+ * @access protected
* @return void
*/
- private function _build_message()
+ protected function _build_message()
{
if ($this->wordwrap === TRUE AND $this->mailtype != 'html')
{
@@ -1177,12 +1177,12 @@ class CI_Email {
* Prepares string for Quoted-Printable Content-Transfer-Encoding
* Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
*
- * @access private
+ * @access protected
* @param string
* @param integer
* @return string
*/
- private function _prep_quoted_printable($str, $charlim = '')
+ protected function _prep_quoted_printable($str, $charlim = '')
{
// Set the character limit
// Don't allow over 76, as that will make servers and MUAs barf
@@ -1275,7 +1275,7 @@ class CI_Email {
* @param bool // set to TRUE for processing From: headers
* @return str
*/
- private function _prep_q_encoding($str, $from = FALSE)
+ protected function _prep_q_encoding($str, $from = FALSE)
{
$str = str_replace(array("\r", "\n"), array('', ''), $str);
@@ -1440,10 +1440,10 @@ class CI_Email {
/**
* Unwrap special elements
*
- * @access private
+ * @access protected
* @return void
*/
- private function _unwrap_specials()
+ protected function _unwrap_specials()
{
$this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
}
@@ -1453,10 +1453,10 @@ class CI_Email {
/**
* Strip line-breaks via callback
*
- * @access private
+ * @access protected
* @return string
*/
- private function _remove_nl_callback($matches)
+ protected function _remove_nl_callback($matches)
{
if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
{
@@ -1471,10 +1471,10 @@ class CI_Email {
/**
* Spool mail to the mail server
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _spool_email()
+ protected function _spool_email()
{
$this->_unwrap_specials();
@@ -1516,10 +1516,10 @@ class CI_Email {
/**
* Send using mail()
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _send_with_mail()
+ protected function _send_with_mail()
{
if ($this->_safe_mode == TRUE)
{
@@ -1553,10 +1553,10 @@ class CI_Email {
/**
* Send using Sendmail
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _send_with_sendmail()
+ protected function _send_with_sendmail()
{
$fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
@@ -1591,10 +1591,10 @@ class CI_Email {
/**
* Send using SMTP
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _send_with_smtp()
+ protected function _send_with_smtp()
{
if ($this->smtp_host == '')
{
@@ -1660,11 +1660,11 @@ class CI_Email {
/**
* SMTP Connect
*
- * @access private
+ * @access protected
* @param string
* @return string
*/
- private function _smtp_connect()
+ protected function _smtp_connect()
{
$this->_smtp_connect = fsockopen($this->smtp_host,
$this->smtp_port,
@@ -1687,12 +1687,12 @@ class CI_Email {
/**
* Send SMTP command
*
- * @access private
+ * @access protected
* @param string
* @param string
* @return string
*/
- private function _send_command($cmd, $data = '')
+ protected function _send_command($cmd, $data = '')
{
switch ($cmd)
{
@@ -1754,10 +1754,10 @@ class CI_Email {
/**
* SMTP Authenticate
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _smtp_authenticate()
+ protected function _smtp_authenticate()
{
if ( ! $this->_smtp_auth)
{
@@ -1808,10 +1808,10 @@ class CI_Email {
/**
* Send SMTP data
*
- * @access private
+ * @access protected
* @return bool
*/
- private function _send_data($data)
+ protected function _send_data($data)
{
if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
{
@@ -1829,10 +1829,10 @@ class CI_Email {
/**
* Get SMTP data
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_smtp_data()
+ protected function _get_smtp_data()
{
$data = "";
@@ -1854,10 +1854,10 @@ class CI_Email {
/**
* Get Hostname
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_hostname()
+ protected function _get_hostname()
{
return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
}
@@ -1867,10 +1867,10 @@ class CI_Email {
/**
* Get IP
*
- * @access private
+ * @access protected
* @return string
*/
- private function _get_ip()
+ protected function _get_ip()
{
if ($this->_IP !== FALSE)
{
@@ -1933,11 +1933,11 @@ class CI_Email {
/**
* Set Message
*
- * @access private
+ * @access protected
* @param string
* @return string
*/
- private function _set_error_message($msg, $val = '')
+ protected function _set_error_message($msg, $val = '')
{
$CI =& get_instance();
$CI->lang->load('email');
@@ -1957,11 +1957,11 @@ class CI_Email {
/**
* Mime Types
*
- * @access private
+ * @access protected
* @param string
* @return string
*/
- private function _mime_types($ext = "")
+ protected 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 6f79a554a..a34809e05 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -26,16 +26,15 @@
*/
class CI_Form_validation {
- var $CI;
- var $_field_data = array();
- var $_config_rules = array();
- var $_error_array = array();
- var $_error_messages = array();
- var $_error_prefix = '<p>';
- var $_error_suffix = '</p>';
- var $error_string = '';
- var $_safe_form_data = FALSE;
-
+ protected $CI;
+ protected $_field_data = array();
+ protected $_config_rules = array();
+ protected $_error_array = array();
+ protected $_error_messages = array();
+ protected $_error_prefix = '<p>';
+ protected $_error_suffix = '</p>';
+ protected $error_string = '';
+ protected $_safe_form_data = FALSE;
/**
* Constructor
@@ -72,7 +71,7 @@ class CI_Form_validation {
* @param string
* @return void
*/
- function set_rules($field, $label = '', $rules = '')
+ public function set_rules($field, $label = '', $rules = '')
{
// No reason to set rules if we have no POST data
if (count($_POST) == 0)
@@ -163,7 +162,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function set_message($lang, $val = '')
+ public function set_message($lang, $val = '')
{
if ( ! is_array($lang))
{
@@ -187,7 +186,7 @@ class CI_Form_validation {
* @param string
* @return void
*/
- function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
+ public function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
{
$this->_error_prefix = $prefix;
$this->_error_suffix = $suffix;
@@ -206,7 +205,7 @@ class CI_Form_validation {
* @param string the field name
* @return void
*/
- function error($field = '', $prefix = '', $suffix = '')
+ public function error($field = '', $prefix = '', $suffix = '')
{
if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '')
{
@@ -238,7 +237,7 @@ class CI_Form_validation {
* @param string
* @return str
*/
- function error_string($prefix = '', $suffix = '')
+ public function error_string($prefix = '', $suffix = '')
{
// No errrors, validation passes!
if (count($this->_error_array) === 0)
@@ -279,7 +278,7 @@ class CI_Form_validation {
* @access public
* @return bool
*/
- function run($group = '')
+ public function run($group = '')
{
// Do we even have any data to process? Mm?
if (count($_POST) == 0)
@@ -374,7 +373,7 @@ class CI_Form_validation {
* @param integer
* @return mixed
*/
- function _reduce_array($array, $keys, $i = 0)
+ protected function _reduce_array($array, $keys, $i = 0)
{
if (is_array($array))
{
@@ -406,7 +405,7 @@ class CI_Form_validation {
* @access private
* @return null
*/
- function _reset_post_array()
+ protected function _reset_post_array()
{
foreach ($this->_field_data as $field => $row)
{
@@ -468,7 +467,7 @@ class CI_Form_validation {
* @param integer
* @return mixed
*/
- function _execute($row, $rules, $postdata = NULL, $cycles = 0)
+ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
// If the $_POST data is an array we will run a recursive call
if (is_array($postdata))
@@ -489,7 +488,7 @@ class CI_Form_validation {
if ( ! in_array('required', $rules) AND is_null($postdata))
{
// Before we bail out, does the rule contain a callback?
- if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
+ if (preg_match("/(callback_\w+(\[.*?\])?)/", implode(' ', $rules), $match))
{
$callback = TRUE;
$rules = (array('1' => $match[1]));
@@ -695,7 +694,7 @@ class CI_Form_validation {
* @param string the field name
* @return string
*/
- function _translate_fieldname($fieldname)
+ protected function _translate_fieldname($fieldname)
{
// Do we need to translate the field name?
// We look for the prefix lang: to determine this
@@ -727,7 +726,7 @@ class CI_Form_validation {
* @param string
* @return void
*/
- function set_value($field = '', $default = '')
+ public function set_value($field = '', $default = '')
{
if ( ! isset($this->_field_data[$field]))
{
@@ -757,7 +756,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function set_select($field = '', $value = '', $default = FALSE)
+ public function set_select($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
@@ -801,7 +800,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function set_radio($field = '', $value = '', $default = FALSE)
+ public function set_radio($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
@@ -845,7 +844,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function set_checkbox($field = '', $value = '', $default = FALSE)
+ public function set_checkbox($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
@@ -885,7 +884,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function required($str)
+ public function required($str)
{
if ( ! is_array($str))
{
@@ -907,7 +906,7 @@ class CI_Form_validation {
* @param regex
* @return bool
*/
- function regex_match($str, $regex)
+ public function regex_match($str, $regex)
{
if ( ! preg_match($regex, $str))
{
@@ -927,7 +926,7 @@ class CI_Form_validation {
* @param field
* @return bool
*/
- function matches($str, $field)
+ public function matches($str, $field)
{
if ( ! isset($_POST[$field]))
{
@@ -938,6 +937,24 @@ class CI_Form_validation {
return ($str !== $field) ? FALSE : TRUE;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Match one field to another
+ *
+ * @access public
+ * @param string
+ * @param field
+ * @return bool
+ */
+ public function is_unique($str, $field)
+ {
+ list($table, $field)=explode('.', $field);
+ $query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
+
+ return $query->num_rows() === 0;
+ }
// --------------------------------------------------------------------
@@ -949,7 +966,7 @@ class CI_Form_validation {
* @param value
* @return bool
*/
- function min_length($str, $val)
+ public function min_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
@@ -974,7 +991,7 @@ class CI_Form_validation {
* @param value
* @return bool
*/
- function max_length($str, $val)
+ public function max_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
@@ -999,7 +1016,7 @@ class CI_Form_validation {
* @param value
* @return bool
*/
- function exact_length($str, $val)
+ public function exact_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
@@ -1023,7 +1040,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function valid_email($str)
+ public function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
@@ -1037,7 +1054,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function valid_emails($str)
+ public function valid_emails($str)
{
if (strpos($str, ',') === FALSE)
{
@@ -1064,7 +1081,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function valid_ip($ip)
+ public function valid_ip($ip)
{
return $this->CI->input->valid_ip($ip);
}
@@ -1078,7 +1095,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function alpha($str)
+ public function alpha($str)
{
return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
}
@@ -1092,7 +1109,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function alpha_numeric($str)
+ public function alpha_numeric($str)
{
return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;
}
@@ -1106,7 +1123,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function alpha_dash($str)
+ public function alpha_dash($str)
{
return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
}
@@ -1120,7 +1137,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function numeric($str)
+ public function numeric($str)
{
return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
@@ -1135,7 +1152,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function is_numeric($str)
+ public function is_numeric($str)
{
return ( ! is_numeric($str)) ? FALSE : TRUE;
}
@@ -1149,7 +1166,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function integer($str)
+ public function integer($str)
{
return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
}
@@ -1163,7 +1180,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function decimal($str)
+ public function decimal($str)
{
return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str);
}
@@ -1177,7 +1194,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function greater_than($str, $min)
+ public function greater_than($str, $min)
{
if ( ! is_numeric($str))
{
@@ -1195,7 +1212,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function less_than($str, $max)
+ public function less_than($str, $max)
{
if ( ! is_numeric($str))
{
@@ -1213,7 +1230,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function is_natural($str)
+ public function is_natural($str)
{
return (bool) preg_match( '/^[0-9]+$/', $str);
}
@@ -1227,7 +1244,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function is_natural_no_zero($str)
+ public function is_natural_no_zero($str)
{
if ( ! preg_match( '/^[0-9]+$/', $str))
{
@@ -1254,7 +1271,7 @@ class CI_Form_validation {
* @param string
* @return bool
*/
- function valid_base64($str)
+ public function valid_base64($str)
{
return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
}
@@ -1271,7 +1288,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function prep_for_form($data = '')
+ public function prep_for_form($data = '')
{
if (is_array($data))
{
@@ -1300,7 +1317,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function prep_url($str = '')
+ public function prep_url($str = '')
{
if ($str == 'http://' OR $str == '')
{
@@ -1324,7 +1341,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function strip_image_tags($str)
+ public function strip_image_tags($str)
{
return $this->CI->input->strip_image_tags($str);
}
@@ -1338,7 +1355,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function xss_clean($str)
+ public function xss_clean($str)
{
return $this->CI->security->xss_clean($str);
}
@@ -1352,7 +1369,7 @@ class CI_Form_validation {
* @param string
* @return string
*/
- function encode_php_tags($str)
+ public function encode_php_tags($str)
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
}
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
new file mode 100644
index 000000000..3943ec130
--- /dev/null
+++ b/system/libraries/Migration.php
@@ -0,0 +1,338 @@
+<?php defined('BASEPATH') OR exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Migration Class
+ *
+ * All migrations should implement this, forces up() and down() and gives
+ * access to the CI super-global.
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Libraries
+ * @author Reactor Engineers
+ * @link
+ */
+class CI_Migration {
+
+ protected $_migration_enabled = FALSE;
+ protected $_migration_path = NULL;
+ protected $_migration_version = 0;
+
+ protected $_error_string = '';
+
+ public function __construct($config = array())
+ {
+ # Only run this constructor on main library load
+ if (get_parent_class($this) !== FALSE)
+ {
+ return;
+ }
+
+ foreach ($config as $key => $val)
+ {
+ $this->{'_' . $key} = $val;
+ }
+
+ log_message('debug', 'Migrations class initialized');
+
+ // Are they trying to use migrations while it is disabled?
+ if ($this->_migration_enabled !== TRUE)
+ {
+ show_error('Migrations has been loaded but is disabled or set up incorrectly.');
+ }
+
+ // If not set, set it
+ $this->_migration_path == '' OR $this->_migration_path = APPPATH . 'migrations/';
+
+ // Add trailing slash if not set
+ $this->_migration_path = rtrim($this->_migration_path, '/').'/';
+
+ // Load migration language
+ $this->lang->load('migration');
+
+ // They'll probably be using dbforge
+ $this->load->dbforge();
+
+ // If the migrations table is missing, make it
+ if ( ! $this->db->table_exists('migrations'))
+ {
+ $this->dbforge->add_field(array(
+ 'version' => array('type' => 'INT', 'constraint' => 3),
+ ));
+
+ $this->dbforge->create_table('migrations', TRUE);
+
+ $this->db->insert('migrations', array('version' => 0));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Migrate to a schema version
+ *
+ * Calls each migration step required to get to the schema version of
+ * choice
+ *
+ * @access public
+ * @param $version integer Target schema version
+ * @return mixed TRUE if already latest, FALSE if failed, int if upgraded
+ */
+ public function version($target_version)
+ {
+ $start = $current_version = $this->_get_version();
+ $stop = $target_version;
+
+ if ($target_version > $current_version)
+ {
+ // Moving Up
+ ++$start;
+ ++$stop;
+ $step = 1;
+ }
+
+ else
+ {
+ // Moving Down
+ $step = -1;
+ }
+
+ $method = $step === 1 ? 'up' : 'down';
+ $migrations = array();
+
+ // We now prepare to actually DO the migrations
+ // But first let's make sure that everything is the way it should be
+ for ($i = $start; $i != $stop; $i += $step)
+ {
+ $f = glob(sprintf($this->_migration_path . '%03d_*.php', $i));
+
+ // Only one migration per step is permitted
+ if (count($f) > 1)
+ {
+ $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $i);
+ return FALSE;
+ }
+
+ // Migration step not found
+ if (count($f) == 0)
+ {
+ // If trying to migrate up to a version greater than the last
+ // existing one, migrate to the last one.
+ if ($step == 1)
+ {
+ break;
+ }
+
+ // If trying to migrate down but we're missing a step,
+ // something must definitely be wrong.
+ $this->_error_string = sprintf($this->lang->line('migration_not_found'), $i);
+ return FALSE;
+ }
+
+ $file = basename($f[0]);
+ $name = basename($f[0], '.php');
+
+ // Filename validations
+ if (preg_match('/^\d{3}_(\w+)$/', $name, $match))
+ {
+ $match[1] = strtolower($match[1]);
+
+ // Cannot repeat a migration at different steps
+ if (in_array($match[1], $migrations))
+ {
+ $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $match[1]);
+ return FALSE;
+ }
+
+ include $f[0];
+ $class = 'Migration_' . ucfirst($match[1]);
+
+ if ( ! class_exists($class))
+ {
+ $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
+ return FALSE;
+ }
+
+ if ( ! is_callable(array($class, $method)))
+ {
+ $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class);
+ return FALSE;
+ }
+
+ $migrations[] = $match[1];
+ }
+ else
+ {
+ $this->_error_string = sprintf($this->lang->line('migration_invalid_filename'), $file);
+ return FALSE;
+ }
+ }
+
+ log_message('debug', 'Current migration: ' . $current_version);
+
+ $version = $i + ($step == 1 ? -1 : 0);
+
+ // If there is nothing to do so quit
+ if ($migrations === array())
+ {
+ return TRUE;
+ }
+
+ log_message('debug', 'Migrating from ' . $method . ' to version ' . $version);
+
+ // Loop through the migrations
+ foreach ($migrations AS $migration)
+ {
+ // Run the migration class
+ $class = 'Migration_' . ucfirst(strtolower($migration));
+ call_user_func(array(new $class, $method));
+
+ $current_version += $step;
+ $this->_update_version($current_version);
+ }
+
+ log_message('debug', 'Finished migrating to '.$current_version);
+
+ return $current_version;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set's the schema to the latest migration
+ *
+ * @access public
+ * @return mixed true if already latest, false if failed, int if upgraded
+ */
+ public function latest()
+ {
+ if ( ! $migrations = $this->find_migrations())
+ {
+ $this->_error_string = $this->line->lang('migration_none_found');
+ return false;
+ }
+
+ $last_migration = basename(end($migrations));
+
+ // Calculate the last migration step from existing migration
+ // filenames and procceed to the standard version migration
+ return $this->version((int) substr($last_migration, 0, 3));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set's the schema to the migration version set in config
+ *
+ * @access public
+ * @return mixed true if already current, false if failed, int if upgraded
+ */
+ public function current()
+ {
+ return $this->version($this->_migration_version);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Error string
+ *
+ * @access public
+ * @return string Error message returned as a string
+ */
+ public function error_string()
+ {
+ return $this->_error_string;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set's the schema to the latest migration
+ *
+ * @access protected
+ * @return mixed true if already latest, false if failed, int if upgraded
+ */
+ protected function find_migrations()
+ {
+ // Load all *_*.php files in the migrations path
+ $files = glob($this->_migration_path . '*_*.php');
+ $file_count = count($files);
+
+ for ($i = 0; $i < $file_count; $i++)
+ {
+ // Mark wrongly formatted files as false for later filtering
+ $name = basename($files[$i], '.php');
+ if ( ! preg_match('/^\d{3}_(\w+)$/', $name))
+ {
+ $files[$i] = FALSE;
+ }
+ }
+
+ sort($files);
+
+ return $files;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Retrieves current schema version
+ *
+ * @access protected
+ * @return integer Current Migration
+ */
+ protected function _get_version()
+ {
+ $row = $this->db->get('migrations')->row();
+ return $row ? $row->version : 0;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Stores the current schema version
+ *
+ * @access protected
+ * @param $migrations integer Migration reached
+ * @return void Outputs a report of the migration
+ */
+ protected function _update_version($migrations)
+ {
+ return $this->db->update('migrations', array(
+ 'version' => $migrations
+ ));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Enable the use of CI super-global
+ *
+ * @access public
+ * @param $var
+ * @return mixed
+ */
+ public function __get($var)
+ {
+ return get_instance()->$var;
+ }
+}
+
+/* End of file Migration.php */
+/* Location: ./system/libraries/Migration.php */ \ No newline at end of file
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 016102a2a..0b77a7d42 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -142,7 +142,7 @@ class CI_User_agent {
{
$this->_set_platform();
- foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function)
+ foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
{
if ($this->$function() === TRUE)
{