From edc9afa09b01f67089f121ed7054fe3a5a3b8ec2 Mon Sep 17 00:00:00 2001 From: Edwin Aw Date: Fri, 25 Jan 2013 16:12:20 +0800 Subject: Fix issue #2191. Signed-off-by: Edwin Aw --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 8734d7774..d64f6f042 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -95,7 +95,7 @@ class CI_Cart { $config = is_array($params) ? $params : array(); // Load the Sessions class - $this->CI->load->library('session', $config); + $this->CI->load->driver('session', $config); // Grab the shopping cart array from the session table $this->_cart_contents = $this->CI->session->userdata('cart_contents'); -- cgit v1.2.3-24-g4f1b From 16c6d7e8ab6b161d11c0e8dbca7dbbef58b49138 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 26 Jan 2013 17:21:29 +0100 Subject: Fix a code comment in Image_lib constant FILE_WRITE_MODE contains octal 0666 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 6d5493696..0cec43fc4 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -810,7 +810,7 @@ class CI_Image_lib { imagedestroy($dst_img); imagedestroy($src_img); - // Set the file to 777 + // Set the file to 666 @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; -- cgit v1.2.3-24-g4f1b From b75e13df03dcf898cc85e144b941e1b1f6c332be Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Sun, 27 Jan 2013 20:10:09 -0600 Subject: Fix newline standardization. Signed-off-by: Eric Roberts --- system/core/Input.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 82e22dd49..68a8fe03f 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -720,9 +720,9 @@ class CI_Input { } // Standardize newlines if needed - if ($this->_standardize_newlines === TRUE && strpos($str, "\r") !== FALSE) + if ($this->_standardize_newlines === TRUE) { - return str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str); + return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str); } return $str; -- cgit v1.2.3-24-g4f1b From db529ca1e13e9f9e1c73be20c3b92a7adc3c6aa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 11:00:02 +0200 Subject: Remove unnecessary defined('ENVIRONMENT') checks As suggested in issue #2134 & PR #2149 --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 4 ++-- system/core/Config.php | 6 +----- system/core/Hooks.php | 2 +- system/core/Loader.php | 6 +++--- system/core/Router.php | 2 +- system/database/DB.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/libraries/User_agent.php | 2 +- 11 files changed, 14 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 8affde64d..cb4b735d5 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -58,7 +58,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * Load the framework constants * ------------------------------------------------------ */ - if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php')) + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php')) { require(APPPATH.'config/'.ENVIRONMENT.'/constants.php'); } diff --git a/system/core/Common.php b/system/core/Common.php index d494caf80..90cc5b3a4 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -241,7 +241,7 @@ if ( ! function_exists('get_config')) } // Is the config file in the environment folder? - if (defined('ENVIRONMENT') && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) + if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) { require($file_path); } @@ -316,7 +316,7 @@ if ( ! function_exists('get_mimes')) { static $_mimes = array(); - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } diff --git a/system/core/Config.php b/system/core/Config.php index 0160d1a15..7e64444bc 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -106,13 +106,9 @@ class CI_Config { $file = ($file === '') ? 'config' : str_replace('.php', '', $file); $found = $loaded = FALSE; - $check_locations = defined('ENVIRONMENT') - ? array(ENVIRONMENT.'/'.$file, $file) - : array($file); - foreach ($this->_config_paths as $path) { - foreach ($check_locations as $location) + foreach (array(ENVIRONMENT.'/'.$file, $file) as $location) { $file_path = $path.'config/'.$location.'.php'; diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 2cb416c0c..59759e02e 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -81,7 +81,7 @@ class CI_Hooks { } // Grab the "hooks" definition file. - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); } diff --git a/system/core/Loader.php b/system/core/Loader.php index 1ad07f1fa..bbd7a84b6 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1089,12 +1089,12 @@ class CI_Loader { // We test for both uppercase and lowercase, for servers that // are case-sensitive with regard to file names. Check for environment // first, global next - if (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) + if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) { include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); break; } - elseif (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) + elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) { include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); break; @@ -1180,7 +1180,7 @@ class CI_Loader { */ protected function _ci_autoloader() { - if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); } diff --git a/system/core/Router.php b/system/core/Router.php index f284e29cc..4755b3712 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -133,7 +133,7 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } diff --git a/system/database/DB.php b/system/database/DB.php index f94685c51..d9104747f 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -43,7 +43,7 @@ function &DB($params = '', $query_builder_override = NULL) if (is_string($params) && strpos($params, '://') === FALSE) { // Is the config file in the environment folder? - if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')) + if ( ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php') && ! file_exists($file_path = APPPATH.'config/database.php')) { show_error('The configuration file database.php does not exist.'); diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 2d474169b..7a71eb82b 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -242,7 +242,7 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 186b24ce9..c2f50ec73 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -213,7 +213,7 @@ if ( ! function_exists('_get_smiley_array')) */ function _get_smiley_array() { - if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 1c7eeaf5f..c255c15a8 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -367,7 +367,7 @@ if ( ! function_exists('convert_accented_characters')) if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) { - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 1f4b2fa52..3fe2e0519 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -175,7 +175,7 @@ class CI_User_agent { */ protected function _load_agent_file() { - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); } -- cgit v1.2.3-24-g4f1b From 9f3a590751da2003698546c205a93fcc9c3325f8 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 04:29:06 -0600 Subject: Multiple pagination bug fixes & optimizations. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 190 ++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 83 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d139980d8..3a513a7c1 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -133,7 +133,7 @@ class CI_Pagination { * * @var int */ - protected $uri_segment = 3; + protected $uri_segment = 0; /** * Full tag open @@ -318,11 +318,9 @@ class CI_Pagination { */ public function initialize($params = array()) { - $attributes = array(); - if (isset($params['attributes']) && is_array($params['attributes'])) { - $attributes = $params['attributes']; + $this->_parse_attributes($params['attributes']); unset($params['attributes']); } @@ -334,8 +332,6 @@ class CI_Pagination { unset($params['anchor_class']); } - $this->_parse_attributes($attributes); - if (count($params) > 0) { foreach ($params as $key => $val) @@ -372,45 +368,111 @@ class CI_Pagination { return ''; } - // Set the base page index for starting page number - $base_page = ($this->use_page_numbers) ? 1 : 0; + // Check the user defined number of links. + $this->num_links = (int) $this->num_links; + + if ($this->num_links < 1) + { + show_error('Your number of links must be a positive number.'); + } - // Determine the current page number. $CI =& get_instance(); - // See if we are using a prefix or suffix on links - if ($this->prefix !== '' OR $this->suffix !== '') + // Keep any existing query string items. + // Note: Has nothing to do with any other query string option. + $get = array(); + + if ($this->reuse_query_string === TRUE) { - $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->rsegment($this->uri_segment)); + $get = $CI->input->get(); + + // Unset the controll, method, old-school routing options + unset($get['c'], $get['m'], $get[$this->query_string_segment]); } + // Put together our base and first URLs. + $this->base_url = trim($this->base_url); + + $query_string = ''; + $query_string_sep = (strpos($this->base_url, '?') === FALSE) ? '?' : '&'; + + // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - if ($CI->input->get($this->query_string_segment) != $base_page) + // If a custom first_url hasn't been specified, we'll create one from + // the base_url, but without the page item. + if ($this->first_url === '') { - $this->cur_page = (int) $CI->input->get($this->query_string_segment); + $this->first_url = $this->base_url; + + // If we saved any GET items earlier, make sure they're appended. + if ( ! empty($get)) + { + $this->first_url .= $query_string_sep . http_build_query($get); + } } + + // Add the page segment to the end of the query string, where the + // page number will be appended. + $this->base_url .= $query_string_sep . http_build_query(array_merge($get, array($this->query_string_segment => ''))); } - elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page) + else { - $this->cur_page = (int) $CI->uri->rsegment($this->uri_segment); + // Standard segment mode. + // Generate our saved query string to append later after the page number. + if ( ! empty($get)) + { + $query_string = $query_string_sep . http_build_query($get); + $this->suffix .= $query_string; + } + + // Does the base_url have the query string in it? + // If we're supposed to save it, remove it so we can append it later. + if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($this->base_url, '?')) !== FALSE) + { + $this->base_url = substr($this->base_url, 0, $base_query_pos); + } + + if ($this->first_url === '') + { + $this->first_url = $this->base_url . $query_string; + } + + $this->base_url = rtrim($this->base_url, '/') . '/'; } - // Set current page to 1 if it's not valid or if using page numbers instead of offset - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) + // Determine the current page number. + $base_page = ($this->use_page_numbers) ? 1 : 0; + + // Are we using query strings? + if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->cur_page = $base_page; + $this->cur_page = (int) $CI->input->get($this->query_string_segment); } + else + { + // Default to the last segment number if one hasn't been defined. + if ($this->uri_segment === 0) + { + $this->uri_segment = count($CI->uri->segment_array()); + } - $this->num_links = (int) $this->num_links; + $this->cur_page = $CI->uri->segment($this->uri_segment); - if ($this->num_links < 1) + // Remove any specified prefix/suffix from the segment. + $this->cur_page = ($this->prefix !== '' OR $this->suffix !== '') + ? (int) str_replace(array($this->prefix, $this->suffix), '', $this->cur_page) + : (int) $this->cur_page; + } + + // If something isn't quite right, back to the default base page. + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) { - show_error('Your number of links must be a positive number.'); + $this->cur_page = $base_page; } // Is the page number beyond the result range? - // If so we show the last page + // If so, we show the last page. if ($this->use_page_numbers) { if ($this->cur_page > $num_pages) @@ -425,80 +487,47 @@ class CI_Pagination { $uri_page_number = $this->cur_page; + // If we're using offset instead of page numbers, convert it + // to a page number, so we can generate the surrounding number links. if ( ! $this->use_page_numbers) { $this->cur_page = (int) floor(($this->cur_page/$this->per_page) + 1); } // Calculate the start and end numbers. These determine - // which number to start and end the digit links with + // which number to start and end the digit links with. $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - // Is pagination being used over GET or POST? If get, add a per_page query - // string. If post, add a trailing slash to the base URL if needed - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - $segment = (strpos($this->base_url, '?')) ? '&' : '?'; - $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'='; - } - else - { - $this->base_url = rtrim($this->base_url, '/') .'/'; - } - // And here we go... $output = ''; - $query_string = ''; - - // Add anything in the query string back to the links - // Note: Nothing to do with query_string_segment or any other query string options - if ($this->reuse_query_string === TRUE) - { - $get = $CI->input->get(); - // Unset the controll, method, old-school routing options - unset($get['c'], $get['m'], $get[$this->query_string_segment]); - - if ( ! empty($get)) - { - // Put everything else onto the end - $query_string = (strpos($this->base_url, '?') !== FALSE ? '&' : '?') - .http_build_query($get, '', '&'); - - // Add this after the suffix to put it into more links easily - $this->suffix .= $query_string; - } - } - - // Render the "First" link + // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; } - // Render the "previous" link + // Render the "Previous" link. if ($this->prev_link !== FALSE && $this->cur_page !== 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - if ($i === $base_page && $this->first_url !== '') + if ($i === $base_page) { - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + // First page + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { - $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix; + $append = $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -513,29 +542,26 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); if ($i >= $base_page) { if ($this->cur_page === $loop) { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + // Current page + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; + } + elseif ($i === $base_page) + { + // First page + $output .= $this->num_tag_open.'_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; } else { - $n = ($i === $base_page) ? '' : $i; - if ($n === '' && ! empty($this->first_url)) - { - $output .= $this->num_tag_open.'_attr_rel('start').'>' - .$loop.''.$this->num_tag_close; - } - else - { - $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'_attr_rel('start').'>' - .$loop.''.$this->num_tag_close; - } + $append = $this->prefix.$i.$this->suffix; + $output .= $this->num_tag_open.'_attr_rel('start').'>' + .$loop.''.$this->num_tag_close; } } } @@ -546,7 +572,6 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); $output .= $this->next_tag_open.'use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); $output .= $this->last_tag_open.'' -- cgit v1.2.3-24-g4f1b From 606fee0e2e0aa6a906db82e77090e91f133d7378 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 12:57:13 +0200 Subject: Fix auto_link() for the Nth time - anchor() is for local links and breaks ones that don't have a protocol prefix - Allow :// links (no actual protocol specified) - Further simplified the URL regular expression --- system/helpers/url_helper.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index a6536cf81..d0fab3fe0 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -384,22 +384,23 @@ if ( ! function_exists('auto_link')) function auto_link($str, $type = 'both', $popup = FALSE) { // Find and replace any URLs. - if ($type !== 'email' && preg_match_all('#\b(([\w-]+://?|www\.)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#', $str, $matches, PREG_OFFSET_CAPTURE)) + if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[^\s()<>;]+\w#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { // Set our target HTML if using popup links. - $target = ($popup) ? 'target="_blank"' : ''; + $target = ($popup) ? ' target="_blank"' : ''; // We process the links in reverse order (last -> first) so that // the returned string offsets from preg_match_all() are not // moved as we add more HTML. - foreach (array_reverse($matches[0]) as $match) + foreach (array_reverse($matches) as $match) { - // $match is an array generated by the PREG_OFFSET_CAPTURE flag. - // $match[0] is the matched string, $match[1] is the string offset. - - $anchor = anchor($match[0], '', $target); - - $str = substr_replace($str, $anchor, $match[1], strlen($match[0])); + // $match[0] is the matched string/link + // $match[1] is either a protocol prefix or 'www.' + // + // With PREG_OFFSET_CAPTURE, both of the above is an array, + // where the actual value is held in [0] and its offset at the [1] index. + $a = ''.$match[0][0].''; + $str = substr_replace($str, $a, $match[0][1], strlen($match[0][0])); } } -- cgit v1.2.3-24-g4f1b From 009c8f09fbe767b01453f32b28f8a8a8dd4ef7c5 Mon Sep 17 00:00:00 2001 From: gommarah Date: Mon, 28 Jan 2013 13:45:50 +0200 Subject: Upload library, clean_file_name function: Fix xss bug. For example: If you clear this string "%%3f3f" according to the $bad array will fail. The result will be "%3f" Because str_replace() replaces left to right. Signed-off-by: xeptor --- system/libraries/Upload.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 96bb17edc..86c93411e 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1005,6 +1005,13 @@ class CI_Upload { '%3d' // = ); + do + { + $old_filename = $filename; + $filename = str_replace($bad, '', $filename); + } + while ($old_filename !== $filename); + return stripslashes(str_replace($bad, '', $filename)); } -- cgit v1.2.3-24-g4f1b From 9be4cd74db158d805e0bc04c48c52a6453337c1d Mon Sep 17 00:00:00 2001 From: gommarah Date: Mon, 28 Jan 2013 13:58:35 +0200 Subject: Remove str_replace in return --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 86c93411e..1f0bd6a6e 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1012,7 +1012,7 @@ class CI_Upload { } while ($old_filename !== $filename); - return stripslashes(str_replace($bad, '', $filename)); + return stripslashes($filename); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3608e1a094945631c5b65e1f66460e4486c5b541 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 16:27:30 +0200 Subject: Libraries' filenames must be named in a ucfirst-like manner --- system/core/Loader.php | 144 ++--- system/libraries/Javascript.php | 2 +- system/libraries/Javascript/Jquery.php | 1069 ++++++++++++++++++++++++++++++++ system/libraries/Javascript/index.html | 10 + system/libraries/javascript/Jquery.php | 1069 -------------------------------- system/libraries/javascript/index.html | 10 - 6 files changed, 1140 insertions(+), 1164 deletions(-) create mode 100644 system/libraries/Javascript/Jquery.php create mode 100644 system/libraries/Javascript/index.html delete mode 100644 system/libraries/javascript/Jquery.php delete mode 100644 system/libraries/javascript/index.html (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index bbd7a84b6..3ecce1676 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -96,13 +96,6 @@ class CI_Loader { */ protected $_ci_classes = array(); - /** - * List of loaded files - * - * @var array - */ - protected $_ci_loaded_files = array(); - /** * List of loaded models * @@ -943,117 +936,100 @@ class CI_Loader { // Was the path included with the class name? // We look for a slash to determine this - $subdir = ''; if (($last_slash = strrpos($class, '/')) !== FALSE) { // Extract the path - $subdir = substr($class, 0, ++$last_slash); + $subdir = ucfirst(substr($class, 0, ++$last_slash)); // Get the filename from the path $class = substr($class, $last_slash); } + else + { + $subdir = ''; + } + + $class = ucfirst($class); + $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php'; - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) + // Is this a class extension request? + if (file_exists($subclass)) { - $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php'; + $baseclass = BASEPATH.'libraries/'.$class.'.php'; - // Is this a class extension request? - if (file_exists($subclass)) + if ( ! file_exists($baseclass)) { - $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php'; - - if ( ! file_exists($baseclass)) - { - log_message('error', 'Unable to load the requested class: '.$class); - show_error('Unable to load the requested class: '.$class); - } + log_message('error', 'Unable to load the requested class: '.$class); + show_error('Unable to load the requested class: '.$class); + } - // Safety: Was the class already loaded by a previous call? - if (in_array($subclass, $this->_ci_loaded_files)) + // Safety: Was the class already loaded by a previous call? + if (class_exists(config_item('subclass_prefix').$class, FALSE)) + { + // Before we deem this to be a duplicate request, let's see + // if a custom object name is being supplied. If so, we'll + // return a new instance of the object + if ($object_name !== NULL) { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ($object_name !== NULL) + $CI =& get_instance(); + if ( ! isset($CI->$object_name)) { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); - } + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); } - - $is_duplicate = TRUE; - log_message('debug', $class.' class already loaded. Second attempt ignored.'); - return; } - include_once($baseclass); - include_once($subclass); - $this->_ci_loaded_files[] = $subclass; - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); + log_message('debug', $class.' class already loaded. Second attempt ignored.'); + return; } - // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - foreach ($this->_ci_library_paths as $path) - { - $filepath = $path.'libraries/'.$subdir.$class.'.php'; + include_once($baseclass); + include_once($subclass); - // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) - { - continue; - } + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); + } + + // Lets search for the requested library file and load it. + foreach ($this->_ci_library_paths as $path) + { + $filepath = $path.'libraries/'.$subdir.$class.'.php'; - // Safety: Was the class already loaded by a previous call? - if (in_array($filepath, $this->_ci_loaded_files)) + // Safety: Was the class already loaded by a previous call? + if (class_exists($class, FALSE)) + { + // Before we deem this to be a duplicate request, let's see + // if a custom object name is being supplied. If so, we'll + // return a new instance of the object + if ($object_name !== NULL) { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ($object_name !== NULL) + $CI =& get_instance(); + if ( ! isset($CI->$object_name)) { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, '', $params, $object_name); - } + return $this->_ci_init_class($class, '', $params, $object_name); } - - $is_duplicate = TRUE; - log_message('debug', $class.' class already loaded. Second attempt ignored.'); - return; } - include_once($filepath); - $this->_ci_loaded_files[] = $filepath; - return $this->_ci_init_class($class, '', $params, $object_name); + log_message('debug', $class.' class already loaded. Second attempt ignored.'); + return; + } + // Does the file exist? No? Bummer... + elseif ( ! file_exists($filepath)) + { + continue; } - } // END FOREACH + + include_once($filepath); + return $this->_ci_init_class($class, '', $params, $object_name); + } // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? if ($subdir === '') { - $path = strtolower($class).'/'.$class; - return $this->_ci_load_class($path, $params, $object_name); - } - elseif (ucfirst($subdir) != $subdir) - { - // Lowercase subdir failed - retry capitalized - $path = ucfirst($subdir).$class; - return $this->_ci_load_class($path, $params, $object_name); + return $this->_ci_load_class($class.'/'.$class, $params, $object_name); } // If we got this far we were unable to find the requested class. - // We do not issue errors if the load call failed due to a duplicate request - if ($is_duplicate === FALSE) - { - log_message('error', 'Unable to load the requested class: '.$class); - show_error('Unable to load the requested class: '.$class); - } + log_message('error', 'Unable to load the requested class: '.$class); + show_error('Unable to load the requested class: '.$class); } // -------------------------------------------------------------------- diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 7f1d85511..773a58384 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -69,7 +69,7 @@ class CI_Javascript { $this->CI =& get_instance(); // load the requested js library - $this->CI->load->library('javascript/'.$js_library_driver, array('autoload' => $autoload)); + $this->CI->load->library('Javascript/'.$js_library_driver, array('autoload' => $autoload)); // make js to refer to current library $this->js =& $this->CI->$js_library_driver; diff --git a/system/libraries/Javascript/Jquery.php b/system/libraries/Javascript/Jquery.php new file mode 100644 index 000000000..b6e0434b2 --- /dev/null +++ b/system/libraries/Javascript/Jquery.php @@ -0,0 +1,1069 @@ +CI =& get_instance(); + extract($params); + + if ($autoload === TRUE) + { + $this->script(); + } + + log_message('debug', 'Jquery Class Initialized'); + } + + // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- + + /** + * Blur + * + * Outputs a jQuery blur event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _blur($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'blur'); + } + + // -------------------------------------------------------------------- + + /** + * Change + * + * Outputs a jQuery change event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _change($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'change'); + } + + // -------------------------------------------------------------------- + + /** + * Click + * + * Outputs a jQuery click event + * + * @param string The element to attach the event to + * @param string The code to execute + * @param bool whether or not to return false + * @return string + */ + protected function _click($element = 'this', $js = '', $ret_false = TRUE) + { + is_array($js) OR $js = array($js); + + if ($ret_false) + { + $js[] = 'return false;'; + } + + return $this->_add_event($element, $js, 'click'); + } + + // -------------------------------------------------------------------- + + /** + * Double Click + * + * Outputs a jQuery dblclick event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _dblclick($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'dblclick'); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Outputs a jQuery error event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _error($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'error'); + } + + // -------------------------------------------------------------------- + + /** + * Focus + * + * Outputs a jQuery focus event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _focus($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'focus'); + } + + // -------------------------------------------------------------------- + + /** + * Hover + * + * Outputs a jQuery hover event + * + * @param string - element + * @param string - Javascript code for mouse over + * @param string - Javascript code for mouse out + * @return string + */ + protected function _hover($element = 'this', $over, $out) + { + $event = "\n\t$(".$this->_prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; + + $this->jquery_code_for_compile[] = $event; + + return $event; + } + + // -------------------------------------------------------------------- + + /** + * Keydown + * + * Outputs a jQuery keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _keydown($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'keydown'); + } + + // -------------------------------------------------------------------- + + /** + * Keyup + * + * Outputs a jQuery keydown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _keyup($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'keyup'); + } + + // -------------------------------------------------------------------- + + /** + * Load + * + * Outputs a jQuery load event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _load($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'load'); + } + + // -------------------------------------------------------------------- + + /** + * Mousedown + * + * Outputs a jQuery mousedown event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mousedown($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mousedown'); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Out + * + * Outputs a jQuery mouseout event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseout($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseout'); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Over + * + * Outputs a jQuery mouseover event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseover($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseover'); + } + + // -------------------------------------------------------------------- + + /** + * Mouseup + * + * Outputs a jQuery mouseup event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _mouseup($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'mouseup'); + } + + // -------------------------------------------------------------------- + + /** + * Output + * + * Outputs script directly + * + * @param array $array_js = array() + * @return void + */ + protected function _output($array_js = array()) + { + if ( ! is_array($array_js)) + { + $array_js = array($array_js); + } + + foreach ($array_js as $js) + { + $this->jquery_code_for_compile[] = "\t".$js."\n"; + } + } + + // -------------------------------------------------------------------- + + /** + * Resize + * + * Outputs a jQuery resize event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _resize($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'resize'); + } + + // -------------------------------------------------------------------- + + /** + * Scroll + * + * Outputs a jQuery scroll event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _scroll($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'scroll'); + } + + // -------------------------------------------------------------------- + + /** + * Unload + * + * Outputs a jQuery unload event + * + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + protected function _unload($element = 'this', $js = '') + { + return $this->_add_event($element, $js, 'unload'); + } + + // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- + + /** + * Add Class + * + * Outputs a jQuery addClass event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _addClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').addClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Animate + * + * Outputs a jQuery animate event + * + * @param string $element + * @param array $params + * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds + * @param string $extra + * @return string + */ + protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + $animations = "\t\t\t"; + + foreach ($params as $param => $value) + { + $animations .= $param.": '".$value."', "; + } + + $animations = substr($animations, 0, -2); // remove the last ", " + + if ($speed !== '') + { + $speed = ', '.$speed; + } + + if ($extra !== '') + { + $extra = ', '.$extra; + } + + return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');'; + } + + // -------------------------------------------------------------------- + + /** + * Fade In + * + * Outputs a jQuery hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _fadeIn($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return "$({$element}).fadeIn({$speed}{$callback});"; + } + + // -------------------------------------------------------------------- + + /** + * Fade Out + * + * Outputs a jQuery hide event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _fadeOut($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').fadeOut('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Hide + * + * Outputs a jQuery hide action + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _hide($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return "$({$element}).hide({$speed}{$callback});"; + } + + // -------------------------------------------------------------------- + + /** + * Remove Class + * + * Outputs a jQuery remove class event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _removeClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').removeClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Up + * + * Outputs a jQuery slideUp event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideUp($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideUp('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Down + * + * Outputs a jQuery slideDown event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideDown($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideDown('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Slide Toggle + * + * Outputs a jQuery slideToggle event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _slideToggle($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').slideToggle('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Toggle + * + * Outputs a jQuery toggle event + * + * @param string - element + * @return string + */ + protected function _toggle($element = 'this') + { + $element = $this->_prep_element($element); + return '$('.$element.').toggle();'; + } + + // -------------------------------------------------------------------- + + /** + * Toggle Class + * + * Outputs a jQuery toggle class event + * + * @param string $element + * @param string $class + * @return string + */ + protected function _toggleClass($element = 'this', $class = '') + { + $element = $this->_prep_element($element); + return '$('.$element.').toggleClass("'.$class.'");'; + } + + // -------------------------------------------------------------------- + + /** + * Show + * + * Outputs a jQuery show event + * + * @param string - element + * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds + * @param string - Javascript callback function + * @return string + */ + protected function _show($element = 'this', $speed = '', $callback = '') + { + $element = $this->_prep_element($element); + $speed = $this->_validate_speed($speed); + + if ($callback !== '') + { + $callback = ", function(){\n{$callback}\n}"; + } + + return '$('.$element.').show('.$speed.$callback.');'; + } + + // -------------------------------------------------------------------- + + /** + * Updater + * + * An Ajax call that populates the designated DOM node with + * returned content + * + * @param string The element to attach the event to + * @param string the controller to run the call against + * @param string optional parameters + * @return string + */ + + protected function _updater($container = 'this', $controller, $options = '') + { + $container = $this->_prep_element($container); + $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); + + // ajaxStart and ajaxStop are better choices here... but this is a stop gap + if ($this->CI->config->item('javascript_ajax_img') === '') + { + $loading_notifier = 'Loading...'; + } + else + { + $loading_notifier = 'Loading'; + } + + $updater = '$('.$container.").empty();\n" // anything that was in... get it out + ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image + + $request_options = ''; + if ($options !== '') + { + $request_options .= ', {' + .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'") + .'}'; + } + + return $updater."\t\t$($container).load('$controller'$request_options);"; + } + + // -------------------------------------------------------------------- + // Pre-written handy stuff + // -------------------------------------------------------------------- + + /** + * Zebra tables + * + * @param string $class + * @param string $odd + * @param string $hover + * @return string + */ + protected function _zebraTables($class = '', $odd = 'odd', $hover = '') + { + $class = ($class !== '') ? '.'.$class : ''; + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $this->jquery_code_for_compile[] = $zebra; + + if ($hover !== '') + { + $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); + } + + return $zebra; + } + + // -------------------------------------------------------------------- + // Plugins + // -------------------------------------------------------------------- + + /** + * Corner Plugin + * + * @link http://www.malsup.com/jquery/corner/ + * @param string $element + * @param string $corner_style + * @return string + */ + public function corner($element = '', $corner_style = '') + { + // may want to make this configurable down the road + $corner_location = '/plugins/jquery.corner.js'; + + if ($corner_style !== '') + { + $corner_style = '"'.$corner_style.'"'; + } + + return '$('.$this->_prep_element($element).').corner('.$corner_style.');'; + } + + // -------------------------------------------------------------------- + + /** + * Modal window + * + * Load a thickbox modal window + * + * @param string $src + * @param bool $relative + * @return void + */ + public function modal($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Effect + * + * Load an Effect library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function effect($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Plugin + * + * Load a plugin library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function plugin($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * UI + * + * Load a user interface library + * + * @param string $src + * @param bool $relative + * @return void + */ + public function ui($src, $relative = FALSE) + { + $this->jquery_code_for_load[] = $this->external($src, $relative); + } + + // -------------------------------------------------------------------- + + /** + * Sortable + * + * Creates a jQuery sortable + * + * @param string $element + * @param array $options + * @return string + */ + public function sortable($element, $options = array()) + { + if (count($options) > 0) + { + $sort_options = array(); + foreach ($options as $k=>$v) + { + $sort_options[] = "\n\t\t".$k.': '.$v; + } + $sort_options = implode(',', $sort_options); + } + else + { + $sort_options = ''; + } + + return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});"; + } + + // -------------------------------------------------------------------- + + /** + * Table Sorter Plugin + * + * @param string table name + * @param string plugin location + * @return string + */ + public function tablesorter($table = '', $options = '') + { + $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n"; + } + + // -------------------------------------------------------------------- + // Class functions + // -------------------------------------------------------------------- + + /** + * Add Event + * + * Constructs the syntax for an event, and adds to into the array for compilation + * + * @param string The element to attach the event to + * @param string The code to execute + * @param string The event to pass + * @return string + */ + protected function _add_event($element, $js, $event) + { + if (is_array($js)) + { + $js = implode("\n\t\t", $js); + + } + + $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n"; + $this->jquery_code_for_compile[] = $event; + return $event; + } + + // -------------------------------------------------------------------- + + /** + * Compile + * + * As events are specified, they are stored in an array + * This funciton compiles them all for output on a page + * + * @param string $view_var + * @param bool $script_tags + * @return void + */ + protected function _compile($view_var = 'script_foot', $script_tags = TRUE) + { + // External references + $external_scripts = implode('', $this->jquery_code_for_load); + $this->CI->load->vars(array('library_src' => $external_scripts)); + + if (count($this->jquery_code_for_compile) === 0) + { + // no inline references, let's just return + return; + } + + // Inline references + $script = '$(document).ready(function() {'."\n" + .implode('', $this->jquery_code_for_compile) + .'});'; + + $output = ($script_tags === FALSE) ? $script : $this->inline($script); + + $this->CI->load->vars(array($view_var => $output)); + } + + // -------------------------------------------------------------------- + + /** + * Clear Compile + * + * Clears the array of script events collected for output + * + * @return void + */ + protected function _clear_compile() + { + $this->jquery_code_for_compile = array(); + } + + // -------------------------------------------------------------------- + + /** + * Document Ready + * + * A wrapper for writing document.ready() + * + * @param array $js + * @return void + */ + protected function _document_ready($js) + { + is_array($js) OR $js = array($js); + + foreach ($js as $script) + { + $this->jquery_code_for_compile[] = $script; + } + } + + // -------------------------------------------------------------------- + + /** + * Script Tag + * + * Outputs the script tag that loads the jquery.js file into an HTML document + * + * @param string $library_src + * @param bool $relative + * @return string + */ + public function script($library_src = '', $relative = FALSE) + { + $library_src = $this->external($library_src, $relative); + $this->jquery_code_for_load[] = $library_src; + return $library_src; + } + + // -------------------------------------------------------------------- + + /** + * Prep Element + * + * Puts HTML element in quotes for use in jQuery code + * unless the supplied element is the Javascript 'this' + * object, in which case no quotes are added + * + * @param string + * @return string + */ + protected function _prep_element($element) + { + if ($element !== 'this') + { + $element = '"'.$element.'"'; + } + + return $element; + } + + // -------------------------------------------------------------------- + + /** + * Validate Speed + * + * Ensures the speed parameter is valid for jQuery + * + * @param string + * @return string + */ + protected function _validate_speed($speed) + { + if (in_array($speed, array('slow', 'normal', 'fast'))) + { + return '"'.$speed.'"'; + } + elseif (preg_match('/[^0-9]/', $speed)) + { + return ''; + } + + return $speed; + } + +} + +/* End of file Jquery.php */ +/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file diff --git a/system/libraries/Javascript/index.html b/system/libraries/Javascript/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/libraries/Javascript/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php deleted file mode 100644 index b6e0434b2..000000000 --- a/system/libraries/javascript/Jquery.php +++ /dev/null @@ -1,1069 +0,0 @@ -CI =& get_instance(); - extract($params); - - if ($autoload === TRUE) - { - $this->script(); - } - - log_message('debug', 'Jquery Class Initialized'); - } - - // -------------------------------------------------------------------- - // Event Code - // -------------------------------------------------------------------- - - /** - * Blur - * - * Outputs a jQuery blur event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _blur($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'blur'); - } - - // -------------------------------------------------------------------- - - /** - * Change - * - * Outputs a jQuery change event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _change($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'change'); - } - - // -------------------------------------------------------------------- - - /** - * Click - * - * Outputs a jQuery click event - * - * @param string The element to attach the event to - * @param string The code to execute - * @param bool whether or not to return false - * @return string - */ - protected function _click($element = 'this', $js = '', $ret_false = TRUE) - { - is_array($js) OR $js = array($js); - - if ($ret_false) - { - $js[] = 'return false;'; - } - - return $this->_add_event($element, $js, 'click'); - } - - // -------------------------------------------------------------------- - - /** - * Double Click - * - * Outputs a jQuery dblclick event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _dblclick($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'dblclick'); - } - - // -------------------------------------------------------------------- - - /** - * Error - * - * Outputs a jQuery error event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _error($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'error'); - } - - // -------------------------------------------------------------------- - - /** - * Focus - * - * Outputs a jQuery focus event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _focus($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'focus'); - } - - // -------------------------------------------------------------------- - - /** - * Hover - * - * Outputs a jQuery hover event - * - * @param string - element - * @param string - Javascript code for mouse over - * @param string - Javascript code for mouse out - * @return string - */ - protected function _hover($element = 'this', $over, $out) - { - $event = "\n\t$(".$this->_prep_element($element).").hover(\n\t\tfunction()\n\t\t{\n\t\t\t{$over}\n\t\t}, \n\t\tfunction()\n\t\t{\n\t\t\t{$out}\n\t\t});\n"; - - $this->jquery_code_for_compile[] = $event; - - return $event; - } - - // -------------------------------------------------------------------- - - /** - * Keydown - * - * Outputs a jQuery keydown event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _keydown($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'keydown'); - } - - // -------------------------------------------------------------------- - - /** - * Keyup - * - * Outputs a jQuery keydown event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _keyup($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'keyup'); - } - - // -------------------------------------------------------------------- - - /** - * Load - * - * Outputs a jQuery load event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _load($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'load'); - } - - // -------------------------------------------------------------------- - - /** - * Mousedown - * - * Outputs a jQuery mousedown event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _mousedown($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mousedown'); - } - - // -------------------------------------------------------------------- - - /** - * Mouse Out - * - * Outputs a jQuery mouseout event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _mouseout($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseout'); - } - - // -------------------------------------------------------------------- - - /** - * Mouse Over - * - * Outputs a jQuery mouseover event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _mouseover($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseover'); - } - - // -------------------------------------------------------------------- - - /** - * Mouseup - * - * Outputs a jQuery mouseup event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _mouseup($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'mouseup'); - } - - // -------------------------------------------------------------------- - - /** - * Output - * - * Outputs script directly - * - * @param array $array_js = array() - * @return void - */ - protected function _output($array_js = array()) - { - if ( ! is_array($array_js)) - { - $array_js = array($array_js); - } - - foreach ($array_js as $js) - { - $this->jquery_code_for_compile[] = "\t".$js."\n"; - } - } - - // -------------------------------------------------------------------- - - /** - * Resize - * - * Outputs a jQuery resize event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _resize($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'resize'); - } - - // -------------------------------------------------------------------- - - /** - * Scroll - * - * Outputs a jQuery scroll event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _scroll($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'scroll'); - } - - // -------------------------------------------------------------------- - - /** - * Unload - * - * Outputs a jQuery unload event - * - * @param string The element to attach the event to - * @param string The code to execute - * @return string - */ - protected function _unload($element = 'this', $js = '') - { - return $this->_add_event($element, $js, 'unload'); - } - - // -------------------------------------------------------------------- - // Effects - // -------------------------------------------------------------------- - - /** - * Add Class - * - * Outputs a jQuery addClass event - * - * @param string $element - * @param string $class - * @return string - */ - protected function _addClass($element = 'this', $class = '') - { - $element = $this->_prep_element($element); - return '$('.$element.').addClass("'.$class.'");'; - } - - // -------------------------------------------------------------------- - - /** - * Animate - * - * Outputs a jQuery animate event - * - * @param string $element - * @param array $params - * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds - * @param string $extra - * @return string - */ - protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - $animations = "\t\t\t"; - - foreach ($params as $param => $value) - { - $animations .= $param.": '".$value."', "; - } - - $animations = substr($animations, 0, -2); // remove the last ", " - - if ($speed !== '') - { - $speed = ', '.$speed; - } - - if ($extra !== '') - { - $extra = ', '.$extra; - } - - return "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.');'; - } - - // -------------------------------------------------------------------- - - /** - * Fade In - * - * Outputs a jQuery hide event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _fadeIn($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return "$({$element}).fadeIn({$speed}{$callback});"; - } - - // -------------------------------------------------------------------- - - /** - * Fade Out - * - * Outputs a jQuery hide event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _fadeOut($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return '$('.$element.').fadeOut('.$speed.$callback.');'; - } - - // -------------------------------------------------------------------- - - /** - * Hide - * - * Outputs a jQuery hide action - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _hide($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return "$({$element}).hide({$speed}{$callback});"; - } - - // -------------------------------------------------------------------- - - /** - * Remove Class - * - * Outputs a jQuery remove class event - * - * @param string $element - * @param string $class - * @return string - */ - protected function _removeClass($element = 'this', $class = '') - { - $element = $this->_prep_element($element); - return '$('.$element.').removeClass("'.$class.'");'; - } - - // -------------------------------------------------------------------- - - /** - * Slide Up - * - * Outputs a jQuery slideUp event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _slideUp($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return '$('.$element.').slideUp('.$speed.$callback.');'; - } - - // -------------------------------------------------------------------- - - /** - * Slide Down - * - * Outputs a jQuery slideDown event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _slideDown($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return '$('.$element.').slideDown('.$speed.$callback.');'; - } - - // -------------------------------------------------------------------- - - /** - * Slide Toggle - * - * Outputs a jQuery slideToggle event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _slideToggle($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return '$('.$element.').slideToggle('.$speed.$callback.');'; - } - - // -------------------------------------------------------------------- - - /** - * Toggle - * - * Outputs a jQuery toggle event - * - * @param string - element - * @return string - */ - protected function _toggle($element = 'this') - { - $element = $this->_prep_element($element); - return '$('.$element.').toggle();'; - } - - // -------------------------------------------------------------------- - - /** - * Toggle Class - * - * Outputs a jQuery toggle class event - * - * @param string $element - * @param string $class - * @return string - */ - protected function _toggleClass($element = 'this', $class = '') - { - $element = $this->_prep_element($element); - return '$('.$element.').toggleClass("'.$class.'");'; - } - - // -------------------------------------------------------------------- - - /** - * Show - * - * Outputs a jQuery show event - * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function - * @return string - */ - protected function _show($element = 'this', $speed = '', $callback = '') - { - $element = $this->_prep_element($element); - $speed = $this->_validate_speed($speed); - - if ($callback !== '') - { - $callback = ", function(){\n{$callback}\n}"; - } - - return '$('.$element.').show('.$speed.$callback.');'; - } - - // -------------------------------------------------------------------- - - /** - * Updater - * - * An Ajax call that populates the designated DOM node with - * returned content - * - * @param string The element to attach the event to - * @param string the controller to run the call against - * @param string optional parameters - * @return string - */ - - protected function _updater($container = 'this', $controller, $options = '') - { - $container = $this->_prep_element($container); - $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); - - // ajaxStart and ajaxStop are better choices here... but this is a stop gap - if ($this->CI->config->item('javascript_ajax_img') === '') - { - $loading_notifier = 'Loading...'; - } - else - { - $loading_notifier = 'Loading'; - } - - $updater = '$('.$container.").empty();\n" // anything that was in... get it out - ."\t\t$(".$container.').prepend("'.$loading_notifier."\");\n"; // to replace with an image - - $request_options = ''; - if ($options !== '') - { - $request_options .= ', {' - .(is_array($options) ? "'".implode("', '", $options)."'" : "'".str_replace(':', "':'", $options)."'") - .'}'; - } - - return $updater."\t\t$($container).load('$controller'$request_options);"; - } - - // -------------------------------------------------------------------- - // Pre-written handy stuff - // -------------------------------------------------------------------- - - /** - * Zebra tables - * - * @param string $class - * @param string $odd - * @param string $hover - * @return string - */ - protected function _zebraTables($class = '', $odd = 'odd', $hover = '') - { - $class = ($class !== '') ? '.'.$class : ''; - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; - - $this->jquery_code_for_compile[] = $zebra; - - if ($hover !== '') - { - $hover = $this->hover("table{$class} tbody tr", "$(this).addClass('hover');", "$(this).removeClass('hover');"); - } - - return $zebra; - } - - // -------------------------------------------------------------------- - // Plugins - // -------------------------------------------------------------------- - - /** - * Corner Plugin - * - * @link http://www.malsup.com/jquery/corner/ - * @param string $element - * @param string $corner_style - * @return string - */ - public function corner($element = '', $corner_style = '') - { - // may want to make this configurable down the road - $corner_location = '/plugins/jquery.corner.js'; - - if ($corner_style !== '') - { - $corner_style = '"'.$corner_style.'"'; - } - - return '$('.$this->_prep_element($element).').corner('.$corner_style.');'; - } - - // -------------------------------------------------------------------- - - /** - * Modal window - * - * Load a thickbox modal window - * - * @param string $src - * @param bool $relative - * @return void - */ - public function modal($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * Effect - * - * Load an Effect library - * - * @param string $src - * @param bool $relative - * @return void - */ - public function effect($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * Plugin - * - * Load a plugin library - * - * @param string $src - * @param bool $relative - * @return void - */ - public function plugin($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * UI - * - * Load a user interface library - * - * @param string $src - * @param bool $relative - * @return void - */ - public function ui($src, $relative = FALSE) - { - $this->jquery_code_for_load[] = $this->external($src, $relative); - } - - // -------------------------------------------------------------------- - - /** - * Sortable - * - * Creates a jQuery sortable - * - * @param string $element - * @param array $options - * @return string - */ - public function sortable($element, $options = array()) - { - if (count($options) > 0) - { - $sort_options = array(); - foreach ($options as $k=>$v) - { - $sort_options[] = "\n\t\t".$k.': '.$v; - } - $sort_options = implode(',', $sort_options); - } - else - { - $sort_options = ''; - } - - return '$('.$this->_prep_element($element).').sortable({'.$sort_options."\n\t});"; - } - - // -------------------------------------------------------------------- - - /** - * Table Sorter Plugin - * - * @param string table name - * @param string plugin location - * @return string - */ - public function tablesorter($table = '', $options = '') - { - $this->jquery_code_for_compile[] = "\t$(".$this->_prep_element($table).').tablesorter('.$options.");\n"; - } - - // -------------------------------------------------------------------- - // Class functions - // -------------------------------------------------------------------- - - /** - * Add Event - * - * Constructs the syntax for an event, and adds to into the array for compilation - * - * @param string The element to attach the event to - * @param string The code to execute - * @param string The event to pass - * @return string - */ - protected function _add_event($element, $js, $event) - { - if (is_array($js)) - { - $js = implode("\n\t\t", $js); - - } - - $event = "\n\t$(".$this->_prep_element($element).').'.$event."(function(){\n\t\t{$js}\n\t});\n"; - $this->jquery_code_for_compile[] = $event; - return $event; - } - - // -------------------------------------------------------------------- - - /** - * Compile - * - * As events are specified, they are stored in an array - * This funciton compiles them all for output on a page - * - * @param string $view_var - * @param bool $script_tags - * @return void - */ - protected function _compile($view_var = 'script_foot', $script_tags = TRUE) - { - // External references - $external_scripts = implode('', $this->jquery_code_for_load); - $this->CI->load->vars(array('library_src' => $external_scripts)); - - if (count($this->jquery_code_for_compile) === 0) - { - // no inline references, let's just return - return; - } - - // Inline references - $script = '$(document).ready(function() {'."\n" - .implode('', $this->jquery_code_for_compile) - .'});'; - - $output = ($script_tags === FALSE) ? $script : $this->inline($script); - - $this->CI->load->vars(array($view_var => $output)); - } - - // -------------------------------------------------------------------- - - /** - * Clear Compile - * - * Clears the array of script events collected for output - * - * @return void - */ - protected function _clear_compile() - { - $this->jquery_code_for_compile = array(); - } - - // -------------------------------------------------------------------- - - /** - * Document Ready - * - * A wrapper for writing document.ready() - * - * @param array $js - * @return void - */ - protected function _document_ready($js) - { - is_array($js) OR $js = array($js); - - foreach ($js as $script) - { - $this->jquery_code_for_compile[] = $script; - } - } - - // -------------------------------------------------------------------- - - /** - * Script Tag - * - * Outputs the script tag that loads the jquery.js file into an HTML document - * - * @param string $library_src - * @param bool $relative - * @return string - */ - public function script($library_src = '', $relative = FALSE) - { - $library_src = $this->external($library_src, $relative); - $this->jquery_code_for_load[] = $library_src; - return $library_src; - } - - // -------------------------------------------------------------------- - - /** - * Prep Element - * - * Puts HTML element in quotes for use in jQuery code - * unless the supplied element is the Javascript 'this' - * object, in which case no quotes are added - * - * @param string - * @return string - */ - protected function _prep_element($element) - { - if ($element !== 'this') - { - $element = '"'.$element.'"'; - } - - return $element; - } - - // -------------------------------------------------------------------- - - /** - * Validate Speed - * - * Ensures the speed parameter is valid for jQuery - * - * @param string - * @return string - */ - protected function _validate_speed($speed) - { - if (in_array($speed, array('slow', 'normal', 'fast'))) - { - return '"'.$speed.'"'; - } - elseif (preg_match('/[^0-9]/', $speed)) - { - return ''; - } - - return $speed; - } - -} - -/* End of file Jquery.php */ -/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file diff --git a/system/libraries/javascript/index.html b/system/libraries/javascript/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/libraries/javascript/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 55bbd7207d5276a7546e60f28c4c31325bab2b5e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 19:02:13 +0200 Subject: Fix issue #2179 --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index ac377d996..c7bc4a699 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -937,7 +937,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape); if ($this->qb_caching === TRUE) { - $this->qb_cache_where[] = $like_statement; + $this->qb_cache_where[] = array('condition' => $like_statement, 'escape' => $escape); $this->qb_cache_exists[] = 'where'; } } -- cgit v1.2.3-24-g4f1b From 662e34291a2d5d8997ea9835701fb9a8a7ec244c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 21:19:13 +0200 Subject: Some micro-optimization to the Driver library loader --- system/libraries/Driver.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 4b35dce73..382420db0 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -80,8 +80,7 @@ class CI_Driver_Library { public function load_driver($child) { // Get CodeIgniter instance and subclass prefix - $CI = get_instance(); - $prefix = (string) $CI->config->item('subclass_prefix'); + $prefix = config_item('subclass_prefix'); if ( ! isset($this->lib_name)) { @@ -102,11 +101,12 @@ class CI_Driver_Library { } // Get package paths and filename case variations to search + $CI = get_instance(); $paths = $CI->load->get_package_paths(TRUE); // Is there an extension? $class_name = $prefix.$child_name; - $found = class_exists($class_name); + $found = class_exists($class_name, FALSE); if ( ! $found) { // Check for subclass file @@ -126,8 +126,8 @@ class CI_Driver_Library { } // Include both sources and mark found - include($basepath); - include($file); + include_once($basepath); + include_once($file); $found = TRUE; break; } @@ -139,8 +139,7 @@ class CI_Driver_Library { { // Use standard class name $class_name = 'CI_'.$child_name; - $found = class_exists($class_name); - if ( ! $found) + if ( ! class_exists($class_name, FALSE)) { // Check package paths foreach ($paths as $path) @@ -150,7 +149,7 @@ class CI_Driver_Library { if (file_exists($file)) { // Include source - include($file); + include_once($file); break; } } @@ -158,9 +157,9 @@ class CI_Driver_Library { } // Did we finally find the class? - if ( ! class_exists($class_name)) + if ( ! class_exists($class_name, FALSE)) { - if (class_exists($child_name)) + if (class_exists($child_name, FALSE)) { $class_name = $child_name; } -- cgit v1.2.3-24-g4f1b From c26d34ff12458760eb843454d3224e1dad1fb2e0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 21:46:08 +0200 Subject: Fix issue #2202 and alter Loader Class docs --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 3ecce1676..00ca35199 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -939,7 +939,7 @@ class CI_Loader { if (($last_slash = strrpos($class, '/')) !== FALSE) { // Extract the path - $subdir = ucfirst(substr($class, 0, ++$last_slash)); + $subdir = substr($class, 0, ++$last_slash); // Get the filename from the path $class = substr($class, $last_slash); -- cgit v1.2.3-24-g4f1b From 9668d1d56d39187aa26f058495ca666e3544cbe2 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 17:45:34 -0600 Subject: Remove spaces from concats. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3a513a7c1..76754046b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -408,13 +408,13 @@ class CI_Pagination { // If we saved any GET items earlier, make sure they're appended. if ( ! empty($get)) { - $this->first_url .= $query_string_sep . http_build_query($get); + $this->first_url .= $query_string_sep.http_build_query($get); } } // Add the page segment to the end of the query string, where the // page number will be appended. - $this->base_url .= $query_string_sep . http_build_query(array_merge($get, array($this->query_string_segment => ''))); + $this->base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); } else { @@ -422,7 +422,7 @@ class CI_Pagination { // Generate our saved query string to append later after the page number. if ( ! empty($get)) { - $query_string = $query_string_sep . http_build_query($get); + $query_string = $query_string_sep.http_build_query($get); $this->suffix .= $query_string; } @@ -435,10 +435,10 @@ class CI_Pagination { if ($this->first_url === '') { - $this->first_url = $this->base_url . $query_string; + $this->first_url = $this->base_url.$query_string; } - $this->base_url = rtrim($this->base_url, '/') . '/'; + $this->base_url = rtrim($this->base_url, '/').'/'; } // Determine the current page number. -- cgit v1.2.3-24-g4f1b From b835a4f3b3f8fccd7ce457d4ab13344d3dcb91a9 Mon Sep 17 00:00:00 2001 From: Chris Buckley Date: Mon, 28 Jan 2013 23:35:13 +0000 Subject: Fix list_fields seek bug On the first list_fields call, the field pointer is moved to the end of the list of fields. This change ensures that the pointer is positioned at the start of the field list before grabbing the names. Signed-off-by: Chris Buckley --- system/database/drivers/mssql/mssql_result.php | 1 + system/database/drivers/mysql/mysql_result.php | 1 + system/database/drivers/mysqli/mysqli_result.php | 1 + 3 files changed, 3 insertions(+) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index ea3f8e4d1..b6e5f2b17 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -74,6 +74,7 @@ class CI_DB_mssql_result extends CI_DB_result { public function list_fields() { $field_names = array(); + mssql_field_seek($this->result_id, 0); while ($field = mssql_fetch_field($this->result_id)) { $field_names[] = $field->name; diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 1ed2759b6..a2affcb58 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -89,6 +89,7 @@ class CI_DB_mysql_result extends CI_DB_result { public function list_fields() { $field_names = array(); + mysql_field_seek($this->result_id, 0); while ($field = mysql_fetch_field($this->result_id)) { $field_names[] = $field->name; diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 4105f99f6..3fe05f9c5 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -74,6 +74,7 @@ class CI_DB_mysqli_result extends CI_DB_result { public function list_fields() { $field_names = array(); + $this->result_id->field_seek(0); while ($field = $this->result_id->fetch_field()) { $field_names[] = $field->name; -- cgit v1.2.3-24-g4f1b From ba67f3bb595817115a15f6c3249e41e7c85f2ce4 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 18:01:01 -0600 Subject: Move $get assignment to if/else. Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 76754046b..562a2d3eb 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -380,8 +380,6 @@ class CI_Pagination { // Keep any existing query string items. // Note: Has nothing to do with any other query string option. - $get = array(); - if ($this->reuse_query_string === TRUE) { $get = $CI->input->get(); @@ -389,6 +387,10 @@ class CI_Pagination { // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); } + else + { + $get = array(); + } // Put together our base and first URLs. $this->base_url = trim($this->base_url); -- cgit v1.2.3-24-g4f1b From 032af98ab94482cc7c5b10013ec033acfdc34c74 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 28 Jan 2013 23:25:52 -0600 Subject: Replace is_numeric() with ctype_digit() Signed-off-by: Eric Roberts --- system/libraries/Pagination.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 562a2d3eb..438d6c477 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -449,7 +449,8 @@ class CI_Pagination { // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->cur_page = (int) $CI->input->get($this->query_string_segment); + // Cast as string for use in ctype_digit() later. + $this->cur_page = (string) $CI->input->get($this->query_string_segment); } else { @@ -459,19 +460,25 @@ class CI_Pagination { $this->uri_segment = count($CI->uri->segment_array()); } - $this->cur_page = $CI->uri->segment($this->uri_segment); + $this->cur_page = (string) $CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. - $this->cur_page = ($this->prefix !== '' OR $this->suffix !== '') - ? (int) str_replace(array($this->prefix, $this->suffix), '', $this->cur_page) - : (int) $this->cur_page; + if ($this->prefix !== '' OR $this->suffix !== '') + { + $this->cur_page = str_replace(array($this->prefix, $this->suffix), '', $this->cur_page); + } } // If something isn't quite right, back to the default base page. - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page === 0)) + if ( ! ctype_digit($this->cur_page) OR ($this->use_page_numbers && (int) $this->cur_page === 0)) { $this->cur_page = $base_page; } + else + { + // Make sure we're using integers for comparisons later. + $this->cur_page = (int) $this->cur_page; + } // Is the page number beyond the result range? // If so, we show the last page. -- cgit v1.2.3-24-g4f1b From 0687911229be13e100724dbf8b15b95146b591a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 29 Jan 2013 15:05:02 +0200 Subject: Replace is_file() with the faster file_exists() (where it makes sense) Also: - Implemented caching of configuration arrays for smileys, foreign characters and doctypes. - Implemented cascading-style loading of configuration files (except for library configs, DB and constants.php). --- system/core/Common.php | 4 ++-- system/core/Hooks.php | 5 +++-- system/core/Router.php | 9 +++++---- system/helpers/download_helper.php | 2 +- system/helpers/html_helper.php | 20 ++++++++++++-------- system/helpers/smiley_helper.php | 28 +++++++++++++++++++++------- system/helpers/text_helper.php | 22 +++++++++++++--------- system/libraries/User_agent.php | 13 ++++++++----- 8 files changed, 65 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 90cc5b3a4..258cd4967 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -316,11 +316,11 @@ if ( ! function_exists('get_mimes')) { static $_mimes = array(); - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } - elseif (is_file(APPPATH.'config/mimes.php')) + elseif (file_exists(APPPATH.'config/mimes.php')) { $_mimes = include(APPPATH.'config/mimes.php'); } diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 59759e02e..17f6a027e 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -81,11 +81,12 @@ class CI_Hooks { } // Grab the "hooks" definition file. - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); } - elseif (is_file(APPPATH.'config/hooks.php')) + + if (file_exists(APPPATH.'config/hooks.php')) { include(APPPATH.'config/hooks.php'); } diff --git a/system/core/Router.php b/system/core/Router.php index 4755b3712..bb0ce16bd 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -133,13 +133,14 @@ class CI_Router { } // Load the routes.php file. - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (file_exists(APPPATH.'config/routes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + include(APPPATH.'config/routes.php'); } - elseif (is_file(APPPATH.'config/routes.php')) + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { - include(APPPATH.'config/routes.php'); + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } $this->routes = (empty($route) OR ! is_array($route)) ? array() : $route; diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 7294d50c5..4fe6a0e88 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -58,7 +58,7 @@ if ( ! function_exists('force_download')) } elseif ($data === NULL) { - if (@is_file($filename) && @file_exists($filename) && ($filesize = @filesize($filename)) !== FALSE) + if (@is_file($filename) && ($filesize = @filesize($filename)) !== FALSE) { $filepath = $filename; $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 7a71eb82b..80a27876f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -238,26 +238,30 @@ if ( ! function_exists('doctype')) */ function doctype($type = 'xhtml1-strict') { - global $_doctypes; + static $doctypes; - if ( ! is_array($_doctypes)) + if ( ! is_array($doctypes)) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + if (file_exists(APPPATH.'config/doctypes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); + include(APPPATH.'config/doctypes.php'); } - elseif (is_file(APPPATH.'config/doctypes.php')) + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { - include(APPPATH.'config/doctypes.php'); + include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } - if ( ! is_array($_doctypes)) + if (empty($_doctypes) OR ! is_array($_doctypes)) { + $doctypes = array(); return FALSE; } + + $doctypes = $_doctypes; } - return isset($_doctypes[$type]) ? $_doctypes[$type] : FALSE; + return isset($doctypes[$type]) ? $doctypes[$type] : FALSE; } } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index c2f50ec73..d9a693493 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -213,16 +213,30 @@ if ( ! function_exists('_get_smiley_array')) */ function _get_smiley_array() { - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); - } - elseif (file_exists(APPPATH.'config/smileys.php')) + static $_smileys; + + if ( ! is_array($smileys)) { - include(APPPATH.'config/smileys.php'); + if (file_exists(APPPATH.'config/smileys.php')) + { + include(APPPATH.'config/smileys.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); + } + + if (empty($smileys) OR ! is_array($smileys)) + { + $_smileys = array(); + return FALSE; + } + + $_smileys = $smileys; } - return (isset($smileys) && is_array($smileys)) ? $smileys : FALSE; + return $_smileys; } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index c255c15a8..54db14f94 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -358,31 +358,35 @@ if ( ! function_exists('convert_accented_characters')) /** * Convert Accented Foreign Characters to ASCII * - * @param string the text string + * @param string $str Input string * @return string */ function convert_accented_characters($str) { - global $foreign_characters; + static $_foreign_characters; - if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) + if ( ! is_array($_foreign_characters)) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + if (file_exists(APPPATH.'config/foreign_chars.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); + include(APPPATH.'config/foreign_chars.php'); } - elseif (is_file(APPPATH.'config/foreign_chars.php')) + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { - include(APPPATH.'config/foreign_chars.php'); + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } - if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) + if (empty($foreign_characters) OR ! is_array($foreign_characters)) { + $_foreign_characters = array(); return $str; } + + $_foreign_characters = $foreign_characters; } - return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str); + return preg_replace(array_keys($_foreign_characters), array_values($_foreign_characters), $str); } } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 3fe2e0519..2f6f81909 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -175,15 +175,18 @@ class CI_User_agent { */ protected function _load_agent_file() { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) + if (($found = file_exists(APPPATH.'config/user_agents.php'))) { - include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); + include(APPPATH.'config/user_agents.php'); } - elseif (is_file(APPPATH.'config/user_agents.php')) + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { - include(APPPATH.'config/user_agents.php'); + include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); + $found = TRUE; } - else + + if ($found !== TRUE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 7e5597782a589e4171ca08abdd9ce1a185542ff4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 29 Jan 2013 15:38:33 +0200 Subject: Replace CI_Upload::clean_file_name() usage with CI_Security::sanitize_filename() Also applied @xeptor's fix (a big thanks) to the sanitize_filename() method and added a changelog entry for it - fixes issue #73. --- system/core/Security.php | 10 ++++++++- system/libraries/Upload.php | 50 ++------------------------------------------- 2 files changed, 11 insertions(+), 49 deletions(-) (limited to 'system') diff --git a/system/core/Security.php b/system/core/Security.php index a6cd14a5f..7aae54efc 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -576,7 +576,15 @@ class CI_Security { } $str = remove_invisible_characters($str, FALSE); - return stripslashes(str_replace($bad, '', $str)); + + do + { + $old = $str; + $str = str_replace($bad, '', $str); + } + while ($old !== $str); + + return stripslashes($str); } // ---------------------------------------------------------------- diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 1f0bd6a6e..814ea68a4 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -463,7 +463,8 @@ class CI_Upload { } // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); + $CI =& get_instance(); + $this->file_name = $CI->security->sanitize_filename($this->file_name); // Truncate the file name if it's too long if ($this->max_filename > 0) @@ -970,53 +971,6 @@ class CI_Upload { // -------------------------------------------------------------------- - /** - * Clean the file name for security - * - * @param string $filename - * @return string - */ - public function clean_file_name($filename) - { - $bad = array( - '', - "'", '"', - '<', '>', - '&', '$', - '=', - ';', - '?', - '/', - '!', - '#', - '%20', - '%22', - '%3c', // < - '%253c', // < - '%3e', // > - '%0e', // > - '%28', // ( - '%29', // ) - '%2528', // ( - '%26', // & - '%24', // $ - '%3f', // ? - '%3b', // ; - '%3d' // = - ); - - do - { - $old_filename = $filename; - $filename = str_replace($bad, '', $filename); - } - while ($old_filename !== $filename); - - return stripslashes($filename); - } - - // -------------------------------------------------------------------- - /** * Limit the File Name Length * -- cgit v1.2.3-24-g4f1b From 8151cbb586edf565a57e33287b01222d9c4a85b6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 30 Jan 2013 13:57:56 +0200 Subject: Fix/improve #2211 --- system/libraries/Migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index fd915c382..b673e9cb7 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -104,8 +104,8 @@ class CI_Migration { */ public function __construct($config = array()) { - # Only run this constructor on main library load - if (get_parent_class($this) !== FALSE) + // Only run this constructor on main library load + if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE)) { return; } -- cgit v1.2.3-24-g4f1b From 3683723212c1de682c4e026df28fe3b03b4ea404 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 30 Jan 2013 23:18:50 +0800 Subject: core comment error. Signed-off-by: Bo-Yi Wu --- system/core/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index cd3c17e1e..f5d091e14 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -179,4 +179,4 @@ class CI_Log { } /* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ \ No newline at end of file +/* Location: ./system/core/Log.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2d1608a6325d55ab31c55c27c31052c2daa76e46 Mon Sep 17 00:00:00 2001 From: Sajan Parikh Date: Sat, 2 Feb 2013 08:00:39 -0600 Subject: Added Form Validation rule for alphanum + spaces. Signed-off-by: Sajan Parikh --- system/libraries/Form_validation.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index bbd0b523e..7b9215c04 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1229,6 +1229,21 @@ class CI_Form_validation { return ctype_alnum((string) $str); } + // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric w/ spaces + * + * @param string + * @return bool + */ + public function alpha_numeric_spaces($str) + { + return (bool) preg_match('#^[A-Z0-9 ]+$#i', $str); + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 9c0b890bb15394d8d6d976df65a9aa7c19c1c33d Mon Sep 17 00:00:00 2001 From: Sajan Parikh Date: Sat, 2 Feb 2013 08:56:35 -0600 Subject: Added error message in lang file. Signed-off-by: Sajan Parikh --- system/language/english/form_validation_lang.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index 3fb007dd2..476123b06 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -28,20 +28,21 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $lang['form_validation_required'] = 'The {field} field is required.'; $lang['form_validation_isset'] = 'The {field} field must have a value.'; -$lang['form_validation_valid_email'] = 'The {field} field must contain a valid email address.'; -$lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.'; +$lang['form_validation_valid_email'] = 'The {field} field must contain a valid email address.'; +$lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.'; $lang['form_validation_valid_url'] = 'The {field} field must contain a valid URL.'; $lang['form_validation_valid_ip'] = 'The {field} field must contain a valid IP.'; $lang['form_validation_min_length'] = 'The {field} field must be at least {param} characters in length.'; $lang['form_validation_max_length'] = 'The {field} field cannot exceed {param} characters in length.'; -$lang['form_validation_exact_length'] = 'The {field} field must be exactly {param} characters in length.'; +$lang['form_validation_exact_length'] = 'The {field} field must be exactly {param} characters in length.'; $lang['form_validation_alpha'] = 'The {field} field may only contain alphabetical characters.'; -$lang['form_validation_alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.'; +$lang['form_validation_alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.'; +$lang['form_validation_alpha_numeric_spaces'] = 'The {field} field may only contain alpha-numeric characters and spaces.'; $lang['form_validation_alpha_dash'] = 'The {field} field may only contain alpha-numeric characters, underscores, and dashes.'; $lang['form_validation_numeric'] = 'The {field} field must contain only numbers.'; $lang['form_validation_is_numeric'] = 'The {field} field must contain only numeric characters.'; $lang['form_validation_integer'] = 'The {field} field must contain an integer.'; -$lang['form_validation_regex_match'] = 'The {field} field is not in the correct format.'; +$lang['form_validation_regex_match'] = 'The {field} field is not in the correct format.'; $lang['form_validation_matches'] = 'The {field} field does not match the {param} field.'; $lang['form_validation_differs'] = 'The {field} field must differ from the {param} field.'; $lang['form_validation_is_unique'] = 'The {field} field must contain a unique value.'; -- cgit v1.2.3-24-g4f1b From df3bfed9c19fe22d6449e2ee78ca5bd2fe9c6476 Mon Sep 17 00:00:00 2001 From: Sajan Parikh Date: Mon, 4 Feb 2013 12:25:49 -0600 Subject: Cleaned up for pull request. Signed-off-by: Sajan Parikh --- system/language/english/form_validation_lang.php | 10 +++++----- system/libraries/Form_validation.php | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index 476123b06..7c0277c25 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -28,21 +28,21 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $lang['form_validation_required'] = 'The {field} field is required.'; $lang['form_validation_isset'] = 'The {field} field must have a value.'; -$lang['form_validation_valid_email'] = 'The {field} field must contain a valid email address.'; -$lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.'; +$lang['form_validation_valid_email'] = 'The {field} field must contain a valid email address.'; +$lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.'; $lang['form_validation_valid_url'] = 'The {field} field must contain a valid URL.'; $lang['form_validation_valid_ip'] = 'The {field} field must contain a valid IP.'; $lang['form_validation_min_length'] = 'The {field} field must be at least {param} characters in length.'; $lang['form_validation_max_length'] = 'The {field} field cannot exceed {param} characters in length.'; -$lang['form_validation_exact_length'] = 'The {field} field must be exactly {param} characters in length.'; +$lang['form_validation_exact_length'] = 'The {field} field must be exactly {param} characters in length.'; $lang['form_validation_alpha'] = 'The {field} field may only contain alphabetical characters.'; -$lang['form_validation_alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.'; +$lang['form_validation_alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.'; $lang['form_validation_alpha_numeric_spaces'] = 'The {field} field may only contain alpha-numeric characters and spaces.'; $lang['form_validation_alpha_dash'] = 'The {field} field may only contain alpha-numeric characters, underscores, and dashes.'; $lang['form_validation_numeric'] = 'The {field} field must contain only numbers.'; $lang['form_validation_is_numeric'] = 'The {field} field must contain only numeric characters.'; $lang['form_validation_integer'] = 'The {field} field must contain an integer.'; -$lang['form_validation_regex_match'] = 'The {field} field is not in the correct format.'; +$lang['form_validation_regex_match'] = 'The {field} field is not in the correct format.'; $lang['form_validation_matches'] = 'The {field} field does not match the {param} field.'; $lang['form_validation_differs'] = 'The {field} field must differ from the {param} field.'; $lang['form_validation_is_unique'] = 'The {field} field must contain a unique value.'; diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 7b9215c04..1511d9add 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1229,8 +1229,6 @@ class CI_Form_validation { return ctype_alnum((string) $str); } - // -------------------------------------------------------------------- - // -------------------------------------------------------------------- /** @@ -1241,7 +1239,7 @@ class CI_Form_validation { */ public function alpha_numeric_spaces($str) { - return (bool) preg_match('#^[A-Z0-9 ]+$#i', $str); + return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9708855b4c2e5f6c75403da5aa0c07247518ab64 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Feb 2013 21:53:20 +0200 Subject: Allow non-string values to be used as captcha words (issue #2215) --- system/helpers/captcha_helper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 83783324b..78e255a15 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -93,7 +93,7 @@ if ( ! function_exists('create_captcha')) // Do we have a "word" yet? // ----------------------------------- - if ($word === '') + if (empty($word)) { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $word = ''; @@ -102,6 +102,10 @@ if ( ! function_exists('create_captcha')) $word .= $pool[mt_rand(0, $mt_rand_max)]; } } + elseif ( ! is_string($word)) + { + $word = (string) $word; + } // ----------------------------------- // Determine angle and position -- cgit v1.2.3-24-g4f1b From cc221dc434e0d31138e81a940d38b81e994d48fe Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Feb 2013 21:57:42 +0200 Subject: [ci skip] Add a missing space --- system/libraries/Session/drivers/Session_cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 474641642..11bb32fe0 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -805,7 +805,7 @@ class CI_Session_cookie extends CI_Session_driver { { if (is_string($val)) { - $val= str_replace('{{slash}}', '\\', $val); + $val = str_replace('{{slash}}', '\\', $val); } } -- cgit v1.2.3-24-g4f1b From 870f11351b6e7a916bf30aa22b4a8c3dd49bf33f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Feb 2013 22:06:00 +0200 Subject: [ci skip] Remove unnecessary string casts in Pagination --- system/libraries/Pagination.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 438d6c477..10fb29dbd 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -449,8 +449,7 @@ class CI_Pagination { // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - // Cast as string for use in ctype_digit() later. - $this->cur_page = (string) $CI->input->get($this->query_string_segment); + $this->cur_page = $CI->input->get($this->query_string_segment); } else { @@ -460,7 +459,7 @@ class CI_Pagination { $this->uri_segment = count($CI->uri->segment_array()); } - $this->cur_page = (string) $CI->uri->segment($this->uri_segment); + $this->cur_page = $CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. if ($this->prefix !== '' OR $this->suffix !== '') -- cgit v1.2.3-24-g4f1b From c2268711a27809575f82b21e64fde6cd953ef7f9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Feb 2013 22:10:23 +0200 Subject: Fix issue #2230 --- system/libraries/Form_validation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 1511d9add..4cf4ecae0 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -517,7 +517,7 @@ class CI_Form_validation { { if (isset($_POST[$row['field']])) { - $_POST[$row['field']] = $this->prep_for_form($row['postdata']); + $_POST[$row['field']] = $row['postdata']; } } else @@ -543,14 +543,14 @@ class CI_Form_validation { $array = array(); foreach ($row['postdata'] as $k => $v) { - $array[$k] = $this->prep_for_form($v); + $array[$k] = $v; } $post_ref = $array; } else { - $post_ref = $this->prep_for_form($row['postdata']); + $post_ref = $row['postdata']; } } } -- cgit v1.2.3-24-g4f1b From 0b607252b1f3bcabfb8150120e683795ec3a0890 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 13 Feb 2013 10:34:16 +0200 Subject: Added small feature to profiler: total execution time count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adds additional information to profiler like: DATABASE:  test   QUERIES: 3 (0.0016s)  (Hide) --- system/libraries/Profiler.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index e93239901..67922d51c 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -238,6 +238,8 @@ class CI_Profiler { foreach ($dbs as $name => $db) { $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; + + $total_time = number_format(array_sum($db->query_times), 4) . 's'; $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; @@ -250,7 +252,7 @@ class CI_Profiler { ."\n" .'  '.$this->CI->lang->line('profiler_database') .':  '.$db->database.' ('.$name.')   '.$this->CI->lang->line('profiler_queries') - .': '.count($db->queries).'  '.$show_hide_js."\n\n\n" + .': '.count($db->queries).'('.$total_time.')'.'  '.$show_hide_js."\n\n\n" .'\n"; if (count($db->queries) === 0) @@ -553,4 +555,4 @@ class CI_Profiler { } /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file +/* Location: ./system/libraries/Profiler.php */ -- cgit v1.2.3-24-g4f1b From aae91a45e27cb11e09b22bf9be04a7da9f6ff20b Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:51:30 -0500 Subject: Update system/core/Log.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated Log.php so that a developer can extend it and change the log file extension. It makes sense to default to .php when logs are in the public web folder.  It would be nice if a developer moves the log file path we have the option to use a standard extension like .log --- system/core/Log.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index f5d091e14..3b0a9213d 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -71,6 +71,13 @@ class CI_Log { * @var string */ protected $_date_fmt = 'Y-m-d H:i:s'; + + /** + * Log file extension + * + * @var string + */ + protected $_log_ext = 'php'; /** * Whether or not the logger can write to the log files @@ -147,7 +154,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_log_ext; $message = ''; if ( ! file_exists($filepath)) @@ -179,4 +186,4 @@ class CI_Log { } /* End of file Log.php */ -/* Location: ./system/core/Log.php */ \ No newline at end of file +/* Location: ./system/core/Log.php */ -- cgit v1.2.3-24-g4f1b From 0bd6b28045c9b9a820e580b3f651f474b60348a3 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 14:16:18 -0500 Subject: Added support for changing the default log file extension from .php to whatever is preferred. example (.log) This is a follow up to this pull request. https://github.com/EllisLab/CodeIgniter/pull/2243 --- system/core/Log.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index 3b0a9213d..7572d2ac6 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,6 +104,8 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; + $this->_log_ext = ($config['log_file_extension'] !== '') ? $config['log_file_extension'] : $this->_log_ext; + file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) -- cgit v1.2.3-24-g4f1b From 554d5dc6c1b9c6880a2fba150018c21ded8675c6 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 13 Feb 2013 22:37:31 +0200 Subject: changes according to narfbg's request --- system/language/english/profiler_lang.php | 1 + system/libraries/Profiler.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index dfe034e79..68e794e79 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -46,6 +46,7 @@ $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; $lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; $lang['profiler_section_hide'] = 'Hide'; $lang['profiler_section_show'] = 'Show'; +$lang['profiler_seconds'] = 'seconds'; /* End of file profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 67922d51c..a3fa61c7c 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -238,8 +238,8 @@ class CI_Profiler { foreach ($dbs as $name => $db) { $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - - $total_time = number_format(array_sum($db->query_times), 4) . 's'; + + $total_time = number_format(array_sum($db->query_times), 4).$this->CI->lang->line('profiler_seconds'); $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; @@ -555,4 +555,4 @@ class CI_Profiler { } /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ +/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3224f077c37a054ea1995c07fe54bbe8b00e058a Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 14 Feb 2013 09:26:24 +0200 Subject: changes according to narfbg's request --- system/language/english/profiler_lang.php | 2 +- system/libraries/Profiler.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index 68e794e79..0ed5f4cb0 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -46,7 +46,7 @@ $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; $lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; $lang['profiler_section_hide'] = 'Hide'; $lang['profiler_section_show'] = 'Show'; -$lang['profiler_seconds'] = 'seconds'; +$lang['profiler_seconds'] = 'seconds'; /* End of file profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index a3fa61c7c..ac8f6ba71 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -238,8 +238,8 @@ class CI_Profiler { foreach ($dbs as $name => $db) { $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - - $total_time = number_format(array_sum($db->query_times), 4).$this->CI->lang->line('profiler_seconds'); + + $total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds'); $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; -- cgit v1.2.3-24-g4f1b From 7219232771ee28f6f18248cfffd4fdffa570dfb7 Mon Sep 17 00:00:00 2001 From: maltzurra Date: Thu, 14 Feb 2013 11:12:37 +0100 Subject: Update system/core/Common.php Updated is_https() to avoid "NULL" or "0" values to set HTTPS. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 258cd4967..136dd521c 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + return (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on'); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 2718f6c8a5bbae38b7a7f875c6eef40739ce8ee4 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Thu, 14 Feb 2013 08:57:49 -0500 Subject: Update system/core/Log.php Added ltrim() as requested to strip '.' incase it's added by mistake. --- system/core/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index 7572d2ac6..abc7b2494 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,7 +104,7 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - $this->_log_ext = ($config['log_file_extension'] !== '') ? $config['log_file_extension'] : $this->_log_ext; + $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'],'.') : $this->_log_ext; file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); -- cgit v1.2.3-24-g4f1b From fb8de247990189721bc7b2e48fe57ceb2db039f5 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Thu, 14 Feb 2013 09:01:24 -0500 Subject: Update system/core/Log.php Don't print no script access code into log file if log file is not .php anymore. --- system/core/Log.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index abc7b2494..7b2082a6c 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -162,7 +162,10 @@ class CI_Log { if ( ! file_exists($filepath)) { $newfile = TRUE; - $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; + if($this->_log_ext === 'php') + { + $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; + } } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) -- cgit v1.2.3-24-g4f1b From de8766f0a538ef9c4d39dcd88efc9422b5170360 Mon Sep 17 00:00:00 2001 From: maltzurra Date: Thu, 14 Feb 2013 15:38:58 +0100 Subject: Update system/core/Common.php --- system/core/Common.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 136dd521c..0386ff37a 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -713,4 +713,5 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php +*/ -- cgit v1.2.3-24-g4f1b From beafe2fffbe5407f735caf2c286540d896d113f3 Mon Sep 17 00:00:00 2001 From: maltzurra Date: Thu, 14 Feb 2013 15:39:17 +0100 Subject: Update system/core/Common.php --- system/core/Common.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 0386ff37a..136dd521c 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -713,5 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php -*/ +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 3567246091195e035ea4c8d3b2915eb6b45ad5e2 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Fri, 15 Feb 2013 01:36:04 +0100 Subject: Various cosmetic fixes --- system/core/Loader.php | 2 +- system/core/URI.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Form_validation.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Upload.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 00ca35199..9306a09ef 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -988,7 +988,7 @@ class CI_Loader { return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); } - // Lets search for the requested library file and load it. + // Let's search for the requested library file and load it. foreach ($this->_ci_library_paths as $path) { $filepath = $path.'libraries/'.$subdir.$class.'.php'; diff --git a/system/core/URI.php b/system/core/URI.php index 9b31a646b..b2286f032 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -126,7 +126,7 @@ class CI_URI { return; } - // As a last ditch effort lets try using the $_GET array + // As a last ditch effort let's try using the $_GET array if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') !== '') { $this->_set_uri_string(key($_GET)); diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index d64f6f042..b7b0697fb 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -365,7 +365,7 @@ class CI_Cart { */ protected function _save_cart() { - // Lets add up the individual prices and set the cart sub-total + // Let's add up the individual prices and set the cart sub-total $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; foreach ($this->_cart_contents as $key => $val) { diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 4cf4ecae0..172e799f6 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -356,7 +356,7 @@ class CI_Form_validation { */ public function error_string($prefix = '', $suffix = '') { - // No errrors, validation passes! + // No errors, validation passes! if (count($this->_error_array) === 0) { return ''; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ac8f6ba71..36e0431b2 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -238,7 +238,7 @@ class CI_Profiler { foreach ($dbs as $name => $db) { $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - + $total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds'); $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 814ea68a4..acd76b03b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -430,7 +430,7 @@ class CI_Upload { } else { - // An extension was provided, lets have it! + // An extension was provided, let's have it! $this->file_ext = $this->get_extension($this->_file_name_override); } @@ -1050,7 +1050,7 @@ class CI_Upload { // ]/i', $opening_bytes); } -- cgit v1.2.3-24-g4f1b From 8d8636778ac600176772c4d54321a1e0842e5b07 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Fri, 15 Feb 2013 09:06:11 -0500 Subject: Update system/core/Log.php Added a space after the comma on the ltrim(). --- system/core/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index 7b2082a6c..2a4728dc4 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -104,7 +104,7 @@ class CI_Log { $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'],'.') : $this->_log_ext; + $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'], '.') : $this->_log_ext; file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); -- cgit v1.2.3-24-g4f1b From ce6f43b7120a184aa0cff0bdb90fa3d7f032e14b Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Tue, 12 Feb 2013 16:58:38 -0500 Subject: Update system/core/Common.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If using nginx instead of apache by default nginx will not populate the $_SERVER['HTTPS'] value.  This change allows falling back to checking the port number of the request to determine if your on SSL or not. The other option is adding the following to your nginx config. fastcgi_param HTTPS on; #some php apps require this to detent https --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 258cd4967..b9c872748 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 614cc1c384b84801428f9823007586584af00653 Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:45:20 -0500 Subject: Revert "Update system/core/Common.php" This reverts commit 8af05ac97513764cc539919e179794df87352c30. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index b9c872748..258cd4967 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); + return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b0607703b32ec790cc300e9f77a18ea17ab6d7dd Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:02 -0500 Subject: Revert "Revert "Update system/core/Common.php"" This reverts commit 3de57eaea8510ea9cfd70f063565c24904669c4c. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 258cd4967..b9c872748 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From 6f19fd770b67804797c55d47c1c5f5fcb3a37b2e Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:02 -0500 Subject: Revert "Update system/core/Log.php" This reverts commit bbc6ab4736a896be83e3e3d5f8856374ffa2984c. --- system/core/Log.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/core/Log.php b/system/core/Log.php index 2a4728dc4..0749de8ba 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -71,13 +71,6 @@ class CI_Log { * @var string */ protected $_date_fmt = 'Y-m-d H:i:s'; - - /** - * Log file extension - * - * @var string - */ - protected $_log_ext = 'php'; /** * Whether or not the logger can write to the log files @@ -156,7 +149,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_log_ext; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; if ( ! file_exists($filepath)) @@ -191,4 +184,4 @@ class CI_Log { } /* End of file Log.php */ -/* Location: ./system/core/Log.php */ +/* Location: ./system/core/Log.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62f7cdf3a6f5d701430267ef9ba9bfd92650deab Mon Sep 17 00:00:00 2001 From: Chris Passas Date: Wed, 13 Feb 2013 11:47:45 -0500 Subject: Revert "Update system/core/Common.php" This reverts commit 8af05ac97513764cc539919e179794df87352c30. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index b9c872748..258cd4967 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -343,7 +343,7 @@ if ( ! function_exists('is_https')) */ function is_https() { - return ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ) || ($_SERVER["SERVER_PORT"] === '443') ); + return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a107a0fd79d0ee5f6292138a76398ed390041710 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 15 Feb 2013 22:30:31 +0200 Subject: Fix some stuff from recent pull requests --- system/core/Common.php | 6 +++--- system/core/Log.php | 24 +++++++++++++++++------- system/libraries/Profiler.php | 3 +-- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 136dd521c..f8c1290f5 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -414,7 +414,7 @@ if ( ! function_exists('log_message')) function log_message($level = 'error', $message, $php_error = FALSE) { static $_log, $_log_threshold; - + if ($_log_threshold === NULL) { $_log_threshold = config_item('log_threshold'); @@ -429,7 +429,7 @@ if ( ! function_exists('log_message')) { $_log =& load_class('Log', 'core'); } - + $_log->write_log($level, $message, $php_error); } } @@ -713,4 +713,4 @@ if ( ! function_exists('function_usable')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file diff --git a/system/core/Log.php b/system/core/Log.php index 0749de8ba..a84d3dc22 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -72,6 +72,13 @@ class CI_Log { */ protected $_date_fmt = 'Y-m-d H:i:s'; + /** + * Filename extension + * + * @var string + */ + protected $_file_ext; + /** * Whether or not the logger can write to the log files * @@ -86,8 +93,10 @@ class CI_Log { */ protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + // -------------------------------------------------------------------- + /** - * Initialize Logging class + * Class constructor * * @return void */ @@ -96,8 +105,8 @@ class CI_Log { $config =& get_config(); $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; - - $this->_log_ext = ($config['log_file_extension'] !== '') ? ltrim($config['log_file_extension'], '.') : $this->_log_ext; + $this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '') + ? ltrim($config['log_file_extension'], '.') : 'php'; file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE); @@ -149,15 +158,16 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext; + $message = ''; if ( ! file_exists($filepath)) { $newfile = TRUE; - if($this->_log_ext === 'php') + // Only add protection to php files + if ($this->_file_ext === 'php') { - $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n"; + $message .= "\n\n"; } } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 36e0431b2..470688fdc 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -238,7 +238,6 @@ class CI_Profiler { foreach ($dbs as $name => $db) { $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - $total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds'); $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; @@ -252,7 +251,7 @@ class CI_Profiler { ."\n" .'  '.$this->CI->lang->line('profiler_database') .':  '.$db->database.' ('.$name.')   '.$this->CI->lang->line('profiler_queries') - .': '.count($db->queries).'('.$total_time.')'.'  '.$show_hide_js."\n\n\n" + .': '.count($db->queries).' ('.$total_time.')  '.$show_hide_js."\n\n\n" .'
\n"; if (count($db->queries) === 0) -- cgit v1.2.3-24-g4f1b From 99ba3a26973848604719db08bbcafbfa82ca087f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 15 Feb 2013 22:42:22 +0200 Subject: Fix #2247 --- system/helpers/form_helper.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index f343b6c71..d6e3e85fa 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -228,13 +228,10 @@ if ( ! function_exists('form_upload')) */ function form_upload($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - + $default = array('type' => 'file', 'name' => ''); + is_array($data) OR $data = array('name' => $data); $data['type'] = 'file'; - return form_input($data, $value, $extra); + return '\n"; } } -- cgit v1.2.3-24-g4f1b From cf22557383fea89906633b8034ff9f08eb498621 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 18 Feb 2013 01:08:04 +0530 Subject: Added keep-alive connection to SMTP. Fixed socket read/write timeouts. Added PHP useragent --- system/libraries/Email.php | 524 +++++++++++++++++++++++++-------------------- 1 file changed, 290 insertions(+), 234 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 997757b0a..36cebfab5 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -94,6 +94,13 @@ class CI_Email { * @var int */ public $smtp_timeout = 5; + + /** + * STMP Persistent connection + * + * @var bool + */ + public $smtp_keepalive = FALSE; /** * SMTP Encryption @@ -399,6 +406,19 @@ class CI_Email { log_message('debug', 'Email Class Initialized'); } + + // -------------------------------------------------------------------- + + /** + * Destructor - Releases Resources + * + * @return void + */ + function __destruct() + { + if(is_resource($this->_smtp_connect)) + $this->_send_command('quit'); + } // -------------------------------------------------------------------- @@ -770,6 +790,23 @@ class CI_Email { // -------------------------------------------------------------------- + /** + * Set Useragent + * + * @param string + * @return void + */ + public function set_useragent($type = '') + { + if( ! $type) + $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : 'PHP/'.phpversion(); + else + $this->useragent = $type; + return $this; + } + + // -------------------------------------------------------------------- + /** * Set Wordwrap * @@ -1766,241 +1803,260 @@ class CI_Email { * @return bool */ protected function _send_with_smtp() - { - if ($this->smtp_host === '') - { - $this->_set_error_message('lang:email_no_hostname'); - return FALSE; - } - - if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate()) - { - return FALSE; - } - - $this->_send_command('from', $this->clean_email($this->_headers['From'])); - - foreach ($this->_recipients as $val) - { - $this->_send_command('to', $val); - } - - if (count($this->_cc_array) > 0) - { - foreach ($this->_cc_array as $val) - { - if ($val !== '') - { - $this->_send_command('to', $val); - } - } - } - - if (count($this->_bcc_array) > 0) - { - foreach ($this->_bcc_array as $val) - { - if ($val !== '') - { - $this->_send_command('to', $val); - } - } - } - - $this->_send_command('data'); - - // perform dot transformation on any lines that begin with a dot - $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); - - $this->_send_data('.'); - - $reply = $this->_get_smtp_data(); - - $this->_set_error_message($reply); - - if (strpos($reply, '250') !== 0) - { - $this->_set_error_message('lang:email_smtp_error', $reply); - return FALSE; - } - - $this->_send_command('quit'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * SMTP Connect - * - * @return string - */ - protected function _smtp_connect() - { - $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; - - $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout); - - if ( ! is_resource($this->_smtp_connect)) - { - $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); - return FALSE; - } - - $this->_set_error_message($this->_get_smtp_data()); - - if ($this->smtp_crypto === 'tls') - { - $this->_send_command('hello'); - $this->_send_command('starttls'); - - $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); - - if ($crypto !== TRUE) - { - $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); - return FALSE; - } - } - - return $this->_send_command('hello'); - } - - // -------------------------------------------------------------------- + { + if ($this->smtp_host === '') + { + $this->_set_error_message('lang:email_no_hostname'); + return FALSE; + } + + if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate()) + { + return FALSE; + } + + $this->_send_command('from', $this->clean_email($this->_headers['From'])); + + foreach ($this->_recipients as $val) + { + $this->_send_command('to', $val); + } + + if (count($this->_cc_array) > 0) + { + foreach ($this->_cc_array as $val) + { + if ($val !== '') + { + $this->_send_command('to', $val); + } + } + } + + if (count($this->_bcc_array) > 0) + { + foreach ($this->_bcc_array as $val) + { + if ($val !== '') + { + $this->_send_command('to', $val); + } + } + } + + $this->_send_command('data'); + + // perform dot transformation on any lines that begin with a dot + $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); + + $this->_send_data('.'); + + $reply = $this->_get_smtp_data(); + + $this->_set_error_message($reply); + + if (strpos($reply, '250') !== 0) + { + $this->_set_error_message('lang:email_smtp_error', $reply); + return FALSE; + } + + if($this->smtp_keepalive) + $this->_send_command('reset'); + else + $this->_send_command('quit'); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * SMTP Connect + * + * @param bool + * @return string + */ + protected function _smtp_connect($force=FALSE) + { + if( ! is_resource($this->_smtp_connect) || $force) + { + $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; + + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout); + + if ( ! is_resource($this->_smtp_connect)) + { + $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); + return FALSE; + } + + stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); + $this->_set_error_message($this->_get_smtp_data()); + + if ($this->smtp_crypto === 'tls') + { + $this->_send_command('hello'); + $this->_send_command('starttls'); + + $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + + if ($crypto !== TRUE) + { + $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); + return FALSE; + } + } + + return $this->_send_command('hello'); + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Send SMTP command + * + * @param string + * @param string + * @return string + */ + protected function _send_command($cmd, $data = '') + { + switch ($cmd) + { + case 'hello' : + + if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') + { + $this->_send_data('EHLO '.$this->_get_hostname()); + } + else + { + $this->_send_data('HELO '.$this->_get_hostname()); + } + + $resp = 250; + break; + case 'starttls' : + + $this->_send_data('STARTTLS'); + $resp = 220; + break; + case 'from' : + + $this->_send_data('MAIL FROM:<'.$data.'>'); + $resp = 250; + break; + case 'to' : + + if ($this->dsn) + { + $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); + } + else + { + $this->_send_data('RCPT TO:<'.$data.'>'); + } + + $resp = 250; + break; + case 'data' : + + $this->_send_data('DATA'); + $resp = 354; + break; + case 'reset': + + $this->_send_data('RSET'); + + $resp = 250; + break; + case 'quit' : + + $this->_send_data('QUIT'); + $resp = 221; + break; + } + + $reply = $this->_get_smtp_data(); + + $this->_debug_msg[] = '
'.$cmd.': '.$reply.'
'; + + if ((int) substr($reply, 0, 3) !== $resp) + { + $this->_set_error_message('lang:email_smtp_error', $reply); + return FALSE; + } + + if ($cmd === 'quit') + { + fclose($this->_smtp_connect); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * SMTP Authenticate + * + * @return bool + */ + protected function _smtp_authenticate() + { + if ( ! $this->_smtp_auth) + { + return TRUE; + } + + if ($this->smtp_user === '' && $this->smtp_pass === '') + { + $this->_set_error_message('lang:email_no_smtp_unpw'); + return FALSE; + } + + $this->_send_data('AUTH LOGIN'); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '503') === 0) // Already authenticated + return TRUE; + + if (strpos($reply, '334') !== 0) + { + $this->_set_error_message('lang:email_failed_smtp_login', $reply); + return FALSE; + } + + $this->_send_data(base64_encode($this->smtp_user)); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '334') !== 0) + { + $this->_set_error_message('lang:email_smtp_auth_un', $reply); + return FALSE; + } + + $this->_send_data(base64_encode($this->smtp_pass)); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '235') !== 0) + { + $this->_set_error_message('lang:email_smtp_auth_pw', $reply); + return FALSE; + } - /** - * Send SMTP command - * - * @param string - * @param string - * @return string - */ - protected function _send_command($cmd, $data = '') - { - switch ($cmd) - { - case 'hello' : - - if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') - { - $this->_send_data('EHLO '.$this->_get_hostname()); - } - else - { - $this->_send_data('HELO '.$this->_get_hostname()); - } - - $resp = 250; - break; - case 'starttls' : - - $this->_send_data('STARTTLS'); - $resp = 220; - break; - case 'from' : - - $this->_send_data('MAIL FROM:<'.$data.'>'); - $resp = 250; - break; - case 'to' : - - if ($this->dsn) - { - $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); - } - else - { - $this->_send_data('RCPT TO:<'.$data.'>'); - } - - $resp = 250; - break; - case 'data' : - - $this->_send_data('DATA'); - $resp = 354; - break; - case 'quit' : - - $this->_send_data('QUIT'); - $resp = 221; - break; - } - - $reply = $this->_get_smtp_data(); - - $this->_debug_msg[] = '
'.$cmd.': '.$reply.'
'; - - if ((int) substr($reply, 0, 3) !== $resp) - { - $this->_set_error_message('lang:email_smtp_error', $reply); - return FALSE; - } - - if ($cmd === 'quit') - { - fclose($this->_smtp_connect); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * SMTP Authenticate - * - * @return bool - */ - protected function _smtp_authenticate() - { - if ( ! $this->_smtp_auth) - { - return TRUE; - } - - if ($this->smtp_user === '' && $this->smtp_pass === '') - { - $this->_set_error_message('lang:email_no_smtp_unpw'); - return FALSE; - } - - $this->_send_data('AUTH LOGIN'); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '334') !== 0) - { - $this->_set_error_message('lang:email_failed_smtp_login', $reply); - return FALSE; - } - - $this->_send_data(base64_encode($this->smtp_user)); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '334') !== 0) - { - $this->_set_error_message('lang:email_smtp_auth_un', $reply); - return FALSE; - } - - $this->_send_data(base64_encode($this->smtp_pass)); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '235') !== 0) - { - $this->_set_error_message('lang:email_smtp_auth_pw', $reply); - return FALSE; - } - - return TRUE; - } + return TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 06ddcf05c6861a908a0b3b57c6ba4a05bb82e10a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 18 Feb 2013 08:52:05 +0800 Subject: Fixed form helper variable error Signed-off-by: Bo-Yi Wu --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d6e3e85fa..692909c79 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -228,7 +228,7 @@ if ( ! function_exists('form_upload')) */ function form_upload($data = '', $value = '', $extra = '') { - $default = array('type' => 'file', 'name' => ''); + $defaults = array('type' => 'file', 'name' => ''); is_array($data) OR $data = array('name' => $data); $data['type'] = 'file'; return '\n"; -- cgit v1.2.3-24-g4f1b From 59209deaf2467372ba0deef5a4266758b366ca70 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 18 Feb 2013 17:02:13 +0530 Subject: Fixed tab-indentation. Made appropriate entries in changelog --- system/libraries/Email.php | 565 ++++++++++++++++++++++----------------------- 1 file changed, 282 insertions(+), 283 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 36cebfab5..7ea49a959 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -96,11 +96,11 @@ class CI_Email { public $smtp_timeout = 5; /** - * STMP Persistent connection - * - * @var bool - */ - public $smtp_keepalive = FALSE; + * SMTP persistent connection + * + * @var bool + */ + public $smtp_keepalive = FALSE; /** * SMTP Encryption @@ -406,19 +406,19 @@ class CI_Email { log_message('debug', 'Email Class Initialized'); } - + // -------------------------------------------------------------------- /** - * Destructor - Releases Resources - * - * @return void - */ - function __destruct() - { - if(is_resource($this->_smtp_connect)) - $this->_send_command('quit'); - } + * Destructor - Releases Resources + * + * @return void + */ + public function __destruct() + { + if(is_resource($this->_smtp_connect)) + $this->_send_command('quit'); + } // -------------------------------------------------------------------- @@ -789,22 +789,22 @@ class CI_Email { } // -------------------------------------------------------------------- - - /** - * Set Useragent - * - * @param string - * @return void - */ - public function set_useragent($type = '') - { - if( ! $type) - $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : 'PHP/'.phpversion(); - else - $this->useragent = $type; - return $this; - } + /** + * Set Useragent + * + * @param string + * @return void + */ + public function set_useragent($type = '') + { + if( ! $type) + $this->useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'PHP/'.phpversion(); + else + $this->useragent = $type; + return $this; + } + // -------------------------------------------------------------------- /** @@ -1803,260 +1803,259 @@ class CI_Email { * @return bool */ protected function _send_with_smtp() - { - if ($this->smtp_host === '') - { - $this->_set_error_message('lang:email_no_hostname'); - return FALSE; - } - - if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate()) - { - return FALSE; - } - - $this->_send_command('from', $this->clean_email($this->_headers['From'])); - - foreach ($this->_recipients as $val) - { - $this->_send_command('to', $val); - } - - if (count($this->_cc_array) > 0) - { - foreach ($this->_cc_array as $val) - { - if ($val !== '') - { - $this->_send_command('to', $val); - } - } - } - - if (count($this->_bcc_array) > 0) - { - foreach ($this->_bcc_array as $val) - { - if ($val !== '') - { - $this->_send_command('to', $val); - } - } - } - - $this->_send_command('data'); - - // perform dot transformation on any lines that begin with a dot - $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); - - $this->_send_data('.'); - - $reply = $this->_get_smtp_data(); - - $this->_set_error_message($reply); - - if (strpos($reply, '250') !== 0) - { - $this->_set_error_message('lang:email_smtp_error', $reply); - return FALSE; - } - - if($this->smtp_keepalive) - $this->_send_command('reset'); - else - $this->_send_command('quit'); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * SMTP Connect - * - * @param bool - * @return string - */ - protected function _smtp_connect($force=FALSE) - { - if( ! is_resource($this->_smtp_connect) || $force) - { - $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; - - $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout); - - if ( ! is_resource($this->_smtp_connect)) - { - $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); - return FALSE; - } - - stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); - $this->_set_error_message($this->_get_smtp_data()); - - if ($this->smtp_crypto === 'tls') - { - $this->_send_command('hello'); - $this->_send_command('starttls'); - - $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); - - if ($crypto !== TRUE) - { - $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); - return FALSE; - } - } - - return $this->_send_command('hello'); - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Send SMTP command - * - * @param string - * @param string - * @return string - */ - protected function _send_command($cmd, $data = '') - { - switch ($cmd) - { - case 'hello' : - - if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') - { - $this->_send_data('EHLO '.$this->_get_hostname()); - } - else - { - $this->_send_data('HELO '.$this->_get_hostname()); - } - - $resp = 250; - break; - case 'starttls' : - - $this->_send_data('STARTTLS'); - $resp = 220; - break; - case 'from' : - - $this->_send_data('MAIL FROM:<'.$data.'>'); - $resp = 250; - break; - case 'to' : - - if ($this->dsn) - { - $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); - } - else - { - $this->_send_data('RCPT TO:<'.$data.'>'); - } - - $resp = 250; - break; - case 'data' : - - $this->_send_data('DATA'); - $resp = 354; - break; - case 'reset': - - $this->_send_data('RSET'); - - $resp = 250; - break; - case 'quit' : - - $this->_send_data('QUIT'); - $resp = 221; - break; - } - - $reply = $this->_get_smtp_data(); - - $this->_debug_msg[] = '
'.$cmd.': '.$reply.'
'; - - if ((int) substr($reply, 0, 3) !== $resp) - { - $this->_set_error_message('lang:email_smtp_error', $reply); - return FALSE; - } - - if ($cmd === 'quit') - { - fclose($this->_smtp_connect); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * SMTP Authenticate - * - * @return bool - */ - protected function _smtp_authenticate() - { - if ( ! $this->_smtp_auth) - { - return TRUE; - } - - if ($this->smtp_user === '' && $this->smtp_pass === '') - { - $this->_set_error_message('lang:email_no_smtp_unpw'); - return FALSE; - } - - $this->_send_data('AUTH LOGIN'); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '503') === 0) // Already authenticated - return TRUE; - - if (strpos($reply, '334') !== 0) - { - $this->_set_error_message('lang:email_failed_smtp_login', $reply); - return FALSE; - } - - $this->_send_data(base64_encode($this->smtp_user)); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '334') !== 0) - { - $this->_set_error_message('lang:email_smtp_auth_un', $reply); - return FALSE; - } - - $this->_send_data(base64_encode($this->smtp_pass)); - - $reply = $this->_get_smtp_data(); - - if (strpos($reply, '235') !== 0) - { - $this->_set_error_message('lang:email_smtp_auth_pw', $reply); - return FALSE; - } + { + if ($this->smtp_host === '') + { + $this->_set_error_message('lang:email_no_hostname'); + return FALSE; + } + + if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate()) + { + return FALSE; + } + + $this->_send_command('from', $this->clean_email($this->_headers['From'])); + + foreach ($this->_recipients as $val) + { + $this->_send_command('to', $val); + } + + if (count($this->_cc_array) > 0) + { + foreach ($this->_cc_array as $val) + { + if ($val !== '') + { + $this->_send_command('to', $val); + } + } + } - return TRUE; - } + if (count($this->_bcc_array) > 0) + { + foreach ($this->_bcc_array as $val) + { + if ($val !== '') + { + $this->_send_command('to', $val); + } + } + } + + $this->_send_command('data'); + + // perform dot transformation on any lines that begin with a dot + $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); + + $this->_send_data('.'); + + $reply = $this->_get_smtp_data(); + + $this->_set_error_message($reply); + + if (strpos($reply, '250') !== 0) + { + $this->_set_error_message('lang:email_smtp_error', $reply); + return FALSE; + } + + if($this->smtp_keepalive) + $this->_send_command('reset'); + else + $this->_send_command('quit'); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * SMTP Connect + * + * @param bool + * @return string + */ + protected function _smtp_connect($force=FALSE) + { + if( ! is_resource($this->_smtp_connect) || $force) + { + $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; + + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout); + + if ( ! is_resource($this->_smtp_connect)) + { + $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); + return FALSE; + } + + stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); + $this->_set_error_message($this->_get_smtp_data()); + + if ($this->smtp_crypto === 'tls') + { + $this->_send_command('hello'); + $this->_send_command('starttls'); + + $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + + if ($crypto !== TRUE) + { + $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); + return FALSE; + } + } + + return $this->_send_command('hello'); + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Send SMTP command + * + * @param string + * @param string + * @return string + */ + protected function _send_command($cmd, $data = '') + { + switch ($cmd) + { + case 'hello' : + + if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') + { + $this->_send_data('EHLO '.$this->_get_hostname()); + } + else + { + $this->_send_data('HELO '.$this->_get_hostname()); + } + + $resp = 250; + break; + case 'starttls' : + + $this->_send_data('STARTTLS'); + $resp = 220; + break; + case 'from' : + + $this->_send_data('MAIL FROM:<'.$data.'>'); + $resp = 250; + break; + case 'to' : + + if ($this->dsn) + { + $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); + } + else + { + $this->_send_data('RCPT TO:<'.$data.'>'); + } + + $resp = 250; + break; + case 'data' : + + $this->_send_data('DATA'); + $resp = 354; + break; + case 'reset': + + $this->_send_data('RSET'); + $resp = 250; + break; + case 'quit' : + + $this->_send_data('QUIT'); + $resp = 221; + break; + } + + $reply = $this->_get_smtp_data(); + + $this->_debug_msg[] = '
'.$cmd.': '.$reply.'
'; + + if ((int) substr($reply, 0, 3) !== $resp) + { + $this->_set_error_message('lang:email_smtp_error', $reply); + return FALSE; + } + + if ($cmd === 'quit') + { + fclose($this->_smtp_connect); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * SMTP Authenticate + * + * @return bool + */ + protected function _smtp_authenticate() + { + if ( ! $this->_smtp_auth) + { + return TRUE; + } + + if ($this->smtp_user === '' && $this->smtp_pass === '') + { + $this->_set_error_message('lang:email_no_smtp_unpw'); + return FALSE; + } + + $this->_send_data('AUTH LOGIN'); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '503') !== 0) // Already authenticated + return TRUE; + + if (strpos($reply, '334') !== 0) + { + $this->_set_error_message('lang:email_failed_smtp_login', $reply); + return FALSE; + } + + $this->_send_data(base64_encode($this->smtp_user)); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '334') !== 0) + { + $this->_set_error_message('lang:email_smtp_auth_un', $reply); + return FALSE; + } + + $this->_send_data(base64_encode($this->smtp_pass)); + + $reply = $this->_get_smtp_data(); + + if (strpos($reply, '235') !== 0) + { + $this->_set_error_message('lang:email_smtp_auth_pw', $reply); + return FALSE; + } + + return TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 758f40c3d971837d739fa5bc47529bccc846dcfd Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 18 Feb 2013 17:18:51 +0530 Subject: Fixed curly braces. Removed redundant method set_useragent() --- system/libraries/Email.php | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7ea49a959..b0d0921eb 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -416,8 +416,10 @@ class CI_Email { */ public function __destruct() { - if(is_resource($this->_smtp_connect)) + if (is_resource($this->_smtp_connect)) + { $this->_send_command('quit'); + } } // -------------------------------------------------------------------- @@ -788,23 +790,6 @@ class CI_Email { return $this; } - // -------------------------------------------------------------------- - - /** - * Set Useragent - * - * @param string - * @return void - */ - public function set_useragent($type = '') - { - if( ! $type) - $this->useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'PHP/'.phpversion(); - else - $this->useragent = $type; - return $this; - } - // -------------------------------------------------------------------- /** @@ -1861,10 +1846,14 @@ class CI_Email { return FALSE; } - if($this->smtp_keepalive) + if ($this->smtp_keepalive) + { $this->_send_command('reset'); + } else + { $this->_send_command('quit'); + } return TRUE; } @@ -1879,7 +1868,7 @@ class CI_Email { */ protected function _smtp_connect($force=FALSE) { - if( ! is_resource($this->_smtp_connect) || $force) + if ( ! is_resource($this->_smtp_connect) || $force) { $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; @@ -2026,7 +2015,9 @@ class CI_Email { $reply = $this->_get_smtp_data(); if (strpos($reply, '503') !== 0) // Already authenticated + { return TRUE; + } if (strpos($reply, '334') !== 0) { -- cgit v1.2.3-24-g4f1b From 193f0c76edbd85cf98ae730006b459c7c55a5b78 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 18 Feb 2013 17:29:23 +0530 Subject: removed PR from the bug list --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b0d0921eb..91c119e02 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1868,7 +1868,7 @@ class CI_Email { */ protected function _smtp_connect($force=FALSE) { - if ( ! is_resource($this->_smtp_connect) || $force) + if ( ! is_resource($this->_smtp_connect) OR $force) { $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; -- cgit v1.2.3-24-g4f1b From a44e6913324bd47e17bfd4109fc65b699c508006 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 18 Feb 2013 18:07:03 +0530 Subject: Removed the unused $force paramter in Email::_smtp_connect() --- system/libraries/Email.php | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 91c119e02..1bf1da15e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1863,47 +1863,47 @@ class CI_Email { /** * SMTP Connect * - * @param bool * @return string */ - protected function _smtp_connect($force=FALSE) + protected function _smtp_connect() { - if ( ! is_resource($this->_smtp_connect) OR $force) + if (is_resource($this->_smtp_connect)) { - $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; + return TRUE; + } - $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout); + $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL; - if ( ! is_resource($this->_smtp_connect)) - { - $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); - return FALSE; - } + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout); - stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); - $this->_set_error_message($this->_get_smtp_data()); + if ( ! is_resource($this->_smtp_connect)) + { + $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr); + return FALSE; + } - if ($this->smtp_crypto === 'tls') - { - $this->_send_command('hello'); - $this->_send_command('starttls'); + stream_set_timeout($this->_smtp_connect, $this->smtp_timeout); + $this->_set_error_message($this->_get_smtp_data()); - $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + if ($this->smtp_crypto === 'tls') + { + $this->_send_command('hello'); + $this->_send_command('starttls'); - if ($crypto !== TRUE) - { - $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); - return FALSE; - } - } + $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); - return $this->_send_command('hello'); + if ($crypto !== TRUE) + { + $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); + return FALSE; + } } - return TRUE; + + return $this->_send_command('hello'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f399425bacfa461a77be2e841c3c1f48f9241c4a Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 19 Feb 2013 01:45:23 +0100 Subject: Fix a code comment in Upload->_file_mime_type() Availability of dangerous functions is now tested using function_usable(). --- system/libraries/Email.php | 6 +++--- system/libraries/Upload.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1bf1da15e..074ce60fc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -94,7 +94,7 @@ class CI_Email { * @var int */ public $smtp_timeout = 5; - + /** * SMTP persistent connection * @@ -408,7 +408,7 @@ class CI_Email { } // -------------------------------------------------------------------- - + /** * Destructor - Releases Resources * @@ -2018,7 +2018,7 @@ class CI_Email { { return TRUE; } - + if (strpos($reply, '334') !== 0) { $this->_set_error_message('lang:email_failed_smtp_login', $reply); diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index acd76b03b..1c14f99ed 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1212,7 +1212,7 @@ class CI_Upload { * Notes: * - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system * - many system admins would disable the exec(), shell_exec(), popen() and similar functions - * due to security concerns, hence the function_exists() checks + * due to security concerns, hence the function_usable() checks */ if (DIRECTORY_SEPARATOR !== '\\') { @@ -1223,7 +1223,7 @@ class CI_Upload { if (function_usable('exec')) { /* This might look confusing, as $mime is being populated with all of the output when set in the second parameter. - * However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites + * However, we only need the last line, which is the actual return value of exec(), and as such - it overwrites * anything that could already be set for $mime previously. This effectively makes the second parameter a dummy * value, which is only put to allow us to get the return status code. */ -- cgit v1.2.3-24-g4f1b From 6bb98903662ed2870d1d46c492106fec3be1ca6f Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Tue, 19 Feb 2013 18:11:14 +0530 Subject: Fixed the issue with bcc_batch_mode and subject --- system/libraries/Email.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1bf1da15e..0319ac5e7 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1205,8 +1205,11 @@ class CI_Email { { if ($this->protocol === 'mail') { - $this->_subject = $this->_headers['Subject']; - unset($this->_headers['Subject']); + if (isset($this->_headers['Subject'])) + { + $this->_subject = $this->_headers['Subject']; + unset($this->_headers['Subject']); + } } reset($this->_headers); -- cgit v1.2.3-24-g4f1b From 07a59548c0761c5ac4562019d13913f2b82c6018 Mon Sep 17 00:00:00 2001 From: Dionysis Arvanitis Date: Tue, 19 Feb 2013 22:31:05 +0200 Subject: Set transaction enabled flag default to TRUE --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 34adf0f86..ffbafea6b 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -53,7 +53,7 @@ class CI_DB_pdo_driver extends CI_DB { * * @var bool */ - public $trans_enabled = FALSE; + public $trans_enabled = TRUE; /** * PDO Options -- cgit v1.2.3-24-g4f1b From 635ced168ce1ce7a91cfef782a1a3c37789f8930 Mon Sep 17 00:00:00 2001 From: Dionysis Arvanitis Date: Tue, 19 Feb 2013 23:11:34 +0200 Subject: DB_driver's trans_complete exception fix --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 35ac8e870..05abd864b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -625,7 +625,7 @@ abstract class CI_DB_driver { // if transactions are enabled. If we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. - $this->trans_complete(); + $this->_trans_depth > 0 && $this->trans_complete(); // Display errors return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql)); -- cgit v1.2.3-24-g4f1b From f8e2d0ed10018f81db5814d421dbafbe6d0834e4 Mon Sep 17 00:00:00 2001 From: Dionysis Arvanitis Date: Tue, 19 Feb 2013 23:27:16 +0200 Subject: Issue #2086 Session_cookie's _update_db not guaranteed to update --- system/libraries/Session/drivers/Session_cookie.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 11bb32fe0..057e5a1d1 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -602,6 +602,9 @@ class CI_Session_cookie extends CI_Session_driver { $set['user_data'] = $this->_serialize($userdata); } + // Reset query builder values. + $this->CI->db->reset_query(); + // Run the update query // Any time we change the session id, it gets updated immediately, // so our where clause below is always safe -- cgit v1.2.3-24-g4f1b From 95da6e75c41bcef079215972efa4a0734be7e8c4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 20 Feb 2013 12:38:44 +0200 Subject: Remove CI_DB_pdo_driver:: Improving on PR #2265, the property is inherited with the same value and doesn't need to be set. --- system/database/drivers/pdo/pdo_driver.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'system') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index ffbafea6b..fa89661b1 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -48,13 +48,6 @@ class CI_DB_pdo_driver extends CI_DB { */ public $dbdriver = 'pdo'; - /** - * Transaction enabled flag - * - * @var bool - */ - public $trans_enabled = TRUE; - /** * PDO Options * -- cgit v1.2.3-24-g4f1b From 3e01437a5b23d9ffdf1b1cc9fc0a0f8b66551342 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 21 Feb 2013 15:59:34 +0200 Subject: Manually apply PR #2234 --- system/database/DB_query_builder.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index c7bc4a699..85a233b50 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2627,6 +2627,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->_reset_run(array( 'qb_set' => array(), 'qb_from' => array(), + 'qb_join' => array(), 'qb_where' => array(), 'qb_orderby' => array(), 'qb_keys' => array(), -- cgit v1.2.3-24-g4f1b From 49e68de96b420a444c826995746a5f09470e76d9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 21 Feb 2013 16:30:55 +0200 Subject: Disable autoloader call from class_exists() occurences to improve performance Note: The Driver libary tests seem to depend on that, so one occurence in CI_Loader is left until we resolve that. --- system/core/CodeIgniter.php | 6 +++--- system/core/Common.php | 4 ++-- system/core/Hooks.php | 2 +- system/core/Loader.php | 10 +++++----- system/core/Output.php | 2 +- system/database/DB.php | 4 ++-- system/database/DB_driver.php | 4 ++-- system/libraries/Cache/drivers/Cache_memcached.php | 4 ++-- system/libraries/Migration.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index cb4b735d5..7f76977b5 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -263,7 +263,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); - if ( ! class_exists($class) OR $method[0] === '_' OR method_exists('CI_Controller', $method)) + if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method)) { if ( ! empty($RTR->routes['404_override'])) { @@ -272,7 +272,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $method = 'index'; } - if ( ! class_exists($class)) + if ( ! class_exists($class, FALSE)) { if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) { @@ -310,7 +310,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $method = 'index'; } - if ( ! class_exists($class)) + if ( ! class_exists($class, FALSE)) { if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) { diff --git a/system/core/Common.php b/system/core/Common.php index f8c1290f5..ee9bb2e87 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -149,7 +149,7 @@ if ( ! function_exists('load_class')) { $name = $prefix.$class; - if (class_exists($name) === FALSE) + if (class_exists($name, FALSE) === FALSE) { require_once($path.$directory.'/'.$class.'.php'); } @@ -163,7 +163,7 @@ if ( ! function_exists('load_class')) { $name = config_item('subclass_prefix').$class; - if (class_exists($name) === FALSE) + if (class_exists($name, FALSE) === FALSE) { require_once(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'); } diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 17f6a027e..b3b111991 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -195,7 +195,7 @@ class CI_Hooks { // Call the requested class and/or function if ($class !== FALSE) { - if ( ! class_exists($class)) + if ( ! class_exists($class, FALSE)) { require($filepath); } diff --git a/system/core/Loader.php b/system/core/Loader.php index 9306a09ef..6e5b58ba7 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -270,7 +270,7 @@ class CI_Loader { continue; } - if ($db_conn !== FALSE && ! class_exists('CI_DB')) + if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE)) { if ($db_conn === TRUE) { @@ -280,7 +280,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('CI_Model')) + if ( ! class_exists('CI_Model', FALSE)) { load_class('Model', 'core'); } @@ -1091,11 +1091,11 @@ class CI_Loader { if ($prefix === '') { - if (class_exists('CI_'.$class)) + if (class_exists('CI_'.$class, FALSE)) { $name = 'CI_'.$class; } - elseif (class_exists(config_item('subclass_prefix').$class)) + elseif (class_exists(config_item('subclass_prefix').$class, FALSE)) { $name = config_item('subclass_prefix').$class; } @@ -1110,7 +1110,7 @@ class CI_Loader { } // Is the class name valid? - if ( ! class_exists($name)) + if ( ! class_exists($name, FALSE)) { log_message('error', 'Non-existent class: '.$name); show_error('Non-existent class: '.$name); diff --git a/system/core/Output.php b/system/core/Output.php index a20841463..25ecd496c 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -395,7 +395,7 @@ class CI_Output { global $BM, $CFG; // Grab the super object if we can. - if (class_exists('CI_Controller')) + if (class_exists('CI_Controller', FALSE)) { $CI =& get_instance(); } diff --git a/system/database/DB.php b/system/database/DB.php index d9104747f..83d973304 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -149,7 +149,7 @@ function &DB($params = '', $query_builder_override = NULL) if ( ! isset($query_builder) OR $query_builder === TRUE) { require_once(BASEPATH.'database/DB_query_builder.php'); - if ( ! class_exists('CI_DB')) + if ( ! class_exists('CI_DB', FALSE)) { /** * CI_DB @@ -162,7 +162,7 @@ function &DB($params = '', $query_builder_override = NULL) class CI_DB extends CI_DB_query_builder { } } } - elseif ( ! class_exists('CI_DB')) + elseif ( ! class_exists('CI_DB', FALSE)) { /** * @ignore diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 35ac8e870..213e2c3a8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -704,7 +704,7 @@ abstract class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if ( ! class_exists($driver)) + if ( ! class_exists($driver, FALSE)) { include_once(BASEPATH.'database/DB_result.php'); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); @@ -1560,7 +1560,7 @@ abstract class CI_DB_driver { */ protected function _cache_init() { - if (class_exists('CI_DB_Cache')) + if (class_exists('CI_DB_Cache', FALSE)) { if (is_object($this->CACHE)) { diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 8096b2650..246a7a264 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -182,11 +182,11 @@ class CI_Cache_memcached extends CI_Driver { } } - if (class_exists('Memcached')) + if (class_exists('Memcached', FALSE)) { $this->_memcached = new Memcached(); } - elseif (class_exists('Memcache')) + elseif (class_exists('Memcache', FALSE)) { $this->_memcached = new Memcache(); } diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index b673e9cb7..cc6fe48f0 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -228,7 +228,7 @@ class CI_Migration { $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); // Validate the migration file structure - if ( ! class_exists($class)) + if ( ! class_exists($class, FALSE)) { $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); return FALSE; diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index d4524d230..d263d789d 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -31,7 +31,7 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } -if ( ! class_exists('CI_Xmlrpc')) +if ( ! class_exists('CI_Xmlrpc', FALSE)) { show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } -- cgit v1.2.3-24-g4f1b From 8cf596b5eabe431572ec1c4f21b9c32101feb22f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 21 Feb 2013 16:44:12 +0200 Subject: DB_result tests seem to also depend on autoloading via the class_exists() checks ... --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 213e2c3a8..f03f56c85 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -704,7 +704,7 @@ abstract class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if ( ! class_exists($driver, FALSE)) + if ( ! class_exists($driver)) { include_once(BASEPATH.'database/DB_result.php'); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); -- cgit v1.2.3-24-g4f1b