diff options
Diffstat (limited to 'system/libraries')
-rw-r--r-- | system/libraries/Cache/drivers/Cache_file.php | 7 | ||||
-rw-r--r-- | system/libraries/Cache/drivers/Cache_memcached.php | 83 | ||||
-rw-r--r-- | system/libraries/Cart.php | 8 | ||||
-rw-r--r-- | system/libraries/Driver.php | 4 | ||||
-rw-r--r-- | system/libraries/Email.php | 124 | ||||
-rw-r--r-- | system/libraries/Form_validation.php | 119 | ||||
-rw-r--r-- | system/libraries/Image_lib.php | 2 | ||||
-rw-r--r-- | system/libraries/Log.php | 21 | ||||
-rw-r--r-- | system/libraries/Migration.php | 338 | ||||
-rw-r--r-- | system/libraries/Profiler.php | 4 | ||||
-rw-r--r-- | system/libraries/Upload.php | 54 | ||||
-rw-r--r-- | system/libraries/User_agent.php | 2 |
12 files changed, 581 insertions, 185 deletions
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 13e2d1af6..6c37e7005 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -157,17 +157,16 @@ class CI_Cache_file extends CI_Driver { if (is_array($data)) { - $data = $data['data']; $mtime = filemtime($this->_cache_path.$id); - if ( ! isset($data['ttl'])) + if ( ! isset($data['data']['ttl'])) { return FALSE; } return array( - 'expire' => $mtime + $data['ttl'], - 'mtime' => $mtime + 'expire' => $mtime + $data['data']['ttl'], + 'mtime' => $mtime ); } diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index ec2fd216a..04aa81a5a 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -10,19 +10,19 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter Memcached Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_memcached extends CI_Driver { @@ -37,18 +37,18 @@ class CI_Cache_memcached extends CI_Driver { ) ); - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ /** * 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; } @@ -64,11 +64,11 @@ class CI_Cache_memcached extends CI_Driver { */ public function save($id, $data, $ttl = 60) { - return $this->_memcached->add($id, array($data, time(), $ttl), $ttl); + return $this->_memcached->set($id, array($data, time(), $ttl), $ttl); } // ------------------------------------------------------------------------ - + /** * Delete from Cache * @@ -81,7 +81,7 @@ class CI_Cache_memcached extends CI_Driver { } // ------------------------------------------------------------------------ - + /** * Clean the Cache * @@ -106,7 +106,7 @@ class CI_Cache_memcached extends CI_Driver { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -140,6 +140,7 @@ class CI_Cache_memcached extends CI_Driver { { // 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'])) @@ -149,11 +150,24 @@ class CI_Cache_memcached extends CI_Driver { foreach ($CI->config->config['memcached'] as $name => $conf) { $this->_memcache_conf[$name] = $conf; - } - } + } + } + } + + if (class_exists('Memcached')) + { + $this->_memcached = new Memcached(); + } + else if (class_exists('Memcache')) + { + $this->_memcached = new Memcache(); + } + else + { + log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?'); + + return FALSE; } - - $this->_memcached = new Memcached(); foreach ($this->_memcache_conf as $name => $cache_server) { @@ -161,26 +175,42 @@ class CI_Cache_memcached extends CI_Driver { { $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'] - ); + + if (get_class($this->_memcached) == 'Memcache') + { + // Third parameter is persistance and defaults to TRUE. + $this->_memcached->addServer( + $cache_server['hostname'], + $cache_server['port'], + TRUE, + $cache_server['weight'] + ); + } + else + { + $this->_memcached->addServer( + $cache_server['hostname'], + $cache_server['port'], + $cache_server['weight'] + ); + } } + + return TRUE; } // ------------------------------------------------------------------------ - /** * Is supported * @@ -189,15 +219,14 @@ class CI_Cache_memcached extends CI_Driver { */ public function is_supported() { - if ( ! extension_loaded('memcached')) + if ( ! extension_loaded('memcached') && ! extension_loaded('memcache')) { log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.'); - + return FALSE; } - - $this->_setup_memcached(); - return TRUE; + + return $this->_setup_memcached(); } // ------------------------------------------------------------------------ diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b2eaa9ad7..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; } // -------------------------------------------------------------------- diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index c32f2c1eb..9881c1eec 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -54,7 +54,7 @@ class CI_Driver_Library { if ( ! class_exists($child_class)) { // check application path first - foreach (array(APPPATH, BASEPATH) as $path) + foreach (get_instance()->load->get_package_paths(TRUE) as $path) { // loves me some nesting! foreach (array(ucfirst($driver_name), $driver_name) as $class) @@ -226,4 +226,4 @@ class CI_Driver { // END CI_Driver CLASS /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ +/* Location: ./system/libraries/Driver.php */
\ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 03eccea09..28a3d17b4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -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)) { @@ -452,7 +452,7 @@ class CI_Email { */ public function set_alt_message($str = '') { - $this->alt_message = ($str == '') ? '' : $str; + $this->alt_message = (string) $str; return $this; } @@ -477,12 +477,12 @@ class CI_Email { * Set Wordwrap * * @access public - * @param string + * @param bool * @return void */ public function set_wordwrap($wordwrap = TRUE) { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; + $this->wordwrap = (bool) $wordwrap; return $this; } @@ -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('<?php', '<?PHP', '<?', '?>'), $str); } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8902f524d..a8a0387d8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1334,7 +1334,7 @@ class CI_Image_lib { return FALSE; } - $vals = @getimagesize($path); + $vals = getimagesize($path); $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 9f1db76ba..bf10d4727 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -27,10 +27,12 @@ class CI_Log { protected $_log_path; - protected $_threshold = 1; - protected $_date_fmt = 'Y-m-d H:i:s'; - protected $_enabled = TRUE; - protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_threshold = 1; + protected $_threshold_max = 0; + protected $_threshold_array = array(); + protected $_date_fmt = 'Y-m-d H:i:s'; + protected $_enabled = TRUE; + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -50,6 +52,11 @@ class CI_Log { { $this->_threshold = $config['log_threshold']; } + elseif (is_array($config['log_threshold'])) + { + $this->_threshold = $this->_threshold_max; + $this->_threshold_array = array_flip($config['log_threshold']); + } if ($config['log_date_format'] != '') { @@ -80,9 +87,13 @@ class CI_Log { if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { - return FALSE; + if (empty($this->_threshold_array) OR ! isset($this->_threshold_array[$this->_levels[$level]])) + { + return FALSE; + } } + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; 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/Profiler.php b/system/libraries/Profiler.php index 082a5ee1d..330acce73 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -493,7 +493,7 @@ class CI_Profiler { * * @return string */ - private function _compile_session_data() + protected function _compile_session_data() { if ( ! isset($this->CI->session)) { @@ -555,4 +555,4 @@ class CI_Profiler { // END CI_Profiler class /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */
\ No newline at end of file +/* Location: ./system/libraries/Profiler.php */ diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3177424c4..8f324de79 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -30,6 +30,7 @@ class CI_Upload { public $max_width = 0; public $max_height = 0; public $max_filename = 0; + public $max_filename_increment = 100; public $allowed_types = ""; public $file_temp = ""; public $file_name = ""; @@ -80,31 +81,32 @@ class CI_Upload { public function initialize($config = array()) { $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'max_filename' => 0, - 'allowed_types' => "", - 'file_temp' => "", - 'file_name' => "", - 'orig_name' => "", - 'file_type' => "", - 'file_size' => "", - 'file_ext' => "", - 'upload_path' => "", - 'overwrite' => FALSE, - 'encrypt_name' => FALSE, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '', - 'error_msg' => array(), - 'mimes' => array(), - 'remove_spaces' => TRUE, - 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_", - 'client_name' => '' + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'max_filename' => 0, + 'max_filename_increment' => 100, + 'allowed_types' => "", + 'file_temp' => "", + 'file_name' => "", + 'orig_name' => "", + 'file_type' => "", + 'file_size' => "", + 'file_ext' => "", + 'upload_path' => "", + 'overwrite' => FALSE, + 'encrypt_name' => FALSE, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '', + 'error_msg' => array(), + 'mimes' => array(), + 'remove_spaces' => TRUE, + 'xss_clean' => FALSE, + 'temp_prefix' => "temp_file_", + 'client_name' => '' ); @@ -402,7 +404,7 @@ class CI_Upload { $filename = str_replace($this->file_ext, '', $filename); $new_filename = ''; - for ($i = 1; $i < 100; $i++) + for ($i = 1; $i < $this->max_filename_increment; $i++) { if ( ! file_exists($path.$filename.$i.$this->file_ext)) { 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) { |