From 1e74da235f7739e3d9b5e1f84cda6313499cefa1 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 15 Dec 2010 10:45:06 +0000 Subject: Upload library file_name can now be set without an extension, the extension will be taken from the uploaded file instead of the given name. --- system/libraries/Upload.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 4ccbdde90..b0e1f4c6c 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -212,7 +212,18 @@ class CI_Upload { if ($this->_file_name_override != '') { $this->file_name = $this->_prep_filename($this->_file_name_override); - $this->file_ext = $this->get_extension($this->file_name); + + // If no extension was provided in the file_name config item, use the uploaded one + if(strpos($this->_file_name_override, '.') === FALSE) + { + $this->file_name .= $this->file_ext; + } + + // An extension was provided, lets have it! + else + { + $this->file_ext = $this->get_extension($this->_file_name_override); + } if ( ! $this->is_allowed_filetype(TRUE)) { -- cgit v1.2.3-24-g4f1b From 2280e8ea67f94e67f2c803e804fb1b8125b579b0 Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Wed, 15 Dec 2010 10:16:38 -0500 Subject: Added the regex_match Form Validation rule. Had to change how the rules are split so that no regex breaks the rule splitting. --- system/libraries/Form_validation.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index bf3689058..38f50fa41 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -339,7 +339,13 @@ class CI_Form_validation { } } - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + preg_match_all('/([a-zA-Z_-]*(\[.*\])?)\|?/i', $row['rules'], $matches); + + $rules = $matches[1]; + array_pop($rules); + unset($matches); + + $this->_execute($row, $rules, $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -576,7 +582,7 @@ class CI_Form_validation { // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + if (preg_match("/(.*?)\[(.*)\]/", $rule, $match)) { $rule = $match[1]; $param = $match[2]; @@ -888,6 +894,26 @@ class CI_Form_validation { // -------------------------------------------------------------------- + /** + * Performs a Regular Expression match test. + * + * @access public + * @param string + * @param regex + * @return bool + */ + function regex_match($str, $regex) + { + if ( ! preg_match($regex, $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Match one field to another * -- cgit v1.2.3-24-g4f1b From bde25d971bfbf4a54f1d40eedfd3290ebb5f91e5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 21 Dec 2010 09:31:21 -0600 Subject: Initial commit of Caching Driver. --- system/libraries/Cache/Cache.php | 216 +++++++++++++++++++++ system/libraries/Cache/drivers/Cache_apc.php | 151 ++++++++++++++ system/libraries/Cache/drivers/Cache_dummy.php | 129 ++++++++++++ system/libraries/Cache/drivers/Cache_file.php | 196 +++++++++++++++++++ system/libraries/Cache/drivers/Cache_memcached.php | 209 ++++++++++++++++++++ 5 files changed, 901 insertions(+) create mode 100644 system/libraries/Cache/Cache.php create mode 100644 system/libraries/Cache/drivers/Cache_apc.php create mode 100644 system/libraries/Cache/drivers/Cache_dummy.php create mode 100644 system/libraries/Cache/drivers/Cache_file.php create mode 100644 system/libraries/Cache/drivers/Cache_memcached.php (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php new file mode 100644 index 000000000..ea3194237 --- /dev/null +++ b/system/libraries/Cache/Cache.php @@ -0,0 +1,216 @@ +_initialize($config); + } + } + + // ------------------------------------------------------------------------ + + /** + * Get + * + * Look for a value in the cache. If it exists, return the data + * if not, return FALSE + * + * @param string + * @return mixed value that is stored/FALSE on failure + */ + public function get($id) + { + return $this->{$this->_adapter}->get($id); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Save + * + * @param string Unique Key + * @param mixed Data to store + * @param int Length of time (in seconds) to cache the data + * + * @return boolean true on success/false on failure + */ + public function save($id, $data, $ttl = 60) + { + return $this->{$this->_adapter}->save($id, $data, $ttl); + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed unique identifier of the item in the cache + * @return boolean true on success/false on failure + */ + public function delete($id) + { + return $this->{$this->_adapter}->delete($id); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the cache + * + * @return boolean false on failure/true on success + */ + public function clean() + { + return $this->{$this->_adapter}->clean(); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @param string user/filehits + * @return mixed array on success, false on failure + */ + public function cache_info($type = 'user') + { + return $this->{$this->_adapter}->cache_info($type); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed return value from child method + */ + public function get_metadata($id) + { + return $this->{$this->_adapter}->get_metadata($id); + } + + // ------------------------------------------------------------------------ + + /** + * Initialize + * + * Initialize class properties based on the configuration array. + * + * @param array + * @return void + */ + private function _initialize($config) + { + $default_config = array( + 'adapter', + 'memcached' + ); + + foreach ($default_config as $key) + { + if (isset($config[$key])) + { + $param = '_'.$key; + + $this->{$param} = $config[$key]; + } + } + + if (isset($config['backup'])) + { + if (in_array('cache_'.$config['backup'], $this->valid_drivers)) + { + $this->_backup_driver = $config['backup']; + } + } + } + + // ------------------------------------------------------------------------ + + /** + * Is the requested driver supported in this environment? + * + * @param string The driver to test. + * @return array + */ + public function is_supported($driver) + { + static $support = array(); + + if ( ! isset($support[$driver])) + { + $support[$driver] = $this->{$driver}->is_supported(); + } + + return $support[$driver]; + } + + // ------------------------------------------------------------------------ + + /** + * __get() + * + * @param child + * @return object + */ + public function __get($child) + { + $obj = parent::__get($child); + + if ( ! $this->is_supported($child)) + { + $this->_adapter = $this->_backup_driver; + } + + return $obj; + } + + // ------------------------------------------------------------------------ +} +// End Class + +/* End of file Cache.php */ +/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php new file mode 100644 index 000000000..9c716a971 --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -0,0 +1,151 @@ + $time + $ttl, + 'mtime' => $time, + 'data' => $data + ); + } + + // ------------------------------------------------------------------------ + + /** + * is_supported() + * + * Check to see if APC is available on this system, bail if it isn't. + */ + public function is_supported() + { + if ( ! extension_loaded('apc') OR ! function_exists('apc_store')) + { + log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); + return FALSE; + } + + return TRUE; + } + + // ------------------------------------------------------------------------ + + +} +// End Class + +/* End of file Cache_apc.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php new file mode 100644 index 000000000..13c1f5cde --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -0,0 +1,129 @@ +load->helper('file'); + + $path = $CI->config->item('cache_path'); + + $this->_cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + } + + // ------------------------------------------------------------------------ + + /** + * Fetch from cache + * + * @param mixed unique key id + * @return mixed data on success/false on failure + */ + public function get($id) + { + if ( ! file_exists($this->_cache_path.$id)) + { + return FALSE; + } + + $data = read_file($this->_cache_path.$id); + $data = unserialize($data); + + if (time() > $data['time'] + $data['ttl']) + { + unlink($this->_cache_path.$id); + return FALSE; + } + + return $data['data']; + } + + // ------------------------------------------------------------------------ + + /** + * Save into cache + * + * @param string unique key + * @param mixed data to store + * @param int length of time (in seconds) the cache is valid + * - Default is 60 seconds + * @return boolean true on success/false on failure + */ + public function save($id, $data, $ttl = 60) + { + $contents = array( + 'time' => time(), + 'ttl' => $ttl, + 'data' => $data + ); + + if (write_file($this->_cache_path.$id, serialize($contents))) + { + @chmod($this->_cache_path.$id, 0777); + return TRUE; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed unique identifier of item in cache + * @return boolean true on success/false on failure + */ + public function delete($id) + { + return unlink($this->_cache_path.$id); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the Cache + * + * @return boolean false on failure/true on success + */ + public function clean() + { + return delete_files($this->_cache_path); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * Not supported by file-based caching + * + * @param string user/filehits + * @return mixed FALSE + */ + public function cache_info($type = NULL) + { + return get_dir_file_info($this->_cache_path); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed FALSE on failure, array on success. + */ + public function get_metadata($id) + { + if ( ! file_exists($this->_cache_path.$id)) + { + return FALSE; + } + + $data = read_file($this->_cache_path.$id); + $data = unserialize($data); + + if (is_array($data)) + { + $data = $data['data']; + $mtime = filemtime($this->_cache_path.$id); + + if ( ! isset($data['ttl'])) + { + return FALSE; + } + + return array( + 'expire' => $mtime + $data['ttl'], + 'mtime' => $mtime + ); + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Is supported + * + * In the file driver, check to see that the cache directory is indeed writable + * + * @return boolean + */ + public function is_supported() + { + return is_really_writable($this->_cache_path); + } + + // ------------------------------------------------------------------------ +} +// End Class + +/* End of file Cache_file.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ \ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php new file mode 100644 index 000000000..adc7fbf44 --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -0,0 +1,209 @@ + array( + 'default_host' => '127.0.0.1', + 'default_port' => 11211, + 'default_weight' => 1 + ) + ); + + // ------------------------------------------------------------------------ + + /** + * Fetch from cache + * + * @param mixed unique key id + * @return mixed data on success/false on failure + */ + public function get($id) + { + $data = $this->_memcached->get($id); + + return (is_array($data)) ? $data[0] : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Save + * + * @param string unique identifier + * @param mixed data being cached + * @param int time to live + * @return boolean true on success, false on failure + */ + public function save($id, $data, $ttl = 60) + { + return $this->_memcached->add($id, array($data, time(), $ttl), $ttl); + } + + // ------------------------------------------------------------------------ + + /** + * Delete from Cache + * + * @param mixed key to be deleted. + * @return boolean true on success, false on failure + */ + public function delete($id) + { + return $this->_memcached->delete($id); + } + + // ------------------------------------------------------------------------ + + /** + * Clean the Cache + * + * @return boolean false on failure/true on success + */ + public function clean() + { + return $this->_memcached->flush(); + } + + // ------------------------------------------------------------------------ + + /** + * Cache Info + * + * @param null type not supported in memcached + * @return mixed array on success, false on failure + */ + public function cache_info($type = NULL) + { + return $this->_memcached->getStats(); + } + + // ------------------------------------------------------------------------ + + /** + * Get Cache Metadata + * + * @param mixed key to get cache metadata on + * @return mixed FALSE on failure, array on success. + */ + public function get_metadata($id) + { + $stored = $this->_memcached->get($id); + + if (count($stored) !== 3) + { + return FALSE; + } + + list($value, $time, $ttl) = $stored; + + return array( + 'expire' => $time + $ttl, + 'mtime' => $time, + 'data' => $data + ); + } + + // ------------------------------------------------------------------------ + + /** + * Setup memcached. + */ + private function _setup_memcached() + { + // Try to load memcached server info from the config file. + $CI =& get_instance(); + if ($CI->config->load('memcached', TRUE, TRUE)) + { + if (is_array($CI->config->config['memcached'])) + { + $this->_memcache_conf = NULL; + + foreach ($CI->config->config['memcached'] as $name => $conf) + { + $this->_memcache_conf[$name] = $conf; + } + } + } + + $this->_memcached = new Memcached(); + + foreach ($this->_memcache_conf as $name => $cache_server) + { + if ( ! array_key_exists('hostname', $cache_server)) + { + $cache_server['hostname'] = $this->_default_options['default_host']; + } + + if ( ! array_key_exists('port', $cache_server)) + { + $cache_server['port'] = $this->_default_options['default_port']; + } + + if ( ! array_key_exists('weight', $cache_server)) + { + $cache_server['weight'] = $this->_default_options['default_weight']; + } + + $this->_memcached->addServer( + $cache_server['hostname'], $cache_server['port'], $cache_server['weight'] + ); + } + } + + // ------------------------------------------------------------------------ + + + /** + * Is supported + * + * Returns FALSE if memcached is not supported on the system. + * If it is, we setup the memcached object & return TRUE + */ + public function is_supported() + { + if ( ! extension_loaded('memcached')) + { + log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.'); + + return FALSE; + } + + $this->_setup_memcached(); + return TRUE; + } + + // ------------------------------------------------------------------------ + +} +// End Class + +/* End of file Cache_memcached.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6c597f8d4b1b1bc12ccb4ad298053f03e6def36c Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 27 Dec 2010 17:35:35 +0000 Subject: Issue #298: $this->table->function = can now accept an array with a valid callback which is passed to call_user_func(). --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index a57781c29..b4c6d366e 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -346,7 +346,7 @@ class CI_Table { { if ($function !== FALSE && is_callable($function)) { - $out .= $function($cell); + $out .= call_user_func($function, $cell); } else { -- cgit v1.2.3-24-g4f1b From 6113f5462c5801964b12a95e62922606aa258808 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Wed, 29 Dec 2010 13:36:12 -0500 Subject: Changed email library to allow setting different user-agent. Fixes #286 --- system/libraries/Email.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 0a0d6c287..cda902593 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -108,7 +108,6 @@ class CI_Email { */ function initialize($config = array()) { - $this->clear(); foreach ($config as $key => $val) { if (isset($this->$key)) @@ -125,6 +124,7 @@ class CI_Email { } } } + $this->clear(); $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; @@ -160,7 +160,7 @@ class CI_Email { $this->_attach_type = array(); $this->_attach_disp = array(); } - + return $this; } @@ -203,7 +203,7 @@ class CI_Email { $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); - + return $this; } @@ -278,7 +278,7 @@ class CI_Email { case 'mail' : $this->_recipients = implode(", ", $to); break; } - + return $this; } @@ -307,7 +307,7 @@ class CI_Email { { $this->_cc_array = $cc; } - + return $this; } @@ -345,7 +345,7 @@ class CI_Email { { $this->_set_header('Bcc', implode(", ", $bcc)); } - + return $this; } @@ -543,7 +543,7 @@ class CI_Email { } $this->newline = $newline; - + return $this; } @@ -565,7 +565,7 @@ class CI_Email { } $this->crlf = $crlf; - + return $this; } @@ -1023,7 +1023,7 @@ class CI_Email { { $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body; } - + return; break; @@ -1048,10 +1048,10 @@ class CI_Email { $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; } - + $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; - - + + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; @@ -1077,8 +1077,8 @@ class CI_Email { if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - } - + } + $body .= $this->_get_mime_message() . $this->newline . $this->newline; $body .= "--" . $this->_atc_boundary . $this->newline; @@ -1091,7 +1091,7 @@ class CI_Email { case 'html-attach' : $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; - + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; @@ -1152,7 +1152,7 @@ class CI_Email { } $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; - + if ($this->_get_protocol() == 'mail') { @@ -1162,7 +1162,7 @@ class CI_Email { { $this->_finalbody = $hdr . $body; } - + return; } @@ -1533,7 +1533,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. - + if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) { return FALSE; @@ -1567,7 +1567,7 @@ class CI_Email { fputs($fp, $this->_finalbody); $status = pclose($fp); - + if (version_compare(PHP_VERSION, '4.2.3') == -1) { $status = $status >> 8 & 0xFF; -- cgit v1.2.3-24-g4f1b From 5c561805bd9ae6a4ad5d202277c34a879617b683 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 5 Jan 2011 16:31:59 +0000 Subject: If the data is an array output them one at a time. E.g: form_input('name[]', set_value('name[]'); --- system/libraries/Form_validation.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 38f50fa41..f45760024 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -736,6 +736,13 @@ class CI_Form_validation { return $default; } + // If the data is an array output them one at a time. + // E.g: form_input('name[]', set_value('name[]'); + if (is_array($this->_field_data[$field]['postdata'])) + { + return array_shift($this->_field_data[$field]['postdata']); + } + return $this->_field_data[$field]['postdata']; } -- cgit v1.2.3-24-g4f1b From dac1b468d5432ff9166fe221ac520b5050a65f0e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 6 Jan 2011 17:40:10 +0000 Subject: Altered User agent library so that is_browser(), is_mobile() and is_robot() can optionally check for a specific browser or mobile device. --- system/libraries/User_agent.php | 95 ++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 30 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index c1fb0231a..53cd7b2fd 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -82,7 +82,7 @@ class CI_User_agent { * @access private * @return bool */ - function _load_agent_file() + private function _load_agent_file() { if ( ! @include(APPPATH.'config/user_agents'.EXT)) { @@ -130,7 +130,7 @@ class CI_User_agent { * @access private * @return bool */ - function _compile_data() + private function _compile_data() { $this->_set_platform(); @@ -151,7 +151,7 @@ class CI_User_agent { * @access private * @return mixed */ - function _set_platform() + private function _set_platform() { if (is_array($this->platforms) AND count($this->platforms) > 0) { @@ -175,7 +175,7 @@ class CI_User_agent { * @access private * @return bool */ - function _set_browser() + private function _set_browser() { if (is_array($this->browsers) AND count($this->browsers) > 0) { @@ -202,7 +202,7 @@ class CI_User_agent { * @access private * @return bool */ - function _set_robot() + private function _set_robot() { if (is_array($this->robots) AND count($this->robots) > 0) { @@ -227,7 +227,7 @@ class CI_User_agent { * @access private * @return bool */ - function _set_mobile() + private function _set_mobile() { if (is_array($this->mobiles) AND count($this->mobiles) > 0) { @@ -252,7 +252,7 @@ class CI_User_agent { * @access private * @return void */ - function _set_languages() + private function _set_languages() { if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { @@ -275,7 +275,7 @@ class CI_User_agent { * @access private * @return void */ - function _set_charsets() + private function _set_charsets() { if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { @@ -298,9 +298,21 @@ class CI_User_agent { * @access public * @return bool */ - function is_browser() + public function is_browser($key = NULL) { - return $this->is_browser; + if ( ! $this->is_browser) + { + return FALSE; + } + + // No need to be specific, it's a browser + if ($key === NULL) + { + return TRUE; + } + + // Check for a specific browser + return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key]; } // -------------------------------------------------------------------- @@ -311,9 +323,21 @@ class CI_User_agent { * @access public * @return bool */ - function is_robot() + public function is_robot($key = NULL) { - return $this->is_robot; + if ( ! $this->is_robot) + { + return FALSE; + } + + // No need to be specific, it's a robot + if ($key === NULL) + { + return TRUE; + } + + // Check for a specific robot + return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key]; } // -------------------------------------------------------------------- @@ -324,9 +348,21 @@ class CI_User_agent { * @access public * @return bool */ - function is_mobile() + public function is_mobile($key = NULL) { - return $this->is_mobile; + if ( ! $this->is_mobile) + { + return FALSE; + } + + // No need to be specific, it's a mobile + if ($key === NULL) + { + return TRUE; + } + + // Check for a specific robot + return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key]; } // -------------------------------------------------------------------- @@ -337,9 +373,9 @@ class CI_User_agent { * @access public * @return bool */ - function is_referral() + public function is_referral() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == ''); } // -------------------------------------------------------------------- @@ -350,7 +386,7 @@ class CI_User_agent { * @access public * @return string */ - function agent_string() + public function agent_string() { return $this->agent; } @@ -363,7 +399,7 @@ class CI_User_agent { * @access public * @return string */ - function platform() + public function platform() { return $this->platform; } @@ -376,7 +412,7 @@ class CI_User_agent { * @access public * @return string */ - function browser() + public function browser() { return $this->browser; } @@ -389,7 +425,7 @@ class CI_User_agent { * @access public * @return string */ - function version() + public function version() { return $this->version; } @@ -402,7 +438,7 @@ class CI_User_agent { * @access public * @return string */ - function robot() + public function robot() { return $this->robot; } @@ -414,7 +450,7 @@ class CI_User_agent { * @access public * @return string */ - function mobile() + public function mobile() { return $this->mobile; } @@ -427,7 +463,7 @@ class CI_User_agent { * @access public * @return bool */ - function referrer() + public function referrer() { return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } @@ -440,7 +476,7 @@ class CI_User_agent { * @access public * @return array */ - function languages() + public function languages() { if (count($this->languages) == 0) { @@ -458,7 +494,7 @@ class CI_User_agent { * @access public * @return array */ - function charsets() + public function charsets() { if (count($this->charsets) == 0) { @@ -476,9 +512,9 @@ class CI_User_agent { * @access public * @return bool */ - function accept_lang($lang = 'en') + public function accept_lang($lang = 'en') { - return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; + return (in_array(strtolower($lang), $this->languages(), TRUE)); } // -------------------------------------------------------------------- @@ -489,12 +525,11 @@ class CI_User_agent { * @access public * @return bool */ - function accept_charset($charset = 'utf-8') + public function accept_charset($charset = 'utf-8') { - return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; + return (in_array(strtolower($charset), $this->charsets(), TRUE)); } - } -- cgit v1.2.3-24-g4f1b From a0f980e361d3025b8d34e7cbe3b747460de80dea Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 13 Jan 2011 10:59:12 +0000 Subject: Added access scope to Email library and allow method chaining from $this->email->initialize(). --- system/libraries/Email.php | 125 +++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 61 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index cda902593..132f3db25 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -82,7 +82,7 @@ class CI_Email { * * The constructor can be passed an array of config values */ - function __construct($config = array()) + public function __construct($config = array()) { if (count($config) > 0) { @@ -106,7 +106,7 @@ class CI_Email { * @param array * @return void */ - function initialize($config = array()) + public function initialize($config = array()) { foreach ($config as $key => $val) { @@ -128,6 +128,8 @@ class CI_Email { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; + + return $this; } // -------------------------------------------------------------------- @@ -138,7 +140,7 @@ class CI_Email { * @access public * @return void */ - function clear($clear_attachments = FALSE) + public function clear($clear_attachments = FALSE) { $this->_subject = ""; $this->_body = ""; @@ -174,7 +176,7 @@ class CI_Email { * @param string * @return void */ - function from($from, $name = '') + public function from($from, $name = '') { if (preg_match( '/\<(.*)\>/', $from, $match)) { @@ -217,7 +219,7 @@ class CI_Email { * @param string * @return void */ - function reply_to($replyto, $name = '') + public function reply_to($replyto, $name = '') { if (preg_match( '/\<(.*)\>/', $replyto, $match)) { @@ -254,7 +256,7 @@ class CI_Email { * @param string * @return void */ - function to($to) + public function to($to) { $to = $this->_str_to_array($to); $to = $this->clean_email($to); @@ -271,11 +273,12 @@ class CI_Email { switch ($this->_get_protocol()) { - case 'smtp' : $this->_recipients = $to; + case 'smtp' : + $this->_recipients = $to; break; - case 'sendmail' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); + case 'sendmail' : + case 'mail' : + $this->_recipients = implode(", ", $to); break; } @@ -291,7 +294,7 @@ class CI_Email { * @param string * @return void */ - function cc($cc) + public function cc($cc) { $cc = $this->_str_to_array($cc); $cc = $this->clean_email($cc); @@ -321,7 +324,7 @@ class CI_Email { * @param string * @return void */ - function bcc($bcc, $limit = '') + public function bcc($bcc, $limit = '') { if ($limit != '' && is_numeric($limit)) { @@ -358,7 +361,7 @@ class CI_Email { * @param string * @return void */ - function subject($subject) + public function subject($subject) { $subject = $this->_prep_q_encoding($subject); $this->_set_header('Subject', $subject); @@ -374,7 +377,7 @@ class CI_Email { * @param string * @return void */ - function message($body) + public function message($body) { $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); return $this; @@ -389,7 +392,7 @@ class CI_Email { * @param string * @return void */ - function attach($filename, $disposition = 'attachment') + public function attach($filename, $disposition = 'attachment') { $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); @@ -407,7 +410,7 @@ class CI_Email { * @param string * @return void */ - function _set_header($header, $value) + private function _set_header($header, $value) { $this->_headers[$header] = $value; } @@ -421,7 +424,7 @@ class CI_Email { * @param string * @return array */ - function _str_to_array($email) + private function _str_to_array($email) { if ( ! is_array($email)) { @@ -447,7 +450,7 @@ class CI_Email { * @param string * @return void */ - function set_alt_message($str = '') + public function set_alt_message($str = '') { $this->alt_message = ($str == '') ? '' : $str; return $this; @@ -462,7 +465,7 @@ class CI_Email { * @param string * @return void */ - function set_mailtype($type = 'text') + public function set_mailtype($type = 'text') { $this->mailtype = ($type == 'html') ? 'html' : 'text'; return $this; @@ -477,7 +480,7 @@ class CI_Email { * @param string * @return void */ - function set_wordwrap($wordwrap = TRUE) + public function set_wordwrap($wordwrap = TRUE) { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; return $this; @@ -492,7 +495,7 @@ class CI_Email { * @param string * @return void */ - function set_protocol($protocol = 'mail') + public function set_protocol($protocol = 'mail') { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); return $this; @@ -507,7 +510,7 @@ class CI_Email { * @param integer * @return void */ - function set_priority($n = 3) + public function set_priority($n = 3) { if ( ! is_numeric($n)) { @@ -534,7 +537,7 @@ class CI_Email { * @param string * @return void */ - function set_newline($newline = "\n") + public function set_newline($newline = "\n") { if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") { @@ -556,7 +559,7 @@ class CI_Email { * @param string * @return void */ - function set_crlf($crlf = "\n") + public function set_crlf($crlf = "\n") { if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") { @@ -577,7 +580,7 @@ class CI_Email { * @access private * @return void */ - function _set_boundaries() + private function _set_boundaries() { $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary @@ -591,7 +594,7 @@ class CI_Email { * @access private * @return string */ - function _get_message_id() + private function _get_message_id() { $from = $this->_headers['Return-Path']; $from = str_replace(">", "", $from); @@ -609,7 +612,7 @@ class CI_Email { * @param bool * @return string */ - function _get_protocol($return = TRUE) + private function _get_protocol($return = TRUE) { $this->protocol = strtolower($this->protocol); $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; @@ -629,7 +632,7 @@ class CI_Email { * @param bool * @return string */ - function _get_encoding($return = TRUE) + private function _get_encoding($return = TRUE) { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; @@ -655,7 +658,7 @@ class CI_Email { * @access private * @return string */ - function _get_content_type() + private function _get_content_type() { if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { @@ -683,7 +686,7 @@ class CI_Email { * @access private * @return string */ - function _set_date() + private function _set_date() { $timezone = date("Z"); $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; @@ -701,7 +704,7 @@ class CI_Email { * @access private * @return string */ - function _get_mime_message() + private function _get_mime_message() { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } @@ -715,7 +718,7 @@ class CI_Email { * @param string * @return bool */ - function validate_email($email) + public function validate_email($email) { if ( ! is_array($email)) { @@ -744,7 +747,7 @@ class CI_Email { * @param string * @return bool */ - function valid_email($address) + public function valid_email($address) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } @@ -758,7 +761,7 @@ class CI_Email { * @param string * @return string */ - function clean_email($email) + public function clean_email($email) { if ( ! is_array($email)) { @@ -794,7 +797,7 @@ class CI_Email { /** * Build alternative plain text message * - * This function provides the raw message for use + * This public function provides the raw message for use * in plain-text headers of HTML-formatted emails. * If the user hasn't specified his own alternative message * it creates one by stripping the HTML @@ -802,7 +805,7 @@ class CI_Email { * @access private * @return string */ - function _get_alt_message() + private function _get_alt_message() { if ($this->alt_message != "") { @@ -847,7 +850,7 @@ class CI_Email { * @param integer * @return string */ - function word_wrap($str, $charlim = '') + public function word_wrap($str, $charlim = '') { // Se the character limit if ($charlim == '') @@ -876,7 +879,7 @@ class CI_Email { } } - // Use PHP's native function to do the initial wordwrap. + // Use PHP's native public function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); @@ -942,7 +945,7 @@ class CI_Email { * @param string * @return string */ - function _build_headers() + private function _build_headers() { $this->_set_header('X-Sender', $this->clean_email($this->_headers['From'])); $this->_set_header('X-Mailer', $this->useragent); @@ -959,7 +962,7 @@ class CI_Email { * @access private * @return void */ - function _write_headers() + private function _write_headers() { if ($this->protocol == 'mail') { @@ -994,7 +997,7 @@ class CI_Email { * @access private * @return void */ - function _build_message() + private function _build_message() { if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { @@ -1179,7 +1182,7 @@ class CI_Email { * @param integer * @return string */ - function _prep_quoted_printable($str, $charlim = '') + private function _prep_quoted_printable($str, $charlim = '') { // Set the character limit // Don't allow over 76, as that will make servers and MUAs barf @@ -1272,7 +1275,7 @@ class CI_Email { * @param bool // set to TRUE for processing From: headers * @return str */ - function _prep_q_encoding($str, $from = FALSE) + private function _prep_q_encoding($str, $from = FALSE) { $str = str_replace(array("\r", "\n"), array('', ''), $str); @@ -1339,7 +1342,7 @@ class CI_Email { * @access public * @return bool */ - function send() + public function send() { if ($this->_replyto_flag == FALSE) { @@ -1382,7 +1385,7 @@ class CI_Email { * @access public * @return bool */ - function batch_bcc_send() + public function batch_bcc_send() { $float = $this->bcc_batch_size -1; @@ -1440,7 +1443,7 @@ class CI_Email { * @access private * @return void */ - function _unwrap_specials() + private function _unwrap_specials() { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } @@ -1453,7 +1456,7 @@ class CI_Email { * @access private * @return string */ - function _remove_nl_callback($matches) + private function _remove_nl_callback($matches) { if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE) { @@ -1471,7 +1474,7 @@ class CI_Email { * @access private * @return bool */ - function _spool_email() + private function _spool_email() { $this->_unwrap_specials(); @@ -1516,7 +1519,7 @@ class CI_Email { * @access private * @return bool */ - function _send_with_mail() + private function _send_with_mail() { if ($this->_safe_mode == TRUE) { @@ -1553,7 +1556,7 @@ class CI_Email { * @access private * @return bool */ - function _send_with_sendmail() + private function _send_with_sendmail() { $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); @@ -1591,7 +1594,7 @@ class CI_Email { * @access private * @return bool */ - function _send_with_smtp() + private function _send_with_smtp() { if ($this->smtp_host == '') { @@ -1661,7 +1664,7 @@ class CI_Email { * @param string * @return string */ - function _smtp_connect() + private function _smtp_connect() { $this->_smtp_connect = fsockopen($this->smtp_host, $this->smtp_port, @@ -1689,7 +1692,7 @@ class CI_Email { * @param string * @return string */ - function _send_command($cmd, $data = '') + private function _send_command($cmd, $data = '') { switch ($cmd) { @@ -1754,7 +1757,7 @@ class CI_Email { * @access private * @return bool */ - function _smtp_authenticate() + private function _smtp_authenticate() { if ( ! $this->_smtp_auth) { @@ -1808,7 +1811,7 @@ class CI_Email { * @access private * @return bool */ - function _send_data($data) + private function _send_data($data) { if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) { @@ -1829,7 +1832,7 @@ class CI_Email { * @access private * @return string */ - function _get_smtp_data() + private function _get_smtp_data() { $data = ""; @@ -1854,7 +1857,7 @@ class CI_Email { * @access private * @return string */ - function _get_hostname() + private function _get_hostname() { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } @@ -1867,7 +1870,7 @@ class CI_Email { * @access private * @return string */ - function _get_ip() + private function _get_ip() { if ($this->_IP !== FALSE) { @@ -1909,7 +1912,7 @@ class CI_Email { * @access public * @return string */ - function print_debugger() + public function print_debugger() { $msg = ''; @@ -1934,7 +1937,7 @@ class CI_Email { * @param string * @return string */ - function _set_error_message($msg, $val = '') + private function _set_error_message($msg, $val = '') { $CI =& get_instance(); $CI->lang->load('email'); @@ -1958,7 +1961,7 @@ class CI_Email { * @param string * @return string */ - function _mime_types($ext = "") + private function _mime_types($ext = "") { $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', -- cgit v1.2.3-24-g4f1b From 9805ecce97dbd3f60891c19f27111f75851bd666 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 16 Jan 2011 23:35:16 -0500 Subject: Added access scope to security library and added config options for csrf protection --- system/libraries/Security.php | 67 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 31 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index d2638560c..b022947a0 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -25,14 +25,15 @@ * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Security { - var $xss_hash = ''; - var $csrf_hash = ''; - var $csrf_expire = 7200; // Two hours (in seconds) - var $csrf_token_name = 'ci_csrf_token'; - var $csrf_cookie_name = 'ci_csrf_token'; + + public $xss_hash = ''; + public $csrf_hash = ''; + public $csrf_expire = 7200; // Two hours (in seconds) + public $csrf_token_name = 'ci_csrf_token'; + public $csrf_cookie_name = 'ci_csrf_token'; /* never allowed, string replacement */ - var $never_allowed_str = array( + public $never_allowed_str = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', '.parentNode' => '[removed]', @@ -44,7 +45,7 @@ class CI_Security { ' '<![CDATA[' ); /* never allowed, regex replacement */ - var $never_allowed_regex = array( + public $never_allowed_regex = array( "javascript\s*:" => '[removed]', "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE "vbscript\s*:" => '[removed]', // IE, surprise! @@ -53,6 +54,10 @@ class CI_Security { public function __construct() { + $this->csrf_token_name = (config_item('csrf_token_name')) ? config_item('csrf_token_name') : 'csrf_token_name'; + $this->csrf_cookie_name = (config_item('csrf_cookie_name')) ? config_item('csrf_cookie_name') : 'csrf_cookie_name'; + $this->csrf_expire = (config_item('csrf_expire')) ? config_item('csrf_expire') : 7200; + // Append application specific cookie prefix to token name $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; @@ -70,7 +75,7 @@ class CI_Security { * @access public * @return null */ - function csrf_verify() + public function csrf_verify() { // If no POST data exists we will set the CSRF cookie if (count($_POST) == 0) @@ -109,7 +114,7 @@ class CI_Security { * @access public * @return null */ - function csrf_set_cookie() + public function csrf_set_cookie() { $expire = time() + $this->csrf_expire; @@ -123,10 +128,10 @@ class CI_Security { /** * Set Cross Site Request Forgery Protection Cookie * - * @access public + * @access private * @return null */ - function _csrf_set_hash() + private function _csrf_set_hash() { if ($this->csrf_hash == '') { @@ -153,7 +158,7 @@ class CI_Security { * @access public * @return null */ - function csrf_show_error() + public function csrf_show_error() { show_error('The action you have requested is not allowed.'); } @@ -186,7 +191,7 @@ class CI_Security { * @param mixed string or array * @return string */ - function xss_clean($str, $is_image = FALSE) + public function xss_clean($str, $is_image = FALSE) { /* * Is the string an array? @@ -210,9 +215,9 @@ class CI_Security { /* * Protect GET variables in URLs */ - + // 901119URL5918AMP18930PROTECT8198 - + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); /* @@ -259,7 +264,7 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* @@ -470,7 +475,7 @@ class CI_Security { * @access public * @return string */ - function xss_hash() + public function xss_hash() { if ($this->xss_hash == '') { @@ -493,11 +498,11 @@ class CI_Security { * Callback function for xss_clean() to remove whitespace from * things like j a v a s c r i p t * - * @access public + * @access private * @param type * @return type */ - function _compact_exploded_words($matches) + private function _compact_exploded_words($matches) { return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; } @@ -513,7 +518,7 @@ class CI_Security { * @param array * @return string */ - function _sanitize_naughty_html($matches) + private function _sanitize_naughty_html($matches) { // encode opening brace $str = '<'.$matches[1].$matches[2].$matches[3]; @@ -538,7 +543,7 @@ class CI_Security { * @param array * @return string */ - function _js_link_removal($match) + private function _js_link_removal($match) { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); } @@ -585,11 +590,11 @@ class CI_Security { * * Filters tag attributes for consistency and safety * - * @access public + * @access private * @param string * @return string */ - function _filter_attributes($str) + private function _filter_attributes($str) { $out = ''; @@ -611,11 +616,11 @@ class CI_Security { * * Used as a callback for XSS Clean * - * @access public + * @access private * @param array * @return string */ - function _decode_entity($match) + private function _decode_entity($match) { return $this->entity_decode($match[0], strtoupper(config_item('charset'))); } @@ -641,7 +646,7 @@ class CI_Security { * @param string * @return string */ - function entity_decode($str, $charset='UTF-8') + public function entity_decode($str, $charset='UTF-8') { if (stristr($str, '&') === FALSE) return $str; @@ -680,7 +685,7 @@ class CI_Security { * @param string * @return string */ - function sanitize_filename($str, $relative_path = FALSE) + public function sanitize_filename($str, $relative_path = FALSE) { $bad = array( "../", @@ -715,7 +720,7 @@ class CI_Security { "%3b", // ; "%3d" // = ); - + if ( ! $relative_path) { $bad[] = './'; -- cgit v1.2.3-24-g4f1b From c3828718925a0f1660cddadc95b63e14f7189faa Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 19 Jan 2011 12:31:47 +0000 Subject: Reverted regex validation while we re-think the implementation, and added ->input->is_cli_request(); --- system/libraries/Form_validation.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index f45760024..9fe76b5f2 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -171,7 +171,7 @@ class CI_Form_validation { } $this->_error_messages = array_merge($this->_error_messages, $lang); - + return $this; } @@ -191,7 +191,7 @@ class CI_Form_validation { { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; - + return $this; } @@ -339,13 +339,7 @@ class CI_Form_validation { } } - preg_match_all('/([a-zA-Z_-]*(\[.*\])?)\|?/i', $row['rules'], $matches); - - $rules = $matches[1]; - array_pop($rules); - unset($matches); - - $this->_execute($row, $rules, $this->_field_data[$field]['postdata']); + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -742,7 +736,7 @@ class CI_Form_validation { { return array_shift($this->_field_data[$field]['postdata']); } - + return $this->_field_data[$field]['postdata']; } -- cgit v1.2.3-24-g4f1b From 700205ad5cb6c00596ad82d5ed282f516add5481 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 28 Jan 2011 07:44:28 -0600 Subject: updating copyrights to 2011 --- system/libraries/Cache/Cache.php | 2 +- system/libraries/Cache/drivers/Cache_apc.php | 2 +- system/libraries/Cache/drivers/Cache_dummy.php | 2 +- system/libraries/Cache/drivers/Cache_file.php | 2 +- system/libraries/Cache/drivers/Cache_memcached.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Driver.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index ea3194237..d3f6105ea 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index 9c716a971..e82e8e1f5 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index 13c1f5cde..74f689241 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index bedbfaff8..3ed357f2f 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index adc7fbf44..a7efdc5de 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010 EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 5d3f91d43..7f65b48b9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 8579a6023..15fc3da26 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 9d3ad267e8e8f2972ceea05c4281b0234ed3efb4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 28 Jan 2011 14:06:58 -0600 Subject: some cleanup for the javascript class docs --- system/libraries/javascript/Jquery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php index 0fbb52696..baab83d25 100644 --- a/system/libraries/javascript/Jquery.php +++ b/system/libraries/javascript/Jquery.php @@ -21,7 +21,7 @@ * @subpackage Libraries * @author ExpressionEngine Dev Team * @category Loader - * @link http://www.codeigniter.com/user_guide/libraries/jquery.html + * @link http://www.codeigniter.com/user_guide/libraries/javascript.html */ class CI_Jquery extends CI_Javascript { -- cgit v1.2.3-24-g4f1b From 999e7472aa094dac056494ff41772f9204da04b2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sat, 29 Jan 2011 16:16:58 -0600 Subject: Fix #21 - Typo in get_metadata() function of apc and memcached cache drivers. --- system/libraries/Cache/drivers/Cache_apc.php | 2 +- system/libraries/Cache/drivers/Cache_memcached.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index e82e8e1f5..4b995c793 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -114,7 +114,7 @@ class Cache_apc extends CI_Driver { return FALSE; } - list($value, $time, $ttl) = $stored; + list($data, $time, $ttl) = $stored; return array( 'expire' => $time + $ttl, diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index a7efdc5de..5f5a31591 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -122,7 +122,7 @@ class Cache_memcached extends CI_Driver { return FALSE; } - list($value, $time, $ttl) = $stored; + list($data, $time, $ttl) = $stored; return array( 'expire' => $time + $ttl, -- cgit v1.2.3-24-g4f1b From f6f51a6ef6bad21dc04997a5d585f90eab082187 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 5 Feb 2011 21:41:17 -0500 Subject: Fixed is_referral to return proper status. Fixes #40 --- system/libraries/User_agent.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index c62174836..3774fc283 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -375,7 +375,11 @@ class CI_User_agent { */ public function is_referral() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == ''); + if ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') + { + return FALSE; + } + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ef112c0830df4a31563351125888b0d522a1c965 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 7 Feb 2011 13:01:47 +0000 Subject: Added decimal, less_than and greater_than rules to the Form validation Class. --- system/libraries/Form_validation.php | 70 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index fc5b82ee3..745fb7c03 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -138,14 +138,14 @@ class CI_Form_validation { // Build our master array $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, - 'rules' => $rules, - 'is_array' => $is_array, - 'keys' => $indexes, - 'postdata' => NULL, - 'error' => '' - ); + 'field' => $field, + 'label' => $label, + 'rules' => $rules, + 'is_array' => $is_array, + 'keys' => $indexes, + 'postdata' => NULL, + 'error' => '' + ); return $this; } @@ -1147,7 +1147,57 @@ class CI_Form_validation { */ function integer($str) { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); + return (bool) preg_match('/^[\-+]?[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Decimal number + * + * @access public + * @param string + * @return bool + */ + function decimal($str) + { + return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Greather than + * + * @access public + * @param string + * @return bool + */ + function greater_than($str, $min) + { + if ( ! is_numeric($str)) + { + return false; + } + return $str > $min; + } + + // -------------------------------------------------------------------- + + /** + * Less than + * + * @access public + * @param string + * @return bool + */ + function less_than($str, $max) + { + if ( ! is_numeric($str)) + { + return false; + } + return $str < $max; } // -------------------------------------------------------------------- @@ -1161,7 +1211,7 @@ class CI_Form_validation { */ function is_natural($str) { - return (bool)preg_match( '/^[0-9]+$/', $str); + return (bool) preg_match( '/^[0-9]+$/', $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9758d84b69185f80fd8197f28046af7ef3b2a2d3 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 7 Feb 2011 20:39:00 +0000 Subject: Added Migrations library, config and an example controller/migration file. --- system/libraries/Migration.php | 336 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 system/libraries/Migration.php (limited to 'system/libraries') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php new file mode 100644 index 000000000..73c55c346 --- /dev/null +++ b/system/libraries/Migration.php @@ -0,0 +1,336 @@ + $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, '/').'/'; + + // 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 + */ + 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 = sprintf($this->lang->line('multiple_migration_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 = 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 = sprintf($this->lang->line('multiple_migrations_name'), $match[1]); + return FALSE; + } + + include $f[0]; + $class = 'Migration_' . ucfirst($match[1]); + + if ( ! class_exists($class)) + { + $this->error = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); + return FALSE; + } + + if ( ! is_callable(array($class, 'up')) || ! is_callable(array($class, 'down'))) + { + $this->error = sprintf($this->lang->line('wrong_migration_interface'), $class); + return FALSE; + } + + $migrations[] = $match[1]; + } + else + { + $this->error = sprintf($this->lang->line('invalid_migration_filename'), $file); + return FALSE; + } + } + + $this->log('Current schema version: ' . $current_version); + + $version = $i + ($step == 1 ? -1 : 0); + + // If there is nothing to do so quit + if ($migrations === array()) + { + return TRUE; + } + + $this->log('Moving ' . $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); + } + + $this->log('All done. Schema is at version '.$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()) + { + throw new Exception('no_migrations_found'); + return false; + } + + $last_migration = basename(end($migrations)); + + // Calculate the last migration step from existing migration + // filenames and procceed to the standard version migration + $last_version = intval(substr($last_migration, 0, 3)); + return $this->version($last_version); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + $version = $this->_migration_version; + return $this->version($version); + } + + // -------------------------------------------------------------------- + + /** + * Set's the schema to the latest migration + * + * @access public + * @return mixed true if already latest, false if failed, int if upgraded + */ + + protected static 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 private + * @return integer Current Schema version + */ + private function _get_version() + { + $row = $this->db->get('migrations')->row(); + return $row ? $row->version : 0; + } + + // -------------------------------------------------------------------- + + /** + * Stores the current schema version + * + * @access private + * @param $migrations integer Schema version reached + * @return void Outputs a report of the migration + */ + private function _update_version($migrations) + { + return $this->db->update('migrations', array( + 'version' => $migrations + )); + } + + // -------------------------------------------------------------------- + + /** + * Stores the current schema version + * + * @access private + * @param $migrations integer Schema version reached + * @return void Outputs a report of the migration + */ + private function log($text) + { + echo $text.'
'; + } + + // -------------------------------------------------------------------- + + /** + * Enable the use of CI super-global + * + * @access public + * @param $var + * @return mixed + */ + public function __get($var) + { + return get_instance()->$var; + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 23351dc30a1787d30a97dd0a8ba83d6e312a5a2f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 14 Feb 2011 00:14:21 -0600 Subject: Fix #329 where the file caching driver referenced the incorrect cache directory. --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 3ed357f2f..86d1a3b6a 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -39,7 +39,7 @@ class Cache_file extends CI_Driver { $path = $CI->config->item('cache_path'); - $this->_cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 8761ef56b465a190489ed555c6a0ab58470bfc73 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:13:52 -0500 Subject: Uppercasing some stray lowercase keywords for code consistency --- system/libraries/Form_validation.php | 4 ++-- system/libraries/Image_lib.php | 2 +- system/libraries/Xmlrpc.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 745fb7c03..c6d7c2976 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1177,7 +1177,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str > $min; } @@ -1195,7 +1195,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str < $max; } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 41f9ad393..8902f524d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -749,7 +749,7 @@ class CI_Image_lib { @chmod($this->full_dst_path, FILE_WRITE_MODE); - return true; + return TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 9cf307cc0..0d5a261f9 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -358,7 +358,7 @@ class XML_RPC_Client extends CI_Xmlrpc var $errno = ''; var $errstring = ''; var $timeout = 5; - var $no_multicall = false; + var $no_multicall = FALSE; public function __construct($path, $server, $port=80) { @@ -896,7 +896,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf'] = 1; break; case 'PARAM': - $this->xh[$the_parser]['value'] = null; + $this->xh[$the_parser]['value'] = NULL; break; case 'VALUE': $this->xh[$the_parser]['vt'] = 'value'; @@ -925,7 +925,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['valuestack'][0]['name'] = ''; // Set NULL value to check to see if value passed for this param/member - $this->xh[$the_parser]['value'] = null; + $this->xh[$the_parser]['value'] = NULL; break; case 'DATA': case 'METHODCALL': -- cgit v1.2.3-24-g4f1b From 68d29873fb155651f46523fdcfb9027102a89f1f Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:39:06 -0500 Subject: Large cleanup of xmlrpcs docblocks. --- system/libraries/Xmlrpcs.php | 178 ++++++++++++++++++++++++++++++------------- 1 file changed, 123 insertions(+), 55 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 6bedfe324..9cd332147 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -59,10 +59,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc log_message('debug', "XML-RPC Server Class Initialized"); } - //------------------------------------- - // Initialize Prefs and Serve - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Initialize Prefs and Serve + * + * @access public + * @param mixed + * @return void + */ function initialize($config=array()) { if (isset($config['functions']) && is_array($config['functions'])) @@ -86,11 +91,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc } } - //------------------------------------- - // Setting of System Methods - //------------------------------------- + // -------------------------------------------------------------------- - function set_system_methods () + /** + * Setting of System Methods + * + * @access public + * @return void + */ + function set_system_methods() { $this->methods = array( 'system.listMethods' => array( @@ -112,11 +121,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc ); } + // -------------------------------------------------------------------- - //------------------------------------- - // Main Server Function - //------------------------------------- - + /** + * Main Server Function + * + * @access public + * @return void + */ function serve() { $r = $this->parseRequest(); @@ -129,11 +141,19 @@ class CI_Xmlrpcs extends CI_Xmlrpc exit($payload); } - //------------------------------------- - // Add Method to Class - //------------------------------------- + // -------------------------------------------------------------------- - function add_to_map($methodname,$function,$sig,$doc) + /** + * Add Method to Class + * + * @access public + * @param string method name + * @param string function + * @param string signature + * @param string docstring + * @return void + */ + function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( 'function' => $function, @@ -142,11 +162,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc ); } + // -------------------------------------------------------------------- - //------------------------------------- - // Parse Server Request - //------------------------------------- - + /** + * Parse Server Request + * + * @access public + * @param string data + * @return object xmlrpc response + */ function parseRequest($data='') { global $HTTP_RAW_POST_DATA; @@ -196,7 +220,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc xml_get_current_line_number($parser))); xml_parser_free($parser); } - elseif($parser_object->xh[$parser]['isf']) + elseif ($parser_object->xh[$parser]['isf']) { return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); } @@ -207,7 +231,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); $plist=''; - for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) + for ($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) { if ($this->debug === TRUE) { @@ -239,10 +263,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc return $r; } - //------------------------------------- - // Executes the Method - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Executes the Method + * + * @access protected + * @param object + * @return mixed + */ function _execute($m) { $methName = $m->method_name; @@ -297,13 +326,13 @@ class CI_Xmlrpcs extends CI_Xmlrpc if (isset($this->methods[$methName]['signature'])) { $sig = $this->methods[$methName]['signature']; - for($i=0; $iparams)+1) { - for($n=0; $n < count($m->params); $n++) + for ($n=0; $n < count($m->params); $n++) { $p = $m->params[$n]; $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); @@ -352,23 +381,27 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } + + // -------------------------------------------------------------------- - - //------------------------------------- - // Server Function: List Methods - //------------------------------------- - + /** + * Server Function: List Methods + * + * @access public + * @param mixed + * @return object + */ function listMethods($m) { $v = new XML_RPC_Values(); $output = array(); - foreach($this->methods as $key => $value) + foreach ($this->methods as $key => $value) { $output[] = new XML_RPC_Values($key, 'string'); } - foreach($this->system_methods as $key => $value) + foreach ($this->system_methods as $key => $value) { $output[]= new XML_RPC_Values($key, 'string'); } @@ -376,11 +409,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } + + // -------------------------------------------------------------------- - //------------------------------------- - // Server Function: Return Signature for Method - //------------------------------------- - + /** + * Server Function: Return Signature for Method + * + * @access public + * @param mixed + * @return object + */ function methodSignature($m) { $parameters = $m->output_parameters(); @@ -393,11 +431,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $sigs = array(); $signature = $this->methods[$method_name]['signature']; - for($i=0; $i < count($signature); $i++) + for ($i=0; $i < count($signature); $i++) { $cursig = array(); $inSig = $signature[$i]; - for($j=0; $joutput_parameters(); @@ -437,11 +480,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } + + // -------------------------------------------------------------------- - //------------------------------------- - // Server Function: Multi-call - //------------------------------------- - + /** + * Server Function: Multi-call + * + * @access public + * @param mixed + * @return object + */ function multicall($m) { // Disabled @@ -459,7 +507,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($value[0]); $plist=''; - for($i=0; $i < count($value[1]); $i++) + for ($i=0; $i < count($value[1]); $i++) { $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); } @@ -477,11 +525,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); } + // -------------------------------------------------------------------- - //------------------------------------- - // Multi-call Function: Error Handling - //------------------------------------- - + /** + * Multi-call Function: Error Handling + * + * @access public + * @param mixed + * @return object + */ function multicall_error($err) { $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); @@ -493,29 +545,45 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Values($struct, 'struct'); } + // -------------------------------------------------------------------- - //------------------------------------- - // Multi-call Function: Processes method - //------------------------------------- - + /** + * Multi-call Function: Processes method + * + * @access public + * @param mixed + * @return object + */ function do_multicall($call) { if ($call->kindOf() != 'struct') + { return $this->multicall_error('notstruct'); + } elseif ( ! $methName = $call->me['struct']['methodName']) + { return $this->multicall_error('nomethod'); + } list($scalar_type,$scalar_value)=each($methName->me); $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') + { return $this->multicall_error('notstring'); + } elseif ($scalar_value == 'system.multicall') + { return $this->multicall_error('recursion'); + } elseif ( ! $params = $call->me['struct']['params']) + { return $this->multicall_error('noparams'); + } elseif ($params->kindOf() != 'array') + { return $this->multicall_error('notarray'); + } list($a,$b)=each($params->me); $numParams = count($b); -- cgit v1.2.3-24-g4f1b From 14287f3e81d4d717ff49e640d799c579e593f0c0 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:39:34 -0500 Subject: Whitespace cleanup in libraries/ --- system/libraries/Driver.php | 6 ++--- system/libraries/Email.php | 12 +++++----- system/libraries/Form_validation.php | 2 +- system/libraries/Profiler.php | 4 ++-- system/libraries/Security.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 8 +++---- system/libraries/Trackback.php | 4 ++-- system/libraries/Upload.php | 2 +- system/libraries/Xmlrpc.php | 46 +++++++++++++++++------------------- system/libraries/Zip.php | 2 +- 11 files changed, 44 insertions(+), 46 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 15fc3da26..02e093d7e 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -lib_name)) + if ( ! isset($this->lib_name)) { $this->lib_name = get_class($this); } @@ -143,7 +143,7 @@ class CI_Driver { } } - foreach($r->getProperties() as $prop) + foreach ($r->getProperties() as $prop) { if ($prop->isPublic()) { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e5af38f45..6c21f114d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -897,7 +897,7 @@ class CI_Email { } $temp = ''; - while((strlen($line)) > $charlim) + while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) @@ -973,7 +973,7 @@ class CI_Email { reset($this->_headers); $this->_header_str = ""; - foreach($this->_headers as $key => $val) + foreach ($this->_headers as $key => $val) { $val = trim($val); @@ -1607,14 +1607,14 @@ class CI_Email { $this->_send_command('from', $this->clean_email($this->_headers['From'])); - foreach($this->_recipients as $val) + foreach ($this->_recipients as $val) { $this->_send_command('to', $val); } if (count($this->_cc_array) > 0) { - foreach($this->_cc_array as $val) + foreach ($this->_cc_array as $val) { if ($val != "") { @@ -1625,7 +1625,7 @@ class CI_Email { if (count($this->_bcc_array) > 0) { - foreach($this->_bcc_array as $val) + foreach ($this->_bcc_array as $val) { if ($val != "") { @@ -1672,7 +1672,7 @@ class CI_Email { $errstr, $this->smtp_timeout); - if( ! is_resource($this->_smtp_connect)) + if ( ! is_resource($this->_smtp_connect)) { $this->_set_error_message('email_smtp_error', $errno." ".$errstr); return FALSE; diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c6d7c2976..adfd17db1 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1040,7 +1040,7 @@ class CI_Form_validation { return $this->valid_email(trim($str)); } - foreach(explode(',', $str) as $email) + foreach (explode(',', $str) as $email) { if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) { diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6587eae0b..8a1f18ced 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -415,7 +415,7 @@ class CI_Profiler { $output .= "\n\n\n"; - foreach(array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) + foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; $output .= "\n"; @@ -446,7 +446,7 @@ class CI_Profiler { $output .= "\n\n
".$header."  ".$val."
\n"; - foreach($this->CI->config->config as $config=>$val) + foreach ($this->CI->config->config as $config=>$val) { if (is_array($val)) { diff --git a/system/libraries/Security.php b/system/libraries/Security.php index ba64c7326..91896866f 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -373,7 +373,7 @@ class CI_Security { $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); } } - while($original != $str); + while ($original != $str); unset($original); diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index ad747a001..05a42345a 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -88,7 +88,7 @@ class CI_SHA { $oldd = $d; $olde = $e; - for($j = 0; $j < 80; $j++) + for ($j = 0; $j < 80; $j++) { if ($j < 16) { diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 485541630..2a1a95b16 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -108,7 +108,7 @@ class CI_Table { } $new = array(); - while(count($array) > 0) + while (count($array) > 0) { $temp = array_splice($array, 0, $col_limit); @@ -280,7 +280,7 @@ class CI_Table { $out .= $this->template['heading_row_start']; $out .= $this->newline; - foreach($this->heading as $heading) + foreach ($this->heading as $heading) { $temp = $this->template['heading_cell_start']; @@ -310,7 +310,7 @@ class CI_Table { $out .= $this->newline; $i = 1; - foreach($this->rows as $row) + foreach ($this->rows as $row) { if ( ! is_array($row)) { @@ -323,7 +323,7 @@ class CI_Table { $out .= $this->template['row_'.$name.'start']; $out .= $this->newline; - foreach($row as $cell) + foreach ($row as $cell) { $temp = $this->template['cell_'.$name.'start']; diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index e29b35c7a..b0a767822 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -94,7 +94,7 @@ class CI_Trackback { { $$item = $this->convert_ascii($$item); } - elseif($item == 'blog_name') + elseif ($item == 'blog_name') { $$item = $this->convert_ascii($$item); } @@ -261,7 +261,7 @@ class CI_Trackback { // Was it successful? $this->response = ""; - while( ! feof($fp)) + while ( ! feof($fp)) { $this->response .= fgets($fp, 128); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 8f84ffd7e..c8c42d885 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -214,7 +214,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($this->_file_name_override); // If no extension was provided in the file_name config item, use the uploaded one - if(strpos($this->_file_name_override, '.') === FALSE) + if (strpos($this->_file_name_override, '.') === FALSE) { $this->file_name .= $this->file_ext; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 0d5a261f9..a24bca9b6 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -207,7 +207,7 @@ class CI_Xmlrpc { $this->data = array(); - foreach($incoming as $key => $value) + foreach ($incoming as $key => $value) { $this->data[$key] = $this->values_parsing($value); } @@ -232,7 +232,7 @@ class CI_Xmlrpc { { if (is_array($value) && array_key_exists(0, $value)) { - if ( ! isset($value['1']) OR (! isset($this->xmlrpcTypes[$value['1']]))) + if ( ! isset($value['1']) OR ( ! isset($this->xmlrpcTypes[$value['1']]))) { if (is_array($value[0])) { @@ -243,7 +243,7 @@ class CI_Xmlrpc { $temp = new XML_RPC_Values($value['0'], 'string'); } } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + elseif (is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) { while (list($k) = each($value['0'])) { @@ -281,7 +281,7 @@ class CI_Xmlrpc { $this->error = $this->result->errstr; return FALSE; } - elseif( ! is_object($this->result->val)) + elseif ( ! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -392,7 +392,7 @@ class XML_RPC_Client extends CI_Xmlrpc return $r; } - if(empty($msg->payload)) + if (empty($msg->payload)) { // $msg = XML_RPC_Messages $msg->createPayload(); @@ -553,11 +553,11 @@ class XML_RPC_Response { $kind = $xmlrpc_val->kindOf(); - if($kind == 'scalar') + if ($kind == 'scalar') { return $xmlrpc_val->scalarval(); } - elseif($kind == 'array') + elseif ($kind == 'array') { reset($xmlrpc_val->me); list($a,$b) = each($xmlrpc_val->me); @@ -565,18 +565,18 @@ class XML_RPC_Response $arr = array(); - for($i = 0; $i < $size; $i++) + for ($i = 0; $i < $size; $i++) { $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); } return $arr; } - elseif($kind == 'struct') + elseif ($kind == 'struct') { reset($xmlrpc_val->me['struct']); $arr = array(); - while(list($key,$value) = each($xmlrpc_val->me['struct'])) + while (list($key,$value) = each($xmlrpc_val->me['struct'])) { $arr[$key] = $this->xmlrpc_decoder($value); } @@ -595,10 +595,8 @@ class XML_RPC_Response $t = 0; if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + $fnc = ($utc == 1) ? 'gmmktime' : 'mktime'; + $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); } return $t; } @@ -628,7 +626,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->method_name = $method; if (is_array($pars) && count($pars) > 0) { - for($i=0; $iparams[] = $pars[$i]; @@ -646,7 +644,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->payload .= '' . $this->method_name . "\r\n"; $this->payload .= "\r\n"; - for($i=0; $iparams); $i++) + for ($i=0; $iparams); $i++) { // $p = XML_RPC_Values $p = $this->params[$i]; @@ -664,7 +662,7 @@ class XML_RPC_Message extends CI_Xmlrpc { $data = ''; - while($datum = fread($fp, 4096)) + while ($datum = fread($fp, 4096)) { $data .= $datum; } @@ -684,7 +682,7 @@ class XML_RPC_Message extends CI_Xmlrpc // Check for data //------------------------------------- - if($data == "") + if ($data == "") { error_log($this->xmlrpcstr['no_data']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); @@ -1108,7 +1106,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if( ! @isset($this->xh[$the_parser]['ac'])) + if ( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } @@ -1174,11 +1172,11 @@ class XML_RPC_Message extends CI_Xmlrpc { $kind = $param->kindOf(); - if($kind == 'scalar') + if ($kind == 'scalar') { return $param->scalarval(); } - elseif($kind == 'array') + elseif ($kind == 'array') { reset($param->me); list($a,$b) = each($param->me); @@ -1192,13 +1190,13 @@ class XML_RPC_Message extends CI_Xmlrpc return $arr; } - elseif($kind == 'struct') + elseif ($kind == 'struct') { reset($param->me['struct']); $arr = array(); - while(list($key,$value) = each($param->me['struct'])) + while (list($key,$value) = each($param->me['struct'])) { $arr[$key] = $this->decode_message($value); } @@ -1343,7 +1341,7 @@ class XML_RPC_Values extends CI_Xmlrpc // struct $rs .= "\n"; reset($val); - while(list($key2, $val2) = each($val)) + while (list($key2, $val2) = each($val)) { $rs .= "\n{$key2}\n"; $rs .= $this->serializeval($val2); diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 80633c708..666327d5c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -289,7 +289,7 @@ class CI_Zip { while (FALSE !== ($file = readdir($fp))) { - if(substr($file, 0, 1) == '.') + if (substr($file, 0, 1) == '.') { continue; } -- cgit v1.2.3-24-g4f1b From f46d9d6abdc6ae71a3307cf76f7064d0aa18eb65 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 14 Feb 2011 21:53:48 +0000 Subject: Removed Migration code for now, will come back later. --- system/libraries/Migration.php | 336 ----------------------------------------- 1 file changed, 336 deletions(-) delete mode 100644 system/libraries/Migration.php (limited to 'system/libraries') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php deleted file mode 100644 index 73c55c346..000000000 --- a/system/libraries/Migration.php +++ /dev/null @@ -1,336 +0,0 @@ - $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, '/').'/'; - - // 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 - */ - 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 = sprintf($this->lang->line('multiple_migration_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 = 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 = sprintf($this->lang->line('multiple_migrations_name'), $match[1]); - return FALSE; - } - - include $f[0]; - $class = 'Migration_' . ucfirst($match[1]); - - if ( ! class_exists($class)) - { - $this->error = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); - return FALSE; - } - - if ( ! is_callable(array($class, 'up')) || ! is_callable(array($class, 'down'))) - { - $this->error = sprintf($this->lang->line('wrong_migration_interface'), $class); - return FALSE; - } - - $migrations[] = $match[1]; - } - else - { - $this->error = sprintf($this->lang->line('invalid_migration_filename'), $file); - return FALSE; - } - } - - $this->log('Current schema version: ' . $current_version); - - $version = $i + ($step == 1 ? -1 : 0); - - // If there is nothing to do so quit - if ($migrations === array()) - { - return TRUE; - } - - $this->log('Moving ' . $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); - } - - $this->log('All done. Schema is at version '.$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()) - { - throw new Exception('no_migrations_found'); - return false; - } - - $last_migration = basename(end($migrations)); - - // Calculate the last migration step from existing migration - // filenames and procceed to the standard version migration - $last_version = intval(substr($last_migration, 0, 3)); - return $this->version($last_version); - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - $version = $this->_migration_version; - return $this->version($version); - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the latest migration - * - * @access public - * @return mixed true if already latest, false if failed, int if upgraded - */ - - protected static 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 private - * @return integer Current Schema version - */ - private function _get_version() - { - $row = $this->db->get('migrations')->row(); - return $row ? $row->version : 0; - } - - // -------------------------------------------------------------------- - - /** - * Stores the current schema version - * - * @access private - * @param $migrations integer Schema version reached - * @return void Outputs a report of the migration - */ - private function _update_version($migrations) - { - return $this->db->update('migrations', array( - 'version' => $migrations - )); - } - - // -------------------------------------------------------------------- - - /** - * Stores the current schema version - * - * @access private - * @param $migrations integer Schema version reached - * @return void Outputs a report of the migration - */ - private function log($text) - { - echo $text.'
'; - } - - // -------------------------------------------------------------------- - - /** - * Enable the use of CI super-global - * - * @access public - * @param $var - * @return mixed - */ - public function __get($var) - { - return get_instance()->$var; - } -} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f2b9c911bcee47166f3fdc8f2f57d1cafeade006 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 16 Feb 2011 16:56:37 +0000 Subject: Applied Dan's fix for the incorrectly named Sha1 class. --- system/libraries/Sha1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 05a42345a..1a657572b 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -42,7 +42,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/general/encryption.html */ -class CI_SHA { +class CI_SHA1 { public function __construct() { -- cgit v1.2.3-24-g4f1b From ba6432c6e16350c4235ee49ac0388500b28a150c Mon Sep 17 00:00:00 2001 From: tobiasbg Date: Fri, 18 Feb 2011 21:58:48 +0100 Subject: Consistent handling of 'cookie_secure' setting, also makes the variable changeable through the Session class constructor --- system/libraries/Session.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 0b94340d5..182294059 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -37,6 +37,7 @@ class CI_Session { var $cookie_prefix = ''; var $cookie_path = ''; var $cookie_domain = ''; + var $cookie_secure = FALSE; var $sess_time_to_update = 300; var $encryption_key = ''; var $flashdata_key = 'flash'; @@ -61,7 +62,7 @@ class CI_Session { // Set all the session preferences, which can either be set // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); } @@ -658,8 +659,6 @@ class CI_Session { } $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); - - $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0; // Set the cookie setcookie( @@ -668,7 +667,7 @@ class CI_Session { $expire, $this->cookie_path, $this->cookie_domain, - $secure_cookie + $this->cookie_secure ); } -- cgit v1.2.3-24-g4f1b