diff options
Diffstat (limited to 'system')
102 files changed, 3802 insertions, 3802 deletions
diff --git a/system/core/Base4.php b/system/core/Base4.php index bd0434158..ef7838d69 100644 --- a/system/core/Base4.php +++ b/system/core/Base4.php @@ -32,7 +32,7 @@ * Since PHP 5 doesn't suffer from this problem so we load one of * two files based on the version of PHP being run. * @PHP4 - * + * * @package CodeIgniter * @subpackage codeigniter * @category front-controller @@ -46,7 +46,7 @@ // This allows syntax like $this->load->foo() to work parent::CI_Loader(); $this->load =& $this; - + // This allows resources used within controller constructors to work global $OBJ; $OBJ = $this->load; // Do NOT use a reference. @@ -56,12 +56,12 @@ function &get_instance() { global $CI, $OBJ; - + if (is_object($CI)) { return $CI; } - + return $OBJ->load; } diff --git a/system/core/Base5.php b/system/core/Base5.php index 6f2fbdab0..ac6c7f020 100644 --- a/system/core/Base5.php +++ b/system/core/Base5.php @@ -23,7 +23,7 @@ * run under PHP 5. It allows us to manage the CI super object more * gracefully than what is possible with PHP 4. * @PHP4 (no need for separate Bases after PHP 4 is gone) - * + * * @package CodeIgniter * @subpackage codeigniter * @category front-controller diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index 1149b7a76..80933f424 100644 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -80,13 +80,13 @@ class CI_Benchmark { { $this->marker[$point2] = microtime(); } - + list($sm, $ss) = explode(' ', $this->marker[$point1]); list($em, $es) = explode(' ', $this->marker[$point2]); return number_format(($em + $es) - ($sm + $ss), $decimals); } - + // -------------------------------------------------------------------- /** diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 295917c92..f67bb8c10 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -61,10 +61,10 @@ * ------------------------------------------------------ */ set_error_handler('_exception_handler'); - + if ( ! is_php('5.3')) { - @set_magic_quotes_runtime(0); // Kill magic quotes + @set_magic_quotes_runtime(0); // Kill magic quotes } // Set a liberal script execution time limit @@ -78,18 +78,18 @@ * Set the subclass_prefix * ------------------------------------------------------ * - * Normally the "subclass_prefix" is set in the config file. - * The subclass prefix allows CI to know if a core class is + * Normally the "subclass_prefix" is set in the config file. + * The subclass prefix allows CI to know if a core class is * being extended via a library in the local application - * "libraries" folder. Since CI allows config items to be - * overriden via data set in the main index. php file, - * before proceeding we need to know if a subclass_prefix + * "libraries" folder. Since CI allows config items to be + * overriden via data set in the main index. php file, + * before proceeding we need to know if a subclass_prefix * override exists. If so, we will set this value now, * before any classes are loaded - * Note: Since the config file data is cached it doesn't + * Note: Since the config file data is cached it doesn't * hurt to load it here. */ - if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '') + if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '') { get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); } @@ -121,12 +121,12 @@ * ------------------------------------------------------ * Instantiate the config class * ------------------------------------------------------ - */ + */ $CFG =& load_class('Config', 'core'); // Do we have any manually set config items in the index.php file? if (isset($assign_to_config)) - { + { $CFG->_assign_to_config($assign_to_config); } @@ -134,16 +134,16 @@ * ------------------------------------------------------ * Instantiate the Unicode class * ------------------------------------------------------ - * + * * Note: Order here is rather important as the Unicode * class needs to be used very early on, but it cannot - * properly determine if UTf-8 can be supported until + * properly determine if UTf-8 can be supported until * after the Config class is instantiated. - * + * */ $UNI =& load_class('Unicode', 'core'); - + /* * ------------------------------------------------------ * Instantiate the URI class @@ -155,10 +155,10 @@ * ------------------------------------------------------ * Instantiate the routing class and set the routing * ------------------------------------------------------ - */ + */ $RTR =& load_class('Router', 'core'); $RTR->_set_routing(); - + // Set any routing overrides that may exist in the main index file if (isset($routing)) { @@ -190,7 +190,7 @@ * Load the Input class and sanitize globals * ------------------------------------------------------ */ - $IN =& load_class('Input', 'core'); + $IN =& load_class('Input', 'core'); /* * ------------------------------------------------------ @@ -208,9 +208,9 @@ * conditionally load different versions of the base * class. Retaining PHP 4 compatibility requires a bit of a hack. * @PHP4 - * + * */ - if (is_php('5.0.0') == TRUE) + if (is_php('5.0.0') == TRUE) { require(BASEPATH.'core/Base5'.EXT); } @@ -220,25 +220,25 @@ load_class('Loader', 'core'); require(BASEPATH.'core/Base4'.EXT); } - + // Load the base controller class require BASEPATH.'core/Controller'.EXT; - + if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT)) { require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT; } - + // Load the local application controller - // Note: The Router class automatically validates the controller path using the router->_validate_request(). + // Note: The Router class automatically validates the controller path using the router->_validate_request(). // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid. if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) { show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); } - + include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); - + // Set a mark point for benchmarking $BM->mark('loading_time:_base_classes_end'); @@ -253,7 +253,7 @@ */ $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); - + if ( ! class_exists($class) OR $method == 'controller' OR strncmp($method, '_', 1) == 0 @@ -277,7 +277,7 @@ */ // Mark a start point so we can benchmark the controller $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); - + $CI = new $class(); /* @@ -307,11 +307,11 @@ } // Call the requested method. - // Any URI segments present (besides the class/function) will be passed to the method for convenience - call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); + // Any URI segments present (besides the class/function) will be passed to the method for convenience + call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); } - + // Mark a benchmark end point $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); @@ -331,7 +331,7 @@ { $OUT->_display(); } - + /* * ------------------------------------------------------ * Is there a "post_system" hook? diff --git a/system/core/Common.php b/system/core/Common.php index 2b8ad26b1..90ba7c963 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -43,7 +43,7 @@ { static $_is_php; $version = (string)$version; - + if ( ! isset($_is_php[$version])) { $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; @@ -57,13 +57,13 @@ /** * Tests for file writability * - * is_writable() returns TRUE on Windows servers when you really can't write to + * is_writable() returns TRUE on Windows servers when you really can't write to * the file, based on the read-only attribute. is_writable() is also unreliable * on Unix servers if safe_mode is on. * * @access private * @return void - */ + */ function is_really_writable($file) { // If we're on a Unix server with safe_mode off we call is_writable @@ -115,7 +115,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_') { static $_classes = array(); - + // Does the class exist? If so, we're done... if (isset($_classes[$class])) { @@ -127,25 +127,25 @@ // Look for the class first in the native system/libraries folder // thenin the local application/libraries folder foreach (array(BASEPATH, APPPATH) as $path) - { + { if (file_exists($path.$directory.'/'.$class.EXT)) { $name = $prefix.$class; - + if (class_exists($name) === FALSE) { require($path.$directory.'/'.$class.EXT); } - + break; } } // Is the request a class extension? If so we load it too if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT)) - { + { $name = config_item('subclass_prefix').$class; - + if (class_exists($name) === FALSE) { require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT); @@ -155,8 +155,8 @@ // Did we find the class? if ($name === FALSE) { - // Note: We use exit() rather then show_error() in order to avoid a - // self-referencing loop with the Excptions class + // Note: We use exit() rather then show_error() in order to avoid a + // self-referencing loop with the Excptions class exit('Unable to locate the specified class: '.$class.EXT); } @@ -176,7 +176,7 @@ * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. * * Use: $obj =& instantiate_class(new Foo()); - * + * * @access public * @param object * @return object @@ -221,11 +221,11 @@ function &get_config($replace = array()) { static $_config; - + if (isset($_config)) { return $_config[0]; - } + } // Fetch the config file if ( ! file_exists(APPPATH.'config/config'.EXT)) @@ -254,7 +254,7 @@ } } } - + return $_config[0] =& $config; } @@ -269,18 +269,18 @@ function config_item($item) { static $_config_item = array(); - + if ( ! isset($_config_item[$item])) { $config =& get_config(); - + if ( ! isset($config[$item])) { return FALSE; } $_config_item[$item] = $config[$item]; } - + return $_config_item[$item]; } @@ -343,7 +343,7 @@ { return; } - + $_log =& load_class('Log'); $_log->write_log($level, $message, $php_error); } @@ -354,10 +354,10 @@ * Set HTTP Status Header * * @access public - * @param int the status code - * @param string + * @param int the status code + * @param string * @return void - */ + */ function set_status_header($code = 200, $text = '') { $stati = array( @@ -408,15 +408,15 @@ } if (isset($stati[$code]) AND $text == '') - { + { $text = $stati[$code]; } - + if ($text == '') { show_error('No status text available. Please check your status code number or supply your own message text.', 500); } - + $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; if (substr(php_sapi_name(), 0, 3) == 'cgi') @@ -432,7 +432,7 @@ header("HTTP/1.1 {$code} {$text}", TRUE, $code); } } - + // -------------------------------------------------------------------- /** @@ -450,20 +450,20 @@ * @return void */ function _exception_handler($severity, $message, $filepath, $line) - { + { // We don't bother with "strict" notices since they tend to fill up // the log file with excess information that isn't normally very helpful. - // For example, if you are running PHP 5 and you use version 4 style - // class functions (without prefixes like "public", "private", etc.) + // For example, if you are running PHP 5 and you use version 4 style + // class functions (without prefixes like "public", "private", etc.) // you'll get notices telling you that these have been deprecated. if ($severity == E_STRICT) { return; } - + $_error =& load_class('Exceptions', 'core'); - - // Should we display the error? We'll get the current error_reporting + + // Should we display the error? We'll get the current error_reporting // level and add its bits with the severity bits to find out. if (($severity & error_reporting()) == $severity) { @@ -475,12 +475,12 @@ { return; } - + $_error->log_exception($severity, $message, $filepath, $line); } // -------------------------------------------------------------------- - + /** * Remove Invisible Characters * @@ -494,7 +494,7 @@ function remove_invisible_characters($str) { static $non_displayables; - + if ( ! isset($non_displayables)) { // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), diff --git a/system/core/Compat.php b/system/core/Compat.php index 088d5815a..bd11b9836 100644 --- a/system/core/Compat.php +++ b/system/core/Compat.php @@ -32,7 +32,7 @@ /* * PHP versions prior to 5.0 don't support the E_STRICT constant - * so we need to explicitly define it otherwise the Exception class + * so we need to explicitly define it otherwise the Exception class * will generate errors when running under PHP 4 * @PHP4 * @@ -61,9 +61,9 @@ if ( ! function_exists('ctype_digit')) { return FALSE; } - + return ! preg_match('/[^0-9]/', $str); - } + } } // -------------------------------------------------------------------- @@ -87,9 +87,9 @@ if ( ! function_exists('ctype_alnum')) { return FALSE; } - + return ! preg_match('/[^0-9a-z]/i', $str); - } + } } // -------------------------------------------------------------------- diff --git a/system/core/Config.php b/system/core/Config.php index 7e0443c1f..24503ab5d 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -45,10 +45,10 @@ class CI_Config { */ function CI_Config() { - $this->config =& get_config(); + $this->config =& get_config(); log_message('debug', "Config Class Initialized"); } - + // -------------------------------------------------------------------- /** @@ -57,16 +57,16 @@ class CI_Config { * @access public * @param string the config file name * @return boolean if the file was loaded correctly - */ + */ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); $loaded = FALSE; - + foreach($this->_config_paths as $path) { $file_path = $path.'config/'.$file.EXT; - + if (in_array($file_path, $this->is_loaded, TRUE)) { $loaded = TRUE; @@ -77,7 +77,7 @@ class CI_Config { { continue; } - + include($file_path); if ( ! isset($config) OR ! is_array($config)) @@ -88,7 +88,7 @@ class CI_Config { } show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); } - + if ($use_sections === TRUE) { if (isset($this->config[$file])) @@ -104,14 +104,14 @@ class CI_Config { { $this->config = array_merge($this->config, $config); } - + $this->is_loaded[] = $file_path; unset($config); - + $loaded = TRUE; log_message('debug', 'Config file loaded: '.$file_path); } - + if ($loaded === FALSE) { if ($fail_gracefully === TRUE) @@ -123,7 +123,7 @@ class CI_Config { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -137,9 +137,9 @@ class CI_Config { * @return string */ function item($item, $index = '') - { + { if ($index == '') - { + { if ( ! isset($this->config[$item])) { return FALSE; @@ -164,8 +164,8 @@ class CI_Config { return $pref; } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- /** * Fetch a config file item - adds slash after item @@ -188,13 +188,13 @@ class CI_Config { $pref = $this->config[$item]; if ($pref != '' && substr($pref, -1) != '/') - { + { $pref .= '/'; } return $pref; } - + // -------------------------------------------------------------------- /** @@ -224,9 +224,9 @@ class CI_Config { { $uri = implode('/', $uri); } - + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; + return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; } else { @@ -254,7 +254,7 @@ class CI_Config { } } } - + // -------------------------------------------------------------------- /** @@ -268,7 +268,7 @@ class CI_Config { $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); return $this->slash_item('base_url').end($x).'/'; } - + // -------------------------------------------------------------------- /** @@ -283,7 +283,7 @@ class CI_Config { { $this->config[$item] = $value; } - + // -------------------------------------------------------------------- /** @@ -296,7 +296,7 @@ class CI_Config { * @access private * @param array * @return void - */ + */ function _assign_to_config($items = array()) { if (is_array($items)) @@ -305,7 +305,7 @@ class CI_Config { { $this->set_item($key, $val); } - } + } } } diff --git a/system/core/Controller.php b/system/core/Controller.php index c9d797ca2..9bd9912dc 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -28,18 +28,18 @@ * @link http://codeigniter.com/user_guide/general/controllers.html */ class Controller extends CI_Base { - + /** * Constructor * * Calls the initialize() function */ function Controller() - { + { parent::CI_Base(); // Assign all the class objects that were instantiated by the - // bootstrap file (CodeIgniter.php) to local class variables + // bootstrap file (CodeIgniter.php) to local class variables // so that CI can run as one big super object. foreach (is_loaded() as $var => $class) { @@ -48,18 +48,18 @@ class Controller extends CI_Base { // In PHP 5 the Loader class is run as a discreet // class. In PHP 4 it extends the Controller @PHP4 - if (is_php('5.0.0') == TRUE) + if (is_php('5.0.0') == TRUE) { $this->load =& load_class('Loader', 'core'); - + $this->load->_base_classes =& is_loaded(); - + $this->load->_ci_autoloader(); } else { $this->_ci_autoloader(); - + // sync up the objects since PHP4 was working from a copy foreach (array_keys(get_object_vars($this)) as $attribute) { @@ -71,7 +71,7 @@ class Controller extends CI_Base { } log_message('debug', "Controller Class Initialized"); - + } } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index 419ea2b61..108861de7 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -51,13 +51,13 @@ class CI_Exceptions { /** * Constructor * - */ + */ function CI_Exceptions() { $this->ob_level = ob_get_level(); // Note: Do not log messages from this constructor. } - + // -------------------------------------------------------------------- /** @@ -73,9 +73,9 @@ class CI_Exceptions { * @return string */ function log_exception($severity, $message, $filepath, $line) - { + { $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - + log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } @@ -89,7 +89,7 @@ class CI_Exceptions { * @return string */ function show_404($page = '', $log_error = TRUE) - { + { $heading = "404 Page Not Found"; $message = "The page you requested was not found."; @@ -102,7 +102,7 @@ class CI_Exceptions { echo $this->show_error($heading, $message, 'error_404', 404); exit; } - + // -------------------------------------------------------------------- /** @@ -121,12 +121,12 @@ class CI_Exceptions { function show_error($heading, $message, $template = 'error_general', $status_code = 500) { set_status_header($status_code); - + $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>'; if (ob_get_level() > $this->ob_level + 1) { - ob_end_flush(); + ob_end_flush(); } ob_start(); include(APPPATH.'errors/'.$template.EXT); @@ -148,21 +148,21 @@ class CI_Exceptions { * @return string */ function show_php_error($severity, $message, $filepath, $line) - { + { $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - + $filepath = str_replace("\\", "/", $filepath); - + // For safety reasons we do not show the full file path if (FALSE !== strpos($filepath, '/')) { $x = explode('/', $filepath); $filepath = $x[count($x)-2].'/'.end($x); } - + if (ob_get_level() > $this->ob_level + 1) { - ob_end_flush(); + ob_end_flush(); } ob_start(); include(APPPATH.'errors/error_php'.EXT); diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 3b063f792..9026a5eb6 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -28,8 +28,8 @@ */ class CI_Hooks { - var $enabled = FALSE; - var $hooks = array(); + var $enabled = FALSE; + var $hooks = array(); var $in_progress = FALSE; /** @@ -41,7 +41,7 @@ class CI_Hooks { $this->_initialize(); log_message('debug', "Hooks Class Initialized"); } - + // -------------------------------------------------------------------- /** @@ -49,9 +49,9 @@ class CI_Hooks { * * @access private * @return void - */ - function _initialize() - { + */ + function _initialize() + { $CFG =& load_class('Config', 'core'); // If hooks are not enabled in the config file @@ -74,8 +74,8 @@ class CI_Hooks { $this->hooks =& $hook; $this->enabled = TRUE; - } - + } + // -------------------------------------------------------------------- /** diff --git a/system/core/Input.php b/system/core/Input.php index 2eef82458..df3be207c 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -257,7 +257,7 @@ class CI_Input { { return $this->ip_address; } - + if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); @@ -308,7 +308,7 @@ class CI_Input { * Validate IP Address * * Updated version suggested by Geert De Deckere - * + * * @access public * @param string * @return string @@ -330,7 +330,7 @@ class CI_Input { // Check each segment foreach ($ip_segments as $segment) { - // IP segments must be digits and can not be + // IP segments must be digits and can not be // longer than 3 digits or greater then 255 if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3) { @@ -383,7 +383,7 @@ class CI_Input { $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA', 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN'); - // Unset globals for securiy. + // Unset globals for securiy. // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE) as $global) { diff --git a/system/core/Lang.php b/system/core/Lang.php index e071495b8..cbd4e38b8 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -120,7 +120,7 @@ class CI_Lang { * Fetch a single line of text from the language array * * @access public - * @param string $line the language line + * @param string $line the language line * @return string */ function line($line = '') diff --git a/system/core/Loader.php b/system/core/Loader.php index 292fdc955..69b3da0c9 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -34,7 +34,7 @@ class CI_Loader { var $_ci_library_paths = array(); var $_ci_model_paths = array(); var $_ci_helper_paths = array(); - var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() + var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_base_classes = array(); // Set by the controller class var $_ci_cached_vars = array(); var $_ci_classes = array(); @@ -42,7 +42,7 @@ class CI_Loader { var $_ci_models = array(); var $_ci_helpers = array(); var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); - + /** * Constructor @@ -52,18 +52,18 @@ class CI_Loader { * @access public */ function CI_Loader() - { + { $this->_ci_view_path = APPPATH.'views/'; $this->_ci_ob_level = ob_get_level(); $this->_ci_library_paths = array(APPPATH, BASEPATH); $this->_ci_helper_paths = array(APPPATH, BASEPATH); $this->_ci_model_paths = array(APPPATH); - + log_message('debug', "Loader Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Class Loader * @@ -75,7 +75,7 @@ class CI_Loader { * @param mixed the optional parameters * @param string an optional object name * @return void - */ + */ function library($library = '', $params = NULL, $object_name = NULL) { if ($library == '' OR isset($this->_base_classes[$library])) @@ -99,12 +99,12 @@ class CI_Loader { { $this->_ci_load_class($library, $params, $object_name); } - + $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- - + /** * Model Loader * @@ -115,14 +115,14 @@ class CI_Loader { * @param string name for the model * @param bool database connection * @return void - */ + */ function model($model, $name = '', $db_conn = FALSE) - { + { if (is_array($model)) { foreach($model as $babe) { - $this->model($babe); + $this->model($babe); } return; } @@ -131,9 +131,9 @@ class CI_Loader { { return; } - + $path = ''; - + // Is the model in a sub-folder? If so, parse out the filename and path. if (($last_slash = strrpos($model, '/')) !== FALSE) { @@ -143,23 +143,23 @@ class CI_Loader { // And the model name behind it $model = substr($model, $last_slash + 1); } - + if ($name == '') { $name = $model; } - + if (in_array($name, $this->_ci_models, TRUE)) { return; } - + $CI =& get_instance(); if (isset($CI->$name)) { show_error('The model name you are loading is the name of a resource that is already being used: '.$name); } - + $model = strtolower($model); foreach ($this->_ci_model_paths as $mod_path) @@ -192,13 +192,13 @@ class CI_Loader { $this->_ci_models[] = $name; return; } - + // couldn't find the model show_error('Unable to locate the model you have specified: '.$model); } - + // -------------------------------------------------------------------- - + /** * Database Loader * @@ -207,57 +207,57 @@ class CI_Loader { * @param bool whether to return the DB object * @param bool whether to enable active record (this allows us to override the config setting) * @return object - */ + */ function database($params = '', $return = FALSE, $active_record = NULL) { // Grab the super object $CI =& get_instance(); - + // Do we even need to load the database class? if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) { return FALSE; - } - + } + require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { return DB($params, $active_record); } - - // Initialize the db variable. Needed to prevent + + // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ''; - + // Load the DB class - $CI->db =& DB($params, $active_record); - + $CI->db =& DB($params, $active_record); + // Assign the DB object to any existing models $this->_ci_assign_to_models(); } - + // -------------------------------------------------------------------- /** * Load the Utilities Class * * @access public - * @return string - */ + * @return string + */ function dbutil() { if ( ! class_exists('CI_DB')) { $this->database(); } - + $CI =& get_instance(); // for backwards compatibility, load dbforge so we can extend dbutils off it // this use is deprecated and strongly discouraged $CI->load->dbforge(); - + require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; @@ -266,35 +266,35 @@ class CI_Loader { $CI->load->_ci_assign_to_models(); } - + // -------------------------------------------------------------------- /** * Load the Database Forge Class * * @access public - * @return string - */ + * @return string + */ function dbforge() { if ( ! class_exists('CI_DB')) { $this->database(); } - + $CI =& get_instance(); - + require_once(BASEPATH.'database/DB_forge'.EXT); require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; $CI->dbforge = new $class(); - + $CI->load->_ci_assign_to_models(); } - + // -------------------------------------------------------------------- - + /** * Load View * @@ -316,9 +316,9 @@ class CI_Loader { { return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); } - + // -------------------------------------------------------------------- - + /** * Load File * @@ -333,9 +333,9 @@ class CI_Loader { { return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); } - + // -------------------------------------------------------------------- - + /** * Set Variables * @@ -352,9 +352,9 @@ class CI_Loader { { $vars = array($vars => $val); } - + $vars = $this->_ci_object_to_array($vars); - + if (is_array($vars) AND count($vars) > 0) { foreach ($vars as $key => $val) @@ -363,9 +363,9 @@ class CI_Loader { } } } - + // -------------------------------------------------------------------- - + /** * Load Helper * @@ -376,9 +376,9 @@ class CI_Loader { * @return void */ function helper($helpers = array()) - { + { foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) - { + { if (isset($this->_ci_helpers[$helper])) { continue; @@ -386,33 +386,33 @@ class CI_Loader { $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; - // Is this a helper extension request? + // Is this a helper extension request? if (file_exists($ext_helper)) { $base_helper = BASEPATH.'helpers/'.$helper.EXT; - + if ( ! file_exists($base_helper)) { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } - + include_once($ext_helper); include_once($base_helper); - + $this->_ci_helpers[$helper] = TRUE; log_message('debug', 'Helper loaded: '.$helper); continue; } - + // Try to load the helper foreach ($this->_ci_helper_paths as $path) { if (file_exists($path.'helpers/'.$helper.EXT)) - { + { include_once($path.'helpers/'.$helper.EXT); $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); + log_message('debug', 'Helper loaded: '.$helper); break; } } @@ -420,13 +420,13 @@ class CI_Loader { // unable to load the helper if ( ! isset($this->_ci_helpers[$helper])) { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + show_error('Unable to load the requested file: helpers/'.$helper.EXT); } - } + } } - + // -------------------------------------------------------------------- - + /** * Load Helpers * @@ -441,9 +441,9 @@ class CI_Loader { { $this->helper($helpers); } - + // -------------------------------------------------------------------- - + /** * Loads a language file * @@ -462,13 +462,13 @@ class CI_Loader { } foreach ($file as $langfile) - { + { $CI->lang->load($langfile, $lang); } } - + // -------------------------------------------------------------------- - + /** * Loads a config file * @@ -477,7 +477,7 @@ class CI_Loader { * @return void */ function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { + { $CI =& get_instance(); $CI->config->load($file, $use_sections, $fail_gracefully); } @@ -501,19 +501,19 @@ class CI_Loader { // we aren't instantiating an object here, that'll be done by the Library itself require BASEPATH.'libraries/Driver'.EXT; } - + // We can save the loader some time since Drivers will *always* be in a subfolder, // and typically identically named to the library if ( ! strpos($library, '/')) { $library = ucfirst($library).'/'.$library; } - + return $this->library($library, $params, $object_name); } // -------------------------------------------------------------------- - + /** * Add Package Path * @@ -528,7 +528,7 @@ class CI_Loader { array_unshift($this->_ci_library_paths, $path); array_unshift($this->_ci_model_paths, $path); array_unshift($this->_ci_helper_paths, $path); - + // Add config file path $config =& $this->_ci_get_component('config'); array_unshift($config->_config_paths, $path); @@ -549,7 +549,7 @@ class CI_Loader { function remove_package_path($path = '', $remove_config_path = TRUE) { $config =& $this->_ci_get_component('config'); - + if ($path == '') { $void = array_shift($this->_ci_library_paths); @@ -566,13 +566,13 @@ class CI_Loader { unset($this->{$var}[$key]); } } - + if (($key = array_search($path, $config->_config_paths)) !== FALSE) { unset($config->_config_paths[$key]); } } - + // make sure the application default paths are still in the array $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); @@ -581,7 +581,7 @@ class CI_Loader { } // -------------------------------------------------------------------- - + /** * Loader * @@ -613,16 +613,16 @@ class CI_Loader { $_ci_x = explode('/', $_ci_path); $_ci_file = end($_ci_x); } - + if ( ! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } - + // This allows anything loaded using $this->load (views, files, etc.) // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 - + if ($this->_ci_is_instance()) { $_ci_CI =& get_instance(); @@ -642,13 +642,13 @@ class CI_Loader { * function or via the second parameter of this function. We'll merge * the two types and cache them so that views that are embedded within * other views can have access to these variables. - */ + */ if (is_array($_ci_vars)) { $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); } extract($this->_ci_cached_vars); - + /* * Buffer the output * @@ -662,11 +662,11 @@ class CI_Loader { * the browser and then stop the timer it won't be accurate. */ ob_start(); - + // If the PHP installation does not support short tags we'll // do a little string replacement, changing the short tags // to standard PHP echo statements. - + if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path)))); @@ -675,12 +675,12 @@ class CI_Loader { { include($_ci_path); // include() vs include_once() allows for multiple views with the same name } - + log_message('debug', 'File loaded: '.$_ci_path); - + // Return the file data if requested if ($_ci_return === TRUE) - { + { $buffer = ob_get_contents(); @ob_end_clean(); return $buffer; @@ -695,7 +695,7 @@ class CI_Loader { * it can be seen and included properly by the first included * template and any subsequent ones. Oy! * - */ + */ if (ob_get_level() > $this->_ci_ob_level + 1) { ob_end_flush(); @@ -717,18 +717,18 @@ class CI_Loader { * This function loads the requested class. * * @access private - * @param string the item that is being loaded + * @param string the item that is being loaded * @param mixed any additional parameters * @param string an optional object name - * @return void + * @return void */ function _ci_load_class($class, $params = NULL, $object_name = NULL) - { - // Get the class name, and while we're at it trim any slashes. - // The directory path can be included as part of the class name, + { + // Get the class name, and while we're at it trim any slashes. + // The directory path can be included as part of the class name, // but we don't want a leading slash $class = str_replace(EXT, '', trim($class, '/')); - + // Was the path included with the class name? // We look for a slash to determine this $subdir = ''; @@ -736,7 +736,7 @@ class CI_Loader { { // Extract the path $subdir = substr($class, 0, $last_slash + 1); - + // Get the filename from the path $class = substr($class, $last_slash + 1); } @@ -746,11 +746,11 @@ class CI_Loader { { $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; - // Is this a class extension request? + // Is this a class extension request? if (file_exists($subclass)) { $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - + if ( ! file_exists($baseclass)) { log_message('error', "Unable to load the requested class: ".$class); @@ -768,22 +768,22 @@ class CI_Loader { $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($baseclass); include_once($subclass); $this->_ci_loaded_files[] = $subclass; - - 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); } - + // Lets search for the requested library file and load it. $is_duplicate = FALSE; foreach ($this->_ci_library_paths as $path) @@ -795,7 +795,7 @@ class CI_Loader { { continue; } - + // Safety: Was the class already loaded by a previous call? if (in_array($filepath, $this->_ci_loaded_files)) { @@ -810,15 +810,15 @@ class CI_Loader { 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); + return $this->_ci_init_class($class, '', $params, $object_name); } } // END FOREACH @@ -829,7 +829,7 @@ class CI_Loader { $path = strtolower($class).'/'.$class; return $this->_ci_load_class($path, $params); } - + // 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) @@ -838,7 +838,7 @@ class CI_Loader { show_error("Unable to load the requested class: ".$class); } } - + // -------------------------------------------------------------------- /** @@ -851,7 +851,7 @@ class CI_Loader { * @return null */ function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) - { + { // Is there an associated config file for this class? Note: these should always be lowercase if ($config === NULL) { @@ -860,20 +860,20 @@ class CI_Loader { if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) { include_once(APPPATH.'config/'.strtolower($class).EXT); - } + } elseif (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) { include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); } } - + if ($prefix == '') - { - if (class_exists('CI_'.$class)) + { + if (class_exists('CI_'.$class)) { $name = 'CI_'.$class; } - elseif (class_exists(config_item('subclass_prefix').$class)) + elseif (class_exists(config_item('subclass_prefix').$class)) { $name = config_item('subclass_prefix').$class; } @@ -886,18 +886,18 @@ class CI_Loader { { $name = $prefix.$class; } - + // Is the class name valid? if ( ! class_exists($name)) { log_message('error', "Non-existent class: ".$name); show_error("Non-existent class: ".$class); } - + // Set the variable name we will assign the class to // Was a custom class name supplied? If so we'll use it $class = strtolower($class); - + if (is_null($object_name)) { $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; @@ -907,23 +907,23 @@ class CI_Loader { $classvar = $object_name; } - // Save the class name and object name + // Save the class name and object name $this->_ci_classes[$class] = $classvar; - // Instantiate the class + // Instantiate the class $CI =& get_instance(); if ($config !== NULL) { $CI->$classvar = new $name($config); } else - { + { $CI->$classvar = new $name; - } - } - + } + } + // -------------------------------------------------------------------- - + /** * Autoloader * @@ -935,31 +935,31 @@ class CI_Loader { * @return void */ function _ci_autoloader() - { + { include_once(APPPATH.'config/autoload'.EXT); - + if ( ! isset($autoload)) { return FALSE; } - + // Load any custom config file if (count($autoload['config']) > 0) - { + { $CI =& get_instance(); foreach ($autoload['config'] as $key => $val) { $CI->config->load($val); } - } + } // Autoload helpers and languages foreach (array('helper', 'language') as $type) - { + { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { $this->$type($autoload[$type]); - } + } } // A little tweak to remain backward compatible @@ -968,7 +968,7 @@ class CI_Loader { { $autoload['libraries'] = $autoload['core']; } - + // Load libraries if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) { @@ -978,13 +978,13 @@ class CI_Loader { $this->database(); $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); } - + // Load all other libraries foreach ($autoload['libraries'] as $item) { $this->library($item); } - } + } // Autoload models if (isset($autoload['model'])) @@ -993,7 +993,7 @@ class CI_Loader { } } - + // -------------------------------------------------------------------- /** @@ -1012,13 +1012,13 @@ class CI_Loader { { return; } - + foreach($this->_ci_models as $model) { $model = $this->_ci_get_component($model); $model->_assign_libraries(); } - } + } // -------------------------------------------------------------------- @@ -1041,7 +1041,7 @@ class CI_Loader { /** * Determines whether we should use the CI instance or $this * @PHP4 - * + * * @access private * @return bool */ @@ -1051,11 +1051,11 @@ class CI_Loader { { return TRUE; } - + global $CI; return (is_object($CI)) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- /** @@ -1078,7 +1078,7 @@ class CI_Loader { } // -------------------------------------------------------------------- - + /** * Prep filename * @@ -1091,20 +1091,20 @@ class CI_Loader { function _ci_prep_filename($filename, $extension) { if ( ! is_array($filename)) - { - return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension)); + { + return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension)); } else { foreach ($filename as $key => $val) { - $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension); + $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension); } - + return $filename; } } - + } diff --git a/system/core/Model.php b/system/core/Model.php index 16c4e7dd8..ebbb0fbe6 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -37,11 +37,11 @@ class CI_Model { { // If the magic __get() or __set() methods are used in a Model references can't be used. $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - + // We don't want to assign the model object to itself when using the // assign_libraries function below so we'll grab the name of the model parent $this->_parent_name = ucfirst(get_class($this)); - + log_message('debug', "Model Class Initialized"); } @@ -50,17 +50,17 @@ class CI_Model { * * Creates local references to all currently instantiated objects * so that any syntax that can be legally used in a controller - * can be used within models. + * can be used within models. * * @access private - */ + */ function _assign_libraries($use_reference = TRUE) { - $CI =& get_instance(); + $CI =& get_instance(); foreach (array_keys(get_object_vars($CI)) as $key) { if ( ! isset($this->$key) AND $key != $this->_parent_name) - { + { // In some cases using references can cause // problems so we'll conditionally use them if ($use_reference == TRUE) @@ -74,7 +74,7 @@ class CI_Model { $this->$key = $CI->$key; } } - } + } } } diff --git a/system/core/Output.php b/system/core/Output.php index ad9ffbabe..04e452d2c 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -30,8 +30,8 @@ class CI_Output { var $final_output; var $cache_expiration = 0; - var $headers = array(); - var $enable_profiler = FALSE; + var $headers = array(); + var $enable_profiler = FALSE; var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage} var $_zlib_oc = FALSE; @@ -40,12 +40,12 @@ class CI_Output { function CI_Output() { $this->_zlib_oc = @ini_get('zlib.output_compression'); - + log_message('debug', "Output Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Get Output * @@ -53,14 +53,14 @@ class CI_Output { * * @access public * @return string - */ + */ function get_output() { return $this->final_output; } - + // -------------------------------------------------------------------- - + /** * Set Output * @@ -69,7 +69,7 @@ class CI_Output { * @access public * @param string * @return void - */ + */ function set_output($output) { $this->final_output = $output; @@ -85,7 +85,7 @@ class CI_Output { * @access public * @param string * @return void - */ + */ function append_output($output) { if ($this->final_output == '') @@ -111,52 +111,52 @@ class CI_Output { * @access public * @param string * @return void - */ + */ function set_header($header, $replace = TRUE) { // If zlib.output_compression is enabled it will compress the output, // but it will not modify the content-length header to compensate for // the reduction, causing the browser to hang waiting for more data. // We'll just skip content-length in those cases. - + if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0) { return; } - + $this->headers[] = array($header, $replace); } // -------------------------------------------------------------------- - + /** * Set HTTP Status Header * moved to Common procedural functions in 1.7.2 - * + * * @access public - * @param int the status code - * @param string + * @param int the status code + * @param string * @return void - */ + */ function set_status_header($code = 200, $text = '') { set_status_header($code, $text); } - + // -------------------------------------------------------------------- - + /** * Enable/disable Profiler * * @access public * @param bool * @return void - */ + */ function enable_profiler($val = TRUE) { $this->enable_profiler = (is_bool($val)) ? $val : TRUE; } - + // -------------------------------------------------------------------- /** @@ -177,21 +177,21 @@ class CI_Output { } // -------------------------------------------------------------------- - + /** * Set Cache * * @access public * @param integer * @return void - */ + */ function cache($time) { $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; } - + // -------------------------------------------------------------------- - + /** * Display Output * @@ -205,9 +205,9 @@ class CI_Output { * * @access public * @return mixed - */ + */ function _display($output = '') - { + { // Note: We use globals because we can't use $CI =& get_instance() // since this function is sometimes called by the caching mechanism, // which happens before the CI super object is available. @@ -220,15 +220,15 @@ class CI_Output { } // -------------------------------------------------------------------- - + // Set the output data if ($output == '') { $output =& $this->final_output; } - + // -------------------------------------------------------------------- - + // Do we need to write a cache file? Only if the controller does not have its // own _output() method and we are not dealing with a cache file, which we // can determine by the existence of the $CI object above @@ -236,24 +236,24 @@ class CI_Output { { $this->_write_cache($output); } - + // -------------------------------------------------------------------- // Parse out the elapsed time and memory usage, // then swap the pseudo-variables with the data - - $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); + + $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); if ($this->parse_exec_vars === TRUE) { $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - + $output = str_replace('{elapsed_time}', $elapsed, $output); $output = str_replace('{memory_usage}', $memory, $output); } // -------------------------------------------------------------------- - + // Is compression requested? if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE) { @@ -267,7 +267,7 @@ class CI_Output { } // -------------------------------------------------------------------- - + // Are there any server headers to send? if (count($this->headers) > 0) { @@ -275,10 +275,10 @@ class CI_Output { { @header($header[0], $header[1]); } - } + } // -------------------------------------------------------------------- - + // Does the $CI object exist? // If not we know we are dealing with a cache file so we'll // simply echo out the data and exit. @@ -289,19 +289,19 @@ class CI_Output { log_message('debug', "Total execution time: ".$elapsed); return TRUE; } - + // -------------------------------------------------------------------- - + // Do we need to generate profile data? // If so, load the Profile class and run it. if ($this->enable_profiler == TRUE) { - $CI->load->library('profiler'); - + $CI->load->library('profiler'); + if ( ! empty($this->_profiler_sections)) { $CI->profiler->set_sections($this->_profiler_sections); - } + } // If the output data contains closing </body> and </html> tags // we will remove them and add them back after we insert the profile data @@ -316,7 +316,7 @@ class CI_Output { $output .= $CI->profiler->run(); } } - + // -------------------------------------------------------------------- // Does the controller contain a function named _output()? @@ -329,36 +329,36 @@ class CI_Output { { echo $output; // Send it to the browser! } - + log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); + log_message('debug', "Total execution time: ".$elapsed); } - + // -------------------------------------------------------------------- - + /** * Write a Cache File * * @access public * @return void - */ + */ function _write_cache($output) { - $CI =& get_instance(); + $CI =& get_instance(); $path = $CI->config->item('cache_path'); - + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { log_message('error', "Unable to write cache file: ".$cache_path); return; } - + $uri = $CI->config->item('base_url'). $CI->config->item('index_page'). $CI->uri->uri_string(); - + $cache_path .= md5($uri); if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE)) @@ -366,9 +366,9 @@ class CI_Output { log_message('error', "Unable to write cache file: ".$cache_path); return; } - + $expire = time() + ($this->cache_expiration * 60); - + if (flock($fp, LOCK_EX)) { fwrite($fp, $expire.'TS--->'.$output); @@ -386,51 +386,51 @@ class CI_Output { } // -------------------------------------------------------------------- - + /** * Update/serve a cached file * * @access public * @return void - */ + */ function _display_cache(&$CFG, &$URI) { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - + // Build the file path. The file name is an MD5 hash of the full URI $uri = $CFG->item('base_url'). $CFG->item('index_page'). $URI->uri_string; - + $filepath = $cache_path.md5($uri); - + if ( ! @file_exists($filepath)) { return FALSE; } - + if ( ! $fp = @fopen($filepath, FOPEN_READ)) { return FALSE; } - + flock($fp, LOCK_SH); - + $cache = ''; if (filesize($filepath) > 0) { $cache = fread($fp, filesize($filepath)); } - + flock($fp, LOCK_UN); fclose($fp); - - // Strip out the embedded timestamp + + // Strip out the embedded timestamp if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) { return FALSE; } - + // Has the file expired? If so we'll delete it. if (time() >= trim(str_replace('TS--->', '', $match['1']))) { @@ -438,13 +438,13 @@ class CI_Output { { @unlink($filepath); log_message('debug', "Cache file has expired. File deleted"); - return FALSE; + return FALSE; } } // Display the cache $this->_display(str_replace($match['0'], '', $cache)); - log_message('debug', "Cache file is current. Sending it to browser."); + log_message('debug', "Cache file is current. Sending it to browser."); return TRUE; } diff --git a/system/core/Router.php b/system/core/Router.php index d911eb224..918ea24bf 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -28,14 +28,14 @@ */ class CI_Router { - var $config; - var $routes = array(); + var $config; + var $routes = array(); var $error_routes = array(); var $class = ''; var $method = 'index'; var $directory = ''; var $default_controller; - + /** * Constructor * @@ -47,9 +47,9 @@ class CI_Router { $this->uri =& load_class('URI', 'core'); log_message('debug', "Router Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Set the route mapping * @@ -60,9 +60,9 @@ class CI_Router { * @return void */ function _set_routing() - { + { // Are query strings enabled in the config file? Normally CI doesn't utilize query strings - // since URI segments are more search-engine friendly, but they can optionally be used. + // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently $segments = array(); if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) @@ -72,65 +72,65 @@ class CI_Router { $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); $segments[] = $this->fetch_directory(); } - + if (isset($_GET[$this->config->item('controller_trigger')])) { $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); $segments[] = $this->fetch_class(); } - + if (isset($_GET[$this->config->item('function_trigger')])) { $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); $segments[] = $this->fetch_method(); } } - + // Load the routes.php file. @include(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); - + // Set the default controller so we can display it in the event // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + // Were there any query string segments? If so, we'll validate them and bail out since we're done. if (count($segments) > 0) { return $this->_validate_request($segments); } - + // Fetch the complete URI string $this->uri->_fetch_uri_string(); - + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. if ($this->uri->uri_string == '') { return $this->_set_default_controller(); } - + // Do we need to remove the URL suffix? $this->uri->_remove_url_suffix(); - + // Compile the segments into an array $this->uri->_explode_segments(); - + // Parse any custom routing that may exist - $this->_parse_routes(); - + $this->_parse_routes(); + // Re-index the segment array so that it starts with 1 rather than 0 $this->uri->_reindex_segments(); } // -------------------------------------------------------------------- - + /** * Set the default controller * * @access private * @return void - */ + */ function _set_default_controller() { if ($this->default_controller === FALSE) @@ -141,26 +141,26 @@ class CI_Router { if (strpos($this->default_controller, '/') !== FALSE) { $x = explode('/', $this->default_controller); - + $this->set_class($x[0]); $this->set_method($x[1]); $this->_set_request(array($x[0], $x[1])); - } + } else { $this->set_class($this->default_controller); $this->set_method('index'); $this->_set_request(array($this->default_controller, 'index')); } - + // re-index the routed segments array so it starts with 1 rather than 0 $this->uri->_reindex_segments(); - + log_message('debug', "No URI present. Default controller set."); } - + // -------------------------------------------------------------------- - + /** * Set the Route * @@ -173,16 +173,16 @@ class CI_Router { * @return void */ function _set_request($segments = array()) - { + { $segments = $this->_validate_request($segments); - + if (count($segments) == 0) { return $this->_set_default_controller(); } - + $this->set_class($segments[0]); - + if (isset($segments[1])) { // A standard method request @@ -194,15 +194,15 @@ class CI_Router { // index method is being used. $segments[1] = 'index'; } - + // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be // identical to $this->uri->segments $this->uri->rsegments = $segments; } - + // -------------------------------------------------------------------- - + /** * Validates the supplied segments. Attempts to determine the path to * the controller. @@ -210,33 +210,33 @@ class CI_Router { * @access private * @param array * @return array - */ + */ function _validate_request($segments) { if (count($segments) == 0) { return $segments; } - + // Does the requested controller exist in the root folder? if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) { return $segments; } - + // Is the controller in a sub-folder? if (is_dir(APPPATH.'controllers/'.$segments[0])) { // Set the directory and remove it from the segment array $this->set_directory($segments[0]); $segments = array_slice($segments, 1); - + if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { - show_404($this->fetch_directory().$segments[0]); + show_404($this->fetch_directory().$segments[0]); } } else @@ -245,29 +245,29 @@ class CI_Router { if (strpos($this->default_controller, '/') !== FALSE) { $x = explode('/', $this->default_controller); - + $this->set_class($x[0]); $this->set_method($x[1]); - } + } else { $this->set_class($this->default_controller); $this->set_method('index'); } - + // Does the default controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); } - + } - + return $segments; } - - + + // If we've gotten this far it means that the URI does not correlate to a valid // controller class. We will now see if there is an override if (isset($this->routes['404_override']) AND $this->routes['404_override'] != '') @@ -275,20 +275,20 @@ class CI_Router { if (strpos($this->routes['404_override'], '/') !== FALSE) { $x = explode('/', $this->routes['404_override']); - + $this->set_class($x[0]); $this->set_method($x[1]); - + return $x; - } + } } - + // Nothing else to do at this point but show a 404 - show_404($segments[0]); + show_404($segments[0]); } - + // -------------------------------------------------------------------- - + /** * Parse Routes * @@ -303,16 +303,16 @@ class CI_Router { { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); - + // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { return $this->_set_request(explode('/', $this->routes[$uri])); } - + // Loop through the route array looking for wild-cards foreach ($this->routes as $key => $val) - { + { // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); @@ -324,8 +324,8 @@ class CI_Router { { $val = preg_replace('#^'.$key.'$#', $val, $uri); } - - return $this->_set_request(explode('/', $val)); + + return $this->_set_request(explode('/', $val)); } } @@ -335,54 +335,54 @@ class CI_Router { } // -------------------------------------------------------------------- - + /** * Set the class name * * @access public * @param string * @return void - */ + */ function set_class($class) { $this->class = str_replace(array('/', '.'), '', $class); } - + // -------------------------------------------------------------------- - + /** * Fetch the current class * * @access public * @return string - */ + */ function fetch_class() { return $this->class; } - + // -------------------------------------------------------------------- - + /** * Set the method name * * @access public * @param string * @return void - */ + */ function set_method($method) { $this->method = $method; } // -------------------------------------------------------------------- - + /** * Fetch the current method * * @access public * @return string - */ + */ function fetch_method() { if ($this->method == $this->fetch_class()) @@ -394,58 +394,58 @@ class CI_Router { } // -------------------------------------------------------------------- - + /** * Set the directory name * * @access public * @param string * @return void - */ + */ function set_directory($dir) { $this->directory = str_replace(array('/', '.'), '', $dir).'/'; } // -------------------------------------------------------------------- - + /** * Fetch the sub-directory (if any) that contains the requested controller class * * @access public * @return string - */ + */ function fetch_directory() { return $this->directory; } // -------------------------------------------------------------------- - + /** * Set the controller overrides * * @access public * @param array * @return null - */ + */ function _set_overrides($routing) { if ( ! is_array($routing)) { return; } - + if (isset($routing['directory'])) { $this->set_directory($routing['directory']); } - + if (isset($routing['controller']) AND $routing['controller'] != '') { $this->set_class($routing['controller']); } - + if (isset($routing['function'])) { $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function']; diff --git a/system/core/URI.php b/system/core/URI.php index cffffc20d..a3bd45091 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -195,7 +195,7 @@ class CI_URI { } // Convert programatic characters to entities - $bad = array('$', '(', ')', '%28', '%29'); + $bad = array('$', '(', ')', '%28', '%29'); $good = array('$', '(', ')', '(', ')'); return str_replace($bad, $good, $str); @@ -321,7 +321,7 @@ class CI_URI { */ function uri_to_assoc($n = 3, $default = array()) { - return $this->_uri_to_assoc($n, $default, 'segment'); + return $this->_uri_to_assoc($n, $default, 'segment'); } /** * Identical to above only it uses the re-routed segment array @@ -329,7 +329,7 @@ class CI_URI { */ function ruri_to_assoc($n = 3, $default = array()) { - return $this->_uri_to_assoc($n, $default, 'rsegment'); + return $this->_uri_to_assoc($n, $default, 'rsegment'); } // -------------------------------------------------------------------- diff --git a/system/core/Unicode.php b/system/core/Unicode.php index c8f1203f7..ecc8d3042 100644 --- a/system/core/Unicode.php +++ b/system/core/Unicode.php @@ -30,14 +30,14 @@ class CI_Unicode { /** * Constructor - * + * * Determines if UTF-8 support is to be enabled - * + * */ function CI_Unicode() { log_message('debug', "Unicode Class Initialized"); - + global $CFG; if ( @@ -48,7 +48,7 @@ class CI_Unicode { ) { log_message('debug', "Unicode Class - UTF-8 Support Enabled"); - + define('UTF8_ENABLED', TRUE); // set internal encoding for multibyte string functions if necessary @@ -68,11 +68,11 @@ class CI_Unicode { { log_message('debug', "Unicode Class - UTF-8 Support Disabled"); define('UTF8_ENABLED', FALSE); - } + } } - + // -------------------------------------------------------------------- - + /** * Clean UTF-8 strings * @@ -88,19 +88,19 @@ class CI_Unicode { { $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str); } - + return $str; } // -------------------------------------------------------------------- - + /** * Remove ASCII control characters * * Removes all ASCII control characters except horizontal tabs, * line feeds, and carriage returns, as all others can cause * problems in XML - * + * * @access public * @param string * @return string @@ -111,7 +111,7 @@ class CI_Unicode { } // -------------------------------------------------------------------- - + /** * Convert to UTF-8 * @@ -136,12 +136,12 @@ class CI_Unicode { { return FALSE; } - + return $str; } // -------------------------------------------------------------------- - + /** * Is ASCII? * @@ -157,7 +157,7 @@ class CI_Unicode { } // -------------------------------------------------------------------- - + } // End Unicode Class diff --git a/system/database/DB.php b/system/database/DB.php index a91ca08fa..1b4eb8bec 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -28,39 +28,39 @@ function &DB($params = '', $active_record_override = NULL) if (is_string($params) AND strpos($params, '://') === FALSE) { include(APPPATH.'config/database'.EXT); - + if ( ! isset($db) OR count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } - + if ($params != '') { $active_group = $params; } - + if ( ! isset($active_group) OR ! isset($db[$active_group])) { show_error('You have specified an invalid database connection group.'); } - + $params = $db[$active_group]; } elseif (is_string($params)) { - + /* parse the URL from the DSN string - * Database settings can be passed as discreet - * parameters or as a data source name in the first - * parameter. DSNs must have this prototype: - * $dsn = 'driver://username:password@hostname/database'; - */ - + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + if (($dns = @parse_url($params)) === FALSE) { show_error('Invalid DB Connection String'); } - + $params = array( 'dbdriver' => $dns['scheme'], 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', @@ -68,7 +68,7 @@ function &DB($params = '', $active_record_override = NULL) 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' ); - + // were additional config items set? if (isset($dns['query'])) { @@ -90,7 +90,7 @@ function &DB($params = '', $active_record_override = NULL) } } } - + // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') { @@ -101,18 +101,18 @@ function &DB($params = '', $active_record_override = NULL) // we need to dynamically create a class that extends proper parent class // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() - + if ($active_record_override !== NULL) { $active_record = $active_record_override; } - + require_once(BASEPATH.'database/DB_driver'.EXT); if ( ! isset($active_record) OR $active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); - + if ( ! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_active_record { }'); @@ -125,25 +125,25 @@ function &DB($params = '', $active_record_override = NULL) eval('class CI_DB extends CI_DB_driver { }'); } } - + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; $DB =& instantiate_class(new $driver($params)); - + if ($DB->autoinit == TRUE) { $DB->initialize(); } - + if (isset($params['stricton']) && $params['stricton'] == TRUE) { - $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); + $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); } - + return $DB; -} +} diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 25645a050..ce50479cc 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -41,13 +41,13 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_offset = FALSE; var $ar_order = FALSE; var $ar_orderby = array(); - var $ar_set = array(); + var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); var $ar_store_array = array(); - + // Active Record Caching variables - var $ar_caching = FALSE; + var $ar_caching = FALSE; var $ar_cache_exists = array(); var $ar_cache_select = array(); var $ar_cache_from = array(); @@ -57,7 +57,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_groupby = array(); var $ar_cache_having = array(); var $ar_cache_orderby = array(); - var $ar_cache_set = array(); + var $ar_cache_set = array(); // -------------------------------------------------------------------- @@ -73,12 +73,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function select($select = '*', $escape = NULL) { - // Set the global value if this was sepecified + // Set the global value if this was sepecified if (is_bool($escape)) { $this->_protect_identifiers = $escape; } - + if (is_string($select)) { $select = explode(',', $select); @@ -118,7 +118,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } - + // -------------------------------------------------------------------- /** @@ -179,7 +179,7 @@ class CI_DB_active_record extends CI_DB_driver { * select_min() * select_avg() * select_sum() - * + * * @access public * @param string the field * @param string an alias @@ -191,29 +191,29 @@ class CI_DB_active_record extends CI_DB_driver { { $this->display_error('db_invalid_query'); } - + $type = strtoupper($type); - + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) { show_error('Invalid function type: '.$type); } - + if ($alias == '') { $alias = $this->_create_alias_from_table(trim($select)); } - + $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; $this->ar_cache_exists[] = 'select'; } - + return $this; } @@ -232,7 +232,7 @@ class CI_DB_active_record extends CI_DB_driver { { return end(explode('.', $item)); } - + return $item; } @@ -252,7 +252,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; } - + // -------------------------------------------------------------------- /** @@ -276,12 +276,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($v); $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); $this->ar_cache_exists[] = 'from'; - } + } } } @@ -290,11 +290,11 @@ class CI_DB_active_record extends CI_DB_driver { $val = trim($val); // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($val); - + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); @@ -320,7 +320,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function join($table, $cond, $type = '') - { + { if ($type != '') { $type = strtoupper(trim($type)); @@ -336,7 +336,7 @@ class CI_DB_active_record extends CI_DB_driver { } // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); // Strip apart the condition and protect the identifiers @@ -344,10 +344,10 @@ class CI_DB_active_record extends CI_DB_driver { { $match[1] = $this->_protect_identifiers($match[1]); $match[3] = $this->_protect_identifiers($match[3]); - - $cond = $match[1].$match[2].$match[3]; + + $cond = $match[1].$match[2].$match[3]; } - + // Assemble the JOIN statement $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; @@ -378,7 +378,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where($key, $value, 'AND ', $escape); } - + // -------------------------------------------------------------------- /** @@ -416,7 +416,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + // If the escape value was not set will will base it on the global setting if ( ! is_bool($escape)) { @@ -432,13 +432,13 @@ class CI_DB_active_record extends CI_DB_driver { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - + if ( ! is_null($v)) { if ($escape === TRUE) { $k = $this->_protect_identifiers($k, FALSE, $escape); - + $v = ' '.$this->escape($v); } @@ -449,19 +449,19 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $k = $this->_protect_identifiers($k, FALSE, $escape); + $k = $this->_protect_identifiers($k, FALSE, $escape); } $this->ar_where[] = $prefix.$k.$v; - + if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; $this->ar_cache_exists[] = 'where'; } - + } - + return $this; } @@ -482,7 +482,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where_in($key, $values); } - + // -------------------------------------------------------------------- /** @@ -518,7 +518,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where_in($key, $values, TRUE); } - + // -------------------------------------------------------------------- /** @@ -548,7 +548,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string The field to search * @param array The values searched on * @param boolean If the statement would be IN or NOT IN - * @param string + * @param string * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') @@ -557,12 +557,12 @@ class CI_DB_active_record extends CI_DB_driver { { return; } - + if ( ! is_array($values)) { $values = array($values); } - + $not = ($not) ? ' NOT' : ''; foreach ($values as $value) @@ -571,7 +571,7 @@ class CI_DB_active_record extends CI_DB_driver { } $prefix = (count($this->ar_where) == 0) ? '' : $type; - + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; $this->ar_where[] = $where_in; @@ -585,7 +585,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_wherein = array(); return $this; } - + // -------------------------------------------------------------------- /** @@ -621,7 +621,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -657,7 +657,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -677,7 +677,7 @@ class CI_DB_active_record extends CI_DB_driver { { $field = array($field => $match); } - + foreach ($field as $k => $v) { $k = $this->_protect_identifiers($k); @@ -711,11 +711,11 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_cache_like[] = $like_statement; $this->ar_cache_exists[] = 'like'; } - + } return $this; } - + // -------------------------------------------------------------------- /** @@ -731,15 +731,15 @@ class CI_DB_active_record extends CI_DB_driver { { $by = explode(',', $by); } - + foreach ($by as $val) { $val = trim($val); - + if ($val != '') { $this->ar_groupby[] = $this->_protect_identifiers($val); - + if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); @@ -766,7 +766,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND ', $escape); } - + // -------------------------------------------------------------------- /** @@ -783,7 +783,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'OR ', $escape); } - + // -------------------------------------------------------------------- /** @@ -802,7 +802,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; @@ -821,7 +821,7 @@ class CI_DB_active_record extends CI_DB_driver { { $v = ' '.$this->escape_str($v); } - + $this->ar_having[] = $prefix.$k.$v; if ($this->ar_caching === TRUE) { @@ -829,10 +829,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_cache_exists[] = 'having'; } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -854,8 +854,8 @@ class CI_DB_active_record extends CI_DB_driver { { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - - + + if (strpos($orderby, ',') !== FALSE) { $temp = array(); @@ -866,19 +866,19 @@ class CI_DB_active_record extends CI_DB_driver { { $part = $this->_protect_identifiers(trim($part)); } - + $temp[] = $part; } - - $orderby = implode(', ', $temp); + + $orderby = implode(', ', $temp); } else if ($direction != $this->_random_keyword) { $orderby = $this->_protect_identifiers($orderby); } - + $orderby_statement = $orderby.$direction; - + $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) { @@ -888,7 +888,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -907,10 +907,10 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_offset = $offset; } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -925,7 +925,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_offset = $offset; return $this; } - + // -------------------------------------------------------------------- /** @@ -940,11 +940,11 @@ class CI_DB_active_record extends CI_DB_driver { function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); - + if ( ! is_array($key)) { $key = array($key => $value); - } + } foreach ($key as $k => $v) { @@ -957,10 +957,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -982,12 +982,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($table); $this->from($table); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -998,7 +998,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * "Count All Results" query * - * Generates a platform-specific query string that counts all records + * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @access public @@ -1012,12 +1012,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($table); $this->from($table); } - + $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); - + if ($query->num_rows() == 0) { return '0'; @@ -1051,12 +1051,12 @@ class CI_DB_active_record extends CI_DB_driver { { $this->where($where); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -1077,17 +1077,17 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function insert_batch($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set_insert_batch($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //No valid data array. Folds in cases where keys and values did not match up return $this->display_error('db_must_use_set'); } return FALSE; @@ -1103,25 +1103,25 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { - + $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)); //echo $sql; $this->query($sql); } - + $this->_reset_write(); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1139,26 +1139,26 @@ class CI_DB_active_record extends CI_DB_driver { function set_insert_batch($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); - + if ( ! is_array($key)) { $key = array($key => $value); - } + } $keys = array_keys(current($key)); sort($keys); foreach ($key as $row) { - if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) - { - // batch function above returns an error on an empty array - $this->ar_set[] = array(); - return; - } - - ksort($row); // puts $row in the same order as our keys + if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) + { + // batch function above returns an error on an empty array + $this->ar_set[] = array(); + return; + } + ksort($row); // puts $row in the same order as our keys + if ($escape === FALSE) { $this->ar_set[] = '('.implode(',', $row).')'; @@ -1169,18 +1169,18 @@ class CI_DB_active_record extends CI_DB_driver { foreach($row as $value) { - $clean[] = $this->escape($value); + $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; - } + $this->ar_set[] = '('.implode(',', $clean).')'; + } } foreach ($keys as $k) { $this->ar_keys[] = $this->_protect_identifiers($k); } - + return $this; } @@ -1197,12 +1197,12 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function insert($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1222,23 +1222,23 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - + $this->_reset_write(); - return $this->query($sql); + return $this->query($sql); } - + function replace($table = '', $set = NULL) { if ( ! is_null($set)) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1258,14 +1258,14 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - + $this->_reset_write(); - return $this->query($sql); + return $this->query($sql); } // -------------------------------------------------------------------- @@ -1290,7 +1290,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1310,10 +1310,10 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } - + if ($where != NULL) { $this->where($where); @@ -1323,9 +1323,9 @@ class CI_DB_active_record extends CI_DB_driver { { $this->limit($limit); } - + $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - + $this->_reset_write(); return $this->query($sql); } @@ -1348,7 +1348,7 @@ class CI_DB_active_record extends CI_DB_driver { { // Combine any cached components with the current statements $this->_merge_cache(); - + if (is_null($index)) { if ($this->db_debug) @@ -1384,10 +1384,10 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } - + // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { @@ -1395,7 +1395,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->query($sql); } - + $this->_reset_write(); } @@ -1414,11 +1414,11 @@ class CI_DB_active_record extends CI_DB_driver { function set_update_batch($key, $index = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); - + if ( ! is_array($key)) { // @todo error - } + } foreach ($key as $k => $v) { @@ -1442,7 +1442,7 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); + $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); } } @@ -1453,7 +1453,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set[] = $clean; } - + return $this; } @@ -1491,7 +1491,7 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_delete($table); $this->_reset_write(); - + return $this->query($sql); } @@ -1531,10 +1531,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_truncate($table); $this->_reset_write(); - + return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1600,7 +1600,7 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; - } + } $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); @@ -1608,7 +1608,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_reset_write(); } - + return $this->query($sql); } @@ -1643,7 +1643,7 @@ class CI_DB_active_record extends CI_DB_driver { * @access private * @param string The table to inspect * @return string - */ + */ function _track_aliases($table) { if (is_array($table)) @@ -1654,23 +1654,23 @@ class CI_DB_active_record extends CI_DB_driver { } return; } - + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { return $this->_track_aliases(explode(',', $table)); } - + // if a table alias is used we can recognize it by a space if (strpos($table, " ") !== FALSE) { // if the alias is written with the AS keyword, remove it $table = preg_replace('/ AS /i', ' ', $table); - + // Grab the alias $table = trim(strrchr($table, " ")); - + // Store the alias, if it doesn't already exist if ( ! in_array($table, $this->ar_aliased_tables)) { @@ -1696,7 +1696,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_merge_cache(); // ---------------------------------------------------------------- - + // Write the "select" portion of the query if ($select_override !== FALSE) @@ -1706,13 +1706,13 @@ class CI_DB_active_record extends CI_DB_driver { else { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - + if (count($this->ar_select) == 0) { - $sql .= '*'; + $sql .= '*'; } else - { + { // Cycle through the "select" portion of the query and prep each column name. // The reason we protect identifiers here rather then in the select() function // is because until the user calls the from() function we don't know if there are aliases @@ -1720,13 +1720,13 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_select[$key] = $this->_protect_identifiers($val); } - + $sql .= implode(', ', $this->ar_select); } } // ---------------------------------------------------------------- - + // Write the "FROM" portion of the query if (count($this->ar_from) > 0) @@ -1737,7 +1737,7 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "JOIN" portion of the query if (count($this->ar_join) > 0) @@ -1748,7 +1748,7 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "WHERE" portion of the query if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) @@ -1761,9 +1761,9 @@ class CI_DB_active_record extends CI_DB_driver { $sql .= implode("\n", $this->ar_where); // ---------------------------------------------------------------- - + // Write the "LIKE" portion of the query - + if (count($this->ar_like) > 0) { if (count($this->ar_where) > 0) @@ -1775,20 +1775,20 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "GROUP BY" portion of the query - + if (count($this->ar_groupby) > 0) { $sql .= "\nGROUP BY "; - + $sql .= implode(', ', $this->ar_groupby); } // ---------------------------------------------------------------- - + // Write the "HAVING" portion of the query - + if (count($this->ar_having) > 0) { $sql .= "\nHAVING "; @@ -1796,24 +1796,24 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "ORDER BY" portion of the query if (count($this->ar_orderby) > 0) { $sql .= "\nORDER BY "; $sql .= implode(', ', $this->ar_orderby); - + if ($this->ar_order !== FALSE) { $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } + } } // ---------------------------------------------------------------- - + // Write the "LIMIT" portion of the query - + if (is_numeric($this->ar_limit)) { $sql .= "\n"; @@ -1840,7 +1840,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $object; } - + $array = array(); foreach (get_object_vars($object) as $key => $val) { @@ -1853,7 +1853,7 @@ class CI_DB_active_record extends CI_DB_driver { return $array; } - + // -------------------------------------------------------------------- /** @@ -1871,7 +1871,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $object; } - + $array = array(); $out = get_object_vars($object); $fields = array_keys($out); @@ -1893,7 +1893,7 @@ class CI_DB_active_record extends CI_DB_driver { return $array; } - + // -------------------------------------------------------------------- /** @@ -1903,7 +1903,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function start_cache() { $this->ar_caching = TRUE; @@ -1918,7 +1918,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function stop_cache() { $this->ar_caching = FALSE; @@ -1933,23 +1933,23 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function flush_cache() - { + { $this->_reset_run( array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), 'ar_cache_set' => array(), 'ar_cache_exists' => array() ) - ); + ); } // -------------------------------------------------------------------- @@ -1957,7 +1957,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Merge Cache * - * When called, this function merges any cached AR arrays with + * When called, this function merges any cached AR arrays with * locally called ones. * * @access private @@ -2022,25 +2022,25 @@ class CI_DB_active_record extends CI_DB_driver { function _reset_select() { $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), 'ar_aliased_tables' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, 'ar_order' => FALSE, ); - + $this->_reset_run($ar_reset_items); } - + // -------------------------------------------------------------------- /** @@ -2052,21 +2052,21 @@ class CI_DB_active_record extends CI_DB_driver { * @return void */ function _reset_write() - { + { $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), 'ar_like' => array(), 'ar_orderby' => array(), - 'ar_keys' => array(), - 'ar_limit' => FALSE, + 'ar_keys' => array(), + 'ar_limit' => FALSE, 'ar_order' => FALSE ); $this->_reset_run($ar_reset_items); } - + } /* End of file DB_active_rec.php */ diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 2606df842..6eff5943e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -32,14 +32,14 @@ class CI_DB_Cache { * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_Cache(&$db) { // Assign the main CI object to $this->CI // and load the file helper since we use it a lot $this->CI =& get_instance(); $this->db =& $db; - $this->CI->load->helper('file'); + $this->CI->load->helper('file'); } // -------------------------------------------------------------------- @@ -50,7 +50,7 @@ class CI_DB_Cache { * @access public * @param string the path to the cache directory * @return bool - */ + */ function check_path($path = '') { if ($path == '') @@ -59,10 +59,10 @@ class CI_DB_Cache { { return $this->db->cache_off(); } - + $path = $this->db->cachedir; } - + // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); @@ -71,11 +71,11 @@ class CI_DB_Cache { // If the path is wrong we'll turn off caching return $this->db->cache_off(); } - + $this->db->cachedir = $path; return TRUE; } - + // -------------------------------------------------------------------- /** @@ -95,18 +95,18 @@ class CI_DB_Cache { } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); - + + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); + if (FALSE === ($cachedata = read_file($filepath))) - { + { return FALSE; } - - return unserialize($cachedata); - } + + return unserialize($cachedata); + } // -------------------------------------------------------------------- @@ -124,28 +124,28 @@ class CI_DB_Cache { } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - + $filename = md5($sql); - + if ( ! @is_dir($dir_path)) { if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } - - @chmod($dir_path, DIR_WRITE_MODE); + + @chmod($dir_path, DIR_WRITE_MODE); } - + if (write_file($dir_path.$filename, serialize($object)) === FALSE) { return FALSE; } - + @chmod($dir_path.$filename, FILE_WRITE_MODE); return TRUE; } @@ -159,19 +159,19 @@ class CI_DB_Cache { * @return bool */ function delete($segment_one = '', $segment_two = '') - { + { if ($segment_one == '') { $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } - + if ($segment_two == '') { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - + delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 8e6f88801..cbfa33e78 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -71,13 +71,13 @@ class CI_DB_driver { var $limit_used; - + /** * Constructor. Accepts one parameter containing the database * connection settings. * * @param array - */ + */ function CI_DB_driver($params) { if (is_array($params)) @@ -90,7 +90,7 @@ class CI_DB_driver { log_message('debug', 'Database Driver Class Initialized'); } - + // -------------------------------------------------------------------- /** @@ -99,7 +99,7 @@ class CI_DB_driver { * @access private Called by the constructor * @param mixed * @return void - */ + */ function initialize() { // If an existing connection resource is available @@ -108,9 +108,9 @@ class CI_DB_driver { { return TRUE; } - + // ---------------------------------------------------------------- - + // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); @@ -118,7 +118,7 @@ class CI_DB_driver { if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); - + if ($this->db_debug) { $this->display_error('db_unable_to_connect'); @@ -134,12 +134,12 @@ class CI_DB_driver { if ( ! $this->db_select()) { log_message('error', 'Unable to select database: '.$this->database); - + if ($this->db_debug) { $this->display_error('db_unable_to_select', $this->database); } - return FALSE; + return FALSE; } else { @@ -148,14 +148,14 @@ class CI_DB_driver { { return FALSE; } - + return TRUE; } } return TRUE; } - + // -------------------------------------------------------------------- /** @@ -171,26 +171,26 @@ class CI_DB_driver { if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) { log_message('error', 'Unable to set database connection charset: '.$this->char_set); - + if ($this->db_debug) { $this->display_error('db_unable_to_set_charset', $this->char_set); } - + return FALSE; } - + return TRUE; } - + // -------------------------------------------------------------------- /** * The name of the platform in use (mysql, mssql, etc...) * * @access public - * @return string - */ + * @return string + */ function platform() { return $this->dbdriver; @@ -203,8 +203,8 @@ class CI_DB_driver { * version of the database being used * * @access public - * @return string - */ + * @return string + */ function version() { if (FALSE === ($sql = $this->_version())) @@ -230,7 +230,7 @@ class CI_DB_driver { return $query->row('ver'); } } - + // -------------------------------------------------------------------- /** @@ -245,8 +245,8 @@ class CI_DB_driver { * @access public * @param string An SQL query string * @param array An array of binding data - * @return mixed - */ + * @return mixed + */ function query($sql, $binds = FALSE, $return_object = TRUE) { if ($sql == '') @@ -279,7 +279,7 @@ class CI_DB_driver { } } } - + // Compile binds if needed if ($binds !== FALSE) { @@ -291,10 +291,10 @@ class CI_DB_driver { { $this->queries[] = $sql; } - + // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); - + // Run the Query if (FALSE === ($this->result_id = $this->simple_query($sql))) { @@ -302,7 +302,7 @@ class CI_DB_driver { { $this->query_times[] = 0; } - + // This will trigger a rollback if transactions are being used $this->_trans_status = FALSE; @@ -312,10 +312,10 @@ class CI_DB_driver { // additional queries before displaying the error $error_no = $this->_error_number(); $error_msg = $this->_error_message(); - + // We call this function in order to roll-back queries // if transactions are enabled. If we don't call this here - // the error message will trigger an exit, causing the + // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); @@ -329,10 +329,10 @@ class CI_DB_driver { ) ); } - + return FALSE; } - + // Stop and aggregate the query time results $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); @@ -341,10 +341,10 @@ class CI_DB_driver { { $this->query_times[] = ($em + $es) - ($sm + $ss); } - + // Increment the query counter $this->query_count++; - + // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) @@ -355,10 +355,10 @@ class CI_DB_driver { { $this->CACHE->delete(); } - + return TRUE; } - + // Return TRUE if we don't need to create a result object // Currently only the Oracle driver uses this when stored // procedures are used @@ -366,11 +366,11 @@ class CI_DB_driver { { return TRUE; } - - // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); + + // Load and instantiate the result driver + + $driver = $this->load_rdriver(); + $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; @@ -381,10 +381,10 @@ class CI_DB_driver { $RES->limit_used = $this->limit_used; $this->stmt_id = FALSE; } - + // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) @@ -396,17 +396,17 @@ class CI_DB_driver { // result object, so we'll have to compile the data // and save it) $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); + $CR->num_rows = $RES->num_rows(); $CR->result_object = $RES->result_object(); $CR->result_array = $RES->result_array(); - + // Reset these since cached objects can not utilize resource IDs. $CR->conn_id = NULL; $CR->result_id = NULL; $this->CACHE->write($sql, $CR); } - + return $RES; } @@ -416,8 +416,8 @@ class CI_DB_driver { * Load the result drivers * * @access public - * @return string the name of the result class - */ + * @return string the name of the result class + */ function load_rdriver() { $driver = 'CI_DB_'.$this->dbdriver.'_result'; @@ -427,10 +427,10 @@ class CI_DB_driver { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); } - + return $driver; } - + // -------------------------------------------------------------------- /** @@ -441,8 +441,8 @@ class CI_DB_driver { * * @access public * @param string the sql query - * @return mixed - */ + * @return mixed + */ function simple_query($sql) { if ( ! $this->conn_id) @@ -452,7 +452,7 @@ class CI_DB_driver { return $this->_execute($sql); } - + // -------------------------------------------------------------------- /** @@ -460,8 +460,8 @@ class CI_DB_driver { * This permits transactions to be disabled at run-time. * * @access public - * @return void - */ + * @return void + */ function trans_off() { $this->trans_enabled = FALSE; @@ -477,23 +477,23 @@ class CI_DB_driver { * a failure of one group will not affect any others * * @access public - * @return void - */ + * @return void + */ function trans_strict($mode = TRUE) { $this->trans_strict = is_bool($mode) ? $mode : TRUE; } - + // -------------------------------------------------------------------- /** * Start Transaction * * @access public - * @return void - */ + * @return void + */ function trans_start($test_mode = FALSE) - { + { if ( ! $this->trans_enabled) { return FALSE; @@ -505,7 +505,7 @@ class CI_DB_driver { $this->_trans_depth += 1; return; } - + $this->trans_begin($test_mode); } @@ -515,27 +515,27 @@ class CI_DB_driver { * Complete Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_complete() { if ( ! $this->trans_enabled) { return FALSE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 1) { $this->_trans_depth -= 1; return TRUE; } - + // The query() function will set this flag to FALSE in the event that a query failed if ($this->_trans_status === FALSE) { $this->trans_rollback(); - + // If we are NOT running in strict mode, we will reset // the _trans_status flag so that subsequent groups of transactions // will be permitted. @@ -547,7 +547,7 @@ class CI_DB_driver { log_message('debug', 'DB Transaction Failure'); return FALSE; } - + $this->trans_commit(); return TRUE; } @@ -558,8 +558,8 @@ class CI_DB_driver { * Lets you retrieve the transaction flag to determine if it has failed * * @access public - * @return bool - */ + * @return bool + */ function trans_status() { return $this->_trans_status; @@ -573,20 +573,20 @@ class CI_DB_driver { * @access public * @param string the sql statement * @param array an array of bind data - * @return string - */ + * @return string + */ function compile_binds($sql, $binds) { if (strpos($sql, $this->bind_marker) === FALSE) { return $sql; } - + if ( ! is_array($binds)) { $binds = array($binds); } - + // Get the sql segments around the bind markers $segments = explode($this->bind_marker, $sql); @@ -607,7 +607,7 @@ class CI_DB_driver { return $result; } - + // -------------------------------------------------------------------- /** @@ -615,8 +615,8 @@ class CI_DB_driver { * * @access public * @param string An SQL query string - * @return boolean - */ + * @return boolean + */ function is_write_type($sql) { if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) @@ -625,7 +625,7 @@ class CI_DB_driver { } return TRUE; } - + // -------------------------------------------------------------------- /** @@ -633,34 +633,34 @@ class CI_DB_driver { * * @access public * @param integer The number of decimal places - * @return integer - */ + * @return integer + */ function elapsed_time($decimals = 6) { return number_format($this->benchmark, $decimals); } - + // -------------------------------------------------------------------- /** * Returns the total number of queries * * @access public - * @return integer - */ + * @return integer + */ function total_queries() { return $this->query_count; } - + // -------------------------------------------------------------------- /** * Returns the last query that was executed * * @access public - * @return void - */ + * @return void + */ function last_query() { return end($this->queries); @@ -676,10 +676,10 @@ class CI_DB_driver { * * @access public * @param string - * @return mixed - */ + * @return mixed + */ function escape($str) - { + { if (is_string($str)) { $str = "'".$this->escape_str($str)."'"; @@ -703,14 +703,14 @@ class CI_DB_driver { * * Calls the individual driver for platform * specific escaping for LIKE conditions - * + * * @access public * @param string * @return mixed */ - function escape_like_str($str) - { - return $this->escape_str($str, TRUE); + function escape_like_str($str) + { + return $this->escape_str($str, TRUE); } // -------------------------------------------------------------------- @@ -723,12 +723,12 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return string - */ + * @return string + */ function primary($table = '') - { + { $fields = $this->list_fields($table); - + if ( ! is_array($fields)) { return FALSE; @@ -743,8 +743,8 @@ class CI_DB_driver { * Returns an array of table names * * @access public - * @return array - */ + * @return array + */ function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? @@ -752,7 +752,7 @@ class CI_DB_driver { { return $this->data_cache['table_names']; } - + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) { if ($this->db_debug) @@ -764,7 +764,7 @@ class CI_DB_driver { $retval = array(); $query = $this->query($sql); - + if ($query->num_rows() > 0) { foreach($query->result_array() as $row) @@ -783,7 +783,7 @@ class CI_DB_driver { $this->data_cache['table_names'] = $retval; return $this->data_cache['table_names']; } - + // -------------------------------------------------------------------- /** @@ -792,10 +792,10 @@ class CI_DB_driver { * @return boolean */ function table_exists($table_name) - { + { return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -803,7 +803,7 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return array + * @return array */ function list_fields($table = '') { @@ -812,7 +812,7 @@ class CI_DB_driver { { return $this->data_cache['field_names'][$table]; } - + if ($table == '') { if ($this->db_debug) @@ -821,7 +821,7 @@ class CI_DB_driver { } return FALSE; } - + if (FALSE === ($sql = $this->_list_columns($table))) { if ($this->db_debug) @@ -830,9 +830,9 @@ class CI_DB_driver { } return FALSE; } - + $query = $this->query($sql); - + $retval = array(); foreach($query->result_array() as $row) { @@ -843,9 +843,9 @@ class CI_DB_driver { else { $retval[] = current($row); - } + } } - + $this->data_cache['field_names'][$table] = $retval; return $this->data_cache['field_names'][$table]; } @@ -860,10 +860,10 @@ class CI_DB_driver { * @return boolean */ function field_exists($field_name, $table_name) - { + { return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -871,8 +871,8 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return object - */ + * @return object + */ function field_data($table = '') { if ($table == '') @@ -883,36 +883,36 @@ class CI_DB_driver { } return FALSE; } - + $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); return $query->field_data(); - } + } // -------------------------------------------------------------------- - + /** * Generate an insert string * * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values - * @return string - */ + * @return string + */ function insert_string($table, $data) { $fields = array(); $values = array(); - + foreach($data as $key => $val) { $fields[] = $this->_escape_identifiers($key); $values[] = $this->escape($val); } - + return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); - } - + } + // -------------------------------------------------------------------- /** @@ -922,15 +922,15 @@ class CI_DB_driver { * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement - * @return string - */ + * @return string + */ function update_string($table, $data, $where) { if ($where == '') { return false; } - + $fields = array(); foreach($data as $key => $val) { @@ -947,23 +947,23 @@ class CI_DB_driver { foreach ($where as $key => $val) { $prefix = (count($dest) == 0) ? '' : ' AND '; - + if ($val !== '') { if ( ! $this->_has_operator($key)) { $key .= ' ='; } - + $val = ' '.$this->escape($val); } - + $dest[] = $prefix.$key.$val; } - } + } return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); - } + } // -------------------------------------------------------------------- @@ -993,17 +993,17 @@ class CI_DB_driver { * @access public * @param string the function name * @param mixed any parameters needed by the function - * @return mixed - */ + * @return mixed + */ function call_function($function) { $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; - + if (FALSE === strpos($driver, $function)) { $function = $driver.$function; } - + if ( ! function_exists($function)) { if ($this->db_debug) @@ -1028,7 +1028,7 @@ class CI_DB_driver { * @access public * @param string the path to the cache directory * @return void - */ + */ function cache_set_path($path = '') { $this->cachedir = $path; @@ -1041,7 +1041,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_on() { $this->cache_on = TRUE; @@ -1055,13 +1055,13 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_off() { $this->cache_on = FALSE; return FALSE; } - + // -------------------------------------------------------------------- @@ -1070,7 +1070,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) @@ -1087,7 +1087,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_delete_all() { if ( ! $this->_cache_init()) @@ -1105,7 +1105,7 @@ class CI_DB_driver { * * @access private * @return void - */ + */ function _cache_init() { if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) @@ -1131,8 +1131,8 @@ class CI_DB_driver { * Close DB Connection * * @access public - * @return void - */ + * @return void + */ function close() { if (is_resource($this->conn_id) OR is_object($this->conn_id)) @@ -1141,7 +1141,7 @@ class CI_DB_driver { } $this->conn_id = FALSE; } - + // -------------------------------------------------------------------- /** @@ -1151,8 +1151,8 @@ class CI_DB_driver { * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message - * @return string sends the application/error_db.php template - */ + * @return string sends the application/error_db.php template + */ function display_error($error = '', $swap = '', $native = FALSE) { $LANG =& load_class('Lang', 'core'); @@ -1168,11 +1168,11 @@ class CI_DB_driver { { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - + // Find the most likely culprit of the error by going through // the backtrace until the source file is no longer in the // database folder. - + $trace = debug_backtrace(); foreach($trace as $call) @@ -1182,11 +1182,11 @@ class CI_DB_driver { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); $message[] = 'Line Number: '.$call['line']; - + break; } } - + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; @@ -1214,7 +1214,7 @@ class CI_DB_driver { * Protect Identifiers * * This function is used extensively by the Active Record class, and by - * a couple functions in this class. + * a couple functions in this class. * It takes a column or table name (optionally with an alias) and inserts * the table prefix onto it. Some logic is necessary in order to deal with * column names that include the path. Consider a query like this: @@ -1236,7 +1236,7 @@ class CI_DB_driver { * @param mixed * @param bool * @return string - */ + */ function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) { if ( ! is_bool($protect_identifiers)) @@ -1258,7 +1258,7 @@ class CI_DB_driver { // Convert tabs or multiple spaces into single spaces $item = preg_replace('/[\t ]+/', ' ', $item); - + // If the item has an alias declaration we remove it and set it aside. // Basically we remove everything to the right of the first space $alias = ''; @@ -1269,7 +1269,7 @@ class CI_DB_driver { } // This is basically a bug fix for queries that use MAX, MIN, etc. - // If a parenthesis is found we know that we do not need to + // If a parenthesis is found we know that we do not need to // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) @@ -1283,7 +1283,7 @@ class CI_DB_driver { if (strpos($item, '.') !== FALSE) { $parts = explode('.', $item); - + // Does the first segment of the exploded item match // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item @@ -1298,12 +1298,12 @@ class CI_DB_driver { $parts[$key] = $this->_escape_identifiers($val); } } - + $item = implode('.', $parts); - } + } return $item.$alias; } - + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { @@ -1326,35 +1326,35 @@ class CI_DB_driver { { $i = 0; } - + // This flag is set when the supplied $item does not contain a field name. // This can happen when this function is being called from a JOIN. if ($field_exists == FALSE) { $i++; } - + // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) { $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); } - + // We only add the table prefix if it does not already exist if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) { $parts[$i] = $this->dbprefix.$parts[$i]; } - + // Put the parts back together $item = implode('.', $parts); } - + if ($protect_identifiers === TRUE) { $item = $this->_escape_identifiers($item); } - + return $item.$alias; } @@ -1371,14 +1371,14 @@ class CI_DB_driver { if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) { $item = $this->dbprefix.$item; - } + } } if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); } - + return $item.$alias; } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 8be65e0d6..74aed8610 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -24,9 +24,9 @@ */ class CI_DB_forge { - var $fields = array(); + var $fields = array(); var $keys = array(); - var $primary_keys = array(); + var $primary_keys = array(); var $db_char_set = ''; /** @@ -34,7 +34,7 @@ class CI_DB_forge { * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_forge() { // Assign the main database object to $this->db @@ -55,12 +55,12 @@ class CI_DB_forge { function create_database($db_name) { $sql = $this->_create_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -76,12 +76,12 @@ class CI_DB_forge { function drop_database($db_name) { $sql = $this->_drop_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -103,15 +103,15 @@ class CI_DB_forge { { $this->add_key($one, $primary); } - + return; } - + if ($key == '') { show_error('Key information is required for that operation.'); } - + if ($primary === TRUE) { $this->primary_keys[] = $key; @@ -137,7 +137,7 @@ class CI_DB_forge { { show_error('Field information is required.'); } - + if (is_string($field)) { if ($field == 'id') @@ -157,16 +157,16 @@ class CI_DB_forge { { show_error('Field information is required for that operation.'); } - + $this->fields[] = $field; } } - + if (is_array($field)) { $this->fields = array_merge($this->fields, $field); } - + } // -------------------------------------------------------------------- @@ -179,19 +179,19 @@ class CI_DB_forge { * @return bool */ function create_table($table = '', $if_not_exists = FALSE) - { + { if ($table == '') { show_error('A table name is required for that operation.'); } - + if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - + $this->_reset(); return $this->db->query($sql); } @@ -208,12 +208,12 @@ class CI_DB_forge { function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -233,7 +233,7 @@ class CI_DB_forge { { show_error('A table name is required for that operation.'); } - + $sql = $this->_rename_table($table_name, $new_table_name); return $this->db->query($sql); } @@ -259,25 +259,25 @@ class CI_DB_forge { // add field info into field array, but we can only do one at a time // so we cycle through - foreach ($field as $k => $v) - { - $this->add_field(array($k => $field[$k])); + foreach ($field as $k => $v) + { + $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; } @@ -294,7 +294,7 @@ class CI_DB_forge { */ function drop_column($table = '', $column_name = '') { - + if ($table == '') { show_error('A table name is required for that operation.'); @@ -306,7 +306,7 @@ class CI_DB_forge { } $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); - + return $this->db->query($sql); } @@ -336,20 +336,20 @@ class CI_DB_forge { $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; } @@ -365,9 +365,9 @@ class CI_DB_forge { */ function _reset() { - $this->fields = array(); + $this->fields = array(); $this->keys = array(); - $this->primary_keys = array(); + $this->primary_keys = array(); } } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b9e64feeb..406afb1b8 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -32,7 +32,7 @@ class CI_DB_result { var $result_id = NULL; var $result_array = array(); var $result_object = array(); - var $current_row = 0; + var $current_row = 0; var $num_rows = 0; var $row_data = NULL; @@ -42,10 +42,10 @@ class CI_DB_result { * * @access public * @param string can be "object" or "array" - * @return mixed either a result object or array - */ + * @return mixed either a result object or array + */ function result($type = 'object') - { + { return ($type == 'object') ? $this->result_object() : $this->result_array(); } @@ -56,16 +56,16 @@ class CI_DB_result { * * @access public * @return object - */ + */ function result_object() { if (count($this->result_object) > 0) { return $this->result_object; } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { @@ -77,10 +77,10 @@ class CI_DB_result { { $this->result_object[] = $row; } - + return $this->result_object; } - + // -------------------------------------------------------------------- /** @@ -88,7 +88,7 @@ class CI_DB_result { * * @access public * @return array - */ + */ function result_array() { if (count($this->result_array) > 0) @@ -96,8 +96,8 @@ class CI_DB_result { return $this->result_array; } - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { @@ -109,7 +109,7 @@ class CI_DB_result { { $this->result_array[] = $row; } - + return $this->result_array; } @@ -121,8 +121,8 @@ class CI_DB_result { * @access public * @param string * @param string can be "object" or "array" - * @return mixed either a result object or array - */ + * @return mixed either a result object or array + */ function row($n = 0, $type = 'object') { if ( ! is_numeric($n)) @@ -132,16 +132,16 @@ class CI_DB_result { { $this->row_data = $this->row_array(0); } - + // array_key_exists() instead of isset() to allow for MySQL NULL values if (array_key_exists($n, $this->row_data)) { return $this->row_data[$n]; } - // reset the $n variable if the result was not achieved + // reset the $n variable if the result was not achieved $n = 0; } - + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); } @@ -152,7 +152,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function set_row($key, $value = NULL) { // We cache the row data for subsequent uses @@ -160,17 +160,17 @@ class CI_DB_result { { $this->row_data = $this->row_array(0); } - + if (is_array($key)) { foreach ($key as $k => $v) { $this->row_data[$k] = $v; } - + return; } - + if ($key != '' AND ! is_null($value)) { $this->row_data[$key] = $value; @@ -184,11 +184,11 @@ class CI_DB_result { * * @access public * @return object - */ + */ function row_object($n = 0) { $result = $this->result_object(); - + if (count($result) == 0) { return $result; @@ -209,7 +209,7 @@ class CI_DB_result { * * @access public * @return array - */ + */ function row_array($n = 0) { $result = $this->result_array(); @@ -218,16 +218,16 @@ class CI_DB_result { { return $result; } - + if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } - + return $result[$this->current_row]; } - + // -------------------------------------------------------------------- /** @@ -235,7 +235,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function first_row($type = 'object') { $result = $this->result($type); @@ -246,7 +246,7 @@ class CI_DB_result { } return $result[0]; } - + // -------------------------------------------------------------------- /** @@ -254,7 +254,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function last_row($type = 'object') { $result = $this->result($type); @@ -264,7 +264,7 @@ class CI_DB_result { return $result; } return $result[count($result) -1]; - } + } // -------------------------------------------------------------------- @@ -273,7 +273,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function next_row($type = 'object') { $result = $this->result($type); @@ -287,10 +287,10 @@ class CI_DB_result { { ++$this->current_row; } - + return $result[$this->current_row]; } - + // -------------------------------------------------------------------- /** @@ -298,7 +298,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function previous_row($type = 'object') { $result = $this->result($type); @@ -329,12 +329,12 @@ class CI_DB_result { function num_rows() { return $this->num_rows; } function num_fields() { return 0; } function list_fields() { return array(); } - function field_data() { return array(); } + function field_data() { return array(); } function free_result() { return TRUE; } function _data_seek() { return TRUE; } - function _fetch_assoc() { return array(); } + function _fetch_assoc() { return array(); } function _fetch_object() { return array(); } - + } // END DB_result class diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 124967a5a..2811d8802 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,20 +25,20 @@ class CI_DB_utility extends CI_DB_forge { var $db; - var $data_cache = array(); + var $data_cache = array(); /** * Constructor * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_utility() { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; - + log_message('debug', "Database Utility Class Initialized"); } @@ -51,13 +51,13 @@ class CI_DB_utility extends CI_DB_forge { * @return bool */ function list_databases() - { + { // Is there a cached result? if (isset($this->data_cache['db_names'])) { return $this->data_cache['db_names']; } - + $query = $this->db->query($this->_list_databases()); $dbs = array(); if ($query->num_rows() > 0) @@ -67,7 +67,7 @@ class CI_DB_utility extends CI_DB_forge { $dbs[] = current($row); } } - + $this->data_cache['db_names'] = $dbs; return $this->data_cache['db_names']; } @@ -109,15 +109,15 @@ class CI_DB_utility extends CI_DB_forge { function optimize_table($table_name) { $sql = $this->_optimize_table($table_name); - + if (is_bool($sql)) { show_error('db_must_use_set'); } - + $query = $this->db->query($sql); $res = $query->result_array(); - + // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it return current($res); @@ -137,14 +137,14 @@ class CI_DB_utility extends CI_DB_forge { foreach ($this->db->list_tables() as $table_name) { $sql = $this->_optimize_table($table_name); - + if (is_bool($sql)) { return $sql; } - + $query = $this->db->query($sql); - + // Build the result array... // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it @@ -153,7 +153,7 @@ class CI_DB_utility extends CI_DB_forge { $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); unset($res[$keys[0]]); - + $result[$key] = $res; } @@ -172,20 +172,20 @@ class CI_DB_utility extends CI_DB_forge { function repair_table($table_name) { $sql = $this->_repair_table($table_name); - + if (is_bool($sql)) { return $sql; } - + $query = $this->db->query($sql); - + // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $res = $query->result_array(); return current($res); } - + // -------------------------------------------------------------------- /** @@ -203,25 +203,25 @@ class CI_DB_utility extends CI_DB_forge { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); - } - + } + $out = ''; - + // First generate the headings from the table column names foreach ($query->list_fields() as $name) { $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } - + $out = rtrim($out); $out .= $newline; - + // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; @@ -229,7 +229,7 @@ class CI_DB_utility extends CI_DB_forge { return $out; } - + // -------------------------------------------------------------------- /** @@ -246,7 +246,7 @@ class CI_DB_utility extends CI_DB_forge { { show_error('You must submit a valid result object'); } - + // Set our default values foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { @@ -255,10 +255,10 @@ class CI_DB_utility extends CI_DB_forge { $params[$key] = $val; } } - + // Create variables for convenience extract($params); - + // Load the xml helper $CI =& get_instance(); $CI->load->helper('xml'); @@ -268,7 +268,7 @@ class CI_DB_utility extends CI_DB_forge { foreach ($query->result_array() as $row) { $xml .= $tab."<{$element}>".$newline; - + foreach ($row as $key => $val) { $xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline; @@ -276,7 +276,7 @@ class CI_DB_utility extends CI_DB_forge { $xml .= $tab."</{$element}>".$newline; } $xml .= "</$root>".$newline; - + return $xml; } @@ -297,9 +297,9 @@ class CI_DB_utility extends CI_DB_forge { { $params = array('tables' => $params); } - + // ------------------------------------------------------ - + // Set up our default preferences $prefs = array( 'tables' => array(), @@ -325,13 +325,13 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ - // Are we backing up a complete database or individual tables? + // Are we backing up a complete database or individual tables? // If no table names were submitted we'll fetch the entire table list if (count($prefs['tables']) == 0) { $prefs['tables'] = $this->db->list_tables(); } - + // ------------------------------------------------------ // Validate the format @@ -345,13 +345,13 @@ class CI_DB_utility extends CI_DB_forge { // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_compression'); } - + $prefs['format'] = 'txt'; } @@ -365,7 +365,7 @@ class CI_DB_utility extends CI_DB_forge { } // ------------------------------------------------------ - + // Was a Gzip file requested? if ($prefs['format'] == 'gzip') { @@ -373,7 +373,7 @@ class CI_DB_utility extends CI_DB_forge { } // ------------------------------------------------------ - + // Was a text file requested? if ($prefs['format'] == 'txt') { @@ -382,7 +382,7 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ - // Was a Zip file requested? + // Was a Zip file requested? if ($prefs['format'] == 'zip') { // If they included the .zip file extension we'll remove it @@ -390,7 +390,7 @@ class CI_DB_utility extends CI_DB_forge { { $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } - + // Tack on the ".sql" file extension if needed if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { @@ -398,13 +398,13 @@ class CI_DB_utility extends CI_DB_forge { } // Load the Zip class and output it - + $CI =& get_instance(); $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); return $CI->zip->get_zip(); } - + } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 40900e832..63f9e9cc3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -31,14 +31,14 @@ class CI_DB_mssql_driver extends CI_DB { var $dbdriver = 'mssql'; - + // The character used for escaping var $_escape_char = ''; // clause and character used for LIKE escape sequences var $_like_escape_str = " ESCAPE '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -52,7 +52,7 @@ class CI_DB_mssql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ($this->port != '') @@ -62,7 +62,7 @@ class CI_DB_mssql_driver extends CI_DB { return @mssql_connect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -70,7 +70,7 @@ class CI_DB_mssql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { if ($this->port != '') @@ -80,9 +80,9 @@ class CI_DB_mssql_driver extends CI_DB { return @mssql_pconnect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- - + /** * Reconnect * @@ -98,13 +98,13 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Select the database * * @access private called by the base class * @return resource - */ + */ function db_select() { // Note: The brackets are required in the event that the DB name @@ -113,7 +113,7 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Set client character set * @@ -129,20 +129,20 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Execute the query * * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @mssql_query($sql, $this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -153,7 +153,7 @@ class CI_DB_mssql_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -165,15 +165,15 @@ class CI_DB_mssql_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -195,8 +195,8 @@ class CI_DB_mssql_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -220,8 +220,8 @@ class CI_DB_mssql_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -238,7 +238,7 @@ class CI_DB_mssql_driver extends CI_DB { $this->simple_query('ROLLBACK TRAN'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -254,16 +254,16 @@ class CI_DB_mssql_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + // Escape single quotes $str = str_replace("'", "''", remove_invisible_characters($str)); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -271,10 +271,10 @@ class CI_DB_mssql_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -287,7 +287,7 @@ class CI_DB_mssql_driver extends CI_DB { { return @mssql_rows_affected($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -312,7 +312,7 @@ class CI_DB_mssql_driver extends CI_DB { /** * Parse major version * - * Grabs the major version number from the + * Grabs the major version number from the * database server version string passed in. * * @access private @@ -382,14 +382,14 @@ class CI_DB_mssql_driver extends CI_DB { function _list_tables($prefix_limit = FALSE) { $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - + // for future compatibility if ($prefix_limit !== FALSE AND $this->dbprefix != '') { //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } - + return $sql; } @@ -406,7 +406,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; } // -------------------------------------------------------------------- @@ -422,7 +422,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 * FROM ".$table; + return "SELECT TOP 1 * FROM ".$table; } // -------------------------------------------------------------------- @@ -437,7 +437,7 @@ class CI_DB_mssql_driver extends CI_DB { { return mssql_get_last_message(); } - + // -------------------------------------------------------------------- /** @@ -474,26 +474,26 @@ class CI_DB_mssql_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -512,12 +512,12 @@ class CI_DB_mssql_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -530,10 +530,10 @@ class CI_DB_mssql_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -555,21 +555,21 @@ class CI_DB_mssql_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -582,12 +582,12 @@ class CI_DB_mssql_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -600,7 +600,7 @@ class CI_DB_mssql_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -618,7 +618,7 @@ class CI_DB_mssql_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -638,8 +638,8 @@ class CI_DB_mssql_driver extends CI_DB { function _limit($sql, $limit, $offset) { $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); } // -------------------------------------------------------------------- @@ -654,7 +654,7 @@ class CI_DB_mssql_driver extends CI_DB { function _close($conn_id) { @mssql_close($conn_id); - } + } } diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index f6a17811f..5aa4406b1 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -79,12 +79,12 @@ class CI_DB_mssql_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; @@ -100,41 +100,41 @@ class CI_DB_mssql_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -147,24 +147,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -218,9 +218,9 @@ class CI_DB_mssql_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index e7b338045..09b1ec80b 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return @mssql_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_mssql_result extends CI_DB_result { { $field_names[] = $field->name; } - + return $field_names; } @@ -85,17 +85,17 @@ class CI_DB_mssql_result extends CI_DB_result { { $retval = array(); while ($field = mssql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; $F->max_length = $field->max_length; $F->primary_key = 0; $F->default = ''; - + $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_mssql_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -131,7 +131,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return mssql_data_seek($this->result_id, $n); } - + // -------------------------------------------------------------------- /** @@ -146,7 +146,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return mssql_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 751be146c..e58c7e0c3 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -52,7 +52,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { } // -------------------------------------------------------------------- - + /** * Repair table query * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index d684c8a49..cb985a764 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -43,9 +43,9 @@ class CI_DB_mysql_driver extends CI_DB { * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, * adding a bit more processing to all queries. - */ + */ var $delete_hack = TRUE; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -59,17 +59,17 @@ class CI_DB_mysql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ($this->port != '') { $this->hostname .= ':'.$this->port; } - + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); } - + // -------------------------------------------------------------------- /** @@ -77,7 +77,7 @@ class CI_DB_mysql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { if ($this->port != '') @@ -87,7 +87,7 @@ class CI_DB_mysql_driver extends CI_DB { return @mysql_pconnect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -108,13 +108,13 @@ class CI_DB_mysql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Select the database * * @access private called by the base class * @return resource - */ + */ function db_select() { return @mysql_select_db($this->database, $this->conn_id); @@ -136,7 +136,7 @@ class CI_DB_mysql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -156,13 +156,13 @@ class CI_DB_mysql_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @mysql_query($sql, $this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -173,7 +173,7 @@ class CI_DB_mysql_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { // "DELETE FROM TABLE" returns 0 affected rows This hack modifies @@ -185,7 +185,7 @@ class CI_DB_mysql_driver extends CI_DB { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } - + return $sql; } @@ -195,15 +195,15 @@ class CI_DB_mysql_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -214,7 +214,7 @@ class CI_DB_mysql_driver extends CI_DB { // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - + $this->simple_query('SET AUTOCOMMIT=0'); $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK return TRUE; @@ -226,8 +226,8 @@ class CI_DB_mysql_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -252,8 +252,8 @@ class CI_DB_mysql_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -271,7 +271,7 @@ class CI_DB_mysql_driver extends CI_DB { $this->simple_query('SET AUTOCOMMIT=1'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -282,17 +282,17 @@ class CI_DB_mysql_driver extends CI_DB { * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str, $like = FALSE) - { + function escape_str($str, $like = FALSE) + { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { @@ -306,16 +306,16 @@ class CI_DB_mysql_driver extends CI_DB { { $str = addslashes($str); } - + // escape LIKE condition wildcards if ($like === TRUE) { $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -328,7 +328,7 @@ class CI_DB_mysql_driver extends CI_DB { { return @mysql_affected_rows($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -360,7 +360,7 @@ class CI_DB_mysql_driver extends CI_DB { { return 0; } - + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) @@ -385,7 +385,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; if ($prefix_limit !== FALSE AND $this->dbprefix != '') { @@ -394,7 +394,7 @@ class CI_DB_mysql_driver extends CI_DB { return $sql; } - + // -------------------------------------------------------------------- /** @@ -439,7 +439,7 @@ class CI_DB_mysql_driver extends CI_DB { { return mysql_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -475,26 +475,26 @@ class CI_DB_mysql_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -513,12 +513,12 @@ class CI_DB_mysql_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -531,13 +531,13 @@ class CI_DB_mysql_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- - + /** * Replace statement * @@ -550,10 +550,10 @@ class CI_DB_mysql_driver extends CI_DB { * @return string */ function _replace($table, $keys, $values) - { + { return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -568,10 +568,10 @@ class CI_DB_mysql_driver extends CI_DB { * @return string */ function _insert_batch($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } - + // -------------------------------------------------------------------- @@ -594,17 +594,17 @@ class CI_DB_mysql_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } @@ -630,16 +630,16 @@ class CI_DB_mysql_driver extends CI_DB { foreach($values as $key => $val) { $ids[] = $val[$index]; - + foreach(array_keys($val) as $field) - { + { if ($field != $index) { $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } - + $sql = "UPDATE ".$table." SET "; $cases = ''; @@ -650,14 +650,14 @@ class CI_DB_mysql_driver extends CI_DB { { $cases .= $row."\n"; } - + $cases .= 'ELSE '.$k.' END, '; } - + $sql .= substr($cases, 0, -2); - + $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - + return $sql; } @@ -674,12 +674,12 @@ class CI_DB_mysql_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -692,7 +692,7 @@ class CI_DB_mysql_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -710,7 +710,7 @@ class CI_DB_mysql_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -728,7 +728,7 @@ class CI_DB_mysql_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { if ($offset == 0) { $offset = ''; @@ -737,7 +737,7 @@ class CI_DB_mysql_driver extends CI_DB { { $offset .= ", "; } - + return $sql."LIMIT ".$offset.$limit; } @@ -754,7 +754,7 @@ class CI_DB_mysql_driver extends CI_DB { { @mysql_close($conn_id); } - + } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index ccacf99f8..973f32dcb 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -23,7 +23,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysql_forge extends CI_DB_forge { - + /** * Create database * @@ -76,52 +76,52 @@ class CI_DB_mysql_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); if (array_key_exists('NAME', $attributes)) { $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; } - + if (array_key_exists('TYPE', $attributes)) { $sql .= ' '.$attributes['TYPE']; } - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes)) { $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { $sql .= ','; } } - + return $sql; } @@ -141,12 +141,12 @@ class CI_DB_mysql_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $sql .= $this->_process_fields($fields); @@ -165,14 +165,14 @@ class CI_DB_mysql_forge extends CI_DB_forge { if (is_array($key)) { $key_name = $this->db->_protect_identifiers(implode('_', $key)); - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key_name = $this->db->_protect_identifiers($key); $key = array($key_name); } - + $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; } } @@ -226,7 +226,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; } diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index acc586626..0140ec647 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -36,7 +36,7 @@ class CI_DB_mysql_result extends CI_DB_result { { return @mysql_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -49,7 +49,7 @@ class CI_DB_mysql_result extends CI_DB_result { { return @mysql_num_fields($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_mysql_result extends CI_DB_result { { $field_names[] = $field->name; } - + return $field_names; } @@ -85,27 +85,27 @@ class CI_DB_mysql_result extends CI_DB_result { { $retval = array(); while ($field = mysql_fetch_field($this->result_id)) - { + { $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; + $F->name = $field->name; + $F->type = $field->type; $F->default = $field->def; $F->max_length = $field->max_length; $F->primary_key = $field->primary_key; - + $retval[] = $F; } - + return $retval; } - + // -------------------------------------------------------------------- /** * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_mysql_result extends CI_DB_result { { return mysql_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_mysql_result extends CI_DB_result { { return mysql_fetch_object($this->result_id); } - + } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index c4a970cfd..3b574c6f4 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -84,7 +84,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Extract the prefs for simplicity extract($params); - + // Build the output $output = ''; foreach ((array)$tables as $table) @@ -97,31 +97,31 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Get the table schema $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table); - + // No result means the table name was invalid if ($query === FALSE) { continue; } - + // Write out the table schema $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; - if ($add_drop == TRUE) - { + if ($add_drop == TRUE) + { $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; } - + $i = 0; $result = $query->result_array(); foreach ($result[0] as $val) { if ($i++ % 2) - { + { $output .= $val.';'.$newline.$newline; } } - + // If inserts are not needed we're done... if ($add_insert == FALSE) { @@ -130,16 +130,16 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Grab all the data from the current table $query = $this->db->query("SELECT * FROM $table"); - + if ($query->num_rows() == 0) { continue; } - + // Fetch the field names and determine if the field is an // integer type. We use this info to decide whether to // surround the data with quotes or not - + $i = 0; $field_str = ''; $is_int = array(); @@ -148,24 +148,24 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Most versions of MySQL store timestamp as a string $is_int[$i] = (in_array( strtolower(mysql_field_type($query->result_id, $i)), - array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), TRUE) ) ? TRUE : FALSE; - + // Create a string of field names $field_str .= '`'.$field->name.'`, '; $i++; } - + // Trim off the end comma $field_str = preg_replace( "/, $/" , "" , $field_str); - - + + // Build the insert string foreach ($query->result_array() as $row) { $val_str = ''; - + $i = 0; foreach ($row as $v) { @@ -184,21 +184,21 @@ class CI_DB_mysql_utility extends CI_DB_utility { else { $val_str .= $v; - } - } - + } + } + // Append a comma $val_str .= ', '; $i++; } - + // Remove the comma at the end of the string $val_str = preg_replace( "/, $/" , "" , $val_str); - + // Build the INSERT string $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - + $output .= $newline.$newline; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d0e2defec..69e092839 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -31,7 +31,7 @@ class CI_DB_mysqli_driver extends CI_DB { var $dbdriver = 'mysqli'; - + // The character used for escaping var $_escape_char = '`'; @@ -51,7 +51,7 @@ class CI_DB_mysqli_driver extends CI_DB { * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, * adding a bit more processing to all queries. - */ + */ var $delete_hack = TRUE; // -------------------------------------------------------------------- @@ -61,12 +61,12 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ($this->port != '') { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); } else { @@ -82,12 +82,12 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return $this->db_connect(); } - + // -------------------------------------------------------------------- /** @@ -114,7 +114,7 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { return @mysqli_select_db($this->conn_id, $this->database); @@ -136,7 +136,7 @@ class CI_DB_mysqli_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -156,14 +156,14 @@ class CI_DB_mysqli_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { - $sql = $this->_prep_query($sql); + $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); return $result; } - + // -------------------------------------------------------------------- /** @@ -174,7 +174,7 @@ class CI_DB_mysqli_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { // "DELETE FROM TABLE" returns 0 affected rows This hack modifies @@ -186,7 +186,7 @@ class CI_DB_mysqli_driver extends CI_DB { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } - + return $sql; } @@ -196,15 +196,15 @@ class CI_DB_mysqli_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -227,8 +227,8 @@ class CI_DB_mysqli_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -253,8 +253,8 @@ class CI_DB_mysqli_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -283,17 +283,17 @@ class CI_DB_mysqli_driver extends CI_DB { * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str, $like = FALSE) + function escape_str($str, $like = FALSE) { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) { @@ -307,16 +307,16 @@ class CI_DB_mysqli_driver extends CI_DB { { $str = addslashes($str); } - + // escape LIKE condition wildcards if ($like === TRUE) { $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -329,7 +329,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return @mysqli_affected_rows($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -386,13 +386,13 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; - + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } - + return $sql; } @@ -440,7 +440,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return mysqli_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -471,31 +471,31 @@ class CI_DB_mysqli_driver extends CI_DB { { return $item; } - + foreach ($this->_reserved_identifiers as $id) { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -514,12 +514,12 @@ class CI_DB_mysqli_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -532,10 +532,10 @@ class CI_DB_mysqli_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -557,21 +557,21 @@ class CI_DB_mysqli_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - + $sql .= $orderby.$limit; - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -584,12 +584,12 @@ class CI_DB_mysqli_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -602,7 +602,7 @@ class CI_DB_mysqli_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -620,7 +620,7 @@ class CI_DB_mysqli_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -638,14 +638,14 @@ class CI_DB_mysqli_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 262d491ed..85491a873 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -23,7 +23,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_forge extends CI_DB_forge { - + /** * Create database * @@ -76,52 +76,52 @@ class CI_DB_mysqli_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); if (array_key_exists('NAME', $attributes)) { $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; } - + if (array_key_exists('TYPE', $attributes)) { $sql .= ' '.$attributes['TYPE']; } - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes)) { $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { $sql .= ','; } } - + return $sql; } @@ -141,12 +141,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $sql .= $this->_process_fields($fields); @@ -165,14 +165,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge { if (is_array($key)) { $key_name = $this->db->_protect_identifiers(implode('_', $key)); - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key_name = $this->db->_protect_identifiers($key); $key = array($key_name); } - + $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; } } @@ -226,7 +226,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 81d22cc9c..dd58ed878 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return @mysqli_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { $field_names[] = $field->name; } - + return $field_names; } @@ -85,17 +85,17 @@ class CI_DB_mysqli_result extends CI_DB_result { { $retval = array(); while ($field = mysqli_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; $F->default = $field->def; $F->max_length = $field->max_length; $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - + $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_mysqli_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_object($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return mysqli_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return mysqli_fetch_object($this->result_id); } - + } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 3ba14d25a..e0dbca7c0 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -23,7 +23,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_utility extends CI_DB_utility { - + /** * List databases * @@ -34,7 +34,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "SHOW DATABASES"; } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 6f317d2e6..fb65ad8a1 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author ExpressionEngine Dev Team + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -22,10 +22,10 @@ * creates dynamically based on whether the active record * class is being used or not. * - * @package CodeIgniter + * @package CodeIgniter * @subpackage Drivers * @category Database - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ @@ -44,14 +44,14 @@ class CI_DB_oci8_driver extends CI_DB { var $dbdriver = 'oci8'; - + // The character used for excaping var $_escape_char = '"'; - + // clause and character used for LIKE escape sequences var $_like_escape_str = " escape '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -141,7 +141,7 @@ class CI_DB_oci8_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -248,7 +248,7 @@ class CI_DB_oci8_driver extends CI_DB { } return FALSE; } - + // build the query string $sql = "begin $package.$procedure("; @@ -256,20 +256,20 @@ class CI_DB_oci8_driver extends CI_DB { foreach($params as $param) { $sql .= $param['name'] . ","; - + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) { $have_cursor = TRUE; } } $sql = trim($sql, ",") . "); end;"; - + $this->stmt_id = FALSE; $this->_set_stmt_id($sql); $this->_bind_params($params); $this->query($sql, FALSE, $have_cursor); } - + // -------------------------------------------------------------------- /** @@ -284,10 +284,10 @@ class CI_DB_oci8_driver extends CI_DB { { return; } - + foreach ($params as $param) { - foreach (array('name', 'value', 'type', 'length') as $val) + foreach (array('name', 'value', 'type', 'length') as $val) { if ( ! isset($param[$val])) { @@ -305,26 +305,26 @@ class CI_DB_oci8_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } - + // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - + $this->_commit = OCI_DEFAULT; return TRUE; } @@ -335,8 +335,8 @@ class CI_DB_oci8_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -361,8 +361,8 @@ class CI_DB_oci8_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -396,15 +396,15 @@ class CI_DB_oci8_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = remove_invisible_characters($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -412,7 +412,7 @@ class CI_DB_oci8_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } @@ -492,7 +492,7 @@ class CI_DB_oci8_driver extends CI_DB { { $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } @@ -555,7 +555,7 @@ class CI_DB_oci8_driver extends CI_DB { $error = ocierror($this->conn_id); return $error['code']; } - + // -------------------------------------------------------------------- /** @@ -578,26 +578,26 @@ class CI_DB_oci8_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -616,12 +616,12 @@ class CI_DB_oci8_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -659,17 +659,17 @@ class CI_DB_oci8_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } @@ -685,12 +685,12 @@ class CI_DB_oci8_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE TABLE ".$table; } - + // -------------------------------------------------------------------- /** @@ -703,7 +703,7 @@ class CI_DB_oci8_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -721,7 +721,7 @@ class CI_DB_oci8_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -752,7 +752,7 @@ class CI_DB_oci8_driver extends CI_DB { $this->limit_used = TRUE; return $newsql; - } + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index d77ed8de6..1d369ae32 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -66,12 +66,12 @@ class CI_DB_oci8_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; @@ -87,41 +87,41 @@ class CI_DB_oci8_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -141,17 +141,17 @@ class CI_DB_oci8_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -218,9 +218,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index cab538e21..647ec6e43 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author ExpressionEngine Dev Team + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_oci8_result extends CI_DB_result { @@ -35,7 +35,7 @@ class CI_DB_oci8_result extends CI_DB_result { * * Oracle doesn't have a graceful way to retun the number of rows * so we have to use what amounts to a hack. - * + * * * @access public * @return integer @@ -111,7 +111,7 @@ class CI_DB_oci8_result extends CI_DB_result { $fieldCount = $this->num_fields(); for ($c = 1; $c <= $fieldCount; $c++) { - $F = new stdClass(); + $F = new stdClass(); $F->name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); $F->max_length = ocicolumnsize($this->stmt_id, $c); @@ -128,12 +128,12 @@ class CI_DB_oci8_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) { - ocifreestatement($this->result_id); + ocifreestatement($this->result_id); $this->result_id = FALSE; } } @@ -151,8 +151,8 @@ class CI_DB_oci8_result extends CI_DB_result { function _fetch_assoc(&$row) { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); } // -------------------------------------------------------------------- @@ -166,17 +166,17 @@ class CI_DB_oci8_result extends CI_DB_result { * @return object */ function _fetch_object() - { + { $result = array(); // If PHP 5 is being used we can fetch an result object if (function_exists('oci_fetch_object')) { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - + return @oci_fetch_object($id); } - + // If PHP 4 is being used we have to build our own result foreach ($this->result_array() as $key => $val) { @@ -192,7 +192,7 @@ class CI_DB_oci8_result extends CI_DB_result { { $obj->$key = $val; } - + $result[] = $obj; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 6e682313f..0e2c7de5f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -31,14 +31,14 @@ class CI_DB_odbc_driver extends CI_DB { var $dbdriver = 'odbc'; - + // the character used to excape - not necessary for ODBC var $_escape_char = ''; - + // clause and character used for LIKE escape sequences var $_like_escape_str = " {escape '%s'} "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -51,7 +51,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver($params) { parent::CI_DB($params); - + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } @@ -60,12 +60,12 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { return @odbc_connect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -73,12 +73,12 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @odbc_pconnect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -102,7 +102,7 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for ODBC @@ -126,7 +126,7 @@ class CI_DB_odbc_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -146,13 +146,13 @@ class CI_DB_odbc_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @odbc_exec($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -163,7 +163,7 @@ class CI_DB_odbc_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -175,15 +175,15 @@ class CI_DB_odbc_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -204,8 +204,8 @@ class CI_DB_odbc_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -230,8 +230,8 @@ class CI_DB_odbc_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -265,16 +265,16 @@ class CI_DB_odbc_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + // ODBC doesn't require escaping $str = remove_invisible_characters($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -282,10 +282,10 @@ class CI_DB_odbc_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -298,7 +298,7 @@ class CI_DB_odbc_driver extends CI_DB { { return @odbc_num_rows($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -362,10 +362,10 @@ class CI_DB_odbc_driver extends CI_DB { //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -410,7 +410,7 @@ class CI_DB_odbc_driver extends CI_DB { { return odbc_errormsg($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -446,26 +446,26 @@ class CI_DB_odbc_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -484,12 +484,12 @@ class CI_DB_odbc_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -502,10 +502,10 @@ class CI_DB_odbc_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -527,21 +527,21 @@ class CI_DB_odbc_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -554,12 +554,12 @@ class CI_DB_odbc_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return $this->_delete($table); } - + // -------------------------------------------------------------------- /** @@ -572,7 +572,7 @@ class CI_DB_odbc_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -590,7 +590,7 @@ class CI_DB_odbc_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -627,7 +627,7 @@ class CI_DB_odbc_driver extends CI_DB { @odbc_close($conn_id); } - + } diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 1ae559b6e..49a2401f1 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -54,7 +54,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { function _drop_database($name) { // ODBC has no "drop database" command since it's - // designed to connect to an existing database + // designed to connect to an existing database if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -78,12 +78,12 @@ class CI_DB_odbc_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; @@ -99,41 +99,41 @@ class CI_DB_odbc_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -146,24 +146,24 @@ class CI_DB_odbc_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -179,7 +179,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { */ function _drop_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -235,9 +235,9 @@ class CI_DB_odbc_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 5ae46df62..e2dc8415f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_odbc_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_odbc_result extends CI_DB_result { { return @odbc_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -65,9 +65,9 @@ class CI_DB_odbc_result extends CI_DB_result { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $field_names[] = odbc_field_name($this->result_id, $i); + $field_names[] = odbc_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_odbc_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = odbc_field_name($this->result_id, $i); - $F->type = odbc_field_type($this->result_id, $i); + $F = new stdClass(); + $F->name = odbc_field_name($this->result_id, $i); + $F->type = odbc_field_type($this->result_id, $i); $F->max_length = odbc_field_len($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_odbc_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5b874d88f..deeb0320a 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -32,7 +32,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _list_databases() { - // Not sure if ODBC lets you list all databases... + // Not sure if ODBC lets you list all databases... if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -53,7 +53,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _optimize_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -74,7 +74,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _repair_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9f991e4a0..cf865432b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,7 +31,7 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; - + var $_escape_char = '"'; // clause and character used for LIKE escape sequences @@ -51,7 +51,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private * @return string - */ + */ function _connect_string() { $components = array( @@ -61,7 +61,7 @@ class CI_DB_postgre_driver extends CI_DB { 'username' => 'user', 'password' => 'password' ); - + $connect_string = ""; foreach ($components as $key => $val) { @@ -80,9 +80,9 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() - { + { return @pg_connect($this->_connect_string()); } @@ -93,12 +93,12 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @pg_pconnect($this->_connect_string()); } - + // -------------------------------------------------------------------- /** @@ -125,7 +125,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for Postgre so we'll return TRUE @@ -149,7 +149,7 @@ class CI_DB_postgre_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -169,13 +169,13 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @pg_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -186,7 +186,7 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -198,15 +198,15 @@ class CI_DB_postgre_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -227,8 +227,8 @@ class CI_DB_postgre_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -251,8 +251,8 @@ class CI_DB_postgre_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -284,15 +284,15 @@ class CI_DB_postgre_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = pg_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -300,10 +300,10 @@ class CI_DB_postgre_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -316,7 +316,7 @@ class CI_DB_postgre_driver extends CI_DB { { return @pg_affected_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -329,10 +329,10 @@ class CI_DB_postgre_driver extends CI_DB { { $v = $this->_version(); $v = $v['server']; - + $table = func_num_args() > 0 ? func_get_arg(0) : null; $column = func_num_args() > 1 ? func_get_arg(1) : null; - + if ($table == null && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; @@ -400,17 +400,17 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -455,7 +455,7 @@ class CI_DB_postgre_driver extends CI_DB { { return pg_last_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -491,26 +491,26 @@ class CI_DB_postgre_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -529,12 +529,12 @@ class CI_DB_postgre_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -547,10 +547,10 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -572,17 +572,17 @@ class CI_DB_postgre_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } @@ -598,12 +598,12 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -616,7 +616,7 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -634,7 +634,7 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -651,14 +651,14 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index c98ef425d..12eef2923 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -66,12 +66,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; @@ -87,41 +87,41 @@ class CI_DB_postgre_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -134,20 +134,20 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } @@ -218,9 +218,9 @@ class CI_DB_postgre_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 545f413e8..b60ad7dd3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -36,7 +36,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_postgre_result extends CI_DB_result { { $field_names[] = pg_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_postgre_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); $F->max_length = pg_field_size($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_postgre_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_object($this->result_id); } - + } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c08ed2a56..ea0583e9e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -33,14 +33,14 @@ class CI_DB_sqlite_driver extends CI_DB { var $dbdriver = 'sqlite'; - + // The character used to escape with - not needed for SQLite var $_escape_char = ''; // clause and character used for LIKE escape sequences - var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_str = " ESCAPE '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -54,24 +54,24 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); - + if ($this->db_debug) { $this->display_error($error, '', TRUE); } - + return FALSE; } - + return $conn_id; } - + // -------------------------------------------------------------------- /** @@ -79,24 +79,24 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); - + if ($this->db_debug) { $this->display_error($error, '', TRUE); } - + return FALSE; } - + return $conn_id; } - + // -------------------------------------------------------------------- /** @@ -120,7 +120,7 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { return TRUE; @@ -143,7 +143,7 @@ class CI_DB_sqlite_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -154,7 +154,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_libversion(); } - + // -------------------------------------------------------------------- /** @@ -163,13 +163,13 @@ class CI_DB_sqlite_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @sqlite_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -180,7 +180,7 @@ class CI_DB_sqlite_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -192,15 +192,15 @@ class CI_DB_sqlite_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -222,8 +222,8 @@ class CI_DB_sqlite_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -247,8 +247,8 @@ class CI_DB_sqlite_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -265,7 +265,7 @@ class CI_DB_sqlite_driver extends CI_DB { $this->simple_query('ROLLBACK'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -281,15 +281,15 @@ class CI_DB_sqlite_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + $str = sqlite_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -297,10 +297,10 @@ class CI_DB_sqlite_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -313,7 +313,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_changes($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -347,7 +347,7 @@ class CI_DB_sqlite_driver extends CI_DB { } $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + if ($query->num_rows() == 0) { return 0; @@ -424,7 +424,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_error_string(sqlite_last_error($this->conn_id)); } - + // -------------------------------------------------------------------- /** @@ -460,26 +460,26 @@ class CI_DB_sqlite_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -498,12 +498,12 @@ class CI_DB_sqlite_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -516,10 +516,10 @@ class CI_DB_sqlite_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -541,21 +541,21 @@ class CI_DB_sqlite_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -568,12 +568,12 @@ class CI_DB_sqlite_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return $this->_delete($table); } - + // -------------------------------------------------------------------- /** @@ -586,7 +586,7 @@ class CI_DB_sqlite_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -604,10 +604,10 @@ class CI_DB_sqlite_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } - + // -------------------------------------------------------------------- /** @@ -622,7 +622,7 @@ class CI_DB_sqlite_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { if ($offset == 0) { $offset = ''; @@ -631,7 +631,7 @@ class CI_DB_sqlite_driver extends CI_DB { { $offset .= ", "; } - + return $sql."LIMIT ".$offset.$limit; } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 53b20a3c7..7b5c894f6 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -75,13 +75,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + // IF NOT EXISTS added to SQLite in 3.3.0 if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)."("; $current_field_count = 0; @@ -97,41 +97,41 @@ class CI_DB_sqlite_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -151,13 +151,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; } } @@ -237,9 +237,9 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7b0631221..fd6d83d0c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { return @sqlite_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { $field_names[] = sqlite_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_sqlite_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = sqlite_field_name($this->result_id, $i); - $F->type = 'varchar'; + $F = new stdClass(); + $F->name = sqlite_field_name($this->result_id, $i); + $F->type = 'varchar'; $F->max_length = 0; $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_sqlite_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { // Not implemented in SQLite @@ -142,7 +142,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { return sqlite_fetch_array($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -168,7 +168,7 @@ class CI_DB_sqlite_result extends CI_DB_result { return $obj; } else { return NULL; - } + } } } diff --git a/system/fonts/texb.ttf b/system/fonts/texb.ttf Binary files differindex a7aa6469a..6792342a3 100644 --- a/system/fonts/texb.ttf +++ b/system/fonts/texb.ttf diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index b7289900f..bd30b7c16 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -38,7 +38,7 @@ * @param array * @param mixed * @return mixed depends on what the array contains - */ + */ if ( ! function_exists('element')) { function element($item, $array, $default = FALSE) @@ -49,7 +49,7 @@ if ( ! function_exists('element')) } return $array[$item]; - } + } } // ------------------------------------------------------------------------ @@ -60,7 +60,7 @@ if ( ! function_exists('element')) * @access public * @param array * @return mixed depends on what the array contains - */ + */ if ( ! function_exists('random_element')) { function random_element($array) @@ -70,7 +70,7 @@ if ( ! function_exists('random_element')) return $array; } return $array[array_rand($array)]; - } + } } diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 67db50947..3c80bb756 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -40,9 +40,9 @@ if ( ! function_exists('create_captcha')) { function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') - { - $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); - + { + $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); + foreach ($defaults as $key => $val) { if ( ! is_array($data)) @@ -53,11 +53,11 @@ if ( ! function_exists('create_captcha')) } } else - { + { $$key = ( ! isset($data[$key])) ? $val : $data[$key]; } } - + if ($img_path == '' OR $img_url == '') { return FALSE; @@ -67,45 +67,45 @@ if ( ! function_exists('create_captcha')) { return FALSE; } - + if ( ! is_writable($img_path)) { return FALSE; } - + if ( ! extension_loaded('gd')) { return FALSE; - } - + } + // ----------------------------------- - // Remove old images + // Remove old images // ----------------------------------- - + list($usec, $sec) = explode(" ", microtime()); $now = ((float)$usec + (float)$sec); - + $current_dir = @opendir($img_path); - + while($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { $name = str_replace(".jpg", "", $filename); - + if (($name + $expiration) < $now) { @unlink($img_path.$filename); } } } - + @closedir($current_dir); // ----------------------------------- // Do we have a "word" yet? // ----------------------------------- - + if ($word == '') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -115,23 +115,23 @@ if ( ! function_exists('create_captcha')) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } - + $word = $str; } - + // ----------------------------------- - // Determine angle and position + // Determine angle and position // ----------------------------------- - + $length = strlen($word); $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; - $x_axis = rand(6, (360/$length)-16); + $x_axis = rand(6, (360/$length)-16); $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); - + // ----------------------------------- // Create image // ----------------------------------- - + // PHP.net recommends imagecreatetruecolor(), but it isn't always available if (function_exists('imagecreatetruecolor')) { @@ -141,11 +141,11 @@ if ( ! function_exists('create_captcha')) { $im = imagecreate($img_width, $img_height); } - + // ----------------------------------- // Assign colors // ----------------------------------- - + $bg_color = imagecolorallocate ($im, 255, 255, 255); $border_color = imagecolorallocate ($im, 153, 102, 102); $text_color = imagecolorallocate ($im, 204, 153, 153); @@ -155,13 +155,13 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Create the rectangle // ----------------------------------- - + ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); - + // ----------------------------------- // Create the spiral pattern // ----------------------------------- - + $theta = 1; $thetac = 7; $radius = 16; @@ -185,9 +185,9 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Write the text // ----------------------------------- - + $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; - + if ($use_font == FALSE) { $font_size = 5; @@ -210,32 +210,32 @@ if ( ! function_exists('create_captcha')) $x += ($font_size*2); } else - { + { $y = rand($img_height/2, $img_height-3); imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); $x += $font_size; } } - + // ----------------------------------- // Create the border // ----------------------------------- - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); + imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); // ----------------------------------- // Generate the image // ----------------------------------- - + $img_name = $now.'.jpg'; ImageJPEG($im, $img_path.$img_name); - + $img = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />"; - + ImageDestroy($im); - + return array('word' => $word, 'time' => $now, 'image' => $img); } } diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 4d7d466f5..912eae6e2 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -20,13 +20,13 @@ * * This helper contains some functions based on the PEAR PHP_Compat library * http://pear.php.net/package/PHP_Compat - * + * * The PEAR compat library is a little bloated and the code doesn't harmonize * well with CodeIgniter, so those functions have been refactored. * We cheat a little and use CI's _exception_handler() to output our own PHP errors * so that the behavior fully mimicks the PHP 5 counterparts. -- Derek Jones * @PHP4 - * + * * @package CodeIgniter * @subpackage Helpers * @category Helpers @@ -39,7 +39,7 @@ if ( ! defined('PHP_EOL')) { define('PHP_EOL', (DIRECTORY_SEPARATOR == '/') ? "\n" : "\r\n"); -} +} // ------------------------------------------------------------------------ @@ -83,16 +83,16 @@ if ( ! function_exists('file_put_contents')) } $text = ''; - + while ( ! feof($data)) { $text .= fread($data, 4096); } - + $data = $text; unset($text); } - + // strings only please! if (is_array($data)) { @@ -108,7 +108,7 @@ if ( ! function_exists('file_put_contents')) { $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE; } - + // Check if we're using the include path if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag { @@ -118,16 +118,16 @@ if ( ! function_exists('file_put_contents')) { $use_include_path = FALSE; } - + $fp = @fopen($filename, $mode, $use_include_path); - + if ($fp === FALSE) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to open stream', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if (($flags & LOCK_EX) > 0) { if ( ! flock($fp, LOCK_EX)) @@ -137,17 +137,17 @@ if ( ! function_exists('file_put_contents')) return FALSE; } } - + // write it if (($written = @fwrite($fp, $data)) === FALSE) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to write to '.htmlentities($filename), $backtrace[0]['file'], $backtrace[0]['line']); } - + // Close the handle @fclose($fp); - + // Return length return $written; } @@ -179,7 +179,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // OK, it is a resource, but is it a stream? if (get_resource_type($handle) !== 'stream') { @@ -187,7 +187,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.get_resource_type($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // Checking for an array of fields if ( ! is_array($fields)) { @@ -195,7 +195,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // validate delimiter if (strlen($delimiter) > 1) { @@ -203,7 +203,7 @@ if ( ! function_exists('fputcsv')) $backtrace = debug_backtrace(); _exception_handler(E_NOTICE, 'fputcsv() delimiter must be one character long, "'.htmlentities($delimiter).'" used', $backtrace[0]['file'], $backtrace[0]['line']); } - + // validate enclosure if (strlen($enclosure) > 1) { @@ -212,9 +212,9 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_NOTICE, 'fputcsv() enclosure must be one character long, "'.htmlentities($enclosure).'" used', $backtrace[0]['file'], $backtrace[0]['line']); } - + $out = ''; - + foreach ($fields as $cell) { $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); @@ -228,9 +228,9 @@ if ( ! function_exists('fputcsv')) $out .= $cell.$delimiter; } } - + $length = @fwrite($handle, substr($out, 0, -1)."\n"); - + return $length; } } @@ -258,33 +258,33 @@ if ( ! function_exists('stripos')) { settype($haystack, 'STRING'); } - + if ( ! is_string($haystack)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if ( ! is_scalar($needle)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if (is_float($offset)) { $offset = (int)$offset; } - + if ( ! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); return NULL; } - + return strpos(strtolower($haystack), strtolower($needle), $offset); } } @@ -314,7 +314,7 @@ if ( ! function_exists('str_ireplace')) { return $subject; } - + // Crazy arguments if (is_scalar($search) && is_array($replace)) { @@ -329,7 +329,7 @@ if ( ! function_exists('str_ireplace')) _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']); } } - + // Searching for an array if (is_array($search)) { @@ -360,28 +360,28 @@ if ( ! function_exists('str_ireplace')) $search = array((string)$search); $replace = array((string)$replace); } - + // Prepare the search array foreach ($search as $search_key => $search_value) { $search[$search_key] = '/'.preg_quote($search_value, '/').'/i'; } - + // Prepare the replace array (escape backreferences) foreach ($replace as $k => $v) { $replace[$k] = str_replace(array(chr(92), '$'), array(chr(92).chr(92), '\$'), $v); } - + // do the replacement $result = preg_replace($search, $replace, (array)$subject); - + // Check if subject was initially a string and return it as a string if ( ! is_array($subject)) { return current($result); } - + // Otherwise, just return the array return $result; } @@ -412,19 +412,19 @@ if ( ! function_exists('http_build_query')) _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // Cast it as array if (is_object($formdata)) { $formdata = get_object_vars($formdata); } - + // If the array is empty, return NULL if (empty($formdata)) { return NULL; } - + // Argument separator if ($separator === NULL) { @@ -435,7 +435,7 @@ if ( ! function_exists('http_build_query')) $separator = '&'; } } - + // Start building the query $tmp = array(); @@ -445,36 +445,36 @@ if ( ! function_exists('http_build_query')) { continue; } - + if (is_integer($key) && $numeric_prefix != NULL) { $key = $numeric_prefix.$key; } - + if (is_resource($val)) { return NULL; } - + // hand it off to a recursive parser $tmp[] = _http_build_query_helper($key, $val, $separator); } - + return implode($separator, $tmp); } - - + + // Helper helper. Remind anyone of college? // Required to handle recursion in nested arrays. - // + // // You could shave fractions of fractions of a second by moving where // the urlencoding takes place, but it's much less intuitive, and if // your application has 10,000 form fields, well, you have other problems ;) function _http_build_query_helper($key, $val, $separator = '&') - { + { if (is_scalar($val)) { - return urlencode($key).'='.urlencode($val); + return urlencode($key).'='.urlencode($val); } else { @@ -483,13 +483,13 @@ if ( ! function_exists('http_build_query')) { $val = get_object_vars($val); } - + foreach ($val as $k => $v) { $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator); } } - + return implode($separator, $tmp); } } diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 4be371efe..2821fadb1 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -51,7 +51,7 @@ if ( ! function_exists('set_cookie')) $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix); } } - + // -------------------------------------------------------------------- /** @@ -67,14 +67,14 @@ if ( ! function_exists('get_cookie')) function get_cookie($index = '', $xss_clean = FALSE) { $CI =& get_instance(); - + $prefix = ''; - + if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') { $prefix = config_item('cookie_prefix'); } - + return $CI->input->cookie($prefix.$index, $xss_clean); } } diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 2c60f0302..e762be007 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -34,24 +34,24 @@ * * @access public * @return integer - */ + */ if ( ! function_exists('now')) { function now() { $CI =& get_instance(); - + if (strtolower($CI->config->item('time_reference')) == 'gmt') { $now = time(); $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - + if (strlen($system_time) < 10) { $system_time = time(); log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); } - + return $system_time; } else @@ -60,7 +60,7 @@ if ( ! function_exists('now')) } } } - + // ------------------------------------------------------------------------ /** @@ -79,22 +79,22 @@ if ( ! function_exists('now')) * @param string * @param integer * @return integer - */ + */ if ( ! function_exists('mdate')) { function mdate($datestr = '', $time = '') { if ($datestr == '') return ''; - + if ($time == '') $time = now(); - + $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); return date($datestr, $time); } } - + // ------------------------------------------------------------------------ /** @@ -106,7 +106,7 @@ if ( ! function_exists('mdate')) * @param string the chosen format * @param integer Unix timestamp * @return string - */ + */ if ( ! function_exists('standard_date')) { function standard_date($fmt = 'DATE_RFC822', $time = '') @@ -127,11 +127,11 @@ if ( ! function_exists('standard_date')) { return FALSE; } - + return mdate($formats[$fmt], $time); } } - + // ------------------------------------------------------------------------ /** @@ -144,7 +144,7 @@ if ( ! function_exists('standard_date')) * @param integer a number of seconds * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('timespan')) { function timespan($seconds = 1, $time = '') @@ -156,12 +156,12 @@ if ( ! function_exists('timespan')) { $seconds = 1; } - + if ( ! is_numeric($time)) { $time = time(); } - + if ($time <= $seconds) { $seconds = 1; @@ -170,85 +170,85 @@ if ( ! function_exists('timespan')) { $seconds = $time - $seconds; } - + $str = ''; $years = floor($seconds / 31536000); - + if ($years > 0) - { + { $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; - } - + } + $seconds -= $years * 31536000; $months = floor($seconds / 2628000); - + if ($years > 0 OR $months > 0) { if ($months > 0) - { + { $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; - } - + } + $seconds -= $months * 2628000; } $weeks = floor($seconds / 604800); - + if ($years > 0 OR $months > 0 OR $weeks > 0) { if ($weeks > 0) - { + { $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; } - + $seconds -= $weeks * 604800; - } + } $days = floor($seconds / 86400); - + if ($months > 0 OR $weeks > 0 OR $days > 0) { if ($days > 0) - { + { $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; } - + $seconds -= $days * 86400; } - + $hours = floor($seconds / 3600); - + if ($days > 0 OR $hours > 0) { if ($hours > 0) { $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; } - + $seconds -= $hours * 3600; } - + $minutes = floor($seconds / 60); - + if ($days > 0 OR $hours > 0 OR $minutes > 0) { if ($minutes > 0) - { + { $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } - + $seconds -= $minutes * 60; } - + if ($str == '') { $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; } - + return substr(trim($str), 0, -1); } } - + // ------------------------------------------------------------------------ /** @@ -261,7 +261,7 @@ if ( ! function_exists('timespan')) * @param integer a numeric month * @param integer a numeric year * @return integer - */ + */ if ( ! function_exists('days_in_month')) { function days_in_month($month = 0, $year = '') @@ -270,12 +270,12 @@ if ( ! function_exists('days_in_month')) { return 0; } - + if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } - + if ($month == 2) { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) @@ -297,18 +297,18 @@ if ( ! function_exists('days_in_month')) * @access public * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('local_to_gmt')) { function local_to_gmt($time = '') { if ($time == '') $time = time(); - + return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time)); } } - + // ------------------------------------------------------------------------ /** @@ -323,23 +323,23 @@ if ( ! function_exists('local_to_gmt')) * @param string timezone * @param bool whether DST is active * @return integer - */ + */ if ( ! function_exists('gmt_to_local')) { function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) - { + { if ($time == '') { return now(); } - + $time += timezones($timezone) * 3600; if ($dst == TRUE) { $time += 3600; } - + return $time; } } @@ -352,7 +352,7 @@ if ( ! function_exists('gmt_to_local')) * @access public * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('mysql_to_unix')) { function mysql_to_unix($time = '') @@ -360,11 +360,11 @@ if ( ! function_exists('mysql_to_unix')) // We'll remove certain characters for backward compatibility // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS - + $time = str_replace('-', '', $time); $time = str_replace(':', '', $time); $time = str_replace(' ', '', $time); - + // YYYYMMDDHHMMSS return mktime( substr($time, 8, 2), @@ -376,7 +376,7 @@ if ( ! function_exists('mysql_to_unix')) ); } } - + // ------------------------------------------------------------------------ /** @@ -389,13 +389,13 @@ if ( ! function_exists('mysql_to_unix')) * @param bool whether to show seconds * @param string format: us or euro * @return string - */ + */ if ( ! function_exists('unix_to_human')) { function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - + if ($fmt == 'us') { $r .= date('h', $time).':'.date('i', $time); @@ -404,21 +404,21 @@ if ( ! function_exists('unix_to_human')) { $r .= date('H', $time).':'.date('i', $time); } - + if ($seconds) { $r .= ':'.date('s', $time); } - + if ($fmt == 'us') { $r .= ' '.date('A', $time); } - + return $r; } } - + // ------------------------------------------------------------------------ /** @@ -429,7 +429,7 @@ if ( ! function_exists('unix_to_human')) * @access public * @param string format: us or euro * @return integer - */ + */ if ( ! function_exists('human_to_unix')) { function human_to_unix($datestr = '') @@ -438,25 +438,25 @@ if ( ! function_exists('human_to_unix')) { return FALSE; } - + $datestr = trim($datestr); $datestr = preg_replace("/\040+/", ' ', $datestr); - + if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) { return FALSE; } - + $split = explode(' ', $datestr); $ex = explode("-", $split['0']); - + $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; $ex = explode(":", $split['1']); - + $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; @@ -469,25 +469,25 @@ if ( ! function_exists('human_to_unix')) // Unless specified, seconds get set to zero. $sec = '00'; } - + if (isset($split['2'])) { $ampm = strtolower($split['2']); - + if (substr($ampm, 0, 1) == 'p' AND $hour < 12) $hour = $hour + 12; - + if (substr($ampm, 0, 1) == 'a' AND $hour == 12) $hour = '00'; - + if (strlen($hour) == 1) $hour = '0'.$hour; } - + return mktime($hour, $min, $sec, $month, $day, $year); } } - + // ------------------------------------------------------------------------ /** @@ -500,26 +500,26 @@ if ( ! function_exists('human_to_unix')) * @param string classname * @param string menu name * @return string - */ + */ if ( ! function_exists('timezone_menu')) { function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { $CI =& get_instance(); $CI->lang->load('date'); - + if ($default == 'GMT') $default = 'UTC'; $menu = '<select name="'.$name.'"'; - + if ($class != '') { $menu .= ' class="'.$class.'"'; } - + $menu .= ">\n"; - + foreach (timezones() as $key => $val) { $selected = ($default == $key) ? " selected='selected'" : ''; @@ -531,7 +531,7 @@ if ( ! function_exists('timezone_menu')) return $menu; } } - + // ------------------------------------------------------------------------ /** @@ -543,15 +543,15 @@ if ( ! function_exists('timezone_menu')) * @access public * @param string timezone * @return string - */ + */ if ( ! function_exists('timezones')) { function timezones($tz = '') { // Note: Don't change the order of these even though // some items appear to be in the wrong order - - $zones = array( + + $zones = array( 'UM12' => -12, 'UM11' => -11, 'UM10' => -10, @@ -593,15 +593,15 @@ if ( ! function_exists('timezones')) 'UP13' => +13, 'UP14' => +14 ); - + if ($tz == '') { return $zones; } - + if ($tz == 'GMT') $tz = 'UTC'; - + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; } } diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 7de6a3c51..574a5d8b0 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -38,7 +38,7 @@ * @param string path to source * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * @return array - */ + */ if ( ! function_exists('directory_map')) { function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) @@ -47,8 +47,8 @@ if ( ! function_exists('directory_map')) { $filedata = array(); $new_depth = $directory_depth - 1; - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] @@ -66,7 +66,7 @@ if ( ! function_exists('directory_map')) $filedata[] = $file; } } - + closedir($fp); return $filedata; } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index eac024fcb..4a17e519e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -36,7 +36,7 @@ * @param string filename * @param mixed the data to be downloaded * @return void - */ + */ if ( ! function_exists('force_download')) { function force_download($filename = '', $data = '') @@ -52,14 +52,14 @@ if ( ! function_exists('force_download')) { return FALSE; } - + // Grab the file extension $x = explode('.', $filename); $extension = end($x); // Load the mime types @include(APPPATH.'config/mimes'.EXT); - + // Set a default mime if we can't find it if ( ! isset($mimes[$extension])) { @@ -69,7 +69,7 @@ if ( ! function_exists('force_download')) { $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } - + // Generate the server headers if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { @@ -90,7 +90,7 @@ if ( ! function_exists('force_download')) header('Pragma: no-cache'); header("Content-Length: ".strlen($data)); } - + exit($data); } } diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 046562a91..7c8a610de 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -32,7 +32,7 @@ * * @access public * @return bool - */ + */ if ( ! function_exists('valid_email')) { function valid_email($address) @@ -48,7 +48,7 @@ if ( ! function_exists('valid_email')) * * @access public * @return bool - */ + */ if ( ! function_exists('send_email')) { function send_email($recipient, $subject = 'Test email', $message = 'Hello World') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 448bf275f..c1ac167a0 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -35,7 +35,7 @@ * @access public * @param string path to file * @return string - */ + */ if ( ! function_exists('read_file')) { function read_file($file) @@ -44,19 +44,19 @@ if ( ! function_exists('read_file')) { return FALSE; } - + if (function_exists('file_get_contents')) { - return file_get_contents($file); + return file_get_contents($file); } if ( ! $fp = @fopen($file, FOPEN_READ)) { return FALSE; } - + flock($fp, LOCK_SH); - + $data = ''; if (filesize($file) > 0) { @@ -69,7 +69,7 @@ if ( ! function_exists('read_file')) return $data; } } - + // ------------------------------------------------------------------------ /** @@ -82,7 +82,7 @@ if ( ! function_exists('read_file')) * @param string path to file * @param string file data * @return bool - */ + */ if ( ! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) @@ -91,16 +91,16 @@ if ( ! function_exists('write_file')) { return FALSE; } - + flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); - fclose($fp); + fclose($fp); return TRUE; } } - + // ------------------------------------------------------------------------ /** @@ -115,19 +115,19 @@ if ( ! function_exists('write_file')) * @param string path to file * @param bool whether to delete any directories found in the path * @return bool - */ + */ if ( ! function_exists('delete_files')) { function delete_files($path, $del_dir = FALSE, $level = 0) - { + { // Trim the trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR); - + if ( ! $current_dir = @opendir($path)) { - return FALSE; + return FALSE; } - + while(FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") @@ -138,7 +138,7 @@ if ( ! function_exists('delete_files')) if (substr($filename, 0, 1) != '.') { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); - } + } } else { @@ -147,12 +147,12 @@ if ( ! function_exists('delete_files')) } } @closedir($current_dir); - + if ($del_dir == TRUE AND $level > 0) { return @rmdir($path); } - + return TRUE; } } @@ -162,7 +162,7 @@ if ( ! function_exists('delete_files')) /** * Get Filenames * - * Reads the specified directory and builds an array containing the filenames. + * Reads the specified directory and builds an array containing the filenames. * Any sub-folders contained within the specified path are read as well. * * @access public @@ -170,13 +170,13 @@ if ( ! function_exists('delete_files')) * @param bool whether to include the path as part of the filename * @param bool internal variable to determine recursion status - do not use in calls * @return array - */ + */ if ( ! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - + if ($fp = @opendir($source_dir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call @@ -185,12 +185,12 @@ if ( ! function_exists('get_filenames')) $_filedata = array(); $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } - + while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) { - get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } elseif (strncmp($file, '.', 1) !== 0) { @@ -211,7 +211,7 @@ if ( ! function_exists('get_filenames')) /** * Get Directory File Information * - * Reads the specified directory and builds an array containing the filenames, + * Reads the specified directory and builds an array containing the filenames, * filesize, dates, and permissions * * Any sub-folders contained within the specified path are read as well. @@ -221,7 +221,7 @@ if ( ! function_exists('get_filenames')) * @param bool Look only at the top level directory specified? * @param bool internal variable to determine recursion status - do not use in calls * @return array - */ + */ if ( ! function_exists('get_dir_file_info')) { function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) @@ -243,10 +243,10 @@ if ( ! function_exists('get_dir_file_info')) { if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) - { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif (strncmp($file, '.', 1) !== 0) + { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } @@ -332,7 +332,7 @@ if ( ! function_exists('get_file_info')) /** * Get Mime by Extension * - * Translates a file extension into a mime type based on config/mimes.php. + * Translates a file extension into a mime type based on config/mimes.php. * Returns FALSE if it can't determine the type, or open the mime config file * * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience @@ -341,7 +341,7 @@ if ( ! function_exists('get_file_info')) * @access public * @param string path to file * @return mixed - */ + */ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) @@ -388,11 +388,11 @@ if ( ! function_exists('get_mime_by_extension')) * @access public * @param int * @return string - */ + */ if ( ! function_exists('symbolic_permissions')) { function symbolic_permissions($perms) - { + { if (($perms & 0xC000) == 0xC000) { $symbolic = 's'; // Socket @@ -441,7 +441,7 @@ if ( ! function_exists('symbolic_permissions')) $symbolic .= (($perms & 0x0002) ? 'w' : '-'); $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); - return $symbolic; + return $symbolic; } } @@ -456,7 +456,7 @@ if ( ! function_exists('symbolic_permissions')) * @access public * @param int * @return string - */ + */ if ( ! function_exists('octal_permissions')) { function octal_permissions($perms) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 42355df42..e722a0758 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -37,7 +37,7 @@ * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string - */ + */ if ( ! function_exists('form_open')) { function form_open($action = '', $attributes = '', $hidden = array()) @@ -52,9 +52,9 @@ if ( ! function_exists('form_open')) $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; $form = '<form action="'.$action.'"'; - + $form .= _attributes_to_string($attributes, TRUE); - + $form .= '>'; // CSRF @@ -143,7 +143,7 @@ if ( ! function_exists('form_hidden')) { foreach ($value as $k => $v) { - $k = (is_int($k)) ? '' : $k; + $k = (is_int($k)) ? '' : $k; form_hidden($name.'['.$k.']', $v, TRUE); } } @@ -250,10 +250,10 @@ if ( ! function_exists('form_textarea')) } else { - $val = $data['value']; + $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - + $name = (is_array($data)) ? $data['name'] : $data; return "<textarea "._parse_form_attributes($data, $defaults).$extra.">".form_prep($val, $name)."</textarea>"; } @@ -279,7 +279,7 @@ if ( ! function_exists('form_multiselect')) { $extra .= ' multiple="multiple"'; } - + return form_dropdown($name, $options, $selected, $extra); } } @@ -414,7 +414,7 @@ if ( ! function_exists('form_radio')) function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if ( ! is_array($data)) - { + { $data = array('name' => $data); } @@ -435,7 +435,7 @@ if ( ! function_exists('form_radio')) * @return string */ if ( ! function_exists('form_submit')) -{ +{ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); @@ -512,7 +512,7 @@ if ( ! function_exists('form_label')) if ($id != '') { - $label .= " for=\"$id\""; + $label .= " for=\"$id\""; } if (is_array($attributes) AND count($attributes) > 0) @@ -610,7 +610,7 @@ if ( ! function_exists('form_prep')) function form_prep($str = '', $field_name = '') { static $prepped_fields = array(); - + // if the field name is an array we do this recursively if (is_array($str)) { @@ -635,7 +635,7 @@ if ( ! function_exists('form_prep')) { return $str; } - + $str = htmlspecialchars($str); // In case htmlspecialchars misses these. @@ -645,7 +645,7 @@ if ( ! function_exists('form_prep')) { $prepped_fields[$field_name] = $field_name; } - + return $str; } } @@ -757,7 +757,7 @@ if ( ! function_exists('set_checkbox')) $OBJ =& _get_validation_object(); if ($OBJ === FALSE) - { + { if ( ! isset($_POST[$field])) { if (count($_POST) === 0 AND $default == TRUE) @@ -768,7 +768,7 @@ if ( ! function_exists('set_checkbox')) } $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -823,7 +823,7 @@ if ( ! function_exists('set_radio')) } $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -933,7 +933,7 @@ if ( ! function_exists('_parse_form_attributes')) } $att = ''; - + foreach ($default as $key => $val) { if ($key == 'value') @@ -978,7 +978,7 @@ if ( ! function_exists('_attributes_to_string')) return ' '.$attributes; } - + if (is_object($attributes) AND count($attributes) > 0) { $attributes = (array)$attributes; diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index cd7b4ce6b..1c8603dbc 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -388,9 +388,9 @@ if ( ! function_exists('meta')) $str = ''; foreach ($name as $meta) { - $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; - $name = ( ! isset($meta['name'])) ? '' : $meta['name']; - $content = ( ! isset($meta['content'])) ? '' : $meta['content']; + $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; + $name = ( ! isset($meta['name'])) ? '' : $meta['name']; + $content = ( ! isset($meta['content'])) ? '' : $meta['content']; $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline']; $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline; diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index c4c530bc5..cd05c8d6d 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -36,14 +36,14 @@ * @access public * @param string * @return str - */ + */ if ( ! function_exists('singular')) -{ +{ function singular($str) { $str = strtolower(trim($str)); $end = substr($str, -3); - + if ($end == 'ies') { $str = substr($str, 0, strlen($str)-3).'y'; @@ -55,13 +55,13 @@ if ( ! function_exists('singular')) else { $end = substr($str, -1); - + if ($end == 's') { $str = substr($str, 0, strlen($str)-1); } } - + return $str; } } @@ -77,9 +77,9 @@ if ( ! function_exists('singular')) * @param string * @param bool * @return str - */ + */ if ( ! function_exists('plural')) -{ +{ function plural($str, $force = FALSE) { $str = strtolower(trim($str)); @@ -93,14 +93,14 @@ if ( ! function_exists('plural')) } elseif ($end == 'h') { - if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') - { - $str .= 'es'; - } - else - { - $str .= 's'; - } + if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') + { + $str .= 'es'; + } + else + { + $str .= 's'; + } } elseif ($end == 's') { @@ -128,11 +128,11 @@ if ( ! function_exists('plural')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('camelize')) -{ +{ function camelize($str) - { + { $str = 'x'.strtolower(trim($str)); $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); return substr(str_replace(' ', '', $str), 1); @@ -149,7 +149,7 @@ if ( ! function_exists('camelize')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('underscore')) { function underscore($str) @@ -168,15 +168,15 @@ if ( ! function_exists('underscore')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('humanize')) -{ +{ function humanize($str) { return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); } } - + /* End of file inflector_helper.php */ /* Location: ./system/helpers/inflector_helper.php */
\ No newline at end of file diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 442619c93..c6bbe8636 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -36,7 +36,7 @@ * @param string the language line * @param string the id of the form element * @return string - */ + */ if ( ! function_exists('lang')) { function lang($line, $id = '') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index f7979215c..e4535f620 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -40,23 +40,23 @@ if ( ! function_exists('byte_format')) { $CI =& get_instance(); $CI->lang->load('number'); - - if ($num >= 1000000000000) + + if ($num >= 1000000000000) { $num = round($num / 1099511627776, $precision); $unit = $CI->lang->line('terabyte_abbr'); } - elseif ($num >= 1000000000) + elseif ($num >= 1000000000) { $num = round($num / 1073741824, $precision); $unit = $CI->lang->line('gigabyte_abbr'); } - elseif ($num >= 1000000) + elseif ($num >= 1000000) { $num = round($num / 1048576, $precision); $unit = $CI->lang->line('megabyte_abbr'); } - elseif ($num >= 1000) + elseif ($num >= 1000) { $num = round($num / 1024, $precision); $unit = $CI->lang->line('kilobyte_abbr'); @@ -68,7 +68,7 @@ if ( ! function_exists('byte_format')) } return number_format($num, $precision).' '.$unit; - } + } } diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 030b6bff1..556e8c9a2 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -34,7 +34,7 @@ * @param string * @param bool checks to see if the path exists * @return string - */ + */ if ( ! function_exists('set_realpath')) { function set_realpath($path, $check_existance = FALSE) @@ -44,16 +44,16 @@ if ( ! function_exists('set_realpath')) { show_error('The path you submitted must be a local server path, not a URL'); } - + // Resolve the path if (function_exists('realpath') AND @realpath($path) !== FALSE) { $path = realpath($path).'/'; } - + // Add a trailing slash $path = preg_replace("#([^/])/*$#", "\\1/", $path); - + // Make sure the path exists if ($check_existance == TRUE) { @@ -62,7 +62,7 @@ if ( ! function_exists('set_realpath')) show_error('Not a valid path: '.$path); } } - + return $path; } } diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 63f0e9cdb..08dd48a85 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -34,7 +34,7 @@ * @param string * @param bool whether or not the content is an image file * @return string - */ + */ if ( ! function_exists('xss_clean')) { function xss_clean($str, $is_image = FALSE) @@ -52,7 +52,7 @@ if ( ! function_exists('xss_clean')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('sanitize_filename')) { function sanitize_filename($filename) @@ -71,7 +71,7 @@ if ( ! function_exists('sanitize_filename')) * dohash() is now deprecated */ if ( ! function_exists('dohash')) -{ +{ function dohash($str, $type = 'sha1') { return do_hash($str, $type); @@ -86,9 +86,9 @@ if ( ! function_exists('dohash')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('do_hash')) -{ +{ function do_hash($str, $type = 'sha1') { if ($type == 'sha1') @@ -96,7 +96,7 @@ if ( ! function_exists('do_hash')) if ( ! function_exists('sha1')) { if ( ! function_exists('mhash')) - { + { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; return $SH->generate($str); @@ -109,7 +109,7 @@ if ( ! function_exists('do_hash')) else { return sha1($str); - } + } } else { @@ -117,7 +117,7 @@ if ( ! function_exists('do_hash')) } } } - + // ------------------------------------------------------------------------ /** @@ -126,18 +126,18 @@ if ( ! function_exists('do_hash')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('strip_image_tags')) { function strip_image_tags($str) { $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str); $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str); - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -146,7 +146,7 @@ if ( ! function_exists('strip_image_tags')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('encode_php_tags')) { function encode_php_tags($str) diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index b9eb0a23e..3ebb61253 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -45,7 +45,7 @@ if ( ! function_exists('smiley_js')) static $do_setup = TRUE; $r = ''; - + if ($alias != '' && ! is_array($alias)) { $alias = array($alias => $field_id); @@ -54,9 +54,9 @@ if ( ! function_exists('smiley_js')) if ($do_setup === TRUE) { $do_setup = FALSE; - + $m = array(); - + if (is_array($alias)) { foreach($alias as $name => $id) @@ -64,22 +64,22 @@ if ( ! function_exists('smiley_js')) $m[] = '"'.$name.'" : "'.$id.'"'; } } - + $m = '{'.implode(',', $m).'}'; - + $r .= <<<EOF var smiley_map = {$m}; function insert_smiley(smiley, field_id) { var el = document.getElementById(field_id), newStart; - + if ( ! el && smiley_map[field_id]) { el = document.getElementById(smiley_map[field_id]); - + if ( ! el) return false; } - + el.focus(); smiley = " " + smiley; @@ -110,7 +110,7 @@ EOF; if ($inline) { - return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'; + return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'; } else { @@ -124,8 +124,8 @@ EOF; /** * Get Clickable Smileys * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. + * Returns an array of image tag links that can be clicked to be inserted + * into a form field. * * @access public * @param string the URL to the folder containing the smiley images @@ -136,12 +136,12 @@ if ( ! function_exists('get_clickable_smileys')) function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) { // For backward compatibility with js_insert_smiley - + if (is_array($alias)) { $smileys = $alias; } - + if ( ! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) @@ -152,7 +152,7 @@ if ( ! function_exists('get_clickable_smileys')) // Add a trailing slash to the file path if needed $image_url = rtrim($image_url, '/').'/'; - + $used = array(); foreach ($smileys as $key => $val) { @@ -164,12 +164,12 @@ if ( ! function_exists('get_clickable_smileys')) { continue; } - - $link[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>"; - + + $link[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>"; + $used[$smileys[$key][0]] = TRUE; } - + return $link; } } diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 60f6ed171..544b3b42b 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -41,12 +41,12 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { - return trim($str, '/'); + return trim($str, '/'); } } @@ -60,13 +60,13 @@ if ( ! function_exists('trim_slashes')) * @access public * @param mixed string or array * @return mixed string or array - */ + */ if ( ! function_exists('strip_slashes')) { function strip_slashes($str) { if (is_array($str)) - { + { foreach ($str as $key => $val) { $str[$key] = strip_slashes($val); @@ -76,7 +76,7 @@ if ( ! function_exists('strip_slashes')) { $str = stripslashes($str); } - + return $str; } } @@ -91,7 +91,7 @@ if ( ! function_exists('strip_slashes')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('strip_quotes')) { function strip_quotes($str) @@ -110,11 +110,11 @@ if ( ! function_exists('strip_quotes')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('quotes_to_entities')) { function quotes_to_entities($str) - { + { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); } } @@ -136,7 +136,7 @@ if ( ! function_exists('quotes_to_entities')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) @@ -163,7 +163,7 @@ if ( ! function_exists('reduce_double_slashes')) * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string - */ + */ if ( ! function_exists('reduce_multiples')) { function reduce_multiples($str, $character = ',', $trim = FALSE) @@ -174,11 +174,11 @@ if ( ! function_exists('reduce_multiples')) { $str = trim($str, $character); } - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -187,23 +187,23 @@ if ( ! function_exists('reduce_multiples')) * Useful for generating passwords or hashes. * * @access public - * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 + * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param integer number of characters * @return string - */ + */ if ( ! function_exists('random_string')) { function random_string($type = 'alnum', $len = 8) - { + { switch($type) { case 'basic' : return mt_rand(); - break; + break; case 'alnum' : case 'numeric' : case 'nozero' : case 'alpha' : - + switch ($type) { case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -222,20 +222,20 @@ if ( ! function_exists('random_string')) $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; - break; - case 'unique' : - case 'md5' : - + break; + case 'unique' : + case 'md5' : + return md5(uniqid(mt_rand())); - break; - case 'encrypt' : - case 'sha1' : - + break; + case 'encrypt' : + case 'sha1' : + $CI =& get_instance(); $CI->load->helper('security'); - + return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); - break; + break; } } } @@ -250,12 +250,12 @@ if ( ! function_exists('random_string')) * @access public * @param string (as many parameters as needed) * @return string - */ + */ if ( ! function_exists('alternator')) { function alternator() { - static $i; + static $i; if (func_num_args() == 0) { @@ -276,13 +276,13 @@ if ( ! function_exists('alternator')) * @param string * @param integer number of repeats * @return string - */ + */ if ( ! function_exists('repeater')) { function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); - } + } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b85e2aaef..8bc1cd5e5 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -37,7 +37,7 @@ * @param integer * @param string the end character. Usually an ellipsis * @return string - */ + */ if ( ! function_exists('word_limiter')) { function word_limiter($str, $limit = 100, $end_char = '…') @@ -46,18 +46,18 @@ if ( ! function_exists('word_limiter')) { return $str; } - + preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); - + if (strlen($str) == strlen($matches[0])) { $end_char = ''; } - + return rtrim($matches[0]).$end_char; } } - + // ------------------------------------------------------------------------ /** @@ -71,7 +71,7 @@ if ( ! function_exists('word_limiter')) * @param integer * @param string the end character. Usually an ellipsis * @return string - */ + */ if ( ! function_exists('character_limiter')) { function character_limiter($str, $n = 500, $end_char = '…') @@ -80,28 +80,28 @@ if ( ! function_exists('character_limiter')) { return $str; } - + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { $out .= $val.' '; - + if (strlen($out) >= $n) { $out = trim($out); return (strlen($out) == strlen($str)) ? $out : $out.$end_char; - } + } } } } - + // ------------------------------------------------------------------------ /** @@ -112,21 +112,21 @@ if ( ! function_exists('character_limiter')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('ascii_to_entities')) { function ascii_to_entities($str) { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { /* If the $temp array has a value but we have moved on, then it seems only fair that we output that entity and restart $temp before continuing. -Paul @@ -136,33 +136,33 @@ if ( ! function_exists('ascii_to_entities')) $out .= '&#'.array_shift($temp).';'; $count = 1; } - + $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; } } - + // ------------------------------------------------------------------------ /** @@ -174,51 +174,51 @@ if ( ! function_exists('ascii_to_entities')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('entities_to_ascii')) { function entities_to_ascii($str, $all = TRUE) { - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches['0']); $i < $s; $i++) + { + $digits = $matches['1'][$i]; + + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); + $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + + $str = str_replace($matches['0'][$i], $out, $str); + } + } + + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } + + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -233,7 +233,7 @@ if ( ! function_exists('entities_to_ascii')) * @param string the array of censoered words * @param string the optional replacement value * @return string - */ + */ if ( ! function_exists('word_censor')) { function word_censor($str, $censored, $replacement = '') @@ -242,8 +242,8 @@ if ( ! function_exists('word_censor')) { return $str; } - - $str = ' '.$str.' '; + + $str = ' '.$str.' '; // \w, \b and a few others do not match on a unicode character // set for performance reasons. As a result words like über @@ -263,10 +263,10 @@ if ( ! function_exists('word_censor')) } } - return trim($str); + return trim($str); } } - + // ------------------------------------------------------------------------ /** @@ -277,26 +277,26 @@ if ( ! function_exists('word_censor')) * @access public * @param string the text string * @return string - */ + */ if ( ! function_exists('highlight_code')) { function highlight_code($str) - { + { // The highlight string function encodes and highlights // brackets so we need them to start raw $str = str_replace(array('<', '>'), array('<', '>'), $str); - + // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), + + $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); // The highlight_string function requires that the text be surrounded // by PHP tags, which we will remove later $str = '<?php '.$str.' ?>'; // <? - // All the magic happens here, baby! + // All the magic happens here, baby! $str = highlight_string($str, TRUE); // Prior to PHP 5, the highligh function used icky <font> tags @@ -307,20 +307,20 @@ if ( ! function_exists('highlight_code')) $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } - + // Remove our artificially added PHP, and the syntax highlighting that came with it $str = preg_replace('/<span style="color: #([A-Z0-9]+)"><\?php( | )/i', '<span style="color: #$1">', $str); $str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str); $str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str); - + // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -334,7 +334,7 @@ if ( ! function_exists('highlight_code')) * @param string the openging tag to precede the phrase with * @param string the closing tag to end the phrase with * @return string - */ + */ if ( ! function_exists('highlight_phrase')) { function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>') @@ -343,7 +343,7 @@ if ( ! function_exists('highlight_phrase')) { return ''; } - + if ($phrase != '') { return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); @@ -361,7 +361,7 @@ if ( ! function_exists('highlight_phrase')) * @access public * @param string the text string * @return string - */ + */ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($match) @@ -370,16 +370,16 @@ if ( ! function_exists('convert_accented_characters')) { return $match; } - + include APPPATH.'config/foreign_chars'.EXT; - + if ( ! isset($foreign_characters)) { return $match; } - + $ord = ord($match['1']); - + if (isset($foreign_characters[$ord])) { return $foreign_characters[$ord]; @@ -390,7 +390,7 @@ if ( ! function_exists('convert_accented_characters')) } } } - + // ------------------------------------------------------------------------ /** @@ -404,7 +404,7 @@ if ( ! function_exists('convert_accented_characters')) * @param string the text string * @param integer the number of characters to wrap at * @return string - */ + */ if ( ! function_exists('word_wrap')) { function word_wrap($str, $charlim = '76') @@ -412,47 +412,47 @@ if ( ! function_exists('word_wrap')) // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; - + // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); - + // Standardize newlines if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $str = str_replace(array("\r\n", "\r"), "\n", $str); } - - // If the current word is surrounded by {unwrap} tags we'll + + // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { - $unwrap[] = $matches['1'][$i]; + $unwrap[] = $matches['1'][$i]; $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); } } - - // Use PHP's native function to do the initial wordwrap. - // We set the cut flag to FALSE so that any individual words that are + + // Use PHP's native function to do the initial wordwrap. + // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); - + // Split the string into individual lines of text and cycle through them $output = ""; - foreach (explode("\n", $str) as $line) + foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { - $output .= $line."\n"; + $output .= $line."\n"; continue; } - + $temp = ''; - while((strlen($line)) > $charlim) + while((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) @@ -464,12 +464,12 @@ if ( ! function_exists('word_wrap')) $temp .= substr($line, 0, $charlim-1); $line = substr($line, $charlim-1); } - - // If $temp contains data it means we had to split up an over-length + + // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { - $output .= $temp."\n".$line; + $output .= $temp."\n".$line; } else { @@ -481,7 +481,7 @@ if ( ! function_exists('word_wrap')) // Put our markers back if (count($unwrap) > 0) - { + { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); @@ -491,10 +491,10 @@ if ( ! function_exists('word_wrap')) // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - return $output; + return $output; } } - + // ------------------------------------------------------------------------ /** @@ -502,10 +502,10 @@ if ( ! function_exists('word_wrap')) * * This function will strip tags from a string, split it at its max_length and ellipsize * - * @param string string to ellipsize + * @param string string to ellipsize * @param integer max length of string * @param mixed int (1|0) or float, .5, .2, etc for position to split - * @param string ellipsis ; Default '...' + * @param string ellipsis ; Default '...' * @return string ellipsized string */ if ( ! function_exists('ellipsize')) @@ -534,7 +534,7 @@ if ( ! function_exists('ellipsize')) $end = substr($str, -($max_length - strlen($beg))); } - return $beg.$ellipsis.$end; + return $beg.$ellipsis.$end; } } diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index e45480e1a..1a71d1857 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -33,19 +33,19 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('nl2br_except_pre')) { function nl2br_except_pre($str) { $CI =& get_instance(); - + $CI->load->library('typography'); - + return $CI->typography->nl2br_except_pre($str); } } - + // ------------------------------------------------------------------------ /** @@ -62,7 +62,7 @@ if ( ! function_exists('auto_typography')) { function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) { - $CI =& get_instance(); + $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); } @@ -84,7 +84,7 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - $CI =& get_instance(); + $CI =& get_instance(); $CI->load->library('security'); return $CI->security->entity_decode($str, $charset); } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index dad761145..e59efffec 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -70,7 +70,7 @@ if ( ! function_exists('base_url')) /** * Current URL * - * Returns the full URL (including segments) of the page where this + * Returns the full URL (including segments) of the page where this * function is placed * * @access public @@ -224,7 +224,7 @@ if ( ! function_exists('anchor_popup')) * @access public * @param string the email address * @param string the link title - * @param mixed any attributes + * @param mixed any attributes * @return string */ if ( ! function_exists('mailto')) @@ -254,7 +254,7 @@ if ( ! function_exists('mailto')) * @access public * @param string the email address * @param string the link title - * @param mixed any attributes + * @param mixed any attributes * @return string */ if ( ! function_exists('safe_mailto')) @@ -320,7 +320,7 @@ if ( ! function_exists('safe_mailto')) { $count = ($ordinal < 224) ? 2 : 3; } - + $temp[] = $ordinal; if (count($temp) == $count) { @@ -369,7 +369,7 @@ if ( ! function_exists('safe_mailto')) * @access public * @param string the string * @param string the type: email, url, or both - * @param bool whether to create pop-up links + * @param bool whether to create pop-up links * @return string */ if ( ! function_exists('auto_link')) @@ -381,7 +381,7 @@ if ( ! function_exists('auto_link')) if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) { $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; - + for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; @@ -390,7 +390,7 @@ if ( ! function_exists('auto_link')) $period = '.'; $matches['6'][$i] = substr($matches['6'][$i], 0, -1); } - + $str = str_replace($matches['0'][$i], $matches['1'][$i].'<a href="http'. $matches['4'][$i].'://'. @@ -416,7 +416,7 @@ if ( ! function_exists('auto_link')) $period = '.'; $matches['3'][$i] = substr($matches['3'][$i], 0, -1); } - + $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); } } @@ -447,7 +447,7 @@ if ( ! function_exists('prep_url')) } $url = parse_url($str); - + if ( ! $url OR ! isset($url['scheme'])) { $str = 'http://'.$str; @@ -495,7 +495,7 @@ if ( ! function_exists('url_title')) $replace.'$' => $replace, '^'.$replace => $replace, '\.+$' => '' - ); + ); $str = strip_tags($str); @@ -508,7 +508,7 @@ if ( ! function_exists('url_title')) { $str = strtolower($str); } - + return trim(stripslashes($str)); } } @@ -535,7 +535,7 @@ if ( ! function_exists('redirect')) { $uri = site_url($uri); } - + switch($method) { case 'refresh' : header("Refresh:0;url=".$uri); diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 56f5e0112..dcfbbdf74 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -33,36 +33,36 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('xml_convert')) { function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; - // Replace entities to temporary markers so that - // ampersands won't get messed up + // Replace entities to temporary markers so that + // ampersands won't get messed up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - + if ($protect_all === TRUE) { $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); } - + $str = str_replace(array("&","<",">","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), $str); - // Decode the temp markers back to entities + // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - + if ($protect_all === TRUE) { $str = preg_replace("/$temp(\w+);/","&\\1;", $str); } - + return $str; - } + } } // ------------------------------------------------------------------------ diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index e26f84930..3e6312361 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -1,19 +1,19 @@ <?php $lang['cal_su'] = "Su"; -$lang['cal_mo'] = "Mo"; -$lang['cal_tu'] = "Tu"; -$lang['cal_we'] = "We"; -$lang['cal_th'] = "Th"; -$lang['cal_fr'] = "Fr"; -$lang['cal_sa'] = "Sa"; -$lang['cal_sun'] = "Sun"; -$lang['cal_mon'] = "Mon"; -$lang['cal_tue'] = "Tue"; -$lang['cal_wed'] = "Wed"; -$lang['cal_thu'] = "Thu"; -$lang['cal_fri'] = "Fri"; -$lang['cal_sat'] = "Sat"; +$lang['cal_mo'] = "Mo"; +$lang['cal_tu'] = "Tu"; +$lang['cal_we'] = "We"; +$lang['cal_th'] = "Th"; +$lang['cal_fr'] = "Fr"; +$lang['cal_sa'] = "Sa"; +$lang['cal_sun'] = "Sun"; +$lang['cal_mon'] = "Mon"; +$lang['cal_tue'] = "Tue"; +$lang['cal_wed'] = "Wed"; +$lang['cal_thu'] = "Thu"; +$lang['cal_fri'] = "Fri"; +$lang['cal_sat'] = "Sat"; $lang['cal_sunday'] = "Sunday"; $lang['cal_monday'] = "Monday"; $lang['cal_tuesday'] = "Tuesday"; @@ -21,30 +21,30 @@ $lang['cal_wednesday'] = "Wednesday"; $lang['cal_thursday'] = "Thursday"; $lang['cal_friday'] = "Friday"; $lang['cal_saturday'] = "Saturday"; -$lang['cal_jan'] = "Jan"; -$lang['cal_feb'] = "Feb"; -$lang['cal_mar'] = "Mar"; -$lang['cal_apr'] = "Apr"; -$lang['cal_may'] = "May"; -$lang['cal_jun'] = "Jun"; -$lang['cal_jul'] = "Jul"; -$lang['cal_aug'] = "Aug"; -$lang['cal_sep'] = "Sep"; -$lang['cal_oct'] = "Oct"; -$lang['cal_nov'] = "Nov"; -$lang['cal_dec'] = "Dec"; -$lang['cal_january'] = "January"; -$lang['cal_february'] = "February"; -$lang['cal_march'] = "March"; +$lang['cal_jan'] = "Jan"; +$lang['cal_feb'] = "Feb"; +$lang['cal_mar'] = "Mar"; +$lang['cal_apr'] = "Apr"; +$lang['cal_may'] = "May"; +$lang['cal_jun'] = "Jun"; +$lang['cal_jul'] = "Jul"; +$lang['cal_aug'] = "Aug"; +$lang['cal_sep'] = "Sep"; +$lang['cal_oct'] = "Oct"; +$lang['cal_nov'] = "Nov"; +$lang['cal_dec'] = "Dec"; +$lang['cal_january'] = "January"; +$lang['cal_february'] = "February"; +$lang['cal_march'] = "March"; $lang['cal_april'] = "April"; -$lang['cal_mayl'] = "May"; -$lang['cal_june'] = "June"; -$lang['cal_july'] = "July"; +$lang['cal_mayl'] = "May"; +$lang['cal_june'] = "June"; +$lang['cal_july'] = "July"; $lang['cal_august'] = "August"; $lang['cal_september'] = "September"; -$lang['cal_october'] = "October"; +$lang['cal_october'] = "October"; $lang['cal_november'] = "November"; -$lang['cal_december'] = "December"; +$lang['cal_december'] = "December"; /* End of file calendar_lang.php */ diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index 8a123f4bd..99ed70a5c 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -1,11 +1,11 @@ <?php -$lang['required'] = "The %s field is required."; +$lang['required'] = "The %s field is required."; $lang['isset'] = "The %s field must have a value."; $lang['valid_email'] = "The %s field must contain a valid email address."; -$lang['valid_emails'] = "The %s field must contain all valid email addresses."; -$lang['valid_url'] = "The %s field must contain a valid URL."; -$lang['valid_ip'] = "The %s field must contain a valid IP."; +$lang['valid_emails'] = "The %s field must contain all valid email addresses."; +$lang['valid_url'] = "The %s field must contain a valid URL."; +$lang['valid_ip'] = "The %s field must contain a valid IP."; $lang['min_length'] = "The %s field must be at least %s characters in length."; $lang['max_length'] = "The %s field can not exceed %s characters in length."; $lang['exact_length'] = "The %s field must be exactly %s characters in length."; diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index 7876331f9..b6460fb83 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -1,6 +1,6 @@ <?php -$lang['profiler_database'] = 'DATABASE'; +$lang['profiler_database'] = 'DATABASE'; $lang['profiler_controller_info'] = 'CLASS/METHOD'; $lang['profiler_benchmarks'] = 'BENCHMARKS'; $lang['profiler_queries'] = 'QUERIES'; diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 275bf2451..924333faa 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -33,7 +33,7 @@ class CI_Calendar { var $local_time; var $template = ''; var $start_day = 'sunday'; - var $month_type = 'long'; + var $month_type = 'long'; var $day_type = 'abr'; var $show_next_prev = FALSE; var $next_prev_url = ''; @@ -46,26 +46,26 @@ class CI_Calendar { * @access public */ function CI_Calendar($config = array()) - { + { $this->CI =& get_instance(); - + if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); } $this->local_time = time(); - + if (count($config) > 0) { $this->initialize($config); } - + log_message('debug', "Calendar Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Initialize the user preferences * @@ -74,7 +74,7 @@ class CI_Calendar { * @access public * @param array config preferences * @return void - */ + */ function initialize($config = array()) { foreach ($config as $key => $val) @@ -85,7 +85,7 @@ class CI_Calendar { } } } - + // -------------------------------------------------------------------- /** @@ -102,66 +102,66 @@ class CI_Calendar { // Set and validate the supplied month/year if ($year == '') $year = date("Y", $this->local_time); - + if ($month == '') $month = date("m", $this->local_time); - - if (strlen($year) == 1) + + if (strlen($year) == 1) $year = '200'.$year; - - if (strlen($year) == 2) + + if (strlen($year) == 2) $year = '20'.$year; - if (strlen($month) == 1) + if (strlen($month) == 1) $month = '0'.$month; - + $adjusted_date = $this->adjust_date($month, $year); - + $month = $adjusted_date['month']; $year = $adjusted_date['year']; - + // Determine the total days in the month $total_days = $this->get_total_days($month, $year); - + // Set the starting day of the week $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); $start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day]; - + // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); $date = getdate($local_date); $day = $start_day + 1 - $date["wday"]; - + while ($day > 1) { $day -= 7; } - + // Set the current month/year/day // We use this to determine the "today" date $cur_year = date("Y", $this->local_time); $cur_month = date("m", $this->local_time); $cur_day = date("j", $this->local_time); - + $is_current_month = ($cur_year == $year AND $cur_month == $month) ? TRUE : FALSE; - + // Generate the template data array $this->parse_template(); - - // Begin building the calendar output + + // Begin building the calendar output $out = $this->temp['table_open']; - $out .= "\n"; + $out .= "\n"; - $out .= "\n"; + $out .= "\n"; $out .= $this->temp['heading_row_start']; $out .= "\n"; - + // "previous" month link if ($this->show_next_prev == TRUE) { // Add a trailing slash to the URL if needed $this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->next_prev_url); - + $adjusted_date = $this->adjust_date($month - 1, $year); $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell']); $out .= "\n"; @@ -169,26 +169,26 @@ class CI_Calendar { // Heading containing the month/year $colspan = ($this->show_next_prev == TRUE) ? 5 : 7; - + $this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['heading_title_cell']); $this->temp['heading_title_cell'] = str_replace('{heading}', $this->get_month_name($month)." ".$year, $this->temp['heading_title_cell']); - + $out .= $this->temp['heading_title_cell']; $out .= "\n"; // "next" month link if ($this->show_next_prev == TRUE) - { + { $adjusted_date = $this->adjust_date($month + 1, $year); $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']); } - $out .= "\n"; + $out .= "\n"; $out .= $this->temp['heading_row_end']; $out .= "\n"; // Write the cells containing the days of the week - $out .= "\n"; + $out .= "\n"; $out .= $this->temp['week_row_start']; $out .= "\n"; @@ -213,11 +213,11 @@ class CI_Calendar { for ($i = 0; $i < 7; $i++) { $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; - + if ($day > 0 AND $day <= $total_days) - { + { if (isset($data[$day])) - { + { // Cells with content $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content']; $out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp)); @@ -234,22 +234,22 @@ class CI_Calendar { // Blank cells $out .= $this->temp['cal_cell_blank']; } - - $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; + + $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; $day++; } - - $out .= "\n"; + + $out .= "\n"; $out .= $this->temp['cal_row_end']; - $out .= "\n"; + $out .= "\n"; } - $out .= "\n"; + $out .= "\n"; $out .= $this->temp['table_close']; return $out; } - + // -------------------------------------------------------------------- /** @@ -272,9 +272,9 @@ class CI_Calendar { { $month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december'); } - + $month = $month_names[$month]; - + if ($this->CI->lang->line($month) === FALSE) { return ucfirst(str_replace('cal_', '', $month)); @@ -282,7 +282,7 @@ class CI_Calendar { return $this->CI->lang->line($month); } - + // -------------------------------------------------------------------- /** @@ -299,7 +299,7 @@ class CI_Calendar { { if ($day_type != '') $this->day_type = $day_type; - + if ($this->day_type == 'long') { $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); @@ -312,16 +312,16 @@ class CI_Calendar { { $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'); } - + $days = array(); foreach ($day_names as $val) - { + { $days[] = ($this->CI->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->CI->lang->line('cal_'.$val); } - + return $days; } - + // -------------------------------------------------------------------- /** @@ -362,7 +362,7 @@ class CI_Calendar { return $date; } - + // -------------------------------------------------------------------- /** @@ -393,7 +393,7 @@ class CI_Calendar { return $days_in_month[$month - 1]; } - + // -------------------------------------------------------------------- /** @@ -407,17 +407,17 @@ class CI_Calendar { function default_template() { return array ( - 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', - 'heading_row_start' => '<tr>', + 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', + 'heading_row_start' => '<tr>', 'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>', - 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', - 'heading_next_cell' => '<th><a href="{next_url}">>></a></th>', - 'heading_row_end' => '</tr>', - 'week_row_start' => '<tr>', - 'week_day_cell' => '<td>{week_day}</td>', - 'week_row_end' => '</tr>', - 'cal_row_start' => '<tr>', - 'cal_cell_start' => '<td>', + 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', + 'heading_next_cell' => '<th><a href="{next_url}">>></a></th>', + 'heading_row_end' => '</tr>', + 'week_row_start' => '<tr>', + 'week_day_cell' => '<td>{week_day}</td>', + 'week_row_end' => '</tr>', + 'cal_row_start' => '<tr>', + 'cal_cell_start' => '<td>', 'cal_cell_start_today' => '<td>', 'cal_cell_content' => '<a href="{content}">{day}</a>', 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>', @@ -428,9 +428,9 @@ class CI_Calendar { 'cal_cell_end_today' => '</td>', 'cal_row_end' => '</tr>', 'table_close' => '</table>' - ); + ); } - + // -------------------------------------------------------------------- /** @@ -442,17 +442,17 @@ class CI_Calendar { * @access public * @return void */ - function parse_template() - { + function parse_template() + { $this->temp = $this->default_template(); - - if ($this->template == '') - { - return; - } - + + if ($this->template == '') + { + return; + } + $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); - + foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val) { if (preg_match("/\{".$val."\}(.*?)\{\/".$val."\}/si", $this->template, $match)) @@ -466,8 +466,8 @@ class CI_Calendar { $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; } } - } - } + } + } } diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 643d2eca4..f3969ef2c 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -29,7 +29,7 @@ class CI_Cart { // These are the regular expression rules that we use to validate the product ID and product name var $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods var $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods - + // Private variables. Do not change! var $CI; var $_cart_contents = array(); @@ -39,12 +39,12 @@ class CI_Cart { * Shopping Class Constructor * * The constructor loads the Session class, used to store the shopping cart contents. - */ + */ function CI_Cart($params = array()) - { + { // Set the super object to a local variable for use later $this->CI =& get_instance(); - + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) @@ -54,10 +54,10 @@ class CI_Cart { $config[$key] = $val; } } - + // Load the Sessions class $this->CI->load->library('session', $config); - + // Grab the shopping cart array from the session table, if it exists if ($this->CI->session->userdata('cart_contents') !== FALSE) { @@ -66,15 +66,15 @@ class CI_Cart { else { // No cart exists so we'll set some base values - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; + $this->_cart_contents['cart_total'] = 0; + $this->_cart_contents['total_items'] = 0; } - + log_message('debug', "Cart Class Initialized"); } // -------------------------------------------------------------------- - + /** * Insert items into the cart and save it to the session table * @@ -90,15 +90,15 @@ class CI_Cart { log_message('error', 'The insert method must be passed an array containing data.'); return FALSE; } - - // You can either insert a single product using a one-dimensional array, + + // You can either insert a single product using a one-dimensional array, // or multiple products using a multi-dimensional one. The way we // determine the array type is by looking for a required array key named "id" // at the top level. If it's not found, we will assume it's a multi-dimensional array. - - $save_cart = FALSE; + + $save_cart = FALSE; if (isset($items['id'])) - { + { if ($this->_insert($items) == TRUE) { $save_cart = TRUE; @@ -114,7 +114,7 @@ class CI_Cart { { $save_cart = TRUE; } - } + } } } @@ -129,7 +129,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Insert * @@ -145,9 +145,9 @@ class CI_Cart { log_message('error', 'The insert method must be passed an array containing data.'); return FALSE; } - + // -------------------------------------------------------------------- - + // Does the $items array contain an id, quantity, price, and name? These are required if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name'])) { @@ -156,7 +156,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // Prep the quantity. It can only be a number. Duh... $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); // Trim any leading zeros @@ -167,9 +167,9 @@ class CI_Cart { { return FALSE; } - + // -------------------------------------------------------------------- - + // Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods // Not totally sure we should impose this rule, but it seems prudent to standardize IDs. // Note: These can be user-specified by setting the $this->product_id_rules variable. @@ -180,7 +180,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods. // Note: These can be user-specified by setting the $this->product_name_rules variable. if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name'])) @@ -195,7 +195,7 @@ class CI_Cart { $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price'])); // Trim any leading zeros $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price'])); - + // Is the price a valid number? if ( ! is_numeric($items['price'])) { @@ -204,13 +204,13 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // We now need to create a unique identifier for the item being inserted into the cart. - // Every time something is added to the cart it is stored in the master cart array. - // Each row in the cart array, however, must have a unique index that identifies not only - // a particular product, but makes it possible to store identical products with different options. - // For example, what if someone buys two identical t-shirts (same product ID), but in - // different sizes? The product ID (and other attributes, like the name) will be identical for + // Every time something is added to the cart it is stored in the master cart array. + // Each row in the cart array, however, must have a unique index that identifies not only + // a particular product, but makes it possible to store identical products with different options. + // For example, what if someone buys two identical t-shirts (same product ID), but in + // different sizes? The product ID (and other attributes, like the name) will be identical for // both sizes because it's the same shirt. The only difference will be the size. // Internally, we need to treat identical submissions, but with different options, as a unique product. // Our solution is to convert the options array to a string and MD5 it along with the product ID. @@ -225,19 +225,19 @@ class CI_Cart { // Technically, we don't need to MD5 the ID in this case, but it makes // sense to standardize the format of array indexes for both conditions $rowid = md5($items['id']); - } + } // -------------------------------------------------------------------- // Now that we have our unique "row ID", we'll add our cart items to the master array - + // let's unset this first, just to make sure our index contains only the data from this submission - unset($this->_cart_contents[$rowid]); - + unset($this->_cart_contents[$rowid]); + // Create a new index with our new row ID $this->_cart_contents[$rowid]['rowid'] = $rowid; - - // And add the new items to the cart array + + // And add the new items to the cart array foreach ($items as $key => $val) { $this->_cart_contents[$rowid][$key] = $val; @@ -248,11 +248,11 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * This function permits the quantity of a given item to be changed. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. @@ -269,8 +269,8 @@ class CI_Cart { { return FALSE; } - - // You can either update a single product using a one-dimensional array, + + // You can either update a single product using a one-dimensional array, // or multiple products using a multi-dimensional one. The way we // determine the array type is by looking for a required array key named "id". // If it's not found we assume it's a multi-dimensional array @@ -292,7 +292,7 @@ class CI_Cart { { $save_cart = TRUE; } - } + } } } @@ -307,11 +307,11 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * This function permits the quantity of a given item to be changed. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. @@ -319,7 +319,7 @@ class CI_Cart { * @access private * @param array * @return bool - */ + */ function _update($items = array()) { // Without these array indexes there is nothing we can do @@ -327,7 +327,7 @@ class CI_Cart { { return FALSE; } - + // Prep the quantity $items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']); @@ -336,7 +336,7 @@ class CI_Cart { { return FALSE; } - + // Is the new quantity different than what is already saved in the cart? // If it's the same there's nothing to do if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) @@ -348,18 +348,18 @@ class CI_Cart { // If the quantity is greater than zero we are updating if ($items['qty'] == 0) { - unset($this->_cart_contents[$items['rowid']]); + unset($this->_cart_contents[$items['rowid']]); } else { $this->_cart_contents[$items['rowid']]['qty'] = $items['qty']; } - + return TRUE; } // -------------------------------------------------------------------- - + /** * Save the cart array to the session DB * @@ -383,20 +383,20 @@ class CI_Cart { } $total += ($val['price'] * $val['qty']); - + // Set the subtotal $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); } // Set the cart total and total items. - $this->_cart_contents['total_items'] = count($this->_cart_contents); + $this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['cart_total'] = $total; - + // Is our cart empty? If so we delete it from the session if (count($this->_cart_contents) <= 2) { $this->CI->session->unset_userdata('cart_contents'); - + // Nothing more to do... coffee time! return FALSE; } @@ -406,11 +406,11 @@ class CI_Cart { $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents)); // Woot! - return TRUE; + return TRUE; } // -------------------------------------------------------------------- - + /** * Cart Total * @@ -423,7 +423,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Total Items * @@ -438,7 +438,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Cart Contents * @@ -450,16 +450,16 @@ class CI_Cart { function contents() { $cart = $this->_cart_contents; - + // Remove these so they don't create a problem when showing the cart table unset($cart['total_items']); unset($cart['cart_total']); - + return $cart; } // -------------------------------------------------------------------- - + /** * Has options * @@ -475,12 +475,12 @@ class CI_Cart { { return FALSE; } - + return TRUE; } // -------------------------------------------------------------------- - + /** * Product options * @@ -500,7 +500,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Format Number * @@ -515,15 +515,15 @@ class CI_Cart { { return ''; } - + // Remove anything that isn't a number or decimal point. $n = trim(preg_replace('/([^0-9\.])/i', '', $n)); - + return number_format($n, 2, '.', ','); } - + // -------------------------------------------------------------------- - + /** * Destroy the cart * @@ -535,9 +535,9 @@ class CI_Cart { function destroy() { unset($this->_cart_contents); - - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; + + $this->_cart_contents['cart_total'] = 0; + $this->_cart_contents['total_items'] = 0; $this->CI->session->unset_userdata('cart_contents'); } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 07ef2e724..1261b4c72 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -25,25 +25,25 @@ * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link + * @link */ class CI_Driver_Library { protected $valid_drivers = array(); protected static $lib_name; - + // The first time a child is used it won't exist, so we instantiate it // subsequents calls will go straight to the proper child. function __get($child) { if (! isset($this->lib_name)) { - $this->lib_name = get_class($this); + $this->lib_name = get_class($this); } // The class will be prefixed with the parent lib $child_class = $this->lib_name.'_'.$child; - + if (in_array(strtolower($child_class), array_map('strtolower', $this->valid_drivers))) { // check and see if the driver is in a separate file @@ -64,11 +64,11 @@ class CI_Driver_Library { { include_once $filepath; break; - } + } } } } - + // it's a valid driver, but the file simply can't be found if ( ! class_exists($child_class)) { @@ -82,14 +82,14 @@ class CI_Driver_Library { $this->$child = $obj; return $this->$child; } - + // The requested driver isn't valid! log_message('error', "Invalid driver requested: ".$child_class); show_error("Invalid driver requested: ".$child_class); } - + // -------------------------------------------------------------------- - + } // END CI_Driver_Library CLASS @@ -104,11 +104,11 @@ class CI_Driver_Library { * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link + * @link */ class CI_Driver { protected $parent; - + private $methods = array(); private $properties = array(); @@ -126,16 +126,16 @@ class CI_Driver { function decorate($parent) { $this->parent = $parent; - + // Lock down attributes to what is defined in the class // and speed up references in magic methods - + $class_name = get_class($parent); - + if ( ! isset(self::$reflections[$class_name])) { $r = new ReflectionObject($parent); - + foreach ($r->getMethods() as $method) { if ($method->isPublic()) @@ -151,7 +151,7 @@ class CI_Driver { $this->properties[] = $prop->getName(); } } - + self::$reflections[$class_name] = array($this->methods, $this->properties); } else @@ -159,9 +159,9 @@ class CI_Driver { list($this->methods, $this->properties) = self::$reflections[$class_name]; } } - + // -------------------------------------------------------------------- - + /** * __call magic method * @@ -185,7 +185,7 @@ class CI_Driver { } // -------------------------------------------------------------------- - + /** * __get magic method * @@ -204,7 +204,7 @@ class CI_Driver { } // -------------------------------------------------------------------- - + /** * __set magic method * @@ -222,9 +222,9 @@ class CI_Driver { $this->parent->$var = $val; } } - + // -------------------------------------------------------------------- - + } // END CI_Driver CLASS diff --git a/system/libraries/Email.php b/system/libraries/Email.php index af48757bb..6c0309b0d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -129,7 +129,7 @@ class CI_Email { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_Email { $this->_attach_disp = array(); } } - + // -------------------------------------------------------------------- /** @@ -202,7 +202,7 @@ class CI_Email { $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); } - + // -------------------------------------------------------------------- /** @@ -238,7 +238,7 @@ class CI_Email { $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); $this->_replyto_flag = TRUE; } - + // -------------------------------------------------------------------- /** @@ -273,7 +273,7 @@ class CI_Email { break; } } - + // -------------------------------------------------------------------- /** @@ -300,7 +300,7 @@ class CI_Email { $this->_cc_array = $cc; } } - + // -------------------------------------------------------------------- /** @@ -336,7 +336,7 @@ class CI_Email { $this->_set_header('Bcc', implode(", ", $bcc)); } } - + // -------------------------------------------------------------------- /** @@ -351,7 +351,7 @@ class CI_Email { $subject = $this->_prep_q_encoding($subject); $this->_set_header('Subject', $subject); } - + // -------------------------------------------------------------------- /** @@ -365,7 +365,7 @@ class CI_Email { { $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); } - + // -------------------------------------------------------------------- /** @@ -396,7 +396,7 @@ class CI_Email { { $this->_headers[$header] = $value; } - + // -------------------------------------------------------------------- /** @@ -422,7 +422,7 @@ class CI_Email { } return $email; } - + // -------------------------------------------------------------------- /** @@ -436,7 +436,7 @@ class CI_Email { { $this->alt_message = ($str == '') ? '' : $str; } - + // -------------------------------------------------------------------- /** @@ -450,7 +450,7 @@ class CI_Email { { $this->mailtype = ($type == 'html') ? 'html' : 'text'; } - + // -------------------------------------------------------------------- /** @@ -464,7 +464,7 @@ class CI_Email { { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -478,7 +478,7 @@ class CI_Email { { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } - + // -------------------------------------------------------------------- /** @@ -504,7 +504,7 @@ class CI_Email { $this->priority = $n; } - + // -------------------------------------------------------------------- /** @@ -524,7 +524,7 @@ class CI_Email { $this->newline = $newline; } - + // -------------------------------------------------------------------- /** @@ -544,7 +544,7 @@ class CI_Email { $this->crlf = $crlf; } - + // -------------------------------------------------------------------- /** @@ -558,7 +558,7 @@ class CI_Email { $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary } - + // -------------------------------------------------------------------- /** @@ -575,7 +575,7 @@ class CI_Email { return "<".uniqid('').strstr($from, '@').">"; } - + // -------------------------------------------------------------------- /** @@ -595,7 +595,7 @@ class CI_Email { return $this->protocol; } } - + // -------------------------------------------------------------------- /** @@ -650,7 +650,7 @@ class CI_Email { return 'plain'; } } - + // -------------------------------------------------------------------- /** @@ -668,7 +668,7 @@ class CI_Email { return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } - + // -------------------------------------------------------------------- /** @@ -681,7 +681,7 @@ class CI_Email { { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } - + // -------------------------------------------------------------------- /** @@ -710,7 +710,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -724,7 +724,7 @@ class CI_Email { { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -740,11 +740,11 @@ class CI_Email { { if (preg_match('/\<(.*)\>/', $email, $match)) { - return $match['1']; + return $match['1']; } - else + else { - return $email; + return $email; } } @@ -754,17 +754,17 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $addy, $match)) { - $clean_email[] = $match['1']; + $clean_email[] = $match['1']; } - else + else { - $clean_email[] = $addy; + $clean_email[] = $addy; } } return $clean_email; } - + // -------------------------------------------------------------------- /** @@ -804,7 +804,7 @@ class CI_Email { for ($x = 1; $x <= $i; $x ++) { - $n .= "\n"; + $n .= "\n"; } $body = str_replace($n, "\n\n", $body); @@ -812,7 +812,7 @@ class CI_Email { return $this->word_wrap($body, '76'); } - + // -------------------------------------------------------------------- /** @@ -908,7 +908,7 @@ class CI_Email { return $output; } - + // -------------------------------------------------------------------- /** @@ -926,7 +926,7 @@ class CI_Email { $this->_set_header('Message-ID', $this->_get_message_id()); $this->_set_header('Mime-Version', '1.0'); } - + // -------------------------------------------------------------------- /** @@ -961,7 +961,7 @@ class CI_Email { $this->_header_str = rtrim($this->_header_str); } } - + // -------------------------------------------------------------------- /** @@ -1150,7 +1150,7 @@ class CI_Email { return; } - + // -------------------------------------------------------------------- /** @@ -1245,7 +1245,7 @@ class CI_Email { } // -------------------------------------------------------------------- - + /** * Prep Q Encoding * @@ -1317,7 +1317,7 @@ class CI_Email { } // -------------------------------------------------------------------- - + /** * Send Email * @@ -1358,7 +1358,7 @@ class CI_Email { return TRUE; } } - + // -------------------------------------------------------------------- /** @@ -1416,7 +1416,7 @@ class CI_Email { $this->_spool_email(); } } - + // -------------------------------------------------------------------- /** @@ -1429,7 +1429,7 @@ class CI_Email { { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } - + // -------------------------------------------------------------------- /** @@ -1447,7 +1447,7 @@ class CI_Email { return $matches[1]; } - + // -------------------------------------------------------------------- /** @@ -1492,7 +1492,7 @@ class CI_Email { $this->_set_error_message('email_sent', $this->_get_protocol()); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1528,7 +1528,7 @@ class CI_Email { } } } - + // -------------------------------------------------------------------- /** @@ -1550,12 +1550,12 @@ class CI_Email { fputs($fp, $this->_header_str); fputs($fp, $this->_finalbody); - $status = pclose($fp); - + $status = pclose($fp); + if (version_compare(PHP_VERSION, '4.2.3') == -1) { $status = $status >> 8 & 0xFF; - } + } if ($status != 0) { @@ -1566,7 +1566,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1635,7 +1635,7 @@ class CI_Email { $this->_send_command('quit'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1662,7 +1662,7 @@ class CI_Email { $this->_set_error_message($this->_get_smtp_data()); return $this->_send_command('hello'); } - + // -------------------------------------------------------------------- /** @@ -1729,7 +1729,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1783,7 +1783,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1804,7 +1804,7 @@ class CI_Email { return TRUE; } } - + // -------------------------------------------------------------------- /** @@ -1829,7 +1829,7 @@ class CI_Email { return $data; } - + // -------------------------------------------------------------------- /** @@ -1842,7 +1842,7 @@ class CI_Email { { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } - + // -------------------------------------------------------------------- /** @@ -1862,7 +1862,7 @@ class CI_Email { $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; - if ($cip && $rip) $this->_IP = $cip; + if ($cip && $rip) $this->_IP = $cip; elseif ($rip) $this->_IP = $rip; elseif ($cip) $this->_IP = $cip; elseif ($fip) $this->_IP = $fip; @@ -1884,7 +1884,7 @@ class CI_Email { return $this->_IP; } - + // -------------------------------------------------------------------- /** @@ -1908,7 +1908,7 @@ class CI_Email { $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>'; return $msg; } - + // -------------------------------------------------------------------- /** @@ -1932,7 +1932,7 @@ class CI_Email { $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />"; } } - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b27847a55..b95dd999c 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -144,7 +144,7 @@ class CI_Encrypt { function decode($string, $key = '') { $key = $this->get_key($key); - + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; @@ -163,12 +163,12 @@ class CI_Encrypt { { $dec = $this->_xor_decode($dec, $key); } - + return $dec; } // -------------------------------------------------------------------- - + /** * Encode from Legacy * @@ -176,7 +176,7 @@ class CI_Encrypt { * returns a newly encoded string using the improved method added in 2.0.0 * This allows for backwards compatibility and a method to transition to the * new encryption algorithms. - * + * * For more details, see http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption * * @access public @@ -192,22 +192,22 @@ class CI_Encrypt { log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.'); return FALSE; } - + // decode it first // set mode temporarily to what it was when string was encoded with the legacy - // algorithm - typically MCRYPT_MODE_ECB + // algorithm - typically MCRYPT_MODE_ECB $current_mode = $this->_get_mode(); $this->set_mode($legacy_mode); - + $key = $this->get_key($key); - + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; } $dec = base64_decode($string); - + if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) { return FALSE; @@ -223,7 +223,7 @@ class CI_Encrypt { } // -------------------------------------------------------------------- - + /** * XOR Encode * @@ -247,7 +247,7 @@ class CI_Encrypt { $enc = ''; for ($i = 0; $i < strlen($string); $i++) - { + { $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1)); } @@ -410,7 +410,7 @@ class CI_Encrypt { { $temp = $temp + 256; } - + $str .= chr($temp); } @@ -418,7 +418,7 @@ class CI_Encrypt { } // -------------------------------------------------------------------- - + /** * Set the Mcrypt Cipher * @@ -477,7 +477,7 @@ class CI_Encrypt { { $this->_mcrypt_mode = MCRYPT_MODE_CBC; } - + return $this->_mcrypt_mode; } @@ -503,7 +503,7 @@ class CI_Encrypt { * @access public * @param string * @return string - */ + */ function hash($str) { return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str); diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 64baaef25..566655b12 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -25,29 +25,29 @@ * @link http://codeigniter.com/user_guide/libraries/form_validation.html */ class CI_Form_validation { - + var $CI; - var $_field_data = array(); + var $_field_data = array(); var $_config_rules = array(); var $_error_array = array(); - var $_error_messages = array(); + var $_error_messages = array(); var $_error_prefix = '<p>'; var $_error_suffix = '</p>'; var $error_string = ''; - var $_safe_form_data = FALSE; + var $_safe_form_data = FALSE; /** * Constructor * - */ + */ function CI_Form_validation($rules = array()) - { + { $this->CI =& get_instance(); - + // Validation rules can be stored in a config file. $this->_config_rules = $rules; - + // Automatically load the form helper $this->CI->load->helper('form'); @@ -56,12 +56,12 @@ class CI_Form_validation { { mb_internal_encoding($this->CI->config->item('charset')); } - + log_message('debug', "Form Validation Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Set Rules * @@ -80,7 +80,7 @@ class CI_Form_validation { { return; } - + // If an array was passed via the first parameter instead of indidual string // values we cycle through it and recursively call this function. if (is_array($field)) @@ -101,7 +101,7 @@ class CI_Form_validation { } return; } - + // No fields? Nothing to do... if ( ! is_string($field) OR ! is_string($rules) OR $field == '') { @@ -113,9 +113,9 @@ class CI_Form_validation { // Is the field name an array? We test for the existence of a bracket "[" in // the field name to determine this. If it is an array, we break it apart - // into its components so that we can fetch the corresponding POST data later + // into its components so that we can fetch the corresponding POST data later if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) - { + { // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $x = explode('[', $field); @@ -128,19 +128,19 @@ class CI_Form_validation { $indexes[] = $matches['1'][$i]; } } - + $is_array = TRUE; } else { - $indexes = array(); - $is_array = FALSE; + $indexes = array(); + $is_array = FALSE; } - - // Build our master array + + // Build our master array $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, + 'field' => $field, + 'label' => $label, 'rules' => $rules, 'is_array' => $is_array, 'keys' => $indexes, @@ -150,7 +150,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Set Error Message * @@ -168,12 +168,12 @@ class CI_Form_validation { { $lang = array($lang => $val); } - + $this->_error_messages = array_merge($this->_error_messages, $lang); } - + // -------------------------------------------------------------------- - + /** * Set The Error Delimiter * @@ -183,7 +183,7 @@ class CI_Form_validation { * @param string * @param string * @return void - */ + */ function set_error_delimiters($prefix = '<p>', $suffix = '</p>') { $this->_error_prefix = $prefix; @@ -191,7 +191,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Get Error Message * @@ -200,14 +200,14 @@ class CI_Form_validation { * @access public * @param string the field name * @return void - */ + */ function error($field = '', $prefix = '', $suffix = '') - { + { if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') { return ''; } - + if ($prefix == '') { $prefix = $this->_error_prefix; @@ -222,7 +222,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Error String * @@ -232,7 +232,7 @@ class CI_Form_validation { * @param string * @param string * @return str - */ + */ function error_string($prefix = '', $suffix = '') { // No errrors, validation passes! @@ -240,7 +240,7 @@ class CI_Form_validation { { return ''; } - + if ($prefix == '') { $prefix = $this->_error_prefix; @@ -250,7 +250,7 @@ class CI_Form_validation { { $suffix = $this->_error_suffix; } - + // Generate the error string $str = ''; foreach ($this->_error_array as $val) @@ -260,12 +260,12 @@ class CI_Form_validation { $str .= $prefix.$val.$suffix."\n"; } } - + return $str; } // -------------------------------------------------------------------- - + /** * Run the Validator * @@ -273,7 +273,7 @@ class CI_Form_validation { * * @access public * @return bool - */ + */ function run($group = '') { // Do we even have any data to process? Mm? @@ -281,7 +281,7 @@ class CI_Form_validation { { return FALSE; } - + // Does the _field_data array containing the validation rules exist? // If not, we look to see if they were assigned via a config file if (count($this->_field_data) == 0) @@ -291,10 +291,10 @@ class CI_Form_validation { { return FALSE; } - + // Is there a validation rule for the particular URI being accessed? $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - + if ($uri != '' AND isset($this->_config_rules[$uri])) { $this->set_rules($this->_config_rules[$uri]); @@ -303,7 +303,7 @@ class CI_Form_validation { { $this->set_rules($this->_config_rules); } - + // We're we able to set the rules correctly? if (count($this->_field_data) == 0) { @@ -311,17 +311,17 @@ class CI_Form_validation { return FALSE; } } - + // Load the language file containing error messages $this->CI->lang->load('form_validation'); - - // Cycle through the rules for each field, match the + + // Cycle through the rules for each field, match the // corresponding $_POST item and test for errors foreach ($this->_field_data as $field => $row) - { + { // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. // Depending on whether the field name is an array or a string will determine where we get it from. - + if ($row['is_array'] == TRUE) { $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); @@ -333,8 +333,8 @@ class CI_Form_validation { $this->_field_data[$field]['postdata'] = $_POST[$field]; } } - - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -347,7 +347,7 @@ class CI_Form_validation { // Now we need to re-set the POST data with the new, processed data $this->_reset_post_array(); - + // No errors, validation passes! if ($total_errors == 0) { @@ -359,7 +359,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Traverse a multidimensional $_POST array index until the data is found * @@ -368,7 +368,7 @@ class CI_Form_validation { * @param array * @param integer * @return mixed - */ + */ function _reduce_array($array, $keys, $i = 0) { if (is_array($array)) @@ -389,18 +389,18 @@ class CI_Form_validation { return $array; } } - + return $array; } // -------------------------------------------------------------------- - + /** * Re-populate the _POST array with our finalized and processed data * * @access private * @return null - */ + */ function _reset_post_array() { foreach ($this->_field_data as $field => $row) @@ -418,7 +418,7 @@ class CI_Form_validation { { // start with a reference $post_ref =& $_POST; - + // before we assign values, make a reference to the right POST key if (count($row['keys']) == 1) { @@ -452,7 +452,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Executes the Validation routines * @@ -462,21 +462,21 @@ class CI_Form_validation { * @param mixed * @param integer * @return mixed - */ + */ function _execute($row, $rules, $postdata = NULL, $cycles = 0) { // If the $_POST data is an array we will run a recursive call if (is_array($postdata)) - { + { foreach ($postdata as $key => $val) { $this->_execute($row, $rules, $val, $cycles); $cycles++; } - + return; } - + // -------------------------------------------------------------------- // If the field is blank, but NOT required, no further tests are necessary @@ -496,7 +496,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + // Isset Test. Typically this rule will only apply to checkboxes. if (is_null($postdata) AND $callback == FALSE) { @@ -504,31 +504,31 @@ class CI_Form_validation { { // Set the message type $type = (in_array('required', $rules)) ? 'required' : 'isset'; - + if ( ! isset($this->_error_messages[$type])) { if (FALSE === ($line = $this->CI->lang->line($type))) { $line = 'The field was not set'; - } + } } else { $line = $this->_error_messages[$type]; } - + // Build the error message $message = sprintf($line, $this->_translate_fieldname($row['label'])); // Save the error message $this->_field_data[$row['field']]['error'] = $message; - + if ( ! isset($this->_error_array[$row['field']])) { $this->_error_array[$row['field']] = $message; } } - + return; } @@ -538,7 +538,7 @@ class CI_Form_validation { foreach ($rules As $rule) { $_in_array = FALSE; - + // We set the $postdata variable with the current data in our master array so that // each cycle of the loop is dealing with the processed data from the last cycle if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) @@ -549,7 +549,7 @@ class CI_Form_validation { { continue; } - + $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; $_in_array = TRUE; } @@ -559,15 +559,15 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - - // Is the rule a callback? + + // Is the rule a callback? $callback = FALSE; if (substr($rule, 0, 9) == 'callback_') { $rule = substr($rule, 9); $callback = TRUE; } - + // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; @@ -576,15 +576,15 @@ class CI_Form_validation { $rule = $match[1]; $param = $match[2]; } - + // Call the function that corresponds to the rule if ($callback === TRUE) { if ( ! method_exists($this->CI, $rule)) - { + { continue; } - + // Run the function and grab the result $result = $this->CI->$rule($postdata, $param); @@ -597,7 +597,7 @@ class CI_Form_validation { { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } - + // If the field isn't required and we just processed a callback we'll move on... if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) { @@ -605,15 +605,15 @@ class CI_Form_validation { } } else - { + { if ( ! method_exists($this, $rule)) { - // If our own wrapper function doesn't exist we see if a native PHP function does. + // If our own wrapper function doesn't exist we see if a native PHP function does. // Users can use any native PHP function call that has one param. if (function_exists($rule)) { $result = $rule($postdata); - + if ($_in_array == TRUE) { $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; @@ -623,7 +623,7 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } - + continue; } @@ -638,54 +638,54 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } - + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) - { + { if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { $line = 'Unable to access an error message corresponding to your field name.'; - } + } } else { $line = $this->_error_messages[$rule]; } - + // Is the parameter we are inserting into the error message the name // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); } - + // Build the error message $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); // Save the error message $this->_field_data[$row['field']]['error'] = $message; - + if ( ! isset($this->_error_array[$row['field']])) { $this->_error_array[$row['field']] = $message; } - + return; } } } // -------------------------------------------------------------------- - + /** * Translate a field name * * @access private * @param string the field name * @return string - */ + */ function _translate_fieldname($fieldname) { // Do we need to translate the field name? @@ -693,8 +693,8 @@ class CI_Form_validation { if (substr($fieldname, 0, 5) == 'lang:') { // Grab the variable - $line = substr($fieldname, 5); - + $line = substr($fieldname, 5); + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { @@ -706,7 +706,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Get the value from a form * @@ -717,19 +717,19 @@ class CI_Form_validation { * @param string the field name * @param string * @return void - */ + */ function set_value($field = '', $default = '') { if ( ! isset($this->_field_data[$field])) { return $default; } - + return $this->_field_data[$field]['postdata']; } - + // -------------------------------------------------------------------- - + /** * Set Select * @@ -740,9 +740,9 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_select($field = '', $value = '', $default = FALSE) - { + { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { if ($default === TRUE AND count($this->_field_data) === 0) @@ -751,9 +751,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -768,12 +768,12 @@ class CI_Form_validation { return ''; } } - + return ' selected="selected"'; } - + // -------------------------------------------------------------------- - + /** * Set Radio * @@ -784,7 +784,7 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_radio($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) @@ -795,9 +795,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -812,12 +812,12 @@ class CI_Form_validation { return ''; } } - + return ' checked="checked"'; } - + // -------------------------------------------------------------------- - + /** * Set Checkbox * @@ -828,7 +828,7 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_checkbox($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) @@ -839,9 +839,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -856,12 +856,12 @@ class CI_Form_validation { return ''; } } - + return ' checked="checked"'; } - + // -------------------------------------------------------------------- - + /** * Required * @@ -880,9 +880,9 @@ class CI_Form_validation { return ( ! empty($str)); } } - + // -------------------------------------------------------------------- - + /** * Match one field to another * @@ -895,16 +895,16 @@ class CI_Form_validation { { if ( ! isset($_POST[$field])) { - return FALSE; + return FALSE; } - + $field = $_POST[$field]; return ($str !== $field) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Minimum Length * @@ -912,7 +912,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function min_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -922,14 +922,14 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) < $val) ? FALSE : TRUE; + return (mb_strlen($str) < $val) ? FALSE : TRUE; } - + return (strlen($str) < $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Max Length * @@ -937,7 +937,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function max_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -947,14 +947,14 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) > $val) ? FALSE : TRUE; + return (mb_strlen($str) > $val) ? FALSE : TRUE; } - + return (strlen($str) > $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Exact Length * @@ -962,7 +962,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function exact_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -972,42 +972,42 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) != $val) ? FALSE : TRUE; + return (mb_strlen($str) != $val) ? FALSE : TRUE; } - + return (strlen($str) != $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Valid Email * * @access public * @param string * @return bool - */ + */ function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- - + /** * Valid Emails * * @access public * @param string * @return bool - */ + */ function valid_emails($str) { if (strpos($str, ',') === FALSE) { return $this->valid_email(trim($str)); } - + foreach(explode(',', $str) as $email) { if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) @@ -1015,12 +1015,12 @@ class CI_Form_validation { return FALSE; } } - + return TRUE; } // -------------------------------------------------------------------- - + /** * Validate IP Address * @@ -1034,56 +1034,56 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Alpha * * @access public * @param string * @return bool - */ + */ function alpha($str) { return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Alpha-numeric * * @access public * @param string * @return bool - */ + */ function alpha_numeric($str) { return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Alpha-numeric with underscores and dashes * * @access public * @param string * @return bool - */ + */ function alpha_dash($str) { return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Numeric * * @access public * @param string * @return bool - */ + */ function numeric($str) { return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); @@ -1092,72 +1092,72 @@ class CI_Form_validation { // -------------------------------------------------------------------- - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } // -------------------------------------------------------------------- - + /** * Integer * * @access public * @param string * @return bool - */ + */ function integer($str) { return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); } - + // -------------------------------------------------------------------- - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } // -------------------------------------------------------------------- - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - + { + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; + } + // -------------------------------------------------------------------- - + /** * Valid Base64 * @@ -1172,9 +1172,9 @@ class CI_Form_validation { { return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); } - + // -------------------------------------------------------------------- - + /** * Prep data for form * @@ -1193,10 +1193,10 @@ class CI_Form_validation { { $data[$key] = $this->prep_for_form($val); } - + return $data; } - + if ($this->_safe_form_data == FALSE OR $data === '') { return $data; @@ -1204,54 +1204,54 @@ class CI_Form_validation { return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); } - + // -------------------------------------------------------------------- - + /** * Prep URL * * @access public * @param string * @return string - */ + */ function prep_url($str = '') { if ($str == 'http://' OR $str == '') { return ''; } - + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') { $str = 'http://'.$str; } - + return $str; } - + // -------------------------------------------------------------------- - + /** * Strip Image Tags * * @access public * @param string * @return string - */ + */ function strip_image_tags($str) { return $this->CI->input->strip_image_tags($str); } - + // -------------------------------------------------------------------- - + /** * XSS Clean * * @access public * @param string * @return string - */ + */ function xss_clean($str) { if ( ! isset($this->CI->security)) @@ -1261,16 +1261,16 @@ class CI_Form_validation { return $this->CI->security->xss_clean($str); } - + // -------------------------------------------------------------------- - + /** * Convert PHP tags to entities * * @access public * @param string * @return string - */ + */ function encode_php_tags($str) { return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str); diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 07f4b1ff3..fa2d3770b 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -295,7 +295,7 @@ class CI_FTP { { return FALSE; } - + // Set the mode if not specified if ($mode == 'auto') { @@ -303,9 +303,9 @@ class CI_FTP { $ext = $this->_getext($rempath); $mode = $this->_settype($ext); } - + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; - + $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode); if ($result === FALSE) @@ -314,11 +314,11 @@ class CI_FTP { { $this->_error('ftp_unable_to_download'); } - return FALSE; + return FALSE; } - + return TRUE; - } + } // -------------------------------------------------------------------- @@ -454,7 +454,7 @@ class CI_FTP { * Set file permissions * * @access public - * @param string the file path + * @param string the file path * @param string the permissions * @return bool */ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 806d942ba..99225600f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -26,7 +26,7 @@ */ class CI_Image_lib { - var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 + var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 var $library_path = ''; var $dynamic_output = FALSE; // Whether to send to browser or write to disk var $source_image = ''; @@ -36,7 +36,7 @@ class CI_Image_lib { var $quality = '90'; var $create_thumb = FALSE; var $thumb_marker = '_thumb'; - var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values + var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values var $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension var $rotation_angle = ''; var $x_axis = ''; @@ -54,11 +54,11 @@ class CI_Image_lib { var $wm_hor_alignment = 'C'; // Horizontal alignment: L R C var $wm_padding = 0; // Padding around text var $wm_hor_offset = 0; // Lets you push text to the right - var $wm_vrt_offset = 0; // Lets you push text down + var $wm_vrt_offset = 0; // Lets you push text down var $wm_font_color = '#ffffff'; // Text color var $wm_shadow_color = ''; // Dropshadow color var $wm_shadow_distance = 2; // Dropshadow distance - var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image + var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image // Private Vars var $source_folder = ''; @@ -147,7 +147,7 @@ class CI_Image_lib { if ($this->source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* @@ -190,7 +190,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -400,7 +400,7 @@ class CI_Image_lib { if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); - return FALSE; + return FALSE; } // Reassign the width and height @@ -455,8 +455,8 @@ class CI_Image_lib { { if ($this->orig_width == $this->width AND $this->orig_height == $this->height) { - if ($this->source_image != $this->new_image) - { + if ($this->source_image != $this->new_image) + { if (@copy($this->full_src_path, $this->full_dst_path)) { @chmod($this->full_dst_path, FILE_WRITE_MODE); @@ -494,14 +494,14 @@ class CI_Image_lib { return FALSE; } - // Create The Image + // Create The Image // // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment // below should that ever prove inaccurate. // // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; @@ -519,7 +519,7 @@ class CI_Image_lib { imagealphablending($dst_img, FALSE); imagesavealpha($dst_img, TRUE); } - + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); // Show the image @@ -584,9 +584,9 @@ class CI_Image_lib { { switch ($this->rotation_angle) { - case 'hor' : $angle = '-flop'; + case 'hor' : $angle = '-flop'; break; - case 'vrt' : $angle = '-flip'; + case 'vrt' : $angle = '-flip'; break; default : $angle = '-rotate '.$this->rotation_angle; break; @@ -664,7 +664,7 @@ class CI_Image_lib { break; case 180 : $angle = 'r180'; break; - case 270 : $angle = 'r90'; + case 270 : $angle = 'r90'; break; case 'vrt' : $angle = 'tb'; break; @@ -889,7 +889,7 @@ class CI_Image_lib { $this->get_image_properties(); // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; @@ -944,7 +944,7 @@ class CI_Image_lib { if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); - } + } // Set RGB values for text and shadow $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); @@ -1266,7 +1266,7 @@ class CI_Image_lib { switch ($this->image_type) { - case 1 : imagegif($resource); + case 1 : imagegif($resource); break; case 2 : imagejpeg($resource, '', $this->quality); break; @@ -1384,8 +1384,8 @@ class CI_Image_lib { * new variable needs to be known * * $props = array( - * 'width' => $width, - * 'height' => $height, + * 'width' => $width, + * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' * ); @@ -1446,7 +1446,7 @@ class CI_Image_lib { { $ext = strrchr($source_image, '.'); $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); - + return array('ext' => $ext, 'name' => $name); } diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index c149bb111..30b62e1c2 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -29,9 +29,9 @@ class CI_Javascript { var $_javascript_location = 'js'; function CI_Javascript($params = array()) - { + { $defaults = array('js_library_driver' => 'jquery', 'autoload' => TRUE); - + foreach ($defaults as $key => $val) { if (isset($params[$key]) && $params[$key] !== "") @@ -39,7 +39,7 @@ class CI_Javascript { $defaults[$key] = $params[$key]; } } - + extract($defaults); $this->CI =& get_instance(); @@ -48,13 +48,13 @@ class CI_Javascript { $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; - + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- - // Event Code // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- /** * Blur @@ -70,9 +70,9 @@ class CI_Javascript { { return $this->js->_blur($element, $js); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -87,9 +87,9 @@ class CI_Javascript { { return $this->js->_change($element, $js); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -107,7 +107,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -124,7 +124,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -141,7 +141,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -158,7 +158,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -168,7 +168,7 @@ class CI_Javascript { * @param string - element * @param string - Javascript code for mouse over * @param string - Javascript code for mouse out - * @return string + * @return string */ function hover($element = 'this', $over, $out) { @@ -176,7 +176,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -193,7 +193,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -207,10 +207,10 @@ class CI_Javascript { function keyup($element = 'this', $js = '') { return $this->js->_keyup($element, $js); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -224,10 +224,10 @@ class CI_Javascript { function load($element = 'this', $js = '') { return $this->js->_load($element, $js); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -244,7 +244,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -261,7 +261,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -360,7 +360,7 @@ class CI_Javascript { { return $this->js->_scroll($element, $js); } - + // -------------------------------------------------------------------- /** @@ -378,9 +378,9 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- - // Effects // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- /** @@ -391,14 +391,14 @@ class CI_Javascript { * @access public * @param string - element * @param string - Class to add - * @return string + * @return string */ function addClass($element = 'this', $class = '') { return $this->js->_addClass($element, $class); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Animate @@ -409,7 +409,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function animate($element = 'this', $params = array(), $speed = '', $extra = '') { @@ -417,7 +417,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Fade In * @@ -427,15 +427,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function fadeIn($element = 'this', $speed = '', $callback = '') { return $this->js->_fadeIn($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -445,14 +445,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function fadeOut($element = 'this', $speed = '', $callback = '') { return $this->js->_fadeOut($element, $speed, $callback); } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -462,14 +462,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideUp($element = 'this', $speed = '', $callback = '') { return $this->js->_slideUp($element, $speed, $callback); } - + // -------------------------------------------------------------------- /** @@ -480,15 +480,15 @@ class CI_Javascript { * @access public * @param string - element * @param string - Class to add - * @return string + * @return string */ function removeClass($element = 'this', $class = '') { return $this->js->_removeClass($element, $class); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Slide Down * @@ -498,7 +498,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideDown($element = 'this', $speed = '', $callback = '') { @@ -506,7 +506,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -516,14 +516,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideToggle($element = 'this', $speed = '', $callback = '') { return $this->js->_slideToggle($element, $speed, $callback); } - + // -------------------------------------------------------------------- /** @@ -535,15 +535,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function hide($element = 'this', $speed = '', $callback = '') { return $this->js->_hide($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -551,16 +551,16 @@ class CI_Javascript { * * @access public * @param string - element - * @return string + * @return string */ function toggle($element = 'this') { return $this->js->_toggle($element); } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -568,15 +568,15 @@ class CI_Javascript { * * @access public * @param string - element - * @return string + * @return string */ function toggleClass($element = 'this', $class='') { return $this->js->_toggleClass($element, $class); } - + // -------------------------------------------------------------------- - + /** * Show * @@ -586,7 +586,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function show($element = 'this', $speed = '', $callback = '') { @@ -604,12 +604,12 @@ class CI_Javascript { * @access public * @param string The element to attach the event to * @return string - */ + */ function compile($view_var = 'script_foot', $script_tags = TRUE) { $this->js->_compile($view_var, $script_tags); } - + /** * Clear Compile * @@ -624,7 +624,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * External * @@ -645,16 +645,16 @@ class CI_Javascript { if ($this->CI->config->item('javascript_location') != '') { $this->_javascript_location = $this->CI->config->item('javascript_location'); - } + } } - + if ($relative === TRUE OR strncmp($external_file, 'http://', 7) == 0 OR strncmp($external_file, 'https://', 8) == 0) { - $str = $this->_open_script($external_file); + $str = $this->_open_script($external_file); } elseif (strpos($this->_javascript_location, 'http://') !== FALSE) { - $str = $this->_open_script($this->_javascript_location.$external_file); + $str = $this->_open_script($this->_javascript_location.$external_file); } else { @@ -664,13 +664,13 @@ class CI_Javascript { $str .= $this->_close_script(); return $str; } - + // -------------------------------------------------------------------- - + /** * Inline * - * Outputs a <script> tag + * Outputs a <script> tag * * @access public * @param string The element to attach the event to @@ -682,19 +682,19 @@ class CI_Javascript { $str = $this->_open_script(); $str .= ($cdata) ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n"; $str .= $this->_close_script(); - + return $str; } - - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- + /** * Open Script * - * Outputs an opening <script> + * Outputs an opening <script> * * @access private - * @param string + * @param string * @return string */ function _open_script($src = '') @@ -705,22 +705,22 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Close Script * - * Outputs an closing </script> + * Outputs an closing </script> * * @access private - * @param string + * @param string * @return string */ function _close_script($extra = "\n") { return "</script>$extra"; } - - + + // -------------------------------------------------------------------- // -------------------------------------------------------------------- // AJAX-Y STUFF - still a testbed @@ -736,15 +736,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function update($element = 'this', $speed = '', $callback = '') { return $this->js->_updater($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Generate JSON * @@ -780,7 +780,7 @@ class CI_Javascript { $json = array(); $_is_assoc = TRUE; - + if ( ! is_array($json_result) AND empty($json_result)) { show_error("Generate JSON Failed - Illegal key, value pair."); @@ -805,11 +805,11 @@ class CI_Javascript { $json = implode(',', $json); return $_is_assoc ? "{".$json."}" : "[".$json."]"; - + } - + // -------------------------------------------------------------------- - + /** * Is associative array * @@ -828,12 +828,12 @@ class CI_Javascript { return TRUE; } } - + return FALSE; } - + // -------------------------------------------------------------------- - + /** * Prep Args * @@ -862,7 +862,7 @@ class CI_Javascript { return $result; } } - + // -------------------------------------------------------------------- } // END Javascript Class diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 4e6b3bc39..99ed126f4 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,27 +40,27 @@ class CI_Log { function CI_Log() { $config =& get_config(); - + $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } - + if (is_numeric($config['log_threshold'])) { $this->_threshold = $config['log_threshold']; } - + if ($config['log_date_format'] != '') { $this->_date_fmt = $config['log_date_format']; } } - + // -------------------------------------------------------------------- - + /** * Write Log File * @@ -71,42 +71,42 @@ class CI_Log { * @param string the error message * @param bool whether the error is a native PHP error * @return bool - */ + */ function write_log($level = 'error', $msg, $php_error = FALSE) - { + { if ($this->_enabled === FALSE) { return FALSE; } - + $level = strtoupper($level); - + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } - + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - + if ( ! file_exists($filepath)) { $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - + if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; - - flock($fp, LOCK_EX); + + flock($fp, LOCK_EX); fwrite($fp, $message); flock($fp, LOCK_UN); fclose($fp); - - @chmod($filepath, FILE_WRITE_MODE); + + @chmod($filepath, FILE_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3a0632d09..b3175f997 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -30,11 +30,11 @@ class CI_Pagination { var $prefix = ''; // A custom prefix added to the path. var $suffix = ''; // A custom suffix added to the path. - var $total_rows = ''; // Total number of items (database results) - var $per_page = 10; // Max number of items you want shown per page + var $total_rows = ''; // Total number of items (database results) + var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - var $cur_page = 0; // The current page being viewed - var $first_link = '‹ First'; + var $cur_page = 0; // The current page being viewed + var $first_link = '‹ First'; var $next_link = '>'; var $prev_link = '<'; var $last_link = 'Last ›'; @@ -190,7 +190,7 @@ class CI_Pagination { $this->base_url = rtrim($this->base_url, '/') .'/'; } - // And here we go... + // And here we go... $output = ''; // Render the "First" link @@ -204,17 +204,17 @@ class CI_Pagination { if ($this->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; - + if ($i == 0 && $this->first_url != '') { - $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; + $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; } else { $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; } - + } // Render the pages @@ -234,7 +234,7 @@ class CI_Pagination { else { $n = ($i == 0) ? '' : $i; - + if ($n == '' && $this->first_url != '') { $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close; @@ -242,7 +242,7 @@ class CI_Pagination { else { $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; - + $output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close; } } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 41a438bac..b969ce4d4 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -94,7 +94,7 @@ class CI_Parser { { if (is_array($val)) { - $template = $this->_parse_pair($key, $val, $template); + $template = $this->_parse_pair($key, $val, $template); } else { @@ -110,9 +110,9 @@ class CI_Parser { return $template; } - + // -------------------------------------------------------------------- - + /** * Set the left/right variable delimiters * @@ -126,9 +126,9 @@ class CI_Parser { $this->l_delim = $l; $this->r_delim = $r; } - + // -------------------------------------------------------------------- - + /** * Parse a single key/value * @@ -142,9 +142,9 @@ class CI_Parser { { return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); } - + // -------------------------------------------------------------------- - + /** * Parse a tag pair * @@ -157,7 +157,7 @@ class CI_Parser { * @return string */ function _parse_pair($variable, $data, $string) - { + { if (FALSE === ($match = $this->_match_pair($string, $variable))) { return $string; @@ -178,15 +178,15 @@ class CI_Parser { $temp = $this->_parse_pair($key, $val, $temp); } } - + $str .= $temp; } - + return str_replace($match['0'], $str, $string); } - + // -------------------------------------------------------------------- - + /** * Matches a variable pair * @@ -201,7 +201,7 @@ class CI_Parser { { return FALSE; } - + return $match; } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index db179976b..796db2d6b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -33,7 +33,7 @@ class CI_Profiler { var $CI; - + var $_available_sections = array( 'benchmarks', 'get', @@ -46,11 +46,11 @@ class CI_Profiler { 'config' ); - function CI_Profiler($config = array()) - { - $this->CI =& get_instance(); - $this->CI->load->language('profiler'); - + function CI_Profiler($config = array()) + { + $this->CI =& get_instance(); + $this->CI->load->language('profiler'); + // default all sections to display foreach ($this->_available_sections as $section) { @@ -59,10 +59,10 @@ class CI_Profiler { $this->_compile_{$section} = TRUE; } } - + $this->set_sections($config); - } - + } + // -------------------------------------------------------------------- /** @@ -80,13 +80,13 @@ class CI_Profiler { { if (in_array($method, $this->_available_sections)) { - $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; + $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; } } } // -------------------------------------------------------------------- - + /** * Auto Profiler * @@ -98,45 +98,45 @@ class CI_Profiler { * @access private * @return array */ - function _compile_benchmarks() - { - $profile = array(); - foreach ($this->CI->benchmark->marker as $key => $val) - { - // We match the "end" marker so that the list ends - // up in the order that it was defined - if (preg_match("/(.+?)_end/i", $key, $match)) - { - if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) - { - $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); - } - } - } + function _compile_benchmarks() + { + $profile = array(); + foreach ($this->CI->benchmark->marker as $key => $val) + { + // We match the "end" marker so that the list ends + // up in the order that it was defined + if (preg_match("/(.+?)_end/i", $key, $match)) + { + if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) + { + $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); + } + } + } // Build a table containing the profile data. // Note: At some point we should turn this into a template that can // be modified. We also might want to make this data available to be logged - + $output = "\n\n"; $output .= '<fieldset style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks').' </legend>'; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n"; - + foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); $output .= "<tr><td style='width:50%;color:#000;font-weight:bold;background-color:#ddd;'>".$key." </td><td style='width:50%;color:#900;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; } - + $output .= "</table>\n"; $output .= "</fieldset>"; - - return $output; - } - + + return $output; + } + // -------------------------------------------------------------------- /** @@ -144,7 +144,7 @@ class CI_Profiler { * * @access private * @return string - */ + */ function _compile_queries() { $dbs = array(); @@ -157,22 +157,22 @@ class CI_Profiler { $dbs[] = $CI_object; } } - + if (count($dbs) == 0) { $output = "\n\n"; $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>'; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' style='width:100%'>\n"; $output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n"; $output .= "</table>\n"; $output .= "</fieldset>"; - + return $output; } - + // Load the text helper so we can highlight the SQL $this->CI->load->helper('text'); @@ -180,45 +180,45 @@ class CI_Profiler { $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); $output = "\n\n"; - + foreach ($dbs as $db) { $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database').': '.$db->database.' '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).' </legend>'; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' style='width:100%;'>\n"; - + if (count($db->queries) == 0) { $output .= "<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n"; } else - { + { foreach ($db->queries as $key => $val) - { + { $time = number_format($db->query_times[$key], 4); $val = highlight_code($val, ENT_QUOTES); - + foreach ($highlight as $bold) { - $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); + $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); } - + $output .= "<tr><td valign='top' style='width:1%;color:#900;font-weight:normal;background-color:#ddd;'>".$time." </td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; } } - + $output .= "</table>\n"; $output .= "</fieldset>"; - + } - + return $output; } - + // -------------------------------------------------------------------- /** @@ -226,15 +226,15 @@ class CI_Profiler { * * @access private * @return string - */ + */ function _compile_get() - { + { $output = "\n\n"; $output .= '<fieldset style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data').' </legend>'; $output .= "\n"; - + if (count($_GET) == 0) { $output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_get')."</div>"; @@ -242,14 +242,14 @@ class CI_Profiler { else { $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n"; - + foreach ($_GET as $key => $val) { if ( ! is_numeric($key)) { $key = "'".$key."'"; } - + $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_GET[".$key."] </td><td width='50%' style='color:#cd6e00;font-weight:normal;background-color:#ddd;'>"; if (is_array($val)) { @@ -261,30 +261,30 @@ class CI_Profiler { } $output .= "</td></tr>\n"; } - + $output .= "</table>\n"; } $output .= "</fieldset>"; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Compile $_POST Data * * @access private * @return string - */ + */ function _compile_post() - { + { $output = "\n\n"; $output .= '<fieldset style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data').' </legend>'; $output .= "\n"; - + if (count($_POST) == 0) { $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>"; @@ -292,14 +292,14 @@ class CI_Profiler { else { $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n"; - + foreach ($_POST as $key => $val) { if ( ! is_numeric($key)) { $key = "'".$key."'"; } - + $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_POST[".$key."] </td><td width='50%' style='color:#009900;font-weight:normal;background-color:#ddd;'>"; if (is_array($val)) { @@ -311,70 +311,70 @@ class CI_Profiler { } $output .= "</td></tr>\n"; } - + $output .= "</table>\n"; } $output .= "</fieldset>"; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Show query string * * @access private * @return string - */ + */ function _compile_uri_string() - { + { $output = "\n\n"; $output .= '<fieldset style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string').' </legend>'; $output .= "\n"; - + if ($this->CI->uri->uri_string == '') { $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_uri')."</div>"; } else { - $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->uri->uri_string."</div>"; + $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->uri->uri_string."</div>"; } - + $output .= "</fieldset>"; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Show the controller and function that were called * * @access private * @return string - */ + */ function _compile_controller_info() - { + { $output = "\n\n"; $output .= '<fieldset style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; $output .= "\n"; $output .= '<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info').' </legend>'; $output .= "\n"; - - $output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."</div>"; - + $output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."</div>"; + + $output .= "</fieldset>"; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Compile memory usage * @@ -390,23 +390,23 @@ class CI_Profiler { $output .= "\n"; $output .= '<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage').' </legend>'; $output .= "\n"; - + if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') { $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage).' bytes</div>'; } else { - $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory_usage')."</div>"; + $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory_usage')."</div>"; } - + $output .= "</fieldset>"; return $output; } // -------------------------------------------------------------------- - + /** * Compile header information * @@ -463,7 +463,7 @@ class CI_Profiler { { $val = print_r($val, TRUE); } - + $output .= "<tr><td valign='top' style='color:#900;background-color:#ddd;'>".$config." </td><td style='color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n"; } @@ -474,18 +474,18 @@ class CI_Profiler { } // -------------------------------------------------------------------- - + /** * Run the Profiler * * @access private * @return string - */ + */ function run() { $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>"; $fields_displayed = 0; - + foreach ($this->_available_sections as $section) { if ($this->_compile_{$section} !== FALSE) @@ -500,7 +500,7 @@ class CI_Profiler { { $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>'; } - + $output .= '</div>'; return $output; diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 3c1e9cfba..fa5317ea3 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -25,12 +25,12 @@ * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Security { - var $xss_hash = ''; - var $csrf_hash = ''; + var $xss_hash = ''; + var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; var $csrf_cookie_name = 'ci_csrf_token'; - + /* never allowed, string replacement */ var $never_allowed_str = array( 'document.cookie' => '[removed]', @@ -63,7 +63,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * Verify Cross Site Request Forgery Protection * @@ -92,7 +92,7 @@ class CI_Security { // We kill this since we're done and we don't want to polute the _POST array unset($_POST[$this->csrf_token_name]); - + // Nothing should last forever unset($_COOKIE[$this->csrf_cookie_name]); $this->_csrf_set_hash(); @@ -100,9 +100,9 @@ class CI_Security { log_message('debug', "CSRF token verified "); } - + // -------------------------------------------------------------------- - + /** * Set Cross Site Request Forgery Protection Cookie * @@ -114,12 +114,12 @@ class CI_Security { $expire = time() + $this->csrf_expire; setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); - - log_message('debug', "CRSF cookie Set"); + + log_message('debug', "CRSF cookie Set"); } - + // -------------------------------------------------------------------- - + /** * Set Cross Site Request Forgery Protection Cookie * @@ -146,7 +146,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * Show CSRF Error * @@ -159,7 +159,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * XSS Clean * @@ -198,7 +198,7 @@ class CI_Security { { $str[$key] = $this->xss_clean($str[$key]); } - + return $str; } @@ -210,9 +210,9 @@ class CI_Security { /* * Protect GET variables in URLs */ - + // 901119URL5918AMP18930PROTECT8198 - + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); /* @@ -225,7 +225,7 @@ class CI_Security { $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); /* - * Validate UTF16 two byte encoding (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * @@ -248,9 +248,9 @@ class CI_Security { * */ $str = rawurldecode($str); - + /* - * Convert character entities to ASCII + * Convert character entities to ASCII * * This permits our tests below to work reliably. * We only convert entities that are within tags since @@ -259,14 +259,14 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* * Remove Invisible Characters Again! */ $str = remove_invisible_characters($str); - + /* * Convert all tabs to spaces * @@ -276,29 +276,29 @@ class CI_Security { * so we use str_replace. * */ - + if (strpos($str, "\t") !== FALSE) { $str = str_replace("\t", ' ', $str); } - + /* * Capture converted string for later comparison */ $converted_string = $str; - + /* * Not Allowed Under Any Conditions */ - + foreach ($this->never_allowed_str as $key => $val) { - $str = str_replace($key, $val, $str); + $str = str_replace($key, $val, $str); } - + foreach ($this->never_allowed_regex as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } /* @@ -321,7 +321,7 @@ class CI_Security { { $str = str_replace(array('<?', '?'.'>'), array('<?', '?>'), $str); } - + /* * Compact any exploded words * @@ -333,7 +333,7 @@ class CI_Security { foreach ($words as $word) { $temp = ''; - + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) { $temp .= substr($word, $i, 1)."\s*"; @@ -343,7 +343,7 @@ class CI_Security { // That way valid stuff like "dealer to" does not become "dealerto" $str = preg_replace_callback('#('.substr($temp, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str); } - + /* * Remove disallowed Javascript in links or img tags * We used to do some version comparisons and use of stripos for PHP5, but it is dog slow compared @@ -352,17 +352,17 @@ class CI_Security { do { $original = $str; - + if (preg_match("/<a/i", $str)) { $str = preg_replace_callback("#<a\s+([^>]*?)(>|$)#si", array($this, '_js_link_removal'), $str); } - + if (preg_match("/<img/i", $str)) { $str = preg_replace_callback("#<img\s+([^>]*?)(\s?/?>|$)#si", array($this, '_js_img_removal'), $str); } - + if (preg_match("/script/i", $str) OR preg_match("/xss/i", $str)) { $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); @@ -385,14 +385,14 @@ class CI_Security { if ($is_image === TRUE) { /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, * so we have to allow this for images. -Paul */ unset($event_handlers[array_search('xmlns', $event_handlers)]); } $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - + /* * Sanitize naughty HTML elements * @@ -420,7 +420,7 @@ class CI_Security { * */ $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); - + /* * Final clean up * @@ -430,9 +430,9 @@ class CI_Security { */ foreach ($this->never_allowed_str as $key => $val) { - $str = str_replace($key, $val, $str); + $str = str_replace($key, $val, $str); } - + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); @@ -457,13 +457,13 @@ class CI_Security { return FALSE; } } - + log_message('debug', "XSS Filtering completed"); return $str; } // -------------------------------------------------------------------- - + /** * Random Hash for protecting URLs * @@ -471,22 +471,22 @@ class CI_Security { * @return string */ function xss_hash() - { + { if ($this->xss_hash == '') { if (phpversion() >= 4.2) mt_srand(); else mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); } - + return $this->xss_hash; } // -------------------------------------------------------------------- - + /** * Compact Exploded Words * @@ -501,9 +501,9 @@ class CI_Security { { return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; } - + // -------------------------------------------------------------------- - + /** * Sanitize Naughty HTML * @@ -517,15 +517,15 @@ class CI_Security { { // encode opening brace $str = '<'.$matches[1].$matches[2].$matches[3]; - + // encode captured opening or closing brace to prevent recursive vectors $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - + return $str; } - + // -------------------------------------------------------------------- - + /** * JS Link Removal * @@ -543,7 +543,7 @@ class CI_Security { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]); } - + /** * JS Image Removal * @@ -563,7 +563,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * Attribute Conversion * @@ -577,7 +577,7 @@ class CI_Security { { return str_replace(array('>', '<', '\\'), array('>', '<', '\\\\'), $match[0]); } - + // -------------------------------------------------------------------- /** @@ -644,35 +644,35 @@ class CI_Security { function entity_decode($str, $charset='UTF-8') { if (stristr($str, '&') === FALSE) return $str; - + // The reason we are not using html_entity_decode() by itself is because // while it is not technically correct to leave out the semicolon // at the end of an entity most browsers will still interpret the entity // correctly. html_entity_decode() does not convert entities without // semicolons, so we are left with our own little solution here. Bummer. - + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR is_php('5.0.0'))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); } - + // Numeric Entities $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - + // Literal Entities - Slightly slow so we do another check if (stristr($str, '&') === FALSE) { $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); } - + return $str; } - + // -------------------------------------------------------------------- - + /** * Filename Security * @@ -703,16 +703,16 @@ class CI_Security { "%20", "%22", "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; "%3d" // = ); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 7394e5897..1e606de9c 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -39,7 +39,7 @@ class CI_Session { var $cookie_domain = ''; var $sess_time_to_update = 300; var $encryption_key = ''; - var $flashdata_key = 'flash'; + var $flashdata_key = 'flash'; var $time_reference = 'time'; var $gc_probability = 5; var $userdata = array(); @@ -96,7 +96,7 @@ class CI_Session { { $this->sess_expiration = (60*60*24*365*2); } - + // Set the cookie name $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; @@ -112,10 +112,10 @@ class CI_Session { } // Delete 'old' flashdata (from last request) - $this->_flashdata_sweep(); + $this->_flashdata_sweep(); // Mark all new flashdata as old (data will be deleted before next request) - $this->_flashdata_mark(); + $this->_flashdata_mark(); // Delete expired sessions if necessary $this->_sess_gc(); @@ -313,9 +313,9 @@ class CI_Session { $sessid .= $this->CI->input->ip_address(); $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->CI->input->ip_address(), - 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), + 'session_id' => md5(uniqid($sessid, TRUE)), + 'ip_address' => $this->CI->input->ip_address(), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), 'last_activity' => $this->now ); @@ -656,9 +656,9 @@ class CI_Session { // if encryption is not used, we provide an md5 hash to prevent userside tampering $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); } - + $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); - + // Set the cookie setcookie( $this->sess_cookie_name, @@ -690,7 +690,7 @@ class CI_Session { { if (is_string($val)) { - $data[$key] = str_replace('\\', '{{slash}}', $val); + $data[$key] = str_replace('\\', '{{slash}}', $val); } } } @@ -698,7 +698,7 @@ class CI_Session { { if (is_string($data)) { - $data = str_replace('\\', '{{slash}}', $data); + $data = str_replace('\\', '{{slash}}', $data); } } @@ -727,7 +727,7 @@ class CI_Session { { if (is_string($val)) { - $data[$key] = str_replace('{{slash}}', '\\', $val); + $data[$key] = str_replace('{{slash}}', '\\', $val); } } diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index f9611a8a5..ff7e72033 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -55,7 +55,7 @@ class CI_SHA { * @access public * @param string * @return string - */ + */ function generate($str) { $n = ((strlen($str) + 8) >> 6) + 1; @@ -117,7 +117,7 @@ class CI_SHA { return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); } - + // -------------------------------------------------------------------- /** @@ -126,7 +126,7 @@ class CI_SHA { * @access private * @param string * @return string - */ + */ function _hex($str) { $str = dechex($str); @@ -138,7 +138,7 @@ class CI_SHA { return $str; } - + // -------------------------------------------------------------------- /** @@ -146,7 +146,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _ft($t, $b, $c, $d) { if ($t < 20) @@ -166,7 +166,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _kt($t) { if ($t < 20) @@ -186,7 +186,7 @@ class CI_SHA { return -899497514; } } - + // -------------------------------------------------------------------- /** @@ -194,7 +194,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _safe_add($x, $y) { $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); @@ -202,7 +202,7 @@ class CI_SHA { return ($msw << 16) | ($lsw & 0xFFFF); } - + // -------------------------------------------------------------------- /** @@ -210,7 +210,7 @@ class CI_SHA { * * @access private * @return integer - */ + */ function _rol($num, $cnt) { return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); @@ -223,7 +223,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _zero_fill($a, $b) { $bin = decbin($a); diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1f920ea9e..2fc1b634d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -30,13 +30,13 @@ class CI_Table { var $rows = array(); var $heading = array(); - var $auto_heading = TRUE; - var $caption = NULL; - var $template = NULL; + var $auto_heading = TRUE; + var $caption = NULL; + var $template = NULL; var $newline = "\n"; var $empty_cells = ""; var $function = FALSE; - + function CI_Table() { log_message('debug', "Table Class Initialized"); @@ -57,7 +57,7 @@ class CI_Table { { return FALSE; } - + $this->template = $template; } @@ -97,21 +97,21 @@ class CI_Table { { return FALSE; } - - // Turn off the auto-heading feature since it's doubtful we + + // Turn off the auto-heading feature since it's doubtful we // will want headings from a one-dimensional array $this->auto_heading = FALSE; - + if ($col_limit == 0) { return $array; } - + $new = array(); while(count($array) > 0) - { - $temp = array_splice($array, 0, $col_limit); - + { + $temp = array_splice($array, 0, $col_limit); + if (count($temp) < $col_limit) { for ($i = count($temp); $i < $col_limit; $i++) @@ -119,10 +119,10 @@ class CI_Table { $temp[] = ' '; } } - + $new[] = $temp; } - + return $new; } @@ -141,7 +141,7 @@ class CI_Table { { $this->empty_cells = $value; } - + // -------------------------------------------------------------------- /** @@ -160,7 +160,7 @@ class CI_Table { } // -------------------------------------------------------------------- - + /** * Prep Args * @@ -188,9 +188,9 @@ class CI_Table { } else { - $args[$key] = array('data' => $val); + $args[$key] = array('data' => $val); } - } + } } } else @@ -203,12 +203,12 @@ class CI_Table { } } } - + return $args; } // -------------------------------------------------------------------- - + /** * Add a table caption * @@ -219,7 +219,7 @@ class CI_Table { function set_caption($caption) { $this->caption = $caption; - } + } // -------------------------------------------------------------------- @@ -246,23 +246,23 @@ class CI_Table { $this->_set_from_array($table_data, $set_heading); } } - + // Is there anything to display? No? Smite them! if (count($this->heading) == 0 AND count($this->rows) == 0) { return 'Undefined table data'; } - + // Compile and validate the template date $this->_compile_template(); - + // set a custom cell manipulation function to a locally scoped variable so its callable $function = $this->function; - + // Build the table! - + $out = $this->template['table_open']; - $out .= $this->newline; + $out .= $this->newline; // Add any caption here if ($this->caption) @@ -283,16 +283,16 @@ class CI_Table { foreach($this->heading as $heading) { $temp = $this->template['heading_cell_start']; - + foreach ($heading as $key => $val) { if ($key != 'data') { $temp = str_replace('<th', "<th $key='$val'", $temp); - } + } } - $out .= $temp; + $out .= $temp; $out .= isset($heading['data']) ? $heading['data'] : ''; $out .= $this->template['heading_cell_end']; } @@ -302,13 +302,13 @@ class CI_Table { $out .= $this->template['thead_close']; $out .= $this->newline; } - + // Build the table rows if (count($this->rows) > 0) { $out .= $this->template['tbody_open']; $out .= $this->newline; - + $i = 1; foreach($this->rows as $row) { @@ -316,25 +316,25 @@ class CI_Table { { break; } - + // We use modulus to alternate the row colors $name = (fmod($i++, 2)) ? '' : 'alt_'; - + $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; - + $out .= $this->newline; + foreach($row as $cell) { $temp = $this->template['cell_'.$name.'start']; - + foreach ($cell as $key => $val) { if ($key != 'data') { $temp = str_replace('<td', "<td $key='$val'", $temp); - } + } } - + $cell = isset($cell['data']) ? $cell['data'] : ''; $out .= $temp; @@ -353,23 +353,23 @@ class CI_Table { $out .= $cell; } } - + $out .= $this->template['cell_'.$name.'end']; } - + $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; + $out .= $this->newline; } - + $out .= $this->template['tbody_close']; $out .= $this->newline; } $out .= $this->template['table_close']; - + return $out; } - + // -------------------------------------------------------------------- /** @@ -382,9 +382,9 @@ class CI_Table { { $this->rows = array(); $this->heading = array(); - $this->auto_heading = TRUE; + $this->auto_heading = TRUE; } - + // -------------------------------------------------------------------- /** @@ -400,7 +400,7 @@ class CI_Table { { return FALSE; } - + // First generate the headings from the table column names if (count($this->heading) == 0) { @@ -408,12 +408,12 @@ class CI_Table { { return FALSE; } - + $this->heading = $this->_prep_args($query->list_fields()); } - + // Next blast through the result array and build out the rows - + if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) @@ -438,10 +438,10 @@ class CI_Table { { return FALSE; } - + $i = 0; foreach ($data as $row) - { + { // If a heading hasn't already been set we'll use the first row of the array as the heading if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE) { @@ -451,7 +451,7 @@ class CI_Table { { $this->rows[] = $this->_prep_args($row); } - + $i++; } } @@ -464,14 +464,14 @@ class CI_Table { * @access private * @return void */ - function _compile_template() - { - if ($this->template == NULL) - { - $this->template = $this->_default_template(); - return; - } - + function _compile_template() + { + if ($this->template == NULL) + { + $this->template = $this->_default_template(); + return; + } + $this->temp = $this->_default_template(); foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) { @@ -479,9 +479,9 @@ class CI_Table { { $this->template[$val] = $this->temp[$val]; } - } - } - + } + } + // -------------------------------------------------------------------- /** @@ -493,33 +493,33 @@ class CI_Table { function _default_template() { return array ( - 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', - + 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', + 'thead_open' => '<thead>', 'thead_close' => '</thead>', - - 'heading_row_start' => '<tr>', - 'heading_row_end' => '</tr>', + + 'heading_row_start' => '<tr>', + 'heading_row_end' => '</tr>', 'heading_cell_start' => '<th>', 'heading_cell_end' => '</th>', 'tbody_open' => '<tbody>', 'tbody_close' => '</tbody>', - - 'row_start' => '<tr>', - 'row_end' => '</tr>', + + 'row_start' => '<tr>', + 'row_end' => '</tr>', 'cell_start' => '<td>', 'cell_end' => '</td>', - 'row_alt_start' => '<tr>', - 'row_alt_end' => '</tr>', + 'row_alt_start' => '<tr>', + 'row_alt_end' => '</tr>', 'cell_alt_start' => '<td>', 'cell_alt_end' => '</td>', - 'table_close' => '</table>' - ); + 'table_close' => '</table>' + ); } - + } diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index a27914487..a8be8a877 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -27,7 +27,7 @@ * @link http://codeigniter.com/user_guide/libraries/trackback.html */ class CI_Trackback { - + var $time_format = 'local'; var $charset = 'UTF-8'; var $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); @@ -44,24 +44,24 @@ class CI_Trackback { { log_message('debug', "Trackback Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Send Trackback * * @access public * @param array * @return bool - */ + */ function send($tb_data) - { + { if ( ! is_array($tb_data)) { $this->set_error('The send() method must be passed an array'); return FALSE; } - + // Pre-process the Trackback Data foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { @@ -70,14 +70,14 @@ class CI_Trackback { $this->set_error('Required item missing: '.$item); return FALSE; } - + switch ($item) { case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]); break; case 'excerpt' : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); break; - case 'url' : $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); + case 'url' : $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); break; default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); break; @@ -103,9 +103,9 @@ class CI_Trackback { // Build the Trackback data string $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; - + $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset); - + // Send Trackback(s) $return = TRUE; if (count($ping_url) > 0) @@ -116,14 +116,14 @@ class CI_Trackback { { $return = FALSE; } - } + } } return $return; } - + // -------------------------------------------------------------------- - + /** * Receive Trackback Data * @@ -134,9 +134,9 @@ class CI_Trackback { * * @access public * @return bool - */ + */ function receive() - { + { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { if ( ! isset($_POST[$val]) OR $_POST[$val] == '') @@ -144,29 +144,29 @@ class CI_Trackback { $this->set_error('The following required POST variable is missing: '.$val); return FALSE; } - + $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); - + if ($val != 'url' && function_exists('mb_convert_encoding')) { $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); } - + $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]); - + if ($val == 'excerpt') { $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']); } - + $this->data[$val] = $_POST[$val]; } return TRUE; - } - + } + // -------------------------------------------------------------------- - + /** * Send Trackback Error Message * @@ -177,15 +177,15 @@ class CI_Trackback { * @access public * @param string * @return void - */ + */ function send_error($message = 'Incomplete Information') { echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>"; exit; } - + // -------------------------------------------------------------------- - + /** * Send Trackback Success Message * @@ -194,29 +194,29 @@ class CI_Trackback { * * @access public * @return void - */ + */ function send_success() { echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>0</error>\n</response>"; exit; } - + // -------------------------------------------------------------------- - + /** * Fetch a particular item * * @access public * @param string * @return string - */ + */ function data($item) { return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } // -------------------------------------------------------------------- - + /** * Process Trackback * @@ -227,11 +227,11 @@ class CI_Trackback { * @param string * @param string * @return bool - */ + */ function process($url, $data) { $target = parse_url($url); - + // Open the socket if ( ! $fp = @fsockopen($target['host'], 80)) { @@ -241,7 +241,7 @@ class CI_Trackback { // Build the path $ppath = ( ! isset($target['path'])) ? $url : $target['path']; - + $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; // Add the Trackback ID to the data string @@ -260,32 +260,32 @@ class CI_Trackback { // Was it successful? $this->response = ""; - + while( ! feof($fp)) { $this->response .= fgets($fp, 128); } @fclose($fp); - - + + if (stristr($this->response, '<error>0</error>') === FALSE) { $message = 'An unknown error was encountered'; - + if (preg_match("/<message>(.*?)<\/message>/is", $this->response, $match)) { $message = trim($match['1']); } - + $this->set_error($message); return FALSE; } return TRUE; } - + // -------------------------------------------------------------------- - + /** * Extract Trackback URLs * @@ -296,34 +296,34 @@ class CI_Trackback { * @access public * @param string * @return string - */ + */ function extract_urls($urls) - { + { // Remove the pesky white space and replace with a comma. $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls); - + // If they use commas get rid of the doubles. $urls = str_replace(",,", ",", $urls); - + // Remove any comma that might be at the end if (substr($urls, -1) == ",") { $urls = substr($urls, 0, -1); } - + // Break into an array via commas $urls = preg_split('/[,]/', $urls); - + // Removes duplicates $urls = array_unique($urls); - + array_walk($urls, array($this, 'validate_url')); - + return $urls; } - + // -------------------------------------------------------------------- - + /** * Validate URL * @@ -332,7 +332,7 @@ class CI_Trackback { * @access public * @param string * @return string - */ + */ function validate_url($url) { $url = trim($url); @@ -342,46 +342,46 @@ class CI_Trackback { $url = "http://".$url; } } - + // -------------------------------------------------------------------- - + /** * Find the Trackback URL's ID * * @access public * @param string * @return string - */ + */ function get_id($url) - { + { $tb_id = ""; - + if (strpos($url, '?') !== FALSE) { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - + if ( ! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } - + $tb_array = explode('=', $tb_end); $tb_id = $tb_array[count($tb_array)-1]; } else { $url = rtrim($url, '/'); - + $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - + if ( ! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } - } - + } + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) { return FALSE; @@ -389,11 +389,11 @@ class CI_Trackback { else { return $tb_id; - } + } } - + // -------------------------------------------------------------------- - + /** * Convert Reserved XML characters to Entities * @@ -404,22 +404,22 @@ class CI_Trackback { function convert_xml($str) { $temp = '__TEMP_AMPERSANDS__'; - + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - + $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - + array("&", "<", ">", """, "'", "-"), + $str); + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - + return $str; - } - + } + // -------------------------------------------------------------------- - + /** * Character limiter * @@ -437,27 +437,27 @@ class CI_Trackback { { return $str; } - + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); - + if (strlen($str) <= $n) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { - $out .= $val.' '; + $out .= $val.' '; if (strlen($out) >= $n) { return trim($out).$end_char; - } + } } } - + // -------------------------------------------------------------------- - + /** * High ASCII to Entities * @@ -470,58 +470,58 @@ class CI_Trackback { */ function convert_ascii($str) { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + $out .= $str[$i]; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; } - + // -------------------------------------------------------------------- - + /** * Set error message * * @access public * @param string * @return void - */ + */ function set_error($msg) { log_message('error', $msg); $this->error_msg[] = $msg; } - + // -------------------------------------------------------------------- - + /** * Show error messages * @@ -529,15 +529,15 @@ class CI_Trackback { * @param string * @param string * @return string - */ + */ function display_errors($open = '<p>', $close = '</p>') - { + { $str = ''; foreach ($this->error_msg as $val) { $str .= $open.$val.$close; } - + return $str; } diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index f058769ec..d8b295e7b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -28,22 +28,22 @@ class CI_Typography { // Block level elements that should not be wrapped inside <p> tags var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul'; - + // Elements that should not have <p> and <br /> tags within them. var $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d'; - + // Tags we want the parser to completely ignore when splitting the string. var $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var'; - + // array of block level elements that require inner content to be within another block level element var $inner_block_required = array('blockquote'); - + // the last block element parsed var $last_block_element = ''; - + // whether or not to protect quotes within { curly braces } var $protect_braced_quotes = FALSE; - + /** * Nothing to do here... * @@ -56,11 +56,11 @@ class CI_Typography { * Auto Typography * * This function converts text, making it typographically correct: - * - Converts double spaces into paragraphs. - * - Converts single line breaks into <br /> tags - * - Converts single and double quotes into correctly facing curly quote entities. - * - Converts three dots into ellipsis. - * - Converts double dashes into em-dashes. + * - Converts double spaces into paragraphs. + * - Converts single line breaks into <br /> tags + * - Converts single and double quotes into correctly facing curly quote entities. + * - Converts three dots into ellipsis. + * - Converts double dashes into em-dashes. * - Converts two spaces into entities * * @access public @@ -78,15 +78,15 @@ class CI_Typography { // Standardize Newlines to make matching easier if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $str = str_replace(array("\r\n", "\r"), "\n", $str); } - + // Reduce line breaks. If there are more than two consecutive linebreaks // we'll compress them down to a maximum of two since there's no benefit to more. if ($reduce_linebreaks === TRUE) { $str = preg_replace("/\n\n+/", "\n\n", $str); - } + } // HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed $html_comments = array(); @@ -101,50 +101,50 @@ class CI_Typography { } } } - + // match and yank <pre> tags if they exist. It's cheaper to do this separately since most content will // not contain <pre> tags, and it keeps the PCRE patterns below simpler and faster if (strpos($str, '<pre') !== FALSE) { $str = preg_replace_callback("#<pre.*?>.*?</pre>#si", array($this, '_protect_characters'), $str); } - + // Convert quotes within tags to temporary markers. $str = preg_replace_callback("#<.+?>#si", array($this, '_protect_characters'), $str); // Do the same with braces if necessary if ($this->protect_braced_quotes === TRUE) { - $str = preg_replace_callback("#\{.+?\}#si", array($this, '_protect_characters'), $str); + $str = preg_replace_callback("#\{.+?\}#si", array($this, '_protect_characters'), $str); } - - // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag - // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be + + // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag + // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); // Split the string at every tag. This expression creates an array with this prototype: - // - // [array] - // { - // [0] = <opening tag> - // [1] = Content... - // [2] = <closing tag> - // Etc... - // } + // + // [array] + // { + // [0] = <opening tag> + // [1] = Content... + // [2] = <closing tag> + // Etc... + // } $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - - // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text + + // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text $str = ''; $process = TRUE; $paragraph = FALSE; $current_chunk = 0; $total_chunks = count($chunks); - + foreach ($chunks as $chunk) - { + { $current_chunk++; - + // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip <pre> tags and a few other things. if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match)) @@ -153,7 +153,7 @@ class CI_Typography { { $process = ($match[1] == '/') ? TRUE : FALSE; } - + if ($match[1] == '') { $this->last_block_element = $match[2]; @@ -162,32 +162,32 @@ class CI_Typography { $str .= $chunk; continue; } - + if ($process == FALSE) { $str .= $chunk; continue; } - + // Force a newline to make sure end tags get processed by _format_newlines() if ($current_chunk == $total_chunks) { - $chunk .= "\n"; + $chunk .= "\n"; } - + // Convert Newlines into <p> and <br /> tags $str .= $this->_format_newlines($chunk); } - + // No opening block level tag? Add it if needed. if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) { $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '<p>$1</p><$2', $str); } - + // Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands $str = $this->format_characters($str); - + // restore HTML comments for ($i = 0, $total = count($html_comments); $i < $total; $i++) { @@ -196,18 +196,18 @@ class CI_Typography { // if '<p>{@HC1}' then replace <p>{@HC1}</p> with the comment, else replace only {@HC1} with the comment $str = preg_replace('#(?(?=<p>\{@HC'.$i.'\})<p>\{@HC'.$i.'\}(\s*</p>)|\{@HC'.$i.'\})#s', $html_comments[$i], $str); } - + // Final clean up $table = array( - + // If the user submitted their own paragraph tags within the text // we will retain them instead of using our tags. '/(<p[^>*?]>)<p>/' => '$1', // <?php BBEdit syntax coloring bug fix - + // Reduce multiple instances of opening/closing paragraph tags to a single one '#(</p>)+#' => '</p>', '/(<p>\W*<p>)+/' => '<p>', - + // Clean up stray paragraph tags that appear before block level elements '#<p></p><('.$this->block_elements.')#' => '<$1', @@ -223,15 +223,15 @@ class CI_Typography { // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in <p> tags - // starting immediately after <block> tags on the same line. + // starting immediately after <block> tags on the same line. // This forces a newline after such occurrences, which looks much nicer. "/><p>\n/" => ">\n<p>", - + // Similarly, there might be cases where a closing </block> will follow // a closing </p> tag, so we'll correct it by adding a newline in between "#</p></#" => "</p>\n</" ); - + // Do we need to reduce empty lines? if ($reduce_linebreaks === TRUE) { @@ -243,13 +243,13 @@ class CI_Typography { // otherwise most browsers won't treat them as true paragraphs $table['#<p></p>#'] = '<p> </p>'; } - + return preg_replace(array_keys($table), $table, $str); } - + // -------------------------------------------------------------------- - + /** * Format Characters * @@ -264,10 +264,10 @@ class CI_Typography { function format_characters($str) { static $table; - + if ( ! isset($table)) { - $table = array( + $table = array( // nested smart quotes, opening and closing // note that rules for grammar (English) allow only for two levels deep // and that single quotes are _supposed_ to always be on the outside @@ -313,7 +313,7 @@ class CI_Typography { return preg_replace(array_keys($table), $table, $str); } - + // -------------------------------------------------------------------- /** @@ -324,25 +324,25 @@ class CI_Typography { * @access public * @param string * @return string - */ + */ function _format_newlines($str) { if ($str == '') { return $str; } - + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } - + // Convert two consecutive newlines to paragraphs $str = str_replace("\n\n", "</p>\n\n<p>", $str); - + // Convert single spaces to <br /> tags $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1<br />\\2\\3", $str); - + // Wrap the whole enchilada in enclosing paragraphs if ($str != "\n") { @@ -355,19 +355,19 @@ class CI_Typography { // Remove empty paragraphs if they are on the first line, as this // is a potential unintended consequence of the previous code $str = preg_replace("/<p><\/p>(.*)/", "\\1", $str, 1); - + return $str; } - + // ------------------------------------------------------------------------ - + /** * Protect Characters * * Protects special characters from being formatted later * We don't want quotes converted within tags so we'll temporarily convert them to {@DQ} and {@SQ} - * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} - * likewise double spaces are converted to {@NBS} to prevent entity conversion + * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} + * likewise double spaces are converted to {@NBS} to prevent entity conversion * * @access public * @param array @@ -379,19 +379,19 @@ class CI_Typography { } // -------------------------------------------------------------------- - + /** * Convert newlines to HTML line breaks except within PRE tags * * @access public * @param string * @return string - */ + */ function nl2br_except_pre($str) { $ex = explode("pre>",$str); $ct = count($ex); - + $newstr = ""; for ($i = 0; $i < $ct; $i++) { @@ -403,14 +403,14 @@ class CI_Typography { { $newstr .= $ex[$i]; } - + if ($ct - 1 != $i) $newstr .= "pre>"; } - + return $newstr; } - + } // END Typography Class diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index c47143637..9a90cb47c 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -29,9 +29,9 @@ class CI_Unit_test { var $active = TRUE; - var $results = array(); + var $results = array(); var $strict = FALSE; - var $_template = NULL; + var $_template = NULL; var $_template_rows = NULL; var $_test_items_visible = array(); @@ -82,32 +82,32 @@ class CI_Unit_test { * @param mixed * @param string * @return string - */ + */ function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { if ($this->active == FALSE) { return FALSE; } - + if (in_array($expected, array('is_object', 'is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; + $result = ($expected($test)) ? TRUE : FALSE; $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); } else { if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; + $result = ($test === $expected) ? TRUE : FALSE; else - $result = ($test == $expected) ? TRUE : FALSE; - + $result = ($test == $expected) ? TRUE : FALSE; + $extype = gettype($expected); } - + $back = $this->_backtrace(); - + $report[] = array ( 'test_name' => $test_name, 'test_datatype' => gettype($test), @@ -124,7 +124,7 @@ class CI_Unit_test { } // -------------------------------------------------------------------- - + /** * Generate a report * @@ -175,9 +175,9 @@ class CI_Unit_test { return $r; } - + // -------------------------------------------------------------------- - + /** * Use strict comparison * @@ -191,9 +191,9 @@ class CI_Unit_test { { $this->strict = ($state == FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Make Unit testing active * @@ -207,9 +207,9 @@ class CI_Unit_test { { $this->active = ($state == FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Result Array * @@ -219,15 +219,15 @@ class CI_Unit_test { * @return array */ function result($results = array()) - { + { $CI =& get_instance(); $CI->load->language('unit_test'); - + if (count($results) == 0) { $results = $this->results; } - + $retval = array(); foreach ($results as $result) { @@ -246,8 +246,8 @@ class CI_Unit_test { if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; } } else @@ -255,19 +255,19 @@ class CI_Unit_test { if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) { $val = $line; - } + } $temp[$CI->lang->line('ut_'.$key)] = $val; } } - + $retval[] = $temp; } - + return $retval; } - + // -------------------------------------------------------------------- - + /** * Set the template * @@ -276,14 +276,14 @@ class CI_Unit_test { * @access public * @param string * @return void - */ + */ function set_template($template) { $this->_template = $template; } - + // -------------------------------------------------------------------- - + /** * Generate a backtrace * @@ -297,17 +297,17 @@ class CI_Unit_test { if (function_exists('debug_backtrace')) { $back = debug_backtrace(); - + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - + return array('file' => $file, 'line' => $line); } return array('file' => 'Unknown', 'line' => 'Unknown'); } // -------------------------------------------------------------------- - + /** * Get Default Template * @@ -315,17 +315,17 @@ class CI_Unit_test { * @return string */ function _default_template() - { + { $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">'; $this->_template .= '{rows}'; $this->_template .= "\n".'</table>'; - + $this->_template_rows = "\n\t".'<tr>'; $this->_template_rows .= "\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>'; $this->_template_rows .= "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>'; - $this->_template_rows .= "\n\t".'</tr>'; + $this->_template_rows .= "\n\t".'</tr>'; } - + // -------------------------------------------------------------------- /** @@ -336,29 +336,29 @@ class CI_Unit_test { * @access private * @return void */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { - $this->_default_template(); - return; + $this->_default_template(); + return; } $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + } // END Unit_test Class diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c18c178df..c83d0aeaa 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/libraries/file_uploading.html */ class CI_Upload { - + var $max_size = 0; var $max_width = 0; var $max_height = 0; @@ -51,9 +51,9 @@ class CI_Upload { var $xss_clean = FALSE; var $temp_prefix = "temp_file_"; var $client_name = ''; - + var $_file_name_override = ''; //@PHP4 (should be private) - + /** * Constructor * @@ -65,19 +65,19 @@ class CI_Upload { { $this->initialize($props); } - + log_message('debug', "Upload Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Initialize preferences * * @access public * @param array * @return void - */ + */ function initialize($config = array()) { @@ -107,9 +107,9 @@ class CI_Upload { 'xss_clean' => FALSE, 'temp_prefix' => "temp_file_", 'client_name' => '' - ); - - + ); + + foreach ($defaults as $key => $val) { if (isset($config[$key])) @@ -122,27 +122,27 @@ class CI_Upload { else { $this->$key = $config[$key]; - } + } } else { $this->$key = $val; } } - + // if a file_name was provided in the config, use it instead of the user input // supplied file name for all uploads until initialized again $this->_file_name_override = $this->file_name; } - + // -------------------------------------------------------------------- - + /** * Perform the file upload * * @access public * @return bool - */ + */ function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. @@ -151,7 +151,7 @@ class CI_Upload { $this->set_error('upload_no_file_selected'); return FALSE; } - + // Is the upload path valid? if ( ! $this->validate_upload_path()) { @@ -173,10 +173,10 @@ class CI_Upload { $this->set_error('upload_file_exceeds_form_limit'); break; case 3: // UPLOAD_ERR_PARTIAL - $this->set_error('upload_file_partial'); + $this->set_error('upload_file_partial'); break; case 4: // UPLOAD_ERR_NO_FILE - $this->set_error('upload_no_file_selected'); + $this->set_error('upload_no_file_selected'); break; case 6: // UPLOAD_ERR_NO_TMP_DIR $this->set_error('upload_no_temp_directory'); @@ -196,14 +196,14 @@ class CI_Upload { // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_size = $_FILES[$field]['size']; + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_ext = $this->get_extension($this->file_name); $this->client_name = $this->file_name; - + // Is the file type allowed to be uploaded? if ( ! $this->is_allowed_filetype()) { @@ -220,10 +220,10 @@ class CI_Upload { if ( ! $this->is_allowed_filetype(TRUE)) { $this->set_error('upload_invalid_filetype'); - return FALSE; + return FALSE; } } - + // Convert the file size to kilobytes if ($this->file_size > 0) { @@ -247,7 +247,7 @@ class CI_Upload { // Sanitize the file name for security $this->file_name = $this->clean_file_name($this->file_name); - + // Truncate the file name if it's too long if ($this->max_filename > 0) { @@ -271,7 +271,7 @@ class CI_Upload { if ($this->overwrite == FALSE) { $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - + if ($this->file_name === FALSE) { return FALSE; @@ -304,8 +304,8 @@ class CI_Upload { { if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { - $this->set_error('upload_destination_error'); - return FALSE; + $this->set_error('upload_destination_error'); + return FALSE; } } @@ -319,18 +319,18 @@ class CI_Upload { return TRUE; } - + // -------------------------------------------------------------------- - + /** * Finalized Data Array - * + * * Returns an associative array containing all of the information * related to the upload, allowing the developer easy access in one array. * * @access public * @return array - */ + */ function data() { return array ( @@ -350,24 +350,24 @@ class CI_Upload { 'image_size_str' => $this->image_size_str, ); } - + // -------------------------------------------------------------------- - + /** * Set Upload Path * * @access public * @param string * @return void - */ + */ function set_upload_path($path) { // Make sure it has a trailing slash $this->upload_path = rtrim($path, '/').'/'; } - + // -------------------------------------------------------------------- - + /** * Set the file name * @@ -379,25 +379,25 @@ class CI_Upload { * @param string * @param string * @return string - */ + */ function set_filename($path, $filename) { if ($this->encrypt_name == TRUE) - { + { mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; + $filename = md5(uniqid(mt_rand())).$this->file_ext; } - + if ( ! file_exists($path.$filename)) { return $filename; } - + $filename = str_replace($this->file_ext, '', $filename); - + $new_filename = ''; for ($i = 1; $i < 100; $i++) - { + { if ( ! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; @@ -415,72 +415,72 @@ class CI_Upload { return $new_filename; } } - + // -------------------------------------------------------------------- - + /** * Set Maximum File Size * * @access public * @param integer * @return void - */ + */ function set_max_filesize($n) { $this->max_size = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Maximum File Name Length * * @access public * @param integer * @return void - */ + */ function set_max_filename($n) { $this->max_filename = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- - + /** * Set Maximum Image Width * * @access public * @param integer * @return void - */ + */ function set_max_width($n) { $this->max_width = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Maximum Image Height * * @access public * @param integer * @return void - */ + */ function set_max_height($n) { $this->max_height = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Allowed File Types * * @access public * @param string * @return void - */ + */ function set_allowed_types($types) { if ( ! is_array($types) && $types == '*') @@ -490,9 +490,9 @@ class CI_Upload { } $this->allowed_types = explode('|', $types); } - + // -------------------------------------------------------------------- - + /** * Set Image Properties * @@ -501,7 +501,7 @@ class CI_Upload { * @access public * @param string * @return void - */ + */ function set_image_properties($path = '') { if ( ! $this->is_image()) @@ -512,7 +512,7 @@ class CI_Upload { if (function_exists('getimagesize')) { if (FALSE !== ($D = @getimagesize($path))) - { + { $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $this->image_width = $D['0']; @@ -522,9 +522,9 @@ class CI_Upload { } } } - + // -------------------------------------------------------------------- - + /** * Set XSS Clean * @@ -539,15 +539,15 @@ class CI_Upload { { $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Validate the image * * @access public * @return bool - */ + */ function is_image() { // IE will sometimes return odd mime-types during upload, so here we just standardize all @@ -555,12 +555,12 @@ class CI_Upload { $png_mimes = array('image/x-png'); $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); - + if (in_array($this->file_type, $png_mimes)) { $this->file_type = 'image/png'; } - + if (in_array($this->file_type, $jpeg_mimes)) { $this->file_type = 'image/jpeg'; @@ -570,80 +570,80 @@ class CI_Upload { 'image/gif', 'image/jpeg', 'image/png', - ); + ); return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Verify that the filetype is allowed * * @access public * @return bool - */ + */ function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { return TRUE; } - + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; } - + $ext = strtolower(ltrim($this->file_ext, '.')); - + if ( ! in_array($ext, $this->allowed_types)) { return FALSE; } - // Images get some additional checks + // Images get some additional checks $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); - + if (in_array($ext, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { return FALSE; - } + } } - + if ($ignore_mime === TRUE) { return TRUE; } - + $mime = $this->mimes_types($ext); - + if (is_array($mime)) { if (in_array($this->file_type, $mime, TRUE)) { return TRUE; - } + } } elseif ($mime == $this->file_type) { return TRUE; } - + return FALSE; } - + // -------------------------------------------------------------------- - + /** * Verify that the file is within the allowed size * * @access public * @return bool - */ + */ function is_allowed_filesize() { if ($this->max_size != 0 AND $this->file_size > $this->max_size) @@ -655,15 +655,15 @@ class CI_Upload { return TRUE; } } - + // -------------------------------------------------------------------- - + /** * Verify that the image is within the allowed width/height * * @access public * @return bool - */ + */ function is_allowed_dimensions() { if ( ! $this->is_image()) @@ -690,9 +690,9 @@ class CI_Upload { return TRUE; } - + // -------------------------------------------------------------------- - + /** * Validate Upload Path * @@ -701,7 +701,7 @@ class CI_Upload { * * @access public * @return bool - */ + */ function validate_upload_path() { if ($this->upload_path == '') @@ -709,7 +709,7 @@ class CI_Upload { $this->set_error('upload_no_filepath'); return FALSE; } - + if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); @@ -730,31 +730,31 @@ class CI_Upload { $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } - + // -------------------------------------------------------------------- - + /** * Extract the file extension * * @access public * @param string * @return string - */ + */ function get_extension($filename) { $x = explode('.', $filename); return '.'.end($x); - } - + } + // -------------------------------------------------------------------- - + /** * Clean the file name for security * * @access public * @param string * @return string - */ + */ function clean_file_name($filename) { $bad = array( @@ -773,40 +773,40 @@ class CI_Upload { "%20", "%22", "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; "%3d" // = ); - + $filename = str_replace($bad, '', $filename); return stripslashes($filename); } // -------------------------------------------------------------------- - + /** * Limit the File Name Length * * @access public * @param string * @return string - */ + */ function limit_filename_length($filename, $length) { if (strlen($filename) < $length) { return $filename; } - + $ext = ''; if (strpos($filename, '.') !== FALSE) { @@ -814,12 +814,12 @@ class CI_Upload { $ext = '.'.array_pop($parts); $filename = implode('.', $parts); } - + return substr($filename, 0, ($length - strlen($ext))).$ext; } // -------------------------------------------------------------------- - + /** * Runs the file through the XSS clean function * @@ -829,26 +829,26 @@ class CI_Upload { * * @access public * @return void - */ + */ function do_xss_clean() - { + { $file = $this->file_temp; - + if (filesize($file) == 0) { return FALSE; } - + if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit') != '') { $current = ini_get('memory_limit') * 1024 * 1024; - + // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output // into scientific notation. number_format() ensures this number is an integer // http://bugs.php.net/bug.php?id=43053 - + $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); - + ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net } @@ -856,18 +856,18 @@ class CI_Upload { // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of - // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an + // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an // attempted XSS attack. if (function_exists('getimagesize') && @getimagesize($file) !== FALSE) { - if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary - { + if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary + { return FALSE; // Couldn't open the file, return FALSE - } + } - $opening_bytes = fread($file, 256); - fclose($file); + $opening_bytes = fread($file, 256); + fclose($file); // These are known to throw IE into mime-type detection chaos // <a, <body, <head, <html, <img, <plaintext, <pre, <script, <table, <title @@ -885,37 +885,37 @@ class CI_Upload { } $CI =& get_instance(); - + if ( ! isset($CI->security)) { $CI->load->library('security'); } - + return $CI->security->xss_clean($data, TRUE); } - + // -------------------------------------------------------------------- - + /** * Set an error message * * @access public * @param string * @return void - */ + */ function set_error($msg) { - $CI =& get_instance(); + $CI =& get_instance(); $CI->lang->load('upload'); - + if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); - } + } } else { @@ -924,9 +924,9 @@ class CI_Upload { log_message('error', $msg); } } - + // -------------------------------------------------------------------- - + /** * Display the error message * @@ -934,7 +934,7 @@ class CI_Upload { * @param string * @param string * @return string - */ + */ function display_errors($open = '<p>', $close = '</p>') { $str = ''; @@ -942,12 +942,12 @@ class CI_Upload { { $str .= $open.$val.$close; } - + return $str; } - + // -------------------------------------------------------------------- - + /** * List of Mime Types * @@ -957,11 +957,11 @@ class CI_Upload { * @access public * @param string * @return string - */ + */ function mimes_types($mime) { global $mimes; - + if (count($this->mimes) == 0) { if (@require_once(APPPATH.'config/mimes'.EXT)) @@ -970,12 +970,12 @@ class CI_Upload { unset($mimes); } } - + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } // -------------------------------------------------------------------- - + /** * Prep Filename * @@ -1010,7 +1010,7 @@ class CI_Upload { } $filename .= '.'.$ext; - + return $filename; } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a7c7a7609..00cbf6967 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -29,25 +29,25 @@ class CI_User_agent { var $agent = NULL; - + var $is_browser = FALSE; var $is_robot = FALSE; var $is_mobile = FALSE; var $languages = array(); var $charsets = array(); - + var $platforms = array(); var $browsers = array(); var $mobiles = array(); var $robots = array(); - + var $platform = ''; var $browser = ''; var $version = ''; var $mobile = ''; var $robot = ''; - + /** * Constructor * @@ -55,14 +55,14 @@ class CI_User_agent { * * @access public * @return void - */ + */ function CI_User_agent() { if (isset($_SERVER['HTTP_USER_AGENT'])) { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - + if ( ! is_null($this->agent)) { if ($this->_load_agent_file()) @@ -70,27 +70,27 @@ class CI_User_agent { $this->_compile_data(); } } - + log_message('debug', "User Agent Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Compile the User Agent Data * * @access private * @return bool - */ + */ function _load_agent_file() { if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } - + $return = FALSE; - + if (isset($platforms)) { $this->platforms = $platforms; @@ -111,7 +111,7 @@ class CI_User_agent { unset($mobiles); $return = TRUE; } - + if (isset($robots)) { $this->robots = $robots; @@ -121,36 +121,36 @@ class CI_User_agent { return $return; } - + // -------------------------------------------------------------------- - + /** * Compile the User Agent Data * * @access private * @return bool - */ + */ function _compile_data() { $this->_set_platform(); - + foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) { if ($this->$function() === TRUE) { break; } - } + } } - + // -------------------------------------------------------------------- - + /** * Set the Platform * * @access private * @return mixed - */ + */ function _set_platform() { if (is_array($this->platforms) AND count($this->platforms) > 0) @@ -168,19 +168,19 @@ class CI_User_agent { } // -------------------------------------------------------------------- - + /** * Set the Browser * * @access private * @return bool - */ + */ function _set_browser() { if (is_array($this->browsers) AND count($this->browsers) > 0) { foreach ($this->browsers as $key => $val) - { + { if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) { $this->is_browser = TRUE; @@ -193,19 +193,19 @@ class CI_User_agent { } return FALSE; } - + // -------------------------------------------------------------------- - + /** * Set the Robot * * @access private * @return bool - */ + */ function _set_robot() { if (is_array($this->robots) AND count($this->robots) > 0) - { + { foreach ($this->robots as $key => $val) { if (preg_match("|".preg_quote($key)."|i", $this->agent)) @@ -220,17 +220,17 @@ class CI_User_agent { } // -------------------------------------------------------------------- - + /** * Set the Mobile Device * * @access private * @return bool - */ + */ function _set_mobile() { if (is_array($this->mobiles) AND count($this->mobiles) > 0) - { + { foreach ($this->mobiles as $key => $val) { if (FALSE !== (strpos(strtolower($this->agent), $key))) @@ -240,261 +240,261 @@ class CI_User_agent { return TRUE; } } - } + } return FALSE; } - + // -------------------------------------------------------------------- - + /** * Set the accepted languages * * @access private * @return void - */ + */ function _set_languages() { if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); - + $this->languages = explode(',', $languages); } - + if (count($this->languages) == 0) { $this->languages = array('Undefined'); - } + } } - + // -------------------------------------------------------------------- - + /** * Set the accepted character sets * * @access private * @return void - */ + */ function _set_charsets() - { + { if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); - + $this->charsets = explode(',', $charsets); } - + if (count($this->charsets) == 0) { $this->charsets = array('Undefined'); - } + } } // -------------------------------------------------------------------- - + /** * Is Browser * * @access public * @return bool - */ + */ function is_browser() { return $this->is_browser; } // -------------------------------------------------------------------- - + /** * Is Robot * * @access public * @return bool - */ + */ function is_robot() { return $this->is_robot; } // -------------------------------------------------------------------- - + /** * Is Mobile * * @access public * @return bool - */ + */ function is_mobile() { return $this->is_mobile; - } + } // -------------------------------------------------------------------- - + /** * Is this a referral from another site? * * @access public * @return bool - */ + */ function is_referral() { return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- - + /** * Agent String * * @access public * @return string - */ + */ function agent_string() { return $this->agent; } // -------------------------------------------------------------------- - + /** * Get Platform * * @access public * @return string - */ + */ function platform() { return $this->platform; } // -------------------------------------------------------------------- - + /** * Get Browser Name * * @access public * @return string - */ + */ function browser() { return $this->browser; } // -------------------------------------------------------------------- - + /** * Get the Browser Version * * @access public * @return string - */ + */ function version() { return $this->version; } // -------------------------------------------------------------------- - + /** * Get The Robot Name * * @access public * @return string - */ + */ function robot() { return $this->robot; } // -------------------------------------------------------------------- - + /** * Get the Mobile Device * * @access public * @return string - */ + */ function mobile() { return $this->mobile; } - + // -------------------------------------------------------------------- - + /** * Get the referrer * * @access public * @return bool - */ + */ function referrer() { return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- - + /** * Get the accepted languages * * @access public * @return array - */ + */ function languages() { if (count($this->languages) == 0) { $this->_set_languages(); } - + return $this->languages; } // -------------------------------------------------------------------- - + /** * Get the accepted Character Sets * * @access public * @return array - */ + */ function charsets() { if (count($this->charsets) == 0) { $this->_set_charsets(); } - + return $this->charsets; } - + // -------------------------------------------------------------------- - + /** * Test for a particular language * * @access public * @return bool - */ + */ function accept_lang($lang = 'en') { return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Test for a particular character set * * @access public * @return bool - */ + */ function accept_charset($charset = 'utf-8') { return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; } - - + + } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ff03a503a..54ee70771 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -14,7 +14,7 @@ */ if ( ! function_exists('xml_parser_create')) -{ +{ show_error('Your PHP installation does not support XML'); } @@ -32,34 +32,34 @@ if ( ! function_exists('xml_parser_create')) */ class CI_Xmlrpc { - var $debug = FALSE; // Debugging on or off + var $debug = FALSE; // Debugging on or off var $xmlrpcI4 = 'i4'; var $xmlrpcInt = 'int'; var $xmlrpcBoolean = 'boolean'; - var $xmlrpcDouble = 'double'; + var $xmlrpcDouble = 'double'; var $xmlrpcString = 'string'; var $xmlrpcDateTime = 'dateTime.iso8601'; var $xmlrpcBase64 = 'base64'; var $xmlrpcArray = 'array'; var $xmlrpcStruct = 'struct'; - + var $xmlrpcTypes = array(); var $valid_parents = array(); var $xmlrpcerr = array(); // Response numbers var $xmlrpcstr = array(); // Response strings - + var $xmlrpc_defencoding = 'UTF-8'; var $xmlrpcName = 'XML-RPC for CodeIgniter'; var $xmlrpcVersion = '1.1'; var $xmlrpcerruser = 800; // Start of user errors var $xmlrpcerrxml = 100; // Start of XML Parse errors var $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp - + var $client; var $method; var $data; var $message = ''; - var $error = ''; // Error string for request + var $error = ''; // Error string for request var $result; var $response = array(); // Response from remote server @@ -71,22 +71,22 @@ class CI_Xmlrpc { function CI_Xmlrpc ($config = array()) { - $this->xmlrpcName = $this->xmlrpcName; + $this->xmlrpcName = $this->xmlrpcName; $this->xmlrpc_backslash = chr(92).chr(92); - + // Types for info sent back and forth $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', - $this->xmlrpcBoolean => '1', - $this->xmlrpcString => '1', - $this->xmlrpcDouble => '1', - $this->xmlrpcDateTime => '1', - $this->xmlrpcBase64 => '1', - $this->xmlrpcArray => '2', - $this->xmlrpcStruct => '3' + $this->xmlrpcI4 => '1', + $this->xmlrpcInt => '1', + $this->xmlrpcBoolean => '1', + $this->xmlrpcString => '1', + $this->xmlrpcDouble => '1', + $this->xmlrpcDateTime => '1', + $this->xmlrpcBase64 => '1', + $this->xmlrpcArray => '2', + $this->xmlrpcStruct => '3' ); - + // Array of Valid Parents for Various XML-RPC elements $this->valid_parents = array('BOOLEAN' => array('VALUE'), 'I4' => array('VALUE'), @@ -106,8 +106,8 @@ class CI_Xmlrpc { 'FAULT' => array('METHODRESPONSE'), 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') ); - - + + // XML-RPC Responses $this->xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; @@ -121,13 +121,13 @@ class CI_Xmlrpc { $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; $this->xmlrpcerr['no_data'] = '6'; $this->xmlrpcstr['no_data'] ='No data received from server.'; - + $this->initialize($config); - + log_message('debug', "XML-RPC Class Initialized"); } - - + + //------------------------------------- // Initialize Prefs //------------------------------------- @@ -140,13 +140,13 @@ class CI_Xmlrpc { { if (isset($this->$key)) { - $this->$key = $val; + $this->$key = $val; } } } } // END - + //------------------------------------- // Take URL and parse it //------------------------------------- @@ -157,20 +157,20 @@ class CI_Xmlrpc { { $url = "http://".$url; } - + $parts = parse_url($url); - + $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; - + if (isset($parts['query']) && $parts['query'] != '') { $path .= '?'.$parts['query']; - } - + } + $this->client = new XML_RPC_Client($path, $parts['host'], $port); } // END - + //------------------------------------- // Set Timeout //------------------------------------- @@ -183,7 +183,7 @@ class CI_Xmlrpc { } } // END - + //------------------------------------- // Set Methods //------------------------------------- @@ -193,7 +193,7 @@ class CI_Xmlrpc { $this->method = $function; } // END - + //------------------------------------- // Take Array of Data and Create Objects //------------------------------------- @@ -204,17 +204,17 @@ class CI_Xmlrpc { { // Send Error } - + $this->data = array(); - + foreach($incoming as $key => $value) { $this->data[$key] = $this->values_parsing($value); } } // END - - + + //------------------------------------- // Set Debug //------------------------------------- @@ -223,7 +223,7 @@ class CI_Xmlrpc { { $this->debug = ($flag == TRUE) ? TRUE : FALSE; } - + //------------------------------------- // Values Parsing //------------------------------------- @@ -249,7 +249,7 @@ class CI_Xmlrpc { { $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); } - + $temp = new XML_RPC_Values($value['0'], $value['1']); } else @@ -275,7 +275,7 @@ class CI_Xmlrpc { { $this->message = new XML_RPC_Message($this->method,$this->data); $this->message->debug = $this->debug; - + if ( ! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; @@ -286,13 +286,13 @@ class CI_Xmlrpc { $this->error = $this->result->errstr; return FALSE; } - + $this->response = $this->result->decode(); - + return TRUE; } // END - + //------------------------------------- // Returns Error //------------------------------------- @@ -302,7 +302,7 @@ class CI_Xmlrpc { return $this->error; } // END - + //------------------------------------- // Returns Remote Server Response //------------------------------------- @@ -312,37 +312,37 @@ class CI_Xmlrpc { return $this->response; } // END - + //------------------------------------- // Sends an Error Message for Server Request //------------------------------------- - + function send_error_message($number, $message) { return new XML_RPC_Response('0',$number, $message); } // END - - + + //------------------------------------- // Send Response for Server Request //------------------------------------- - + function send_response($response) { // $response should be array of values, which will be parsed // based on their data and type into a valid group of XML-RPC values - + $response = $this->values_parsing($response); - + return new XML_RPC_Response($response); } // END - + } // END XML_RPC Class - - + + /** * XML-RPC Client class * @@ -363,12 +363,12 @@ class XML_RPC_Client extends CI_Xmlrpc function XML_RPC_Client($path, $server, $port=80) { parent::CI_Xmlrpc(); - + $this->port = $port; $this->server = $server; $this->path = $path; } - + function send($msg) { if (is_array($msg)) @@ -382,22 +382,22 @@ class XML_RPC_Client extends CI_Xmlrpc } function sendPayload($msg) - { + { $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - + if ( ! is_resource($fp)) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); return $r; } - + if(empty($msg->payload)) { // $msg = XML_RPC_Messages $msg->createPayload(); } - + $r = "\r\n"; $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; @@ -405,7 +405,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op .= "User-Agent: {$this->xmlrpcName}$r"; $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; $op .= $msg->payload; - + if ( ! fputs($fp, $op, strlen($op))) { @@ -437,7 +437,7 @@ class XML_RPC_Response var $xss_clean = TRUE; function XML_RPC_Response($val, $code = 0, $fstr = '') - { + { if ($code != 0) { // error @@ -470,7 +470,7 @@ class XML_RPC_Response { return $this->val; } - + function prepare_response() { $result = "<methodResponse>\n"; @@ -500,7 +500,7 @@ class XML_RPC_Response $result .= "\n</methodResponse>"; return $result; } - + function decode($array=FALSE) { $CI =& get_instance(); @@ -523,13 +523,13 @@ class XML_RPC_Response $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key]; } } - + $result = $array; } else { $result = $this->xmlrpc_decoder($this->val); - + if (is_array($result)) { $result = $this->decode($result); @@ -539,12 +539,12 @@ class XML_RPC_Response $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; } } - + return $result; } - - + + //------------------------------------- // XML-RPC Object to PHP Types //------------------------------------- @@ -562,7 +562,7 @@ class XML_RPC_Response reset($xmlrpc_val->me); list($a,$b) = each($xmlrpc_val->me); $size = count($b); - + $arr = array(); for($i = 0; $i < $size; $i++) @@ -583,8 +583,8 @@ class XML_RPC_Response return $arr; } } - - + + //------------------------------------- // ISO-8601 time to server or UTC time //------------------------------------- @@ -602,7 +602,7 @@ class XML_RPC_Response } return $t; } - + } // End Response Class @@ -619,12 +619,12 @@ class XML_RPC_Message extends CI_Xmlrpc var $payload; var $method_name; var $params = array(); - var $xh = array(); + var $xh = array(); function XML_RPC_Message($method, $pars=0) { parent::CI_Xmlrpc(); - + $this->method_name = $method; if (is_array($pars) && count($pars) > 0) { @@ -635,51 +635,51 @@ class XML_RPC_Message extends CI_Xmlrpc } } } - + //------------------------------------- // Create Payload to Send //------------------------------------- - + function createPayload() { $this->payload = "<?xml version=\"1.0\"?".">\r\n<methodCall>\r\n"; $this->payload .= '<methodName>' . $this->method_name . "</methodName>\r\n"; $this->payload .= "<params>\r\n"; - + for($i=0; $i<count($this->params); $i++) { // $p = XML_RPC_Values $p = $this->params[$i]; $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n"; } - + $this->payload .= "</params>\r\n</methodCall>\r\n"; } - + //------------------------------------- // Parse External XML-RPC Server's Response //------------------------------------- - + function parseResponse($fp) { $data = ''; - + while($datum = fread($fp, 4096)) { $data .= $datum; } - + //------------------------------------- // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- - + if ($this->debug === TRUE) { echo "<pre>"; echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n"; echo "</pre>"; } - + //------------------------------------- // Check for data //------------------------------------- @@ -690,32 +690,32 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); return $r; } - - + + //------------------------------------- // Check for HTTP 200 Response //------------------------------------- - + if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) { $errstr= substr($data, 0, strpos($data, "\n")-1); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); return $r; } - + //------------------------------------- // Create and Set Up XML Parser //------------------------------------- - + $parser = xml_parser_create($this->xmlrpc_defencoding); - $this->xh[$parser] = array(); - $this->xh[$parser]['isf'] = 0; - $this->xh[$parser]['ac'] = ''; - $this->xh[$parser]['headers'] = array(); - $this->xh[$parser]['stack'] = array(); - $this->xh[$parser]['valuestack'] = array(); - $this->xh[$parser]['isf_reason'] = 0; + $this->xh[$parser] = array(); + $this->xh[$parser]['isf'] = 0; + $this->xh[$parser]['ac'] = ''; + $this->xh[$parser]['headers'] = array(); + $this->xh[$parser]['stack'] = array(); + $this->xh[$parser]['valuestack'] = array(); + $this->xh[$parser]['isf_reason'] = 0; xml_set_object($parser, $this); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); @@ -727,7 +727,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // GET HEADERS //------------------------------------- - + $lines = explode("\r\n", $data); while (($line = array_shift($lines))) { @@ -738,11 +738,11 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$parser]['headers'][] = $line; } $data = implode("\r\n", $lines); - - + + //------------------------------------- // PARSE XML DATA - //------------------------------------- + //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) { @@ -755,11 +755,11 @@ class XML_RPC_Message extends CI_Xmlrpc return $r; } xml_parser_free($parser); - + // --------------------------------------- // Got Ourselves Some Badness, It Seems // --------------------------------------- - + if ($this->xh[$parser]['isf'] > 1) { if ($this->debug === TRUE) @@ -768,7 +768,7 @@ class XML_RPC_Message extends CI_Xmlrpc echo $this->xh[$parser]['isf_reason']; echo "---Invalid Return---\n\n"; } - + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } @@ -777,15 +777,15 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } - + //------------------------------------- // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - + //------------------------------------- + if ($this->debug === TRUE) { echo "<pre>"; - + if (count($this->xh[$parser]['headers'] > 0)) { echo "---HEADERS---\n"; @@ -795,20 +795,20 @@ class XML_RPC_Message extends CI_Xmlrpc } echo "---END HEADERS---\n\n"; } - + echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n"; - + echo "---PARSED---\n" ; var_dump($this->xh[$parser]['value']); echo "\n---END PARSED---</pre>"; } - + //------------------------------------- // SEND RESPONSE //------------------------------------- - + $v = $this->xh[$parser]['value']; - + if ($this->xh[$parser]['isf']) { $errno_v = $v->me['struct']['faultCode']; @@ -831,11 +831,11 @@ class XML_RPC_Message extends CI_Xmlrpc $r->headers = $this->xh[$parser]['headers']; return $r; } - + // ------------------------------------ // Begin Return Message Parsing section // ------------------------------------ - + // quick explanation of components: // ac - used to accumulate values // isf - used to indicate a fault @@ -854,9 +854,9 @@ class XML_RPC_Message extends CI_Xmlrpc { // If invalid nesting, then return if ($this->xh[$the_parser]['isf'] > 1) return; - + // Evaluate and check for correct nesting of XML elements - + if (count($this->xh[$the_parser]['stack']) == 0) { if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') @@ -876,16 +876,16 @@ class XML_RPC_Message extends CI_Xmlrpc return; } } - + switch($name) { case 'STRUCT': case 'ARRAY': // Creates array for child elements - + $cur_val = array('value' => array(), 'type' => $name); - + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); break; case 'METHODNAME': @@ -917,13 +917,13 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; return; } - + $this->xh[$the_parser]['ac'] = ''; break; case 'MEMBER': // Set name of <member> to nothing to prevent errors later if no <name> is found $this->xh[$the_parser]['valuestack'][0]['name'] = ''; - + // Set NULL value to check to see if value passed for this param/member $this->xh[$the_parser]['value'] = null; break; @@ -939,7 +939,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; break; } - + // Add current element name to stack, to allow validation of nesting array_unshift($this->xh[$the_parser]['stack'], $name); @@ -955,14 +955,14 @@ class XML_RPC_Message extends CI_Xmlrpc function closing_tag($the_parser, $name) { if ($this->xh[$the_parser]['isf'] > 1) return; - + // Remove current element from stack and set variable // NOTE: If the XML validates, then we do not have to worry about // the opening and closing of elements. Nesting is checked on the opening // tag so we be safe there as well. - + $curr_elem = array_shift($this->xh[$the_parser]['stack']); - + switch($name) { case 'STRUCT': @@ -982,7 +982,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'DATETIME.ISO8601': case 'BASE64': $this->xh[$the_parser]['vt'] = strtolower($name); - + if ($name == 'STRING') { $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; @@ -1044,10 +1044,10 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; $this->xh[$the_parser]['vt'] = $this->xmlrpcString; } - + // build the XML-RPC value out of the data received, and substitute it $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); - + if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') { // Array @@ -1061,7 +1061,7 @@ class XML_RPC_Message extends CI_Xmlrpc break; case 'MEMBER': $this->xh[$the_parser]['ac']=''; - + // If value add to array in the stack for the last element built if ($this->xh[$the_parser]['value']) { @@ -1099,7 +1099,7 @@ class XML_RPC_Message extends CI_Xmlrpc function character_data($the_parser, $data) { if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already - + // If a value has not been found if ($this->xh[$the_parser]['lv'] != 3) { @@ -1107,28 +1107,28 @@ class XML_RPC_Message extends CI_Xmlrpc { $this->xh[$the_parser]['lv'] = 2; // Found a value } - + if( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } - + $this->xh[$the_parser]['ac'] .= $data; } } - - + + function addParam($par) { $this->params[]=$par; } - + function output_parameters($array=FALSE) { - $CI =& get_instance(); + $CI =& get_instance(); if ($this->xss_clean && ! isset($CI->security)) { $CI->load->library('security'); } - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -1144,17 +1144,17 @@ class XML_RPC_Message extends CI_Xmlrpc $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]); } } - + $parameters = $array; } else { $parameters = array(); - + for ($i = 0; $i < count($this->params); $i++) { $a_param = $this->decode_message($this->params[$i]); - + if (is_array($a_param)) { $parameters[] = $this->output_parameters($a_param); @@ -1163,13 +1163,13 @@ class XML_RPC_Message extends CI_Xmlrpc { $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; } - } + } } - + return $parameters; } - - + + function decode_message($param) { $kind = $param->kindOf(); @@ -1182,31 +1182,31 @@ class XML_RPC_Message extends CI_Xmlrpc { reset($param->me); list($a,$b) = each($param->me); - + $arr = array(); for($i = 0; $i < count($b); $i++) { $arr[] = $this->decode_message($param->me['array'][$i]); } - + return $arr; } elseif($kind == 'struct') { reset($param->me['struct']); - + $arr = array(); while(list($key,$value) = each($param->me['struct'])) { $arr[$key] = $this->decode_message($value); } - + return $arr; } } - + } // End XML_RPC_Messages class @@ -1220,17 +1220,17 @@ class XML_RPC_Message extends CI_Xmlrpc */ class XML_RPC_Values extends CI_Xmlrpc { - var $me = array(); + var $me = array(); var $mytype = 0; function XML_RPC_Values($val=-1, $type='') - { + { parent::CI_Xmlrpc(); - + if ($val != -1 OR $type != '') { $type = $type == '' ? 'string' : $type; - + if ($this->xmlrpcTypes[$type] == 1) { $this->addScalar($val,$type); @@ -1249,13 +1249,13 @@ class XML_RPC_Values extends CI_Xmlrpc function addScalar($val, $type='string') { $typeof = $this->xmlrpcTypes[$type]; - + if ($this->mytype==1) { echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />'; return 0; } - + if ($typeof != 1) { echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />'; @@ -1392,12 +1392,12 @@ class XML_RPC_Values extends CI_Xmlrpc { $ar = $o->me; reset($ar); - + list($typ, $val) = each($ar); $rs = "<value>\n".$this->serializedata($typ, $val)."</value>\n"; return $rs; } - + function scalarval() { reset($this->me); @@ -1409,11 +1409,11 @@ class XML_RPC_Values extends CI_Xmlrpc //------------------------------------- // Encode time in ISO-8601 form. //------------------------------------- - + // Useful for sending time in XML-RPC function iso8601_encode($time, $utc=0) - { + { if ($utc == 1) { $t = strftime("%Y%m%dT%H:%M:%S", $time); @@ -1427,7 +1427,7 @@ class XML_RPC_Values extends CI_Xmlrpc } return $t; } - + } // END XML_RPC_Values Class diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index c1fe649f9..56fd655df 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -14,7 +14,7 @@ */ if ( ! function_exists('xml_parser_create')) -{ +{ show_error('Your PHP installation does not support XML'); } @@ -36,11 +36,11 @@ if ( ! class_exists('CI_Xmlrpc')) */ class CI_Xmlrpcs extends CI_Xmlrpc { - var $methods = array(); //array of methods mapped to function names and signatures + var $methods = array(); //array of methods mapped to function names and signatures var $debug_msg = ''; // Debug Message - var $system_methods = array(); // XML RPC Server methods + var $system_methods = array(); // XML RPC Server methods var $controller_obj; - + var $object = FALSE; @@ -49,49 +49,49 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- function CI_Xmlrpcs($config=array()) - { + { parent::CI_Xmlrpc(); $this->set_system_methods(); - + if (isset($config['functions']) && is_array($config['functions'])) { $this->methods = array_merge($this->methods, $config['functions']); } - + log_message('debug', "XML-RPC Server Class Initialized"); } - + //------------------------------------- // Initialize Prefs and Serve //------------------------------------- - + function initialize($config=array()) - { + { if (isset($config['functions']) && is_array($config['functions'])) { $this->methods = array_merge($this->methods, $config['functions']); } - + if (isset($config['debug'])) { $this->debug = $config['debug']; } - + if (isset($config['object']) && is_object($config['object'])) { $this->object = $config['object']; } - + if (isset($config['xss_clean'])) { $this->xss_clean = $config['xss_clean']; } } - + //------------------------------------- // Setting of System Methods //------------------------------------- - + function set_system_methods () { $this->methods = array( @@ -118,14 +118,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Main Server Function //------------------------------------- - + function serve() { $r = $this->parseRequest(); $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); - + header("Content-Type: text/xml"); header("Content-Length: ".strlen($payload)); exit($payload); @@ -134,7 +134,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Add Method to Class //------------------------------------- - + function add_to_map($methodname,$function,$sig,$doc) { $this->methods[$methodname] = array( @@ -148,11 +148,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Parse Server Request //------------------------------------- - + function parseRequest($data='') { global $HTTP_RAW_POST_DATA; - + //------------------------------------- // Get Data //------------------------------------- @@ -165,10 +165,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Set up XML Parser //------------------------------------- - + $parser = xml_parser_create($this->xmlrpc_defencoding); $parser_object = new XML_RPC_Message("filler"); - + $parser_object->xh[$parser] = array(); $parser_object->xh[$parser]['isf'] = 0; $parser_object->xh[$parser]['isf_reason'] = ''; @@ -182,12 +182,12 @@ class CI_Xmlrpcs extends CI_Xmlrpc xml_set_element_handler($parser, 'open_tag', 'closing_tag'); xml_set_character_data_handler($parser, 'character_data'); //xml_set_default_handler($parser, 'default_handler'); - - + + //------------------------------------- // PARSE + PROCESS XML DATA - //------------------------------------- - + //------------------------------------- + if ( ! xml_parse($parser, $data, 1)) { // return XML error as a faultCode @@ -205,53 +205,53 @@ class CI_Xmlrpcs extends CI_Xmlrpc else { xml_parser_free($parser); - + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); $plist=''; - + for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) { if ($this->debug === TRUE) { $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } - + $m->addParam($parser_object->xh[$parser]['params'][$i]); } - + if ($this->debug === TRUE) { echo "<pre>"; echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n"; echo "</pre>"; } - + $r = $this->_execute($m); } - + //------------------------------------- // SET DEBUGGING MESSAGE - //------------------------------------- - + //------------------------------------- + if ($this->debug === TRUE) { $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n"; } - + return $r; } //------------------------------------- // Executes the Method //------------------------------------- - + function _execute($m) { $methName = $m->method_name; - + // Check to see if it is a system call $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE; - + if ($this->xss_clean == FALSE) { $m->xss_clean = FALSE; @@ -260,19 +260,19 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Valid Method //------------------------------------- - + if ( ! isset($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } - + //------------------------------------- // Check for Method (and Object) //------------------------------------- - + $method_parts = explode(".", $this->methods[$methName]['function']); $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE; - + if ($system_call === TRUE) { if ( ! is_callable(array($this,$method_parts['1']))) @@ -291,30 +291,30 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } } - + //------------------------------------- // Checking Methods Signature //------------------------------------- - + if (isset($this->methods[$methName]['signature'])) { $sig = $this->methods[$methName]['signature']; for($i=0; $i<count($sig); $i++) { $current_sig = $sig[$i]; - + if (count($current_sig) == count($m->params)+1) { for($n=0; $n < count($m->params); $n++) { $p = $m->params[$n]; $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); - + if ($pt != $current_sig[$n+1]) { $pno = $n+1; $wanted = $current_sig[$n+1]; - + return new XML_RPC_Response(0, $this->xmlrpcerr['incorrect_params'], $this->xmlrpcstr['incorrect_params'] . @@ -354,22 +354,22 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - - + + //------------------------------------- // Server Function: List Methods //------------------------------------- - + function listMethods($m) { $v = new XML_RPC_Values(); $output = array(); - + foreach($this->methods as $key => $value) { $output[] = new XML_RPC_Values($key, 'string'); } - + foreach($this->system_methods as $key => $value) { $output[]= new XML_RPC_Values($key, 'string'); @@ -378,23 +378,23 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + //------------------------------------- // Server Function: Return Signature for Method //------------------------------------- - + function methodSignature($m) { $parameters = $m->output_parameters(); $method_name = $parameters[0]; - + if (isset($this->methods[$method_name])) { if ($this->methods[$method_name]['signature']) { $sigs = array(); $signature = $this->methods[$method_name]['signature']; - + for($i=0; $i < count($signature); $i++) { $cursig = array(); @@ -418,20 +418,20 @@ class CI_Xmlrpcs extends CI_Xmlrpc } return $r; } - + //------------------------------------- // Server Function: Doc String for Method //------------------------------------- - + function methodHelp($m) { $parameters = $m->output_parameters(); $method_name = $parameters[0]; - + if (isset($this->methods[$method_name])) { $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; - + return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); } else @@ -448,7 +448,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { // Disabled return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - + $parameters = $m->output_parameters(); $calls = $parameters[0]; @@ -457,15 +457,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc foreach ($calls as $value) { //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1])); - + $m = new XML_RPC_Message($value[0]); $plist=''; - + for($i=0; $i < count($value[1]); $i++) { $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); } - + $attempt = $this->_execute($m); if ($attempt->faultCode() != 0) @@ -478,8 +478,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); } - - + + //------------------------------------- // Multi-call Function: Error Handling //------------------------------------- @@ -488,28 +488,28 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); - + $struct['faultCode'] = new XML_RPC_Values($code, 'int'); $struct['faultString'] = new XML_RPC_Values($str, 'string'); - + return new XML_RPC_Values($struct, 'struct'); } - - + + //------------------------------------- // Multi-call Function: Processes method //------------------------------------- - + function do_multicall($call) { if ($call->kindOf() != 'struct') return $this->multicall_error('notstruct'); elseif ( ! $methName = $call->me['struct']['methodName']) return $this->multicall_error('nomethod'); - + list($scalar_type,$scalar_value)=each($methName->me); $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; - + if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') return $this->multicall_error('notstring'); elseif ($scalar_value == 'system.multicall') @@ -518,7 +518,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return $this->multicall_error('noparams'); elseif ($params->kindOf() != 'array') return $this->multicall_error('notarray'); - + list($a,$b)=each($params->me); $numParams = count($b); @@ -536,8 +536,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc } return new XML_RPC_Values(array($result->value()), 'array'); - } - + } + } // END XML_RPC_Server class diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 92dfc814d..da3e5eb63 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -32,17 +32,17 @@ */ class CI_Zip { - var $zipdata = ''; - var $directory = ''; - var $entries = 0; - var $file_num = 0; + var $zipdata = ''; + var $directory = ''; + var $entries = 0; + var $file_num = 0; var $offset = 0; var $now; function CI_Zip() { log_message('debug', "Zip Compression Class Initialized"); - + $this->now = time(); } @@ -72,24 +72,24 @@ class CI_Zip { } } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Get file/directory modification time - * + * * If this is a newly created file/dir, we will set the time to 'now' * * @param string path to file - * @return array filemtime/filemdate + * @return array filemtime/filemdate */ function _get_mod_time($dir) { // filemtime() will return false, but it does raise an error. - $date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now); + $date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now); $time['file_mtime'] = ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2; $time['file_mdate'] = (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']; - + return $time; } @@ -103,7 +103,7 @@ class CI_Zip { * @return void */ function _add_dir($dir, $file_mtime, $file_mdate) - { + { $dir = str_replace("\\", "/", $dir); $this->zipdata .= @@ -140,7 +140,7 @@ class CI_Zip { $this->offset = strlen($this->zipdata); $this->entries++; } - + // -------------------------------------------------------------------- /** @@ -154,14 +154,14 @@ class CI_Zip { * @param mixed * @param string * @return void - */ + */ function add_data($filepath, $data = NULL) - { + { if (is_array($filepath)) { foreach ($filepath as $path => $data) { - $file_data = $this->_get_mod_time($path); + $file_data = $this->_get_mod_time($path); $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); } @@ -169,7 +169,7 @@ class CI_Zip { else { $file_data = $this->_get_mod_time($filepath); - + $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } @@ -183,7 +183,7 @@ class CI_Zip { * @param string the file name/path * @param string the data to be encoded * @return void - */ + */ function _add_data($filepath, $data, $file_mtime, $file_mdate) { $filepath = str_replace("\\", "/", $filepath); @@ -227,7 +227,7 @@ class CI_Zip { $this->entries++; $this->file_num++; } - + // -------------------------------------------------------------------- /** @@ -235,7 +235,7 @@ class CI_Zip { * * @access public * @return bool - */ + */ function read_file($path, $preserve_filepath = FALSE) { if ( ! file_exists($path)) @@ -246,7 +246,7 @@ class CI_Zip { if (FALSE !== ($data = file_get_contents($path))) { $name = str_replace("\\", "/", $path); - + if ($preserve_filepath === FALSE) { $name = preg_replace("|.*/(.+)|", "\\1", $name); @@ -259,7 +259,7 @@ class CI_Zip { } // ------------------------------------------------------------------------ - + /** * Read a directory and add it to the zip. * @@ -321,7 +321,7 @@ class CI_Zip { * * @access public * @return binary string - */ + */ function get_zip() { // Is there any data to return? @@ -340,7 +340,7 @@ class CI_Zip { return $zip_data; } - + // -------------------------------------------------------------------- /** @@ -351,7 +351,7 @@ class CI_Zip { * @access public * @param string the file name * @return bool - */ + */ function archive($filepath) { if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) @@ -359,12 +359,12 @@ class CI_Zip { return FALSE; } - flock($fp, LOCK_EX); + flock($fp, LOCK_EX); fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); fclose($fp); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -404,7 +404,7 @@ class CI_Zip { * * @access public * @return void - */ + */ function clear_data() { $this->zipdata = ''; @@ -413,7 +413,7 @@ class CI_Zip { $this->file_num = 0; $this->offset = 0; } - + } /* End of file Zip.php */ diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php index f6b8dce69..db80c1428 100644 --- a/system/libraries/javascript/Jquery.php +++ b/system/libraries/javascript/Jquery.php @@ -173,7 +173,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - Javascript code for mouse over * @param string - Javascript code for mouse out - * @return string + * @return string */ function _hover($element = 'this', $over, $out) { @@ -390,7 +390,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _addClass($element = 'this', $class='') { @@ -410,7 +410,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _animate($element = 'this', $params = array(), $speed = '', $extra = '') { @@ -452,7 +452,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _fadeIn($element = 'this', $speed = '', $callback = '') { @@ -480,7 +480,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _fadeOut($element = 'this', $speed = '', $callback = '') { @@ -508,7 +508,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _hide($element = 'this', $speed = '', $callback = '') { @@ -534,7 +534,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _removeClass($element = 'this', $class='') { @@ -554,7 +554,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideUp($element = 'this', $speed = '', $callback = '') { @@ -582,7 +582,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideDown($element = 'this', $speed = '', $callback = '') { @@ -610,7 +610,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideToggle($element = 'this', $speed = '', $callback = '') { @@ -636,7 +636,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _toggle($element = 'this') { @@ -654,7 +654,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _toggleClass($element = 'this', $class='') { @@ -674,7 +674,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _show($element = 'this', $speed = '', $callback = '') { @@ -884,7 +884,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Table Sorter Plugin * |